https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
CSG::CSGRegion Class Reference

CSGRegions creates an internal representation of a CSG region, which can refer to an intersection, union, complement, or half-space. More...

#include <CSGRegion.h>

Public Types

enum class  RegionType {
  EMPTY , HALFSPACE , COMPLEMENT , INTERSECTION ,
  UNION
}
 Enum for representing region types, defined to match _region_type MooseEnum. More...
 
typedef std::variant< std::reference_wrapper< const CSGSurface >, RegionType, CSGSurface::HalfspacePostfixTokenVariant
 Type definition for a variant that represents the datatypes for entries within the list that represents the region in postfix notation.
 

Public Member Functions

 CSGRegion ()
 Default Constructor.
 
 CSGRegion (const CSGSurface &surf, const CSGSurface::Halfspace halfspace)
 Constructor for half-space of a surface.
 
 CSGRegion (const CSGRegion &region_a, const CSGRegion &region_b, const std::string &region_type)
 Constructor for union and intersection.
 
 CSGRegion (const CSGRegion &region, const std::string &region_type)
 Constructor for complement or empty region (clear the region)
 
virtual ~CSGRegion ()=default
 Destructor.
 
nlohmann::json toInfixJSON () const
 gets the infix JSON representation of the region, which involves converting region representation from postfix to infix notation
 
std::vector< std::string > toPostfixStringList () const
 gets the list of postfix tokens of the region in string representation
 
std::string postfixTokenToString (const PostfixTokenVariant &token) const
 converts postfix token from PostfixTokenVariant to string representation
 
RegionType getRegionType () const
 Get the region type.
 
const std::string getRegionTypeString () const
 Get the region type as a string.
 
std::vector< std::reference_wrapper< const CSGSurface > > getSurfaces () const
 Get the list of surfaces associated with the region.
 
void updateSurfaceReferences (std::map< std::string, std::reference_wrapper< const CSGSurface > > &identical_surface_refs)
 Update surface references of region based on map of input surface references.
 
CSGRegionoperator&= (const CSGRegion &other_region)
 Operator overload for &= which creates an intersection between the current region and the other_region.
 
CSGRegionoperator|= (const CSGRegion &other_region)
 Operator overload for |= which creates a union of the current region with the other_region.
 
bool operator== (const CSGRegion &other) const
 Operator overload for checking if two CSGRegion objects are equal.
 
bool operator!= (const CSGRegion &other) const
 Operator overload for checking if two CSGRegion objects are not equal.
 

Static Public Member Functions

static char regionSymbol (const RegionType region_type)
 
static char halfspaceSymbol (const CSGSurface::Halfspace halfspace)
 
static std::string regionTypeName (const RegionType region_type)
 

Protected Member Functions

const std::vector< PostfixTokenVariant > & getPostfixTokens () const
 Get the list of postfix tokens associated with the region.
 
void replaceWithSubRegion (const CSGSurface &old_surf, const CSGRegion &sub_region)
 Replace all occurrences of old_surf in this region's postfix token stream with the tokens of sub_region.
 
bool nextRegionOpIsIdentical (const RegionType region, const std::size_t postfix_token_index) const
 Iterate through postfix tokens and check if next region operator matches the given operator.
 
bool checkRegionEquality (const std::vector< PostfixTokenVariant > &other_tokens) const
 Loop through postfix tokens and check equality with another list of postfix tokens.
 

Protected Attributes

MooseEnum _region_type {"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"}
 An enum for type of type of operation that defines region.
 
std::vector< PostfixTokenVariant_postfix_tokens
 List of tokens representing the region in postfix notation.
 

Friends

class CSGBase
 

Detailed Description

CSGRegions creates an internal representation of a CSG region, which can refer to an intersection, union, complement, or half-space.

Definition at line 22 of file CSGRegion.h.

Member Typedef Documentation

◆ PostfixTokenVariant

typedef std::variant<std::reference_wrapper<const CSGSurface>, RegionType, CSGSurface::Halfspace> CSG::CSGRegion::PostfixTokenVariant

