OGS
MeshGeoToolsLib Namespace Reference

Classes

class  BoundaryElementsAlongPolyline
class  BoundaryElementsAtPoint
 This class collects point elements located at a given point elements. More...
class  BoundaryElementsOnSurface
class  BoundaryElementsSearcher
class  GeoMapper
 A set of tools for mapping the elevation of geometric objects. More...
class  HeuristicSearchLength
class  MeshNodesAlongPolyline
class  MeshNodesAlongSurface
class  MeshNodeSearcher
class  MeshNodesOnPoint
class  SearchLength

Enumerations

enum class  SearchAllNodes : bool { Yes = true , No = false }

Functions

std::unique_ptr< MeshLib::MeshappendLinesAlongPolylines (const MeshLib::Mesh &mesh, const GeoLib::PolylineVec &ply_vec)
template<typename CacheType, typename GeometryType>
std::vector< MeshLib::Element * > const & getBoundaryElements (std::vector< CacheType * > &cached_elements, std::function< GeometryType(CacheType const &)> getCachedItem, GeometryType const &item, MeshLib::Mesh const &mesh, MeshNodeSearcher const &mesh_node_searcher, bool const multiple_nodes_allowed)
std::string meshNameFromGeometry (std::string const &geometrical_set_name, std::string const &geometry_name)
template<typename GeometryVec>
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeometries (std::vector< GeometryVec * > const &geometries, MeshGeoToolsLib::BoundaryElementsSearcher &boundary_element_searcher, bool const multiple_nodes_allowed)
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeoObjects (GeoLib::GEOObjects const &geo_objects, MeshLib::Mesh const &mesh, std::unique_ptr< SearchLength > search_length_algorithm, bool const multiple_nodes_allowed)
std::unique_ptr< MeshGeoToolsLib::SearchLengthcreateSearchLengthAlgorithm (BaseLib::ConfigTree const &external_config, MeshLib::Mesh const &mesh)
static MeshLib::Element const * findElementContainingPointXY (std::vector< MeshLib::Element const * > const &elements, MathLib::Point3d const &p)
static std::vector< MathLib::Point3dcomputeElementSegmentIntersections (MeshLib::Element const &elem, GeoLib::LineSegment const &segment)
static std::vector< GeoLib::LineSegmentcreateSubSegmentsForElement (std::vector< MathLib::Point3d > const &intersections, MeshLib::Element const *const beg_elem, MeshLib::Element const *const end_elem, MathLib::Point3d const &beg_pnt, MathLib::Point3d const &end_pnt, MeshLib::Element const *const elem)
static std::vector< GeoLib::LineSegmentmapLineSegment (GeoLib::LineSegment const &segment, std::vector< MeshLib::Element const * > const &surface_elements, MeshLib::Element const *const beg_elem, MeshLib::Element const *const end_elem)
static void mapPointOnSurfaceElement (MeshLib::Element const &elem, MathLib::Point3d &q)
static std::vector< MeshLib::Element const * > getCandidateElementsForLineSegmentIntersection (MeshLib::MeshElementGrid const &mesh_element_grid, GeoLib::LineSegment const &segment)
static bool snapPointToElementNode (MathLib::Point3d &p, MeshLib::Element const &elem, double rel_eps)
static void insertSubSegments (GeoLib::Polyline &ply, GeoLib::PointVec &points, GeoLib::Polyline::SegmentIterator &segment_it, std::vector< GeoLib::LineSegment > const &sub_segments)
static void mapPolylineOnSurfaceMesh (GeoLib::Polyline &ply, GeoLib::PointVec &orig_points, MeshLib::MeshElementGrid const &mesh_element_grid)
void identifySubdomainMesh (MeshLib::Mesh &subdomain_mesh, MeshLib::Mesh const &bulk_mesh, MeshNodeSearcher const &mesh_node_searcher, bool const force_overwrite=false)
std::vector< bool > markNodesOutSideOfPolygon (std::vector< MeshLib::Node * > const &nodes, GeoLib::Polygon const &polygon)
template<typename PT>
void resetMeshElementProperty (MeshLib::Mesh &mesh, GeoLib::Polygon const &polygon, std::string const &property_name, PT new_property_value, int restrict_to_material_id, bool const any_of)
template<typename CacheType, typename GeometryType>
std::vector< std::size_t > const & getMeshNodeIDs (std::vector< CacheType * > &cached_elements, std::function< GeometryType(CacheType const &)> getCachedItem, GeometryType const &item, MeshLib::Mesh const &mesh, GeoLib::Grid< MeshLib::Node > const &mesh_grid, double const search_length, SearchAllNodes const search_all_nodes)

Enumeration Type Documentation

◆ SearchAllNodes

enum class MeshGeoToolsLib::SearchAllNodes : bool
strong
Enumerator
Yes 
No 

Definition at line 8 of file SearchAllNodes.h.

Function Documentation

◆ appendLinesAlongPolylines()

std::unique_ptr< MeshLib::Mesh > MeshGeoToolsLib::appendLinesAlongPolylines ( const MeshLib::Mesh & mesh,
const GeoLib::PolylineVec & ply_vec )

Add line elements to a copy of a given mesh

The function creates line elements from nodes located along user-provided polylines. New elements will have a distinct material ID for each polyline.

Remarks
The function allows creation of duplicated line elements.
Line elements may not be placed along edges of existing elements.
Parameters
meshoriginal mesh
ply_vecpolyline vector whose nodes are used to create line elements
Returns
a new mesh which is copied from a given mesh and additionally includes line elements

Definition at line 23 of file AppendLinesAlongPolyline.cpp.

