libMesh
Loading...
Searching...
No Matches
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
14using namespace libMesh;
15
19class DualShapeTest : public CppUnit::TestCase
20{
21public:
25
26private:
27 std::unique_ptr<Mesh> _mesh;
28 std::unique_ptr<QGauss> _qrule;
29 std::unique_ptr<FEBase> _fe;
31
32public:
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
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
This class is for unit testing dual coefficient and shape function values.
LIBMESH_CPPUNIT_TEST_SUITE(DualShapeTest)
std::unique_ptr< FEBase > _fe
std::unique_ptr< QGauss > _qrule
std::unique_ptr< Mesh > _mesh
CPPUNIT_TEST(testEdge2Lagrange)
Defines a dense matrix for use in Finite Element-type computations.
This is the base class from which all geometric element types are derived.
Definition elem.h:96
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
Order default_quadrature_order() const
Definition fe_type.h:415
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(DualShapeTest)
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.
The libMesh namespace provides an interface to certain functionality in the library.
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:153
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real