Debian Codegraph @

dune/localfunctions/test/monomialshapefunctiontest.cc

raw
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6 #include <iostream>
7
8 #include <dune/geometry/quadraturerules.hh>
9
10 #include <dune/localfunctions/monomial.hh>
11 #include <dune/localfunctions/test/test-localfe.hh>
12
13 /** \file
14 \brief Performs some tests for the monomial shape functions
15 */
16
17 double epsilon = 1e-8;
18
19 using namespace Dune;
20
21
22 template<int dim, int order>
23 bool testShapeFunctionValue(const GeometryType& gt,
24 const FieldVector<double, dim> &pos,
25 int comp, double expected)
26 {
27 MonomialLocalFiniteElement<double,double,dim,order> shapeFunctionSet(gt);
28 std::vector<FieldVector<double,1> > out;
29 shapeFunctionSet.localBasis().evaluateFunction(pos, out);
30
31 if(std::abs(out[comp][0]-expected) > epsilon) {
32 std::cerr << "Bug in shape function of dimension " << dim
33 << " and order " << order << " for "
34 << gt << "." << std::endl;
35 std::cerr << "Value of shape function number " << comp << " at position "
36 << pos << " is " << out[comp][0] << " but " << expected
37 << " was expected." << std::endl;
38 return false;
39 }
40 return true;
41 }
42
43 int main (int argc, char *argv[])
44 {
45 bool success = true;
46
47 // Do the standard shape function tests
48 std::cout << "Monomials are only tested up to order 2 due to the instability of interpolate()." << std::endl;
49 Hybrid::forEach(std::make_index_sequence<3>{},[&success](auto i)
50 {
51 Dune::MonomialLocalFiniteElement<double,double,1,i> monom1d(GeometryTypes::line);
52 TEST_FE(monom1d);
53
54 Dune::MonomialLocalFiniteElement<double,double,2,i> monom2d(GeometryTypes::triangle);
55 TEST_FE(monom2d);
56
57 Dune::MonomialLocalFiniteElement<double,double,3,i> monom3d(GeometryTypes::tetrahedron);
58 TEST_FE(monom3d);
59 });
60
61 // Test whether the shape function values are correct
62 // dim=1
63 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0}, 0, 1);
64 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0}, 1, 0);
65 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0}, 2, 0);
66
67 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0.5}, 0, 1);
68 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0.5}, 1, .5);
69 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {0.5}, 2, .25);
70
71 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {1}, 0, 1);
72 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {1}, 1, 1);
73 success &= testShapeFunctionValue<1,2>(GeometryTypes::line, {1}, 2, 1);
74
75 // dim=2
76 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0,0}, 0, 1);
77 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0,0}, 1, 0);
78 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0,0}, 2, 0);
79
80 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0.5,0.5}, 0, 1);
81 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0.5,0.5}, 1, .5);
82 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {0.5,0.5}, 2, .5);
83
84 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {1,1}, 0, 1);
85 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {1,1}, 1, 1);
86 success &= testShapeFunctionValue<2,1>(GeometryTypes::quadrilateral, {1,1}, 2, 1);
87
88 return success ? 0 : 1;
89 }