25{
26 // copy existing nodes and elements
27 std::vector<MeshLib::Node*> vec_new_nodes =
29 std::vector<MeshLib::Element*> vec_new_eles =
30 MeshLib::copyElementVector(mesh.getElements(), vec_new_nodes);
31
32 auto const material_ids = materialIDs(mesh);
33 assert(material_ids != nullptr);
34 int const max_matID = material_ids ? ranges::max(*material_ids) : 0;
35
36 auto const edgeLengths = minMaxEdgeLength(mesh.getElements());
37 double const min_edge = edgeLengths.first;
38
39 std::vector<int> new_mat_ids;
40 const std::size_t n_ply(ply_vec.size());
41 // for each polyline
42 for (std::size_t k(0); k < n_ply; k++)
43 {
44 auto const* const ply = ply_vec.getVector()[k];
45
46 // search nodes on the polyline
48 mesh, *ply, min_edge * 0.5, MeshGeoToolsLib::SearchAllNodes::Yes);
49 auto& vec_nodes_on_ply = mshNodesAlongPoly.getNodeIDs();
50 if (vec_nodes_on_ply.empty())
51 {
52 std::string ply_name;
53 ply_vec.getNameOfElementByID(k, ply_name);
54 INFO("No nodes found on polyline {:s}", ply_name);
55 continue;
56 }
57
58 // add line elements
59 for (std::size_t i = 0; i < vec_nodes_on_ply.size() - 1; i++)
60 {
61 std::array<MeshLib::Node*, 2> element_nodes{};
62 element_nodes[0] = vec_new_nodes[vec_nodes_on_ply[i]];
63 element_nodes[1] = vec_new_nodes[vec_nodes_on_ply[i + 1]];
64 vec_new_eles.push_back(
65 new MeshLib::Line(element_nodes, vec_new_eles.size()));
66 new_mat_ids.push_back(max_matID + k + 1);
67 }
68 }
69
70 // generate a mesh
71 const std::string name = mesh.getName() + "_with_lines";
72 auto new_mesh =
73 std::make_unique<MeshLib::Mesh>(name, vec_new_nodes, vec_new_eles,
74 true /* compute_element_neighbors */);
75 auto new_material_ids =
76 new_mesh->getProperties().createNewPropertyVector<int>(
77 "MaterialIDs", MeshLib::MeshItemType::Cell);
78 if (!new_material_ids)
79 {
80 OGS_FATAL("Could not create MaterialIDs cell vector in new mesh.");
81 }
82
83 auto initial_values =
84 material_ids ? ranges::any_view<int const>(*material_ids)
85 : ranges::views::repeat_n(0, mesh.getNumberOfElements());
86
87 new_material_ids->assign(ranges::views::common(
88 ranges::views::concat(initial_values, new_mat_ids)));
89
90 return new_mesh;
91}
#define OGS_FATAL(...)
Definition Error.h:10
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
bool getNameOfElementByID(std::size_t id, std::string &element_name) const
std::size_t size() const
Definition TemplateVec.h:88
std::vector< T * > const & getVector() const
Definition TemplateVec.h:94
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:98
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:101
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:95
std::vector< Node * > copyNodeVector(const std::vector< Node * > &nodes)
Creates a deep copy of a Node vector.
TemplateElement< MeshLib::LineRule2 > Line
Definition Line.h:14
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)

References MeshLib::Cell, MeshLib::copyElementVector(), MeshLib::copyNodeVector(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), GeoLib::TemplateVec< T >::getNameOfElementByID(), MeshGeoToolsLib::MeshNodesAlongPolyline::getNodeIDs(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfElements(), GeoLib::TemplateVec< T >::getVector(), INFO(), OGS_FATAL, GeoLib::TemplateVec< T >::size(), and Yes.

Referenced by main().

◆ computeElementSegmentIntersections()

std::vector< MathLib::Point3d > MeshGeoToolsLib::computeElementSegmentIntersections ( MeshLib::Element const & elem,
GeoLib::LineSegment const & segment )
static

Definition at line 284 of file GeoMapper.cpp.

286{
287 std::vector<MathLib::Point3d> element_intersections;
288 for (std::size_t k(0); k < elem.getNumberOfEdges(); ++k)
289 {
290 auto const edge =
291 std::unique_ptr<MeshLib::Element const>(elem.getEdge(k));
292 GeoLib::LineSegment elem_segment{
293 new GeoLib::Point(*dynamic_cast<MathLib::Point3d*>(
294 const_cast<MeshLib::Node*>(edge->getNode(0))),
295 0),
296 new GeoLib::Point(*dynamic_cast<MathLib::Point3d*>(
297 const_cast<MeshLib::Node*>(edge->getNode(1))),
298 0),
299 true};
300 std::vector<MathLib::Point3d> const intersections(
301 GeoLib::lineSegmentIntersect2d(segment, elem_segment));
302 element_intersections.insert(end(element_intersections),
303 begin(intersections), end(intersections));
304 }
305 return element_intersections;
306}
std::vector< MathLib::Point3d > lineSegmentIntersect2d(GeoLib::LineSegment const &ab, GeoLib::LineSegment const &cd)

References computeElementSegmentIntersections(), MeshLib::Element::getEdge(), MeshLib::Element::getNumberOfEdges(), and GeoLib::lineSegmentIntersect2d().

Referenced by computeElementSegmentIntersections(), and mapLineSegment().

◆ constructAdditionalMeshesFromGeometries()

template<typename GeometryVec>
std::vector< std::unique_ptr< MeshLib::Mesh > > MeshGeoToolsLib::constructAdditionalMeshesFromGeometries ( std::vector< GeometryVec * > const & geometries,
MeshGeoToolsLib::BoundaryElementsSearcher & boundary_element_searcher,
bool const multiple_nodes_allowed )

Definition at line 32 of file ConstructMeshesFromGeometries.cpp.

36{
37 std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
38
39#ifdef USE_PETSC
40 // The subdomain_mesh is not yet a NodePartitionedMesh.
41 // The bulk_mesh, which is a NodePartitionedMesh, is needed to construct the
42 // subdomain NodePartitionedMesh.
43 auto const* bulk_mesh = dynamic_cast<MeshLib::NodePartitionedMesh const*>(
44 &boundary_element_searcher.mesh);
45#endif
46 for (GeometryVec* const geometry_vec : geometries)
47 {
48 // Each geometry_vec has a name, this is the first part of the full
49 // name.
50 auto const& vec_name = geometry_vec->getName();
51
52 auto const& vec_data = geometry_vec->getVector();
53
54 auto const vec_size = geometry_vec->size();
55 for (std::size_t i = 0; i < vec_size; ++i)
56 {
57 // Each geometry has a name, this is the second part of the full
58 // name.
59 std::string geometry_name;
60 bool const is_geometry_named =
61 geometry_vec->getNameOfElementByID(i, geometry_name);
62 if (!is_geometry_named)
63 {
64 continue;
65 }
66
67 auto const& geometry = *vec_data[i];
68
69 DBUG("Creating mesh from geometry {:s} {:s}.", vec_name,
70 geometry_name);
71
72 auto subdomain_mesh = createMeshFromElementSelection(
73 meshNameFromGeometry(vec_name, geometry_name),
75 boundary_element_searcher.getBoundaryElements(
76 geometry, multiple_nodes_allowed)));
77
78#ifdef USE_PETSC
79 additional_meshes.push_back(
81 bulk_mesh, subdomain_mesh.get()));
82#else
83 // Nothing special to be done in the serial case.
84 additional_meshes.emplace_back(std::move(subdomain_mesh));
85#endif
86 }
87 }
88 return additional_meshes;
89}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
std::vector< MeshLib::Element * > const & getBoundaryElements(GeoLib::GeoObject const &geoObj, bool const multiple_nodes_allowed)
std::string meshNameFromGeometry(std::string const &geometrical_set_name, std::string const &geometry_name)
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.
std::unique_ptr< NodePartitionedMesh > transformMeshToNodePartitionedMesh(NodePartitionedMesh const *const bulk_mesh, Mesh const *const subdomain_mesh)

