https://mooseframework.inl.gov
CSGLattice.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 "CSGLattice.h"
11 #include "CSGUtils.h"
12 
13 namespace CSG
14 {
15 
16 CSGLattice::CSGLattice(const std::string & name,
17  const std::string & lattice_type,
18  const std::optional<OuterVariant> & outer)
19  : _name(name), _lattice_type(lattice_type), _outer_type("VOID"), _outer_universe(nullptr)
20 {
22  // Handle the outer variant if provided
23  if (outer.has_value())
24  {
25  std::visit([this](auto && outer_arg) { updateOuter(outer_arg); }, outer.value());
26  }
27 }
28 
29 void
30 CSGLattice::setUniverseAtIndex(const CSGUniverse & universe, const std::pair<int, int> index)
31 {
32  std::string base_msg = "Cannot set universe at location (" + std::to_string(index.first) + ", " +
33  std::to_string(index.second) + ") for lattice " + getName() + ". ";
34  if (_universe_map.size() == 0)
35  mooseError(base_msg + "Universe map has not been initialized.");
36  if (!isValidIndex(index))
37  mooseError(base_msg + "Not a valid location.");
38  _universe_map[index.first][index.second] = universe;
39 }
40 
41 bool
42 CSGLattice::hasUniverse(const std::string & name) const
43 {
44  for (auto list_univ : _universe_map)
45  for (const CSGUniverse & univ : list_univ)
46  if (univ.getName() == name)
47  return true;
48  return false; // no universe with matching name was found
49 }
50 
51 const std::vector<std::vector<std::string>>
53 {
54  std::vector<std::vector<std::string>> name_map;
55  for (auto & univ_list : _universe_map)
56  {
57  std::vector<std::string> name_list;
58  for (const CSGUniverse & univ : univ_list)
59  name_list.push_back(univ.getName());
60  name_map.push_back(name_list);
61  }
62  return name_map;
63 }
64 
65 const CSGUniverse &
66 CSGLattice::getUniverseAtIndex(const std::pair<int, int> index)
67 {
68  if (!isValidIndex(index))
69  mooseError("Index (" + std::to_string(index.first) + ", " + std::to_string(index.second) +
70  ") is not a valid index for lattice " + getName());
71  else
72  return _universe_map[index.first][index.second];
73 }
74 
75 const std::vector<std::pair<unsigned int, unsigned int>>
76 CSGLattice::getUniverseIndices(const std::string & univ_name) const
77 {
78  if (!hasUniverse(univ_name))
79  mooseError("Universe " + univ_name + " does not exist in lattice " + getName());
80 
81  std::vector<std::pair<unsigned int, unsigned int>> indices;
82  for (auto i : index_range(_universe_map))
83  for (auto j : index_range(_universe_map[i]))
84  {
85  const CSGUniverse & univ = _universe_map[i][j];
86  if (univ.getName() == univ_name)
87  indices.push_back(std::make_pair(i, j));
88  }
89  return indices;
90 }
91 
92 const std::vector<std::reference_wrapper<const CSGUniverse>>
94 {
95  std::vector<std::reference_wrapper<const CSGUniverse>> unique_univs;
96  auto all_univs = getUniverses();
97 
98  for (const auto & ulist : all_univs)
99  for (const auto & u : ulist)
100  {
101  auto it = std::find_if(unique_univs.begin(),
102  unique_univs.end(),
103  [&u](const auto & ref) { return &ref.get() == &u.get(); });
104  if (it == unique_univs.end())
105  unique_univs.push_back(u);
106  }
107  return unique_univs;
108 }
109 
110 const CSGUniverse &
112 {
113  if (getOuterType() != "UNIVERSE")
114  mooseError("Lattice '" + getName() + "' has " + getOuterType() + " outer, not UNIVERSE.");
115  else
116  return *_outer_universe;
117 }
118 
119 const std::string &
121 {
122  if (getOuterType() != "CSG_MATERIAL")
123  mooseError("Lattice '" + getName() + "' has " + getOuterType() + " outer, not CSG_MATERIAL.");
124  else
125  return _outer_material;
126 }
127 
128 void
129 CSGLattice::updateOuter(const CSGUniverse & outer_universe)
130 {
131  _outer_type = "UNIVERSE";
132  _outer_universe = &outer_universe;
133  _outer_material = "";
134 }
135 
136 void
137 CSGLattice::updateOuter(const std::string & outer_name)
138 {
139  _outer_type = "CSG_MATERIAL";
140  _outer_material = outer_name;
141  _outer_universe = nullptr;
142 }
143 
144 void
146 {
147  _outer_type = "VOID";
148  _outer_material = "";
149  _outer_universe = nullptr;
150 }
151 
152 bool
153 CSGLattice::operator==(const CSGLattice & other) const
154 {
155  if (this->getName() != other.getName())
156  return false;
157  if (this->getType() != other.getType())
158  return false;
159  if (this->getTransformations() != other.getTransformations())
160  return false;
161  if (this->getOuterType() != other.getOuterType())
162  return false;
163  if ((this->getOuterType() == "CSG_MATERIAL") &&
164  (this->getOuterMaterial() != other.getOuterMaterial()))
165  return false;
166  if ((this->getOuterType() == "UNIVERSE") &&
167  (this->getOuterUniverse() != other.getOuterUniverse()))
168  return false;
169  if (!this->compareAttributes(other))
170  return false;
171 
172  const auto & this_univs = this->getUniverses();
173  const auto & other_univs = other.getUniverses();
174  if (this_univs.size() != other_univs.size())
175  return false;
176  for (unsigned int i = 0; i < this_univs.size(); ++i)
177  {
178  if (this_univs[i].size() != other_univs[i].size())
179  return false;
180  for (unsigned int j = 0; j < this_univs[i].size(); j++)
181  if (this_univs[i][j].get() != other_univs[i][j].get())
182  return false;
183  }
184 
185  return true;
186 }
187 
188 bool
189 CSGLattice::operator!=(const CSGLattice & other) const
190 {
191  return !(*this == other);
192 }
193 
194 } // namespace CSG
std::string name(const ElemQuality q)
std::string _outer_material
name of the outer material
Definition: CSGLattice.h:231
std::string _outer_type
An enum for type of outer fill for lattice.
Definition: CSGLattice.h:228
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
const std::vector< std::pair< unsigned int, unsigned int > > getUniverseIndices(const std::string &univ_name) const
get all locations in lattice where universe of the specified name exists
Definition: CSGLattice.C:76
bool operator!=(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are not equal.
Definition: CSGLattice.C:189
CSGLattice(const std::string &name, const std::string &lattice_type, const std::optional< OuterVariant > &outer=std::nullopt)
Construct a new CSGLattice of specific type.
Definition: CSGLattice.C:16
virtual bool isValidIndex(const std::pair< int, int > index) const =0
Checks if the given index location is a valid index for the lattice.
const CSGUniverse & getOuterUniverse() const
Get the outer universe if outer type is UNIVERSE.
Definition: CSGLattice.C:111
void setUniverseAtIndex(const CSGUniverse &universe, const std::pair< int, int > index)
replace the element at specified index in the lattice with the provided CSGUniverse.
Definition: CSGLattice.C:30
CSGUniverse creates an internal representation of a Constructive Solid Geometry (CSG) universe...
Definition: CSGUniverse.h:27
const std::string & getType() const
Get the lattice type.
Definition: CSGLattice.h:69
const std::string & getName() const
Get the name of lattice.
Definition: CSGLattice.h:62
const std::vector< std::reference_wrapper< const CSGUniverse > > getUniqueUniverses() const
Get the list of unique universe objects in the lattice.
Definition: CSGLattice.C:93
CSGLattice is the abstract class for defining lattices.
Definition: CSGLattice.h:34
const std::string & getName() const
Get the name of the universe.
Definition: CSGUniverse.h:80
void resetOuter()
reset the outer fill around the lattice elements to be VOID
Definition: CSGLattice.C:145
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > _universe_map
Universes in the arrangement of how they appear in the lattice; dimensions depends on lattice type...
Definition: CSGLattice.h:225
const std::string & getOuterMaterial() const
Get the outer material name if outer fype is CSG_MATERIAL.
Definition: CSGLattice.C:120
const CSGUniverse & getUniverseAtIndex(const std::pair< int, int > index)
Get the universe located at the given index.
Definition: CSGLattice.C:66
void updateOuter(const std::string &outer_name)
Update the outer of the lattice to be the provided material name.
Definition: CSGLattice.C:137
const std::vector< std::vector< std::string > > getUniverseNameMap() const
Get the arrangement of CSGUniverses in the lattice as their names.
Definition: CSGLattice.C:52
void checkValidCSGName(const std::string &name)
Check name of CSG component for disallowed characters and symbols.
Definition: CSGUtils.C:36
const CSGUniverse * _outer_universe
outer object if fill is CSGUniverse
Definition: CSGLattice.h:234
virtual bool compareAttributes(const CSGLattice &other) const =0
helper function to compare the attributes of the lattice type
std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > getUniverses() const
Get the arrangement of CSGUniverses in the lattice.
Definition: CSGLattice.h:97
bool hasUniverse(const std::string &name) const
whether or not the universe of the specified name exists in the lattice
Definition: CSGLattice.C:42
const std::string getOuterType() const
Get the type of outer that fills the space around the lattice elements.
Definition: CSGLattice.h:76
auto index_range(const T &sizable)
const std::vector< std::pair< TransformationType, std::tuple< Real, Real, Real > > > & getTransformations() const
Get the list of transformations.
bool operator==(const CSGLattice &other) const
Operator overload for checking if two CSGLattice objects are equal.
Definition: CSGLattice.C:153