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

CSGEngUnitList is a non-owning index of CSGEngUnit objects stored in the type lists (CSGSurfaceList, CSGCellList, CSGUniverseList) of a CSGBase instance. More...

#include <CSGEngUnitList.h>

Protected Member Functions

 CSGEngUnitList ()
 Default constructor. More...
 
virtual ~CSGEngUnitList ()=default
 Destructor. More...
 
bool hasEngUnit (const std::string &name) const
 Return whether an engineering unit with the given name exists in this list. More...
 
std::vector< std::reference_wrapper< const CSGEngUnit > > getAllEngUnits () const
 Get all engineering units of all types in the list. More...
 
std::vector< std::reference_wrapper< const CSGSurfaceEngUnit > > getAllSurfaceEngUnits () const
 Get all surface-like engineering units. More...
 
std::vector< std::reference_wrapper< const CSGCellEngUnit > > getAllCellEngUnits () const
 Get all cell-like engineering units. More...
 
std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > getAllUniverseEngUnits () const
 Get all universe-like engineering units. More...
 
CSGEngUnitaddEngUnit (CSGEngUnit &unit)
 Register an engineering unit in this index. More...
 
CSGEngUnitgetEngUnit (const std::string &name) const
 Get an engineering unit by name. More...
 
void removeEngUnit (const CSGEngUnit &unit)
 Remove an engineering unit from this index by address. More...
 
bool operator== (const CSGEngUnitList &other) const
 Operator overload for checking if two CSGEngUnitList objects are equal. More...
 
bool operator!= (const CSGEngUnitList &other) const
 Operator overload for checking if two CSGEngUnitList objects are not equal. More...
 

Protected Attributes

std::vector< CSGEngUnit * > _eng_units
 Non-owning index: raw pointers into the type lists. More...
 

Friends

class CSGBase
 

Detailed Description

CSGEngUnitList is a non-owning index of CSGEngUnit objects stored in the type lists (CSGSurfaceList, CSGCellList, CSGUniverseList) of a CSGBase instance.

It provides lookup by name and typed queries without holding ownership of the objects.

A vector of raw pointers is used rather than a name-keyed map so that renames require no index update. The object's name is updated in-place by the owning type list, and the pointer in this vector automatically reflects the new name.

Definition at line 28 of file CSGEngUnitList.h.

Constructor & Destructor Documentation

◆ CSGEngUnitList()

CSG::CSGEngUnitList::CSGEngUnitList ( )
protected

Default constructor.

Definition at line 15 of file CSGEngUnitList.C.

15 {}

◆ ~CSGEngUnitList()

virtual CSG::CSGEngUnitList::~CSGEngUnitList ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ addEngUnit()

CSGEngUnit & CSG::CSGEngUnitList::addEngUnit ( CSGEngUnit unit)
protected

Register an engineering unit in this index.

The object must already be owned by the appropriate type list (CSGSurfaceList, CSGCellList, or CSGUniverseList).

Throws if an engineering unit with the given name already exists.

Parameters
unitreference to the engineering unit to register (non-owning)
Returns
reference to the registered engineering unit

Definition at line 18 of file CSGEngUnitList.C.

Referenced by CSG::CSGBase::addEngUnit(), and CSG::CSGBase::rebuildEngUnitList().

