Loading [MathJax]/extensions/MathMenu.js
OGS
anonymous_namespace{SubmeshResiduumOutputConfig.cpp} Namespace Reference

Functions

std::vector< std::reference_wrapper< MeshLib::Mesh > > filterMeshesForResiduumOutput (std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes, std::vector< std::string > const &mesh_names_for_output)
 
bool areElementsUnique (std::vector< std::string > const &strings)
 
void checkBulkIDMappingsPresent (MeshLib::Mesh const &mesh)
 
void checkMatchingElementCounts (MeshLib::Mesh const &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submesh_refs)
 
std::vector< bool > computeNonOverlappingBulkMeshCoverBySubmeshes (MeshLib::Mesh const &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submesh_refs)
 
void checkNonOverlappingCover (MeshLib::Mesh const &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submesh_refs)
 

Function Documentation

◆ areElementsUnique()

bool anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::areElementsUnique ( std::vector< std::string > const & strings)

Definition at line 53 of file SubmeshResiduumOutputConfig.cpp.

54{
55 std::unordered_set<std::string_view> const strings_set(strings.begin(),
56 strings.end());
57
58 return strings_set.size() == strings.size();
59}

◆ checkBulkIDMappingsPresent()

void anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::checkBulkIDMappingsPresent ( MeshLib::Mesh const & mesh)

Definition at line 61 of file SubmeshResiduumOutputConfig.cpp.

