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.

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