19 {
20  const auto & name = unit.getName();
21  if (hasEngUnit(name))
22  mooseError("An engineering unit with name '", name, "' already exists in geometry.");
23  _eng_units.push_back(&unit);
24  return unit;
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:311
bool hasEngUnit(const std::string &name) const
Return whether an engineering unit with the given name exists in this list.
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ getAllCellEngUnits()

std::vector< std::reference_wrapper< const CSGCellEngUnit > > CSG::CSGEngUnitList::getAllCellEngUnits ( ) const
protected

Get all cell-like engineering units.

Returns
list of const references to all CSGCellEngUnit objects

Definition at line 64 of file CSGEngUnitList.C.

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

65 {
66  std::vector<std::reference_wrapper<const CSGCellEngUnit>> result;
67  for (const auto * ptr : _eng_units)
68  if (const auto * cell = dynamic_cast<const CSGCellEngUnit *>(ptr))
69  result.push_back(*cell);
70  return result;
71 }
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ getAllEngUnits()

std::vector< std::reference_wrapper< const CSGEngUnit > > CSG::CSGEngUnitList::getAllEngUnits ( ) const
protected

Get all engineering units of all types in the list.

Returns
list of const references to all CSGEngUnit objects

Definition at line 45 of file CSGEngUnitList.C.

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

46 {
47  std::vector<std::reference_wrapper<const CSGEngUnit>> result;
48  for (const auto * ptr : _eng_units)
49  result.push_back(*ptr);
50  return result;
51 }
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ getAllSurfaceEngUnits()

std::vector< std::reference_wrapper< const CSGSurfaceEngUnit > > CSG::CSGEngUnitList::getAllSurfaceEngUnits ( ) const
protected

Get all surface-like engineering units.

Returns
list of const references to all CSGSurfaceEngUnit objects

Definition at line 54 of file CSGEngUnitList.C.

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

55 {
56  std::vector<std::reference_wrapper<const CSGSurfaceEngUnit>> result;
57  for (const auto * ptr : _eng_units)
58  if (const auto * surf = dynamic_cast<const CSGSurfaceEngUnit *>(ptr))
59  result.push_back(*surf);
60  return result;
61 }
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ getAllUniverseEngUnits()

std::vector< std::reference_wrapper< const CSGUniverseEngUnit > > CSG::CSGEngUnitList::getAllUniverseEngUnits ( ) const
protected

Get all universe-like engineering units.

Returns
list of const references to all CSGUniverseEngUnit objects

Definition at line 74 of file CSGEngUnitList.C.

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

75 {
76  std::vector<std::reference_wrapper<const CSGUniverseEngUnit>> result;
77  for (const auto * ptr : _eng_units)
78  if (const auto * univ = dynamic_cast<const CSGUniverseEngUnit *>(ptr))
79  result.push_back(*univ);
80  return result;
81 }
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ getEngUnit()

CSGEngUnit & CSG::CSGEngUnitList::getEngUnit ( const std::string &  name) const
protected

Get an engineering unit by name.

Parameters
namename of the engineering unit
Returns
reference to the CSGEngUnit of the specified name

Definition at line 28 of file CSGEngUnitList.C.

Referenced by CSG::CSGBase::addTransformation(), CSG::CSGBase::checkEngUnitInBase(), CSG::CSGBase::getEngUnitByName(), and operator==().

29 {
30  for (auto * ptr : _eng_units)
31  if (ptr->getName() == name)
32  return *ptr;
33  mooseError("Engineering unit with name '", name, "' does not exist in this CSGBase.");
34 }
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:311
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ hasEngUnit()

bool CSG::CSGEngUnitList::hasEngUnit ( const std::string &  name) const
inlineprotected

Return whether an engineering unit with the given name exists in this list.

Parameters
namename of the engineering unit
Returns
true if an engineering unit with the given name exists, false otherwise

Definition at line 47 of file CSGEngUnitList.h.

Referenced by addEngUnit(), CSG::CSGBase::addEngUnit(), CSG::CSGBase::hasEngUnit(), CSG::CSGBase::renameCell(), CSG::CSGBase::renameSurface(), and CSG::CSGBase::renameUniverse().

48  {
49  for (const auto * ptr : _eng_units)
50  if (ptr->getName() == name)
51  return true;
52  return false;
53  }
std::string name(const ElemQuality q)
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

◆ operator!=()

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

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

Definition at line 103 of file CSGEngUnitList.C.

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

◆ operator==()

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

Operator overload for checking if two CSGEngUnitList objects are equal.

Definition at line 84 of file CSGEngUnitList.C.

85 {
86  const auto all_units = this->getAllEngUnits();
87  const auto other_units = other.getAllEngUnits();
88 
89  if (all_units.size() != other_units.size())
90  return false;
91 
92  for (const auto & unit : all_units)
93  {
94  const std::string & unit_name = unit.get().getName();
95  const auto & other_unit = other.getEngUnit(unit_name);
96  if (unit.get() != other_unit)
97  return false;
98  }
99  return true;
100 }
std::vector< std::reference_wrapper< const CSGEngUnit > > getAllEngUnits() const
Get all engineering units of all types in the list.

◆ removeEngUnit()

void CSG::CSGEngUnitList::removeEngUnit ( const CSGEngUnit unit)
protected

Remove an engineering unit from this index by address.

Called by CSGBase when a unit is deleted or expanded. Does not affect ownership because the object is destroyed by the owning type list.

Parameters
unitreference to the engineering unit to remove

Definition at line 37 of file CSGEngUnitList.C.

Referenced by CSG::CSGBase::deleteCell(), CSG::CSGBase::deleteSurface(), and CSG::CSGBase::deleteUniverse().

38 {
39  auto it = std::find(_eng_units.begin(), _eng_units.end(), &unit);
40  if (it != _eng_units.end())
41  _eng_units.erase(it);
42 }
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
std::vector< CSGEngUnit * > _eng_units
Non-owning index: raw pointers into the type lists.

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 123 of file CSGEngUnitList.h.

Member Data Documentation

◆ _eng_units

std::vector<CSGEngUnit *> CSG::CSGEngUnitList::_eng_units
protected

Non-owning index: raw pointers into the type lists.

Rename does not require updating this vector because the pointed-to object's name is updated in-place by the type list.

Definition at line 120 of file CSGEngUnitList.h.

Referenced by addEngUnit(), getAllCellEngUnits(), getAllEngUnits(), getAllSurfaceEngUnits(), getAllUniverseEngUnits(), getEngUnit(), hasEngUnit(), and removeEngUnit().


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