7#include <dune/common/ftraits.hh>
8#include <dune/common/hash.hh>
9#include <dune/common/indices.hh>
10#include <dune/common/typetree/childaccess.hh>
12#include <dune/geometry/type.hh>
14#include <dune/typetree/compositenode.hh>
15#include <dune/typetree/dynamicpowernode.hh>
16#include <dune/typetree/leafnode.hh>
17#include <dune/typetree/powernode.hh>
19#include <amdis/common/ConcurrentCache.hpp>
20#include <amdis/typetree/NodeTags.hpp>
26 template <
class Node,
class NodeTag = AMDiS::NodeTag_t<Node>>
27 struct NodeCacheFactory;
34 using NodeCache_t =
typename Impl::NodeCacheFactory<Node>::type;
38 auto makeNodeCache (Node
const& node)
40 return NodeCache_t<Node>::create(node);
46 template <
class NodeType>
50 using Node = NodeType;
51 using Element =
typename Node::Element;
62 assert(node_ !=
nullptr);
69 return node_->element();
75 return node_->localIndex(i);
87 return node_->treeIndex();
91 Node
const* node_ =
nullptr;
104 template <
class Node>
106 :
public Dune::TypeTree::LeafNode
110 using BasisNode = Node;
112 using FiniteElement =
typename Node::FiniteElement;
113 using LocalBasis =
typename FiniteElement::Traits::LocalBasisType;
115 using ShapeValues = std::vector<typename LocalBasis::Traits::RangeType>;
116 using ShapeGradients = std::vector<typename LocalBasis::Traits::JacobianType>;
119 using DomainType =
typename LocalBasis::Traits::DomainType;
129 std::size_t operator()(CoordKey
const& t)
const
131 std::size_t seed = 0;
132 Dune::hash_combine(seed, t.id);
133 Dune::hash_range(seed, t.local.begin(), t.local.end());
138 friend bool operator==(CoordKey
const& lhs, CoordKey
const& rhs)
140 return std::tie(lhs.id,lhs.local) == std::tie(rhs.id,rhs.local);
160 return this->node_->finiteElement();
166 CoordKey key{this->
element().type().id(), local};
167 return shapeValues_.get(key, [&](CoordKey
const&)
170 this->localBasis().evaluateFunction(local, data);
178 CoordKey key{this->
element().type().id(), local};
179 return shapeGradients_.get(key, [&](CoordKey
const&)
182 this->localBasis().evaluateJacobian(local, data);
189 LocalBasis
const& localBasis ()
const
191 return this->node_->finiteElement().localBasis();
195 template <
class Value>
196 using CoordCache = ConcurrentCache<CoordKey, Value, ConsecutivePolicy,
197 std::unordered_map<CoordKey, Value, typename CoordKey::hasher>>;
199 CoordCache<ShapeValues> shapeValues_;
200 CoordCache<ShapeGradients> shapeGradients_;
204 template <
class Node>
206 :
public Impl::NodeCacheFactory<Node>::Base
210 using Super =
typename Impl::NodeCacheFactory<Node>::Base;
219 static auto create (Node
const& basisNode)
221 Self cache{basisNode};
222 for (std::size_t i = 0; i < std::size_t(basisNode.degree()); ++i)
223 cache.setChild(i, Dune::TypeTree::Child<Super,0>::create(basisNode.child(i)));
229 template <
class Node>
231 :
public Impl::NodeCacheFactory<Node>::Base
235 using Super =
typename Impl::NodeCacheFactory<Node>::Base;
239 : Super(basisNode.degree())
245 static auto create (Node
const& basisNode)
247 Self cache{basisNode};
248 for (std::size_t i = 0; i < std::size_t(basisNode.degree()); ++i)
249 cache.setChild(i, Dune::TypeTree::Child<Super,0>::create(basisNode.child(i)));
255 template <
class Node>
257 :
public Impl::NodeCacheFactory<Node>::Base
261 using Super =
typename Impl::NodeCacheFactory<Node>::Base;
270 static auto create (Node
const& basisNode)
272 Self cache{basisNode};
273 Dune::Hybrid::forEach(std::make_index_sequence<std::size_t(Node::degree())>{}, [&](
auto ii) {
274 cache.setChild(Dune::TypeTree::Child<Super,ii>::create(basisNode.child(ii)), ii);
282 template <
class Node>
283 struct NodeCacheFactory<Node, AMDiS::LeafNodeTag>
285 using Base = Dune::TypeTree::LeafNode;
286 using type = LeafNodeCache<Node>;
289 template <
class Node>
290 struct NodeCacheFactory<Node, AMDiS::PowerNodeTag>
292 using Child =
typename NodeCacheFactory<Dune::TypeTree::Child<Node,0>>::type;
293 using Base = Dune::TypeTree::PowerNode<Child, std::size_t(Node::degree())>;
294 using type = PowerNodeCache<Node>;
297 template <
class Node>
298 struct NodeCacheFactory<Node, AMDiS::DynamicPowerNodeTag>
300 using Child =
typename NodeCacheFactory<Dune::TypeTree::Child<Node,0>>::type;
301 using Base = Dune::TypeTree::DynamicPowerNode<Child>;
302 using type = DynamicPowerNodeCache<Node>;
305 template <
class Node>
306 struct NodeCacheFactory<Node, AMDiS::CompositeNodeTag>
308 template <
class Indices>
struct Childs;
309 template <std::size_t... i>
310 struct Childs<std::index_sequence<i...>> {
311 using type = Dune::TypeTree::CompositeNode<
312 typename NodeCacheFactory<Dune::TypeTree::Child<Node,i>>::type...
316 using Base =
typename Childs<std::make_index_sequence<std::size_t(Node::degree())>>::type;
317 using type = CompositeNodeCache<Node>;
Definition NodeCache.hpp:259
static auto create(Node const &basisNode)
Construct a new composite node by setting each child individually.
Definition NodeCache.hpp:270
Definition NodeCache.hpp:233
static auto create(Node const &basisNode)
Construct a new power node by setting each child individually.
Definition NodeCache.hpp:245
Cache of LocalBasis evaluations and jacobians at local points.
Definition NodeCache.hpp:108
static LeafNodeCache create(Node const &basisNode)
Construct a new local-basis cache.
Definition NodeCache.hpp:152
FiniteElement const & finiteElement() const
Return the local finite-element of the stored basis-node.
Definition NodeCache.hpp:158
ShapeValues const & localBasisValuesAt(DomainType const &local) const
Evaluate local basis functions at local coordinates.
Definition NodeCache.hpp:164
ShapeGradients const & localBasisJacobiansAt(DomainType const &local) const
Evaluate local basis jacobians at local coordinates.
Definition NodeCache.hpp:176
Wrapper around a basis-node storing just a pointer and providing some essential functionality like si...
Definition NodeCache.hpp:48
NodeWrapper(Node const &node)
Store a reference to the node.
Definition NodeCache.hpp:55
auto size() const
Return the size of the index-set of the node.
Definition NodeCache.hpp:79
Node const & node() const
Return the stored basis-node.
Definition NodeCache.hpp:60
Element const & element() const
Return the bound grid element.
Definition NodeCache.hpp:67
auto localIndex(std::size_t i) const
Return the index of the i-th local basis function in the index-set of the whole tree.
Definition NodeCache.hpp:73
auto treeIndex() const
Return a unique index within the tree.
Definition NodeCache.hpp:85
Definition NodeCache.hpp:208
static auto create(Node const &basisNode)
Construct a new power node by setting each child individually.
Definition NodeCache.hpp:219
Definition NodeCache.hpp:128