Skip to content

Commit 9fb3ee2

Browse files
committed
Add unit test for generated 1d Lagrange shape functions
1 parent 262f590 commit 9fb3ee2

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ unit_tests_sources = \
4444
fe/fe_test.h \
4545
fe/fe_xyz_test.C \
4646
fe/dual_shape_verification_test.C \
47+
fe/fe_lagrange_shape_verification_test.C \
4748
geom/bbox_test.C \
4849
geom/edge_test.C \
4950
geom/elem_test.C \
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// libmesh includes
2+
#include "libmesh/libmesh.h"
3+
#include "libmesh/fe_lagrange_shape_1D.h"
4+
5+
// unit test includes
6+
#include "test_comm.h"
7+
8+
#include "libmesh_cppunit.h"
9+
10+
using namespace libMesh;
11+
12+
/**
13+
* This class is for unit testing lagrange shape function values and derivatives
14+
*/
15+
class LagrangeShapeTest : public CppUnit::TestCase
16+
{
17+
public:
18+
19+
LIBMESH_CPPUNIT_TEST_SUITE( LagrangeShapeTest );
20+
CPPUNIT_TEST( test1DLagrange );
21+
CPPUNIT_TEST_SUITE_END();
22+
23+
public:
24+
25+
void test1DLagrange ()
26+
{
27+
LOG_UNIT_TEST;
28+
29+
// TOLERANCE*TOLERANCE works with double but not float128
30+
Real my_tol = TOLERANCE*std::sqrt(TOLERANCE);
31+
32+
for (auto xi : {0., 1./3., -.5, -1./7.})
33+
for(auto o : make_range(1, 4))
34+
for(auto i : make_range(o + 1))
35+
{
36+
LIBMESH_ASSERT_FP_EQUAL(fe_lagrange_1D_shape(Order(o), i, xi),
37+
fe_lagrange_1D_any_shape(Order(o), i, xi), my_tol);
38+
LIBMESH_ASSERT_FP_EQUAL(fe_lagrange_1D_shape_deriv(Order(o), i, 0, xi),
39+
fe_lagrange_1D_any_shape_deriv(Order(o), i, 0, xi), my_tol);
40+
LIBMESH_ASSERT_FP_EQUAL(fe_lagrange_1D_shape_second_deriv(Order(o), i, 0, xi),
41+
fe_lagrange_1D_any_shape_second_deriv(Order(o), i, 0, xi), my_tol);
42+
}
43+
}
44+
45+
void setUp() {}
46+
47+
void tearDown() {}
48+
49+
};
50+
51+
CPPUNIT_TEST_SUITE_REGISTRATION( LagrangeShapeTest );

0 commit comments

Comments
 (0)