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

CSGSurfaceList is a container for storing CSGSurface objects in the CSGBase object. More...

#include <CSGSurfaceList.h>

Protected Member Functions

 CSGSurfaceList ()
 Default constructor. More...
 
 CSGSurfaceList (const CSGSurfaceList &other_surface_list)
 Copy constructor. More...
 
virtual ~CSGSurfaceList ()=default
 Destructor. More...
 
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > & getSurfaceListMap ()
 Get non-const map of all names to surfaces in surface list. More...
 
const std::unordered_map< std::string, std::unique_ptr< CSGSurface > > & getSurfaceListMap () const
 Get const map of all names to surfaces in surface list. More...
 
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces () const
 Get list of references to all surfaces in surface list. More...
 
bool hasSurface (const std::string &name) const
 return whether surface with given name exists in surface list More...
 
CSGSurfacegetSurface (const std::string &name) const
 Get a surface by name. More...
 
CSGSurfaceaddSurface (std::unique_ptr< CSGSurface > surf)
 add a surface object to existing SurfaceList. More...
 
void renameSurface (const CSGSurface &surface, const std::string &name)
 rename the specified surface More...
 
bool operator== (const CSGSurfaceList &other) const
 Operator overload for checking if two CSGSurfaceList objects are equal. More...
 
bool operator!= (const CSGSurfaceList &other) const
 Operator overload for checking if two CSGSurfaceList objects are not equal. More...
 

Protected Attributes

std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
 Mapping of surface names to pointers of stored surface objects. More...
 

Friends

class CSGBase
 

Detailed Description

CSGSurfaceList is a container for storing CSGSurface objects in the CSGBase object.

Definition at line 20 of file CSGSurfaceList.h.

Constructor & Destructor Documentation

◆ CSGSurfaceList() [1/2]

CSG::CSGSurfaceList::CSGSurfaceList ( )
protected

Default constructor.

Definition at line 20 of file CSGSurfaceList.C.

20 {}

◆ CSGSurfaceList() [2/2]

CSG::CSGSurfaceList::CSGSurfaceList ( const CSGSurfaceList other_surface_list)
protected

Copy constructor.

Definition at line 22 of file CSGSurfaceList.C.

23 {
24  for (const auto & [name, surf] : other_surface_list.getSurfaceListMap())
25  _surfaces.emplace(name, surf->clone());
26 }
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ ~CSGSurfaceList()

virtual CSG::CSGSurfaceList::~CSGSurfaceList ( )
protectedvirtualdefault

Destructor.

Member Function Documentation

◆ addSurface()

CSGSurface & CSG::CSGSurfaceList::addSurface ( std::unique_ptr< CSGSurface surf)
protected

add a surface object to existing SurfaceList.

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

Parameters
surfCSGSurface to add
Returns
reference to CSGSurface

Definition at line 48 of file CSGSurfaceList.C.

Referenced by CSG::CSGBase::addSurface(), CSG::CSGBase::joinSurfaceList(), and renameSurface().

49 {
50  auto surf_name = surf->getName();
51  auto [it, inserted] = _surfaces.emplace(surf_name, std::move(surf));
52  if (!inserted)
53  mooseError("Surface with name " + surf_name + " already exists in geometry.");
54  return *it->second;
55 }
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< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ getAllSurfaces()

std::vector< std::reference_wrapper< const CSGSurface > > CSG::CSGSurfaceList::getAllSurfaces ( ) const
protected

Get list of references to all surfaces in surface list.

Returns
list of references to surfaces

Definition at line 39 of file CSGSurfaceList.C.

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

40 {
41  std::vector<std::reference_wrapper<const CSGSurface>> surfaces;
42  for (auto it = _surfaces.begin(); it != _surfaces.end(); ++it)
43  surfaces.push_back(*(it->second));
44  return surfaces;
45 }
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ getSurface()

CSGSurface & CSG::CSGSurfaceList::getSurface ( const std::string &  name) const
protected

Get a surface by name.

Parameters
namename of surface
Returns
reference to CSGSurface of the specified name

Definition at line 29 of file CSGSurfaceList.C.