References MeshLib::cloneElements(), DBUG(), MeshGeoToolsLib::BoundaryElementsSearcher::getBoundaryElements(), MeshGeoToolsLib::BoundaryElementsSearcher::mesh, meshNameFromGeometry(), and MeshLib::transformMeshToNodePartitionedMesh().

Referenced by constructAdditionalMeshesFromGeoObjects().

◆ constructAdditionalMeshesFromGeoObjects()

std::vector< std::unique_ptr< MeshLib::Mesh > > MeshGeoToolsLib::constructAdditionalMeshesFromGeoObjects ( GeoLib::GEOObjects const & geo_objects,
MeshLib::Mesh const & mesh,
std::unique_ptr< SearchLength > search_length_algorithm,
bool const multiple_nodes_allowed )

For each named geometry in the give geo_objects (defined on the given mesh) constructs a mesh corresponding to the geometry with mappings to the bulk mesh elements and nodes.

Definition at line 92 of file ConstructMeshesFromGeometries.cpp.

97{
98 std::vector<std::unique_ptr<MeshLib::Mesh>> additional_meshes;
99
100 auto const& mesh_node_searcher =
102 mesh, std::move(search_length_algorithm));
103
104 MeshGeoToolsLib::BoundaryElementsSearcher boundary_element_searcher(
105 mesh, mesh_node_searcher);
106
107 //
108 // Points
109 //
110 {
111 auto point_meshes = constructAdditionalMeshesFromGeometries(
112 geo_objects.getPoints(), boundary_element_searcher,
113 multiple_nodes_allowed);
114 std::move(begin(point_meshes), end(point_meshes),
115 std::back_inserter(additional_meshes));
116 }
117
118 //
119 // Polylines
120 //
121 {
122 auto polyline_meshes = constructAdditionalMeshesFromGeometries(
123 geo_objects.getPolylines(), boundary_element_searcher,
124 multiple_nodes_allowed);
125 std::move(begin(polyline_meshes), end(polyline_meshes),
126 std::back_inserter(additional_meshes));
127 }
128
129 // Surfaces
130 {
131 auto surface_meshes = constructAdditionalMeshesFromGeometries(
132 geo_objects.getSurfaces(), boundary_element_searcher,
133 multiple_nodes_allowed);
134 std::move(begin(surface_meshes), end(surface_meshes),
135 std::back_inserter(additional_meshes));
136 }
137
138 // Set axial symmetry for the additional meshes to the same value as the
139 // "bulk" mesh.
140 std::for_each(begin(additional_meshes), end(additional_meshes),
141 [axial_symmetry = mesh.isAxiallySymmetric()](auto& m)
142 { m->setAxiallySymmetric(axial_symmetry); });
143 return additional_meshes;
144}
static OGS_NO_DANGLING MeshNodeSearcher const & getMeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)
std::vector< std::unique_ptr< MeshLib::Mesh > > constructAdditionalMeshesFromGeometries(std::vector< GeometryVec * > const &geometries, MeshGeoToolsLib::BoundaryElementsSearcher &boundary_element_searcher, bool const multiple_nodes_allowed)

References constructAdditionalMeshesFromGeometries(), MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher(), GeoLib::GEOObjects::getPoints(), GeoLib::GEOObjects::getPolylines(), GeoLib::GEOObjects::getSurfaces(), and MeshLib::Mesh::isAxiallySymmetric().

Referenced by anonymous_namespace{ProjectData.cpp}::readMeshes().

◆ createSearchLengthAlgorithm()

std::unique_ptr< MeshGeoToolsLib::SearchLength > MeshGeoToolsLib::createSearchLengthAlgorithm ( BaseLib::ConfigTree const & external_config,
MeshLib::Mesh const & mesh )

Creates a search length algorithm from the given config.

In case, that there is no tag for the search length algorithm found in the config, the default SearchLength algorithm is returned.

Input File Parameter
prj__search_length_algorithm
Input File Parameter
prj__search_length_algorithm__type
Input File Parameter
prj__search_length_algorithm__fixed
Input File Parameter
prj__search_length_algorithm__fixed__value
Input File Parameter
prj__search_length_algorithm__heuristic

Definition at line 13 of file CreateSearchLength.cpp.

15{
16 std::optional<BaseLib::ConfigTree> config =
18 external_config.getConfigSubtreeOptional("search_length_algorithm");
19
20 if (!config)
21 {
22 return std::make_unique<MeshGeoToolsLib::SearchLength>();
23 }
24
26 std::string const type = config->getConfigParameter<std::string>("type");
27
29 if (type == "fixed")
30 {
32 auto const length = config->getConfigParameter<double>("value");
33 return std::make_unique<MeshGeoToolsLib::SearchLength>(length);
34 }
35 if (type == "heuristic")
36 {
38 return std::make_unique<HeuristicSearchLength>(mesh);
39 }
40 OGS_FATAL("Unknown search length algorithm type '{:s}'.", type);
41}

References BaseLib::ConfigTree::getConfigSubtreeOptional(), and OGS_FATAL.

Referenced by anonymous_namespace{ProjectData.cpp}::readMeshes().

◆ createSubSegmentsForElement()

