Skip to content
Snippets Groups Projects
Commit b18ba9cc authored by Max Kahnt's avatar Max Kahnt
Browse files

Add an improved algorithm header

Meant to replace dune/solvers/common/algorithm.hh
parent c0d5f251
No related branches found
No related tags found
1 merge request!3Feature/multitype arithmetic
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_MATRIX_VECTOR_ALGORITHM_HH
#define DUNE_MATRIX_VECTOR_ALGORITHM_HH
#include <type_traits>
#include <dune/common/hybridutilities.hh>
#include <dune/istl/multitypeblockmatrix.hh>
#include <dune/istl/multitypeblockvector.hh>
namespace Dune {
namespace MatrixVector {
template <class C>
struct IsMultiTypeBlockContainer : public std::false_type {};
template <class... Args>
struct IsMultiTypeBlockContainer<MultiTypeBlockMatrix<Args...>>
: public std::true_type {};
template <class... Args>
struct IsMultiTypeBlockContainer<MultiTypeBlockVector<Args...>>
: public std::true_type {};
/**
* \brief Hybrid for loop over sparse range
*/
template <class Range, class F,
typename = std::enable_if_t<IsMultiTypeBlockContainer<Range>::value>>
void rangeForEach(const Range& range, F&& f) {
using namespace Dune::Hybrid;
forEach(integralRange(size(range)), [&](auto&& i) { f(range[i], i); });
}
/**
* \brief Hybrid for loop over sparse range
*/
template<class Range, class F>
void rangeForEach(Range&& range, F&& f)
{
for (auto it = range.begin(); it != range.end(); ++it)
f(*it, it.index());
}
} // namespace MatrixVector
} // namespace Dune
#endif // DUNE_MATRIX_VECTOR_ALGORITHM_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment