Loading [MathJax]/extensions/tex2jax.js
OGS
MeshToolsLib::MeshSurfaceExtraction Class Reference

Detailed Description

A set of tools concerned with extracting nodes and elements from a mesh surface.

Definition at line 38 of file MeshSurfaceExtraction.h.

#include <MeshSurfaceExtraction.h>

Static Public Member Functions

static std::vector< double > getSurfaceAreaForNodes (const MeshLib::Mesh &mesh)
 Returns a vector of the areas assigned to each node on a surface mesh.
 
static std::vector< MeshLib::Node * > getSurfaceNodes (const MeshLib::Mesh &mesh, Eigen::Vector3d const &dir, double angle)
 Returns the surface nodes of a mesh.
 
static MeshLib::MeshgetMeshSurface (const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string_view subsfc_node_id_prop_name="", std::string_view subsfc_element_id_prop_name="", std::string_view face_id_prop_name="")
 

Static Private Member Functions

static void get2DSurfaceElements (const std::vector< MeshLib::Element * > &all_elements, std::vector< MeshLib::Element * > &sfc_elements, std::vector< std::size_t > &element_to_bulk_element_id_map, std::vector< std::size_t > &element_to_bulk_face_id_map, Eigen::Vector3d const &dir, double angle, unsigned mesh_dimension)
 Functionality needed for getSurfaceNodes() and getMeshSurface()
 

Member Function Documentation

◆ get2DSurfaceElements()

void MeshToolsLib::MeshSurfaceExtraction::get2DSurfaceElements ( const std::vector< MeshLib::Element * > & all_elements,
std::vector< MeshLib::Element * > & sfc_elements,
std::vector< std::size_t > & element_to_bulk_element_id_map,
std::vector< std::size_t > & element_to_bulk_face_id_map,
Eigen::Vector3d const & dir,
double angle,
unsigned mesh_dimension )
staticprivate

Functionality needed for getSurfaceNodes() and getMeshSurface()

Definition at line 303 of file MeshSurfaceExtraction.cpp.

309{
310 if (mesh_dimension < 2 || mesh_dimension > 3)
311 {
312 ERR("Cannot handle meshes of dimension {}", mesh_dimension);
313 }
314
315 bool const complete_surface = (dir.dot(dir) == 0);
316
317 double const cos_theta(std::cos(angle * std::numbers::pi / 180.0));
318 Eigen::Vector3d const norm_dir(dir.normalized());
319
320 for (auto const* elem : all_elements)
321 {
322 const unsigned element_dimension(elem->getDimension());
323 if (element_dimension < mesh_dimension)
324 {
325 continue;
326 }
327
328 if (element_dimension == 2)
329 {
330 if (!complete_surface)
331 {
332 if (MeshLib::FaceRule::getSurfaceNormal(*elem).normalized().dot(
333 norm_dir) > cos_theta)
334 {
335 continue;
336 }
337 }
338 sfc_elements.push_back(elem->clone());
339 element_to_bulk_element_id_map.push_back(elem->getID());
340 element_to_bulk_face_id_map.push_back(0);
341 }
342 else
343 {
344 if (!elem->isBoundaryElement())
345 {
346 continue;
347 }
348 const unsigned nFaces(elem->getNumberOfFaces());
349 for (unsigned j = 0; j < nFaces; ++j)
350 {
351 if (elem->getNeighbor(j) != nullptr)
352 {
353 continue;
354 }
355
356 auto const face =
357 std::unique_ptr<MeshLib::Element const>{elem->getFace(j)};
358 if (!complete_surface)
359 {
361 .normalized()
362 .dot(norm_dir) < cos_theta)
363 {
364 continue;
365 }
366 }
367 switch (face->getCellType())
368 {
370 sfc_elements.push_back(new MeshLib::Tri(
371 *static_cast<const MeshLib::Tri*>(face.get())));
372 break;
374 sfc_elements.push_back(new MeshLib::Tri6(
375 *static_cast<const MeshLib::Tri6*>(face.get())));
376 break;
378 sfc_elements.push_back(new MeshLib::Quad(
379 *static_cast<const MeshLib::Quad*>(face.get())));
380 break;
382 sfc_elements.push_back(new MeshLib::Quad8(
383 *static_cast<const MeshLib::Quad8*>(face.get())));
384 break;
386 sfc_elements.push_back(new MeshLib::Quad9(
387 *static_cast<const MeshLib::Quad9*>(face.get())));
388 break;
389 default:
390 DBUG("unknown cell type");
391 }
392 element_to_bulk_element_id_map.push_back(elem->getID());
393 element_to_bulk_face_id_map.push_back(j);
394 }
395 }
396 }
397}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:40

