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

Restructure/detailed balance foundation #2770

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d583510
change numberdensity to input
wkerzendorf Apr 30, 2024
7aaba5d
fixed number density
wkerzendorf May 4, 2024
32b22ea
some fixes
wkerzendorf May 5, 2024
261bbad
removing density
wkerzendorf May 6, 2024
df3c406
remove atomic and isotope mass
wkerzendorf May 6, 2024
d05e819
add isotopic_number_density
wkerzendorf May 6, 2024
61f3db5
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf May 6, 2024
e804942
add opacities package
wkerzendorf May 6, 2024
e573f16
Update imports in property_collections.py, base.py, test_numba_interf…
wkerzendorf May 7, 2024
73f2ddc
Add calculate_transition_probabilities function to util.py in macro_a…
wkerzendorf May 7, 2024
52d5523
Add calculate_transition_probabilities function to util.py in macro_a…
wkerzendorf May 9, 2024
9530fee
Remove unused imports and update plasma properties
wkerzendorf May 9, 2024
2fb7f92
add __init__ to macroatom
wkerzendorf May 9, 2024
6ac3e88
blackify tardis
wkerzendorf May 10, 2024
801c92b
blackified
wkerzendorf May 10, 2024
ae0650d
chore: Update imports and remove unused code
wkerzendorf May 10, 2024
69dc1b5
chore: Add PlanckRadiationField and DilutePlanckRadiationField classes
wkerzendorf May 10, 2024
448d5c4
chore: Update imports and remove unused code
wkerzendorf May 10, 2024
c1dc52d
removed density
wkerzendorf May 13, 2024
f053967
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf May 20, 2024
17c033c
Merge branch 'restructure/plasma_prepare' into restructure/plasma_opa…
wkerzendorf May 23, 2024
5e02054
ruff output
wkerzendorf Jun 6, 2024
28c4348
cleanup and adding object mode
wkerzendorf Jun 6, 2024
cfffe5b
starting to make radiation_field a thing
wkerzendorf Jun 7, 2024
4e68723
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 7, 2024
41779e2
switched over to old tau_sobolev calculation
wkerzendorf Jun 9, 2024
0d1bc4d
renamed function to indicate numba use
wkerzendorf Jun 9, 2024
7cc84a2
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 9, 2024
c924749
address comments
wkerzendorf Jun 10, 2024
ad5a314
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 10, 2024
af7e39e
added dilute planckian radiation field
wkerzendorf Jun 11, 2024
36fa4b6
refactor: Convert species lists to proper format in assemble_plasma f…
wkerzendorf Jun 13, 2024
4bc0dd7
moved radiation field into plasma. Resulting in some renames
wkerzendorf Jun 14, 2024
863f281
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 19, 2024
2f042f2
some fixes
wkerzendorf Jun 19, 2024
d849f85
black montecarlo
wkerzendorf Jun 19, 2024
3379062
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jun 19, 2024
6feefbe
Merge branch 'restructure/plasma_opacities' into restructure/plasma_r…
wkerzendorf Jun 19, 2024
1786436
chore: Initialize atom data and simulation state in `initialization.py`
wkerzendorf Jun 19, 2024
5740708
updating the documentation
wkerzendorf Jun 19, 2024
92f4e90
feat: Add EstimatedRadiationFieldProperties class for Monte Carlo est…
wkerzendorf Jun 20, 2024
e3f1819
trying to get rid of j_blues in plasma with MC restructure
wkerzendorf Jun 21, 2024
a99fbb8
completely restructure j_blues. Estimators and all.
wkerzendorf Jun 22, 2024
2d7e1c5
cleanup for the restructure
wkerzendorf Jun 22, 2024
63e0e0c
Merge remote-tracking branch 'upstream/master' into restructure/plasm…
wkerzendorf Jul 23, 2024
818c6d4
remove parse_input.py
wkerzendorf Jul 23, 2024
3ec64f1
chore: Refactor radiation field configuration parsing and state creation
wkerzendorf Jul 23, 2024
f1f0cdd
revert astropy_helpers
wkerzendorf Jul 23, 2024
2a7d460
remove astropy_helpers
wkerzendorf Jul 23, 2024
dbc34ac
removed test.txt
wkerzendorf Jul 23, 2024
251d1cb
blackified code
wkerzendorf Jul 23, 2024
e80b15c
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 23, 2024
8581bed
Merge branch 'restructure/simulation_from_config_cleanup' into restru…
wkerzendorf Jul 23, 2024
d49a49c
cleanup simulation from merges
wkerzendorf Jul 23, 2024
adbaf7f
fix
wkerzendorf Jul 24, 2024
bb19fdb
remove unused Input
wkerzendorf Jul 24, 2024
aca1099
added description
wkerzendorf Jul 24, 2024
44ffcf9
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 24, 2024
54ffe68
blackiefied codebase
wkerzendorf Jul 24, 2024
71a2b13
Merge branch 'restructure/simulation_from_config_cleanup' into restru…
wkerzendorf Jul 24, 2024
2ea3122
cleanup of branch
wkerzendorf Jul 24, 2024
9800fc8
blackify code
wkerzendorf Jul 24, 2024
5914618
Merge branch 'restructure/plasma_radiation_field' into restructure/si…
wkerzendorf Jul 24, 2024
d19e423
chore: Refactor atom data parsing and simulation state initialization
wkerzendorf Jul 24, 2024
49b9819
Merge branch 'restructure/simulation_from_config_cleanup' into restru…
wkerzendorf Jul 24, 2024
b3bf356
restructure logger
wkerzendorf Jul 24, 2024
a22223e
Merge branch 'restructure/simulation_from_config_cleanup' into restru…
wkerzendorf Jul 24, 2024
734ffc8
working on continuum radfield properties
wkerzendorf Jul 24, 2024
d69533a
Refactor continuum processes module structure
wkerzendorf Jul 24, 2024
98f8340
Refactor opacities module structure
wkerzendorf Jul 24, 2024
84671ca
cleanup from restructure
wkerzendorf Jul 25, 2024
bf25313
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 25, 2024
7782d07
cleanup
wkerzendorf Jul 25, 2024
cfc5078
clean up
wkerzendorf Jul 25, 2024
ee864bb
more cleanup
wkerzendorf Jul 25, 2024
ad4f1b1
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 25, 2024
0ebcef8
cleanup standard_plasmas.py
wkerzendorf Jul 25, 2024
cf1396a
working nlte ionizations
wkerzendorf Jul 26, 2024
557dde9
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 26, 2024
fcf2563
start of assemble plasma cleanup
wkerzendorf Jul 26, 2024
8324074
cleanup standard_plasmas.py
wkerzendorf Jul 26, 2024
60239f8
updated tests
wkerzendorf Jul 26, 2024
5e4902a
some more cleanup
wkerzendorf Jul 26, 2024
9f92256
fix benchmarks
wkerzendorf Jul 26, 2024
3c7ee67
cleanup assembly
wkerzendorf Jul 26, 2024
0890747
cleanup assembly
wkerzendorf Jul 26, 2024
cd1badc
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 26, 2024
7540e55
working on the restructure
wkerzendorf Jul 26, 2024
bd04642
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 26, 2024
e29ae22
slowly fixing the assembly module
wkerzendorf Jul 27, 2024
930462f
blackify
wkerzendorf Jul 27, 2024
9e47b81
reverse the import pygraphviz
wkerzendorf Jul 27, 2024
8d67db8
fix docstrings
wkerzendorf Jul 27, 2024
f6f3160
fixed all plasma
wkerzendorf Jul 27, 2024
7f1c301
slow fixes
wkerzendorf Jul 27, 2024
e05aeca
Refactor recomb_rate_coeff.py and test_continuum_property_solver.py
wkerzendorf Jul 27, 2024
efdb5b1
fixing assembly
wkerzendorf Jul 27, 2024
9078307
restructure the read in
wkerzendorf Jul 27, 2024
683e811
fixup plasma assemble to be clean
wkerzendorf Jul 27, 2024
d381f02
fix shell info widget
wkerzendorf Jul 27, 2024
fcce9e0
fix the widgets
wkerzendorf Jul 28, 2024
ac141ec
fixing hopefully last bugs
wkerzendorf Jul 28, 2024
01b4df7
slowly fix up assembly
wkerzendorf Jul 28, 2024
4ba4afb
working on getting the notebook running
wkerzendorf Jul 29, 2024
7d8e6e0
Refactor code to address comments
wkerzendorf Jul 29, 2024
03e1aae
Merge branch 'restructure/base_estimator_cleanup' into restructure/as…
wkerzendorf Jul 29, 2024
7cb89bb
feat: Add RadiativeRatesSolver class for detailed balance rates calcu…
wkerzendorf Jul 30, 2024
3e7d82c
feat: Add solve method to RadiativeRatesSolver class
wkerzendorf Jul 30, 2024
521c808
add rates ipynb
wkerzendorf Jul 30, 2024
9f93d84
remove abundance
wkerzendorf Jul 30, 2024
f130046
feat: Refactor code to improve readability and maintainability
wkerzendorf Jul 30, 2024
f9ba888
first commit of the rates solver working
wkerzendorf Jul 31, 2024
e393365
fix up detailed balance foundation
wkerzendorf Jul 31, 2024
b5839a6
Merge remote-tracking branch 'upstream/master' into restructure/assem…
wkerzendorf Jul 31, 2024
c61ac3d
Merge branch 'restructure/assemble_plasma_cleanup' into restructure/d…
wkerzendorf Jul 31, 2024
3627811
further work on including the rates
wkerzendorf Aug 6, 2024
25973be
including the new rates structure
wkerzendorf Aug 6, 2024
c6eeff1
getting the rates ready
wkerzendorf Aug 6, 2024
37930ce
feat: Refactor collision_rates module to improve code organization an…
wkerzendorf Aug 7, 2024
f2ebb65
further work on collisional strengths
wkerzendorf Aug 7, 2024
3206dbe
further work on the collisional cross sections
wkerzendorf Aug 8, 2024
4a4aa47
further work o nthe collisional rates
wkerzendorf Aug 8, 2024
feaeb9a
feat: Add ThermalCollisionalRateSolver class for calculating thermal …
wkerzendorf Aug 8, 2024
ab2cf5c
further fixes
wkerzendorf Aug 12, 2024
9d593dc
further testing
wkerzendorf Aug 12, 2024
4d98e92
Merge remote-tracking branch 'upstream/master' into restructure/detai…
wkerzendorf Aug 13, 2024
95e4cef
refactor: Refactor collisional rates calculation in ThermalCollisiona…
wkerzendorf Aug 13, 2024
16327b3
finished collisional_rates
wkerzendorf Aug 13, 2024
c2aee79
Fixes collisional rates test so it can run (still fails)
andrewfullard Sep 24, 2024
cbcd089
Correct de-excitation rate calculation
andrewfullard Sep 24, 2024
75926c0
Merge branch 'master' into pr/wkerzendorf/2770
andrewfullard Sep 25, 2024
1aad3c7
Merge branch 'master' into pr/wkerzendorf/2770
andrewfullard Sep 30, 2024
0121ba8
Add Chianti upsilon solver
andrewfullard Sep 30, 2024
fd5d612
Docstrings and better variable names
andrewfullard Sep 30, 2024
45a5d63
Fix rename error
andrewfullard Oct 1, 2024
9f53bfa
Comparison notebook between Chianti, CMFGEN et al.
andrewfullard Oct 1, 2024
948247b
Add reference data and config, save notebook with plots
andrewfullard Oct 1, 2024
6edb432
Chianti test beginnings
andrewfullard Oct 1, 2024
0d4005b
Working tests
andrewfullard Oct 7, 2024
d62f96d
Up to date comparison notebook
andrewfullard Oct 7, 2024
072b7b0
Remove irrelevant change
andrewfullard Oct 7, 2024
7be9ed6
Corrected changes to the plasma solver factory
andrewfullard Oct 7, 2024
f53d429
Merge branch 'master' into pr/wkerzendorf/2770
andrewfullard Oct 7, 2024
571356d
Partially fixes tests
andrewfullard Oct 8, 2024
35f09c2
Slightly dirty fix for electron densities not refreshing properly
andrewfullard Oct 8, 2024
30c89cc
Fix NLTE tests by passing electron densities as an option input to th…
andrewfullard Oct 9, 2024
71cc456
Ruff formatting
andrewfullard Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
2,132 changes: 2,132 additions & 0 deletions docs/physics/plasma/detailed_balance/comparison.ipynb

