Skip to content

Commit

Permalink
Merge pull request #24873 from joshuahansel/time-sequence-stepper-las…
Browse files Browse the repository at this point in the history
…t-step

Added extrapolation option to TimeSequenceStepperBase
  • Loading branch information
joshuahansel authored Jul 5, 2023
2 parents 083b79b + e81a9af commit bc7f9c9
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# 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
(using the "column_name" parameter, provided that the CSV file has a header
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.
See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior
of this time stepper for failed time steps.

!syntax parameters /Executioner/TimeSteppers/CSVTimeSequenceStepper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# 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.
See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior
of this time stepper for failed time steps.

## Example input file

Expand Down
11 changes: 5 additions & 6 deletions framework/doc/content/source/timesteppers/TimeSequenceStepper.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# TimeSequenceStepper

!syntax description /Executioner/TimeSteppers/TimeSequenceStepper
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).

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".
See [TimeSequenceStepperBase.md#failed_solves] for information on the behavior
of this time stepper for failed time steps.

## Example input syntax

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

## 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
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} \,.
3 changes: 3 additions & 0 deletions framework/include/timesteppers/TimeSequenceStepperBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 19 additions & 1 deletion framework/src/timesteppers/TimeSequenceStepperBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ InputParameters
TimeSequenceStepperBase::validParams()
{
InputParameters params = TimeStepper::validParams();
params.addParam<bool>(
"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<bool>("use_last_dt_after_last_t")),
_current_step(declareRestartableData<unsigned int>("current_step", 0)),
_time_sequence(declareRestartableData<std::vector<Real>>("time_sequence"))
{
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions modules/doc/content/newsletter/2023/2023_07.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
time,dt
0,0
1,1
3,2
4,1
8,4
12,4
16,4
12 changes: 10 additions & 2 deletions test/tests/time_steppers/timesequence_stepper/tests
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Tests]
issues = '#9698 #6353 #6795'
issues = '#9698 #6353 #6795 #24868'
design = 'TimeSequenceStepper.md'

[time_sequence]
Expand Down Expand Up @@ -63,7 +63,15 @@
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]
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.'
[]
[]

Expand Down
Original file line number Diff line number Diff line change
@@ -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
[]

0 comments on commit bc7f9c9

Please sign in to comment.