https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CSGCellList.C
Go to the documentation of this file.
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 "CSGCellList.h"
11
12namespace CSG
13{
14
16
17CSGCell &
18CSGCellList::addCell(std::unique_ptr<CSGCell> cell, const bool ignore_identical_cell)
19{
20 auto cell_name = cell->getName();
21 if (ignore_identical_cell)
22 // Check that cell already defined in _cells and if so, confirm it matches with input cell
23 if (auto it = _cells.find(cell_name); it != _cells.end())
24 {
25 if (*cell == *it->second)
26 return *it->second;
27 else
28 mooseError("Cell with name ",
29 cell_name,
30 " has the same name as an existing cell in CSGBase instance but cannot be "
31 "discarded as it is not an identical cell.");
32 }
33
34 // Otherwise, add the cell to the cell list. At this point, we don't expect the cell
35 // to already be defined in the cell list
36 auto [it, inserted] = _cells.emplace(cell_name, std::move(cell));
37 if (!inserted)
38 mooseError("Cell with name " + cell_name + " already exists in geometry.");
39
40 return *it->second;
41}
42
43CSGCell &
44CSGCellList::getCell(const std::string & name) const
45{
46 if (_cells.find(name) == _cells.end())
47 mooseError("No cell by name " + name + " exists in the geometry.");
48 else
49 return *(_cells.find(name)->second);
50}
51
52CSGCell &
53CSGCellList::addVoidCell(const std::string & name, const CSGRegion & region)
54{
55 return addCell(std::make_unique<CSGCell>(name, region));
56}
57
58CSGCell &
59CSGCellList::addMaterialCell(const std::string & name,
60 const std::string & mat_name,
61 const CSGRegion & region)
62{
63 return addCell(std::make_unique<CSGCell>(name, mat_name, region));
64}
65
66CSGCell &
67CSGCellList::addUniverseCell(const std::string & name,
68 const CSGUniverse & univ,
69 const CSGRegion & region)
70{
71 return addCell(std::make_unique<CSGCell>(name, &univ, region));
72}
73
74CSGCell &
75CSGCellList::addLatticeCell(const std::string & name,
76 const CSGLattice & lattice,
77 const CSGRegion & region)
78{
79 return addCell(std::make_unique<CSGCell>(name, &lattice, region));
80}
81
82std::vector<std::reference_wrapper<const CSGCell>>
84{
85 std::vector<std::reference_wrapper<const CSGCell>> cells;
86 for (auto it = _cells.begin(); it != _cells.end(); ++it)
87 cells.push_back(*(it->second));
88 return cells;
89}
90
91void
92CSGCellList::renameCell(const CSGCell & cell, const std::string & name)
93{
94 // check that this cell passed in is actually in the same cell that is in the cell list
95 auto prev_name = cell.getName();
96 auto it = _cells.find(prev_name);
97 if (it == _cells.end() || it->second.get() != &cell)
98 mooseError("Cell " + prev_name + " cannot be renamed to " + name +
99 " as it does not exist in this CSGBase instance.");
100
101 auto existing_cell = std::move(_cells.find(prev_name)->second);
102 existing_cell->setName(name);
103 _cells.erase(prev_name);
104 addCell(std::move(existing_cell));
105}
106
107bool
109{
110 const auto all_cells = this->getAllCells();
111 const auto other_cells = other.getAllCells();
112
113 // Check that same number of cells are defined in both lists
114 if (all_cells.size() != other_cells.size())
115 return false;
116
117 // Iterate through each CSGCell in list and check equality of each cell
118 // with other list
119 for (const auto & cell : all_cells)
120 {
121 const auto & cell_name = cell.get().getName();
122 if (!other.hasCell(cell_name))
123 return false;
124 const auto & other_cell = other.getCell(cell_name);
125 if (cell.get() != other_cell)
126 return false;
127 }
128 return true;
129}
130
131bool
133{
134 return !(*this == other);
135}
136
137} // namespace CSG
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
CSGCellList creates a container for CSGCell objects to pass to CSGBase object.
Definition CSGCellList.h:21
CSGCellList()
Default constructor.
Definition CSGCellList.C:15
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition CSGCellList.C:83
bool operator!=(const CSGCellList &other) const
Operator overload for checking if two CSGCellList objects are not equal.
CSGCell & addLatticeCell(const std::string &name, const CSGLattice &lattice, const CSGRegion &region)
Add a Lattice Cell object to cell list.
Definition CSGCellList.C:75
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
void renameCell(const CSGCell &cell, const std::string &name)
rename the specified cell
Definition CSGCellList.C:92
bool hasCell(const std::string &name) const
return whether cell with given name exists in cell list
Definition CSGCellList.h:85
CSGCell & addVoidCell(const std::string &name, const CSGRegion &region)
Add a Void Cell object cell list.
Definition CSGCellList.C:53
CSGCell & addMaterialCell(const std::string &name, const std::string &mat_name, const CSGRegion &region)
Add a Material Cell object to cell list.
Definition CSGCellList.C:59
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
Definition CSGCellList.C:44
CSGCell & addUniverseCell(const std::string &name, const CSGUniverse &univ, const CSGRegion &region)
Add a Universe Cell object to cell list.
Definition CSGCellList.C:67
bool operator==(const CSGCellList &other) const
Operator overload for checking if two CSGCellList objects are equal.
CSGCell & addCell(std::unique_ptr< CSGCell > cell, const bool ignore_identical_cell=false)
add a cell to the CellList.
Definition CSGCellList.C:18
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell,...
Definition CSGCell.h:30
const std::string & getName() const
Get the cell name.
Definition CSGCell.h:112
CSGLattice is the abstract class for defining lattices.
Definition CSGLattice.h:35
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection,...
Definition CSGRegion.h:23
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe,...
Definition CSGUniverse.h:28