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 "CSGCellList.h" 13 : 14 : #ifdef MOOSE_UNIT_TEST 15 : #include "gtest/gtest.h" 16 : #endif 17 : 18 : namespace CSG 19 : { 20 : 21 : /** 22 : * CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) 23 : * universe, which represents a collection of cells that can be defined repeatedly within a separate 24 : * container of cells 25 : */ 26 : class CSGUniverse 27 : { 28 : public: 29 : /** 30 : * @brief Construct a new CSGUniverse object 31 : * 32 : * @param name unique name of universe 33 : * @param is_root true to set universe as the root universe (default false) 34 : */ 35 : CSGUniverse(const std::string & name, bool is_root = false); 36 : 37 : /** 38 : * @brief Construct a new CSGUniverse object from list of cells 39 : * 40 : * @param name unique name of universe 41 : * @param cells list of cells to add to universe 42 : * @param is_root true to set universe as the root universe (default false) 43 : */ 44 : CSGUniverse(const std::string & name, std::vector<CSGCell *> & cells, bool is_root = false); 45 : 46 : /** 47 : * Destructor 48 : */ 49 280 : virtual ~CSGUniverse() = default; 50 : 51 : /** 52 : * @brief Get the CSGCell object by name 53 : * 54 : * @param name name of cell 55 : * @return reference to the cell of the specified name in this universe 56 : */ 57 : const CSGCell & getCell(const std::string & name); 58 : 59 : /** 60 : * @brief check if cell of provided name is present in universe 61 : * 62 : * @param name name of cell 63 : * @return true if cell of name is in universe, otherwise false 64 : */ 65 : bool hasCell(const std::string & name) const; 66 : 67 : /** 68 : * @brief Get list of the all cells in the universe 69 : * 70 : * @return list of pointers to cells in universe 71 : */ 72 118 : const std::vector<std::reference_wrapper<const CSGCell>> & getAllCells() const { return _cells; } 73 : 74 : /** 75 : * @brief Get the name of the universe 76 : * 77 : * @return name of universe 78 : */ 79 471 : const std::string & getName() const { return _name; } 80 : 81 : /** 82 : * @brief return true if the universe is the root universe 83 : * 84 : * @return true / false 85 : */ 86 72 : bool isRoot() const { return _is_root; } 87 : 88 : /// Operator overload for checking if two CSGUniverse objects are equal 89 : bool operator==(const CSGUniverse & other) const; 90 : 91 : /// Operator overload for checking if two CSGUniverse objects are not equal 92 : bool operator!=(const CSGUniverse & other) const; 93 : 94 : protected: 95 : /** 96 : * @brief add cell to universe 97 : * 98 : * @param reference to cell to add 99 : */ 100 : void addCell(const CSGCell & cell); 101 : 102 : /** 103 : * @brief remove a cell of the specified name from the universe 104 : * 105 : * @param name name of cell to remove 106 : */ 107 : void removeCell(const std::string & name); 108 : 109 : /** 110 : * @brief remove all cells from the universe 111 : */ 112 2 : void removeAllCells() { _cells.clear(); } 113 : 114 : // set the name of the universe - intentionally not public because 115 : // name needs to be managed at the CSGUniverseList level 116 8 : void setName(const std::string & name) { _name = name; } 117 : 118 : /// Name of universe 119 : std::string _name; 120 : 121 : /// list of references to cells in universe 122 : std::vector<std::reference_wrapper<const CSGCell>> _cells; 123 : 124 : /// whether or not this universe is the root universe 125 : bool _is_root; 126 : 127 : // CSGUniverseList needs to be friend to access setName() 128 : friend class CSGUniverseList; 129 : 130 : // CSGUniverseList needs to be friend to access addCell() 131 : friend class CSGBase; 132 : 133 : #ifdef MOOSE_UNIT_TEST 134 : /// Friends for unit testing 135 : ///@{ 136 : FRIEND_TEST(CSGUniverseTest, testGetCell); 137 : FRIEND_TEST(CSGUniverseTest, testAddCell); 138 : FRIEND_TEST(CSGUniverseTest, testRemoveCell); 139 : FRIEND_TEST(CSGUniverseTest, testRemoveAllCells); 140 : FRIEND_TEST(CSGUniverseTest, testSetName); 141 : ///@} 142 : #endif 143 : }; 144 : } // namespace CSG