OGS
BoundaryElementsOnSurface.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/Surface.h"
9#include "MeshLib/Mesh.h"
11
12namespace MeshGeoToolsLib
13{
15 MeshLib::Mesh const& mesh, MeshNodeSearcher const& mshNodeSearcher,
16 GeoLib::Surface const& sfc)
17 : _sfc(sfc)
18{
19 // search elements near the surface
20 auto node_ids_on_sfc = mshNodeSearcher.getMeshNodeIDs(sfc);
22 es.searchByNodeIDs(node_ids_on_sfc);
23 auto& ele_ids_near_sfc = es.getSearchedElementIDs();
24
25 // get a list of faces made of the nodes
26 for (auto ele_id : ele_ids_near_sfc)
27 {
28 auto* e = mesh.getElement(ele_id);
29 // skip internal elements
30 if (!e->isBoundaryElement())
31 {
32 continue;
33 }
34 // find faces on surface
35 for (unsigned i = 0; i < e->getNumberOfFaces(); i++)
36 {
37 auto* face = e->getFace(i);
38 // check
39 std::size_t cnt_match = 0;
40 for (std::size_t j = 0; j < face->getNumberOfBaseNodes(); j++)
41 {
42 if (std::find(node_ids_on_sfc.begin(), node_ids_on_sfc.end(),
43 getNodeIndex(*face, j)) != node_ids_on_sfc.end())
44 {
45 cnt_match++;
46 }
47 else
48 {
49 break;
50 }
51 }
52 // update the list
53 if (cnt_match == face->getNumberOfBaseNodes())
54 {
55 _boundary_elements.push_back(
56 const_cast<MeshLib::Element*>(face));
57 }
58 else
59 {
60 delete face;
61 }
62 }
63 }
64}
65
67{
68 for (auto p : _boundary_elements)
69 {
70 delete p;
71 }
72}
73
74} // end namespace MeshGeoToolsLib
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
BoundaryElementsOnSurface(MeshLib::Mesh const &mesh, MeshNodeSearcher const &mshNodeSearcher, GeoLib::Surface const &sfc)
std::vector< MeshLib::Element * > _boundary_elements
std::vector< std::size_t > getMeshNodeIDs(GeoLib::GeoObject const &geoObj) const
Element search class.
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
std::size_t searchByNodeIDs(const std::vector< std::size_t > &nodes)
Marks all elements connecting to any of the given nodes.
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:85