OGS
BoundaryElementsSearcher.cpp
Go to the documentation of this file.
1
11
12#include "GeoLib/GeoObject.h"
13#include "GeoLib/Polyline.h"
14#include "GeoLib/Surface.h"
21#include "MeshLib/Mesh.h"
22#include "MeshLib/Node.h"
23
24namespace MeshGeoToolsLib
25{
27 MeshLib::Mesh const& mesh, MeshNodeSearcher const& mshNodeSearcher)
28 : mesh(mesh), _mshNodeSearcher(mshNodeSearcher)
29{
30}
31
33{
34 for (auto p : _boundary_elements_at_point)
35 {
36 delete p;
37 }
39 {
40 delete p;
41 }
43 {
44 delete p;
45 }
46}
47
48template <typename CacheType, typename GeometryType>
49std::vector<MeshLib::Element*> const& getBoundaryElements(
50 std::vector<CacheType*>& cached_elements,
51 std::function<GeometryType(CacheType const&)> getCachedItem,
52 GeometryType const& item, MeshLib::Mesh const& mesh,
53 MeshNodeSearcher const& mesh_node_searcher,
54 [[maybe_unused]] bool const multiple_nodes_allowed)
55{
56 if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements),
57 [&](auto const& element)
58 { return getCachedItem(*element) == item; });
59 it != cend(cached_elements))
60 {
61 return (*it)->getBoundaryElements();
62 }
63 // create new boundary elements
64 if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value)
65 {
66 cached_elements.push_back(new CacheType(mesh, mesh_node_searcher, item,
67 multiple_nodes_allowed));
68 }
69 else
70 {
71 cached_elements.push_back(
72 new CacheType(mesh, mesh_node_searcher, item));
73 }
74 return cached_elements.back()->getBoundaryElements();
75}
76
77std::vector<MeshLib::Element*> const&
79 bool const multiple_nodes_allowed)
80{
81 switch (geoObj.getGeoType())
82 {
84 {
85 std::function<GeoLib::Point(BoundaryElementsAtPoint const&)>
86 get_cached_item = &BoundaryElementsAtPoint::getPoint;
88 _boundary_elements_at_point, get_cached_item,
89 *dynamic_cast<const GeoLib::Point*>(&geoObj), mesh,
90 _mshNodeSearcher, multiple_nodes_allowed);
91 }
92 break;
94 {
95 std::function<GeoLib::Polyline(
100 *dynamic_cast<const GeoLib::Polyline*>(&geoObj), mesh,
101 _mshNodeSearcher, false);
102 }
103 break;
105 {
106 std::function<GeoLib::Surface(BoundaryElementsOnSurface const&)>
107 get_cached_item = &BoundaryElementsOnSurface::getSurface;
109 _boundary_elements_along_surfaces, get_cached_item,
110 *dynamic_cast<const GeoLib::Surface*>(&geoObj), mesh,
111 _mshNodeSearcher, false);
112 }
113 break;
114 default:
115 const static std::vector<MeshLib::Element*> dummy(0);
116 return dummy;
117 }
118}
119
120} // end namespace MeshGeoToolsLib
Definition of the Element class.
Base class for classes Point, Polyline, Surface.
Definition of the Mesh class.
Definition of the Node class.
Definition of the PolyLine class.
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition Surface.h:33
This class collects point elements located at a given point elements.
BoundaryElementsSearcher(MeshLib::Mesh const &mesh, MeshNodeSearcher const &mshNodeSearcher)
std::vector< MeshLib::Element * > const & getBoundaryElements(GeoLib::GeoObject const &geoObj, bool const multiple_nodes_allowed)
std::vector< BoundaryElementsAlongPolyline * > _boundary_elements_along_polylines
std::vector< BoundaryElementsAtPoint * > _boundary_elements_at_point
std::vector< BoundaryElementsOnSurface * > _boundary_elements_along_surfaces
std::vector< MeshLib::Element * > const & getBoundaryElements(std::vector< CacheType * > &cached_elements, std::function< GeometryType(CacheType const &)> getCachedItem, GeometryType const &item, MeshLib::Mesh const &mesh, MeshNodeSearcher const &mesh_node_searcher, bool const multiple_nodes_allowed)
virtual GEOTYPE getGeoType() const =0
return a geometry type