libMesh
mesh_deletions.C
Go to the documentation of this file.
1 #include <libmesh/distributed_mesh.h>
2 #include <libmesh/elem.h>
3 #include "libmesh/enum_partitioner_type.h"
4 #include <libmesh/mesh_generation.h>
5 #include <libmesh/parallel.h>
6 #include <libmesh/partitioner.h>
7 #include <libmesh/replicated_mesh.h>
8 
9 #include "test_comm.h"
10 #include "libmesh_cppunit.h"
11 
12 using namespace libMesh;
13 
14 class MeshDeletionsTest : public CppUnit::TestCase {
19 public:
20  LIBMESH_CPPUNIT_TEST_SUITE( MeshDeletionsTest );
21 
22 #if LIBMESH_DIM > 1
23  CPPUNIT_TEST( testDeleteElemReplicated );
24  CPPUNIT_TEST( testDeleteElemDistributed );
25 #endif
26 
27  CPPUNIT_TEST_SUITE_END();
28 
29 protected:
30 
31 public:
32  void setUp()
33  {
34  }
35 
36  void tearDown()
37  {
38  }
39 
41  {
42  LOG_UNIT_TEST;
43 
44  // Let's not trust Metis or Parmetis to give us a replicable test
45  // case.
47 
49  3, 3,
50  0., 1.,
51  0., 1.,
52  QUAD4);
53 
54  std::vector<std::vector<int>> deletions =
55  {{1, 2, 4}, {0, 3}, {0, 2}, {1}};
56  dof_id_type n_elem = 9;
57  for (auto deletionset : deletions)
58  {
59  for (int e : deletionset)
60  {
61  --n_elem;
62  Elem * elem = mesh.query_elem_ptr(e);
63  if (elem)
64  {
65  elem->remove_links_to_me();
66  mesh.delete_elem(elem);
67  }
68  }
69 
71 
72  CPPUNIT_ASSERT_EQUAL(mesh.n_elem(), n_elem);
73  }
74  }
75 
77  {
78  LOG_UNIT_TEST;
80  testDeleteElem(mesh);
81  }
82 
84  {
85  LOG_UNIT_TEST;
87  testDeleteElem(mesh);
88  }
89 };
90 
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:969
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:759
void testDeleteElemDistributed()
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each prepare_for_use()
Definition: mesh_base.h:160
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.
void remove_links_to_me()
Resets this element&#39;s neighbors&#39; appropriate neighbor pointers and its parent&#39;s and children&#39;s approp...
Definition: elem.C:1639
virtual void delete_elem(Elem *e)=0
Removes element e from the mesh.
static std::unique_ptr< Partitioner > build(const PartitionerType solver_package)
Builds a Partitioner of the type specified by partitioner_type.
Definition: partitioner.C:159
The UnstructuredMesh class is derived from the MeshBase class.
The DistributedMesh class is derived from the MeshBase class, and is intended to provide identical fu...
CPPUNIT_TEST_SUITE_REGISTRATION(MeshDeletionsTest)
void testDeleteElemReplicated()
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual dof_id_type n_elem() const =0
uint8_t dof_id_type
Definition: id_types.h:67
void testDeleteElem(UnstructuredMesh &mesh)