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 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
9 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
10 // warnings. These can be ignored in GCC as long as we wrap the
11 // offending code in appropriate pragmas. We can't get away with a
12 // single ignore_warnings.h inclusion at the beginning of this file,
13 // since the libmesh headers pull in a restore_warnings.h at some
14 // point. We also don't bother restoring warnings at the end of this
15 // file since it's not a header.
16 #include <libmesh/ignore_warnings.h>
17 
18 #include <cppunit/extensions/HelperMacros.h>
19 #include <cppunit/TestCase.h>
20 
21 using namespace libMesh;
22 
23 template <ElemType elem_type>
24 class ElemTest : public CppUnit::TestCase {
25 
26 private:
28 
29 public:
30  void setUp()
31  {
32  const Real minpos = 1.5, maxpos = 5.5;
33  const unsigned int N = 2;
34 
35  _mesh = new Mesh(*TestCommWorld);
36  const UniquePtr<Elem> test_elem = Elem::build(elem_type);
37  const unsigned int dim = test_elem->dim();
38  const unsigned int use_y = dim > 1;
39  const unsigned int use_z = dim > 2;
40 
42  N, N*use_y, N*use_z,
43  minpos, maxpos,
44  minpos, use_y*maxpos,
45  minpos, use_z*maxpos,
46  elem_type);
47  }
48 
49  void tearDown()
50  {
51  delete _mesh;
52  }
53 
55  {
57  elem_it = _mesh->active_local_elements_begin(),
58  elem_end = _mesh->active_local_elements_end();
59  for (; elem_it != elem_end; ++elem_it)
60  {
61  const Elem & elem = **elem_it;
62 
63  const BoundingBox bbox = elem.loose_bounding_box();
64 
65  const Point centroid = elem.centroid();
66 
67  // The "loose" bounding box should actually be pretty tight
68  // in most of these cases, but for weirdly aligned triangles
69  // (such as occur in pyramid elements) it won't be, so we'll
70  // just test against a widened bounding box.
71  BoundingBox wide_bbox(elem.point(0), elem.point(0));
72 
73  for (unsigned int n = 0; n != elem.n_nodes(); ++n)
74  {
75  const Point & p = elem.point(n);
76 
77  CPPUNIT_ASSERT(bbox.contains_point(p));
78 
79  wide_bbox.union_with
80  (BoundingBox(elem.point(n), elem.point(n)));
81  }
82 
83  for (unsigned int d=0; d != LIBMESH_DIM; ++d)
84  {
85  const Real widening =
86  (wide_bbox.max()(d) - wide_bbox.min()(d)) / 3;
87  wide_bbox.min()(d) -= widening;
88  wide_bbox.max()(d) += widening;
89  }
90 
91  CPPUNIT_ASSERT(!bbox.contains_point(wide_bbox.min()));
92  CPPUNIT_ASSERT(!bbox.contains_point(wide_bbox.max()));
93  }
94  }
95 };
96 
97 #define ELEMTEST \
98  CPPUNIT_TEST( test_bounding_box )
99 
100 #define INSTANTIATE_ELEMTEST(elemtype) \
101  class ElemTest_##elemtype : public ElemTest<elemtype> { \
102  public: \
103  CPPUNIT_TEST_SUITE( ElemTest_##elemtype ); \
104  ELEMTEST; \
105  CPPUNIT_TEST_SUITE_END(); \
106  }; \
107  \
108  CPPUNIT_TEST_SUITE_REGISTRATION( ElemTest_##elemtype )
109 
113 
116 
120 
123 
127 
131 
virtual element_iterator active_local_elements_begin() libmesh_override
bool contains_point(const Point &) const
Definition: bounding_box.C:73
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:238
INSTANTIATE_ELEMTEST(EDGE2)
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
unsigned int dim
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
virtual element_iterator active_local_elements_end() libmesh_override
void tearDown()
Definition: elem_test.C:49
The libMesh namespace provides an interface to certain functionality in the library.
void setUp()
Definition: elem_test.C:30
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual unsigned int n_nodes() const =0
void test_bounding_box()
Definition: elem_test.C:54
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & point(const unsigned int i) const
Definition: elem.h:1809
virtual Point centroid() const
Definition: elem.C:446
Mesh * _mesh
Definition: elem_test.C:27
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
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.
virtual BoundingBox loose_bounding_box() const
Definition: elem.C:2997