11#ifndef EBGEOMETRY_DOMAINSETUP_HPP
12#define EBGEOMETRY_DOMAINSETUP_HPP
54 EBGEOMETRY_REQUIRE(!a_regions.empty(),
"DomainSetup: a subdomain needs at least one region");
56 std::sort(a_regions.begin(), a_regions.end());
58 a_regions.erase(std::unique(a_regions.begin(), a_regions.end()), a_regions.end());
60 for (
const uint32_t r : a_regions) {
63 "DomainSetup: region %u is already in subdomain %u",
68 const uint32_t subdomain = m_numSubdomains++;
70 for (
const uint32_t r : a_regions) {
71 if (r >= m_subdomainOf.size()) {
75 m_subdomainOf[r] = subdomain;
89 return m_numSubdomains;
101 return (a_region < m_subdomainOf.size()) ? m_subdomainOf[a_region] :
Subdomains::None;
125 touches(
const uint32_t a_first,
const uint32_t a_second)
const noexcept
136 std::vector<uint32_t>
139 std::vector<uint32_t> regions;
141 for (uint32_t r = 0; r < m_subdomainOf.size(); r++) {
142 if (m_subdomainOf[r] == a_subdomain) {
143 regions.push_back(r);
158 return static_cast<uint32_t
>(m_subdomainOf.size());
172 const uint32_t minus =
196 return m_numSurfaceGroups++;
210 "DomainSetup: surface group %u of %u",
212 unsigned(m_numSurfaceGroups));
214 m_selectors.push_back(a_selector);
215 m_surfaceGroups.push_back(a_group);
228 "DomainSetup: surface group %u of %u",
230 unsigned(m_numSurfaceGroups));
232 std::size_t kept = 0;
234 for (std::size_t i = 0; i < m_selectors.size(); i++) {
235 if (m_surfaceGroups[i] != a_group) {
236 m_selectors[kept] = m_selectors[i];
237 m_surfaceGroups[kept] = (m_surfaceGroups[i] > a_group) ? m_surfaceGroups[i] - 1U : m_surfaceGroups[i];
243 m_selectors.resize(kept);
244 m_surfaceGroups.resize(kept);
246 m_numSurfaceGroups--;
258 std::size_t kept = 0;
260 for (std::size_t i = 0; i < m_selectors.size(); i++) {
261 if (m_surfaceGroups[i] != a_group || !same(m_selectors[i], a_selector)) {
262 m_selectors[kept] = m_selectors[i];
263 m_surfaceGroups[kept] = m_surfaceGroups[i];
269 m_selectors.resize(kept);
270 m_surfaceGroups.resize(kept);
281 return m_numSurfaceGroups;
292 return static_cast<uint32_t
>(m_selectors.size());
304 return m_selectors.at(a_selector);
316 return m_surfaceGroups.at(a_selector);
330 for (
int pass = 0; pass < 2; pass++) {
331 for (std::size_t i = 0; i < m_selectors.size(); i++) {
332 if (m_selectors[i].m_rest == (pass == 1) && m_selectors[i].matches(a_surface)) {
333 return m_surfaceGroups[i];
353 "DomainSetup: a subdomain holds region %u, the tape has %u regions",
355 unsigned(a_numRegions));
359 std::copy(m_subdomainOf.begin(), m_subdomainOf.end(), table.begin());
361 return Subdomains(a_pool, table, m_numSubdomains);
373 return SurfaceGroups(a_pool, m_selectors, m_surfaceGroups, m_numSurfaceGroups);
386 if (m_numSubdomains != a_other.m_numSubdomains || m_numSurfaceGroups != a_other.m_numSurfaceGroups ||
387 m_selectors.size() != a_other.m_selectors.size() || m_surfaceGroups != a_other.m_surfaceGroups) {
391 const std::size_t regions =
Math::max(m_subdomainOf.size(), a_other.m_subdomainOf.size());
393 for (std::size_t r = 0; r < regions; r++) {
394 if (this->
subdomainOf(
static_cast<uint32_t
>(r)) != a_other.subdomainOf(
static_cast<uint32_t
>(r))) {
399 for (std::size_t i = 0; i < m_selectors.size(); i++) {
400 if (!same(m_selectors[i], a_other.m_selectors[i])) {
417 return !(*
this == a_other);
431 return a_first.m_surface == a_second.m_surface && a_first.m_part == a_second.m_part &&
432 a_first.m_regionA == a_second.m_regionA && a_first.m_regionB == a_second.m_regionB &&
433 a_first.m_label == a_second.m_label && a_first.m_materialA == a_second.m_materialA &&
434 a_first.m_materialB == a_second.m_materialB && a_first.m_rest == a_second.m_rest &&
441 std::vector<uint32_t> m_subdomainOf;
446 uint32_t m_numSubdomains = 0;
451 std::vector<SurfaceSelector> m_selectors;
456 std::vector<uint32_t> m_surfaceGroups;
461 uint32_t m_numSurfaceGroups = 0;
#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
Scalar helpers and numeric limits that compile for both host and device.
Growable bump arena for the GPU memory foundation.
Subdomains: the subdomain of each region of a tape, read on the host or a device.
SurfaceSelector and SurfaceGroups: which surfaces a downstream code groups under one meaning.
SurfaceRef: which surface of a shape decides its value at a point, and the container protocol that na...
How a domain is made: its subdomains (the regions each computes in) and its surface groups (the selec...
Definition EBGeometry_DomainSetup.hpp:39
uint32_t getNumSelectors() const noexcept
How many selectors there are, over all surface groups.
Definition EBGeometry_DomainSetup.hpp:290
std::vector< uint32_t > getRegions(const uint32_t a_subdomain) const
The regions of a subdomain.
Definition EBGeometry_DomainSetup.hpp:137
void remove(const uint32_t a_group, const SurfaceSelector &a_selector)
Remove the selectors of a surface group that equal one (to undo a click).
Definition EBGeometry_DomainSetup.hpp:256
uint32_t getRegionsNeeded() const noexcept
One past the largest region in a subdomain: the fewest regions a tape must have for the setup.
Definition EBGeometry_DomainSetup.hpp:156
const SurfaceSelector & getSelector(const uint32_t a_selector) const
A selector.
Definition EBGeometry_DomainSetup.hpp:302
uint32_t getNumSubdomains() const noexcept
How many subdomains there are.
Definition EBGeometry_DomainSetup.hpp:87
bool touches(const uint32_t a_first, const uint32_t a_second) const noexcept
Whether a surface between two regions is one the domain must give a condition: one side or both in it...
Definition EBGeometry_DomainSetup.hpp:125
SurfaceGroups buildSurfaceGroups(Pool &a_pool) const
Build the surface groups.
Definition EBGeometry_DomainSetup.hpp:371
SurfaceRole role(const SurfaceRef< T > &a_surface) const noexcept
What a surface is to the subdomains (as Subdomains::role()).
Definition EBGeometry_DomainSetup.hpp:170
void removeSurfaceGroup(const uint32_t a_group)
Remove a surface group and its selectors; the surface groups after it move down by one.
Definition EBGeometry_DomainSetup.hpp:225
void add(const uint32_t a_group, const SurfaceSelector &a_selector)
Add a selector to a surface group.
Definition EBGeometry_DomainSetup.hpp:207
uint32_t surfaceGroupOf(const SurfaceRef< T > &a_surface) const noexcept
The surface group a surface point is in (as SurfaceGroups::surfaceGroupOf()).
Definition EBGeometry_DomainSetup.hpp:328
uint32_t getSurfaceGroupOfSelector(const uint32_t a_selector) const
The surface group of a selector.
Definition EBGeometry_DomainSetup.hpp:314
uint32_t getNumSurfaceGroups() const noexcept
How many surface groups there are.
Definition EBGeometry_DomainSetup.hpp:279
bool operator!=(const DomainSetup &a_other) const noexcept
Whether two setups make different domains.
Definition EBGeometry_DomainSetup.hpp:415
uint32_t addSurfaceGroup() noexcept
Add a surface group.
Definition EBGeometry_DomainSetup.hpp:194
Subdomains buildSubdomains(Pool &a_pool, const uint32_t a_numRegions) const
Build the subdomains for a tape of a number of regions.
Definition EBGeometry_DomainSetup.hpp:350
bool computesIn(const uint32_t a_region) const noexcept
Whether the domain computes in a region.
Definition EBGeometry_DomainSetup.hpp:111
uint32_t addSubdomain(std::vector< uint32_t > a_regions)
Add a subdomain.
Definition EBGeometry_DomainSetup.hpp:52
uint32_t subdomainOf(const uint32_t a_region) const noexcept
The subdomain a region is in.
Definition EBGeometry_DomainSetup.hpp:99
bool operator==(const DomainSetup &a_other) const noexcept
Whether two setups make the same domain: the same subdomains, and the same selectors in the same grou...
Definition EBGeometry_DomainSetup.hpp:384
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
A domain's surface groups, read on the host or a device: each group a set of surfaces,...
Definition EBGeometry_SurfaceGroups.hpp:296
static constexpr uint32_t None
No surface group: a surface no selector matches.
Definition EBGeometry_SurfaceGroups.hpp:301
constexpr T max(const T &a_a, const T &a_b) noexcept
The larger of two values.
Definition EBGeometry_Math.hpp:61
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
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...
The surface that decides a shape's value at a point, as closestSurface() reports it.
Definition EBGeometry_SurfaceRef.hpp:39
Conditions on a point of a surface, all of which must hold; an unset one (Any) matches anything.
Definition EBGeometry_SurfaceGroups.hpp:40
static constexpr uint32_t Any
An unset condition: matches anything.
Definition EBGeometry_SurfaceGroups.hpp:44