| 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_BREZZIDOUGLASMARINI2_SIMPLEX2D_LOCALINTERPOLATION_HH |
| 6 |
#define DUNE_LOCALFUNCTIONS_BREZZIDOUGLASMARINI2_SIMPLEX2D_LOCALINTERPOLATION_HH |
| 7 |
|
| 8 |
#include <vector> |
| 9 |
|
| 10 |
#include <dune/geometry/quadraturerules.hh> |
| 11 |
|
| 12 |
namespace Dune |
| 13 |
{ |
| 14 |
|
| 15 |
/** |
| 16 |
* \brief First order Brezzi-Douglas-Marini shape functions on triangles. |
| 17 |
* |
| 18 |
* \tparam LB corresponding LocalBasis giving traits |
| 19 |
* |
| 20 |
* \ingroup BrezziDouglasMariniImpl |
| 21 |
* \nosubgrouping |
| 22 |
*/ |
| 23 |
template<class LB> |
| 24 |
class BDM2Simplex2DLocalInterpolation |
| 25 |
{ |
| 26 |
|
| 27 |
public: |
| 28 |
//! \brief Standard constructor |
| 29 |
BDM2Simplex2DLocalInterpolation() |
| 30 |
{ |
| 31 |
sign0 = sign1 = sign2 = 1.0; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* \brief Make set number s, where 0 <= s < 8 |
| 36 |
* |
| 37 |
* \param s Edge orientation indicator |
| 38 |
*/ |
| 39 |
BDM2Simplex2DLocalInterpolation(unsigned int s) |
| 40 |
{ |
| 41 |
sign0 = sign1 = sign2 = 1.0; |
| 42 |
if (s & 1) |
| 43 |
{ |
| 44 |
sign0 = -1.0; |
| 45 |
} |
| 46 |
if (s & 2) |
| 47 |
{ |
| 48 |
sign1 = -1.0; |
| 49 |
} |
| 50 |
if (s & 4) |
| 51 |
{ |
| 52 |
sign2 = -1.0; |
| 53 |
} |
| 54 |
|
| 55 |
m0[0] = 0.5; |
| 56 |
m0[1] = 0.0; |
| 57 |
m1[0] = 0.0; |
| 58 |
m1[1] = 0.5; |
| 59 |
m2[0] = 0.5; |
| 60 |
m2[1] = 0.5; |
| 61 |
n0[0] = 0.0; |
| 62 |
n0[1] = -1.0; |
| 63 |
n1[0] = -1.0; |
| 64 |
n1[1] = 0.0; |
| 65 |
n2[0] = 1.0/sqrt(2.0); |
| 66 |
n2[1] = 1.0/sqrt(2.0); |
| 67 |
c0 = 0.5*n0[0] - 1.0*n0[1]; |
| 68 |
c1 = -1.0*n1[0] + 0.5*n1[1]; |
| 69 |
c2 = 0.5*n2[0] + 0.5*n2[1]; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* \brief Interpolate a given function with shape functions |
| 74 |
* |
| 75 |
* \tparam F Function type for function which should be interpolated |
| 76 |
* \tparam C Coefficient type |
| 77 |
* \param f function which should be interpolated |
| 78 |
* \param out return value, vector of coefficients |
| 79 |
*/ |
| 80 |
template<typename F, typename C> |
| 81 |
void interpolate(const F& f, std::vector<C>& out) const |
| 82 |
{ |
| 83 |
// f gives v*outer normal at a point on the edge! |
| 84 |
typedef typename LB::Traits::RangeFieldType Scalar; |
| 85 |
typedef typename LB::Traits::DomainFieldType Vector; |
| 86 |
|
| 87 |
out.resize(12); |
| 88 |
std::fill(out.begin(), out.end(), 0.0); |
| 89 |
|
| 90 |
const int qOrder = 4; |
| 91 |
const Dune::QuadratureRule<Scalar,1>& rule = Dune::QuadratureRules<Scalar,1>::rule(Dune::GeometryTypes::simplex(1), qOrder); |
| 92 |
|
| 93 |
for (typename Dune::QuadratureRule<Scalar,1>::const_iterator it=rule.begin(); it!=rule.end(); ++it) |
| 94 |
{ |
| 95 |
Scalar qPos = it->position(); |
| 96 |
|
| 97 |
typename LB::Traits::DomainType localPos; |
| 98 |
|
| 99 |
localPos[0] = qPos; |
| 100 |
localPos[1] = 0.0; |
| 101 |
auto y = f(localPos); |
| 102 |
out[0] += (y[0]*n0[0] + y[1]*n0[1])*it->weight()*sign0/c0; |
| 103 |
out[1] += (y[0]*n0[0] + y[1]*n0[1])*(1.0 - 2.0*qPos)*it->weight()/c0; |
| 104 |
out[2] += (y[0]*n0[0] + y[1]*n0[1])*(6.0*qPos*qPos - 6.0*qPos + 1.0)*it->weight()*sign0/c0; |
| 105 |
|
| 106 |
localPos[0] = 0.0; |
| 107 |
localPos[1] = qPos; |
| 108 |
y = f(localPos); |
| 109 |
out[3] += (y[0]*n1[0]+y[1]*n1[1])*it->weight()*sign1/c1; |
| 110 |
out[4] += (y[0]*n1[0]+y[1]*n1[1])*(2.0*qPos-1.0)*it->weight()/c1; |
| 111 |
out[5] += (y[0]*n1[0]+y[1]*n1[1])*(6.0*qPos*qPos - 6.0*qPos + 1.0)*it->weight()*sign1/c1; |
| 112 |
|
| 113 |
localPos[0] = 1.0 - qPos; |
| 114 |
localPos[1] = qPos; |
| 115 |
y = f(localPos); |
| 116 |
out[6] += (y[0]*n2[0] + y[1]*n2[1])*it->weight()*sign2/c2; |
| 117 |
out[7] += (y[0]*n2[0] + y[1]*n2[1])*(1.0 - 2.0*qPos)*it->weight()/c2; |
| 118 |
out[8] += (y[0]*n2[0] + y[1]*n2[1])*(6.0*qPos*qPos - 6.0*qPos + 1.0)*it->weight()*sign2/c2; |
| 119 |
} |
| 120 |
|
| 121 |
// a volume part is needed here for dofs: 9 10 11 |
| 122 |
const QuadratureRule<Vector,2>& rule2 = QuadratureRules<Vector,2>::rule(GeometryTypes::simplex(2), qOrder); |
| 123 |
|
| 124 |
for (typename QuadratureRule<Vector,2>::const_iterator it=rule2.begin(); it!=rule2.end(); ++it) |
| 125 |
{ |
| 126 |
typename LB::Traits::DomainType localPos = it->position(); |
| 127 |
auto y = f(localPos); |
| 128 |
|
| 129 |
out[9] += y[0]*it->weight(); |
| 130 |
out[10] += y[1]*it->weight(); |
| 131 |
out[11] += (y[0]*(localPos[0]-2.0*localPos[0]*localPos[1]-localPos[0]*localPos[0]) |
| 132 |
+y[1]*(-localPos[1]+2.0*localPos[0]*localPos[1]+localPos[1]*localPos[1]))*it->weight(); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
private: |
| 137 |
typename LB::Traits::RangeFieldType sign0, sign1, sign2; |
| 138 |
typename LB::Traits::DomainType m0, m1, m2; |
| 139 |
typename LB::Traits::DomainType n0, n1, n2; |
| 140 |
typename LB::Traits::RangeFieldType c0, c1, c2; |
| 141 |
}; |
| 142 |
} // end namespace Dune |
| 143 |
#endif // DUNE_LOCALFUNCTIONS_BREZZIDOUGLASMARINI2_SIMPLEX2D_LOCALINTERPOLATION_HH |