| 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_DUAL_P1_LOCALBASIS_HH |
| 6 | #define DUNE_DUAL_P1_LOCALBASIS_HH |
| 7 | |
| 8 | #include <numeric> |
| 9 | |
| 10 | #include <dune/common/fvector.hh> |
| 11 | #include <dune/common/fmatrix.hh> |
| 12 | #include <dune/localfunctions/common/localbasis.hh> |
| 13 | |
| 14 | namespace Dune |
| 15 | { |
| 16 | /** |
| 17 | * \ingroup DualMortarImpl |
| 18 | \brief Dual Lagrange shape functions on the simplex. |
| 19 | |
| 20 | Defines the linear dual shape functions on the simplex. |
| 21 | Note that if the dual functions are chosen to be dual on the faces, |
| 22 | the integrated product of a Lagrange \f$\lambda_p\f$ and dual |
| 23 | function \f$\theta_q\f$ over faces not containing \f$q\f$ does in |
| 24 | general not vanish. |
| 25 | |
| 26 | \tparam D Type to represent the field in the domain. |
| 27 | \tparam R Type to represent the field in the range. |
| 28 | \tparam dim The dimension of the simplex |
| 29 | \tparam faceDual If set, the basis functions are bi-orthogonal only on faces containing the corresponding vertex. |
| 30 | |
| 31 | \nosubgrouping |
| 32 | */ |
| 33 | template<class D, class R, int dim, bool faceDualT=false> |
| 34 | class DualP1LocalBasis |
| 35 | { |
| 36 | public: |
| 37 | //! Determines if the basis is only biorthogonal on adjacent faces |
| 38 | static const bool faceDual = faceDualT; |
| 39 | //! \brief export type traits for function signature |
| 40 | typedef LocalBasisTraits<D,dim,Dune::FieldVector<D,dim>,R,1,Dune::FieldVector<R,1>, |
| 41 | Dune::FieldMatrix<R,1,dim> > Traits; |
| 42 | |
| 43 | //! \brief number of shape functions |
| 44 | unsigned int size () const |
| 45 | { |
| 46 | return dim+1; |
| 47 | } |
| 48 | |
| 49 | //! \brief Evaluate all shape functions |
| 50 | inline void evaluateFunction (const typename Traits::DomainType& in, |
| 51 | std::vector<typename Traits::RangeType>& out) const |
| 52 | { |
| 53 | // evaluate P1 basis functions |
| 54 | std::vector<typename Traits::RangeType> p1Values(size()); |
| 55 | |
| 56 | p1Values[0] = 1.0; |
| 57 | |
| 58 | for (int i=0; i<dim; i++) { |
| 59 | p1Values[0] -= in[i]; |
| 60 | p1Values[i+1] = in[i]; |
| 61 | } |
| 62 | |
| 63 | // compute dual basis function values as a linear combination of the Lagrange values |
| 64 | out.resize(size()); |
| 65 | |
| 66 | for (int i=0; i<=dim; i++) { |
| 67 | out[i] = (dim+!faceDual)*p1Values[i]; |
| 68 | for (int j=0; j<i; j++) |
| 69 | out[i] -= p1Values[j]; |
| 70 | |
| 71 | for (int j=i+1; j<=dim; j++) |
| 72 | out[i] -= p1Values[j]; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | //! \brief Evaluate Jacobian of all shape functions |
| 77 | inline void |
| 78 | evaluateJacobian (const typename Traits::DomainType& in, |
| 79 | std::vector<typename Traits::JacobianType>& out) const |
| 80 | { |
| 81 | // evaluate P1 jacobians |
| 82 | std::vector<typename Traits::JacobianType> p1Jacs(size()); |
| 83 | |
| 84 | for (int i=0; i<dim; i++) |
| 85 | p1Jacs[0][0][i] = -1; |
| 86 | |
| 87 | for (int i=0; i<dim; i++) |
| 88 | for (int j=0; j<dim; j++) |
| 89 | p1Jacs[i+1][0][j] = (i==j); |
| 90 | |
| 91 | // compute dual basis jacobians as linear combination of the Lagrange jacobians |
| 92 | out.resize(size()); |
| 93 | |
| 94 | for (size_t i=0; i<=dim; i++) { |
| 95 | out[i][0] = 0; |
| 96 | out[i][0].axpy(dim+!faceDual,p1Jacs[i][0]); |
| 97 | |
| 98 | for (size_t j=0; j<i; j++) |
| 99 | out[i][0] -= p1Jacs[j][0]; |
| 100 | |
| 101 | for (int j=i+1; j<=dim; j++) |
| 102 | out[i][0] -= p1Jacs[j][0]; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | //! \brief Evaluate partial derivatives of all shape functions |
| 107 | void partial (const std::array<unsigned int, dim>& 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 | } |
| 126 | #endif |