| 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_PRISM_LOCALBASIS_HH |
| 6 |
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_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 prism. |
| 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 |
* \ingroup RaviartThomasImpl |
| 24 |
* \nosubgrouping |
| 25 |
*/ |
| 26 |
template<class D, class R> |
| 27 |
class RT0PrismLocalBasis |
| 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 |
RT0PrismLocalBasis (std::bitset<5> s = 0) |
| 40 |
{ |
| 41 |
for (size_t i=0; i<size(); i++) |
| 42 |
sign[i] = s[i] ? -1.0 : 1.0; |
| 43 |
} |
| 44 |
|
| 45 |
//! \brief number of shape functions |
| 46 |
unsigned int size () const |
| 47 |
{ |
| 48 |
return 5; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* \brief Evaluate all shape functions |
| 53 |
* |
| 54 |
* \param in Position |
| 55 |
* \param out return value |
| 56 |
*/ |
| 57 |
inline void evaluateFunction (const typename Traits::DomainType& in, |
| 58 |
std::vector<typename Traits::RangeType>& out) const |
| 59 |
{ |
| 60 |
out.resize(5); |
| 61 |
|
| 62 |
out[0] = { in[0], -1.0 + in[1], 0.0}; |
| 63 |
|
| 64 |
out[1] = { -1.0 + in[0], in[1], 0.0}; |
| 65 |
|
| 66 |
out[2] = { in[0], in[1], 0.0}; |
| 67 |
|
| 68 |
out[3] = { 0.0, 0.0, -2.0 + 2.0*in[2]}; |
| 69 |
|
| 70 |
out[4] = { 0.0, 0.0, 2.0*in[2]}; |
| 71 |
|
| 72 |
for (std::size_t i=0; i<out.size(); i++) |
| 73 |
out[i] *= sign[i]; |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* \brief Evaluate Jacobian of all shape functions |
| 79 |
* |
| 80 |
* \param in Position |
| 81 |
* \param out return value |
| 82 |
*/ |
| 83 |
inline void evaluateJacobian (const typename Traits::DomainType& in, |
| 84 |
std::vector<typename Traits::JacobianType>& out) const |
| 85 |
{ |
| 86 |
out.resize(5); |
| 87 |
|
| 88 |
for (std::size_t i=0; i<size(); i++) |
| 89 |
for(int j=0; j<3; j++) |
| 90 |
out[i][j] = {0.0, 0.0, 0.0}; |
| 91 |
|
| 92 |
out[0][0][0] = sign[0]; |
| 93 |
out[0][1][1] = sign[0]; |
| 94 |
|
| 95 |
out[1][0][0] = sign[1]; |
| 96 |
out[1][1][1] = sign[1]; |
| 97 |
|
| 98 |
out[2][0][0] = sign[2]; |
| 99 |
out[2][1][1] = sign[2]; |
| 100 |
|
| 101 |
out[3][2][2] = sign[3]*(2.0); |
| 102 |
|
| 103 |
out[4][2][2] = sign[4]*(2.0); |
| 104 |
} |
| 105 |
|
| 106 |
//! \brief Evaluate partial derivatives of all shape functions |
| 107 |
void partial (const std::array<unsigned int, 3>& order, |
| 108 |
const typename Traits::DomainType& in, // position |
| 109 |
std::vector<typename Traits::RangeType>& out) const // return value |
| 110 |
{ |
| 111 |
auto totalOrder = std::accumulate(order.begin(), order.end(), 0); |
| 112 |
if (totalOrder == 0) { |
| 113 |
evaluateFunction(in, out); |
| 114 |
} else { |
| 115 |
DUNE_THROW(NotImplemented, "Desired derivative order is not implemented"); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
//! \brief Polynomial order of the shape functions |
| 120 |
unsigned int order () const |
| 121 |
{ |
| 122 |
return 1; |
| 123 |
} |
| 124 |
|
| 125 |
private: |
| 126 |
std::array<R,5> sign; |
| 127 |
}; |
| 128 |
} |
| 129 |
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALBASIS_HH |