From 22d5207c30441db1018188fbb012c6107f36770c Mon Sep 17 00:00:00 2001 From: Josh Shields Date: Mon, 2 Dec 2024 14:57:11 -0500 Subject: [PATCH] try memory efficient arrays for delta_nus --- .../opacities/opacities_solvers/base.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stardis/radiation_field/opacities/opacities_solvers/base.py b/stardis/radiation_field/opacities/opacities_solvers/base.py index f568ef15..3d24a2cd 100644 --- a/stardis/radiation_field/opacities/opacities_solvers/base.py +++ b/stardis/radiation_field/opacities/opacities_solvers/base.py @@ -431,8 +431,16 @@ def calc_alpha_line_at_nu( use_vald_broadening=line_opacity_config.vald_linelist.use_vald_broadening and line_opacity_config.vald_linelist.use_linelist, # don't try to use vald broadening if you don't use vald linelists at all ) - logger.info("Done with broadening") - delta_nus = tracing_nus.value - line_nus[:, np.newaxis] + + # This line is awful for large simulations. Has to solve wavelength points times number of lines. Can be optimized. + # delta_nus = tracing_nus.value - line_nus[:, np.newaxis] + + # Ensure arrays are contiguous + tracing_nus_value = np.ascontiguousarray(tracing_nus.value) + line_nus_reshaped = np.ascontiguousarray(line_nus[:, np.newaxis]) + + # Perform the operation + delta_nus = tracing_nus_value - line_nus_reshaped # If no broadening range, compute the contribution of every line at every frequency. h_lines_indices = None @@ -448,7 +456,7 @@ def calc_alpha_line_at_nu( if line_range.unit.physical_type == "length": logger.info("Broadening range is in length units") lambdas = tracing_nus.to(u.AA, equivalencies=u.spectral()) - logger.info("Convering broadening to frequency units") + logger.info("Converting broadening to frequency units") lambdas_plus_broadening_range = lambdas + line_range.to(u.AA) nus_plus_broadening_range = lambdas_plus_broadening_range.to( u.Hz, equivalencies=u.spectral()