16 #include <deal.II/gmsh/utilities.h> 17 #include <deal.II/opencascade/utilities.h> 19 #include <deal.II/grid/grid_in.h> 20 #include <deal.II/grid/grid_out.h> 24 #ifdef DEAL_II_WITH_GMSH 26 DEAL_II_NAMESPACE_OPEN
31 const std::string &output_base_name):
32 characteristic_length(characteristic_length),
33 output_base_name(output_base_name)
42 "Keep empty, if you want the program to generate " 43 "temporary files, and then remove them when they " 44 "are no longer used.");
49 #ifdef DEAL_II_WITH_OPENCASCADE 50 template <
int spacedim>
57 char dir_template[] =
"ctfbc-XXXXXX";
60 const char *temp = mkdtemp(dir_template);
62 ExcMessage(
"Creating temporary directory failed!"));
67 const std::string iges_file_name = base_name+
".iges";
68 const std::string geo_file_name = base_name+
".geo";
69 const std::string msh_file_name = base_name+
".msh";
70 const std::string log_file_name = base_name+
".log";
71 const std::string warnings_file_name = base_name+
"_warn.log";
73 ::OpenCASCADE::write_IGES(boundary, iges_file_name);
76 geofile.open(geo_file_name);
77 geofile <<
"Merge \"" << iges_file_name <<
"\";" << std::endl
78 <<
"Line Loop (2) = {1};" << std::endl
79 <<
"Plane Surface (3) = {2};" << std::endl
81 <<
"Mesh.RecombineAll = 1;" << std::endl
82 <<
"Mesh.SubdivisionAlgorithm = 1;" << std::endl;
85 std::stringstream command;
86 command << DEAL_II_GMSH_EXECUTABLE_PATH <<
" -2 " << geo_file_name
87 <<
" 1> " << log_file_name
88 <<
" 2> " << warnings_file_name;
90 const auto ret_value = std::system(command.str().c_str());
92 ExcMessage(
"Gmsh failed to run. Check the "+log_file_name+
" file."));
94 std::ifstream grid_file(msh_file_name);
103 const std::array<const std::string *, 5> filenames
104 {{&iges_file_name, &geo_file_name, &msh_file_name, &log_file_name, &warnings_file_name}};
105 for (
const std::string *filename : filenames)
107 const auto ret_value = std::remove(filename->c_str());
110 const auto ret_value = std::remove(dir_template);
112 ExcMessage(
"Failed to remove "+std::string(dir_template)));
118 #ifdef DEAL_II_WITH_OPENCASCADE 119 #include "utilities.inst" 123 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)
std::string output_base_name
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
void read_msh(std::istream &in)
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation=std::string(), const Patterns::PatternBase &pattern= *Patterns::Tools::Convert< ParameterType >::to_pattern())
void attach_triangulation(Triangulation< dim, spacedim > &tria)
AdditionalParameters(const double characteristic_length=1.0, const std::string &output_base_name="")