Rheolef  7.1
an efficient C++ finite element environment
field_seq_put_gmsh.cc
Go to the documentation of this file.
1 //
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 
36 namespace rheolef {
37 using namespace std;
38 
39 // extern:
40 template <class T>
41 odiststream&
42 geo_put_gmsh (odiststream& ods, const geo_basic<T,sequential>&);
43 
44 template <class T>
45 odiststream&
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_component proxy directly:
86  size_type n_comp = uh.size();
87  std::vector<field_component_const<T,sequential> > uh_comp (n_comp);
88  for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
89  uh_comp[i_comp].proxy_assign (uh[i_comp]);
90  }
91  std::vector<T> u_dof (n_comp);
92  for (size_type idof = 0, ndof = uh_comp[0].ndof(); idof < ndof; idof++) {
93  gmsh << idof+1;
94  for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
95  gmsh << " " << uh_comp[i_comp].dof (idof);
96  }
97  for (size_type i_comp = n_comp; i_comp < 3; i_comp++) {
98  gmsh << " 0";
99  }
100  gmsh << endl;
101  }
102  break;
103  }
104  // ---------------------------
105  case space_constant::tensor: {
106  // ---------------------------
107  size_type d = uh.get_geo().dimension();
108  switch (d) {
109  case 1: {
110  field_basic<T,sequential> t00 = uh(0,0);
111  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
112  gmsh << t00.dof(idof) << " 0 0 "
113  << "0 0 0 "
114  << "0 0 0" << endl;
115  }
116  break;
117  }
118  case 2: {
119  field_basic<T,sequential> t00 = uh(0,0);
120  field_basic<T,sequential> t01 = uh(0,1);
121  field_basic<T,sequential> t11 = uh(1,1);
122  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
123  gmsh << t00.dof(idof) << " " << t01.dof(idof) << " 0 "
124  << t01.dof(idof) << " " << t11.dof(idof) << " 0 "
125  << "0 0 0" << endl;
126  }
127  break;
128  }
129  case 3: {
130  field_basic<T,sequential> t00 = uh(0,0);
131  field_basic<T,sequential> t01 = uh(0,1);
132  field_basic<T,sequential> t11 = uh(1,1);
133  field_basic<T,sequential> t02 = uh(0,2);
134  field_basic<T,sequential> t12 = uh(1,2);
135  field_basic<T,sequential> t22 = uh(2,2);
136  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
137  gmsh << t00.dof(idof) << " " << t01.dof(idof) << " " << t02.dof(idof) << " "
138  << t01.dof(idof) << " " << t11.dof(idof) << " " << t12.dof(idof) << " "
139  << t02.dof(idof) << " " << t12.dof(idof) << " " << t22.dof(idof) << endl;
140  }
141  }
142  default: break;
143  }
144  break;
145  }
146  default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
147  }
148  gmsh << "$EndNodeData" << endl;
149  } else if (uh.get_space().degree() == 0) {
150  // ======================================
151  // P0 approx: use gmsh "ElementData"
152  // ======================================
153  gmsh << "$ElementData" << endl
154  << "1" << endl
155  << "\"" << name << "\"" << endl
156  << "1" << endl
157  << "0.0" << endl
158  << "3" << endl
159  << "0" << endl
160  << n_gmsh_comp << endl
161  << uh.get_geo().size() << endl;
162  switch (uh.get_space().valued_tag()) {
163  // ---------------------------
164  case space_constant::scalar: {
165  // ---------------------------
166  for (size_type idof = 0, ndof = uh.ndof(); idof < ndof; idof++) {
167  gmsh << idof+1 << " " << uh.dof(idof) << endl;
168  }
169  break;
170  }
171  default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
172  }
173  gmsh << "$EndElementData" << endl;
174  } else {
175  // TODO: check non-Lagrange, e.g. RTk ?
176  // ======================================
177  // Pkd approx: use gmsh "ElementNodeData"
178  // ======================================
179  gmsh << "$ElementNodeData" << endl
180  << "1" << endl
181  << "\"" << name << "\"" << endl
182  << "1" << endl
183  << "0.0" << endl
184  << "3" << endl
185  << "0" << endl
186  << n_gmsh_comp << endl
187  << uh.get_geo().size() << endl;
188  const geo_basic<T,sequential>& omega = uh.get_geo();
189  const space_basic<T,sequential>& Vh = uh.get_space();
190  switch (uh.get_space().valued_tag()) {
191  // ---------------------------
192  case space_constant::scalar: {
193  // ---------------------------
194  std::vector<size_type> idof;
195  for (size_type ie = 0, ne = omega.size(); ie < ne; ie++) {
196  const geo_element& K = omega[ie];
197  Vh.dis_idof (K, idof);
198  gmsh << ie+1 << " " << idof.size();
199  for (size_type loc_idof = 0; loc_idof < idof.size(); loc_idof++) {
200  gmsh << " " << uh.dof(idof[loc_idof]);
201  }
202  gmsh << endl;
203  }
204  break;
205  }
206  default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
207  }
208  gmsh << "$EndElementNodeData" << endl;
209  }
210  return ods;
211 }
212 template <class T>
213 odiststream&
215 {
216  return field_put_gmsh (ods, uh, "");
217 }
218 // ----------------------------------------------------------------------------
219 // instanciation in library
220 // ----------------------------------------------------------------------------
223 
224 }// namespace rheolef
field::size_type size_type
Definition: branch.cc:425
const space_type & get_space() const
Definition: field.h:300
const geo_type & get_geo() const
Definition: field.h:301
size_type size() const
Definition: field.h:331
T & dof(size_type idof)
Definition: field.h:658
const std::string & valued() const
Definition: field.h:305
size_type ndof() const
Definition: field.h:341
std::size_t size_type
Definition: field.h:239
size_type size(size_type dim) const
Definition: geo.h:1209
see the geo_element page for the full documentation
Definition: geo_element.h:102
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
std::ostream & os()
Definition: diststream.h:236
void dis_idof(const geo_element &K, std::vector< size_type > &dis_idof) const
Definition: space.h:599
size_t size_type
Definition: basis_get.cc:76
#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
size_type ndof(const basis_basic< T > &b, const geo_size &gs, size_type map_dim)
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 > &)