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