EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_RegionNames.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_REGIONNAMES_HPP
12#define EBGEOMETRY_REGIONNAMES_HPP
13
14// Std includes
15#include <cstddef>
16#include <cstdint>
17#include <map>
18#include <string>
19#include <utility>
20#include <vector>
21
22// Our includes
24#include "EBGeometry_Expr.hpp"
25#include "EBGeometry_Macros.hpp"
28#include "EBGeometry_Vec.hpp"
29
30namespace EBGeometry {
31
39{
40public:
44 RegionNames() = default;
45
52 template <class T>
54 explicit RegionNames(const ExprIndex<T>& a_index) : m_inventory(a_index)
55 {
56 for (uint32_t k = 0; k < a_index.getNumMaterialLabels(); k++) {
58 }
59
60 for (uint32_t k = 0; k < a_index.getNumSurfaceLabels(); k++) {
62 }
63
64 for (uint32_t k = 0; k < a_index.getNumRegions(); k++) {
65 const MaterialLabelId material = a_index.getMaterialOf(k);
66
67 m_regionNames.push_back(a_index.getRegion(k).m_name);
68 m_regionMaterials.push_back(material.isNone() ? None : material.value());
69 }
70
71 for (uint32_t s = 0; s < a_index.getNumSurfaces(); s++) {
72 const SurfaceLabelId label = a_index.getSurfaceLabel(a_index.getLeafOfSurface(s));
73
74 m_surfaces.push_back(!label.isNone() ? m_surfaceLabels[label.value()] : std::string());
75 }
76 }
77
81 static constexpr uint32_t None = 0xFFFFFFFFU;
82
91 uint32_t
92 addDomain(std::string a_name, const DomainSetup& a_domain)
93 {
94 m_domainNames.push_back(std::move(a_name));
95 m_domains.push_back(a_domain);
96 m_domainGroups.emplace_back();
97 m_domainSubdomains.emplace_back();
98
99 if (m_activeDomain == None) {
100 m_activeDomain = 0;
101 }
102
103 return static_cast<uint32_t>(m_domains.size() - 1U);
104 }
105
110 [[nodiscard]] EBGEOMETRY_HOST
111 uint32_t
112 getNumDomains() const noexcept
113 {
114 return static_cast<uint32_t>(m_domains.size());
115 }
116
122 [[nodiscard]] EBGEOMETRY_HOST
124 getDomain(const uint32_t a_domain)
125 {
127 a_domain < m_domains.size(), "RegionNames: domain %u of %zu", unsigned(a_domain), m_domains.size());
128
129 return m_domains[a_domain];
130 }
131
137 [[nodiscard]] EBGEOMETRY_HOST
138 const DomainSetup&
139 getDomain(const uint32_t a_domain) const
140 {
142 a_domain < m_domains.size(), "RegionNames: domain %u of %zu", unsigned(a_domain), m_domains.size());
143
144 return m_domains[a_domain];
145 }
146
152 [[nodiscard]] EBGEOMETRY_HOST
153 const std::string&
154 domainName(const uint32_t a_domain) const
155 {
157 a_domain < m_domains.size(), "RegionNames: domain %u of %zu", unsigned(a_domain), m_domains.size());
158
159 return m_domainNames[a_domain];
160 }
161
167 void
168 setActiveDomain(const uint32_t a_domain)
169 {
171 a_domain < m_domains.size(), "RegionNames: domain %u of %zu", unsigned(a_domain), m_domains.size());
172
173 m_activeDomain = a_domain;
174 }
175
180 [[nodiscard]] EBGEOMETRY_HOST
181 uint32_t
182 getActiveDomain() const noexcept
183 {
184 return m_activeDomain;
185 }
186
194 void
195 setSurfaceGroup(const uint32_t a_domain, const uint32_t a_group, std::string a_name)
196 {
197 const uint32_t active = m_activeDomain;
198
199 this->setActiveDomain(a_domain);
200 this->setSurfaceGroup(a_group, std::move(a_name));
201
202 m_activeDomain = active;
203 }
204
212 void
213 setSubdomain(const uint32_t a_domain, const uint32_t a_subdomain, std::string a_name)
214 {
216 a_domain < m_domains.size(), "RegionNames: domain %u of %zu", unsigned(a_domain), m_domains.size());
217
218 std::vector<std::string>& subdomains = m_domainSubdomains[a_domain];
219
220 if (subdomains.size() <= a_subdomain) {
221 subdomains.resize(a_subdomain + 1U);
222 }
223
224 subdomains[a_subdomain] = std::move(a_name);
225 }
226
233 [[nodiscard]] EBGEOMETRY_HOST
234 std::string
235 subdomain(const uint32_t a_subdomain, const bool a_number = true) const
236 {
237 static const std::vector<std::string> none;
238
240 a_subdomain,
241 "subdomain",
242 a_number);
243 }
244
252 void
253 setColor(std::string a_name, const Vec3T<double>& a_color)
254 {
255 m_colors[std::move(a_name)] = a_color;
256 }
257
267 [[nodiscard]] EBGEOMETRY_HOST
268 bool
269 colorOf(const RegionColoring a_coloring, const uint32_t a_key, Vec3T<double>& a_color) const
270 {
271 const std::string* name = nullptr;
272
273 const auto from = [&name, a_key](const std::vector<std::string>& a_names) {
274 name = (a_key < a_names.size()) ? &a_names[a_key] : nullptr;
275 };
276
277 switch (a_coloring) {
279 from(m_regionNames);
280
281 break;
282 }
284 from(m_materials);
285
286 break;
287 }
289 from(m_surfaceLabels);
290
291 break;
292 }
294 from(m_surfaces);
295
296 break;
297 }
299 from(this->groupNames());
300
301 break;
302 }
303 default: {
304 break;
305 }
306 }
307
308 const auto color = (name == nullptr || name->empty()) ? m_colors.end() : m_colors.find(*name);
309
310 if (color != m_colors.end()) {
311 a_color = color->second;
312
313 return true;
314 }
315
316 // A region without a color of its own: its material's.
317 if (a_coloring == RegionColoring::Region && this->materialOf(a_key) != None) {
318 return this->colorOf(RegionColoring::Material, this->materialOf(a_key), a_color);
319 }
320
321 return false;
322 }
323
329 [[nodiscard]] EBGEOMETRY_HOST
330 const SurfaceInventory&
331 getInventory() const noexcept
332 {
333 return m_inventory;
334 }
335
341 [[nodiscard]] EBGEOMETRY_HOST
342 uint32_t
343 materialOf(const uint32_t a_region) const noexcept
344 {
345 return (a_region < m_regionMaterials.size()) ? m_regionMaterials[a_region] : None;
346 }
347
354 void
355 setSurface(const uint32_t a_surface, std::string a_name)
356 {
357 if (a_surface >= m_surfaces.size()) {
358 m_surfaces.resize(a_surface + 1U);
359 }
360
361 m_surfaces[a_surface] = std::move(a_name);
362 }
363
372 void
373 setPickedByLabel(const uint32_t a_surface, const bool a_byLabel = true)
374 {
375 if (a_surface >= m_pickedByLabel.size()) {
376 m_pickedByLabel.resize(a_surface + 1U, false);
377 }
378
379 m_pickedByLabel[a_surface] = a_byLabel;
380 }
381
387 [[nodiscard]] EBGEOMETRY_HOST
388 bool
389 pickedByLabel(const uint32_t a_surface) const noexcept
390 {
391 return a_surface < m_pickedByLabel.size() && m_pickedByLabel[a_surface];
392 }
393
400 void
401 setSurfaceGroup(const uint32_t a_group, std::string a_name)
402 {
403 std::vector<std::string>& groups = this->groupNames();
404
405 if (groups.size() <= a_group) {
406 groups.resize(a_group + 1U);
407 }
408
409 groups[a_group] = std::move(a_name);
410 }
411
418 void
419 removeSurfaceGroup(const uint32_t a_group)
420 {
421 std::vector<std::string>& groups = this->groupNames();
422
423 if (a_group < groups.size()) {
424 groups.erase(groups.begin() + static_cast<std::ptrdiff_t>(a_group));
425 }
426 }
427
435 [[nodiscard]] EBGEOMETRY_HOST
436 std::string
437 region(const uint32_t a_region, const bool a_number = true) const
438 {
439 const std::string number = std::to_string(a_region);
440 const bool named = a_region < m_regionNames.size() && !m_regionNames[a_region].empty();
441
442 std::string shown = named ? (a_number ? number + " " : "") + m_regionNames[a_region]
443 : (a_region == 0U) ? (a_number ? number + " " : "") + "background"
444 : "region " + number;
445
446 const uint32_t material = this->materialOf(a_region);
447
448 if (material < m_materials.size()) {
449 shown += " (" + m_materials[material] + ")";
450 }
451
452 return shown;
453 }
454
461 [[nodiscard]] EBGEOMETRY_HOST
462 std::string
463 material(const uint32_t a_material, const bool a_number = true) const
464 {
465 return named(m_materials, a_material, "material", a_number);
466 }
467
474 [[nodiscard]] EBGEOMETRY_HOST
475 std::string
476 surface(const uint32_t a_surface, const bool a_number = true) const
477 {
478 return named(m_surfaces, a_surface, "surface", a_number);
479 }
480
487 [[nodiscard]] EBGEOMETRY_HOST
488 std::string
489 surfaceLabel(const uint32_t a_label, const bool a_number = true) const
490 {
491 return named(m_surfaceLabels, a_label, "label", a_number);
492 }
493
500 [[nodiscard]] EBGEOMETRY_HOST
501 std::string
502 surfaceGroup(const uint32_t a_group, const bool a_number = true) const
503 {
504 return named(this->groupNames(), a_group, "surface group", a_number);
505 }
506
507protected:
512
516 std::vector<DomainSetup> m_domains;
517
521 std::vector<std::string> m_domainNames;
522
526 std::vector<std::vector<std::string>> m_domainSubdomains;
527
531 std::vector<std::vector<std::string>> m_domainGroups;
532
537
542 [[nodiscard]] std::vector<std::string>&
543 groupNames() noexcept
544 {
546 }
547
552 [[nodiscard]] const std::vector<std::string>&
553 groupNames() const noexcept
554 {
556 }
557
561 std::vector<std::string> m_regionNames;
562
566 std::vector<uint32_t> m_regionMaterials;
567
571 std::map<std::string, Vec3T<double>> m_colors;
572
576 std::vector<std::string> m_materials;
577
581 std::vector<std::string> m_surfaces;
582
586 std::vector<bool> m_pickedByLabel;
587
591 std::vector<std::string> m_surfaceLabels;
592
596 std::vector<std::string> m_surfaceGroups;
597
606 [[nodiscard]] static std::string
607 named(const std::vector<std::string>& a_names, const uint32_t a_index, const char* a_kind, const bool a_number)
608 {
609 const std::string number = std::to_string(a_index);
610
611 return (a_index < a_names.size() && !a_names[a_index].empty()) ? (a_number ? number + " " : "") + a_names[a_index]
612 : std::string(a_kind) + " " + number;
613 }
614};
615
616} // namespace EBGeometry
617
618#endif
DomainSetup: how a domain is made, as an editable value on the host (see Domain).
The tape's front end: Expr, a host-side value that describes a composed object, and the free function...
#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
RegionSettings: how the regions of an object are shown (visibility, coloring, a domain's surface grou...
The pieces of surface an object with regions has, and how a domain's surface groups cover them.
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
How a domain is made: its subdomains (the regions each computes in) and its surface groups (the selec...
Definition EBGeometry_DomainSetup.hpp:39
The nodes of an expression, numbered, with the leaves below each and their labels: on the host,...
Definition EBGeometry_Expr.hpp:1058
const Region & getRegion(uint32_t a_region) const
A region.
MaterialLabelId getMaterialOf(uint32_t a_region) const
A region's material (see Region::m_material).
uint32_t getNumSurfaces() const noexcept
The number of surfaces: Tape::getNumSurfaces() of a tape compiled from the expression.
const std::string & getMaterialLabelName(MaterialLabelId a_label) const
A material label's name.
SurfaceLabelId getSurfaceLabel(uint32_t a_leaf) const
A leaf's label: that of the nearest labeled node on its path, the leaf's own included,...
uint32_t getNumSurfaceLabels() const noexcept
The number of distinct labels.
uint32_t getLeafOfSurface(uint32_t a_surface) const
The leaf a surface belongs to: SurfaceRef::m_leaf of a tape's closestSurface() that reported it.
uint32_t getNumRegions() const noexcept
The number of regions: the background (region 0), and one per operand of the Overlays,...
const std::string & getSurfaceLabelName(SurfaceLabelId a_label) const
A label's name.
uint32_t getNumMaterialLabels() const noexcept
The number of distinct material labels.
The names of an object's regions, materials, surfaces and surface labels, from its expression's index...
Definition EBGeometry_RegionNames.hpp:39
static std::string named(const std::vector< std::string > &a_names, const uint32_t a_index, const char *a_kind, const bool a_number)
A name from a list, after its number, or the kind and the number.
Definition EBGeometry_RegionNames.hpp:607
const std::string & domainName(const uint32_t a_domain) const
A domain's name.
Definition EBGeometry_RegionNames.hpp:154
void setColor(std::string a_name, const Vec3T< double > &a_color)
Give a name a color: a region's, a material's, a surface label's or a surface group's....
Definition EBGeometry_RegionNames.hpp:253
RegionNames()=default
No names: everything is named by its number.
std::map< std::string, Vec3T< double > > m_colors
The colors given to names.
Definition EBGeometry_RegionNames.hpp:571
std::vector< std::vector< std::string > > m_domainSubdomains
Each domain's subdomains' names.
Definition EBGeometry_RegionNames.hpp:526
uint32_t getActiveDomain() const noexcept
The active domain.
Definition EBGeometry_RegionNames.hpp:182
void setActiveDomain(const uint32_t a_domain)
Make a domain the active one: the one whose surface groups setSurfaceGroup() and surfaceGroup() name.
Definition EBGeometry_RegionNames.hpp:168
std::vector< DomainSetup > m_domains
The domains, their names and their surface groups' names; and the active one, or None.
Definition EBGeometry_RegionNames.hpp:516
uint32_t materialOf(const uint32_t a_region) const noexcept
A region's material.
Definition EBGeometry_RegionNames.hpp:343
void setSurfaceGroup(const uint32_t a_group, std::string a_name)
Name a surface group of the active domain (with no domain registered, of those a viewer shows).
Definition EBGeometry_RegionNames.hpp:401
std::vector< std::vector< std::string > > m_domainGroups
Each domain's surface groups' names.
Definition EBGeometry_RegionNames.hpp:531
std::string surfaceGroup(const uint32_t a_group, const bool a_number=true) const
A surface group's name, with its number or not: "0 inlet" or "inlet"; "surface group 0".
Definition EBGeometry_RegionNames.hpp:502
const std::vector< std::string > & groupNames() const noexcept
The surface groups' names in use.
Definition EBGeometry_RegionNames.hpp:553
std::vector< std::string > m_surfaces
The surfaces' names.
Definition EBGeometry_RegionNames.hpp:581
DomainSetup & getDomain(const uint32_t a_domain)
How a domain is made, to edit.
Definition EBGeometry_RegionNames.hpp:124
bool colorOf(const RegionColoring a_coloring, const uint32_t a_key, Vec3T< double > &a_color) const
The color a key has, colored by a kind of key: by the name of the region, material,...
Definition EBGeometry_RegionNames.hpp:269
std::string surfaceLabel(const uint32_t a_label, const bool a_number=true) const
A surface label's name, with its number or not.
Definition EBGeometry_RegionNames.hpp:489
void setPickedByLabel(const uint32_t a_surface, const bool a_byLabel=true)
Pick a surface by its labels rather than its parts: a click on it picks the faces labeled as the one ...
Definition EBGeometry_RegionNames.hpp:373
std::vector< std::string > m_surfaceLabels
The surface labels' names.
Definition EBGeometry_RegionNames.hpp:591
std::vector< std::string > m_regionNames
The regions' own names (RegionName()), empty for none; the lists below too leave the unnamed empty.
Definition EBGeometry_RegionNames.hpp:561
std::string subdomain(const uint32_t a_subdomain, const bool a_number=true) const
A subdomain's name in the active domain, with its number or not: "1 solid" or "solid"; "subdomain 1".
Definition EBGeometry_RegionNames.hpp:235
std::vector< bool > m_pickedByLabel
Which surfaces are picked by their labels (see setPickedByLabel()).
Definition EBGeometry_RegionNames.hpp:586
uint32_t m_activeDomain
The active domain, or None.
Definition EBGeometry_RegionNames.hpp:536
std::vector< std::string > m_surfaceGroups
The groups' names.
Definition EBGeometry_RegionNames.hpp:596
bool pickedByLabel(const uint32_t a_surface) const noexcept
Whether a surface is picked by its labels (see setPickedByLabel()).
Definition EBGeometry_RegionNames.hpp:389
std::vector< std::string > m_domainNames
The domains' names.
Definition EBGeometry_RegionNames.hpp:521
void removeSurfaceGroup(const uint32_t a_group)
Forget a group's name; the names of the groups after it move down by one (as SurfaceGroups::removeSur...
Definition EBGeometry_RegionNames.hpp:419
std::string surface(const uint32_t a_surface, const bool a_number=true) const
A surface's name, with its number or not: its label's, or "surface 3".
Definition EBGeometry_RegionNames.hpp:476
std::vector< uint32_t > m_regionMaterials
Each region's material label number, or None.
Definition EBGeometry_RegionNames.hpp:566
uint32_t addDomain(std::string a_name, const DomainSetup &a_domain)
Register a domain: its name, and how it is made (its subdomains and surface groups,...
Definition EBGeometry_RegionNames.hpp:92
std::string region(const uint32_t a_region, const bool a_number=true) const
A region's name and material, with its number or not: "2 wall (steel)" or "wall (steel)"; the backgro...
Definition EBGeometry_RegionNames.hpp:437
const DomainSetup & getDomain(const uint32_t a_domain) const
How a domain is made.
Definition EBGeometry_RegionNames.hpp:139
void setSurface(const uint32_t a_surface, std::string a_name)
Name a surface (by default it is named by its label): where it comes from, say ("cylinder,...
Definition EBGeometry_RegionNames.hpp:355
SurfaceInventory m_inventory
The surfaces, from the index.
Definition EBGeometry_RegionNames.hpp:511
const SurfaceInventory & getInventory() const noexcept
What the index says about the surfaces: every surface, its parts, the pairs of regions it may separat...
Definition EBGeometry_RegionNames.hpp:331
void setSubdomain(const uint32_t a_domain, const uint32_t a_subdomain, std::string a_name)
Name a subdomain of a domain ("fluid", "solid").
Definition EBGeometry_RegionNames.hpp:213
RegionNames(const ExprIndex< T > &a_index)
The names an expression's index gives: a region by its name and its material ("2 wall (steel)"),...
Definition EBGeometry_RegionNames.hpp:54
std::vector< std::string > & groupNames() noexcept
The surface groups' names in use: the active domain's, or, with no domain, the names' own.
Definition EBGeometry_RegionNames.hpp:543
void setSurfaceGroup(const uint32_t a_domain, const uint32_t a_group, std::string a_name)
Name a surface group of a domain.
Definition EBGeometry_RegionNames.hpp:195
static constexpr uint32_t None
No material, no label.
Definition EBGeometry_RegionNames.hpp:81
std::vector< std::string > m_materials
The materials' names.
Definition EBGeometry_RegionNames.hpp:576
std::string material(const uint32_t a_material, const bool a_number=true) const
A material's name, with its number or not.
Definition EBGeometry_RegionNames.hpp:463
uint32_t getNumDomains() const noexcept
How many domains are registered.
Definition EBGeometry_RegionNames.hpp:112
What an expression's index says about its surfaces, kept for checking surface groups against them wit...
Definition EBGeometry_SurfacePieces.hpp:234
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
RegionColoring
What a view of regions names a surface by, the key a renderer colors by (Render::ColorBy::Primitive).
Definition EBGeometry_RegionSettings.hpp:28
@ SurfaceGroup
The surface group the surface is in (RegionSettings::m_surfaceGroups), or none.
@ Surface
The surface itself (SurfaceRef::m_surface): each shape, each member of a collection.
@ SurfaceLabel
The surface's label (SurfaceLabel()).
@ Material
That region's material.
@ Region
The region the surface belongs to, as seen.
std::string m_name
Its name (RegionName() on its operand, or on a map above it); empty for none and the background.
Definition EBGeometry_Expr.hpp:1137