OGS
AssemblyMixin.cpp
Go to the documentation of this file.
1
11#include "AssemblyMixin.h"
12
13#include <unordered_set>
14
17
18namespace
19{
20std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>
22 MeshLib::Mesh& mesh,
23 std::vector<std::string> const& residuum_names,
24 std::vector<std::reference_wrapper<ProcessLib::ProcessVariable>>
25 pvs)
26{
27 auto const num_residua = residuum_names.size();
28
29 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>
30 residuum_vectors;
31 residuum_vectors.reserve(num_residua);
32
33 for (std::size_t i = 0; i < num_residua; ++i)
34 {
35 auto const& residuum_name = residuum_names[i];
36 auto const& pv = pvs[i].get();
37
38 residuum_vectors.emplace_back(*MeshLib::getOrCreateMeshProperty<double>(
39 mesh, residuum_name, MeshLib::MeshItemType::Node,
40 pv.getNumberOfGlobalComponents()));
41 }
42
43 return residuum_vectors;
44}
45} // namespace
46
47namespace ProcessLib
48{
50 MeshLib::Mesh const& mesh,
51 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>&&
52 residuum_vectors)
53 : bulk_element_ids{*MeshLib::bulkElementIDs(mesh)},
54 bulk_node_ids{*MeshLib::bulkNodeIDs(mesh)},
55 residuum_vectors{std::move(residuum_vectors)}
56{
57}
58
60 const int process_id,
61 MeshLib::Mesh& bulk_mesh,
62 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& submeshes,
63 std::vector<std::string> const& residuum_names,
64 std::vector<std::reference_wrapper<ProcessVariable>> const& pvs)
65{
66 DBUG("AssemblyMixinBase initializeSubmeshOutput().");
67
68 auto const num_residua = residuum_names.size();
69
70 if (pvs.size() != num_residua)
71 {
73 "The number of passed residuum names does not match the number "
74 "of process variables for process id {}: {} != {}",
75 process_id, num_residua, pvs.size());
76 }
77
78 submesh_assembly_data_.reserve(submeshes.size());
79 for (auto& mesh_ref : submeshes)
80 {
81 auto& mesh = mesh_ref.get();
82
83 submesh_assembly_data_.emplace_back(
84 mesh, createResiduumVectors(mesh, residuum_names, pvs));
85 }
86
88 createResiduumVectors(bulk_mesh, residuum_names, pvs);
89}
90
93{
94 DBUG("AssemblyMixinBase updateActiveElements().");
95
97 {
99 return;
100 }
101
102 ActiveElementIDsState const new_state =
103 pv.getActiveElementIDs().empty()
106
109 {
110 // no update necessary
111 return;
112 }
113
114 // updating the active elements is necessary in all remaining cases, because
115 // of the following transitions between old and new states (deactivated
116 // subdomains present? yes/no; old state -> new state):
117 // * no -> yes - now there are deactivated subdomains
118 // * yes -> no - no deactivated subdomains anymore
119 // * yes -> yes - deactivated subdomains might have changed
121}
122
125{
126 DBUG("AssemblyMixinBase updateActiveElementsImpl().");
127
128 auto const& active_element_ids = pv.getActiveElementIDs();
129
130 ActiveElementIDsState const new_state =
131 active_element_ids.empty()
134
136 {
137 // no deactivated subdomains, assemble on all elements as specified
138 // in the bulk_element_ids of the submeshes
139 for (auto& sad : submesh_assembly_data_)
140 {
141 // note: this copies the ID vector!
142 sad.active_element_ids = sad.bulk_element_ids;
143 }
144 }
145 else
146 {
147 // assemble each submesh on the intersection of the "global" active
148 // elements and the submesh
149 std::unordered_set<std::size_t> active_element_ids_set(
150 active_element_ids.begin(), active_element_ids.end());
151
152 for (auto& sad : submesh_assembly_data_)
153 {
154 auto& aeis = sad.active_element_ids;
155 auto& beis = sad.bulk_element_ids;
156 aeis.clear();
157 aeis.reserve(beis.getNumberOfTuples());
158
159 for (auto bei : beis)
160 {
161 if (active_element_ids_set.contains(bei))
162 {
163 aeis.push_back(bei);
164 }
165 }
166 }
167 }
168
169 ids_state_ = new_state;
170}
171
173 GlobalVector const& rhs,
174 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
175 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>
176 residuum_vectors)
177{
178 for (std::size_t variable_id = 0; variable_id < residuum_vectors.size();
179 ++variable_id)
180 {
181 transformVariableFromGlobalVector(
182 rhs, variable_id, local_to_global_index_map,
183 residuum_vectors[variable_id].get(), std::negate<double>());
184 }
185}
186
188 GlobalVector const& rhs,
189 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
190 SubmeshAssemblyData const& sad)
191{
192 for (std::size_t variable_id = 0; variable_id < sad.residuum_vectors.size();
193 ++variable_id)
194 {
195 transformVariableFromGlobalVector(
196 rhs, variable_id, local_to_global_index_map,
197 sad.residuum_vectors[variable_id].get(), sad.bulk_node_ids,
198 std::negate<double>());
199 }
200}
201
202} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Global vector based on Eigen vector.
Definition EigenVector.h:25
void updateActiveElementsImpl(ProcessLib::ProcessVariable const &pv)
static void copyResiduumVectorsToSubmesh(GlobalVector const &rhs, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, SubmeshAssemblyData const &sad)
std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > residuum_vectors_bulk_
static void copyResiduumVectorsToBulkMesh(GlobalVector const &rhs, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > residuum_vectors)
void initializeAssemblyOnSubmeshes(const int process_id, MeshLib::Mesh &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submeshes, std::vector< std::string > const &residuum_names, std::vector< std::reference_wrapper< ProcessVariable > > const &pvs)
void updateActiveElements(ProcessLib::ProcessVariable const &pv)
ActiveElementIDsState ids_state_
std::vector< SubmeshAssemblyData > submesh_assembly_data_
std::vector< std::size_t > const & getActiveElementIDs() const
std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > createResiduumVectors(MeshLib::Mesh &mesh, std::vector< std::string > const &residuum_names, std::vector< std::reference_wrapper< ProcessLib::ProcessVariable > > pvs)
SubmeshAssemblyData(MeshLib::Mesh const &mesh, std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > &&residuum_vectors)
MeshLib::PropertyVector< std::size_t > const & bulk_node_ids
std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > residuum_vectors