libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ExodusC0PolyhedronTest Class Reference
Inheritance diagram for ExodusC0PolyhedronTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ExodusC0PolyhedronTest)
 
 CPPUNIT_TEST (test_write_cube_header)
 
 CPPUNIT_TEST (test_write_hexagonal_prism_header)
 
 CPPUNIT_TEST (test_write_and_read_hexagonal_prism)
 
 CPPUNIT_TEST_SUITE_END ()
 
ExodusHeaderInfo write_and_read_header (Mesh &mesh, const std::string &filename)
 
void build_c0polyhedron (Mesh &mesh, const std::vector< Point > &points, const std::vector< std::vector< unsigned int > > &nodes_on_side)
 
void test_write_cube_header ()
 
void test_write_hexagonal_prism_header ()
 
void test_write_and_read_hexagonal_prism ()
 

Detailed Description

Definition at line 183 of file exodus_test.C.

Member Function Documentation

◆ build_c0polyhedron()

void ExodusC0PolyhedronTest::build_c0polyhedron ( Mesh mesh,
const std::vector< Point > &  points,
const std::vector< std::vector< unsigned int > > &  nodes_on_side 
)
inline

Definition at line 209 of file exodus_test.C.

212 {
213 for (auto p : index_range(points))
214 mesh.add_point(points[p], /*id=*/p);
215
216 std::vector<std::shared_ptr<Polygon>> sides(nodes_on_side.size());
217 for (auto s : index_range(nodes_on_side))
218 {
219 const auto &nodes_on_s = nodes_on_side[s];
220 sides[s] = std::make_shared<C0Polygon>(nodes_on_s.size());
221 for (auto i : index_range(nodes_on_s))
222 sides[s]->set_node(i, mesh.node_ptr(nodes_on_s[i]));
223 }
224
225 std::unique_ptr<Node> mid_elem_node;
226 std::unique_ptr<Elem> polyhedron =
227 std::make_unique<C0Polyhedron>(sides, mid_elem_node);
228 if (mid_elem_node)
229 mesh.add_node(std::move(mid_elem_node));
230
231 polyhedron->set_id() = 0;
232 Elem *elem = mesh.add_elem(std::move(polyhedron));
233 elem->subdomain_id() = 1;
236 }
dof_id_type & set_id()
Definition dof_object.h:827
This is the base class from which all geometric element types are derived.
Definition elem.h:96
subdomain_id_type subdomain_id() const
Definition elem.h:2591
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
Definition mesh_base.C:824
virtual Node * add_node(Node *n)=0
Add Node n to the end of the vertex array.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
MeshBase & mesh
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_node(), libMesh::MeshBase::add_point(), libMesh::MeshBase::cache_elem_data(), libMesh::index_range(), mesh, libMesh::MeshBase::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::DofObject::set_id(), and libMesh::Elem::subdomain_id().

Referenced by test_write_and_read_hexagonal_prism(), and test_write_hexagonal_prism_header().

◆ CPPUNIT_TEST() [1/3]

ExodusC0PolyhedronTest::CPPUNIT_TEST ( test_write_and_read_hexagonal_prism  )

◆ CPPUNIT_TEST() [2/3]

ExodusC0PolyhedronTest::CPPUNIT_TEST ( test_write_cube_header  )

◆ CPPUNIT_TEST() [3/3]

ExodusC0PolyhedronTest::CPPUNIT_TEST ( test_write_hexagonal_prism_header  )

◆ CPPUNIT_TEST_SUITE_END()

ExodusC0PolyhedronTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ExodusC0PolyhedronTest::LIBMESH_CPPUNIT_TEST_SUITE ( ExodusC0PolyhedronTest  )

◆ test_write_and_read_hexagonal_prism()

void ExodusC0PolyhedronTest::test_write_and_read_hexagonal_prism ( )
inline

Definition at line 301 of file exodus_test.C.

