libMesh
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 
13 using namespace libMesh;
14 
15 class MeshBaseTest : public CppUnit::TestCase {
20 public:
21  LIBMESH_CPPUNIT_TEST_SUITE( MeshBaseTest );
22 
23 /* Tests need a 2d mesh */
24 #if LIBMESH_DIM > 1
25  CPPUNIT_TEST( testDistributedMeshVerifyIsPrepared );
26  CPPUNIT_TEST( testMeshVerifyIsPrepared );
27  CPPUNIT_TEST( testReplicatedMeshVerifyIsPrepared );
28 #endif
29 
30  CPPUNIT_TEST_SUITE_END();
31 
32 public:
33 
34  void setUp() {}
35 
36  void tearDown() {}
37 
39  {
45  2, 2,
46  0., 1.,
47  0., 1.,
48  QUAD9);
49 
50  // build_square does its own prepare_for_use(), so we should be
51  // prepared.
52  CPPUNIT_ASSERT(MeshTools::valid_is_prepared(mesh));
53 
54  // Break some neighbor links. Of course nobody would do this in
55  // real life, right?
56  Elem * elem0 = mesh.query_elem_ptr(0);
57  if (elem0)
58  for (auto n : elem0->side_index_range())
59  {
60  Elem * neigh = elem0->neighbor_ptr(n);
61  if (!neigh)
62  continue;
63  auto n_neigh = neigh->which_neighbor_am_i(elem0);
64  CPPUNIT_ASSERT(n_neigh != libMesh::invalid_uint);
65 
66  elem0->set_neighbor(n, nullptr);
67  neigh->set_neighbor(n_neigh, nullptr);
68  }
69 
70  // We're unprepared (prepare_for_use() will restitch those
71  // neighbor pointers) but we're not marked that way.
72  CPPUNIT_ASSERT(!MeshTools::valid_is_prepared(mesh));
73  }
74 
76  {
78  testMeshBaseVerifyIsPrepared(mesh);
79  }
80 
82  {
84  testMeshBaseVerifyIsPrepared(mesh);
85  }
86 
88  {
90  testMeshBaseVerifyIsPrepared(mesh);
91  }
92 }; // End definition of class MeshBaseTest
93 
CPPUNIT_TEST_SUITE_REGISTRATION(MeshBaseTest)
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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:310
void testMeshBaseVerifyIsPrepared(UnstructuredMesh &mesh)
IntRange< unsigned short > side_index_range() const
Definition: elem.h:2710
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
bool valid_is_prepared(const MeshBase &mesh)
A function for testing whether a mesh&#39;s cached is_prepared() setting is not a false positive...
Definition: mesh_tools.C:1182
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
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.
The libMesh namespace provides an interface to certain functionality in the library.
The UnstructuredMesh class is derived from the MeshBase class.
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition: elem.h:2919
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
Definition: elem.h:2618
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
void testMeshVerifyIsPrepared()
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2598
void testReplicatedMeshVerifyIsPrepared()
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
void testDistributedMeshVerifyIsPrepared()
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50