libMesh
mesh_extruder.C
Go to the documentation of this file.
1 #include <libmesh/libmesh.h>
2 #include <libmesh/replicated_mesh.h>
3 #include <libmesh/elem.h>
4 #include <libmesh/mesh_generation.h>
5 
6 #include "test_comm.h"
7 #include "libmesh_cppunit.h"
8 
9 
10 using namespace libMesh;
11 
12 class MeshExtruderTest : public CppUnit::TestCase
13 {
20 public:
21  CPPUNIT_TEST_SUITE( MeshExtruderTest );
22 
23 #if LIBMESH_DIM > 2
24  CPPUNIT_TEST( testExtruder );
25 #endif
26 
27  CPPUNIT_TEST_SUITE_END();
28 
29 protected:
30 
32  {
34  virtual subdomain_id_type get_subdomain_for_layer(const Elem * old_elem, unsigned int layer)
35  {
36  // This method will assign an new id based on the old element and the layer
37  return old_elem->subdomain_id() + layer;
38  }
39  };
40 
41 public:
42  void setUp() {}
43 
44  void tearDown() {}
45 
46  void testExtruder()
47  {
48  ReplicatedMesh src_mesh(*TestCommWorld, /*dim=*/2);
49 
50  const unsigned int n_elems_per_side = 4;
51  const unsigned int num_layers = 4;
52  const unsigned int n_elems_per_layer = n_elems_per_side * n_elems_per_side;
53 
54 
55  MeshTools::Generation::build_square(src_mesh, n_elems_per_side, n_elems_per_side);
56  for (unsigned int i=0; i<n_elems_per_layer; ++i)
57  {
58  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
59  Elem & elem = src_mesh.elem_ref(i);
60  elem.subdomain_id() = i;
61  }
62 
63  ReplicatedMesh dest_mesh(*TestCommWorld, /*dim=*/3);
64 
65  RealVectorValue extrusion_vector(0, 0, 1);
66 
67  QueryElemSubdomainID new_elem_subdomain_id;
68 
73  MeshTools::Generation::build_extrusion(dest_mesh, src_mesh, num_layers, extrusion_vector, &new_elem_subdomain_id);
74 
75  for (unsigned int i=0; i<n_elems_per_layer * num_layers; ++i)
76  {
77  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
78  Elem & elem = dest_mesh.elem_ref(i);
79 
80  CPPUNIT_ASSERT_EQUAL((unsigned int)elem.subdomain_id(), i%n_elems_per_layer + i/n_elems_per_layer /* integer division */);
81  }
82  }
83 };
84 
85 
MeshExtruderTest::setUp
void setUp()
Definition: mesh_extruder.C:42
MeshExtruderTest::QueryElemSubdomainID::get_subdomain_for_layer
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:34
libMesh::MeshBase::elem_ref
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:521
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::VectorValue< Real >
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::MeshTools::Generation::build_square
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.
Definition: mesh_generation.C:1501
MeshExtruderTest::tearDown
void tearDown()
Definition: mesh_extruder.C:44
MeshExtruderTest
Definition: mesh_extruder.C:12
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(MeshExtruderTest)
libmesh_cppunit.h
libMesh::Elem::subdomain_id
subdomain_id_type subdomain_id() const
Definition: elem.h:2069
libMesh::MeshTools::Generation::QueryElemSubdomainIDBase
Class for receiving the callback during extrusion generation and providing user-defined subdomains ba...
Definition: mesh_generation.h:151
libMesh::MeshTools::Generation::build_extrusion
void build_extrusion(UnstructuredMesh &mesh, const MeshBase &cross_section, const unsigned int nz, RealVectorValue extrusion_vector, QueryElemSubdomainIDBase *elem_subdomain=nullptr)
Meshes the tensor product of a 1D and a 1D-or-2D domain.
Definition: mesh_generation.C:1994
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
MeshExtruderTest::QueryElemSubdomainID
Definition: mesh_extruder.C:31
libMesh::TestClass
Definition: id_types.h:33
test_comm.h
MeshExtruderTest::testExtruder
void testExtruder()
Definition: mesh_extruder.C:46