27 auto const& nodes = subdomain_mesh.
getNodes();
28 std::vector<MathLib::Point3dWithID*> subdomain_points{begin(nodes),
31 auto const& bulk_node_ids =
37 "Expected to find exactly one node in the bulk mesh for each node "
38 "of the subdomain; Found {:d} nodes in the bulk mesh out of {:d} "
39 "nodes in the subdomain.",
50 MeshLib::Mesh const& mesh, std::vector<std::size_t>
const& node_ids)
55 std::vector<std::size_t> common_element_ids;
57 auto const nnodes = node_ids.size();
58 common_element_ids.reserve(nnodes);
60 for (
auto const node_id : node_ids)
62 auto const& connected_elements =
64 std::transform(begin(connected_elements), end(connected_elements),
65 back_inserter(common_element_ids),
67 {
return e->
getID(); });
73 std::map<std::size_t, int> element_counts;
74 for (
auto const element_id : common_element_ids)
76 element_counts[element_id]++;
83 std::vector<std::size_t> element_ids;
84 for (
auto const& pair : element_counts)
86 if (pair.second ==
static_cast<int>(nnodes))
88 element_ids.push_back(pair.first);
106 std::vector<std::vector<std::size_t>> bulk_element_ids_map(
111 std::vector<std::size_t> element_node_ids(e->getNumberOfBaseNodes());
112 for (
unsigned n = 0; n < e->getNumberOfBaseNodes(); ++n)
116 std::vector<std::size_t> element_node_ids_bulk(
117 e->getNumberOfBaseNodes());
118 std::transform(begin(element_node_ids), end(element_node_ids),
119 begin(element_node_ids_bulk),
120 [&bulk_node_ids](std::size_t
const id)
121 {
return bulk_node_ids[id]; });
122 std::vector<std::size_t> bulk_element_ids =
125 if (bulk_element_ids.empty())
127 ERR(
"No element could be found for the subdomain element {:d}. "
128 "Corresponding bulk mesh node ids are:",
130 for (
auto const i : element_node_ids_bulk)
135 "Expect at least one element to be found in the bulk mesh.");
138 bulk_element_ids_map[e->getID()] = std::move(bulk_element_ids);
141 return bulk_element_ids_map;
147 std::vector<std::size_t>
const& values,
151 if (!properties.existsPropertyVector<std::size_t>(property_name))
160 auto& original_property =
161 *properties.getPropertyVector<std::size_t>(property_name);
162 if (std::equal(begin(original_property), end(original_property),
163 begin(values), end(values)))
166 "There is already a '{:s}' property present in the subdomain mesh "
167 "'{:s}' and it is equal to the newly computed values.",
168 property_name, mesh.
getName());
176 "There is already a '{:s}' property present in the subdomain mesh "
177 "'{:s}' and it is not equal to the newly computed values.",
181 if (!force_overwrite)
183 OGS_FATAL(
"The force overwrite flag was not specified, exiting.");
186 INFO(
"Overwriting '{:s}' property.", property_name);
187 original_property.resize(values.size());
188 std::copy(begin(values), end(values), begin(original_property));
197 bool const force_overwrite =
false)
199 auto const& bulk_node_ids =
203 subdomain_mesh,
"bulk_node_ids", bulk_node_ids,
206 auto const& bulk_element_ids =
214 if (all_of(begin(bulk_element_ids), end(bulk_element_ids),
215 [](std::vector<std::size_t>
const& v) {
return v.size() == 1; }))
219 std::vector<std::size_t> unique_bulk_element_ids;
220 unique_bulk_element_ids.reserve(bulk_element_ids.size());
221 transform(begin(bulk_element_ids), end(bulk_element_ids),
222 back_inserter(unique_bulk_element_ids),
223 [](std::vector<std::size_t>
const& v) {
return v[0]; });
226 subdomain_mesh,
"bulk_element_ids", unique_bulk_element_ids,
234 std::vector<std::size_t> flat_bulk_element_ids;
235 flat_bulk_element_ids.reserve(2 * bulk_element_ids.size());
236 std::vector<std::size_t> number_of_bulk_element_ids;
237 number_of_bulk_element_ids.reserve(bulk_element_ids.size());
239 for (std::vector<std::size_t>
const& v : bulk_element_ids)
241 number_of_bulk_element_ids.push_back(v.size());
242 flat_bulk_element_ids.insert(end(flat_bulk_element_ids), begin(v),
247 subdomain_mesh,
"number_bulk_elements", number_of_bulk_element_ids,
250 subdomain_mesh,
"bulk_element_ids", flat_bulk_element_ids,
Definition of the Element class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
virtual std::size_t getID() const final
Returns the ID of the element.
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.
const std::string getName() const
Get name of the mesh.
Properties & getProperties()
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 const &name) const
void copy(PETScVector const &x, PETScVector &y)
std::size_t getNodeIndex(Element const &element, unsigned const idx)
void addPropertyToMesh(Mesh &mesh, std::string const &name, MeshItemType item_type, std::size_t number_of_components, std::vector< T > const &values)
std::vector< std::size_t > identifySubdomainMeshNodes(MeshLib::Mesh const &subdomain_mesh, MeshGeoToolsLib::MeshNodeSearcher const &mesh_node_searcher)
std::vector< std::vector< std::size_t > > identifySubdomainMeshElements(MeshLib::Mesh const &subdomain_mesh, MeshLib::Mesh const &bulk_mesh)
void updateOrCheckExistingSubdomainProperty(MeshLib::Mesh &mesh, std::string const &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::size_t > findElementsInMesh(MeshLib::Mesh const &mesh, std::vector< std::size_t > const &node_ids)