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> 32 template <
class Container>
38 static constexpr decltype(
auto)
39 accessByTreePath(C&& container, Dune::TypeTree::HybridTreePath<>
const&)
41 return container.value();
44 template <
class C,
class... T>
45 static constexpr decltype(
auto)
46 accessByTreePath(C&& container, Dune::TypeTree::HybridTreePath<T...>
const& path)
48 auto head = Dune::TypeTree::treePathEntry(path,Dune::Indices::_0);
49 return accessByTreePath(container[head], pop_front(path));
59 : container_(container)
64 : container_(
std::move(container))
69 decltype(
auto) operator[](
Dune::TypeTree::HybridTreePath<T...> const& path)
const 71 return accessByTreePath(container_, path);
76 decltype(
auto) operator[](
Dune::TypeTree::HybridTreePath<T...> const& path)
78 return accessByTreePath(container_, path);
82 Container
const&
data()
const 96 return container_ == other.container_;
102 return container_ != other.container_;
106 Container container_;
112 template <
class Value,
class Container>
113 class ValueAndContainer
116 template <
class V,
class C>
117 ValueAndContainer(V&& value, C&& container)
119 , container_(FWD(container))
128 auto&
operator[](I
const& i) {
return container_[i]; }
131 auto const&
operator[](I
const& i)
const {
return container_[i]; }
133 Value& value() {
return value_; }
134 Value
const& value()
const {
return value_; }
136 Container& container() {
return container_; }
137 Container
const& container()
const {
return container_; }
139 bool operator==(ValueAndContainer
const& other)
const 141 return value_ == other.value_ && container_ == other.container_;
146 Container container_;
149 template <
class Value>
150 class ValueAndContainer<Value,void>
153 template <
class V, Dune::disableCopyMove<ValueAndContainer,V> = 0>
154 ValueAndContainer(V&& value)
162 Value& value() {
return value_; }
163 Value
const& value()
const {
return value_; }
165 bool operator==(ValueAndContainer
const& other)
const 167 return value_ == other.value_;
176 template <
class Container>
177 class ValueAndContainer<Ignore,Container>
181 ValueAndContainer(Ignore, C&& container)
182 : container_(FWD(container))
190 auto&
operator[](I
const& i) {
return container_[i]; }
193 auto const&
operator[](I
const& i)
const {
return container_[i]; }
195 Ignore value() {
return {}; }
196 Ignore value()
const {
return {}; }
198 Container& container() {
return container_; }
199 Container
const& container()
const {
return container_; }
201 bool operator==(ValueAndContainer
const& other)
const 203 return container_ == other.container_;
207 Container container_;
211 template <
class Value,
class Container>
212 ValueAndContainer(Value
const&, Container
const&)
213 -> ValueAndContainer<Value,Container>;
215 template <
class Value>
216 ValueAndContainer(Value
const&)
217 -> ValueAndContainer<Value,void>;
231 template <
class NodeToValue,
bool leafOnly = false>
232 class ContainerFactory
241 ContainerFactory(NodeToValue nodeToValue)
242 : nodeToValue_(std::move(nodeToValue))
246 template <
class Node>
247 auto operator()(Node
const& node)
const 249 if constexpr (Node::isLeaf)
250 return ValueAndContainer{value(node)};
252 if constexpr (Node::isPower) {
253 using TransformedChild = decltype((*
this)(node.child(0)));
254 return ValueAndContainer{
256 std::array<TransformedChild, Node::degree()>()};
259 if constexpr (Node::isComposite) {
260 return ValueAndContainer{
262 Tools::apply_indices<Node::degree()>(
263 [&](
auto... ii) {
return Dune::makeTupleVector((*
this)(node.child(ii))...); })};
266 static_assert(Node::isLeaf || Node::isPower || Node::isComposite,
267 "Node must be one of leaf,power,composite.");
272 template <
class Node>
273 decltype(
auto) value(Node
const& node)
const 275 if constexpr(!Node::isLeaf && leafOnly)
278 return nodeToValue_(node);
282 NodeToValue nodeToValue_;
302 template <
bool leafOnly = false,
class Tree,
class NodeToValue>
305 auto f = std::ref(nodeToValue);
306 auto factory = Impl::ContainerFactory<decltype(f),leafOnly>(f);
326 template <
class Value,
bool leafOnly = false,
class Tree>
329 return makeTreeContainer<leafOnly>(tree, [](
auto&&) {
return Value{}; });
332 template <
template<
class>
class NodeData,
bool leafOnly =
false,
class Tree>
335 return makeTreeContainer<leafOnly>(tree, [](
auto&& node) {
return NodeData<TYPEOF(node)>{}; });
340 template <
class Value,
class Tree,
bool leafOnly = false>
342 = TYPEOF(makeTreeContainer<Value,leafOnly>(std::declval<const Tree&>()));
346 template <
class Value,
class RowTree,
class ColTree = RowTree,
bool leafOnly = false>
352 template <
template <
class Node>
class NodeData,
class Tree,
bool leafOnly =
false>
354 = TYPEOF(makeTreeContainer<NodeData,leafOnly>(std::declval<const Tree&>()));
359 template <
template <
class,
class>
class NodeData,
class Tree,
bool leafOnly>
362 template <
class RowNode>
365 template <
class ColNode>
366 using type = NodeData<RowNode, ColNode>;
369 template <
class RowNode>
377 template <
template <
class,
class>
class NodeData,
class RowTree,
class ColTree = RowTree,
bool leafOnly =
false>
Definition: AdaptiveGrid.hpp:373
Definition: FieldMatVec.hpp:12
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
TreeContainer< Impl::RowNodeData< NodeData, ColTree, leafOnly >::template type, RowTree, leafOnly > TreeMatrix
Definition: TreeContainer.hpp:379
TreeContainerStorage()
Default-construct the tree-container.
Definition: TreeContainer.hpp:54
Container & data()
Obtain the container (mutable)
Definition: TreeContainer.hpp:88
TreeContainerStorage(Container &&container)
Construct the tree-container from a given container storage.
Definition: TreeContainer.hpp:63
auto makeTreeContainer(Tree const &tree, NodeToValue &&nodeToValue)
Create container having the same structure as the given tree.
Definition: TreeContainer.hpp:303
UniformTreeContainer< UniformTreeContainer< Value, ColTree, leafOnly >, RowTree, leafOnly > UniformTreeMatrix
Definition: TreeContainer.hpp:348
Vector data-structure with tree-path index access and hierarchic structure given by the Container tem...
Definition: TreeContainer.hpp:33
bool operator==(TreeContainerStorage const &other) const
Compare two containers for equality.
Definition: TreeContainer.hpp:94
bool operator!=(TreeContainerStorage const &other) const
Compare two containers for inequality.
Definition: TreeContainer.hpp:100
TYPEOF(makeTreeContainer< Value, leafOnly >(std::declval< const Tree & >())) UniformTreeContainer
Definition: TreeContainer.hpp:342
Container const & data() const
Obtain the container (const)
Definition: TreeContainer.hpp:82
TYPEOF(makeTreeContainer< NodeData, leafOnly >(std::declval< const Tree & >())) TreeContainer
Definition: TreeContainer.hpp:354
decltype(auto) operator[](Dune::TypeTree::HybridTreePath< T... > const &path) const
Access a (const) element of the container by treepath.
Definition: TreeContainer.hpp:69