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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (MixedDimensionMeshTest)
 The goal of this test is to ensure that a 2D mesh with 1D elements overlapping on the edge is consistent. More...
 
 CPPUNIT_TEST (testMesh)
 
 CPPUNIT_TEST (testDofOrdering)
 
 CPPUNIT_TEST (testPointLocatorTree)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testMesh ()
 
void testDofOrdering ()
 
void testPointLocatorTree ()
 

Protected Member Functions

void build_mesh ()
 

Protected Attributes

std::unique_ptr< ReplicatedMesh_mesh
 

Detailed Description

Definition at line 18 of file mixed_dim_mesh_test.C.

Member Function Documentation

◆ build_mesh()

void MixedDimensionMeshTest::build_mesh ( )
inlineprotected

Definition at line 41 of file mixed_dim_mesh_test.C.

References libMesh::Elem::build(), libMesh::EDGE2, libMesh::QUAD4, libMesh::Elem::set_node(), and libMesh::Elem::subdomain_id().

42  {
43  _mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
44 
45  // (0,1) (1,1)
46  // x---------------x
47  // | |
48  // | |
49  // | |
50  // | |
51  // | |
52  // x---------------x
53  // (0,0) (1,0)
54  // | |
55  // | |
56  // | |
57  // | |
58  // x---------------x
59  // (0,-1) (1,-1)
60 
61  _mesh->set_mesh_dimension(2);
62 
63  _mesh->add_point( Point(0.0,-1.0), 4 );
64  _mesh->add_point( Point(1.0,-1.0), 5 );
65  _mesh->add_point( Point(1.0, 0.0), 1 );
66  _mesh->add_point( Point(1.0, 1.0), 2 );
67  _mesh->add_point( Point(0.0, 1.0), 3 );
68  _mesh->add_point( Point(0.0, 0.0), 0 );
69 
70  {
71  Elem * elem_top = _mesh->add_elem(Elem::build(QUAD4));
72  elem_top->set_node(0) = _mesh->node_ptr(0);
73  elem_top->set_node(1) = _mesh->node_ptr(1);
74  elem_top->set_node(2) = _mesh->node_ptr(2);
75  elem_top->set_node(3) = _mesh->node_ptr(3);
76 
77  Elem * elem_bottom = _mesh->add_elem(Elem::build(QUAD4));
78  elem_bottom->set_node(0) = _mesh->node_ptr(4);
79  elem_bottom->set_node(1) = _mesh->node_ptr(5);
80  elem_bottom->set_node(2) = _mesh->node_ptr(1);
81  elem_bottom->set_node(3) = _mesh->node_ptr(0);
82 
83  Elem * edge = _mesh->add_elem(Elem::build(EDGE2));
84  edge->set_node(0) = _mesh->node_ptr(0);
85  edge->set_node(1) = _mesh->node_ptr(1);
86 
87  // 2D elements will have subdomain id 0, this one will have 1
88  edge->subdomain_id() = 1;
89  }
90 
91  _mesh->allow_renumbering(true);
92  _mesh->prepare_for_use();
93  }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2381
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
subdomain_id_type subdomain_id() const
Definition: elem.h:2391
std::unique_ptr< ReplicatedMesh > _mesh
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ CPPUNIT_TEST() [1/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testMesh  )

◆ CPPUNIT_TEST() [2/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testDofOrdering  )

◆ CPPUNIT_TEST() [3/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testPointLocatorTree  )

◆ CPPUNIT_TEST_SUITE_END()

MixedDimensionMeshTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

MixedDimensionMeshTest::LIBMESH_CPPUNIT_TEST_SUITE ( MixedDimensionMeshTest  )

The goal of this test is to ensure that a 2D mesh with 1D elements overlapping on the edge is consistent.

That is, they share the same global node numbers and the same dof numbers for a variable.

◆ setUp()

void MixedDimensionMeshTest::setUp ( )
inline

Definition at line 96 of file mixed_dim_mesh_test.C.

97  {
98 #if LIBMESH_DIM > 1
99  this->build_mesh();
100 #endif
101  }

◆ tearDown()

void MixedDimensionMeshTest::tearDown ( )
inline

Definition at line 103 of file mixed_dim_mesh_test.C.

103 {}

◆ testDofOrdering()

void MixedDimensionMeshTest::testDofOrdering ( )
inline

Definition at line 135 of file mixed_dim_mesh_test.C.

References libMesh::EquationSystems::add_system(), libMesh::DofMap::dof_indices(), libMesh::FIRST, libMesh::EquationSystems::get_system(), and libMesh::EquationSystems::init().

