EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_ConnectedComponents.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
11#ifndef EBGEOMETRY_CONNECTEDCOMPONENTS_HPP
12#define EBGEOMETRY_CONNECTEDCOMPONENTS_HPP
13
14// Std includes
15#include <cstdint>
16#include <memory>
17#include <vector>
18
19// Our includes
21#include "EBGeometry_Domain.hpp"
22#include "EBGeometry_Macros.hpp"
23#include "EBGeometry_Tape.hpp"
24#include "EBGeometry_Vec.hpp"
25
26namespace EBGeometry {
27
28template <class T>
29class ConnectedComponents;
30
31namespace ComponentsDetail {
32
33template <class T>
34struct Cells;
35
45template <class T>
47label(const std::shared_ptr<const Cells<T>>& a_cells, const std::vector<uint32_t>& a_groupOf, uint32_t a_numGroups);
48
49} // namespace ComponentsDetail
50
55template <class T>
57{
64 T m_resolution = T(0);
65
72
83 static constexpr uint64_t DefaultMaxCells = 100000000U;
84
91};
92
98template <class T>
100{
104 uint32_t m_group = 0;
105
109 T m_volume = T(0);
110
115
120
125 bool m_reachesBox = false;
126};
127
136template <class T>
138{
139public:
143 static constexpr uint32_t None = 0xFFFFFFFFU;
144
149 [[nodiscard]] EBGEOMETRY_HOST
150 uint32_t
151 getNumComponents() const noexcept;
152
158 [[nodiscard]] EBGEOMETRY_HOST
159 const ConnectedComponent<T>&
160 component(uint32_t a_component) const;
161
166 [[nodiscard]] EBGEOMETRY_HOST
167 uint32_t
168 getNumGroups() const noexcept;
169
175 [[nodiscard]] EBGEOMETRY_HOST
176 std::vector<uint32_t>
177 componentsOf(uint32_t a_group) const;
178
185 [[nodiscard]] EBGEOMETRY_HOST
186 const std::vector<uint32_t>&
187 neighbors(uint32_t a_component) const;
188
195 [[nodiscard]] EBGEOMETRY_HOST
196 uint32_t
197 componentAt(const Vec3T<T>& a_point) const noexcept;
198
203 [[nodiscard]] EBGEOMETRY_HOST
204 T
205 resolution() const noexcept;
206
211 [[nodiscard]] EBGEOMETRY_HOST
212 const BoundingVolumes::AABBT<T>&
213 box() const noexcept;
214
220 [[nodiscard]] EBGEOMETRY_HOST
221 uint64_t
222 getNumCells() const noexcept;
223
224private:
228 ConnectedComponents() = default;
229
230 template <class U>
231 friend ConnectedComponents<U>
232 ComponentsDetail::label(const std::shared_ptr<const ComponentsDetail::Cells<U>>& a_cells,
233 const std::vector<uint32_t>& a_groupOf,
234 uint32_t a_numGroups);
235
239 std::shared_ptr<const ComponentsDetail::Cells<T>> m_cells;
240
244 std::vector<uint32_t> m_componentOfCell;
245
249 std::vector<ConnectedComponent<T>> m_components;
250
254 std::vector<std::vector<uint32_t>> m_neighbors;
255
259 std::vector<uint32_t> m_firstOfGroup;
260};
261
280template <class T, class... UserPrimitives>
281[[nodiscard]] EBGEOMETRY_HOST
283connectedComponents(const Tape<T, UserPrimitives...>& a_tape, const ComponentOptions<T>& a_options);
284
297template <class T, class... UserPrimitives>
298[[nodiscard]] EBGEOMETRY_HOST
300connectedComponents(const Tape<T, UserPrimitives...>& a_tape,
301 const std::vector<uint32_t>& a_groupOf,
302 const ComponentOptions<T>& a_options);
303
315template <class T, class... UserPrimitives>
316[[nodiscard]] EBGEOMETRY_HOST
318connectedComponents(const Domain<T, UserPrimitives...>& a_domain, const ComponentOptions<T>& a_options);
319
320} // namespace EBGeometry
321
322#include "EBGeometry_ConnectedComponentsImplem.hpp"
323
324#endif
Declarations of bounding volume types used in bounding volume hierarchies.
ConnectedComponents< T > label(const std::shared_ptr< const Cells< T > > &a_cells, const std::vector< uint32_t > &a_groupOf, uint32_t a_numGroups)
The components of a search's cells for a grouping of the regions.
Domain: the regions a downstream code computes in and its groups of surfaces, over a tape.
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Utility macros for EBGeometry.
Declaration of Tape, a composed object (an Expr) compiled into a pool, and its evaluator.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Axis-aligned bounding box (AABB) enclosing a set of 3D points.
Definition EBGeometry_BoundingVolumes.hpp:37
The connected components of the regions of a tape, or of groups of them (see connectedComponents()): ...
Definition EBGeometry_ConnectedComponents.hpp:138
uint32_t getNumGroups() const noexcept
How many groups there are: the regions of the tape, or the groups given (one more than the largest).
uint32_t getNumComponents() const noexcept
How many components there are.
static constexpr uint32_t None
What componentAt() gives for a point outside the box searched.
Definition EBGeometry_ConnectedComponents.hpp:143
uint64_t getNumCells() const noexcept
How many cells the search kept (its cost: one evaluation of every region's function per cell,...
std::vector< uint32_t > componentsOf(uint32_t a_group) const
The components of a group, those reaching the box first, then by decreasing volume.
const ConnectedComponent< T > & component(uint32_t a_component) const
A component.
uint32_t componentAt(const Vec3T< T > &a_point) const noexcept
The component holding a point: that of the search's cell holding it. Within h of a surface,...
T resolution() const noexcept
The resolution searched with (ComponentOptions::m_resolution).
const BoundingVolumes::AABBT< T > & box() const noexcept
The box searched, grown to a whole number of cells.
const std::vector< uint32_t > & neighbors(uint32_t a_component) const
The components that touch a component (they share a face of the search's cells), in increasing order:...
A computational domain over a tape, for a downstream code (a solver EBGeometry does not provide): the...
Definition EBGeometry_Domain.hpp:63
A composed object compiled into a pool: a trivially copyable handle that evaluates the object's signe...
Definition EBGeometry_Tape.hpp:758
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
static constexpr Vec3T< T > zeros() noexcept
Return a vector with x = y = z = 0.
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
ConnectedComponents< T > connectedComponents(const Tape< T, UserPrimitives... > &a_tape, const ComponentOptions< T > &a_options)
The connected components of every region of a tape, the outside (region 0) included: its enclosed cav...
How connectedComponents() resolves the space it searches.
Definition EBGeometry_ConnectedComponents.hpp:57
T m_resolution
The resolution h, the size of the smallest cells (those near a surface), positive.
Definition EBGeometry_ConnectedComponents.hpp:64
BoundingVolumes::AABBT< T > m_box
The box searched: the space a solver computes in, say. Empty (the default): the tape's bounding box g...
Definition EBGeometry_ConnectedComponents.hpp:71
uint64_t m_maxCells
The most cells the search may keep, which bounds the memory it takes. A search that reaches it aborts...
Definition EBGeometry_ConnectedComponents.hpp:90
static constexpr uint64_t DefaultMaxCells
The default of m_maxCells.
Definition EBGeometry_ConnectedComponents.hpp:83
Definition EBGeometry_ConnectedComponents.hpp:34
One connected component: a connected part of space where every point is in one region (or one group o...
Definition EBGeometry_ConnectedComponents.hpp:100
bool m_reachesBox
Whether it reaches the boundary of the box searched. A component that does not is enclosed by others:...
Definition EBGeometry_ConnectedComponents.hpp:125
T m_volume
Its volume within the box searched, approximate: the error is of the order of its surface's area time...
Definition EBGeometry_ConnectedComponents.hpp:109
uint32_t m_group
What it is a component of: the region, or the group of regions (a material, a subdomain).
Definition EBGeometry_ConnectedComponents.hpp:104
Vec3T< T > m_seed
A point in it, as far from its surface as the search found one: what a solver asks for to name it.
Definition EBGeometry_ConnectedComponents.hpp:119
BoundingVolumes::AABBT< T > m_box
A box around it, approximate: within h of the smallest one.
Definition EBGeometry_ConnectedComponents.hpp:114