Skip to content

Commit

Permalink
Revert "Restructure: Add radiation field (tardis-sn#123)" (tardis-sn#133
Browse files Browse the repository at this point in the history
)

This reverts commit 1320de3.
  • Loading branch information
jvshields authored Aug 21, 2023
1 parent 1320de3 commit 98d039b
Show file tree
Hide file tree
Showing 21 changed files with 569 additions and 373 deletions.
6 changes: 3 additions & 3 deletions benchmarks/run_stardis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from stardis.io.model.marcs import read_marcs_model
from stardis.plasma import create_stellar_plasma
from stardis.radiation_field.opacities.opacities_solvers import calc_alphas
from stardis.radiation_field.radiation_field_solvers import raytrace
from stardis.radiation_field.opacities.opacities_solvers import calc_alpha_line_at_nu
from stardis.opacities import calc_alphas
from stardis.transport import raytrace
from stardis.opacities import calc_alpha_line_at_nu


class BenchmarkStardis:
Expand Down
36 changes: 9 additions & 27 deletions stardis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from astropy import units as u

from stardis.plasma import create_stellar_plasma
from stardis.radiation_field.opacities.opacities_solvers import calc_alphas
from stardis.radiation_field.radiation_field_solvers import raytrace
from stardis.radiation_field import RadiationField
from stardis.opacities import calc_alphas
from stardis.transport import raytrace


base_dir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -73,34 +72,20 @@ def run_stardis(config_fname, tracing_lambdas_or_nus):
# plasma
stellar_plasma = create_stellar_plasma(stellar_model, adata)

if True: # change to checking source function from config
from stardis.radiation_field.source_functions.blackbody import (
blackbody_flux_at_nu,
)

stellar_radiation_field = RadiationField(
tracing_nus, blackbody_flux_at_nu, stellar_model
)