std::vector< GeoLib::LineSegment > MeshGeoToolsLib::createSubSegmentsForElement ( std::vector< MathLib::Point3d > const & intersections,
MeshLib::Element const *const beg_elem,
MeshLib::Element const *const end_elem,
MathLib::Point3d const & beg_pnt,
MathLib::Point3d const & end_pnt,
MeshLib::Element const *const elem )
static

Definition at line 308 of file GeoMapper.cpp.

313{
314 std::vector<GeoLib::LineSegment> sub_segments;
315 if (intersections.size() > 2)
316 {
317 std::stringstream out;
318 out << "element with id " << elem->getID() << " and seg "
319 << " intersecting at more than two edges\n";
320 for (std::size_t k(0); k < intersections.size(); ++k)
321 {
322 out << k << " " << intersections[k] << "\n";
323 }
324 out << "Could not map segment on element. Aborting.\n";
325 OGS_FATAL("{:s}", out.str());
326 }
327
328 if (intersections.size() == 1 && elem == beg_elem)
329 {
330 // The line segment intersects the element that contains the begin
331 // point of the line segment. Here the first sub line segment is
332 // added.
333 if (MathLib::sqrDist(beg_pnt, intersections[0]) >
334 std::numeric_limits<double>::epsilon())
335 {
336 sub_segments.emplace_back(new GeoLib::Point{beg_pnt, 0},
337 new GeoLib::Point{intersections[0], 0},
338 true);
339 }
340 }
341
342 if (intersections.size() == 1 && elem == end_elem)
343 {
344 // The line segment intersects the element that contains the end
345 // point of the line segment. Here the last sub line segment is
346 // added.
347 if (MathLib::sqrDist(end_pnt, intersections[0]) >
348 std::numeric_limits<double>::epsilon())
349 {
350 sub_segments.emplace_back(new GeoLib::Point{intersections[0], 0},
351 new GeoLib::Point{end_pnt, 0}, true);
352 }
353 }
354
355 if (intersections.size() == 1 && (elem != beg_elem && elem != end_elem))
356 {
357 // Since the line segment enters and leaves the element in the same
358 // point there isn't any need to insert a new sub line segment.
359 return sub_segments;
360 }
361
362 // create sub segment for the current element
363 if (intersections.size() == 2)
364 {
365 sub_segments.emplace_back(new GeoLib::Point{intersections[0], 0},
366 new GeoLib::Point{intersections[1], 0}, true);
367 }
368 return sub_segments;
369}
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19

References createSubSegmentsForElement(), MeshLib::Element::getID(), OGS_FATAL, and MathLib::sqrDist().

Referenced by createSubSegmentsForElement(), and mapLineSegment().

◆ findElementContainingPointXY()

MeshLib::Element const * MeshGeoToolsLib::findElementContainingPointXY ( std::vector< MeshLib::Element const * > const & elements,
MathLib::Point3d const & p )
static

Find the 2d-element within the elements that contains the given point p.

The algorithm projects every element of the elements vector and the point p orthogonal to the \(x\)- \(y\) plane. In the \(x\)- \(y\) plane it is checked if the projected point is in the projected element.

Definition at line 249 of file GeoMapper.cpp.

252{
253 for (auto const elem : elements)
254 {
255 std::unique_ptr<MeshLib::Element> elem_2d(elem->clone());
256 // reset/copy the nodes
257 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
258 {
259 elem_2d->setNode(k, new MeshLib::Node(*elem_2d->getNode(k)));
260 }
261 // project to xy
262 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
263 {
264 (*const_cast<MeshLib::Node*>(elem_2d->getNode(k)))[2] = 0.0;
265 }
266 if (elem_2d->isPntInElement(MathLib::Point3d{{{p[0], p[1], 0.0}}}))
267 {
268 // clean up the copied nodes
269 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
270 {
271 delete elem_2d->getNode(k);
272 }
273 return elem;
274 }
275 // clean up the copied nodes
276 for (std::size_t k(0); k < elem_2d->getNumberOfNodes(); ++k)
277 {
278 delete elem_2d->getNode(k);
279 }
280 }
281 return nullptr;
282}

Referenced by mapPolylineOnSurfaceMesh().

◆ getBoundaryElements()

template<typename CacheType, typename GeometryType>
std::vector< MeshLib::Element * > const & MeshGeoToolsLib::getBoundaryElements ( std::vector< CacheType * > & cached_elements,
std::function< GeometryType(CacheType const &)> getCachedItem,
GeometryType const & item,
MeshLib::Mesh const & mesh,
MeshNodeSearcher const & mesh_node_searcher,
bool const multiple_nodes_allowed )

Definition at line 43 of file BoundaryElementsSearcher.cpp.

49{
50 if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements),
51 [&](auto const& element)
52 { return getCachedItem(*element) == item; });
53 it != cend(cached_elements))
54 {
55 return (*it)->getBoundaryElements();
56 }
57 // create new boundary elements
58 if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value)
59 {
60 cached_elements.push_back(new CacheType(mesh, mesh_node_searcher, item,
61 multiple_nodes_allowed));
62 }
63 else
64 {
65 cached_elements.push_back(
66 new CacheType(mesh, mesh_node_searcher, item));
67 }
68 return cached_elements.back()->getBoundaryElements();
69}

Referenced by MeshGeoToolsLib::BoundaryElementsSearcher::getBoundaryElements().

◆ getCandidateElementsForLineSegmentIntersection()

std::vector< MeshLib::Element const * > MeshGeoToolsLib::getCandidateElementsForLineSegmentIntersection ( MeshLib::MeshElementGrid const & mesh_element_grid,
GeoLib::LineSegment const & segment )
static

Definition at line 454 of file GeoMapper.cpp.

