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 "CSGLatticeList.h" 11 : 12 : namespace CSG 13 : { 14 : 15 316 : CSGLatticeList::CSGLatticeList() {} 16 : 17 : CSGLattice & 18 180 : CSGLatticeList::getLattice(const std::string & name) const 19 : { 20 180 : auto lat = _lattices.find(name); 21 180 : if (lat == _lattices.end()) 22 6 : mooseError("No lattice by name " + name + " exists in the geometry."); 23 : else 24 356 : return *(lat->second); 25 : } 26 : 27 : std::vector<std::reference_wrapper<const CSGLattice>> 28 126 : CSGLatticeList::getAllLattices() const 29 : { 30 126 : std::vector<std::reference_wrapper<const CSGLattice>> lattices; 31 216 : for (auto it = _lattices.begin(); it != _lattices.end(); ++it) 32 90 : lattices.push_back(*(it->second.get())); 33 126 : return lattices; 34 0 : } 35 : 36 : CSGLattice & 37 200 : CSGLatticeList::addLattice(std::unique_ptr<CSGLattice> lattice, const bool ignore_identical_lattice) 38 : { 39 200 : auto lattice_name = lattice->getName(); 40 200 : if (ignore_identical_lattice) 41 : // Check that lattice already defined in _lattice and if so, confirm it matches with input lat 42 6 : if (auto it = _lattices.find(lattice_name); it != _lattices.end()) 43 : { 44 6 : if (*lattice == *it->second) 45 2 : return *it->second; 46 : else 47 4 : mooseError("Lattice with name ", 48 : lattice_name, 49 : " has the same name as an existing lattice in CSGBase instance but cannot be " 50 : "discarded as it is not an identical lattice."); 51 : } 52 : 53 : // Otherwise, add the lattice to the lattice list. At this point, we don't expect the lattice 54 : // to already be defined in the lattice list 55 194 : auto [it, inserted] = _lattices.emplace(lattice_name, std::move(lattice)); 56 194 : if (!inserted) 57 6 : mooseError("Lattice with name " + lattice_name + " already exists in geometry."); 58 192 : return *it->second; 59 200 : } 60 : 61 : void 62 22 : CSGLatticeList::renameLattice(const CSGLattice & lattice, const std::string & name) 63 : { 64 : // check that this lattice passed in is actually in the same lattice that is in the lattice list 65 22 : auto prev_name = lattice.getName(); 66 22 : auto it = _lattices.find(prev_name); 67 22 : if (it == _lattices.end() || it->second.get() != &lattice) 68 10 : mooseError("Lattice " + prev_name + " cannot be renamed to " + name + 69 : " as it does not exist in this CSGBase instance."); 70 : 71 20 : auto existing_lat = std::move(it->second); 72 20 : existing_lat->setName(name); 73 20 : _lattices.erase(prev_name); 74 22 : addLattice(std::move(existing_lat)); 75 24 : } 76 : 77 : bool 78 4 : CSGLatticeList::operator==(const CSGLatticeList & other) const 79 : { 80 4 : const auto all_lats = this->getAllLattices(); 81 4 : const auto other_lats = other.getAllLattices(); 82 : 83 : // Check that same number of lattices are defined in both lists 84 4 : if (all_lats.size() != other_lats.size()) 85 0 : return false; 86 : 87 : // Iterate through each CSGLattices in list and check equality of each cell 88 : // with other list 89 8 : for (const auto & lat : all_lats) 90 : { 91 4 : const auto & lat_name = lat.get().getName(); 92 4 : if (!other.hasLattice(lat_name)) 93 0 : return false; 94 4 : const auto & other_lat = other.getLattice(lat_name); 95 4 : if (lat.get() != other_lat) 96 0 : return false; 97 : } 98 4 : return true; 99 4 : } 100 : 101 : bool 102 0 : CSGLatticeList::operator!=(const CSGLatticeList & other) const 103 : { 104 0 : return !(*this == other); 105 : } 106 : 107 : } // namespace CSG