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:188

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 168 of file SubmeshResiduumOutputConfig.cpp.

171{
172 checkMatchingElementCounts(bulk_mesh, submesh_refs);
173
174 auto const n_elements_bulk = bulk_mesh.getNumberOfElements();
175
176 std::vector<bool> const bulk_element_covered =
177 computeNonOverlappingBulkMeshCoverBySubmeshes(bulk_mesh, submesh_refs);
178
179 auto const n_elements_covered =
180 std::accumulate(bulk_element_covered.begin(),
181 bulk_element_covered.end(), std::size_t{0});
182
183 if (n_elements_covered == n_elements_bulk)
184 {
185 return;
186 }
187
188 // search first bulk element that has not been covered
189 auto const non_covered_it = std::find(bulk_element_covered.begin(),
190 bulk_element_covered.end(), false);
191 auto const non_covered_index =
192 std::distance(bulk_element_covered.begin(), non_covered_it);
193
194 OGS_FATAL(
195 "The bulk mesh ('{}') is not covered completely by the given "
196 "submeshes. Only {} out of {} elements are covered. The first element "
197 "that is not covered is #{}.",
198 bulk_mesh.getName(), n_elements_covered, n_elements_bulk,
199 non_covered_index);
200}
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 =
125 *submesh.getProperties().getPropertyVector<std::size_t>(
126 "bulk_element_ids", MeshLib::MeshItemType::Cell, 1);
127
128 if (bulk_element_ids.size() != submesh.getNumberOfElements())
129 {
130 OGS_FATAL(
131 "There is something terribly wrong with the mesh '{}'. The "
132 "size of 'bulk_element_ids' does not equal the number of "
133 "elements in the mesh: {} != {}",
134 submesh.getName(), bulk_element_ids.size(),
135 submesh.getNumberOfElements());
136 }
137
138 for (auto const bulk_element_id : bulk_element_ids)
139 {
140 // meshes are provided as user input, so we better check the bounds
141 // of the contained data
142 [[unlikely]] if (bulk_element_id >= n_elements_bulk)
143 {
144 OGS_FATAL(
145 "Saw bulk element id {} in submesh '{}', but the bulk mesh "
146 "('{}') has only {} elements, i.e., the maximum allowed "
147 "bulk element id is {}.",
148 bulk_element_id, submesh.getName(), bulk_mesh.getName(),
149 n_elements_bulk, n_elements_bulk - 1);
150 }
151
152 [[unlikely]] if (bulk_element_covered[bulk_element_id])
153 {
154 OGS_FATAL(
155 "The bulk element id {} has already been covered by "
156 "another submesh. The second submesh covering this bulk "
157 "element is '{}'.",
158 bulk_element_id, submesh.getName());
159 }
160
161 bulk_element_covered[bulk_element_id] = true;
162 }
163 }
164
165 return bulk_element_covered;
166}

References MeshLib::Cell, 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}
Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:113

References BaseLib::getOrError(), and OGS_FATAL.