Type definition for a variant that represents the datatypes for entries within the list that represents the region in postfix notation.

This can be a surface reference, a region type, or halfspace

Definition at line 41 of file CSGRegion.h.

Member Enumeration Documentation

◆ RegionType

enum class CSG::CSGRegion::RegionType
strong

Enum for representing region types, defined to match _region_type MooseEnum.

Enumerator
EMPTY 
HALFSPACE 
COMPLEMENT 
INTERSECTION 
UNION 

Definition at line 26 of file CSGRegion.h.

Constructor & Destructor Documentation

◆ CSGRegion() [1/4]

CSG::CSGRegion::CSGRegion ( )

Default Constructor.

Definition at line 113 of file CSGRegion.C.

114{
115 _region_type = "EMPTY";
116 _postfix_tokens.clear();
117}
std::vector< PostfixTokenVariant > _postfix_tokens
List of tokens representing the region in postfix notation.
Definition CSGRegion.h:210
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition CSGRegion.h:207

Referenced by operator&=(), and operator|=().

◆ CSGRegion() [2/4]

CSG::CSGRegion::CSGRegion ( const CSGSurface surf,
const CSGSurface::Halfspace  halfspace 
)

Constructor for half-space of a surface.

Parameters
surfreferance to surface used to define the half-space
halfspacehalf-space to apply to surface (POSITIVE or NEGATIVE)

Definition at line 120 of file CSGRegion.C.

121{
122 _region_type = "HALFSPACE";
123
124 // (halfspace surf) in postfix is represented as (surf halfspace)
125 _postfix_tokens.push_back(surf);
126 _postfix_tokens.push_back(halfspace);
127}

◆ CSGRegion() [3/4]

CSG::CSGRegion::CSGRegion ( const CSGRegion region_a,
const CSGRegion region_b,
const std::string &  region_type 
)

Constructor for union and intersection.

Parameters
region_areference to first region to union or intersect
region_breference to second region to union or intersect
region_typetype of region operation (UNION or INTERSECTION)

Definition at line 130 of file CSGRegion.C.

133{
134 _region_type = region_type;
136 mooseError("Region type " + getRegionTypeString() + " is not supported for two regions.");
137 if (region_a.getRegionType() == RegionType::EMPTY ||
138 region_b.getRegionType() == RegionType::EMPTY)
139 mooseError("Region operation " + getRegionTypeString() +
140 " cannot be performed on an empty region.");
141
142 // (region_a region_type region_b) in postfix is represented as (region_a region_b region_type)
143 _postfix_tokens.insert(_postfix_tokens.end(),
144 region_a.getPostfixTokens().begin(),
145 region_a.getPostfixTokens().end());
146 _postfix_tokens.insert(_postfix_tokens.end(),
147 region_b.getPostfixTokens().begin(),
148 region_b.getPostfixTokens().end());
149 _postfix_tokens.push_back(getRegionType());
150}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
RegionType getRegionType() const
Get the region type.
Definition CSGRegion.h:123
const std::string getRegionTypeString() const
Get the region type as a string.
Definition CSGRegion.h:130

◆ CSGRegion() [4/4]

CSG::CSGRegion::CSGRegion ( const CSGRegion region,
const std::string &  region_type 
)

Constructor for complement or empty region (clear the region)

Parameters
regionreference to region to apply complement
region_typetype of region to apply (COMPLEMENT or EMPTY)

Definition at line 153 of file CSGRegion.C.

154{
155 _region_type = region_type;
157 mooseError("Region type " + getRegionTypeString() + " is not supported for a single region.");
158
160 {
161 // (complement region) in postfix is represented as (region complement)
162 _postfix_tokens = region.getPostfixTokens();
163 _postfix_tokens.push_back(getRegionType());
164 }
165 else if (getRegionType() == RegionType::EMPTY)
166 _postfix_tokens.clear();
167}

◆ ~CSGRegion()

