dune-pdelab  2.4.1-rc2
callableadapter.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_FUNCTION_CALLABLEADAPTER_HH
5 #define DUNE_PDELAB_FUNCTION_CALLABLEADAPTER_HH
6 
7 #include<utility>
8 
9 namespace Dune {
10  namespace PDELab {
11 
12  /************************
13  * Grid function adapters
14  ************************/
15 
17  template<typename GV, typename RF, int n, typename F>
19  : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
20  GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
21  GlobalCallableToGridFunctionAdapter<GV,RF,n,F> >
22  {
23  GV gv;
24  F f;
25  public:
26  typedef Dune::PDELab::
28 
30  GlobalCallableToGridFunctionAdapter (const GV& gv_, const F& f_) : gv(gv_), f(f_) {}
31 
33  inline const GV& getGridView () {return gv;}
34 
36  inline void evaluate (const typename Traits::ElementType& e,
37  const typename Traits::DomainType& xl,
38  typename Traits::RangeType& y) const
39  {
40  typename Traits::DomainType xg = e.geometry().global(xl);
41  y = f(xg);
42  return;
43  }
44  };
45 
46  template<typename T>
48  enum {dim=1};
49  };
50 
51  template<typename T, int n>
52  struct CallableAdapterGetDim< FieldVector<T,n> > {
53  enum {dim=n};
54  };
55 
56  template<typename T>
58  typedef T Type;
59  };
60 
61  template<typename T, int n>
62  struct CallableAdapterGetRangeFieldType< FieldVector<T,n> > {
63  typedef T Type;
64  };
65 
66 
68  template<typename GV, typename RF, int n, typename F>
70  : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
71  GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
72  LocalCallableToGridFunctionAdapter<GV,RF,n,F> >
73  {
74  GV gv;
75  F f;
76  public:
77  typedef Dune::PDELab::
79 
81  LocalCallableToGridFunctionAdapter (const GV& gv_, const F& f_) : gv(gv_), f(f_) {}
82 
84  inline const GV& getGridView () {return gv;}
85 
87  inline void evaluate (const typename Traits::ElementType& e,
88  const typename Traits::DomainType& xl,
89  typename Traits::RangeType& y) const
90  {
91  y = f(e,xl);
92  return;
93  }
94  };
95 
96 #ifdef DOXYGEN
97 
108  template <typename GV, typename F>
109  WrapperConformingToGridFunctionInterface makeGridFunctionFromCallable (const GV& gv, const F& f)
110  {}
111 #endif
112 
113 #ifndef DOXYGEN
114 
115  template <typename GV, typename F>
116  auto makeGridFunctionFromCallable (const GV& gv, const F& f)
117  -> typename std::enable_if<
118  AlwaysTrue <
119  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
120  >::value,
122  GV,
124  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
125  >::Type,
127  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
128  >::dim,
129  F>
130  >::type
131  {
132  typedef typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate X;
133  X x;
134  typedef decltype(f(x)) ReturnType;
138  return TheType(gv,f);
139  }
140 
143  template <typename GV, typename F>
144  auto makeGridFunctionFromCallable (const GV& gv, const F& f)
145  -> typename std::enable_if<
146  AlwaysTrue <
147  decltype(f(
148  std::declval<typename GV::template Codim<0>::Entity>(),
149  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
150  ))
151  >::value,
153  GV,
155  decltype(f(
156  std::declval<typename GV::template Codim<0>::Entity>(),
157  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
158  ))
159  >::Type,
161  decltype(f(
162  std::declval<typename GV::template Codim<0>::Entity>(),
163  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
164  ))
165  >::dim,
166  F>
167  >::type
168  {
169  typedef typename GV::template Codim<0>::Entity E;
170  E e;
171  typedef typename E::Geometry::LocalCoordinate X;
172  X x;
173  typedef decltype(f(e,x)) ReturnType;
177  return TheType(gv,f);
178  }
179 #endif // DOXYGEN
180 
181 
182  /*************************************
183  * Instationary grid function adapters
184  *************************************/
185 
186 
189  template<typename GV, typename RF, int n, typename F, typename P>
191  : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
192  GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
193  GlobalCallableToInstationaryGridFunctionAdapter<GV,RF,n,F,P> >
194  {
195  GV gv;
196  F f;
197  P& p;
198  public:
199  typedef Dune::PDELab::
201 
203  GlobalCallableToInstationaryGridFunctionAdapter (const GV& gv_, const F& f_, P& p_)
204  : gv(gv_), f(f_), p(p_)
205  {}
206 
208  inline const GV& getGridView () {return gv;}
209 
211  inline void evaluate (const typename Traits::ElementType& e,
212  const typename Traits::DomainType& xl,
213  typename Traits::RangeType& y) const
214  {
215  typename Traits::DomainType xg = e.geometry().global(xl);
216  y = f(xg);
217  return;
218  }
219 
220  // pass time to parameter object
221  void setTime (RF t) {
222  p.setTime(t);
223  }
224  };
225 
228  template<typename GV, typename RF, int n, typename F, typename P>
230  : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
231  GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
232  LocalCallableToInstationaryGridFunctionAdapter<GV,RF,n,F,P> >
233  {
234  GV gv;
235  F f;
236  P& p;
237  public:
238  typedef Dune::PDELab::
240 
242  LocalCallableToInstationaryGridFunctionAdapter (const GV& gv_, const F& f_, P& p_) : gv(gv_), f(f_), p(p_) {}
243 
245  inline const GV& getGridView () {return gv;}
246 
248  inline void evaluate (const typename Traits::ElementType& e,
249  const typename Traits::DomainType& xl,
250  typename Traits::RangeType& y) const
251  {
252  y = f(e,xl);
253  return;
254  }
255 
256  // pass time to parameter object
257  void setTime (RF t) {
258  p.setTime(t);
259  }
260  };
261 
262 #ifdef DOXYGEN
263 
276  template <typename GV, typename F>
277  WrapperConformingToGridFunctionInterface makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f)
278  {}
279 #endif
280 
281 #ifndef DOXYGEN
282 
284  template <typename GV, typename F, typename PARAM>
285  auto makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f, PARAM& param)
286  -> typename std::enable_if<
287  AlwaysTrue <
288  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
289  >::value,
291  GV,
293  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
294  >::Type,
296  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
297  >::dim,
298  F,
299  PARAM>
300  >::type
301  {
302  typedef typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate X;
303  X x;
304  typedef decltype(f(x)) ReturnType;
308  return TheType(gv,f,param);
309  }
310 
313  template <typename GV, typename F, typename PARAM>
314  auto makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f, PARAM& param)
315  -> typename std::enable_if<
316  AlwaysTrue <
317  decltype(f(
318  std::declval<typename GV::template Codim<0>::Entity>(),
319  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
320  ))
321  >::value,
323  GV,
325  decltype(f(
326  std::declval<typename GV::template Codim<0>::Entity>(),
327  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
328  ))
329  >::Type,
331  decltype(f(
332  std::declval<typename GV::template Codim<0>::Entity>(),
333  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
334  ))
335  >::dim,
336  F,
337  PARAM>
338  >::type
339  {
340  typedef typename GV::template Codim<0>::Entity E;
341  E e;
342  typedef typename E::Geometry::LocalCoordinate X;
343  X x;
344  typedef decltype(f(e,x)) ReturnType;
348  return TheType(gv,f,param);
349  }
350 #endif // DOXYGEN
351 
352 
353  /*****************************
354  * Boundary condition adapters
355  *****************************/
356 
358  template<typename F>
361  {
362  F f;
363 
364  public:
367 
369  template<typename I>
370  bool isDirichlet(const I & intersection,
371  const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
372  ) const
373  {
374  Dune::FieldVector<typename I::ctype, I::dimension> xg = intersection.geometry().global(coord);
375  return f(xg);
376  }
377 
378  template<typename I>
379  bool isNeumann(const I & ig,
380  const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
381  ) const
382  {
383  return !isDirichlet( ig, coord );
384  }
385 
386  };
387 
389  template<typename F>
393  {
394  const F f;
395 
396  public:
397 
399  : f( f_ )
400  {}
401 
402  template<typename I>
403  bool isDirichlet(const I & ig, const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
404  ) const
405  {
406  return(f(ig.intersection(),coord));
407  }
408 
409  template<typename I>
410  bool isNeumann(const I & ig,
411  const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
412  ) const
413  {
414  return !isDirichlet( ig, coord );
415  }
416  };
417 
418 #ifdef DOXYGEN
419 
431  template <typename GV, typename F>
432  BoundaryConditionAdapter makebBoundaryConditionFromCallable (const GV& gv, const F& f)
433 #endif
434 
435 #ifndef DOXYGEN
436 
437  template<typename GV, typename F>
438  auto makeBoundaryConditionFromCallable (const GV& gv, const F& f)
439  -> typename std::enable_if<
440  AlwaysTrue <
441  decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
442  >::value,
444  >::type
445  {
447  }
448 
451  template<typename GV, typename F>
452  auto makeBoundaryConditionFromCallable (const GV& gv, const F& f)
453  -> typename std::enable_if<
454  AlwaysTrue <
455  decltype(f(
456  std::declval<typename GV::template Codim<0>::Entity>(),
457  std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
458  ))
459  >::value,
461  >::type
462  {
464  }
465 #endif
466 
467 
468  }
469 }
470 #endif
Dune::PDELab::GridFunctionTraits< GV, RF, n, Dune::FieldVector< RF, n > > Traits
Definition: callableadapter.hh:239
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &xl, typename Traits::RangeType &y) const
evaluate extended function on element
Definition: callableadapter.hh:87
static const unsigned int value
Definition: gridfunctionspace/tags.hh:177
Definition: callableadapter.hh:47
bool isNeumann(const I &ig, const Dune::FieldVector< typename I::ctype, I::dimension-1 > &coord) const
Definition: callableadapter.hh:379
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &xl, typename Traits::RangeType &y) const
evaluate extended function on element
Definition: callableadapter.hh:36
Dune::PDELab::GridFunctionTraits< GV, RF, n, Dune::FieldVector< RF, n > > Traits
Definition: callableadapter.hh:200
WrapperConformingToGridFunctionInterface makeGridFunctionFromCallable(const GV &gv, const F &f)
Create a GridFunction adapter from a callable.
Definition: callableadapter.hh:109
const IG & ig
Definition: constraints.hh:148
static const int dim
Definition: adaptivity.hh:83
Dune::PDELab::GridFunctionTraits< GV, RF, n, Dune::FieldVector< RF, n > > Traits
Definition: callableadapter.hh:27
void setTime(RF t)
Definition: callableadapter.hh:257
Adapter for callables f(e,x) expecting an entity e and a global coordinate x.
Definition: callableadapter.hh:69
Adapter for boundary cond from a callable taking global coordinates.
Definition: callableadapter.hh:359
Definition: adaptivity.hh:27
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:117
LocalCallableToGridFunctionAdapter(const GV &gv_, const F &f_)
construct from grid view
Definition: callableadapter.hh:81
GlobalCallableToBoundaryConditionAdapter(F f_)
construct from functor
Definition: callableadapter.hh:366
WrapperConformingToGridFunctionInterface makeInstationaryGridFunctionFromCallable(const GV &gv, const F &f)
Create a GridFunction from callable and parameter class with setTime method.
Definition: callableadapter.hh:277
const GV & getGridView()
get a reference to the grid view
Definition: callableadapter.hh:84
Definition: callableadapter.hh:57
LocalCallableToBoundaryConditionAdapter(const F &f_)
Definition: callableadapter.hh:398
const Entity & e
Definition: localfunctionspace.hh:111
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:48
const GV & getGridView()
get a reference to the grid view
Definition: callableadapter.hh:245
Dune::PDELab::GridFunctionTraits< GV, RF, n, Dune::FieldVector< RF, n > > Traits
Definition: callableadapter.hh:78
LocalCallableToInstationaryGridFunctionAdapter(const GV &gv_, const F &f_, P &p_)
construct from grid view
Definition: callableadapter.hh:242
Adapter for boundary cond from a callable taking an entity and local coordinates. ...
Definition: callableadapter.hh:390
bool isDirichlet(const I &ig, const Dune::FieldVector< typename I::ctype, I::dimension-1 > &coord) const
Definition: callableadapter.hh:403
T Type
Definition: callableadapter.hh:58
Definition: constraintsparameters.hh:24
return a PDELab GridFunction (with setTime method) defined by a parameter class and a callable f(x) g...
Definition: callableadapter.hh:190
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &xl, typename Traits::RangeType &y) const
evaluate extended function on element
Definition: callableadapter.hh:211
const P & p
Definition: constraints.hh:147
XG & xg
Definition: interpolate.hh:67
void setTime(RF t)
Definition: callableadapter.hh:221
return a PDELab GridFunction (with setTime method) defined by a parameter class and a callable f(e...
Definition: callableadapter.hh:229
bool isNeumann(const I &ig, const Dune::FieldVector< typename I::ctype, I::dimension-1 > &coord) const
Definition: callableadapter.hh:410
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &xl, typename Traits::RangeType &y) const
evaluate extended function on element
Definition: callableadapter.hh:248
bool isDirichlet(const I &intersection, const Dune::FieldVector< typename I::ctype, I::dimension-1 > &coord) const
Test whether boundary is Dirichlet-constrained.
Definition: callableadapter.hh:370
Adapter for callables f(x) expecting a global coordinate x.
Definition: callableadapter.hh:18
GlobalCallableToGridFunctionAdapter(const GV &gv_, const F &f_)
construct from grid view
Definition: callableadapter.hh:30
leaf of a function tree
Definition: function.hh:576
const GV & getGridView()
get a reference to the grid view
Definition: callableadapter.hh:208
const GV & getGridView()
get a reference to the grid view
Definition: callableadapter.hh:33
traits class holding the function signature, same as in local function
Definition: function.hh:175
GlobalCallableToInstationaryGridFunctionAdapter(const GV &gv_, const F &f_, P &p_)
construct from grid view
Definition: callableadapter.hh:203
Definition: constraintsparameters.hh:120