Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
field_seq_put_gmsh.cc
Go to the documentation of this file.
1
21//
22// gmsh output
23//
24// author: Pierre.Saramito@imag.fr
25//
26// date: 12 may 1997 update: 23 oct 2011
27//
28#include "rheolef/field.h"
29#include "rheolef/piola_util.h"
30#include "rheolef/rheostream.h"
31#include "rheolef/iorheo.h"
32#include "rheolef/field_evaluate.h"
33#include "rheolef/space_component.h"
34#include "rheolef/field_expr.h"
35
36namespace rheolef {
37using namespace std;
38
39// extern:
40template <class T>
41odiststream&
42geo_put_gmsh (odiststream& ods, const geo_basic<T,sequential>&);
43
44template <class T>
45odiststream&
46field_put_gmsh (odiststream& ods, const field_basic<T,sequential>& uh, std::string name)
47{
49 geo_put_gmsh (ods, uh.get_geo());
50 if (name == "") { name = uh.get_space().valued(); }
51 ostream& gmsh = ods.os();
52 gmsh << setprecision(numeric_limits<T>::digits10);
53 size_type n_gmsh_comp = 1;
54 switch (uh.get_space().valued_tag()) {
55 case space_constant::scalar: n_gmsh_comp = 1; break;
56 case space_constant::vector: n_gmsh_comp = 3; break;
57 case space_constant::tensor: n_gmsh_comp = 9; break;
58 default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
59 }
60 if (uh.get_space().degree() == uh.get_geo().order() && uh.get_space().get_basis().is_continuous()) {
61 // ======================================================
62 // Pk-C0 approx and k-th order mesh: use gmsh "NodeData"
63 // ======================================================
64 gmsh << "$NodeData" << endl
65 << "1" << endl
66 << "\"" << name << "\"" << endl
67 << "1" << endl
68 << "0.0" << endl
69 << "3" << endl
70 << "0" << endl
71 << n_gmsh_comp << endl
72 << uh.get_geo().n_node() << endl;
73 switch (uh.get_space().valued_tag()) {
74 // ---------------------------
76 // ---------------------------
77 for (size_type idof = 0, ndof = uh.ndof(); idof < ndof; idof++) {
78 gmsh << idof+1 << " " << uh.dof(idof) << endl;
79 }
80 break;
81 }
82 // ---------------------------
84 // ---------------------------
85 // without memory allocation: use field_rdof_sliced_const proxy directly:
86 size_type n_comp = uh.size();
87#ifdef TO_CLEAN
88 std::vector<details::field_rdof_sliced_const<field_basic<T,sequential>>> uh_comp (n_comp);
89 for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
90 uh_comp[i_comp].proxy_assign (uh[i_comp]);
91 }
92#endif // TO_CLEAN
93 std::vector<T> u_dof (n_comp);
94 for (size_type idof = 0, ndof = uh[0].ndof(); idof < ndof; idof++) {
95 gmsh << idof+1;
96 for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
97 gmsh << " " << uh[i_comp].dof (idof);
98 }
99 for (size_type i_comp = n_comp; i_comp < 3; i_comp++) {
100 gmsh << " 0";
101 }
102 gmsh << endl;
103 }
104 break;
105 }
106 // ---------------------------
108 // ---------------------------
109 size_type d = uh.get_geo().dimension();
110 switch (d) {
111 case 1: {
112 field_basic<T,sequential> t00 = uh(0,0);
113 for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
114 gmsh << t00.dof(idof) << " 0 0 "
115 << "0 0 0 "
116 << "0 0 0" << endl;
117 }
118 break;
119 }
120 case 2: {
121 field_basic<T,sequential> t00 = uh(0,0);
122 field_basic<T,sequential> t01 = uh(0,1);
123 field_basic<T,sequential> t11 = uh(1,1);
124 for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
125 gmsh << t00.dof(idof) << " " << t01.dof(idof) << " 0 "
126 << t01.dof(idof) << " " << t11.dof(idof) << " 0 "
127 << "0 0 0" << endl;
128 }
129 break;
130 }
131 case 3: {
132 field_basic<T,sequential> t00 = uh(0,0);
133 field_basic<T,sequential> t01 = uh(0,1);
134 field_basic<T,sequential> t11 = uh(1,1);
135 field_basic<T,sequential> t02 = uh(0,2);
136 field_basic<T,sequential> t12 = uh(1,2);
137 field_basic<T,sequential> t22 = uh(2,2);
138 for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
139 gmsh << t00.dof(idof) << " " << t01.dof(idof) << " " << t02.dof(idof) << " "
140 << t01.dof(idof) << " " << t11.dof(idof) << " " << t12.dof(idof) << " "
141 << t02.dof(idof) << " " << t12.dof(idof) << " " << t22.dof(idof) << endl;
142 }
143 }
144 default: break;
145 }
146 break;
147 }
148 default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
149 }
150 gmsh << "$EndNodeData" << endl;
151 } else if (uh.get_space().degree() == 0) {
152 // ======================================
153 // P0 approx: use gmsh "ElementData"
154 // ======================================
155 gmsh << "$ElementData" << endl
156 << "1" << endl
157 << "\"" << name << "\"" << endl
158 << "1" << endl
159 << "0.0" << endl
160 << "3" << endl
161 << "0" << endl
162 << n_gmsh_comp << endl
163 << uh.get_geo().size() << endl;
164 switch (uh.get_space().valued_tag()) {
165 // ---------------------------
167 // ---------------------------
168 for (size_type idof = 0, ndof = uh.ndof(); idof < ndof; idof++) {
169 gmsh << idof+1 << " " << uh.dof(idof) << endl;
170 }
171 break;
172 }
173 default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
174 }
175 gmsh << "$EndElementData" << endl;
176 } else {
177 // TODO: check non-Lagrange, e.g. RTk ?
178 // ======================================
179 // Pkd approx: use gmsh "ElementNodeData"
180 // ======================================
181 gmsh << "$ElementNodeData" << endl
182 << "1" << endl
183 << "\"" << name << "\"" << endl
184 << "1" << endl
185 << "0.0" << endl
186 << "3" << endl
187 << "0" << endl
188 << n_gmsh_comp << endl
189 << uh.get_geo().size() << endl;
190 const geo_basic<T,sequential>& omega = uh.get_geo();
191 const space_basic<T,sequential>& Vh = uh.get_space();
192 switch (uh.get_space().valued_tag()) {
193 // ---------------------------
195 // ---------------------------
196 std::vector<size_type> idof;
197 for (size_type ie = 0, ne = omega.size(); ie < ne; ie++) {
198 const geo_element& K = omega[ie];
199 Vh.dis_idof (K, idof);
200 gmsh << ie+1 << " " << idof.size();
201 for (size_type loc_idof = 0; loc_idof < idof.size(); loc_idof++) {
202 gmsh << " " << uh.dof(idof[loc_idof]);
203 }
204 gmsh << endl;
205 }
206 break;
207 }
208 default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
209 }
210 gmsh << "$EndElementNodeData" << endl;
211 }
212 return ods;
213}
214template <class T>
215odiststream&
217{
218 return field_put_gmsh (ods, uh, "");
219}
220// ----------------------------------------------------------------------------
221// instanciation in library
222// ----------------------------------------------------------------------------
225
226}// namespace rheolef
field::size_type size_type
Definition branch.cc:430
size_type size() const
Definition field.h:441
T & dof(size_type idof)
Definition field.h:738
const geo_type & get_geo() const
Definition field.h:271
const space_type & get_space() const
Definition field.h:270
size_type ndof() const
Definition field.h:298
const std::string & valued() const
Definition field.h:274
std::size_t size_type
Definition field.h:225
generic mesh with rerefence counting
Definition geo.h:1089
see the geo_element page for the full documentation
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
std::ostream & os()
Definition diststream.h:247
the finite element space
Definition space.h:382
#define error_macro(message)
Definition dis_macros.h:49
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin color format format format format format format gmsh
This file is part of Rheolef.
template odiststream & field_put_gmsh< Float >(odiststream &, const field_basic< Float, sequential > &, std::string)
odiststream & field_put_gmsh(odiststream &, const field_basic< T, sequential > &, std::string)
odiststream & geo_put_gmsh(odiststream &ods, const geo_basic< T, sequential > &)
STL namespace.