Skip to content

Commit

Permalink
Merge branch 'lin_time_step' into 'master'
Browse files Browse the repository at this point in the history
Add LinSpaceTimeStepping

See merge request ogs/ogs!5099
  • Loading branch information
endJunction committed Nov 6, 2024
2 parents 32da72c + 07a4c00 commit 8982a58
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
An optional parameter specifying the number of time steps.
All time steps will be of the same size \f$(t_{\rm end} - t_{\rm initial}) \over n\f$.

For more complex setups see the `timesteps` parameter documentation.
31 changes: 31 additions & 0 deletions NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@ FixedTimeSteppingParameters parseFixedTimeStepping(
auto const t_initial = config.getConfigParameter<double>("t_initial");
//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__FixedTimeStepping__t_end}
auto const t_end = config.getConfigParameter<double>("t_end");

//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__FixedTimeStepping__n_steps}
auto const n_steps = config.getConfigParameterOptional<int>("n_steps");
if (n_steps.has_value())
{
if (t_end <= t_initial)
{
OGS_FATAL(
"Creating linearly spaced time steps vector using "
"FixedTimeStepping algorithm failed! "
"User provided start value (t_initial) "
"{} is not smaller then end value (t_end) {}.",
t_initial, t_end);
}

if (*n_steps <= 0)
{
OGS_FATAL(
"Requested number of time steps in time steps vector "
"(n_steps) must be greater then 0. "
"{} time steps were requested",
*n_steps);
}
// Create the RepeatDtPair
std::size_t const t_step = static_cast<std::size_t>(
(t_end - t_initial) / static_cast<double>(*n_steps));
std::vector const repeat_pairs = {
RepeatDtPair{static_cast<std::size_t>(*n_steps), t_step}};
return {t_initial, t_end, repeat_pairs};
}

//! \ogs_file_param{prj__time_loop__processes__process__time_stepping__FixedTimeStepping__timesteps}
auto const delta_ts_config = config.getConfigSubtree("timesteps");

Expand Down
1 change: 1 addition & 0 deletions ProcessLib/Assembly/MatrixOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <spdlog/fmt/bundled/ostream.h>

#include <iomanip>
#include <optional>
#include <unordered_set>

Expand Down
7 changes: 1 addition & 6 deletions Tests/Data/Parabolic/T/1D_dirichlet/line_60_heat.prj
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@
<type>FixedTimeStepping</type>
<t_initial> 0.0 </t_initial>
<t_end> 39062500 </t_end>
<timesteps>
<pair>
<repeat>500</repeat>
<delta_t>78125</delta_t>
</pair>
</timesteps>
<n_steps>500</n_steps>
</time_stepping>
</process>
</processes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='ISO-8859-1'?>
<OpenGeoSysProjectDiff base_file="../line_60_heat.prj">
<remove sel="/*/time_loop/processes/process/time_stepping/timesteps"/>
<remove sel="/*/time_loop/processes/process/time_stepping/n_steps"/>
<add sel="/*/time_loop/processes/process/time_stepping">
<timesteps>
<pair>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<linear>true</linear>
</add>

<remove sel="/*/time_loop/processes/process/time_stepping/timesteps"/>
<remove sel="/*/time_loop/processes/process/time_stepping/n_steps"/>
<add sel="/*/time_loop/processes/process/time_stepping">
<timesteps>
<pair>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<linear_solver_compute_only_upon_timestep_change>true</linear_solver_compute_only_upon_timestep_change>
</add>

<remove sel="/*/time_loop/processes/process/time_stepping/timesteps"/>
<remove sel="/*/time_loop/processes/process/time_stepping/n_steps"/>
<add sel="/*/time_loop/processes/process/time_stepping">
<timesteps>
<pair>
Expand Down
14 changes: 14 additions & 0 deletions web/content/docs/userguide/blocks/time_loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ unit:
</time_stepping>
```

Fixed time stepping can be also used to create linearly spaced steps between `t_initial` and `t_end`.
The number of steps is defined by `n_steps`.

```xml
<time_stepping>
<type>FixedTimeStepping</type>
<t_initial>0</t_initial>
<t_end>10</t_end>
<n_steps>10</n_steps>
</time_stepping>
```

will result in 11 time steps at: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

As fixed time stepping is one of the simplest available, it is a good starting point.

#### Iteration number based time stepping
Expand Down

0 comments on commit 8982a58

Please sign in to comment.