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

CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase. More...

#include <CSGLatticeList.h>

Protected Member Functions

 CSGLatticeList ()
 Default constructor. More...
 
virtual ~CSGLatticeList ()=default
 Destructor. More...
 
CSGLatticeaddLattice (std::unique_ptr< CSGLattice > lattice, const bool ignore_identical_lattice=false)
 add an existing lattice to list. More...
 
bool hasLattice (const std::string &name) const
 return whether lattice with given name exists in lattice list More...
 
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > & getLatticeListMap ()
 Get map of all names to lattices in lattice list. More...
 
const std::unordered_map< std::string, std::unique_ptr< CSGLattice > > & getLatticeListMap () const
 Get const map of all names to lattices in lattice list. More...
 
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices () const
 Get all the lattices in CSGBase instance. More...
 
CSGLatticegetLattice (const std::string &name) const
 Get a Lattice from the list by its name. More...
 
void renameLattice (const CSGLattice &lattice, const std::string &name)
 rename the specified lattice More...
 
bool operator== (const CSGLatticeList &other) const
 Operator overload for checking if two CSGLatticeList objects are equal. More...
 
bool operator!= (const CSGLatticeList &other) const
 Operator overload for checking if two CSGLatticeList objects are not equal. More...
 

Protected Attributes

std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
 Mapping of lattice names to pointers of stored lattice objects. More...
 

Friends

class CSGBase
 

Detailed Description

CSGLatticeList creates a container for CSGLattice objects to pass to CSGBase.

Definition at line 20 of file CSGLatticeList.h.

Constructor & Destructor Documentation

◆ CSGLatticeList()

CSG::CSGLatticeList::CSGLatticeList ( )
protected

Default constructor.

Definition at line 15 of file CSGLatticeList.C.

15 {}

◆ ~CSGLatticeList()

virtual CSG::CSGLatticeList::~CSGLatticeList ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ addLattice()

CSGLattice & CSG::CSGLatticeList::addLattice ( std::unique_ptr< CSGLattice lattice,
const bool  ignore_identical_lattice = false 
)
protected

add an existing lattice to list.

Ownership of lattice will be transferred to CSGLatticeList object that calls this function

Parameters
latticepointer to lattice to add
ignore_identical_latticeskip adding lattice if an identical lattice exists in lattice list
Returns
reference to CSGLattice that is passed in

Definition at line 37 of file CSGLatticeList.C.

Referenced by CSG::CSGBase::addLattice(), CSG::CSGBase::joinLatticeList(), and renameLattice().

38 {
39  auto lattice_name = lattice->getName();
40  if (ignore_identical_lattice)
41  // Check that lattice already defined in _lattice and if so, confirm it matches with input lat
42  if (auto it = _lattices.find(lattice_name); it != _lattices.end())
43  {
44  if (*lattice == *it->second)
45  return *it->second;
46  else
47  mooseError("Lattice with name ",
48  lattice_name,
49  " has the same name as an existing lattice in CSGBase instance but cannot be "
50  "discarded as it is not an identical lattice.");
51  }
52 
53  // Otherwise, add the lattice to the lattice list. At this point, we don't expect the lattice
54  // to already be defined in the lattice list
55  auto [it, inserted] = _lattices.emplace(lattice_name, std::move(lattice));
56  if (!inserted)
57  mooseError("Lattice with name " + lattice_name + " already exists in geometry.");
58  return *it->second;
59 }
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< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ getAllLattices()

std::vector< std::reference_wrapper< const CSGLattice > > CSG::CSGLatticeList::getAllLattices ( ) const
protected

Get all the lattices in CSGBase instance.

Returns
list of references to all CSGLattice objects

Definition at line 28 of file CSGLatticeList.C.

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

29 {
30  std::vector<std::reference_wrapper<const CSGLattice>> lattices;
31  for (auto it = _lattices.begin(); it != _lattices.end(); ++it)
32  lattices.push_back(*(it->second.get()));
33  return lattices;
34 }
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ getLattice()

CSGLattice & CSG::CSGLatticeList::getLattice ( const std::string &  name) const
protected

Get a Lattice from the list by its name.

Parameters
namename of lattice
Returns
reference to CSGLattice of the specified name

Definition at line 18 of file CSGLatticeList.C.

Referenced by CSG::CSGBase::addLatticeToList(), CSG::CSGBase::addTransformation(), CSG::CSGBase::checkLatticeInBase(), CSG::CSGBase::getLatticeByName(), operator==(), CSG::CSGBase::resetLatticeOuter(), CSG::CSGBase::setLatticeOuter(), CSG::CSGBase::setLatticeUniverses(), and CSG::CSGBase::setUniverseAtLatticeIndex().

