Commit 22a7b8d1 authored by Lasse Hinrichsen's avatar Lasse Hinrichsen
Browse files

Convert truncateVector/-Matrix into free functions

This way, they can more easily be used in other contexts.
parent 9861405e
Pipeline #30313 passed with stage
in 7 minutes and 10 seconds
add_subdirectory("common")
add_subdirectory("functionals")
add_subdirectory("iterationsteps")
add_subdirectory("linearsolvers")
......
install(FILES
truncation.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/tnnmg/common)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_TNNMG_COMMON_TRUNCATION_HH
#define DUNE_TNNMG_COMMON_TRUNCATION_HH
#include <dune/common/hybridutilities.hh>
#include <dune/common/typetraits.hh>
#include <dune/matrix-vector/algorithm.hh>
namespace Dune::TNNMG {
/** \brief Truncate vector wrt. given flags.
*
* This calls itself recursively until a scalar entry is found.
* Then, if the corresponding flag is "true", the entry will
* be set to zero. Thus, this should work for general blocking
* schemes.
*/
template<class NV, class NBV>
void truncateVector(NV& x, const NBV& truncationFlags)
{
namespace H = Dune::Hybrid;
if constexpr (IsNumber<NV>())
{
if (truncationFlags)
x = 0;
}
else
{
H::forEach(H::integralRange(H::size(x)), [&](auto&& i) {
truncateVector(x[i], truncationFlags[i]);
});
}
}
/** \brief Truncate matrix wrt. given flags.
*
* This calls itself recursively until a scalar entry is found.
* Then, if the corresponding row OR column flag is "true", the entry will
* be set to zero. Thus, this should work for general blocking
* schemes.
*/
template<class NM, class RBV, class CBV>
void truncateMatrix(NM& A, const RBV& rowTruncationFlags, const CBV& colTruncationFlags)
{
namespace H = Dune::Hybrid;
using namespace Dune::MatrixVector;
if constexpr (IsNumber<NM>())
{
if (rowTruncationFlags or colTruncationFlags)
A = 0;
}
else
{
H::forEach(H::integralRange(H::size(rowTruncationFlags)), [&](auto&& i) {
auto&& Ai = A[i];
sparseRangeFor(Ai, [&](auto&& Aij, auto&& j) {
truncateMatrix(Aij, rowTruncationFlags[i], colTruncationFlags[j]);
});
});
}
}
} // end namespace Dune::TNNMG
#endif
......@@ -10,6 +10,7 @@
#include <dune/common/hybridutilities.hh>
#include <dune/matrix-vector/algorithm.hh>
#include <dune/tnnmg/common/truncation.hh>
......@@ -43,43 +44,6 @@ class BoxConstrainedQuadraticFunctionalConstrainedLinearization
}
}
template<class NV, class NBV>
static void truncateVector(NV& x, const NBV& truncationFlags)
{
namespace H = Dune::Hybrid;
if constexpr (IsNumber<NV>())
{
if (truncationFlags)
x = 0;
}
else
{
H::forEach(H::integralRange(H::size(x)), [&](auto&& i) {
This::truncateVector(x[i], truncationFlags[i]);
});
}
}
template<class NM, class RBV, class CBV>
static void truncateMatrix(NM& A, const RBV& rowTruncationFlags, const CBV& colTruncationFlags)
{
namespace H = Dune::Hybrid;
using namespace Dune::MatrixVector;
if constexpr (IsNumber<NM>())
{
if (rowTruncationFlags or colTruncationFlags)
A = 0;
}
else
{
H::forEach(H::integralRange(H::size(rowTruncationFlags)), [&](auto&& i) {
auto&& Ai = A[i];
sparseRangeFor(Ai, [&](auto&& Aij, auto&& j) {
This::truncateMatrix(Aij, rowTruncationFlags[i], colTruncationFlags[j]);
});
});
}
}
public:
using Matrix = typename F::Matrix;
......
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