19 #include "mesh_reader_exodusii.h"
26 MeshReaderExodusII::MeshReaderExodusII()
30 MeshReaderExodusII::~MeshReaderExodusII()
42 bool operator()(Vertex a, Vertex b)
const
44 if (a.x < b.x)
return true;
45 else if (a.x > b.x)
return false;
48 if (a.y < b.y)
return true;
58 int cpu_ws =
sizeof(double);
62 int exoid = ex_open(file_name, EX_READ, &cpu_ws, &io_ws, &version);
65 int n_dims, n_nodes, n_elems, n_eblocks, n_nodesets, n_sidesets;
66 char title[MAX_LINE_LENGTH + 1];
67 err = ex_get_init(exoid, title, &n_dims, &n_nodes, &n_elems, &n_eblocks, &n_nodesets, &n_sidesets);
69 throw Hermes::Exceptions::Exception(
"File '%s' does not contain 2D mesh", file_name);
72 double *x =
new double[n_nodes];
73 double *y =
new double[n_nodes];
74 err = ex_get_coord(exoid, x, y,
nullptr);
78 std::map<Vertex, int, VCompare> vtx_list;
80 std::map<int, int> vmap;
82 std::vector<Vertex> vtx_arr;
84 for (
int i = 0; i < n_nodes; i++)
87 Vertex v = { x[i], y[i] };
88 if (vtx_list.count(v) == 0)
102 int n_vtx = vtx_arr.size();
103 double2 *vtx =
new double2[n_vtx];
104 for (
int i = 0; i < n_vtx; i++)
106 vtx[i][0] = vtx_arr[i].x;
107 vtx[i][1] = vtx_arr[i].y;
116 int *eid_blocks =
new int[n_eblocks];
117 err = ex_get_elem_blk_ids(exoid, eid_blocks);
119 for (
int i = 0; i < n_eblocks; i++)
121 int id = eid_blocks[i];
124 char elem_type[MAX_STR_LENGTH + 1];
125 int n_elems_in_blk, n_elem_nodes, n_attrs;
126 err = ex_get_elem_block(exoid,
id, elem_type, &n_elems_in_blk, &n_elem_nodes, &n_attrs);
128 if (n_elem_nodes == 3) n_tri += n_elems_in_blk;
129 else if (n_elem_nodes == 4) n_quad += n_elems_in_blk;
133 throw Hermes::Exceptions::Exception(
"Unknown type of element");
137 int3 *tri = n_tri > 0 ?
new int3[n_tri] :
nullptr;
140 int4 *quad = n_quad > 0 ?
new int4[n_quad] :
nullptr;
144 int n_els = n_tri + n_quad;
146 int **els = n_els > 0 ?
new int *[n_els] :
nullptr;
148 int *el_nv = n_els > 0 ?
new int[n_els] :
nullptr;
150 int it = 0, iq = 0, iel = 0;
151 for (
int i = 0; i < n_eblocks; i++)
153 int id = eid_blocks[i];
156 char elem_type[MAX_STR_LENGTH + 1];
157 int n_elems_in_blk, n_elem_nodes, n_attrs;
158 err = ex_get_elem_block(exoid,
id, elem_type, &n_elems_in_blk, &n_elem_nodes, &n_attrs);
161 int *connect =
new int[n_elem_nodes * n_elems_in_blk];
162 err = ex_get_elem_conn(exoid,
id, connect);
165 std::ostringstream string_stream;
171 mesh->element_markers_conversion.insert_marker(el_marker);
174 for (
int j = 0; j < n_elems_in_blk; j++)
176 el_nv[iel] = n_elem_nodes;
177 if (n_elem_nodes == 3)
179 tri[it][0] = vmap[connect[ic++]];
180 tri[it][1] = vmap[connect[ic++]];
181 tri[it][2] = vmap[connect[ic++]];
182 tri_markers[it] = el_marker;
186 else if (n_elem_nodes == 4)
188 quad[iq][0] = vmap[connect[ic++]];
189 quad[iq][1] = vmap[connect[ic++]];
190 quad[iq][2] = vmap[connect[ic++]];
191 quad[iq][3] = vmap[connect[ic++]];
192 quad_markers[iq] = el_marker;
199 throw Hermes::Exceptions::Exception(
"Unknown type of element");
208 int *sid_blocks =
new int[n_sidesets];
209 err = ex_get_side_set_ids(exoid, sid_blocks);
214 for (
int i = 0; i < n_sidesets; i++)
216 int sid = sid_blocks[i];
217 int n_sides_in_set, n_df_in_set;
218 err = ex_get_side_set_param(exoid, sid, &n_sides_in_set, &n_df_in_set);
219 n_mark += n_sides_in_set;
221 int2 *marks =
new int2[n_mark];
225 for (
int i = 0; i < n_sidesets; i++)
227 int sid = sid_blocks[i];
228 int n_sides_in_set, n_df_in_set;
229 err = ex_get_side_set_param(exoid, sid, &n_sides_in_set, &n_df_in_set);
230 int num_elem_in_set = n_sides_in_set;
232 int *elem_list =
new int[num_elem_in_set];
233 int *side_list =
new int[n_sides_in_set];
234 err = ex_get_side_set(exoid, sid, elem_list, side_list);
237 std::ostringstream string_stream;
238 string_stream << sid;
243 mesh->boundary_markers_conversion.insert_marker(bnd_marker);
245 for (
int j = 0; j < num_elem_in_set; j++)
248 int nv = el_nv[side_list[j] - 1];
249 int vt = side_list[j] - 1;
250 marks[im][0] = els[elem_list[j] - 1][vt];
251 marks[im][1] = els[elem_list[j] - 1][(vt + 1) % nv];
252 bnd_markers[im] = bnd_marker;
262 err = ex_close(exoid);
264 mesh->create(n_vtx, vtx, n_tri, tri, tri_markers, n_quad, quad, quad_markers, n_mark, marks, bnd_markers);
270 delete[] tri_markers;
271 delete[] quad_markers;
272 delete[] bnd_markers;
::xsd::cxx::tree::id< char, ncname > id
C++ type corresponding to the ID XML Schema built-in type.
virtual void load(const char *file_name, MeshSharedPtr mesh)
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.