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