16 const std::string & name,
18 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes,
19 const std::optional<OuterVariant> & outer)
29 const std::optional<OuterVariant> & outer)
41 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
const 43 if (universes.size() < 1)
46 if (universes.size() % 2 == 0)
50 unsigned int num_row = universes.size();
51 unsigned int center_row = (num_row - 1) / 2;
55 num_row - ((row_i > center_row) ? (row_i - center_row) : (center_row - row_i));
56 if (universes[row_i].size() != n_ele)
65 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
70 " with universes. Does not have valid dimensions for lattice type " +
getType());
72 _nrow = universes.size();
85 std::unordered_map<std::string, AttributeVariant>
88 return {{
"nrow",
static_cast<unsigned int>(
_nrow)},
89 {
"nring",
static_cast<unsigned int>(
_nring)},
96 auto row = index.first;
97 auto ele = index.second;
100 if (row < 0 || row >= (
int)
_nrow)
104 auto center_row = (
_nrow - 1) / 2;
108 return !(ele < 0 || ele >= max_ele);
119 if (std::get<unsigned int>(this_dims[
"nrow"]) != std::get<unsigned int>(other_dims[
"nrow"]))
121 if (std::get<unsigned int>(this_dims[
"nring"]) != std::get<unsigned int>(other_dims[
"nring"]))
123 if (std::get<Real>(this_dims[
"pitch"]) != std::get<Real>(other_dims[
"pitch"]))
133 unsigned int num_elements = (ring ==
_nring - 1) ? 1 : 6 * (
_nring - 1 - ring);
134 for (
const auto element :
make_range(num_elements))
136 std::pair<unsigned int, unsigned int> ring_index = std::make_pair(ring, element);
146 auto og_ring = ring_ele_index.first;
147 int ring =
_nring - og_ring - 1;
148 auto element = ring_ele_index.second;
150 if (og_ring < 0 || og_ring >= (
int)
_nring)
151 mooseError(
"Ring " + std::to_string(og_ring) +
" is not valid for hexagonal lattice " +
153 if (element < 0 || element >= (ring == 0 ? 1 : 6 * ring))
154 mooseError(
"Position " + std::to_string(element) +
" is not valid for ring " +
155 std::to_string(og_ring) +
" in hexagonal lattice " +
getName());
158 int center_row = (
_nrow - 1) / 2;
159 int center_col = center_row;
163 return {center_row, center_col};
166 int side_length = ring;
169 int side = element / side_length;
170 int offset = element % side_length;
174 auto calc_num_cols_in_row = [&](
int r) {
return _nrow -
std::abs(center_row - r); };
189 row = center_row + offset;
190 col = calc_num_cols_in_row(row) - og_ring - 1;
193 row = center_row + ring;
194 col = calc_num_cols_in_row(row) - og_ring - 1 - offset;
197 row = center_row + (side_length - offset);
198 col = center_col - ring;
201 row = center_row - offset;
202 col = center_col - ring;
205 row = center_row - ring;
206 col = center_col - ring + offset;
209 row = center_row - (side_length - offset);
210 col = calc_num_cols_in_row(row) - og_ring - 1;
217 "Calculated index (" + std::to_string(row) +
", " + std::to_string(col) +
218 ") is not valid for hexagonal lattice " +
getName());
227 mooseError(
"Index (" + std::to_string(row_col_index.first) +
", " +
228 std::to_string(row_col_index.second) +
229 ") is not a valid index for hexagonal " 243 std::string base_msg =
"Cannot convert number of rows " + std::to_string(nrow) +
244 " to number of rings in hexagonal lattice. ";
246 mooseError(base_msg +
"Number of rows must be >= 0.");
248 mooseError(base_msg +
"Number of rows must be odd.");
249 return (nrow + 1) / 2;
258 mooseError(
"Cannot convert number of rings " + std::to_string(nring) +
259 " to number of rows in hexagonal lattice. Number of rings must be >= 0.");
260 return 2 * nring - 1;
std::string name(const ElemQuality q)
void setPitch(Real pitch)
set the pitch of the lattice
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
unsigned int _nring
number of rings in the hexagonal lattice, should be consistent with the number of rows ...
virtual bool compareAttributes(const CSGLattice &other) const override
compare the attributes returned in getAttributes of this lattice to another lattice ...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
const std::string & getType() const
Get the lattice type.
const std::string & getName() const
Get the name of lattice.
CSGLattice is the abstract class for defining lattices.
std::map< std::pair< unsigned int, unsigned int >, std::pair< unsigned int, unsigned int > > _row_to_ring_map
map of row-column indices to ring-position indices for quick conversion and look-up ...
std::pair< int, int > getRingIndexFromRowIndex(const std::pair< int, int > &row_col_index) const
Given an index in row-column form, get the corresponding ring-position index.
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...
CSGHexagonalLattice is the class for constructing hexagonal lattices of CSGUniverses arranged in conc...
virtual bool isValidUniverseMap(std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes) const override
check if the arrangement of the provided universes is valid for the hexagonal lattice given the numbe...
unsigned int nRowToRing(int nrow)
methods to help convert between number of rows and rings get the total number of rings from the numbe...
Real _pitch
lattice pitch (flat-to-flat distance between adjacent hex elements)
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const override
Get attributes that define the lattice (excluding the universe map).
void buildIndexMap()
build a mapping of row-column indices to ring-position indices for quick conversion and look-up...
unsigned int nRingToRow(int nring)
get the total number of rows from the number of rings
virtual bool isValidIndex(const std::pair< int, int > index) const override
check if provided index in row-column form is valid for the given hexagonal lattice ...
IntRange< T > make_range(T beg, T end)
unsigned int _nrow
number of rows in the hexagonal lattice (must be odd), should be consistent with the number of rings ...
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes) override
set the universes that define the lattice layout
std::pair< int, int > getRowIndexFromRingIndex(const std::pair< int, int > &row_col_index) const
Given an index in ring-position form, get the corresponding row-column index.
auto index_range(const T &sizable)
CSGHexagonalLattice(const std::string &name, Real pitch, std::vector< std::vector< std::reference_wrapper< const CSGUniverse >>> universes, const std::optional< OuterVariant > &outer=std::nullopt)
Construct a new CSGHexagonalLattice from a map of universes.
std::string prettyCppType(const std::string &cpp_type)