virtual CSG::CSGRegion::~CSGRegion ( )
virtualdefault

Destructor.

Member Function Documentation

◆ checkRegionEquality()

bool CSG::CSGRegion::checkRegionEquality ( const std::vector< PostfixTokenVariant > &  other_tokens) const
protected

Loop through postfix tokens and check equality with another list of postfix tokens.

Parameters
other_tokenslist of postfix tokens to compare to
Returns
true if postfix token lists are equal, false otherwise

Definition at line 54 of file CSGRegion.C.

55{
56 const auto & tokens = getPostfixTokens();
57 if (tokens.size() != other_tokens.size())
58 return false;
59
60 // Loop through all tokens and check equality
61 for (const auto i : index_range(tokens))
62 {
63 const auto & token = tokens[i];
64 const auto & other_token = other_tokens[i];
65 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(token))
66 {
67 // For surface references, compare references themselves for equality
68 if (!std::holds_alternative<std::reference_wrapper<const CSGSurface>>(other_token))
69 return false;
70 const auto & surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(token);
71 const auto & other_surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(other_token);
72 if (surf_ref.get() != other_surf_ref.get())
73 return false;
74 }
75 else
76 {
77 // For region types and halfspaces, compare based on string representations
78 mooseAssert(std::holds_alternative<RegionType>(token) ||
79 std::holds_alternative<CSGSurface::Halfspace>(token),
80 "Unexpected token type");
81 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(other_token))
82 return false;
84 return false;
85 }
86 }
87 return true;
88}
const std::vector< PostfixTokenVariant > & getPostfixTokens() const
Get the list of postfix tokens associated with the region.
Definition CSGRegion.h:166
std::string postfixTokenToString(const PostfixTokenVariant &token) const
converts postfix token from PostfixTokenVariant to string representation
Definition CSGRegion.C:247
auto index_range(const T &sizable)

Referenced by operator==().

◆ getPostfixTokens()

const std::vector< PostfixTokenVariant > & CSG::CSGRegion::getPostfixTokens ( ) const
inlineprotected

Get the list of postfix tokens associated with the region.

Returns
list of tokens that define the region in postfix notation

Definition at line 166 of file CSGRegion.h.

166{ return _postfix_tokens; }

Referenced by checkRegionEquality(), CSGRegion(), CSGRegion(), and operator==().

◆ getRegionType()

RegionType CSG::CSGRegion::getRegionType ( ) const
inline

Get the region type.

Returns
region type enum

Definition at line 123 of file CSGRegion.h.

123{ return _region_type.getEnum<RegionType>(); }
RegionType
Enum for representing region types, defined to match _region_type MooseEnum.
Definition CSGRegion.h:27
T getEnum() const
get the current value cast to the enum type T
Definition MooseEnum.h:172

Referenced by CSGRegion(), CSGRegion(), CSG::CSGNPolygonUnit::expandUnit(), CSG::CSGSurfaceEngUnit::getExpandedRegion(), CSGUtils::getInnerRegion(), operator==(), and CSG::CSGBase::replaceSurfaceRefsWithRegion().

◆ getRegionTypeString()

const std::string CSG::CSGRegion::getRegionTypeString ( ) const
inline

Get the region type as a string.

Returns
region type string

Definition at line 130 of file CSGRegion.h.

130{ return _region_type; }

Referenced by CSGRegion(), and CSGRegion().

◆ getSurfaces()

std::vector< std::reference_wrapper< const CSGSurface > > CSG::CSGRegion::getSurfaces ( ) const

Get the list of surfaces associated with the region.

Returns
list of references to surfaces that define the region

Definition at line 289 of file CSGRegion.C.

290{
291 std::vector<std::reference_wrapper<const CSGSurface>> surface_references;
292 for (auto & token : _postfix_tokens)
293 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(token))
294 surface_references.push_back(std::get<std::reference_wrapper<const CSGSurface>>(token));
295
296 return surface_references;
297}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
const Elem & get(const ElemType type_in)