calc_alphas(
# Below becomes radiation field
alphas, gammas, doppler_widths = calc_alphas(
stellar_plasma=stellar_plasma,
stellar_model=stellar_model,
stellar_radiation_field=stellar_radiation_field,
tracing_nus=tracing_nus,
opacity_config=config.opacity,
)

raytrace(stellar_model, stellar_radiation_field, no_of_thetas=config.no_of_thetas)
F_nu = raytrace(
stellar_model, alphas, tracing_nus, no_of_thetas=config.no_of_thetas
)

return STARDISOutput(
stellar_plasma,
stellar_model,
stellar_radiation_field.opacities.opacities_dict,
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu_gammas"],
stellar_radiation_field.opacities.opacities_dict[
"alpha_line_at_nu_doppler_widths"
],
stellar_radiation_field.F_nu,
stellar_radiation_field.frequencies,
stellar_plasma, stellar_model, alphas, gammas, doppler_widths, F_nu, tracing_nus
)


Expand Down Expand Up @@ -149,9 +134,6 @@ class STARDISOutput:
Numpy array of wavelengths used for spectrum with units of Angstroms.
"""

###TODO: Instead of returning all these various quantities of the radiation, simply return
# the radiation field with class properties that return useful quantities such as spectrum lambda and lambdas.

def __init__(
self, stellar_plasma, stellar_model, alphas, gammas, doppler_widths, F_nu, nus
):
Expand Down
1 change: 1 addition & 0 deletions stardis/opacities/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from stardis.opacities.base import *
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@

import numba

from tardis.io.config_reader import ConfigurationNameSpace

from astropy import units as u, constants as const

from stardis.radiation_field.opacities.opacities_solvers.broadening import (
calculate_broadening,
)
from stardis.radiation_field.opacities.opacities_solvers.voigt import voigt_profile
from stardis.radiation_field.opacities.opacities_solvers.util import (
sigma_file,
map_items_to_indices,
get_number_density,
)

# constants
from stardis.opacities.broadening import calculate_broadening
from stardis.opacities.voigt import voigt_profile
from stardis.opacities.util import sigma_file, map_items_to_indices, get_number_density


VACUUM_ELECTRIC_PERMITTIVITY = 1 / (4 * np.pi)
BF_CONSTANT = (
64
Expand Down Expand Up @@ -532,18 +528,18 @@ def calc_alan_entries(
def calc_alphas(
stellar_plasma,
stellar_model,
stellar_radiation_field,
tracing_nus,
opacity_config,
):
"""
Calculates each opacity and adds it to the opacity dictionary contained in the radiation field.
Calculates total opacity.
Parameters
----------
stellar_plasma : tardis.plasma.base.BasePlasma
stellar_model : stardis.model.base.StellarModel
stellar_radiation_field stardis.radiation_field.base.RadiationField
Contains the frequencies at which opacities are calculated. Also holds the resulting opacity information.
tracing_nus : astropy.unit.quantity.Quantity
Numpy array of frequencies used for ray tracing with units of Hz.
opacity_config : tardis.io.config_reader.Configuration
Opacity section of the STARDIS configuration.
Expand All @@ -552,61 +548,59 @@ def calc_alphas(
alphas : numpy.ndarray
Array of shape (no_of_depth_points, no_of_frequencies). Total opacity at
each depth point for each frequency in tracing_nus.
gammas : numpy.ndarray
Array of shape (no_of_lines, no_of_depth_points). Collisional broadening
parameter of each line at each depth point.
doppler_widths : numpy.ndarray
Array of shape (no_of_lines, no_of_depth_points). Doppler width of each
line at each depth point.
"""

alpha_file = calc_alpha_file(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.file,
)
stellar_radiation_field.opacities.opacities_dict["alpha_file"] = alpha_file

alpha_bf = calc_alpha_bf(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.bf,
)
stellar_radiation_field.opacities.opacities_dict["alpha_bf"] = alpha_bf

alpha_ff = calc_alpha_ff(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.ff,
)
stellar_radiation_field.opacities.opacities_dict["alpha_ff"] = alpha_ff

alpha_rayleigh = calc_alpha_rayleigh(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.rayleigh,
)
stellar_radiation_field.opacities.opacities_dict["alpha_rayleigh"] = alpha_rayleigh

alpha_electron = calc_alpha_electron(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.disable_electron_scattering,
)
stellar_radiation_field.opacities.opacities_dict["alpha_electron"] = alpha_electron

alpha_line_at_nu, gammas, doppler_widths = calc_alpha_line_at_nu(
stellar_plasma,
stellar_model,
stellar_radiation_field.frequencies,
tracing_nus,
opacity_config.line,
)
stellar_radiation_field.opacities.opacities_dict[
"alpha_line_at_nu"
] = alpha_line_at_nu
stellar_radiation_field.opacities.opacities_dict["alpha_line_at_nu_gammas"] = gammas
stellar_radiation_field.opacities.opacities_dict[
"alpha_line_at_nu_doppler_widths"
] = doppler_widths
alphas = stellar_radiation_field.opacities.calc_total_alphas()

return alphas

alphas = (
alpha_file
+ alpha_bf
+ alpha_ff
+ alpha_rayleigh
+ alpha_electron
+ alpha_line_at_nu
)

### TODO create opacity_dict to return
return alphas, gammas, doppler_widths
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _calc_doppler_width(nu_line, temperature, atomic_mass):
nu_line : float
Frequency of line being considered.
temperature : float
Temperature of depth points being considered.
Temperature of depth point being considered.
atomic_mass : float
Atomic mass of element being considered in grams.
Expand Down Expand Up @@ -188,7 +188,7 @@ def calc_gamma_linear_stark(n_eff_upper, n_eff_lower, electron_density):
n_eff_lower : float
Effective principal quantum number of lower level of transition.
electron_density : float
Electron density at depth point being considered.
Electron density in depth point being considered.
Returns
-------
Expand Down Expand Up @@ -232,7 +232,7 @@ def calc_gamma_quadratic_stark(
electron_density : float
Electron density at depth point being considered.
temperature : float
Temperature of depth points being considered.
Temperature of depth point being considered.
Returns
-------
Expand Down Expand Up @@ -280,7 +280,7 @@ def calc_gamma_van_der_waals(
n_eff_lower : float
Effective principal quantum number of lower level of transition.
temperature : float
Temperature of depth points being considered.
Temperature of depth point being considered.
h_density : float
Number density of Hydrogen at depth point being considered.
h_mass : float
Expand Down Expand Up @@ -329,7 +329,7 @@ def calc_gamma(
):
"""
Calculates total collision broadening parameter for a specific line
and depth points.
and depth point.
Parameters
----------
Expand All @@ -348,7 +348,7 @@ def calc_gamma(
electron_density : float
Electron density at depth point being considered.
temperature : float
Temperature of depth points being considered.
Temperature of depth point being considered.
h_density : float
Number density of Hydrogen at depth point being considered.
h_mass : float
Expand Down Expand Up @@ -440,7 +440,7 @@ def calculate_broadening(
line_cols : dict
Matches the name of a quantity to its column index in lines_array.
no_depth_points : int
Number of depth pointss.
Number of depth points.
atomic_masses : numpy.ndarray
Atomic mass of all elements included in the simulation.
electron_densities : numpy.ndarray
Expand All @@ -467,10 +467,10 @@ def calculate_broadening(
line_nus : numpy.ndarray
Frequency of each line.
gammas : numpy.ndarray
Array of shape (no_of_lines, no_depth_points). Collisional broadening
Array of shape (no_of_lines, no_of_depth_points). Collisional broadening
parameter of each line at each depth point.
doppler_widths : numpy.ndarray
Array of shape (no_of_lines, no_depth_points). Doppler width of each
Array of shape (no_of_lines, no_of_depth_points). Doppler width of each
line at each depth point.
"""

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from astropy import constants as const
from numba import cuda

from stardis.radiation_field.opacities.opacities_solvers.broadening import (
from stardis.opacities.broadening import (
calc_doppler_width,
_calc_doppler_width_cuda,
calc_doppler_width_cuda,
Expand Down
Loading

0 comments on commit 98d039b

Please sign in to comment.