| 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 |
#ifndef DUNE_LOCALFUNCTIONS_META_POWER_HH |
| 7 |
#define DUNE_LOCALFUNCTIONS_META_POWER_HH |
| 8 |
|
| 9 |
#include <cstddef> |
| 10 |
#include <memory> |
| 11 |
|
| 12 |
#include <dune/geometry/type.hh> |
| 13 |
|
| 14 |
#include <dune/localfunctions/meta/power/basis.hh> |
| 15 |
#include <dune/localfunctions/meta/power/coefficients.hh> |
| 16 |
#include <dune/localfunctions/meta/power/interpolation.hh> |
| 17 |
|
| 18 |
namespace Dune { |
| 19 |
|
| 20 |
//! \brief Meta-finite element turning a scalar finite element into |
| 21 |
//! vector-valued one |
| 22 |
/** |
| 23 |
* \ingroup LocalFunctions |
| 24 |
* |
| 25 |
* \tparam Backend Type of finite element to take the power of. |
| 26 |
* \tparam dimR Power to raise the finite element to. |
| 27 |
*/ |
| 28 |
template<class Backend, std::size_t dimR> |
| 29 |
class PowerFiniteElement { |
| 30 |
public: |
| 31 |
//! types of component objects |
| 32 |
struct Traits { |
| 33 |
//! type of the Basis |
| 34 |
typedef PowerBasis<typename Backend::Traits::Basis, dimR> Basis; |
| 35 |
//! type of the Coefficients |
| 36 |
typedef PowerCoefficients Coefficients; |
| 37 |
//! type of the Interpolation |
| 38 |
typedef PowerInterpolation<typename Backend::Traits::Interpolation, |
| 39 |
typename Basis::Traits> Interpolation; |
| 40 |
}; |
| 41 |
private: |
| 42 |
std::shared_ptr<const Backend> backend; |
| 43 |
typename Traits::Basis basis_; |
| 44 |
typename Traits::Coefficients coefficients_; |
| 45 |
typename Traits::Interpolation interpolation_; |
| 46 |
|
| 47 |
public: |
| 48 |
//! Construct a finite element |
| 49 |
/** |
| 50 |
* \note With this constructor a copy of the backend finite element is |
| 51 |
* stored in this object. |
| 52 |
*/ |
| 53 |
PowerFiniteElement(const Backend &backend_) : |
| 54 |
backend(new Backend(backend_)), |
| 55 |
basis_(backend->basis()), |
| 56 |
coefficients_(backend->coefficients(), dimR), |
| 57 |
interpolation_(backend->interpolation()) |
| 58 |
{ } |
| 59 |
|
| 60 |
//! Construct a finite element |
| 61 |
/** |
| 62 |
* \note With this constructor ownership of the backend finite element is |
| 63 |
* determined by the shared_ptr. |
| 64 |
*/ |
| 65 |
PowerFiniteElement(const std::shared_ptr<const Backend> &backendSPtr) : |
| 66 |
backend(backendSPtr), |
| 67 |
basis_(backend->basis()), |
| 68 |
coefficients_(backend->coefficients(), dimR), |
| 69 |
interpolation_(backend->interpolation()) |
| 70 |
{ } |
| 71 |
|
| 72 |
//! Extract basis of this finite element |
| 73 |
/** |
| 74 |
* The returned lvalue must have a lifetime at least as long as the finite |
| 75 |
* element object it was acquired from. |
| 76 |
*/ |
| 77 |
const typename Traits::Basis& basis() const { return basis_; } |
| 78 |
//! Extract coefficients of this finite element |
| 79 |
/** |
| 80 |
* The returned lvalue must have a lifetime at least as long as the finite |
| 81 |
* element object it was acquired from. |
| 82 |
*/ |
| 83 |
const typename Traits::Coefficients& coefficients() const |
| 84 |
{ return coefficients_; } |
| 85 |
//! Extract interpolation of this finite element |
| 86 |
/** |
| 87 |
* The returned lvalue must have a lifetime at least as long as the finite |
| 88 |
* element object it was acquired from. |
| 89 |
*/ |
| 90 |
const typename Traits::Interpolation& interpolation() const |
| 91 |
{ return interpolation_; } |
| 92 |
//! Extract geometry type of this finite element |
| 93 |
GeometryType type() const { return backend->type(); } |
| 94 |
}; |
| 95 |
|
| 96 |
//! \brief Factory for meta-finite elements turning scalar finite elements |
| 97 |
//! into vector-valued ones |
| 98 |
/** |
| 99 |
* \implements FiniteElementFactory |
| 100 |
* \ingroup LocalFunctionsImpl |
| 101 |
* |
| 102 |
* \tparam BackendFiniteElement Type of finite element to take the power of. |
| 103 |
* \tparam dimR Power to raise the finite element to. |
| 104 |
*/ |
| 105 |
template<class BackendFiniteElement, std::size_t dimR> |
| 106 |
class PowerFiniteElementFactory |
| 107 |
{ |
| 108 |
public: |
| 109 |
//! Type of the finite element |
| 110 |
typedef PowerFiniteElement<BackendFiniteElement, dimR> FiniteElement; |
| 111 |
|
| 112 |
//! create a finite element |
| 113 |
/** |
| 114 |
* \note With this overload of make() the backend finite element is copied |
| 115 |
* into the created object. |
| 116 |
*/ |
| 117 |
const FiniteElement make(const BackendFiniteElement &backend) const |
| 118 |
{ return FiniteElement(backend); } |
| 119 |
//! create a finite element |
| 120 |
/** |
| 121 |
* \note With this overload of make() ownership of the backend finite |
| 122 |
* element is determined by the shared_ptr. |
| 123 |
*/ |
| 124 |
const FiniteElement |
| 125 |
make(const std::shared_ptr<const BackendFiniteElement> &backendSPtr) const |
| 126 |
{ return FiniteElement(backendSPtr); } |
| 127 |
|
| 128 |
}; |
| 129 |
|
| 130 |
} // namespace Dune |
| 131 |
|
| 132 |
#endif // DUNE_LOCALFUNCTIONS_META_POWER_HH |