OGS
OutputDataSpecification.cpp
Go to the documentation of this file.
1
12
15
16namespace ProcessLib
17{
19 std::set<std::string>&& output_variables_,
20 std::vector<double>&& fixed_output_times_,
21 std::vector<PairRepeatEachSteps>&& repeats_each_steps_,
22 bool const output_residuals_)
23 : output_variables(std::move(output_variables_)),
24 fixed_output_times(std::move(fixed_output_times_)),
25 repeats_each_steps(std::move(repeats_each_steps_)),
26 output_residuals(output_residuals_)
27{
28 if (!std::is_sorted(cbegin(fixed_output_times), cend(fixed_output_times)))
29 {
31 "Vector of fixed output time steps passed to the "
32 "OutputDataSpecification constructor must be sorted");
33 }
34 // check the repeats_each_steps pairs
35 for (auto const& pair : repeats_each_steps)
36 {
37 if (pair.each_steps == 0)
38 {
40 "Step in pair of <repeats><steps> is zero but has to be "
41 "greater than zero.");
42 }
43 }
44 if (repeats_each_steps.empty())
45 {
46 repeats_each_steps.emplace_back(1, std::numeric_limits<int>::max());
47 }
48}
49
51 NumLib::Time const& time) const
52{
53 auto isFixedOutputStep = [this](NumLib::Time const time) -> bool
54 {
55 return std::any_of(cbegin(fixed_output_times), cend(fixed_output_times),
56 [&](auto fixed_output_time)
57 { return NumLib::Time(fixed_output_time) == time; });
58 };
59
60 auto isPairRepeatsEachTimeStepOutput = [this](int timestep) -> bool
61 {
62 int each_steps = 1;
63
64 for (auto const& pair : repeats_each_steps)
65 {
66 each_steps = pair.each_steps;
67
68 if (timestep > pair.repeat * each_steps)
69 {
70 timestep -= pair.repeat * each_steps;
71 }
72 else
73 {
74 break;
75 }
76 }
77
78 return timestep % each_steps == 0;
79 };
80
81 return isFixedOutputStep(time) || isPairRepeatsEachTimeStepOutput(timestep);
82}
83
84std::ostream& operator<<(std::ostream& os, PairRepeatEachSteps const& pair)
85{
86 os << "Output " << pair.repeat << " times every " << pair.each_steps
87 << " timestep.\n";
88 return os;
89}
90
91std::ostream& operator<<(std::ostream& os, OutputDataSpecification const& o)
92{
93 os << "OuputDataSpecification" << std::endl;
94 os << "\toutput_variables: ";
95 std::copy(o.output_variables.begin(), o.output_variables.end(),
96 std::ostream_iterator<std::string>(os, " "));
97 os << "\n";
98 os << "\tfixed_output_times: ";
99 std::copy(o.fixed_output_times.begin(), o.fixed_output_times.end(),
100 std::ostream_iterator<double>(os, " "));
101 os << "\n";
102 os << "\trepeats_each_steps: ";
103 std::copy(o.repeats_each_steps.begin(), o.repeats_each_steps.end(),
104 std::ostream_iterator<PairRepeatEachSteps>(os, " "));
105 os << "\n";
106 os << "\toutput_residual: " << o.output_residuals << "\n";
107 return os;
108}
109
110} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
std::ostream & operator<<(std::ostream &os, Output const &output)
Definition Output.cpp:447
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.