How to pass multiple tree-paths
This Discussion is about exploring the design space for tree-paths.
A treepath is an instance of Dune::TypeTree::HybridTreePath<I...>
where I
is either a Std::integral_constant<std::size_t,i>
or an std::size_t
, representing a compile-time index or a run-time index. The following methods exist to pass tree-paths to the function addMatrixOperator(...)
:
For single indices
addMatrixOperator(op, 0, 1); // single run-time index
addMatrixOperator(op, _0, _1); // single compile-time index
addMatrixOperator(op, 0_c, 1_c); // single compile-time index using index constant literal
addMatrixOperator(op, 0_tp, 1_tp); // single compile-time index using tree-path literal
addMatrixOperator(op, makeTreePath(0), makeTreePath(_1)); // single index using the makeTreePath function
For multiple indices
addMatrixOperator(op, makeTreePath(0,_1), makeTreePath(_1,2));
addMatrixOperator(op, std::tuple{0,_1}, std::tuple{_1,2});
addMatrixOperator(op, 01_tp, 12_tp);
Iterating over tree-path indices
for (std::size_t i = 0; i < 10; ++i)
addMatrixOperator(op, makeTreePath(i,_1), makeTreePath(_1,i));
Ranges::forIndices<10>([&](auto _i) {
addMatrixOperator(op, makeTreePath(0,_i), makeTreePath(_i,0));
});
Extensions:
If all indices in the tree-path are run-time indices: use std::initializer_list<T>
or std::array
addMatrixOperator(op, {0,1}, {1,2});
for the iteration, a forEach
method in the static/dynamic range class could be useful:
range(10).forEach([&](auto i) {
addMatrixOperator(op, makeTreePath(i,_1), makeTreePath(_1,i));
});
range(10_c).forEach([&](auto _i) {
addMatrixOperator(op, makeTreePath(0,_i), makeTreePath(_i,0));
});
Is it possible to use a run-time index for a composite tree? Maybe if the TreeContainer recursively provides a FakeContainer
in case someone accesses the the container in a wrong way(?) Not sure whether this would be possible.