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 "CSGCellList.h" 11 : 12 : namespace CSG 13 : { 14 : 15 95 : CSGCellList::CSGCellList() {} 16 : 17 : CSGCell & 18 126 : CSGCellList::addCell(std::unique_ptr<CSGCell> cell) 19 : { 20 126 : auto name = cell->getName(); 21 126 : auto [it, inserted] = _cells.emplace(name, std::move(cell)); 22 126 : if (!inserted) 23 12 : mooseError("Cell with name " + name + " already exists in geometry."); 24 244 : return *it->second; 25 126 : } 26 : 27 : CSGCell & 28 176 : CSGCellList::getCell(const std::string & name) const 29 : { 30 176 : if (_cells.find(name) == _cells.end()) 31 6 : mooseError("No cell by name " + name + " exists in the geometry."); 32 : else 33 174 : return *(_cells.find(name)->second); 34 : } 35 : 36 : CSGCell & 37 60 : CSGCellList::addVoidCell(const std::string & name, const CSGRegion & region) 38 : { 39 60 : return addCell(std::make_unique<CSGCell>(name, region)); 40 : } 41 : 42 : CSGCell & 43 35 : CSGCellList::addMaterialCell(const std::string & name, 44 : const std::string & mat_name, 45 : const CSGRegion & region) 46 : { 47 35 : return addCell(std::make_unique<CSGCell>(name, mat_name, region)); 48 : } 49 : 50 : CSGCell & 51 6 : CSGCellList::addUniverseCell(const std::string & name, 52 : const CSGUniverse & univ, 53 : const CSGRegion & region) 54 : { 55 6 : return addCell(std::make_unique<CSGCell>(name, &univ, region)); 56 : } 57 : 58 : std::vector<std::reference_wrapper<const CSGCell>> 59 35 : CSGCellList::getAllCells() const 60 : { 61 35 : std::vector<std::reference_wrapper<const CSGCell>> cells; 62 84 : for (auto it = _cells.begin(); it != _cells.end(); ++it) 63 49 : cells.push_back(*(it->second)); 64 35 : return cells; 65 0 : } 66 : 67 : void 68 15 : CSGCellList::renameCell(const CSGCell & cell, const std::string & name) 69 : { 70 : // check that this cell passed in is actually in the same cell that is in the cell list 71 15 : auto prev_name = cell.getName(); 72 15 : auto it = _cells.find(prev_name); 73 15 : if (it == _cells.end() || it->second.get() != &cell) 74 10 : mooseError("Cell " + prev_name + " cannot be renamed to " + name + 75 : " as it does not exist in this CSGBase instance."); 76 : 77 13 : auto existing_cell = std::move(_cells.find(prev_name)->second); 78 13 : existing_cell->setName(name); 79 13 : _cells.erase(prev_name); 80 15 : addCell(std::move(existing_cell)); 81 17 : } 82 : 83 : } // namespace CSG