References DBUG(), ERR(), MeshLib::FaceRule::getSurfaceNormal(), MeshLib::QUAD4, MeshLib::QUAD8, MeshLib::QUAD9, MeshLib::TRI3, and MeshLib::TRI6.

Referenced by getMeshSurface(), and getSurfaceNodes().

◆ getMeshSurface()

MeshLib::Mesh * MeshToolsLib::MeshSurfaceExtraction::getMeshSurface ( const MeshLib::Mesh & subsfc_mesh,
Eigen::Vector3d const & dir,
double angle,
std::string_view subsfc_node_id_prop_name = "",
std::string_view subsfc_element_id_prop_name = "",
std::string_view face_id_prop_name = "" )
static

Returns the 2d-element mesh representing the surface of the given mesh.

Parameters
subsfc_meshThe original mesh
dirThe direction in which face normals have to point to be considered surface elements
angleThe angle of the allowed deviation from the given direction (0 <= angle <= 90 degrees)
subsfc_node_id_prop_nameThe name of the PropertyVector in the surface mesh the subsurface mesh node ids are stored to. If the string is empty, there won't be such a PropertyVector.
subsfc_element_id_prop_nameThe name of the PropertyVector in the surface mesh that stores the subsurface element ids. If the string is empty, there won't be such a PropertyVector.
face_id_prop_nameThe name of the PropertyVector in the surface mesh that stores the face number of the subsurface element that belongs to the boundary. If the string is empty, there won't be such a PropertyVector.
Returns
A 2D mesh representing the surface in direction dir

Definition at line 247 of file MeshSurfaceExtraction.cpp.

252{
253 // allow slightly greater angles than 90 degrees for numerical errors
254 if (angle < 0 || angle > 91)
255 {
256 ERR("Supported angle between 0 and 90 degrees only.");
257 return nullptr;
258 }
259
260 INFO("Extracting mesh surface...");
261 std::vector<MeshLib::Element*> sfc_elements;
262 std::vector<std::size_t> element_ids_map;
263 std::vector<std::size_t> face_ids_map;
264 get2DSurfaceElements(subsfc_mesh.getElements(), sfc_elements,
265 element_ids_map, face_ids_map, dir, angle,
266 subsfc_mesh.getDimension());
267
268 if (sfc_elements.empty())
269 {
270 return nullptr;
271 }
272
273 auto [sfc_nodes, node_id_map] = createNodesAndIDMapFromElements(
274 sfc_elements, subsfc_mesh.getNumberOfNodes());
275
276 // create new elements vector with newly created nodes (and delete
277 // temp-elements)
278 auto new_elements =
279 MeshLib::copyElementVector(sfc_elements, sfc_nodes, &node_id_map);
280 std::for_each(sfc_elements.begin(), sfc_elements.end(),
281 [](MeshLib::Element* e) { delete e; });
282
283 auto sfc_node_ids = sfc_nodes | MeshLib::views::ids;
284 std::vector<std::size_t> const id_map(sfc_node_ids.begin(),
285 sfc_node_ids.end());
286
287 MeshLib::Mesh* result(
288 new MeshLib::Mesh(subsfc_mesh.getName() + "-Surface", sfc_nodes,
289 new_elements, true /* compute_element_neighbors */));
290
291 addBulkIDPropertiesToMesh(*result, subsfc_node_id_prop_name, id_map,
292 subsfc_element_id_prop_name, element_ids_map,
293 face_id_prop_name, face_ids_map);
294
295 if (!createSfcMeshProperties(*result, subsfc_mesh.getProperties(), id_map,
296 element_ids_map))
297 {
298 ERR("Transferring subsurface properties failed.");
299 }
300 return result;
301}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:111
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:90
Properties & getProperties()
Definition Mesh.h:136
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:105
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:102
static void get2DSurfaceElements(const std::vector< MeshLib::Element * > &all_elements, std::vector< MeshLib::Element * > &sfc_elements, std::vector< std::size_t > &element_to_bulk_element_id_map, std::vector< std::size_t > &element_to_bulk_face_id_map, Eigen::Vector3d const &dir, double angle, unsigned mesh_dimension)
Functionality needed for getSurfaceNodes() and getMeshSurface()
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:227
std::vector< Element * > copyElementVector(std::vector< Element * > const &elements, std::vector< Node * > const &new_nodes, std::vector< std::size_t > const *const node_id_map)
std::tuple< std::vector< MeshLib::Node * >, std::vector< std::size_t > > createNodesAndIDMapFromElements(std::vector< MeshLib::Element * > const &elements, std::size_t const n_all_nodes)
bool createSfcMeshProperties(MeshLib::Mesh &sfc_mesh, MeshLib::Properties const &properties, std::vector< std::size_t > const &node_ids_map, std::vector< std::size_t > const &element_ids_map)
void addBulkIDPropertiesToMesh(MeshLib::Mesh &surface_mesh, std::string_view node_to_bulk_node_id_map_name, std::vector< std::size_t > const &node_to_bulk_node_id_map, std::string_view element_to_bulk_element_id_map_name, std::vector< std::size_t > const &element_to_bulk_element_id_map, std::string_view element_to_bulk_face_id_map_name, std::vector< std::size_t > const &element_to_bulk_face_id_map)