Referenced by CSG::CSGBase::addTransformation(), CSG::CSGBase::checkRegionSurfaces(), and CSG::CSGBase::expandEngUnit().

◆ halfspaceSymbol()

char CSG::CSGRegion::halfspaceSymbol ( const CSGSurface::Halfspace  halfspace)
static
Returns
The symbol associated with the given halfspace

Definition at line 37 of file CSGRegion.C.

38{
39 mooseAssert(halfspace == CSGSurface::Halfspace::POSITIVE ||
41 "Unexpected halfspace");
42
43 static constexpr std::array<char, 2> symbols = {
44 '+', // CSGSurface::Halfspace::POSITIVE
45 '-' // CSGSurface::Halfspace::NEGATIVE
46 };
47 static_assert(symbols[static_cast<std::size_t>(CSGSurface::Halfspace::POSITIVE)] == '+');
48 static_assert(symbols[static_cast<std::size_t>(CSGSurface::Halfspace::NEGATIVE)] == '-');
49
50 return symbols[static_cast<std::size_t>(halfspace)];
51}

Referenced by postfixTokenToString(), and toInfixJSON().

◆ nextRegionOpIsIdentical()

bool CSG::CSGRegion::nextRegionOpIsIdentical ( const RegionType  region,
const std::size_t  postfix_token_index 
) const
protected

Iterate through postfix tokens and check if next region operator matches the given operator.

Parameters
regionthe region type
postfix_token_indexindex in _postfix_tokens to start region operator comparisons
Returns
true if next region operator in _postfix_tokens matches region_op_string, false otherwise

Definition at line 265 of file CSGRegion.C.

267{
268 for (const auto i : make_range(postfix_token_index, _postfix_tokens.size()))
269 if (const auto region_ptr = std::get_if<RegionType>(&_postfix_tokens[i]))
270 return region == *region_ptr;
271 return false;
272}
IntRange< T > make_range(T beg, T end)

Referenced by toInfixJSON().

◆ operator!=()

bool CSG::CSGRegion::operator!= ( const CSGRegion other) const

Operator overload for checking if two CSGRegion objects are not equal.

Definition at line 360 of file CSGRegion.C.

361{
362 return !(*this == other);
363}

◆ operator&=()

CSGRegion & CSG::CSGRegion::operator&= ( const CSGRegion other_region)

Operator overload for &= which creates an intersection between the current region and the other_region.

Definition at line 300 of file CSGRegion.C.

301{
302 if (this != &other_region)
303 *this = CSGRegion(*this, other_region, "INTERSECTION");
304 return *this;
305}
CSGRegion()
Default Constructor.
Definition CSGRegion.C:113

◆ operator==()

bool CSG::CSGRegion::operator== ( const CSGRegion other) const

Operator overload for checking if two CSGRegion objects are equal.

Definition at line 353 of file CSGRegion.C.

354{
355 const bool region_type_eq = this->getRegionType() == other.getRegionType();
356 return (region_type_eq && checkRegionEquality(other.getPostfixTokens()));
357}
bool checkRegionEquality(const std::vector< PostfixTokenVariant > &other_tokens) const
Loop through postfix tokens and check equality with another list of postfix tokens.
Definition CSGRegion.C:54

◆ operator|=()

CSGRegion & CSG::CSGRegion::operator|= ( const CSGRegion other_region)

Operator overload for |= which creates a union of the current region with the other_region.

Definition at line 308 of file CSGRegion.C.

309{
310 if (this != &other_region)
311 *this = CSGRegion(*this, other_region, "UNION");
312 return *this;
313}

◆ postfixTokenToString()

std::string CSG::CSGRegion::postfixTokenToString ( const PostfixTokenVariant token) const

converts postfix token from PostfixTokenVariant to string representation

Parameters
tokenpostfix token of type PostfixTokenVariant
Returns
string representation of postfix token

Definition at line 247 of file CSGRegion.C.

