Skip to content

Commit 2820081

Browse files
committed
update util to take a reference vector, and change ww to use vector
1 parent 9927c14 commit 2820081

5 files changed

Lines changed: 19 additions & 29 deletions

File tree

mcdc/numba_types.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,7 @@
593593
('Nx', int64),
594594
('Ny', int64),
595595
('Nz', int64),
596-
('px', float64),
597-
('py', float64),
598-
('pz', float64),
596+
('polar_reference', float64, (3,)),
599597
('lower_weights_offset', int64),
600598
('lower_weights_length', int64),
601599
('target_weights_offset', int64),

mcdc/object_/technique.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ class WeightWindows(ObjectSingleton):
100100
Nz: int
101101

102102
# reference vector for calculating mu and azimuthal angle
103-
px: float
104-
py: float
105-
pz: float
103+
polar_reference: Annotated[NDArray[np.float64], (3,)]
106104

107105
# arrays of ww params
108106
lower_weights: Annotated[
@@ -128,9 +126,7 @@ def __init__(self):
128126
self.mesh_ID = -1 # skirt around having to create a MeshBase instance
129127
self.Nx, self.Ny, self.Nz = 1, 1, 1
130128
self.Nt = 1
131-
self.px = 0.0
132-
self.py = 0.0
133-
self.pz = 1.0
129+
self.polar_reference = np.array([0.0, 0.0, 1.0])
134130
shape = (self.Nt, self.Ne, self.Nmu, self.Na, self.Nx, self.Ny, self.Nz)
135131
self.lower_weights = np.array([1.0]).reshape(*shape)
136132
self.target_weights = np.array([1.0]).reshape(*shape)
@@ -217,10 +213,8 @@ def __call__(
217213
)
218214

219215
def set_polar_reference(self, px, py, pz):
220-
norm = np.linalg.norm([px, py, pz])
221-
self.px = px / norm
222-
self.py = py / norm
223-
self.pz = pz / norm
216+
polar_reference = np.array([px, py, pz])
217+
self.polar_reference = polar_reference / np.linalg.norm(polar_reference)
224218

225219
@staticmethod
226220
def __check_array(array: NDArray[np.float64], name: str):

mcdc/transport/tally/filter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
COINCIDENCE_TOLERANCE_ENERGY,
1313
COINCIDENCE_TOLERANCE_TIME,
1414
)
15-
from mcdc.transport.util import find_bin_with_tolerance, find_bin_with_rules, calculate_angles
15+
from mcdc.transport.util import (
16+
find_bin_with_tolerance,
17+
find_bin_with_rules,
18+
calculate_angles,
19+
)
1620

1721

1822
@njit
@@ -34,11 +38,7 @@ def get_filter_indices(particle_container, tally, data, MG_mode):
3438
@njit
3539
def get_direction_index(particle_container, tally, data):
3640
# Polar reference
37-
nx = tally["polar_reference"][0]
38-
ny = tally["polar_reference"][1]
39-
nz = tally["polar_reference"][2]
40-
41-
mu, azi = calculate_angles(particle_container, nx, ny, nz)
41+
mu, azi = calculate_angles(particle_container, tally["polar_reference"])
4242

4343
tolerance = COINCIDENCE_TOLERANCE_DIRECTION
4444

mcdc/transport/technique.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ def get_ww_indices(particle_container, ww_obj, simulation, data):
161161
ie = util.find_bin(energy, energy_bounds)
162162

163163
# get angular indices
164-
mu, azimuthal = util.calculate_angles(
165-
particle_container, ww_obj["px"], ww_obj["py"], ww_obj["pz"]
166-
)
164+
mu, azimuthal = util.calculate_angles(particle_container, ww_obj["polar_reference"])
167165

168166
# mu
169167
mu_bounds = ww_get.mu_bounds_all(ww_obj, data)

mcdc/transport/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,16 @@ def log_interpolation(x, x1, x2, y1, y2):
138138

139139

140140
@njit
141-
def calculate_angles(particle_container, px, py, pz):
141+
def calculate_angles(particle_container, polar_reference):
142142
"""
143143
Calculate particle mu and azimuthal angle from given reference vector
144144
145145
Parameters
146146
----------
147147
particle_container : ndarray
148148
Container holding the particle.
149-
px : float
150-
X-component of reference vector
151-
py : float
152-
Y-component of reference vector
153-
pz : float
154-
Z-component of reference vector
149+
polar_reference : ndarray
150+
3D polar reference vector
155151
156152
Returns
157153
-------
@@ -165,6 +161,10 @@ def calculate_angles(particle_container, px, py, pz):
165161
uy = particle["uy"]
166162
uz = particle["uz"]
167163

164+
px = polar_reference[0]
165+
py = polar_reference[1]
166+
pz = polar_reference[2]
167+
168168
mu = ux * px + uy * py + uz * pz
169169

170170
azimuthal = _calculate_azimuthal(ux, uy, uz, px, py, pz)

0 commit comments

Comments
 (0)