Skip to content

Commit

Permalink
To avoid unnecessary checking when using release builds, use `KRATOS_…
Browse files Browse the repository at this point in the history
…DEBUG_ERROR_IF`

The tests that cover these checks are now conditionally built and run, too.
  • Loading branch information
avdg81 committed Sep 10, 2024
1 parent 9dd799f commit 4cea86c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ Vector GeoEquationOfMotionUtilities::CalculateInternalForceVector(const std::vec
const std::vector<Vector>& rStressVectors,
const std::vector<double>& rIntegrationCoefficients)
{
KRATOS_ERROR_IF((rBs.size() != rStressVectors.size()) || (rBs.size() != rIntegrationCoefficients.size()))
KRATOS_DEBUG_ERROR_IF((rBs.size() != rStressVectors.size()) ||
(rBs.size() != rIntegrationCoefficients.size()))
<< "Cannot calculate the internal force vector: input vectors have different sizes\n";
KRATOS_ERROR_IF(rBs.empty())
KRATOS_DEBUG_ERROR_IF(rBs.empty())
<< "Cannot calculate the internal force vector: input vectors are empty\n";
auto has_inconsistent_sizes = [number_of_rows = rBs.front().size1(),
number_of_columns = rBs.front().size2()](const auto& rMatrix) {
return (rMatrix.size1() != number_of_rows) || (rMatrix.size2() != number_of_columns);
};
KRATOS_ERROR_IF(std::any_of(rBs.begin() + 1, rBs.end(), has_inconsistent_sizes))
KRATOS_DEBUG_ERROR_IF(std::any_of(rBs.begin() + 1, rBs.end(), has_inconsistent_sizes))
<< "Cannot calculate the internal force vector: B-matrices have different sizes";

auto result = Vector{ZeroVector{rBs.front().size2()}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ KRATOS_TEST_CASE_IN_SUITE(TheInternalForceVectorIsTheIntegralOfBTransposedTimesS
expected_internal_force_vector, relative_tolerance)
}

// The following tests only raise errors when using debug builds
#ifdef KRATOS_DEBUG

KRATOS_TEST_CASE_IN_SUITE(CalculatingTheInternalForceVectorFailsWhenTheInputVectorsHaveDifferentSizes,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
Expand Down Expand Up @@ -238,4 +241,6 @@ KRATOS_TEST_CASE_IN_SUITE(CalculatingTheInternalForceVectorFailsWhenBMatricesHav
"Cannot calculate the internal force vector: B-matrices have different sizes")
}

#endif

} // namespace Kratos::Testing

0 comments on commit 4cea86c

Please sign in to comment.