Large diffs are not rendered by default.

1,419 changes: 1,419 additions & 0 deletions docs/physics/plasma/detailed_balance/rates.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Example YAML configuration for TARDIS
tardis_config_version: v1.0

supernova:
time_explosion: 16 day

atom_data: TestNLTE_He_Ti.h5

model:
structure:
type: specific
velocity:
start: 5700 km/s
stop: 12500 km/s
num: 10
density:
type : power_law
time_0: 16.0 day
rho_0: 1.3636e-14 g/cm^3 #1.948e-14 g/cm^3
v_0: 8000 km/s
exponent: -10

abundances:
type: uniform
H: 1.0

plasma:
initial_t_inner: 9000 K
ionization: nebular
excitation: dilute-lte
radiative_rates_type: dilute-blackbody
line_interaction_type: macroatom
#nlte:
# species:
# - H I
continuum_interaction:
species:
- H I
nlte_ionization_species:
- H I
nlte_excitation_species:
- H I

montecarlo:
seed: 23111963
no_of_packets: 500000
iterations: 1
nthreads: 1

last_no_of_packets: 100000
no_of_virtual_packets: 0

convergence_strategy:
type: damped
damping_constant: 0.5
threshold: 0.05
fraction: 0.8
hold_iterations: 3


spectrum:
start: 800 angstrom
stop: 10000 angstrom
num: 4000
119 changes: 32 additions & 87 deletions tardis/plasma/assembly/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,81 +55,24 @@ def map_species_from_string(species):
return [species_string_to_tuple(spec) for spec in species]


