3#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_HH
4#define DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_HH
9#include <dune/common/typetraits.hh>
11#include <dune/typetree/treecontainer.hh>
26template<
typename B,
typename V,
typename NTRE>
35 using Coefficient = Dune::AutonomousValue<decltype(std::declval<Vector>()[std::declval<typename Basis::MultiIndex>()])>;
39 using Tree =
typename Basis::LocalView::Tree;
55 std::shared_ptr<const Basis>
basis;
63 using LocalView =
typename Basis::LocalView;
64 using size_type =
typename Tree::size_type;
132 for (size_type i = 0; i <
localView_.tree().size(); ++i)
137 size_t localIndex =
localView_.tree().localIndex(i);
162 template<
class To,
class From>
167 assert(from_flat.size() == to_flat.size());
168 for (size_type i = 0; i < to_flat.size(); ++i)
169 to_flat[i] = from_flat[i];
172 template<
class Node,
class TreePath,
class Range>
173 decltype(
auto)
nodeToRangeEntry(
const Node& node,
const TreePath& treePath, Range& y)
const
175 return (*
data_->nodeToRangeEntry)(node, treePath, y);
195 return *
data_->basis;
201 return *
data_->coefficients;
207 return *
data_->nodeToRangeEntry;
213 return data_->entitySet;
224template<
typename DGBF>
264template<
typename B,
typename V,
266 typename R =
typename V::value_type>
285 using LocalBasisRange =
typename Node::FiniteElement::Traits::LocalBasisType::Traits::RangeType;
287 using NodeData =
typename std::vector<LocalBasisRange<Node>>;
288 using PerNodeEvaluationBuffer =
typename TypeTree::TreeContainer<NodeData, typename Base::Tree>;
295 using size_type =
typename Base::Tree::size_type;
296 using LocalBase::nodeToRangeEntry;
301 using Domain =
typename LocalBase::Domain;
307 : LocalBase(globalFunction.
data_)
327 TypeTree::forEachLeafNode(this->
localView_.tree(), [&](
auto&& node,
auto&& treePath) {
328 const auto& fe = node.finiteElement();
329 const auto& localBasis = fe.localBasis();
330 auto& shapeFunctionValues = evaluationBuffer_[treePath];
332 localBasis.evaluateFunction(x, shapeFunctionValues);
338 using Value = LocalBasisRange< std::decay_t<decltype(node)> >;
339 static constexpr auto coeffDim = decltype(flatVectorView(this->localDoFs_[node.localIndex(0)]).size())::value;
340 auto values = std::array<Value, coeffDim>{};
342 for (size_type i = 0; i < localBasis.size(); ++i)
345 for (std::size_t j = 0; j < coeffDim; ++j)
346 values[j].axpy(c[j], shapeFunctionValues[i]);
367 mutable PerNodeEvaluationBuffer evaluationBuffer_;
371 template<
class B_T,
class V_T,
class NTRE_T>
373 :
Base(std::make_shared<Data>(Data{{basis.gridView()}, wrap_or_move(std::forward<B_T>(basis)), wrap_or_move(std::forward<V_T>(coefficients)), wrap_or_move(std::forward<NTRE_T>(nodeToRangeEntry))}))
377 DiscreteGlobalBasisFunction(std::shared_ptr<const Basis> basis, std::shared_ptr<const V> coefficients, std::shared_ptr<const typename Base::NodeToRangeEntry> nodeToRangeEntry)
378 :
Base(std::make_shared<Data>(Data{{basis->gridView()}, basis, coefficients, nodeToRangeEntry}))
385 DUNE_THROW(NotImplemented,
"not implemented");
431template<
typename R,
typename B,
typename V>
434 using Basis = std::decay_t<B>;
439 auto toConstVectorBackend = [&](
auto&& v) ->
decltype(
auto) {
440 if constexpr (models<Concept::ConstVectorBackend<Basis>,
decltype(v)>()) {
441 return std::forward<decltype(v)>(v);
447 using Vector = std::decay_t<decltype(toConstVectorBackend(std::forward<V>(vector)))>;
449 std::forward<B>(basis),
450 toConstVectorBackend(std::forward<V>(vector)),
469template<
typename DGBF>
490 using LocalBasisRange =
typename Node::FiniteElement::Traits::LocalBasisType::Traits::JacobianType;
492 using NodeData =
typename std::vector< LocalBasisRange<Node> >;
493 using PerNodeEvaluationBuffer =
typename TypeTree::TreeContainer<NodeData, typename Base::Tree>;
508 using size_type =
typename Base::Tree::size_type;
509 using LocalBase::nodeToRangeEntry;
513 using Domain =
typename LocalBase::Domain;
519 : LocalBase(globalFunction.data_)
520 , evaluationBuffer_(this->localView_.tree())
533 LocalBase::bind(element);
534 geometry_.emplace(element.geometry());
562 const auto& jacobianInverse = geometry_->jacobianInverse(x);
564 TypeTree::forEachLeafNode(this->localView_.tree(), [&](
auto&& node,
auto&& treePath) {
565 const auto& fe = node.finiteElement();
566 const auto& localBasis = fe.localBasis();
567 auto& shapeFunctionJacobians = evaluationBuffer_[treePath];
569 localBasis.evaluateJacobian(x, shapeFunctionJacobians);
575 using RefJacobian = LocalBasisRange< std::decay_t<decltype(node)> >;
576 static constexpr auto coeffDim = decltype(flatVectorView(this->localDoFs_[node.localIndex(0)]).size())::value;
577 auto refJacobians = std::array<RefJacobian, coeffDim>{};
579 for (size_type i = 0; i < localBasis.size(); ++i)
582 for (std::size_t j = 0; j < coeffDim; ++j)
583 refJacobians[j].axpy(c[j], shapeFunctionJacobians[i]);
587 using Jacobian =
decltype(refJacobians[0] * jacobianInverse);
588 auto jacobians = std::array<Jacobian, coeffDim>{};
590 refJacobians.begin(), refJacobians.end(), jacobians.begin(),
591 [&](
const auto& refJacobian) { return refJacobian * jacobianInverse; });
595 LocalBase::assignWith(nodeToRangeEntry(node, treePath, y), jacobians);
604 DUNE_THROW(NotImplemented,
"derivative of derivative is not implemented");
608 mutable PerNodeEvaluationBuffer evaluationBuffer_;
609 std::optional<typename Element::Geometry> geometry_;
628 DUNE_THROW(NotImplemented,
"not implemented");
633 DUNE_THROW(NotImplemented,
"derivative of derivative is not implemented");
auto makeDiscreteGlobalBasisFunction(B &&basis, V &&vector)
Generate a DiscreteGlobalBasisFunction.
Definition: discreteglobalbasisfunction.hh:432
auto istlVectorBackend(Vector &v)
Return a vector backend wrapping non-const ISTL like containers.
Definition: istlvectorbackend.hh:346
Definition: polynomial.hh:10
auto flatVectorView(T &t)
Create flat vector view of passed mutable container.
Definition: flatvectorview.hh:179
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
Helper class to deduce the signature of a callable.
Definition: signature.hh:56
A simple node to range map using the nested tree indices.
Definition: hierarchicnodetorangemap.hh:30
Definition: discreteglobalbasisfunction.hh:28
std::shared_ptr< const Data > data_
Definition: discreteglobalbasisfunction.hh:217
const Vector & dofs() const
Return the coefficients of this discrete function by reference.
Definition: discreteglobalbasisfunction.hh:199
B Basis
Definition: discreteglobalbasisfunction.hh:30
typename Basis::LocalView::Tree Tree
Definition: discreteglobalbasisfunction.hh:39
V Vector
Definition: discreteglobalbasisfunction.hh:31
typename EntitySet::Element Element
Definition: discreteglobalbasisfunction.hh:45
typename EntitySet::LocalCoordinate LocalDomain
Definition: discreteglobalbasisfunction.hh:44
const NodeToRangeEntry & nodeToRangeEntry() const
Return the stored node-to-range map.
Definition: discreteglobalbasisfunction.hh:205
NTRE NodeToRangeEntry
Definition: discreteglobalbasisfunction.hh:40
DiscreteGlobalBasisFunctionBase(const std::shared_ptr< const Data > &data)
Definition: discreteglobalbasisfunction.hh:184
typename Basis::GridView GridView
Definition: discreteglobalbasisfunction.hh:37
const Basis & basis() const
Return a const reference to the stored basis.
Definition: discreteglobalbasisfunction.hh:193
GridViewEntitySet< GridView, 0 > EntitySet
Definition: discreteglobalbasisfunction.hh:38
const EntitySet & entitySet() const
Get associated set of entities the local-function can be bound to.
Definition: discreteglobalbasisfunction.hh:211
typename EntitySet::GlobalCoordinate Domain
Definition: discreteglobalbasisfunction.hh:42
Dune::AutonomousValue< decltype(std::declval< Vector >()[std::declval< typename Basis::MultiIndex >()])> Coefficient
Definition: discreteglobalbasisfunction.hh:35
Definition: discreteglobalbasisfunction.hh:53
EntitySet entitySet
Definition: discreteglobalbasisfunction.hh:54
std::shared_ptr< const NodeToRangeEntry > nodeToRangeEntry
Definition: discreteglobalbasisfunction.hh:57
std::shared_ptr< const Basis > basis
Definition: discreteglobalbasisfunction.hh:55
std::shared_ptr< const Vector > coefficients
Definition: discreteglobalbasisfunction.hh:56
Definition: discreteglobalbasisfunction.hh:62
LocalFunctionBase & operator=(const LocalFunctionBase &other)
Copy-assignment of the local-function.
Definition: discreteglobalbasisfunction.hh:100
bool bound() const
Check if LocalFunction is already bound to an element.
Definition: discreteglobalbasisfunction.hh:149
void bind(const Element &element)
Bind LocalFunction to grid element.
Definition: discreteglobalbasisfunction.hh:116
typename EntitySet::Element Element
Definition: discreteglobalbasisfunction.hh:68
const Element & localContext() const
Return the element the local-function is bound to.
Definition: discreteglobalbasisfunction.hh:155
LocalFunctionBase(const LocalFunctionBase &other)
Copy-construct the local-function.
Definition: discreteglobalbasisfunction.hh:84
std::vector< Coefficient > localDoFs_
Definition: discreteglobalbasisfunction.hh:180
void assignWith(To &to, const From &from) const
Definition: discreteglobalbasisfunction.hh:163
std::shared_ptr< const Data > data_
Definition: discreteglobalbasisfunction.hh:178
decltype(auto) nodeToRangeEntry(const Node &node, const TreePath &treePath, Range &y) const
Definition: discreteglobalbasisfunction.hh:173
LocalView localView_
Definition: discreteglobalbasisfunction.hh:179
void unbind()
Unbind the local-function.
Definition: discreteglobalbasisfunction.hh:143
LocalDomain Domain
Definition: discreteglobalbasisfunction.hh:67
LocalFunctionBase(const std::shared_ptr< const Data > &data)
Definition: discreteglobalbasisfunction.hh:71
Derivative of a DiscreteGlobalBasisFunction
Definition: discreteglobalbasisfunction.hh:472
typename Base::Basis Basis
Definition: discreteglobalbasisfunction.hh:479
friend Traits::DerivativeInterface derivative(const DiscreteGlobalBasisFunctionDerivative &f)
Definition: discreteglobalbasisfunction.hh:631
Range operator()(const Domain &x) const
Not implemented.
Definition: discreteglobalbasisfunction.hh:625
typename SignatureTraits< typename DiscreteGlobalBasisFunction::Traits::DerivativeInterface >::Range Range
Definition: discreteglobalbasisfunction.hh:483
friend LocalFunction localFunction(const DiscreteGlobalBasisFunctionDerivative &f)
Construct local function from a DiscreteGlobalBasisFunctionDerivative
Definition: discreteglobalbasisfunction.hh:637
DiscreteGlobalBasisFunctionDerivative(const std::shared_ptr< const Data > &data)
create object from DiscreateGlobalBasisFunction data
Definition: discreteglobalbasisfunction.hh:618
DGBF DiscreteGlobalBasisFunction
Definition: discreteglobalbasisfunction.hh:477
typename Base::Vector Vector
Definition: discreteglobalbasisfunction.hh:480
Imp::GridFunctionTraits< Range(Domain), typename Base::EntitySet, DefaultDerivativeTraits, 16 > Traits
Definition: discreteglobalbasisfunction.hh:485
typename Base::Domain Domain
Definition: discreteglobalbasisfunction.hh:482
A grid function induced by a global basis and a coefficient vector.
Definition: discreteglobalbasisfunction.hh:269
friend DiscreteGlobalBasisFunctionDerivative< DiscreteGlobalBasisFunction > derivative(const DiscreteGlobalBasisFunction &f)
Derivative of the DiscreteGlobalBasisFunction
Definition: discreteglobalbasisfunction.hh:389
DiscreteGlobalBasisFunction(B_T &&basis, V_T &&coefficients, NTRE_T &&nodeToRangeEntry)
Create a grid-function, by wrapping the arguments in std::shared_ptr.
Definition: discreteglobalbasisfunction.hh:372
DiscreteGlobalBasisFunction(std::shared_ptr< const Basis > basis, std::shared_ptr< const V > coefficients, std::shared_ptr< const typename Base::NodeToRangeEntry > nodeToRangeEntry)
Create a grid-function, by moving the arguments in std::shared_ptr.
Definition: discreteglobalbasisfunction.hh:377
friend LocalFunction localFunction(const DiscreteGlobalBasisFunction &t)
Construct local function from a DiscreteGlobalBasisFunction.
Definition: discreteglobalbasisfunction.hh:402
typename Base::Basis Basis
Definition: discreteglobalbasisfunction.hh:274
Imp::GridFunctionTraits< Range(Domain), typename Base::EntitySet, DefaultDerivativeTraits, 16 > Traits
Definition: discreteglobalbasisfunction.hh:280
R Range
Definition: discreteglobalbasisfunction.hh:278
typename Base::Vector Vector
Definition: discreteglobalbasisfunction.hh:275
typename Base::Domain Domain
Definition: discreteglobalbasisfunction.hh:277
Definition: discreteglobalbasisfunction.hh:293
GlobalFunction::Range Range
Definition: discreteglobalbasisfunction.hh:302
LocalFunction(const DiscreteGlobalBasisFunction &globalFunction)
Create a local-function from the associated grid-function.
Definition: discreteglobalbasisfunction.hh:306
friend DiscreteGlobalBasisFunctionDerivative< DiscreteGlobalBasisFunction >::LocalFunction derivative(const LocalFunction &lf)
Local function of the derivative.
Definition: discreteglobalbasisfunction.hh:358
Range operator()(const Domain &x) const
Evaluate this local-function in coordinates x in the bound element.
Definition: discreteglobalbasisfunction.hh:322
local function evaluating the derivative in reference coordinates
Definition: discreteglobalbasisfunction.hh:506
Range operator()(const Domain &x) const
Evaluate this local-function in coordinates x in the bound element.
Definition: discreteglobalbasisfunction.hh:557
friend Traits::LocalFunctionTraits::DerivativeInterface derivative(const LocalFunction &)
Not implemented.
Definition: discreteglobalbasisfunction.hh:602
GlobalFunction::Range Range
Definition: discreteglobalbasisfunction.hh:514
void unbind()
Unbind the local-function.
Definition: discreteglobalbasisfunction.hh:538
LocalFunction(const GlobalFunction &globalFunction)
Create a local function from the associated grid function.
Definition: discreteglobalbasisfunction.hh:518
void bind(const Element &element)
Bind LocalFunction to grid element.
Definition: discreteglobalbasisfunction.hh:531
Definition: gridfunction.hh:32
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
Element::Geometry::GlobalCoordinate GlobalCoordinate
Definition: gridviewentityset.hh:36