457{
458 GeoLib::LineSegment seg_deep_copy(
459 new GeoLib::Point(segment.getBeginPoint()),
460 new GeoLib::Point(segment.getEndPoint()), true);
461 // modify z coordinates such that all surface elements around the line
462 // segment are found
463 seg_deep_copy.getBeginPoint()[2] = mesh_element_grid.getMinPoint()[2];
464 seg_deep_copy.getEndPoint()[2] = mesh_element_grid.getMaxPoint()[2];
465 std::array<MathLib::Point3d, 2> const pnts{
466 {seg_deep_copy.getBeginPoint(), seg_deep_copy.getEndPoint()}};
467 GeoLib::AABB aabb(pnts.cbegin(), pnts.cend());
468
469 // TODO TF: remove after getElementsInVolume interface change
470 auto convert_to_Point3d = [](Eigen::Vector3d const& v) {
471 return MathLib::Point3d{std::array{v[0], v[1], v[2]}};
472 };
473
474 auto const min = convert_to_Point3d(aabb.getMinPoint());
475 auto const max = convert_to_Point3d(aabb.getMaxPoint());
476 auto candidate_elements = mesh_element_grid.getElementsInVolume(min, max);
477
478 // make candidate elements unique
479 BaseLib::makeVectorUnique(candidate_elements);
480
481 return candidate_elements;
482}
void makeVectorUnique(std::vector< T > &v)
Definition Algorithm.h:198

References GeoLib::LineSegment::getBeginPoint(), getCandidateElementsForLineSegmentIntersection(), MeshLib::MeshElementGrid::getElementsInVolume(), GeoLib::LineSegment::getEndPoint(), GeoLib::AABB::getMaxPoint(), MeshLib::MeshElementGrid::getMaxPoint(), GeoLib::AABB::getMinPoint(), MeshLib::MeshElementGrid::getMinPoint(), and BaseLib::makeVectorUnique().

Referenced by getCandidateElementsForLineSegmentIntersection(), and mapPolylineOnSurfaceMesh().

◆ getMeshNodeIDs()

template<typename CacheType, typename GeometryType>
std::vector< std::size_t > const & MeshGeoToolsLib::getMeshNodeIDs ( std::vector< CacheType * > & cached_elements,
std::function< GeometryType(CacheType const &)> getCachedItem,
GeometryType const & item,
MeshLib::Mesh const & mesh,
GeoLib::Grid< MeshLib::Node > const & mesh_grid,
double const search_length,
SearchAllNodes const search_all_nodes )

Definition at line 56 of file MeshNodeSearcher.cpp.

62{
63 if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements),
64 [&](auto const& element)
65 { return getCachedItem(*element) == item; });
66 it != cend(cached_elements))
67 {
68 return (*it)->getNodeIDs();
69 }
70 // search IDs for geometry object
71 if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value)
72 {
73 cached_elements.push_back(new CacheType(
74 mesh, mesh_grid, item, search_length, search_all_nodes));
75 }
76 else
77 {
78 cached_elements.push_back(
79 new CacheType(mesh, item, search_length, search_all_nodes));
80 }
81 return cached_elements.back()->getNodeIDs();
82}

Referenced by MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs().

◆ identifySubdomainMesh()

void MeshGeoToolsLib::identifySubdomainMesh ( MeshLib::Mesh & subdomain_mesh,
MeshLib::Mesh const & bulk_mesh,
MeshNodeSearcher const & mesh_node_searcher,
bool const force_overwrite = false )

Geometrically finds nodes and elements of the subdomain mesh in the bulk mesh, and updates or verifies the corresponding bulk_node_ids and bulk_element_ids properties.

In case of unexpected results OGS_FATAL is called.

Definition at line 232 of file IdentifySubdomainMesh.cpp.

236{
237 BaseLib::RunTime time;
238 time.start();
239 auto const& bulk_node_ids =
240 identifySubdomainMeshNodes(subdomain_mesh, mesh_node_searcher);
241 INFO("identifySubdomainMesh(): identifySubdomainMeshNodes took {:g} s",
242 time.elapsed());
243
244 updateOrCheckExistingSubdomainProperty(
246 bulk_node_ids, MeshLib::MeshItemType::Node, force_overwrite);
247
248 time.start();
249 auto const& bulk_element_ids =
250 identifySubdomainMeshElements(subdomain_mesh, bulk_mesh);
251 INFO("identifySubdomainMesh(): identifySubdomainMeshElements took {:g} s",
252 time.elapsed());
253
254 // The bulk_element_ids could be of two types: one element per entry---this
255 // is the expected case for the boundary meshes; multiple elements per
256 // entry---this happens if the subdomain mesh lies inside the bulk mesh and
257 // has lower dimension.
258 // First find out the type, then add/check the CellData or FieldData.
259 bool const all_single_elements =
260 all_of(begin(bulk_element_ids), end(bulk_element_ids),
261 [](std::vector<std::size_t> const& v) { return v.size() == 1; });
262 if (all_single_elements)
263 {
264 // All vectors are of size 1, so the data can be flattened and
265 // stored in CellData or compared to existing CellData.
266 std::vector<std::size_t> unique_bulk_element_ids;
267 unique_bulk_element_ids.reserve(bulk_element_ids.size());
268 transform(begin(bulk_element_ids), end(bulk_element_ids),
269 back_inserter(unique_bulk_element_ids),
270 [](std::vector<std::size_t> const& v) { return v[0]; });
271
273 subdomain_mesh,
275 unique_bulk_element_ids, MeshLib::MeshItemType::Cell,
276 force_overwrite);
277 }
278 else
279 {
280 // Some of the boundary elements are connected to multiple bulk
281 // elements; Store the array in FieldData with additional CellData array
282 // for the number of elements, which also provides the offsets.
283 std::vector<std::size_t> flat_bulk_element_ids;
284 flat_bulk_element_ids.reserve(2 * bulk_element_ids.size()); // Guess.
285 std::vector<std::size_t> number_of_bulk_element_ids;
286 number_of_bulk_element_ids.reserve(bulk_element_ids.size());
287
288 for (auto const& v : bulk_element_ids)
289 {
290 // The element ids are already sorted descending by
291 // findElementsInMesh(), making the ordering deterministic across
292 // compilers and parallel execution.
293 // TODO: sort the bulk element ids by the positions of the
294 // corresponding subdomain element to the subdomain element, e.g.
295 // left-to-right for 1D subdomains in 2D bulk meshes or 2D
296 // subdomains in 3D bulk meshes.
297 number_of_bulk_element_ids.push_back(v.size());
298 flat_bulk_element_ids.insert(end(flat_bulk_element_ids), begin(v),
299 end(v));
300 }
301
303 subdomain_mesh, "number_bulk_elements", number_of_bulk_element_ids,
304 MeshLib::MeshItemType::Cell, force_overwrite);
306 subdomain_mesh,
308 flat_bulk_element_ids, MeshLib::MeshItemType::IntegrationPoint,
309 force_overwrite);
310 }
311}
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
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.

