3#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_HH
4#define DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETEGLOBALBASISFUNCTIONS_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>
80 using GridView =
typename Basis::GridView;
82 using Tree =
typename Basis::LocalView::Tree;
83 using NodeToRangeEntry = NTRE;
85 using Domain =
typename EntitySet::GlobalCoordinate;
95 using LocalView =
typename Basis::LocalView;
96 using size_type =
typename Tree::size_type;
99 using LocalBasisRange =
typename Node::FiniteElement::Traits::LocalBasisType::Traits::RangeType;
102 using NodeData =
typename std::vector<LocalBasisRange<Node>>;
109 using Domain = LocalDomain;
110 using Range = GlobalFunction::Range;
111 using Element = GlobalFunction::Element;
114 : globalFunction_(&globalFunction)
115 , localView_(globalFunction.basis().localView())
116 , evaluationBuffer_(localView_.tree())
119 localDoFs_.reserve(localView_.maxSize());
122 LocalFunction(
const LocalFunction& other)
123 : globalFunction_(other.globalFunction_)
124 , localView_(other.localView_)
125 , evaluationBuffer_(localView_.tree())
126 , bound_(other.bound_)
128 localDoFs_.reserve(localView_.maxSize());
130 localDoFs_ = other.localDoFs_;
133 LocalFunction& operator=(
const LocalFunction& other)
135 globalFunction_ = other.globalFunction_;
136 localView_ = other.localView_;
137 bound_ = other.bound_;
139 localDoFs_ = other.localDoFs_;
149 void bind(
const Element& element)
151 localView_.bind(element);
164 localDoFs_.resize(localView_.size());
165 for (size_type i = 0; i < localView_.tree().size(); ++i)
170 size_t localIndex = localView_.tree().localIndex(i);
171 localDoFs_[localIndex] = globalFunction_->dofs()[localView_.index(localIndex)];
197 Range operator()(
const Domain& x)
const
202 const auto& nodeToRangeEntry = globalFunction_->nodeToRangeEntry();
203 const auto& fe = node.finiteElement();
204 const auto& localBasis = fe.localBasis();
205 auto& shapeFunctionValues = evaluationBuffer_[treePath];
207 localBasis.evaluateFunction(x, shapeFunctionValues);
210 auto re = flatVectorView(nodeToRangeEntry(node, treePath, y));
212 for (size_type i = 0; i < localBasis.size(); ++i)
215 auto c = flatVectorView(localDoFs_[node.localIndex(i)]);
218 auto v = flatVectorView(shapeFunctionValues[i]);
224 auto&& dimC = c.size();
225 auto dimV = v.size();
226 assert(dimC*dimV == re.size());
227 for(size_type j=0; j<dimC; ++j)
230 for(size_type k=0; k<dimV; ++k)
231 re[j*dimV + k] += c_j*v[k];
239 const Element& localContext()
const
241 return localView_.element();
244 friend typename Traits::LocalFunctionTraits::DerivativeInterface derivative(
const LocalFunction& t)
252 LocalView localView_;
253 mutable PerNodeEvaluationBuffer evaluationBuffer_;
255 std::vector<Coefficient> localDoFs_;
258 template<
class B_T,
class V_T,
class NTRE_T>
260 entitySet_(basis.gridView()),
263 nodeToRangeEntry_(
wrap_or_move(
std::forward<NTRE_T>(nodeToRangeEntry)))
266 DiscreteGlobalBasisFunction(std::shared_ptr<const Basis> basis, std::shared_ptr<const V> coefficients, std::shared_ptr<const NodeToRangeEntry> nodeToRangeEntry) :
267 entitySet_(basis->gridView()),
269 coefficients_(coefficients),
270 nodeToRangeEntry_(nodeToRangeEntry)
273 const Basis& basis()
const
278 const V& dofs()
const
280 return *coefficients_;
283 const NodeToRangeEntry& nodeToRangeEntry()
const
285 return *nodeToRangeEntry_;
289 Range operator() (
const Domain& x)
const
294 friend typename Traits::DerivativeInterface
derivative(
const DiscreteGlobalBasisFunction& t)
316 return LocalFunction(t);
329 EntitySet entitySet_;
330 std::shared_ptr<const Basis> basis_;
331 std::shared_ptr<const V> coefficients_;
332 std::shared_ptr<const NodeToRangeEntry> nodeToRangeEntry_;
347template<
typename... TT>
352template<
typename R,
typename B,
typename V>
353auto makeDiscreteGlobalBasisFunction(B&& basis, V&& vector)
355 using Basis = std::decay_t<B>;
360 auto toConstVectorBackend = [&](
auto&& v) ->
decltype(
auto) {
361 if constexpr (models<Concept::ConstVectorBackend<Basis>,
decltype(v)>()) {
362 return std::forward<decltype(v)>(v);
368 using Vector = std::decay_t<decltype(toConstVectorBackend(std::forward<V>(vector)))>;
370 std::forward<B>(basis),
371 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:322
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
Traits for type conversions and type information.
typename AutonomousValueType< T >::type AutonomousValue
Type free of internal references that T can be converted to.
Definition: typetraits.hh:558
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
friend LocalFunction localFunction(const DiscreteGlobalBasisFunction &t)
Construct local function from a DiscreteGlobalBasisFunction.
Definition: discreteglobalbasisfunction.hh:314
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
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:304
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:304
Dune namespace.
Definition: alignedallocator.hh:11
auto wrap_or_move(T &&t)
Capture R-value reference to shared_ptr.
Definition: shared_ptr.hh:94
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
A simple node to range map using the nested tree indices.
Definition: hierarchicnodetorangemap.hh:30