Debian Codegraph @

dune/localfunctions/refined/refinedp0/refinedp0localbasis.hh

raw
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_REFINED_P0_LOCALBASIS_HH
6 #define DUNE_REFINED_P0_LOCALBASIS_HH
7
8 #include <numeric>
9
10 #include <dune/common/fvector.hh>
11 #include <dune/common/fmatrix.hh>
12
13 #include <dune/localfunctions/common/localbasis.hh>
14 #include <dune/localfunctions/refined/common/refinedsimplexlocalbasis.hh>
15
16 namespace Dune
17 {
18
19 /**
20 \brief Uniformly refined constant shape functions on a unit simplex in R^dim
21
22 This shape function set mimics the P0 shape functions that you would get on
23 a uniformly refined grid. Hence these shape functions are only piecewise
24 constant!
25
26 Shape functions like these are necessary for hierarchical error estimators
27 for certain nonlinear problems.
28
29 The functions are associated with the subelements as defined in RefinedSimplexLocalBasis
30
31 \tparam D Type to represent the field in the domain.
32 \tparam R Type to represent the field in the range.
33 \tparam dim Dimension of domain space
34
35 \nosubgrouping
36 * \ingroup LocalFunctionsImpl
37 */
38 template<class D, class R, int dim>
39 class RefinedP0LocalBasis
40 : public RefinedSimplexLocalBasis<D,dim>
41 {
42 // 2 to the k-th power
43 constexpr static int N = 1<<dim;
44 public:
45 //! \brief export type traits for function signature
46 typedef LocalBasisTraits<D,dim,Dune::FieldVector<D,dim>,R,1,Dune::FieldVector<R,1>, Dune::FieldMatrix<R,1,dim> > Traits;
47
48 //! \brief number of shape functions
49 unsigned int size () const
50 {
51 return N;
52 }
53
54 //! \brief Evaluate all shape functions
55 inline void evaluateFunction (const typename Traits::DomainType& in,
56 std::vector<typename Traits::RangeType>& out) const
57 {
58 int subElement = this->getSubElement(in);
59 out.resize(N);
60 for(int i=0; i<N; ++i)
61 out[i] = (i==subElement) ? 1 : 0;
62 }
63
64 inline void
65 evaluateJacobian (const typename Traits::DomainType& in, // position
66 std::vector<typename Traits::JacobianType>& out) const // return value
67 {
68 out.resize(N);
69 for(int i=0; i<N; ++i)
70 out[i][0] = 0;
71 }
72
73 //! \brief Evaluate partial derivatives of all shape functions
74 void partial (const std::array<unsigned int, dim>& order,
75 const typename Traits::DomainType& in, // position
76 std::vector<typename Traits::RangeType>& out) const // return value
77 {
78 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
79 if (totalOrder == 0) {
80 evaluateFunction(in, out);
81 } else {
82 out.resize(size());
83 for (std::size_t i = 0; i < size(); ++i)
84 out[i] = 0;
85 }
86 }
87
88 /** \brief Polynomial order of the shape functions
89 *
90 * Doesn't really apply: these shape functions are only piecewise constant
91 */
92 unsigned int order () const
93 {
94 return 0;
95 }
96
97 };
98
99 }
100 #endif