AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
HierarchicNodeToRangeMap.hpp
1#pragma once
2
3#include <utility>
4#include <type_traits>
5
6#include <dune/common/concept.hh>
7#include <dune/functions/common/indexaccess.hh>
8
9#include <amdis/common/Concepts.hpp>
10#include <amdis/common/DerivativeTraits.hpp>
11
12namespace AMDiS
13{
23 template <class TreePath, class Range>
24 decltype(auto) hierarchicNodeToRangeMap(const TreePath& treePath, Range&& y)
25 {
26 if constexpr(Concepts::HasIndexAccess<Range, Dune::index_constant<0>>)
27 // Specialization for ranges with operator[] access
28 return Dune::Functions::resolveStaticMultiIndex(y, treePath);
29 else
30 // Specialization for non-container ranges
31 return std::forward<Range>(y);
32 }
33
34
40 template <class TreePath, class F>
42 {
43 HierarchicNodeWrapper(TreePath const& tp, F const& f)
44 : tp_{tp}
45 , f_{f}
46 {}
47
48 template <class Domain>
49 auto operator() (Domain const& x) const
50 {
51 return hierarchicNodeToRangeMap(tp_, Dune::MatVec::as_vector(f_(x)));
52 }
53
54 decltype(auto) friend derivative(HierarchicNodeWrapper<TreePath,F> const& t)
55 {
56 auto df = derivativeOf(t.f_, tag::jacobian{});
57 df.bind(t.f_.localContext());
59 }
60
61 TreePath tp_;
62 F f_;
63 };
64
65} // end namespace AMDiS
Definition: HierarchicNodeToRangeMap.hpp:42
Definition: DerivativeTraits.hpp:19