PetscJacobianTester

The PetscJacobianTester tester uses the -snes_test_jacobian command line option in PETSc to evaluate the quality of the Jacobian in the specified tests.

Options

Test configuration options are specified in the tests file.

  • ratio_tol: Relative tolerance to compare the ration against, defaults to 1e-8

  • difference_tol: Relative tolerance to compare the difference against, defaults to 1e-8

  • state: The state for which we want to compare against the finite-differenced Jacobian ('user' (default) 'const_positive' or 'const_negative'.)

  • run_sim: Whether to actually run the simulation, testing the Jacobian at every non-linear iteration of every time step. This is only relevant for petsc versions >= 3.9. Defaults to False.

  • turn_off_exodus_output: Whether to set exodus=false in Outputs. Defaults to True

  • only_final_jacobian: Check only final Jacobian comparison. Defaults to False

Other test commands & restrictions may be found in the TestHarness documentation.

Example test configuration in the MOOSE test suite

In this example, four PetscJacobianTester and two Exodiff tests are used to check the proper behavior of automatic differentiation in boundary conditions. The Jacobian tests make sure the contribution to the Jacobian of the boundary conditions is correct.

[Tests]
  issues = '#5658'
  [test]
    type = 'Exodiff'
    input = 'ad_bc.i'
    exodiff = 'ad_bc_out.e'
    requirement = 'We shall be able to produce the expected result using ADKernel, ADNodalBC, and '
                  'ADIntegratedBC'
    design = 'ADFunctionDirichletBC.md ADDiffusion.md'
  []
  [jac]
    type = 'PetscJacobianTester'
    input = 'ad_bc.i'
    cli_args = 'Outputs/exodus=false Mesh/nx=3 Mesh/ny=3'
    run_sim = True
    ratio_tol = 1e-7
    difference_tol = 1e-6
    requirement = 'We shall be able to produce the exact Jacobian using ADKernel, ADNodalBC, and '
                  'ADIntegratedBC with a first order variable'
    design = 'ADFunctionDirichletBC.md ADDiffusion.md'
  []
  [2nd_order_jac]
    type = 'PetscJacobianTester'
    input = 'ad_bc.i'
    cli_args = 'Outputs/exodus=false Mesh/nx=2 Mesh/ny=2 Mesh/elem_type=QUAD9 '
               'Variables/u/order=SECOND'
    run_sim = True
    ratio_tol = 1e-7
    difference_tol = 1e-6
    requirement = 'We shall be able to produce the exact Jacobian using ADKernel, ADNodalBC, and '
                  'ADIntegratedBC with a second order variable'
    design = 'ADFunctionDirichletBC.md ADDiffusion.md'
  []
  [vector_test]
    type = 'Exodiff'
    input = 'vector_ad_bc.i'
    exodiff = 'vector_ad_bc_out.e'
    requirement = 'We shall be able to produce the expected result using ADVectorKernel, '
                  'ADVectorNodalBC, and ADVectorIntegratedBC'
    design = 'ADVectorFunctionDirichletBC.md ADVectorDiffusion.md'
  []
  [vector_jac]
    type = 'PetscJacobianTester'
    input = 'vector_ad_bc.i'
    cli_args = 'Outputs/exodus=false Mesh/nx=3 Mesh/ny=3'
    run_sim = True
    ratio_tol = 1e-7
    difference_tol = 1e-6
    requirement = 'We shall be able to produce the exact Jacobian using ADVectorKernel, '
                  'ADVectorNodalBC, and ADVectorIntegratedBC with a first order variable'
    design = 'ADVectorFunctionDirichletBC.md ADVectorDiffusion.md'
  []
  [2nd_order_vector_jac]
    type = 'PetscJacobianTester'
    input = 'vector_ad_bc.i'
    cli_args = 'Outputs/exodus=false Mesh/nx=2 Mesh/ny=2 Mesh/elem_type=QUAD9 '
               'Variables/u/order=SECOND'
    run_sim = True
    ratio_tol = 1e-7
    difference_tol = 1e-6
    requirement = 'We shall be able to produce the exact Jacobian using ADVectorKernel, '
                  'ADVectorNodalBC, and ADVectorIntegratedBC with a second order variable'
    design = 'ADVectorFunctionDirichletBC.md ADVectorDiffusion.md'
  []
[]
(contrib/moose/test/tests/bcs/ad_bcs/tests)