Skip to content

Use SNESSetLagJacobianPersists to force recalculating Jacobian#3404

Open
cmacmackin wants to merge 1 commit into
nextfrom
cmacmackin/snes-jacobian-lag
Open

Use SNESSetLagJacobianPersists to force recalculating Jacobian#3404
cmacmackin wants to merge 1 commit into
nextfrom
cmacmackin/snes-jacobian-lag

Conversation

@cmacmackin

Copy link
Copy Markdown
Collaborator

Previously when something happened that would require the Jacobian to be recalculated (instead of lagged), SNESSetLagJacobian() would be used to set the lag to 1 for the next time-step. However, this would turn off lagging altogether for that time-step. What we actually want to do is use SNESSetLagJacobianPersists() so that the Jacobian is recalculated at the start of the time-step and then is lagged as usual. This commit changes to doing that.

Note that, in practice, the lag wasn't actually being forced to 1 in most cases, because previously there was a line that would set it back to the value from the configurations. As far as I can tell this line shouldn't have been there.

Previously when something happened that would require the Jacobian to
be recalculated (instead of lagged), SNESSetLagJacobian() would be
used to set the lag to 1 for the next time-step. However, this would
turn off lagging altogether for that time-step. What we actually want
to do is use SNESSetLagJacobianPersists() so that the Jacobian is
recalculated at the start of the time-step and then is lagged as
usual. This commit changes to doing that.

Note that, in practice, the lag wasn't actually being forced to 1 in
most cases, because previously there was a line that would set it
back to the value from the configurations. As far as I can tell this
line shouldn't have been there.
@cmacmackin cmacmackin requested review from ZedThree and bendudson June 23, 2026 14:58
continue; // Try again
}

if (saved_jacobian_lag != 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should restore the previous Jacobian lag on successful SNES convergence. I think this should restore the JacobianPersists setting to its input option. It looks like rescale() will set JacobianPersists to False, but where would it be restored to True (if that's what was in the settings)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If rescale determines that JacobianPersists should be false then that applies for the current time-step and it will be reset on the next one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the reset happen? This point (around line 1165) is where the Jacobian lag was being reset: Execution reaches this point only after a successful SNES convergence. If this is removed then I don't see where JacobianPersists is reset.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sequence is:

  1. Start the iteration
  2. If not persist_jac_lag_off, reset SNESSetLagJacobianPersists. Otherwise leave SNESSetLagJacobianPersists to whatever it was set to in the last iteration and set persist_jac_lag_off to false.
  3. Rescale, if necessary. If a rescale is performed, set SNESSetLagJacobianPersists to false, but don't change persist_jac_lag_off.
  4. Try to perform the timestep. If something happens that will require the length of the timestep to be changed for the next iteration, set SNESSetLagJacobianPersists to false and persist_jac_lag_off to true.
  5. Repeat.

So, to answer your questions, the value of JacobianPersists is reset to the input value at step 2, or line 998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants