OGS 6.2.0-97-g4a610c866
CreateOutput.cpp
Go to the documentation of this file.
1 
10 #include "CreateOutput.h"
11 
12 #include <logog/include/logog.hpp>
13 #include <memory>
14 #include <tuple>
15 
16 #include "BaseLib/Algorithm.h"
17 #include "BaseLib/ConfigTree.h"
18 #include "BaseLib/FileTools.h"
19 
20 #include "MeshLib/Mesh.h"
21 
22 #include "Output.h"
23 
24 namespace ProcessLib
25 {
26 std::unique_ptr<Output> createOutput(
27  const BaseLib::ConfigTree& config,
28  std::string const& output_directory,
29  std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes)
30 {
31  DBUG("Parse output configuration:");
32 
34  config.checkConfigParameter("type", "VTK");
35 
36  auto const prefix =
38  config.getConfigParameter<std::string>("prefix");
39 
40  auto const compress_output =
42  config.getConfigParameter("compress_output", true);
43 
44  auto const data_mode =
46  config.getConfigParameter<std::string>("data_mode", "Binary");
47 
48  // Construction of output times
49  std::vector<Output::PairRepeatEachSteps> repeats_each_steps;
50 
51  std::vector<double> fixed_output_times;
52 
54  if (auto const timesteps = config.getConfigSubtreeOptional("timesteps"))
55  {
57  for (auto pair : timesteps->getConfigSubtreeList("pair"))
58  {
60  auto repeat = pair.getConfigParameter<unsigned>("repeat");
62  auto each_steps = pair.getConfigParameter<unsigned>("each_steps");
63 
64  assert(repeat != 0 && each_steps != 0);
65  repeats_each_steps.emplace_back(repeat, each_steps);
66  }
67 
68  if (repeats_each_steps.empty())
69  {
70  OGS_FATAL(
71  "You have not given any pair (<repeat/>, <each_steps/>) that "
72  "defines"
73  " at which timesteps output shall be written. Aborting.");
74  }
75  }
76  else
77  {
78  repeats_each_steps.emplace_back(1, 1);
79  }
80 
82  auto const out_vars = config.getConfigSubtree("variables");
83 
84  std::set<std::string> output_variables;
85  for (auto out_var :
87  out_vars.getConfigParameterList<std::string>("variable"))
88  {
89  if (output_variables.find(out_var) != output_variables.cend())
90  {
91  OGS_FATAL("output variable `%s' specified more than once.",
92  out_var.c_str());
93  }
94 
95  DBUG("adding output variable `%s'", out_var.c_str());
96  output_variables.insert(out_var);
97  }
98 
100  bool const output_residuals = config.getConfigParameter<bool>(
101  "output_extrapolation_residuals", false);
102 
103  ProcessOutput process_output{output_variables, output_residuals};
104 
105  std::vector<std::string> mesh_names_for_output;
107  if (auto const meshes_config = config.getConfigSubtreeOptional("meshes"))
108  {
110  for (auto mesh_config : meshes_config->getConfigParameterList("mesh"))
111  {
112  mesh_names_for_output.push_back(
113  mesh_config.getValue<std::string>());
114  INFO("Configure mesh '%s' for output.",
115  mesh_names_for_output.back().c_str());
116  }
117  }
118 
119  auto fixed_output_times_ptr =
121  config.getConfigParameterOptional<std::vector<double>>(
122  "fixed_output_times");
123  if (fixed_output_times_ptr)
124  {
125  fixed_output_times = std::move(*fixed_output_times_ptr);
126  // Remove possible duplicated elements and sort in descending order.
127  BaseLib::makeVectorUnique(fixed_output_times, std::greater<>());
128  }
129 
130  bool const output_iteration_results =
132  config.getConfigParameter<bool>("output_iteration_results", false);
133 
134  return std::make_unique<Output>(
135  output_directory, prefix, compress_output, data_mode,
136  output_iteration_results, std::move(repeats_each_steps),
137  std::move(fixed_output_times), std::move(process_output),
138  std::move(mesh_names_for_output), meshes);
139 }
140 
141 } // namespace ProcessLib
std::unique_ptr< Output > createOutput(const BaseLib::ConfigTree &config, std::string const &output_directory, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes)
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:177
Definition of the Mesh class.
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, T const &value) const
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:150
boost::optional< T > getConfigParameterOptional(std::string const &param) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:160
Filename manipulation routines.
Holds information about which variables to write to output files.
Definition: ProcessOutput.h:20