Loading [MathJax]/jax/input/TeX/config.js
OGS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
anonymous_namespace{IdentifySubdomainMesh.cpp} Namespace Reference

Functions

std::vector< std::size_t > identifySubdomainMeshNodes (MeshLib::Mesh const &subdomain_mesh, MeshGeoToolsLib::MeshNodeSearcher const &mesh_node_searcher)
 
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)
 
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_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.
 

Function Documentation

◆ findElementsInMesh()

std::vector< std::size_t > anonymous_namespace{IdentifySubdomainMesh.cpp}::findElementsInMesh ( std::vector< std::size_t > const & node_ids,
std::vector< std::vector< std::size_t > > const & connected_element_ids_per_node )

Find all elements which consist of all of the given node ids.

Note
It is recommended to include only base nodes of elements into the search node_ids.

Definition at line 53 of file IdentifySubdomainMesh.cpp.

56{
57 //
58 // Count how often an element is shared by all nodes.
59 //
60 std::unordered_map<std::size_t, int> element_counts(8);
61 for (auto const node_id : node_ids)
62 {
63 for (auto const element_id : connected_element_ids_per_node[node_id])
64 {
65 element_counts[element_id]++;
66 }
67 }
68
69 //
70 // Elements which are shared by as many nodes as the input nodes are the
71 // desired elements.
72 //
73 auto const nnodes = node_ids.size();
74 std::vector<std::size_t> element_ids;
75 for (auto const& pair : element_counts)
76 {
77 if (pair.second == static_cast<int>(nnodes))
78 {
79 element_ids.push_back(pair.first);
80 }
81 }
82
83 return element_ids;
84}

Referenced by identifySubdomainMeshElements().

◆ identifySubdomainMeshElements()

std::vector< std::vector< std::size_t > > anonymous_namespace{IdentifySubdomainMesh.cpp}::identifySubdomainMeshElements ( MeshLib::Mesh const & subdomain_mesh,
MeshLib::Mesh const & bulk_mesh )

Tries to find all elements' ids in the bulk mesh. The subdomain elements' nodes are mapped to the bulk mesh and are then used to identify the bulk mesh elements.

Definition at line 89 of file IdentifySubdomainMesh.cpp.

91{
92 auto const& bulk_node_ids = *MeshLib::bulkNodeIDs(subdomain_mesh);
93
94 // Allocate space for all elements for random insertion.
95 std::vector<std::vector<std::size_t>> bulk_element_ids_map(
96 subdomain_mesh.getNumberOfElements());
97
98 // For each node a vector of connected element ids of that node.
99 std::vector<std::vector<std::size_t>> connected_element_ids_per_node(
100 bulk_mesh.getNumberOfNodes());
101 for (auto const node_id : bulk_mesh.getNodes() | MeshLib::views::ids)
102 {
103 connected_element_ids_per_node[node_id] =
104 bulk_mesh.getElementsConnectedToNode(node_id) |
105 MeshLib::views::ids | ranges::to<std::vector>;
106 }
107
108 auto const& elements = subdomain_mesh.getElements();
109#pragma omp parallel for
110 for (std::ptrdiff_t j = 0; j < std::ssize(elements); ++j)
111 {
112 auto* const e = elements[j];
113 std::vector<std::size_t> element_node_ids(e->getNumberOfBaseNodes());
114 for (unsigned n = 0; n < e->getNumberOfBaseNodes(); ++n)
115 {
116 element_node_ids[n] = MeshLib::getNodeIndex(*e, n);
117 }
118 std::vector<std::size_t> element_node_ids_bulk(
119 e->getNumberOfBaseNodes());
120 std::transform(begin(element_node_ids), end(element_node_ids),
121 begin(element_node_ids_bulk),
122 [&bulk_node_ids](std::size_t const id)
123 { return bulk_node_ids[id]; });
124
125 std::vector<std::size_t> bulk_element_ids = findElementsInMesh(
126 element_node_ids_bulk, connected_element_ids_per_node);
127
128 if (bulk_element_ids.empty())
129 {
130 ERR("No element could be found for the subdomain element {:d}. "
131 "Corresponding bulk mesh node ids are:",
132 e->getID());
133 for (auto const i : element_node_ids_bulk)
134 {
135 ERR("\t{:d}", i);
136 }
137 OGS_FATAL(
138 "Expect at least one element to be found in the bulk mesh.");
139 }
140
141 bulk_element_ids_map[e->getID()] = std::move(bulk_element_ids);
142 }
143
144 return bulk_element_ids_map;
145}
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:227
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:219
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
Definition Mesh.cpp:292
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)

References MeshLib::bulkNodeIDs(), ERR(), findElementsInMesh(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::getNodeIndex(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::views::ids, and OGS_FATAL.

◆ identifySubdomainMeshNodes()

std::vector< std::size_t > anonymous_namespace{IdentifySubdomainMesh.cpp}::identifySubdomainMeshNodes ( MeshLib::Mesh const & subdomain_mesh,
MeshGeoToolsLib::MeshNodeSearcher const & mesh_node_searcher )

Find one-to-one mapping of subdomain nodes to the bulk mesh nodes and returns the map of ids.

Definition at line 26 of file IdentifySubdomainMesh.cpp.

29{
30 // Convert nodes pointers needed for the mesh_node_searcher algorithm.
31 auto const& nodes = subdomain_mesh.getNodes();
32 std::vector<MathLib::Point3dWithID*> subdomain_points{begin(nodes),
33 end(nodes)};
34
35 auto const& bulk_node_ids =
36 mesh_node_searcher.getMeshNodeIDs(subdomain_points);
37
38 if (bulk_node_ids.size() != subdomain_mesh.getNumberOfNodes())
39 {
41 "Expected to find exactly one node in the bulk mesh for each node "
42 "of the subdomain; Found {:d} nodes in the bulk mesh out of {:d} "
43 "nodes in the subdomain.",
44 bulk_node_ids.size(), subdomain_mesh.getNumberOfNodes());
45 }
46
47 return bulk_node_ids;
48}

References MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), and OGS_FATAL.

◆ updateOrCheckExistingSubdomainProperty()

void anonymous_namespace{IdentifySubdomainMesh.cpp}::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.

Definition at line 148 of file IdentifySubdomainMesh.cpp.

152{
153 auto& properties = mesh.getProperties();
154 if (!properties.existsPropertyVector<std::size_t>(property_name))
155 {
156 addPropertyToMesh(mesh, property_name, mesh_item_type, 1, values);
157 return;
158 }
159
160 //
161 // Check the existing property against new values.
162 //
163 auto& original_property =
164 *properties.getPropertyVector<std::size_t>(property_name);
165 if (ranges::equal(original_property, values))
166 {
167 INFO(
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());
171 return;
172 }
173
174 //
175 // Property differs. Notify and update if forced.
176 //
177 WARN(
178 "There is already a '{:s}' property present in the subdomain mesh "
179 "'{:s}' and it is not equal to the newly computed values.",
180 property_name,
181 mesh.getName());
182
183 if (!force_overwrite)
184 {
185 OGS_FATAL("The force overwrite flag was not specified, exiting.");
186 }
187
188 INFO("Overwriting '{:s}' property.", property_name);
189 original_property.assign(values.begin(), values.end());
190}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Properties & getProperties()
Definition Mesh.h:136
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:105
PropertyVector< T > const * getPropertyVector(std::string_view name) const

References MeshLib::Mesh::getName(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), INFO(), OGS_FATAL, and WARN().