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...
 
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)
 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)
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.
Returns
reference to CSGCell that was added to CellList

Definition at line 18 of file CSGCellList.C.

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

19 {
20  auto name = cell->getName();
21  auto [it, inserted] = _cells.emplace(name, std::move(cell));
22  if (!inserted)
23  mooseError("Cell with name " + name + " already exists in geometry.");
24  return *it->second;
25 }
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::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:131

◆ 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 43 of file CSGCellList.C.

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

46 {
47  return addCell(std::make_unique<CSGCell>(name, mat_name, region));
48 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell)
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 51 of file CSGCellList.C.

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

54 {
55  return addCell(std::make_unique<CSGCell>(name, &univ, region));
56 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell)
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 37 of file CSGCellList.C.

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

38 {
39  return addCell(std::make_unique<CSGCell>(name, region));
40 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell)
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 59 of file CSGCellList.C.

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

60 {
61  std::vector<std::reference_wrapper<const CSGCell>> cells;
62  for (auto it = _cells.begin(); it != _cells.end(); ++it)
63  cells.push_back(*(it->second));
64  return cells;
65 }
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:131

◆ 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 28 of file CSGCellList.C.

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

29 {
30  if (_cells.find(name) == _cells.end())
31  mooseError("No cell by name " + name + " exists in the geometry.");
32  else
33  return *(_cells.find(name)->second);
34 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:131

◆ 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 80 of file CSGCellList.h.

Referenced by CSG::CSGBase::CSGBase(), and CSG::CSGBase::joinCellList().

80 { 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:131

◆ 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 87 of file CSGCellList.h.

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

◆ 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 73 of file CSGCellList.h.

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

73 { 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:131

◆ operator!=()

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

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

Definition at line 108 of file CSGCellList.C.

109 {
110  return !(*this == other);
111 }

◆ operator==()

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

Operator overload for checking if two CSGCellList objects are equal.

Definition at line 84 of file CSGCellList.C.

85 {
86  const auto all_cells = this->getAllCells();
87  const auto other_cells = other.getAllCells();
88 
89  // Check that same number of cells are defined in both lists
90  if (all_cells.size() != other_cells.size())
91  return false;
92 
93  // Iterate through each CSGCell in list and check equality of each cell
94  // with other list
95  for (const auto & cell : all_cells)
96  {
97  const auto & cell_name = cell.get().getName();
98  if (!other.hasCell(cell_name))
99  return false;
100  const auto & other_cell = other.getCell(cell_name);
101  if (cell.get() != other_cell)
102  return false;
103  }
104  return true;
105 }
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition: CSGCellList.C:59

◆ 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 68 of file CSGCellList.C.

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

69 {
70  // check that this cell passed in is actually in the same cell that is in the cell list
71  auto prev_name = cell.getName();
72  auto it = _cells.find(prev_name);
73  if (it == _cells.end() || it->second.get() != &cell)
74  mooseError("Cell " + prev_name + " cannot be renamed to " + name +
75  " as it does not exist in this CSGBase instance.");
76 
77  auto existing_cell = std::move(_cells.find(prev_name)->second);
78  existing_cell->setName(name);
79  _cells.erase(prev_name);
80  addCell(std::move(existing_cell));
81 }
CSGCell & addCell(std::unique_ptr< CSGCell > cell)
add a cell to the CellList.
Definition: CSGCellList.C:18
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:131

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 134 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 131 of file CSGCellList.h.

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


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