Dune Core Modules (2.6.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
9
10#include <dune/localfunctions/common/localbasis.hh>
11#include <dune/localfunctions/common/localkey.hh>
12#include <dune/localfunctions/common/virtualinterface.hh>
13
14namespace Dune
15{
16
17 // forward declaration needed by friend declarations
18 template<class Imp>
19 class LocalFiniteElementVirtualImp;
20
21 // default clone method is the copy constructor
22 template<class Imp, bool IsInterface>
23 struct LocalFiniteElementCloneFactoryHelper
24 {
25 static Imp* clone(const Imp& imp)
26 {
27 return new Imp(imp);
28 }
29 };
30
31 // if FE derives from virtual interface the clone method is used
32 template<class Imp>
33 struct LocalFiniteElementCloneFactoryHelper<Imp, true>
34 {
35 static Imp* clone(const Imp& imp)
36 {
37 return imp.clone();
38 }
39 };
40
41 // factory template to clone and create an objects
42 template<class Imp>
43 struct LocalFiniteElementCloneFactory
44 {
45 typedef LocalFiniteElementVirtualInterface<typename Imp::Traits::LocalBasisType::Traits> Interface;
46
47 static Imp* clone(const Imp& imp)
48 {
49 return LocalFiniteElementCloneFactoryHelper<Imp, std::is_base_of<Interface, Imp>::value>::clone(imp);
50 }
51
52 static Imp* create()
53 {
54 return new Imp;
55 }
56 };
57
58
59
60 // -----------------------------------------------------------------
61 // Basis
62 // -----------------------------------------------------------------
63
64
65
72 template<class T , class Imp>
75 {
76 template<class FEImp>
78
79 protected:
80
82 LocalBasisVirtualImp( const Imp &imp )
83 : impl_(imp)
84 {}
85
86 public:
87 using Traits = T;
88
90 unsigned int size () const
91 {
92 return impl_.size();
93 }
94
96 unsigned int order () const
97 {
98 return impl_.order();
99 }
100
102 inline void evaluateFunction (const typename Traits::DomainType& in,
103 std::vector<typename Traits::RangeType>& out) const
104 {
105 impl_.evaluateFunction(in,out);
106 }
107
109 inline void evaluateJacobian(
110 const typename Traits::DomainType& in,
111 std::vector<typename Traits::JacobianType>& out) const
112 {
113 impl_.evaluateJacobian(in,out);
114 }
115
121 void partial(const std::array<unsigned int,Traits::dimDomain>& order,
122 const typename Traits::DomainType& in,
123 std::vector<typename Traits::RangeType>& out) const
124 {
125 impl_.partial(order,in,out);
126 }
127
128 protected:
129 const Imp& impl_;
130 };
131
132
133
134 // -----------------------------------------------------------------
135 // Interpolation
136 // -----------------------------------------------------------------
137
146 template<class DomainType, class RangeType, class Imp>
148 : public LocalInterpolationVirtualInterface< DomainType, RangeType >
149 {
150 template<class FEImp>
151 friend class LocalFiniteElementVirtualImp;
152
154
155 protected:
156
159 : impl_(imp) {}
160
161 public:
162
163 typedef typename Base::FunctionType FunctionType;
164
165 typedef typename Base::CoefficientType CoefficientType;
166
168 virtual void interpolate (const FunctionType& f, std::vector<CoefficientType>& out) const
169 {
170 impl_.interpolate(f,out);
171 }
172
173 protected:
174 const Imp& impl_;
175
176 };
177
178
179
180 // -----------------------------------------------------------------
181 // Coefficients
182 // -----------------------------------------------------------------
183
190 template<class Imp>
193 {
194 template<class FEImp>
195 friend class LocalFiniteElementVirtualImp;
196
197 protected:
198
201 : impl_(imp)
202 {}
203
204 public:
205
207 std::size_t size () const
208 {
209 return impl_.size();
210 }
211
213 const LocalKey& localKey (std::size_t i) const
214 {
215 return impl_.localKey(i);
216 }
217
218 protected:
219 const Imp& impl_;
220
221 };
222
223
224
225 // -----------------------------------------------------------------
226 // Finite Element
227 // -----------------------------------------------------------------
228
237 template<class Imp>
239 : public LocalFiniteElementVirtualInterface<typename Imp::Traits::LocalBasisType::Traits>
240 {
241 using LocalBasisTraits = typename Imp::Traits::LocalBasisType::Traits;
243
244 public:
245 typedef typename Interface::Traits Traits;
246
249 : impl_(LocalFiniteElementCloneFactory<Imp>::clone(imp)),
250 localBasisImp_(impl_->localBasis()),
251 localCoefficientsImp_(impl_->localCoefficients()),
252 localInterpolationImp_(impl_->localInterpolation())
253 {}
254
257 : impl_(LocalFiniteElementCloneFactory<Imp>::create()),
258 localBasisImp_(impl_->localBasis()),
259 localCoefficientsImp_(impl_->localCoefficients()),
260 localInterpolationImp_(impl_->localInterpolation())
261 {}
262
265 : impl_(LocalFiniteElementCloneFactory<Imp>::clone(*other.impl_)),
266 localBasisImp_(impl_->localBasis()),
267 localCoefficientsImp_(impl_->localCoefficients()),
268 localInterpolationImp_(impl_->localInterpolation())
269 {}
270
272 {
273 delete impl_;
274 }
275
277 const typename Traits::LocalBasisType& localBasis () const
278 {
279 return localBasisImp_;
280 }
281
284 {
285 return localCoefficientsImp_;
286 }
287
290 {
291 return localInterpolationImp_;
292 }
293
295 unsigned int size () const
296 {
297 return impl_->size();
298 }
299
301 const GeometryType type () const
302 {
303 return impl_->type();
304 }
305
312 {
313 return new LocalFiniteElementVirtualImp<Imp>(*this);
314 }
315
316 protected:
317 const Imp* impl_;
318
323 typename Imp::Traits::LocalInterpolationType> localInterpolationImp_;
324 };
325}
326#endif
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:277
class for wrapping a basis using the virtual interface
Definition: virtualwrappers.hh:75
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:121
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all basis function at given position.
Definition: virtualwrappers.hh:102
unsigned int size() const
Number of shape functions.
Definition: virtualwrappers.hh:90
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:109
LocalBasisVirtualImp(const Imp &imp)
constructor taking an implementation of the interface
Definition: virtualwrappers.hh:82
unsigned int order() const
Polynomial order of the shape functions.
Definition: virtualwrappers.hh:96
virtual base class for a local basis
Definition: virtualinterface.hh:69
class for wrapping local coefficients using the virtual interface
Definition: virtualwrappers.hh:193
LocalCoefficientsVirtualImp(const Imp &imp)
constructor taking an implementation of the Dune::LocalCoefficientsVirtualInterface
Definition: virtualwrappers.hh:200
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition: virtualwrappers.hh:213
std::size_t size() const
number of coefficients
Definition: virtualwrappers.hh:207
virtual base class for local coefficients
Definition: virtualinterface.hh:239
class for wrapping a finite element using the virtual interface
Definition: virtualwrappers.hh:240
const Traits::LocalBasisType & localBasis() const
Definition: virtualwrappers.hh:277
virtual LocalFiniteElementVirtualImp< Imp > * clone() const
clone this wrapper
Definition: virtualwrappers.hh:311
LocalFiniteElementVirtualImp(const Imp &imp)
taking a LocalFiniteElementVirtualInterface implementation
Definition: virtualwrappers.hh:248
LocalFiniteElementVirtualImp()
Default constructor. Assumes that the implementation class is default constructible as well.
Definition: virtualwrappers.hh:256
LocalFiniteElementVirtualImp(const LocalFiniteElementVirtualImp &other)
Copy contructor needed for deep copy.
Definition: virtualwrappers.hh:264
unsigned int size() const
Number of shape functions in this finite element.
Definition: virtualwrappers.hh:295
const GeometryType type() const
Definition: virtualwrappers.hh:301
const Traits::LocalCoefficientsType & localCoefficients() const
Definition: virtualwrappers.hh:283
const Traits::LocalInterpolationType & localInterpolation() const
Definition: virtualwrappers.hh:289
virtual base class for local finite elements with functions
Definition: virtualinterface.hh:266
class for wrapping a local interpolation using the virtual interface
Definition: virtualwrappers.hh:149
virtual void interpolate(const FunctionType &f, std::vector< CoefficientType > &out) const
determine coefficients interpolating a given function
Definition: virtualwrappers.hh:168
LocalInterpolationVirtualImp(const Imp &imp)
constructor taking an implementation of the Dune::LocalInterpolationVirtualInterface
Definition: virtualwrappers.hh:158
virtual base class for a local interpolation
Definition: virtualinterface.hh:162
RangeType::field_type CoefficientType
type of the coefficient vector in the interpolate method
Definition: virtualinterface.hh:169
Dune::VirtualFunction< DomainType, RangeType > FunctionType
type of virtual function to interpolate
Definition: virtualinterface.hh:166
Describe position of one degree of freedom.
Definition: localkey.hh:21
Virtual base class template for function classes.
Definition: function.hh:72
Simple base class templates for functions.
Dune namespace.
Definition: alignedallocator.hh:10
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 26, 23:30, 2024)