19 {
20  auto lat = _lattices.find(name);
21  if (lat == _lattices.end())
22  mooseError("No lattice by name " + name + " exists in the geometry.");
23  else
24  return *(lat->second);
25 }
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< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ getLatticeListMap() [1/2]

std::unordered_map<std::string, std::unique_ptr<CSGLattice> >& CSG::CSGLatticeList::getLatticeListMap ( )
inlineprotected

Get map of all names to lattices in lattice list.

Returns
map of all names to CSGLattice pointers

Definition at line 61 of file CSGLatticeList.h.

Referenced by CSG::CSGBase::CSGBase(), CSG::CSGBase::deleteLattice(), CSG::CSGBase::joinLatticeList(), CSG::CSGBase::replaceUniverseRefsByName(), and CSG::CSGBase::updateIncomingCSGReferences().

62  {
63  return _lattices;
64  }
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ getLatticeListMap() [2/2]

const std::unordered_map<std::string, std::unique_ptr<CSGLattice> >& CSG::CSGLatticeList::getLatticeListMap ( ) const
inlineprotected

Get const map of all names to lattices in lattice list.

Returns
map of all names to CSGLattice pointers

Definition at line 71 of file CSGLatticeList.h.

72  {
73  return _lattices;
74  }
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ hasLattice()

bool CSG::CSGLatticeList::hasLattice ( const std::string &  name) const
inlineprotected

return whether lattice with given name exists in lattice list

Parameters
namename of the lattice
Returns
true if lattice name exists, otherwise false

Definition at line 51 of file CSGLatticeList.h.

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

52  {
53  return _lattices.find(name) != _lattices.end();
54  }
std::unordered_map< std::string, std::unique_ptr< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

◆ operator!=()

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

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

Definition at line 102 of file CSGLatticeList.C.

103 {
104  return !(*this == other);
105 }

◆ operator==()

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

Operator overload for checking if two CSGLatticeList objects are equal.

Definition at line 78 of file CSGLatticeList.C.

79 {
80  const auto all_lats = this->getAllLattices();
81  const auto other_lats = other.getAllLattices();
82 
83  // Check that same number of lattices are defined in both lists
84  if (all_lats.size() != other_lats.size())
85  return false;
86 
87  // Iterate through each CSGLattices in list and check equality of each cell
88  // with other list
89  for (const auto & lat : all_lats)
90  {
91  const auto & lat_name = lat.get().getName();
92  if (!other.hasLattice(lat_name))
93  return false;
94  const auto & other_lat = other.getLattice(lat_name);
95  if (lat.get() != other_lat)
96  return false;
97  }
98  return true;
99 }
std::vector< std::reference_wrapper< const CSGLattice > > getAllLattices() const
Get all the lattices in CSGBase instance.

◆ renameLattice()

void CSG::CSGLatticeList::renameLattice ( const CSGLattice lattice,
const std::string &  name 
)
protected

rename the specified lattice

Parameters
latticereference to lattice whose name should be renamed
namenew name

Definition at line 62 of file CSGLatticeList.C.

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

63 {
64  // check that this lattice passed in is actually in the same lattice that is in the lattice list
65  auto prev_name = lattice.getName();
66  auto it = _lattices.find(prev_name);
67  if (it == _lattices.end() || it->second.get() != &lattice)
68  mooseError("Lattice " + prev_name + " cannot be renamed to " + name +
69  " as it does not exist in this CSGBase instance.");
70 
71  auto existing_lat = std::move(it->second);
72  existing_lat->setName(name);
73  _lattices.erase(prev_name);
74  addLattice(std::move(existing_lat));
75 }
CSGLattice & addLattice(std::unique_ptr< CSGLattice > lattice, const bool ignore_identical_lattice=false)
add an existing lattice to list.
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< CSGLattice > > _lattices
Mapping of lattice names to pointers of stored lattice objects.

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 109 of file CSGLatticeList.h.

Member Data Documentation

◆ _lattices

std::unordered_map<std::string, std::unique_ptr<CSGLattice> > CSG::CSGLatticeList::_lattices
protected

Mapping of lattice names to pointers of stored lattice objects.

Definition at line 106 of file CSGLatticeList.h.

Referenced by addLattice(), getAllLattices(), getLattice(), getLatticeListMap(), hasLattice(), and renameLattice().


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