https://mooseframework.inl.gov
CSGSurfaceList.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "CSGSurfaceList.h"
11 #include "CSGPlane.h"
12 #include "CSGSphere.h"
13 #include "CSGXCylinder.h"
14 #include "CSGYCylinder.h"
15 #include "CSGZCylinder.h"
16 
17 namespace CSG
18 {
19 
21 
23 {
24  for (const auto & [name, surf] : other_surface_list.getSurfaceListMap())
25  _surfaces.emplace(name, surf->clone());
26 }
27 
28 CSGSurface &
29 CSGSurfaceList::getSurface(const std::string & name) const
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 }
37 
38 std::vector<std::reference_wrapper<const CSGSurface>>
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 }
46 
47 CSGSurface &
48 CSGSurfaceList::addSurface(std::unique_ptr<CSGSurface> surf)
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 }
56 
57 void
58 CSGSurfaceList::renameSurface(const CSGSurface & surface, const std::string & name)
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 }
72 
73 bool
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 }
96 
97 bool
99 {
100  return !(*this == other);
101 }
102 
103 } // namespace CSG
bool operator!=(const CSGSurfaceList &other) const
Operator overload for checking if two CSGSurfaceList objects are not equal.
std::string name(const ElemQuality q)
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
bool hasSurface(const std::string &name) const
return whether surface with given name exists in surface list
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
CSGSurface & getSurface(const std::string &name) const
Get a surface by name.
std::vector< std::reference_wrapper< const CSGSurface > > getAllSurfaces() const
Get list of references to all surfaces in surface list.
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > _surfaces
Mapping of surface names to pointers of stored surface objects.
void renameSurface(const CSGSurface &surface, const std::string &name)
rename the specified surface
bool operator==(const CSGSurfaceList &other) const
Operator overload for checking if two CSGSurfaceList objects are equal.
std::unordered_map< std::string, std::unique_ptr< CSGSurface > > & getSurfaceListMap()
Get non-const map of all names to surfaces in surface list.
CSGSurfaceList()
Default constructor.
CSGSurfaceList is a container for storing CSGSurface objects in the CSGBase object.
CSGSurface creates an internal representation of a Constructive Solid Geometry (CSG) surface...
Definition: CSGSurface.h:26
CSGSurface & addSurface(std::unique_ptr< CSGSurface > surf)
add a surface object to existing SurfaceList.