GridFunctionConcepts.hpp 4.01 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1 2 3 4 5 6 7 8 9 10
#pragma once

#include <dune/common/typeutilities.hh>

#include <dune/amdis/common/Concepts.hpp>
#include <dune/amdis/common/IndexSeq.hpp>
#include <dune/amdis/common/Mpl.hpp>

namespace AMDiS
{
11 12 13 14 15 16
  namespace Traits
  {
    template <class T>
    struct IsPreGridFunction
      : std::false_type {};
  } // end namespace Traits
Praetorius, Simon's avatar
Praetorius, Simon committed
17 18 19

  namespace Concepts
  {
20 21 22 23
    /** \addtogroup Concepts
     *  @{
     **/

Praetorius, Simon's avatar
Praetorius, Simon committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    namespace Definition
    {
      struct HasLocalFunction
      {
        template <class F>
        auto requires_(F&& f) -> decltype( localFunction(f) );
      };

      struct HasDerivative
      {
        template <class F>
        auto requires_(F&& f) -> decltype( derivative(f) );
      };

      struct HasLocalFunctionDerivative
      {
        template <class F>
        auto requires_(F&& f) -> decltype( derivative(localFunction(f)) );
      };

44 45 46 47 48 49 50 51 52 53 54 55
      struct HasLocalFunctionOrder
      {
        template <class F>
        auto requires_(F&& f) -> decltype( order(localFunction(f)) );
      };

      struct HasPartial
      {
        template <class F>
        auto requires_(F&& f) -> decltype( partial(f, index_<0>) );
      };

Praetorius, Simon's avatar
Praetorius, Simon committed
56 57 58 59 60 61 62 63 64
      struct HasOrder
      {
        template <class F>
        auto requires_(F&& f) -> decltype( order(f) );
      };

      struct HasGridFunctionTypes
      {
        template <class GF>
65
        auto requires_(GF const& /*gf*/) -> Void_t<
Praetorius, Simon's avatar
Praetorius, Simon committed
66 67 68 69 70 71 72 73 74 75 76 77
          typename GF::Range,
          typename GF::Domain,
          typename GF::EntitySet >;
      };

      template <class F, int dow>
      constexpr bool CallableDow =
        Concepts::Callable<F, Dune::FieldVector<double, dow>>;

    } // end namespace Definition


Praetorius, Simon's avatar
Praetorius, Simon committed
78
    /// \brief GridFunction F has free function `localFunction(F)`
Praetorius, Simon's avatar
Praetorius, Simon committed
79 80 81
    template <class F>
    constexpr bool HasLocalFunction = models<Definition::HasLocalFunction(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
82
    /// \brief GridFunction F has free function `derivative(F)`
Praetorius, Simon's avatar
Praetorius, Simon committed
83 84 85
    template <class F>
    constexpr bool HasDerivative = models<Definition::HasDerivative(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
86
    /// \brief GridFunction F has free function `derivative(localFunction(F))`
Praetorius, Simon's avatar
Praetorius, Simon committed
87 88 89
    template <class F>
    constexpr bool HasLocalFunctionDerivative = models<Definition::HasLocalFunctionDerivative(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
90
    /// \brief GridFunction F has free function `order(localFunction(F))`
91 92 93
    template <class F>
    constexpr bool HasLocalFunctionOrder = models<Definition::HasLocalFunctionOrder(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
94
    /// \brief Functor F has free function `partial(F,_0)`
95 96 97
    template <class F>
    constexpr bool HasPartial = models<Definition::HasPartial(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
98
    /// \brief Functor F has free function `order(F)`
Praetorius, Simon's avatar
Praetorius, Simon committed
99 100 101
    template <class F>
    constexpr bool HasOrder = models<Definition::HasOrder(F)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
102 103

    /// \brief Functor F is collable with GlobalCoordinates `F(Dune::FieldVector<double,DOW>)`
Praetorius, Simon's avatar
Praetorius, Simon committed
104 105 106 107 108 109 110 111 112 113
#ifndef AMDIS_DOW
    template <class F>
    constexpr bool CallableDomain =
      Definition::CallableDow<F, 1> || Definition::CallableDow<F, 2> || Definition::CallableDow<F, 3>;
#else
    template <class F>
    constexpr bool CallableDomain =
      Definition::CallableDow<F, AMDIS_DOW>;
#endif

Praetorius, Simon's avatar
Praetorius, Simon committed
114 115
    /// \brief GridFunction GF is a Type that has LocalFunction and provides some
    /// typedefs for `Domain`, `Range`, and `EntitySet`.
Praetorius, Simon's avatar
Praetorius, Simon committed
116 117 118 119
    template <class GF>
    constexpr bool GridFunction =
      HasLocalFunction<GF> && models<Definition::HasGridFunctionTypes(GF)>;

Praetorius, Simon's avatar
Praetorius, Simon committed
120 121
    /// \brief Concept is fulfilled, if at least one of the massed Expressions
    /// can be converted to a GridFunction, or is already a GridFunction.
Praetorius, Simon's avatar
Praetorius, Simon committed
122 123 124
    template <class... GFs>
    constexpr bool AnyGridFunction =
      any_of_v<GridFunction<std::decay_t<GFs>>...> ||
125
      any_of_v<Traits::IsPreGridFunction<std::decay_t<GFs>>::value...>;
Praetorius, Simon's avatar
Praetorius, Simon committed
126

127 128
    /** @} **/

Praetorius, Simon's avatar
Praetorius, Simon committed
129 130 131
  } // end namespace Concepts


132
  namespace Impl
Praetorius, Simon's avatar
Praetorius, Simon committed
133
  {
134 135 136 137 138 139 140
    // Functions that forwards GridFunctions
    template <class GridFct, class GridView,
      REQUIRES(Concepts::GridFunction<GridFct>)>
    auto const& makeGridFunctionImpl(GridFct const& gridFct, GridView const& /*gridView*/, Dune::PriorityTag<10>)
    {
      return gridFct;
    }
Praetorius, Simon's avatar
Praetorius, Simon committed
141

142
  } // end namespace Impl
Praetorius, Simon's avatar
Praetorius, Simon committed
143
} // end namespace AMDiS