302 {
303 LOG_UNIT_TEST;
304
305 Mesh mesh(*TestCommWorld);
306 const std::vector<Point> points =
307 { { 0, -2, 0}, {-1, -1, 0}, {-1, 1, 0},
308 { 0, 2, 0}, { 1, 1, 0}, { 1, -1, 0},
309 { 0, -2, 1}, {-1, -1, 1}, {-1, 1, 1},
310 { 0, 2, 1}, { 1, 1, 1}, { 1, -1, 1} };
311
312 const std::vector<std::vector<unsigned int>> nodes_on_side =
313 { {0, 1, 2, 3, 4, 5},
314 {0, 1, 7, 6},
315 {1, 2, 8, 7},
316 {2, 3, 9, 8},
317 {3, 4, 10, 9},
318 {4, 5, 11, 10},
319 {5, 0, 6, 11},
320 {6, 7, 8, 9, 10, 11} };
321
322 this->build_c0polyhedron(mesh, points, nodes_on_side);
323
324 std::vector<std::vector<dof_id_type>> expected_nodes_on_side;
325 const Elem *output_elem = mesh.query_elem_ptr(0);
326 const bool have_output_elem = output_elem;
327 bool found_output_elem = have_output_elem;
328 mesh.comm().max(found_output_elem);
329 CPPUNIT_ASSERT(found_output_elem);
330
331 if (output_elem)
332 {
333 expected_nodes_on_side.reserve(output_elem->n_sides());
334 for (auto s : output_elem->side_index_range())
335 {
336 expected_nodes_on_side.emplace_back();
337 for (const auto n : output_elem->nodes_on_side(s))
338 expected_nodes_on_side.back().push_back(output_elem->node_id(n));
339 }
340 }
341
342 {
343 ExodusII_IO exii(mesh);
344 exii.write("write_exodus_C0POLYHEDRON_HEXPRISM_READ.e");
345 }
346
347 Mesh input_mesh(*TestCommWorld);
348 ExodusII_IO exii_input(input_mesh);
349 if (input_mesh.processor_id() == 0)
350 exii_input.read("write_exodus_C0POLYHEDRON_HEXPRISM_READ.e");
351
352 MeshCommunication().broadcast(input_mesh);
353 input_mesh.prepare_for_use();
354
355 CPPUNIT_ASSERT_EQUAL(cast_int<dof_id_type>(1), input_mesh.n_elem());
356
357 const Elem *elem = input_mesh.query_elem_ptr(0);
358 bool found_elem = elem;
359 input_mesh.comm().max(found_elem);
360 CPPUNIT_ASSERT(found_elem);
361
362 const bool can_compare = have_output_elem && elem;
363 bool found_comparable_elem = can_compare;
364 input_mesh.comm().max(found_comparable_elem);
365 CPPUNIT_ASSERT(found_comparable_elem);
366
367 if (!can_compare)
368 return;
369
370 CPPUNIT_ASSERT_EQUAL(C0POLYHEDRON, elem->type());
371 CPPUNIT_ASSERT_EQUAL(12u, elem->n_vertices());
372 CPPUNIT_ASSERT_EQUAL(8u, elem->n_sides());
373
374 for (auto s : index_range(expected_nodes_on_side))
375 {
376 const auto side_nodes = elem->nodes_on_side(s);
377 CPPUNIT_ASSERT_EQUAL(expected_nodes_on_side[s].size(), side_nodes.size());
378 for (auto n : index_range(expected_nodes_on_side[s]))
379 CPPUNIT_ASSERT_EQUAL(expected_nodes_on_side[s][n],
380 elem->node_id(side_nodes[n]));
381 }
382 }
void build_c0polyhedron(Mesh &mesh, const std::vector< Point > &points, const std::vector< std::vector< unsigned int > > &nodes_on_side)
void max(const T &r, T &o, Request &req) const
virtual unsigned int n_sides() const =0
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition exodusII_io.h:53
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
This is the MeshCommunication class.
void broadcast(MeshBase &) const
This method takes a mesh (which is assumed to reside on processor 0) and broadcasts it to all the oth...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
const Parallel::Communicator & comm() const

References libMesh::MeshCommunication::broadcast(), build_c0polyhedron(), libMesh::C0POLYHEDRON, libMesh::ParallelObject::comm(), libMesh::index_range(), libMesh::Parallel::Communicator::max(), mesh, libMesh::DistributedMesh::n_elem(), libMesh::Elem::n_sides(), libMesh::Elem::n_vertices(), libMesh::Elem::node_id(), libMesh::Elem::nodes_on_side(), libMesh::MeshBase::prepare_for_use(), libMesh::ParallelObject::processor_id(), libMesh::MeshBase::query_elem_ptr(), libMesh::DistributedMesh::query_elem_ptr(), libMesh::ExodusII_IO::read(), libMesh::Elem::side_index_range(), TestCommWorld, libMesh::Elem::type(), and libMesh::ExodusII_IO::write().

◆ test_write_cube_header()

void ExodusC0PolyhedronTest::test_write_cube_header ( )
inline

Definition at line 238 of file exodus_test.C.

