p0localbasis.hh 2.4 KB
Newer Older
Peter Bastian's avatar
Peter Bastian committed
1
2
3
4
5
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_P0LOCALBASIS_HH
#define DUNE_P0LOCALBASIS_HH

6
7
#include <numeric>

8
9
#include <dune/common/fmatrix.hh>

10
#include <dune/localfunctions/common/localbasis.hh>
Peter Bastian's avatar
Peter Bastian committed
11

12
13
14
15
namespace Dune
{
  /**@ingroup LocalBasisImplementation
         \brief Constant shape function
Peter Bastian's avatar
Peter Bastian committed
16

17
18
         Defines the constant scalar shape function in d dimensions. Is
         valid on any type of reference element.
Peter Bastian's avatar
Peter Bastian committed
19

20
21
22
         \tparam D Type to represent the field in the domain.
         \tparam R Type to represent the field in the range.
         \tparam d Domain dimension
Peter Bastian's avatar
Peter Bastian committed
23

24
25
26
         \nosubgrouping
   */
  template<class D, class R, int d>
27
  class P0LocalBasis
Peter Bastian's avatar
Peter Bastian committed
28
  {
29
30
  public:
    //! \brief export type traits for function signature
Carsten Gräser's avatar
Carsten Gräser committed
31
    typedef LocalBasisTraits<D,d,Dune::FieldVector<D,d>,R,1,Dune::FieldVector<R,1>,
32
        Dune::FieldMatrix<R,1,d> > Traits;
Peter Bastian's avatar
Peter Bastian committed
33

34
35
36
37
38
    //! \brief number of shape functions
    unsigned int size () const
    {
      return 1;
    }
Peter Bastian's avatar
Peter Bastian committed
39

40
    //! \brief Evaluate all shape functions
41
    inline void evaluateFunction (const typename Traits::DomainType&,
42
43
44
45
46
                                  std::vector<typename Traits::RangeType>& out) const
    {
      out.resize(1);
      out[0] = 1;
    }
Peter Bastian's avatar
Peter Bastian committed
47

48
49
    //! \brief Evaluate Jacobian of all shape functions
    inline void
50
    evaluateJacobian (const typename Traits::DomainType&,         // position
Jorrit Fahlke's avatar
Jorrit Fahlke committed
51
                      std::vector<typename Traits::JacobianType>& out) const      // return value
52
53
54
55
56
    {
      out.resize(1);
      for (int i=0; i<d; i++)
        out[0][0][i] = 0;
    }
Peter Bastian's avatar
Peter Bastian committed
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    /** \brief Evaluate partial derivatives of any order of all shape functions
     * \param order Order of the partial derivatives, in the classic multi-index notation
     * \param in Position where to evaluate the derivatives
     * \param[out] out Return value: the desired partial derivatives
     */
    void partial(const std::array<unsigned int,d>& order,
                 const typename Traits::DomainType& in,
                 std::vector<typename Traits::RangeType>& out) const
    {
      auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
      if (totalOrder == 0) {
        evaluateFunction(in, out);
      } else {
        out.resize(1);
        out[0] = 0;
      }
    }

76
77
78
79
80
81
82
83
    //! \brief Polynomial order of the shape functions
    unsigned int order () const
    {
      return 0;
    }
  };

}
Peter Bastian's avatar
Peter Bastian committed
84
85

#endif