OGS
ProcessOutputData.cpp
Go to the documentation of this file.
1
11#include "ProcessOutputData.h"
12
13#include "ProcessLib/Process.h"
14
15namespace
16{
20 ProcessLib::Process const& process)
21{
22 return mesh == process.getMesh();
23}
24
25std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>
27 MeshLib::Mesh const& submesh,
28 std::size_t const n_processes)
29{
30 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>
31 submesh_dof_tables;
32 submesh_dof_tables.reserve(n_processes);
33
34 for (std::size_t i = 0; i < n_processes; ++i)
35 {
36 submesh_dof_tables.push_back(
38 MeshLib::MeshSubset{submesh, submesh.getNodes()}));
39 }
40
41 return submesh_dof_tables;
42}
43
44std::vector<NumLib::LocalToGlobalIndexMap const*> toNonOwning(
45 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>> const&
46 dof_tables)
47{
48 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table_pointers;
49
50 dof_table_pointers.reserve(dof_tables.size());
51 transform(cbegin(dof_tables), cend(dof_tables),
52 back_inserter(dof_table_pointers),
53 [](std::unique_ptr<NumLib::LocalToGlobalIndexMap> const& p)
54 { return p.get(); });
55
56 return dof_table_pointers;
57}
58
59std::vector<NumLib::LocalToGlobalIndexMap const*> getDofTablesOfAllProcesses(
60 ProcessLib::Process const& process, std::size_t const n_processes)
61{
62 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables_of_all_procs(
63 n_processes);
64
65 for (std::size_t proc_id = 0; proc_id < n_processes; ++proc_id)
66 {
67 dof_tables_of_all_procs[proc_id] = &process.getDOFTable(proc_id);
68 }
69
70 return dof_tables_of_all_procs;
71}
72
85 ProcessLib::Process const& process,
86 MeshLib::Mesh const& output_mesh,
87 std::vector<NumLib::LocalToGlobalIndexMap const*> const&
88 bulk_mesh_dof_tables)
89{
90 if (isSimulationDomain(output_mesh, process))
91 {
92 return std::pair(
93 bulk_mesh_dof_tables /* will be copied */,
94 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>{});
95 }
96
97 auto const n_processes = bulk_mesh_dof_tables.size();
98
99 // TODO Currently these d.o.f. tables will be recomputed every time we write
100 // output. That should be avoided in the future.
101 auto container_that_owns_output_mesh_dof_tables =
102 computeDofTablesForSubmesh(process, output_mesh, n_processes);
103
104 auto output_mesh_dof_tables =
105 toNonOwning(container_that_owns_output_mesh_dof_tables);
106
107 return std::pair(std::move(output_mesh_dof_tables),
108 std::move(container_that_owns_output_mesh_dof_tables));
109}
110
111std::vector<std::reference_wrapper<
112 const std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>>>
114 std::size_t const n_processes)
115{
116 std::vector<std::reference_wrapper<
117 const std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>>>
118 pvs_of_all_procs;
119 pvs_of_all_procs.reserve(n_processes);
120
121 for (std::size_t proc_id = 0; proc_id < n_processes; ++proc_id)
122 {
123 pvs_of_all_procs.emplace_back(process.getProcessVariables(proc_id));
124 }
125
126 return pvs_of_all_procs;
127}
128
129std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>> const*
131 MeshLib::Mesh const& output_mesh)
132{
133 return isSimulationDomain(output_mesh, process)
134 ? &process.getIntegrationPointWriters()
135 : nullptr;
136}
137
138} // namespace
139
140namespace ProcessLib
141{
142
144 std::size_t const n_processes,
145 MeshLib::Mesh& output_mesh)
146{
147 auto bulk_mesh_dof_tables =
148 getDofTablesOfAllProcesses(process, n_processes);
149
150 auto [output_mesh_dof_tables, container_that_owns_output_mesh_dof_tables] =
151 computeOutputMeshDofTables(process, output_mesh, bulk_mesh_dof_tables);
152
153 return {getProcessVariablesOfAllProcesses(process, n_processes),
154 process.getSecondaryVariables(),
155 ::getIntegrationPointWriters(process, output_mesh),
156 std::move(bulk_mesh_dof_tables),
157 std::move(output_mesh_dof_tables),
158 std::move(container_that_owns_output_mesh_dof_tables),
159 output_mesh};
160}
161
163 std::vector<std::reference_wrapper<
164 const std::vector<std::reference_wrapper<ProcessVariable>>>>&&
165 process_variables_of_all_processes,
166 const SecondaryVariableCollection& secondary_variables,
167 const std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>>*
168 integration_point_writers,
169 std::vector<const NumLib::LocalToGlobalIndexMap*>&&
170 bulk_mesh_dof_tables_of_all_processes,
171 std::vector<const NumLib::LocalToGlobalIndexMap*>&&
172 output_mesh_dof_tables_of_all_processes,
173 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>&&
174 container_that_owns_output_mesh_dof_tables,
175 MeshLib::Mesh& output_mesh)
176 : process_variables_of_all_processes_(
177 std::move(process_variables_of_all_processes)),
178 secondary_variables_(secondary_variables),
179 integration_point_writers_(integration_point_writers),
180 bulk_mesh_dof_tables_of_all_processes_(
181 std::move(bulk_mesh_dof_tables_of_all_processes)),
182 output_mesh_dof_tables_of_all_processes_(
183 std::move(output_mesh_dof_tables_of_all_processes)),
184 container_that_owns_output_mesh_dof_tables_(
185 std::move(container_that_owns_output_mesh_dof_tables)),
186 output_mesh_(output_mesh)
187{
188 auto const n_proc_pvs = process_variables_of_all_processes_.size();
189 auto const n_proc_bulk = bulk_mesh_dof_tables_of_all_processes_.size();
190 auto const n_proc_out = output_mesh_dof_tables_of_all_processes_.size();
191 auto const n_proc_own = container_that_owns_output_mesh_dof_tables_.size();
192
193 if (n_proc_pvs != n_proc_bulk)
194 {
195 OGS_FATAL(
196 "Mismatch in number of processes (PVs vs. bulk mesh d.o.f. "
197 "tables): {} != {}",
198 n_proc_pvs, n_proc_bulk);
199 }
200
201 if (n_proc_pvs != n_proc_out)
202 {
203 OGS_FATAL(
204 "Mismatch in number of processes (PVs vs. output mesh d.o.f. "
205 "tables): {} != {}",
206 n_proc_pvs, n_proc_out);
207 }
208
209 // n_proc_own is nonzero only for submesh output
210 if (n_proc_own != 0 && n_proc_pvs != n_proc_own)
211 {
212 OGS_FATAL(
213 "Mismatch in number of processes (PVs vs. output mesh d.o.f. "
214 "tables, owning): {} != {}",
215 n_proc_pvs, n_proc_own);
216 }
217}
218
219} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
A subset of nodes on a single mesh.
Definition MeshSubset.h:26
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
Holds all data of a process that are needed for output.
std::vector< std::unique_ptr< NumLib::LocalToGlobalIndexMap > > container_that_owns_output_mesh_dof_tables_
std::vector< NumLib::LocalToGlobalIndexMap const * > output_mesh_dof_tables_of_all_processes_
std::vector< std::reference_wrapper< const std::vector< std::reference_wrapper< ProcessVariable > > > > process_variables_of_all_processes_
ProcessOutputData(std::vector< std::reference_wrapper< const std::vector< std::reference_wrapper< ProcessVariable > > > > &&process_variables_of_all_processes, const SecondaryVariableCollection &secondary_variables, const std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > *integration_point_writers, std::vector< const NumLib::LocalToGlobalIndexMap * > &&bulk_mesh_dof_tables_of_all_processes, std::vector< const NumLib::LocalToGlobalIndexMap * > &&output_mesh_dof_tables_of_all_processes, std::vector< std::unique_ptr< NumLib::LocalToGlobalIndexMap > > &&container_that_owns_output_mesh_dof_tables, MeshLib::Mesh &output_mesh)
std::vector< NumLib::LocalToGlobalIndexMap const * > bulk_mesh_dof_tables_of_all_processes_
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const & getIntegrationPointWriters() const
Definition Process.h:178
MeshLib::Mesh & getMesh() const
Definition Process.h:153
SecondaryVariableCollection const & getSecondaryVariables() const
Definition Process.h:172
virtual NumLib::LocalToGlobalIndexMap const & getDOFTable(const int) const
Definition Process.h:147
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const & getProcessVariables() const
Definition Process.h:156
Handles configuration of several secondary variables from the project file.
ProcessOutputData createProcessOutputData(Process const &process, std::size_t const n_processes, MeshLib::Mesh &output_mesh)
Extracts data necessary for output from the given process.
std::vector< NumLib::LocalToGlobalIndexMap const * > toNonOwning(std::vector< std::unique_ptr< NumLib::LocalToGlobalIndexMap > > const &dof_tables)
bool isSimulationDomain(MeshLib::Mesh const &mesh, ProcessLib::Process const &process)
std::vector< std::unique_ptr< NumLib::LocalToGlobalIndexMap > > computeDofTablesForSubmesh(ProcessLib::Process const &process, MeshLib::Mesh const &submesh, std::size_t const n_processes)
std::vector< std::reference_wrapper< const std::vector< std::reference_wrapper< ProcessLib::ProcessVariable > > > > getProcessVariablesOfAllProcesses(ProcessLib::Process const &process, std::size_t const n_processes)
decltype(auto) computeOutputMeshDofTables(ProcessLib::Process const &process, MeshLib::Mesh const &output_mesh, std::vector< NumLib::LocalToGlobalIndexMap const * > const &bulk_mesh_dof_tables)
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const * getIntegrationPointWriters(ProcessLib::Process const &process, MeshLib::Mesh const &output_mesh)
std::vector< NumLib::LocalToGlobalIndexMap const * > getDofTablesOfAllProcesses(ProcessLib::Process const &process, std::size_t const n_processes)