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 32 of file mixed_dim_mesh_test.C.

Member Function Documentation

void MixedDimensionMeshTest::build_mesh ( )
protected

Definition at line 51 of file mixed_dim_mesh_test.C.

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.

52  {
54 
55  // (0,1) (1,1)
56  // x---------------x
57  // | |
58  // | |
59  // | |
60  // | |
61  // | |
62  // x---------------x
63  // (0,0) (1,0)
64  // | |
65  // | |
66  // | |
67  // | |
68  // x---------------x
69  // (0,-1) (1,-1)
70 
72 
73  _mesh->add_point( Point(0.0,-1.0), 4 );
74  _mesh->add_point( Point(1.0,-1.0), 5 );
75  _mesh->add_point( Point(1.0, 0.0), 1 );
76  _mesh->add_point( Point(1.0, 1.0), 2 );
77  _mesh->add_point( Point(0.0, 1.0), 3 );
78  _mesh->add_point( Point(0.0, 0.0), 0 );
79 
80  {
81  Elem* elem_top = _mesh->add_elem( new Quad4 );
82  elem_top->set_node(0) = _mesh->node_ptr(0);
83  elem_top->set_node(1) = _mesh->node_ptr(1);
84  elem_top->set_node(2) = _mesh->node_ptr(2);
85  elem_top->set_node(3) = _mesh->node_ptr(3);
86 
87  Elem* elem_bottom = _mesh->add_elem( new Quad4 );
88  elem_bottom->set_node(0) = _mesh->node_ptr(4);
89  elem_bottom->set_node(1) = _mesh->node_ptr(5);
90  elem_bottom->set_node(2) = _mesh->node_ptr(1);
91  elem_bottom->set_node(3) = _mesh->node_ptr(0);
92 
93  Elem* edge = _mesh->add_elem( new Edge2 );
94  edge->set_node(0) = _mesh->node_ptr(0);
95  edge->set_node(1) = _mesh->node_ptr(1);
96 
97  // 2D elements will have subdomain id 0, this one will have 1
98  edge->subdomain_id() = 1;
99  }
100 
101  // libMesh will renumber, but we numbered according to its scheme
102  // anyway. We do this because when we call uniformly_refine subsequently,
103  // it's going use skip_renumber=false.
104  _mesh->prepare_for_use(false /*skip_renumber*/);
105  }
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) libmesh_override
functions for adding /deleting nodes elements.
virtual const Node * node_ptr(const dof_id_type i) const libmesh_override
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1941
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:49
virtual Elem * add_elem(Elem *e) libmesh_override
Add elem e to the end of the element array.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
subdomain_id_type subdomain_id() const
Definition: elem.h:1951
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
Definition: mesh_base.h:199
The Edge2 is an element in 1D composed of 2 nodes.
Definition: edge_edge2.h:43
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
MixedDimensionMeshTest::CPPUNIT_TEST ( testMesh  )
MixedDimensionMeshTest::CPPUNIT_TEST ( testDofOrdering  )
MixedDimensionMeshTest::CPPUNIT_TEST ( testPointLocatorTree  )
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.

MixedDimensionMeshTest::CPPUNIT_TEST_SUITE_END ( )
void MixedDimensionMeshTest::setUp ( )

Definition at line 108 of file mixed_dim_mesh_test.C.

109  {
110  this->build_mesh();
111  }
void MixedDimensionMeshTest::tearDown ( )

Definition at line 113 of file mixed_dim_mesh_test.C.

114  {
115  delete _mesh;
116  }
void MixedDimensionMeshTest::testDofOrdering ( )

Definition at line 146 of file mixed_dim_mesh_test.C.

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

