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

CSGCellList creates a container for CSGCell objects to pass to CSGBase object. More...

#include <CSGCellList.h>

Protected Member Functions

 CSGCellList ()
 Default constructor. More...
 
virtual ~CSGCellList ()=default
 Destructor. More...
 
CSGCelladdMaterialCell (const std::string &name, const std::string &mat_name, const CSGRegion &region)
 Add a Material Cell object to cell list. More...
 
CSGCelladdVoidCell (const std::string &name, const CSGRegion &region)
 Add a Void Cell object cell list. More...
 
CSGCelladdUniverseCell (const std::string &name, const CSGUniverse &univ, const CSGRegion &region)
 Add a Universe Cell object to cell list. More...
 
CSGCelladdLatticeCell (const std::string &name, const CSGLattice &lattice, const CSGRegion &region)
 Add a Lattice Cell object to cell list. More...
 
bool hasCell (const std::string &name) const
 return whether cell with given name exists in cell list More...
 
std::unordered_map< std::string, std::unique_ptr< CSGCell > > & getCellListMap ()
 Get non-const map of all names to cells in cell list. More...
 
const std::unordered_map< std::string, std::unique_ptr< CSGCell > > & getCellListMap () const
 Get const map of all names to cells in cell list. More...
 
std::vector< std::reference_wrapper< const CSGCell > > getAllCells () const
 Get all the cells in CSGBase instance. More...
 
CSGCellgetCell (const std::string &name) const
 Get the CSGCell by name. More...
 
