libMesh
dual_shape_verification_test.C
Go to the documentation of this file.
1 // libmesh includes
2 #include "libmesh/libmesh.h"
3 #include "libmesh/edge_edge2.h"
4 #include "libmesh/fe.h"
5 #include "libmesh/quadrature_gauss.h"
6 #include "libmesh/mesh_generation.h"
7 #include "libmesh/mesh.h"
8 
9 // unit test includes
10 #include "test_comm.h"
11 
12 #include "libmesh_cppunit.h"
13 
14 using namespace libMesh;
15 
19 class DualShapeTest : public CppUnit::TestCase
20 {
21 public:
22  LIBMESH_CPPUNIT_TEST_SUITE( DualShapeTest );
23  CPPUNIT_TEST( testEdge2Lagrange );
24  CPPUNIT_TEST_SUITE_END();
25 
26 private:
27  std::unique_ptr<Mesh> _mesh;
28  std::unique_ptr<QGauss> _qrule;
29  std::unique_ptr<FEBase> _fe;
31 
32 public:
33 
35  {
36  LOG_UNIT_TEST;
37  if (!_elem)
38  return;
39 
40  _fe->reinit(_elem);
41 
42  const DenseMatrix<Real> & dual_coeff = _fe->get_dual_coeff();
43 
44  CPPUNIT_ASSERT_EQUAL(dual_coeff.m(), unsigned(2));
45  CPPUNIT_ASSERT_EQUAL(dual_coeff.n(), unsigned(2));
46 
47  // TOLERANCE*TOLERANCE works with double but not float128
48  Real my_tol = TOLERANCE*std::sqrt(TOLERANCE);
49 
50  LIBMESH_ASSERT_FP_EQUAL(2, dual_coeff(0,0), my_tol);
51  LIBMESH_ASSERT_FP_EQUAL(-1, dual_coeff(0,1), my_tol);
52  LIBMESH_ASSERT_FP_EQUAL(-1, dual_coeff(1,0), my_tol);
53  LIBMESH_ASSERT_FP_EQUAL(2, dual_coeff(1,1), my_tol);
54 
55  const auto & dual_phi = _fe->get_dual_phi();
56 
57  CPPUNIT_ASSERT_EQUAL(std::size_t(2), dual_phi.size());
58 
59  const auto & qpoints = _qrule->get_points();
60 
61  CPPUNIT_ASSERT_EQUAL(qpoints.size(), dual_phi[0].size());
62 
63  for (auto qp : index_range(dual_phi[0]))
64  LIBMESH_ASSERT_FP_EQUAL(1./2. * (1. - 3.*qpoints[qp](0)), dual_phi[0][qp],
65  my_tol);
66 
67  CPPUNIT_ASSERT_EQUAL(qpoints.size(), dual_phi[1].size());
68 
69  for (auto qp : index_range(dual_phi[1]))
70  LIBMESH_ASSERT_FP_EQUAL(1./2. * (1. + 3.*qpoints[qp](0)), dual_phi[1][qp],
71  my_tol);
72  }
73 
74  void setUp()
75  {
76  FEType fe_type(FIRST, LAGRANGE);
77  _fe = FEBase::build(1, fe_type);
78  _fe->get_phi();
79  _fe->get_dual_phi();
80 
81  _mesh = std::make_unique<Mesh>(*TestCommWorld);
82 
83  MeshTools::Generation::build_line(*_mesh, 1, -1, 1, EDGE2);
84 
85  auto rng = _mesh->active_local_element_ptr_range();
86  _elem = rng.begin() == rng.end() ? nullptr : *(rng.begin());
87 
88  _qrule = std::make_unique<QGauss>(1, fe_type.default_quadrature_order());
89  _fe->attach_quadrature_rule(_qrule.get());
90  }
91 
92  void tearDown() {}
93 
94 };
95 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:196
static constexpr Real TOLERANCE
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
Order default_quadrature_order() const
Definition: fe_type.h:371
unsigned int m() const
The libMesh namespace provides an interface to certain functionality in the library.
std::unique_ptr< QGauss > _qrule
This class is for unit testing dual coefficient and shape function values.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
std::unique_ptr< Mesh > _mesh
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::unique_ptr< FEBase > _fe
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
unsigned int n() const
CPPUNIT_TEST_SUITE_REGISTRATION(DualShapeTest)
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117