libMesh
all_tri.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 #include <libmesh/mesh_modification.h>
6 
7 #include "test_comm.h"
8 #include "libmesh_cppunit.h"
9 
10 
11 using namespace libMesh;
12 
13 class AllTriTest : public CppUnit::TestCase
14 {
21 public:
22  CPPUNIT_TEST_SUITE( AllTriTest );
23 
24  // 2D tests
25 #if LIBMESH_DIM > 1
26  CPPUNIT_TEST( testAllTriTri );
27  CPPUNIT_TEST( testAllTriQuad );
28  CPPUNIT_TEST( testAllTriQuad8 );
29  CPPUNIT_TEST( testAllTriQuad9 );
30 #endif
31 
32  // 3D tests
33 #if LIBMESH_DIM > 2
34  CPPUNIT_TEST( testAllTriPrism6 );
35  CPPUNIT_TEST( testAllTriPrism18 );
36 #endif
37 
38  CPPUNIT_TEST_SUITE_END();
39 
40 protected:
41  // Helper function called by the test implementations, saves a few lines of code.
42  void test_helper_2D(ElemType elem_type,
43  dof_id_type n_elem_expected,
44  std::size_t n_boundary_conds_expected)
45  {
46  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/2);
47 
48  // Build a 2x1 TRI3 mesh and ask to split it into triangles.
49  // Should be a no-op
51  /*nx=*/2, /*ny=*/1,
52  /*xmin=*/0., /*xmax=*/1.,
53  /*ymin=*/0., /*ymax=*/1.,
54  elem_type);
55 
57 
58  // Make sure that the expected number of elements is found.
59  CPPUNIT_ASSERT_EQUAL(n_elem_expected, mesh.n_elem());
60 
61  // Make sure the expected number of BCs is found.
62  CPPUNIT_ASSERT_EQUAL(n_boundary_conds_expected, mesh.get_boundary_info().n_boundary_conds());
63  }
64 
65  // Helper function called by the test implementations in 3D, saves a few lines of code.
66  void test_helper_3D(ElemType elem_type,
67  dof_id_type n_elem_expected,
68  std::size_t n_boundary_conds_expected)
69  {
70  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/3);
71 
72  // Build a 2x1 TRI3 mesh and ask to split it into triangles.
73  // Should be a no-op
75  /*nx=*/1, /*ny=*/1, /*nz=*/1,
76  /*xmin=*/0., /*xmax=*/1.,
77  /*ymin=*/0., /*ymax=*/1.,
78  /*zmin=*/0., /*zmax=*/1.,
79  elem_type);
80 
82 
83  // Make sure that the expected number of elements is found.
84  CPPUNIT_ASSERT_EQUAL(n_elem_expected, mesh.n_elem());
85 
86  // Make sure the expected number of BCs is found.
87  CPPUNIT_ASSERT_EQUAL(n_boundary_conds_expected, mesh.get_boundary_info().n_boundary_conds());
88  }
89 
90 public:
91  void setUp() {}
92 
93  void tearDown() {}
94 
95  // 4 TRIs no-op
96  void testAllTriTri() { test_helper_2D(TRI3, /*nelem=*/4, /*nbcs=*/6); }
97 
98  // 2 quads split into 4 TRIs.
99  void testAllTriQuad() { test_helper_2D(QUAD4, /*nelem=*/4, /*nbcs=*/6); }
100 
101  // 2 QUAD8s split into 4 TRIs.
102  void testAllTriQuad8() { test_helper_2D(QUAD8, /*nelem=*/4, /*nbcs=*/6); }
103 
104  // 2 QUAD9s split into 4 TRIs.
105  void testAllTriQuad9() { test_helper_2D(QUAD9, /*nelem=*/4, /*nbcs=*/6); }
106 
107  // 2 PRISM6s split into 6 TETs with 2 boundary faces per side.
108  void testAllTriPrism6() { test_helper_3D(PRISM6, /*nelem=*/6, /*nbcs=*/12); }
109 
110  // 2 PRISM6s split into 6 TETs with 2 boundary faces per side.
111  void testAllTriPrism18() { test_helper_3D(PRISM18, /*nelem=*/6, /*nbcs=*/12); }
112 };
113 
114 
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::PRISM6
Definition: enum_elem_type.h:50
libMesh::MeshBase::get_boundary_info
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:132
libMesh::BoundaryInfo::n_boundary_conds
std::size_t n_boundary_conds() const
Definition: boundary_info.C:1615
libMesh::MeshBase::n_elem
virtual dof_id_type n_elem() const =0
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
AllTriTest::test_helper_3D
void test_helper_3D(ElemType elem_type, dof_id_type n_elem_expected, std::size_t n_boundary_conds_expected)
Definition: all_tri.C:66
libMesh::MeshTools::Generation::build_cube
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.
Definition: mesh_generation.C:298
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
AllTriTest::testAllTriQuad9
void testAllTriQuad9()
Definition: all_tri.C:105
AllTriTest::test_helper_2D
void test_helper_2D(ElemType elem_type, dof_id_type n_elem_expected, std::size_t n_boundary_conds_expected)
Definition: all_tri.C:42
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
AllTriTest::setUp
void setUp()
Definition: all_tri.C:91
AllTriTest
Definition: all_tri.C:13
AllTriTest::testAllTriPrism6
void testAllTriPrism6()
Definition: all_tri.C:108
libMesh::QUAD4
Definition: enum_elem_type.h:41
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::TRI3
Definition: enum_elem_type.h:39
AllTriTest::testAllTriTri
void testAllTriTri()
Definition: all_tri.C:96
AllTriTest::testAllTriQuad
void testAllTriQuad()
Definition: all_tri.C:99
libMesh::MeshTools::Modification::all_tri
void all_tri(MeshBase &mesh)
Converts the 2D quadrilateral elements of a Mesh into triangular elements.
Definition: mesh_modification.C:280
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(AllTriTest)
libmesh_cppunit.h
AllTriTest::testAllTriQuad8
void testAllTriQuad8()
Definition: all_tri.C:102
AllTriTest::testAllTriPrism18
void testAllTriPrism18()
Definition: all_tri.C:111
libMesh::QUAD9
Definition: enum_elem_type.h:43
test_comm.h
AllTriTest::tearDown
void tearDown()
Definition: all_tri.C:93
libMesh::PRISM18
Definition: enum_elem_type.h:52
libMesh::QUAD8
Definition: enum_elem_type.h:42
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33