rheolef  6.5
field_seq_put_gmsh.cc
Go to the documentation of this file.
1 #include "rheolef/field.h"
2 #include "rheolef/field_expr_ops.h"
3 #include "rheolef/piola.h"
4 #include "rheolef/rheostream.h"
5 #include "rheolef/iorheo.h"
6 #include "rheolef/field_evaluate.h"
7 #include "rheolef/space_component.h"
8 namespace rheolef {
9 using namespace std;
10 
11 template <class T>
12 odiststream&
13 geo_put_gmsh (odiststream& ods, const geo_basic<T,sequential>&);
14 
15 template <class T>
16 odiststream&
17 field_put_gmsh (odiststream& ods, const field_basic<T,sequential>& uh, std::string name)
18 {
20  geo_put_gmsh (ods, uh.get_geo());
21  if (name == "") { name = uh.get_space().valued(); }
22  ostream& gmsh = ods.os();
23  gmsh << setprecision(numeric_limits<T>::digits10);
24  size_type n_gmsh_comp = 1;
25  switch (uh.get_space().valued_tag()) {
26  case space_constant::scalar: n_gmsh_comp = 1; break;
27  case space_constant::vector: n_gmsh_comp = 3; break;
28  case space_constant::tensor: n_gmsh_comp = 9; break;
29  default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
30  }
31  if (uh.get_space().degree() != uh.get_geo().order()) {
32  warning_macro ("gmsh: unsupported field degree != geo order");
33  }
34  gmsh << "$NodeData" << endl
35  << "1" << endl
36  << "\"" << name << "\"" << endl
37  << "1" << endl
38  << "0.0" << endl
39  << "3" << endl
40  << "0" << endl
41  << n_gmsh_comp << endl
42  << uh.get_geo().n_node() << endl;
43  switch (uh.get_space().valued_tag()) {
45  for (size_type idof = 0, ndof = uh.ndof(); idof < ndof; idof++) {
46  gmsh << idof+1 << " " << uh.dof(idof) << endl;
47  }
48  break;
49  }
51  size_type n_comp = uh.size();
52  std::vector<field_component_const<T,sequential> > uh_comp (n_comp);
53  for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
54  uh_comp[i_comp] = uh[i_comp];
55  }
56  std::vector<T> u_dof (n_comp);
57  for (size_type idof = 0, ndof = uh_comp[0].ndof(); idof < ndof; idof++) {
58  gmsh << idof+1;
59  for (size_type i_comp = 0; i_comp < n_comp; i_comp++) {
60  gmsh << " " << uh_comp[i_comp].dof (idof);
61  }
62  for (size_type i_comp = n_comp; i_comp < 3; i_comp++) {
63  gmsh << " 0";
64  }
65  gmsh << endl;
66  }
67  break;
68  }
70  size_type d = uh.get_geo().dimension();
71  switch (d) {
72  case 1: {
73  field_basic<T,sequential> t00 = uh(0,0);
74  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
75  gmsh << t00.dof(idof) << " 0 0 "
76  << "0 0 0 "
77  << "0 0 0" << endl;
78  }
79  break;
80  }
81  case 2: {
82  field_basic<T,sequential> t00 = uh(0,0);
83  field_basic<T,sequential> t01 = uh(0,1);
84  field_basic<T,sequential> t11 = uh(1,1);
85  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
86  gmsh << t00.dof(idof) << " " << t01.dof(idof) << " 0 "
87  << t01.dof(idof) << " " << t11.dof(idof) << " 0 "
88  << "0 0 0" << endl;
89  }
90  break;
91  }
92  case 3: {
93  field_basic<T,sequential> t00 = uh(0,0);
94  field_basic<T,sequential> t01 = uh(0,1);
95  field_basic<T,sequential> t11 = uh(1,1);
96  field_basic<T,sequential> t02 = uh(0,2);
97  field_basic<T,sequential> t12 = uh(1,2);
98  field_basic<T,sequential> t22 = uh(2,2);
99  for (size_type idof = 0, ndof = t00.ndof(); idof < ndof; idof++) {
100  gmsh << t00.dof(idof) << " " << t01.dof(idof) << " " << t02.dof(idof) << " "
101  << t01.dof(idof) << " " << t11.dof(idof) << " " << t12.dof(idof) << " "
102  << t02.dof(idof) << " " << t12.dof(idof) << " " << t22.dof(idof) << endl;
103  }
104  }
105  default: break;
106  }
107  break;
108  }
109  default: error_macro ("put_gmsh: do not known how to print " << uh.valued() << "-valued field");
110  }
111  gmsh << "$EndNodeData" << endl;
112  return ods;
113 }
114 template <class T>
115 odiststream&
117 {
118  return field_put_gmsh (ods, uh, "");
119 }
120 template odiststream& field_put_gmsh<Float> (odiststream&, const field_basic<Float,sequential>&, std::string);
121 template odiststream& field_put_gmsh<Float> (odiststream&, const field_basic<Float,sequential>&);
122 
123 }// namespace rheolef
124