DUNE PDELab (git)

darcyfem.hh
1// -*- tab-width: 2; indent-tabs-mode: nil -*-
2#ifndef DUNE_PDELAB_LOCALOPERATOR_DARCYFEM_HH
3#define DUNE_PDELAB_LOCALOPERATOR_DARCYFEM_HH
4
7
8#include <dune/geometry/referenceelements.hh>
9
10#include <dune/pdelab/common/function.hh>
11#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
12#include <dune/pdelab/gridfunctionspace/localfunctionspace.hh>
13
15
23template<typename P, typename T, typename X>
26 Dune::PDELab::GridFunctionTraits<
27 typename T::Traits::GridViewType,
28 typename T::Traits::FiniteElementType::Traits::LocalBasisType
29 ::Traits::RangeFieldType,
30 T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
31 ::dimDomain,
32 Dune::FieldVector<
33 typename T::Traits::FiniteElementType::Traits
34 ::LocalBasisType::Traits::RangeFieldType,
35 T::Traits::FiniteElementType::Traits::LocalBasisType::Traits
36 ::dimDomain> >,
37 DarcyVelocityFromHeadFEM<P,T,X> >
38{
39 using GFS = T;
40 using LBTraits = typename GFS::Traits::FiniteElementType::
41 Traits::LocalBasisType::Traits;
42
44 using LFSCache = Dune::PDELab::LFSIndexCache<LFS>;
45 using LView = typename X::template LocalView<LFSCache>;
46
47public:
49 typename GFS::Traits::GridViewType,
50 typename LBTraits::RangeFieldType,
51 LBTraits::dimDomain,
53 typename LBTraits::RangeFieldType,
54 LBTraits::dimDomain> >;
55
56private:
58 Traits,
60
61public:
67 DarcyVelocityFromHeadFEM (const P& p, const GFS& gfs, X& x_)
68 : pgfs(stackobject_to_shared_ptr(gfs))
71 , lfs(pgfs)
72 , lfs_cache(lfs)
73 , lview(*pxg)
74 {}
75
76 // Evaluate
77 inline void evaluate (const typename Traits::ElementType& e,
78 const typename Traits::DomainType& x,
79 typename Traits::RangeType& y) const
80 {
81 // get and bind local functions space
82 lfs.bind(e);
83 lfs_cache.update();
84
85 // get local coefficients
86 std::vector<typename Traits::RangeFieldType> xl(lfs.size());
87 lview.bind(lfs_cache);
88 lview.read(xl);
89 lview.unbind();
90
91 // get geometry
92 auto geo = e.geometry();
93
94 // get Jacobian of geometry
95 const typename Traits::ElementType::Geometry::JacobianInverseTransposed
96 JgeoIT(geo.jacobianInverseTransposed(x));
97
98 // get local Jacobians/gradients of the shape functions
99 std::vector<typename LBTraits::JacobianType> J(lfs.size());
100 lfs.finiteElement().localBasis().evaluateJacobian(x,J);
101
102 typename Traits::RangeType gradphi;
103 typename Traits::RangeType minusgrad(0);
104 for(unsigned int i = 0; i < lfs.size(); ++i) {
105 // compute global gradient of shape function i
106 gradphi = 0;
107 JgeoIT.umv(J[i][0], gradphi);
108
109 // sum up global gradients, weighting them with the appropriate coeff
110 minusgrad.axpy(-xl[i], gradphi);
111 }
112
113 // multiply with permeability tensor
114 auto inside_cell_center_local = referenceElement(geo).position(0,0);
115 typename P::Traits::PermTensorType A(pp->A(e,inside_cell_center_local));
116 A.mv(minusgrad,y);
117 }
118
120 inline const typename Traits::GridViewType& getGridView () const
121 {
122 return pgfs->gridView();
123 }
124
125private:
126 std::shared_ptr<const GFS> pgfs;
127 std::shared_ptr<X> pxg;
128 std::shared_ptr<const P> pp;
129 mutable LFS lfs;
130 mutable LFSCache lfs_cache;
131 mutable LView lview;
132};
133
134#endif // DUNE_PDELAB_LOCALOPERATOR_DARCYFEM_HH
Provide Darcy velocity as a vector-valued grid function.
Definition: darcyfem.hh:38
const Traits::GridViewType & getGridView() const
get a reference to the GridView
Definition: darcyfem.hh:120
DarcyVelocityFromHeadFEM(const P &p, const GFS &gfs, X &x_)
Construct a DarcyVelocityFromHeadFEM.
Definition: darcyfem.hh:67
vector space out of a tensor product of fields.
Definition: fvector.hh:91
leaf of a function tree
Definition: function.hh:302
Implements a vector constructed from a given type representing a field and a compile-time given size.
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
This file implements several utilities related to std::shared_ptr.
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:50
traits class holding the function signature, same as in local function
Definition: function.hh:183
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:119
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:116
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)