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

Public Member Functions

 CPPUNIT_TEST_SUITE (NodalNeighborsTest)
 The goal of this test is to ensure that MeshTools::find_nodal_neighbors() works in 1D. More...
 
 CPPUNIT_TEST (testEdge2)
 
 CPPUNIT_TEST (testEdge3)
 
 CPPUNIT_TEST (testEdge4)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testEdge2 ()
 
void testEdge3 ()
 
void testEdge4 ()
 

Protected Member Functions

void do_test (unsigned n_elem, ElemType elem_type, dof_id_type *validation_data)
 

Detailed Description

Definition at line 13 of file nodal_neighbors.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/3]

NodalNeighborsTest::CPPUNIT_TEST ( testEdge2  )

◆ CPPUNIT_TEST() [2/3]

NodalNeighborsTest::CPPUNIT_TEST ( testEdge3  )

◆ CPPUNIT_TEST() [3/3]

NodalNeighborsTest::CPPUNIT_TEST ( testEdge4  )

◆ CPPUNIT_TEST_SUITE()

NodalNeighborsTest::CPPUNIT_TEST_SUITE ( NodalNeighborsTest  )

The goal of this test is to ensure that MeshTools::find_nodal_neighbors() works in 1D.

If the numbering of MeshGeneration::build_line() ever changes, this test will break, as it compares hand-checked hard-coded "validation" data with the results of MeshTools::find_nodal_neighbors(). We also use a ReplicatedMesh here to match the hard-coded numbering.

◆ CPPUNIT_TEST_SUITE_END()

NodalNeighborsTest::CPPUNIT_TEST_SUITE_END ( )

◆ do_test()

void NodalNeighborsTest::do_test ( unsigned  n_elem,
ElemType  elem_type,
dof_id_type validation_data 
)
inlineprotected

Definition at line 35 of file nodal_neighbors.C.

38  {
39  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/1);
40 
42  n_elem,
43  /*xmin=*/0.,
44  /*xmax=*/1.,
45  elem_type);
46 
47  // find_nodal_neighbors() needs a data structure which is prepared by another function
48  std::vector<std::vector<const Elem *>> nodes_to_elem_map;
49  MeshTools::build_nodes_to_elem_map(mesh, nodes_to_elem_map);
50 
51  // Loop over the nodes and call find_nodal_neighbors()
52  {
53  std::vector<const Node*> neighbor_nodes;
54 
55  unsigned ctr = 0;
56  for (const auto & node : mesh.node_ptr_range())
57  {
58  MeshTools::find_nodal_neighbors(mesh, *node, nodes_to_elem_map, neighbor_nodes);
59 
60  // The entries in neighbor_nodes are just sorted according
61  // to memory address, which is somewhat arbitrary, so create
62  // a vector sorted by IDs for test purposes.
63  std::vector<dof_id_type> neighbor_node_ids(neighbor_nodes.size());
64  for (std::size_t i=0; i<neighbor_nodes.size(); ++i)
65  neighbor_node_ids[i] = neighbor_nodes[i]->id();
66  std::sort(neighbor_node_ids.begin(), neighbor_node_ids.end());
67 
68  // Compare to validation_data
69  for (std::size_t j=0; j<neighbor_node_ids.size(); ++j)
70  {
71  CPPUNIT_ASSERT_EQUAL( validation_data[2*ctr + j], neighbor_node_ids[j] );
72  }
73 
74  ++ctr;
75  }
76  }
77  }

References libMesh::MeshTools::Generation::build_line(), libMesh::MeshTools::build_nodes_to_elem_map(), libMesh::MeshTools::find_nodal_neighbors(), mesh, libMesh::MeshTools::n_elem(), libMesh::MeshBase::node_ptr_range(), and TestCommWorld.

◆ setUp()

void NodalNeighborsTest::setUp ( )
inline

Definition at line 80 of file nodal_neighbors.C.

80 {}

◆ tearDown()

void NodalNeighborsTest::tearDown ( )
inline

Definition at line 82 of file nodal_neighbors.C.

82 {}

◆ testEdge2()

void NodalNeighborsTest::testEdge2 ( )
inline

Definition at line 84 of file nodal_neighbors.C.

85  {
86  // 11 nodes, 2 neighbor entries per node
87  dof_id_type validation_data[22] =
88  {
89  1, DofObject::invalid_id,
90  0, 2,
91  1, 3,
92  2, 4,
93  3, 5,
94  4, 6,
95  5, 7,
96  6, 8,
97  7, 9,
98  8, 10,
99  9, DofObject::invalid_id
100  };
101 
102  do_test(/*n_elem=*/10, EDGE2, validation_data);
103  }

References libMesh::EDGE2, and libMesh::DofObject::invalid_id.

◆ testEdge3()

void NodalNeighborsTest::testEdge3 ( )
inline

Definition at line 106 of file nodal_neighbors.C.

107  {
108  // 11 nodes, 2 neighbor entries per node
109  dof_id_type validation_data[22] =
110  {
111  2, DofObject::invalid_id,
112  2, 4,
113  0, 1,
114  4, 6,
115  1, 3,
116  6, 8,
117  3, 5,
118  8, 10,
119  5, 7,
120  10, DofObject::invalid_id,
121  7, 9
122  };
123 
124  do_test(/*n_elem=*/5, EDGE3, validation_data);
125  }

References libMesh::EDGE3, and libMesh::DofObject::invalid_id.

◆ testEdge4()

void NodalNeighborsTest::testEdge4 ( )
inline

Definition at line 128 of file nodal_neighbors.C.

129  {
130  // 10 nodes, 2 neighbor entries per node
131  dof_id_type validation_data[20] =
132  {
133  2, DofObject::invalid_id,
134  3, 5,
135  0, 3,
136  1, 2,
137  6, 8,
138  1, 6,
139  4, 5,
140  9, DofObject::invalid_id,
141  4, 9,
142  7, 8
143  };
144 
145  do_test(/*n_elem=*/3, EDGE4, validation_data);
146  }

References libMesh::EDGE4, and libMesh::DofObject::invalid_id.


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::n_elem
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:705
libMesh::EDGE4
Definition: enum_elem_type.h:37
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshTools::build_nodes_to_elem_map
void build_nodes_to_elem_map(const MeshBase &mesh, std::vector< std::vector< dof_id_type >> &nodes_to_elem_map)
After calling this function the input vector nodes_to_elem_map will contain the node to element conne...
Definition: mesh_tools.C:248
NodalNeighborsTest::do_test
void do_test(unsigned n_elem, ElemType elem_type, dof_id_type *validation_data)
Definition: nodal_neighbors.C:35
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::MeshBase::node_ptr_range
virtual SimpleRange< node_iterator > node_ptr_range()=0
libMesh::MeshTools::Generation::build_line
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
Definition: mesh_generation.C:1480
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::MeshTools::find_nodal_neighbors
void find_nodal_neighbors(const MeshBase &mesh, const Node &n, const std::vector< std::vector< const Elem * >> &nodes_to_elem_map, std::vector< const Node * > &neighbors)
Given a mesh and a node in the mesh, the vector will be filled with every node directly attached to t...
Definition: mesh_tools.C:743
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::EDGE2
Definition: enum_elem_type.h:35