Loading...
Searching...
No Matches
adapt_gmsh.cc
Go to the documentation of this file.
#include "rheolef/adapt.h"
#include "rheolef/form.h"
#include "rheolef/field_wdof_sliced.h"
#include "rheolef/rheostream.h"
#include "rheolef/field_expr.h"
namespace rheolef {
// extern in adapt.cc
template<class T, class M>
field_basic<T,M>
hessian_criterion (
const field_basic<T,M>& uh0,
const adapt_option& opts);
// -----------------------------------------
// adapt
// -----------------------------------------
template<class T, class M>
geo_basic<T,M>
adapt_gmsh (
const field_basic<T,M>& uh,
const adapt_option& opts)
{
trace_macro("adapt_gmsh...");
using namespace std;
typedef typename geo_basic<T,M>::size_type size_type;
bool do_verbose = iorheo::getverbose(clog);
bool do_clean = iorheo::getclean(clog);
string command, clean_files;
// -----------------------------------------
// 1a) sortie du maillage : nom-<i>.geo
// -----------------------------------------
const geo_basic<T,M>& omega = uh.get_geo();
size_type i = omega.serial_number();
string i_name = omega.name();
string geo_name = i_name + ".geo";
odiststream out;
if (! dis_file_exists(geo_name) &&
! dis_file_exists(geo_name + ".gz")) {
out.open (geo_name, io::nogz);
out << omega;
check_macro (out.good(), "adapt: file \"" << geo_name << "\"creation failed");
out.close();
clean_files += " " + geo_name;
}
// -----------------------------------------
// 2a) sortie du critere : nom-crit-<i>.field
// -----------------------------------------
string crit_name = i_name + "-crit.field";
clean_files += " " + crit_name + ".gz";
out.open (crit_name, "field");
out << hessian_criterion(uh,opts);
check_macro (out.good(), "adapt: file \"" << crit_name << "\"creation failed");
out.close();
// --------------------------------------------
// 2b) conversion field : nom-crit-<i>.pos
// --------------------------------------------
string pos_name = i_name + "-crit.pos";
clean_files += " " + pos_name;
string bindir = string(_RHEOLEF_RHEOLEF_LIBDIR) + "/rheolef";
command = "zcat " + crit_name + ".gz | " + bindir + "/field2gmsh_pos > " + pos_name;
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "adapt: unix command failed");
// ----------------------------------------
// 3) run gmsh in adapt mode with bamg:
// => nom-<i+1>.msh
// ----------------------------------------
// TODO: use a "cad" header entry in the .geo file
// => get "mshcad_file" from omega.cad_filename();
string mshcad_file = omega.familyname() + ".mshcad";
check_macro (dis_file_exists(mshcad_file), "adapt: missing \""<<mshcad_file<<"\" file");
string options = "-clmin " + ftos(opts.hmin)
+ " -clmax " + ftos(opts.hmax)
+ " -clscale " + ftos(opts.hcoef);
char buffer [100];
sprintf (buffer, "%.3d", int(i+1)); // see geo::name() in geo.cc
string i1_name = omega.familyname() + "-" + buffer;
size_type d = omega.dimension();
string algo = (d <= 1) ? "meshadapt" : (d == 2) ? "bamg" : "mmg3d";
command = "gmsh " + options
+ " " + mshcad_file
+ " -" + std::to_string(d) + " -algo " + algo
+ " -bgm " + pos_name
+ " -format msh2 -o " + i1_name + ".msh";
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "adapt: command failed");
// ----------------------------------------
// 4) conversion : nom-crit-<i>.msh
// ----------------------------------------
command = "msh2geo -" + omega.coordinate_system_name()
+ " " + i1_name + ".msh | gzip -9 > " + i1_name + ".geo.gz";
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "adapt: command failed");
clean_files += " " + i1_name + ".msh";
// ----------------------------------------
// 5) chargement nom-<i+1>.geo
// ----------------------------------------
idiststream in (i1_name, "geo");
geo_basic<T,M> new_omega;
in >> new_omega;
new_omega.set_name (omega.familyname());
new_omega.set_serial_number (i+1);
clean_files += " " + i1_name + ".geo";
clean_files += " " + i1_name + ".geo.gz";
// ----------------------------------------
// 6) clean
// ----------------------------------------
if (do_clean) {
command = "rm -f" + clean_files;
if (do_verbose) derr << "! " << command << endl;
check_macro (dis_system (command) == 0, "adapt: command failed");
}
trace_macro("adapt_gmsh done");
return new_omega;
}
// ----------------------------------------------------------------------------
// instanciation in library
// ----------------------------------------------------------------------------
#define _RHEOLEF_instanciation(T,M) \
template geo_basic<T,M> adapt_gmsh (const field_basic<T,M>&, const adapt_option&);
_RHEOLEF_instanciation(Float,sequential)
#ifdef _RHEOLEF_HAVE_MPI
_RHEOLEF_instanciation(Float,distributed)
#endif // _RHEOLEF_HAVE_MPI
} // namespace rheolef
_RHEOLEF_instanciation
#define _RHEOLEF_instanciation(T, M, A)
Definition asr.cc:223
size_type
field::size_type size_type
Definition branch.cc:430
Float
see the Float page for the full documentation
rheolef::field_basic
Definition field.h:219
rheolef::field_basic::get_geo
const geo_type & get_geo() const
Definition field.h:271
rheolef::geo_basic
generic mesh with rerefence counting
Definition geo.h:1089
rheolef::idiststream
idiststream: see the diststream page for the full documentation
Definition diststream.h:336
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
_RHEOLEF_RHEOLEF_LIBDIR
#define _RHEOLEF_RHEOLEF_LIBDIR
Definition config.h:237
trace_macro
#define trace_macro(message)
Definition dis_macros.h:111
check_macro
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
rheolef::io::nogz
@ nogz
Definition rheostream.h:175
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
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::dis_system
int dis_system(const std::string &command, const communicator &comm)
Definition diststream.cc:214
rheolef::dis_file_exists
bool dis_file_exists(const std::string &filename, const communicator &comm)
Definition diststream.cc:233
rheolef::ftos
string ftos(const Float &x)
itof: see the rheostream page for the full documentation
Definition rheostream.cc:59
std
STL namespace.
d
size_t d
Definition neumann-laplace-lambda.cc:28
rheolef::adapt_option
adapt_option: see the adapt page for the full documentation
Definition adapt.h:147
rheolef::adapt_option::hmax
Float hmax
Definition adapt.h:155
rheolef::adapt_option::hcoef
Float hcoef
Definition adapt.h:153
rheolef::adapt_option::hmin
Float hmin
Definition adapt.h:154