Debian Codegraph @

dune/localfunctions/lagrange/p0/p0localbasis.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_P0LOCALBASIS_HH
6 #define DUNE_P0LOCALBASIS_HH
7
8 #include <numeric>
9
10 #include <dune/common/fmatrix.hh>
11
12 #include <dune/localfunctions/common/localbasis.hh>
13
14 namespace Dune
15 {
16 /**
17 \brief Constant shape function
18
19 Defines the constant scalar shape function in d dimensions. Is
20 valid on any type of reference element.
21
22 \tparam D Type to represent the field in the domain.
23 \tparam R Type to represent the field in the range.
24 \tparam d Domain dimension
25
26 * \ingroup LagrangeImpl
27 \nosubgrouping
28 */
29 template<class D, class R, int d>
30 class P0LocalBasis
31 {
32 public:
33 //! \brief export type traits for function signature
34 typedef LocalBasisTraits<D,d,Dune::FieldVector<D,d>,R,1,Dune::FieldVector<R,1>,
35 Dune::FieldMatrix<R,1,d> > Traits;
36
37 //! \brief number of shape functions
38 unsigned int size () const
39 {
40 return 1;
41 }
42
43 //! \brief Evaluate all shape functions
44 inline void evaluateFunction (const typename Traits::DomainType&,
45 std::vector<typename Traits::RangeType>& out) const
46 {
47 out.resize(1);
48 out[0] = 1;
49 }
50
51 //! \brief Evaluate Jacobian of all shape functions
52 inline void
53 evaluateJacobian (const typename Traits::DomainType&, // position
54 std::vector<typename Traits::JacobianType>& out) const // return value
55 {
56 out.resize(1);
57 for (int i=0; i<d; i++)
58 out[0][0][i] = 0;
59 }
60
61 /** \brief Evaluate partial derivatives of any order of all shape functions
62 * \param order Order of the partial derivatives, in the classic multi-index notation
63 * \param in Position where to evaluate the derivatives
64 * \param[out] out Return value: the desired partial derivatives
65 */
66 void partial(const std::array<unsigned int,d>& order,
67 const typename Traits::DomainType& in,
68 std::vector<typename Traits::RangeType>& out) const
69 {
70 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
71 if (totalOrder == 0) {
72 evaluateFunction(in, out);
73 } else {
74 out.resize(1);
75 out[0] = 0;
76 }
77 }
78
79 //! \brief Polynomial order of the shape functions
80 unsigned int order () const
81 {
82 return 0;
83 }
84 };
85
86 }
87
88 #endif