EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_Subdomains.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_SUBDOMAINS_HPP
12#define EBGEOMETRY_SUBDOMAINS_HPP
13
14// Std includes
15#include <cstdint>
16#include <type_traits>
17#include <vector>
18
19// Our includes
20#include "EBGeometry_GPU.hpp"
21#include "EBGeometry_Macros.hpp"
23#include "EBGeometry_Pool.hpp"
25
26namespace EBGeometry {
27
31enum class SurfaceRole : uint8_t
32{
33 None,
34 Boundary,
35 Interface,
37};
38
50class Subdomains : public PoolHandle
51{
52public:
56 static constexpr uint32_t None = 0xFFFFFFFFU;
57
61 struct Layout
62 {
67
71 uint32_t m_numSubdomains = 0;
72 };
73
77 Subdomains() noexcept = default;
78
87 Subdomains(Pool& a_pool, const std::vector<uint32_t>& a_subdomainOf, const uint32_t a_numSubdomains)
88 {
89 this->attach(a_pool, "Subdomains");
90
91 m_layout.m_table.reserveSizedFrom(a_pool, static_cast<uint32_t>(a_subdomainOf.size()));
92 m_layout.m_numSubdomains = a_numSubdomains;
93
94 for (uint32_t r = 0; r < a_subdomainOf.size(); r++) {
95 EBGEOMETRY_REQUIRE(a_subdomainOf[r] == None || a_subdomainOf[r] < a_numSubdomains,
96 "Subdomains: region %u is in subdomain %u of %u",
97 unsigned(r),
98 unsigned(a_subdomainOf[r]),
99 unsigned(a_numSubdomains));
100
101 m_layout.m_table.at(this->base(), r) = a_subdomainOf[r];
102 }
103 }
104
111 Subdomains(const Layout& a_layout, const PoolLocation& a_location) noexcept
112 : PoolHandle(a_location), m_layout(a_layout)
113 {}
114
119 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
120 inline const Layout&
121 layout() const noexcept
122 {
123 return m_layout;
124 }
125
130 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
131 inline uint32_t
132 getNumSubdomains() const noexcept
133 {
134 return m_layout.m_numSubdomains;
135 }
136
141 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
142 inline uint32_t
143 getNumRegions() const noexcept
144 {
145 return m_layout.m_table.size();
146 }
147
153 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
154 inline uint32_t
155 subdomainOf(const uint32_t a_region) const noexcept
156 {
157 return (a_region < m_layout.m_table.size()) ? m_layout.m_table.at(this->base(), a_region) : None;
158 }
159
167 template <class T>
168 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
169 inline SurfaceRole
170 role(const SurfaceRef<T>& a_surface) const noexcept
171 {
172 const uint32_t minus =
173 (a_surface.m_ownerRegion != SurfaceRef<T>::None) ? this->subdomainOf(a_surface.m_ownerRegion) : None;
174 const uint32_t plus =
175 (a_surface.m_neighborRegion != SurfaceRef<T>::None) ? this->subdomainOf(a_surface.m_neighborRegion) : None;
176
177 if (minus == None && plus == None) {
178 return SurfaceRole::None;
179 }
180 if (minus == None || plus == None) {
182 }
183
184 return (minus == plus) ? SurfaceRole::Internal : SurfaceRole::Interface;
185 }
186
192 [[nodiscard]] EBGEOMETRY_HOST
193 inline Subdomains
194 rebasedView(const Pool& a_pool) const noexcept
195 {
196 Subdomains view = *this;
197
198 view.setLocation(this->rebasedLocation(a_pool, m_layout.m_table.endByte(), "Subdomains"));
199
200 return view;
201 }
202
203private:
207 Layout m_layout;
208};
209
210static_assert(std::is_trivially_copyable_v<Subdomains>,
211 "Subdomains must be trivially copyable, for a kernel to take it");
212
213} // namespace EBGeometry
214
215#endif
GPU portability layer: host/device decoration macros and backend detection.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#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.
#define EBGEOMETRY_REQUIRE(cond,...)
Always-on check of user input and one-time host setup.
Definition EBGeometry_Macros.hpp:200
Placement-independent POD array views for the GPU memory foundation.
Growable bump arena for the GPU memory foundation.
SurfaceRef: which surface of a shape decides its value at a point, and the container protocol that na...
Base of every pool-resident handle: the one PoolLocation its arrays resolve against.
Definition EBGeometry_Pool.hpp:563
PoolLocation rebasedLocation(const Pool &a_pool, uint64_t a_endByte, const char *a_who) const noexcept
The location of this handle's arrays in another pool of its mirror chain; see PoolLocation::rebasedOn...
Definition EBGeometry_Pool.hpp:680
PoolHandle() noexcept=default
An unset location; the first reservation attaches it.
void attach(const Pool &a_pool, const char *a_who, const bool a_deviceWritten=false) noexcept
Follow a_pool, as the first reservation does; see PoolLocation::attach().
Definition EBGeometry_Pool.hpp:665
void * base() noexcept
The base address this handle's offsets resolve against; see PoolLocation::base().
Definition EBGeometry_Pool.hpp:639
Growable bump arena over a MemoryResource.
Definition EBGeometry_Pool.hpp:205
The subdomains of a domain (see Domain), read on the host or a device: the subdomain of each region o...
Definition EBGeometry_Subdomains.hpp:51
static constexpr uint32_t None
No subdomain, or a region in no subdomain.
Definition EBGeometry_Subdomains.hpp:56
Subdomains(const Layout &a_layout, const PoolLocation &a_location) noexcept
Rebuild a view from a stored layout and the location of the pool that holds it (as a Domain does).
Definition EBGeometry_Subdomains.hpp:111
const Layout & layout() const noexcept
The arrays, as offsets.
Definition EBGeometry_Subdomains.hpp:121
uint32_t subdomainOf(const uint32_t a_region) const noexcept
The subdomain a region is in.
Definition EBGeometry_Subdomains.hpp:155
uint32_t getNumRegions() const noexcept
How many regions the table has a row for: the tape's.
Definition EBGeometry_Subdomains.hpp:143
Subdomains rebasedView(const Pool &a_pool) const noexcept
A view resolving against another pool of the table's mirror chain (see PoolHandle).
Definition EBGeometry_Subdomains.hpp:194
Subdomains() noexcept=default
No subdomains: every region is in none.
uint32_t getNumSubdomains() const noexcept
How many subdomains there are.
Definition EBGeometry_Subdomains.hpp:132
SurfaceRole role(const SurfaceRef< T > &a_surface) const noexcept
What a surface is to the subdomains at a point: from the regions on its two sides there,...
Definition EBGeometry_Subdomains.hpp:170
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
@ Interface
The pair of regions on its two sides there (see RegionSettings::interfaceKey()).
SurfaceRole
What a surface is to a domain, at a point, from the regions on its two sides (see Subdomains::role())...
Definition EBGeometry_Subdomains.hpp:32
@ Interface
The two sides are in two different subdomains: one surface the solver couples across.
@ None
Neither side is in a subdomain: the solver does not cut it.
@ Internal
Both sides are in the same subdomain (two of its regions touching): the solver decides; usually not c...
@ Boundary
One side is in a subdomain: cut once, from that side; its surface group gives its meaning (a boundary...
@ None
As written: the tape evaluates every operand, however many there are.
Placement-independent descriptor of a POD array inside a Pool.
Definition EBGeometry_PODVector.hpp:131
void reserveSizedFrom(Pool &a_pool, uint32_t a_count)
Reserve a_count slots from a_pool and count them all as elements.
Definition EBGeometry_PODVector.hpp:181
uint64_t endByte() const noexcept
One past the last byte this array occupies, measured from the pool base.
Definition EBGeometry_PODVector.hpp:264
T & at(void *a_base, uint32_t a_i) const noexcept
Mutable element access against a_base.
Definition EBGeometry_PODVector.hpp:220
uint32_t size() const noexcept
Number of constructed elements.
Definition EBGeometry_PODVector.hpp:248
Where a pool-resident descriptor resolves its offsets, and the rules for moving it.
Definition EBGeometry_Pool.hpp:99
The arrays, as offsets: what a Domain stores.
Definition EBGeometry_Subdomains.hpp:62
PODVector< uint32_t > m_table
The subdomain of each region, or None.
Definition EBGeometry_Subdomains.hpp:66
uint32_t m_numSubdomains
How many subdomains there are.
Definition EBGeometry_Subdomains.hpp:71
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39