Skip to content

Commit

Permalink
Reintroduce j_blues_detailed as a ProcessingPlasmaProperty instead of…
Browse files Browse the repository at this point in the history
… just Input.
  • Loading branch information
ftsamis committed Dec 2, 2016
1 parent 9a58d8a commit 48ceb8c
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 10 deletions.
20 changes: 18 additions & 2 deletions tardis/plasma/properties/general.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import logging

import numpy as np
from astropy import constants as const
from astropy import constants as const, units as u

from tardis.plasma.properties.base import ProcessingPlasmaProperty

logger = logging.getLogger(__name__)

__all__ = ['BetaRadiation', 'GElectron', 'NumberDensity', 'SelectedAtoms',
'ElectronTemperature', 'BetaElectron']
'ElectronTemperature', 'BetaElectron', 'LuminosityInner',
'TimeSimulation']

class BetaRadiation(ProcessingPlasmaProperty):
"""
Expand Down Expand Up @@ -98,3 +99,18 @@ def __init__(self, plasma_parent):

def calculate(self, t_electrons):
return 1 / (self.k_B_cgs * t_electrons)

class LuminosityInner(ProcessingPlasmaProperty):
outputs = ('luminosity_inner',)

@staticmethod
def calculate(r_inner, t_inner):
return (4 * np.pi * const.sigma_sb.cgs * r_inner[0] ** 2
* t_inner ** 4).to('erg/s')

class TimeSimulation(ProcessingPlasmaProperty):
outputs = ('time_simulation',)

@staticmethod
def calculate(luminosity_inner):
return 1.0 * u.erg / luminosity_inner
48 changes: 47 additions & 1 deletion tardis/plasma/properties/j_blues.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import numpy as np
import pandas as pd
from astropy import constants as const

from tardis.plasma.properties.base import ProcessingPlasmaProperty
from tardis.plasma.properties.base import ProcessingPlasmaProperty, \
DataFrameInput
from tardis.util import intensity_black_body


Expand Down Expand Up @@ -33,3 +35,47 @@ def calculate(lines, nu, t_rad, w):
j_blues = pd.DataFrame(j_blues, index=lines.index,
columns=np.arange(len(t_rad)))
return np.array(j_blues, copy=False)


class JBluesDetailed(ProcessingPlasmaProperty):
outputs = ('j_blues',)
latex_name = ('J_{\\textrm{blue}}')

def __init__(self, w_epsilon):
self.w_epsilon = w_epsilon

def calculate(self, lines, nu, t_rad, w, j_blues_norm_factor,
j_blue_estimator):
# Used for initialization
if len(j_blue_estimator) == 0:
return JBluesDiluteBlackBody.calculate(lines, nu, t_rad, w)
else:
j_blues = pd.DataFrame(
j_blue_estimator *
j_blues_norm_factor.value,
index=lines.index,
columns=np.arange(len(t_rad)))

for i in xrange(len(j_blues)):
zero_j_blues = j_blues[i] == 0.0
j_blues[i][zero_j_blues] = (
self.w_epsilon *
intensity_black_body(lines.nu[zero_j_blues].values,
t_rad.value[i]))
return j_blues


class JBluesNormFactor(ProcessingPlasmaProperty):

outputs = ('j_blues_norm_factor',)
latex = ('\\frac{c time_\\textrm{simulation}}}{4 \\pi '
'time_\\textrm{simulation} volume}')

@staticmethod
def calculate(time_explosion, time_simulation, volume):
return (const.c.cgs * time_explosion /
(4 * np.pi * time_simulation * volume))


class JBluesEstimator(DataFrameInput):
outputs = ('j_blue_estimator',)
11 changes: 10 additions & 1 deletion tardis/plasma/properties/plasma_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__all__ = ['TRadiative', 'DilutionFactor', 'AtomicData', 'Abundance', 'Density',
'TimeExplosion', 'JBlueEstimator', 'LinkTRadTElectron',
'HeliumTreatment']
'HeliumTreatment', 'RInner', 'TInner', 'Volume']

class TRadiative(ArrayInput):
"""
Expand Down Expand Up @@ -95,3 +95,12 @@ class LinkTRadTElectron(Input):

class HeliumTreatment(Input):
outputs = ('helium_treatment',)

class RInner(Input):
outputs = ('r_inner',)

class TInner(Input):
outputs = ('t_inner',)

class Volume(Input):
outputs = ('volume',)
6 changes: 5 additions & 1 deletion tardis/plasma/properties/property_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ class PlasmaPropertyCollection(list):
helium_lte_properties = PlasmaPropertyCollection([LevelNumberDensity,
IonNumberDensity])
helium_numerical_nlte_properties = PlasmaPropertyCollection([
HeliumNumericalNLTE])
HeliumNumericalNLTE])
detailed_j_blues_properties = PlasmaPropertyCollection([JBluesDetailed,
JBluesNormFactor,
LuminosityInner,
TimeSimulation])
12 changes: 8 additions & 4 deletions tardis/plasma/standard_plasmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
macro_atom_properties, dilute_lte_excitation_properties,
nebular_ionization_properties, non_nlte_properties,
nlte_properties, helium_nlte_properties, helium_numerical_nlte_properties,
helium_lte_properties)
helium_lte_properties, detailed_j_blues_properties)
from tardis.plasma.exceptions import PlasmaConfigError
from tardis.plasma.properties import (LevelBoltzmannFactorNLTE, JBluesBlackBody,
JBluesDiluteBlackBody)
JBluesDiluteBlackBody, JBluesDetailed)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,8 +86,12 @@ def assemble_plasma(config, model, atom_data=None):
elif config.plasma.radiative_rates_type == 'dilute-blackbody':
plasma_modules.append(JBluesDiluteBlackBody)
elif config.plasma.radiative_rates_type == 'detailed':
# FIXME: Detailed j_blues not implemented after restructure.
raise NotImplementedError("Detailed mode not implemented yet.")
plasma_modules += detailed_j_blues_properties
kwargs.update(r_inner=model.r_inner,
t_inner=model.t_inner,
volume=model.volume,
j_blue_estimator=None)
property_kwargs[JBluesDetailed] = {'w_epsilon': config.plasma.w_epsilon}
else:
raise ValueError('radiative_rates_type type unknown - %s',
config.plasma.radiative_rates_type)
Expand Down
10 changes: 9 additions & 1 deletion tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@ def advance_state(self):
# model.update_plasmas() equivalent
# TODO: if nlte_config is not None and nlte_config.species:
# self.store_previous_properties()
self.plasma.update(t_rad=self.model.t_rad, w=self.model.w)

update_properties = dict(t_rad=self.model.t_rad, w=self.model.w)
# A check to see if the plasma is set with JBluesDetailed, in which
# case it needs some extra kwargs.
if 'j_blue_estimator' in self.plasma.outputs_dict:
update_properties.update(t_inner=next_t_inner,
j_blue_estimator=self.runner.j_blue_estimator)

self.plasma.update(**update_properties)

return converged

Expand Down

0 comments on commit 48ceb8c

Please sign in to comment.