dune-localfunctions  2.2.1
virtualwrappers.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil -*-
2 // vi: set ts=8 sw=2 et sts=2:
3 #ifndef DUNE_VIRTUALWRAPPERS_HH
4 #define DUNE_VIRTUALWRAPPERS_HH
5 
6 #include<dune/common/function.hh>
7 
11 
12 namespace Dune
13 {
14 
15  // forward declaration needed by friend declarations
16  template<class Imp>
18 
19  // default clone method is the copy constructor
20  template<class Imp, bool IsInterface>
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>
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>
42  {
44 
45  static Imp* clone(const Imp& imp)
46  {
48  }
49 
50  static Imp* create()
51  {
52  return new Imp;
53  }
54  };
55 
56 
57 
58  // -----------------------------------------------------------------
59  // Basis
60  // -----------------------------------------------------------------
61 
71  template<class T , class Imp>
73  : public virtual LocalBasisVirtualInterface<T>,
74  public LocalBasisVirtualImp<typename LowerOrderLocalBasisTraits<T>::Traits,Imp>
75  {
76  template<class FEImp>
78 
80 
81  protected:
82 
84  LocalBasisVirtualImp( const Imp &imp )
85  : Base(imp)
86  {}
87 
88  public:
89  typedef T Traits;
90 
91  using Base::size;
92  using Base::order;
93  using Base::evaluateFunction;
94  using Base::evaluateJacobian;
95  using Base::evaluate;
96 
98  inline void evaluate(
99  const typename Dune::template array<int,Traits::diffOrder>& directions,
100  const typename Traits::DomainType& in,
101  std::vector<typename Traits::RangeType>& out) const
102  {
103  // Even for double virtualization it is save to call the template method
104  // since the interface provides it redirecting to the virtual method
105  // of the derived class
106  //
107  // Unfortunately not all compiler can determine Traits::diffOrder from the
108  // type of the arument directions
109  impl_.template evaluate<Traits::diffOrder>(directions, in, out);
110  }
111 
112  protected:
113  using Base::impl_;
114 
115  };
116 
117 
125  template<class DF, int n, class D, class RF, int m, class R, class J, class Imp>
126  class LocalBasisVirtualImp<LocalBasisTraits<DF,n,D,RF,m,R,J,0>, Imp>
127  : public virtual LocalBasisVirtualInterface<LocalBasisTraits<DF,n,D,RF,m,R,J,0> >
128  {
129  template<class FEImp>
131 
132  protected:
133 
135  LocalBasisVirtualImp( const Imp &imp )
136  : impl_(imp)
137  {}
138 
139  public:
141 
143  unsigned int size () const
144  {
145  return impl_.size();
146  }
147 
149  unsigned int order () const
150  {
151  return impl_.order();
152  }
153 
155  inline void evaluateFunction (const typename Traits::DomainType& in,
156  std::vector<typename Traits::RangeType>& out) const
157  {
158  impl_.evaluateFunction(in,out);
159  }
160 
162  inline void evaluateJacobian(
163  const typename Traits::DomainType& in,
164  std::vector<typename Traits::JacobianType>& out) const
165  {
166  impl_.evaluateJacobian(in,out);
167  }
168 
170  inline void evaluate(
171  const typename Dune::template array<int,Traits::diffOrder>& directions,
172  const typename Traits::DomainType& in,
173  std::vector<typename Traits::RangeType>& out) const
174  {
175 // impl_.template evaluate<Traits::diffOrder> (directions, in,out);
176 // impl_.template evaluate<0> (directions, in,out);
177  impl_.evaluateFunction(in,out);
178  }
179 
180  protected:
181  const Imp& impl_;
182  };
183 
184 
185 
186  // -----------------------------------------------------------------
187  // Interpolation
188  // -----------------------------------------------------------------
189 
198  template<class DomainType, class RangeType, class Imp>
200  : public LocalInterpolationVirtualInterface< DomainType, RangeType >
201  {
202  template<class FEImp>
204 
206 
207  protected:
208 
211  : impl_(imp) {}
212 
213  public:
214 
216 
218 
220  virtual void interpolate (const FunctionType& f, std::vector<CoefficientType>& out) const
221  {
222  impl_.interpolate(f,out);
223  }
224 
225  protected:
226  const Imp& impl_;
227 
228  };
229 
230 
231 
232  // -----------------------------------------------------------------
233  // Coefficients
234  // -----------------------------------------------------------------
235 
242  template<class Imp>
245  {
246  template<class FEImp>
248 
249  protected:
250 
252  LocalCoefficientsVirtualImp( const Imp &imp )
253  : impl_(imp)
254  {}
255 
256  public:
257 
259  std::size_t size () const
260  {
261  return impl_.size();
262  }
263 
265  const LocalKey& localKey (std::size_t i) const
266  {
267  return impl_.localKey(i);
268  }
269 
270  protected:
271  const Imp& impl_;
272 
273  };
274 
275 
276 
277  // -----------------------------------------------------------------
278  // Finite Element
279  // -----------------------------------------------------------------
280 
289  template<class Imp>
291  : public virtual LocalFiniteElementVirtualInterface<typename Imp::Traits::LocalBasisType::Traits>
292  {
293  typedef typename Imp::Traits::LocalBasisType::Traits T;
294  typedef LocalFiniteElementVirtualInterface<T> Interface;
295 
296  public:
297  typedef typename Interface::Traits Traits;
298 
305  {}
306 
309  : impl_(LocalFiniteElementCloneFactory<Imp>::create()),
313  {}
314 
321  {}
322 
324  {
325  delete impl_;
326  }
327 
329  const typename Traits::LocalBasisType& localBasis () const
330  {
331  return localBasisImp_;
332  }
333 
336  {
337  return localCoefficientsImp_;
338  }
339 
342  {
343  return localInterpolationImp_;
344  }
345 
347  const GeometryType type () const
348  {
349  return impl_->type();
350  }
351 
358  {
359  return new LocalFiniteElementVirtualImp<Imp>(*this);
360  }
361 
362  protected:
363  const Imp* impl_;
364 
368  const LocalInterpolationVirtualImp<typename T::DomainType,
369  typename T::RangeType,
370  typename Imp::Traits::LocalInterpolationType> localInterpolationImp_;
371  };
372 }
373 #endif