Skip to content

Commit abd8fa0

Browse files
committed
FIX: Call SNESTestJacobian() with residual norms as args.
1 parent b1383c8 commit abd8fa0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tests/src/MMSTest.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,20 @@ pylith::testing::MMSTest::testJacobianFiniteDiff(void) {
187187
if (debug.state()) {
188188
err = PetscOptionsSetValue(NULL, "-snes_test_jacobian_view", "");PYLITH_CHECK_ERROR(err);
189189
} // if
190-
err = PetscOptionsSetValue(NULL, "-snes_test_jacobian", "1.0e-6");PYLITH_CHECK_ERROR(err);
191190
err = PetscOptionsSetValue(NULL, "-snes_error_if_not_converged", "false");PYLITH_CHECK_ERROR(err);
192191
err = SNESSetFromOptions(_problem->getPetscSNES());PYLITH_CHECK_ERROR(err);
193192

194-
_problem->solve();
195-
INFO("IMPORTANT: You must check the Jacobian values printed here manually!\n"
196-
<< " They should be O(1.0e-6) or smaller.\n");
197-
err = PetscOptionsClearValue(NULL, "-snes_test_jacobian");PYLITH_CHECK_ERROR(err);
193+
PetscReal jacobianNorm = 1.0e+20, diffNorm = 1.0e+20;
194+
err = TSSetUp(_problem->getPetscTS());PYLITH_CHECK_ERROR(err);
195+
PetscMat jacobian = PETSC_NULLPTR, jacobianPreconditioner = PETSC_NULLPTR;
196+
err = TSGetIJacobian(_problem->getPetscTS(), &jacobian, &jacobianPreconditioner, NULL, NULL);PYLITH_CHECK_ERROR(err);
197+
err = SNESComputeJacobian(_problem->getPetscSNES(), _solutionExactVec, jacobian, jacobianPreconditioner);PYLITH_CHECK_ERROR(err);
198+
err = SNESTestJacobian(_problem->getPetscSNES(), &jacobianNorm, &diffNorm);PYLITH_CHECK_ERROR(err);
199+
200+
INFO("jacobianNorm=" << jacobianNorm << ", ||Code Jacobian - Finite Diff Jacobain||="<<diffNorm);
201+
const PetscReal jacobianTolerance = 100 * _tolerance * jacobianNorm;
202+
REQUIRE_THAT(jacobianNorm, !Catch::Matchers::WithinAbs(0.0, _tolerance));
203+
REQUIRE_THAT(diffNorm, Catch::Matchers::WithinAbs(0.0, jacobianTolerance));
198204
err = PetscOptionsClearValue(NULL, "-snes_test_jacobian_view");PYLITH_CHECK_ERROR(err);
199205

200206
PYLITH_METHOD_END;

0 commit comments

Comments
 (0)