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 27 of file nodal_neighbors.C.

Member Function Documentation

NodalNeighborsTest::CPPUNIT_TEST ( testEdge2  )
NodalNeighborsTest::CPPUNIT_TEST ( testEdge3  )
NodalNeighborsTest::CPPUNIT_TEST ( testEdge4  )
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.

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

Definition at line 49 of file nodal_neighbors.C.

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

52  {
53  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/1);
54 
56  n_elem,
57  /*xmin=*/0.,
58  /*xmax=*/1.,
59  elem_type);
60 
61  // find_nodal_neighbors() needs a data structure which is prepared by another function
62  std::vector<std::vector<const Elem *>> nodes_to_elem_map;
63  MeshTools::build_nodes_to_elem_map(mesh, nodes_to_elem_map);
64 
65  // Loop over the nodes and call find_nodal_neighbors()
66  {
67  std::vector<const Node*> neighbor_nodes;
68 
69  unsigned ctr = 0;
70  for (const auto & node : mesh.node_ptr_range())
71  {
72  MeshTools::find_nodal_neighbors(mesh, *node, nodes_to_elem_map, neighbor_nodes);
73 
74  // The entries in neighbor_nodes are just sorted according
75  // to memory address, which is somewhat arbitrary, so create
76  // a vector sorted by IDs for test purposes.
77  std::vector<dof_id_type> neighbor_node_ids(neighbor_nodes.size());
78  for (std::size_t i=0; i<neighbor_nodes.size(); ++i)
79  neighbor_node_ids[i] = neighbor_nodes[i]->id();
80  std::sort(neighbor_node_ids.begin(), neighbor_node_ids.end());
81 
82  // Compare to validation_data
83  for (std::size_t j=0; j<neighbor_node_ids.size(); ++j)
84  {
85  CPPUNIT_ASSERT_EQUAL( validation_data[2*ctr + j], neighbor_node_ids[j] );
86  }
87 
88  ++ctr;
89  }
90  }
91  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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:656
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
MeshBase & mesh
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:257
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:699
virtual SimpleRange< node_iterator > node_ptr_range()=0
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.
void NodalNeighborsTest::setUp ( )

Definition at line 94 of file nodal_neighbors.C.

94 {}
void NodalNeighborsTest::tearDown ( )

Definition at line 96 of file nodal_neighbors.C.

96 {}
void NodalNeighborsTest::testEdge2 ( )

Definition at line 98 of file nodal_neighbors.C.

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

99  {
100  // 11 nodes, 2 neighbor entries per node
101  dof_id_type validation_data[22] =
102  {
103  1, DofObject::invalid_id,
104  0, 2,
105  1, 3,
106  2, 4,
107  3, 5,
108  4, 6,
109  5, 7,
110  6, 8,
111  7, 9,
112  8, 10,
113  9, DofObject::invalid_id
114  };
115 
116  do_test(/*n_elem=*/10, EDGE2, validation_data);
117  }
void do_test(unsigned n_elem, ElemType elem_type, dof_id_type *validation_data)
uint8_t dof_id_type
Definition: id_types.h:64
void NodalNeighborsTest::testEdge3 ( )

Definition at line 120 of file nodal_neighbors.C.

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

121  {
122  // 11 nodes, 2 neighbor entries per node
123  dof_id_type validation_data[22] =
124  {
125  2, DofObject::invalid_id,
126  2, 4,
127  0, 1,
128  4, 6,
129  1, 3,
130  6, 8,
131  3, 5,
132  8, 10,
133  5, 7,
134  10, DofObject::invalid_id,
135  7, 9
136  };
137 
138  do_test(/*n_elem=*/5, EDGE3, validation_data);
139  }
void do_test(unsigned n_elem, ElemType elem_type, dof_id_type *validation_data)
uint8_t dof_id_type
Definition: id_types.h:64
void NodalNeighborsTest::testEdge4 ( )

Definition at line 142 of file nodal_neighbors.C.

References CPPUNIT_TEST_SUITE_REGISTRATION(), libMesh::EDGE4, and libMesh::DofObject::invalid_id.

143  {
144  // 10 nodes, 2 neighbor entries per node
145  dof_id_type validation_data[20] =
146  {
147  2, DofObject::invalid_id,
148  3, 5,
149  0, 3,
150  1, 2,
151  6, 8,
152  1, 6,
153  4, 5,
154  9, DofObject::invalid_id,
155  4, 9,
156  7, 8
157  };
158 
159  do_test(/*n_elem=*/3, EDGE4, validation_data);
160  }
void do_test(unsigned n_elem, ElemType elem_type, dof_id_type *validation_data)
uint8_t dof_id_type
Definition: id_types.h:64

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