Skip to content

Commit

Permalink
Fix sign check in FD Jacobian pattern test and adjust tolerances acco…
Browse files Browse the repository at this point in the history
…rdingly

Co-authored-by: Jan Breuer <[email protected]>
  • Loading branch information
ronald-jaepel and jbreue16 committed Jan 16, 2025
1 parent 2040e7b commit e054d22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 3 additions & 2 deletions test/Crystallization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ TEST_CASE("Crystallization Jacobian verification for a DPFR/LRM with primary and
pp_setup.pushScope("model");
pp_setup.pushScope("unit_001");

// for this specific test, we need to define a (high) absolute tolerance as the values in this test are numerically very challenging (values of ca. 1E+24)
// for this specific test, we need to define a (high) tolerances as the values in this test are numerically very challenging (values of ca. 1E+24)
const double ADabsTol = 2e+7;
const double FDabsTol = 5e+7;

cadet::test::column::testJacobianAD(pp_setup, std::numeric_limits<float>::epsilon() * 100.0, ADabsTol);
cadet::test::column::testJacobianAD(pp_setup, FDabsTol, ADabsTol);
}
12 changes: 6 additions & 6 deletions test/GeneralRateModelDG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ TEST_CASE("GRM_DG linear binding single particle matches particle distribution",

TEST_CASE("GRM_DG multiple particle types Jacobian analytic vs AD", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ParticleType],[CI]")
{
cadet::test::particle::testJacobianMixedParticleTypes("GENERAL_RATE_MODEL", "DG");
cadet::test::particle::testJacobianMixedParticleTypes("GENERAL_RATE_MODEL", "DG", 1e-14);
}

TEST_CASE("GRM_DG multiple particle types time derivative Jacobian vs FD", "[GRM],[DG],[DG1D],[UnitOp],[Residual],[Jacobian],[ParticleType],[CI]")
Expand All @@ -285,27 +285,27 @@ TEST_CASE("GRM_DG linear binding single particle matches spatially dependent par

TEST_CASE("GRM_DG dynamic reactions Jacobian vs AD bulk", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ReactionModel],[CI]")
{
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, false, false);
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, false, false, 1e-14);
}

TEST_CASE("GRM_DG dynamic reactions Jacobian vs AD particle", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ReactionModel],[CI]")
{
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", false, true, false);
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", false, true, false, 1e-14);
}

TEST_CASE("GRM_DG dynamic reactions Jacobian vs AD modified particle", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ReactionModel],[CI]")
{
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", false, true, true);
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", false, true, true, 1e-14);
}

TEST_CASE("GRM_DG dynamic reactions Jacobian vs AD bulk and particle", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ReactionModel],[CI]")
{
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, true, false);
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, true, false, 1e-14);
}

TEST_CASE("GRM_DG dynamic reactions Jacobian vs AD bulk and modified particle", "[GRM],[DG],[DG1D],[Jacobian],[AD],[ReactionModel],[CI]")
{
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, true, true);
cadet::test::reaction::testUnitJacobianDynamicReactionsAD("GENERAL_RATE_MODEL", "DG", true, true, true, 1e-14);
}

TEST_CASE("GRM_DG dynamic reactions time derivative Jacobian vs FD bulk", "[GRM],[DG],[DG1D],[Jacobian],[Residual],[ReactionModel],[CI],[FD]")
Expand Down
5 changes: 3 additions & 2 deletions test/JacobianHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ inline void checkJacobianPatternFD(const std::function<void(double const*, doubl
CAPTURE(col);
CAPTURE(colA[row]);
CAPTURE(colB[row]);
if (std::abs(colA[row]) <= absTol)
CHECK(std::abs(colA[row]) <= absTol);

if (std::abs(colA[row]) <= absTol) // allow different signs, if both entries are near zero
CHECK(std::abs(colB[row]) <= absTol);
else if (std::isnan(colA[row]))
CHECK(std::isnan(colB[row]));
else
Expand Down

0 comments on commit e054d22

Please sign in to comment.