File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments