OGS 6.2.1-97-g73d1aeda3
BoundaryElementsAtPoint.cpp
Go to the documentation of this file.
1 
10 
11 #include "GeoLib/Point.h"
12 #include "MathLib/Point3d.h"
13 #include "MeshLib/Elements/Point.h"
14 #include "MeshLib/Mesh.h"
16 #include "MeshLib/Node.h"
17 
19 
20 namespace MeshGeoToolsLib
21 {
23  MeshLib::Mesh const& mesh, MeshNodeSearcher const& mshNodeSearcher,
24  GeoLib::Point const& point, const bool multiple_nodes_allowed)
25  : _mesh(mesh), _point(point)
26 {
27  auto const node_ids = mshNodeSearcher.getMeshNodeIDs(_point);
28  if (node_ids.empty())
29  {
30  OGS_FATAL(
31  "BoundaryElementsAtPoint: the mesh node searcher was unable to "
32  "locate the point (%f, %f, %f) in the mesh.",
33  _point[0], _point[1], _point[2]);
34  }
35  if (node_ids.size() == 1)
36  {
37  std::array<MeshLib::Node*, 1> const nodes = {
38  {const_cast<MeshLib::Node*>(_mesh.getNode(node_ids[0]))}};
39  _boundary_elements.push_back(new MeshLib::Point{nodes, node_ids[0]});
40  return;
41  }
42 
43  auto& mesh_nodes =
44  const_cast<std::vector<MeshLib::Node*>&>(mesh.getNodes());
45  std::size_t const nearest_node_id =
46  *std::min_element(node_ids.begin(), node_ids.end(),
47  [&mesh_nodes, &point](auto id0, auto id1) {
48  return MathLib::sqrDist(*mesh_nodes[id0], point) <
49  MathLib::sqrDist(*mesh_nodes[id1], point);
50  });
51 
52  if (!multiple_nodes_allowed)
53  {
54  OGS_FATAL(
55  "BoundaryElementsAtPoint: the mesh node searcher found %d points "
56  "near the requested point (%f, %f, %f) in the mesh, while exactly "
57  "one is expected. Node (id=%d) (%f, %f, %f) has distance %f.",
58  node_ids.size(), _point[0], _point[1], _point[2],
59  mesh_nodes[nearest_node_id]->getID(),
60  (*mesh_nodes[nearest_node_id])[0],
61  (*mesh_nodes[nearest_node_id])[1],
62  (*mesh_nodes[nearest_node_id])[2],
63  MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
64  }
65  WARN(
66  "BoundaryElementsAtPoint: the mesh node searcher found %d points "
67  "near the requested point (%f, %f, %f) in the mesh, while exactly "
68  "one is expected. Node (id=%d) (%f, %f, %f) has distance %f.",
69  node_ids.size(), _point[0], _point[1], _point[2],
70  mesh_nodes[nearest_node_id]->getID(),
71  (*mesh_nodes[nearest_node_id])[0],
72  (*mesh_nodes[nearest_node_id])[1],
73  (*mesh_nodes[nearest_node_id])[2],
74  MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
75 
76  std::array<MeshLib::Node*, 1> const nodes = {
77  {const_cast<MeshLib::Node*>(_mesh.getNode(nearest_node_id))}};
78 
79  _boundary_elements.push_back(
80  new MeshLib::Point{nodes, nearest_node_id});
81 }
82 
84 {
85  for (auto p : _boundary_elements)
86  {
87  delete p;
88  }
89 }
90 } // namespace MeshGeoToolsLib
Implementation of heuristic search length strategy.
Definition of the Point class.
double sqrDist(const double *p0, const double *p1)
Definition: MathTools.h:83
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:84
Definition of the Node class.
Definition of the Point3d class.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:105
Definition of the Mesh class.
std::size_t getID() const
Definition: Point3dWithID.h:62
std::vector< std::size_t > getMeshNodeIDs(GeoLib::GeoObject const &geoObj) const
BoundaryElementsAtPoint(MeshLib::Mesh const &mesh, MeshNodeSearcher const &mshNodeSearcher, GeoLib::Point const &point, const bool multiple_nodes_allowed)
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
std::vector< MeshLib::Element * > _boundary_elements