62{
63 auto const& properties = mesh.getProperties();
64
65 if (!properties.existsPropertyVector<std::size_t>(
68 {
70 "The required nodal property '{}' is missing in mesh '{}' or has "
71 "the wrong data type or the wrong number of components",
73 mesh.getName());
74 }
75
76 if (!properties.existsPropertyVector<std::size_t>(
79 {
81 "The required cell property '{}' is missing in mesh '{}' or has "
82 "the wrong data type or the wrong number of components",
84 mesh.getName());
85 }
86}
#define OGS_FATAL(...)
Definition Error.h:26
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:185

References MeshLib::Cell, MeshLib::getBulkIDString(), MeshLib::Mesh::getName(), MeshLib::Mesh::getProperties(), MeshLib::Node, and OGS_FATAL.

◆ checkMatchingElementCounts()

void anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::checkMatchingElementCounts ( MeshLib::Mesh const & bulk_mesh,
std::vector< std::reference_wrapper< MeshLib::Mesh > > const & submesh_refs )

Definition at line 88 of file SubmeshResiduumOutputConfig.cpp.

91{
92 auto const n_elements_bulk = bulk_mesh.getNumberOfElements();
93 auto const sum_elements_submeshes = [&submesh_refs]()
94 {
95 std::size_t n = 0;
96 for (auto const& submesh_ref : submesh_refs)
97 {
98 n += submesh_ref.get().getNumberOfElements();
99 }
100 return n;
101 }();
102
103 if (n_elements_bulk != sum_elements_submeshes)
104 {
105 OGS_FATAL(
106 "The number of bulk mesh elements does not match the sum of all "
107 "submesh elements: {} != {}. Hence, the set of all submeshes "
108 "cannot be a non-overlapping cover of the bulk mesh.",
109 n_elements_bulk, sum_elements_submeshes);
110 }
111}

References MeshLib::Mesh::getNumberOfElements(), and OGS_FATAL.

Referenced by checkNonOverlappingCover().

◆ checkNonOverlappingCover()

void anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::checkNonOverlappingCover ( MeshLib::Mesh const & bulk_mesh,
std::vector< std::reference_wrapper< MeshLib::Mesh > > const & submesh_refs )

Definition at line 173 of file SubmeshResiduumOutputConfig.cpp.

176{
177 checkMatchingElementCounts(bulk_mesh, submesh_refs);
178
179 auto const n_elements_bulk = bulk_mesh.getNumberOfElements();
180
181 std::vector<bool> const bulk_element_covered =
182 computeNonOverlappingBulkMeshCoverBySubmeshes(bulk_mesh, submesh_refs);
183
184 auto const n_elements_covered =
185 std::accumulate(bulk_element_covered.begin(),
186 bulk_element_covered.end(), std::size_t{0});
187
188 if (n_elements_covered == n_elements_bulk)
189 {
190 return;
191 }
192
193 // search first bulk element that has not been covered
194 auto const non_covered_it = std::find(bulk_element_covered.begin(),
195 bulk_element_covered.end(), false);
196 auto const non_covered_index =
197 std::distance(bulk_element_covered.begin(), non_covered_it);
198
199 OGS_FATAL(
200 "The bulk mesh ('{}') is not covered completely by the given "
201 "submeshes. Only {} out of {} elements are covered. The first element "
202 "that is not covered is #{}.",
203 bulk_mesh.getName(), n_elements_covered, n_elements_bulk,
204 non_covered_index);
205}
void checkMatchingElementCounts(MeshLib::Mesh const &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submesh_refs)
std::vector< bool > computeNonOverlappingBulkMeshCoverBySubmeshes(MeshLib::Mesh const &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submesh_refs)

References checkMatchingElementCounts(), computeNonOverlappingBulkMeshCoverBySubmeshes(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), and OGS_FATAL.

◆ computeNonOverlappingBulkMeshCoverBySubmeshes()

std::vector< bool > anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::computeNonOverlappingBulkMeshCoverBySubmeshes ( MeshLib::Mesh const & bulk_mesh,
std::vector< std::reference_wrapper< MeshLib::Mesh > > const & submesh_refs )

Definition at line 113 of file SubmeshResiduumOutputConfig.cpp.

116{
117 auto const n_elements_bulk = bulk_mesh.getNumberOfElements();
118
119 std::vector<bool> bulk_element_covered(n_elements_bulk);
120
121 for (auto const& submesh_ref : submesh_refs)
122 {
123 auto const& submesh = submesh_ref.get();
124 auto const& bulk_element_ids = bulkElementIDs(submesh);
125 if (bulk_element_ids == nullptr)
126 {
127 OGS_FATAL(
128 "The 'bulk_element_ids' property does not exist on the submesh "
129 "{:s}.",
130 submesh.getName());
131 }
132
133 if (bulk_element_ids->size() != submesh.getNumberOfElements())
134 {
135 OGS_FATAL(
136 "There is something terribly wrong with the mesh '{}'. The "
137 "size of 'bulk_element_ids' does not equal the number of "
138 "elements in the mesh: {} != {}",
139 submesh.getName(), bulk_element_ids->size(),
140 submesh.getNumberOfElements());
141 }
142
143 for (auto const bulk_element_id : *bulk_element_ids)
144 {
145 // meshes are provided as user input, so we better check the bounds
146 // of the contained data
147 [[unlikely]] if (bulk_element_id >= n_elements_bulk)
148 {
149 OGS_FATAL(
150 "Saw bulk element id {} in submesh '{}', but the bulk mesh "
151 "('{}') has only {} elements, i.e., the maximum allowed "
152 "bulk element id is {}.",
153 bulk_element_id, submesh.getName(), bulk_mesh.getName(),
154 n_elements_bulk, n_elements_bulk - 1);
155 }
156
157 [[unlikely]] if (bulk_element_covered[bulk_element_id])
158 {
159 OGS_FATAL(
160 "The bulk element id {} has already been covered by "
161 "another submesh. The second submesh covering this bulk "
162 "element is '{}'.",
163 bulk_element_id, submesh.getName());
164 }
165
166 bulk_element_covered[bulk_element_id] = true;
167 }
168 }
169
170 return bulk_element_covered;
171}

References MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), and OGS_FATAL.

Referenced by checkNonOverlappingCover().

◆ filterMeshesForResiduumOutput()

std::vector< std::reference_wrapper< MeshLib::Mesh > > anonymous_namespace{SubmeshResiduumOutputConfig.cpp}::filterMeshesForResiduumOutput ( std::vector< std::unique_ptr< MeshLib::Mesh > > const & meshes,
std::vector< std::string > const & mesh_names_for_output )

Definition at line 22 of file SubmeshResiduumOutputConfig.cpp.

25{
26 std::map<std::string, std::reference_wrapper<MeshLib::Mesh>>
27 map_mesh_name_to_mesh;
28 for (auto const& mesh : meshes)
29 {
30 auto const [it, inserted] =
31 map_mesh_name_to_mesh.emplace(mesh->getName(), *mesh);
32
33 if (!inserted)
34 {
35 OGS_FATAL("Duplicate mesh name '{}' detected.", mesh->getName());
36 }
37 }
38
39 std::vector<std::reference_wrapper<MeshLib::Mesh>> meshes_filtered;
40
41 for (auto const& mesh_name : mesh_names_for_output)
42 {
43 auto const& mesh = BaseLib::getOrError(
44 map_mesh_name_to_mesh, mesh_name,
45 "A mesh that has been requested for output is not known to OGS.");
46
47 meshes_filtered.push_back(mesh);
48 }
49
50 return meshes_filtered;
51}
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:118

References BaseLib::getOrError(), and OGS_FATAL.