10#include <range/v3/range/conversion.hpp>
11#include <unordered_map>
30 auto const& nodes = subdomain_mesh.
getNodes();
31 std::vector<MathLib::Point3dWithID*> subdomain_points{begin(nodes),
34 auto const& bulk_node_ids =
40 "Expected to find exactly one node in the bulk mesh for each node "
41 "of the subdomain; Found {:d} nodes in the bulk mesh out of {:d} "
42 "nodes in the subdomain.",
53 std::vector<std::size_t>
const& node_ids,
54 std::vector<std::vector<std::size_t>>
const& connected_element_ids_per_node)
59 std::unordered_map<std::size_t, int> element_counts(8);
60 for (
auto const node_id : node_ids)
62 for (
auto const element_id : connected_element_ids_per_node[node_id])
64 element_counts[element_id]++;
72 auto const nnodes = node_ids.size();
73 std::vector<std::size_t> element_ids;
74 for (
auto const& pair : element_counts)
76 if (pair.second ==
static_cast<int>(nnodes))
78 element_ids.push_back(pair.first);
94 std::vector<std::vector<std::size_t>> bulk_element_ids_map(
98 std::vector<std::vector<std::size_t>> connected_element_ids_per_node(
102 connected_element_ids_per_node[node_id] =
107 auto const& elements = subdomain_mesh.
getElements();
108#pragma omp parallel for
109 for (std::ptrdiff_t j = 0; j < std::ssize(elements); ++j)
111 auto*
const e = elements[j];
112 std::vector<std::size_t> element_node_ids(e->getNumberOfBaseNodes());
113 for (
unsigned n = 0; n < e->getNumberOfBaseNodes(); ++n)
117 std::vector<std::size_t> element_node_ids_bulk(
118 e->getNumberOfBaseNodes());
119 std::transform(begin(element_node_ids), end(element_node_ids),
120 begin(element_node_ids_bulk),
121 [&bulk_node_ids](std::size_t
const id)
122 {
return bulk_node_ids[id]; });
125 element_node_ids_bulk, connected_element_ids_per_node);
127 if (bulk_element_ids.empty())
129 ERR(
"No element could be found for the subdomain element {:d}. "
130 "Corresponding bulk mesh node ids are:",
132 for (
auto const i : element_node_ids_bulk)
137 "Expect at least one element to be found in the bulk mesh.");
140 bulk_element_ids_map[e->getID()] = std::move(bulk_element_ids);
143 return bulk_element_ids_map;
149 std::vector<std::size_t>
const& values,
153 if (!properties.existsPropertyVector<std::size_t>(property_name))
155 addPropertyToMesh(mesh, property_name, mesh_item_type, 1, values);
162 auto& original_property =
163 *properties.getPropertyVector<std::size_t>(property_name);
164 if (std::equal(begin(original_property), end(original_property),
165 begin(values), end(values)))
168 "There is already a '{:s}' property present in the subdomain mesh "
169 "'{:s}' and it is equal to the newly computed values.",
170 property_name, mesh.
getName());
178 "There is already a '{:s}' property present in the subdomain mesh "
179 "'{:s}' and it is not equal to the newly computed values.",
183 if (!force_overwrite)
185 OGS_FATAL(
"The force overwrite flag was not specified, exiting.");
188 INFO(
"Overwriting '{:s}' property.", property_name);
189 original_property.resize(values.size());
190 std::copy(begin(values), end(values), begin(original_property));
199 bool const force_overwrite =
false)
203 auto const& bulk_node_ids =
204 identifySubdomainMeshNodes(subdomain_mesh, mesh_node_searcher);
205 INFO(
"identifySubdomainMesh(): identifySubdomainMeshNodes took {:g} s",
208 updateOrCheckExistingSubdomainProperty(
213 auto const& bulk_element_ids =
214 identifySubdomainMeshElements(subdomain_mesh, bulk_mesh);
215 INFO(
"identifySubdomainMesh(): identifySubdomainMeshElements took {:g} s",
223 if (all_of(begin(bulk_element_ids), end(bulk_element_ids),
224 [](std::vector<std::size_t>
const& v) {
return v.size() == 1; }))
228 std::vector<std::size_t> unique_bulk_element_ids;
229 unique_bulk_element_ids.reserve(bulk_element_ids.size());
230 transform(begin(bulk_element_ids), end(bulk_element_ids),
231 back_inserter(unique_bulk_element_ids),
232 [](std::vector<std::size_t>
const& v) {
return v[0]; });
234 updateOrCheckExistingSubdomainProperty(
245 std::vector<std::size_t> flat_bulk_element_ids;
246 flat_bulk_element_ids.reserve(2 * bulk_element_ids.size());
247 std::vector<std::size_t> number_of_bulk_element_ids;
248 number_of_bulk_element_ids.reserve(bulk_element_ids.size());
250 for (std::vector<std::size_t>
const& v : bulk_element_ids)
252 number_of_bulk_element_ids.push_back(v.size());
253 flat_bulk_element_ids.insert(end(flat_bulk_element_ids), begin(v),
257 updateOrCheckExistingSubdomainProperty(
258 subdomain_mesh,
"number_bulk_elements", number_of_bulk_element_ids,
260 updateOrCheckExistingSubdomainProperty(
Definition of the Element class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
Definition of the Node class.
Definition of the RunTime class.
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
const std::string getName() const
Get name of the mesh.
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
std::size_t getNumberOfElements() const
Get the number of elements.
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
std::size_t getNodeIndex(Element const &element, unsigned const idx)
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
std::vector< std::size_t > identifySubdomainMeshNodes(MeshLib::Mesh const &subdomain_mesh, MeshGeoToolsLib::MeshNodeSearcher const &mesh_node_searcher)
void updateOrCheckExistingSubdomainProperty(MeshLib::Mesh &mesh, std::string_view property_name, std::vector< std::size_t > const &values, MeshLib::MeshItemType const mesh_item_type, bool const force_overwrite)
Updates or checks the existing mesh's property with the given values.
std::vector< std::vector< std::size_t > > identifySubdomainMeshElements(MeshLib::Mesh const &subdomain_mesh, MeshLib::Mesh const &bulk_mesh)
std::vector< std::size_t > findElementsInMesh(std::vector< std::size_t > const &node_ids, std::vector< std::vector< std::size_t > > const &connected_element_ids_per_node)