-
-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Restructure/plasma] estimator cleanup (#2675)
* change numberdensity to input * fixed number density * some fixes * removing density * remove atomic and isotope mass * add isotopic_number_density * add opacities package * Update imports in property_collections.py, base.py, test_numba_interface.py, transport_montecarlo_numba_interface.py, conftest.py, formal_integral.py, base.py, and macro_atom.py * Add calculate_transition_probabilities function to util.py in macro_atom package * Add calculate_transition_probabilities function to util.py in macro_atom package * Remove unused imports and update plasma properties * add __init__ to macroatom * blackify tardis * blackified * chore: Update imports and remove unused code * chore: Add PlanckRadiationField and DilutePlanckRadiationField classes * chore: Update imports and remove unused code * removed density * ruff output * cleanup and adding object mode * starting to make radiation_field a thing * switched over to old tau_sobolev calculation * renamed function to indicate numba use * address comments * added dilute planckian radiation field * refactor: Convert species lists to proper format in assemble_plasma function * moved radiation field into plasma. Resulting in some renames * some fixes * black montecarlo * chore: Initialize atom data and simulation state in `initialization.py` * updating the documentation * feat: Add EstimatedRadiationFieldProperties class for Monte Carlo estimators * trying to get rid of j_blues in plasma with MC restructure * completely restructure j_blues. Estimators and all. * cleanup for the restructure * remove parse_input.py * chore: Refactor radiation field configuration parsing and state creation Refactor the `parse_radiation_field_configuration.py` module to improve code organization and readability. Update the import statements to reflect the changes in the module structure. Replace the deprecated `DiluteBlackBodyRadiationFieldState` class with the new `DilutePlanckianRadiationField` class from the `tardis.plasma.radiation_field` module. This change ensures consistency and compatibility with the latest codebase. Also, update the `tardis/simulation/base.py` module to import the `DilutePlanckianRadiationField` class from the `tardis.plasma.radiation_field` module. This change ensures that the correct class is used for creating the radiation field in the simulation. * revert astropy_helpers * remove astropy_helpers * removed test.txt * blackified code * cleanup simulation from merges * fix * remove unused Input * added description * blackiefied codebase * cleanup of branch * blackify code * chore: Refactor atom data parsing and simulation state initialization * restructure logger * working on continuum radfield properties * Refactor continuum processes module structure * Refactor opacities module structure * cleanup from restructure * cleanup * clean up * more cleanup * cleanup standard_plasmas.py * working nlte ionizations * some more cleanup * fix benchmarks * blackify * reverse the import pygraphviz * fix docstrings * Refactor code to address comments
- Loading branch information
1 parent
f84a4be
commit 9339cd2
Showing
35 changed files
with
705 additions
and
765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from tardis.plasma.exceptions import PlasmaException | ||
from tardis.plasma.properties.base import ProcessingPlasmaProperty | ||
|
||
|
||
class BoundFreeOpacity(ProcessingPlasmaProperty): | ||
""" | ||
Attributes | ||
---------- | ||
chi_bf : pandas.DataFrame, dtype float | ||
Bound-free opacity corrected for stimulated emission. | ||
""" | ||
|
||
outputs = ("chi_bf",) | ||
latex_name = (r"\chi^{\textrm{bf}}",) | ||
|
||
def calculate( | ||
self, | ||
photo_ion_cross_sections, | ||
t_electrons, | ||
phi_ik, | ||
level_number_density, | ||
lte_level_number_density, | ||
boltzmann_factor_photo_ion, | ||
): | ||
cross_section = photo_ion_cross_sections["x_sect"].values | ||
|
||
n_i = level_number_density.loc[photo_ion_cross_sections.index] | ||
lte_n_i = lte_level_number_density.loc[photo_ion_cross_sections.index] | ||
chi_bf = (n_i - lte_n_i * boltzmann_factor_photo_ion).multiply( | ||
cross_section, axis=0 | ||
) | ||
|
||
num_neg_elements = (chi_bf < 0).sum().sum() | ||
if num_neg_elements: | ||
raise PlasmaException("Negative values in bound-free opacity.") | ||
return chi_bf |
Empty file.
94 changes: 94 additions & 0 deletions
94
tardis/opacities/macro_atom/continuum_processes/collisional_ion_trans_prob.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import pandas as pd | ||
|
||
from tardis import constants as const | ||
from tardis.plasma.properties.base import ( | ||
TransitionProbabilitiesProperty, | ||
) | ||
from tardis.plasma.properties.continuum_processes.rates import ( | ||
IndexSetterMixin, | ||
) | ||
|
||
H = const.h.cgs.value | ||
|
||
|
||
class RawCollIonTransProbs(TransitionProbabilitiesProperty, IndexSetterMixin): | ||
""" | ||
Attributes | ||
---------- | ||
p_coll_ion : pandas.DataFrame, dtype float | ||
The unnormalized transition probabilities for | ||
collisional ionization. | ||
p_coll_recomb : pandas.DataFrame, dtype float | ||
The unnormalized transition probabilities for | ||
collisional recombination. | ||
cool_rate_coll_ion : pandas.DataFrame, dtype float | ||
The collisional ionization cooling rates of the electron gas. | ||
""" | ||
|
||
outputs = ("p_coll_ion", "p_coll_recomb", "cool_rate_coll_ion") | ||
transition_probabilities_outputs = ( | ||
"p_coll_ion", | ||
"p_coll_recomb", | ||
"cool_rate_coll_ion", | ||
) | ||
latex_name = ( | ||
r"p^{\textrm{coll ion}}", | ||
r"p^{\textrm{coll recomb}}", | ||
r"C^{\textrm{ion}}", | ||
) | ||
|
||
def calculate( | ||
self, | ||
coll_ion_coeff, | ||
coll_recomb_coeff, | ||
nu_i, | ||
photo_ion_idx, | ||
electron_densities, | ||
energy_i, | ||
level_number_density, | ||
): | ||
p_coll_ion = coll_ion_coeff.multiply(energy_i, axis=0) | ||
p_coll_ion = p_coll_ion.multiply(electron_densities, axis=1) | ||
p_coll_ion = self.set_index(p_coll_ion, photo_ion_idx, reverse=False) | ||
|
||
coll_recomb_rate = coll_recomb_coeff.multiply( | ||
electron_densities, axis=1 | ||
) # The full rate is obtained from this by multiplying by the | ||
# electron density and ion number density. | ||
p_recomb_deactivation = coll_recomb_rate.multiply(nu_i, axis=0) * H | ||
p_recomb_deactivation = self.set_index( | ||
p_recomb_deactivation, photo_ion_idx, transition_type=-1 | ||
) | ||
p_recomb_deactivation = p_recomb_deactivation.groupby(level=[0]).sum() | ||
index_dd = pd.MultiIndex.from_product( | ||
[p_recomb_deactivation.index.values, ["k"], [0]], | ||
names=list(photo_ion_idx.columns) + ["transition_type"], | ||
) | ||
p_recomb_deactivation = p_recomb_deactivation.set_index(index_dd) | ||
|
||
p_recomb_internal = coll_recomb_rate.multiply(energy_i, axis=0) | ||
p_recomb_internal = self.set_index( | ||
p_recomb_internal, photo_ion_idx, transition_type=0 | ||
) | ||
p_coll_recomb = pd.concat([p_recomb_deactivation, p_recomb_internal]) | ||
|
||
cool_rate_coll_ion = (coll_ion_coeff * electron_densities).multiply( | ||
nu_i * H, axis=0 | ||
) | ||
level_lower_index = coll_ion_coeff.index | ||
cool_rate_coll_ion = ( | ||
cool_rate_coll_ion | ||
* level_number_density.loc[level_lower_index].values | ||
) | ||
cool_rate_coll_ion = self.set_index( | ||
cool_rate_coll_ion, photo_ion_idx, reverse=False | ||
) | ||
cool_rate_coll_ion = cool_rate_coll_ion.groupby( | ||
level="destination_level_idx" | ||
).sum() | ||
ion_cool_index = pd.MultiIndex.from_product( | ||
[["k"], cool_rate_coll_ion.index.values, [0]], | ||
names=list(photo_ion_idx.columns) + ["transition_type"], | ||
) | ||
cool_rate_coll_ion = cool_rate_coll_ion.set_index(ion_cool_index) | ||
return p_coll_ion, p_coll_recomb, cool_rate_coll_ion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from tardis.plasma.properties.continuum_processes.photo_ion_rate_coeff import ( | ||
PhotoIonRateCoeff, | ||
) | ||
from tardis.plasma.properties.continuum_processes.rates import * | ||
from tardis.plasma.properties.continuum_processes.recomb_rate_coeff import ( | ||
StimRecombRateFactor, | ||
SpontRecombRateCoeff, | ||
StimRecombRateCoeff, | ||
) |
Oops, something went wrong.