AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
DerivativeGridFunction.hpp
1#pragma once
2
3#include <type_traits>
4
5#include <dune/grid/utility/hierarchicsearch.hh>
6
7#include <amdis/common/Concepts.hpp>
8#include <amdis/common/DerivativeTraits.hpp>
9#include <amdis/gridfunctions/Derivative.hpp>
10#include <amdis/gridfunctions/GridFunction.hpp>
11
12namespace AMDiS
13{
14 namespace Impl
15 {
16 template <class LF, class Sig>
17 struct CheckFunctorConcept
18 {
19 static_assert(Concepts::Functor<LF, Sig>, "Derivative of LocalFunction can not be called as a functor.");
20 };
21
22 template <class Traits>
23 struct CheckValidRange
24 {
25 static_assert(!std::is_same_v<typename Traits::Range, Dune::Functions::InvalidRange>, "Invalid Range.");
26 };
27 }
28
31
43 template <class GridFunction, class Type>
45 {
46 using GridFctRange = typename GridFunction::Range;
47 using GridFctDomain = typename GridFunction::Domain;
48 using RawSignature = typename Dune::Functions::SignatureTraits<GridFctRange(GridFctDomain)>::RawSignature;
49
51 using LocalFunction = TYPEOF( derivativeOf(localFunction(std::declval<GridFunction>()), std::declval<Type>()) ) ;
52
53 using LocalFctRange = typename Traits::Range;
54 using LocalFctDomain = typename GridFunction::EntitySet::LocalCoordinate;
55
56 CHECK_CONCEPT(Impl::CheckValidRange<Traits>);
57 CHECK_CONCEPT(Impl::CheckFunctorConcept<LocalFunction, LocalFctRange(LocalFctDomain)>);
58
59 enum { hasDerivative = false };
60
61 public:
63 using Range = typename Traits::Range;
64
66 using Domain = GridFctDomain;
67
69 using EntitySet = typename GridFunction::EntitySet;
70
71 public:
73 DerivativeGridFunction(GridFunction const& gridFct, Type const& type)
74 : gridFct_{gridFct}
75 , type_{type}
76 {}
77
79 DerivativeGridFunction(GridFunction&& gridFct, Type const& type)
80 : gridFct_{std::move(gridFct)}
81 , type_{type}
82 {}
83
85 Range operator()(Domain const& x) const
86 {
87 auto gv = entitySet().gridView();
88
89 using GridView = decltype(gv);
90 using Grid = typename GridView::Grid;
91 using IS = typename GridView::IndexSet;
92
93 Dune::HierarchicSearch<Grid,IS> hsearch{gv.grid(), gv.indexSet()};
94
95 auto element = hsearch.findEntity(x);
96 auto geometry = element.geometry();
97 auto localFct = makeLocalFunction();
98 localFct.bind(element);
99 return localFct(geometry.local(x));
100 }
101
103 LocalFunction makeLocalFunction() const
104 {
105 return derivativeOf(localFunction(gridFct_), type_);
106 }
107
109 EntitySet const& entitySet() const
110 {
111 return gridFct_.entitySet();
112 }
113
114 private:
115 GridFunction gridFct_;
116 Type type_;
117 };
118
119
123
133 template <class GridFct, class Type,
134 class LocalFct = decltype( localFunction(std::declval<GridFct>()) ),
135 REQUIRES(not GridFct::hasDerivative)>
136 auto derivativeOf(GridFct const& gridFct, Type const& type)
137 {
138 static_assert(Concepts::HasDerivative<LocalFct,Type>,
139 "derivativeOf(LocalFunction,type) not defined!");
140 return DerivativeGridFunction<GridFct,Type>{gridFct, type};
141 }
142
143
144#ifndef DOXYGEN
145 template <class Expr, class Type>
147 {
149
150 struct Creator
151 {
152 template <class GridView>
153 static auto create(Self const& self, GridView const& gridView)
154 {
155 return derivativeOf(makeGridFunction(self.expr_, gridView), self.type_);
156 }
157 };
158
159 Expr expr_;
160 Type type_ = {};
161 };
162
163 namespace Traits
164 {
165 template <class Expr,class Type>
167 : std::true_type {};
168 }
169#endif
170
171
175
184 template <class Expr>
185 auto gradientOf(Expr const& expr)
186 {
188 }
189
191 template <class Expr>
192 auto divergenceOf(Expr const& expr)
193 {
194 return DerivativePreGridFunction<Expr, tag::divergence>{expr};
195 }
196
198 template <class Expr>
199 auto partialDerivativeOf(Expr const& expr, std::size_t i)
200 {
201 return DerivativePreGridFunction<Expr, tag::partial>{expr, tag::partial{i}};
202 }
203
206} // end namespace AMDiS
A Gridfunction that returns the derivative when calling localFunction.
Definition: DerivativeGridFunction.hpp:45
LocalFunction makeLocalFunction() const
Return the derivative-localFunction of the GridFunction.
Definition: DerivativeGridFunction.hpp:103
DerivativeGridFunction(GridFunction const &gridFct, Type const &type)
Constructor. Stores a copy of gridFct.
Definition: DerivativeGridFunction.hpp:73
Range operator()(Domain const &x) const
Evaluate derivative in global coordinates. NOTE: expensive.
Definition: DerivativeGridFunction.hpp:85
DerivativeGridFunction(GridFunction &&gridFct, Type const &type)
Constructor. Moves the gridFct into an instance variable.
Definition: DerivativeGridFunction.hpp:79
GridFctDomain Domain
The domain of the GridFunction.
Definition: DerivativeGridFunction.hpp:66
EntitySet const & entitySet() const
Return the EntitySet of the GridFunction.
Definition: DerivativeGridFunction.hpp:109
typename Traits::Range Range
The Range of the derivative of the GridFunction.
Definition: DerivativeGridFunction.hpp:63
typename GridFunction::EntitySet EntitySet
The EntitySet of the GridFunction.
Definition: DerivativeGridFunction.hpp:69
constexpr bool GridFunction
GridFunction GF is a Type that has LocalFunction and provides some typedefs for Domain,...
Definition: GridFunction.hpp:72
auto gradientOf(Expr const &expr)
Definition: DerivativeGridFunction.hpp:185
decltype(auto) makeGridFunction(PreGridFct const &preGridFct, GridView const &gridView)
Generator for Gridfunctions from Expressions (PreGridfunctions)
Definition: GridFunction.hpp:168
Definition: DerivativeGridFunction.hpp:151
Definition: DerivativeGridFunction.hpp:147
Definition: DerivativeTraits.hpp:29
Definition: GridFunction.hpp:27