AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
GridFunction.hpp
1#pragma once
2
3#include <type_traits>
4
5#include <dune/common/typeutilities.hh>
6
7#include <amdis/common/Concepts.hpp>
8#include <amdis/common/Logical.hpp>
9#include <amdis/common/Order.hpp>
10#include <amdis/gridfunctions/Derivative.hpp>
11
12namespace AMDiS
13{
14 // The localFunction of a GridFunction
15 template <class GridFunction>
16 auto localFunction(GridFunction const& gf)
17 -> decltype(gf.makeLocalFunction())
18 {
19 return gf.makeLocalFunction();
20 }
21
22
23 namespace Traits
24 {
25 template <class T>
27 : std::false_type {};
28
29 } // end namespace Traits
30
31
32 namespace Concepts
33 {
38 namespace Definition
39 {
41 {
42 template <class F>
43 auto require(F&& f) -> decltype(
44 localFunction(f)
45 );
46 };
47
49 {
50 template <class GF>
51 auto require(GF const& /*gf*/) -> std::void_t<
52 typename GF::Range,
53 typename GF::Domain,
54 typename GF::EntitySet
55 >;
56 };
57
58 } // end namespace Definition
59
60
62 template <class GF>
63 constexpr bool HasLocalFunction = models<Definition::HasLocalFunction(GF)>;
64
65 template <class GF>
66 using HasLocalFunction_t = models_t<Definition::HasLocalFunction(GF)>;
67
68
71 template <class GF>
72 constexpr bool GridFunction =
73 HasLocalFunction<GF> && models<Definition::HasGridFunctionTypes(GF)>;
74
75 template <class GF>
76 using GridFunction_t = bool_t<GridFunction<GF>>;
77
78
81 template <class... GFs>
82 constexpr bool AnyGridFunction =
83 (GridFunction<remove_cvref_t<GFs>> ||...) ||
85
86 template <class... GFs>
87 using AnyGridFunction_t = bool_t<AnyGridFunction<GFs...>>;
88
91 } // end namespace Concepts
92
93
94#ifndef DOXYGEN
95 template <class PreGridFct, class = void>
97 : PreGridFct::Creator {};
98
99 // forward declaration
100 template <class Function>
102
103 namespace Impl
104 {
105 // Specialization for type that is already a GridFunction
106 template <class GridFct, class GridView>
107 GridFct const& makeGridFunctionImpl(GridFct const& gridFct, GridView const& /*gridView*/, std::true_type, Dune::PriorityTag<2>)
108 {
109 return gridFct;
110 }
111
112 // If F is a callable with global coordinates, create an AnalyticGridFunction
113 template <class F, class GridView,
114 class Coordinate = typename GridView::template Codim<0>::Entity::Geometry::GlobalCoordinate,
115 std::enable_if_t<std::is_invocable_v<F, Coordinate>, int> = 0>
116 auto makeGridFunctionImpl(F const& f, GridView const& gridView, std::false_type, Dune::PriorityTag<1>)
117 {
118 AnalyticPreGridFunction<F> preGridFct{f};
119 return AnalyticPreGridFunction<F>::Creator::create(preGridFct, gridView);
120 }
121
122 // Use the \ref GridFunctionCreator to create a gridFunction from a preGridFunction
123 template <class PreGridFct, class GridView,
124 class Creator = GridFunctionCreator<PreGridFct>>
125 decltype(auto) makeGridFunctionImpl(PreGridFct const& preGridFct, GridView const& gridView, std::false_type, Dune::PriorityTag<0>)
126 {
127 return Creator::create(preGridFct, gridView);
128 }
129 }
130#endif
131
132
134
167 template <class PreGridFct, class GridView>
168 decltype(auto) makeGridFunction(PreGridFct const& preGridFct, GridView const& gridView)
169 {
170 using isGridFct = Concepts::GridFunction_t<PreGridFct>;
171 return Impl::makeGridFunctionImpl(preGridFct, gridView, isGridFct{}, Dune::PriorityTag<5>{});
172 }
173
174} // end namespace AMDiS
constexpr bool HasLocalFunction
GridFunction GF has free function localFunction(GF)
Definition: GridFunction.hpp:63
constexpr bool GridFunction
GridFunction GF is a Type that has LocalFunction and provides some typedefs for Domain,...
Definition: GridFunction.hpp:72
constexpr bool AnyGridFunction
Concept is fulfilled, if at least one of the massed Expressions can be converted to a GridFunction,...
Definition: GridFunction.hpp:82
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
Definition: AnalyticGridFunction.hpp:221
Definition: GridFunction.hpp:41
Definition: GridFunction.hpp:97
Definition: GridFunction.hpp:27