https://mooseframework.inl.gov
Public Types | Public Member Functions | Protected Attributes | 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  RegionType {
  RegionType::EMPTY = 0, RegionType::HALFSPACE = 1, RegionType::COMPLEMENT = 2, RegionType::INTERSECTION = 3,
  RegionType::UNION = 4
}
 Enum for representing region types, defined to match _region_type MooseEnum. More...
 

Public Member Functions

 CSGRegion ()
 Default Constructor. More...
 
 CSGRegion (const CSGSurface &surf, const CSGSurface::Halfspace halfspace)
 Constructor for half-space of a surface. More...
 
 CSGRegion (const CSGRegion &region_a, const CSGRegion &region_b, const std::string &region_type)
 Constructor for union and intersection. More...
 
 CSGRegion (const CSGRegion &region, const std::string &region_type)
 Constructor for complement or empty region (clear the region) More...
 
virtual ~CSGRegion ()=default
 Destructor. More...
 
const std::string & toString () const
 gets the string representation of the region More...
 
RegionType getRegionType () const
 Get the region type. More...
 
const std::string getRegionTypeString () const
 Get the region type as a string. More...
 
const std::vector< std::reference_wrapper< const CSGSurface > > & getSurfaces () const
 Get the list of surfaces associated with the region. More...
 
CSGRegionoperator &= (const CSGRegion &other_region)
 Operator overload for &= which creates an intersection between the current region and the other_region. More...
 
CSGRegionoperator|= (const CSGRegion &other_region)
 Operator overload for |= which creates a union of the current region with the other_region. More...
 
bool operator== (const CSGRegion &other) const
 Operator overload for checking if two CSGRegion objects are equal. More...
 
bool operator!= (const CSGRegion &other) const
 Operator overload for checking if two CSGRegion objects are not equal. More...
 

Protected Attributes

std::string _region_str
 String representation of region - defaults to empty string. More...
 
MooseEnum _region_type {"EMPTY=0 HALFSPACE=1 COMPLEMENT=2 INTERSECTION=3 UNION=4"}
 An enum for type of type of operation that defines region. More...
 
std::vector< std::reference_wrapper< const CSGSurface > > _surfaces
 Surface list associated with the region. More...
 

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 21 of file CSGRegion.h.

Member Enumeration Documentation

◆ RegionType

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

Enumerator
EMPTY 
HALFSPACE 
COMPLEMENT 
INTERSECTION 
UNION 

Definition at line 25 of file CSGRegion.h.

26  {
27  EMPTY = 0,
28  HALFSPACE = 1,
29  COMPLEMENT = 2,
30  INTERSECTION = 3,
31  UNION = 4
32  };

Constructor & Destructor Documentation

◆ CSGRegion() [1/4]

CSG::CSGRegion::CSGRegion ( )

Default Constructor.

Definition at line 15 of file CSGRegion.C.

Referenced by operator|=().

16 {
17  _region_str = "";
18  _region_type = "EMPTY";
19 }
std::string _region_str
String representation of region - defaults to empty string.
Definition: CSGRegion.h:116
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119

◆ 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 22 of file CSGRegion.C.

23 {
24  _region_type = "HALFSPACE";
25  _region_str = ((halfspace == CSGSurface::Halfspace::POSITIVE) ? "+" : "-") + surf.getName();
26  _surfaces.push_back(surf);
27 }
std::string _region_str
String representation of region - defaults to empty string.
Definition: CSGRegion.h:116
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119
std::vector< std::reference_wrapper< const CSGSurface > > _surfaces
Surface list associated with the region.
Definition: CSGRegion.h:122

◆ 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 30 of file CSGRegion.C.

33 {
34  _region_type = region_type;
36  mooseError("Region type " + getRegionTypeString() + " is not supported for two regions.");
37  if (region_a.getRegionType() == RegionType::EMPTY ||
38  region_b.getRegionType() == RegionType::EMPTY)
39  mooseError("Region operation " + getRegionTypeString() +
40  " cannot be performed on an empty region.");
41 
42  std::string op = (getRegionType() == RegionType::UNION) ? " | " : " & ";
43  auto a_string = stripRegionString(region_a.toString(), op);
44  auto b_string = stripRegionString(region_b.toString(), op);
45 
46  _region_str = "(" + a_string + op + b_string + ")";
47  const auto & a_surfs = region_a.getSurfaces();
48  const auto & b_surfs = region_b.getSurfaces();
49  _surfaces.insert(_surfaces.end(), a_surfs.begin(), a_surfs.end());
50  _surfaces.insert(_surfaces.end(), b_surfs.begin(), b_surfs.end());
51 }
std::string _region_str
String representation of region - defaults to empty string.
Definition: CSGRegion.h:116
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
RegionType getRegionType() const
Get the region type.
Definition: CSGRegion.h:83
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119
std::vector< std::reference_wrapper< const CSGSurface > > _surfaces
Surface list associated with the region.
Definition: CSGRegion.h:122
const std::string stripRegionString(std::string region_str, std::string op)
strip the leading and trailing parentheses from the string if only the specified operator is present ...
Definition: CSGRegion.C:91
const std::string getRegionTypeString() const
Get the region type as a string.
Definition: CSGRegion.h:90

