Am Montag, 13. Mai 2022, finden Wartungsarbeiten am Gitlab-Server (Update auf neue Version statt). Der Dienst wird daher am Montag für einige Zeit nicht verfügbar sein.
On Monday, May 13th 2022, the Gitlab server will be updated. The service will therefore not be accessible for some time on Monday.

Commit 59e7bf37 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Make TreeContainer default constructible and thus allow matrix containers

parent 95a126a5
......@@ -12,6 +12,7 @@
#include <amdis/common/Apply.hpp>
#include <amdis/common/TypeTraits.hpp>
#include <amdis/typetree/TreePath.hpp>
// NOTE: backport of dune/typetree/treecontainer.hh
......@@ -65,8 +66,9 @@ namespace AMDiS
std::enable_if_t<Node::isComposite, int> = 0>
auto operator()(const Node& node)
{
return Tools::apply_indices([&](auto... indices) { return Dune::makeTupleVector((*this)(node.child(indices))...); },
index_t<Node::degree()>{});
return Tools::apply_indices([&](auto... indices) {
return Dune::makeTupleVector((*this)(node.child(indices))...);
}, index_t<Node::degree()>{});
}
private:
......@@ -80,6 +82,8 @@ namespace AMDiS
template<class Container>
class TreeContainerVectorBackend
{
using Self = TreeContainerVectorBackend;
template<class C>
static constexpr decltype(auto) accessByTreePath(C&& container, const Dune::TypeTree::HybridTreePath<>& path)
{
......@@ -90,23 +94,22 @@ namespace AMDiS
static constexpr decltype(auto) accessByTreePath(C&& container, const Dune::TypeTree::HybridTreePath<T...>& path)
{
auto head = Dune::TypeTree::treePathEntry(path,Dune::Indices::_0);
auto tailPath = Tools::apply_indices([&](auto... i)
{
using namespace Dune::TypeTree;
return hybridTreePath(treePathEntry(path,index_t<i.value+1>{})...);
}, index_t<sizeof...(T)-1>{});
return accessByTreePath(container[head], tailPath);
return accessByTreePath(container[head], pop_front(path));
}
public:
TreeContainerVectorBackend(Container&& container) :
container_(std::move(container))
{}
TreeContainerVectorBackend() = default;
TreeContainerVectorBackend(TreeContainerVectorBackend&& other) :
container_(std::move(other.container_))
TreeContainerVectorBackend(Container&& container)
: container_(std::move(container))
{}
TreeContainerVectorBackend(const Self&) = default;
TreeContainerVectorBackend(Self&&) = default;
Self& operator=(const Self&) = default;
Self& operator=(Self&&) = default;
template<class... T>
decltype(auto) operator[](const Dune::TypeTree::HybridTreePath<T...>& path) const
{
......@@ -129,6 +132,16 @@ namespace AMDiS
return container_;
}
bool operator==(TreeContainerVectorBackend const& other) const
{
return container_ == other.container_;
}
bool operator!=(TreeContainerVectorBackend const& other) const
{
return container_ != other.container_;
}
private:
Container container_;
};
......
......@@ -54,3 +54,6 @@ dune_add_test(SOURCES StringTest.cpp
dune_add_test(SOURCES TreeDataTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES TreeContainerTest.cpp
LINK_LIBRARIES amdis)
#include <dune/grid/yaspgrid.hh>
#include <dune/functions/functionspacebases/compositebasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/powerbasis.hh>
#include <amdis/typetree/Traversal.hpp>
#include <amdis/typetree/TreeContainer.hpp>
#include "Tests.hpp"
using namespace AMDiS;
int main ()
{
Dune::YaspGrid<2> grid({1.0,1.0}, {1,1});
auto gridView = grid.leafGridView();
using namespace Dune::Functions::BasisFactory;
auto basis = makeBasis(gridView,
composite(
power<2>(lagrange<2>()),
lagrange<1>()
));
auto localView = basis.localView();
auto const& tree = localView.tree();
auto c1 = makeTreeContainer<double>(tree);
auto c2 = makeTreeContainer<decltype(c1)>(tree);
auto c3 = makeTreeContainer(tree, [&](auto const&) { return makeTreeContainer<double>(tree); });
// fill 1d treeContainer with data
for_each_leaf_node(tree, [&](auto const& node, auto tp) {
c1[tp] = double(node.treeIndex());
});
// copy construction
auto c4 = c1;
AMDIS_TEST(c4 == c1);
// fill 2d treeContainer with data
for_each_leaf_node(tree, [&](auto const& row_node, auto row_tp) {
for_each_leaf_node(tree, [&](auto const& col_node, auto col_tp) {
c3[row_tp][col_tp] = double(row_node.treeIndex() + col_node.treeIndex());
});
});
// copy construction
auto c5 = c3;
AMDIS_TEST(c5 == c3);
// copy-assignment of container
c2 = c3;
AMDIS_TEST(c2 == c3);
return report_errors();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment