libMesh
Loading...
Searching...
No Matches
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.
 
 CPPUNIT_TEST (testEdge2)
 These tests require a valid solver package to be enabled because they build a SparseMatrix.
 
 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.

45 {
46 Mesh mesh(*TestCommWorld);
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
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 }
void max(const T &r, T &o, Request &req) const
processor_id_type rank() const
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:1378
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 dof_id_type n_nodes() const =0
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
virtual dof_id_type max_node_id() const =0
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
Definition mesh_base.C:2490
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:40
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
MeshBase & mesh
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.
dof_id_type n_connected_components(const MeshBase &mesh, Real constraint_tol=0)
Definition mesh_tools.C:864
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
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:176
const dof_id_type n_nodes
Definition tecplot_io.C:67

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(), libMesh::Parallel::Communicator::max(), libMesh::MeshBase::max_node_id(), mesh, libMesh::MeshTools::n_connected_components(), libMesh::MeshBase::n_nodes(), n_nodes, libMesh::MeshBase::prepare_for_use(), libMesh::Parallel::Communicator::rank(), libMesh::Real, and TestCommWorld.

Referenced by testEdge2(), testEdge3(), and testEdge4().

◆ testEdge2()

void ConnectedComponentsTest::testEdge2 ( )
inline

Definition at line 138 of file connected_components.C.

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

References libMesh::EDGE2, and testEdge().

◆ testEdge3()

void ConnectedComponentsTest::testEdge3 ( )
inline

Definition at line 145 of file connected_components.C.

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

References libMesh::EDGE3, and testEdge().

◆ testEdge4()

void ConnectedComponentsTest::testEdge4 ( )
inline

Definition at line 152 of file connected_components.C.

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

References libMesh::EDGE4, and testEdge().


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