OGS 6.1.0-1721-g6382411ad
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 
32 std::vector<std::unique_ptr<MeshNodeSearcher>> MeshNodeSearcher::_mesh_node_searchers;
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  delete pointer;
51  for (auto pointer : _mesh_nodes_along_polylines)
52  delete pointer;
53  for (auto pointer : _mesh_nodes_along_surfaces)
54  delete pointer;
55 }
56 
57 std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(
58  GeoLib::GeoObject const& geoObj) const
59 {
60  std::vector<std::size_t> vec_nodes;
61  switch (geoObj.getGeoType()) {
63  {
64  vec_nodes = this->getMeshNodeIDsForPoint(*static_cast<const GeoLib::Point*>(&geoObj));
65  break;
66  }
68  vec_nodes = this->getMeshNodeIDsAlongPolyline(*static_cast<const GeoLib::Polyline*>(&geoObj));
69  break;
71  vec_nodes = this->getMeshNodeIDsAlongSurface(*static_cast<const GeoLib::Surface*>(&geoObj));
72  break;
73  default:
74  break;
75  }
76  return vec_nodes;
77 }
78 
79 std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs(
80  std::vector<MathLib::Point3dWithID*> const& points) const
81 {
82  double const epsilon_radius = _search_length_algorithm->getSearchLength();
83 
84  std::vector<std::size_t> node_ids;
85  node_ids.reserve(points.size());
86 
87  for (auto const* const p_ptr : points)
88  {
89  auto const& p = *p_ptr;
90  std::vector<std::size_t> const ids =
91  _mesh_grid.getPointsInEpsilonEnvironment(p, epsilon_radius);
92  if (ids.empty())
93  {
94  OGS_FATAL(
95  "No nodes could be found in the mesh for point %d : (%g, %g, "
96  "%g) in %g epsilon radius in the mesh '%s'",
97  p.getID(), p[0], p[1], p[2], epsilon_radius,
98  _mesh.getName().c_str());
99  }
100  if (ids.size() != 1)
101  {
102  OGS_FATAL(
103  "Found %d nodes in the mesh for point %d : (%g, %g, %g) in %g "
104  "epsilon radius in the mesh '%s'. Expected to find exactly one "
105  "node.",
106  ids.size(), p.getID(), p[0], p[1], p[2], epsilon_radius,
107  _mesh.getName().c_str());
108  }
109  node_ids.push_back(ids.front());
110  }
111  return node_ids;
112 }
113 
114 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsForPoint(
115  GeoLib::Point const& pnt) const
116 {
117  return getMeshNodesOnPoint(pnt).getNodeIDs();
118 }
119 
120 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongPolyline(
121  GeoLib::Polyline const& ply) const
122 {
124 }
125 
126 std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongSurface(
127  GeoLib::Surface const& sfc) const
128 {
129  return getMeshNodesAlongSurface(sfc).getNodeIDs();
130 }
131 
133  GeoLib::Point const& pnt) const
134 {
135  std::vector<MeshNodesOnPoint*>::const_iterator it(_mesh_nodes_on_points.begin());
136  for (; it != _mesh_nodes_on_points.end(); ++it) {
137  if (&(*it)->getPoint() == &pnt) {
138  return *(*it);
139  }
140  }
141 
142  _mesh_nodes_on_points.push_back(
144  _mesh_grid,
145  pnt,
146  _search_length_algorithm->getSearchLength(),
148  return *_mesh_nodes_on_points.back();
149 }
150 
152  GeoLib::Polyline const& ply) const
153 {
154  std::vector<MeshNodesAlongPolyline*>::const_iterator it(_mesh_nodes_along_polylines.begin());
155  for (; it != _mesh_nodes_along_polylines.end(); ++it) {
156  if (&(*it)->getPolyline() == &ply) {
157  // we calculated mesh nodes for this polyline already
158  return *(*it);
159  }
160  }
161 
162  // compute nodes (and supporting points) along polyline
164  _mesh, ply, _search_length_algorithm->getSearchLength(),
166  return *_mesh_nodes_along_polylines.back();
167 }
168 
170  GeoLib::Surface const& sfc) const
171 {
172  std::vector<MeshNodesAlongSurface*>::const_iterator it(_mesh_nodes_along_surfaces.begin());
173  for (; it != _mesh_nodes_along_surfaces.end(); ++it) {
174  if (&(*it)->getSurface() == &sfc) {
175  // we calculated mesh nodes on this surface already
176  return *(*it);
177  }
178  }
179 
180  // compute nodes (and supporting points) on surface
181  _mesh_nodes_along_surfaces.push_back(
183  sfc,
184  _search_length_algorithm->getSearchLength(),
186  return *_mesh_nodes_along_surfaces.back();
187 }
188 
190  MeshLib::Mesh const& mesh,
191  std::unique_ptr<MeshGeoToolsLib::SearchLength>&& search_length_algorithm)
192 {
193  std::size_t const mesh_id = mesh.getID();
194  if (_mesh_node_searchers.size() < mesh_id+1)
195  _mesh_node_searchers.resize(mesh_id+1);
196 
197  if (_mesh_node_searchers[mesh_id])
198  {
199  auto const& m = *_mesh_node_searchers[mesh_id];
200  // return searcher if search length algorithm and the returned search
201  // lenght are the same, else recreate the searcher
202  if (typeid(m._search_length_algorithm) ==
203  typeid(search_length_algorithm) &&
204  m._search_length_algorithm->getSearchLength() ==
205  search_length_algorithm->getSearchLength())
206  {
207  return m;
208  }
209  }
210 
211  _mesh_node_searchers[mesh_id] =
212  std::make_unique<MeshGeoToolsLib::MeshNodeSearcher>(
213  mesh, std::move(search_length_algorithm), SearchAllNodes::Yes);
214 
215  return *_mesh_node_searchers[mesh_id];
216 }
217 
218 std::size_t
220 {
221  return _mesh.getID();
222 }
223 
224 } // 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:588
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
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:71
virtual GEOTYPE getGeoType() const =0
return a geometry type
MeshNodesAlongSurface & getMeshNodesAlongSurface(GeoLib::Surface const &sfc) const
Definition of the Element class.
GeoLib::Grid< MeshLib::Node > _mesh_grid