OGS
ProcessLib/Output/Output.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <iosfwd>
7#include <map>
8#include <utility>
9#include <vector>
10
13#include "OutputFormat.h"
14
15namespace NumLib
16{
17struct Time;
18}
19
20namespace ProcessLib
21{
22class Process;
23
29class Output
30{
31public:
32 Output(std::unique_ptr<OutputFormat>&& output_format,
33 bool const output_nonlinear_iteration_results,
34 OutputDataSpecification&& output_data_specification,
35 std::vector<std::string>&& mesh_names_for_output,
36 std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes);
37
38 Output(Output const& other) = delete;
39 Output(Output&& other) = default;
40 Output& operator=(Output const& src) = delete;
41 Output& operator=(Output&& src) = default;
42 ~Output() = default;
43
45 void addProcess(ProcessLib::Process const& process);
46
50 std::string const& property_name,
51 MeshLib::MeshItemType const mesh_item_type);
52
55 void doOutput(Process const& process, const int process_id,
56 int const timestep, const NumLib::Time& t,
57 int const iteration, bool const converged,
58 std::vector<GlobalVector*> const& xs) const;
59
63 void doOutputLastTimestep(Process const& process, const int process_id,
64 int const timestep, const NumLib::Time& t,
65 int const iteration, bool const converged,
66 std::vector<GlobalVector*> const& xs) const;
67
71 void doOutputAlways(Process const& process, const int process_id,
72 int const timestep, const NumLib::Time& t,
73 int const iteration, bool const converged,
74 std::vector<GlobalVector*> const& xs) const;
75
81 void doOutputNonlinearIteration(Process const& process,
82 const int process_id, int const timestep,
83 const NumLib::Time& t, const int iteration,
84 std::vector<GlobalVector*> const& xs) const;
85
87 bool isOutputStep(int const timestep, NumLib::Time const& t) const;
88
89 std::vector<double> const& getFixedOutputTimes() const
90 {
91 return _output_data_specification.fixed_output_times;
92 }
93
94 std::vector<std::string> getFileNamesForOutput() const;
95
96 friend std::ostream& operator<<(std::ostream& os, Output const& output);
97
98private:
102 bool isOutputProcess(int const process_id, Process const& process) const;
103
104 void outputMeshes(
105 int const timestep, const double t, int const iteration,
106 bool const converged,
107 std::vector<std::reference_wrapper<const MeshLib::Mesh>> const& meshes)
108 const;
109
111 std::string const& submesh_output_name, Process const& process,
112 const int process_id, NumLib::Time const& t,
113 std::vector<GlobalVector*> const& xs) const;
114
115 std::unique_ptr<OutputFormat> _output_format;
116
118
120 std::vector<std::reference_wrapper<Process const>> _output_processes;
121 std::vector<std::string> _mesh_names_for_output;
122 // The reference wrapper enables the compiler to generate a move constructor
123 // and move assignment operator
124 // - another possibility would be to transform the
125 // std::vector<std::unique_ptr<MeshLib::Mesh>> to
126 // std::vector<MeshLib::Mesh*>
127 // - this issue could also be solved by (globally) storing the meshes into a
128 // std::vector<std::shared_ptr<MeshLib::Mesh>>
129 std::reference_wrapper<std::vector<std::unique_ptr<MeshLib::Mesh>> const>
131
132 std::set<std::pair<std::string, MeshLib::MeshItemType>>
134};
135
137 std::vector<Output> const& outputs);
138
139} // namespace ProcessLib
std::set< std::pair< std::string, MeshLib::MeshItemType > > _do_not_project_from_bulk_mesh_to_submeshes
std::reference_wrapper< std::vector< std::unique_ptr< MeshLib::Mesh > > const > _meshes
void doOutputAlways(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, int const iteration, bool const converged, std::vector< GlobalVector * > const &xs) const
void doOutput(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, int const iteration, bool const converged, std::vector< GlobalVector * > const &xs) const
std::vector< std::string > _mesh_names_for_output
void doOutputLastTimestep(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, int const iteration, bool const converged, std::vector< GlobalVector * > const &xs) const
void outputMeshes(int const timestep, const double t, int const iteration, bool const converged, std::vector< std::reference_wrapper< const MeshLib::Mesh > > const &meshes) const
Output & operator=(Output &&src)=default
friend std::ostream & operator<<(std::ostream &os, Output const &output)
Output(Output &&other)=default
Output(Output const &other)=delete
void doNotProjectFromBulkMeshToSubmeshes(std::string const &property_name, MeshLib::MeshItemType const mesh_item_type)
OutputDataSpecification _output_data_specification
std::vector< std::reference_wrapper< Process const > > _output_processes
MeshLib::Mesh const & prepareSubmesh(std::string const &submesh_output_name, Process const &process, const int process_id, NumLib::Time const &t, std::vector< GlobalVector * > const &xs) const
void doOutputNonlinearIteration(Process const &process, const int process_id, int const timestep, const NumLib::Time &t, const int iteration, std::vector< GlobalVector * > const &xs) const
Output & operator=(Output const &src)=delete
Output(std::unique_ptr< OutputFormat > &&output_format, bool const output_nonlinear_iteration_results, OutputDataSpecification &&output_data_specification, std::vector< std::string > &&mesh_names_for_output, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)
bool isOutputProcess(int const process_id, Process const &process) const
std::unique_ptr< OutputFormat > _output_format
void addProcess(ProcessLib::Process const &process)
TODO doc. Opens a PVD file for each process.
std::vector< std::string > getFileNamesForOutput() const
bool isOutputStep(int const timestep, NumLib::Time const &t) const
Tells if output will be written at the specified timestep/time.
std::vector< double > const & getFixedOutputTimes() const
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)
Holds information about which variables to write to output files.