Skip to content

Commit

Permalink
avoid the warning of division zero
Browse files Browse the repository at this point in the history
  • Loading branch information
DeerWhale committed Jul 10, 2024
1 parent 467decd commit 950f95c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tardis/plasma/properties/radiative_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ def calculate(
metastability, lines_upper_level_index
)

stimulated_emission_factor = 1 - (
(g_lower * n_upper) / (g_upper * n_lower)
# In theory the factor should be 1 for n_lower = 0, but in practice the opacity is reduced to 0 anyway
stimulated_emission_factor = np.zeros(n_lower.shape, dtype=np.float64)

n_lower_zero_mask = n_lower == 0.0
stimulated_emission_factor[~n_lower_zero_mask] = 1 - (
(g_lower * n_upper)[~n_lower_zero_mask]
/ (g_upper * n_lower)[~n_lower_zero_mask]
)

# the following line probably can be removed as well
stimulated_emission_factor[np.isneginf(stimulated_emission_factor)] = (
0.0
)
stimulated_emission_factor[n_lower == 0.0] = 0.0
stimulated_emission_factor[
np.isneginf(stimulated_emission_factor)
] = 0.0
stimulated_emission_factor[
meta_stable_upper & (stimulated_emission_factor < 0)
] = 0.0
Expand Down

0 comments on commit 950f95c

Please sign in to comment.