| 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_CUBE3D_ALL_HH |
| 6 |
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE3D_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 hexahedron. |
| 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 RT0Cube3DLocalBasis |
| 30 |
{ |
| 31 |
public: |
| 32 |
typedef LocalBasisTraits<D,3,Dune::FieldVector<D,3>,R,3,Dune::FieldVector<R,3>, |
| 33 |
Dune::FieldMatrix<R,3,3> > Traits; |
| 34 |
|
| 35 |
//! \brief Make set number s, where 0 <= s < 64 |
| 36 |
RT0Cube3DLocalBasis (unsigned int s = 0) |
| 37 |
{ |
| 38 |
sign0 = sign1 = sign2 = sign3 = sign4 = sign5 = 1.0; |
| 39 |
if (s&1) sign0 = -1.0; |
| 40 |
if (s&2) sign1 = -1.0; |
| 41 |
if (s&4) sign2 = -1.0; |
| 42 |
if (s&8) sign3 = -1.0; |
| 43 |
if (s&16) sign4 = -1.0; |
| 44 |
if (s&32) sign5 = -1.0; |
| 45 |
} |
| 46 |
|
| 47 |
//! \brief number of shape functions |
| 48 |
unsigned int size () const |
| 49 |
{ |
| 50 |
return 6; |
| 51 |
} |
| 52 |
|
| 53 |
//! \brief Evaluate all shape functions |
| 54 |
inline void evaluateFunction (const typename Traits::DomainType& in, |
| 55 |
std::vector<typename Traits::RangeType>& out) const |
| 56 |
{ |
| 57 |
out.resize(6); |
| 58 |
out[0][0] = sign0*(in[0]-1.0); out[0][1]=0.0; out[0][2]=0.0; |
| 59 |
out[1][0] = sign1*(in[0]); out[1][1]=0.0; out[1][2]=0.0; |
| 60 |
out[2][0] = 0.0; out[2][1]=sign2*(in[1]-1.0); out[2][2]=0.0; |
| 61 |
out[3][0] = 0.0; out[3][1]=sign3*(in[1]); out[3][2]=0.0; |
| 62 |
out[4][0] = 0.0; out[4][1]=0.0; out[4][2]=sign4*(in[2]-1.0); |
| 63 |
out[5][0] = 0.0; out[5][1]=0.0; out[5][2]=sign5*(in[2]); |
| 64 |
} |
| 65 |
|
| 66 |
//! \brief Evaluate Jacobian of all shape functions |
| 67 |
inline void |
| 68 |
evaluateJacobian (const typename Traits::DomainType& in, // position |
| 69 |
std::vector<typename Traits::JacobianType>& out) const // return value |
| 70 |
{ |
| 71 |
out.resize(6); |
| 72 |
out[0][0][0] = sign0; out[0][0][1] = 0; out[0][0][2] = 0; |
| 73 |
out[0][1][0] = 0; out[0][1][1] = 0; out[0][1][2] = 0; |
| 74 |
out[0][2][0] = 0; out[0][2][1] = 0; out[0][2][2] = 0; |
| 75 |
|
| 76 |
out[1][0][0] = sign1; out[1][0][1] = 0; out[1][0][2] = 0; |
| 77 |
out[1][1][0] = 0; out[1][1][1] = 0; out[1][1][2] = 0; |
| 78 |
out[1][2][0] = 0; out[1][2][1] = 0; out[1][2][2] = 0; |
| 79 |
|
| 80 |
out[2][0][0] = 0; out[2][0][1] = 0; out[2][0][2] = 0; |
| 81 |
out[2][1][0] = 0; out[2][1][1] = sign2; out[2][1][2] = 0; |
| 82 |
out[2][2][0] = 0; out[2][2][1] = 0; out[2][2][2] = 0; |
| 83 |
|
| 84 |
out[3][0][0] = 0; out[3][0][1] = 0; out[3][0][2] = 0; |
| 85 |
out[3][1][0] = 0; out[3][1][1] = sign3; out[3][1][2] = 0; |
| 86 |
out[3][2][0] = 0; out[3][2][1] = 0; out[3][2][2] = 0; |
| 87 |
|
| 88 |
out[4][0][0] = 0; out[4][0][1] = 0; out[4][0][2] = 0; |
| 89 |
out[4][1][0] = 0; out[4][1][1] = 0; out[4][1][2] = 0; |
| 90 |
out[4][2][0] = 0; out[4][2][1] = 0; out[4][2][2] = sign4; |
| 91 |
|
| 92 |
out[5][0][0] = 0; out[5][0][1] = 0; out[5][0][2] = 0; |
| 93 |
out[5][1][0] = 0; out[5][1][1] = 0; out[5][1][2] = 0; |
| 94 |
out[5][2][0] = 0; out[5][2][1] = 0; out[5][2][2] = sign5; |
| 95 |
} |
| 96 |
|
| 97 |
//! \brief Evaluate partial derivatives of all shape functions |
| 98 |
void partial (const std::array<unsigned int, 3>& order, |
| 99 |
const typename Traits::DomainType& in, // position |
| 100 |
std::vector<typename Traits::RangeType>& out) const // return value |
| 101 |
{ |
| 102 |
auto totalOrder = std::accumulate(order.begin(), order.end(), 0); |
| 103 |
if (totalOrder == 0) { |
| 104 |
evaluateFunction(in, out); |
| 105 |
} else if (totalOrder == 1) { |
| 106 |
auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1)); |
| 107 |
out.resize(size()); |
| 108 |
|
| 109 |
for (std::size_t i = 0; i < size(); ++i) |
| 110 |
out[i][0] = out[i][1] = out[i][2] = 0; |
| 111 |
|
| 112 |
switch (direction) { |
| 113 |
case 0: |
| 114 |
out[0][0] = sign0; |
| 115 |
out[1][0] = sign1; |
| 116 |
break; |
| 117 |
case 1: |
| 118 |
out[2][1] = sign2; |
| 119 |
out[3][1] = sign3; |
| 120 |
break; |
| 121 |
case 2: |
| 122 |
out[4][2] = sign4; |
| 123 |
out[5][2] = sign5; |
| 124 |
break; |
| 125 |
default: |
| 126 |
DUNE_THROW(RangeError, "Component out of range."); |
| 127 |
} |
| 128 |
} else { |
| 129 |
out.resize(size()); |
| 130 |
for (std::size_t i = 0; i < size(); ++i) |
| 131 |
for (std::size_t j = 0; j < 2; ++j) |
| 132 |
out[i][j] = 0; |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
//! \brief Polynomial order of the shape functions |
| 138 |
unsigned int order () const |
| 139 |
{ |
| 140 |
return 1; |
| 141 |
} |
| 142 |
|
| 143 |
private: |
| 144 |
R sign0, sign1, sign2, sign3, sign4, sign5; |
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
\brief Lowest order Raviart-Thomas shape functions on the reference hexahedron. |
| 150 |
|
| 151 |
\tparam LB corresponding LocalBasis giving traits |
| 152 |
|
| 153 |
* \ingroup RaviartThomasImpl |
| 154 |
\nosubgrouping |
| 155 |
*/ |
| 156 |
template<class LB> |
| 157 |
class RT0Cube3DLocalInterpolation |
| 158 |
{ |
| 159 |
public: |
| 160 |
|
| 161 |
//! \brief Make set number s, where 0 <= s < 64 |
| 162 |
RT0Cube3DLocalInterpolation (unsigned int s = 0) |
| 163 |
{ |
| 164 |
sign0 = sign1 = sign2 = sign3 = sign4 = sign5 = 1.0; |
| 165 |
if (s&1) sign0 *= -1.0; |
| 166 |
if (s&2) sign1 *= -1.0; |
| 167 |
if (s&4) sign2 *= -1.0; |
| 168 |
if (s&8) sign3 *= -1.0; |
| 169 |
if (s&16) sign4 *= -1.0; |
| 170 |
if (s&32) sign5 *= -1.0; |
| 171 |
|
| 172 |
m0[0] = 0.0; m0[1] = 0.5; m0[2] = 0.5; |
| 173 |
m1[0] = 1.0; m1[1] = 0.5; m1[2] = 0.5; |
| 174 |
m2[0] = 0.5; m2[1] = 0.0; m2[2] = 0.5; |
| 175 |
m3[0] = 0.5; m3[1] = 1.0; m3[2] = 0.5; |
| 176 |
m4[0] = 0.5; m4[1] = 0.5; m4[2] = 0.0; |
| 177 |
m5[0] = 0.5; m5[1] = 0.5; m5[2] = 1.0; |
| 178 |
|
| 179 |
n0[0] = -1.0; n0[1] = 0.0; n0[2] = 0.0; |
| 180 |
n1[0] = 1.0; n1[1] = 0.0; n1[2] = 0.0; |
| 181 |
n2[0] = 0.0; n2[1] = -1.0; n2[2] = 0.0; |
| 182 |
n3[0] = 0.0; n3[1] = 1.0; n3[2] = 0.0; |
| 183 |
n4[0] = 0.0; n4[1] = 0.0; n4[2] =-1.0; |
| 184 |
n5[0] = 0.0; n5[1] = 0.0; n5[2] = 1.0; |
| 185 |
} |
| 186 |
|
| 187 |
template<typename F, typename C> |
| 188 |
void interpolate (const F& f, std::vector<C>& out) const |
| 189 |
{ |
| 190 |
// f gives v*outer normal at a point on the edge! |
| 191 |
|
| 192 |
out.resize(6); |
| 193 |
|
| 194 |
auto y = f(m0); out[0] = (y[0]*n0[0]+y[1]*n0[1]+y[2]*n0[2])*sign0; |
| 195 |
y = f(m1); out[1] = (y[0]*n1[0]+y[1]*n1[1]+y[2]*n1[2])*sign1; |
| 196 |
y = f(m2); out[2] = (y[0]*n2[0]+y[1]*n2[1]+y[2]*n2[2])*sign2; |
| 197 |
y = f(m3); out[3] = (y[0]*n3[0]+y[1]*n3[1]+y[2]*n3[2])*sign3; |
| 198 |
y = f(m4); out[4] = (y[0]*n4[0]+y[1]*n4[1]+y[2]*n4[2])*sign4; |
| 199 |
y = f(m5); out[5] = (y[0]*n5[0]+y[1]*n5[1]+y[2]*n5[2])*sign5; |
| 200 |
} |
| 201 |
|
| 202 |
private: |
| 203 |
typename LB::Traits::RangeFieldType sign0,sign1,sign2,sign3,sign4,sign5; |
| 204 |
typename LB::Traits::DomainType m0,m1,m2,m3,m4,m5; |
| 205 |
typename LB::Traits::DomainType n0,n1,n2,n3,n4,n5; |
| 206 |
}; |
| 207 |
|
| 208 |
/** |
| 209 |
\brief Layout map for RT0 elements on quadrilaterals |
| 210 |
|
| 211 |
\nosubgrouping |
| 212 |
* \ingroup RaviartThomasImpl |
| 213 |
\implements Dune::LocalCoefficientsVirtualImp |
| 214 |
*/ |
| 215 |
class RT0Cube3DLocalCoefficients |
| 216 |
{ |
| 217 |
public: |
| 218 |
//! \brief Standard constructor |
| 219 |
RT0Cube3DLocalCoefficients () : li(6) |
| 220 |
{ |
| 221 |
for (std::size_t i=0; i<6; i++) |
| 222 |
li[i] = LocalKey(i,1,0); |
| 223 |
} |
| 224 |
|
| 225 |
//! number of coefficients |
| 226 |
std::size_t size () const |
| 227 |
{ |
| 228 |
return 6; |
| 229 |
} |
| 230 |
|
| 231 |
//! get i'th index |
| 232 |
const LocalKey& localKey (std::size_t i) const |
| 233 |
{ |
| 234 |
return li[i]; |
| 235 |
} |
| 236 |
|
| 237 |
private: |
| 238 |
std::vector<LocalKey> li; |
| 239 |
}; |
| 240 |
|
| 241 |
} |
| 242 |
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_CUBE3D_ALL_HH |