@@ -107,7 +107,8 @@ namespace
107107/* ----------------------------------------------------------------------*
108108 | ctor (public) maf 12/07|
109109 *----------------------------------------------------------------------*/
110- Core::IO::Exodus::Mesh::Mesh (const std::string exofilename)
110+ Core::IO::Exodus::Mesh::Mesh (std::filesystem::path exodus_file, MeshParameters mesh_data)
111+ : mesh_data_(mesh_data)
111112{
112113 int error;
113114 int CPU_word_size, IO_word_size;
@@ -118,8 +119,8 @@ Core::IO::Exodus::Mesh::Mesh(const std::string exofilename)
118119
119120 // open EXODUS II file
120121 int exo_handle =
121- ex_open (exofilename .c_str (), EX_READ, &CPU_word_size, &IO_word_size, &exoversion);
122- if (exo_handle <= 0 ) FOUR_C_THROW (" Error while opening EXODUS II file {}" , exofilename );
122+ ex_open (exodus_file .c_str (), EX_READ, &CPU_word_size, &IO_word_size, &exoversion);
123+ if (exo_handle <= 0 ) FOUR_C_THROW (" Error while opening EXODUS II file {}" , exodus_file. string () );
123124
124125 // read database parameters
125126 int num_elem_blk, num_node_sets, num_side_sets, num_nodes;
@@ -138,10 +139,12 @@ Core::IO::Exodus::Mesh::Mesh(const std::string exofilename)
138139 error = ex_get_coord (exo_handle, x.data (), y.data (), z.data ());
139140 if (error != 0 ) FOUR_C_THROW (" exo error returned" );
140141
142+ FOUR_C_ASSERT_ALWAYS (
143+ mesh_data_.node_start_id >= 0 , " Node start id must be greater than or equal to 0" );
144+
141145 for (int i = 0 ; i < num_nodes; ++i)
142146 {
143- // Node numbering starts at one in 4C
144- nodes_[i + 1 ] = {x[i], y[i], z[i]};
147+ nodes_[i + mesh_data_.node_start_id ] = {x[i], y[i], z[i]};
145148 }
146149 }
147150
@@ -175,13 +178,16 @@ Core::IO::Exodus::Mesh::Mesh(const std::string exofilename)
175178 error = ex_get_conn (exo_handle, EX_ELEM_BLOCK, ebids[i], allconn.data (), nullptr , nullptr );
176179 if (error != 0 ) FOUR_C_THROW (" exo error returned" );
177180 std::map<int , std::vector<int >> eleconn;
181+
182+ // Compare the desired start ID to Exodus' one-based indexing to get the offset.
183+ const int node_offset = mesh_data_.node_start_id - 1 ;
178184 for (int j = 0 ; j < num_el_in_blk; ++j)
179185 {
180186 std::vector<int >& actconn = eleconn[j];
181187 actconn.reserve (num_nod_per_elem);
182188 for (int k = 0 ; k < num_nod_per_elem; ++k)
183189 {
184- actconn.push_back (allconn[k + j * num_nod_per_elem]);
190+ actconn.push_back (allconn[k + j * num_nod_per_elem] + node_offset );
185191 }
186192 reorder_nodes_exodus_to_four_c (actconn, cell_type_from_exodus_string (ele_type));
187193 }
@@ -217,10 +223,12 @@ Core::IO::Exodus::Mesh::Mesh(const std::string exofilename)
217223 else if (error < 0 )
218224 FOUR_C_THROW (" error reading node set" );
219225 std::set<int > nodes_in_set;
220- for (int j = 0 ; j < num_nodes_in_set; ++j) nodes_in_set.insert (node_set_node_list[j]);
226+ // Compare the desired start ID to Exodus' one-based indexing to get the offset.
227+ const int node_offset = mesh_data_.node_start_id - 1 ;
228+ for (int j = 0 ; j < num_nodes_in_set; ++j)
229+ nodes_in_set.insert (node_set_node_list[j] + node_offset);
221230 NodeSet actNodeSet (nodes_in_set, nodesetname);
222231
223- // Add this NodeSet into Mesh map (here prelim due to pro names)
224232 node_sets_.insert (std::pair<int , NodeSet>(npropID[i], actNodeSet));
225233 }
226234 } // end of nodeset section
@@ -362,48 +370,6 @@ void Core::IO::Exodus::Mesh::set_nsd(const int nsd)
362370
363371 four_c_dim_ = nsd;
364372}
365- /* ----------------------------------------------------------------------*/
366- /* ----------------------------------------------------------------------*/
367-
368-
369- /* ----------------------------------------------------------------------*/
370- /* ----------------------------------------------------------------------*/
371- std::vector<double > Core::IO::Exodus::Mesh::normal (
372- const int head1, const int origin, const int head2) const
373- {
374- std::vector<double > normal (3 );
375- std::vector<double > h1 = get_node (head1);
376- std::vector<double > h2 = get_node (head2);
377- std::vector<double > o = get_node (origin);
378-
379- normal[0 ] = ((h1[1 ] - o[1 ]) * (h2[2 ] - o[2 ]) - (h1[2 ] - o[2 ]) * (h2[1 ] - o[1 ]));
380- normal[1 ] = -((h1[0 ] - o[0 ]) * (h2[2 ] - o[2 ]) - (h1[2 ] - o[2 ]) * (h2[0 ] - o[0 ]));
381- normal[2 ] = ((h1[0 ] - o[0 ]) * (h2[1 ] - o[1 ]) - (h1[1 ] - o[1 ]) * (h2[0 ] - o[0 ]));
382-
383- double length = sqrt (normal[0 ] * normal[0 ] + normal[1 ] * normal[1 ] + normal[2 ] * normal[2 ]);
384- normal[0 ] = normal[0 ] / length;
385- normal[1 ] = normal[1 ] / length;
386- normal[2 ] = normal[2 ] / length;
387-
388- return normal;
389- }
390-
391- /* ----------------------------------------------------------------------*/
392- /* ----------------------------------------------------------------------*/
393- std::vector<double > Core::IO::Exodus::Mesh::node_vec (const int tail, const int head) const
394- {
395- std::vector<double > nv (3 );
396- std::vector<double > t = get_node (tail);
397- std::vector<double > h = get_node (head);
398- nv[0 ] = h[0 ] - t[0 ];
399- nv[1 ] = h[1 ] - t[1 ];
400- nv[2 ] = h[2 ] - t[2 ];
401- double length = sqrt (nv[0 ] * nv[0 ] + nv[1 ] * nv[1 ] + nv[2 ] * nv[2 ]);
402- nv[0 ] = nv[0 ] / length;
403- nv[1 ] = nv[1 ] / length;
404- nv[2 ] = nv[2 ] / length;
405- return nv;
406- }
407373
408374
409375/* ----------------------------------------------------------------------*/
0 commit comments