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)
30 :
CSGLattice(name, outer), _pitch(pitch), _nrow(0), _nring(0)
38 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
const
40 if (universes.size() < 1)
43 if (universes.size() % 2 == 0)
47 unsigned int num_row = universes.size();
48 unsigned int center_row = (num_row - 1) / 2;
49 for (
unsigned int row_i : index_range(universes))
52 num_row - ((row_i > center_row) ? (row_i - center_row) : (center_row - row_i));
53 if (universes[row_i].size() != n_ele)
62 std::vector<std::vector<std::reference_wrapper<const CSGUniverse>>> universes)
67 " with universes. Does not have valid dimensions for lattice type " +
getType());
69 _nrow = universes.size();
82std::unordered_map<std::string, AttributeVariant>
85 return {{
"nrow",
static_cast<unsigned int>(
_nrow)},
86 {
"nring",
static_cast<unsigned int>(
_nring)},
93 auto row = index.first;
94 auto ele = index.second;
97 if (row < 0 || row >= (
int)
_nrow)
101 auto center_row = (
_nrow - 1) / 2;
102 int max_ele =
_nrow - std::abs((
int)(row - center_row));
105 return !(ele < 0 || ele >= max_ele);
111 if (other.
getType() != this->getType())
116 if (std::get<unsigned int>(this_dims[
"nrow"]) != std::get<unsigned int>(other_dims[
"nrow"]))
118 if (std::get<unsigned int>(this_dims[
"nring"]) != std::get<unsigned int>(other_dims[
"nring"]))
120 if (std::get<Real>(this_dims[
"pitch"]) != std::get<Real>(other_dims[
"pitch"]))
128 for (
const auto ring : make_range(
_nring))
130 unsigned int num_elements = (ring ==
_nring - 1) ? 1 : 6 * (
_nring - 1 - ring);
131 for (
const auto element : make_range(num_elements))
133 std::pair<unsigned int, unsigned int> ring_index = std::make_pair(ring, element);
143 auto og_ring = ring_ele_index.first;
144 int ring =
_nring - og_ring - 1;
145 auto element = ring_ele_index.second;
147 if (og_ring < 0 || og_ring >= (
int)
_nring)
148 mooseError(
"Ring " + std::to_string(og_ring) +
" is not valid for hexagonal lattice " +
150 if (element < 0 || element >= (ring == 0 ? 1 : 6 * ring))
151 mooseError(
"Position " + std::to_string(element) +
" is not valid for ring " +
152 std::to_string(og_ring) +
" in hexagonal lattice " +
getName());
155 int center_row = (
_nrow - 1) / 2;
156 int center_col = center_row;
160 return {center_row, center_col};
163 int side_length = ring;
166 int side = element / side_length;
167 int offset = element % side_length;
171 auto calc_num_cols_in_row = [&](
int r) {
return _nrow - std::abs(center_row - r); };
186 row = center_row + offset;
187 col = calc_num_cols_in_row(row) - og_ring - 1;
190 row = center_row + ring;
191 col = calc_num_cols_in_row(row) - og_ring - 1 - offset;
194 row = center_row + (side_length - offset);
195 col = center_col - ring;
198 row = center_row - offset;
199 col = center_col - ring;
202 row = center_row - ring;
203 col = center_col - ring + offset;
206 row = center_row - (side_length - offset);
207 col = calc_num_cols_in_row(row) - og_ring - 1;
214 "Calculated index (" + std::to_string(row) +
", " + std::to_string(col) +
215 ") is not valid for hexagonal lattice " +
getName());
224 mooseError(
"Index (" + std::to_string(row_col_index.first) +
", " +
225 std::to_string(row_col_index.second) +
226 ") is not a valid index for hexagonal "
240 std::string base_msg =
"Cannot convert number of rows " + std::to_string(nrow) +
241 " to number of rings in hexagonal lattice. ";
243 mooseError(base_msg +
"Number of rows must be >= 0.");
245 mooseError(base_msg +
"Number of rows must be odd.");
246 return (nrow + 1) / 2;
255 mooseError(
"Cannot convert number of rings " + std::to_string(nring) +
256 " to number of rows in hexagonal lattice. Number of rings must be >= 0.");
257 return 2 * nring - 1;
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
unsigned int _nring
number of rings in the hexagonal lattice, should be consistent with the number of rows
Real _pitch
lattice pitch (flat-to-flat distance between adjacent hex elements)
void buildIndexMap()
build a mapping of row-column indices to ring-position indices for quick conversion and look-up.
virtual bool compareAttributes(const CSGLattice &other) const override
compare the attributes returned in getAttributes of this lattice to another lattice
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
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
unsigned int _nrow
number of rows in the hexagonal lattice (must be odd), should be consistent with the number of rings
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.
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.
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const override
Get attributes that define the lattice (excluding the universe map).
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.
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...
void setPitch(Real pitch)
set the pitch of the lattice
virtual void setUniverses(std::vector< std::vector< std::reference_wrapper< const CSGUniverse > > > universes) override
set the universes that define the lattice layout
CSGLattice is the abstract class for defining lattices.
const std::string & getName() const
Get the name of lattice.
virtual std::unordered_map< std::string, AttributeVariant > getAttributes() const =0
Get attributes that define the lattice (excluding the universe map).
const std::string getType() const
Get the lattice type.
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.
unsigned int nRowToRing(int nrow)
methods to help convert between number of rows and rings get the total number of rings from the numbe...
unsigned int nRingToRow(int nring)
get the total number of rows from the number of rings