Rheolef  7.1
an efficient C++ finite element environment
field_seq_visu_gmsh.cc
Go to the documentation of this file.
1 //
22 // gmsh visualization
23 //
24 // author: Pierre.Saramito@imag.fr
25 //
26 // date: 12 may 1997 update: 23 oct 2011
27 //
28 #include "rheolef/field_expr.h"
29 #include "rheolef/piola_util.h"
30 #include "rheolef/rheostream.h"
31 #include "rheolef/iorheo.h"
32 #include "rheolef/iofem.h"
33 #include "rheolef/interpolate.h"
34 
35 using namespace std;
36 namespace rheolef {
37 
38 // ----------------------------------------------------------------------------
39 // field puts
40 // ----------------------------------------------------------------------------
41 // extern:
42 template <class T>
43 odiststream&
44 field_put_gmsh (odiststream& ods, const field_basic<T,sequential>& uh, std::string name);
45 
46 template <class T>
47 odiststream&
49 {
50  //
51  // 1) prerequises
52  //
53  using namespace std;
54  typedef typename field_basic<T,sequential>::float_type float_type;
56  ostream& os = ops.os();
57  string valued = uh.get_space().valued();
58  bool is_scalar = (valued == "scalar");
59  bool verbose = iorheo::getverbose(os);
60  bool clean = iorheo::getclean(os);
61  bool execute = iorheo::getexecute(os);
62  string basename = iorheo::getbasename(os);
63  string tmp = get_tmpdir() + "/";
64  if (!clean) tmp = "";
65  bool fill = iorheo::getfill(os); // isocontours or color fill
66  size_type n_isovalue = iorheo::getn_isovalue(os);
67  size_type n_isovalue_negative = iorheo::getn_isovalue_negative(os);
68  const geo_basic<float_type,sequential>& omega = uh.get_geo();
69  size_type subdivide = iorheo::getsubdivide(os);
70  if (subdivide == 0) { // subdivide is unset: use default
71  subdivide = std::max(omega.order(), subdivide);
72  subdivide = std::max(uh.get_space().get_basis().degree (), subdivide);
73  }
74  bool elevation = iorheo::getelevation(os);
75  bool iso = iorheo::getiso(os);
76  T isovalue = iorheo::getisovalue(os);
77  bool color = iorheo::getcolor(os);
78  bool gray = iorheo::getgray(os);
79  bool black_and_white = iorheo::getblack_and_white(os);
80  if (black_and_white) fill = false;
81  string format = iorheo::getimage_format(os);
82  if (format == "tiff") format = "tif";
83  if (format == "jpeg") format = "jpg";
84 #ifdef TODO
85  string mark = iorheo::getmark(os);
86  typedef point_basic<size_type> ilat;
87  bool label = iorheo::getshowlabel(os);
88  bool stereo = iorheo::getstereo(os);
89  bool volume = iorheo::getvolume(os);
90  bool cut = iorheo::getcut(os);
91  bool grid = iorheo::getgrid(os);
92  if (mark != "" && !is_scalar) mark = "|"+mark +"|";
93  bool velocity = iorheo::getvelocity(os);
94  bool deformation = iorheo::getdeformation(os);
95  Float vscale = iorheo::getvectorscale(os);
96  point_basic<float_type> origin = iofem::getorigin(os);
97  point_basic<float_type> normal = iofem::getnormal(os);
98  point_basic<size_type> resolution = iofem::getresolution(os);
99  string outfile_fmt = "";
100 
101  size_type dim = omega.dimension();
102  size_type map_dim = omega.map_dimension();
103  size_type nv = omega.sizes().ownership_by_dimension[0].size();
104  size_type nedg = omega.sizes().ownership_by_dimension[1].size();
105  size_type nfac = omega.sizes().ownership_by_dimension[2].size();
106  size_type nvol = omega.sizes().ownership_by_dimension[3].size();
107  size_type ne = omega.sizes().ownership_by_dimension[map_dim].size();
108 
109  const basis_basic<float_type>& b_fem = uh.get_space().get_basis();
110  basis_on_pointset<float_type> bops (b_fem, omega.get_piola_basis());
111 #endif // TODO
112  //
113  // 2) output data
114  //
115  string filelist;
116  string msh_name = tmp+basename + ".msh";
117  filelist = filelist + " " + msh_name;
118  ofstream msh_os (msh_name.c_str());
119  odiststream msh (msh_os);
120  if (verbose) clog << "! file \"" << msh_name << "\" created.\n";
121  field_put_gmsh (msh, uh, "");
122  msh.close();
123  //
124  // 3) create mshopt file
125  //
126  std::string opt_name = tmp+basename + ".mshopt";
127  filelist = filelist + " " + opt_name;
128  ofstream opt (opt_name.c_str());
129  if (verbose) clog << "! file \"" << opt_name << "\" created.\n";
130  Float z_scale = 0;
131  Float umin = uh.min();
132  Float umax = uh.max();
133  if (elevation) {
134  Float xy_delta = std::max(omega.xmax()[0]-omega.xmin()[0],
135  omega.xmax()[1]-omega.xmin()[1]);
136  Float z_delta = umax-umin;
137  z_scale = (fabs(z_delta)+1 == 1) ? 0 : xy_delta/(umax-umin);
138  }
139  opt << "View.Color.Background2D={255,255,255};" << endl
140  << "General.SmallAxes = 0; // no small xyz axes" << endl
141  << "General.BackgroundGradient = 0; // no color bg grad" << endl
142  << "Mesh.ColorCarousel = 0; // 0: by element type, 1: by elementary entity, 2: by physical entity, 3: by partition" << endl
143  << "gray = 125;" << endl
144  << "Mesh.Color.Triangles = {gray,gray,gray};" << endl
145  << "View.Type=1; // 1: 3D, 2: 2D space, 3: 2D time, 4: 2D" << endl
146  << "View.RaiseZ=" << z_scale << "; // elevation view" << endl
147  ;
148  if (n_isovalue_negative != 0) {
149  n_isovalue = 2*n_isovalue_negative; // since cannot control each value
150  if (!fill) n_isovalue++; // add a last one
151  Float z_delta = std::max(umax, -umin);
152  umax = z_delta;
153  umin = - z_delta;
154  }
155  opt << "View.CustomMin = " << umin << ";" << endl
156  << "View.CustomMax = " << umax << ";" << endl
157  << "View.NbIso = " << n_isovalue << ";" << endl
158  << "View.IntervalsType = " << (fill ? 3 : 1) << "; // 1: iso, 2: continuous, 3=discrete(bandes), 4=nums(?)" << endl
159  << "View.RangeType = 2; // 1: default, 2: custom, 3: per time step" << endl
160  << "View.SaturateValues = 1;" << endl
161  ;
162  if (black_and_white) {
163  opt << "View.ColorTable = { Gray, Black };" << endl
164  << "View.LineWidth=3;" << endl
165  << "View.ShowScale=0;" << endl
166  ;
167  } else if (gray) {
168  opt << "View.ColormapNumber = 9; // grayscale" << endl
169  ;
170  }
171  if (subdivide) {
172  opt << "nsub = " << subdivide << ";" << endl
173  << "View.AdaptVisualizationGrid = 1; // quand degree > 1" << endl
174  << "View.MaxRecursionLevel = nsub; // quand degree > 1" << endl
175  << "View.TargetError = 1e-7;" << endl
176  << "Mesh.NumSubEdges = nsub; // quand order > 1" << endl
177  << endl
178  ;
179  }
180  opt.close();
181  //
182  // 4) create mshsav file
183  //
184  std::string sav_name = tmp+basename + ".mshsav";
185  if (format != "") {
186  filelist = filelist + " " + sav_name;
187  ofstream sav (sav_name.c_str());
188  if (verbose) clog << "! file \"" << sav_name << "\" created.\n";
189  sav << "Print.Height = 768;" << endl
190  << "Print.Width = 1024;" << endl
191  << "Draw;" << endl
192  << "Print \"" << basename << "." << format << "\";" << endl
193  << "Printf(\"! output writen to " << basename << "." << format << "\") > \"/dev/stderr\";" << endl
194  << "Exit; // no true batch mode, will open the GL window...\";" << endl
195  ;
196  sav.close();
197  }
198  //
199  // 4) run gmsh
200  //
201  int status = 0;
202  string command;
203  if (execute) {
204  command = "gmsh -option " + opt_name + " " + msh_name;
205  if (format != "") command = command + " " + sav_name;
206  if (verbose) clog << "! " << command << endl;
207  status = system (command.c_str());
208  }
209  //
210  // 4) clear msh data
211  //
212  if (clean) {
213  command = "/bin/rm -f " + filelist;
214  if (verbose) clog << "! " << command << endl;
215  status = system (command.c_str());
216  }
217  return ops;
218 }
219 // ----------------------------------------------------------------------------
220 // instanciation in library
221 // ----------------------------------------------------------------------------
222 template odiststream& visu_gmsh<Float> (odiststream&, const field_basic<Float,sequential>&);
223 
224 }// namespace rheolef
rheolef::geo_basic
generic mesh with rerefence counting
Definition: domain_indirect.h:64
rheolef::field_basic::get_space
const space_type & get_space() const
Definition: field.h:300
rheolef::point_basic
Definition: point.h:87
rheolef::normal
details::field_expr_v2_nonlinear_terminal_function< details::normal_pseudo_function< Float > > normal()
normal: see the expression page for the full documentation
Definition: field_expr_terminal.h:439
rheolef::get_tmpdir
std::string get_tmpdir()
get_tmpdir: see the rheostream page for the full documentation
Definition: rheostream.cc:50
rheolef::field_basic::float_type
typename float_traits< T >::type float_type
Definition: field.h:245
rheolef::odiststream::os
std::ostream & os()
Definition: diststream.h:236
rheolef::visu_gmsh< Float >
template odiststream & visu_gmsh< Float >(odiststream &, const field_basic< Float, sequential > &)
rheolef::visu_gmsh
odiststream & visu_gmsh(odiststream &, const field_basic< T, sequential > &)
Definition: field_seq_visu_gmsh.cc:48
rheolef::basis_basic
Definition: basis.h:206
rheolef::field_basic::get_geo
const geo_type & get_geo() const
Definition: field.h:301
rheolef::field_basic::min
T min() const
Definition: field.h:683
mkgeo_ball.clean
clean
Definition: mkgeo_ball.sh:335
rheolef::field_basic::max
T max() const
Definition: field.h:699
rheolef::field_basic
Definition: field_expr_utilities.h:38
mkgeo_couette.basename
basename
Definition: mkgeo_couette.sh:73
gray
verbose clean transpose logscale grid shrink ball stereo iso volume skipvtk deformation fastfieldload lattice reader_on_stdin gray
Definition: iorheo-members.h:62
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
Float
see the Float page for the full documentation
rheolef::basis_on_pointset
Definition: basis_on_pointset.h:191
mkgeo_ball.verbose
verbose
Definition: mkgeo_ball.sh:133
rheolef::field_put_gmsh
odiststream & field_put_gmsh(odiststream &, const field_basic< T, sequential > &, std::string)
Definition: field_seq_put_gmsh.cc:46
size_type
field::size_type size_type
Definition: branch.cc:425
mkgeo_ball.map_dim
map_dim
Definition: mkgeo_ball.sh:337
mkgeo_ball.tmp
tmp
Definition: mkgeo_ball.sh:380
mkgeo_ball.dim
dim
Definition: mkgeo_ball.sh:307
rheolef::std
Definition: vec_expr_v2.h:391
mkgeo_contraction.status
status
Definition: mkgeo_contraction.sh:290
mkgeo_ball.command
command
Definition: mkgeo_ball.sh:136
mkgeo_contraction.name
name
Definition: mkgeo_contraction.sh:133
T
Expr1::float_type T
Definition: field_expr.h:218