OGS
MeshGeoToolsLib::MeshNodeSearcher Class Reference

Detailed Description

Class for searching mesh node ids along polylines or points. This ids can be used to set boundary conditions, source terms, initial conditions or for outputting simulation results.

Definition at line 45 of file MeshNodeSearcher.h.

#include <MeshNodeSearcher.h>

Collaboration diagram for MeshGeoToolsLib::MeshNodeSearcher:
[legend]

Public Member Functions

 MeshNodeSearcher (MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm, SearchAllNodes search_all_nodes)
virtual ~MeshNodeSearcher ()
std::vector< std::size_t > getMeshNodeIDs (GeoLib::GeoObject const &geoObj) const
std::vector< std::size_t > getMeshNodeIDs (std::vector< MathLib::Point3dWithID * > const &points) const

Static Public Member Functions

static OGS_NO_DANGLING MeshNodeSearcher const & getMeshNodeSearcher (MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)

Private Attributes

MeshLib::Mesh const & _mesh
GeoLib::Grid< MeshLib::Node_mesh_grid
std::unique_ptr< MeshGeoToolsLib::SearchLength_search_length_algorithm
SearchAllNodes _search_all_nodes
std::vector< MeshNodesOnPoint * > _mesh_nodes_on_points
std::vector< MeshNodesAlongPolyline * > _mesh_nodes_along_polylines
std::vector< MeshNodesAlongSurface * > _mesh_nodes_along_surfaces

Static Private Attributes

static std::vector< std::unique_ptr< MeshNodeSearcher > > _mesh_node_searchers
 Mesh node searcher for the meshes indexed by the meshs' ids.

Constructor & Destructor Documentation

◆ MeshNodeSearcher()

MeshGeoToolsLib::MeshNodeSearcher::MeshNodeSearcher ( MeshLib::Mesh const & mesh,
std::unique_ptr< MeshGeoToolsLib::SearchLength > && search_length_algorithm,
SearchAllNodes search_all_nodes )

Constructor for objects of class MeshNodeSearcher. It calculates internally used search length from the given MeshLib::Mesh.

Parameters
meshRun search algorithm on this mesh. It is assumed that the mesh does not change its geometry.
search_length_algorithmAlgorithm to determine the search length.
search_all_nodesswitch between searching all mesh nodes and searching the base nodes.

Definition at line 26 of file MeshNodeSearcher.cpp.

30 : _mesh(mesh),
31 _mesh_grid(_mesh.getNodes().cbegin(), _mesh.getNodes().cend()),
32 _search_length_algorithm(std::move(search_length_algorithm)),
33 _search_all_nodes(search_all_nodes)
34{
35 DBUG("The search length for mesh '{:s}' is {:e}.", _mesh.getName(),
36 _search_length_algorithm->getSearchLength());
37}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
GeoLib::Grid< MeshLib::Node > _mesh_grid
std::unique_ptr< MeshGeoToolsLib::SearchLength > _search_length_algorithm

References _mesh, _mesh_grid, _search_all_nodes, _search_length_algorithm, DBUG(), and getNodes().

Referenced by getMeshNodeSearcher().

◆ ~MeshNodeSearcher()

MeshGeoToolsLib::MeshNodeSearcher::~MeshNodeSearcher ( )
virtual

Definition at line 39 of file MeshNodeSearcher.cpp.

40{
41 for (auto pointer : _mesh_nodes_on_points)
42 {
43 delete pointer;
44 }
45 for (auto pointer : _mesh_nodes_along_polylines)
46 {
47 delete pointer;
48 }
49 for (auto pointer : _mesh_nodes_along_surfaces)
50 {
51 delete pointer;
52 }
53}
std::vector< MeshNodesOnPoint * > _mesh_nodes_on_points
std::vector< MeshNodesAlongSurface * > _mesh_nodes_along_surfaces
std::vector< MeshNodesAlongPolyline * > _mesh_nodes_along_polylines

References _mesh_nodes_along_polylines, _mesh_nodes_along_surfaces, and _mesh_nodes_on_points.

Member Function Documentation

◆ getMeshNodeIDs() [1/2]

std::vector< std::size_t > MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs ( GeoLib::GeoObject const & geoObj) const

Searches for the nearest mesh nodes on the given geometric object (point, polyline, surface).

Parameters
geoObja GeoLib::GeoObject where the nearest mesh node is searched for
Returns
a vector of mesh node ids

Definition at line 84 of file MeshNodeSearcher.cpp.

