libMesh
Loading...
Searching...
No Matches
tests
mesh
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
31
class
QueryElemSubdomainID
:
public
MeshTools::Generation::QueryElemSubdomainIDBase
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
88
CPPUNIT_TEST_SUITE_REGISTRATION
(
MeshExtruderTest
);
MeshExtruderTest::QueryElemSubdomainID
Definition
mesh_extruder.C:32
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
MeshExtruderTest
Definition
mesh_extruder.C:13
MeshExtruderTest::CPPUNIT_TEST_SUITE_END
CPPUNIT_TEST_SUITE_END()
MeshExtruderTest::CPPUNIT_TEST
CPPUNIT_TEST(testExtruder)
MeshExtruderTest::tearDown
void tearDown()
Definition
mesh_extruder.C:44
MeshExtruderTest::testExtruder
void testExtruder()
Definition
mesh_extruder.C:46
MeshExtruderTest::LIBMESH_CPPUNIT_TEST_SUITE
LIBMESH_CPPUNIT_TEST_SUITE(MeshExtruderTest)
The goal of this test is to verify proper operation of the Mesh Extruder with the optional object cal...
MeshExtruderTest::setUp
void setUp()
Definition
mesh_extruder.C:42
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition
elem.h:96
libMesh::Elem::subdomain_id
subdomain_id_type subdomain_id() const
Definition
elem.h:2591
libMesh::MeshBase::elem_ref
virtual const Elem & elem_ref(const dof_id_type i) const
Definition
mesh_base.h:788
libMesh::MeshTools::Generation::QueryElemSubdomainIDBase
Class for receiving the callback during extrusion generation and providing user-defined subdomains ba...
Definition
mesh_generation.h:179
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::TestClass
Definition
id_types.h:33
libMesh::VectorValue< Real >
TestCommWorld
Communicator * TestCommWorld
libmesh_cppunit.h
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(MeshExtruderTest)
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:1981
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:2508
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
test_comm.h
Generated on Fri Aug 21 2026 13:32:31 for libMesh by
1.9.8