8 #include <dune/common/indices.hh> 9 #include <dune/common/tuplevector.hh> 11 #include <dune/typetree/treepath.hh> 13 #include <amdis/common/Apply.hpp> 14 #include <amdis/common/TypeTraits.hpp> 15 #include <amdis/typetree/TreePath.hpp> 22 template <
class Value>
35 Value& value() {
return value_; }
36 Value
const& value()
const {
return value_; }
40 return value_ == other.value_;
47 template <
class Value>
52 template <
class Value,
class Container>
56 template <
class V,
class C>
59 , container_(FWD(container))
68 auto& operator[](I
const& i) {
return container_[i]; }
71 auto const& operator[](I
const& i)
const {
return container_[i]; }
73 Value& value() {
return value_; }
74 Value
const& value()
const {
return value_; }
76 Container& container() {
return container_; }
77 Container
const& container()
const {
return container_; }
81 return value_ == other.value_ && container_ == other.container_;
89 template <
class Value,
class Container>
105 template <
class NodeToValue,
bool leafOnly = false>
116 : nodeToValue_(
std::move(nodeToValue))
120 template <
class Node>
123 if constexpr (Node::isLeaf)
126 if constexpr (Node::isPower) {
127 using TransformedChild = decltype((*
this)(node.child(0)));
128 return makeInnerNodeStorage(node,
129 std::array<TransformedChild, Node::degree()>());
132 if constexpr (Node::isComposite) {
133 return makeInnerNodeStorage(node,
134 Ranges::applyIndices<Node::degree()>(
135 [&](
auto... ii) {
return Dune::makeTupleVector((*
this)(node.child(ii))...); }));
138 static_assert(Node::isLeaf || Node::isPower || Node::isComposite,
139 "Node must be one of leaf, power, composite.");
144 template <
class Node,
class Container>
145 auto makeInnerNodeStorage(Node
const& node, Container&& container)
const 147 if constexpr(!Node::isLeaf && leafOnly)
148 return FWD(container);
154 NodeToValue nodeToValue_;
168 template <
class Container>
174 static constexpr
auto 175 accessByTreePath(C&& container, Dune::TypeTree::HybridTreePath<>) -> decltype(container.value())
177 return container.value();
180 template <
class C,
class T0,
class... T>
181 static constexpr decltype(
auto)
182 accessByTreePath(C&& container, Dune::TypeTree::HybridTreePath<T0,T...>
const& path)
184 auto head = Dune::TypeTree::treePathEntry(path,Dune::Indices::_0);
185 return accessByTreePath(container[head],
pop_front(path));
196 : container_(container)
201 : container_(
std::move(container))
205 template <
class... T>
206 decltype(
auto) operator[](
Dune::TypeTree::HybridTreePath<T...> const& path)
const 208 return accessByTreePath(container_, path);
212 template <
class... T>
213 decltype(
auto) operator[](
Dune::TypeTree::HybridTreePath<T...> const& path)
215 return accessByTreePath(container_, path);
233 return container_ == other.container_;
239 return container_ != other.container_;
243 Container container_;
263 template <
bool leafOnly = false,
class Tree,
class NodeToValue>
264 auto treeContainer(
Tree const& tree, NodeToValue nodeToValue)
286 template <
class Value,
bool leafOnly = false,
class Tree>
287 auto treeContainer(
Tree const& tree)
289 return treeContainer<leafOnly>(tree, [](
auto&&) {
return Value{}; });
292 template <
template<
class>
class NodeData,
bool leafOnly =
false,
class Tree>
293 auto treeContainer(
Tree const& tree)
295 return treeContainer<leafOnly>(tree, [](
auto&& node) {
return NodeData<TYPEOF(node)>{}; });
300 template <
class Value,
class Tree,
bool leafOnly = false>
301 using UniformTreeContainer
302 = TYPEOF(treeContainer<Value,leafOnly>(std::declval<const Tree&>()));
306 template <
class Value,
class RowTree,
class ColTree = RowTree,
bool leafOnly = false>
307 using UniformTreeMatrix
308 = UniformTreeContainer<UniformTreeContainer<Value,ColTree,leafOnly>,RowTree,leafOnly>;
312 template <
template <
class Node>
class NodeData,
class Tree,
bool leafOnly =
false>
314 = TYPEOF(treeContainer<NodeData,leafOnly>(std::declval<const Tree&>()));
319 template <
template <
class,
class>
class NodeData,
class Tree,
bool leafOnly>
322 template <
class RowNode>
325 template <
class ColNode>
326 using type = NodeData<RowNode, ColNode>;
329 template <
class RowNode>
330 using type = TreeContainer<ColNodeData<RowNode>::template type, Tree, leafOnly>;
337 template <
template <
class,
class>
class NodeData,
class RowTree,
class ColTree = RowTree,
bool leafOnly =
false>
339 = TreeContainer<Impl_::RowNodeData<NodeData,ColTree,leafOnly>::template type,RowTree,leafOnly>;
bool operator==(TreeContainerStorage const &other) const
Compare two containers for equality.
Definition: TreeContainer.hpp:231
TreeContainerStorage(Container const &container)
Construct the tree-container from a given container storage.
Definition: TreeContainer.hpp:195
bool operator!=(TreeContainerStorage const &other) const
Compare two containers for inequality.
Definition: TreeContainer.hpp:237
Container & data()
Obtain the container (mutable)
Definition: TreeContainer.hpp:225
Definition: AdaptiveGrid.hpp:373
Definition: TreeContainer.hpp:320
Definition: FieldMatVec.hpp:12
auto operator()(Node const &node) const
Return a container for storing the node content.
Definition: TreeContainer.hpp:121
Container const & data() const
Obtain the container (const)
Definition: TreeContainer.hpp:219
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
TreeContainerStorage(Container &&container)
Construct the tree-container from a given container storage.
Definition: TreeContainer.hpp:200
Definition: TreeContainer.hpp:53
Vector data-structure with tree-path index access and hierarchic structure given by the Container tem...
Definition: TreeContainer.hpp:169
auto pop_front(Dune::TypeTree::HybridTreePath< T0, T... > const &tp)
Extract the first entry in the treepath.
Definition: TreePath.hpp:191
TreeContainerStorage()
Default-construct the tree-container.
Definition: TreeContainer.hpp:190
ContainerFactory(NodeToValue nodeToValue)
Create ContainerFactory.
Definition: TreeContainer.hpp:115
A factory class creating a hybrid container compatible with a type tree.
Definition: TreeContainer.hpp:106
Definition: TreeContainer.hpp:23
Definition: TreeContainer.hpp:323