OGS 6.2.1-97-g73d1aeda3
MeshNodeSearcher.cpp
Go to the documentation of this file.
1 
11 #include "MeshNodeSearcher.h"
12 
13 #include <typeinfo>
14 
15 #include "HeuristicSearchLength.h"
16 #include "MeshNodesAlongPolyline.h"
17 #include "MeshNodesAlongSurface.h"
18 #include "MeshNodesOnPoint.h"
19 
20 #include <logog/include/logog.hpp>
21 
22 #include "GeoLib/Point.h"
23 #include "GeoLib/Polyline.h"
24 
26 #include "MeshLib/Mesh.h"
27 #include "MeshLib/Node.h"
28 
29 namespace MeshGeoToolsLib
30 {
31 std::vector<std::unique_ptr<MeshNodeSearcher>>
33 
35  MeshLib::Mesh const& mesh,
36  std::unique_ptr<MeshGeoToolsLib::SearchLength>&& search_length_algorithm,
37  SearchAllNodes search_all_nodes)
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().c_str(),
44  _search_length_algorithm->getSearchLength());
45 }
46 
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 }
62 
63 std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(
64  GeoLib::GeoObject const& geoObj) const
65 {
66  std::vector<std::size_t> vec_nodes;
67  switch (geoObj.getGeoType())
68  {
70  {
71  vec_nodes = this->getMeshNodeIDsForPoint(
72  *static_cast<const GeoLib::Point*>(&geoObj));
73  break;
74  }
76  vec_nodes = this->getMeshNodeIDsAlongPolyline(
77  *static_cast<const GeoLib::Polyline*>(&geoObj));
78  break;
80  vec_nodes = this->getMeshNodeIDsAlongSurface(
81  *static_cast<const GeoLib::Surface*>(&geoObj));
82  break;
83  default:
84  break;
85  }
86  return vec_nodes;
87 }
88 
89 std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(
90  std::vector<MathLib::Point3dWithID*> const& points) const
91 {
92  double const epsilon_radius = _search_length_algorithm->getSearchLength();
93 
94  std::vector<std::size_t> node_ids;
95  node_ids.reserve(points.size());
96 
97  for (auto const* const p_ptr : points)
98  {
99  auto const& p = *p_ptr;
100  std::vector<std::size_t> const ids =
101  _mesh_grid.getPointsInEpsilonEnvironment(p, epsilon_radius);
102  if (ids.empty())
103  {
104  OGS_FATAL(
105  "No nodes could be found in the mesh for point %d : (%g, %g, "
106  "%g) in %g epsilon radius in the mesh '%s'",
107  p.getID(), p[0], p[1], p[2], epsilon_radius,
108  _mesh.getName().c_str());
109  }
110  if (ids.size() != 1)
111  {
112  OGS_FATAL(
113  "Found %d nodes in the mesh for point %d : (%g, %g, %g) in %g "
114  "epsilon radius in the mesh '%s'. Expected to find exactly one "
115  "node.",
116  ids.size(), p.getID(), p[0], p[1], p[2], epsilon_radius,
117  _mesh.getName().c_str());
118  }
119  node_ids.push_back(ids.front());
120  }
121  return node_ids;
122 }
123 
124 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsForPoint(
125  GeoLib::Point const& pnt) const
126 {
127  return getMeshNodesOnPoint(pnt).getNodeIDs();
128 }
129 
130 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongPolyline(
131  GeoLib::Polyline const& ply) const
132 {
134 }
135 
136 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongSurface(
137  GeoLib::Surface const& sfc) const
138 {
139  return getMeshNodesAlongSurface(sfc).getNodeIDs();
140 }
141 
143  GeoLib::Point const& pnt) const
144 {
145  for (auto const& mesh_nodes_on_point : _mesh_nodes_on_points)
146  {
147  if (&(mesh_nodes_on_point->getPoint()) == &pnt)
148  {
149  return *mesh_nodes_on_point;
150  }
151  }
152 
153  _mesh_nodes_on_points.push_back(
155  _mesh_grid,
156  pnt,
157  _search_length_algorithm->getSearchLength(),
159  return *_mesh_nodes_on_points.back();
160 }
161 
163  GeoLib::Polyline const& ply) const
164 {
165  for (auto const& mesh_nodes_along_polyline : _mesh_nodes_along_polylines)
166  {
167  if (&(mesh_nodes_along_polyline->getPolyline()) == &ply)
168  {
169  return *mesh_nodes_along_polyline;
170  }
171  }
172 
173  // compute nodes (and supporting points) along polyline
174  _mesh_nodes_along_polylines.push_back(new MeshNodesAlongPolyline(
175  _mesh, ply, _search_length_algorithm->getSearchLength(),
177  return *_mesh_nodes_along_polylines.back();
178 }
179 
181  GeoLib::Surface const& sfc) const
182 {
183  for (auto const& mesh_nodes_along_surface : _mesh_nodes_along_surfaces)
184  {
185  if (&(mesh_nodes_along_surface->getSurface()) == &sfc)
186  {
187  return *mesh_nodes_along_surface;
188  }
189  }
190 
191  // compute nodes (and supporting points) on surface
192  _mesh_nodes_along_surfaces.push_back(
194  sfc,
195  _search_length_algorithm->getSearchLength(),
197  return *_mesh_nodes_along_surfaces.back();
198 }
199 
201  MeshLib::Mesh const& mesh,
202  std::unique_ptr<MeshGeoToolsLib::SearchLength>&& search_length_algorithm)
203 {
204  std::size_t const mesh_id = mesh.getID();
205  if (_mesh_node_searchers.size() < mesh_id + 1)
206  {
207  _mesh_node_searchers.resize(mesh_id + 1);
208  }
209 
210  if (_mesh_node_searchers[mesh_id])
211  {
212  auto const& m = *_mesh_node_searchers[mesh_id];
213  // return searcher if search length algorithm and the returned search
214  // lenght are the same, else recreate the searcher
215  if (typeid(m._search_length_algorithm) ==
216  typeid(search_length_algorithm) &&
217  m._search_length_algorithm->getSearchLength() ==
218  search_length_algorithm->getSearchLength())
219  {
220  return m;
221  }
222  }
223 
224  _mesh_node_searchers[mesh_id] =
225  std::make_unique<MeshGeoToolsLib::MeshNodeSearcher>(
226  mesh, std::move(search_length_algorithm), SearchAllNodes::Yes);
227 
228  return *_mesh_node_searchers[mesh_id];
229 }
230 
231 std::size_t MeshNodeSearcher::getMeshId() const
232 {
233  return _mesh.getID();
234 }
235 
236 } // end namespace MeshGeoToolsLib
Implementation of heuristic search length strategy.
std::vector< MeshNodesOnPoint * > _mesh_nodes_on_points
Definition of the PolyLine class.
Definition of the Point class.
std::vector< std::size_t > const & getNodeIDs() const
MeshNodesOnPoint & getMeshNodesOnPoint(GeoLib::Point const &pnt) const
std::vector< MeshNodesAlongSurface * > _mesh_nodes_along_surfaces
std::vector< std::size_t > const & getMeshNodeIDsAlongPolyline(GeoLib::Polyline const &ply) const
Definition of the Node class.
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:123
std::vector< std::size_t > getPointsInEpsilonEnvironment(P const &pnt, double eps) const
Definition: Grid.h:591
std::vector< std::size_t > const & getMeshNodeIDsAlongSurface(GeoLib::Surface const &sfc) const
Definition of the Mesh class.
std::vector< MeshNodesAlongPolyline * > _mesh_nodes_along_polylines
std::vector< std::size_t > const & getNodeIDs() const
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:102
virtual GEOTYPE getGeoType() const =0
return a geometry type
std::vector< std::size_t > const & getMeshNodeIDsForPoint(GeoLib::Point const &pnt) const
MeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm, SearchAllNodes search_all_nodes)
static std::vector< std::unique_ptr< MeshNodeSearcher > > _mesh_node_searchers
Mesh node searcher for the meshes indexed by the meshs&#39; ids.
std::unique_ptr< MeshGeoToolsLib::SearchLength > _search_length_algorithm
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:50
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
std::vector< std::size_t > getMeshNodeIDs(GeoLib::GeoObject const &geoObj) const
static MeshNodeSearcher const & getMeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)
std::vector< std::size_t > const & getNodeIDs() const
MeshNodesAlongPolyline & getMeshNodesAlongPolyline(GeoLib::Polyline const &ply) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
MeshNodesAlongSurface & getMeshNodesAlongSurface(GeoLib::Surface const &sfc) const
Definition of the Element class.
GeoLib::Grid< MeshLib::Node > _mesh_grid