136  {
137  LOG_UNIT_TEST;
138 
139  EquationSystems es(*_mesh);
140  es.add_system<LinearImplicitSystem>("TestDofSystem");
141  es.get_system("TestDofSystem").add_variable("u",FIRST);
142  es.init();
143 
144  DofMap& dof_map = es.get_system("TestDofSystem").get_dof_map();
145 
146  std::vector<dof_id_type> top_quad_dof_indices, bottom_quad_dof_indices, edge_dof_indices;
147 
148  dof_map.dof_indices( _mesh->elem_ptr(0), top_quad_dof_indices );
149  dof_map.dof_indices( _mesh->elem_ptr(1), bottom_quad_dof_indices );
150  dof_map.dof_indices( _mesh->elem_ptr(2), edge_dof_indices );
151 
152  /* The dofs for the EDGE2 element should be the same
153  as the bottom edge of the top QUAD4 dofs */
154  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], top_quad_dof_indices[0] );
155  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], top_quad_dof_indices[1] );
156 
157  /* The dofs for the EDGE2 element should be the same
158  as the top edge of the bottom QUAD4 dofs */
159  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], bottom_quad_dof_indices[3] );
160  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], bottom_quad_dof_indices[2] );
161 
162  /* The nodes for the bottom edge of the top QUAD4 element should have
163  the same global ids as the top edge of the bottom QUAD4 element */
164  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[0], bottom_quad_dof_indices[3] );
165  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[1], bottom_quad_dof_indices[2] );
166  }
This is the EquationSystems class.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1992
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:169
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1305
std::unique_ptr< ReplicatedMesh > _mesh

◆ testMesh()

void MixedDimensionMeshTest::testMesh ( )
inline

Definition at line 105 of file mixed_dim_mesh_test.C.

106  {
107  LOG_UNIT_TEST;
108 
109  // There'd better be 3 elements
110  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(3), _mesh->n_elem());
111 
112  // There'd better be only 6 nodes
113  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(6), _mesh->n_nodes());
114 
115  /* The nodes for the EDGE2 element should have the same global ids
116  as the bottom edge of the top QUAD4 element */
117  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(0), _mesh->elem_ref(0).node_id(0) );
118  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(1), _mesh->elem_ref(0).node_id(1) );
119 
120  /* The nodes for the EDGE2 element should have the same global ids
121  as the top edge of the bottom QUAD4 element */
122  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(0), _mesh->elem_ref(1).node_id(3) );
123  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(1), _mesh->elem_ref(1).node_id(2) );
124 
125  /* The nodes for the bottom edge of the top QUAD4 element should have
126  the same global ids as the top edge of the bottom QUAD4 element */
127  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(0).node_id(0), _mesh->elem_ref(1).node_id(3) );
128  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(0).node_id(1), _mesh->elem_ref(1).node_id(2) );
129 
130  // We didn't set an interior_parent on the edge element, so it
131  // should default to NULL
132  CPPUNIT_ASSERT( _mesh->elem_ref(2).interior_parent() );
133  }
std::unique_ptr< ReplicatedMesh > _mesh

◆ testPointLocatorTree()

void MixedDimensionMeshTest::testPointLocatorTree ( )
inline

Definition at line 168 of file mixed_dim_mesh_test.C.

References libMesh::DofObject::id().

169  {
170  LOG_UNIT_TEST;
171 
172  std::unique_ptr<PointLocatorBase> locator = _mesh->sub_point_locator();
173 
174  Point top_point(0.5, 0.5);
175  const Elem* top_elem = (*locator)(top_point);
176  CPPUNIT_ASSERT(top_elem);
177 
178  // We should have gotten back the top quad
179  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(0), top_elem->id());
180 
181  Point bottom_point(0.5, -0.5);
182  const Elem* bottom_elem = (*locator)(bottom_point);
183  CPPUNIT_ASSERT(bottom_elem);
184 
185  // We should have gotten back the bottom quad
186  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(1), bottom_elem->id());
187 
188  // Test getting back the edge
189  {
190  std::set<subdomain_id_type> subdomain_id; subdomain_id.insert(1);
191  Point interface_point( 0.5, 0.0 );
192  const Elem* interface_elem = (*locator)(interface_point, &subdomain_id);
193  CPPUNIT_ASSERT(interface_elem);
194 
195  // We should have gotten back the overlapping edge element
196  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(2), interface_elem->id());
197  }
198  }
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
dof_id_type id() const
Definition: dof_object.h:823
std::unique_ptr< ReplicatedMesh > _mesh
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

Member Data Documentation

◆ _mesh

std::unique_ptr<ReplicatedMesh> MixedDimensionMeshTest::_mesh
protected

Definition at line 39 of file mixed_dim_mesh_test.C.


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