class PlasmaSolverFactory:
"""Factory class for creating plasma solvers.

atom_data : object
Object containing atomic data.
selected_atomic_numbers : list
List of selected atomic numbers.

Attributes
----------
excitation_analytical_approximation : str
Analytical approximation for excitation (default: "lte").
ionization_analytical_approximation : str
Analytical approximation for ionization (default: "lte").
nebular_ionization_delta_treatment : tuple
Species to use for the delta_treatment in nebular ionization ML93 (default: ()).
link_t_rad_t_electron : float
Link between t_rad and t_electron (default: 1.0).
radiative_rates_type : str
Type of radiative rates (default: "dilute-blackbody").
delta_treatment : float or None
Delta treatment (default: None).
legacy_nlte_species : list
List of legacy non-LTE species (default: []).
nlte_excitation_species : list
List of non-LTE excitation species (default: []).
nlte_ionization_species : list
List of non-LTE ionization species (default: []).
nlte_solver : str
Non-LTE solver (default: "lu").
Helium treatment options (default: "none").
heating_rate_data_file : str
Heating rate data file (default: "none").
continuum_interaction_species : list
List of continuum interaction species (default: []).
enable_adiabatic_cooling : bool
Flag for enabling adiabatic cooling (default: False).
enable_two_photon_decay : bool
Flag for enabling two-photon decay (default: False).
line_interaction_type : str
Type of line interaction (default: "scatter").
plasma_modules : list
List of plasma modules (default: []).
kwargs : dict
Additional keyword arguments (default: {}).
property_kwargs : dict
Additional keyword arguments for properties (default: {}).

Methods
-------
parse_plasma_config(plasma_config)
continuum_interaction_species_multi_index()
Get the continuum interaction species as a multi-index.
setup_factory(config)
setup_helium_treatment()
setup_legacy_nlte(nlte_config)
Set up the non-LTE properties for the legacy species.
setup_analytical_approximations()
Set up the analytical approximations for excitation and ionization.
initialize_j_blues(dilute_planckian_radiation_field, lines_df)
Initialize j_blues.
"""
def convert_species_to_multi_index(species_strs):
return pd.MultiIndex.from_tuples(
map_species_from_string(species_strs),
names=["atomic_number", "ion_number"],
)


