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