Skip to content

beuler solver timestep and Jacobian calculation#3107

Merged
bendudson merged 2 commits into
nextfrom
snes-timestep
Jun 21, 2025
Merged

beuler solver timestep and Jacobian calculation#3107
bendudson merged 2 commits into
nextfrom
snes-timestep

Conversation

@bendudson
Copy link
Copy Markdown
Contributor

The Jacobian that SNES uses for preconditioning depends on the timestep, so when the timestep is changed the preconditioner becomes less effective unless it is recalculated.

  • Don't cut the timestep to reach the output time. Instead step over and interpolate
  • Attempt to reduce how often timesteps are adjusted, since recalculating the Jacobian is expensive.

Adding more tuning parameters, will need to optimise for problems of interest.

bendudson added 2 commits May 2, 2025 21:10
The preconditioner depends on the timestep, so avoid changing
timestep unless necessary. Allow timesteps to go past output time,
then interpolate.

If timesteps are adjusted then recalculate the Jacobian. This
could be optimised to update the Jacobian and recalculate the
preconditioner, without finite differencing the RHS.
New tunable inputs for adjustment when timestep fails, and when number
of iterations is either too high or too low.
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

int loop_count = 0;
do {
if (simtime >= target)
break; // Could happen if step over multiple outputs
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.

warning: statement should be inside braces [readability-braces-around-statements]

Suggested change
break; // Could happen if step over multiple outputs
if (simtime >= target) {
break; // Could happen if step over multiple outputs
}


// Note: If simtime = target then alpha = 0
// and output_x = snes_x
BoutReal alpha = (simtime - target) / dt;
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.

warning: variable 'alpha' of type 'BoutReal' (aka 'double') can be declared 'const' [misc-const-correctness]

Suggested change
BoutReal alpha = (simtime - target) / dt;
xconst

@ZedThree
Copy link
Copy Markdown
Member

This looks reasonable to me, but I thought PETSc could do this sort of interpolate automatically? Is it just easier to do this interpolation ourselves?

@bendudson bendudson merged commit 520ba06 into next Jun 21, 2025
26 checks passed
@bendudson bendudson deleted the snes-timestep branch June 21, 2025 04:03
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