diff --git a/Documentation/ProjectFile/prj/time_loop/processes/process/time_stepping/FixedTimeStepping/t_n_steps.md b/Documentation/ProjectFile/prj/time_loop/processes/process/time_stepping/FixedTimeStepping/t_n_steps.md new file mode 100644 index 0000000000000000000000000000000000000000..41b490517f72115268106c19a58e4da028ae1dc9 --- /dev/null +++ b/Documentation/ProjectFile/prj/time_loop/processes/process/time_stepping/FixedTimeStepping/t_n_steps.md @@ -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. diff --git a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp index 2b9d74cd15c19319b01180e5c52922829b512176..73d5203b0176cc747ae3be0530d28f11ebf944a4 100644 --- a/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/CreateFixedTimeStepping.cpp @@ -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"); diff --git a/Tests/Data/Parabolic/T/1D_dirichlet/line_60_heat.prj b/Tests/Data/Parabolic/T/1D_dirichlet/line_60_heat.prj index 006833f04df0b00b9f4249db63e0c008b4dde9c9..4ad5c3a2aa210b5a6096856a3a31659815012f49 100644 --- a/Tests/Data/Parabolic/T/1D_dirichlet/line_60_heat.prj +++ b/Tests/Data/Parabolic/T/1D_dirichlet/line_60_heat.prj @@ -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> diff --git a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt/line_60_heat.xml b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt/line_60_heat.xml index bab27be155b5c592b1e51e21af2aecefad357c4c..59d0b8a106134db59c21401184c01ebc88c258a2 100644 --- a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt/line_60_heat.xml +++ b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt/line_60_heat.xml @@ -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> diff --git a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear/line_60_heat.xml b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear/line_60_heat.xml index 4f356a5f27828ced3a529c7649145c9d08e9e91c..9c72843f1467e897e12130f6178269095c12a5b7 100644 --- a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear/line_60_heat.xml +++ b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear/line_60_heat.xml @@ -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> diff --git a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear_compute_only_on_dt_change/line_60_heat.xml b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear_compute_only_on_dt_change/line_60_heat.xml index e1ec26c894bdd60e53c14687fd77ad7a83129596..5ee7efb034ee1dfddd4390dff070ae0bd25c9ad4 100644 --- a/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear_compute_only_on_dt_change/line_60_heat.xml +++ b/Tests/Data/Parabolic/T/1D_dirichlet/varying_dt_linear_compute_only_on_dt_change/line_60_heat.xml @@ -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> diff --git a/web/content/docs/userguide/blocks/time_loop.md b/web/content/docs/userguide/blocks/time_loop.md index 6a73149f2a130a536cce4aeca3b9604626eced6e..289110e23be60b0ee61e9b51436abe3dfca89c8c 100644 --- a/web/content/docs/userguide/blocks/time_loop.md +++ b/web/content/docs/userguide/blocks/time_loop.md @@ -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