OGS
BoundaryElementsSearcher.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include "GeoLib/GeoObject.h"
7#include "GeoLib/Polyline.h"
8#include "GeoLib/Surface.h"
15#include "MeshLib/Mesh.h"
16#include "MeshLib/Node.h"
17
18namespace MeshGeoToolsLib
19{
21 MeshLib::Mesh const& mesh, MeshNodeSearcher const& mshNodeSearcher)
22 : mesh(mesh), _mshNodeSearcher(mshNodeSearcher)
23{
24}
25
27{
28 for (auto p : _boundary_elements_at_point)
29 {
30 delete p;
31 }
33 {
34 delete p;
35 }
37 {
38 delete p;
39 }
40}
41
42template <typename CacheType, typename GeometryType>
43std::vector<MeshLib::Element*> const& getBoundaryElements(
44 std::vector<CacheType*>& cached_elements,
45 std::function<GeometryType(CacheType const&)> getCachedItem,
46 GeometryType const& item, MeshLib::Mesh const& mesh,
47 MeshNodeSearcher const& mesh_node_searcher,
48 [[maybe_unused]] bool const multiple_nodes_allowed)
49{
50 if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements),
51 [&](auto const& element)
52 { return getCachedItem(*element) == item; });
53 it != cend(cached_elements))
54 {
55 return (*it)->getBoundaryElements();
56 }
57 // create new boundary elements
58 if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value)
59 {
60 cached_elements.push_back(new CacheType(mesh, mesh_node_searcher, item,
61 multiple_nodes_allowed));
62 }
63 else
64 {
65 cached_elements.push_back(
66 new CacheType(mesh, mesh_node_searcher, item));
67 }
68 return cached_elements.back()->getBoundaryElements();
69}
70
71std::vector<MeshLib::Element*> const&
73 bool const multiple_nodes_allowed)
74{
75 switch (geoObj.getGeoType())
76 {
78 {
79 std::function<GeoLib::Point(BoundaryElementsAtPoint const&)>
80 get_cached_item = &BoundaryElementsAtPoint::getPoint;
82 _boundary_elements_at_point, get_cached_item,
83 *dynamic_cast<const GeoLib::Point*>(&geoObj), mesh,
84 _mshNodeSearcher, multiple_nodes_allowed);
85 }
86 break;
88 {
89 std::function<GeoLib::Polyline(
94 *dynamic_cast<const GeoLib::Polyline*>(&geoObj), mesh,
95 _mshNodeSearcher, false);
96 }
97 break;
99 {
100 std::function<GeoLib::Surface(BoundaryElementsOnSurface const&)>
101 get_cached_item = &BoundaryElementsOnSurface::getSurface;
103 _boundary_elements_along_surfaces, get_cached_item,
104 *dynamic_cast<const GeoLib::Surface*>(&geoObj), mesh,
105 _mshNodeSearcher, false);
106 }
107 break;
108 default:
109 const static std::vector<MeshLib::Element*> dummy(0);
110 return dummy;
111 }
112}
113
114} // end namespace MeshGeoToolsLib
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:29
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
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