OGS
CreateFixedTimeStepping.cpp
Go to the documentation of this file.
1
13
14#include "BaseLib/ConfigTree.h"
15#include "BaseLib/Error.h"
16#include "FixedTimeStepping.h"
17#include "TimeStepAlgorithm.h"
18
19namespace NumLib
20{
22 BaseLib::ConfigTree const& config)
23{
25 config.checkConfigParameter("type", "FixedTimeStepping");
26
28 auto const t_initial = config.getConfigParameter<double>("t_initial");
30 auto const t_end = config.getConfigParameter<double>("t_end");
31
33 auto const n_steps = config.getConfigParameterOptional<int>("n_steps");
34 if (n_steps.has_value())
35 {
36 if (t_end <= t_initial)
37 {
39 "Creating linearly spaced time steps vector using "
40 "FixedTimeStepping algorithm failed! "
41 "User provided start value (t_initial) "
42 "{} is not smaller then end value (t_end) {}.",
43 t_initial, t_end);
44 }
45
46 if (*n_steps <= 0)
47 {
49 "Requested number of time steps in time steps vector "
50 "(n_steps) must be greater then 0. "
51 "{} time steps were requested",
52 *n_steps);
53 }
54 // Create the RepeatDtPair
55 double const t_step =
56 (t_end - t_initial) / static_cast<double>(*n_steps);
57 std::vector const repeat_pairs = {
58 RepeatDtPair{static_cast<std::size_t>(*n_steps), t_step}};
59 return {t_initial, t_end, repeat_pairs};
60 }
61
63 auto const delta_ts_config = config.getConfigSubtree("timesteps");
64
65 // TODO: consider adding call "listNonEmpty" to config tree
67 auto const range = delta_ts_config.getConfigSubtreeList("pair");
68 if (range.begin() == range.end())
69 {
70 OGS_FATAL("no timesteps have been given");
71 }
72
73 std::vector<RepeatDtPair> repeat_dt_pairs;
74 for (auto const pair : range)
75 {
76 repeat_dt_pairs.emplace_back(
78 pair.getConfigParameter<std::size_t>("repeat"),
80 pair.getConfigParameter<double>("delta_t"));
81 }
82
83 return {t_initial, t_end, repeat_dt_pairs};
84}
85
86std::unique_ptr<TimeStepAlgorithm> createFixedTimeStepping(
87 FixedTimeSteppingParameters const& parameters,
88 std::vector<double> const& fixed_times_for_output)
89{
90 if (parameters.t_end < parameters.t_initial)
91 {
93 "fixed timestepping: end time ({}) is smaller than initial time "
94 "({})",
95 parameters.t_end,
96 parameters.t_initial);
97 }
98
100 {
101 OGS_FATAL(
102 "CreateFixedTimeStepping: invalid specification of (repeat, "
103 "delta_t) pairs");
104 }
105
106 return std::make_unique<FixedTimeStepping>(parameters.t_initial,
107 parameters.t_end,
108 parameters.repeat_dt_pairs,
109 fixed_times_for_output);
110}
111} // end of namespace NumLib
#define OGS_FATAL(...)
Definition Error.h:26
std::optional< T > getConfigParameterOptional(std::string const &param) const
T getConfigParameter(std::string const &param) const
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
ConfigTree getConfigSubtree(std::string const &root) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
static bool areRepeatDtPairsValid(std::vector< RepeatDtPair > const &repeat_dt_pairs)
FixedTimeSteppingParameters parseFixedTimeStepping(BaseLib::ConfigTree const &config)
std::tuple< std::size_t, double > RepeatDtPair
std::unique_ptr< TimeStepAlgorithm > createFixedTimeStepping(FixedTimeSteppingParameters const &parameters, std::vector< double > const &fixed_times_for_output)
std::vector< RepeatDtPair > repeat_dt_pairs