Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading nlte_excitation_species from config #2195

Merged
merged 11 commits into from
Jan 31, 2023
42 changes: 41 additions & 1 deletion tardis/io/tests/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_plasma_nlte_section_config(tardis_config_verysimple_nlte):

Parameter
---------
`tardis_config_verysimple` : YAML File
`tardis_config_verysimple_nlte` : YAML File

Result
------
Expand Down Expand Up @@ -221,6 +221,46 @@ def test_plasma_nlte_section_config(tardis_config_verysimple_nlte):
assert ve.type is ValueError


def test_plasma_nlte_exc_section_config(tardis_config_verysimple_nlte):
"""
Configuration Validation Test for Plasma Section of the Tardis Config YAML File.

Validates:
nlte_excitation_species: should be included in continuum_interaction

Parameter
---------
`tardis_config_verysimple_nlte` : YAML File
sonachitchyan marked this conversation as resolved.
Show resolved Hide resolved

Result
------
Assertion based on validation for specified values
"""
conf = Configuration.from_config_dict(
tardis_config_verysimple_nlte, validate=True, config_dirname="test"
)
tardis_config_verysimple_nlte["plasma"]["continuum_interaction"][
"species"
] = [
"He I",
]
tardis_config_verysimple_nlte["plasma"]["nlte_excitation_species"] = ["H I"]
with pytest.raises(ValueError) as ve:
nlte_excitation_species = tardis_config_verysimple_nlte["plasma"][
"nlte_excitation_species"
]

for species in nlte_excitation_species:
if not (
species
in tardis_config_verysimple_nlte["plasma"][
"continuum_interaction"
]["species"]
):
raise ValueError("Nlte excitation species not in continuum.")
assert ve.type is ValueError
chvogl marked this conversation as resolved.
Show resolved Hide resolved


def test_spectrum_section_config(tardis_config_verysimple):
"""
Configuration Validation Test for Plasma Section of the Tardis Config YAML File
Expand Down
6 changes: 6 additions & 0 deletions tardis/plasma/properties/plasma_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"Volume",
"ContinuumInteractionSpecies",
"NLTEIonizationSpecies",
"NLTEExcitationSpecies",
]


Expand Down Expand Up @@ -154,3 +155,8 @@ class ContinuumInteractionSpecies(Input):
class NLTEIonizationSpecies(Input):

outputs = ("nlte_ionization_species",)


class NLTEExcitationSpecies(Input):

outputs = ("nlte_excitation_species",)
1 change: 1 addition & 0 deletions tardis/plasma/properties/property_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PlasmaPropertyCollection(list):
HeliumTreatment,
ContinuumInteractionSpecies,
NLTEIonizationSpecies,
NLTEExcitationSpecies,
]
)
basic_properties = PlasmaPropertyCollection(
Expand Down
12 changes: 10 additions & 2 deletions tardis/plasma/properties/rate_matrix_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
class NLTEIndexHelper(ProcessingPlasmaProperty):
outputs = ("rate_matrix_index",)

def __init__(self, plasma_parent, nlte_ionization_species=0):
def __init__(
self,
plasma_parent,
nlte_ionization_species=0,
nlte_excitation_species=0,
):
super().__init__(plasma_parent)
self.nlte_ionization_species = nlte_ionization_species
self.nlte_excitation_species = nlte_excitation_species

def calculate(self, levels, nlte_ionization_species):
def calculate(
self, levels, nlte_ionization_species, nlte_excitation_species
):
"""Generates rate_matrix_index using levels and changing the last index(level) to
"lte_ion" if that ion_number is treated in LTE or nebular, "nlte_ion" for NLTE ionization and
keeps the levels for the rest.
Expand Down
39 changes: 31 additions & 8 deletions tardis/plasma/standard_plasmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def assemble_plasma(config, model, atom_data=None):
species_string_to_tuple(s)
for s in config.plasma.nlte_ionization_species
]
nlte_excitation_species = [
species_string_to_tuple(s)
for s in config.plasma.nlte_excitation_species
]

kwargs = dict(
t_rad=model.t_radiative,
Expand All @@ -140,6 +144,7 @@ def assemble_plasma(config, model, atom_data=None):
link_t_rad_t_electron=config.plasma.link_t_rad_t_electron,
continuum_interaction_species=continuum_interaction_species,
nlte_ionization_species=nlte_ionization_species,
nlte_excitation_species=nlte_excitation_species,
)

plasma_modules = basic_inputs + basic_properties
Expand Down Expand Up @@ -175,15 +180,33 @@ def assemble_plasma(config, model, atom_data=None):
property_kwargs[MarkovChainTransProbsCollector] = {
"inputs": transition_probabilities_outputs
}
if config.plasma.nlte_ionization_species:
nlte_ionization_species = config.plasma.nlte_ionization_species
for species in nlte_ionization_species:
if not (species in config.plasma.continuum_interaction.species):
raise PlasmaConfigError(
f"NLTE ionization species {species} not in continuum species."
)
if (
config.plasma.nlte_ionization_species
or config.plasma.nlte_excitation_species
):
sonachitchyan marked this conversation as resolved.
Show resolved Hide resolved
nlte_ionization_species = []
nlte_excitation_species = []
chvogl marked this conversation as resolved.
Show resolved Hide resolved
if config.plasma.nlte_ionization_species:
nlte_ionization_species = config.plasma.nlte_ionization_species
for species in nlte_ionization_species:
if not (
species in config.plasma.continuum_interaction.species
):
raise PlasmaConfigError(
f"NLTE ionization species {species} not in continuum species."
)
if config.plasma.nlte_excitation_species:
nlte_excitation_species = config.plasma.nlte_excitation_species
for species in nlte_excitation_species:
if not (
species in config.plasma.continuum_interaction.species
):
raise PlasmaConfigError(
f"NLTE excitation species {species} not in continuum species."
)
property_kwargs[NLTEIndexHelper] = {
"nlte_ionization_species": nlte_ionization_species
"nlte_ionization_species": nlte_ionization_species,
"nlte_excitation_species": nlte_excitation_species,
}
plasma_modules += nlte_solver_properties

Expand Down