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 "CSGUniverse.h" 11 : #include "CSGUtils.h" 12 : #include "MooseError.h" 13 : 14 : namespace CSG 15 : { 16 : 17 572 : CSGUniverse::CSGUniverse(const std::string & name, bool is_root) : _name(name), _is_root(is_root) {} 18 : 19 20 : CSGUniverse::CSGUniverse(const std::string & name, std::vector<CSGCell *> & cells, bool is_root) 20 20 : : _name(name), _is_root(is_root) 21 : { 22 20 : CSGUtils::checkValidCSGName(name); 23 64 : for (auto cell : cells) 24 44 : addCell(*cell); 25 20 : } 26 : 27 : void 28 505 : CSGUniverse::addCell(const CSGCell & cell) 29 : { 30 505 : auto cell_name = cell.getName(); 31 505 : if (!hasCell(cell_name)) 32 503 : _cells.push_back(cell); 33 : else 34 12 : mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " + 35 : "Skipping cell insertion for cell with duplicate name."); 36 505 : } 37 : 38 : const CSGCell & 39 4 : CSGUniverse::getCell(const std::string & name) 40 : { 41 4 : if (!hasCell(name)) 42 10 : mooseError("Cell with name " + name + " does not exist in universe " + _name + "."); 43 2 : for (const CSGCell & cell : _cells) 44 2 : if (cell.getName() == name) 45 2 : return cell; 46 0 : mooseError("Should not reach here."); 47 : } 48 : 49 : bool 50 581 : CSGUniverse::hasCell(const std::string & name) const 51 : { 52 879 : for (const CSGCell & cell : _cells) 53 354 : if (cell.getName() == name) 54 56 : return true; 55 525 : return false; 56 : } 57 : 58 : void 59 14 : CSGUniverse::removeCell(const std::string & name) 60 : { 61 14 : if (!hasCell(name)) 62 12 : mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " + 63 8 : _name + "."); 64 20 : for (auto it = _cells.begin(); it != _cells.end(); ++it) 65 20 : if (it->get().getName() == name) 66 : { 67 12 : _cells.erase(it); 68 12 : break; 69 : } 70 12 : } 71 : 72 : bool 73 248 : CSGUniverse::operator==(const CSGUniverse & other) const 74 : { 75 458 : if ((this->getName() != other.getName()) || 76 210 : (this->getTransformations() != other.getTransformations())) 77 40 : return false; 78 208 : const auto & all_cells = getAllCells(); 79 208 : const auto & other_cells = other.getAllCells(); 80 208 : const bool num_cells_eq = all_cells.size() == other_cells.size(); 81 208 : if (num_cells_eq) 82 : { 83 248 : for (unsigned int i = 0; i < all_cells.size(); ++i) 84 42 : if (all_cells[i].get() != other_cells[i].get()) 85 2 : return false; 86 206 : return true; 87 : } 88 : else 89 0 : return false; 90 : } 91 : 92 : bool 93 88 : CSGUniverse::operator!=(const CSGUniverse & other) const 94 : { 95 88 : return !(*this == other); 96 : } 97 : 98 : } // namespace CSG