https://mooseframework.inl.gov
CSGUniverseList.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 "CSGUniverseList.h"
11 
12 namespace CSG
13 {
14 
16 {
17  // create root universe by default when CSG object is initialized
18  std::string root_name = "ROOT_UNIVERSE";
19  auto root_universe = std::make_unique<CSGUniverse>(root_name, /* is_root = */ true);
20  _root_universe = root_universe.get();
21  _universes.insert(std::make_pair(root_name, std::move(root_universe)));
22 }
23 
25 CSGUniverseList::getUniverse(const std::string & name) const
26 {
27  auto univ = _universes.find(name);
28  if (univ == _universes.end())
29  mooseError("No universe by name " + name + " exists in the geometry.");
30  else
31  return *(univ->second);
32 }
33 
34 std::vector<std::reference_wrapper<const CSGUniverse>>
36 {
37  std::vector<std::reference_wrapper<const CSGUniverse>> univs;
38  for (auto it = _universes.begin(); it != _universes.end(); ++it)
39  univs.push_back(*(it->second.get()));
40  return univs;
41 }
42 
44 CSGUniverseList::addUniverse(const std::string & name)
45 {
46  return addUniverse(std::make_unique<CSGUniverse>(name));
47 }
48 
50 CSGUniverseList::addUniverse(std::unique_ptr<CSGUniverse> universe)
51 {
52  auto name = universe->getName();
53  auto [it, inserted] = _universes.emplace(name, std::move(universe));
54  if (!inserted)
55  mooseError("Universe with name " + name + " already exists in geometry.");
56  return *it->second;
57 }
58 
59 void
60 CSGUniverseList::renameUniverse(const CSGUniverse & universe, const std::string & name)
61 {
62  // check that this universe passed in is actually in the same universe that is in the universe
63  // list
64  auto prev_name = universe.getName();
65  auto it = _universes.find(prev_name);
66  if (it == _universes.end() || it->second.get() != &universe)
67  mooseError("Universe " + prev_name + " cannot be renamed to " + name +
68  " as it does not exist in this CSGBase instance.");
69 
70  auto existing_univ = std::move(it->second);
71  existing_univ->setName(name);
72  _universes.erase(prev_name);
73  addUniverse(std::move(existing_univ));
74 }
75 
76 } // namespace CSG
std::string name(const ElemQuality q)
std::vector< std::reference_wrapper< const CSGUniverse > > getAllUniverses() const
Get all the universes in CSGBase instance.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const CSGUniverse * _root_universe
root universe for the CSGBase instance
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:26
CSGUniverse & getUniverse(const std::string &name) const
Get a Universe from the list by its name.
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:79
CSGUniverse & addUniverse(const std::string &name)
create an empty universe
void renameUniverse(const CSGUniverse &universe, const std::string &name)
rename the specified universe
std::unordered_map< std::string, std::unique_ptr< CSGUniverse > > _universes
Mapping of universe names to pointers of stored universe objects.
CSGUniverseList()
Default constructor.