https://mooseframework.inl.gov
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
CSG::CSGUniverse Class Reference

CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe, which represents a collection of cells that can be defined repeatedly within a separate container of cells. More...

#include <CSGUniverse.h>

Inheritance diagram for CSG::CSGUniverse:
[legend]

Public Member Functions

 CSGUniverse (const std::string &name, bool is_root=false)
 Construct a new CSGUniverse object. More...
 
 CSGUniverse (const std::string &name, std::vector< CSGCell *> &cells, bool is_root=false)
 Construct a new CSGUniverse object from list of cells. More...
 
virtual ~CSGUniverse ()=default
 Destructor. More...
 
const CSGCellgetCell (const std::string &name)
 Get the CSGCell object by name. More...
 
bool hasCell (const std::string &name) const
 check if cell of provided name is present in universe More...
 
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells () const
 Get list of the all cells in the universe. More...
 
const std::string & getName () const
 Get the name of the universe. More...
 
bool isRoot () const
 return true if the universe is the root universe More...
 
bool operator== (const CSGUniverse &other) const
 Operator overload for checking if two CSGUniverse objects are equal. More...
 
bool operator!= (const CSGUniverse &other) const
 Operator overload for checking if two CSGUniverse objects are not equal. More...
 
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations () const
 Get the list of transformations. More...
 
std::vector< std::pair< std::string, std::tuple< Real, Real, Real > > > getTransformationsAsStrings () const
 Get the transformations of this object with string representations for types. More...
 

Static Public Member Functions

static bool isValidTransformationValue (TransformationType type, const std::tuple< Real, Real, Real > &values)
 Check if the transformation value is valid for the given type. More...
 
static std::string getTransformationTypeString (TransformationType type)
 Get the string representation of the transformation type. More...
 

Protected Member Functions

void addCell (const CSGCell &cell)
 add cell to universe More...
 
void removeCell (const std::string &name)
 remove a cell of the specified name from the universe More...
 
void removeAllCells ()
 remove all cells from the universe More...
 
void setName (const std::string &name)
 
void addTransformation (TransformationType type, const std::tuple< Real, Real, Real > &values)
 Add a transformation to the list of transformations. More...
 
Point applyReverseTransformsToPoint (Point p) const
 update the value of point p by applying the inverse of the list of transformations to the point More...
 
 FRIEND_TEST (CSGUniverseTest, testGetCell)
 Friends for unit testing. More...
 
 FRIEND_TEST (CSGUniverseTest, testAddCell)
 
 FRIEND_TEST (CSGUniverseTest, testRemoveCell)
 
 FRIEND_TEST (CSGUniverseTest, testRemoveAllCells)
 
 FRIEND_TEST (CSGUniverseTest, testSetName)
 
 FRIEND_TEST (CSGUniverseTest, testUniverseEquality)
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithTransform)
 Friends for unit testing. More...
 
 FRIEND_TEST (CSGSurfaceTest, testHalfspaceWithNullTransform)
 

Protected Attributes

std::string _name
 Name of universe. More...
 
std::vector< std::reference_wrapper< const CSGCell > > _cells
 list of references to cells in universe More...
 
bool _is_root
 whether or not this universe is the root universe More...
 
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
 List of transformations applied to this object. More...
 

Friends

class CSGUniverseList
 
class CSGBase
 

Detailed Description

CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe, which represents a collection of cells that can be defined repeatedly within a separate container of cells.

Definition at line 27 of file CSGUniverse.h.

Constructor & Destructor Documentation

◆ CSGUniverse() [1/2]

CSG::CSGUniverse::CSGUniverse ( const std::string &  name,
bool  is_root = false 
)

Construct a new CSGUniverse object.

Parameters
nameunique name of universe
is_roottrue to set universe as the root universe (default false)

Definition at line 17 of file CSGUniverse.C.

17 : _name(name), _is_root(is_root) {}
std::string _name
Name of universe.
Definition: CSGUniverse.h:120
bool _is_root
whether or not this universe is the root universe
Definition: CSGUniverse.h:126

◆ CSGUniverse() [2/2]

CSG::CSGUniverse::CSGUniverse ( const std::string &  name,
std::vector< CSGCell *> &  cells,
bool  is_root = false 
)

Construct a new CSGUniverse object from list of cells.

