Skip to content

Commit e054d22

Browse files
Fix sign check in FD Jacobian pattern test and adjust tolerances accordingly
Co-authored-by: Jan Breuer <[email protected]>
1 parent 2040e7b commit e054d22

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

test/Crystallization.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ TEST_CASE("Crystallization Jacobian verification for a DPFR/LRM with primary and
166166
pp_setup.pushScope("model");
167167
pp_setup.pushScope("unit_001");
168168

169-
// 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)
169+
// 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)
170170
const double ADabsTol = 2e+7;
171+
const double FDabsTol = 5e+7;
171172

172-
cadet::test::column::testJacobianAD(pp_setup, std::numeric_limits<float>::epsilon() * 100.0, ADabsTol);
173+
cadet::test::column::testJacobianAD(pp_setup, FDabsTol, ADabsTol);
173174
}

test/GeneralRateModelDG.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ TEST_CASE("GRM_DG linear binding single particle matches particle distribution",
265265

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

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

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

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

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

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

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

311311
TEST_CASE("GRM_DG dynamic reactions time derivative Jacobian vs FD bulk", "[GRM],[DG],[DG1D],[Jacobian],[Residual],[ReactionModel],[CI],[FD]")

test/JacobianHelper.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,9 @@ inline void checkJacobianPatternFD(const std::function<void(double const*, doubl
409409
CAPTURE(col);
410410
CAPTURE(colA[row]);
411411
CAPTURE(colB[row]);
412-
if (std::abs(colA[row]) <= absTol)
413-
CHECK(std::abs(colA[row]) <= absTol);
412+
413+
if (std::abs(colA[row]) <= absTol) // allow different signs, if both entries are near zero
414+
CHECK(std::abs(colB[row]) <= absTol);
414415
else if (std::isnan(colA[row]))
415416
CHECK(std::isnan(colB[row]));
416417
else

0 commit comments

Comments
 (0)