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