Skip to content

Commit 25edd85

Browse files
authored
Merge pull request #3 from paulromano/newhex-clockwise
Change order of x-oriented hex lattice universes to clockwise
2 parents 8d29648 + d36adef commit 25edd85

File tree

2 files changed

+65
-39
lines changed

2 files changed

+65
-39
lines changed

openmc/lattice.py

+62-36
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ def get_universe_index(self, idx):
12411241
else:
12421242
i_within = 5*g - z
12431243

1244-
if (self._orientation == 'x') and (i_within > 0):
1245-
i_within = 6*(self._num_rings - i_ring - 1) - i_within_
1244+
if self._orientation == 'x' and g > 0:
1245+
i_within = (i_within + 5*g) % (6*g)
12461246

12471247
if self.num_axial is None:
12481248
return (i_ring, i_within)
@@ -1376,6 +1376,7 @@ def from_xml_element(cls, elem, get_universe):
13761376
lat = cls(lat_id, name)
13771377
lat.center = [float(i) for i in get_text(elem, 'center').split()]
13781378
lat.pitch = [float(i) for i in get_text(elem, 'pitch').split()]
1379+
lat.orientation = get_text(elem, 'orientation', 'y')
13791380
outer = get_text(elem, 'outer')
13801381
if outer is not None:
13811382
lat.outer = get_universe(int(outer))
@@ -1390,7 +1391,7 @@ def from_xml_element(cls, elem, get_universe):
13901391
if n_axial > 1:
13911392
univs = [deepcopy(univs) for i in range(n_axial)]
13921393

1393-
# Get flat array of universes numbers
1394+
# Get flat array of universes
13941395
uarray = np.array([get_universe(int(i)) for i in
13951396
get_text(elem, 'universes').split()])
13961397

@@ -1400,28 +1401,53 @@ def from_xml_element(cls, elem, get_universe):
14001401
# Get list for a single axial level
14011402
axial_level = univs[z] if n_axial > 1 else univs
14021403

1403-
# Start iterating from top
1404-
x, alpha = 0, n_rings - 1
1405-
while True:
1406-
# Set entry in list based on (x,alpha,z) coordinates
1407-
_, i_ring, i_within = lat.get_universe_index((x, alpha, z))
1408-
axial_level[i_ring][i_within] = uarray[j]
1409-
1410-
# Move to the right
1411-
x += 2
1412-
alpha -= 1
1413-
if not lat.is_valid_index((x, alpha, z)):
1414-
# Move down in y direction
1415-
alpha += x - 1
1416-
x = 1 - x
1404+
if lat.orientation == 'y':
1405+
# Start iterating from top
1406+
x, alpha = 0, n_rings - 1
1407+
while True:
1408+
# Set entry in list based on (x,alpha,z) coordinates
1409+
_, i_ring, i_within = lat.get_universe_index((x, alpha, z))
1410+
axial_level[i_ring][i_within] = uarray[j]
1411+
1412+
# Move to the right
1413+
x += 2
1414+
alpha -= 1
14171415
if not lat.is_valid_index((x, alpha, z)):
1418-
# Move to the right
1419-
x += 2
1420-
alpha -= 1
1416+
# Move down in y direction
1417+
alpha += x - 1
1418+
x = 1 - x
14211419
if not lat.is_valid_index((x, alpha, z)):
1422-
# Reached the bottom
1420+
# Move to the right
1421+
x += 2
1422+
alpha -= 1
1423+
if not lat.is_valid_index((x, alpha, z)):
1424+
# Reached the bottom
1425+
break
1426+
j += 1
1427+
else:
1428+
# Start iterating from top
1429+
alpha, y = 1 - n_rings, n_rings - 1
1430+
while True:
1431+
# Set entry in list based on (alpha,y,z) coordinates
1432+
_, i_ring, i_within = lat.get_universe_index((alpha, y, z))
1433+
axial_level[i_ring][i_within] = uarray[j]
1434+
1435+
# Move to the right
1436+
alpha += 1
1437+
if not lat.is_valid_index((alpha, y, z)):
1438+
# Move down to next row
1439+
alpha = 1 - n_rings
1440+
y -= 1
1441+
1442+
# Check if we've reached the bottom
1443+
if y == -n_rings:
14231444
break
1424-
j += 1
1445+
1446+
while not lat.is_valid_index((alpha, y, z)):
1447+
# Move to the right
1448+
alpha += 1
1449+
j += 1
1450+
14251451
lat.universes = univs
14261452
return lat
14271453

@@ -1469,7 +1495,7 @@ def _repr_axial_slice_x(self, universes):
14691495
theta = 0
14701496
y = middle
14711497

1472-
# Climb up the top-right.
1498+
# Climb down the bottom-right
14731499
for i in range(r):
14741500
# Add the universe.
14751501
universe = universes[r_prime][theta]
@@ -1479,7 +1505,7 @@ def _repr_axial_slice_x(self, universes):
14791505
y += 1
14801506
theta += 1
14811507

