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

Ionization rates #2897

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
379 changes: 379 additions & 0 deletions docs/physics/plasma/equilibrium/tardis_solver_cmfgen.ipynb

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions tardis/plasma/equilibrium/rates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
UpsilonCMFGENSolver,
UpsilonRegemorterSolver,
)
from tardis.plasma.equilibrium.rates.collisional_ionization_rates import (
CollisionalIonizationSolver,
)
from tardis.plasma.equilibrium.rates.collisional_ionization_strengths import (
CollisionalIonizationSeaton,
)
from tardis.plasma.equilibrium.rates.collisional_rates import (
ThermalCollisionalRateSolver,
)
from tardis.plasma.equilibrium.rates.photoionization_strengths import (
AnalyticPhotoionizationCoeffSolver,
EstimatedPhotoionizationCoeffSolver,
SpontaneousRecombinationCoeffSolver,
)
from tardis.plasma.equilibrium.rates.radiative_rates import (
RadiativeRatesSolver,
)
50 changes: 50 additions & 0 deletions tardis/plasma/equilibrium/rates/collisional_ionization_rates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from tardis.plasma.equilibrium.rates.collisional_ionization_strengths import (
CollisionalIonizationSeaton,
)


class CollisionalIonizationSolver:
"""Solver for collisional ionization and recombination rates."""

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

def solve(self, electron_temperature, saha_factor, approximation="seaton"):
"""Solve the collisional ionization and recombination rates.

Parameters
----------
electron_temperature : u.Quantity
Electron temperatures per cell
saha_factor : pandas.DataFrame, dtype float
The Saha factor for each cell. Indexed by atom number, ion number, level number.
approximation : str, optional
The rate approximation to use, by default "seaton"

Returns
-------
pd.DataFrame
Collisional ionization rates
pd.DataFrame
Collisional recombination rates

Raises
------
ValueError
If an unsupported approximation is requested.
"""
if approximation == "seaton":
strength_solver = CollisionalIonizationSeaton(
self.photoionization_cross_sections, electron_temperature
)
else:
raise ValueError(f"approximation {approximation} not supported")

collision_ionization_rates = strength_solver.solve()

# Inverse of the ionization rate for equilibrium
collision_recombination_rates = collision_ionization_rates.multiply(
saha_factor.loc[collision_ionization_rates.index]
)

return collision_ionization_rates, collision_recombination_rates
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import numpy as np
import pandas as pd

from tardis import constants as const

H = const.h.cgs.value
K_B = const.k_B.cgs.value


class CollisionalIonizationSeaton:
"""Solver for collisional ionization rates in the Seaton approximation."""

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

def solve(self, electron_temperature):
"""
Parameters
----------
electron_temperature : u.Quantity
The electron temperature in K.

Returns
-------
pandas.DataFrame, dtype float
The rate coefficient for collisional ionization in the Seaton
approximation. Multiply with the electron density and the
level number density to obtain the total rate.

Notes
-----
The rate coefficient for collisional ionization in the Seaton approximation
is calculated according to Eq. 9.60 in [1].

References
----------
.. [1] Hubeny, I. and Mihalas, D., "Theory of Stellar Atmospheres". 2014.
"""
photo_ion_cross_sections_threshold = (
self.photoionization_cross_sections.groupby(level=[0, 1, 2]).first()
)
nu_i = photo_ion_cross_sections_threshold["nu"]
u0s = nu_i.values[np.newaxis].T / electron_temperature * (H / K_B)
factor = np.exp(-u0s) / u0s
factor = pd.DataFrame(factor, index=nu_i.index)
coll_ion_coeff = 1.55e13 * photo_ion_cross_sections_threshold["x_sect"]
coll_ion_coeff = factor.multiply(coll_ion_coeff, axis=0)
coll_ion_coeff = coll_ion_coeff.divide(
np.sqrt(electron_temperature), axis=1
)

ion_number = coll_ion_coeff.index.get_level_values("ion_number").values
coll_ion_coeff[ion_number == 0] *= 0.1
coll_ion_coeff[ion_number == 1] *= 0.2
coll_ion_coeff[ion_number >= 2] *= 0.3
return coll_ion_coeff
61 changes: 61 additions & 0 deletions tardis/plasma/equilibrium/rates/photoionization_rates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from tardis.plasma.equilibrium.rates.photoionization_strengths import (
AnalyticPhotoionizationCoeffSolver,
EstimatedPhotoionizationCoeffSolver,
SpontaneousRecombinationCoeffSolver,
)


class PhotoionizationRateSolver:
def __init__(
self, photoionization_cross_sections, level2continuum_edge_idx
):
self.photoionization_cross_sections = photoionization_cross_sections
self.level2continuum_edge_idx = level2continuum_edge_idx

def solve(
self, electron_temperature, n_i, n_k, n_e, saha_factor, type="analytic"
):
if type == "analytic":
# TODO: try merging the analytic and estimator based approaches
# look at the Lucy 2003 equations and our MC estimator classes
photoionization_rate_coeff_solver = (
AnalyticPhotoionizationCoeffSolver(
self.photoionization_cross_sections
)
)
elif type == "estimated":
photoionization_rate_coeff_solver = (
EstimatedPhotoionizationCoeffSolver(
self.level2continuum_edge_idx
)
)
else:
raise ValueError(f"Type {type} not supported")

spontaneous_recombination_rate_coeff_solver = (
SpontaneousRecombinationCoeffSolver(
self.photoionization_cross_sections
)
)

photoionization_rate_coeff, stimulated_recombination_rate_coeff = (
# TODO: bifurcation of classes here is a problem
photoionization_rate_coeff_solver.solve()
)

spontaneous_recombination_rate_coeff = (
spontaneous_recombination_rate_coeff_solver.solve(
electron_temperature
)
)

# TODO: decide if these n_i, n_k, n_e numbers should be here (probably not)
photoionization_rate = (
photoionization_rate_coeff * n_i
- saha_factor * stimulated_recombination_rate_coeff * n_k * n_e
)
spontaneous_recombination_rate = (
saha_factor * spontaneous_recombination_rate_coeff * n_k * n_e
)

return photoionization_rate, spontaneous_recombination_rate
Loading
Loading