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