38 static index_t vertices_in_vertex[1] = { 0 };
40 static index_t vertices_in_edge[2] = { 0, 1 };
42 static index_t vertices_in_triangle[3] = { 0, 1, 2 };
44 static index_t vertices_in_quad[4] = { 0, 1, 2, 3 };
46 static index_t vertices_in_tetrahedron[4] = { 0, 1, 2, 3 };
48 static index_t vertices_in_hexahedron[8] = { 4, 0, 5, 1, 7, 3, 6, 2 };
50 static index_t vertices_in_prism[6] = { 0, 1, 2, 3, 4, 5 };
52 static index_t vertices_in_pyramid[5] = { 0, 1, 2, 3, 4 };
55 index_t gmsh_offset = 1;
68 index_t element_type[12] =
69 { NO_ID, 15, NO_ID, 1, NO_ID, 2, 3, 4, 7, 6, NO_ID, 5 };
73 index_t * vertices_in_elements[12] = {
nullptr, vertices_in_vertex,
nullptr,
74 vertices_in_edge,
nullptr,
75 vertices_in_triangle, vertices_in_quad,
76 vertices_in_tetrahedron,
77 vertices_in_pyramid, vertices_in_prism,
78 nullptr, vertices_in_hexahedron };
81 index_t physical_id = 0;
84 index_t nb_of_tags = 2;
91 class MSHIOHandler final:
public GeoModelIOHandler< 3 > {
93 void load(
const std::string& filename, GeoModel< 3 >& geomodel )
final 97 throw RINGMeshException(
"I/O",
98 "Loading of a GeoModel from GMSH not implemented yet" );
100 void save(
const GeoModel< 3 >& geomodel,
const std::string& filename )
final 102 std::ofstream out( filename.c_str() );
105 out <<
"$MeshFormat" <<
EOL;
106 out <<
"2.2 0 8" <<
EOL;
107 out <<
"$EndMeshFormat" <<
EOL;
109 out <<
"$Nodes" <<
EOL;
110 out << geomodel.mesh.vertices.nb() <<
EOL;
111 for(
auto v : range( geomodel.mesh.vertices.nb() ) ) {
112 out << v + gmsh_offset <<
SPACE << geomodel.mesh.vertices.vertex( v )
115 out <<
"$EndNodes" <<
EOL;
117 out <<
"$Elements" <<
EOL;
118 out << count_elements( geomodel ) <<
EOL;
119 const std::vector< MeshEntityType >& gmme_types =
120 geomodel.entity_type_manager().mesh_entity_manager.mesh_entity_types();
122 index_t element_index = 1;
123 for(
auto gmme_type_index : range(
124 geomodel.entity_type_manager().mesh_entity_manager.nb_mesh_entity_types() ) ) {
125 MeshEntityType cur_mesh_entity_type = gmme_types[gmme_type_index];
126 for(
auto index_of_gmme_of_the_current_type : range(
127 geomodel.nb_mesh_entities( cur_mesh_entity_type ) ) ) {
128 gmme_id cur_gmme_id = gmme_id( cur_mesh_entity_type,
129 index_of_gmme_of_the_current_type );
132 for(
auto elem_in_cur_gmme : range(
133 cur_gmme.nb_mesh_elements() ) ) {
134 index_t nb_vertices_in_cur_element =
135 cur_gmme.nb_mesh_element_vertices( elem_in_cur_gmme );
136 index_t gmsh_element_type = find_gmsh_element_type(
137 nb_vertices_in_cur_element, gmme_type_index );
138 out << element_index++ <<
SPACE << gmsh_element_type <<
SPACE 139 << nb_of_tags <<
SPACE << physical_id <<
SPACE 140 << index_of_gmme_of_the_current_type + gmsh_offset
142 for(
auto v_index_in_cur_element : range(
143 nb_vertices_in_cur_element ) ) {
145 << geomodel.mesh.vertices.geomodel_vertex_id(
147 cur_gmme.mesh_element_vertex_index(
148 ElementLocalVertex( elem_in_cur_gmme,
149 find_gmsh_element_local_vertex_id(
150 nb_vertices_in_cur_element,
152 v_index_in_cur_element ) ) ) )
153 + gmsh_offset << SPACE;
159 out <<
"$EndElements" <<
EOL;
169 index_t find_gmsh_element_type(
171 index_t mesh_entity_type_index )
173 return element_type[nb_vertices + mesh_entity_type_index];
181 index_t find_gmsh_element_local_vertex_id(
183 index_t mesh_entity_type_index,
184 index_t local_vertex_index )
186 return vertices_in_elements[nb_vertices + mesh_entity_type_index][local_vertex_index];
201 index_t count_elements(
const GeoModel< 3 >& geomodel )
203 index_t nb_elements = 0;
204 const std::vector< MeshEntityType >& gmme_types =
205 geomodel.entity_type_manager().mesh_entity_manager.mesh_entity_types();
206 for(
const MeshEntityType& cur_mesh_entity_type : gmme_types ) {
207 for(
auto index_of_gmme_of_the_current_type : range(
208 geomodel.nb_mesh_entities( cur_mesh_entity_type ) ) ) {
209 gmme_id cur_gmme_id = gmme_id( cur_mesh_entity_type,
210 index_of_gmme_of_the_current_type );
213 nb_elements += cur_gmme.nb_mesh_elements();
void ringmesh_unused(const T &)
template class RINGMESH_API GeoModelMeshEntity< 3 >