38 static const index_t reg_phys = 0;
40 static const index_t adeli_point_type = 15;
41 static const index_t adeli_line_type = 1;
42 static const index_t adeli_triangle_type = 2;
43 static const index_t adeli_tet_type = 4;
44 static const index_t adeli_cell_types[4] =
45 { adeli_point_type, adeli_line_type, adeli_triangle_type, adeli_tet_type };
48 static const index_t id_offset_adeli = 1;
61 class AdeliIOHandler final:
public GeoModelIOHandler< 3 > {
63 void load(
const std::string& filename, GeoModel3D& geomodel )
final 67 throw RINGMeshException(
"I/O",
68 "Loading of a GeoModel from Adeli .msh mesh not implemented yet" );
70 void save(
const GeoModel3D& geomodel,
const std::string& filename )
final 72 std::ofstream out( filename.c_str() );
74 const RINGMesh::GeoModelMesh3D& geomodel_mesh = geomodel.mesh;
75 if( geomodel_mesh.cells.nb() != geomodel_mesh.cells.nb_tet() ) {
77 throw RINGMeshException(
"I/O",
78 "Adeli supports only tet meshes" );
82 write_vertices( geomodel_mesh, out );
84 write_mesh_elements( geomodel, out );
90 const GeoModelMesh3D& geomodel_mesh,
91 std::ofstream& out )
const 94 out << geomodel_mesh.vertices.nb() <<
EOL;
95 for(
auto v : range( geomodel_mesh.vertices.nb() ) ) {
96 out << v + id_offset_adeli <<
" " 97 << geomodel_mesh.vertices.vertex( v ) <<
EOL;
99 out <<
"$ENDNOD" <<
EOL;
102 index_t write_corners(
103 const GeoModel3D& geomodel,
104 std::ofstream& out )
const 106 out <<
"$ELM" <<
EOL;
107 out << nb_total_elements( geomodel ) <<
EOL;
109 for(
const auto& corner : geomodel.corners() ) {
110 out << elt++ <<
" " << adeli_cell_types[0] <<
" " << reg_phys <<
" " 111 << corner.index() + id_offset_adeli <<
" " 112 << corner.nb_vertices() <<
" " 113 << geomodel.mesh.vertices.geomodel_vertex_id( corner.gmme(),
114 0 ) + id_offset_adeli << EOL;
119 void write_mesh_elements(
120 const GeoModel3D& geomodel,
121 std::ofstream& out )
const 123 index_t elt = write_corners( geomodel, out );
124 const MeshEntityTypeManager3D& manager =
125 geomodel.entity_type_manager().mesh_entity_manager;
126 const std::vector< MeshEntityType >& mesh_entity_types =
127 manager.mesh_entity_types();
129 for(
auto geomodel_mesh_entities : range( 1,
130 manager.nb_mesh_entity_types() ) ) {
131 for(
auto entity : range(
132 geomodel.nb_mesh_entities(
133 mesh_entity_types[geomodel_mesh_entities] ) ) ) {
134 write_mesh_elements_for_a_mesh_entity(
135 geomodel.mesh_entity(
136 mesh_entity_types[geomodel_mesh_entities], entity ),
137 adeli_cell_types[geomodel_mesh_entities], elt, out );
140 out <<
"$ENDELM" <<
EOL;
143 index_t nb_total_elements(
const GeoModel3D& geomodel )
const 145 const MeshEntityTypeManager3D& manager =
146 geomodel.entity_type_manager().mesh_entity_manager;
147 const std::vector< MeshEntityType >& mesh_entity_types =
148 manager.mesh_entity_types();
152 index_t nb_mesh_entities = geomodel.nb_corners();
153 for(
auto geomodel_mesh_entities : range( 1,
154 manager.nb_mesh_entity_types() ) ) {
155 for(
auto entity : range(
156 geomodel.nb_mesh_entities(
157 mesh_entity_types[geomodel_mesh_entities] ) ) ) {
159 geomodel.mesh_entity(
160 mesh_entity_types[geomodel_mesh_entities], entity ).nb_mesh_elements();
163 return nb_mesh_entities;
166 void write_mesh_elements_for_a_mesh_entity(
167 const GeoModelMeshEntity3D& geomodel_mesh_entity,
168 index_t cell_descriptor,
170 std::ofstream& out )
const 172 for(
auto elt : range( geomodel_mesh_entity.nb_mesh_elements() ) ) {
173 out << elt_id++ <<
" " << cell_descriptor <<
" " << reg_phys <<
" " 174 << geomodel_mesh_entity.index() + id_offset_adeli <<
" " 175 << geomodel_mesh_entity.nb_mesh_element_vertices( elt ) <<
" ";
177 geomodel_mesh_entity.nb_mesh_element_vertices( elt ) ) ) {
179 << geomodel_mesh_entity.geomodel().mesh.vertices.geomodel_vertex_id(
180 geomodel_mesh_entity.gmme(),
181 ElementLocalVertex( elt, v ) ) + id_offset_adeli <<
" ";
void ringmesh_unused(const T &)