OGS
OutputDataSpecification.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
8
9namespace ProcessLib
10{
12 std::set<std::string>&& output_variables_,
13 std::vector<double>&& fixed_output_times_,
14 std::vector<PairRepeatEachSteps>&& repeats_each_steps_,
15 bool const output_residuals_)
16 : output_variables(std::move(output_variables_)),
17 fixed_output_times(std::move(fixed_output_times_)),
18 repeats_each_steps(std::move(repeats_each_steps_)),
19 output_residuals(output_residuals_)
20{
21 if (!std::is_sorted(cbegin(fixed_output_times), cend(fixed_output_times)))
22 {
24 "Vector of fixed output time steps passed to the "
25 "OutputDataSpecification constructor must be sorted");
26 }
27 // check the repeats_each_steps pairs
28 for (auto const& pair : repeats_each_steps)
29 {
30 if (pair.each_steps == 0)
31 {
33 "Step in pair of <repeats><steps> is zero but has to be "
34 "greater than zero.");
35 }
36 }
37 if (repeats_each_steps.empty())
38 {
39 repeats_each_steps.emplace_back(1, std::numeric_limits<int>::max());
40 }
41}
42
44 NumLib::Time const& time) const
45{
46 auto isFixedOutputStep = [this](NumLib::Time const time) -> bool
47 {
48 return std::any_of(cbegin(fixed_output_times), cend(fixed_output_times),
49 [&](auto fixed_output_time)
50 { return NumLib::Time(fixed_output_time) == time; });
51 };
52
53 auto isPairRepeatsEachTimeStepOutput = [this](int timestep) -> bool
54 {
55 int each_steps = 1;
56
57 for (auto const& pair : repeats_each_steps)
58 {
59 each_steps = pair.each_steps;
60
61 if (timestep > pair.repeat * each_steps)
62 {
63 timestep -= pair.repeat * each_steps;
64 }
65 else
66 {
67 break;
68 }
69 }
70
71 return timestep % each_steps == 0;
72 };
73
74 return isFixedOutputStep(time) || isPairRepeatsEachTimeStepOutput(timestep);
75}
76
77std::ostream& operator<<(std::ostream& os, PairRepeatEachSteps const& pair)
78{
79 os << "Output " << pair.repeat << " times every " << pair.each_steps
80 << " timestep.\n";
81 return os;
82}
83
84std::ostream& operator<<(std::ostream& os, OutputDataSpecification const& o)
85{
86 os << "OuputDataSpecification" << std::endl;
87 os << "\toutput_variables: ";
88 std::copy(o.output_variables.begin(), o.output_variables.end(),
89 std::ostream_iterator<std::string>(os, " "));
90 os << "\n";
91 os << "\tfixed_output_times: ";
92 std::copy(o.fixed_output_times.begin(), o.fixed_output_times.end(),
93 std::ostream_iterator<double>(os, " "));
94 os << "\n";
95 os << "\trepeats_each_steps: ";
96 std::copy(o.repeats_each_steps.begin(), o.repeats_each_steps.end(),
97 std::ostream_iterator<PairRepeatEachSteps>(os, " "));
98 os << "\n";
99 os << "\toutput_residual: " << o.output_residuals << "\n";
100 return os;
101}
102
103} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
std::ostream & operator<<(std::ostream &os, Output const &output)
Holds information about which variables to write to output files.
bool isOutputStep(int timestep, NumLib::Time const &time) const
std::vector< PairRepeatEachSteps > repeats_each_steps
Describes after which timesteps to write output.
std::vector< double > fixed_output_times
Given times that steps have to reach.
bool output_residuals
Tells if also to output extrapolation residuals.
std::set< std::string > output_variables
All variables that shall be output.
OutputDataSpecification(std::set< std::string > &&output_variables_, std::vector< double > &&fixed_output_times_, std::vector< PairRepeatEachSteps > &&repeats_each_steps_, bool const output_residuals_)
const int repeat
Apply each_steps repeat times.
const int each_steps
Do output every each_steps timestep.