Skip to content

Commit

Permalink
remove individual intensity preservation w/ no radiation_field return
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshields committed Nov 4, 2024
1 parent 71a7c27 commit eb49c03
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion stardis/config_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ properties:
return_radiation_field:
type: boolean
default: false
description: Options for what to return from the simulation.
description: Options for what to return from the simulation. Note that return_radiation_field can be very memory intensive because it returns the intensity at every depth point, wavelength, and theta in the model.
required:
- stardis_config_version
- atom_data
Expand Down
26 changes: 20 additions & 6 deletions stardis/radiation_field/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ class RadiationField(HDFWriterMixin):
Weights for the theta angles.
I_nus : numpy.ndarray
Radiation field intensity at each frequency at each depth point at each theta angle. Initialized as zeros and calculated by a solver.
track_individual_intensities : bool
Flag to track individual intensities at each theta angle. Default is False.
"""

hdf_properties = ["frequencies", "opacities", "F_nu"]

def __init__(self, frequencies, source_function, stellar_model, num_of_thetas):
def __init__(
self,
frequencies,
source_function,
stellar_model,
num_of_thetas,
track_individual_intensities=False,
):
self.frequencies = frequencies
self.source_function = source_function
self.opacities = Opacities(frequencies, stellar_model)
Expand All @@ -52,6 +61,11 @@ def __init__(self, frequencies, source_function, stellar_model, num_of_thetas):
thetas, weights = np.polynomial.legendre.leggauss(num_of_thetas)
self.thetas = (thetas / 2) + 0.5 * np.pi / 2
self.I_nus_weights = weights * np.pi / 2
self.track_individual_intensities = track_individual_intensities
if track_individual_intensities:
self.I_nus = np.zeros(
(stellar_model.no_of_depth_points, len(frequencies), len(self.thetas))
)

# This was our original theta sampling method
# dtheta = (np.pi / 2) / num_of_thetas # Korg uses Gauss-Legendre quadrature here
Expand All @@ -62,10 +76,6 @@ def __init__(self, frequencies, source_function, stellar_model, num_of_thetas):
# 2 * np.pi * dtheta * np.sin(self.thetas) * np.cos(self.thetas)
# )

self.I_nus = np.zeros(
(stellar_model.no_of_depth_points, len(frequencies), len(self.thetas))
)


def create_stellar_radiation_field(tracing_nus, stellar_model, stellar_plasma, config):
"""
Expand Down Expand Up @@ -94,7 +104,11 @@ def create_stellar_radiation_field(tracing_nus, stellar_model, stellar_plasma, c
"""

stellar_radiation_field = RadiationField(
tracing_nus, blackbody_flux_at_nu, stellar_model, config.no_of_thetas
tracing_nus,
blackbody_flux_at_nu,
stellar_model,
config.no_of_thetas,
track_individual_intensities=config.result_options.return_radiation_field,
)
logger.info("Calculating alphas")
calc_alphas(
Expand Down
7 changes: 3 additions & 4 deletions stardis/radiation_field/radiation_field_solvers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ def raytrace(
-1, 1
) / np.cos(stellar_radiation_field.thetas)
inward_rays = False
if (
False
): # Commenting out serial threaded block for now - currently doesn't work with spherical geometry and not sure it's worth maintaining
if False: # Commenting out serial threaded block for now - currently doesn't work with spherical geometry and not sure it's worth maintaining
# if n_threads == 1: # Single threaded
stellar_radiation_field.I_nus = all_thetas_trace(
ray_distances,
Expand All @@ -431,7 +429,8 @@ def raytrace(
stellar_radiation_field.source_function,
inward_rays=inward_rays,
)
stellar_radiation_field.I_nus[:, :, theta_index] = I_nu
if stellar_radiation_field.track_individual_intensities:
stellar_radiation_field.I_nus[:, :, theta_index] = I_nu

stellar_radiation_field.F_nu += (
I_nu * stellar_radiation_field.I_nus_weights[theta_index]
Expand Down

0 comments on commit eb49c03

Please sign in to comment.