CSGCelladdCell (std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
 add a cell to the CellList. More...
 
void renameCell (const CSGCell &cell, const std::string &name)
 rename the specified cell More...
 
bool operator== (const CSGCellList &other) const
 Operator overload for checking if two CSGCellList objects are equal. More...
 
bool operator!= (const CSGCellList &other) const
 Operator overload for checking if two CSGCellList objects are not equal. More...
 

Protected Attributes

std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
 Mapping of cell names to pointers of stored cell objects. More...
 

Friends

class CSGBase
 

Detailed Description

CSGCellList creates a container for CSGCell objects to pass to CSGBase object.

Definition at line 20 of file CSGCellList.h.

Constructor & Destructor Documentation

◆ CSGCellList()

CSG::CSGCellList::CSGCellList ( )
protected

Default constructor.

Definition at line 15 of file CSGCellList.C.

15 {}

◆ ~CSGCellList()

virtual CSG::CSGCellList::~CSGCellList ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ addCell()

CSGCell & CSG::CSGCellList::addCell ( std::unique_ptr< CSGCell cell,
const bool  ignore_identical_cell = false 
)
protected

add a cell to the CellList.

Ownership of cell will be transferred to cell list object that calls this function

Parameters
cellcell to add to the CellList.
ignore_identical_cellskip adding cell if an identical cell exists in cell list
Returns
reference to CSGCell that was added to CellList

Definition at line 18 of file CSGCellList.C.

Referenced by addLatticeCell(), addMaterialCell(), addUniverseCell(), addVoidCell(), CSG::CSGBase::joinCellList(), and renameCell().

19 {
20  auto cell_name = cell->getName();
21  if (ignore_identical_cell)
22  // Check that cell already defined in _cells and if so, confirm it matches with input cell
23  if (auto it = _cells.find(cell_name); it != _cells.end())
24  {
25  if (*cell == *it->second)
26  return *it->second;
27  else
28  mooseError("Cell with name ",
29  cell_name,
30  " has the same name as an existing cell in CSGBase instance but cannot be "
31  "discarded as it is not an identical cell.");
32  }
33 
34  // Otherwise, add the cell to the cell list. At this point, we don't expect the cell
35  // to already be defined in the cell list
36  auto [it, inserted] = _cells.emplace(cell_name, std::move(cell));
37  if (!inserted)
38  mooseError("Cell with name " + cell_name + " already exists in geometry.");
39 
40  return *it->second;
41 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ addLatticeCell()

CSGCell & CSG::CSGCellList::addLatticeCell ( const std::string &  name,
const CSGLattice lattice,
const CSGRegion region 
)
protected

Add a Lattice Cell object to cell list.

Parameters
nameunique cell name
latticelattice
regioncell region
Returns
reference to CSGCell with lattice fill that was created and added to this CSGCellList

Definition at line 75 of file CSGCellList.C.

Referenced by CSG::CSGBase::addCellToList(), and CSG::CSGBase::createCell().

78 {
79  return addCell(std::make_unique<CSGCell>(name, &lattice, region));
80 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18

◆ addMaterialCell()

CSGCell & CSG::CSGCellList::addMaterialCell ( const std::string &  name,
const std::string &  mat_name,
const CSGRegion region 
)
protected

Add a Material Cell object to cell list.

Parameters
nameunique cell name
mat_namematerial name
regioncell region
Returns
reference to CSGCell with material fill that was created and added to this CSGCellList

Definition at line 59 of file CSGCellList.C.

Referenced by CSG::CSGBase::addCellToList(), and CSG::CSGBase::createCell().

62 {
63  return addCell(std::make_unique<CSGCell>(name, mat_name, region));
64 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18

◆ addUniverseCell()

CSGCell & CSG::CSGCellList::addUniverseCell ( const std::string &  name,
const CSGUniverse univ,
const CSGRegion region 
)
protected

Add a Universe Cell object to cell list.

Parameters
nameunique cell name
univuniverse
regioncell region
Returns
reference to CSGCell with universe fill that was created and added to this CSGCellList

Definition at line 67 of file CSGCellList.C.

Referenced by CSG::CSGBase::addCellToList(), and CSG::CSGBase::createCell().

70 {
71  return addCell(std::make_unique<CSGCell>(name, &univ, region));
72 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18

◆ addVoidCell()

CSGCell & CSG::CSGCellList::addVoidCell ( const std::string &  name,
const CSGRegion region 
)
protected

Add a Void Cell object cell list.

Parameters
nameunique cell name
regioncell region
Returns
reference to CSGCell with void fill that was created and added to this CSGCellList

Definition at line 53 of file CSGCellList.C.

Referenced by CSG::CSGBase::addCellToList(), and CSG::CSGBase::createCell().

54 {
55  return addCell(std::make_unique<CSGCell>(name, region));
56 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18

◆ getAllCells()

std::vector< std::reference_wrapper< const CSGCell > > CSG::CSGCellList::getAllCells ( ) const
protected

Get all the cells in CSGBase instance.

Returns
list of references to all CSGCell objects

Definition at line 83 of file CSGCellList.C.

Referenced by CSG::CSGBase::deleteLattice(), CSG::CSGBase::deleteSurface(), CSG::CSGBase::deleteUniverse(), CSG::CSGBase::getAllCells(), and operator==().

84 {
85  std::vector<std::reference_wrapper<const CSGCell>> cells;
86  for (auto it = _cells.begin(); it != _cells.end(); ++it)
87  cells.push_back(*(it->second));
88  return cells;
89 }
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ getCell()

CSGCell & CSG::CSGCellList::getCell ( const std::string &  name) const
protected

Get the CSGCell by name.

Parameters
name
Returns
reference to CSGCell of the specified name

Definition at line 44 of file CSGCellList.C.

Referenced by CSG::CSGBase::addCellToList(), CSG::CSGBase::addTransformation(), CSG::CSGBase::checkCellInBase(), CSG::CSGBase::CSGBase(), CSG::CSGBase::getCellByName(), operator==(), CSG::CSGBase::resetCellFill(), CSG::CSGBase::updateCellFill(), and CSG::CSGBase::updateCellRegion().

45 {
46  if (_cells.find(name) == _cells.end())
47  mooseError("No cell by name " + name + " exists in the geometry.");
48  else
49  return *(_cells.find(name)->second);
50 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ getCellListMap() [1/2]

std::unordered_map<std::string, std::unique_ptr<CSGCell> >& CSG::CSGCellList::getCellListMap ( )
inlineprotected

Get non-const map of all names to cells in cell list.

Returns
map of all names to CSGCell pointers

Definition at line 92 of file CSGCellList.h.

Referenced by CSG::CSGBase::CSGBase(), CSG::CSGBase::deleteCell(), CSG::CSGBase::joinCellList(), CSG::CSGBase::replaceLatticeRefsByName(), CSG::CSGBase::replaceSurfaceRefsByName(), CSG::CSGBase::replaceUniverseRefsByName(), and CSG::CSGBase::updateIncomingCSGReferences().

92 { return _cells; }
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ getCellListMap() [2/2]

const std::unordered_map<std::string, std::unique_ptr<CSGCell> >& CSG::CSGCellList::getCellListMap ( ) const
inlineprotected

Get const map of all names to cells in cell list.

Returns
map of all names to CSGCell pointers

Definition at line 99 of file CSGCellList.h.

100  {
101  return _cells;
102  }
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ hasCell()

bool CSG::CSGCellList::hasCell ( const std::string &  name) const
inlineprotected

return whether cell with given name exists in cell list

Parameters
namename of cell
Returns
true if cell name exists, false otherwise

Definition at line 85 of file CSGCellList.h.

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

85 { return _cells.find(name) != _cells.end(); }
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

◆ operator!=()

bool CSG::CSGCellList::operator!= ( const CSGCellList other) const
protected

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

Definition at line 132 of file CSGCellList.C.

133 {
134  return !(*this == other);
135 }

◆ operator==()

bool CSG::CSGCellList::operator== ( const CSGCellList other) const
protected

Operator overload for checking if two CSGCellList objects are equal.

Definition at line 108 of file CSGCellList.C.

109 {
110  const auto all_cells = this->getAllCells();
111  const auto other_cells = other.getAllCells();
112 
113  // Check that same number of cells are defined in both lists
114  if (all_cells.size() != other_cells.size())
115  return false;
116 
117  // Iterate through each CSGCell in list and check equality of each cell
118  // with other list
119  for (const auto & cell : all_cells)
120  {
121  const auto & cell_name = cell.get().getName();
122  if (!other.hasCell(cell_name))
123  return false;
124  const auto & other_cell = other.getCell(cell_name);
125  if (cell.get() != other_cell)
126  return false;
127  }
128  return true;
129 }
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition: CSGCellList.C:83

◆ renameCell()

void CSG::CSGCellList::renameCell ( const CSGCell cell,
const std::string &  name 
)
protected

rename the specified cell

Parameters
cellreference to CSGCell object that should be renamed
namenew name

Definition at line 92 of file CSGCellList.C.

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

93 {
94  // check that this cell passed in is actually in the same cell that is in the cell list
95  auto prev_name = cell.getName();
96  auto it = _cells.find(prev_name);
97  if (it == _cells.end() || it->second.get() != &cell)
98  mooseError("Cell " + prev_name + " cannot be renamed to " + name +
99  " as it does not exist in this CSGBase instance.");
100 
101  auto existing_cell = std::move(_cells.find(prev_name)->second);
102  existing_cell->setName(name);
103  _cells.erase(prev_name);
104  addCell(std::move(existing_cell));
105 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition: CSGCellList.C:18
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:144

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 147 of file CSGCellList.h.

Member Data Documentation

◆ _cells

std::unordered_map<std::string, std::unique_ptr<CSGCell> > CSG::CSGCellList::_cells
protected

Mapping of cell names to pointers of stored cell objects.

Definition at line 144 of file CSGCellList.h.

Referenced by addCell(), getAllCells(), getCell(), getCellListMap(), hasCell(), and renameCell().


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