147  {
148  EquationSystems es(*_mesh);
149  es.add_system<LinearImplicitSystem>("TestDofSystem");
150  es.get_system("TestDofSystem").add_variable("u",FIRST);
151  es.init();
152 
153  DofMap& dof_map = es.get_system("TestDofSystem").get_dof_map();
154 
155  std::vector<dof_id_type> top_quad_dof_indices, bottom_quad_dof_indices, edge_dof_indices;
156 
157  dof_map.dof_indices( _mesh->elem_ptr(0), top_quad_dof_indices );
158  dof_map.dof_indices( _mesh->elem_ptr(1), bottom_quad_dof_indices );
159  dof_map.dof_indices( _mesh->elem_ptr(2), edge_dof_indices );
160 
161  /* The dofs for the EDGE2 element should be the same
162  as the bottom edge of the top QUAD4 dofs */
163  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], top_quad_dof_indices[0] );
164  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], top_quad_dof_indices[1] );
165 
166  /* The dofs for the EDGE2 element should be the same
167  as the top edge of the bottom QUAD4 dofs */
168  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[0], bottom_quad_dof_indices[3] );
169  CPPUNIT_ASSERT_EQUAL( edge_dof_indices[1], bottom_quad_dof_indices[2] );
170 
171  /* The nodes for the bottom edge of the top QUAD4 element should have
172  the same global ids as the top edge of the bottom QUAD4 element */
173  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[0], bottom_quad_dof_indices[3] );
174  CPPUNIT_ASSERT_EQUAL( top_quad_dof_indices[1], bottom_quad_dof_indices[2] );
175  }
virtual const Elem * elem_ptr(const dof_id_type i) const libmesh_override
This is the EquationSystems class.
This class provides a specific system class.
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:167
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:1917
void MixedDimensionMeshTest::testMesh ( )

Definition at line 118 of file mixed_dim_mesh_test.C.

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

119  {
120  // There'd better be 3 elements
121  CPPUNIT_ASSERT_EQUAL( (dof_id_type)3, _mesh->n_elem() );
122 
123  // There'd better be only 6 nodes
124  CPPUNIT_ASSERT_EQUAL( (dof_id_type)6, _mesh->n_nodes() );
125 
126  /* The nodes for the EDGE2 element should have the same global ids
127  as the bottom edge of the top QUAD4 element */
128  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(0), _mesh->elem_ref(0).node_id(0) );
129  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(1), _mesh->elem_ref(0).node_id(1) );
130 
131  /* The nodes for the EDGE2 element should have the same global ids
132  as the top edge of the bottom QUAD4 element */
133  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(0), _mesh->elem_ref(1).node_id(3) );
134  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(2).node_id(1), _mesh->elem_ref(1).node_id(2) );
135 
136  /* The nodes for the bottom edge of the top QUAD4 element should have
137  the same global ids as the top edge of the bottom QUAD4 element */
138  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(0).node_id(0), _mesh->elem_ref(1).node_id(3) );
139  CPPUNIT_ASSERT_EQUAL( _mesh->elem_ref(0).node_id(1), _mesh->elem_ref(1).node_id(2) );
140 
141  // We didn't set an interior_parent on the edge element, so it
142  // should default to NULL
143  CPPUNIT_ASSERT( _mesh->elem_ref(2).interior_parent() );
144  }
const Elem * interior_parent() const
Definition: elem.C:951
virtual dof_id_type n_elem() const libmesh_override
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:490
virtual dof_id_type n_nodes() const libmesh_override
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1831
uint8_t dof_id_type
Definition: id_types.h:64
void MixedDimensionMeshTest::testPointLocatorTree ( )

Definition at line 177 of file mixed_dim_mesh_test.C.

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

178  {
180 
181  Point top_point(0.5, 0.5);
182  const Elem* top_elem = (*locator)(top_point);
183  CPPUNIT_ASSERT(top_elem);
184 
185  // We should have gotten back the top quad
186  CPPUNIT_ASSERT_EQUAL( (dof_id_type)0, top_elem->id() );
187 
188  Point bottom_point(0.5, -0.5);
189  const Elem* bottom_elem = (*locator)(bottom_point);
190  CPPUNIT_ASSERT(bottom_elem);
191 
192  // We should have gotten back the bottom quad
193  CPPUNIT_ASSERT_EQUAL( (dof_id_type)1, bottom_elem->id() );
194 
195  // Test getting back the edge
196  {
197  std::set<subdomain_id_type> subdomain_id; subdomain_id.insert(1);
198  Point interface_point( 0.5, 0.0 );
199  const Elem* interface_elem = (*locator)(interface_point, &subdomain_id);
200  CPPUNIT_ASSERT(interface_elem);
201 
202  // We should have gotten back the overlapping edge element
203  CPPUNIT_ASSERT_EQUAL( (dof_id_type)2, interface_elem->id() );
204  }
205  }
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
dof_id_type id() const
Definition: dof_object.h:632
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
uint8_t dof_id_type
Definition: id_types.h:64

Member Data Documentation

ReplicatedMesh* MixedDimensionMeshTest::_mesh
protected

Definition at line 49 of file mixed_dim_mesh_test.C.


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