Dune Core Modules (2.8.0)

virtualwrappers.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_LOCALFUNCTIONS_COMMON_VIRTUALWRAPPERS_HH
4#define DUNE_LOCALFUNCTIONS_COMMON_VIRTUALWRAPPERS_HH
5
6#include <array>
7
8#include <dune/localfunctions/common/localbasis.hh>
9#include <dune/localfunctions/common/localkey.hh>
10#include <dune/localfunctions/common/virtualinterface.hh>
11
12namespace Dune
13{
14
15 // forward declaration needed by friend declarations
16 template<class Imp>
17 class LocalFiniteElementVirtualImp;
18
19 // default clone method is the copy constructor
20 template<class Imp, bool IsInterface>
21 struct LocalFiniteElementCloneFactoryHelper
22 {
23 static Imp* clone(const Imp& imp)
24 {
25 return new Imp(imp);
26 }
27 };
28
29 // if FE derives from virtual interface the clone method is used
30 template<class Imp>
31 struct LocalFiniteElementCloneFactoryHelper<Imp, true>
32 {
33 static Imp* clone(const Imp& imp)
34 {
35 return imp.clone();
36 }
37 };
38
39 // factory template to clone and create an objects
40 template<class Imp>
41 struct LocalFiniteElementCloneFactory
42 {
43 typedef LocalFiniteElementVirtualInterface<typename Imp::Traits::LocalBasisType::Traits> Interface;
44
45 static Imp* clone(const Imp& imp)
46 {
47 return LocalFiniteElementCloneFactoryHelper<Imp, std::is_base_of<Interface, Imp>::value>::clone(imp);
48 }
49
50 static Imp* create()
51 {
52 return new Imp;
53 }
54 };
55
56
57
58 // -----------------------------------------------------------------
59 // Basis
60 // -----------------------------------------------------------------
61
62
63
70 template<class T , class Imp>
73 {
74 template<class FEImp>
76
77 protected:
78
80 LocalBasisVirtualImp( const Imp &imp )
81 : impl_(imp)
82 {}
83
84 public:
85 using Traits = T;
86
88 unsigned int size () const
89 {
90 return impl_.size();
91 }
92
94 unsigned int order () const
95 {
96 return impl_.order();
97 }
98
100 inline void evaluateFunction (const typename Traits::DomainType& in,
101 std::vector<typename Traits::RangeType>& out) const
102 {
103 impl_.evaluateFunction(in,out);
104 }
105
107 inline void evaluateJacobian(
108 const typename Traits::DomainType& in,
109 std::vector<typename Traits::JacobianType>& out) const
110 {
111 impl_.evaluateJacobian(in,out);
112 }
113
119 void partial(const std::array<unsigned int,Traits::dimDomain>& order,
120 const typename Traits::DomainType& in,
121 std::vector<typename Traits::RangeType>& out) const
122 {
123 impl_.partial(order,in,out);
124 }
125
126 protected:
127 const Imp& impl_;
128 };
129
130
131
132 // -----------------------------------------------------------------
133 // Interpolation
134 // -----------------------------------------------------------------
135
144 template<class DomainType, class RangeType, class Imp>
146 : public LocalInterpolationVirtualInterface< DomainType, RangeType >
147 {
148 template<class FEImp>
149 friend class LocalFiniteElementVirtualImp;
150
152
153 protected:
154
157 : impl_(imp) {}
158
159 public:
160
161 typedef typename Base::FunctionType FunctionType;
162
163 typedef typename Base::CoefficientType CoefficientType;
164
166 virtual void interpolate (const FunctionType& f, std::vector<CoefficientType>& out) const
167 {
168 impl_.interpolate(f,out);
169 }
170
171 protected:
172 const Imp& impl_;
173
174 };
175
176
177
178 // -----------------------------------------------------------------
179 // Coefficients
180 // -----------------------------------------------------------------
181
188 template<class Imp>
191 {
192 template<class FEImp>
193 friend class LocalFiniteElementVirtualImp;
194
195 protected:
196
199 : impl_(imp)
200 {}
201
202 public:
203
205 std::size_t size () const
206 {
207 return impl_.size();
208 }
209
211 const LocalKey& localKey (std::size_t i) const
212 {
213 return impl_.localKey(i);
214 }
215
216 protected:
217 const Imp& impl_;
218
219 };
220
221
222
223 // -----------------------------------------------------------------
224 // Finite Element
225 // -----------------------------------------------------------------
226
235 template<class Imp>
237 : public LocalFiniteElementVirtualInterface<typename Imp::Traits::LocalBasisType::Traits>
238 {
239 using LocalBasisTraits = typename Imp::Traits::LocalBasisType::Traits;
241
242 public:
243 typedef typename Interface::Traits Traits;
244
247 : impl_(LocalFiniteElementCloneFactory<Imp>::clone(imp)),
248 localBasisImp_(impl_->localBasis()),
249 localCoefficientsImp_(impl_->localCoefficients()),
250 localInterpolationImp_(impl_->localInterpolation())
251 {}
252
255 : impl_(LocalFiniteElementCloneFactory<Imp>::create()),
256 localBasisImp_(impl_->localBasis()),
257 localCoefficientsImp_(impl_->localCoefficients()),
258 localInterpolationImp_(impl_->localInterpolation())
259 {}
260
263 : impl_(LocalFiniteElementCloneFactory<Imp>::clone(*other.impl_)),
264 localBasisImp_(impl_->localBasis()),
265 localCoefficientsImp_(impl_->localCoefficients()),
266 localInterpolationImp_(impl_->localInterpolation())
267 {}
268
270 {
271 delete impl_;
272 }
273
275 const typename Traits::LocalBasisType& localBasis () const
276 {
277 return localBasisImp_;
278 }
279
282 {
283 return localCoefficientsImp_;
284 }
285
288 {
289 return localInterpolationImp_;
290 }
291
293 unsigned int size () const
294 {
295 return impl_->size();
296 }
297
299 const GeometryType type () const
300 {
301 return impl_->type();
302 }
303
310 {
311 return new LocalFiniteElementVirtualImp<Imp>(*this);
312 }
313
314 protected:
315 const Imp* impl_;
316
321 typename Imp::Traits::LocalInterpolationType> localInterpolationImp_;
322 };
323}
324#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
class for wrapping a basis using the virtual interface
Definition: virtualwrappers.hh:73
void partial(const std::array< unsigned int, Traits::dimDomain > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of any order of all shape functions.
Definition: virtualwrappers.hh:119
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all basis function at given position.
Definition: virtualwrappers.hh:100
unsigned int size() const
Number of shape functions.
Definition: virtualwrappers.hh:88
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate jacobian of all shape functions at given position.
Definition: virtualwrappers.hh:107
LocalBasisVirtualImp(const Imp &imp)
constructor taking an implementation of the interface
Definition: virtualwrappers.hh:80
unsigned int order() const
Polynomial order of the shape functions.
Definition: virtualwrappers.hh:94
virtual base class for a local basis
Definition: virtualinterface.hh:95
class for wrapping local coefficients using the virtual interface
Definition: virtualwrappers.hh:191
LocalCoefficientsVirtualImp(const Imp &imp)
constructor taking an implementation of the Dune::LocalCoefficientsVirtualInterface
Definition: virtualwrappers.hh:198
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition: virtualwrappers.hh:211
std::size_t size() const
number of coefficients
Definition: virtualwrappers.hh:205
virtual base class for local coefficients
Definition: virtualinterface.hh:257
class for wrapping a finite element using the virtual interface
Definition: virtualwrappers.hh:238
const Traits::LocalBasisType & localBasis() const
Definition: virtualwrappers.hh:275
virtual LocalFiniteElementVirtualImp< Imp > * clone() const
clone this wrapper
Definition: virtualwrappers.hh:309
LocalFiniteElementVirtualImp(const Imp &imp)
taking a LocalFiniteElementVirtualInterface implementation
Definition: virtualwrappers.hh:246
LocalFiniteElementVirtualImp()
Default constructor. Assumes that the implementation class is default constructible as well.
Definition: virtualwrappers.hh:254
LocalFiniteElementVirtualImp(const LocalFiniteElementVirtualImp &other)
Copy contructor needed for deep copy.
Definition: virtualwrappers.hh:262
unsigned int size() const
Number of shape functions in this finite element.
Definition: virtualwrappers.hh:293
const GeometryType type() const
Definition: virtualwrappers.hh:299
const Traits::LocalCoefficientsType & localCoefficients() const
Definition: virtualwrappers.hh:281
const Traits::LocalInterpolationType & localInterpolation() const
Definition: virtualwrappers.hh:287
virtual base class for local finite elements with functions
Definition: virtualinterface.hh:284
class for wrapping a local interpolation using the virtual interface
Definition: virtualwrappers.hh:147
virtual void interpolate(const FunctionType &f, std::vector< CoefficientType > &out) const
determine coefficients interpolating a given function
Definition: virtualwrappers.hh:166
LocalInterpolationVirtualImp(const Imp &imp)
constructor taking an implementation of the Dune::LocalInterpolationVirtualInterface
Definition: virtualwrappers.hh:156
std::function< RangeType(DomainType)> FunctionType
type of function to interpolate
Definition: virtualinterface.hh:161
virtual base class for a local interpolation
Definition: virtualinterface.hh:188
std::function< RangeType(DomainType)> FunctionType
type of function to interpolate
Definition: virtualinterface.hh:192
RangeType::field_type CoefficientType
type of the coefficient vector in the interpolate method
Definition: virtualinterface.hh:195
Describe position of one degree of freedom.
Definition: localkey.hh:21
Dune namespace.
Definition: alignedallocator.hh:11
D DomainType
domain type
Definition: localbasis.hh:43
R RangeType
range type
Definition: localbasis.hh:55
traits helper struct
Definition: localfiniteelementtraits.hh:11
LB LocalBasisType
Definition: localfiniteelementtraits.hh:14
LC LocalCoefficientsType
Definition: localfiniteelementtraits.hh:18
LI LocalInterpolationType
Definition: localfiniteelementtraits.hh:22
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)