References MeshLib::Cell, BaseLib::RunTime::elapsed(), MeshLib::getBulkIDString(), INFO(), MeshLib::IntegrationPoint, MeshLib::Node, and BaseLib::RunTime::start().

◆ insertSubSegments()

void MeshGeoToolsLib::insertSubSegments ( GeoLib::Polyline & ply,
GeoLib::PointVec & points,
GeoLib::Polyline::SegmentIterator & segment_it,
std::vector< GeoLib::LineSegment > const & sub_segments )
static

Definition at line 513 of file GeoMapper.cpp.

517{
518 std::size_t const j(segment_it.getSegmentNumber());
519 std::size_t new_pnts_cnt(0);
520 for (auto const& segment : sub_segments)
521 {
522 auto const begin_id(points.push_back(
523 new GeoLib::Point(segment.getBeginPoint(), points.size())));
524 if (ply.insertPoint(j + new_pnts_cnt + 1, begin_id))
525 {
526 new_pnts_cnt++;
527 }
528 auto const end_id(points.push_back(
529 new GeoLib::Point(segment.getEndPoint(), points.size())));
530 if (ply.insertPoint(j + new_pnts_cnt + 1, end_id))
531 {
532 new_pnts_cnt++;
533 }
534 }
535 std::advance(segment_it, new_pnts_cnt);
536}
std::size_t push_back(Point *pnt)
Definition PointVec.cpp:124
std::size_t getSegmentNumber() const
Definition Polyline.cpp:376
virtual bool insertPoint(std::size_t pos, std::size_t pnt_id)
Definition Polyline.cpp:44

References GeoLib::Polyline::SegmentIterator::getSegmentNumber(), GeoLib::Polyline::insertPoint(), insertSubSegments(), GeoLib::PointVec::push_back(), and GeoLib::TemplateVec< T >::size().

Referenced by insertSubSegments(), and mapPolylineOnSurfaceMesh().

◆ mapLineSegment()

std::vector< GeoLib::LineSegment > MeshGeoToolsLib::mapLineSegment ( GeoLib::LineSegment const & segment,
std::vector< MeshLib::Element const * > const & surface_elements,
MeshLib::Element const *const beg_elem,
MeshLib::Element const *const end_elem )
static

Definition at line 371 of file GeoMapper.cpp.

376{
377 std::vector<GeoLib::LineSegment> sub_segments;
378 MathLib::Point3d const& beg_pnt(segment.getBeginPoint());
379 MathLib::Point3d const& end_pnt(segment.getEndPoint());
380
381 for (auto const elem : surface_elements)
382 {
383 // compute element-segment-intersections (2d in x-y-plane)
384 std::vector<MathLib::Point3d> element_intersections(
385 computeElementSegmentIntersections(*elem, segment));
386 if (element_intersections.empty())
387 {
388 continue;
389 }
390
391 BaseLib::makeVectorUnique(element_intersections);
392
393 std::vector<GeoLib::LineSegment> sub_seg_elem(
394 createSubSegmentsForElement(element_intersections, beg_elem,
395 end_elem, beg_pnt, end_pnt, elem));
396 sub_segments.insert(sub_segments.end(), sub_seg_elem.begin(),
397 sub_seg_elem.end());
398 }
399
400 // beg_elem == nullptr means there isn't any element corresponding to the
401 // beg_pnt and as a consequence the above algorithm doesn't insert a sub
402 // segment
403 if (beg_elem == nullptr)
404 {
405 auto min_dist_segment = std::min_element(
406 sub_segments.begin(), sub_segments.end(),
407 [&beg_pnt](GeoLib::LineSegment const& seg0,
408 GeoLib::LineSegment const& seg1)
409 {
410 // min dist for segment 0
411 const double d0(
412 std::min(MathLib::sqrDist(beg_pnt, seg0.getBeginPoint()),
413 MathLib::sqrDist(beg_pnt, seg0.getEndPoint())));
414 // min dist for segment 1
415 const double d1(
416 std::min(MathLib::sqrDist(beg_pnt, seg1.getBeginPoint()),
417 MathLib::sqrDist(beg_pnt, seg1.getEndPoint())));
418 return d0 < d1;
419 });
420 GeoLib::Point* pnt{
421 MathLib::sqrDist(beg_pnt, min_dist_segment->getBeginPoint()) <
422 MathLib::sqrDist(beg_pnt, min_dist_segment->getEndPoint())
423 ? new GeoLib::Point{min_dist_segment->getBeginPoint()}
424 : new GeoLib::Point{min_dist_segment->getEndPoint()}};
425 sub_segments.emplace_back(new GeoLib::Point{beg_pnt, 0}, pnt, true);
426 }
427 // sort all sub segments for the given segment (beg_pnt, end_pnt)
428 GeoLib::sortSegments(beg_pnt, sub_segments);
429
430 sub_segments.erase(std::unique(sub_segments.begin(), sub_segments.end()),
431 sub_segments.end());
432
433 return sub_segments;
434}
void sortSegments(MathLib::Point3d const &seg_beg_pnt, std::vector< GeoLib::LineSegment > &sub_segments)
static std::vector< GeoLib::LineSegment > createSubSegmentsForElement(std::vector< MathLib::Point3d > const &intersections, MeshLib::Element const *const beg_elem, MeshLib::Element const *const end_elem, MathLib::Point3d const &beg_pnt, MathLib::Point3d const &end_pnt, MeshLib::Element const *const elem)
static std::vector< MathLib::Point3d > computeElementSegmentIntersections(MeshLib::Element const &elem, GeoLib::LineSegment const &segment)

References computeElementSegmentIntersections(), createSubSegmentsForElement(), GeoLib::LineSegment::getBeginPoint(), GeoLib::LineSegment::getEndPoint(), BaseLib::makeVectorUnique(), mapLineSegment(), GeoLib::sortSegments(), and MathLib::sqrDist().

Referenced by mapLineSegment(), and mapPolylineOnSurfaceMesh().

◆ mapPointOnSurfaceElement()

void MeshGeoToolsLib::mapPointOnSurfaceElement ( MeshLib::Element const & elem,
MathLib::Point3d & q )
static

Definition at line 436 of file GeoMapper.cpp.

438{
439 // create plane equation: n*p = d
440 auto const& p = elem.getNode(0)->asEigenVector3d();
441 Eigen::Vector3d const n(MeshLib::FaceRule::getSurfaceNormal(elem));
442 if (n[2] == 0.0)
443 { // vertical plane, z coordinate is arbitrary
444 q[2] = p[2];
445 }
446 else
447 {
448 double const d(n.dot(p));
449 q[2] = (d - n[0] * q[0] - n[1] * q[1]) / n[2];
450 }
451}
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition FaceRule.cpp:33

References MathLib::Point3d::asEigenVector3d(), MeshLib::Element::getNode(), MeshLib::FaceRule::getSurfaceNormal(), and mapPointOnSurfaceElement().

Referenced by mapPointOnSurfaceElement(), and mapPolylineOnSurfaceMesh().

◆ mapPolylineOnSurfaceMesh()

void MeshGeoToolsLib::mapPolylineOnSurfaceMesh ( GeoLib::Polyline & ply,
GeoLib::PointVec & orig_points,
MeshLib::MeshElementGrid const & mesh_element_grid )
static

Definition at line 538 of file GeoMapper.cpp.

542{
543 // for each segment ...
544 for (auto segment_it(ply.begin()); segment_it != ply.end(); ++segment_it)
545 {
547 mesh_element_grid, *segment_it));
548
549 auto mapPoint = [&candidate_elements](MathLib::Point3d& p)
550 {
551 auto const* elem(
552 findElementContainingPointXY(candidate_elements, p));
553 if (elem)
554 {
555 if (!snapPointToElementNode(p, *elem, 1e-3))
556 {
557 mapPointOnSurfaceElement(*elem, p);
558 }
559 }
560 return elem;
561 };
562
563 // map segment begin and end point
564 auto const* beg_elem(mapPoint((*segment_it).getBeginPoint()));
565 auto const* end_elem(mapPoint((*segment_it).getEndPoint()));
566
567 // Since the mapping of the segment begin and end points the coordinates
568 // changed. The internal data structures of PointVec are possibly
569 // invalid and hence it is necessary to re-create them.
570 orig_points.resetInternalDataStructures();
571
572 if (beg_elem == end_elem)
573 {
574 // TODO: handle cases: beg_elem == end_elem == nullptr
575 // There are further checks necessary to determine which case we are
576 // in:
577 // 1. beg_elem == end_elem and the segment intersects elements
578 // 2. beg_elem == end_elem and the segment does not intersect any
579 // element, i.e., the segment is located outside of the mesh area
580 //
581 // Case 1 needs additional work.
582 continue;
583 }
584
585 // map the line segment (and if necessary for the mapping partition it)
586 std::vector<GeoLib::LineSegment> sub_segments(mapLineSegment(
587 *segment_it, candidate_elements, beg_elem, end_elem));
588
589 if (sub_segments.empty())
590 {
591 continue;
592 }
593
594 // The case sub_segment.size() == 1 is already handled above.
595
596 if (sub_segments.size() > 1)
597 {
598 insertSubSegments(ply, orig_points, segment_it, sub_segments);
599 }
600 }
601}
void resetInternalDataStructures()
Definition PointVec.cpp:249
SegmentIterator begin() const
Definition Polyline.h:165
SegmentIterator end() const
Definition Polyline.h:167
static bool snapPointToElementNode(MathLib::Point3d &p, MeshLib::Element const &elem, double rel_eps)
static void insertSubSegments(GeoLib::Polyline &ply, GeoLib::PointVec &points, GeoLib::Polyline::SegmentIterator &segment_it, std::vector< GeoLib::LineSegment > const &sub_segments)
static void mapPointOnSurfaceElement(MeshLib::Element const &elem, MathLib::Point3d &q)
static std::vector< MeshLib::Element const * > getCandidateElementsForLineSegmentIntersection(MeshLib::MeshElementGrid const &mesh_element_grid, GeoLib::LineSegment const &segment)
static MeshLib::Element const * findElementContainingPointXY(std::vector< MeshLib::Element const * > const &elements, MathLib::Point3d const &p)
static std::vector< GeoLib::LineSegment > mapLineSegment(GeoLib::LineSegment const &segment, std::vector< MeshLib::Element const * > const &surface_elements, MeshLib::Element const *const beg_elem, MeshLib::Element const *const end_elem)

References GeoLib::Polyline::begin(), GeoLib::Polyline::end(), findElementContainingPointXY(), getCandidateElementsForLineSegmentIntersection(), insertSubSegments(), mapLineSegment(), mapPointOnSurfaceElement(), mapPolylineOnSurfaceMesh(), GeoLib::PointVec::resetInternalDataStructures(), and snapPointToElementNode().

Referenced by MeshGeoToolsLib::GeoMapper::advancedMapOnMesh(), and mapPolylineOnSurfaceMesh().

◆ markNodesOutSideOfPolygon()

std::vector< bool > MeshGeoToolsLib::markNodesOutSideOfPolygon ( std::vector< MeshLib::Node * > const & nodes,
GeoLib::Polygon const & polygon )

Definition at line 16 of file MarkNodesOutsideOfPolygon.h.

