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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (ConnectedComponentsTest)
 The goal of this test is to ensure that the count returned by MeshTools::n_connected_components() is correct for hand-checked cases. More...
 
 CPPUNIT_TEST (testEdge2)
 These tests require a valid solver package to be enabled because they build a SparseMatrix. More...
 
 CPPUNIT_TEST (testEdge3)
 
 CPPUNIT_TEST (testEdge4)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testEdge2 ()
 
void testEdge3 ()
 
void testEdge4 ()
 

Protected Member Functions

void testEdge (unsigned n_elem, ElemType elem_type)
 

Detailed Description

Definition at line 18 of file connected_components.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/3]

ConnectedComponentsTest::CPPUNIT_TEST ( testEdge2  )

These tests require a valid solver package to be enabled because they build a SparseMatrix.

Note: LIBMESH_HAVE_SOLVER is actually defined in libmesh/system.h

◆ CPPUNIT_TEST() [2/3]

ConnectedComponentsTest::CPPUNIT_TEST ( testEdge3  )

◆ CPPUNIT_TEST() [3/3]

ConnectedComponentsTest::CPPUNIT_TEST ( testEdge4  )

◆ CPPUNIT_TEST_SUITE_END()

ConnectedComponentsTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

ConnectedComponentsTest::LIBMESH_CPPUNIT_TEST_SUITE ( ConnectedComponentsTest  )

The goal of this test is to ensure that the count returned by MeshTools::n_connected_components() is correct for hand-checked cases.

◆ setUp()

void ConnectedComponentsTest::setUp ( )
inline

Definition at line 134 of file connected_components.C.

134 {}

◆ tearDown()

void ConnectedComponentsTest::tearDown ( )
inline

Definition at line 136 of file connected_components.C.

136 {}

◆ testEdge()

void ConnectedComponentsTest::testEdge ( unsigned  n_elem,
ElemType  elem_type 
)
inlineprotected

Definition at line 43 of file connected_components.C.

References libMesh::MeshBase::allow_remote_element_removal(), libMesh::SparseMatrix< T >::build(), libMesh::MeshTools::Generation::build_line(), libMesh::ParallelObject::comm(), libMesh::MeshBase::copy_constraint_rows(), libMesh::MeshBase::delete_elem(), libMesh::make_range(), TIMPI::Communicator::max(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshTools::n_connected_components(), libMesh::MeshTools::n_elem(), n_nodes, libMesh::MeshBase::n_nodes(), libMesh::MeshBase::prepare_for_use(), TIMPI::Communicator::rank(), libMesh::Real, and TestCommWorld.

45  {
47 
48  // We don't yet support n_connected_components() on distributed
49  // meshes
51 
53  n_elem,
54  /*xmin=*/0.,
55  /*xmax=*/1.,
56  elem_type);
57 
58  const dof_id_type n_components_orig =
60 
61  CPPUNIT_ASSERT_EQUAL(n_components_orig, dof_id_type(1));
62 
63  // We can't disconnect a too-small mesh
64  if (n_elem < 3)
65  return;
66 
67  for (const auto & elem : mesh.element_ptr_range())
68  {
69  const Point c = elem->vertex_average();
70 
71  if (std::abs(c(0) - 0.5) < 0.2)
72  mesh.delete_elem(elem);
73  }
74 
76 
77  const dof_id_type n_components_broken =
79 
80  CPPUNIT_ASSERT_EQUAL(n_components_broken, dof_id_type(2));
81 
82  // Add a constraint connecting the original end nodes
83  auto matrix = SparseMatrix<Number>::build (mesh.comm());
84 
85  dof_id_type left_node = 0, right_node = 0;
86  for (const auto & elem : mesh.element_ptr_range())
87  for (const auto & node : elem->node_ref_range())
88  {
89  if (node(0) == Real(0))
90  left_node = node.id();
91  if (node(0) == Real(1))
92  right_node = node.id();
93  }
94 
95  mesh.comm().max(left_node);
96  mesh.comm().max(right_node);
97 
98  const dof_id_type n_nodes = mesh.n_nodes();
99  CPPUNIT_ASSERT_EQUAL(n_nodes, mesh.max_node_id());
100 
101  processor_id_type my_rank = mesh.comm().rank();
102  matrix->init(n_nodes, n_nodes-1,
103  (my_rank ? 0 : n_nodes),
104  (my_rank ? 0 : n_nodes-1),
105  (my_rank ? 0 : n_nodes-1),
106  0);
107 
108  if (!my_rank)
109  {
110  for (auto i : make_range(n_nodes))
111  {
112  if (i < right_node)
113  matrix->set(i,i,1);
114  if (i > right_node)
115  matrix->set(i,i-1,1);
116  }
117  if (left_node > right_node)
118  matrix->set(right_node, left_node-1, 1);
119  else
120  matrix->set(right_node, left_node, 1);
121  }
122 
123  matrix->close();
124 
125  mesh.copy_constraint_rows(*matrix);
126 
127  const dof_id_type n_components_constrained =
129 
130  CPPUNIT_ASSERT_EQUAL(n_components_constrained, dof_id_type(1));
131  }
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:969
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:759
MeshBase & mesh
processor_id_type rank() const
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
Definition: mesh_base.C:2063
const Parallel::Communicator & comm() const
Generic sparse matrix.
Definition: vector_fe_ex5.C:46
uint8_t processor_id_type
void allow_remote_element_removal(bool allow)
If false is passed in then this mesh will no longer have remote elements deleted when being prepared ...
Definition: mesh_base.h:1212
const dof_id_type n_nodes
Definition: tecplot_io.C:67
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
dof_id_type n_connected_components(const MeshBase &mesh, Real constraint_tol=0)
Definition: mesh_tools.C:840
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
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.
virtual dof_id_type max_node_id() const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
virtual dof_id_type n_nodes() const =0
uint8_t dof_id_type
Definition: id_types.h:67

◆ testEdge2()

void ConnectedComponentsTest::testEdge2 ( )
inline

Definition at line 138 of file connected_components.C.

References libMesh::EDGE2.

139  {
140  LOG_UNIT_TEST;
141 
142  testEdge(/*n_elem=*/10, EDGE2);
143  }
void testEdge(unsigned n_elem, ElemType elem_type)

◆ testEdge3()

void ConnectedComponentsTest::testEdge3 ( )
inline

Definition at line 145 of file connected_components.C.

References libMesh::EDGE3.

146  {
147  LOG_UNIT_TEST;
148 
149  testEdge(/*n_elem=*/10, EDGE3);
150  }
void testEdge(unsigned n_elem, ElemType elem_type)

◆ testEdge4()

void ConnectedComponentsTest::testEdge4 ( )
inline

Definition at line 152 of file connected_components.C.

References libMesh::EDGE4.

153  {
154  LOG_UNIT_TEST;
155 
156  testEdge(/*n_elem=*/10, EDGE4);
157  }
void testEdge(unsigned n_elem, ElemType elem_type)

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