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