Loading [MathJax]/extensions/tex2jax.js
libMesh
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
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  LIBMESH_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  LOG_UNIT_TEST;
49 
50  ReplicatedMesh src_mesh(*TestCommWorld, /*dim=*/2);
51 
52  const unsigned int n_elems_per_side = 4;
53  const unsigned int num_layers = 4;
54  const unsigned int n_elems_per_layer = n_elems_per_side * n_elems_per_side;
55 
56 
57  MeshTools::Generation::build_square(src_mesh, n_elems_per_side, n_elems_per_side);
58  for (unsigned int i=0; i<n_elems_per_layer; ++i)
59  {
60  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
61  Elem & elem = src_mesh.elem_ref(i);
62  elem.subdomain_id() = i;
63  }
64 
65  ReplicatedMesh dest_mesh(*TestCommWorld, /*dim=*/3);
66 
67  RealVectorValue extrusion_vector(0, 0, 1);
68 
69  QueryElemSubdomainID new_elem_subdomain_id;
70 
75  MeshTools::Generation::build_extrusion(dest_mesh, src_mesh, num_layers, extrusion_vector, &new_elem_subdomain_id);
76 
77  for (unsigned int i=0; i<n_elems_per_layer * num_layers; ++i)
78  {
79  // Retrieve the element from the mesh by ID to guarantee proper ordering instead of with iterators
80  Elem & elem = dest_mesh.elem_ref(i);
81 
82  CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(elem.subdomain_id()), i%n_elems_per_layer + i/n_elems_per_layer /* integer division */);
83  }
84  }
85 };
86 
87 
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.
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:171
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
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:34
The libMesh namespace provides an interface to certain functionality in the library.
subdomain_id_type subdomain_id() const
Definition: elem.h:2504
virtual const Elem & elem_ref(const dof_id_type i) const
Definition: mesh_base.h:634
CPPUNIT_TEST_SUITE_REGISTRATION(MeshExtruderTest)