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 : #pragma once 11 : 12 : #include "CSGLattice.h" 13 : 14 : #ifdef MOOSE_UNIT_TEST 15 : #include "gtest/gtest.h" 16 : #endif 17 : 18 : namespace CSG 19 : { 20 : 21 : /** 22 : * CSGCartesianLattice is the class for constructing regular Cartesian lattices of CSGUniverses. 23 : */ 24 : class CSGCartesianLattice : public CSGLattice 25 : { 26 : public: 27 : /** 28 : * @brief Construct a new CSGCartesianLattice object from the map of universes provided. 29 : * 30 : * @param name unique identifying name of lattice 31 : * @param pitch pitch of lattice elements 32 : * @param universes list of list of universes to set as the lattice map 33 : * @param outer optional outer universe or material name that fills space around lattice elements. 34 : * If not provided, outer is assumed to be VOID. 35 : */ 36 : CSGCartesianLattice(const std::string & name, 37 : const Real pitch, 38 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes, 39 : const std::optional<OuterVariant> & outer = std::nullopt); 40 : 41 : /** 42 : * @brief Construct a new empty CSGCartesianLattice object with specified pitch. 43 : * NOTE: must call setLatticeUniverses to populate the universe map. 44 : * 45 : * @param name unique identifying name of lattice 46 : * @param pitch pitch of lattice elements 47 : * @param outer optional outer universe or material name that fills space around lattice elements. 48 : * If not provided, outer is assumed to be VOID. 49 : */ 50 : CSGCartesianLattice(const std::string & name, 51 : const Real pitch, 52 : const std::optional<OuterVariant> & outer = std::nullopt); 53 : 54 : /** 55 : * Destructor 56 : */ 57 300 : virtual ~CSGCartesianLattice() = default; 58 : 59 : /** 60 : * @brief clone this Cartesian lattice 61 : * 62 : * @return std::unique_ptr<CSGLattice> unique pointer to cloned Cartesian lattice 63 : */ 64 10 : std::unique_ptr<CSGLattice> clone() const override 65 : { 66 10 : return std::make_unique<CSGCartesianLattice>(*this); 67 : } 68 : 69 : /** 70 : * @brief Get attributes that define the lattice (excluding the universe map). 71 : * - nrow: number of rows (int) 72 : * - ncol: number of columns (int) 73 : * - pitch: pitch of the lattice element (Real) 74 : * 75 : * @return map of string dimension name to value of that dimension 76 : */ 77 : virtual std::unordered_map<std::string, AttributeVariant> getAttributes() const override; 78 : 79 : /** 80 : * @brief Checks if the given index location (row, column) is a valid index for the 81 : * lattice. Allowable indices are: 0 <= row < _nrow and 0 <= column < _ncol. 82 : * 83 : * @param index location in (row, column) form 84 : * @return true if index is valid for the lattice 85 : */ 86 : virtual bool isValidIndex(const std::pair<int, int> index) const override; 87 : 88 : /** 89 : * @brief check that any provided list of list of CSGUniverses are the correct dimensions. Must 90 : * have number of lists within universes equal to _nrow. And each sublist must be size _ncol. 91 : * 92 : * @param universes list of list of universes to be used to define the lattice structure 93 : * @return true if universe dimensions are valid 94 : */ 95 : virtual bool isValidUniverseMap( 96 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) const override; 97 : 98 : /** 99 : * @brief get the number of rows 100 : * 101 : * @return number of rows 102 : */ 103 8 : unsigned int getNRows() const { return _nrow; } 104 : 105 : /** 106 : * @brief get number of columns 107 : * 108 : * @return number of columns 109 : */ 110 8 : unsigned int getNCols() const { return _ncol; } 111 : 112 : /** 113 : * @brief get lattice pitch 114 : * 115 : * @return pitch 116 : */ 117 6 : Real getPitch() const { return _pitch; } 118 : 119 : /** 120 : * @brief set the pitch of the lattice 121 : * 122 : * @param pitch new pitch value 123 : */ 124 : void setPitch(Real pitch); 125 : 126 : protected: 127 : /// compare the attributes returned in getAttributes of this lattice to another lattice 128 : virtual bool compareAttributes(const CSGLattice & other) const override; 129 : 130 : /** 131 : * @brief set the universes that define the lattice layout 132 : * 133 : * @param universes list of list of universes to set as the lattice map 134 : */ 135 : virtual void setUniverses( 136 : std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes) override; 137 : 138 : /// pitch 139 : Real _pitch; 140 : 141 : /// number of elements in the first dimension (rows) 142 : unsigned int _nrow; 143 : 144 : /// number of elements in the second direction (columns) 145 : unsigned int _ncol; 146 : 147 : friend class CSGBase; 148 : 149 : #ifdef MOOSE_UNIT_TEST 150 : /// Friends for unit testing 151 : ///@{ 152 : FRIEND_TEST(CSGLatticeTest, testCartSetUniverses); 153 : FRIEND_TEST(CSGLatticeTest, testCartSetUniverseAtIndex); 154 : FRIEND_TEST(CSGLatticeTest, testEmptyToFilled); 155 : FRIEND_TEST(CSGLatticeTest, testCartLatticeEquality); 156 : ///@} 157 : #endif 158 : }; 159 : }