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/estimators #2500

Closed
wants to merge 199 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
314cf30
restructure of geometry
wkerzendorf Sep 28, 2023
d353133
add radial1d boundary logic
wkerzendorf Oct 4, 2023
2475551
black format
wkerzendorf Oct 4, 2023
e6d1697
several fixes
wkerzendorf Oct 4, 2023
3c53cda
fix epsilon
wkerzendorf Oct 4, 2023
6dce2b4
add testing of boundaries
wkerzendorf Oct 4, 2023
1fdcea8
change the r_inner_active
wkerzendorf Oct 4, 2023
56e9da5
first integration with `from_config` working
wkerzendorf Oct 7, 2023
f6743d7
hunting down density indexing bug
wkerzendorf Oct 8, 2023
b55b21d
all model tests (without csvy) pass
wkerzendorf Oct 8, 2023
ed978d9
more fixes
wkerzendorf Oct 9, 2023
cae9c19
fix of model to simulation_state
wkerzendorf Oct 9, 2023
d829e73
fix inner boundary packet error
wkerzendorf Oct 9, 2023
9592a97
fix some leftovers
wkerzendorf Oct 10, 2023
4da6869
final fix for csvy
wkerzendorf Oct 10, 2023
f381d2e
blackify
wkerzendorf Oct 10, 2023
e59741d
restructure to readers and remove some leftover code
wkerzendorf Oct 11, 2023
a42dd55
further cleanup
wkerzendorf Oct 11, 2023
3288c6c
first start of the restructure
wkerzendorf Oct 11, 2023
518a8f9
add comment about removing quantitiness
wkerzendorf Oct 11, 2023
c78b6de
add velocity check
wkerzendorf Oct 11, 2023
006ca9d
add new abundance functions
wkerzendorf Oct 12, 2023
9c680a8
remove default units
wkerzendorf Oct 12, 2023
268bd23
add new matter module
wkerzendorf Oct 12, 2023
6b03e93
several restructures. move decay from io to tardis/model/matter
wkerzendorf Oct 12, 2023
3114413
mid restructure
wkerzendorf Oct 13, 2023
217dcf2
slow progress on abundance refactor
wkerzendorf Oct 16, 2023
78055b4
include effective_element_masses
wkerzendorf Oct 22, 2023
73f5175
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Oct 22, 2023
b96d717
further updates
wkerzendorf Nov 2, 2023
08ea21d
fix of csvy readers
wkerzendorf Nov 2, 2023
f0fc7c2
last fixes to custom abundance widget
wkerzendorf Nov 4, 2023
fe7c415
restructuring the radiation field
wkerzendorf Nov 5, 2023
226fb57
some cleanup
wkerzendorf Nov 5, 2023
cbd025e
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
afb9613
cleanup
wkerzendorf Nov 5, 2023
daf12a5
further cleanup
wkerzendorf Nov 5, 2023
f2d26a8
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 5, 2023
7575512
clearnup
wkerzendorf Nov 5, 2023
dc34343
changes
wkerzendorf Nov 6, 2023
37d36e1
remove matter base.py
wkerzendorf Nov 8, 2023
4a77a4a
removing matter
wkerzendorf Nov 8, 2023
dbd47cc
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 8, 2023
f4be8c6
Fix zero division handling in normalize_trans_probs (which breaks to_…
chvogl Nov 10, 2023
f12775d
Use correct references_idx for levels
chvogl Nov 10, 2023
a9398ed
Convert probabilities to float64
chvogl Nov 10, 2023
d1792bf
fixed last tests
wkerzendorf Nov 20, 2023
c757848
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 20, 2023
1f42760
first commit for regression_data
wkerzendorf Nov 20, 2023
5b1c7b2
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
398631a
add several parsers
wkerzendorf Nov 20, 2023
ed60c0f
add composition
wkerzendorf Nov 20, 2023
8723fdf
remove isotopemassfractions
wkerzendorf Nov 20, 2023
08874ca
some small fixes
wkerzendorf Nov 20, 2023
d89b957
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 20, 2023
1da7ed0
fixed w, t_rad to dilution_factor, t_radiative
wkerzendorf Nov 20, 2023
9f28ecd
add setters for w, t_rad
wkerzendorf Nov 20, 2023
0d85540
several fixes for instantiating the right t_rads.
wkerzendorf Nov 21, 2023
7161791
add the from_config atom_data
wkerzendorf Nov 21, 2023
4f4aad6
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 21, 2023
f65a2d7
fixing model.ipynb
wkerzendorf Nov 21, 2023
cbfe685
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Nov 21, 2023
b961734
fix some more tests
wkerzendorf Nov 21, 2023
63a86fb
start of montecarlo restructure
wkerzendorf Nov 21, 2023
1d46d45
large scale changes
wkerzendorf Nov 22, 2023
9a21714
further disentangling state and solver
wkerzendorf Nov 23, 2023
1c38607
fix tests
wkerzendorf Nov 23, 2023
c99e9d4
fix some of the issues wdigets
wkerzendorf Nov 23, 2023
4c0b49a
assert mass fractions positive.
wkerzendorf Nov 23, 2023
7474e66
update estimators
wkerzendorf Nov 23, 2023
6735fad
add packet collection
wkerzendorf Nov 23, 2023
2135c5a
move spectrum to mct_state
wkerzendorf Nov 23, 2023
8e0de5c
add radiation_field_state
wkerzendorf Nov 23, 2023
ba9cdf6
Merge branch 'restructure/radiation_field' into restructure/transport…
wkerzendorf Nov 23, 2023
8fd5633
Refactor packet initialization in
wkerzendorf Nov 24, 2023
305e89d
Update model_nparray_attrs in test_base.py and fix
wkerzendorf Nov 24, 2023
de63d0f
Fix temperature assertion in
wkerzendorf Nov 24, 2023
0f4608a
Fix Integrator
wkerzendorf Nov 26, 2023
098cc76
Fix SDEC plot for MCTState
wkerzendorf Nov 26, 2023
455a820
Fix variable names in transport module
wkerzendorf Nov 26, 2023
9de8b34
Refactor the to_hdf code.
wkerzendorf Nov 27, 2023
5159c30
Refactor Monte Carlo transport solver
wkerzendorf Nov 27, 2023
fcd34bb
Fix isotope mass fraction typo and t_radiatve duplicate definition
wkerzendorf Nov 27, 2023
1e3a035
Document remove functionality for effective element masses
wkerzendorf Nov 27, 2023
af1f114
Fix variable name in
wkerzendorf Nov 27, 2023
203bae0
Refactor test names and variable names in
wkerzendorf Nov 27, 2023
56aaa8c
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 27, 2023
1f419b6
restructuring montecarlo state
wkerzendorf Nov 28, 2023
2a50667
Refactor gamma ray simulation setup and test
wkerzendorf Nov 29, 2023
b17b7c7
fix gamma ray tests
wkerzendorf Nov 29, 2023
a479cf6
Add model_isotope_time_0 property to abundances
wkerzendorf Nov 29, 2023
6d64b2d
Add test for montecarlo main loop with vpacket
wkerzendorf Nov 29, 2023
b92158d
Refactor config_reader and config_validator
wkerzendorf Nov 29, 2023
e56ddcc
Fix model_isotope_time_0 property in
wkerzendorf Nov 29, 2023
29fa091
Refactor simulation module to use pathlib
wkerzendorf Nov 29, 2023
8dff14e
remove bad comment and refactor with ruff
wkerzendorf Nov 29, 2023
fcb5dba
Fix variable name in test_simulation_state_mass()
wkerzendorf Nov 29, 2023
7da18f3
Fix unit conversion in calculate_cell_masses
wkerzendorf Nov 29, 2023
1bb7266
Fix logger debug message in CSV reader and update
wkerzendorf Nov 29, 2023
821f4ce
black formatting
wkerzendorf Nov 29, 2023
2257093
Refactor code to use composition variable in
wkerzendorf Nov 29, 2023
e105e71
Merge remote-tracking branch 'upstream/master' into restructure/abund…
wkerzendorf Nov 30, 2023
75840d3
Refactor imports in atom_web_download.py and
wkerzendorf Nov 30, 2023
59d5eff
fix for documentation not builiding
wkerzendorf Dec 4, 2023
1f65771
add fix for model_isotope_time_0
wkerzendorf Dec 4, 2023
dd6ba4f
fix grid test
wkerzendorf Dec 4, 2023
5391968
restructure the grid
wkerzendorf Dec 4, 2023
9706437
final change
wkerzendorf Dec 4, 2023
512d737
Merge branch 'restructure/abundance' into restructure/radiation_field
wkerzendorf Dec 4, 2023
c6d3a59
add stuff
wkerzendorf Dec 4, 2023
d9a191c
add vpacket_log
wkerzendorf Dec 4, 2023
ee4e6c6
transfer over to VPacketCollection constructor
wkerzendorf Dec 4, 2023
b31561e
Refactor model_reader.py and shell_info.py
wkerzendorf Dec 4, 2023
f438ec3
Update damping constants and variable names
wkerzendorf Dec 4, 2023
e7acaac
Refactor vpacket tracking in montecarlo_radial1d
wkerzendorf Dec 4, 2023
ef8cf30
fix w in several places in tardis
wkerzendorf Dec 4, 2023
361e0b7
slowly fixing radiation_field changes
wkerzendorf Dec 4, 2023
bfcf19a
fixing montecarlo tests
wkerzendorf Dec 4, 2023
d5cb35d
Merge remote-tracking branch 'origin/restructure/radiation_field' int…
wkerzendorf Dec 4, 2023
ca4b267
slowly fixing vpacket_tracker
wkerzendorf Dec 4, 2023
6244535
last fix
wkerzendorf Dec 4, 2023
3c8f3da
change hdf from model to simulation_state
wkerzendorf Dec 4, 2023
815b0d8
fixing model->simulation-state
wkerzendorf Dec 4, 2023
5925f6e
Merge remote-tracking branch 'upstream/master' into restructure/radia…
wkerzendorf Dec 4, 2023
81ebd21
Fix model_reader.py imports and formatting issues
wkerzendorf Dec 4, 2023
e24f1fa
Refactor variable names for clarity and
wkerzendorf Dec 4, 2023
50d3ec3
Update variable names in model.ipynb
wkerzendorf Dec 4, 2023
566d279
Update variable name for average temperature
wkerzendorf Dec 4, 2023
f068e64
Merge branch 'restructure/radiation_field' into restructure/transport…
wkerzendorf Dec 5, 2023
86a4974
Fix file paths in test_grid.py, test_base.py,
wkerzendorf Dec 5, 2023
145a9fc
Fix transport dictionary comparison
wkerzendorf Dec 5, 2023
871b849
Merge branch 'restructure/radiation_field' into tests/regression_data
wkerzendorf Dec 7, 2023
eb0e055
Implement regression data configurations
wkerzendorf Dec 9, 2023
d0c26dd
Refactor snapshot fixtures and add regression data
wkerzendorf Dec 9, 2023
67236a4
Update to new testing framework
wkerzendorf Dec 10, 2023
5e04422
Merge remote-tracking branch 'origin/restructure/radiation_field' int…
wkerzendorf Dec 10, 2023
e18bfe0
Refactor imports and fixtures in conftest.py and
wkerzendorf Dec 10, 2023
a68a006
Make regression-data optional
wkerzendorf Dec 10, 2023
f219356
Fix regression data synchronization in plasma
wkerzendorf Dec 10, 2023
a949f49
Refactor variable names in model reader and
wkerzendorf Dec 10, 2023
56a948d
Refactor store_model_to_hdf to
wkerzendorf Dec 10, 2023
2e6caac
Refactor HDF file handling and model reader
wkerzendorf Dec 11, 2023
1cc8004
add docstr
wkerzendorf Dec 11, 2023
e5dedcc
Merge branch 'restructure/radiation_field' into tests/regression_data
wkerzendorf Dec 11, 2023
537e7d3
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 11, 2023
051a62b
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 11, 2023
0044907
Merge remote-tracking branch 'upstream/master' into tests/regression_…
wkerzendorf Dec 11, 2023
f1151c3
Remove syrupy_extensions.py
wkerzendorf Dec 11, 2023
c85d64e
Refactor code and remove unused imports and
wkerzendorf Dec 14, 2023
dc1cffe
Merge remote-tracking branch 'upstream/master' into restructure/trans…
wkerzendorf Dec 15, 2023
5a902a4
Fix test_base and test_simulation
wkerzendorf Dec 15, 2023
a7c1c1e
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 15, 2023
b0e6eac
setting up regression with github actions
wkerzendorf Dec 15, 2023
6cc25b7
Update LFS cache IDs for refdata and regression
wkerzendorf Dec 16, 2023
ccf0a99
Fix test_montecarlo_radial1d function
wkerzendorf Dec 16, 2023
71f1317
Update sync_hdf_store method in RegressionData class
wkerzendorf Dec 16, 2023
0a1ae4a
Refactor test_base.py for improved accuracy and precision
wkerzendorf Dec 16, 2023
74cf7a2
update docstrings
wkerzendorf Dec 16, 2023
173b0f0
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 16, 2023
57d4055
Refactor transport state access in test_base.py
wkerzendorf Dec 20, 2023
fb09b33
Fix warnings and add HDF output in sdec_plot.ipynb and cleanup regres…
wkerzendorf Dec 20, 2023
3e86d61
Update demo.hdf file
wkerzendorf Dec 21, 2023
c9c9ee0
Fix negative values in last_interaction_types
wkerzendorf Dec 24, 2023
69e85cf
Update URL for atomic data repository
wkerzendorf Dec 24, 2023
8c7759a
Refactor code for improved readability and maintainability
wkerzendorf Dec 24, 2023
a0a23a0
Refactor code to remove unnecessary array conversion
wkerzendorf Dec 24, 2023
5ff5432
Refactor code to remove unnecessary conversion to numpy array in test…
wkerzendorf Dec 24, 2023
16afba3
Merge branch 'tests/regression_data' into restructure/transport_solver
wkerzendorf Dec 24, 2023
e541eb2
Merge branch 'restructure/transport_solver' into restructure/separate…
wkerzendorf Dec 24, 2023
829d609
Refactor vpacket tracking in montecarlo_main_loop
wkerzendorf Dec 26, 2023
a49c259
Update packet_collection and vpacket_tracker
wkerzendorf Dec 29, 2023
45eb023
fixup of code
wkerzendorf Dec 30, 2023
0c36b9b
Add packet functionality to VPacketCollection
wkerzendorf Dec 30, 2023
c1137e0
ruffify test_sdec_plot
wkerzendorf Dec 30, 2023
2261b1b
Update estimator_statistics module
wkerzendorf Dec 31, 2023
70a2dc5
Add bound-free estimator utility functions and classes
wkerzendorf Dec 31, 2023
458ee16
Work ongoing
wkerzendorf Jan 4, 2024
77897f4
ongoing work
wkerzendorf Jan 4, 2024
2565b9e
ongoing work
wkerzendorf Jan 4, 2024
cc3f04a
Merge remote-tracking branch 'upstream/pr/2469' into restructure/esti…
wkerzendorf Jan 4, 2024
f9cddad
Update code in various files
wkerzendorf Jan 4, 2024
de6ccc8
Fix photo ion calculation and radiation field intensity calculation
wkerzendorf Jan 5, 2024
d233bfd
Co-authored-by: Christian Vogl <cvogl@mpa-garching.mpg.de>
wkerzendorf Jan 5, 2024
af9c4a2
Delete unused files and workspace configuration
wkerzendorf Jan 5, 2024
214f9e5
Add Visual Studio Code workspace file to .gitignore
wkerzendorf Jan 5, 2024
97683a8
Remove unused import in parse_input.py
wkerzendorf Jan 6, 2024
0cceb79
Update VPACKET_TAU_RUSSIAN constant
wkerzendorf Jan 6, 2024
ca18310
Refactor montecarlo_main_loop and FormalIntegrator classes
wkerzendorf Jan 6, 2024
984a1a2
Merge branch 'restructure/separate_transport_state' into restructure/…
wkerzendorf Jan 6, 2024
813376c
Fix import statement in base.py
wkerzendorf Jan 6, 2024
c7581b8
Merge branch 'restructure/separate_transport_state' into restructure/…
wkerzendorf Jan 6, 2024
6b4b490
Add import statement for radfield_mc_estimators
wkerzendorf Jan 6, 2024
fb9c8cd
add new solvers
wkerzendorf Jan 12, 2024
0064c8c
Merge branch 'master' into pr/2500
andrewfullard Jan 22, 2024
1235772
Fix most tests
andrewfullard Jan 22, 2024
c32312a
Remove unused util
andrewfullard Jan 29, 2024
aa15361
Fixes downbranch tests
andrewfullard Jan 29, 2024
105cfbe
Fix plasma continuum test name
andrewfullard Jan 29, 2024
b2a384f
Fix excess quantity in RPacket definition
andrewfullard Jan 29, 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
8 changes: 6 additions & 2 deletions tardis/model/radiation_field_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from tardis.util.base import intensity_black_body

from typing import Union


class DiluteBlackBodyRadiationFieldState:
"""
Expand Down Expand Up @@ -30,7 +32,7 @@ def __init__(
self.t_radiative = t_radiative
self.dilution_factor = dilution_factor

def calculate_mean_intensity(self, nu):
def calculate_mean_intensity(self, nu: Union[u.Quantity, np.ndarray]):
"""
Calculate the intensity of the radiation field at a given frequency.

Expand All @@ -44,4 +46,6 @@ def calculate_mean_intensity(self, nu):
intensity : u.Quantity
Intensity of the radiation field at the given frequency
"""
return self.dilution_factor * intensity_black_body(nu, self.t_radiative)
return self.dilution_factor * intensity_black_body(
nu[np.newaxis].T, self.t_radiative
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this transpose happening here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the number of nues vs the number of shells - what comes out is a 2D frame

)
182 changes: 94 additions & 88 deletions tardis/montecarlo/estimators/estimated_radfield_properties.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass

import numpy as np
import pandas as pd
from astropy import units as u

import tardis.constants as const
from tardis.io.atom_data import AtomData
from tardis.model.radiation_field_state import (
DiluteBlackBodyRadiationFieldState,
)
from tardis.montecarlo.estimators.util import (
bound_free_estimator_array2frame,
integrate_array_by_blocks,
)
from tardis.montecarlo.estimators.radfield_mc_estimators import (
RadiationFieldMCEstimators,
)
from tardis.plasma.properties.continuum_processes import PhotoIonBoltzmannFactor

H = const.h.cgs.value

Expand All @@ -25,143 +32,136 @@ def calculate_stimulated_recomb_rate_coefficient(self):
pass


class EstimatedMCContinuumProperties(EstimatedContinuumPropertiesABC):
class MCContinuumPropertiesSolver(EstimatedContinuumPropertiesABC):
def __init__(
self,
radfield_mc_estimators,
level2continuum_idx,
atom_data: AtomData,
):
self.atom_data = atom_data

def solve(
self,
radfield_mc_estimators: RadiationFieldMCEstimators,
time_simulation,
volume,
):
self.radfield_mc_estimators = radfield_mc_estimators
self.level2continuum_idx = level2continuum_idx
photo_ion_norm_factor = (time_simulation * volume * H) ** -1

# initializing the lazy properties
self._gamma_estimator_df = None
self._alpha_stimulated_estimator_df = None
self.photo_ion_norm_factor = (time_simulation * volume * H) ** -1
photo_ionization_rate_coefficient = bound_free_estimator_array2frame(
radfield_mc_estimators.photo_ion_estimator,
self.atom_data.level2continuum_edge_idx,
)
photo_ionization_rate_coefficient *= photo_ion_norm_factor

def calculate_photo_ionization_rate_coefficient(self):
return self.gamma_estimator_df * self.photo_ion_norm_factor.value
stimulated_recomb_rate_factor = bound_free_estimator_array2frame(
radfield_mc_estimators.stim_recomb_estimator,,
self.atom_data.level2continuum_edge_idx,
)
stimulated_recomb_rate_factor *= photo_ion_norm_factor

def calculate_stimulated_recomb_rate_factor(self):
"""
Calculates the stimulated recombination rate coefficient.
return ContinuumProperties(stimulated_recomb_rate_factor, photo_ionization_rate_coefficient)

Returns
-------
alpha_stim : ndarray
The calculated stimulated recombination rate coefficient.

See Equation 15 in Lucy 2003
"""
alpha_factor = (
self.alpha_stimulated_estimator_df * self.photo_ion_norm_factor
class DiluteBlackBodyContinuumPropertiesSolver(EstimatedContinuumPropertiesABC):
def __init__(self, atom_data: AtomData) -> None:
self.atom_data = atom_data

def solve(
self,
dilute_blackbody_radiationfield_state: DiluteBlackBodyRadiationFieldState,
t_electrons: u.Quantity,
):
photo_ion_boltzmann_factor = PhotoIonBoltzmannFactor.calculate(
self.atom_data.photoionization_data, t_electrons
)
return alpha_factor

@property
def alpha_stimulated_estimator_df(self):
if self._alpha_stimulated_estimator_df is None:
self._alpha_stimulated_estimator_df = (
bound_free_estimator_array2frame(
self.radfield_mc_estimators.stim_recomb_estimator,
self.level2continuum_idx,
)
mean_intensity_photo_ion_df = (
self.calculate_mean_intensity_photo_ion_table(
dilute_blackbody_radiationfield_state
)
return self._alpha_stimulated_estimator_df

@property
def gamma_estimator_df(self):
if self._gamma_estimator_df is None:
self._gamma_estimator_df = bound_free_estimator_array2frame(
self.radfield_mc_estimators.photo_ion_estimator,
self.level2continuum_idx,
)
return self._gamma_estimator_df
)

photo_ion_rate_coeff = self.calculate_photo_ionization_rate_coefficient(
mean_intensity_photo_ion_df
)
stimulated_recomb_rate_coeff = (
self.calculate_stimulated_recomb_rate_coefficient(
mean_intensity_photo_ion_df,
photo_ion_boltzmann_factor,
)
)

class EstimatedDiluteBlackBodyContinuumProperties(
EstimatedContinuumPropertiesABC
):
def __init__(
self,
dilute_blackbody_radiationfield_state: DiluteBlackBodyRadiationFieldState,
) -> None:
self.dilute_blackbody_radiationfield_state = (
dilute_blackbody_radiationfield_state
return ContinuumProperties(
stimulated_recomb_rate_coeff, photo_ion_rate_coeff
)

def calculate_photo_ionization_rate_coefficient(
self,
photo_ion_cross_sections_df,
photo_ion_block_references,
photo_ion_index,
mean_intensity_photo_ion_df: pd.DataFrame,
):
mean_intensity_df = self.calculate_mean_intensity_for_photo_ion_table(
photo_ion_cross_sections_df
)

gamma = mean_intensity_df.multiply(
gamma = mean_intensity_photo_ion_df.multiply(
4.0
* np.pi
* photo_ion_cross_sections_df.x_sect
/ (photo_ion_cross_sections_df.nu * H),
* self.atom_data.photoionization_data.x_sect
/ (self.atom_data.photoionization_data.nu * H),
axis=0,
)
gamma = integrate_array_by_blocks(
gamma.values,
photo_ion_cross_sections_df.nu.values,
photo_ion_block_references,
self.atom_data.photoionization_data.nu.values,
self.atom_data.photo_ion_block_references,
)
gamma = pd.DataFrame(gamma, index=photo_ion_index)
gamma = pd.DataFrame(gamma, index=self.atom_data.photo_ion_unique_index)
return gamma

def calculate_stimulated_recomb_rate_coefficient(
self,
photo_ion_cross_sections_df,
photo_ion_block_references,
photo_ion_index,
boltzmann_factor_photo_ion,
mean_intensity_photo_ion_df: pd.DataFrame,
photo_ion_boltzmann_factor: np.ndarray,
):
nu = photo_ion_cross_sections["nu"]
x_sect = photo_ion_cross_sections["x_sect"]
# TODO: duplicated; also used in calculate_photo_ionization_rate_coefficient
mean_intensity_df = self.calculate_mean_intensity_for_photo_ion_table(
photo_ion_cross_sections_df
alpha_stim_factor = (
mean_intensity_photo_ion_df * photo_ion_boltzmann_factor
)

mean_intensity_df *= boltzmann_factor_photo_ion
alpha_stim = mean_intensity_df.multiply(
4.0 * np.pi * x_sect / nu / H, axis=0
alpha_stim_factor = alpha_stim_factor.multiply(
4.0
* np.pi
* self.atom_data.photoionization_data.x_sect
/ (self.atom_data.photoionization_data.nu * H),
axis=0,
)
alpha_stim = integrate_array_by_blocks(
alpha_stim.values, nu.values, photo_ion_block_references
alpha_stim_factor = integrate_array_by_blocks(
alpha_stim_factor.values,
self.atom_data.photoionization_data.nu.values,
self.atom_data.photo_ion_block_references,
)
alpha_stim = pd.DataFrame(alpha_stim, index=photo_ion_index)
return alpha_stim

def calculate_mean_intensity_for_photo_ion_table(
self, photo_ion_cross_sections_df
alpha_stim_factor = pd.DataFrame(
alpha_stim_factor, index=self.atom_data.photo_ion_unique_index
)

return alpha_stim_factor

def calculate_mean_intensity_photo_ion_table(
self,
dilute_blackbody_radiationfield_state: DiluteBlackBodyRadiationFieldState,
):
mean_intensity = (
self.dilute_blackbody_radiationfield_state.calculate_mean_intensity(
photo_ion_cross_sections_df.nu
dilute_blackbody_radiationfield_state.calculate_mean_intensity(
self.atom_data.photoionization_data.nu.values
)
)
mean_intensity_df = pd.DataFrame(
mean_intensity,
index=photo_ion_cross_sections_df.index,
index=self.atom_data.photoionization_data.index,
columns=np.arange(
len(self.dilute_blackbody_radiationfield_state.t_radiative)
len(dilute_blackbody_radiationfield_state.t_radiative)
),
)
return mean_intensity_df


"""
class PhotoIonBoltzmannFactor(ProcessingPlasmaProperty):

Attributes
----------
boltzmann_factor_photo_ion : pandas.DataFrame, dtype float
Expand All @@ -175,3 +175,9 @@ def calculate(self, photo_ion_cross_sections, t_electrons):
boltzmann_factor = np.exp(-nu[np.newaxis].T / t_electrons * (H / K_B))
return boltzmann_factor
"""


@dataclass
class ContinuumProperties:
stimulated_recomb_rate_factor: pd.DataFrame
photo_ionization_rate_coefficient: pd.DataFrame
29 changes: 1 addition & 28 deletions tardis/montecarlo/montecarlo_numba/tests/test_continuum.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
from copy import deepcopy

import pytest

from tardis.io.configuration.config_reader import Configuration
from tardis.simulation import Simulation

import numpy.testing as npt


@pytest.fixture(scope="function")
def continuum_config(
tardis_config_verysimple_nlte,
):
continuum_config = Configuration.from_config_dict(
tardis_config_verysimple_nlte
)
continuum_config.plasma.continuum_interaction.species = ["H I"]
continuum_config.plasma.nlte_ionization_species = []

""""
montecarlo_configuration.LEGACY_MODE_ENABLED = True
# Setup model config from verysimple

config_montecarlo_1e5_verysimple.montecarlo.last_no_of_packets = 1e5
config_montecarlo_1e5_verysimple.montecarlo.no_of_virtual_packets = 0
config_montecarlo_1e5_verysimple.montecarlo.iterations = 1
config_montecarlo_1e5_verysimple.plasma.line_interaction_type = "macroatom"

del config_montecarlo_1e5_verysimple["config_dirname"]
"""
return continuum_config
from tardis.simulation import Simulation


def test_montecarlo_continuum(
Expand Down
3 changes: 2 additions & 1 deletion tardis/plasma/properties/continuum_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ class PhotoIonBoltzmannFactor(ProcessingPlasmaProperty):

outputs = ("boltzmann_factor_photo_ion",)

def calculate(self, photo_ion_cross_sections, t_electrons):
@staticmethod
def calculate(photo_ion_cross_sections, t_electrons):
nu = photo_ion_cross_sections["nu"].values

boltzmann_factor = np.exp(-nu[np.newaxis].T / t_electrons * (H / K_B))
Expand Down
Loading