Parameters
nameunique name of universe
cellslist of cells to add to universe
is_roottrue to set universe as the root universe (default false)

Definition at line 19 of file CSGUniverse.C.

20  : _name(name), _is_root(is_root)
21 {
23  for (auto cell : cells)
24  addCell(*cell);
25 }
std::string _name
Name of universe.
Definition: CSGUniverse.h:120
bool _is_root
whether or not this universe is the root universe
Definition: CSGUniverse.h:126
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition: CSGUtils.C:36
void addCell(const CSGCell &cell)
add cell to universe
Definition: CSGUniverse.C:28

◆ ~CSGUniverse()

virtual CSG::CSGUniverse::~CSGUniverse ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addCell()

void CSG::CSGUniverse::addCell ( const CSGCell cell)
protected

add cell to universe

Parameters
referenceto cell to add

Definition at line 28 of file CSGUniverse.C.

Referenced by CSG::CSGBase::addCellToUniverse(), and CSGUniverse().

29 {
30  auto cell_name = cell.getName();
31  if (!hasCell(cell_name))
32  _cells.push_back(cell);
33  else
34  mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " +
35  "Skipping cell insertion for cell with duplicate name.");
36 }
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:345
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:50
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:80
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ addTransformation()

void CSG::CSGTransformationHelper::addTransformation ( TransformationType  type,
const std::tuple< Real, Real, Real > &  values 
)
protectedinherited

Add a transformation to the list of transformations.

Parameters
typeThe type of transformation
valuesThe values for the transformation

Definition at line 16 of file CSGTransformationHelper.C.

