https://mooseframework.inl.gov
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>

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...
 

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)
 
 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)
 

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...
 

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 26 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 15 of file CSGUniverse.C.

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

◆ 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 17 of file CSGUniverse.C.

18  : _name(name), _is_root(is_root)
19 {
20  for (auto cell : cells)
21  addCell(*cell);
22 }
std::string _name
Name of universe.
Definition: CSGUniverse.h:119
bool _is_root
whether or not this universe is the root universe
Definition: CSGUniverse.h:125
void addCell(const CSGCell &cell)
add cell to universe
Definition: CSGUniverse.C:25

◆ ~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 25 of file CSGUniverse.C.

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

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

◆ FRIEND_TEST() [1/5]

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

Friends for unit testing.

◆ FRIEND_TEST() [2/5]

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

◆ FRIEND_TEST() [3/5]

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

◆ FRIEND_TEST() [4/5]

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

◆ FRIEND_TEST() [5/5]

CSG::CSGUniverse::FRIEND_TEST ( CSGUniverseTest  ,
testSetName   
)
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 72 of file CSGUniverse.h.

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

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

◆ 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 36 of file CSGUniverse.C.

37 {
38  if (!hasCell(name))
39  mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
40  for (const CSGCell & cell : _cells)
41  if (cell.getName() == name)
42  return cell;
43  mooseError("Should not reach here.");
44 }
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:323
std::string _name
Name of universe.
Definition: CSGUniverse.h:119
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:47
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:122

◆ getName()

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

Get the name of the universe.

Returns
name of universe

Definition at line 79 of file CSGUniverse.h.

Referenced by addCell(), CSG::CSGBase::addCellToUniverse(), CSG::CSGBase::checkUniverseInBase(), CSG::CSGBase::getLinkedUniverses(), operator==(), CSG::CSGBase::removeCellFromUniverse(), and CSG::CSGUniverseList::renameUniverse().

79 { return _name; }
std::string _name
Name of universe.
Definition: CSGUniverse.h:119

◆ 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 47 of file CSGUniverse.C.

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

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

◆ isRoot()

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

return true if the universe is the root universe

Returns
true / false

Definition at line 86 of file CSGUniverse.h.

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

◆ 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 70 of file CSGUniverse.C.

71 {
72  const bool names_eq = this->getName() == other.getName();
73  if (names_eq)
74  {
75  const auto & all_cells = getAllCells();
76  const auto & other_cells = other.getAllCells();
77  const bool num_cells_eq = all_cells.size() == other_cells.size();
78  if (num_cells_eq)
79  {
80  for (unsigned int i = 0; i < all_cells.size(); ++i)
81  if (all_cells[i].get() != other_cells[i].get())
82  return false;
83  return true;
84  }
85  else
86  return false;
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:72
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:79

◆ removeAllCells()

void CSG::CSGUniverse::removeAllCells ( )
inlineprotected

remove all cells from the universe

Definition at line 112 of file CSGUniverse.h.

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

◆ 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 56 of file CSGUniverse.C.

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

57 {
58  if (!hasCell(name))
59  mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
60  _name + ".");
61  for (auto it = _cells.begin(); it != _cells.end(); ++it)
62  if (it->get().getName() == name)
63  {
64  _cells.erase(it);
65  break;
66  }
67 }
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:323
std::string _name
Name of universe.
Definition: CSGUniverse.h:119
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:47
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:122

◆ setName()

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

Definition at line 116 of file CSGUniverse.h.

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

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 131 of file CSGUniverse.h.

◆ CSGUniverseList

friend class CSGUniverseList
friend

Definition at line 128 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 122 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 125 of file CSGUniverse.h.

Referenced by isRoot().

◆ _name

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

Name of universe.

Definition at line 119 of file CSGUniverse.h.

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


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