libMesh
mesh_extruder.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 #include <libmesh/libmesh.h>
8 #include <libmesh/replicated_mesh.h>
9 #include <libmesh/elem.h>
10 #include <libmesh/mesh_generation.h>
11 
12 #include "test_comm.h"
13 
14 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
15 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
16 // warnings. These can be ignored in GCC as long as we wrap the
17 // offending code in appropriate pragmas. We can't get away with a
18 // single ignore_warnings.h inclusion at the beginning of this file,
19 // since the libmesh headers pull in a restore_warnings.h at some
20 // point. We also don't bother restoring warnings at the end of this
21 // file since it's not a header.
22 #include <libmesh/ignore_warnings.h>
23 
24 using namespace libMesh;
25 
26 class MeshExtruderTest : public CppUnit::TestCase
27 {
34 public:
35  CPPUNIT_TEST_SUITE( MeshExtruderTest );
36 
37  CPPUNIT_TEST( testExtruder );
38 
39  CPPUNIT_TEST_SUITE_END();
40 
41 protected:
42 
44  {
46  virtual subdomain_id_type get_subdomain_for_layer(const Elem * old_elem, unsigned int layer)
47  {
48  // This method will assign an new id based on the old element and the layer
49  return old_elem->subdomain_id() + layer;
50  }
51  };
52 
53 public:
54  void setUp() {}
55 
56  void tearDown() {}
57 
58  void testExtruder()
59  {
60  ReplicatedMesh src_mesh(*TestCommWorld, /*dim=*/2);
61 
62  const unsigned int n_elems_per_side = 4;
63  const unsigned int num_layers = 4;
64  const unsigned int n_elems_per_layer = n_elems_per_side * n_elems_per_side;
65 
66 
67  MeshTools::Generation::build_square(src_mesh, n_elems_per_side, n_elems_per_side);
68  for (unsigned int i=0; i<n_elems_per_layer; ++i)
69  {
70  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
71  Elem & elem = src_mesh.elem_ref(i);
72  elem.subdomain_id() = i;
73  }
74 
75  ReplicatedMesh dest_mesh(*TestCommWorld, /*dim=*/3);
76 
77  RealVectorValue extrusion_vector(0, 0, 1);
78 
79  QueryElemSubdomainID new_elem_subdomain_id;
80 
85  MeshTools::Generation::build_extrusion(dest_mesh, src_mesh, num_layers, extrusion_vector, &new_elem_subdomain_id);
86 
87  for (unsigned int i=0; i<n_elems_per_layer * num_layers; ++i)
88  {
89  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
90  Elem & elem = dest_mesh.elem_ref(i);
91 
92  CPPUNIT_ASSERT_EQUAL((unsigned int)elem.subdomain_id(), i%n_elems_per_layer + i/n_elems_per_layer /* integer division */);
93  }
94  }
95 };
96 
97 
Class for receiving the callback during extrusion generation and providing user-defined subdomains ba...
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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 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.
virtual subdomain_id_type get_subdomain_for_layer(const Elem *old_elem, unsigned int layer)
The override from the base class for obtaining a new id based on the old (original) element and the s...
Definition: mesh_extruder.C:46
The libMesh namespace provides an interface to certain functionality in the library.
subdomain_id_type subdomain_id() const
Definition: elem.h:1951
void build_extrusion(UnstructuredMesh &mesh, const MeshBase &cross_section, const unsigned int nz, RealVectorValue extrusion_vector, QueryElemSubdomainIDBase *elem_subdomain=libmesh_nullptr)
Meshes the tensor product of a 1D and a 1D-or-2D domain.
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:490
CPPUNIT_TEST_SUITE_REGISTRATION(MeshExtruderTest)