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