Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible error in jacobian tests #358

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading