From f0ae87e1da27cd69bb2bb82319eda2c717783515 Mon Sep 17 00:00:00 2001 From: "Joshua E. Hansel" Date: Thu, 29 Jun 2023 17:39:38 -0500 Subject: [PATCH 1/3] Added extrapolation option to TimeSequenceStepperBase Closes #24868 --- .../timesteppers/CSVTimeSequenceStepper.md | 9 ++--- .../timesteppers/ExodusTimeSequenceStepper.md | 5 ++- .../timesteppers/TimeSequenceStepper.md | 10 ++---- .../timesteppers/TimeSequenceStepperBase.md | 34 +++++++++++++++++++ .../timesteppers/TimeSequenceStepperBase.h | 3 ++ .../timesteppers/TimeSequenceStepperBase.C | 20 ++++++++++- .../doc/content/newsletter/2023/2023_06.md | 9 +++++ .../gold/timesequence_last_dt_out.csv | 8 +++++ .../time_steppers/timesequence_stepper/tests | 10 +++++- .../timesequence_last_dt.i | 28 +++++++++++++++ 10 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md create mode 100644 test/tests/time_steppers/timesequence_stepper/gold/timesequence_last_dt_out.csv create mode 100644 test/tests/time_steppers/timesequence_stepper/timesequence_last_dt.i diff --git a/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md b/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md index c38ad22efd8d..092e8b2e8eb3 100644 --- a/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md @@ -1,7 +1,8 @@ # CSVTimeSequenceStepper -Imports a time sequence from a CSV file, or similar delimited text files. -The CSVTimeSequenceStepper uses a [DelimitedFileReader](MooseUtils.md#delimitedfilereader) +This time stepper derives from [TimeSequenceStepperBase.md] and provides the +sequence of time values from a CSV file or similarly delimited text file. +A [DelimitedFileReader](MooseUtils.md#delimitedfilereader) is used to read the CSV file. The file is always read in columns. The column can either be accessed by name @@ -9,10 +10,6 @@ The file is always read in columns. The column can either be accessed by name containing the names of the different columns) or by index (using the "column_index" parameter, with 0 the index of the first column). -If the solve fails to converge during a time step, the behavior of the -`CSVTimeSequenceStepper` is the same as the [TimeSequenceStepper.md]. The -time step will be cut then the time stepper will attempt to return to the original sequence. - !syntax parameters /Executioner/TimeSteppers/CSVTimeSequenceStepper !syntax inputs /Executioner/TimeSteppers/CSVTimeSequenceStepper diff --git a/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md b/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md index d9d39667ac91..e7a71ff87893 100644 --- a/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md @@ -1,11 +1,10 @@ # ExodusTimeSequenceStepper -!syntax description /Executioner/TimeSteppers/ExodusTimeSequenceStepper +This time stepper derives from [TimeSequenceStepperBase.md] and provides the +sequence of time values from an Exodus file. The Exodus file is read by the first process (rank 0), and the time step sequence is then broadcast to all other processes. -If the solve fails to converge during a time step, the behavior of the `ExodusTimeSequenceStepper` is the same as the [TimeSequenceStepper.md]. The time step will be cut then the time stepper will attempt to return to the original sequence. - ## Example input file In this example, the time stepper extracts the time sequence from an exodus output file. This exodus file may not necessarily have been generated using the same input file. The starting and end time of the simulation may still be set independently. diff --git a/framework/doc/content/source/timesteppers/TimeSequenceStepper.md b/framework/doc/content/source/timesteppers/TimeSequenceStepper.md index 75b9841ee4b1..994dca2b92a5 100644 --- a/framework/doc/content/source/timesteppers/TimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/TimeSequenceStepper.md @@ -1,12 +1,8 @@ # TimeSequenceStepper -!syntax description /Executioner/TimeSteppers/TimeSequenceStepper - -If the solver fails to obtain a converged solution for a given -step, the executioner cuts back the step size and attempts to advance the time -from the previous step using a smaller time step. The time step is cut back by -multiplying the time step by the cutback factor, defaulting to 0.5. If this is successful, -the time stepper will then attempt to use the next time in the sequence, adjusting the time step to "get back on track". +This time stepper derives from [TimeSequenceStepperBase.md] and provides the +sequence of time values from a user-specified list, given by +[!param](/Executioner/TimeSteppers/TimeSequenceStepper/time_sequence). ## Example input syntax diff --git a/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md b/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md new file mode 100644 index 000000000000..13a6404f44e7 --- /dev/null +++ b/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md @@ -0,0 +1,34 @@ +# TimeSequenceStepperBase + +`TimeSequenceStepperBase` is a base class for time steppers that use a sequence +time values $t_i$ to produce time step sizes. + +## Choosing the time step size past the final time value + +Suppose that $t_N$ is the maximum time value provided in the sequence. This value +may be less than the simulation end time $t_\text{end}$ given by the +[!param](/Executioner/Transient/end_time) parameter. If this is true and the current simulation +time $t$ is past $t_N$, then by default, there will be a single, final time step +that jumps to the end time: + +!equation +\Delta t = t_\text{end} - t_N \,. + +However, in many cases this is undesirable, such as when a steady state condition +is used to terminate a transient, in which case an arbitrarily large end time +is specified, leading to a very large time step size. This behavior can be +altered with [!param](/Executioner/TimeSteppers/TimeSequenceStepper/use_last_dt_after_last_t). +If set to `true`, this uses the final time step size in the sequence instead +for all time past $t_N$: + +!equation +\Delta t = t_N - t_{N-1} \,. + +## Failed solves + +If the solver fails to obtain a converged solution for a given +step, the executioner cuts back the step size and attempts to advance the time +from the previous step using a smaller time step. The time step is cut back by +multiplying the time step by the cutback factor, defaulting to 0.5. If this is successful, +the time stepper will then attempt to use the next time in the sequence, +adjusting the time step to "get back on track". diff --git a/framework/include/timesteppers/TimeSequenceStepperBase.h b/framework/include/timesteppers/TimeSequenceStepperBase.h index ed38a8c2e882..e2be130bb00d 100644 --- a/framework/include/timesteppers/TimeSequenceStepperBase.h +++ b/framework/include/timesteppers/TimeSequenceStepperBase.h @@ -38,6 +38,9 @@ class TimeSequenceStepperBase : public TimeStepper virtual Real computeDT() override; virtual Real computeFailedDT() override; + /// Whether to use the final dt past the last t in sequence + const bool _use_last_dt_after_last_t; + /// the step that the time stepper is currently at unsigned int & _current_step; diff --git a/framework/src/timesteppers/TimeSequenceStepperBase.C b/framework/src/timesteppers/TimeSequenceStepperBase.C index 21c89c9aef29..98a654ae0bf5 100644 --- a/framework/src/timesteppers/TimeSequenceStepperBase.C +++ b/framework/src/timesteppers/TimeSequenceStepperBase.C @@ -18,11 +18,17 @@ InputParameters TimeSequenceStepperBase::validParams() { InputParameters params = TimeStepper::validParams(); + params.addParam( + "use_last_dt_after_last_t", + false, + "If true, uses the final time step size for times after the last time in the sequence, " + "instead of taking a single step directly to the simulation end time"); return params; } TimeSequenceStepperBase::TimeSequenceStepperBase(const InputParameters & parameters) : TimeStepper(parameters), + _use_last_dt_after_last_t(getParam("use_last_dt_after_last_t")), _current_step(declareRestartableData("current_step", 0)), _time_sequence(declareRestartableData>("time_sequence")) { @@ -129,7 +135,19 @@ TimeSequenceStepperBase::computeInitialDT() Real TimeSequenceStepperBase::computeDT() { - return _time_sequence[_current_step + 1] - _time_sequence[_current_step]; + const auto standard_dt = _time_sequence[_current_step + 1] - _time_sequence[_current_step]; + + if (_use_last_dt_after_last_t) + { + // last *provided* time value index; actual last index corresponds to end time + const auto last_t_index = _time_sequence.size() - 2; + if (_current_step + 1 > last_t_index) + return _time_sequence[last_t_index] - _time_sequence[last_t_index - 1]; + else + return standard_dt; + } + else + return standard_dt; } Real diff --git a/modules/doc/content/newsletter/2023/2023_06.md b/modules/doc/content/newsletter/2023/2023_06.md index a9a192345e18..0d27caf57b6f 100644 --- a/modules/doc/content/newsletter/2023/2023_06.md +++ b/modules/doc/content/newsletter/2023/2023_06.md @@ -93,3 +93,12 @@ TIMPI changes: ## PETSc-level Changes ## Bug Fixes and Minor Enhancements + +### New option for time-stepping past the last time in time sequence steppers + +The various time sequence steppers ([TimeSequenceStepper.md], [CSVTimeSequenceStepper.md], +and [ExodusTimeSequenceStepper.md]) compute time step size from a sequence of +time values. Past the final time value, they previously could only make a single +time step directly to the simulation end time. Now an option +`use_last_dt_after_last_t` has been added, which when true, will instead use +the final time step size in the provided sequence past the last time in the sequence. diff --git a/test/tests/time_steppers/timesequence_stepper/gold/timesequence_last_dt_out.csv b/test/tests/time_steppers/timesequence_stepper/gold/timesequence_last_dt_out.csv new file mode 100644 index 000000000000..85bdb73daa64 --- /dev/null +++ b/test/tests/time_steppers/timesequence_stepper/gold/timesequence_last_dt_out.csv @@ -0,0 +1,8 @@ +time,dt +0,0 +1,1 +3,2 +4,1 +8,4 +12,4 +16,4 diff --git a/test/tests/time_steppers/timesequence_stepper/tests b/test/tests/time_steppers/timesequence_stepper/tests index 57d57dff7d1e..f0b1bdb7f177 100644 --- a/test/tests/time_steppers/timesequence_stepper/tests +++ b/test/tests/time_steppers/timesequence_stepper/tests @@ -1,5 +1,5 @@ [Tests] - issues = '#9698 #6353 #6795' + issues = '#9698 #6353 #6795 #24868' design = 'TimeSequenceStepper.md' [time_sequence] @@ -65,6 +65,14 @@ detail = 'when reading the sequence from a comma-separated input file.' [] + + [use_last_dt] + type = CSVDiff + input = 'timesequence_last_dt.i' + csvdiff = 'timesequence_last_dt_out.csv' + + detail = 'allowing the last time step size to be used past the final time in the sequence.' + [] [] [timesequence_failed] diff --git a/test/tests/time_steppers/timesequence_stepper/timesequence_last_dt.i b/test/tests/time_steppers/timesequence_stepper/timesequence_last_dt.i new file mode 100644 index 000000000000..734f31f22700 --- /dev/null +++ b/test/tests/time_steppers/timesequence_stepper/timesequence_last_dt.i @@ -0,0 +1,28 @@ +[Mesh] + type = GeneratedMesh + dim = 1 +[] + +[Problem] + solve = false +[] + +[Executioner] + type = Transient + num_steps = 6 + [TimeStepper] + type = TimeSequenceStepper + time_sequence = '0 1 3 4 8' + use_last_dt_after_last_t = true + [] +[] + +[Postprocessors] + [dt] + type = TimestepSize + [] +[] + +[Outputs] + csv = true +[] From 4d2733596e413254ddf20e41553d10b131ed5948 Mon Sep 17 00:00:00 2001 From: "Joshua E. Hansel" Date: Mon, 3 Jul 2023 12:29:43 -0500 Subject: [PATCH 2/3] Addressed reviewer comments Refs #24868 --- .../timesteppers/CSVTimeSequenceStepper.md | 3 +++ .../timesteppers/TimeSequenceStepperBase.md | 18 +++++++-------- .../doc/content/newsletter/2023/2023_06.md | 9 -------- .../doc/content/newsletter/2023/2023_07.md | 23 +++++++++++++++++++ .../time_steppers/timesequence_stepper/tests | 2 +- 5 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 modules/doc/content/newsletter/2023/2023_07.md diff --git a/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md b/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md index 092e8b2e8eb3..487f918a56a4 100644 --- a/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/CSVTimeSequenceStepper.md @@ -10,6 +10,9 @@ The file is always read in columns. The column can either be accessed by name containing the names of the different columns) or by index (using the "column_index" parameter, with 0 the index of the first column). +See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior +of this time stepper for failed time steps. + !syntax parameters /Executioner/TimeSteppers/CSVTimeSequenceStepper !syntax inputs /Executioner/TimeSteppers/CSVTimeSequenceStepper diff --git a/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md b/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md index 13a6404f44e7..89b898764982 100644 --- a/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md +++ b/framework/doc/content/source/timesteppers/TimeSequenceStepperBase.md @@ -3,6 +3,15 @@ `TimeSequenceStepperBase` is a base class for time steppers that use a sequence time values $t_i$ to produce time step sizes. +## Failed solves id=failed_solves + +If the solver fails to obtain a converged solution for a given +step, the executioner cuts back the step size and attempts to advance the time +from the previous step using a smaller time step. The time step is cut back by +multiplying the time step by the cutback factor, defaulting to 0.5. If this is successful, +the time stepper will then attempt to use the next time in the sequence, +adjusting the time step to "get back on track". + ## Choosing the time step size past the final time value Suppose that $t_N$ is the maximum time value provided in the sequence. This value @@ -23,12 +32,3 @@ for all time past $t_N$: !equation \Delta t = t_N - t_{N-1} \,. - -## Failed solves - -If the solver fails to obtain a converged solution for a given -step, the executioner cuts back the step size and attempts to advance the time -from the previous step using a smaller time step. The time step is cut back by -multiplying the time step by the cutback factor, defaulting to 0.5. If this is successful, -the time stepper will then attempt to use the next time in the sequence, -adjusting the time step to "get back on track". diff --git a/modules/doc/content/newsletter/2023/2023_06.md b/modules/doc/content/newsletter/2023/2023_06.md index 0d27caf57b6f..a9a192345e18 100644 --- a/modules/doc/content/newsletter/2023/2023_06.md +++ b/modules/doc/content/newsletter/2023/2023_06.md @@ -93,12 +93,3 @@ TIMPI changes: ## PETSc-level Changes ## Bug Fixes and Minor Enhancements - -### New option for time-stepping past the last time in time sequence steppers - -The various time sequence steppers ([TimeSequenceStepper.md], [CSVTimeSequenceStepper.md], -and [ExodusTimeSequenceStepper.md]) compute time step size from a sequence of -time values. Past the final time value, they previously could only make a single -time step directly to the simulation end time. Now an option -`use_last_dt_after_last_t` has been added, which when true, will instead use -the final time step size in the provided sequence past the last time in the sequence. diff --git a/modules/doc/content/newsletter/2023/2023_07.md b/modules/doc/content/newsletter/2023/2023_07.md new file mode 100644 index 000000000000..4d1f39db9c30 --- /dev/null +++ b/modules/doc/content/newsletter/2023/2023_07.md @@ -0,0 +1,23 @@ +# MOOSE Newsletter (July 2023) + +!alert! construction title=In Progress +This MOOSE Newsletter edition is in progress. Please check back in August 2023 +for a complete description of all MOOSE changes. +!alert-end! + +## MOOSE Improvements + +## libMesh-level Changes + +## PETSc-level Changes + +## Bug Fixes and Minor Enhancements + +### New option for time-stepping past the last time in time sequence steppers + +The various time sequence steppers ([TimeSequenceStepper.md], [CSVTimeSequenceStepper.md], +and [ExodusTimeSequenceStepper.md]) compute time step size from a sequence of +time values. Past the final time value, they previously could only make a single +time step directly to the simulation end time. Now an option +`use_last_dt_after_last_t` has been added, which when true, will instead use +the final time step size in the provided sequence past the last time in the sequence. diff --git a/test/tests/time_steppers/timesequence_stepper/tests b/test/tests/time_steppers/timesequence_stepper/tests index f0b1bdb7f177..a911c500d4c1 100644 --- a/test/tests/time_steppers/timesequence_stepper/tests +++ b/test/tests/time_steppers/timesequence_stepper/tests @@ -63,7 +63,7 @@ input = 'csvtimesequence.i' exodiff = 'csvtimesequence_out.e' - detail = 'when reading the sequence from a comma-separated input file.' + detail = 'when reading the sequence from a comma-separated input file, and' [] [use_last_dt] From e81a9af4251fa2225acd8f2390eb5e3b8b1d794d Mon Sep 17 00:00:00 2001 From: "Joshua E. Hansel" Date: Wed, 5 Jul 2023 08:41:18 -0500 Subject: [PATCH 3/3] Addressed reviewer comments Refs #24868 --- .../content/source/timesteppers/ExodusTimeSequenceStepper.md | 3 +++ .../doc/content/source/timesteppers/TimeSequenceStepper.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md b/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md index e7a71ff87893..50c2ce6dc5b5 100644 --- a/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/ExodusTimeSequenceStepper.md @@ -5,6 +5,9 @@ sequence of time values from an Exodus file. The Exodus file is read by the first process (rank 0), and the time step sequence is then broadcast to all other processes. +See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior +of this time stepper for failed time steps. + ## Example input file In this example, the time stepper extracts the time sequence from an exodus output file. This exodus file may not necessarily have been generated using the same input file. The starting and end time of the simulation may still be set independently. diff --git a/framework/doc/content/source/timesteppers/TimeSequenceStepper.md b/framework/doc/content/source/timesteppers/TimeSequenceStepper.md index 994dca2b92a5..1a32e4f19f8c 100644 --- a/framework/doc/content/source/timesteppers/TimeSequenceStepper.md +++ b/framework/doc/content/source/timesteppers/TimeSequenceStepper.md @@ -4,6 +4,9 @@ This time stepper derives from [TimeSequenceStepperBase.md] and provides the sequence of time values from a user-specified list, given by [!param](/Executioner/TimeSteppers/TimeSequenceStepper/time_sequence). +See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior +of this time stepper for failed time steps. + ## Example input syntax In this example, the numerical problem is solved at four specified points in time using