Referenced by CSG::CSGBase::checkRegionSurfaces(), CSG::CSGBase::getSurface(), CSG::CSGBase::getSurfaceByName(), and operator==().

30 {
31  auto surf = _surfaces.find(name);
32  if (surf == _surfaces.end())
33  mooseError("No surface by name " + name + " exists in the geometry.");
34  else
35  return *(surf->second);
36 }
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< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ getSurfaceListMap() [1/2]

std::unordered_map<std::string, std::unique_ptr<CSGSurface> >& CSG::CSGSurfaceList::getSurfaceListMap ( )
inlineprotected

Get non-const map of all names to surfaces in surface list.

Returns
map of all names to CSGSurface pointers

Definition at line 43 of file CSGSurfaceList.h.

Referenced by CSGSurfaceList(), and CSG::CSGBase::joinSurfaceList().

44  {
45  return _surfaces;
46  }
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ getSurfaceListMap() [2/2]

const std::unordered_map<std::string, std::unique_ptr<CSGSurface> >& CSG::CSGSurfaceList::getSurfaceListMap ( ) const
inlineprotected

Get const map of all names to surfaces in surface list.

Returns
map of all names to CSGSurface pointers

Definition at line 53 of file CSGSurfaceList.h.

54  {
55  return _surfaces;
56  }
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ hasSurface()

bool CSG::CSGSurfaceList::hasSurface ( const std::string &  name) const
inlineprotected

return whether surface with given name exists in surface list

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

Definition at line 71 of file CSGSurfaceList.h.

Referenced by operator==().

72  {
73  return _surfaces.find(name) != _surfaces.end();
74  }
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.

◆ operator!=()

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

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

Definition at line 98 of file CSGSurfaceList.C.

99 {
100  return !(*this == other);
101 }

◆ operator==()

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

Operator overload for checking if two CSGSurfaceList objects are equal.

Definition at line 74 of file CSGSurfaceList.C.

75 {
76  const auto all_surfs = this->getAllSurfaces();
77  const auto other_surfs = other.getAllSurfaces();
78 
79  // Check that same number of surfaces are defined in both lists
80  if (all_surfs.size() != other_surfs.size())
81  return false;
82 
83  // Iterate through each CSGSurface in list and check equality of surface
84  // with other list
85  for (const auto & surf : all_surfs)
86  {
87  const auto & surf_name = surf.get().getName();
88  if (!other.hasSurface(surf_name))
89  return false;
90  const auto & other_surf = other.getSurface(surf_name);
91  if (surf.get() != other_surf)
92  return false;
93  }
94  return true;
95 }
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get list of references to all surfaces in surface list.

◆ renameSurface()

void CSG::CSGSurfaceList::renameSurface ( const CSGSurface surface,
const std::string &  name 
)
protected

rename the specified surface

Parameters
namenew name of surface

Definition at line 58 of file CSGSurfaceList.C.

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

59 {
60  // check that this surface passed in is actually in the same surface that is in the surface list
61  auto prev_name = surface.getName();
62  auto it = _surfaces.find(prev_name);
63  if (it == _surfaces.end() || it->second.get() != &surface)
64  mooseError("Surface " + prev_name + " cannot be renamed to " + name +
65  " as it does not exist in this CSGBase instance.");
66 
67  auto existing_surface = std::move(it->second);
68  existing_surface->setName(name);
69  _surfaces.erase(prev_name);
70  addSurface(std::move(existing_surface));
71 }
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< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.
CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a surface object to existing SurfaceList.

Friends And Related Function Documentation

◆ CSGBase

friend class CSGBase
friend

Definition at line 112 of file CSGSurfaceList.h.

Member Data Documentation

◆ _surfaces

std::unordered_map<std::string, std::unique_ptr<CSGSurface> > CSG::CSGSurfaceList::_surfaces
protected

Mapping of surface names to pointers of stored surface objects.

Definition at line 109 of file CSGSurfaceList.h.

Referenced by addSurface(), CSGSurfaceList(), getAllSurfaces(), getSurface(), getSurfaceListMap(), hasSurface(), and renameSurface().


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