3#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_HH
4#define DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_HH
9#include <dune/common/hybridutilities.hh>
11#include <dune/typetree/treecontainer.hh>
13#include <dune/functions/functionspacebases/hierarchicnodetorangemap.hh>
14#include <dune/functions/functionspacebases/flatvectorview.hh>
15#include <dune/functions/gridfunctions/gridviewentityset.hh>
16#include <dune/functions/gridfunctions/gridfunction.hh>
17#include <dune/functions/backends/concepts.hh>
18#include <dune/functions/backends/istlvectorbackend.hh>
67template<
typename B,
typename V,
68 typename NTRE = HierarchicNodeToRangeMap,
69 typename R =
typename V::value_type>
76 using Coefficient = std::decay_t<decltype(std::declval<Vector>()[std::declval<typename Basis::MultiIndex>()])>;
78 using GridView =
typename Basis::GridView;
80 using Tree =
typename Basis::LocalView::Tree;
81 using NodeToRangeEntry = NTRE;
83 using Domain =
typename EntitySet::GlobalCoordinate;
93 using LocalView =
typename Basis::LocalView;
94 using size_type =
typename Tree::size_type;
97 using LocalBasisRange =
typename Node::FiniteElement::Traits::LocalBasisType::Traits::RangeType;
100 using NodeData =
typename std::vector<LocalBasisRange<Node>>;
107 using Domain = LocalDomain;
108 using Range = GlobalFunction::Range;
109 using Element = GlobalFunction::Element;
112 : globalFunction_(&globalFunction)
113 , localView_(globalFunction.basis().localView())
117 LocalFunction(
const LocalFunction& other)
118 : globalFunction_(other.globalFunction_)
119 , localView_(other.localView_)
120 , bound_(other.bound_)
123 LocalFunction operator=(
const LocalFunction& other)
125 globalFunction_ = other.globalFunction_;
126 localView_ = other.localView_;
127 bound_ = other.bound_;
136 void bind(
const Element& element)
138 localView_.bind(element);
164 Range operator()(
const Domain& x)
const
169 const auto& dofs = globalFunction_->dofs();
170 const auto& nodeToRangeEntry = globalFunction_->nodeToRangeEntry();
171 const auto& fe = node.finiteElement();
172 const auto& localBasis = fe.localBasis();
173 auto& shapeFunctionValues = evaluationBuffer_[treePath];
175 localBasis.evaluateFunction(x, shapeFunctionValues);
178 auto re = flatVectorView(nodeToRangeEntry(node, treePath, y));
180 for (size_type i = 0; i < localBasis.size(); ++i)
182 const auto& multiIndex = localView_.index(node.localIndex(i));
185 auto c = flatVectorView(dofs[multiIndex]);
188 auto v = flatVectorView(shapeFunctionValues[i]);
194 auto&& dimC = c.size();
195 auto dimV = v.size();
196 assert(dimC*dimV == re.size());
197 for(size_type j=0; j<dimC; ++j)
200 for(size_type k=0; k<dimV; ++k)
201 re[j*dimV + k] += c_j*v[k];
209 const Element& localContext()
const
211 return localView_.element();
214 friend typename Traits::LocalFunctionTraits::DerivativeInterface derivative(
const LocalFunction& t)
222 LocalView localView_;
223 mutable PerNodeEvaluationBuffer evaluationBuffer_;
227 template<
class B_T,
class V_T,
class NTRE_T>
229 entitySet_(basis.gridView()),
232 nodeToRangeEntry_(
wrap_or_move(
std::forward<NTRE_T>(nodeToRangeEntry)))
235 DiscreteGlobalBasisFunction(std::shared_ptr<const Basis> basis, std::shared_ptr<const V> coefficients, std::shared_ptr<const NodeToRangeEntry> nodeToRangeEntry) :
236 entitySet_(basis->gridView()),
238 coefficients_(coefficients),
239 nodeToRangeEntry_(nodeToRangeEntry)
242 const Basis& basis()
const
247 const V& dofs()
const
249 return *coefficients_;
252 const NodeToRangeEntry& nodeToRangeEntry()
const
254 return *nodeToRangeEntry_;
258 Range operator() (
const Domain& x)
const
263 friend typename Traits::DerivativeInterface
derivative(
const DiscreteGlobalBasisFunction& t)
285 return LocalFunction(t);
298 EntitySet entitySet_;
299 std::shared_ptr<const Basis> basis_;
300 std::shared_ptr<const V> coefficients_;
301 std::shared_ptr<const NodeToRangeEntry> nodeToRangeEntry_;
316template<
typename... TT>
321template<
typename R,
typename B,
typename V>
322auto makeDiscreteGlobalBasisFunction(B&& basis, V&& vector)
324 using Basis = std::decay_t<B>;
329 auto toConstVectorBackend = [&](
auto&& v) ->
decltype(
auto) {
331 [&](
auto id) ->
decltype(
auto) {
332 return std::forward<decltype(v)>(v);
333 }, [&](
auto id) ->
decltype(
auto) {
338 using Vector = std::decay_t<decltype(toConstVectorBackend(std::forward<V>(vector)))>;
340 std::forward<B>(basis),
341 toConstVectorBackend(std::forward<V>(vector)),
A grid function induced by a global basis and a coefficient vector.
Definition: discreteglobalbasisfunction.hh:71
const EntitySet & entitySet() const
Get associated EntitySet.
Definition: discreteglobalbasisfunction.hh:291
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 for dummy implementations.
Definition: exceptions.hh:261
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:182
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
friend LocalFunction localFunction(const DiscreteGlobalBasisFunction &t)
Construct local function from a DiscreteGlobalBasisFunction.
Definition: discreteglobalbasisfunction.hh:283
void localFunction(DiscreteGlobalBasisFunction< TT... > &&t)=delete
Construction of local functions from a temporary DiscreteGlobalBasisFunction (forbidden)
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition: trigonometricfunction.hh:39
auto istlVectorBackend(Vector &v)
Return a vector backend wrapping non-const ISTL like containers.
Definition: istlvectorbackend.hh:345
decltype(auto) ifElse(const Condition &condition, IfFunc &&ifFunc, ElseFunc &&elseFunc)
A conditional expression.
Definition: hybridutilities.hh:355
constexpr HybridTreePath< T... > treePath(const T &... t)
Constructs a new HybridTreePath from the given indices.
Definition: treepath.hh:188
void forEachLeafNode(Tree &&tree, LeafFunc &&leafFunc)
Traverse tree and visit each leaf node.
Definition: traversal.hh:277
std::decay_t< decltype(makeTreeContainer(std::declval< const Tree & >(), std::declval< Detail::LeafToDefaultConstructibleValue< LeafToValue > >()))> TreeContainer
Alias to container type generated by makeTreeContainer for give tree type and when using LeafToValue ...
Definition: treecontainer.hh:222
Dune namespace.
Definition: alignedallocator.hh:14
auto wrap_or_move(T &&t)
Capture R-value reference to shared_ptr.
Definition: shared_ptr.hh:99
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
A simple node to range map using the nested tree indices.
Definition: hierarchicnodetorangemap.hh:30