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