Rheolef  7.1
an efficient C++ finite element environment
adapt_gmsh.cc
Go to the documentation of this file.
1 #include "rheolef/adapt.h"
22 #include "rheolef/form.h"
23 #include "rheolef/field_component.h"
24 #include "rheolef/rheostream.h"
25 #include "rheolef/field_expr.h"
26 
27 namespace rheolef {
28 
29 // extern in adapt.cc
30 template<class T, class M>
31 field_basic<T,M>
33  const field_basic<T,M>& uh0,
34  const adapt_option& opts);
35 
36 // -----------------------------------------
37 // adapt
38 // -----------------------------------------
39 template<class T, class M>
40 geo_basic<T,M>
42  const field_basic<T,M>& uh,
43  const adapt_option& opts)
44 {
45  using namespace std;
46  typedef typename geo_basic<T,M>::size_type size_type;
47  bool do_verbose = iorheo::getverbose(clog);
48  bool do_clean = iorheo::getclean(clog);
49  string command, clean_files;
50  // -----------------------------------------
51  // 1a) sortie du maillage : nom-<i>.geo
52  // -----------------------------------------
53  const geo_basic<T,M>& omega = uh.get_geo();
54  size_type i = omega.serial_number();
55  string i_name = omega.name();
56  string geo_name = i_name + ".geo";
58  if (! dis_file_exists(geo_name) &&
59  ! dis_file_exists(geo_name + ".gz")) {
60  out.open (geo_name, io::nogz);
61  out << omega;
62  check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
63  out.close();
64  clean_files += " " + geo_name;
65  }
66  // -----------------------------------------
67  // 2a) sortie du critere : nom-crit-<i>.field
68  // -----------------------------------------
69  string crit_name = i_name + "-crit.field";
70  clean_files += " " + crit_name + ".gz";
71  out.open (crit_name, "field");
72  out << hessian_criterion(uh,opts);
73  check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
74  out.close();
75  // --------------------------------------------
76  // 2b) conversion field : nom-crit-<i>.pos
77  // --------------------------------------------
78  string pos_name = i_name + "-crit.pos";
79  clean_files += " " + pos_name;
80  string bindir = string(_RHEOLEF_RHEOLEF_LIBDIR) + "/rheolef";
81  command = "zcat " + crit_name + ".gz | " + bindir + "/field2gmsh_pos > " + pos_name;
82  if (do_verbose) derr << "! " << command << endl;
83  check_macro (dis_system (command) == 0, "adapt: unix command failed");
84  // ----------------------------------------
85  // 3) run gmsh in adapt mode with bamg:
86  // => nom-<i+1>.msh
87  // ----------------------------------------
88  // TODO: use a "cad" header entry in the .geo file
89  // => get "mshcad_file" from omega.cad_filename();
90  string mshcad_file = omega.familyname() + ".mshcad";
91  check_macro (dis_file_exists(mshcad_file), "adapt: missing \""<<mshcad_file<<"\" file");
92  string options = "-clmin " + ftos(opts.hmin)
93  + " -clmax " + ftos(opts.hmax)
94  + " -clscale " + ftos(opts.hcoef);
95  char buffer [100];
96  sprintf (buffer, "%.3d", int(i+1)); // see geo::name() in geo.cc
97  string i1_name = omega.familyname() + "-" + buffer;
98  size_type d = omega.dimension();
99  string algo = (d <= 2) ? "bamg" : "mmg3d";
100  command = "gmsh " + options
101  + " " + mshcad_file
102  + " -" + itos(d) + " -algo " + algo
103  + " -bgm " + pos_name
104  + " -format msh2 -o " + i1_name + ".msh";
105  if (do_verbose) derr << "! " << command << endl;
106  check_macro (dis_system (command) == 0, "adapt: command failed");
107  // ----------------------------------------
108  // 4) conversion : nom-crit-<i>.msh
109  // ----------------------------------------
110  command = "msh2geo -" + omega.coordinate_system_name()
111  + " " + i1_name + ".msh | gzip -9 > " + i1_name + ".geo.gz";
112  if (do_verbose) derr << "! " << command << endl;
113  check_macro (dis_system (command) == 0, "adapt: command failed");
114  clean_files += " " + i1_name + ".msh";
115  // ----------------------------------------
116  // 5) chargement nom-<i+1>.geo
117  // ----------------------------------------
118  idiststream in (i1_name, "geo");
119  geo_basic<T,M> new_omega;
120  in >> new_omega;
121  new_omega.set_name (omega.familyname());
122  new_omega.set_serial_number (i+1);
123  clean_files += " " + i1_name + ".geo";
124  clean_files += " " + i1_name + ".geo.gz";
125  // ----------------------------------------
126  // 6) clean
127  // ----------------------------------------
128  if (do_clean) {
129  command = "rm -f" + clean_files;
130  if (do_verbose) derr << "! " << command << endl;
131  check_macro (dis_system (command) == 0, "adapt: command failed");
132  }
133  return new_omega;
134 }
135 // ----------------------------------------------------------------------------
136 // instanciation in library
137 // ----------------------------------------------------------------------------
138 #define _RHEOLEF_instanciation(T,M) \
139 template geo_basic<T,M> adapt_gmsh (const field_basic<T,M>&, const adapt_option&);
140 
141 _RHEOLEF_instanciation(Float,sequential)
142 #ifdef _RHEOLEF_HAVE_MPI
144 #endif // _RHEOLEF_HAVE_MPI
145 
146 } // namespace rheolef
rheolef::geo_basic
generic mesh with rerefence counting
Definition: domain_indirect.h:64
rheolef::io::out
Definition: rheostream.h:167
rheolef::_RHEOLEF_instanciation
_RHEOLEF_instanciation(Float, sequential, std::allocator< Float >) _RHEOLEF_instanciation(Float
rheolef::adapt_option
adapt_option: see the adapt page for the full documentation
Definition: adapt.h:147
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::adapt_option::hcoef
Float hcoef
Definition: adapt.h:153
rheolef::io::nogz
Definition: rheostream.h:170
_RHEOLEF_RHEOLEF_LIBDIR
#define _RHEOLEF_RHEOLEF_LIBDIR
Definition: config.h:243
rheolef::field_basic::get_geo
const geo_type & get_geo() const
Definition: field.h:301
rheolef::adapt_option::hmin
Float hmin
Definition: adapt.h:154
rheolef::dis_file_exists
bool dis_file_exists(const std::string &filename, const communicator &comm)
Definition: diststream.cc:232
rheolef::field_basic
Definition: field_expr_utilities.h:38
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::dis_system
int dis_system(const std::string &command, const communicator &comm)
Definition: diststream.cc:213
rheolef::derr
odiststream derr(cerr)
see the diststream page for the full documentation
Definition: diststream.h:436
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
Float
see the Float page for the full documentation
mkgeo_ball.d
d
Definition: mkgeo_ball.sh:154
rheolef::ftos
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition: rheostream.cc:55
rheolef-config.bindir
bindir
Definition: rheolef-config.in:129
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
rheolef::distributed
distributed
Definition: asr.cc:228
rheolef::std
Definition: vec_expr_v2.h:391
mkgeo_ball.command
command
Definition: mkgeo_ball.sh:136
rheolef::hessian_criterion
field_basic< T, M > hessian_criterion(const field_basic< T, M > &uh0, const adapt_option &opts)
Definition: adapt.cc:104
rheolef::adapt_gmsh
geo_basic< T, M > adapt_gmsh(const field_basic< T, M > &uh, const adapt_option &opts)
Definition: adapt_gmsh.cc:41
rheolef::adapt_option::hmax
Float hmax
Definition: adapt.h:155