Debian Codegraph @

dune/localfunctions/test/test-nedelecsimplex.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 <dune/common/dynmatrix.hh>
7 #include <dune/localfunctions/nedelec/nedelecsimplex/nedelecsimplexbasis.hh>
8 #include <dune/localfunctions/utility/field.hh>
9 #include <dune/localfunctions/utility/basisprint.hh>
10
11 /**
12 * \file
13 * \brief Performs some tests for the generic Nedelec
14 * shape functions on simplices.
15 *
16 * The topology can be chosen at compile time by setting TOPOLOGY
17 * to a Dune::GeometryType like
18 * \code
19 * GeometryTypes::simplex(2)
20 * \endcode
21 * which generates a 2d simplex. If TOPOLOGY is not set, triangles and tetrahedra
22 * are tested. Note, this may lead to prolonged compiler runs.
23 *
24 * For debugging purpuse the functions and the derivatives can be
25 * printed. You have to define the macro TEST_OUTPUT_FUNCTIONS to
26 * activate this function.
27 */
28
29 #if HAVE_GMP
30 typedef Dune::GMPField< 128 > StorageField;
31 typedef Dune::GMPField< 512 > ComputeField;
32 #else
33 typedef double StorageField;
34 typedef double ComputeField;
35 #endif
36
37 template< Dune::GeometryType::Id geometryId >
38 bool test(unsigned int order)
39 {
40 bool ret = true;
41 constexpr Dune::GeometryType geometry = geometryId;
42
43 for (unsigned int o = 1; o <= order; ++o)
44 {
45 std::cout << "Testing " << geometry << " of the " << o <<"-th kind"<< std::endl;
46 typedef Dune::NedelecBasisFactory<geometry.dim(),StorageField,ComputeField> BasisFactory;
47 const typename BasisFactory::Object &basis = *BasisFactory::template create<geometry>(o);
48
49 // define the macro TEST_OUTPUT_FUNCTIONS to output files containing functions and
50 // derivatives in a human readabible form (aka LaTeX source)
51 #ifdef TEST_OUTPUT_FUNCTIONS
52 std::stringstream name;
53 name << "ned_" << geometry << "_p" << o << ".basis";
54 std::ofstream out(name.str().c_str());
55 Dune::basisPrint<0, BasisFactory, typename BasisFactory::StorageField, geometry>(out,basis);
56 Dune::basisPrint<1, BasisFactory, typename BasisFactory::StorageField, geometry>(out,basis);
57 #endif // TEST_OUTPUT_FUNCTIONS
58
59 // test interpolation
60 typedef Dune::NedelecL2InterpolationFactory<geometry.dim(), StorageField> InterpolationFactory;
61 const typename InterpolationFactory::Object &interpol = *InterpolationFactory::template create<geometry>(o);
62 Dune::DynamicMatrix<StorageField> matrix;
63 interpol.interpolate(basis,matrix);
64 for (unsigned int i=0; i<matrix.rows(); ++i)
65 matrix[i][i]-=1;
66 for (unsigned int i=0; i<matrix.rows(); ++i)
67 for (unsigned int j=0; j<matrix.cols(); ++j)
68 if ( std::abs( matrix[i][j] ) > 1000.*Dune::Zero<double>::epsilon() )
69 std::cout << " non-zero entry in interpolation matrix: "
70 << "(" << i << "," << j << ") = " << Dune::field_cast<double>(matrix[i][j])
71 << std::endl;
72
73 BasisFactory::release(&basis);
74 std::cout<<"----------------------------------------------------------------------------------------------------------------\n";
75 }
76 if (!ret) {
77 std::cout << " FAILED !" << std::endl;
78 }
79 return ret;
80 }
81
82 #ifdef CHECKDIM
83 #if CHECKDIM==2
84 #define CHECKDIM2
85 #elif CHECKDIM==3
86 #define CHECKDIM3
87 #endif
88 #else
89 #define CHECKDIM2
90 #define CHECKDIM3
91 #endif
92
93
94
95 int main ( int argc, char **argv )
96 {
97 using namespace Dune;
98 using namespace Impl;
99
100 unsigned int order = (argc < 2) ? 5 : atoi(argv[1]);
101
102 if (argc < 2)
103 {
104 std::cerr << "Usage: " << argv[ 0 ] << " <p>" << std::endl
105 << "Using default kind of " << order << std::endl;
106 }
107 #ifdef TOPOLOGY
108 return (test<TOPOLOGY>(order) ? 0 : 1 );
109 #else
110 bool tests = true;
111
112
113 #ifdef CHECKDIM2
114 tests &= test<GeometryTypes::simplex(2)>(order);
115 #endif
116
117 #ifdef CHECKDIM3
118 tests &= test<GeometryTypes::simplex(3)>(order);
119 #endif
120
121 return (tests ? 0 : 1);
122 #endif // TOPOLOGY
123 }