55 std::vector<double>
const& delta_ts,
56 Time const& fixed_output_time)
58 if (fixed_output_time < t_initial)
60 return std::numeric_limits<std::size_t>::max();
63 auto timestepper_time = t_initial;
64 for (std::size_t k = 0; k < delta_ts.size(); ++k)
66 if (timestepper_time <= fixed_output_time &&
67 fixed_output_time < timestepper_time + delta_ts[k])
71 timestepper_time += delta_ts[k];
74 return std::numeric_limits<std::size_t>::max();
79 std::vector<double>& delta_ts,
80 std::vector<double>
const& fixed_times_for_output)
82 if (fixed_times_for_output.empty())
87 if (
auto lower_bound = std::lower_bound(
88 begin(fixed_times_for_output), end(fixed_times_for_output),
92 lower_bound != begin(fixed_times_for_output))
95 "Request for output at times {}, but the simulation's start time "
96 "is {}. Output will be skipped.",
97 fmt::join(begin(fixed_times_for_output), lower_bound,
", "),
101 if (
auto upper_bound =
102 std::upper_bound(begin(fixed_times_for_output),
103 end(fixed_times_for_output), t_end());
104 upper_bound != end(fixed_times_for_output))
107 "Request for output at times {}, but simulation's end time is {}. "
108 "Output will be skipped.",
109 fmt::join(upper_bound, end(fixed_times_for_output),
", "),
113 if (delta_ts.empty())
115 WARN(
"No timesteps specified.");
120 for (
auto const fixed_time_for_output : fixed_times_for_output)
123 t_initial, delta_ts,
Time(fixed_time_for_output));
124 if (interval_number == std::numeric_limits<std::size_t>::max())
126 WARN(
"Did not find interval for fixed output time {}",
127 fixed_time_for_output);
131 auto const lower_bound = std::accumulate(
132 begin(delta_ts), begin(delta_ts) + interval_number, t_initial);
133 auto const upper_bound = lower_bound + delta_ts[interval_number];
143 delta_ts[interval_number] = fixed_time_for_output - lower_bound();
145 delta_ts.insert(delta_ts.begin() + interval_number + 1,
146 upper_bound() - fixed_time_for_output);
151 double t0,
double tn, std::vector<RepeatDtPair>
const& repeat_dt_pairs,
152 std::vector<double>
const& fixed_times_for_output)
159 OGS_FATAL(
"FixedTimeStepping: Couldn't construct object from data");
161 for (
auto const& [repeat, delta_t] : repeat_dt_pairs)
165 t_curr = addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
172 auto const delta_t = std::get<1>(repeat_dt_pairs.back());
173 auto const repeat =
static_cast<std::size_t
>(
174 std::ceil((
_t_end() - t_curr()) / delta_t));
175 addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
179 fixed_times_for_output);
185 auto const new_size =
186 static_cast<std::size_t
>(std::ceil((t_end - t0) / dt));
189 _dt_vector = std::vector<double>(new_size, dt);
191 catch (std::length_error
const& e)
194 "Resize of the time steps vector failed for the requested new "
195 "size {}. Probably there is not enough memory ({:g} GiB "
197 "Thrown exception: {}",
198 new_size, new_size *
sizeof(
double) / 1024. / 1024. / 1024.,
201 catch (std::bad_alloc
const& e)
204 "Allocation of the time steps vector failed for the requested "
205 "size {}. Probably there is not enough memory ({:g} GiB "
207 "Thrown exception: {}",
209 new_size *
sizeof(
double) / 1024. / 1024. / 1024.,