239 {
240 LOG_UNIT_TEST;
241
242 Mesh mesh(*TestCommWorld);
244 -1., 1.,
245 -1., 1.,
246 -1., 1.,
249
250 for (auto &elem : mesh.element_ptr_range())
251 elem->subdomain_id() = 1;
253
254 ExodusHeaderInfo header_info =
255 this->write_and_read_header(mesh, "write_exodus_C0POLYHEDRON.e");
256
257 CPPUNIT_ASSERT_EQUAL(header_info.num_dim, 3);
258 CPPUNIT_ASSERT_EQUAL(header_info.num_elem, 8);
259 CPPUNIT_ASSERT_EQUAL(header_info.num_elem_blk, 1);
260 CPPUNIT_ASSERT_EQUAL(header_info.num_face, 48);
261 CPPUNIT_ASSERT_EQUAL(header_info.num_face_blk, 1);
262 CPPUNIT_ASSERT_EQUAL(header_info.num_node_sets, 0);
263 CPPUNIT_ASSERT_EQUAL(header_info.num_side_sets, 0);
264 }
ExodusHeaderInfo write_and_read_header(Mesh &mesh, const std::string &filename)
void clear()
Clears the underlying data structures and restores the object to a pristine state with no data stored...
This class is used as both an external data structure for passing around Exodus file header informati...
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.

References libMesh::MeshTools::Generation::build_cube(), libMesh::C0POLYHEDRON, libMesh::MeshBase::cache_elem_data(), libMesh::BoundaryInfo::clear(), libMesh::MeshBase::get_boundary_info(), mesh, libMesh::ExodusHeaderInfo::num_dim, libMesh::ExodusHeaderInfo::num_elem, libMesh::ExodusHeaderInfo::num_elem_blk, libMesh::ExodusHeaderInfo::num_face, libMesh::ExodusHeaderInfo::num_face_blk, libMesh::ExodusHeaderInfo::num_node_sets, libMesh::ExodusHeaderInfo::num_side_sets, TestCommWorld, and write_and_read_header().

◆ test_write_hexagonal_prism_header()

void ExodusC0PolyhedronTest::test_write_hexagonal_prism_header ( )
inline

Definition at line 266 of file exodus_test.C.

267 {
268 LOG_UNIT_TEST;
269
270 Mesh mesh(*TestCommWorld);
271 const std::vector<Point> points =
272 { { 0, -2, 0}, {-1, -1, 0}, {-1, 1, 0},
273 { 0, 2, 0}, { 1, 1, 0}, { 1, -1, 0},
274 { 0, -2, 1}, {-1, -1, 1}, {-1, 1, 1},
275 { 0, 2, 1}, { 1, 1, 1}, { 1, -1, 1} };
276
277 const std::vector<std::vector<unsigned int>> nodes_on_side =
278 { {0, 1, 2, 3, 4, 5},
279 {0, 1, 7, 6},
280 {1, 2, 8, 7},
281 {2, 3, 9, 8},
282 {3, 4, 10, 9},
283 {4, 5, 11, 10},
284 {5, 0, 6, 11},
285 {6, 7, 8, 9, 10, 11} };
286
287 this->build_c0polyhedron(mesh, points, nodes_on_side);
288
289 ExodusHeaderInfo header_info =
290 this->write_and_read_header(mesh, "write_exodus_C0POLYHEDRON_HEXPRISM.e");
291
292 CPPUNIT_ASSERT_EQUAL(header_info.num_dim, 3);
293 CPPUNIT_ASSERT_EQUAL(header_info.num_elem, 1);
294 CPPUNIT_ASSERT_EQUAL(header_info.num_elem_blk, 1);
295 CPPUNIT_ASSERT_EQUAL(header_info.num_face, 8);
296 CPPUNIT_ASSERT_EQUAL(header_info.num_face_blk, 1);
297 CPPUNIT_ASSERT_EQUAL(header_info.num_node_sets, 0);
298 CPPUNIT_ASSERT_EQUAL(header_info.num_side_sets, 0);
299 }

References build_c0polyhedron(), mesh, libMesh::ExodusHeaderInfo::num_dim, libMesh::ExodusHeaderInfo::num_elem, libMesh::ExodusHeaderInfo::num_elem_blk, libMesh::ExodusHeaderInfo::num_face, libMesh::ExodusHeaderInfo::num_face_blk, libMesh::ExodusHeaderInfo::num_node_sets, libMesh::ExodusHeaderInfo::num_side_sets, TestCommWorld, and write_and_read_header().

◆ write_and_read_header()

ExodusHeaderInfo ExodusC0PolyhedronTest::write_and_read_header ( Mesh mesh,
const std::string &  filename 
)
inline

Definition at line 194 of file exodus_test.C.

196 {
197 {
198 ExodusII_IO exii(mesh);
199 exii.write(filename);
200 }
201
202 TestCommWorld->barrier();
203
204 Mesh header_mesh(*TestCommWorld);
205 ExodusII_IO exii(header_mesh);
206 return exii.read_header(filename);
207 }
Communicator * TestCommWorld

References mesh, libMesh::ExodusII_IO::read_header(), TestCommWorld, and libMesh::ExodusII_IO::write().

Referenced by test_write_cube_header(), and test_write_hexagonal_prism_header().


The documentation for this class was generated from the following file: