OGS
ElementSearch.h
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#pragma once
5
6#include <limits>
7#include <vector>
8
9#include "GeoLib/AABB.h"
10#include "MeshLib/Mesh.h"
11#include "MeshLib/MeshEnums.h"
12
13namespace MeshLib {
14
15// forward declarations
16class Mesh;
17class Element;
18
20class ElementSearch final
21{
22public:
23 explicit ElementSearch(const MeshLib::Mesh &mesh);
24
26 const std::vector<std::size_t>& getSearchedElementIDs() const { return _marked_elements; }
27
38 template <typename PROPERTY_TYPE>
39 std::size_t searchByPropertyValue(std::string const& property_name,
40 PROPERTY_TYPE const property_value)
41 {
43 property_name, property_value, property_value, false);
44 }
45
62 template <typename PROPERTY_TYPE>
64 std::string const& property_name,
65 PROPERTY_TYPE const min_property_value,
66 PROPERTY_TYPE const max_property_value,
67 bool outside_of)
68 {
70 try
71 {
72 pv = _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>(
73 property_name, MeshLib::MeshItemType::Cell, 1);
74 }
75 catch (std::runtime_error const& e)
76 {
77 ERR("{:s}", e.what());
78 WARN(
79 "Value-based element removal currently only works for "
80 "scalars.");
81 return 0;
82 }
83
84 std::vector<std::size_t> matchedIDs;
85
86 if (outside_of)
87 {
88 for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
89 {
90 if ((*pv)[i] < min_property_value ||
91 (*pv)[i] > max_property_value)
92 {
93 matchedIDs.push_back(i);
94 }
95 }
96 }
97 else
98 {
99 for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
100 {
101 if ((*pv)[i] >= min_property_value &&
102 (*pv)[i] <= max_property_value)
103 {
104 matchedIDs.push_back(i);
105 }
106 }
107 }
108 updateUnion(matchedIDs);
109 return matchedIDs.size();
110 }
111
113 std::size_t searchByElementType(MeshElemType eleType);
114
116 std::size_t searchByContent(double eps = std::numeric_limits<double>::epsilon());
117
121 std::size_t searchByBoundingBox(GeoLib::AABB const& aabb,
122 bool const invert = false);
123
125 std::size_t searchByNodeIDs(const std::vector<std::size_t>& nodes);
126
127private:
129 void updateUnion(const std::vector<std::size_t> &vec);
130
134 std::vector<std::size_t> _marked_elements;
135};
136
137} // end namespace MeshLib
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
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)
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
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 searchByPropertyValueRange(std::string const &property_name, PROPERTY_TYPE const min_property_value, PROPERTY_TYPE const max_property_value, bool outside_of)
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)
std::size_t searchByPropertyValue(std::string const &property_name, PROPERTY_TYPE const property_value)
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.
constexpr std::size_t getNumberOfTuples() const
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37