OGS
ProcessOutputData.cpp
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#include "ProcessOutputData.h"
5
7
8namespace
9{
13 ProcessLib::Process const& process)
14{
15 return mesh == process.getMesh();
16}
17
18std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>
20 MeshLib::Mesh const& submesh,
21 std::size_t const n_processes)
22{
23 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>
24 submesh_dof_tables;
25 submesh_dof_tables.reserve(n_processes);
26
27 for (std::size_t i = 0; i < n_processes; ++i)
28 {
29 submesh_dof_tables.push_back(
31 MeshLib::MeshSubset{submesh, submesh.getNodes()}));
32 }
33
34 return submesh_dof_tables;
35}
36
37std::vector<NumLib::LocalToGlobalIndexMap const*> toNonOwning(
38 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>> const&
39 dof_tables)
40{
41 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_table_pointers;
42
43 dof_table_pointers.reserve(dof_tables.size());
44 transform(cbegin(dof_tables), cend(dof_tables),
45 back_inserter(dof_table_pointers),
46 [](std::unique_ptr<NumLib::LocalToGlobalIndexMap> const& p)
47 { return p.get(); });
48
49 return dof_table_pointers;
50}
51
52std::vector<NumLib::LocalToGlobalIndexMap const*> getDofTablesOfAllProcesses(
53 ProcessLib::Process const& process, std::size_t const n_processes)
54{
55 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables_of_all_procs(
56 n_processes);
57
58 for (std::size_t proc_id = 0; proc_id < n_processes; ++proc_id)
59 {
60 dof_tables_of_all_procs[proc_id] = &process.getDOFTable(proc_id);
61 }
62
63 return dof_tables_of_all_procs;
64}
65
78 ProcessLib::Process const& process,
79 MeshLib::Mesh const& output_mesh,
80 std::vector<NumLib::LocalToGlobalIndexMap const*> const&
81 bulk_mesh_dof_tables)
82{
83 if (isSimulationDomain(output_mesh, process))
84 {
85 return std::pair(
86 bulk_mesh_dof_tables /* will be copied */,
87 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>{});
88 }
89
90 auto const n_processes = bulk_mesh_dof_tables.size();
91
92 // TODO Currently these d.o.f. tables will be recomputed every time we write
93 // output. That should be avoided in the future.
94 auto container_that_owns_output_mesh_dof_tables =
95 computeDofTablesForSubmesh(process, output_mesh, n_processes);
96
97 auto output_mesh_dof_tables =
98 toNonOwning(container_that_owns_output_mesh_dof_tables);
99
100 return std::pair(std::move(output_mesh_dof_tables),
101 std::move(container_that_owns_output_mesh_dof_tables));
102}
103
104std::vector<std::reference_wrapper<
105 const std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>>>
107 std::size_t const n_processes)
108{
109 std::vector<std::reference_wrapper<
110 const std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>>>
111 pvs_of_all_procs;
112 pvs_of_all_procs.reserve(n_processes);
113
114 for (std::size_t proc_id = 0; proc_id < n_processes; ++proc_id)
115 {
116 pvs_of_all_procs.emplace_back(process.getProcessVariables(proc_id));
117 }
118
119 return pvs_of_all_procs;
120}
121
122std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>> const*
124 MeshLib::Mesh const& output_mesh)
125{
126 return isSimulationDomain(output_mesh, process)
127 ? &process.getIntegrationPointWriters()
128 : nullptr;
129}
130
131} // namespace
132
133namespace ProcessLib
134{
135
137 std::size_t const n_processes,
138 MeshLib::Mesh& output_mesh)
139{
140 auto bulk_mesh_dof_tables =
141 getDofTablesOfAllProcesses(process, n_processes);
142
143 auto [output_mesh_dof_tables, container_that_owns_output_mesh_dof_tables] =
144 computeOutputMeshDofTables(process, output_mesh, bulk_mesh_dof_tables);
145
146 return {getProcessVariablesOfAllProcesses(process, n_processes),
147 process.getSecondaryVariables(),
148 ::getIntegrationPointWriters(process, output_mesh),
149 std::move(bulk_mesh_dof_tables),
150 std::move(output_mesh_dof_tables),
151 std::move(container_that_owns_output_mesh_dof_tables),
152 output_mesh};
153}
154
156 std::vector<std::reference_wrapper<
157 const std::vector<std::reference_wrapper<ProcessVariable>>>>&&
158 process_variables_of_all_processes,
159 const SecondaryVariableCollection& secondary_variables,
160 const std::vector<std::unique_ptr<MeshLib::IntegrationPointWriter>>*
161 integration_point_writers,
162 std::vector<const NumLib::LocalToGlobalIndexMap*>&&
163 bulk_mesh_dof_tables_of_all_processes,
164 std::vector<const NumLib::LocalToGlobalIndexMap*>&&
165 output_mesh_dof_tables_of_all_processes,
166 std::vector<std::unique_ptr<NumLib::LocalToGlobalIndexMap>>&&
167 container_that_owns_output_mesh_dof_tables,
168 MeshLib::Mesh& output_mesh)
170 std::move(process_variables_of_all_processes)),
171 secondary_variables_(secondary_variables),
172 integration_point_writers_(integration_point_writers),
174 std::move(bulk_mesh_dof_tables_of_all_processes)),
176 std::move(output_mesh_dof_tables_of_all_processes)),
178 std::move(container_that_owns_output_mesh_dof_tables)),
179 output_mesh_(output_mesh)
180{
181 auto const n_proc_pvs = process_variables_of_all_processes_.size();
182 auto const n_proc_bulk = bulk_mesh_dof_tables_of_all_processes_.size();
183 auto const n_proc_out = output_mesh_dof_tables_of_all_processes_.size();
184 auto const n_proc_own = container_that_owns_output_mesh_dof_tables_.size();
185
186 if (n_proc_pvs != n_proc_bulk)
187 {
188 OGS_FATAL(
189 "Mismatch in number of processes (PVs vs. bulk mesh d.o.f. "
190 "tables): {} != {}",
191 n_proc_pvs, n_proc_bulk);
192 }
193
194 if (n_proc_pvs != n_proc_out)
195 {
196 OGS_FATAL(
197 "Mismatch in number of processes (PVs vs. output mesh d.o.f. "
198 "tables): {} != {}",
199 n_proc_pvs, n_proc_out);
200 }
201
202 // n_proc_own is nonzero only for submesh output
203 if (n_proc_own != 0 && n_proc_pvs != n_proc_own)
204 {
205 OGS_FATAL(
206 "Mismatch in number of processes (PVs vs. output mesh d.o.f. "
207 "tables, owning): {} != {}",
208 n_proc_pvs, n_proc_own);
209 }
210}
211
212} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
A subset of nodes on a single mesh.
Definition MeshSubset.h:17
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_
SecondaryVariableCollection const & secondary_variables_
std::vector< NumLib::LocalToGlobalIndexMap const * > output_mesh_dof_tables_of_all_processes_
std::vector< std::unique_ptr< MeshLib::IntegrationPointWriter > > const * integration_point_writers_
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:171
MeshLib::Mesh & getMesh() const
Definition Process.h:146
SecondaryVariableCollection const & getSecondaryVariables() const
Definition Process.h:165
virtual NumLib::LocalToGlobalIndexMap const & getDOFTable(const int) const
Definition Process.h:140
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const & getProcessVariables() const
Definition Process.h:149
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)