class PlasmaSolverFactory:
## Analytical Approximations
excitation_analytical_approximation: str = "lte"
ionization_analytical_approximation: str = "lte"
nebular_ionization_delta_treatment: (
tuple
) = () # species to use for the delta_treatment in nebular ionization ML93
nebular_ionization_delta_treatment: tuple # species to use for the delta_treatment in nebular ionization ML93

link_t_rad_t_electron: float = 1.0

radiative_rates_type: str = "dilute-blackbody"

delta_treatment: float | None = None
delta_treatment = None

## Statistical Balance Solver
legacy_nlte_species: list = []
Expand All @@ -155,26 +98,19 @@ class PlasmaSolverFactory:
kwargs: dict = {}
property_kwargs: dict = {}

def __init__(self, atom_data, selected_atomic_numbers, config=None) -> None:
self.plasma_modules = []
self.kwargs = {}
self.property_kwargs = {}

def __init__(
self,
atom_data,
config=None,
) -> None:
if config is not None:
self.parse_plasma_config(config.plasma)
self.atom_data = atom_data
self.atom_data.prepare_atom_data(
selected_atomic_numbers,
line_interaction_type=self.line_interaction_type,
continuum_interaction_species=self.continuum_interaction_species_multi_index,
nlte_species=self.legacy_nlte_species,
)

