libMesh
all_tri.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 #include <libmesh/libmesh.h>
8 #include <libmesh/replicated_mesh.h>
9 #include <libmesh/elem.h>
10 #include <libmesh/mesh_generation.h>
11 #include <libmesh/mesh_modification.h>
12 
13 #include "test_comm.h"
14 
15 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
16 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
17 // warnings. These can be ignored in GCC as long as we wrap the
18 // offending code in appropriate pragmas. We can't get away with a
19 // single ignore_warnings.h inclusion at the beginning of this file,
20 // since the libmesh headers pull in a restore_warnings.h at some
21 // point. We also don't bother restoring warnings at the end of this
22 // file since it's not a header.
23 #include <libmesh/ignore_warnings.h>
24 
25 using namespace libMesh;
26 
27 class AllTriTest : public CppUnit::TestCase
28 {
35 public:
36  CPPUNIT_TEST_SUITE( AllTriTest );
37 
38  // 2D tests
39  CPPUNIT_TEST( testAllTriTri );
40  CPPUNIT_TEST( testAllTriQuad );
41  CPPUNIT_TEST( testAllTriQuad8 );
42  CPPUNIT_TEST( testAllTriQuad9 );
43 
44  // 3D tests
45  CPPUNIT_TEST( testAllTriPrism6 );
46  CPPUNIT_TEST( testAllTriPrism18 );
47 
48  CPPUNIT_TEST_SUITE_END();
49 
50 protected:
51  // Helper function called by the test implementations, saves a few lines of code.
52  void test_helper_2D(ElemType elem_type,
53  dof_id_type n_elem_expected,
54  std::size_t n_boundary_conds_expected)
55  {
56  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/2);
57 
58  // Build a 2x1 TRI3 mesh and ask to split it into triangles.
59  // Should be a no-op
61  /*nx=*/2, /*ny=*/1,
62  /*xmin=*/0., /*xmax=*/1.,
63  /*ymin=*/0., /*ymax=*/1.,
64  elem_type);
65 
67 
68  // Make sure that the expected number of elements is found.
69  CPPUNIT_ASSERT_EQUAL(n_elem_expected, mesh.n_elem());
70 
71  // Make sure the expected number of BCs is found.
72  CPPUNIT_ASSERT_EQUAL(n_boundary_conds_expected, mesh.get_boundary_info().n_boundary_conds());
73  }
74 
75  // Helper function called by the test implementations in 3D, saves a few lines of code.
76  void test_helper_3D(ElemType elem_type,
77  dof_id_type n_elem_expected,
78  std::size_t n_boundary_conds_expected)
79  {
80  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/3);
81 
82  // Build a 2x1 TRI3 mesh and ask to split it into triangles.
83  // Should be a no-op
85  /*nx=*/1, /*ny=*/1, /*nz=*/1,
86  /*xmin=*/0., /*xmax=*/1.,
87  /*ymin=*/0., /*ymax=*/1.,
88  /*zmin=*/0., /*zmax=*/1.,
89  elem_type);
90 
92 
93  // Make sure that the expected number of elements is found.
94  CPPUNIT_ASSERT_EQUAL(n_elem_expected, mesh.n_elem());
95 
96  // Make sure the expected number of BCs is found.
97  CPPUNIT_ASSERT_EQUAL(n_boundary_conds_expected, mesh.get_boundary_info().n_boundary_conds());
98  }
99 
100 public:
101  void setUp() {}
102 
103  void tearDown() {}
104 
105  // 4 TRIs no-op
106  void testAllTriTri() { test_helper_2D(TRI3, /*nelem=*/4, /*nbcs=*/6); }
107 
108  // 2 quads split into 4 TRIs.
109  void testAllTriQuad() { test_helper_2D(QUAD4, /*nelem=*/4, /*nbcs=*/6); }
110 
111  // 2 QUAD8s split into 4 TRIs.
112  void testAllTriQuad8() { test_helper_2D(QUAD8, /*nelem=*/4, /*nbcs=*/6); }
113 
114  // 2 QUAD9s split into 4 TRIs.
115  void testAllTriQuad9() { test_helper_2D(QUAD9, /*nelem=*/4, /*nbcs=*/6); }
116 
117  // 2 PRISM6s split into 6 TETs with 2 boundary faces per side.
118  void testAllTriPrism6() { test_helper_3D(PRISM6, /*nelem=*/6, /*nbcs=*/12); }
119 
120  // 2 PRISM6s split into 6 TETs with 2 boundary faces per side.
121  void testAllTriPrism18() { test_helper_3D(PRISM18, /*nelem=*/6, /*nbcs=*/12); }
122 };
123 
124 
void testAllTriTri()
Definition: all_tri.C:106
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition: mesh_base.h:117
void testAllTriPrism6()
Definition: all_tri.C:118
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
void testAllTriQuad()
Definition: all_tri.C:109
ElemType
Defines an enum for geometric element types.
void testAllTriQuad8()
Definition: all_tri.C:112
void testAllTriPrism18()
Definition: all_tri.C:121
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.
std::size_t n_boundary_conds() const
The libMesh namespace provides an interface to certain functionality in the library.
void tearDown()
Definition: all_tri.C:103
virtual dof_id_type n_elem() const libmesh_override
void all_tri(MeshBase &mesh)
Converts the 2D quadrilateral elements of a Mesh into triangular 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:76
void test_helper_2D(ElemType elem_type, dof_id_type n_elem_expected, std::size_t n_boundary_conds_expected)
Definition: all_tri.C:52
void testAllTriQuad9()
Definition: all_tri.C:115
CPPUNIT_TEST_SUITE_REGISTRATION(AllTriTest)
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.
uint8_t dof_id_type
Definition: id_types.h:64
void setUp()
Definition: all_tri.C:101