42 #include <geogram/basic/progress.h> 61 template < index_t DIMENSION >
65 for(
const auto& line : geomodel.
lines() )
67 result += line.nb_mesh_elements();
72 template < index_t DIMENSION >
76 for(
const auto& surface : geomodel.
surfaces() )
78 result += surface.nb_mesh_elements();
83 template < index_t DIMENSION >
87 index_t count_geomodel_cells(
const GeoModel2D& geomodel )
94 index_t count_geomodel_cells(
const GeoModel3D& geomodel )
96 index_t nb_cells{ 0 };
97 for(
const auto& region : geomodel.regions() )
99 nb_cells += region.nb_mesh_elements();
104 template < index_t DIMENSION >
105 std::tuple< double, double, double, double, double >
106 compute_region_volumes_per_cell_type(
109 double tet_volume{ 0 };
110 double pyramid_volume{ 0 };
111 double prism_volume{ 0 };
112 double hex_volume{ 0 };
113 double poly_volume{ 0 };
117 double volume{ region.
mesh().cell_volume( c ) };
118 switch( nb_vertices )
121 tet_volume += volume;
124 pyramid_volume += volume;
127 prism_volume += volume;
130 hex_volume += volume;
133 poly_volume += volume;
137 return std::make_tuple(
138 tet_volume, pyramid_volume, prism_volume, hex_volume, poly_volume );
141 template < index_t DIMENSION >
142 std::tuple< double, double, double, double, double, double >
143 compute_geomodel_volumes_per_cell_type(
146 double tet_volume{ 0 };
147 double pyramid_volume{ 0 };
148 double prism_volume{ 0 };
150 double hex_volume{ 0 };
151 double poly_volume{ 0 };
153 for(
const auto& region : geomodel.regions() )
155 std::tie( tet_volume, pyramid_volume, prism_volume, hex_volume,
156 poly_volume ) = compute_region_volumes_per_cell_type( region );
158 double total{ tet_volume + pyramid_volume + prism_volume + hex_volume
160 return std::make_tuple( total, tet_volume, pyramid_volume, prism_volume,
161 hex_volume, poly_volume );
164 void print_one_cell_stat(
const index_t& nb_cell,
165 const index_t& nb_cell_total,
166 const std::string& cell_type )
168 Logger::out(
"GeoModel",
"* ", nb_cell,
" ", cell_type,
" (",
169 nb_cell * 100 / nb_cell_total,
"%)" );
172 void print_one_cell_volume_stat(
const double& cell_volume,
173 const double& cell_volume_total,
174 const std::string& cell_type )
176 Logger::out(
"GeoModel",
"* ", cell_type,
" volume ", cell_volume,
" (",
177 static_cast< index_t >(
178 cell_volume * 100 / cell_volume_total + 0.5 ),
181 template < index_t DIMENSION >
185 std::setw( 10 ), std::left, geomodel.
mesh.vertices.nb(),
186 " vertices\n", std::setw( 10 ), std::left,
187 count_geomodel_edges( geomodel ),
" edges" );
189 index_t nb_triangles{ geomodel.
mesh.polygons.nb_triangle() };
190 index_t nb_quads{ geomodel.
mesh.polygons.nb_quad() };
191 index_t nb_unclassified_polygons{
192 geomodel.
mesh.polygons.nb_unclassified_polygon()
194 index_t nb_polygons{ geomodel.
mesh.polygons.nb_polygons() };
196 "GeoModel", std::setw( 10 ), std::left, nb_polygons,
" polygons" );
197 if( nb_triangles > 0 )
199 print_one_cell_stat( nb_triangles, nb_polygons,
"triangles" );
203 print_one_cell_stat( nb_quads, nb_polygons,
"quads" );
205 if( nb_unclassified_polygons > 0 )
207 print_one_cell_stat( nb_unclassified_polygons, nb_polygons,
208 "unclassified polygons" );
215 template < index_t DIMENSION >
219 Logger::out(
"GeoModel", std::setw( 10 ), std::left,
223 template < index_t DIMENSION >
231 Logger::out(
"GeoModel", std::setw( 10 ), std::left,
235 template < index_t DIMENSION >
239 std::setw( 10 ), std::left, geomodel.
mesh.vertices.nb(),
240 " vertices\n", std::setw( 10 ), std::left,
241 count_geomodel_edges( geomodel ),
" edges\n", std::setw( 10 ),
242 std::left, count_geomodel_polygons( geomodel ),
" polygons" );
243 index_t nb_cells{ count_geomodel_cells( geomodel ) };
247 "GeoModel", std::setw( 10 ), std::left, nb_cells,
" cells" );
253 const std::vector< MeshEntityType >& mesh_entity_types =
259 const std::vector< GeologicalEntityType >& geological_entity_types =
270 print_geomodel_base_mesh_stats( geomodel );
276 print_geomodel_base_mesh_stats( geomodel );
278 index_t nb_tet{ geomodel.mesh.cells.nb_tet() };
279 index_t nb_pyramids{ geomodel.mesh.cells.nb_pyramid() };
280 index_t nb_prisms{ geomodel.mesh.cells.nb_prism() };
281 index_t nb_hex{ geomodel.mesh.cells.nb_hex() };
282 index_t nb_poly{ geomodel.mesh.cells.nb_connector() };
283 index_t nb_cells{ geomodel.mesh.cells.nb_cells() };
285 "GeoModel", std::setw( 10 ), std::left, nb_cells,
" cells" );
288 print_one_cell_stat( nb_tet, nb_cells,
"tet" );
290 if( nb_pyramids > 0 )
292 print_one_cell_stat( nb_pyramids, nb_cells,
"pyramids" );
296 print_one_cell_stat( nb_prisms, nb_cells,
"prisms" );
300 print_one_cell_stat( nb_hex, nb_cells,
"hex" );
304 print_one_cell_stat( nb_poly, nb_cells,
"polyhedra" );
312 double tet_volume{ 0 };
313 double pyramid_volume{ 0 };
314 double prism_volume{ 0 };
315 double hex_volume{ 0 };
316 double poly_volume{ 0 };
317 std::tie( volume, tet_volume, pyramid_volume, prism_volume, hex_volume,
318 poly_volume ) = compute_geomodel_volumes_per_cell_type( geomodel );
319 Logger::out(
"GeoModel",
"Model ", geomodel.name(),
" has a volume of ",
323 print_one_cell_volume_stat( tet_volume, volume,
"tet" );
325 if( pyramid_volume > 0 )
327 print_one_cell_volume_stat( pyramid_volume, volume,
"pyramid" );
329 if( prism_volume > 0 )
331 print_one_cell_volume_stat( prism_volume, volume,
"prism" );
335 print_one_cell_volume_stat( hex_volume, volume,
"hex" );
337 if( poly_volume > 0 )
339 print_one_cell_volume_stat( poly_volume, volume,
"polyhedron" );
344 template < index_t DIMENSION >
348 const std::string& name )
350 index_t mesh_entity_id{ NO_ID };
355 if( cur_gme.
name() == name )
357 if( mesh_entity_id != NO_ID )
360 " At least two GeoModelMeshEntity have the same name " 364 mesh_entity_id = cur_gme.
index();
367 if( mesh_entity_id == NO_ID )
370 "GeoModel", name,
" does not match with any actual " 371 "GeoModelEntity name in the GeoModel" );
373 return mesh_entity_id;
376 template < index_t DIMENSION >
380 const std::string& name )
382 index_t geological_entity_id{ NO_ID };
385 if( cur_gme.name() == name )
387 if( geological_entity_id != NO_ID )
390 "At least two GeoModelGeologicalEntity have the same " 391 "name in the GeoModel : ",
394 geological_entity_id = cur_gme.index();
397 if( geological_entity_id == NO_ID )
400 "GeoModel", name,
" does not match with any actual " 401 "GeoModelEntity name in the GeoModel" );
403 return geological_entity_id;
408 template < index_t DIMENSION >
412 for(
auto v :
range( geomodel.
mesh.vertices.nb() ) )
417 geomodel.
mesh.vertices.update_point( v, p + translation_vector );
427 if( length( axis ) < geomodel.epsilon() )
430 "Rotation around an epsilon length axis is impossible" );
434 origin, axis, theta, degrees ) };
436 for(
auto v :
range( geomodel.mesh.vertices.nb() ) )
438 const vec3& p = geomodel.mesh.vertices.vertex( v );
439 std::array< double, 4 > old{ { p[0], p[1], p[2], 1. } };
440 std::array< double, 4 > new_p{ { 0, 0, 0, 1. } };
441 GEO::mult( rot_mat, old.data(), new_p.data() );
444 geomodel.mesh.vertices.update_point( v,
vec3{ new_p.data() } );
448 #ifdef RINGMESH_WITH_TETGEN 450 void tetrahedralize( GeoModel3D& geomodel,
451 const std::string& method,
453 bool add_steiner_points )
459 std::vector< std::vector< vec3 > > internal_vertices(
460 geomodel.nb_regions() );
461 tetrahedralize( geomodel, method, region_id, add_steiner_points,
465 void tetrahedralize( GeoModel3D& geomodel,
466 const std::string& method,
468 bool add_steiner_points,
469 const std::vector< std::vector< vec3 > >& internal_vertices )
471 if( region_id == NO_ID )
474 GEO::ProgressTask progress(
"Compute", geomodel.nb_regions() );
475 for(
auto i :
range( geomodel.nb_regions() ) )
477 tetrahedralize( geomodel, method, i, add_steiner_points,
485 geomodel, region_id, method ) };
486 tetragen->set_boundaries(
487 geomodel.region( region_id ), geomodel.wells() );
488 tetragen->set_internal_points( internal_vertices[region_id] );
491 tetragen->tetrahedralize( add_steiner_points );
497 geomodel.mesh.vertices.clear();
505 const RINGMesh::GeoModel2D&,
507 const std::string& );
508 template void RINGMESH_API
translate( GeoModel2D&,
const vec2& );
514 const RINGMesh::GeoModel3D&,
516 const std::string& );
517 template void RINGMESH_API
translate( GeoModel3D&,
const vec3& );
const VolumeMesh< DIMENSION > & mesh() const
Get the low level mesh data structure.
GeoModelMesh< DIMENSION > mesh
void print_nb_geological_entities(const GeoModel< DIMENSION > &geomodel, const GeologicalEntityType &type)
Abstract base class for GeoModelMeshEntity.
GEO::vecng< DIMENSION, double > vecn
index_t find_mesh_entity_id_from_name(const GeoModel< DIMENSION > &geomodel, const MeshEntityType &gmme_type, const std::string &name)
GeologicalTypeManager geological_entity_manager
const EntityTypeManager< DIMENSION > & entity_type_manager() const
Gets the EntityTypeManager associated to the GeoModel.
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
virtual const GeoModelMeshEntity< DIMENSION > & mesh_entity(const gmme_id &id) const
Generic access to a meshed entity.
void RINGMESH_API print_geomodel_mesh_cell_volumes(const GeoModel3D &geomodel)
void ringmesh_unused(const T &)
void RINGMESH_API rotate(GeoModel3D &geomodel, const vec3 &origin, const vec3 &axis, double angle, bool degrees=false)
Rotate the boundary geomodel.
void translate(GeoModel< DIMENSION > &geomodel, const vecn< DIMENSION > &translation_vector)
Translates the boundary geomodel by a vector.
void print_nb_mesh_entities(const GeoModel< DIMENSION > &geomodel, const MeshEntityType &type)
void print_geomodel(const GeoModel< DIMENSION > &geomodel)
Print in the console the geomodel statistics.
MeshEntityTypeManager< DIMENSION > mesh_entity_manager
const std::string & name() const
Gets the name of the GeoModel.
static std::unique_ptr< TetraGen > create(GeoModel3D &M, index_t region_id, const std::string &algo_name)
geol_entity_range< DIMENSION > geol_entities(const GeologicalEntityType &geol_type) const
GEO::Matrix< 4, double > RINGMESH_API rotation_matrix_about_arbitrary_axis(const vec3 &origin, const vec3 &axis, double theta, bool degrees)
Builds a rotational matrix about an arbitrary axis.
index_t nb_mesh_elements() const final
index_t nb_mesh_element_vertices(index_t cell_index) const final
static void err(const std::string &feature, const Args &... args)
index_t find_geological_entity_id_from_name(const RINGMesh::GeoModel< DIMENSION > &geomodel, const RINGMesh::GeologicalEntityType &gmge_type, const std::string &name)
const std::vector< GeologicalEntityType > & geological_entity_types() const
const std::string & name() const
static void out(const std::string &feature, const Args &... args)
static GEO::Logger * instance()
Global entity manager which could be associated to a geomodel to give access to different manager to ...
line_range< DIMENSION > lines() const
#define ringmesh_assert(x)
A GeoModelEntity of type REGION.
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Classes to build GeoModel from various inputs.
void print_geomodel_mesh_stats(const GeoModel< DIMENSION > &geomodel)
surface_range< DIMENSION > surfaces() const
virtual index_t nb_mesh_entities(const MeshEntityType &type) const
Returns the number of mesh entities of the given type.
index_t nb_geological_entities(const GeologicalEntityType &type) const
Returns the number of geological entities of the given type.