dune-pdelab  2.0.0
gridfunctionspaceutilities.hh
Go to the documentation of this file.
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_PDELAB_GRIDFUNCTIONSPACEUTILITIES_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACEUTILITIES_HH
5 
6 #include <cstdlib>
7 #include<vector>
8 
9 #include<dune/common/exceptions.hh>
10 #include <dune/common/fvector.hh>
11 #include <dune/common/static_assert.hh>
12 
13 #include <dune/localfunctions/common/interfaceswitch.hh>
14 
15 #include"../common/function.hh"
17 #include"gridfunctionspace.hh"
20 
21 namespace Dune {
22  namespace PDELab {
23 
27 
28  //===============================================================
29  // output: convert grid function space to discrete grid function
30  //===============================================================
31 
32 
53  template<typename T, typename X>
55  : public TypeTree::LeafNode
57  GridFunctionTraits<
58  typename T::Traits::GridViewType,
59  typename BasisInterfaceSwitch<
60  typename FiniteElementInterfaceSwitch<
61  typename T::Traits::FiniteElementType
62  >::Basis
63  >::RangeField,
64  BasisInterfaceSwitch<
65  typename FiniteElementInterfaceSwitch<
66  typename T::Traits::FiniteElementType
67  >::Basis
68  >::dimRange,
69  typename BasisInterfaceSwitch<
70  typename FiniteElementInterfaceSwitch<
71  typename T::Traits::FiniteElementType
72  >::Basis
73  >::Range
74  >,
75  DiscreteGridFunction<T,X>
76  >
77  {
78  typedef T GFS;
79 
80  typedef typename Dune::BasisInterfaceSwitch<
81  typename FiniteElementInterfaceSwitch<
82  typename T::Traits::FiniteElementType
83  >::Basis
84  > BasisSwitch;
85  typedef GridFunctionInterface<
87  typename T::Traits::GridViewType,
88  typename BasisSwitch::RangeField,
89  BasisSwitch::dimRange,
90  typename BasisSwitch::Range
91  >,
93  > BaseT;
94 
95  public:
96  typedef typename BaseT::Traits Traits;
97 
103  DiscreteGridFunction (const GFS& gfs, const X& x_)
104  : pgfs(stackobject_to_shared_ptr(gfs))
105  , lfs(gfs)
106  , lfs_cache(lfs)
107  , x_view(x_)
108  , xl(gfs.maxLocalSize())
109  , yb(gfs.maxLocalSize())
110  {
111  }
112 
118  DiscreteGridFunction (shared_ptr<const GFS> gfs, shared_ptr<const X> x_)
119  : pgfs(gfs)
120  , lfs(*gfs)
121  , lfs_cache(lfs)
122  , x_view(*x_)
123  , xl(gfs->maxLocalSize())
124  , yb(gfs->maxLocalSize())
125  , px(x_) // FIXME: The LocalView should handle a shared_ptr correctly!
126  {
127  }
128 
129  // Evaluate
130  inline void evaluate (const typename Traits::ElementType& e,
131  const typename Traits::DomainType& x,
132  typename Traits::RangeType& y) const
133  {
134  typedef FiniteElementInterfaceSwitch<
136  > FESwitch;
137  lfs.bind(e);
138  lfs_cache.update();
139  x_view.bind(lfs_cache);
140  x_view.read(xl);
141  x_view.unbind();
142  FESwitch::basis(lfs.finiteElement()).evaluateFunction(x,yb);
143  y = 0;
144  for (unsigned int i=0; i<yb.size(); i++)
145  {
146  y.axpy(xl[i],yb[i]);
147  }
148  }
149 
151  inline const typename Traits::GridViewType& getGridView () const
152  {
153  return pgfs->gridView();
154  }
155 
156  private:
157 
158  typedef LocalFunctionSpace<GFS> LFS;
159  typedef LFSIndexCache<LFS> LFSCache;
160  typedef typename X::template ConstLocalView<LFSCache> XView;
161 
162  shared_ptr<GFS const> pgfs;
163  mutable LFS lfs;
164  mutable LFSCache lfs_cache;
165  mutable XView x_view;
166  mutable std::vector<typename Traits::RangeFieldType> xl;
167  mutable std::vector<typename Traits::RangeType> yb;
168  shared_ptr<const X> px; // FIXME: dummy pointer to make sure we take ownership of X
169  };
170 
180  template<typename T, typename X>
182  public GridFunctionInterface<
183  GridFunctionTraits<
184  typename T::Traits::GridViewType,
185  typename JacobianToCurl<typename T::Traits::FiniteElementType::
186  Traits::LocalBasisType::Traits::JacobianType>::CurlField,
187  JacobianToCurl<typename T::Traits::FiniteElementType::Traits::LocalBasisType::
188  Traits::JacobianType>::dimCurl,
189  typename JacobianToCurl<typename T::Traits::FiniteElementType::
190  Traits::LocalBasisType::Traits::JacobianType>::Curl
191  >,
192  DiscreteGridFunctionCurl<T,X>
193  >
194  {
195  typedef T GFS;
196  typedef typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::
197  JacobianType Jacobian;
199 
200  public:
201  typedef GridFunctionTraits<
202  typename T::Traits::GridViewType,
203  typename J2C::CurlField, J2C::dimCurl, typename J2C::Curl
205 
211  DiscreteGridFunctionCurl(const GFS& gfs, const X& x_)
212  : pgfs(stackobject_to_shared_ptr(gfs))
213  , lfs(gfs)
214  , lfs_cache(lfs)
215  , x_view(x_)
216  , xl(gfs.maxLocalSize())
217  , jacobian(gfs.maxLocalSize())
218  , yb(gfs.maxLocalSize())
219  , px(stackobject_to_shared_ptr(x_))
220  {}
221 
222  // Evaluate
223  void evaluate (const typename Traits::ElementType& e,
224  const typename Traits::DomainType& x,
225  typename Traits::RangeType& y) const
226  {
227  static const J2C& j2C = J2C();
228 
229  lfs.bind();
230  lfs_cache.update();
231  x_view.bind(lfs_cache);
232  x_view.read(xl);
233  x_view.unbind();
234 
235  lfs.finiteElement().basis().evaluateJacobian(x,jacobian);
236 
237  y = 0;
238  for (std::size_t i=0; i < lfs.size(); i++) {
239  j2C(jacobian[i], yb);
240  y.axpy(xl[i], yb);
241  }
242  }
243 
245  const typename Traits::GridViewType& getGridView() const
246  { return pgfs->gridView(); }
247 
248  private:
250  BaseT;
251  typedef LocalFunctionSpace<GFS> LFS;
252  typedef LFSIndexCache<LFS> LFSCache;
253  typedef typename X::template ConstLocalView<LFSCache> XView;
254 
255  shared_ptr<GFS const> pgfs;
256  mutable LFS lfs;
257  mutable LFSCache lfs_cache;
258  mutable XView x_view;
259  mutable std::vector<typename Traits::RangeFieldType> xl;
260  mutable std::vector<Jacobian> jacobian;
261  mutable std::vector<typename Traits::RangeType> yb;
262  shared_ptr<const X> px; // FIXME: dummy pointer to make sure we take ownership of X
263  };
264 
266 
278  template<typename GV, typename RangeFieldType, int dimRangeOfBasis>
281  "DiscreteGridFunctionCurl (and friends) work in 2D "
282  "and 3D only");
283  };
285 
291  template<typename GV, typename RangeFieldType>
293  : public GridFunctionTraits<GV,
294  RangeFieldType, 2,
295  FieldVector<RangeFieldType, 2> >
296  {
297  dune_static_assert(GV::dimensionworld == 2,
298  "World dimension of grid must be 2 for the curl of a "
299  "scalar (1D) quantity");
300  };
302 
307  template<typename GV, typename RangeFieldType>
309  : public GridFunctionTraits<GV,
310  RangeFieldType, 1,
311  FieldVector<RangeFieldType, 1> >
312  {
313  dune_static_assert(GV::dimensionworld == 2,
314  "World dimension of grid must be 2 for the curl of a"
315  "2D quantity");
316  };
318 
323  template<typename GV, typename RangeFieldType>
325  : public GridFunctionTraits<GV,
326  RangeFieldType, 3,
327  FieldVector<RangeFieldType, 3> >
328  {
329  dune_static_assert(GV::dimensionworld == 3,
330  "World dimension of grid must be 3 for the curl of a"
331  "3D quantity");
332  };
333 
336 
350  template<typename T, typename X>
352  : public GridFunctionInterface<
353  DiscreteGridFunctionCurlTraits<
354  typename T::Traits::GridViewType,
355  typename T::Traits::FiniteElementType::Traits::
356  LocalBasisType::Traits::RangeFieldType,
357  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::
358  dimRange>,
359  DiscreteGridFunctionGlobalCurl<T,X> >
360  {
361  public:
363  typename T::Traits::GridViewType,
364  typename T::Traits::FiniteElementType::Traits::
365  LocalBasisType::Traits::RangeFieldType,
366  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::
367  dimRange> Traits;
368 
369  private:
370  typedef T GFS;
371  typedef GridFunctionInterface<
372  Traits,
374  typedef typename T::Traits::FiniteElementType::Traits::
375  LocalBasisType::Traits LBTraits;
376 
377  public:
383  DiscreteGridFunctionGlobalCurl (const GFS& gfs, const X& x_)
384  : pgfs(stackobject_to_shared_ptr(gfs))
385  , lfs(gfs)
386  , lfs_cache(lfs)
387  , x_view(x_)
388  , xl(gfs.maxLocalSize())
389  , J(gfs.maxLocalSize())
390  , px(stackobject_to_shared_ptr(x_))
391  {}
392 
393 
394  // Evaluate
395  inline void evaluate (const typename Traits::ElementType& e,
396  const typename Traits::DomainType& x,
397  typename Traits::RangeType& y) const
398  {
399  lfs.bind(e);
400  lfs_cache.update();
401  x_view.bind(lfs_cache);
402  x_view.read(xl);
403  x_view.unbind();
404 
405  lfs.finiteElement().localBasis().
406  evaluateJacobianGlobal(x,J,e.geometry());
407  y = 0;
408  for (unsigned int i=0; i<J.size(); i++)
409  // avoid a "case label value exceeds maximum value for type"
410  // warning: since dimRange is an anonymous enum, its type may
411  // contain only the values 0 and 1, resulting in a warning.
412  switch(unsigned(Traits::dimRange)) {
413  case 1:
414  y[0] += xl[i] * J[i][0][1];
415  y[1] += xl[i] * -J[i][0][0];
416  break;
417  case 2:
418  y[0] += xl[i]*(J[i][1][0] - J[i][0][1]);
419  break;
420  case 3:
421  y[0] += xl[i]*(J[i][2][1] - J[i][1][2]);
422  y[1] += xl[i]*(J[i][0][2] - J[i][2][0]);
423  y[2] += xl[i]*(J[i][1][0] - J[i][0][1]);
424  break;
425  default:
426  //how did that pass all the static asserts?
427  std::abort();
428  }
429  }
430 
432  inline const typename Traits::GridViewType& getGridView () const
433  {
434  return pgfs->gridView();
435  }
436 
437  private:
438  typedef LocalFunctionSpace<GFS> LFS;
439  typedef LFSIndexCache<LFS> LFSCache;
440  typedef typename X::template ConstLocalView<LFSCache> XView;
441 
442  shared_ptr<GFS const> pgfs;
443  mutable LFS lfs;
444  mutable LFSCache lfs_cache;
445  mutable XView x_view;
446  mutable std::vector<typename Traits::RangeFieldType> xl;
447  mutable std::vector<typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::JacobianType> J;
448  shared_ptr<const X> px; // FIXME: dummy pointer to make sure we take ownership of X
449  };
450 
453 
461  template<typename T, typename X>
463  : public GridFunctionInterface<
464  GridFunctionTraits<
465  typename T::Traits::GridViewType,
466  typename T::Traits::FiniteElementType::Traits::LocalBasisType
467  ::Traits::RangeFieldType,
468  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
469  ::dimDomain,
470  FieldVector<
471  typename T::Traits::FiniteElementType::Traits
472  ::LocalBasisType::Traits::RangeFieldType,
473  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
474  ::dimDomain> >,
475  DiscreteGridFunctionGradient<T,X> >
476  {
477  typedef T GFS;
478  typedef typename GFS::Traits::FiniteElementType::Traits::
479  LocalBasisType::Traits LBTraits;
480 
481  public:
482  typedef GridFunctionTraits<
483  typename GFS::Traits::GridViewType,
484  typename LBTraits::RangeFieldType,
485  LBTraits::dimDomain,
486  FieldVector<
487  typename LBTraits::RangeFieldType,
488  LBTraits::dimDomain> > Traits;
489 
490  private:
491  typedef GridFunctionInterface<
492  Traits,
494 
495  public:
501  DiscreteGridFunctionGradient (const GFS& gfs, const X& x_)
502  : pgfs(stackobject_to_shared_ptr(gfs))
503  , lfs(gfs)
504  , lfs_cache(lfs)
505  , x_view(x_)
506  , xl(lfs.size())
507  { }
508 
509  // Evaluate
510  inline void evaluate (const typename Traits::ElementType& e,
511  const typename Traits::DomainType& x,
512  typename Traits::RangeType& y) const
513  {
514  // get and bind local functions space
515  lfs.bind(e);
516  lfs_cache.update();
517  x_view.bind(lfs_cache);
518 
519  // get local coefficients
520  xl.resize(lfs.size());
521  x_view.read(xl);
522  x_view.unbind();
523 
524  // get Jacobian of geometry
525  const typename Traits::ElementType::Geometry::JacobianInverseTransposed
526  JgeoIT = e.geometry().jacobianInverseTransposed(x);
527 
528  // get local Jacobians/gradients of the shape functions
529  std::vector<typename LBTraits::JacobianType> J(lfs.size());
530  lfs.finiteElement().localBasis().evaluateJacobian(x,J);
531 
532  typename Traits::RangeType gradphi;
533  y = 0;
534  for(unsigned int i = 0; i < lfs.size(); ++i) {
535  // compute global gradient of shape function i
536  gradphi = 0;
537  JgeoIT.umv(J[i][0], gradphi);
538 
539  // sum up global gradients, weighting them with the appropriate coeff
540  y.axpy(xl[i], gradphi);
541  }
542 
543  }
544 
546  inline const typename Traits::GridViewType& getGridView () const
547  {
548  return pgfs->gridView();
549  }
550 
551  private:
552  typedef LocalFunctionSpace<GFS> LFS;
553  typedef LFSIndexCache<LFS> LFSCache;
554  typedef typename X::template ConstLocalView<LFSCache> XView;
555 
556  shared_ptr<GFS const> pgfs;
557  mutable LFS lfs;
558  mutable LFSCache lfs_cache;
559  mutable XView x_view;
560  mutable std::vector<typename Traits::RangeFieldType> xl;
561  };
562 
567  template<typename T, typename X>
569  : public GridFunctionInterface<
570  GridFunctionTraits<
571  typename T::Traits::GridViewType,
572  typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
573  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimRange,
574  typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeType
575  >,
576  DiscreteGridFunctionPiola<T,X>
577  >
578  {
579  typedef T GFS;
580 
581  typedef GridFunctionInterface<
583  typename T::Traits::GridViewType,
584  typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
585  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimRange,
586  typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeType
587  >,
589  > BaseT;
590 
591  public:
592  typedef typename BaseT::Traits Traits;
593 
598  DiscreteGridFunctionPiola (const GFS& gfs, const X& x_)
599  : pgfs(stackobject_to_shared_ptr(gfs))
600  , lfs(gfs)
601  , lfs_cache(lfs)
602  , x_view(x_)
603  , xl(pgfs->maxLocalSize())
604  , yb(pgfs->maxLocalSize())
605  {
606  }
607 
608  inline void evaluate (const typename Traits::ElementType& e,
609  const typename Traits::DomainType& x,
610  typename Traits::RangeType& y) const
611  {
612  // evaluate shape function on the reference element as before
613  lfs.bind(e);
614  lfs_cache.update();
615  x_view.bind(lfs_cache);
616  x_view.read(xl);
617  x_view.unbind();
618 
619  lfs.finiteElement().localBasis().evaluateFunction(x,yb);
620  typename Traits::RangeType yhat;
621  yhat = 0;
622  for (unsigned int i=0; i<yb.size(); i++)
623  yhat.axpy(xl[i],yb[i]);
624 
625  // apply Piola transformation
626  typename Traits::ElementType::Geometry::JacobianInverseTransposed
627  J = e.geometry().jacobianInverseTransposed(x);
628  J.invert();
629  y = 0;
630  J.umtv(yhat,y);
631  y /= J.determinant();
632  }
633 
635  inline const typename Traits::GridViewType& getGridView () const
636  {
637  return pgfs->gridView();
638  }
639 
640  private:
641 
642  typedef LocalFunctionSpace<GFS> LFS;
643  typedef LFSIndexCache<LFS> LFSCache;
644  typedef typename X::template ConstLocalView<LFSCache> XView;
645 
646  shared_ptr<GFS const> pgfs;
647  mutable LFS lfs;
648  mutable LFSCache lfs_cache;
649  mutable XView x_view;
650  mutable std::vector<typename Traits::RangeFieldType> xl;
651  mutable std::vector<typename Traits::RangeType> yb;
652 
653  };
654 
666  template<typename T, typename X, std::size_t dimR = T::CHILDREN>
668  : public GridFunctionInterface<
669  GridFunctionTraits<
670  typename T::Traits::GridViewType,
671  typename T::template Child<0>::Type::Traits::FiniteElementType
672  ::Traits::LocalBasisType::Traits::RangeFieldType,
673  dimR,
674  Dune::FieldVector<
675  typename T::template Child<0>::Type::Traits::FiniteElementType
676  ::Traits::LocalBasisType::Traits::RangeFieldType,
677  dimR
678  >
679  >,
680  VectorDiscreteGridFunction<T,X>
681  >,
682  public TypeTree::LeafNode
683  {
684  typedef T GFS;
685 
686  typedef GridFunctionInterface<
688  typename T::Traits::GridViewType,
689  typename T::template Child<0>::Type::Traits::FiniteElementType
690  ::Traits::LocalBasisType::Traits::RangeFieldType,
691  dimR,
692  Dune::FieldVector<
693  typename T::template Child<0>::Type::Traits::FiniteElementType
694  ::Traits::LocalBasisType::Traits::RangeFieldType,
695  dimR
696  >
697  >,
699  > BaseT;
700 
701  public:
702  typedef typename BaseT::Traits Traits;
703  typedef typename T::template Child<0>::Type ChildType;
704  typedef typename ChildType::Traits::FiniteElementType
705  ::Traits::LocalBasisType::Traits::RangeFieldType RF;
706  typedef typename ChildType::Traits::FiniteElementType
707  ::Traits::LocalBasisType::Traits::RangeType RT;
708 
710 
715  VectorDiscreteGridFunction(const GFS& gfs, const X& x_,
716  std::size_t start = 0)
717  : pgfs(stackobject_to_shared_ptr(gfs))
718  , lfs(gfs)
719  , lfs_cache(lfs)
720  , x_view(x_)
721  , xl(gfs.maxLocalSize())
722  , yb(gfs.maxLocalSize())
723  {
724  for(std::size_t i = 0; i < dimR; ++i)
725  remap[i] = i + start;
726  }
727 
729 
740  template<class Remap>
741  VectorDiscreteGridFunction(const GFS& gfs, const X& x_,
742  const Remap &remap_)
743  : pgfs(stackobject_to_shared_ptr(gfs))
744  , lfs(gfs)
745  , lfs_cache(lfs)
746  , x_view(x_)
747  , xl(gfs.maxLocalSize())
748  , yb(gfs.maxLocalSize())
749  , px(stackobject_to_shared_ptr(x_))
750  {
751  for(std::size_t i = 0; i < dimR; ++i)
752  remap[i] = remap_[i];
753  }
754 
755  inline void evaluate (const typename Traits::ElementType& e,
756  const typename Traits::DomainType& x,
757  typename Traits::RangeType& y) const
758  {
759  lfs.bind(e);
760  lfs_cache.update();
761  x_view.bind(lfs_cache);
762  x_view.read(xl);
763  x_view.unbind();
764  for (unsigned int k=0; k < dimR; k++)
765  {
766  lfs.child(remap[k]).finiteElement().localBasis().
767  evaluateFunction(x,yb);
768  y[k] = 0.0;
769  for (unsigned int i=0; i<yb.size(); i++)
770  y[k] += xl[lfs.child(remap[k]).localIndex(i)]*yb[i];
771  }
772  }
773 
775  inline const typename Traits::GridViewType& getGridView () const
776  {
777  return pgfs->gridView();
778  }
779 
780  private:
781  typedef LocalFunctionSpace<GFS> LFS;
782  typedef LFSIndexCache<LFS> LFSCache;
783  typedef typename X::template ConstLocalView<LFSCache> XView;
784 
785  shared_ptr<GFS const> pgfs;
786  std::size_t remap[dimR];
787  mutable LFS lfs;
788  mutable LFSCache lfs_cache;
789  mutable XView x_view;
790  mutable std::vector<RF> xl;
791  mutable std::vector<RT> yb;
792  shared_ptr<const X> px; // FIXME: dummy pointer to make sure we take ownership of X
793  };
794 
800  template<typename T, typename X>
802  : public GridFunctionInterface<
803  GridFunctionTraits<
804  typename T::Traits::GridViewType,
805  typename T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
806  //T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimDomain,
807  T::CHILDREN,
808  Dune::FieldMatrix<
809  typename T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
810  T::CHILDREN,
811  T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimDomain
812  >
813  >,
814  VectorDiscreteGridFunctionGradient<T,X>
815  >,
816  public TypeTree::LeafNode
817  {
818  typedef T GFS;
819 
820  typedef GridFunctionInterface<
822  typename T::Traits::GridViewType,
823  typename T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
824  //T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimDomain,
825  T::CHILDREN,
826  Dune::FieldMatrix<
827  typename T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType,
828  T::CHILDREN,
829  T::template Child<0>::Type::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimDomain>
830  >,
832  > BaseT;
833 
834  public:
835  typedef typename BaseT::Traits Traits;
836  typedef typename T::template Child<0>::Type ChildType;
837  typedef typename ChildType::Traits::FiniteElementType::Traits::LocalBasisType::Traits LBTraits;
838 
839  typedef typename LBTraits::RangeFieldType RF;
840  typedef typename LBTraits::JacobianType JT;
841 
842  VectorDiscreteGridFunctionGradient (const GFS& gfs, const X& x_)
843  : pgfs(stackobject_to_shared_ptr(gfs))
844  , lfs(gfs)
845  , lfs_cache(lfs)
846  , x_view(x_)
847  , xl(gfs.maxLocalSize())
848  , J(gfs.maxLocalSize())
849  {
850  }
851 
852  inline void evaluate(const typename Traits::ElementType& e,
853  const typename Traits::DomainType& x,
854  typename Traits::RangeType& y) const
855  {
856  // get and bind local functions space
857  lfs.bind(e);
858  lfs_cache.update();
859  x_view.bind(lfs_cache);
860  x_view.read(xl);
861  x_view.unbind();
862 
863  // get Jacobian of geometry
864  const typename Traits::ElementType::Geometry::JacobianInverseTransposed
865  JgeoIT = e.geometry().jacobianInverseTransposed(x);
866 
867  y = 0.0;
868 
869  // Loop over PowerLFS and calculate gradient for each child separately
870  for(unsigned int k = 0; k != T::CHILDREN; ++k)
871  {
872  // get local Jacobians/gradients of the shape functions
873  std::vector<typename LBTraits::JacobianType> J(lfs.child(k).size());
874  lfs.child(k).finiteElement().localBasis().evaluateJacobian(x,J);
875 
876  Dune::FieldVector<RF,LBTraits::dimDomain> gradphi;
877  for (typename LFS::Traits::SizeType i=0; i<lfs.child(k).size(); i++)
878  {
879  gradphi = 0;
880  JgeoIT.umv(J[i][0], gradphi);
881 
882  y[k].axpy(xl[lfs.child(k).localIndex(i)], gradphi);
883  }
884  }
885  }
886 
887 
889  inline const typename Traits::GridViewType& getGridView () const
890  {
891  return pgfs->gridView();
892  }
893 
894  private:
895  typedef LocalFunctionSpace<GFS> LFS;
896  typedef LFSIndexCache<LFS> LFSCache;
897  typedef typename X::template ConstLocalView<LFSCache> XView;
898 
899  shared_ptr<GFS const> pgfs;
900  mutable LFS lfs;
901  mutable LFSCache lfs_cache;
902  mutable XView x_view;
903  mutable std::vector<RF> xl;
904  mutable std::vector<JT> J;
905  shared_ptr<const X> px; // FIXME: dummy pointer to make sure we take ownership of X
906  };
907 
908 
910  } // namespace PDELab
911 } // namespace Dune
912 
913 #endif
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:432
DiscreteGridFunction(shared_ptr< const GFS > gfs, shared_ptr< const X > x_)
Construct a DiscreteGridFunction.
Definition: gridfunctionspaceutilities.hh:118
BaseT::Traits Traits
Definition: gridfunctionspaceutilities.hh:835
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:775
DiscreteGridFunctionGradient(const GFS &gfs, const X &x_)
Construct a DiscreteGridFunctionGradient.
Definition: gridfunctionspaceutilities.hh:501
VectorDiscreteGridFunctionGradient(const GFS &gfs, const X &x_)
Definition: gridfunctionspaceutilities.hh:842
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:755
convert a single component function space with experimental global finite elements into a grid functi...
Definition: gridfunctionspaceutilities.hh:351
dune_static_assert(AlwaysFalse< GV >::value,"DiscreteGridFunctionCurl (and friends) work in 2D ""and 3D only")
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:223
T::template Child< 0 >::Type ChildType
Definition: gridfunctionspaceutilities.hh:836
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:118
void update()
Definition: lfsindexcache.hh:300
Equivalent of DiscreteGridFunctionGradient for vector-valued functions.
Definition: gridfunctionspaceutilities.hh:801
DiscreteGridFunctionGlobalCurl(const GFS &gfs, const X &x_)
Construct a DiscreteGridFunctionGlobalCurl.
Definition: gridfunctionspaceutilities.hh:383
Helper class to calculate the Traits of DiscreteGridFunctionCurl.
Definition: gridfunctionspaceutilities.hh:279
ChildType::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType RF
Definition: gridfunctionspaceutilities.hh:705
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:49
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:635
VectorDiscreteGridFunction(const GFS &gfs, const X &x_, std::size_t start=0)
construct
Definition: gridfunctionspaceutilities.hh:715
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:130
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:510
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:889
extract the curl of a function from the jacobian of that function
Definition: jacobiantocurl.hh:28
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:546
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:187
DiscreteGridFunction for vector-valued functions.
Definition: gridfunctionspaceutilities.hh:667
DiscreteGridFunction with Piola transformation.
Definition: gridfunctionspaceutilities.hh:568
DiscreteGridFunctionCurlTraits< typename T::Traits::GridViewType, typename T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeFieldType, T::Traits::FiniteElementType::Traits::LocalBasisType::Traits::dimRange > Traits
Definition: gridfunctionspaceutilities.hh:367
Traits::IndexContainer::size_type size() const
get current size
Definition: localfunctionspace.hh:206
GridFunctionTraits< typename T::Traits::GridViewType, typename J2C::CurlField, J2C::dimCurl, typename J2C::Curl > Traits
Definition: gridfunctionspaceutilities.hh:204
BaseT::Traits Traits
Definition: gridfunctionspaceutilities.hh:96
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
Create a local function space from a global function space.
Definition: localfunctionspace.hh:702
DiscreteGridFunctionPiola(const GFS &gfs, const X &x_)
Construct a DiscreteGridFunctionPiola.
Definition: gridfunctionspaceutilities.hh:598
traits class holding the function signature, same as in local function
Definition: function.hh:176
convert a grid function space and a coefficient vector into a grid function of the curl ...
Definition: gridfunctionspaceutilities.hh:181
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:151
T Traits
Export type traits.
Definition: function.hh:192
DiscreteGridFunction(const GFS &gfs, const X &x_)
Construct a DiscreteGridFunction.
Definition: gridfunctionspaceutilities.hh:103
DiscreteGridFunctionCurl(const GFS &gfs, const X &x_)
Construct a DiscreteGridFunctionCurl.
Definition: gridfunctionspaceutilities.hh:211
BaseT::Traits Traits
Definition: gridfunctionspaceutilities.hh:592
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:115
BaseT::Traits Traits
Definition: gridfunctionspaceutilities.hh:702
ChildType::Traits::FiniteElementType::Traits::LocalBasisType::Traits::RangeType RT
Definition: gridfunctionspaceutilities.hh:707
T::template Child< 0 >::Type ChildType
Definition: gridfunctionspaceutilities.hh:703
const E & e
Definition: interpolate.hh:172
VectorDiscreteGridFunction(const GFS &gfs, const X &x_, const Remap &remap_)
construct
Definition: gridfunctionspaceutilities.hh:741
LBTraits::RangeFieldType RF
Definition: gridfunctionspaceutilities.hh:839
convert a single component function space with a grid function representing the gradient ...
Definition: gridfunctionspaceutilities.hh:462
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:395
convert a grid function space and a coefficient vector into a grid function
Definition: gridfunctionspaceutilities.hh:54
LBTraits::JacobianType JT
Definition: gridfunctionspaceutilities.hh:840
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:608
GridFunctionTraits< typename GFS::Traits::GridViewType, typename LBTraits::RangeFieldType, LBTraits::dimDomain, FieldVector< typename LBTraits::RangeFieldType, LBTraits::dimDomain > > Traits
Definition: gridfunctionspaceutilities.hh:488
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: gridfunctionspaceutilities.hh:245
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: gridfunctionspaceutilities.hh:852
ChildType::Traits::FiniteElementType::Traits::LocalBasisType::Traits LBTraits
Definition: gridfunctionspaceutilities.hh:837