-
Notifications
You must be signed in to change notification settings - Fork 105
SNES timestep control changes #3273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
Allows the target to be set to push timestep rather than stall once reaching a set number of iterations.
Calculates a moving average of recent SNES failures. Enables timestep controllers to be more cautious when SNES is repeatedly failing.
Separate out the global timestep control into a function
Now always calculates local and global residuals. If pseudo timestepping is used then another loop over variables is used to update per-cell timesteps and set `dt_vec`. When `diagnose=true`, the local residual will be saved as `snes_local_residual`, and the global residual will be printed after each internal timestep.
Selects the trigger for writing an output. The default is `fixed_time_interval` that outputs at regular time intervals. Other choice is `residual_ratio` that outputs when the global residual falls by a factor `output_residual_ratio`.
Describe new settings `timestep_control` and `output_trigger` that select different strategies to adjust global timesteps and output simulation state.
Save the global residual diagnostic
Uses setting `pid_controller` rather than `pid_nonlinear_its`.
There was a problem hiding this 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; | ||
| recent_failure_rate = 0.0; | ||
|
|
||
| BoutReal start_global_residual = global_residual; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'start_global_residual' of type 'BoutReal' (aka 'double') can be declared 'const' [misc-const-correctness]
| BoutReal start_global_residual = global_residual; | |
| BoutReal const start_global_residual = global_residual; |
| if ((output_trigger == BoutSnesOutput::fixed_time_interval && (simtime >= target)) | ||
| || (output_trigger == BoutSnesOutput::residual_ratio | ||
| && (global_residual <= start_global_residual * output_residual_ratio))) | ||
| break; // Could happen if step over multiple outputs |
There was a problem hiding this comment.
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]
| break; // Could happen if step over multiple outputs | |
| && (global_residual <= start_global_residual * output_residual_ratio))) { | |
| break; // Could happen if step over multiple outputs | |
| } |
| break; | ||
| } | ||
| return timestep; // No change | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "copy" is directly included [misc-include-cleaner]
d
^| } | ||
| return timestep; // No change | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "copy" is directly included [misc-include-cleaner]
;
^| PetscCall(rhs_function(x, snes_f, false)); | ||
|
|
||
| // Reading the residual vectors | ||
| const BoutReal* current_residual = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: pointee of variable 'mesh' of type 'Mesh *' can be declared 'const' [misc-const-correctness]
| const BoutReal* current_residual = nullptr; | |
| n const |
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "mean" is directly included [misc-include-cleaner]
)
^| history_based, ///< Grow/shrink dt based on residual decrease/increase | ||
| hybrid); ///< Combine inverse_residual and history_based strategies | ||
|
|
||
| BOUT_ENUM_CLASS(BoutSnesTimestep, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: enum 'BoutSnesTimestep' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]
BOUT_ENUM_CLASS(BoutSnesTimestep,
^| residual_ratio, ///< Use ratio of previous and current residual | ||
| fixed); ///< Fixed timestep (no adaptation) | ||
|
|
||
| BOUT_ENUM_CLASS(BoutSnesOutput, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: enum 'BoutSnesOutput' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]
BOUT_ENUM_CLASS(BoutSnesOutput,
^
timestep_controlreplacespid_controllerboolean. Choices are:pid_nonlinear_itsthat uses a PID controller and the nonlinear iteration count. This is now the default.residual_ratiothat uses the ratio of the global residual (Root-Mean-Square of the time derivatives, averaged over all fields and cells). The algorithm is taken from PETSc TSPSEUDO: https://petsc.org/release/manualpages/TS/TSPSEUDO/ .threshold_nonlinear_itsis the previous default, that increases and decreases timestep based on thresholds in the number of nonlinear iterationsfixedis for testing; no timestep controloutput_triggerchanges when outputs are written:fixed_time_intervalis the default, outputting at regular time intervals.residual_ratiooutputs when the global residual has reduced below a given factor (output_residual_ratiooption, default 0.5) times the residual at the previous output. This is a useful measure of progress towards steady state.