diff --git a/dune/solvers/common/algorithm.hh b/dune/solvers/common/algorithm.hh index 65181d8b67f52f72795d750dcc8b2448ec2b7811..ecec1416d531c875c75db839e72f0f6d08d452cb 100644 --- a/dune/solvers/common/algorithm.hh +++ b/dune/solvers/common/algorithm.hh @@ -242,6 +242,33 @@ constexpr auto hybridSize(const T& t) +/** + * \brief Hybrid for loop over sparse range + */ +template<class... T, class F> +void sparseRangeFor(Dune::MultiTypeBlockMatrix<T...>& range, F&& f) +{ + integralRangeFor<std::size_t>(Indices::_0, hybridSize(range), [&](auto&& i) { + f(range[i], i); + }); +} + + + +/** + * \brief Hybrid for loop over sparse range + */ +template<class Range, class F> +void sparseRangeFor(Range&& range, F&& f) +{ + auto it = range.begin(); + auto end = range.end(); + for(; it!=end; ++it) + f(*it, it.index()); +} + + + } // namespace Solvers } // namespace Dune