3#ifndef DUNE_PDELAB_FUNCTION_DISCRETEGRIDVIEWFUNCTION_HH
4#define DUNE_PDELAB_FUNCTION_DISCRETEGRIDVIEWFUNCTION_HH
16#include <dune/localfunctions/common/interfaceswitch.hh>
18#include <dune/pdelab/common/jacobiantocurl.hh>
19#include <dune/pdelab/gridfunctionspace/gridfunctionspace.hh>
20#include <dune/pdelab/gridfunctionspace/localfunctionspace.hh>
21#include <dune/pdelab/gridfunctionspace/lfsindexcache.hh>
23#include <dune/functions/gridfunctions/gridviewfunction.hh>
27 template<
typename T,
int N,
typename R2>
28 struct common_type<
Dune::FieldVector<T,N>, R2>
33 template<
typename T,
int N,
typename R2>
43template<
typename Signature,
typename E,
template<
class>
class D,
int B,
45struct DiscreteGridViewFunctionTraits :
46 Functions::Imp::GridFunctionTraits<
47 typename DiscreteGridViewFunctionTraits<Signature,E,D,B,diffOrder-1>::DerivativeSignature
51template<
typename Signature,
typename E,
template<
class>
class D,
int B>
52struct DiscreteGridViewFunctionTraits<Signature,E,D,B,0> :
53 Functions::Imp::GridFunctionTraits<Signature,E,D,B>
70template<
typename GFS,
typename V,
int diffOrder = 0>
74 using GridView =
typename GFS::Traits::GridView;
77 using Domain =
typename EntitySet::GlobalCoordinate;
78 using LocalBasisTraits =
typename GFS::Traits::FiniteElementMap::Traits::FiniteElement::Traits::LocalBasisType::Traits;
80 using VectorRange =
typename V::ElementType;
81 using ElementaryRange =
typename std::common_type<LocalBasisRange, VectorRange>::type;
87 DiscreteGridViewFunctionTraits<ElementaryRange(Domain),
EntitySet,
90 using Range =
typename Traits::Range;
93 using GridFunctionSpace = GFS;
99 using LFSCache = LFSIndexCache<LFS>;
100 using XView =
typename Vector::template ConstLocalView<LFSCache>;
105 using Domain = LocalDomain;
106 using Range = GlobalFunction::Range;
107 using Element = GlobalFunction::Element;
108 using size_type = std::size_t;
110 LocalFunction(
const std::shared_ptr<const GridFunctionSpace> gfs,
const std::shared_ptr<const Vector> v)
116 , xl_(pgfs_->maxLocalSize())
117 , yb_(pgfs_->maxLocalSize())
127 void bind(
const Element& element)
132 x_view_.bind(lfs_cache_);
142 const Element& localContext()
const
171 if (t.element_) diff.bind(*t.element_);
185 operator()(
const Domain& coord)
const
187 return evaluate<diffOrder>(coord);
192 typename std::enable_if<(dOrder > 2),
194 evaluate(
const Domain& coord)
const
197 "Derivatives are only implemented up to degree 2");
201 typename std::enable_if<dOrder == 0,
203 evaluate(
const Domain& coord)
const
206 auto& basis = lfs_.finiteElement().localBasis();
207 basis.evaluateFunction(coord,yb_);
208 for (size_type i = 0; i < yb_.size(); ++i)
210 r.axpy(xl_[i],yb_[i]);
216 typename std::enable_if<dOrder == 1,
218 evaluate(
const Domain& coord)
const
222 const typename Element::Geometry::JacobianInverseTransposed
223 JgeoIT = element_->geometry().jacobianInverseTransposed(coord);
226 lfs_.finiteElement().localBasis().evaluateJacobian(coord,yb_);
230 for(std::size_t i = 0; i < yb_.size(); ++i) {
231 assert(gradphi.size() == yb_[i].size());
232 for(std::size_t j = 0; j < gradphi.size(); ++j) {
235 JgeoIT.mv(yb_[i][j], gradphi[j]);
240 r[j].axpy(xl_[i], gradphi[j]);
247 typename std::enable_if<dOrder == 2,
249 evaluate(
const Domain& coord)
const
253 if (! element_->geometry().affine())
255 "the computation of higher derivatives (>=2) works only for affine transformations.");
257 const typename Element::Geometry::JacobianInverseTransposed
258 JgeoIT = element_->geometry().jacobianInverseTransposed(coord);
268 std::array<std::size_t, dim> directions;
269 for(std::size_t i = 0; i < dim; ++i) {
274 for(std::size_t j = i+1; j < dim; ++j) {
276 lfs_.finiteElement().localBasis().partial(directions,coord,yb_);
277 assert( yb_.size() == 1);
278 for(std::size_t n = 0; n < yb_.size(); ++n) {
280 r[i][j] += xl_[i] * yb_[j];
289 for(std::size_t i = 0; i < dim; ++i)
290 for(std::size_t j = i; j < dim; ++j)
291 r[i][j] *= JgeoIT[i][j] * JgeoIT[i][j];
297 const std::shared_ptr<const GridFunctionSpace> pgfs_;
298 const std::shared_ptr<const Vector> v_;
302 mutable std::vector<ElementaryRange> xl_;
303 mutable std::vector<Range> yb_;
304 const Element* element_;
316 const Basis& basis()
const
320 const GridFunctionSpace& gridFunctionSpace()
const
325 const V& dofs()
const
343 Range operator() (
const Domain& x)
const
348 friend DiscreteGridViewFunction<GFS,V,diffOrder+1> derivative(
const DiscreteGridViewFunction& t)
350 return DiscreteGridViewFunction<GFS,V,diffOrder+1>(t.pgfs_, t.v_);
364 return LocalFunction(t.pgfs_, t.v_);
372 return pgfs_->gridView();
377 const std::shared_ptr<const GridFunctionSpace> pgfs_;
378 const std::shared_ptr<const Vector> v_;
vector space out of a tensor product of fields.
Definition: fvector.hh:95
GridView::template Codim< codim >::Entity Element
Type of Elements contained in this EntitySet.
Definition: gridviewentityset.hh:32
Element::Geometry::LocalCoordinate LocalCoordinate
Type of local coordinates with respect to the Element.
Definition: gridviewentityset.hh:35
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
Default exception for dummy implementations.
Definition: exceptions.hh:261
A discrete function defined over a GridFunctionSpace.
Definition: discretegridviewfunction.hh:72
EntitySet entitySet() const
Get associated EntitySet.
Definition: discretegridviewfunction.hh:370
auto dofsStorage() const
Returns storage object of the dof storage vector.
Definition: discretegridviewfunction.hh:337
friend LocalFunction localFunction(const DiscreteGridViewFunction &t)
Get local function of wrapped function.
Definition: discretegridviewfunction.hh:362
auto gridFunctionSpaceStorage() const
Returns storage object of the grid function space.
Definition: discretegridviewfunction.hh:331
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
@ dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:134
Dune namespace.
Definition: alignedallocator.hh:11
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:70
This file implements several utilities related to std::shared_ptr.
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
R RangeType
range type
Definition: localbasis.hh:55