dune-pdelab  2.4.1-rc2
darcyfem.hh
Go to the documentation of this file.
1 // -*- tab-width: 2; indent-tabs-mode: nil -*-
2 #ifndef DUNE_PDELAB_LOCALOPERATOR_DARCYFEM_HH
3 #define DUNE_PDELAB_LOCALOPERATOR_DARCYFEM_HH
4 
5 #include <dune/common/fvector.hh>
6 #include <dune/geometry/referenceelements.hh>
7 
11 
13 
21 template<typename P, typename T, typename X>
24  Dune::PDELab::GridFunctionTraits<
25  typename T::Traits::GridViewType,
26  typename T::Traits::FiniteElementType::Traits::LocalBasisType
27  ::Traits::RangeFieldType,
28  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
29  ::dimDomain,
30  Dune::FieldVector<
31  typename T::Traits::FiniteElementType::Traits
32  ::LocalBasisType::Traits::RangeFieldType,
33  T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
34  ::dimDomain> >,
35  DarcyVelocityFromHeadFEM<P,T,X> >
36 {
37  typedef T GFS;
38  typedef typename GFS::Traits::FiniteElementType::Traits::
39  LocalBasisType::Traits LBTraits;
40 
43  typedef typename X::template LocalView<LFSCache> LView;
44 
45 public:
47  typename GFS::Traits::GridViewType,
48  typename LBTraits::RangeFieldType,
49  LBTraits::dimDomain,
50  Dune::FieldVector<
51  typename LBTraits::RangeFieldType,
52  LBTraits::dimDomain> > Traits;
53 
54 private:
56  Traits,
58 
59 public:
65  DarcyVelocityFromHeadFEM (const P& p, const GFS& gfs, X& x_)
66  : pgfs(stackobject_to_shared_ptr(gfs))
67  , pxg(stackobject_to_shared_ptr(x_))
68  , pp(stackobject_to_shared_ptr(p))
69  , lfs(pgfs)
70  , lfs_cache(lfs)
71  , lview(*pxg)
72  {}
73 
74  // Evaluate
75  inline void evaluate (const typename Traits::ElementType& e,
76  const typename Traits::DomainType& x,
77  typename Traits::RangeType& y) const
78  {
79  // get and bind local functions space
80  lfs.bind(e);
81  lfs_cache.update();
82 
83  // get local coefficients
84  std::vector<typename Traits::RangeFieldType> xl(lfs.size());
85  lview.bind(lfs_cache);
86  lview.read(xl);
87  lview.unbind();
88 
89  // get Jacobian of geometry
90  const typename Traits::ElementType::Geometry::JacobianInverseTransposed
91  JgeoIT(e.geometry().jacobianInverseTransposed(x));
92 
93  // get local Jacobians/gradients of the shape functions
94  std::vector<typename LBTraits::JacobianType> J(lfs.size());
95  lfs.finiteElement().localBasis().evaluateJacobian(x,J);
96 
97  typename Traits::RangeType gradphi;
98  typename Traits::RangeType minusgrad(0);
99  for(unsigned int i = 0; i < lfs.size(); ++i) {
100  // compute global gradient of shape function i
101  gradphi = 0;
102  JgeoIT.umv(J[i][0], gradphi);
103 
104  // sum up global gradients, weighting them with the appropriate coeff
105  minusgrad.axpy(-xl[i], gradphi);
106  }
107 
108  // multiply with permeability tensor
109  typedef typename Traits::DomainFieldType DF;
110  const int dim = LBTraits::dimDomain;
111  const Dune::FieldVector<DF,dim>
112  inside_cell_center_local = Dune::ReferenceElements<DF,dim>::
113  general(e.type()).position(0,0);
114  typename P::Traits::PermTensorType A(pp->A(e,inside_cell_center_local));
115  A.mv(minusgrad,y);
116  }
117 
119  inline const typename Traits::GridViewType& getGridView () const
120  {
121  return pgfs->gridView();
122  }
123 
124 private:
125  std::shared_ptr<const GFS> pgfs;
126  std::shared_ptr<X> pxg;
127  std::shared_ptr<const P> pp;
128  mutable LFS lfs;
129  mutable LFSCache lfs_cache;
130  mutable LView lview;
131 };
132 
133 #endif
static const int dim
Definition: adaptivity.hh:83
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:114
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:117
Dune::PDELab::GridFunctionTraits< typename GFS::Traits::GridViewType, typename LBTraits::RangeFieldType, LBTraits::dimDomain, Dune::FieldVector< typename LBTraits::RangeFieldType, LBTraits::dimDomain > > Traits
Definition: darcyfem.hh:52
DarcyVelocityFromHeadFEM(const P &p, const GFS &gfs, X &x_)
Construct a DarcyVelocityFromHeadFEM.
Definition: darcyfem.hh:65
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
Traits::IndexContainer::size_type size() const
get current size
Definition: localfunctionspace.hh:206
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: darcyfem.hh:75
const P & p
Definition: constraints.hh:147
Provide Darcy velocity as a vector-valued grid function.
Definition: darcyfem.hh:22
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: darcyfem.hh:119
void update()
Definition: lfsindexcache.hh:300
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:186
traits class holding the function signature, same as in local function
Definition: function.hh:175