https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 "CSGEngUnit.h"
12#include "CSGUtils.h"
13#include "MooseError.h"
14
15namespace CSG
16{
17
18CSGUniverse::CSGUniverse(const std::string & name, bool is_root) : _name(name), _is_root(is_root) {}
19
20CSGUniverse::CSGUniverse(const std::string & name, std::vector<CSGCell *> & cells, bool is_root)
21 : _name(name), _is_root(is_root)
22{
24 for (auto cell : cells)
25 addCell(*cell);
26}
27
28void
30{
31 auto cell_name = cell.getName();
32 if (!hasCell(cell_name))
33 _cells.push_back(cell);
34 else
35 mooseWarning("Universe " + getName() + " already contains a cell by name " + cell_name + ". " +
36 "Skipping cell insertion for cell with duplicate name.");
37}
38
39const CSGCell &
40CSGUniverse::getCell(const std::string & name)
41{
42 if (!hasCell(name))
43 mooseError("Cell with name " + name + " does not exist in universe " + _name + ".");
44 for (const CSGCell & cell : _cells)
45 if (cell.getName() == name)
46 return cell;
47 mooseError("Should not reach here.");
48}
49
50bool
51CSGUniverse::hasCell(const std::string & name) const
52{
53 for (const CSGCell & cell : _cells)
54 if (cell.getName() == name)
55 return true;
56 return false;
57}
58
59void
60CSGUniverse::removeCell(const std::string & name)
61{
62 if (!hasCell(name))
63 mooseError("Cannot remove cell. Cell with name " + name + " does not exist in universe " +
64 _name + ".");
65 for (auto it = _cells.begin(); it != _cells.end(); ++it)
66 if (it->get().getName() == name)
67 {
68 _cells.erase(it);
69 break;
70 }
71}
72
73bool
75{
76 // If both objects are engineering units, delegate to CSGEngUnit::operator==. The
77 // isEngUnit() check keeps the common plain-universe path free of any dynamic_cast;
78 // the casts below only run once we know the objects are engineering units.
79 if (isEngUnit())
80 {
81 if (other.isEngUnit())
82 return *dynamic_cast<const CSGEngUnit *>(this) == *dynamic_cast<const CSGEngUnit *>(&other);
83 return false; // an engineering unit cannot equal a plain universe
84 }
85
86 if ((this->getName() != other.getName()) ||
87 (this->getTransformations() != other.getTransformations()))
88 return false;
89 const auto & all_cells = getAllCells();
90 const auto & other_cells = other.getAllCells();
91 const bool num_cells_eq = all_cells.size() == other_cells.size();
92 if (num_cells_eq)
93 {
94 for (unsigned int i = 0; i < all_cells.size(); ++i)
95 if (all_cells[i].get() != other_cells[i].get())
96 return false;
97 return true;
98 }
99 else
100 return false;
101}
102
103bool
105{
106 return !(*this == other);
107}
108
109} // namespace CSG
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
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
CSGEngUnit is the abstract base class for all "engineering unit" types in the CSG system.
Definition CSGEngUnit.h:33
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe,...
Definition CSGUniverse.h:28
CSGUniverse(const std::string &name, bool is_root=false)
Construct a new CSGUniverse object.
Definition CSGUniverse.C:18
virtual bool isEngUnit() const
Whether this universe is an engineering unit.
Definition CSGUniverse.h:98
const std::string & getName() const
Get the name of the universe.
Definition CSGUniverse.h:80
void addCell(const CSGCell &cell)
add cell to universe
Definition CSGUniverse.C:29
bool operator!=(const CSGUniverse &other) const
Operator overload for checking if two CSGUniverse objects are not equal.
const CSGCell & getCell(const std::string &name)
Get the CSGCell object by name.
Definition CSGUniverse.C:40
std::vector< std::reference_wrapper< const CSGCell > > _cells
list of references to cells in universe
void removeCell(const std::string &name)
remove a cell of the specified name from the universe
Definition CSGUniverse.C:60
const std::vector< std::reference_wrapper< const CSGCell > > & getAllCells() const
Get list of the all cells in the universe.
Definition CSGUniverse.h:73
std::string _name
Name of universe.
bool hasCell(const std::string &name) const
check if cell of provided name is present in universe
Definition CSGUniverse.C:51
bool operator==(const CSGUniverse &other) const
Operator overload for checking if two CSGUniverse objects are equal.
Definition CSGUniverse.C:74
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition CSGUtils.C:36