| 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/raviartthomas/raviartthomassimplex/raviartthomassimplexbasis.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 Raviart-Thomas |
| 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, all |
| 22 |
* topologies up to 4d are tested. Note, this may lead to prolonged |
| 23 |
* compiler runs. |
| 24 |
* |
| 25 |
* For debugging purpuse the functions and the derivatives can be |
| 26 |
* printed. You have to define the macro TEST_OUTPUT_FUNCTIONS to |
| 27 |
* activate this function. |
| 28 |
*/ |
| 29 |
|
| 30 |
#if HAVE_GMP |
| 31 |
typedef Dune::GMPField< 128 > StorageField; |
| 32 |
typedef Dune::GMPField< 512 > ComputeField; |
| 33 |
#else |
| 34 |
typedef double StorageField; |
| 35 |
typedef double ComputeField; |
| 36 |
#endif |
| 37 |
|
| 38 |
template< Dune::GeometryType::Id geometryId > |
| 39 |
bool test(unsigned int order) |
| 40 |
{ |
| 41 |
bool ret = true; |
| 42 |
|
| 43 |
constexpr Dune::GeometryType geometry = geometryId; |
| 44 |
for (unsigned int o = 0; o <= order; ++o) |
| 45 |
{ |
| 46 |
std::cout << "Testing " << geometry << " with order " << o << std::endl; |
| 47 |
typedef Dune::RaviartThomasBasisFactory<geometry.dim(),StorageField,ComputeField> BasisFactory; |
| 48 |
const typename BasisFactory::Object &basis = *BasisFactory::template create<geometry>(o); |
| 49 |
|
| 50 |
// define the macro TEST_OUTPUT_FUNCTIONS to output files containing functions and |
| 51 |
// derivatives in a human readabible form (aka LaTeX source) |
| 52 |
#ifdef TEST_OUTPUT_FUNCTIONS |
| 53 |
std::stringstream name; |
| 54 |
name << "rt_" << geometry << "_p" << o << ".basis"; |
| 55 |
std::ofstream out(name.str().c_str()); |
| 56 |
Dune::basisPrint<0,BasisFactory,typename BasisFactory::StorageField,geometry>(out,basis); |
| 57 |
Dune::basisPrint<1,BasisFactory,typename BasisFactory::StorageField,geometry>(out,basis); |
| 58 |
#endif // TEST_OUTPUT_FUNCTIONS |
| 59 |
|
| 60 |
// test interpolation |
| 61 |
typedef Dune::RaviartThomasL2InterpolationFactory<geometry.dim(),StorageField> InterpolationFactory; |
| 62 |
const typename InterpolationFactory::Object &interpol = *InterpolationFactory::template create<geometry>(o); |
| 63 |
Dune::DynamicMatrix<StorageField> matrix; |
| 64 |
interpol.interpolate(basis,matrix); |
| 65 |
for (unsigned int i=0; i<matrix.rows(); ++i) |
| 66 |
matrix[i][i]-=1; |
| 67 |
for (unsigned int i=0; i<matrix.rows(); ++i) |
| 68 |
for (unsigned int j=0; j<matrix.cols(); ++j) |
| 69 |
if ( std::abs( matrix[i][j] ) > 1000.*Dune::Zero<double>::epsilon() ) |
| 70 |
std::cout << " non-zero entry in interpolation matrix: " |
| 71 |
<< "(" << i << "," << j << ") = " << Dune::field_cast<double>(matrix[i][j]) |
| 72 |
<< std::endl; |
| 73 |
|
| 74 |
BasisFactory::release(&basis); |
| 75 |
} |
| 76 |
if (!ret) { |
| 77 |
std::cout << " FAILED !" << std::endl; |
| 78 |
} |
| 79 |
return ret; |
| 80 |
} |
| 81 |
|
| 82 |
#ifdef CHECKDIM |
| 83 |
#if CHECKDIM==1 |
| 84 |
#define CHECKDIM1 |
| 85 |
#elif CHECKDIM==2 |
| 86 |
#define CHECKDIM2 |
| 87 |
#elif CHECKDIM==3 |
| 88 |
#define CHECKDIM3 |
| 89 |
#elif CHECKDIM==4 |
| 90 |
#define CHECKDIM4 |
| 91 |
#endif |
| 92 |
#else |
| 93 |
#define CHECKDIM1 |
| 94 |
#define CHECKDIM2 |
| 95 |
#define CHECKDIM3 |
| 96 |
#define CHECKDIM4 |
| 97 |
#endif |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
int main ( int argc, char **argv ) |
| 102 |
{ |
| 103 |
using namespace Dune; |
| 104 |
using namespace Impl; |
| 105 |
|
| 106 |
unsigned int order = (argc < 2) ? 5 : atoi(argv[1]); |
| 107 |
|
| 108 |
if (argc < 2) |
| 109 |
{ |
| 110 |
std::cerr << "Usage: " << argv[ 0 ] << " <p>" << std::endl |
| 111 |
<< "Using default order of " << order << std::endl; |
| 112 |
} |
| 113 |
#ifdef TOPOLOGY |
| 114 |
return (test<TOPOLOGY>(order) ? 0 : 1 ); |
| 115 |
#else |
| 116 |
bool tests = true; |
| 117 |
|
| 118 |
#ifdef CHECKDIM1 |
| 119 |
tests &= test<GeometryTypes::simplex(1)> (order); |
| 120 |
#endif |
| 121 |
|
| 122 |
#ifdef CHECKDIM2 |
| 123 |
tests &= test<GeometryTypes::simplex(2)> (order); |
| 124 |
#endif |
| 125 |
|
| 126 |
#ifdef CHECKDIM3 |
| 127 |
tests &= test<GeometryTypes::simplex(3)> (order); |
| 128 |
#endif |
| 129 |
|
| 130 |
// reduce tested order to 4 in 4d unless explicitly asked for more |
| 131 |
if (argc < 2) |
| 132 |
order = 4; |
| 133 |
|
| 134 |
#ifdef CHECKDIM4 |
| 135 |
tests &= test<GeometryTypes::simplex(4)> (order); |
| 136 |
#endif |
| 137 |
|
| 138 |
return (tests ? 0 : 1); |
| 139 |
#endif // TOPOLOGY |
| 140 |
} |