Commit 9861405e authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Merge branch 'use-if-constexpr' into 'master'

Port bcqfconstrainedlinearization.hh to 'if constexpr'

See merge request !15
parents d13a9cbb 98810ea1
Pipeline #28821 passed with stage
in 5 minutes and 18 seconds
...@@ -3,6 +3,13 @@ before_script: ...@@ -3,6 +3,13 @@ before_script:
- duneci-install-module https://git.imp.fu-berlin.de/agnumpde/dune-matrix-vector.git - duneci-install-module https://git.imp.fu-berlin.de/agnumpde/dune-matrix-vector.git
- duneci-install-module https://git.imp.fu-berlin.de/agnumpde/dune-solvers.git - duneci-install-module https://git.imp.fu-berlin.de/agnumpde/dune-solvers.git
.common: &common
script: duneci-standard-test
artifacts:
expire_in: 2 years
reports:
junit: junit/*.xml
dune:git clang C++17: dune:git clang C++17:
image: registry.dune-project.org/docker/ci/dune:git-debian-10-clang-7-libcpp-17 image: registry.dune-project.org/docker/ci/dune:git-debian-10-clang-7-libcpp-17
script: duneci-standard-test script: duneci-standard-test
...@@ -10,7 +17,3 @@ dune:git clang C++17: ...@@ -10,7 +17,3 @@ dune:git clang C++17:
dune:git gcc-8 C++17: dune:git gcc-8 C++17:
image: registry.dune-project.org/docker/ci/dune:git-debian-10-gcc-8-17 image: registry.dune-project.org/docker/ci/dune:git-debian-10-gcc-8-17
script: duneci-standard-test script: duneci-standard-test
dune:git gcc-6 C++14:
image: registry.dune-project.org/docker/ci/dune:git-debian-9-gcc-6-14
script: duneci-standard-test
...@@ -30,28 +30,34 @@ class BoxConstrainedQuadraticFunctionalConstrainedLinearization ...@@ -30,28 +30,34 @@ class BoxConstrainedQuadraticFunctionalConstrainedLinearization
static void determineTruncation(const NV& x, const NV& lower, const NV& upper, NBV&& truncationFlags, const T& truncationTolerance) static void determineTruncation(const NV& x, const NV& lower, const NV& upper, NBV&& truncationFlags, const T& truncationTolerance)
{ {
namespace H = Dune::Hybrid; namespace H = Dune::Hybrid;
H::ifElse(IsNumber<NV>(), [&](auto id){ if constexpr (IsNumber<NV>())
if ((id(x) <= id(lower)+truncationTolerance) || (id(x) >= id(upper) - truncationTolerance)) {
id(truncationFlags) = true; if ((x <= lower+truncationTolerance) || (x >= upper - truncationTolerance))
}, [&](auto id){ truncationFlags = true;
H::forEach(H::integralRange(H::size(id(x))), [&](auto&& i) { }
else
{
H::forEach(H::integralRange(H::size(x)), [&](auto&& i) {
This::determineTruncation(x[i], lower[i], upper[i], truncationFlags[i], truncationTolerance); This::determineTruncation(x[i], lower[i], upper[i], truncationFlags[i], truncationTolerance);
}); });
}); }
} }
template<class NV, class NBV> template<class NV, class NBV>
static void truncateVector(NV& x, const NBV& truncationFlags) static void truncateVector(NV& x, const NBV& truncationFlags)
{ {
namespace H = Dune::Hybrid; namespace H = Dune::Hybrid;
H::ifElse(IsNumber<NV>(), [&](auto id){ if constexpr (IsNumber<NV>())
if (id(truncationFlags)) {
id(x) = 0; if (truncationFlags)
}, [&](auto id){ x = 0;
H::forEach(H::integralRange(H::size(id(x))), [&](auto&& i) { }
else
{
H::forEach(H::integralRange(H::size(x)), [&](auto&& i) {
This::truncateVector(x[i], truncationFlags[i]); This::truncateVector(x[i], truncationFlags[i]);
}); });
}); }
} }
template<class NM, class RBV, class CBV> template<class NM, class RBV, class CBV>
...@@ -59,17 +65,20 @@ class BoxConstrainedQuadraticFunctionalConstrainedLinearization ...@@ -59,17 +65,20 @@ class BoxConstrainedQuadraticFunctionalConstrainedLinearization
{ {
namespace H = Dune::Hybrid; namespace H = Dune::Hybrid;
using namespace Dune::MatrixVector; using namespace Dune::MatrixVector;
H::ifElse(IsNumber<NM>(), [&](auto id){ if constexpr (IsNumber<NM>())
if(id(rowTruncationFlags) or id(colTruncationFlags)) {
if (rowTruncationFlags or colTruncationFlags)
A = 0; A = 0;
}, [&](auto id){ }
H::forEach(H::integralRange(H::size(id(rowTruncationFlags))), [&](auto&& i) { else
{
H::forEach(H::integralRange(H::size(rowTruncationFlags)), [&](auto&& i) {
auto&& Ai = A[i]; auto&& Ai = A[i];
sparseRangeFor(Ai, [&](auto&& Aij, auto&& j) { sparseRangeFor(Ai, [&](auto&& Aij, auto&& j) {
This::truncateMatrix(Aij, rowTruncationFlags[i], colTruncationFlags[j]); This::truncateMatrix(Aij, rowTruncationFlags[i], colTruncationFlags[j]);
}); });
}); });
}); }
} }
public: public:
......
Supports Markdown
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