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

CSGUniverseList creates a container for CSGUniverse objects to pass to CSGBase. More...

#include <CSGUniverseList.h>

Protected Member Functions

 CSGUniverseList ()
 Default constructor. More...
 
virtual ~CSGUniverseList ()=default
 Destructor. More...
 
CSGUniverseaddUniverse (const std::string &name)
 create an empty universe More...
 
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > & getUniverseListMap ()
 Get map of all names to universes in universe list. More...
 
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses () const
 Get all the universes in CSGBase instance. More...
 
CSGUniversegetUniverse (const std::string &name) const
 Get a Universe from the list by its name. More...
 
const CSGUniversegetRoot () const
 Get the root universe. More...
 
CSGUniverseaddUniverse (std::unique_ptr< CSGUniverse > universe)
 add an existing universe to list. More...
 
void renameUniverse (const CSGUniverse &universe, const std::string &name)
 rename the specified universe More...
 

Protected Attributes

std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
 Mapping of universe names to pointers of stored universe objects. More...
 
const CSGUniverse_root_universe
 root universe for the CSGBase instance More...
 

Friends

class CSGBase
 

Detailed Description

CSGUniverseList creates a container for CSGUniverse objects to pass to CSGBase.

Definition at line 20 of file CSGUniverseList.h.

Constructor & Destructor Documentation

◆ CSGUniverseList()

CSG::CSGUniverseList::CSGUniverseList ( )
protected

Default constructor.

Definition at line 15 of file CSGUniverseList.C.

16 {
17  // create root universe by default when CSG object is initialized
18  std::string root_name = "ROOT_UNIVERSE";
19  auto root_universe = std::make_unique<CSGUniverse>(root_name, /* is_root = */ true);
20  _root_universe = root_universe.get();
21  _universes.insert(std::make_pair(root_name, std::move(root_universe)));
22 }
const CSGUniverse * _root_universe
root universe for the CSGBase instance
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

◆ ~CSGUniverseList()

virtual CSG::CSGUniverseList::~CSGUniverseList ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ addUniverse() [1/2]

CSGUniverse & CSG::CSGUniverseList::addUniverse ( const std::string &  name)
protected

create an empty universe

Parameters
nameunique name of universe
Returns
reference to empty universe that is created

Definition at line 44 of file CSGUniverseList.C.

Referenced by CSG::CSGBase::createUniverse(), CSG::CSGBase::joinUniverseList(), and renameUniverse().

45 {
46  return addUniverse(std::make_unique<CSGUniverse>(name));
47 }
CSGUniverse & addUniverse(const std::string &name)
create an empty universe

◆ addUniverse() [2/2]

CSGUniverse & CSG::CSGUniverseList::addUniverse ( std::unique_ptr< CSGUniverse universe)
protected

add an existing universe to list.

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

Parameters
universepointer to universe to add
Returns
reference to universe that is passed in

Definition at line 50 of file CSGUniverseList.C.

51 {
52  auto name = universe->getName();
53  auto [it, inserted] = _universes.emplace(name, std::move(universe));
54  if (!inserted)
55  mooseError("Universe with name " + name + " already exists in geometry.");
56  return *it->second;
57 }
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< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

◆ getAllUniverses()

std::vector< std::reference_wrapper< const CSGUniverse > > CSG::CSGUniverseList::getAllUniverses ( ) const
protected

Get all the universes in CSGBase instance.

Returns
list of references to all CSGUniverse objects

Definition at line 35 of file CSGUniverseList.C.

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

36 {
37  std::vector<std::reference_wrapper<const CSGUniverse>> univs;
38  for (auto it = _universes.begin(); it != _universes.end(); ++it)
39  univs.push_back(*(it->second.get()));
40  return univs;
41 }
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

◆ getRoot()

const CSGUniverse& CSG::CSGUniverseList::getRoot ( ) const
inlineprotected

Get the root universe.

Returns
reference to the root universe

Definition at line 71 of file CSGUniverseList.h.

Referenced by CSG::CSGBase::getRootUniverse(), and CSG::CSGBase::renameRootUniverse().

71 { return *_root_universe; };
const CSGUniverse * _root_universe
root universe for the CSGBase instance

◆ getUniverse()

CSGUniverse & CSG::CSGUniverseList::getUniverse ( const std::string &  name) const
protected

Get a Universe from the list by its name.

Parameters
namename of universe
Returns
reference to CSGUniverse of the specified name

Definition at line 25 of file CSGUniverseList.C.

Referenced by CSG::CSGBase::addCellToUniverse(), CSG::CSGBase::checkUniverseInBase(), CSG::CSGBase::getUniverseByName(), and CSG::CSGBase::removeCellFromUniverse().

26 {
27  auto univ = _universes.find(name);
28  if (univ == _universes.end())
29  mooseError("No universe by name " + name + " exists in the geometry.");
30  else
31  return *(univ->second);
32 }
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< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

◆ getUniverseListMap()

std::unordered_map<std::string, std::unique_ptr<CSGUniverse> >& CSG::CSGUniverseList::getUniverseListMap ( )
inlineprotected

Get map of all names to universes in universe list.

Returns
map of all names to CSGUniverse pointers

Definition at line 46 of file CSGUniverseList.h.

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

47  {
48  return _universes;
49  }
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

◆ renameUniverse()

void CSG::CSGUniverseList::renameUniverse ( const CSGUniverse universe,
const std::string &  name 
)
protected

rename the specified universe

Parameters
universereference to universe whose name should be renamed
namenew name

Definition at line 60 of file CSGUniverseList.C.

Referenced by CSG::CSGBase::renameRootUniverse(), and CSG::CSGBase::renameUniverse().

61 {
62  // check that this universe passed in is actually in the same universe that is in the universe
63  // list
64  auto prev_name = universe.getName();
65  auto it = _universes.find(prev_name);
66  if (it == _universes.end() || it->second.get() != &universe)
67  mooseError("Universe " + prev_name + " cannot be renamed to " + name +
68  " as it does not exist in this CSGBase instance.");
69 
70  auto existing_univ = std::move(it->second);
71  existing_univ->setName(name);
72  _universes.erase(prev_name);
73  addUniverse(std::move(existing_univ));
74 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 97 of file CSGUniverseList.h.

Member Data Documentation

◆ _root_universe

const CSGUniverse* CSG::CSGUniverseList::_root_universe
protected

root universe for the CSGBase instance

Definition at line 94 of file CSGUniverseList.h.

Referenced by CSGUniverseList(), and getRoot().

◆ _universes

std::unordered_map<std::string, std::unique_ptr<CSGUniverse> > CSG::CSGUniverseList::_universes
protected

Mapping of universe names to pointers of stored universe objects.

Definition at line 91 of file CSGUniverseList.h.

Referenced by addUniverse(), CSGUniverseList(), getAllUniverses(), getUniverse(), getUniverseListMap(), and renameUniverse().


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