OGS
MeshGeoToolsLib::BoundaryElementsAlongPolyline Class Reference

Detailed Description

This class collects element edges located along a polyline. Note that internal edges are not collected in this class.

Definition at line 27 of file BoundaryElementsAlongPolyline.h.

#include <BoundaryElementsAlongPolyline.h>

Collaboration diagram for MeshGeoToolsLib::BoundaryElementsAlongPolyline:
[legend]

Public Member Functions

 BoundaryElementsAlongPolyline (MeshLib::Mesh const &mesh, MeshNodeSearcher const &mshNodeSearcher, GeoLib::Polyline const &ply)
virtual ~BoundaryElementsAlongPolyline ()
 destructor
GeoLib::Polyline const & getPolyline () const
std::vector< MeshLib::Element * > const & getBoundaryElements () const

Private Attributes

GeoLib::Polyline const & _ply
std::vector< MeshLib::Element * > _boundary_elements

Constructor & Destructor Documentation

◆ BoundaryElementsAlongPolyline()

MeshGeoToolsLib::BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline ( MeshLib::Mesh const & mesh,
MeshNodeSearcher const & mshNodeSearcher,
GeoLib::Polyline const & ply )

Constructor

Parameters
mesha mesh object
mshNodeSearchera MeshNodeSearcher object which is internally used to search mesh nodes
plya polyline object where edges are searched

Definition at line 98 of file BoundaryElementsAlongPolyline.cpp.

101 : _ply(ply)
102{
103 // search nodes and elements located along the polyline
104 auto node_ids_on_poly = mshNodeSearcher.getMeshNodeIDs(ply);
105 MeshLib::ElementSearch es(mesh);
106 es.searchByNodeIDs(node_ids_on_poly);
107 auto const& ele_ids_near_ply = es.getSearchedElementIDs();
108
109 // check all edges of the elements near the polyline
110 for (auto ele_id : ele_ids_near_ply)
111 {
112 auto* e = mesh.getElement(ele_id);
113 // skip line elements
114 if (e->getDimension() == 1)
115 {
116 continue;
117 }
118 // skip internal elements
119 if (!e->isBoundaryElement())
120 {
121 continue;
122 }
123 // find edges on the polyline
124 for (unsigned i = 0; i < e->getNumberOfEdges(); i++)
125 {
126 auto* edge = e->getEdge(i);
127 // check if all edge nodes are along the polyline (if yes, store a
128 // distance)
129 std::vector<std::size_t> edge_node_distances_along_ply;
130 if (includesAllEdgeNodeIDs(node_ids_on_poly, *edge,
131 edge_node_distances_along_ply))
132 {
133 auto* new_edge = modifyEdgeNodeOrdering(
134 *edge, ply, edge_node_distances_along_ply,
135 node_ids_on_poly);
136 if (edge != new_edge)
137 {
138 delete edge;
139 }
140 _boundary_elements.push_back(new_edge);
141 }
142 else
143 {
144 delete edge;
145 }
146 }
147 }
148
149 // The sort was necessary in OGS-5 for some reason. I'm not sure if it is
150 // needed anymore in OGS-6.
151 // sort picked edges according to a distance of their first node along the
152 // polyline
153 std::sort(begin(_boundary_elements), end(_boundary_elements),
154 [&](MeshLib::Element* e1, MeshLib::Element* e2)
155 {
156 std::size_t dist1 = std::distance(
157 node_ids_on_poly.begin(),
158 std::find(node_ids_on_poly.begin(),
159 node_ids_on_poly.end(), getNodeIndex(*e1, 0)));
160 std::size_t dist2 = std::distance(
161 node_ids_on_poly.begin(),
162 std::find(node_ids_on_poly.begin(),
163 node_ids_on_poly.end(), getNodeIndex(*e2, 0)));
164 return (dist1 < dist2);
165 });
166}
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:226
MeshLib::Element * modifyEdgeNodeOrdering(const MeshLib::Element &edge, const GeoLib::Polyline &ply, const std::vector< std::size_t > &edge_node_distances_along_ply, const std::vector< std::size_t > &node_ids_on_poly)
bool includesAllEdgeNodeIDs(std::vector< std::size_t > const &vec_node_ids, MeshLib::Element const &edge, std::vector< std::size_t > &edge_node_distances)

References _boundary_elements, _ply, MeshLib::Mesh::getElement(), MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs(), MeshLib::ElementSearch::getSearchedElementIDs(), and MeshLib::ElementSearch::searchByNodeIDs().

◆ ~BoundaryElementsAlongPolyline()

MeshGeoToolsLib::BoundaryElementsAlongPolyline::~BoundaryElementsAlongPolyline ( )
virtual

destructor

Definition at line 168 of file BoundaryElementsAlongPolyline.cpp.

169{
170 for (auto p : _boundary_elements)
171 {
172 delete p;
173 }
174}

References _boundary_elements.

Member Function Documentation

◆ getBoundaryElements()

std::vector< MeshLib::Element * > const & MeshGeoToolsLib::BoundaryElementsAlongPolyline::getBoundaryElements ( ) const
inline

Return the vector of boundary elements (i.e. edges). The elements are sorted according to their distance to the starting point of the given polyline.

Definition at line 56 of file BoundaryElementsAlongPolyline.h.

57 {
58 return _boundary_elements;
59 }

References _boundary_elements.

◆ getPolyline()

GeoLib::Polyline const & MeshGeoToolsLib::BoundaryElementsAlongPolyline::getPolyline ( ) const
inline

Deploying this method the user can get access to the underlying GeoLib::Polyline.

Returns
the underlying GeoLib::Polyline

Definition at line 49 of file BoundaryElementsAlongPolyline.h.

49{ return _ply; }

References _ply.

Referenced by MeshGeoToolsLib::BoundaryElementsSearcher::getBoundaryElements().

Member Data Documentation

◆ _boundary_elements

std::vector<MeshLib::Element*> MeshGeoToolsLib::BoundaryElementsAlongPolyline::_boundary_elements
private

◆ _ply

GeoLib::Polyline const& MeshGeoToolsLib::BoundaryElementsAlongPolyline::_ply
private

Definition at line 62 of file BoundaryElementsAlongPolyline.h.

Referenced by BoundaryElementsAlongPolyline(), and getPolyline().


The documentation for this class was generated from the following files: