rheolef  6.5
adapt_gmsh.cc
Go to the documentation of this file.
1 #include "rheolef/adapt.h"
2 #include "rheolef/form.h"
3 #include "rheolef/field_component.h"
4 #include "rheolef/field_expr_ops.h"
5 #include "rheolef/rheostream.h"
6 
7 namespace rheolef {
8 
9 template<class T, class M>
10 field_basic<T,M>
12  const field_basic<T,M>& uh0,
13  const adapt_option_type& opts);
14 
15 template<class T, class M>
16 geo_basic<T,M>
18  const field_basic<T,M>& uh,
19  const adapt_option_type& opts)
20 {
21  using namespace std;
22  typedef typename geo_basic<T,M>::size_type size_type;
23  bool do_verbose = iorheo::getverbose(clog);
24  bool do_clean = iorheo::getclean(clog);
25  string command;
26  // 1a) sortie du maillage : nom-<i>.geo
27  const geo_basic<T,M>& omega = uh.get_geo();
28  size_type i = omega.serial_number();
29  string i_name = omega.name();
30  string geo_name = i_name + ".geo";
31  odiststream out;
32  if (! dis_file_exists(geo_name) &&
33  ! dis_file_exists(geo_name + ".gz")) {
34  out.open (geo_name);
35  out << omega;
36  check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
37  out.close();
38  }
39 #ifdef TO_CLEAN
40  // 1b) conversion geo : nom-<i>.msh
41  command = "geo -noverbose -gmsh " + geo_name + " > " + i_name + ".msh";
42  if (do_verbose) clog << "! " << command << endl;
43  check_macro (dis_system (command) == 0, "adapt: unix command failed");
44 #endif // TO_CLEAN
45  // 2a) sortie du critere : nom-crit-<i>.field
46  string crit_name = i_name + "-crit.field";
47  out.open (crit_name, "field");
48  out << hessian_criterion(uh,opts);
49  check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
50  out.close();
51  // 2b) conversion field : nom-crit-<i>.pos
52  string pos_name = i_name + "-crit.pos";
53  command = "field -noverbose -gmsh-pos " + crit_name + " > " + pos_name;
54  if (do_verbose) clog << "! " << command << endl;
55  check_macro (dis_system (command) == 0, "adapt: unix command failed");
56  // => nom-<i+1>.msh
57  string mshcad_file = omega.familyname() + ".mshcad";
58  check_macro (dis_file_exists(mshcad_file), "adapt: missing \""<<mshcad_file<<"\" file");
59  string options = "-clmin " + ftos(opts.hmin)
60  + " -clmax " + ftos(opts.hmax)
61  + " -clscale " + ftos(opts.hcoef);
62  string i1_name = omega.familyname() + "-" + itos(i+1);
63  size_type d = omega.dimension();
64  string algo = (d <= 2) ? "bamg" : "mmg3d";
65  command = "gmsh " + options
66  + " " + mshcad_file
67  + " -" + itos(d) + " -algo " + algo
68  + " -bgm " + pos_name
69  + " -format msh -o " + i1_name + ".msh";
70  if (do_verbose) clog << "! " << command << endl;
71  check_macro (dis_system (command) == 0, "adapt: command failed");
72  // 4) conversion : nom-crit-<i>.msh
73  command = "msh2geo " + i1_name + ".msh | geo -upgrade - -geo | gzip -9 > " + i1_name + ".geo.gz";
74  if (do_verbose) clog << "! " << command << endl;
75  check_macro (dis_system (command) == 0, "adapt: command failed");
76  // 5) chargement nom-<i+1>.geo
77  idiststream in (i1_name, "geo");
78  geo_basic<T,M> new_omega;
79  in >> new_omega;
80  new_omega.set_name (omega.familyname());
81  new_omega.set_serial_number (i+1);
82  return new_omega;
83 }
84 #define _RHEOLEF_instanciation(T,M) \
85 template geo_basic<T,M> adapt_gmsh (const field_basic<T,M>&, const adapt_option_type&);
86 
87 _RHEOLEF_instanciation(Float,sequential)
88 #ifdef _RHEOLEF_HAVE_MPI
90 #endif // _RHEOLEF_HAVE_MPI
91 
92 } // namespace rheolef
93