| 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_LOCALFUNCTIONS_RAVIARTTHOMAS0_PYRAMID_LOCALBASIS_HH |
| 6 |
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PYRAMID_LOCALBASIS_HH |
| 7 |
|
| 8 |
#include <numeric> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#include <dune/common/fmatrix.hh> |
| 12 |
|
| 13 |
#include "../../common/localbasis.hh" |
| 14 |
|
| 15 |
namespace Dune |
| 16 |
{ |
| 17 |
/** |
| 18 |
* \brief First order Raviart-Thomas shape functions on the reference pyramid. |
| 19 |
* |
| 20 |
* \tparam D Type to represent the field in the domain. |
| 21 |
* \tparam R Type to represent the field in the range. |
| 22 |
* |
| 23 |
* \nosubgrouping |
| 24 |
* \ingroup RaviartThomasImpl |
| 25 |
*/ |
| 26 |
template<class D, class R> |
| 27 |
class RT0PyramidLocalBasis |
| 28 |
{ |
| 29 |
|
| 30 |
public: |
| 31 |
typedef LocalBasisTraits<D,3,Dune::FieldVector<D,3>,R,3,Dune::FieldVector<R,3>, |
| 32 |
Dune::FieldMatrix<R,3,3> > Traits; |
| 33 |
|
| 34 |
/** |
| 35 |
* \brief Make set number s, where 0 <= s < 32 |
| 36 |
* |
| 37 |
* \param s Edge orientation indicator |
| 38 |
*/ |
| 39 |
RT0PyramidLocalBasis (std::bitset<5> s = 0) |
| 40 |
{ |
| 41 |
// For each basis function we store the constant offset vector |
| 42 |
// and the factor of the linear term for both sub-elements. |
| 43 |
// In the j-th sub-element the i-th basis function is then |
| 44 |
// given by y = offset_[i][j] + factor_[i][j]*x. |
| 45 |
offset_[0][0] = {0.0, 0.0, -1.0}; |
| 46 |
factor_[0][0] = 1.0; |
| 47 |
offset_[0][1] = {0.0, 0.0, -1.0}; |
| 48 |
factor_[0][1] = 1.0; |
| 49 |
|
| 50 |
offset_[1][0] = {-2.0, -2.0, 0.0}; |
| 51 |
factor_[1][0] = 2.0; |
| 52 |
offset_[1][1] = {0.0, 0.0, 0.0}; |
| 53 |
factor_[1][1] = 0.0; |
| 54 |
|
| 55 |
offset_[2][0] = {0.0, 0.0, 0.0}; |
| 56 |
factor_[2][0] = 0.0; |
| 57 |
offset_[2][1] = {0.0, 0.0, 0.0}; |
| 58 |
factor_[2][1] = 2.0; |
| 59 |
|
| 60 |
offset_[3][0] = {0.0, 0.0, 0.0}; |
| 61 |
factor_[3][0] = 0.0; |
| 62 |
offset_[3][1] = {-2.0, -2.0, 0.0}; |
| 63 |
factor_[3][1] = 2.0; |
| 64 |
|
| 65 |
offset_[4][0] = {0.0, 0.0, 0.0}; |
| 66 |
factor_[4][0] = 2.0; |
| 67 |
offset_[4][1] = {0.0, 0.0, 0.0}; |
| 68 |
factor_[4][1] = 0.0; |
| 69 |
|
| 70 |
// Interior basis function associated to the interior |
| 71 |
// face given by the intersection of the sub-elements |
| 72 |
// in the plane where x[0]==x[1]. |
| 73 |
offset_[5][0] = {0.0, -2.0, 0.0}; |
| 74 |
factor_[5][0] = 2.0; |
| 75 |
offset_[5][1] = {2.0, 0.0, 0.0}; |
| 76 |
factor_[5][1] = -2.0; |
| 77 |
|
| 78 |
for (size_t i=0; i<5; i++) |
| 79 |
sign_[i] = s[i] ? -1.0 : 1.0; |
| 80 |
|
| 81 |
// No need to flip the sign_ for the interior basis function |
| 82 |
sign_[5] = 1.0; |
| 83 |
} |
| 84 |
|
| 85 |
//! \brief number of shape functions |
| 86 |
unsigned int size () const |
| 87 |
{ |
| 88 |
return 6; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* \brief Evaluate all shape functions |
| 93 |
* |
| 94 |
* \param x Position |
| 95 |
* \param out return value |
| 96 |
*/ |
| 97 |
inline void evaluateFunction (const typename Traits::DomainType& x, |
| 98 |
std::vector<typename Traits::RangeType>& out) const |
| 99 |
{ |
| 100 |
out.resize(size()); |
| 101 |
bool compositeElement = x[0] > x[1]; |
| 102 |
for (std::size_t i=0; i<size(); i++) |
| 103 |
{ |
| 104 |
out[i] = x; |
| 105 |
out[i] *= factor_[i][compositeElement]; |
| 106 |
out[i] += offset_[i][compositeElement]; |
| 107 |
out[i] *= sign_[i]; |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* \brief Evaluate Jacobian of all shape functions |
| 113 |
* |
| 114 |
* \param x Position |
| 115 |
* \param out return value |
| 116 |
*/ |
| 117 |
inline void evaluateJacobian (const typename Traits::DomainType& x, |
| 118 |
std::vector<typename Traits::JacobianType>& out) const |
| 119 |
{ |
| 120 |
out.resize(size()); |
| 121 |
bool compositeElement = x[0] > x[1]; |
| 122 |
for (std::size_t i=0; i<size(); i++) |
| 123 |
for(std::size_t j=0; j<3; j++) |
| 124 |
for(std::size_t k=0; k<3; k++) |
| 125 |
out[i][j][k] = (j==k) * factor_[i][compositeElement] * sign_[i]; |
| 126 |
} |
| 127 |
|
| 128 |
//! \brief Evaluate partial derivatives of all shape functions |
| 129 |
void partial (const std::array<unsigned int, 3>& order, |
| 130 |
const typename Traits::DomainType& in, // position |
| 131 |
std::vector<typename Traits::RangeType>& out) const // return value |
| 132 |
{ |
| 133 |
auto totalOrder = std::accumulate(order.begin(), order.end(), 0); |
| 134 |
if (totalOrder == 0) { |
| 135 |
evaluateFunction(in, out); |
| 136 |
} else { |
| 137 |
DUNE_THROW(NotImplemented, "Desired derivative order is not implemented"); |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
//! \brief Polynomial order of the shape functions |
| 142 |
unsigned int order () const |
| 143 |
{ |
| 144 |
return 1; |
| 145 |
} |
| 146 |
|
| 147 |
private: |
| 148 |
std::array<R,6> sign_; |
| 149 |
std::array<std::array<typename Traits::RangeType, 2>, 6> offset_; |
| 150 |
std::array<std::array<R, 2>, 6> factor_; |
| 151 |
}; |
| 152 |
} |
| 153 |
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PYRAMID_LOCALBASIS_HH |