Debian Codegraph @

dune/localfunctions/test/test-pk2d.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 <cstddef>
7 #include <iostream>
8 #include <ostream>
9 #include <utility>
10
11 #include <dune/common/exceptions.hh>
12 #include <dune/common/fvector.hh>
13 #include <dune/common/hybridutilities.hh>
14
15 #include <dune/geometry/type.hh>
16 #include <dune/geometry/generalvertexorder.hh>
17
18 #include <dune/localfunctions/lagrange/pk2d.hh>
19
20 #include "geometries.hh"
21 #include "test-fe.hh"
22
23 // tolerance for floating-point comparisons
24 static const double eps = 1e-9;
25 // stepsize for numerical differentiation
26 static const double delta = 1e-5;
27
28 template<int k>
29 static void test(int &result)
30 {
31 std::cout << "== Checking global-valued Pk2D elements (with k=" << k << ")"
32 << std::endl;
33
34 Dune::GeometryType gt(Dune::GeometryTypes::triangle);
35
36 typedef TestGeometries<double, 2> TestGeos;
37 static const TestGeos testGeos;
38
39 typedef TestGeos::Geometry Geometry;
40 const Geometry &geo = testGeos.get(gt);
41
42 std::size_t vertexIds[] = {0, 1, 2};
43 Dune::GeneralVertexOrder<2, std::size_t>
44 vo(gt, vertexIds+0, vertexIds+3);
45
46 Dune::Pk2DFiniteElementFactory<Geometry, double, k> feFactory;
47 bool success = testFE(geo, feFactory.make(geo, vo), eps, delta);
48
49 if(success && result != 1)
50 result = 0;
51 else
52 result = 1;
53 }
54
55 int main(int argc, char** argv) {
56 try {
57 int result = 77;
58
59 static constexpr std::size_t max_k = 20;
60 Dune::Hybrid::forEach(std::make_index_sequence<max_k+1>{},[&](auto i){test<i>(result);});
61
62 return result;
63 }
64 catch (const Dune::Exception& e) {
65 std::cerr << e << std::endl;
66 throw;
67 }
68 }