@property
def continuum_interaction_species_multi_index(self):
return pd.MultiIndex.from_tuples(
map_species_from_string(self.continuum_interaction_species),
names=["atomic_number", "ion_number"],
return convert_species_to_multi_index(
self.continuum_interaction_species
)

def parse_plasma_config(self, plasma_config):
Expand Down Expand Up @@ -218,7 +154,7 @@ def parse_plasma_config(self, plasma_config):
plasma_config.continuum_interaction.enable_two_photon_decay
)

def setup_factory(self, config=None):
def prepare_factory(self, selected_atomic_numbers, config=None):
"""
Set up the plasma factory.

Expand All @@ -227,6 +163,13 @@ def setup_factory(self, config=None):
config : object, optional
Configuration object containing plasma settings (default: None).
"""
self.atom_data.prepare_atom_data(
selected_atomic_numbers,
line_interaction_type=self.line_interaction_type,
continuum_interaction_species=self.continuum_interaction_species_multi_index,
nlte_species=self.legacy_nlte_species,
)

self.check_continuum_interaction_species()

self.plasma_modules = basic_inputs + basic_properties
Expand Down Expand Up @@ -590,6 +533,7 @@ def assemble(
dilute_planckian_radiation_field,
time_explosion,
electron_densities=None,
**kwargs,
):
"""
Assemble the plasma based on the provided parameters and settings.
Expand Down Expand Up @@ -622,7 +566,7 @@ def assemble(
RADIATIVE_RATES_TYPE=self.radiative_rates_type
)

kwargs = dict(
plasma_assemble_kwargs = dict(
time_explosion=time_explosion,
dilute_planckian_radiation_field=dilute_planckian_radiation_field,
number_density=number_densities,
Expand All @@ -633,12 +577,11 @@ def assemble(
nlte_ionization_species=self.nlte_ionization_species,
nlte_excitation_species=self.nlte_excitation_species,
)

if len(self.continuum_interaction_species) > 0:
initial_continuum_properties = self.initialize_continuum_properties(
dilute_planckian_radiation_field
)
kwargs.update(
plasma_assemble_kwargs.update(
gamma=initial_continuum_properties.photo_ionization_rate_coefficient,
bf_heating_coeff_estimator=None,
stim_recomb_cooling_coeff_estimator=None,
Expand All @@ -647,11 +590,13 @@ def assemble(

if electron_densities is not None:
electron_densities = pd.Series(electron_densities.cgs.value)
self.setup_electron_densities(electron_densities)
kwargs["helium_treatment"] = self.helium_treatment

self.setup_electron_densities(electron_densities)
plasma_assemble_kwargs["helium_treatment"] = self.helium_treatment
plasma_assemble_kwargs.update(kwargs)
return BasePlasma(
plasma_properties=self.plasma_modules,
property_kwargs=self.property_kwargs,
plasma_solver_settings=plasma_solver_settings,
**kwargs,
**plasma_assemble_kwargs,
)
3 changes: 1 addition & 2 deletions tardis/plasma/assembly/legacy_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def assemble_plasma(config, simulation_state, atom_data=None):
atomic_numbers = simulation_state.abundance.index
plasma_solver_factory = PlasmaSolverFactory(
atom_data,
atomic_numbers,
config,
)
plasma_solver_factory.setup_factory(config)
plasma_solver_factory.prepare_factory(atomic_numbers, config)
dilute_planckian_radiation_field = DilutePlanckianRadiationField(
simulation_state.t_radiative, simulation_state.dilution_factor
)
Expand Down
Empty file.
10 changes: 10 additions & 0 deletions tardis/plasma/detailed_balance/rates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tardis.plasma.detailed_balance.rates.collision_strengths import (
UpsilonCMFGENSolver,
UpsilonRegemorterSolver,
)
from tardis.plasma.detailed_balance.rates.collisional_rates import (
ThermalCollisionalRateSolver,
)
from tardis.plasma.detailed_balance.rates.radiative_rates import (
RadiativeRatesSolver,
)
Loading
Loading