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 51 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 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 34 of file MeshNodeSearcher.cpp.

38 : _mesh(mesh),
39 _mesh_grid(_mesh.getNodes().cbegin(), _mesh.getNodes().cend()),
40 _search_length_algorithm(std::move(search_length_algorithm)),
41 _search_all_nodes(search_all_nodes)
42{
43 DBUG("The search length for mesh '{:s}' is {:e}.", _mesh.getName(),
44 _search_length_algorithm->getSearchLength());
45}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition: Logging.h:30
GeoLib::Grid< MeshLib::Node > _mesh_grid
std::unique_ptr< MeshGeoToolsLib::SearchLength > _search_length_algorithm
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:106
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:103

References _mesh, _search_length_algorithm, DBUG(), and MeshLib::Mesh::getName().

◆ ~MeshNodeSearcher()

MeshGeoToolsLib::MeshNodeSearcher::~MeshNodeSearcher ( )
virtual

Definition at line 47 of file MeshNodeSearcher.cpp.

48{
49 for (auto pointer : _mesh_nodes_on_points)
50 {
51 delete pointer;
52 }
53 for (auto pointer : _mesh_nodes_along_polylines)
54 {
55 delete pointer;
56 }
57 for (auto pointer : _mesh_nodes_along_surfaces)
58 {
59 delete pointer;
60 }
61}
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 92 of file MeshNodeSearcher.cpp.

94{
95 std::vector<std::size_t> vec_nodes;
96 switch (geoObj.getGeoType())
97 {
99 {
100 std::function<GeoLib::Point(MeshNodesOnPoint const&)>
101 get_cached_item_function = &MeshNodesOnPoint::getPoint;
103 _mesh_nodes_on_points, get_cached_item_function,
104 *static_cast<const GeoLib::Point*>(&geoObj), _mesh, _mesh_grid,
105 _search_length_algorithm->getSearchLength(), _search_all_nodes);
106 }
108 {
109 std::function<GeoLib::Polyline(MeshNodesAlongPolyline const&)>
110 get_cached_item_function = &MeshNodesAlongPolyline::getPolyline;
112 _mesh_nodes_along_polylines, get_cached_item_function,
113 *static_cast<const GeoLib::Polyline*>(&geoObj), _mesh,
114 _mesh_grid, _search_length_algorithm->getSearchLength(),
116 }
118 {
119 std::function<GeoLib::Surface(MeshNodesAlongSurface const&)>
120 get_cached_item_function = &MeshNodesAlongSurface::getSurface;
122 _mesh_nodes_along_surfaces, get_cached_item_function,
123 *static_cast<const GeoLib::Surface*>(&geoObj), _mesh,
124 _mesh_grid, _search_length_algorithm->getSearchLength(),
126 }
127 default:
128 break;
129 }
130 return vec_nodes;
131}
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:42
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:35
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 133 of file MeshNodeSearcher.cpp.

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

References _mesh, _mesh_grid, _search_length_algorithm, MeshLib::Mesh::getName(), MeshLib::Mesh::getNodes(), GeoLib::Grid< POINT >::getPointsInEpsilonEnvironment(), 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 176 of file MeshNodeSearcher.cpp.

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

References _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 96 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), and getMeshNodeIDs().

◆ _mesh_grid

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

Definition at line 97 of file MeshNodeSearcher.h.

Referenced by 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 106 of file MeshNodeSearcher.h.

Referenced by getMeshNodeSearcher().

◆ _mesh_nodes_along_polylines

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

Definition at line 102 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 103 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 101 of file MeshNodeSearcher.h.

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

◆ _search_all_nodes

SearchAllNodes MeshGeoToolsLib::MeshNodeSearcher::_search_all_nodes
private

Definition at line 99 of file MeshNodeSearcher.h.

Referenced by getMeshNodeIDs().

◆ _search_length_algorithm

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

Definition at line 98 of file MeshNodeSearcher.h.

Referenced by MeshNodeSearcher(), and getMeshNodeIDs().


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