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 "CSGCartesianLattice.h" 11 : 12 : namespace CSG 13 : { 14 : 15 110 : CSGCartesianLattice::CSGCartesianLattice( 16 : const std::string & name, 17 : const Real pitch, 18 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes, 19 110 : const std::optional<OuterVariant> & outer) 20 110 : : CSGLattice(name, MooseUtils::prettyCppType<CSGCartesianLattice>(), outer), _pitch(pitch) 21 : { 22 112 : setUniverses(universes); // this will set _nrow and _ncol 23 108 : if (_pitch < 0) 24 0 : mooseError("Lattice " + getName() + " must have pitch greater than 0."); 25 110 : } 26 : 27 44 : CSGCartesianLattice::CSGCartesianLattice(const std::string & name, 28 : const Real pitch, 29 44 : const std::optional<OuterVariant> & outer) 30 44 : : CSGLattice(name, MooseUtils::prettyCppType<CSGCartesianLattice>(), outer), 31 44 : _pitch(pitch), 32 44 : _nrow(0), 33 44 : _ncol(0) 34 : { 35 44 : if (_pitch < 0) 36 6 : mooseError("Lattice " + getName() + " must have pitch greater than 0."); 37 44 : } 38 : 39 : void 40 4 : CSGCartesianLattice::setPitch(const Real pitch) 41 : { 42 4 : if (pitch < 0) 43 6 : mooseError("Lattice " + getName() + " must have pitch greater than 0."); 44 2 : _pitch = pitch; 45 2 : } 46 : 47 : std::unordered_map<std::string, AttributeVariant> 48 150 : CSGCartesianLattice::getAttributes() const 49 : { 50 0 : return {{"nrow", static_cast<unsigned int>(_nrow)}, 51 0 : {"ncol", static_cast<unsigned int>(_ncol)}, 52 750 : {"pitch", _pitch}}; 53 150 : } 54 : 55 : bool 56 132 : CSGCartesianLattice::isValidUniverseMap( 57 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) const 58 : { 59 : // need at least one row 60 132 : if (universes.size() < 1) 61 0 : return false; 62 : 63 : // check that each row is same size 64 132 : auto row_size = universes[0].size(); 65 366 : for (auto univ_list : universes) 66 : { 67 236 : if (univ_list.size() != row_size) 68 2 : return false; 69 236 : } 70 130 : return true; 71 : } 72 : 73 : void 74 132 : CSGCartesianLattice::setUniverses( 75 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) 76 : { 77 : // check for valid map arrangment 78 132 : if (!isValidUniverseMap(universes)) 79 10 : mooseError("Cannot set lattice " + getName() + 80 6 : " with universes. Does not have valid dimensions for lattice type " + getType()); 81 : // set attributes based on universe map 82 130 : _nrow = universes.size(); 83 130 : _ncol = universes[0].size(); 84 130 : _universe_map = universes; 85 130 : } 86 : 87 : bool 88 22 : CSGCartesianLattice::isValidIndex(const std::pair<int, int> index) const 89 : { 90 22 : auto row = index.first; // must be (0 <= row < _nrow); rows 91 22 : auto col = index.second; // must be (0 <= col < _ncol); cols 92 22 : return ((0 <= row && row < (int)_nrow) && (0 <= col && col < (int)_ncol)); 93 : } 94 : 95 : bool 96 54 : CSGCartesianLattice::compareAttributes(const CSGLattice & other) const 97 : { 98 54 : if (other.getType() != this->getType()) 99 0 : return false; 100 : 101 54 : auto this_dims = this->getAttributes(); 102 54 : auto other_dims = other.getAttributes(); 103 216 : if (std::get<unsigned int>(this_dims["nrow"]) != std::get<unsigned int>(other_dims["nrow"])) 104 8 : return false; 105 184 : if (std::get<unsigned int>(this_dims["ncol"]) != std::get<unsigned int>(other_dims["ncol"])) 106 6 : return false; 107 160 : if (std::get<Real>(this_dims["pitch"]) != std::get<Real>(other_dims["pitch"])) 108 4 : return false; 109 36 : return true; 110 54 : } 111 : 112 : } // namespace CSG