| 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 |
#ifndef DUNE_GENERIC_LOCALFINITEELEMENT_HH |
| 6 |
#define DUNE_GENERIC_LOCALFINITEELEMENT_HH |
| 7 |
|
| 8 |
#include <dune/geometry/type.hh> |
| 9 |
#include <dune/geometry/typeindex.hh> |
| 10 |
|
| 11 |
#include <dune/localfunctions/common/localfiniteelementtraits.hh> |
| 12 |
#include <dune/localfunctions/utility/l2interpolation.hh> |
| 13 |
#include <dune/localfunctions/utility/dglocalcoefficients.hh> |
| 14 |
|
| 15 |
namespace Dune |
| 16 |
{ |
| 17 |
/** |
| 18 |
* \brief A LocalFiniteElement implementation based on three |
| 19 |
* TopologyFactories providing the LocalBasis, LocalCoefficients, |
| 20 |
* and LocalInterpolations. Note the key type for all three |
| 21 |
* factories must coincide. |
| 22 |
**/ |
| 23 |
template< class BasisF, class CoeffF, class InterpolF> |
| 24 |
struct GenericLocalFiniteElement |
| 25 |
{ |
| 26 |
typedef GenericLocalFiniteElement<BasisF, CoeffF, InterpolF> This; |
| 27 |
typedef LocalFiniteElementTraits< typename BasisF::Object, |
| 28 |
typename CoeffF::Object, |
| 29 |
typename InterpolF::Object > Traits; |
| 30 |
|
| 31 |
typedef typename BasisF::Key Key; |
| 32 |
static const unsigned int dimDomain = BasisF::dimension; |
| 33 |
|
| 34 |
typedef BasisF BasisFactory; |
| 35 |
typedef CoeffF CoefficientFactory; |
| 36 |
typedef InterpolF InterpolationFactory; |
| 37 |
|
| 38 |
static_assert(std::is_same<Key, typename CoeffF::Key>::value, |
| 39 |
"incompatible keys between BasisCreator and CoefficientsCreator"); |
| 40 |
static_assert(std::is_same<Key, typename InterpolF::Key>::value, |
| 41 |
"incompatible keys between BasisCreator and InterpolationCreator" ); |
| 42 |
|
| 43 |
/** \todo Please doc me */ |
| 44 |
GenericLocalFiniteElement ( const GeometryType >, const Key &key ) |
| 45 |
: geometry_( gt ), |
| 46 |
key_( key ), |
| 47 |
finiteElement_() |
| 48 |
{ |
| 49 |
Impl::toGeometryTypeIdConstant<dimDomain>(type(), [&](auto geometryTypeId) { |
| 50 |
finiteElement_.template create<decltype(geometryTypeId)::value>(key_); |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
/** \todo Please doc me */ |
| 55 |
GenericLocalFiniteElement ( const GenericLocalFiniteElement &other ) |
| 56 |
: geometry_( other.type() ), |
| 57 |
key_( other.key_ ), |
| 58 |
finiteElement_() |
| 59 |
{ |
| 60 |
Impl::toGeometryTypeIdConstant<dimDomain>(type(), [&](auto geometryTypeId) { |
| 61 |
finiteElement_.template create<decltype(geometryTypeId)::value>(key_); |
| 62 |
}); |
| 63 |
} |
| 64 |
|
| 65 |
~GenericLocalFiniteElement() |
| 66 |
{ |
| 67 |
finiteElement_.release(); |
| 68 |
} |
| 69 |
|
| 70 |
/** \todo Please doc me ! |
| 71 |
*/ |
| 72 |
const typename Traits::LocalBasisType& localBasis () const |
| 73 |
{ |
| 74 |
return *(finiteElement_.basis_); |
| 75 |
} |
| 76 |
|
| 77 |
/** \todo Please doc me ! |
| 78 |
*/ |
| 79 |
const typename Traits::LocalCoefficientsType& localCoefficients () const |
| 80 |
{ |
| 81 |
return *(finiteElement_.coeff_); |
| 82 |
} |
| 83 |
|
| 84 |
/** \todo Please doc me ! |
| 85 |
*/ |
| 86 |
const typename Traits::LocalInterpolationType& localInterpolation () const |
| 87 |
{ |
| 88 |
return *(finiteElement_.interpol_); |
| 89 |
} |
| 90 |
|
| 91 |
/** \brief Number of shape functions in this finite element */ |
| 92 |
unsigned int size () const |
| 93 |
{ |
| 94 |
return finiteElement_.basis_->size(); |
| 95 |
} |
| 96 |
|
| 97 |
/** \todo Please doc me ! |
| 98 |
*/ |
| 99 |
GeometryType type () const |
| 100 |
{ |
| 101 |
return geometry_; |
| 102 |
} |
| 103 |
private: |
| 104 |
struct FiniteElement |
| 105 |
{ |
| 106 |
FiniteElement() : basis_(0), coeff_(0), interpol_(0) {} |
| 107 |
|
| 108 |
template < GeometryType::Id geometryId > |
| 109 |
void create( const Key &key ) |
| 110 |
{ |
| 111 |
release(); |
| 112 |
basis_ = BasisF::template create<geometryId>(key); |
| 113 |
coeff_ = CoeffF::template create<geometryId>(key); |
| 114 |
interpol_ = InterpolF::template create<geometryId>(key); |
| 115 |
} |
| 116 |
void release() |
| 117 |
{ |
| 118 |
if (basis_) |
| 119 |
BasisF::release(basis_); |
| 120 |
if (coeff_) |
| 121 |
CoeffF::release(coeff_); |
| 122 |
if (interpol_) |
| 123 |
InterpolF::release(interpol_); |
| 124 |
basis_=0; |
| 125 |
coeff_=0; |
| 126 |
interpol_=0; |
| 127 |
} |
| 128 |
typename Traits::LocalBasisType *basis_; |
| 129 |
typename Traits::LocalCoefficientsType *coeff_; |
| 130 |
typename Traits::LocalInterpolationType *interpol_; |
| 131 |
}; |
| 132 |
GeometryType geometry_; |
| 133 |
Key key_; |
| 134 |
FiniteElement finiteElement_; |
| 135 |
}; |
| 136 |
|
| 137 |
/** |
| 138 |
* @brief Takes the basis and interpolation factory from a given |
| 139 |
* LocalFiniteElement (derived from GenericLocalFiniteElement) |
| 140 |
* and replaces the coefficients with dg local keys, i.e., |
| 141 |
* attaches all degrees of freedom to the codimension zero entity. |
| 142 |
**/ |
| 143 |
template <class FE> |
| 144 |
struct DGLocalFiniteElement |
| 145 |
: public GenericLocalFiniteElement< typename FE::BasisFactory, |
| 146 |
DGLocalCoefficientsFactory< typename FE::BasisFactory >, |
| 147 |
typename FE::InterpolationFactory> |
| 148 |
{ |
| 149 |
typedef GenericLocalFiniteElement< typename FE::BasisFactory, |
| 150 |
DGLocalCoefficientsFactory< typename FE::BasisFactory >, |
| 151 |
typename FE::InterpolationFactory> Base; |
| 152 |
public: |
| 153 |
typedef typename Base::Traits Traits; |
| 154 |
|
| 155 |
/** \todo Please doc me ! |
| 156 |
*/ |
| 157 |
DGLocalFiniteElement ( const GeometryType >, const typename Base::Key &key ) |
| 158 |
: Base( gt, key ) |
| 159 |
{} |
| 160 |
}; |
| 161 |
/** |
| 162 |
* @brief Takes the basis factory from a given |
| 163 |
* LocalFiniteElement (derived from GenericLocalFiniteElement) |
| 164 |
* and replaces the coefficients with dg local keys, i.e., |
| 165 |
* attaches all degrees of freedom to the codimension zero entity |
| 166 |
* and uses a l2 interpolation. |
| 167 |
**/ |
| 168 |
template <class FE> |
| 169 |
struct L2LocalFiniteElement |
| 170 |
: public GenericLocalFiniteElement< typename FE::BasisFactory, |
| 171 |
DGLocalCoefficientsFactory< typename FE::BasisFactory >, |
| 172 |
LocalL2InterpolationFactory< typename FE::BasisFactory, false > > |
| 173 |
{ |
| 174 |
typedef GenericLocalFiniteElement< typename FE::BasisFactory, |
| 175 |
DGLocalCoefficientsFactory< typename FE::BasisFactory >, |
| 176 |
LocalL2InterpolationFactory< typename FE::BasisFactory, false > > Base; |
| 177 |
public: |
| 178 |
typedef typename Base::Traits Traits; |
| 179 |
|
| 180 |
/** \todo Please doc me ! |
| 181 |
*/ |
| 182 |
L2LocalFiniteElement ( const GeometryType >, const typename Base::Key &key ) |
| 183 |
: Base( gt, key ) |
| 184 |
{} |
| 185 |
}; |
| 186 |
} |
| 187 |
|
| 188 |
#endif |