libMesh
Loading...
Searching...
No Matches
mesh_base_test.C
Go to the documentation of this file.
1
2#include <libmesh/distributed_mesh.h>
3#include <libmesh/elem.h>
4#include <libmesh/mesh.h>
5#include <libmesh/mesh_generation.h>
6#include <libmesh/mesh_refinement.h>
7#include <libmesh/mesh_tools.h>
8#include <libmesh/replicated_mesh.h>
9
10#include "test_comm.h"
11#include "libmesh_cppunit.h"
12
13using namespace libMesh;
14
15class MeshBaseTest : public CppUnit::TestCase {
20public:
22
23/* Tests need a 2d mesh */
24#if LIBMESH_DIM > 1
37#endif
38
40
41public:
42
43 void setUp() {}
44
45 void tearDown() {}
46
48 {
54 2, 2,
55 0., 1.,
56 0., 1.,
57 QUAD9);
58
59 // Break some neighbor links. Of course nobody would do this in
60 // real life, right?
61 Elem * elem0 = mesh.query_elem_ptr(0);
62 if (elem0)
63 for (auto n : elem0->side_index_range())
64 {
65 Elem * neigh = elem0->neighbor_ptr(n);
66 if (!neigh)
67 continue;
68 auto n_neigh = neigh->which_neighbor_am_i(elem0);
69 CPPUNIT_ASSERT(n_neigh != libMesh::invalid_uint);
70
71 elem0->set_neighbor(n, nullptr);
72 neigh->set_neighbor(n_neigh, nullptr);
73 }
74 }
75
84
90
96
102
104 {
110 2, 2,
111 0., 1.,
112 0., 1.,
113 QUAD9);
114
115 // Invalidate the subdomain ids cache
116 Elem * elem0 = mesh.query_elem_ptr(0);
117 if (elem0)
118 elem0->subdomain_id() = 1;
119
120 // We're unprepared (prepare_for_use() will update that cache) but
121 // we're not marked that way.
122 CPPUNIT_ASSERT(!MeshTools::valid_is_prepared(mesh));
123
126 CPPUNIT_ASSERT(mesh.is_prepared());
127 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
128 }
129
135
141
147
149 {
155 2, 2,
156 0., 1.,
157 0., 1.,
158 QUAD9);
159
160 // Remove elements on one side, orphaning 4 nodes and removing one
161 // boundary condition. Remove dangling neighbor pointers too; we
162 // can't even clone a mesh with dangling pointers.
163 for (auto & elem : mesh.element_ptr_range())
164 if (elem->vertex_average()(0) > 0.5)
165 mesh.delete_elem(elem);
166 else
167 elem->set_neighbor(1, nullptr);
168
169 // We're unprepared (prepare_for_use() will remove those orphaned
170 // nodes and fix the boundary id sets and fix the partitioning of
171 // nodes that might need new owners) but we're not marked that
172 // way.
173 CPPUNIT_ASSERT(!MeshTools::valid_is_prepared(mesh));
174
179 CPPUNIT_ASSERT(mesh.is_prepared());
180 CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
181 }
182
188
194
200
202 {
203 this->BrokenNeighborMesh(mesh);
204
205 // We're unprepared (prepare_for_use() will restitch those
206 // neighbor pointers) but we're not marked that way.
207 CPPUNIT_ASSERT(!MeshTools::valid_is_prepared(mesh));
208 }
209
215
221
227}; // End definition of class MeshBaseTest
228
void testDistributedMeshVerifyHasNeighborPtrs()
void testReplicatedMeshVerifyHasNeighborPtrs()
void testMeshBaseVerifyHasNeighborPtrs(UnstructuredMesh &mesh)
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(testReplicatedMeshVerifyRemovalPreparation)
CPPUNIT_TEST(testMeshVerifyHasCachedElemData)
void testMeshBaseVerifyRemovalPreparation(UnstructuredMesh &mesh)
void testMeshVerifyRemovalPreparation()
CPPUNIT_TEST(testReplicatedMeshVerifyHasCachedElemData)
LIBMESH_CPPUNIT_TEST_SUITE(MeshBaseTest)
This test verifies various operations on the MeshBase and derived classes.
void testMeshVerifyHasCachedElemData()
CPPUNIT_TEST(testDistributedMeshVerifyIsPrepared)
CPPUNIT_TEST(testReplicatedMeshVerifyHasNeighborPtrs)
void testReplicatedMeshVerifyRemovalPreparation()
CPPUNIT_TEST(testDistributedMeshVerifyHasNeighborPtrs)
CPPUNIT_TEST(testDistributedMeshVerifyHasCachedElemData)
void testDistributedMeshVerifyIsPrepared()
CPPUNIT_TEST(testReplicatedMeshVerifyIsPrepared)
void testDistributedMeshVerifyRemovalPreparation()
void testMeshBaseVerifyHasCachedElemData(UnstructuredMesh &mesh)
void testReplicatedMeshVerifyIsPrepared()
void testDistributedMeshVerifyHasCachedElemData()
void BrokenNeighborMesh(UnstructuredMesh &mesh)
CPPUNIT_TEST(testDistributedMeshVerifyRemovalPreparation)
CPPUNIT_TEST(testMeshVerifyIsPrepared)
void testMeshBaseVerifyIsPrepared(UnstructuredMesh &mesh)
CPPUNIT_TEST(testMeshVerifyRemovalPreparation)
CPPUNIT_TEST(testMeshVerifyHasNeighborPtrs)
void testMeshVerifyIsPrepared()
void testReplicatedMeshVerifyHasCachedElemData()
void testMeshVerifyHasNeighborPtrs()
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
This is the base class from which all geometric element types are derived.
Definition elem.h:96
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
Definition elem.h:2635
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition elem.h:2936
subdomain_id_type subdomain_id() const
Definition elem.h:2591
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2615
IntRange< unsigned short > side_index_range() const
Definition elem.h:2727
bool is_prepared() const
Definition mesh_base.C:1064
void complete_preparation()
Definition mesh_base.C:874
void unset_has_neighbor_ptrs()
Tells this we have done some operation (e.g.
Definition mesh_base.h:270
void unset_has_boundary_id_sets()
Tells this we have done some operation which may have invalidated our cached boundary id sets.
Definition mesh_base.h:340
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
void unset_has_removed_orphaned_nodes()
Tells this we have done some operation (e.g.
Definition mesh_base.h:318
void unset_is_partitioned()
Tells this we have done some operation creating unpartitioned elements.
Definition mesh_base.h:246
void unset_has_cached_elem_data()
Tells this we have done some operation (e.g.
Definition mesh_base.h:281
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
The UnstructuredMesh class is derived from the MeshBase class.
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(MeshBaseTest)
MeshBase & mesh
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
bool valid_is_prepared(const MeshBase &mesh)
A function for testing whether a mesh's cached is_prepared() setting is not a false positive.
The libMesh namespace provides an interface to certain functionality in the library.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303