https://mooseframework.inl.gov
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 
12 namespace CSG
13 {
14 
16 
17 CSGCell &
18 CSGCellList::addCell(std::unique_ptr<CSGCell> cell)
19 {
20  auto name = cell->getName();
21  auto [it, inserted] = _cells.emplace(name, std::move(cell));
22  if (!inserted)
23  mooseError("Cell with name " + name + " already exists in geometry.");
24  return *it->second;
25 }
26 
27 CSGCell &
28 CSGCellList::getCell(const std::string & name) const
29 {
30  if (_cells.find(name) == _cells.end())
31  mooseError("No cell by name " + name + " exists in the geometry.");
32  else
33  return *(_cells.find(name)->second);
34 }
35 
36 CSGCell &
37 CSGCellList::addVoidCell(const std::string & name, const CSGRegion & region)
38 {
39  return addCell(std::make_unique<CSGCell>(name, region));
40 }
41 
42 CSGCell &
43 CSGCellList::addMaterialCell(const std::string & name,
44  const std::string & mat_name,
45  const CSGRegion & region)
46 {
47  return addCell(std::make_unique<CSGCell>(name, mat_name, region));
48 }
49 
50 CSGCell &
51 CSGCellList::addUniverseCell(const std::string & name,
52  const CSGUniverse & univ,
53  const CSGRegion & region)
54 {
55  return addCell(std::make_unique<CSGCell>(name, &univ, region));
56 }
57 
58 std::vector<std::reference_wrapper<const CSGCell>>
60 {
61  std::vector<std::reference_wrapper<const CSGCell>> cells;
62  for (auto it = _cells.begin(); it != _cells.end(); ++it)
63  cells.push_back(*(it->second));
64  return cells;
65 }
66 
67 void
68 CSGCellList::renameCell(const CSGCell & cell, const std::string & name)
69 {
70  // check that this cell passed in is actually in the same cell that is in the cell list
71  auto prev_name = cell.getName();
72  auto it = _cells.find(prev_name);
73  if (it == _cells.end() || it->second.get() != &cell)
74  mooseError("Cell " + prev_name + " cannot be renamed to " + name +
75  " as it does not exist in this CSGBase instance.");
76 
77  auto existing_cell = std::move(_cells.find(prev_name)->second);
78  existing_cell->setName(name);
79  _cells.erase(prev_name);
80  addCell(std::move(existing_cell));
81 }
82 
83 } // namespace CSG
std::string name(const ElemQuality q)
CSGCell & addCell(std::unique_ptr< CSGCell > cell)
add a cell to the CellList.
Definition: CSGCellList.C:18
CSGCell & getCell(const std::string &name) const
Get the CSGCell by name.
Definition: CSGCellList.C:28
const std::string & getName() const
Get the cell name.
Definition: CSGCell.h:94
CSGRegions creates an internal representation of a CSG region, which can refer to an intersection...
Definition: CSGRegion.h:21
CSGCellList()
Default constructor.
Definition: CSGCellList.C:15
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
CSGCell & addVoidCell(const std::string &name, const CSGRegion &region)
Add a Void Cell object cell list.
Definition: CSGCellList.C:37
std::vector< std::reference_wrapper< const CSGCell > > getAllCells() const
Get all the cells in CSGBase instance.
Definition: CSGCellList.C:59
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:26
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:43
CSGCell & addUniverseCell(const std::string &name, const CSGUniverse &univ, const CSGRegion &region)
Add a Universe Cell object to cell list.
Definition: CSGCellList.C:51
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell...
Definition: CSGCell.h:27
void renameCell(const CSGCell &cell, const std::string &name)
rename the specified cell
Definition: CSGCellList.C:68
std::unordered_map< std::string, std::unique_ptr< CSGCell > > _cells
Mapping of cell names to pointers of stored cell objects.
Definition: CSGCellList.h:107