DerivativeGridFunction.hpp 2.47 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <type_traits>

#include <dune/functions/common/defaultderivativetraits.hh>

Praetorius, Simon's avatar
Praetorius, Simon committed
7
8
#include <dune/amdis/gridfunctions/GridFunctionConcepts.hpp>

9
10
11
namespace AMDiS
{
  /**
Praetorius, Simon's avatar
Praetorius, Simon committed
12
    * \addtogroup GridFunctions
13
14
15
    * @{
    **/

16
  /// A Gridfunction that returns the derivative when calling localFunction
17
18
19
20
21
22
23
  template <class GridFct>
  class DerivativeGridFunction
  {
    using GridFctRange = typename GridFct::Range;
    using GridFctDomain = typename GridFct::Domain;

  public:
24
25
    using RawSignature = typename Dune::Functions::SignatureTraits<GridFctRange(GridFctDomain)>::RawSignature;
    using Range = typename Dune::Functions::DefaultDerivativeTraits<RawSignature>::Range;
26
    using Domain = GridFctDomain;
Praetorius, Simon's avatar
Praetorius, Simon committed
27
    using LocalFunction = std::decay_t<decltype(derivative(localFunction(std::declval<GridFct>())))>;
28
29
30
31
32
33
34
35

    using EntitySet = typename GridFct::EntitySet;

  public:
    explicit DerivativeGridFunction(GridFct const& gridFct)
      : gridFct_(gridFct)
    {}

36
    /// no global derivative available
37
38
39
40
41
42
43
44
    Range operator()(Domain const& x) const
    {
      error_exit("Not implemented");
      return Range(0);
    }

    friend LocalFunction localFunction(DerivativeGridFunction const& gf)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
      return derivative(localFunction(gf.gridFct_));
    }

48
49
50
51
52
53
54
55
56
    EntitySet const& entitySet() const
    {
      return gridFct_.entitySet();
    }

  private:
    GridFct gridFct_;
  };

Praetorius, Simon's avatar
Praetorius, Simon committed
57
  template <class GridFct,
58
59
  REQUIRES(not Concepts::HasDerivative<GridFct> &&
                Concepts::HasLocalFunctionDerivative<GridFct>)>
Praetorius, Simon's avatar
Praetorius, Simon committed
60
  auto derivative(GridFct const& gridFct)
61
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
62
    return DerivativeGridFunction<GridFct>{gridFct};
63
64
  }

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

  template <class Expr>
  struct DerivativePreGridFunction
  {
    Expr expr;
  };

  namespace Traits
  {
    template <class Expr>
    struct IsPreGridFunction<DerivativePreGridFunction<Expr>>
      : std::true_type {};
  }


  /// Generator function for \ref DerivativeGridFunction expressions
  template <class Expr>
  auto gradientAtQP(Expr const& expr)
  {
    return DerivativePreGridFunction<Expr>{expr};
  }

87
88
  /** @} **/

89
90
91
92
93
94
95
96
97
98
  namespace Impl
  {
    /// Generator function for \ref AnalyticGridFunction expressions from \ref AnalyticPreGridFunction.
    template <class Expr, class GridView>
    auto makeGridFunctionImpl(DerivativePreGridFunction<Expr> const& pre, GridView const& gridView, Dune::PriorityTag<3>)
    {
      return derivative(Impl::makeGridFunctionImpl(pre.expr, gridView, Dune::PriorityTag<10>{}));
    }

  } // end namespace Impl
99
} // end namespace AMDiS