| 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_CUBE2D_ALL_HH |
| 6 |
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE2D_ALL_HH |
| 7 |
|
| 8 |
#include <cstddef> |
| 9 |
#include <numeric> |
| 10 |
#include <vector> |
| 11 |
|
| 12 |
#include <dune/common/fmatrix.hh> |
| 13 |
|
| 14 |
#include <dune/localfunctions/common/localbasis.hh> |
| 15 |
#include <dune/localfunctions/common/localkey.hh> |
| 16 |
|
| 17 |
namespace Dune |
| 18 |
{ |
| 19 |
/** |
| 20 |
\brief Lowest order Raviart-Thomas shape functions on the reference quadrilateral. |
| 21 |
|
| 22 |
\tparam D Type to represent the field in the domain. |
| 23 |
\tparam R Type to represent the field in the range. |
| 24 |
|
| 25 |
\nosubgrouping |
| 26 |
* \ingroup RaviartThomasImpl |
| 27 |
*/ |
| 28 |
template<class D, class R> |
| 29 |
class RT0Cube2DLocalBasis |
| 30 |
{ |
| 31 |
public: |
| 32 |
typedef LocalBasisTraits<D,2,Dune::FieldVector<D,2>,R,2,Dune::FieldVector<R,2>, |
| 33 |
Dune::FieldMatrix<R,2,2> > Traits; |
| 34 |
|
| 35 |
//! \brief Constructor with a set of edge orientations |
| 36 |
RT0Cube2DLocalBasis (std::bitset<4> s = 0) |
| 37 |
{ |
| 38 |
for (int i=0; i<4; i++) |
| 39 |
sign_[i] = s[i] ? -1.0 : 1.0; |
| 40 |
} |
| 41 |
|
| 42 |
//! \brief number of shape functions |
| 43 |
unsigned int size () const |
| 44 |
{ |
| 45 |
return 4; |
| 46 |
} |
| 47 |
|
| 48 |
//! \brief Evaluate all shape functions |
| 49 |
inline void evaluateFunction (const typename Traits::DomainType& in, |
| 50 |
std::vector<typename Traits::RangeType>& out) const |
| 51 |
{ |
| 52 |
out.resize(4); |
| 53 |
out[0] = {sign_[0]*(in[0]-1.0), 0.0}; |
| 54 |
out[1] = {sign_[1]*(in[0]), 0.0}; |
| 55 |
out[2] = {0.0, sign_[2]*(in[1]-1.0)}; |
| 56 |
out[3] = {0.0, sign_[3]*(in[1])}; |
| 57 |
} |
| 58 |
|
| 59 |
//! \brief Evaluate Jacobian of all shape functions |
| 60 |
inline void |
| 61 |
evaluateJacobian (const typename Traits::DomainType& in, // position |
| 62 |
std::vector<typename Traits::JacobianType>& out) const // return value |
| 63 |
{ |
| 64 |
out.resize(4); |
| 65 |
out[0][0] = {sign_[0], 0}; |
| 66 |
out[0][1] = {0, 0}; |
| 67 |
|
| 68 |
out[1][0] = {sign_[1], 0}; |
| 69 |
out[1][1] = {0, 0}; |
| 70 |
|
| 71 |
out[2][0] = {0, 0}; |
| 72 |
out[2][1] = {0, sign_[2]}; |
| 73 |
|
| 74 |
out[3][0] = {0, 0}; |
| 75 |
out[3][1] = {0, sign_[3]}; |
| 76 |
} |
| 77 |
|
| 78 |
//! \brief Evaluate partial derivatives of all shape functions |
| 79 |
void partial (const std::array<unsigned int, 2>& order, |
| 80 |
const typename Traits::DomainType& in, // position |
| 81 |
std::vector<typename Traits::RangeType>& out) const // return value |
| 82 |
{ |
| 83 |
auto totalOrder = std::accumulate(order.begin(), order.end(), 0); |
| 84 |
if (totalOrder == 0) { |
| 85 |
evaluateFunction(in, out); |
| 86 |
} else if (totalOrder == 1) { |
| 87 |
auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1)); |
| 88 |
out.resize(size()); |
| 89 |
|
| 90 |
for (std::size_t i = 0; i < size(); ++i) |
| 91 |
out[i] = {0, 0}; |
| 92 |
|
| 93 |
switch (direction) { |
| 94 |
case 0: |
| 95 |
out[0][0] = sign_[0]; |
| 96 |
out[1][0] = sign_[1]; |
| 97 |
break; |
| 98 |
case 1: |
| 99 |
out[2][1] = sign_[2]; |
| 100 |
out[3][1] = sign_[3]; |
| 101 |
break; |
| 102 |
default: |
| 103 |
DUNE_THROW(RangeError, "Component out of range."); |
| 104 |
} |
| 105 |
} else { |
| 106 |
out.resize(size()); |
| 107 |
for (std::size_t i = 0; i < size(); ++i) |
| 108 |
for (std::size_t j = 0; j < 2; ++j) |
| 109 |
out[i][j] = 0; |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
//! \brief Polynomial order of the shape functions |
| 115 |
unsigned int order () const |
| 116 |
{ |
| 117 |
return 1; |
| 118 |
} |
| 119 |
|
| 120 |
private: |
| 121 |
std::array<R,4> sign_; |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
/** |
| 126 |
\brief Lowest order Raviart-Thomas shape functions on the reference quadrilateral. |
| 127 |
|
| 128 |
\tparam LB corresponding LocalBasis giving traits |
| 129 |
|
| 130 |
\nosubgrouping |
| 131 |
* \ingroup RaviartThomasImpl |
| 132 |
*/ |
| 133 |
template<class LB> |
| 134 |
class RT0Cube2DLocalInterpolation |
| 135 |
{ |
| 136 |
public: |
| 137 |
|
| 138 |
//! \brief Constructor with explicitly given edge orientations |
| 139 |
RT0Cube2DLocalInterpolation (std::bitset<4> s = 0) |
| 140 |
{ |
| 141 |
for (int i=0; i<4; i++) |
| 142 |
sign_[i] = s[i] ? -1.0 : 1.0; |
| 143 |
|
| 144 |
m0 = {0.0, 0.5}; |
| 145 |
m1 = {1.0, 0.5}; |
| 146 |
m2 = {0.5, 0.0}; |
| 147 |
m3 = {0.5, 1.0}; |
| 148 |
|
| 149 |
n0 = {-1.0, 0.0}; |
| 150 |
n1 = { 1.0, 0.0}; |
| 151 |
n2 = { 0.0, -1.0}; |
| 152 |
n3 = { 0.0, 1.0}; |
| 153 |
} |
| 154 |
|
| 155 |
template<typename F, typename C> |
| 156 |
void interpolate (const F& f, std::vector<C>& out) const |
| 157 |
{ |
| 158 |
// f gives v*outer normal at a point on the edge! |
| 159 |
|
| 160 |
out.resize(4); |
| 161 |
|
| 162 |
// Evaluate the normal components at the edge midpoints |
| 163 |
auto y = f(m0); out[0] = (y[0]*n0[0]+y[1]*n0[1])*sign_[0]; |
| 164 |
y = f(m1); out[1] = (y[0]*n1[0]+y[1]*n1[1])*sign_[1]; |
| 165 |
y = f(m2); out[2] = (y[0]*n2[0]+y[1]*n2[1])*sign_[2]; |
| 166 |
y = f(m3); out[3] = (y[0]*n3[0]+y[1]*n3[1])*sign_[3]; |
| 167 |
} |
| 168 |
|
| 169 |
private: |
| 170 |
std::array<typename LB::Traits::RangeFieldType,4> sign_; |
| 171 |
|
| 172 |
// The four edge midpoints of the reference quadrilateral |
| 173 |
typename LB::Traits::DomainType m0,m1,m2,m3; |
| 174 |
|
| 175 |
// The four edge normals of the reference quadrilateral |
| 176 |
typename LB::Traits::DomainType n0,n1,n2,n3; |
| 177 |
}; |
| 178 |
|
| 179 |
/** |
| 180 |
\brief Layout map for RT0 elements on quadrilaterals |
| 181 |
|
| 182 |
\nosubgrouping |
| 183 |
* \ingroup RaviartThomasImpl |
| 184 |
\implements Dune::LocalCoefficientsVirtualImp |
| 185 |
*/ |
| 186 |
class RT0Cube2DLocalCoefficients |
| 187 |
{ |
| 188 |
public: |
| 189 |
//! \brief Standard constructor |
| 190 |
RT0Cube2DLocalCoefficients () : li(4) |
| 191 |
{ |
| 192 |
for (std::size_t i=0; i<4; i++) |
| 193 |
li[i] = LocalKey(i,1,0); |
| 194 |
} |
| 195 |
|
| 196 |
//! number of coefficients |
| 197 |
std::size_t size () const |
| 198 |
{ |
| 199 |
return 4; |
| 200 |
} |
| 201 |
|
| 202 |
//! get i'th index |
| 203 |
const LocalKey& localKey (std::size_t i) const |
| 204 |
{ |
| 205 |
return li[i]; |
| 206 |
} |
| 207 |
|
| 208 |
private: |
| 209 |
std::vector<LocalKey> li; |
| 210 |
}; |
| 211 |
|
| 212 |
} |
| 213 |
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE2D_ALL_HH |