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

Public Member Functions

 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

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.

42  {
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 
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( new 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( new 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( new 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  // libMesh will renumber, but we numbered according to its scheme
92  // anyway. We do this because when we call uniformly_refine subsequently,
93  // it's going use skip_renumber=false.
94  _mesh->prepare_for_use(false /*skip_renumber*/);
95  }

References libMesh::ReplicatedMesh::add_elem(), libMesh::ReplicatedMesh::add_point(), libMesh::ReplicatedMesh::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::Elem::subdomain_id(), and TestCommWorld.

◆ CPPUNIT_TEST() [1/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testDofOrdering  )

◆ CPPUNIT_TEST() [2/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testMesh  )

◆ CPPUNIT_TEST() [3/3]

MixedDimensionMeshTest::CPPUNIT_TEST ( testPointLocatorTree  )

◆ CPPUNIT_TEST_SUITE()

MixedDimensionMeshTest::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.

◆ CPPUNIT_TEST_SUITE_END()

MixedDimensionMeshTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void MixedDimensionMeshTest::setUp ( )
inline

Definition at line 98 of file mixed_dim_mesh_test.C.

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

◆ tearDown()

void MixedDimensionMeshTest::tearDown ( )
inline

Definition at line 105 of file mixed_dim_mesh_test.C.

106  {
107  delete _mesh;
108  }

◆ testDofOrdering()

void MixedDimensionMeshTest::testDofOrdering ( )
inline

Definition at line 138 of file mixed_dim_mesh_test.C.

139  {
140  EquationSystems es(*_mesh);
141  es.add_system<LinearImplicitSystem>("TestDofSystem");
142  es.get_system("TestDofSystem").add_variable("u",FIRST);
143  es.init();
144 
145  DofMap& dof_map = es.get_system("TestDofSystem").get_dof_map();
146 
147  std::vector<dof_id_type> top_quad_dof_indices, bottom_quad_dof_indices, edge_dof_indices;
148 
149  dof_map.dof_indices( _mesh->elem_ptr(0), top_quad_dof_indices );
150  dof_map.dof_indices( _mesh->elem_ptr(1), bottom_quad_dof_indices );
151  dof_map.dof_indices( _mesh->elem_ptr(2), edge_dof_indices );
152 
153  /* The dofs for the EDGE2 element should be the same
154  as the bottom edge of the top QUAD4 dofs */
155  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], top_quad_dof_indices[0] );
156  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], top_quad_dof_indices[1] );
157 
158  /* The dofs for the EDGE2 element should be the same
159  as the top edge of the bottom QUAD4 dofs */
160  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], bottom_quad_dof_indices[3] );
161  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], bottom_quad_dof_indices[2] );
162 
163  /* The nodes for the bottom edge of the top QUAD4 element should have
164  the same global ids as the top edge of the bottom QUAD4 element */
165  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[0], bottom_quad_dof_indices[3] );
166  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[1], bottom_quad_dof_indices[2] );
167  }

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

◆ testMesh()

void MixedDimensionMeshTest::testMesh ( )
inline

Definition at line 110 of file mixed_dim_mesh_test.C.

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

References libMesh::MeshBase::elem_ref(), libMesh::Elem::interior_parent(), libMesh::ReplicatedMesh::n_elem(), libMesh::ReplicatedMesh::n_nodes(), and libMesh::Elem::node_id().

◆ testPointLocatorTree()

void MixedDimensionMeshTest::testPointLocatorTree ( )
inline

Definition at line 169 of file mixed_dim_mesh_test.C.

170  {
171  std::unique_ptr<PointLocatorBase> locator = _mesh->sub_point_locator();
172 
173  Point top_point(0.5, 0.5);
174  const Elem* top_elem = (*locator)(top_point);
175  CPPUNIT_ASSERT(top_elem);
176 
177  // We should have gotten back the top quad
178  CPPUNIT_ASSERT_EQUAL( (dof_id_type)0, top_elem->id() );
179 
180  Point bottom_point(0.5, -0.5);
181  const Elem* bottom_elem = (*locator)(bottom_point);
182  CPPUNIT_ASSERT(bottom_elem);
183 
184  // We should have gotten back the bottom quad
185  CPPUNIT_ASSERT_EQUAL( (dof_id_type)1, bottom_elem->id() );
186 
187  // Test getting back the edge
188  {
189  std::set<subdomain_id_type> subdomain_id; subdomain_id.insert(1);
190  Point interface_point( 0.5, 0.0 );
191  const Elem* interface_elem = (*locator)(interface_point, &subdomain_id);
192  CPPUNIT_ASSERT(interface_elem);
193 
194  // We should have gotten back the overlapping edge element
195  CPPUNIT_ASSERT_EQUAL( (dof_id_type)2, interface_elem->id() );
196  }
197  }

References libMesh::DofObject::id(), and libMesh::MeshBase::sub_point_locator().

Member Data Documentation

◆ _mesh

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:
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::DofMap::dof_indices
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:1967
libMesh::ReplicatedMesh::node_ptr
virtual const Node * node_ptr(const dof_id_type i) const override
Definition: replicated_mesh.C:182
libMesh::MeshBase::elem_ref
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:521
libMesh::ReplicatedMesh::add_elem
virtual Elem * add_elem(Elem *e) override
Add elem e to the end of the element array.
Definition: replicated_mesh.C:282
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
MixedDimensionMeshTest::build_mesh
void build_mesh()
Definition: mixed_dim_mesh_test.C:41
libMesh::System::add_variable
unsigned int add_variable(const std::string &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:1069
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::ReplicatedMesh::n_nodes
virtual dof_id_type n_nodes() const override
Definition: replicated_mesh.h:104
libMesh::Quad4
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:51
MixedDimensionMeshTest::_mesh
ReplicatedMesh * _mesh
Definition: mixed_dim_mesh_test.C:39
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::Elem::set_node
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2059
libMesh::Elem::interior_parent
const Elem * interior_parent() const
Definition: elem.C:749
libMesh::MeshBase::sub_point_locator
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:672
libMesh::ReplicatedMesh::n_elem
virtual dof_id_type n_elem() const override
Definition: replicated_mesh.h:116
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::Elem::subdomain_id
subdomain_id_type subdomain_id() const
Definition: elem.h:2069
libMesh::DofObject::id
dof_id_type id() const
Definition: dof_object.h:767
libMesh::ReplicatedMesh::elem_ptr
virtual const Elem * elem_ptr(const dof_id_type i) const override
Definition: replicated_mesh.C:232
libMesh::Edge2
The Edge2 is an element in 1D composed of 2 nodes.
Definition: edge_edge2.h:43
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::Elem::node_id
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1977
libMesh::MeshBase::prepare_for_use
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:318
libMesh::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
libMesh::MeshBase::set_mesh_dimension
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
Definition: mesh_base.h:218
libMesh::FIRST
Definition: enum_order.h:42
libMesh::ReplicatedMesh::add_point
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id) override
functions for adding /deleting nodes elements.
Definition: replicated_mesh.C:417