57 std::vector<double>
const& delta_ts,
58 Time const& fixed_output_time)
60 if (fixed_output_time < t_initial)
62 return std::numeric_limits<std::size_t>::max();
65 auto timestepper_time = t_initial;
66 for (std::size_t k = 0; k < delta_ts.size(); ++k)
68 if (timestepper_time <= fixed_output_time &&
69 fixed_output_time < timestepper_time + delta_ts[k])
73 timestepper_time += delta_ts[k];
76 return std::numeric_limits<std::size_t>::max();
81 std::vector<double>& delta_ts,
82 std::vector<double>
const& fixed_times_for_output)
84 if (fixed_times_for_output.empty())
89 if (
auto lower_bound = std::lower_bound(
90 begin(fixed_times_for_output), end(fixed_times_for_output),
94 lower_bound != begin(fixed_times_for_output))
97 "Request for output at times {}, but the simulation's start time "
98 "is {}. Output will be skipped.",
99 fmt::join(begin(fixed_times_for_output), lower_bound,
", "),
103 if (
auto upper_bound =
104 std::upper_bound(begin(fixed_times_for_output),
105 end(fixed_times_for_output), t_end());
106 upper_bound != end(fixed_times_for_output))
109 "Request for output at times {}, but simulation's end time is {}. "
110 "Output will be skipped.",
111 fmt::join(upper_bound, end(fixed_times_for_output),
", "),
115 if (delta_ts.empty())
117 WARN(
"No timesteps specified.");
122 for (
auto const fixed_time_for_output : fixed_times_for_output)
125 t_initial, delta_ts,
Time(fixed_time_for_output));
126 if (interval_number == std::numeric_limits<std::size_t>::max())
128 WARN(
"Did not find interval for fixed output time {}",
129 fixed_time_for_output);
133 auto const lower_bound = std::accumulate(
134 begin(delta_ts), begin(delta_ts) + interval_number, t_initial);
135 auto const upper_bound = lower_bound + delta_ts[interval_number];
145 delta_ts[interval_number] = fixed_time_for_output - lower_bound();
147 delta_ts.insert(delta_ts.begin() + interval_number + 1,
148 upper_bound() - fixed_time_for_output);
153 double t0,
double tn, std::vector<RepeatDtPair>
const& repeat_dt_pairs,
154 std::vector<double>
const& fixed_times_for_output)
161 OGS_FATAL(
"FixedTimeStepping: Couldn't construct object from data");
163 for (
auto const& [repeat, delta_t] : repeat_dt_pairs)
167 t_curr = addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
174 auto const delta_t = std::get<1>(repeat_dt_pairs.back());
175 auto const repeat =
static_cast<std::size_t
>(
176 std::ceil((
_t_end() - t_curr()) / delta_t));
177 addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
181 fixed_times_for_output);
187 auto const new_size =
188 static_cast<std::size_t
>(std::ceil((t_end - t0) / dt));
191 _dt_vector = std::vector<double>(new_size, dt);
193 catch (std::length_error
const& e)
196 "Resize of the time steps vector failed for the requested new "
197 "size {}. Probably there is not enough memory ({:g} GiB "
199 "Thrown exception: {}",
200 new_size, new_size *
sizeof(
double) / 1024. / 1024. / 1024.,
203 catch (std::bad_alloc
const& e)
206 "Allocation of the time steps vector failed for the requested "
207 "size {}. Probably there is not enough memory ({:g} GiB "
209 "Thrown exception: {}",
211 new_size *
sizeof(
double) / 1024. / 1024. / 1024.,