Line data Source code
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 : 20 95 : CSGSurfaceList::CSGSurfaceList() {} 21 : 22 : CSGSurface & 23 266 : CSGSurfaceList::getSurface(const std::string & name) const 24 : { 25 266 : auto surf = _surfaces.find(name); 26 266 : if (surf == _surfaces.end()) 27 6 : mooseError("No surface by name " + name + " exists in the geometry."); 28 : else 29 528 : return *(surf->second); 30 : } 31 : 32 : std::vector<std::reference_wrapper<const CSGSurface>> 33 35 : CSGSurfaceList::getAllSurfaces() const 34 : { 35 35 : std::vector<std::reference_wrapper<const CSGSurface>> surfaces; 36 177 : for (auto it = _surfaces.begin(); it != _surfaces.end(); ++it) 37 142 : surfaces.push_back(*(it->second)); 38 35 : return surfaces; 39 0 : } 40 : 41 : CSGSurface & 42 226 : CSGSurfaceList::addSurface(std::unique_ptr<CSGSurface> surf) 43 : { 44 226 : auto surf_name = surf->getName(); 45 226 : auto [it, inserted] = _surfaces.emplace(surf_name, std::move(surf)); 46 226 : if (!inserted) 47 12 : mooseError("Surface with name " + surf_name + " already exists in geometry."); 48 444 : return *it->second; 49 226 : } 50 : 51 : void 52 24 : 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 24 : auto prev_name = surface.getName(); 56 24 : auto it = _surfaces.find(prev_name); 57 24 : if (it == _surfaces.end() || it->second.get() != &surface) 58 10 : mooseError("Surface " + prev_name + " cannot be renamed to " + name + 59 : " as it does not exist in this CSGBase instance."); 60 : 61 22 : auto existing_surface = std::move(it->second); 62 22 : existing_surface->setName(name); 63 22 : _surfaces.erase(prev_name); 64 24 : addSurface(std::move(existing_surface)); 65 26 : } 66 : 67 : } // namespace CSG