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 
22 CSGSurface &
23 CSGSurfaceList::getSurface(const std::string & name) const
24 {
25  auto surf = _surfaces.find(name);
26  if (surf == _surfaces.end())
27  mooseError("No surface by name " + name + " exists in the geometry.");
28  else
29  return *(surf->second);
30 }
31 
32 std::vector<std::reference_wrapper<const CSGSurface>>
34 {
35  std::vector<std::reference_wrapper<const CSGSurface>> surfaces;
36  for (auto it = _surfaces.begin(); it != _surfaces.end(); ++it)
37  surfaces.push_back(*(it->second));
38  return surfaces;
39 }
40 
41 CSGSurface &
42 CSGSurfaceList::addSurface(std::unique_ptr<CSGSurface> surf)
43 {
44  auto surf_name = surf->getName();
45  auto [it, inserted] = _surfaces.emplace(surf_name, std::move(surf));
46  if (!inserted)
47  mooseError("Surface with name " + surf_name + " already exists in geometry.");
48  return *it->second;
49 }
50 
51 void
52 CSGSurfaceList::renameSurface(const CSGSurface & surface, const std::string & name)
53 {
54  // check that this surface passed in is actually in the same surface that is in the surface list
55  auto prev_name = surface.getName();
56  auto it = _surfaces.find(prev_name);
57  if (it == _surfaces.end() || it->second.get() != &surface)
58  mooseError("Surface " + prev_name + " cannot be renamed to " + name +
59  " as it does not exist in this CSGBase instance.");
60 
61  auto existing_surface = std::move(it->second);
62  existing_surface->setName(name);
63  _surfaces.erase(prev_name);
64  addSurface(std::move(existing_surface));
65 }
66 
67 } // namespace CSG
std::string name(const ElemQuality q)
const std::string & getName() const
Get the name of surface.
Definition: CSGSurface.h:95
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
CSGSurfaceList()
Default constructor.
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.