OGS
BoundaryElementsAtPoint.cpp
Go to the documentation of this file.
1
11
12#include "BaseLib/MPI.h"
13#include "GeoLib/Point.h"
14#include "MathLib/Point3d.h"
17#include "MeshLib/Mesh.h"
19#include "MeshLib/Node.h"
20
21namespace MeshGeoToolsLib
22{
24 MeshLib::Mesh const& mesh, MeshNodeSearcher const& mshNodeSearcher,
25 GeoLib::Point const& point, const bool multiple_nodes_allowed)
26 : _point(point)
27{
28 auto const node_ids = mshNodeSearcher.getMeshNodeIDs(_point);
29
30#ifdef USE_PETSC
31 std::size_t const number_of_found_nodes_at_rank = node_ids.size();
32 std::size_t const number_of_total_found_nodes = BaseLib::MPI::allreduce(
33 number_of_found_nodes_at_rank, MPI_SUM, BaseLib::MPI::Mpi{});
34
35 if (number_of_total_found_nodes == 0)
36 {
38 "BoundaryElementsAtPoint: the mesh node searcher was unable to "
39 "locate the point ({:f}, {:f}, {:f}) in the mesh.",
40 _point[0], _point[1], _point[2]);
41 }
42
43 if (number_of_found_nodes_at_rank == 0)
44 {
45 return;
46 }
47#else
48 if (node_ids.empty())
49 {
51 "BoundaryElementsAtPoint: the mesh node searcher was unable to "
52 "locate the point ({:f}, {:f}, {:f}) in the mesh.",
53 _point[0], _point[1], _point[2]);
54 }
55#endif
56
57 if (node_ids.size() == 1)
58 {
59 std::array<MeshLib::Node*, 1> const nodes = {
60 {const_cast<MeshLib::Node*>(mesh.getNode(node_ids[0]))}};
61
62 _boundary_elements.push_back(new MeshLib::Point{nodes, node_ids[0]});
63 return;
64 }
65
66 auto& mesh_nodes =
67 const_cast<std::vector<MeshLib::Node*>&>(mesh.getNodes());
68 std::size_t const nearest_node_id =
69 *std::min_element(node_ids.begin(), node_ids.end(),
70 [&mesh_nodes, &point](auto id0, auto id1)
71 {
72 return MathLib::sqrDist(*mesh_nodes[id0], point) <
73 MathLib::sqrDist(*mesh_nodes[id1], point);
74 });
75
76 if (!multiple_nodes_allowed)
77 {
79 "BoundaryElementsAtPoint: the mesh node searcher found {:d} points "
80 "near the requested point ({:f}, {:f}, {:f}) in the mesh, while "
81 "exactly one is expected. Node (id={:d}) ({:f}, {:f}, {:f}) has "
82 "distance {:f}.",
83 node_ids.size(), _point[0], _point[1], _point[2],
84 mesh_nodes[nearest_node_id]->getID(),
85 (*mesh_nodes[nearest_node_id])[0],
86 (*mesh_nodes[nearest_node_id])[1],
87 (*mesh_nodes[nearest_node_id])[2],
88 MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
89 }
90 WARN(
91 "BoundaryElementsAtPoint: the mesh node searcher found {:d} points "
92 "near the requested point ({:f}, {:f}, {:f}) in the mesh, while "
93 "exactly one is expected. Node (id={:d}) ({:f}, {:f}, {:f}) has "
94 "distance {:f}.",
95 node_ids.size(), _point[0], _point[1], _point[2],
96 mesh_nodes[nearest_node_id]->getID(), (*mesh_nodes[nearest_node_id])[0],
97 (*mesh_nodes[nearest_node_id])[1], (*mesh_nodes[nearest_node_id])[2],
98 MathLib::sqrDist(*mesh_nodes[nearest_node_id], point));
99
100 std::array<MeshLib::Node*, 1> const nodes = {
101 {const_cast<MeshLib::Node*>(mesh.getNode(nearest_node_id))}};
102
103 _boundary_elements.push_back(new MeshLib::Point{nodes, nearest_node_id});
104}
105
107{
108 for (auto p : _boundary_elements)
109 {
110 delete p;
111 }
112}
113} // namespace MeshGeoToolsLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the Point class.
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Definition of the Mesh class.
Definition of the Node class.
Definition of the Point3d class.
std::size_t getID() const
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:106
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition Mesh.h:91
static T allreduce(T const &value, MPI_Op const &mpi_op, Mpi const &mpi)
Definition MPI.h:128
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:26