Skip to content

Commit 50071aa

Browse files
shimwelljon-proximafusionpaulromano
authored
Speed up time correction factors (#3592)
Co-authored-by: Jon Shimwell <[email protected]> Co-authored-by: Paul Romano <[email protected]>
1 parent 8a62e7e commit 50071aa

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

openmc/deplete/d1s.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ def time_correction_factors(
108108
# Create a 2D array for the time correction factors
109109
h = np.zeros((n_timesteps, n_nuclides))
110110

111-
for i, (dt, rate) in enumerate(zip(timesteps, source_rates)):
112-
# Precompute the exponential terms. Since (1 - exp(-x)) is susceptible to
113-
# roundoff error, use expm1 instead (which computes exp(x) - 1)
114-
g = np.exp(-decay_rate*dt)
115-
one_minus_g = -np.expm1(-decay_rate*dt)
111+
# Precompute all exponential terms with same shape as h
112+
decay_dt = decay_rate[np.newaxis, :] * timesteps[:, np.newaxis]
113+
g = np.exp(-decay_dt)
114+
one_minus_g = -np.expm1(-decay_dt)
116115

116+
# Apply recurrence relation step by step
117+
for i in range(len(timesteps)):
117118
# Eq. (4) in doi:10.1016/j.fusengdes.2019.111399
118-
h[i + 1] = rate*one_minus_g + h[i]*g
119+
h[i + 1] = source_rates[i] * one_minus_g[i] + h[i] * g[i]
119120

120121
return {nuclides[i]: h[:, i] for i in range(n_nuclides)}
121122

0 commit comments

Comments
 (0)