23 #ifdef DEAL_II_WITH_OPENCASCADE
24 # include <BRepBndLib.hxx>
25 # include <Bnd_Box.hxx>
26 # include <TopoDS.hxx>
29 #include <boost/algorithm/string/case_conv.hpp>
30 #include <boost/archive/binary_iarchive.hpp>
31 #include <boost/archive/binary_oarchive.hpp>
32 #include <boost/archive/text_iarchive.hpp>
33 #include <boost/archive/text_oarchive.hpp>
39 template <
int dim,
int spacedim>
41 const std::string &prm_section_path,
42 const std::string &grid_generator_function,
43 const std::string &grid_generator_arguments,
44 const std::string &output_file_name,
45 const bool transform_to_simplex_grid,
46 const unsigned int initial_grid_refinement)
48 , grid_generator_function(grid_generator_function)
49 , grid_generator_arguments(grid_generator_arguments)
50 , output_file_name(output_file_name)
51 , transform_to_simplex_grid(transform_to_simplex_grid)
52 , initial_grid_refinement(initial_grid_refinement)
57 add_parameter(
"Transform to simplex grid", this->transform_to_simplex_grid);
58 add_parameter(
"Initial grid refinement", this->initial_grid_refinement);
62 template <
int dim,
int spacedim>
65 dealii::Triangulation<dim, spacedim> &tria)
const
69 boost::algorithm::to_lower_copy(grid_generator_function.substr(
70 grid_generator_function.find_last_of(
'.') + 1));
73 if (ext == boost::algorithm::to_lower_copy(grid_generator_function) ||
76 dealii::GridGenerator::generate_from_name_and_arguments(
77 tria, grid_generator_function, grid_generator_arguments);
87 gi.
read_msh(grid_generator_function);
90 gi.
read(grid_generator_function);
92 catch (std::exception &exc)
94 std::cerr << std::endl
96 <<
"----------------------------------------------------"
98 std::cerr <<
"Exception on processing: " << std::endl
99 << exc.what() << std::endl
100 <<
"Trying other strategies." << std::endl
101 <<
"----------------------------------------------------"
104 std::ifstream in(grid_generator_function);
108 boost::archive::text_iarchive ia(in);
111 else if (ext ==
"bin")
113 boost::archive::binary_iarchive ia(in);
124 #ifdef DEAL_II_WITH_OPENCASCADE
127 using map_type = std::map<types::manifold_id, std::string>;
129 for (
const auto &[manifold_id, cad_file_name] :
130 Converter::to_value(grid_generator_arguments))
132 const auto extension = boost::algorithm::to_lower_copy(
133 cad_file_name.substr(cad_file_name.find_last_of(
'.') + 1));
135 if (extension ==
"iges" || extension ==
"igs")
137 else if (extension ==
"step" || extension ==
"stp")
139 else if (extension ==
"stl")
144 "do not recognize as a CAD file "
145 "extension. Bailing out."));
146 if constexpr (spacedim > 1)
148 const auto [n_faces, n_edges, n_vertices] =
150 deallog <<
"Manifold id: " << manifold_id << std::endl
151 <<
", attached to CAD File " << cad_file_name
154 deallog <<
"Number of faces: " << n_faces << std::endl
155 <<
"Number of edges: " << n_edges << std::endl
156 <<
"Number of vertices: " << n_vertices << std::endl;
159 double Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
163 BRepBndLib::Add(shape, box);
164 box.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
165 deallog <<
"Lower left corner: " << Xmin <<
", " << Ymin <<
", "
167 <<
"Upper right corner: " << Xmax <<
", " << Ymax
168 <<
", " << Zmax << std::endl;
171 if (n_faces == 0 && n_edges > 0)
176 else if constexpr (spacedim == 3)
188 TopoDS::Face(shape)));
194 "OPENCASCADE to do this."));
199 if (transform_to_simplex_grid ==
true &&
200 tria.all_reference_cells_are_hyper_cube() ==
true)
205 dealii::GridGenerator::convert_hypercube_to_simplex_mesh(tmp, tria);
216 tria.refine_global(initial_grid_refinement);
221 template <
int dim,
int spacedim>
224 const dealii::Triangulation<dim, spacedim> &tria,
225 const std::string &filename)
const
227 const std::string outname = filename !=
"" ? filename : output_file_name;
230 const auto ext = boost::algorithm::to_lower_copy(
231 outname.substr(outname.find_last_of(
'.') + 1));
238 std::ofstream out(outname);
247 else if (ext ==
"vtu")
249 else if (ext ==
"ucd" || ext ==
"inp")
251 else if (ext ==
"vtu")
253 else if (ext ==
"ar")
255 boost::archive::text_oarchive oa(out);
258 else if (ext ==
"bin")
260 boost::archive::binary_oarchive oa(out);
void read_assimp(const std::string &filename, const unsigned int mesh_index=numbers::invalid_unsigned_int, const bool remove_duplicates=true, const double tol=1e-12, const bool ignore_unsupported_element_types=true)
void read_msh(std::istream &in)
void read(std::istream &in, Format format=Default)
void set_flags(const GridOutFlags::DX &flags)
void write_vtk(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void write_msh(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void write_vtu(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void write_ucd(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
void push(const std::string &text)
void add_parameter(const std::string &entry, ParameterType ¶meter, const std::string &documentation="", ParameterHandler &prm_=prm, const Patterns::PatternBase &pattern=*Patterns::Tools::Convert< ParameterType >::to_pattern())
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertThrow(cond, exc)
const Manifold< dim, spacedim > & get_manifold(const types::manifold_id number) const
virtual std::vector< types::manifold_id > get_manifold_ids() const
std::tuple< unsigned int, unsigned int, unsigned int > count_elements(const TopoDS_Shape &shape)
TopoDS_Shape read_STEP(const std::string &filename, const double scale_factor=1e-3)
TopoDS_Shape read_STL(const std::string &filename)
TopoDS_Shape read_IGES(const std::string &filename, const double scale_factor=1e-3)
const types::manifold_id flat_manifold_id