248{
249 // Lambda function to return all variant types as strings
250 return std::visit(
251 [](auto && arg) -> std::string
252 {
253 using T = std::decay_t<decltype(arg)>;
254 if constexpr (std::is_same_v<T, std::reference_wrapper<const CSGSurface>>)
255 return arg.get().getName();
256 else if constexpr (std::is_same_v<T, RegionType>)
257 return std::string{regionSymbol(arg)};
258 else // if constexpr (std::is_same_v<T, CSGSurface::Halfspace>)
259 return std::string{halfspaceSymbol(arg)};
260 },
261 token);
262}
static char regionSymbol(const RegionType region_type)
Definition CSGRegion.C:16
static char halfspaceSymbol(const CSGSurface::Halfspace halfspace)
Definition CSGRegion.C:37

Referenced by checkRegionEquality(), and toPostfixStringList().

◆ regionSymbol()

char CSG::CSGRegion::regionSymbol ( const RegionType  region_type)
static
Returns
The symbol associated with the given region type

Definition at line 16 of file CSGRegion.C.

17{
18 mooseAssert(region_type == RegionType::COMPLEMENT || region_type == RegionType::UNION ||
19 region_type == RegionType::INTERSECTION,
20 "Unexpected region type");
21
22 static constexpr std::array<char, 5> symbols = {
23 '\0', // CSGRegion::RegionType::EMPTY (unused)
24 '\0', // CSGRegion::RegionType::HALFSPACE (unused)
25 '~', // CSGRegion::RegionType::COMPLEMENT
26 '&', // CSGRegion::RegionType::INTERSECTION
27 '|' // CSGRegion::RegionType::UNION
28 };
29 static_assert(symbols[static_cast<std::size_t>(RegionType::COMPLEMENT)] == '~');
30 static_assert(symbols[static_cast<std::size_t>(RegionType::INTERSECTION)] == '&');
31 static_assert(symbols[static_cast<std::size_t>(RegionType::UNION)] == '|');
32
33 return symbols[static_cast<std::size_t>(region_type)];
34}

Referenced by postfixTokenToString(), and toInfixJSON().

◆ regionTypeName()

std::string CSG::CSGRegion::regionTypeName ( const RegionType  region_type)
static
Returns
The string associated with the given region type

Definition at line 91 of file CSGRegion.C.

92{
93 mooseAssert(region_type == RegionType::COMPLEMENT || region_type == RegionType::INTERSECTION ||
94 region_type == RegionType::UNION,
95 "Unexpected region type");
96
97 static constexpr std::array<const char *, 5> names = {
98 nullptr, // RegionType::EMPTY (not used as a postfix operator)
99 nullptr, // RegionType::HALFSPACE (not used as a postfix operator)
100 "COMPLEMENT", // RegionType::COMPLEMENT
101 "INTERSECTION", // RegionType::INTERSECTION
102 "UNION" // RegionType::UNION
103 };
104 static_assert(names[static_cast<std::size_t>(RegionType::COMPLEMENT)] ==
105 std::string_view("COMPLEMENT"));
106 static_assert(names[static_cast<std::size_t>(RegionType::INTERSECTION)] ==
107 std::string_view("INTERSECTION"));
108 static_assert(names[static_cast<std::size_t>(RegionType::UNION)] == std::string_view("UNION"));
109
110 return names[static_cast<std::size_t>(region_type)];
111}

Referenced by replaceWithSubRegion().

◆ replaceWithSubRegion()

void CSG::CSGRegion::replaceWithSubRegion ( const CSGSurface old_surf,
const CSGRegion sub_region 
)
protected

Replace all occurrences of old_surf in this region's postfix token stream with the tokens of sub_region.

Each [old_surf_ref][Halfspace] pair in _postfix_tokens is replaced by sub_region's tokens (for NEGATIVE halfspace) or sub_region's tokens followed by a COMPLEMENT token (for POSITIVE halfspace). The flat _surfaces list is rebuilt from the updated token stream.

Called exclusively by CSGBase::replaceSurfaceRefsWithRegion().

Parameters
old_surfsurface to replace
sub_regionregion to substitute (represents the old surface's "negative" interior)

Definition at line 366 of file CSGRegion.C.

367{
368 // Rebuild _postfix_tokens, substituting each [old_surf_ref][Halfspace] pair with the
369 // tokens of sub_region (and a trailing COMPLEMENT for the positive / outside halfspace).
370 // This will also update the _surfaces list to remove the old_surf (if present) and append the
371 // surfaces from the sub-region if they are used to replace the old_surf here.
372 std::vector<PostfixTokenVariant> new_tokens;
373
374 for (std::size_t i = 0; i < _postfix_tokens.size(); ++i)
375 {
376 const auto * ref_ptr =
377 std::get_if<std::reference_wrapper<const CSGSurface>>(&_postfix_tokens[i]);
378
379 if (ref_ptr && &ref_ptr->get() == &old_surf)
380 {
381 // encountered the old_surf to be replaced, so replace with the sub_region tokens
382
383 // The next token must be the Halfspace that was applied to this surface
384 mooseAssert(i + 1 < _postfix_tokens.size() &&
385 std::holds_alternative<CSGSurface::Halfspace>(_postfix_tokens[i + 1]),
386 "Expected a Halfspace token after surface reference in postfix stream");
387 const auto & hs = std::get<CSGSurface::Halfspace>(_postfix_tokens[++i]);
388
389 // Insert the sub-region's token stream in place of the surface + halfspace pair
390 new_tokens.insert(
391 new_tokens.end(), sub_region._postfix_tokens.begin(), sub_region._postfix_tokens.end());
392
393 // Positive halfspace means "outside" so use complement of sub-region
395 new_tokens.push_back(RegionType::COMPLEMENT);
396 }
397 else
398 new_tokens.push_back(_postfix_tokens[i]);
399 }
400 _postfix_tokens = new_tokens;
401
402 // Update _region_type from the last token in the new stream
403 if (_postfix_tokens.empty())
404 _region_type = "EMPTY";
405 else if (const auto * rt = std::get_if<RegionType>(&_postfix_tokens.back()))
407 else
408 {
409 mooseAssert(std::holds_alternative<CSGSurface::Halfspace>(_postfix_tokens.back()),
410 "Expected halfspace as last token");
411 _region_type = "HALFSPACE";
412 }
413}
static std::string regionTypeName(const RegionType region_type)
Definition CSGRegion.C:91

Referenced by CSG::CSGBase::replaceSurfaceRefsWithRegion().

◆ toInfixJSON()

nlohmann::json CSG::CSGRegion::toInfixJSON ( ) const

gets the infix JSON representation of the region, which involves converting region representation from postfix to infix notation

Returns
infix JSON representation of the region

Definition at line 170 of file CSGRegion.C.

171{
172 // Return an empty JSON object if no postfix tokens are defined
173 if (_postfix_tokens.empty())
174 return nlohmann::json::parse("[]");
175
176 // Build the region string using a stack, iterating through each token within _postfix_tokens
177 std::stack<std::string> postfix_stack;
178 for (auto i : index_range(_postfix_tokens))
179 {
180 const auto & token = _postfix_tokens[i];
181 // Surface: Push name to stack
182 if (const auto surface_ref_ptr = std::get_if<std::reference_wrapper<const CSGSurface>>(&token))
183 postfix_stack.push(surface_ref_ptr->get().getName());
184 // Halfspaces and region operators
185 else
186 {
187 std::string region_string;
188 // Halfspace: Pop from the stack, update region string, push back
189 if (const auto halfspace_ptr = std::get_if<CSGSurface::Halfspace>(&token))
190 {
191 std::string symbol = std::string(1, halfspaceSymbol(*halfspace_ptr));
192 region_string = "\"" + symbol + postfix_stack.top() + "\"";
193 postfix_stack.pop();
194 }
195 // Region operator: Pop 1 or 2 values, update region string, push back
196 else
197 {
198 const auto region = std::get<RegionType>(token);
199 const std::string symbol{regionSymbol(region)};
200 if (region == RegionType::COMPLEMENT)
201 {
202 region_string = postfix_stack.top();
203 postfix_stack.pop();
204 if (region_string[0] == '[')
205 region_string = "\"" + symbol + "\", " + region_string;
206 else
207 region_string = "\"" + symbol + "\", [" + region_string + "]";
208 }
209 else
210 {
211 auto region_string_b = postfix_stack.top();
212 postfix_stack.pop();
213 auto region_string_a = postfix_stack.top();
214 postfix_stack.pop();
215 region_string = region_string_a + ", \"" + symbol + "\", " + region_string_b;
216 // Skip putting parentheses around the region string if the next region operator in the
217 // postfix token list is identical
218 if (!nextRegionOpIsIdentical(region, i + 1))
219 region_string = "[" + region_string + "]";
220 }
221 }
222 postfix_stack.push(region_string);
223 }
224 }
225
226 // Top of stack should now have region string we desire. Now, we
227 // parse the string into a JSON object
228 std::string region_string = postfix_stack.top();
229 // Wrap region string in square brackets so that it is always treated as a
230 // list in the output JSON object
231 if (region_string[0] != '[')
232 region_string = "[" + region_string + "]";
233 return nlohmann::json::parse(region_string);
234}
bool nextRegionOpIsIdentical(const RegionType region, const std::size_t postfix_token_index) const
Iterate through postfix tokens and check if next region operator matches the given operator.
Definition CSGRegion.C:265

◆ toPostfixStringList()

std::vector< std::string > CSG::CSGRegion::toPostfixStringList ( ) const

gets the list of postfix tokens of the region in string representation

Returns
list of postfix tokens that represent the region

Definition at line 237 of file CSGRegion.C.

238{
239 std::vector<std::string> postfix_string_list;
240 postfix_string_list.reserve(_postfix_tokens.size());
241 for (const auto & token : _postfix_tokens)
242 postfix_string_list.push_back(postfixTokenToString(token));
243 return postfix_string_list;
244}

◆ updateSurfaceReferences()

void CSG::CSGRegion::updateSurfaceReferences ( std::map< std::string, std::reference_wrapper< const CSGSurface > > &  identical_surface_refs)

Update surface references of region based on map of input surface references.

Parameters
identical_surface_refsmap of surface name to surface references that region should be defined with

Definition at line 275 of file CSGRegion.C.

277{
278 for (auto & token : _postfix_tokens)
279 if (std::holds_alternative<std::reference_wrapper<const CSGSurface>>(token))
280 {
281 const auto & surf_ref = std::get<std::reference_wrapper<const CSGSurface>>(token);
282 const auto & surf_name = surf_ref.get().getName();
283 if (identical_surface_refs.find(surf_name) != identical_surface_refs.end())
284 token = identical_surface_refs.at(surf_name);
285 }
286}

Referenced by CSG::CSGCell::updateCellRegionSurfaces().

Friends And Related Symbol Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 204 of file CSGRegion.h.

Member Data Documentation

◆ _postfix_tokens

std::vector<PostfixTokenVariant> CSG::CSGRegion::_postfix_tokens
protected

List of tokens representing the region in postfix notation.

Definition at line 210 of file CSGRegion.h.

Referenced by CSGRegion(), CSGRegion(), CSGRegion(), CSGRegion(), getPostfixTokens(), getSurfaces(), nextRegionOpIsIdentical(), replaceWithSubRegion(), toInfixJSON(), toPostfixStringList(), and updateSurfaceReferences().

◆ _region_type

MooseEnum CSG::CSGRegion::_region_type {"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"}
protected

An enum for type of type of operation that defines region.

Definition at line 207 of file CSGRegion.h.

207{"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"};

Referenced by CSGRegion(), CSGRegion(), CSGRegion(), CSGRegion(), getRegionType(), getRegionTypeString(), and replaceWithSubRegion().


The documentation for this class was generated from the following files: