16 #include <deal.II/gmsh/utilities.h> 18 #include <deal.II/grid/grid_in.h> 19 #include <deal.II/grid/grid_out.h> 21 #include <deal.II/opencascade/utilities.h> 25 #ifdef DEAL_II_WITH_GMSH 27 DEAL_II_NAMESPACE_OPEN
32 const double characteristic_length,
33 const std::string &output_base_name)
34 : characteristic_length(characteristic_length)
35 , output_base_name(output_base_name)
46 "Keep empty, if you want the program to generate " 47 "temporary files, and then remove them when they " 48 "are no longer used.");
53 # ifdef DEAL_II_WITH_OPENCASCADE 54 template <
int spacedim>
61 char dir_template[] =
"ctfbc-XXXXXX";
62 if (base_name.empty())
64 const char *temp = mkdtemp(dir_template);
66 ExcMessage(
"Creating temporary directory failed!"));
71 const std::string iges_file_name = base_name +
".iges";
72 const std::string geo_file_name = base_name +
".geo";
73 const std::string msh_file_name = base_name +
".msh";
74 const std::string log_file_name = base_name +
".log";
75 const std::string warnings_file_name = base_name +
"_warn.log";
77 ::OpenCASCADE::write_IGES(boundary, iges_file_name);
80 geofile.open(geo_file_name);
81 geofile <<
"Merge \"" << iges_file_name <<
"\";" << std::endl
82 <<
"Line Loop (2) = {1};" << std::endl
83 <<
"Plane Surface (3) = {2};" << std::endl
86 <<
"Mesh.RecombineAll = 1;" << std::endl
87 <<
"Mesh.SubdivisionAlgorithm = 1;" << std::endl;
90 std::stringstream command;
91 command << DEAL_II_GMSH_EXECUTABLE_PATH <<
" -2 " << geo_file_name <<
" 1> " 92 << log_file_name <<
" 2> " << warnings_file_name;
94 const auto ret_value = std::system(command.str().c_str());
96 ExcMessage(
"Gmsh failed to run. Check the " + log_file_name +
99 std::ifstream grid_file(msh_file_name);
114 const std::array<const std::string *, 5> filenames{
119 &warnings_file_name}};
120 for (
const std::string *filename : filenames)
122 const auto ret_value = std::remove(filename->c_str());
126 const auto ret_value = std::remove(dir_template);
129 std::string(dir_template)));
135 # ifdef DEAL_II_WITH_OPENCASCADE 136 # include "utilities.inst" 140 DEAL_II_NAMESPACE_CLOSE
void create_triangulation_from_boundary_curve(const TopoDS_Edge &boundary, Triangulation< 2, spacedim > &tria, const AdditionalParameters &prm=AdditionalParameters())
double characteristic_length
static ::ExceptionBase & ExcIO()
void add_parameters(ParameterHandler &prm)
#define AssertThrow(cond, exc)
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
std::string output_base_name
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
void read_msh(std::istream &in)
void attach_triangulation(Triangulation< dim, spacedim > &tria)
AdditionalParameters(const double characteristic_length=1.0, const std::string &output_base_name="")