libMesh
Public Member Functions | List of all members
MeshStitchTest Class Reference
Inheritance diagram for MeshStitchTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (MeshStitchTest)
 
 CPPUNIT_TEST (testMeshStitch)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testMeshStitch ()
 

Detailed Description

Definition at line 13 of file mesh_stitch.C.

Member Function Documentation

◆ CPPUNIT_TEST()

MeshStitchTest::CPPUNIT_TEST ( testMeshStitch  )

◆ CPPUNIT_TEST_SUITE()

MeshStitchTest::CPPUNIT_TEST_SUITE ( MeshStitchTest  )

◆ CPPUNIT_TEST_SUITE_END()

MeshStitchTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void MeshStitchTest::setUp ( )
inline

Definition at line 26 of file mesh_stitch.C.

27  {}

◆ tearDown()

void MeshStitchTest::tearDown ( )
inline

Definition at line 29 of file mesh_stitch.C.

30  {}

◆ testMeshStitch()

void MeshStitchTest::testMeshStitch ( )
inline

Definition at line 32 of file mesh_stitch.C.

33  {
34  // Generate four meshes to be stitched together
36  mesh1(*TestCommWorld),
37  mesh2(*TestCommWorld),
38  mesh3(*TestCommWorld);
39 
40  // Give the meshes different extra integers to make sure those
41  // merge. Reuse names between nodes and elements to make sure
42  // those don't mix. Add some integers before and others after
43  // generation to test flexibility there.
44 
45  std::vector<std::string> names2 {"bar", "baz"};
46  mesh2.add_elem_integers(names2);
47 
48  std::vector<std::string> names3 {"bar", "foo"};
49  mesh3.add_elem_integers(names3);
50 
51  int ps = 2;
52  MeshTools::Generation::build_cube (mesh0, ps, ps, ps, -1, 0, 0, 1, 0, 1, HEX27);
53  MeshTools::Generation::build_cube (mesh1, ps, ps, ps, 0, 1, 0, 1, 0, 1, HEX27);
54  MeshTools::Generation::build_cube (mesh2, ps, ps, ps, -1, 0, -1, 0, 0, 1, HEX27);
55  MeshTools::Generation::build_cube (mesh3, ps, ps, ps, 0, 1, -1, 0, 0, 1, HEX27);
56 
57  struct trivially_copyable_pair // std::pair triggers -Wclass-memaccess
58  {
59  dof_id_type first, second;
60  };
61 
62  mesh0.add_node_integer("baz");
63  unsigned int foo1e_idx = mesh1.add_elem_integer("foo");
64  mesh2.add_elem_datum<trivially_copyable_pair>("qux");
65  unsigned int qux2n_idx = mesh2.add_node_datum<trivially_copyable_pair>("qux");
66  mesh3.add_node_integers(names3);
67 
68  for (const auto & elem : mesh1.element_ptr_range())
69  elem->set_extra_integer(foo1e_idx, 2);
70 
71  for (const auto & node : mesh2.node_ptr_range())
72  node->set_extra_datum<trivially_copyable_pair>
73  (qux2n_idx, {3, 4});
74 
75  // We stitch the meshes in a hierarchical way.
76  mesh0.stitch_meshes(mesh1, 2, 4, TOLERANCE, true, true, false, false);
77  mesh2.stitch_meshes(mesh3, 2, 4, TOLERANCE, true, true, false, false);
78  mesh0.stitch_meshes(mesh2, 1, 3, TOLERANCE, true, true, false, false);
79 
80  CPPUNIT_ASSERT_EQUAL(mesh0.n_elem(), dof_id_type(32));
81  CPPUNIT_ASSERT_EQUAL(mesh0.n_nodes(), dof_id_type(405));
82  CPPUNIT_ASSERT_EQUAL(mesh0.n_elem_integers(), 5u); // that pair counts 2x
83  CPPUNIT_ASSERT_EQUAL(mesh0.n_node_integers(), 5u);
84  std::vector<std::string> all_names {"foo", "bar", "baz", "qux"};
85  std::vector<unsigned int> node_name_indices {4, 3, 0, 1};
86  for (unsigned int i=0; i != 4; ++i)
87  {
88  CPPUNIT_ASSERT(mesh0.has_elem_integer(all_names[i]));
89  CPPUNIT_ASSERT_EQUAL(mesh0.get_elem_integer_index(all_names[i]), i);
90  CPPUNIT_ASSERT(mesh0.has_node_integer(all_names[i]));
91  CPPUNIT_ASSERT_EQUAL(mesh0.get_node_integer_index(all_names[i]), node_name_indices[i]);
92  }
93 
94  unsigned int foo0e_idx = mesh0.get_elem_integer_index("foo");
95  for (const auto & elem : mesh0.element_ptr_range())
96  {
97  CPPUNIT_ASSERT_EQUAL(elem->n_extra_integers(), 5u);
98  const Point c = elem->centroid();
99  if (c(0) > 0 && c(1) > 0) // this came from mesh1
100  CPPUNIT_ASSERT_EQUAL(elem->get_extra_integer(foo0e_idx), dof_id_type(2));
101  else
102  CPPUNIT_ASSERT_EQUAL(elem->get_extra_integer(foo0e_idx), DofObject::invalid_id);
103  }
104 
105  unsigned int qux0n_idx = mesh0.get_node_integer_index("qux");
106  for (const auto & node : mesh0.node_ptr_range())
107  {
108  CPPUNIT_ASSERT_EQUAL(node->n_extra_integers(), 5u);
109  trivially_copyable_pair datum =
110  node->get_extra_datum<trivially_copyable_pair>(qux0n_idx);
111  if ((*node)(0) <= 0 && (*node)(1) < 0) // this came from mesh2
112  {
113  CPPUNIT_ASSERT_EQUAL(datum.first, dof_id_type(3));
114  CPPUNIT_ASSERT_EQUAL(datum.second, dof_id_type(4));
115  }
116  else
117  {
118  CPPUNIT_ASSERT_EQUAL(datum.first, DofObject::invalid_id);
119  CPPUNIT_ASSERT_EQUAL(datum.second, DofObject::invalid_id);
120  }
121  }
122  }

References libMesh::MeshBase::add_elem_integers(), libMesh::MeshBase::add_node_integers(), libMesh::MeshTools::Generation::build_cube(), libMesh::HEX27, and TestCommWorld.


The documentation for this class was generated from the following file:
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::MeshTools::Generation::build_cube
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.
Definition: mesh_generation.C:298
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::HEX27
Definition: enum_elem_type.h:49
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38