18 {
19  if (!isValidTransformationValue(type, values))
20  mooseError("Invalid transformation values provided for transformation type " +
22  _transformations.emplace_back(type, values);
23 }
static bool isValidTransformationValue(TransformationType type, const std::tuple< Real, Real, Real > &values)
Check if the transformation value is valid for the given type.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
static std::string getTransformationTypeString(TransformationType type)
Get the string representation of the transformation type.
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ applyReverseTransformsToPoint()

Point CSG::CSGTransformationHelper::applyReverseTransformsToPoint ( Point  p) const
protectedinherited

update the value of point p by applying the inverse of the list of transformations to the point

Parameters
ppoint to transform
Returns
transformed point

Definition at line 74 of file CSGTransformationHelper.C.

Referenced by CSG::CSGSurface::getHalfspaceFromPoint().

75 {
76  // iterate list of transformations in reverse and apply the inverse operation
77  for (auto it = _transformations.rbegin(); it != _transformations.rend(); ++it)
78  {
79  auto trans_type = it->first;
80  auto val = it->second;
81 
82  if (trans_type == TransformationType::TRANSLATION)
83  {
84  Point offset(std::get<0>(val), std::get<1>(val), std::get<2>(val));
85  p -= offset;
86  }
87  else if (trans_type == TransformationType::SCALE)
88  {
89  Point scale(std::get<0>(val), std::get<1>(val), std::get<2>(val));
90  for (int i = 0; i < 3; ++i)
91  p(i) /= scale(i);
92  }
93  else if (trans_type == TransformationType::ROTATION)
94  {
95  // get the transpose of the original rotation matrix and apply to point p
96  const auto rot_matrix = RealTensorValue::intrinsic_rotation_matrix(
97  std::get<0>(val), std::get<1>(val), std::get<2>(val));
98  const auto rot_transpose = rot_matrix.transpose();
99  p = rot_transpose * p;
100  }
101  else
102  mooseError("Transformation type is not recognized.");
103  }
104  return p;
105 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.
static TensorValue< Real > intrinsic_rotation_matrix(Real phi, Real theta, Real psi)

◆ FRIEND_TEST() [1/8]

CSG::CSGTransformationHelper::FRIEND_TEST ( CSGSurfaceTest  ,
testHalfspaceWithTransform   
)
protectedinherited

Friends for unit testing.

◆ FRIEND_TEST() [2/8]

CSG::CSGTransformationHelper::FRIEND_TEST ( CSGSurfaceTest  ,
testHalfspaceWithNullTransform   
)
protectedinherited

◆ FRIEND_TEST() [3/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testGetCell   
)
protected

Friends for unit testing.

◆ FRIEND_TEST() [4/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testAddCell   
)
protected

◆ FRIEND_TEST() [5/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testRemoveCell   
)
protected

◆ FRIEND_TEST() [6/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testRemoveAllCells   
)
protected

◆ FRIEND_TEST() [7/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testSetName   
)
protected

◆ FRIEND_TEST() [8/8]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testUniverseEquality   
)
protected

◆ getAllCells()

const std::vector<std::reference_wrapper<const CSGCell> >& CSG::CSGUniverse::getAllCells ( ) const
inline

Get list of the all cells in the universe.

Returns
list of pointers to cells in universe

Definition at line 73 of file CSGUniverse.h.

Referenced by CSG::CSGBase::addUniverseToList(), CSG::CSGBase::CSGBase(), CSG::CSGBase::getLinkedUniverses(), and operator==().

73 { return _cells; }
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ getCell()

const CSGCell & CSG::CSGUniverse::getCell ( const std::string &  name)

Get the CSGCell object by name.

Parameters
namename of cell
Returns
reference to the cell of the specified name in this universe

Definition at line 39 of file CSGUniverse.C.

40 {
41  if (!hasCell(name))
42  mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
43  for (const CSGCell & cell : _cells)
44  if (cell.getName() == name)
45  return cell;
46  mooseError("Should not reach here.");
47 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::string _name
Name of universe.
Definition: CSGUniverse.h:120
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:50
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ getName()

const std::string& CSG::CSGUniverse::getName ( ) const
inline

◆ getTransformations()

const std::vector<std::pair<TransformationType, std::tuple<Real, Real, Real> > >& CSG::CSGTransformationHelper::getTransformations ( ) const
inlineinherited

Get the list of transformations.

Returns
The list of transformations

Definition at line 47 of file CSGTransformationHelper.h.

Referenced by CSG::CSGSurface::getHalfspaceFromPoint(), operator==(), CSG::CSGSurface::operator==(), CSG::CSGCell::operator==(), and CSG::CSGLattice::operator==().

48  {
49  return _transformations;
50  }
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ getTransformationsAsStrings()

std::vector< std::pair< std::string, std::tuple< Real, Real, Real > > > CSG::CSGTransformationHelper::getTransformationsAsStrings ( ) const
inherited

Get the transformations of this object with string representations for types.

Returns
Vector of transformation pairs with string representations for types

Definition at line 65 of file CSGTransformationHelper.C.

66 {
67  std::vector<std::pair<std::string, std::tuple<Real, Real, Real>>> result;
68  for (const auto & transform_pair : _transformations)
69  result.emplace_back(getTransformationTypeString(transform_pair.first), transform_pair.second);
70  return result;
71 }
static std::string getTransformationTypeString(TransformationType type)
Get the string representation of the transformation type.
std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > _transformations
List of transformations applied to this object.

◆ getTransformationTypeString()

std::string CSG::CSGTransformationHelper::getTransformationTypeString ( TransformationType  type)
staticinherited

Get the string representation of the transformation type.

Parameters
typeThe transformation type
Returns
String name of the transformation type

Definition at line 56 of file CSGTransformationHelper.C.

Referenced by CSG::CSGTransformationHelper::addTransformation(), and CSG::CSGTransformationHelper::getTransformationsAsStrings().

57 {
58  // Set the enum to the value and convert it to string
60  enum_copy = static_cast<int>(type);
61  return std::string(enum_copy);
62 }
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
static const MooseEnum transformation_type_enum
MooseEnum for transformation types, matching the TransformationType enum values.

◆ hasCell()

bool CSG::CSGUniverse::hasCell ( const std::string &  name) const

check if cell of provided name is present in universe

Parameters
namename of cell
Returns
true if cell of name is in universe, otherwise false

Definition at line 50 of file CSGUniverse.C.

Referenced by addCell(), getCell(), and removeCell().

51 {
52  for (const CSGCell & cell : _cells)
53  if (cell.getName() == name)
54  return true;
55  return false;
56 }
std::string name(const ElemQuality q)
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ isRoot()

bool CSG::CSGUniverse::isRoot ( ) const
inline

return true if the universe is the root universe

Returns
true / false

Definition at line 87 of file CSGUniverse.h.

87 { return _is_root; }
bool _is_root
whether or not this universe is the root universe
Definition: CSGUniverse.h:126

◆ isValidTransformationValue()

bool CSG::CSGTransformationHelper::isValidTransformationValue ( TransformationType  type,
const std::tuple< Real, Real, Real > &  values 
)
staticinherited

Check if the transformation value is valid for the given type.

Parameters
typeThe type of transformation
valuesThe values for the transformation
Returns
True if the values are valid for the type

Definition at line 26 of file CSGTransformationHelper.C.

Referenced by CSG::CSGTransformationHelper::addTransformation().

28 {
29  // Additional validation specific to each transformation type could be added here
30  switch (type)
31  {
33  // All translation values are inherently valid
34  return true;
35 
37  // Rotation uses euler notation; values are angles in degrees (phi, theta, psi)
38  // For consistency with TransformGenerator, there are no restrictions on the angles
39  // phi: rotation around Z-axis
40  // theta: rotation around new X-axis
41  // psi: rotation around new Z-axis
42  return true;
43 
45  // Scaling factors should be non-zero
46  if (std::get<0>(values) == 0.0 || std::get<1>(values) == 0.0 || std::get<2>(values) == 0.0)
47  return false;
48  return true;
49 
50  default:
51  mooseError("Unknown transformation type");
52  }
53 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311

◆ operator!=()

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

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

Definition at line 93 of file CSGUniverse.C.

94 {
95  return !(*this == other);
96 }

◆ operator==()

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

Operator overload for checking if two CSGUniverse objects are equal.

Definition at line 73 of file CSGUniverse.C.

74 {
75  if ((this->getName() != other.getName()) ||
76  (this->getTransformations() != other.getTransformations()))
77  return false;
78  const auto & all_cells = getAllCells();
79  const auto & other_cells = other.getAllCells();
80  const bool num_cells_eq = all_cells.size() == other_cells.size();
81  if (num_cells_eq)
82  {
83  for (unsigned int i = 0; i < all_cells.size(); ++i)
84  if (all_cells[i].get() != other_cells[i].get())
85  return false;
86  return true;
87  }
88  else
89  return false;
90 }
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in the universe.
Definition: CSGUniverse.h:73
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:80
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.

◆ removeAllCells()

void CSG::CSGUniverse::removeAllCells ( )
inlineprotected

remove all cells from the universe

Definition at line 113 of file CSGUniverse.h.

113 { _cells.clear(); }
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ removeCell()

void CSG::CSGUniverse::removeCell ( const std::string &  name)
protected

remove a cell of the specified name from the universe

Parameters
namename of cell to remove

Definition at line 59 of file CSGUniverse.C.

Referenced by CSG::CSGBase::deleteCell(), and CSG::CSGBase::removeCellFromUniverse().

60 {
61  if (!hasCell(name))
62  mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
63  _name + ".");
64  for (auto it = _cells.begin(); it != _cells.end(); ++it)
65  if (it->get().getName() == name)
66  {
67  _cells.erase(it);
68  break;
69  }
70 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::string _name
Name of universe.
Definition: CSGUniverse.h:120
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:50
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:123

◆ setName()

void CSG::CSGUniverse::setName ( const std::string &  name)
inlineprotected

Definition at line 117 of file CSGUniverse.h.

117 { _name = name; }
std::string name(const ElemQuality q)
std::string _name
Name of universe.
Definition: CSGUniverse.h:120

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 132 of file CSGUniverse.h.

◆ CSGUniverseList

friend class CSGUniverseList
friend

Definition at line 129 of file CSGUniverse.h.

Member Data Documentation

◆ _cells

std::vector<std::reference_wrapper<const CSGCell> > CSG::CSGUniverse::_cells
protected

list of references to cells in universe

Definition at line 123 of file CSGUniverse.h.

Referenced by addCell(), getAllCells(), getCell(), hasCell(), removeAllCells(), and removeCell().

◆ _is_root

bool CSG::CSGUniverse::_is_root
protected

whether or not this universe is the root universe

Definition at line 126 of file CSGUniverse.h.

Referenced by isRoot().

◆ _name

std::string CSG::CSGUniverse::_name
protected

Name of universe.

Definition at line 120 of file CSGUniverse.h.

Referenced by getCell(), getName(), removeCell(), and setName().

◆ _transformations

std::vector<std::pair<TransformationType, std::tuple<Real, Real, Real> > > CSG::CSGTransformationHelper::_transformations
protectedinherited

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