DUNE PDELab (2.7)

oldinterfaceadapter.hh
1//-*- tab-width: 4; c-basic-offset: 2; indent-tabs-mode: nil -*-
2#ifndef DUNE_PDELAB_FUNCTION_OLDINTERFACEADAPTER_HH
3#define DUNE_PDELAB_FUNCTION_OLDINTERFACEADAPTER_HH
4
6#include <dune/pdelab/common/function.hh>
7#include <dune/pdelab/common/typetraits.hh>
8#include <dune/functions/common/signature.hh>
9#include <dune/functions/common/defaultderivativetraits.hh>
10#include <dune/functions/gridfunctions/gridviewfunction.hh>
11
12namespace Dune {
13namespace PDELab {
14namespace Imp {
15
16 template<class F, template<class> class DerivativeTraits = Functions::DefaultDerivativeTraits>
17 class LocalGridViewFunctionAdapter
18 : public TypeTree::LeafNode
19 {
20 public:
21 using Range = typename F::Traits::RangeType;
22 using LocalDomain = typename F::Traits::DomainType;
23 using GridView = typename F::Traits::GridViewType;
24
25 using Signature = Range(LocalDomain);
26 using RawSignature =
27 typename Functions::SignatureTraits<Signature>::RawSignature;
28 using DerivativeSignature =
29 typename DerivativeTraits<RawSignature>::Range(LocalDomain);
30
31 using EntitySet = Functions::GridViewEntitySet<GridView, 0>;
32 using Element = typename EntitySet::Element;
33 using Geometry = typename std::decay<typename Element::Geometry>::type;
34
35 typedef DifferentiableFunctionLocalViewTag ImplementationTag;
36
37 // // Use the inderiction via derivativeIfImplemented to also support
38 // // function types F that do not implement derivative. In this case
39 // // the interface type DifferentiableFunction is used a dummy for
40 // // the derivative type
41 // using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
42 // using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
43 // using Derivative = AnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
44
45 void bind(const Element& element)
46 {
47 element_ = element;
48 }
49
50 void unbind()
51 {}
52
53 Range operator()(const LocalDomain& x) const
54 {
55 Range v;
56 f_->evaluate(element_, x, v);
57 return v;
58 }
59
60 const Element& localContext() const
61 {
62 return element_;
63 }
64
65 // friend LocalDerivative derivative(const LocalAnalyticGridViewFunction& t)
66 // {
67 // return LocalDerivative(Imp::derivativeIfImplemented<DerivativeDummy, F>(t.f_));
68 // }
69
70 LocalGridViewFunctionAdapter(const F & f) : f_(stackobject_to_shared_ptr(f)) {};
71
72 // transforming constructor
73 template<typename Transformation>
74 LocalGridViewFunctionAdapter(std::shared_ptr<const F> f, const Transformation & t) : f_(f) {};
75
76 // transforming constructor
77 template<typename Transformation>
78 LocalGridViewFunctionAdapter(const F & f, const Transformation & t) : f_(stackobject_to_shared_ptr(f)) {};
79
80 private:
81 Element element_;
82 std::shared_ptr<const F> f_;
83 };
84
85 template<class F, template<class> class DerivativeTraits = Functions::DefaultDerivativeTraits>
86 class GridViewFunctionAdapter
87 {
88 public:
89 using Range = typename F::Traits::RangeFieldType;
90 using Domain = typename F::Traits::DomainFieldType;
91 using GridView = typename F::Traits::GridViewType;
92
93 using Signature = Range(Domain);
94 using RawSignature =
95 typename Functions::SignatureTraits<Signature>::RawSignature;
96 using DerivativeSignature =
97 typename DerivativeTraits<RawSignature>::Range(Domain);
98
99 using EntitySet = Functions::GridViewEntitySet<GridView, 0>;
100 using Element = typename EntitySet::Element;
101 using Geometry = typename Element::Geometry;
102
103 // // Use the inderiction via derivativeIfImplemented to also support
104 // // function types F that do not implement derivative. In this case
105 // // the interface type DifferentiableFunction is used a dummy for
106 // // the derivative type
107 // using DerivativeDummy = DifferentiableFunction<DerivativeSignature>;
108 // using GlobalRawDerivative = decltype(Imp::derivativeIfImplemented<DerivativeDummy, F>(std::declval<F>()));
109 // using Derivative = AnalyticGridViewFunction<DerivativeSignature, GridView, GlobalRawDerivative, DerivativeTraits>;
110
111 using LocalDomain = typename EntitySet::LocalCoordinate;
112 using LocalFunction = LocalGridViewFunctionAdapter<F>; // , LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits>;
113
114 template<class FT>
115 GridViewFunctionAdapter(FT&& f) :
116 f_(std::forward<FT>(f))
117 {}
118
119 Range operator()(const Domain& x) const
120 {
121 Range v;
122 f_.evaluate(x,v);
123 return v;
124 }
125
126 // friend Derivative derivative(const AnalyticGridViewFunction& t)
127 // {
128 // }
129
130 friend LocalFunction localFunction(const F& f)
131 {
132 return LocalFunction(f.f_);
133 }
134
135 const EntitySet& entitySet() const
136 {
137 return EntitySet(f_.getGridView());
138 }
139
140 private:
141 F f_;
142 };
143
144} // end namespace Imp
145} // end namespace PDELab
146} // end namespace Dune
147
148#endif // DUNE_PDELAB_FUNCTION_OLDINTERFACEADAPTER_HH
GridView::template Codim< codim >::Entity Element
Type of Elements contained in this EntitySet.
Definition: gridviewentityset.hh:32
Element::Geometry::LocalCoordinate LocalCoordinate
Type of local coordinates with respect to the Element.
Definition: gridviewentityset.hh:35
void localFunction(DiscreteGlobalBasisFunction< TT... > &&t)=delete
Construction of local functions from a temporary DiscreteGlobalBasisFunction (forbidden)
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition: nodeinterface.hh:66
Dune namespace.
Definition: alignedallocator.hh:14
shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:75
STL namespace.
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)