1482-
# Climb left the top-left.
1508+
# Climb left across the bottom
14831509
for i in range(r):
14841510
# Add the universe.
14851511
universe = universes[r_prime][theta]
@@ -1488,7 +1514,7 @@ def _repr_axial_slice_x(self, universes):
14881514
# Translate the indices.
14891515
theta += 1
14901516

1491-
# Climb down the middle left.
1517+
# Climb up the bottom-left
14921518
for i in range(r):
14931519
# Add the universe.
14941520
universe = universes[r_prime][theta]
@@ -1498,7 +1524,7 @@ def _repr_axial_slice_x(self, universes):
14981524
y -= 1
14991525
theta += 1
15001526

1501-
# Climb down the down left.
1527+
# Climb up the top-left
15021528
for i in range(r):
15031529
# Add the universe.
15041530
universe = universes[r_prime][theta]
@@ -1508,7 +1534,7 @@ def _repr_axial_slice_x(self, universes):
15081534
y -= 1
15091535
theta += 1
15101536

1511-
# Climb right the down right.
1537+
# Climb right across the top
15121538
for i in range(r):
15131539
# Add the universe.
15141540
universe = universes[r_prime][theta]
@@ -1517,7 +1543,7 @@ def _repr_axial_slice_x(self, universes):
15171543
# Translate the indices.
15181544
theta += 1
15191545

1520-
# Climb up the middle-right.
1546+
# Climb down the top-right
15211547
for i in range(r):
15221548
# Add the universe.
15231549
universe = universes[r_prime][theta]
@@ -1528,7 +1554,7 @@ def _repr_axial_slice_x(self, universes):
15281554
theta += 1
15291555

15301556
# Flip the rows and join each row into a single string.
1531-
rows = [pad.join(x) for x in rows[::-1]]
1557+
rows = [pad.join(x) for x in rows]
15321558

15331559
# Pad the beginning of the rows so they line up properly.
15341560
for y in range(self._num_rings - 1):
@@ -1806,41 +1832,41 @@ def _show_indices_x(num_rings):
18061832
y = middle
18071833

18081834
for i in range(r):
1809-
# Climb up the top-right.
1835+
# Climb down the bottom-right
18101836
rows[y].append(str_form.format(r_prime, theta))
18111837
y += 1
18121838
theta += 1
18131839

18141840
for i in range(r):
1815-
# Climb left the top-left.
1841+
# Climb left across the bottom
18161842
rows[y].insert(0, str_form.format(r_prime, theta))
18171843
theta += 1
18181844

18191845
for i in range(r):
1820-
# Climb down the middle left.
1846+
# Climb up the bottom-left
18211847
rows[y].insert(0, str_form.format(r_prime, theta))
18221848
y -= 1
18231849
theta += 1
18241850

18251851
for i in range(r):
1826-
# Climb down the down left.
1852+
# Climb up the top-left
18271853
rows[y].insert(0, str_form.format(r_prime, theta))
18281854
y -= 1
18291855
theta += 1
18301856

18311857
for i in range(r):
1832-
# Climb right the down right.
1858+
# Climb right across the top
18331859
rows[y].append(str_form.format(r_prime, theta))
18341860
theta += 1
18351861

18361862
for i in range(r):
1837-
# Climb up the middle-right.
1863+
# Climb down the top-right
18381864
rows[y].append(str_form.format(r_prime, theta))
18391865
y += 1
18401866
theta += 1
18411867

18421868
# Flip the rows and join each row into a single string.
1843-
rows = [pad.join(x) for x in rows[::-1]]
1869+
rows = [pad.join(x) for x in rows]
18441870

18451871
# Pad the beginning of the rows so they line up properly.
18461872
for y in range(num_rings - 1):

tests/regression_tests/lattice_hex_x/test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ def _build_inputs(self):
161161
arr.append(fuel_ch_univ)
162162
universes.append(arr)
163163
universes[-1] = [tube_ch_univ]
164-
channels = [(7, 16), (7, 13), (7, 10), (7, 7), (7, 4), (7, 1), (5, 0),
165-
(4, 33), (5, 25), (4, 27), (5, 20), (4, 21), (5, 15),
166-
(4, 15), (5, 10), (4, 9), (5, 5), (4, 3)]
164+
channels = [(7, 2), (7, 5), (7, 8), (7, 11), (7, 14), (7, 17), (5, 0),
165+
(4, 3), (5, 5), (4, 9), (5, 10), (4, 15), (5, 15),
166+
(4, 21), (5, 20), (4, 27), (5, 25), (4, 33)]
167167
for i, j in channels:
168168
universes[i][j] = abs_ch_univ
169169
lattice = openmc.HexLattice(name="regular fuel assembly")

0 commit comments

Comments
 (0)