52 std::vector<double>
const& delta_ts,
53 double const fixed_output_time)
55 if (fixed_output_time < t_initial)
57 return std::numeric_limits<std::size_t>::max();
60 auto timestepper_time = t_initial;
61 for (std::size_t k = 0; k < delta_ts.size(); ++k)
63 if (timestepper_time <= fixed_output_time &&
64 fixed_output_time < timestepper_time + delta_ts[k])
68 timestepper_time += delta_ts[k];
71 return std::numeric_limits<std::size_t>::max();
75 double const t_initial,
double const t_end, std::vector<double>& delta_ts,
76 std::vector<double>
const& fixed_times_for_output)
78 if (fixed_times_for_output.empty())
83 if (
auto lower_bound =
84 std::lower_bound(begin(fixed_times_for_output),
85 end(fixed_times_for_output), t_initial);
86 lower_bound != begin(fixed_times_for_output))
89 "Request for output at times {}, but the simulation's start time "
90 "is {}. Output will be skipped.",
91 fmt::join(begin(fixed_times_for_output), lower_bound,
", "),
95 if (
auto upper_bound = std::upper_bound(begin(fixed_times_for_output),
96 end(fixed_times_for_output), t_end);
97 upper_bound != end(fixed_times_for_output))
100 "Request for output at times {}, but simulation's end time is {}. "
101 "Output will be skipped.",
102 fmt::join(upper_bound, end(fixed_times_for_output),
", "),
106 if (delta_ts.empty())
108 WARN(
"No timesteps specified.");
113 for (
auto const fixed_time_for_output : fixed_times_for_output)
115 auto const interval_number =
117 if (interval_number == std::numeric_limits<std::size_t>::max())
119 WARN(
"Did not find interval for fixed output time {}",
120 fixed_time_for_output);
123 auto const lower_bound = std::accumulate(
124 begin(delta_ts), begin(delta_ts) + interval_number, t_initial);
125 auto const upper_bound = lower_bound + delta_ts[interval_number];
126 if (fixed_time_for_output - lower_bound <=
127 std::numeric_limits<double>::epsilon())
131 if (upper_bound - fixed_time_for_output <=
132 std::numeric_limits<double>::epsilon())
136 delta_ts[interval_number] = fixed_time_for_output - lower_bound;
138 delta_ts.insert(delta_ts.begin() + interval_number + 1,
139 upper_bound - fixed_time_for_output);
144 double t0,
double tn,
145 std::vector<std::pair<std::size_t, double>>
const& repeat_dt_pairs,
146 std::vector<double>
const& fixed_times_for_output)
151 for (
auto const& [repeat, delta_t] : repeat_dt_pairs)
159 OGS_FATAL(
"timestep <delta_t> is <= 0.0.");
164 t_curr = addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
171 auto const delta_t = repeat_dt_pairs.back().second;
173 static_cast<std::size_t
>(std::ceil((
_t_end - t_curr) / delta_t));
174 addTimeIncrement(
_dt_vector, repeat, delta_t, t_curr);
178 fixed_times_for_output);
184 auto const new_size =
185 static_cast<std::size_t
>(std::ceil((t_end - t0) / dt));
188 _dt_vector = std::vector<double>(new_size, dt);
190 catch (std::length_error
const& e)
193 "Resize of the time steps vector failed for the requested new "
194 "size {}. Probably there is not enough memory ({:g} GiB "
196 "Thrown exception: {}",
197 new_size, new_size *
sizeof(
double) / 1024. / 1024. / 1024.,
200 catch (std::bad_alloc
const& e)
203 "Allocation of the time steps vector failed for the requested "
204 "size {}. Probably there is not enough memory ({:g} GiB "
206 "Thrown exception: {}",
208 new_size *
sizeof(
double) / 1024. / 1024. / 1024.,