https://mooseframework.inl.gov
CSGUniverse.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 "CSGUniverse.h"
11 
12 namespace CSG
13 {
14 
15 CSGUniverse::CSGUniverse(const std::string & name, bool is_root) : _name(name), _is_root(is_root) {}
16 
17 CSGUniverse::CSGUniverse(const std::string & name, std::vector<CSGCell *> & cells, bool is_root)
18  : _name(name), _is_root(is_root)
19 {
20  for (auto cell : cells)
21  addCell(*cell);
22 }
23 
24 void
26 {
27  auto cell_name = cell.getName();
28  if (!hasCell(cell_name))
29  _cells.push_back(cell);
30  else
31  mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " +
32  "Skipping cell insertion for cell with duplicate name.");
33 }
34 
35 const CSGCell &
36 CSGUniverse::getCell(const std::string & name)
37 {
38  if (!hasCell(name))
39  mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
40  for (const CSGCell & cell : _cells)
41  if (cell.getName() == name)
42  return cell;
43  mooseError("Should not reach here.");
44 }
45 
46 bool
47 CSGUniverse::hasCell(const std::string & name) const
48 {
49  for (const CSGCell & cell : _cells)
50  if (cell.getName() == name)
51  return true;
52  return false;
53 }
54 
55 void
56 CSGUniverse::removeCell(const std::string & name)
57 {
58  if (!hasCell(name))
59  mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
60  _name + ".");
61  for (auto it = _cells.begin(); it != _cells.end(); ++it)
62  if (it->get().getName() == name)
63  {
64  _cells.erase(it);
65  break;
66  }
67 }
68 
69 bool
71 {
72  const bool names_eq = this->getName() == other.getName();
73  if (names_eq)
74  {
75  const auto & all_cells = getAllCells();
76  const auto & other_cells = other.getAllCells();
77  const bool num_cells_eq = all_cells.size() == other_cells.size();
78  if (num_cells_eq)
79  {
80  for (unsigned int i = 0; i < all_cells.size(); ++i)
81  if (all_cells[i].get() != other_cells[i].get())
82  return false;
83  return true;
84  }
85  else
86  return false;
87  }
88  else
89  return false;
90 }
91 
92 bool
94 {
95  return !(*this == other);
96 }
97 
98 } // namespace CSG
std::string name(const ElemQuality q)
const std::string & getName() const
Get the cell name.
Definition: CSGCell.h:94
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
std::string _name
Name of universe.
Definition: CSGUniverse.h:119
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:357
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition: CSGUniverse.C:47
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:26
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in the universe.
Definition: CSGUniverse.h:72
const CSGCell & getCell(const std::string &name)
Get the CSGCell object by name.
Definition: CSGUniverse.C:36
void removeCell(const std::string &name)
remove a cell of the specified name from the universe
Definition: CSGUniverse.C:56
bool operator==(const CSGUniverse &other) const
Operator overload for checking if two CSGUniverse objects are equal.
Definition: CSGUniverse.C:70
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:79
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
Definition: CSGUniverse.h:122
CSGCell creates an internal representation of a Constructive Solid Geometry (CSG) cell...
Definition: CSGCell.h:27
CSGUniverse(const std::string &name, bool is_root=false)
Construct a new CSGUniverse object.
Definition: CSGUniverse.C:15
bool operator!=(const CSGUniverse &other) const
Operator overload for checking if two CSGUniverse objects are not equal.
Definition: CSGUniverse.C:93
void addCell(const CSGCell &cell)
add cell to universe
Definition: CSGUniverse.C:25