OGS
ElementSearch.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
4#include "ElementSearch.h"
5
6#include <range/v3/algorithm/any_of.hpp>
7#include <range/v3/range/conversion.hpp>
8#include <range/v3/view/filter.hpp>
9#include <range/v3/view/take.hpp>
10
11#include "BaseLib/Algorithm.h"
13#include "MeshLib/Node.h"
14
15namespace MeshLib
16{
18
19template <typename Container, typename Predicate>
20std::vector<std::size_t> filter(Container const& container, Predicate const& p)
21{
22 return ranges::views::filter(container, p) | views::ids |
23 ranges::to<std::vector>;
24}
25
27{
28 auto matchedIDs = filter(_mesh.getElements(), [&](MeshLib::Element const* e)
29 { return e->getGeomType() == eleType; });
30
31 this->updateUnion(matchedIDs);
32 return matchedIDs.size();
33}
34
35std::size_t ElementSearch::searchByContent(double eps)
36{
37 auto matchedIDs =
38 filter(_mesh.getElements(), [&eps](MeshLib::Element const* e)
39 { return e->getContent() < eps; });
40
41 this->updateUnion(matchedIDs);
42 return matchedIDs.size();
43}
44
46 bool const invert)
47{
48 auto matchedIDs = filter(
49 _mesh.getElements(),
50 [&aabb, invert](MeshLib::Element const* e)
51 {
52 // any node of element is in aabb.
53 return ranges::any_of(
54 e->nodes() | ranges::views::take(e->getNumberOfBaseNodes()),
55 [&aabb, invert](auto const* n)
56 { return (aabb.containsPoint(*n, 0) != invert); });
57 });
58
59 this->updateUnion(matchedIDs);
60 return matchedIDs.size();
61}
62
64 const std::vector<std::size_t>& nodes)
65{
66 std::vector<std::size_t> connected_elements;
67 for (std::size_t node_id : nodes)
68 {
69 auto const& elements = _mesh.getElementsConnectedToNode(node_id);
70 std::transform(begin(elements), end(elements),
71 back_inserter(connected_elements),
72 [](Element const* const e) { return e->getID(); });
73 }
74
75 BaseLib::makeVectorUnique(connected_elements);
76
77 this->updateUnion(connected_elements);
78 return connected_elements.size();
79}
80
81void ElementSearch::updateUnion(const std::vector<std::size_t>& vec)
82{
83 std::vector<std::size_t> vec_temp(vec.size() + _marked_elements.size());
84 auto it = std::set_union(vec.begin(), vec.end(), _marked_elements.begin(),
85 _marked_elements.end(), vec_temp.begin());
86 vec_temp.resize(it - vec_temp.begin());
87 _marked_elements.assign(vec_temp.begin(), vec_temp.end());
88}
89
90} // end namespace MeshLib
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:45
void updateUnion(const std::vector< std::size_t > &vec)
Updates the vector of marked elements with values from vec.
std::size_t searchByBoundingBox(GeoLib::AABB const &aabb, bool const invert=false)
std::size_t searchByElementType(MeshElemType eleType)
Marks all elements of the given element type.
std::size_t searchByNodeIDs(const std::vector< std::size_t > &nodes)
Marks all elements connecting to any of the given nodes.
std::size_t searchByContent(double eps=std::numeric_limits< double >::epsilon())
Marks all elements with a volume smaller than eps.
ElementSearch(const MeshLib::Mesh &mesh)
const MeshLib::Mesh & _mesh
The mesh from which elements should be removed.
std::vector< std::size_t > _marked_elements
The vector of element indices that should be removed.
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
void makeVectorUnique(std::vector< T > &v)
Definition Algorithm.h:173
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216
std::vector< std::size_t > filter(Container const &container, Predicate const &p)
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37