◆ 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 54 of file CSGRegion.C.

55 {
56  _region_type = region_type;
58  mooseError("Region type " + getRegionTypeString() + " is not supported for a single region.");
59 
61  {
62  // no change to surfaces, but update string
63  _region_str = "~" + region.toString();
64  _surfaces = region.getSurfaces();
65  }
66  else if (getRegionType() == RegionType::EMPTY)
67  {
68  // reset the region and make it empty
69  _region_str = "";
70  _surfaces.clear();
71  }
72 }
std::string _region_str
String representation of region - defaults to empty string.
Definition: CSGRegion.h:116
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
RegionType getRegionType() const
Get the region type.
Definition: CSGRegion.h:83
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119
std::vector< std::reference_wrapper< const CSGSurface > > _surfaces
Surface list associated with the region.
Definition: CSGRegion.h:122
const std::string getRegionTypeString() const
Get the region type as a string.
Definition: CSGRegion.h:90

◆ ~CSGRegion()

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

Destructor.

Member Function Documentation

◆ getRegionType()

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

Get the region type.

Returns
region type enum

Definition at line 83 of file CSGRegion.h.

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

83 { return _region_type.getEnum<RegionType>(); }
T getEnum() const
get the current value cast to the enum type T
Definition: MooseEnum.h:151
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119
RegionType
Enum for representing region types, defined to match _region_type MooseEnum.
Definition: CSGRegion.h:25

◆ getRegionTypeString()

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

Get the region type as a string.

Returns
region type string

Definition at line 90 of file CSGRegion.h.

Referenced by CSGRegion().

90 { return _region_type; }
MooseEnum _region_type
An enum for type of type of operation that defines region.
Definition: CSGRegion.h:119

◆ getSurfaces()

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

Get the list of surfaces associated with the region.

Returns
list of pointers to surfaces that define the region

Definition at line 97 of file CSGRegion.h.

Referenced by CSG::CSGBase::checkRegionSurfaces(), CSGRegion(), and operator==().

98  {
99  return _surfaces;
100  }
std::vector< std::reference_wrapper< const CSGSurface > > _surfaces
Surface list associated with the region.
Definition: CSGRegion.h:122

◆ operator &=()

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

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

◆ operator!=()

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

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

Definition at line 188 of file CSGRegion.C.

189 {
190  return !(*this == other);
191 }

◆ operator==()

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

Operator overload for checking if two CSGRegion objects are equal.

Definition at line 164 of file CSGRegion.C.

165 {
166  const bool region_type_eq = this->getRegionType() == other.getRegionType();
167  const bool region_str_eq = this->toString() == other.toString();
168  if (region_type_eq && region_str_eq)
169  {
170  const auto & all_surfs = getSurfaces();
171  const auto & other_surfs = other.getSurfaces();
172  const bool num_cells_eq = all_surfs.size() == other_surfs.size();
173  if (num_cells_eq)
174  {
175  for (const auto i : index_range(all_surfs))
176  if (all_surfs[i].get() != other_surfs[i].get())
177  return false;
178  return true;
179  }
180  else
181  return false;
182  }
183  else
184  return false;
185 }
const std::string & toString() const
gets the string representation of the region
Definition: CSGRegion.h:76
RegionType getRegionType() const
Get the region type.
Definition: CSGRegion.h:83
const std::vector< std::reference_wrapper< const CSGSurface > > & getSurfaces() const
Get the list of surfaces associated with the region.
Definition: CSGRegion.h:97
auto index_range(const T &sizable)

◆ 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 83 of file CSGRegion.C.

84 {
85  if (this != &other_region)
86  *this = CSGRegion(*this, other_region, "UNION");
87  return *this;
88 }
CSGRegion()
Default Constructor.
Definition: CSGRegion.C:15

◆ toString()

const std::string& CSG::CSGRegion::toString ( ) const
inline

gets the string representation of the region

Returns
string representation of the region

Definition at line 76 of file CSGRegion.h.

Referenced by CSGRegion(), CSG::CSGCell::getRegionAsString(), and operator==().

76 { return _region_str; }
std::string _region_str
String representation of region - defaults to empty string.
Definition: CSGRegion.h:116

Member Data Documentation

◆ _region_str

std::string CSG::CSGRegion::_region_str
protected

String representation of region - defaults to empty string.

Definition at line 116 of file CSGRegion.h.

Referenced by CSGRegion(), and toString().

◆ _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 119 of file CSGRegion.h.

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

◆ _surfaces

std::vector<std::reference_wrapper<const CSGSurface> > CSG::CSGRegion::_surfaces
protected

Surface list associated with the region.

Definition at line 122 of file CSGRegion.h.

Referenced by CSGRegion(), and getSurfaces().


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