86{
87 std::vector<std::size_t> vec_nodes;
88 switch (geoObj.getGeoType())
89 {
91 {
92 std::function<GeoLib::Point(MeshNodesOnPoint const&)>
93 get_cached_item_function = &MeshNodesOnPoint::getPoint;
95 _mesh_nodes_on_points, get_cached_item_function,
96 *static_cast<const GeoLib::Point*>(&geoObj), _mesh, _mesh_grid,
98 }
100 {
101 std::function<GeoLib::Polyline(MeshNodesAlongPolyline const&)>
102 get_cached_item_function = &MeshNodesAlongPolyline::getPolyline;
104 _mesh_nodes_along_polylines, get_cached_item_function,
105 *static_cast<const GeoLib::Polyline*>(&geoObj), _mesh,
106 _mesh_grid, _search_length_algorithm->getSearchLength(),
108 }
110 {
111 std::function<GeoLib::Surface(MeshNodesAlongSurface const&)>
112 get_cached_item_function = &MeshNodesAlongSurface::getSurface;
114 _mesh_nodes_along_surfaces, get_cached_item_function,
115 *static_cast<const GeoLib::Surface*>(&geoObj), _mesh,
116 _mesh_grid, _search_length_algorithm->getSearchLength(),
118 }
119 default:
120 break;
121 }
122 return vec_nodes;
123}
GeoLib::Polyline const & getPolyline() const
GeoLib::Surface const & getSurface() const
GeoLib::Point const & getPoint() const
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)

References _mesh, _mesh_grid, _mesh_nodes_along_polylines, _mesh_nodes_along_surfaces, _mesh_nodes_on_points, _search_all_nodes, _search_length_algorithm, GeoLib::GeoObject::getGeoType(), MeshGeoToolsLib::getMeshNodeIDs(), MeshGeoToolsLib::MeshNodesOnPoint::getPoint(), MeshGeoToolsLib::MeshNodesAlongPolyline::getPolyline(), MeshGeoToolsLib::MeshNodesAlongSurface::getSurface(), GeoLib::POINT, GeoLib::POLYLINE, and GeoLib::SURFACE.

Referenced by MeshGeoToolsLib::BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline(), MeshGeoToolsLib::BoundaryElementsAtPoint::BoundaryElementsAtPoint(), MeshGeoToolsLib::BoundaryElementsOnSurface::BoundaryElementsOnSurface(), anonymous_namespace{IdentifySubdomainMesh.cpp}::identifySubdomainMeshNodes(), and main().

◆ getMeshNodeIDs() [2/2]

std::vector< std::size_t > MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs ( std::vector< MathLib::Point3dWithID * > const & points) const

Finds unique mesh nodes of each of the input points.

Returns
a vector of mesh node ids.

Definition at line 125 of file MeshNodeSearcher.cpp.

127{
128 double const epsilon_radius = _search_length_algorithm->getSearchLength();
129
130 std::vector<std::size_t> node_ids(points.size());
131
132 auto const number_of_points = std::ssize(points);
133#pragma omp for
134 for (std::ptrdiff_t i = 0; i < number_of_points; ++i)
135 {
136 auto const& p = *points[i];
137 std::vector<std::size_t> const ids =
138 _mesh_grid.getPointsInEpsilonEnvironment(p, epsilon_radius);
139 if (ids.empty())
140 {
141 OGS_FATAL(
142 "No nodes could be found in the mesh for point {:d} : ({:g}, "
143 "{:g}, {:g}) in {:g} epsilon radius in the mesh '{:s}'",
144 p.getID(), p[0], p[1], p[2], epsilon_radius, _mesh.getName());
145 }
146 if (ids.size() != 1)
147 {
148 std::stringstream ss;
149 auto const& bulk_nodes = _mesh.getNodes();
150 for (auto const id : ids)
151 {
152 ss << "- bulk node: " << (*bulk_nodes[id])[0] << ", "
153 << (*bulk_nodes[id])[1] << ", " << (*bulk_nodes[id])[2]
154 << ", distance: "
155 << std::sqrt(MathLib::sqrDist(*bulk_nodes[id], p)) << "\n";
156 }
157 OGS_FATAL(
158 "Found {:d} nodes in the mesh for point {:d} : ({:g}, {:g}, "
159 "{:g}) in {:g} epsilon radius in the mesh '{:s}'. Expected to "
160 "find exactly one node.\n{:s}",
161 ids.size(), p.getID(), p[0], p[1], p[2], epsilon_radius,
162 _mesh.getName(), ss.str());
163 }
164 node_ids[i] = ids.front();
165 }
166 return node_ids;
167}
#define OGS_FATAL(...)
Definition Error.h:19
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216

References _mesh, _mesh_grid, _search_length_algorithm, OGS_FATAL, and MathLib::sqrDist().

◆ getMeshNodeSearcher()

MeshNodeSearcher const & MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher ( MeshLib::Mesh const & mesh,
std::unique_ptr< MeshGeoToolsLib::SearchLength > && search_length_algorithm )
static

Returns a (possibly new) mesh node searcher for the mesh. A new one will be created, if it does not already exists.

Definition at line 169 of file MeshNodeSearcher.cpp.

172{
173 std::size_t const mesh_id = mesh.getID();
174 if (_mesh_node_searchers.size() < mesh_id + 1)
175 {
176 _mesh_node_searchers.resize(mesh_id + 1);
177 }
178
179 if (_mesh_node_searchers[mesh_id])
180 {
181 auto const& m = *_mesh_node_searchers[mesh_id];
182 // return searcher if search length algorithm and the returned search
183 // length are the same, else recreate the searcher
184 if (typeid(m._search_length_algorithm) ==
185 typeid(search_length_algorithm) &&
186 m._search_length_algorithm->getSearchLength() ==
187 search_length_algorithm->getSearchLength())
188 {
189 return m;
190 }
191 }
192
193 _mesh_node_searchers[mesh_id] =
194 std::make_unique<MeshGeoToolsLib::MeshNodeSearcher>(
195 mesh, std::move(search_length_algorithm), SearchAllNodes::Yes);
196
197 return *_mesh_node_searchers[mesh_id];
198}
static std::vector< std::unique_ptr< MeshNodeSearcher > > _mesh_node_searchers
Mesh node searcher for the meshes indexed by the meshs' ids.

References MeshNodeSearcher(), _mesh_node_searchers, MeshLib::Mesh::getID(), and MeshGeoToolsLib::Yes.

Referenced by MeshGeoToolsLib::constructAdditionalMeshesFromGeoObjects(), identifyAndWriteBoundaryMeshes(), and main().

Member Data Documentation

◆ _mesh

MeshLib::Mesh const& MeshGeoToolsLib::MeshNodeSearcher::_mesh
private

Definition at line 91 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), getMeshNodeIDs(), and getMeshNodeIDs().

◆ _mesh_grid

GeoLib::Grid<MeshLib::Node> MeshGeoToolsLib::MeshNodeSearcher::_mesh_grid
private

Definition at line 92 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), getMeshNodeIDs(), and getMeshNodeIDs().

◆ _mesh_node_searchers

std::vector< std::unique_ptr< MeshNodeSearcher > > MeshGeoToolsLib::MeshNodeSearcher::_mesh_node_searchers
staticprivate

Mesh node searcher for the meshes indexed by the meshs' ids.

Definition at line 101 of file MeshNodeSearcher.h.

Referenced by getMeshNodeSearcher().

◆ _mesh_nodes_along_polylines

std::vector<MeshNodesAlongPolyline*> MeshGeoToolsLib::MeshNodeSearcher::_mesh_nodes_along_polylines
mutableprivate

Definition at line 97 of file MeshNodeSearcher.h.

Referenced by ~MeshNodeSearcher(), and getMeshNodeIDs().

◆ _mesh_nodes_along_surfaces

std::vector<MeshNodesAlongSurface*> MeshGeoToolsLib::MeshNodeSearcher::_mesh_nodes_along_surfaces
mutableprivate

Definition at line 98 of file MeshNodeSearcher.h.

Referenced by ~MeshNodeSearcher(), and getMeshNodeIDs().

◆ _mesh_nodes_on_points

std::vector<MeshNodesOnPoint*> MeshGeoToolsLib::MeshNodeSearcher::_mesh_nodes_on_points
mutableprivate

Definition at line 96 of file MeshNodeSearcher.h.

Referenced by ~MeshNodeSearcher(), and getMeshNodeIDs().

◆ _search_all_nodes

SearchAllNodes MeshGeoToolsLib::MeshNodeSearcher::_search_all_nodes
private

Definition at line 94 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), and getMeshNodeIDs().

◆ _search_length_algorithm

std::unique_ptr<MeshGeoToolsLib::SearchLength> MeshGeoToolsLib::MeshNodeSearcher::_search_length_algorithm
private

Definition at line 93 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), getMeshNodeIDs(), and getMeshNodeIDs().


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