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