OGS
BoundaryElementsAtPoint.cpp
Go to the documentation of this file.
1 
11 
12 #include "GeoLib/Point.h"
13 #include "MathLib/Point3d.h"
15 #include "MeshLib/Elements/Point.h"
16 #include "MeshLib/Mesh.h"
18 #include "MeshLib/Node.h"
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  {
49  return MathLib::sqrDist(*mesh_nodes[id0], point) <
50  MathLib::sqrDist(*mesh_nodes[id1], point);
51  });
52 
53  if (!multiple_nodes_allowed)
54  {
55  OGS_FATAL(
56  "BoundaryElementsAtPoint: the mesh node searcher found {:d} points "
57  "near the requested point ({:f}, {:f}, {:f}) in the mesh, while "
58  "exactly one is expected. Node (id={:d}) ({:f}, {:f}, {:f}) has "
59  "distance {:f}.",
60  node_ids.size(), _point[0], _point[1], _point[2],
61  mesh_nodes[nearest_node_id]->getID(),
62  (*mesh_nodes[nearest_node_id])[0],
63  (*mesh_nodes[nearest_node_id])[1],
64  (*mesh_nodes[nearest_node_id])[2],
65  MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
66  }
67  WARN(
68  "BoundaryElementsAtPoint: the mesh node searcher found {:d} points "
69  "near the requested point ({:f}, {:f}, {:f}) in the mesh, while "
70  "exactly one is expected. Node (id={:d}) ({:f}, {:f}, {:f}) has "
71  "distance {:f}.",
72  node_ids.size(), _point[0], _point[1], _point[2],
73  mesh_nodes[nearest_node_id]->getID(), (*mesh_nodes[nearest_node_id])[0],
74  (*mesh_nodes[nearest_node_id])[1], (*mesh_nodes[nearest_node_id])[2],
75  MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
76 
77  std::array<MeshLib::Node*, 1> const nodes = {
78  {const_cast<MeshLib::Node*>(_mesh.getNode(nearest_node_id))}};
79 
80  _boundary_elements.push_back(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
#define OGS_FATAL(...)
Definition: Error.h:26
Definition of the Point class.
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of the Mesh class.
Definition of the Node class.
Definition of the Point3d class.
std::size_t getID() const
Definition: Point3dWithID.h:62
BoundaryElementsAtPoint(MeshLib::Mesh const &mesh, MeshNodeSearcher const &mshNodeSearcher, GeoLib::Point const &point, const bool multiple_nodes_allowed)
std::vector< MeshLib::Element * > _boundary_elements
std::vector< std::size_t > getMeshNodeIDs(GeoLib::GeoObject const &geoObj) const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:74
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition: Point3d.h:48