libMesh
elem_test.C
Go to the documentation of this file.
1 #include "test_comm.h"
2 
3 #include <libmesh/elem.h>
4 #include <libmesh/enum_elem_type.h>
5 #include <libmesh/mesh.h>
6 #include <libmesh/mesh_generation.h>
7 
8 #include "libmesh_cppunit.h"
9 
10 using namespace libMesh;
11 
12 template <ElemType elem_type>
13 class ElemTest : public CppUnit::TestCase {
14 
15 private:
17 
18 public:
19  void setUp()
20  {
21  const Real minpos = 1.5, maxpos = 5.5;
22  const unsigned int N = 2;
23 
24  _mesh = new Mesh(*TestCommWorld);
25  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
26  const unsigned int dim = test_elem->dim();
27  const unsigned int use_y = dim > 1;
28  const unsigned int use_z = dim > 2;
29 
31  N, N*use_y, N*use_z,
32  minpos, maxpos,
33  minpos, use_y*maxpos,
34  minpos, use_z*maxpos,
35  elem_type);
36  }
37 
38  void tearDown()
39  {
40  delete _mesh;
41  }
42 
44  {
45  for (const auto & elem : _mesh->active_local_element_ptr_range())
46  {
47  const BoundingBox bbox = elem->loose_bounding_box();
48 
49  const Point centroid = elem->centroid();
50 
51  // The "loose" bounding box should actually be pretty tight
52  // in most of these cases, but for weirdly aligned triangles
53  // (such as occur in pyramid elements) it won't be, so we'll
54  // just test against a widened bounding box.
55  BoundingBox wide_bbox(elem->point(0), elem->point(0));
56 
57  for (unsigned int n = 0; n != elem->n_nodes(); ++n)
58  {
59  const Point & p = elem->point(n);
60 
61  CPPUNIT_ASSERT(bbox.contains_point(p));
62 
63  wide_bbox.union_with
64  (BoundingBox(elem->point(n), elem->point(n)));
65  }
66 
67  for (unsigned int d=0; d != LIBMESH_DIM; ++d)
68  {
69  const Real widening =
70  (wide_bbox.max()(d) - wide_bbox.min()(d)) / 3;
71  wide_bbox.min()(d) -= widening;
72  wide_bbox.max()(d) += widening;
73  }
74 
75  CPPUNIT_ASSERT(!bbox.contains_point(wide_bbox.min()));
76  CPPUNIT_ASSERT(!bbox.contains_point(wide_bbox.max()));
77  }
78  }
79 };
80 
81 #define ELEMTEST \
82  CPPUNIT_TEST( test_bounding_box )
83 
84 #define INSTANTIATE_ELEMTEST(elemtype) \
85  class ElemTest_##elemtype : public ElemTest<elemtype> { \
86  public: \
87  CPPUNIT_TEST_SUITE( ElemTest_##elemtype ); \
88  ELEMTEST; \
89  CPPUNIT_TEST_SUITE_END(); \
90  }; \
91  \
92  CPPUNIT_TEST_SUITE_REGISTRATION( ElemTest_##elemtype )
93 
97 
98 #if LIBMESH_DIM > 1
101 
105 #endif
106 
107 #if LIBMESH_DIM > 2
110 
114 
118 
122 #endif
libMesh::HEX20
Definition: enum_elem_type.h:48
libMesh::PRISM6
Definition: enum_elem_type.h:50
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::DistributedMesh::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range() override
Definition: distributed_mesh.h:372
ElemTest::_mesh
Mesh * _mesh
Definition: elem_test.C:16
INSTANTIATE_ELEMTEST
INSTANTIATE_ELEMTEST(EDGE2)
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::EDGE4
Definition: enum_elem_type.h:37
libMesh::BoundingBox
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::TET10
Definition: enum_elem_type.h:46
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
ElemTest::tearDown
void tearDown()
Definition: elem_test.C:38
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::TET4
Definition: enum_elem_type.h:45
libMesh::PRISM15
Definition: enum_elem_type.h:51
ElemTest::test_bounding_box
void test_bounding_box()
Definition: elem_test.C:43
libMesh::HEX27
Definition: enum_elem_type.h:49
ElemTest::setUp
void setUp()
Definition: elem_test.C:19
libMesh::QUAD4
Definition: enum_elem_type.h:41
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::TRI3
Definition: enum_elem_type.h:39
libMesh::TRI6
Definition: enum_elem_type.h:40
libMesh::PYRAMID5
Definition: enum_elem_type.h:53
libmesh_cppunit.h
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::BoundingBox::contains_point
bool contains_point(const Point &) const
Definition: bounding_box.C:135
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
test_comm.h
libMesh::PRISM18
Definition: enum_elem_type.h:52
libMesh::Elem::build
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:246
libMesh::PYRAMID13
Definition: enum_elem_type.h:54
libMesh::PYRAMID14
Definition: enum_elem_type.h:55
libMesh::EDGE2
Definition: enum_elem_type.h:35
libMesh::QUAD8
Definition: enum_elem_type.h:42
ElemTest
Definition: elem_test.C:13