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] =
108 std::vector<std::size_t> element_node_ids(e->getNumberOfBaseNodes());
109 for (
unsigned n = 0; n < e->getNumberOfBaseNodes(); ++n)
113 std::vector<std::size_t> element_node_ids_bulk(
114 e->getNumberOfBaseNodes());
115 std::transform(begin(element_node_ids), end(element_node_ids),
116 begin(element_node_ids_bulk),
117 [&bulk_node_ids](std::size_t
const id)
118 {
return bulk_node_ids[id]; });
121 element_node_ids_bulk, connected_element_ids_per_node);
123 if (bulk_element_ids.empty())
125 ERR(
"No element could be found for the subdomain element {:d}. "
126 "Corresponding bulk mesh node ids are:",
128 for (
auto const i : element_node_ids_bulk)
133 "Expect at least one element to be found in the bulk mesh.");
136 bulk_element_ids_map[e->getID()] = std::move(bulk_element_ids);
139 return bulk_element_ids_map;
145 std::vector<std::size_t>
const& values,
149 if (!properties.existsPropertyVector<std::size_t>(property_name))
151 addPropertyToMesh(mesh, property_name, mesh_item_type, 1, values);
158 auto& original_property =
160 if (std::equal(begin(original_property), end(original_property),
161 begin(values), end(values)))
164 "There is already a '{:s}' property present in the subdomain mesh "
165 "'{:s}' and it is equal to the newly computed values.",
166 property_name, mesh.
getName());
174 "There is already a '{:s}' property present in the subdomain mesh "
175 "'{:s}' and it is not equal to the newly computed values.",
179 if (!force_overwrite)
181 OGS_FATAL(
"The force overwrite flag was not specified, exiting.");
184 INFO(
"Overwriting '{:s}' property.", property_name);
185 original_property.resize(values.size());
186 std::copy(begin(values), end(values), begin(original_property));
195 bool const force_overwrite =
false)
199 auto const& bulk_node_ids =
200 identifySubdomainMeshNodes(subdomain_mesh, mesh_node_searcher);
201 INFO(
"identifySubdomainMesh(): identifySubdomainMeshNodes took {:g} s",
204 updateOrCheckExistingSubdomainProperty(
209 auto const& bulk_element_ids =
210 identifySubdomainMeshElements(subdomain_mesh, bulk_mesh);
211 INFO(
"identifySubdomainMesh(): identifySubdomainMeshElements took {:g} s",
219 if (all_of(begin(bulk_element_ids), end(bulk_element_ids),
220 [](std::vector<std::size_t>
const& v) {
return v.size() == 1; }))
224 std::vector<std::size_t> unique_bulk_element_ids;
225 unique_bulk_element_ids.reserve(bulk_element_ids.size());
226 transform(begin(bulk_element_ids), end(bulk_element_ids),
227 back_inserter(unique_bulk_element_ids),
228 [](std::vector<std::size_t>
const& v) {
return v[0]; });
230 updateOrCheckExistingSubdomainProperty(
241 std::vector<std::size_t> flat_bulk_element_ids;
242 flat_bulk_element_ids.reserve(2 * bulk_element_ids.size());
243 std::vector<std::size_t> number_of_bulk_element_ids;
244 number_of_bulk_element_ids.reserve(bulk_element_ids.size());
246 for (std::vector<std::size_t>
const& v : bulk_element_ids)
248 number_of_bulk_element_ids.push_back(v.size());
249 flat_bulk_element_ids.insert(end(flat_bulk_element_ids), begin(v),
253 updateOrCheckExistingSubdomainProperty(
254 subdomain_mesh,
"number_bulk_elements", number_of_bulk_element_ids,
256 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.
PropertyVector< T > const * getPropertyVector(std::string_view name) const
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)