libMesh
mesh_collection.C
Go to the documentation of this file.
1 #include <libmesh/replicated_mesh.h>
2 #include <libmesh/distributed_mesh.h>
3 #include <libmesh/mesh_generation.h>
4 #include <libmesh/libmesh_config.h>
5 #include <libmesh/mesh_modification.h>
6 
7 #include "test_comm.h"
8 #include "libmesh_cppunit.h"
9 
10 using namespace libMesh;
11 
12 class CopyNodesAndElementsTest : public CppUnit::TestCase
13 {
14 public:
15  LIBMESH_CPPUNIT_TEST_SUITE( CopyNodesAndElementsTest );
16 
17  CPPUNIT_TEST( replicatedCopy );
18  CPPUNIT_TEST( distributedCopy );
19 
20  CPPUNIT_TEST_SUITE_END();
21 
22 private:
23  template <typename T>
25  {
26  // to trigger duplicate unique ids in the old code, you needed the following circumstances:
27  // The single mesh generation routine (e.g. build_cube) *must* add a node after all the elements
28  // such that it is not an element that has the largest unique id in the single mesh. (build_cube
29  // with TET10 adds a node after all the elements are added because it calls all_second_order
30  // after all the elements are created.) If an element has the highest unique id, then the final
31  // value for _next_unique_id was (and still is) correct at the end of copy_nodes_and_elements
32  // because we set the element unique ids before adding the elements into the original mesh, such
33  // that _next_unique_id gets correctly updated. But when a node has the highest unique id, then
34  // _next_unique_id would be incorrect with the old code (but is now correct with the new code!)
35  // and after one mesh collection the value of parallel_max_unique_id() would be conceptually
36  // wrong, such that the next time we collected a mesh we would be at risk of duplicating unique
37  // ids
38  T mesh(*TestCommWorld, /*dim=*/3);
39  MeshTools::Generation::build_cube(mesh, 2, 2, 2, 0, 1, 0, 1, 0, 1, TET10);
40  Real dmin = 2, dmax = 3;
41  for (unsigned int num_other_meshes = 0; num_other_meshes < 2;
42  ++num_other_meshes, dmin += 2, dmax += 2)
43  {
44  T other_mesh(*TestCommWorld, 3);
46  other_mesh, 2, 2, 2, dmin, dmax, dmin, dmax, dmin, dmax, TET10);
47  dof_id_type node_delta = mesh.max_node_id();
48  dof_id_type elem_delta = mesh.max_elem_id();
49  unique_id_type unique_delta =
50 #ifdef LIBMESH_ENABLE_UNIQUE_ID
52 #else
53  0;
54 #endif
55  mesh.copy_nodes_and_elements(other_mesh, false, elem_delta, node_delta, unique_delta);
56  }
57  }
58 
59 public:
60  void setUp() {}
61 
62  void tearDown() {}
63 
64  void replicatedCopy() { LOG_UNIT_TEST; collectMeshes<ReplicatedMesh>(); }
65 
66  void distributedCopy() { LOG_UNIT_TEST; collectMeshes<DistributedMesh>(); }
67 };
68 
69 
virtual unique_id_type parallel_max_unique_id() const =0
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:171
MeshBase & mesh
The libMesh namespace provides an interface to certain functionality in the library.
virtual dof_id_type max_elem_id() const =0
CPPUNIT_TEST_SUITE_REGISTRATION(CopyNodesAndElementsTest)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual dof_id_type max_node_id() const =0
uint8_t unique_id_type
Definition: id_types.h:86
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
uint8_t dof_id_type
Definition: id_types.h:67