18{
19 // *** rotate polygon points to xy-plane
20 auto [rotated_polygon_points, normal] =
22
23 // *** rotate mesh nodes to xy-plane
24 // 1 copy all mesh nodes to GeoLib::Points
25 std::vector<GeoLib::Point*> rotated_nodes;
26 for (auto node : nodes)
27 {
28 rotated_nodes.push_back(new GeoLib::Point(*node, node->getID()));
29 }
30 // 2 rotate the Points
31 Eigen::Matrix3d const rot_mat = GeoLib::computeRotationMatrixToXY(normal);
32 GeoLib::rotatePoints(rot_mat, rotated_nodes);
33 // 3 set z coord to zero
34 std::for_each(rotated_nodes.begin(), rotated_nodes.end(),
35 [](GeoLib::Point* p) { (*p)[2] = 0.0; });
36
37 std::vector<bool> outside(rotated_nodes.size(), true);
38 // *** mark rotated nodes inside rotated polygon
39 {
40 // create new polygon using the rotated points
41 GeoLib::Polyline rotated_polyline(rotated_polygon_points);
42 for (std::size_t k(0); k < polygon.getNumberOfPoints(); k++)
43 {
44 rotated_polyline.addPoint(k);
45 }
46 rotated_polyline.addPoint(0);
47 GeoLib::Polygon const rotated_polygon(rotated_polyline);
48
49 for (std::size_t k(0); k < rotated_nodes.size(); k++)
50 {
51 if (rotated_polygon.isPntInPolygon(*(rotated_nodes[k])))
52 {
53 outside[k] = false;
54 }
55 }
56 }
57
58 for (auto& rotated_node : rotated_nodes)
59 {
60 delete rotated_node;
61 }
62
63 for (auto& rot_polygon_pnt : rotated_polygon_points)
64 {
65 delete rot_polygon_pnt;
66 }
67
68 return outside;
69}
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:29
void rotatePoints(Eigen::Matrix3d const &rot_mat, InputIterator pnts_begin, InputIterator pnts_end)
std::tuple< std::vector< GeoLib::Point * >, Eigen::Vector3d > rotatePolygonPointsToXY(GeoLib::Polygon const &polygon_in)
Eigen::Matrix3d computeRotationMatrixToXY(Eigen::Vector3d const &n)

References GeoLib::Polyline::addPoint(), GeoLib::computeRotationMatrixToXY(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Polygon::isPntInPolygon(), GeoLib::rotatePoints(), and GeoLib::rotatePolygonPointsToXY().

Referenced by resetMeshElementProperty().

◆ meshNameFromGeometry()

std::string MeshGeoToolsLib::meshNameFromGeometry ( std::string const & geometrical_set_name,
std::string const & geometry_name )

Definition at line 24 of file ConstructMeshesFromGeometries.cpp.

26{
27 return geometrical_set_name + "_" + geometry_name;
28}

Referenced by constructAdditionalMeshesFromGeometries(), and anonymous_namespace{ProcessVariable.cpp}::findMeshInConfig().

◆ resetMeshElementProperty()

template<typename PT>
void MeshGeoToolsLib::resetMeshElementProperty ( MeshLib::Mesh & mesh,
GeoLib::Polygon const & polygon,
std::string const & property_name,
PT new_property_value,
int restrict_to_material_id,
bool const any_of )

Definition at line 26 of file ResetMeshElementProperty.h.

32{
34 mesh, property_name, MeshLib::MeshItemType::Cell, 1);
35
36 if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell)
37 {
38 ERR("Values of the PropertyVector are not assigned to cells.");
39 return;
40 }
41 auto const* material_ids =
42 mesh.getProperties().getPropertyVector<int>("MaterialIDs");
43
44 if (restrict_to_material_id != -1 && !material_ids)
45 {
47 "Restriction of resetting a property in a polygonal region "
48 "requires that a MaterialIDs data array is available in the "
49 "mesh.");
50 }
51
52 auto has_element_required_material_id = [&](int const element_id)
53 {
54 return restrict_to_material_id == -1 ||
55 (*material_ids)[element_id] == restrict_to_material_id;
56 };
57
58 auto const outside = markNodesOutSideOfPolygon(mesh.getNodes(), polygon);
59
60 auto is_node_outside = [&outside](std::size_t const node_id)
61 { return outside[node_id]; };
62
63 auto is_element_outside = [&](MeshLib::Element const& e)
64 {
65 auto ids = e.nodes() | MeshLib::views::ids;
66 return any_of ? ranges::all_of(ids, is_node_outside)
67 : ranges::any_of(ids, is_node_outside);
68 };
69
70 auto is_valid_element = [&](MeshLib::Element const& e)
71 {
72 return !is_element_outside(e) &&
73 has_element_required_material_id(e.getID());
74 };
75
76 auto compute_value = [&](MeshLib::Element const* const e) -> PT
77 { return is_valid_element(*e) ? new_property_value : (*pv)[e->getID()]; };
78
79 pv->assign(mesh.getElements() | ranges::views::transform(compute_value));
80}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Properties & getProperties()
Definition Mesh.h:127
PropertyVector< T > const * getPropertyVector(std::string_view name) const
constexpr bool any_of(List const &values)
Checks if any of the elements in the given list is true.
Definition Algorithm.h:311
std::vector< bool > markNodesOutSideOfPolygon(std::vector< MeshLib::Node * > const &nodes, GeoLib::Polygon const &polygon)
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:223
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)

References MeshLib::Cell, ERR(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::getOrCreateMeshProperty(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), MeshLib::views::ids, markNodesOutSideOfPolygon(), and OGS_FATAL.

Referenced by main().

◆ snapPointToElementNode()

bool MeshGeoToolsLib::snapPointToElementNode ( MathLib::Point3d & p,
MeshLib::Element const & elem,
double rel_eps )
static

Definition at line 484 of file GeoMapper.cpp.

486{
487 // values will be initialized within computeSqrNodeDistanceRange
488 auto const [sqr_min, sqr_max] = MeshLib::computeSqrNodeDistanceRange(elem);
489
490 double const sqr_eps(rel_eps * rel_eps * sqr_min);
491 for (std::size_t k(0); k < elem.getNumberOfNodes(); ++k)
492 {
493 auto const& node(*elem.getNode(k));
494 double const sqr_dist_2d(MathLib::sqrDist2d(p, node));
495 if (sqr_dist_2d < sqr_eps)
496 {
497#ifdef DEBUG_GEOMAPPER
498 std::stringstream out;
499 out.precision(std::numeric_limits<double>::max_digits10);
500 out << "Segment point snapped from " << p;
501#endif
502 p = node;
503#ifdef DEBUG_GEOMAPPER
504 out << "to " << p;
505 DBUG("{:s}", out.str());
506#endif
507 return true;
508 }
509 }
510 return false;
511}
double sqrDist2d(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.h:114
std::pair< double, double > computeSqrNodeDistanceRange(MeshLib::Element const &element, bool const check_allnodes)
Compute the minimum and maximum node distances for this element.
Definition Element.cpp:143

References MeshLib::computeSqrNodeDistanceRange(), DBUG(), MeshLib::Element::getNode(), MeshLib::Element::getNumberOfNodes(), snapPointToElementNode(), and MathLib::sqrDist2d().

Referenced by mapPolylineOnSurfaceMesh(), and snapPointToElementNode().