References MeshToolsLib::addBulkIDPropertiesToMesh(), MeshLib::copyElementVector(), MeshToolsLib::createNodesAndIDMapFromElements(), MeshToolsLib::createSfcMeshProperties(), ERR(), get2DSurfaceElements(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::views::ids, and INFO().

Referenced by MeshToolsLib::addLayerToMesh(), MeshGeoToolsLib::GeoMapper::advancedMapOnMesh(), DirectConditionGenerator::directWithSurfaceIntegration(), MeshView::extractSurfaceMesh(), main(), and MeshGeoToolsLib::GeoMapper::mapOnMesh().

◆ getSurfaceAreaForNodes()

std::vector< double > MeshToolsLib::MeshSurfaceExtraction::getSurfaceAreaForNodes ( const MeshLib::Mesh & mesh)
static

Returns a vector of the areas assigned to each node on a surface mesh.

Definition at line 205 of file MeshSurfaceExtraction.cpp.

207{
208 std::vector<double> node_area_vec;
209 if (mesh.getDimension() != 2)
210 {
211 ERR("Error in MeshSurfaceExtraction::getSurfaceAreaForNodes() - Given "
212 "mesh is no surface mesh (dimension != 2).");
213 return node_area_vec;
214 }
215
216 double total_area(0);
217
218 // for each node, a vector containing all the element idget every element
219 const std::vector<MeshLib::Node*>& nodes = mesh.getNodes();
220 const std::size_t nNodes(mesh.getNumberOfNodes());
221 for (std::size_t n = 0; n < nNodes; ++n)
222 {
223 double node_area(0);
224
225 auto const conn_elems = mesh.getElementsConnectedToNode(*nodes[n]);
226 const std::size_t nConnElems(conn_elems.size());
227
228 for (std::size_t i = 0; i < nConnElems; ++i)
229 {
230 const MeshLib::Element* elem(conn_elems[i]);
231 const unsigned nElemParts =
232 (elem->getGeomType() == MeshLib::MeshElemType::TRIANGLE) ? 3
233 : 4;
234 const double area = conn_elems[i]->getContent() / nElemParts;
235 node_area += area;
236 total_area += area;
237 }
238
239 node_area_vec.push_back(node_area);
240 }
241
242 INFO("Total surface Area: {:f}", total_area);
243
244 return node_area_vec;
245}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:108
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition Mesh.cpp:257

References ERR(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElementsConnectedToNode(), MeshLib::Element::getGeomType(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfNodes(), INFO(), and MeshLib::TRIANGLE.

Referenced by DirectConditionGenerator::directWithSurfaceIntegration(), and main().

◆ getSurfaceNodes()

std::vector< MeshLib::Node * > MeshToolsLib::MeshSurfaceExtraction::getSurfaceNodes ( const MeshLib::Mesh & mesh,
Eigen::Vector3d const & dir,
double angle )
static

Returns the surface nodes of a mesh.

Definition at line 399 of file MeshSurfaceExtraction.cpp.

401{
402 INFO("Extracting surface nodes...");
403 std::vector<MeshLib::Element*> sfc_elements;
404 std::vector<std::size_t> element_to_bulk_element_id_map;
405 std::vector<std::size_t> element_to_bulk_face_id_map;
406
408 mesh.getElements(), sfc_elements, element_to_bulk_element_id_map,
409 element_to_bulk_face_id_map, dir, angle, mesh.getDimension());
410
411 std::vector<MeshLib::Node*> surface_nodes;
412 std::tie(surface_nodes, std::ignore) =
414
415 for (auto e : sfc_elements)
416 {
417 delete e;
418 }
419
420 return surface_nodes;
421}

References MeshToolsLib::createNodesAndIDMapFromElements(), get2DSurfaceElements(), MeshLib::Mesh::getDimension(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNumberOfNodes(), and INFO().

Referenced by DirectConditionGenerator::directToSurfaceNodes(), and main().


The documentation for this class was generated from the following files: