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/plasma] estimator cleanup #2675

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 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
5e4902a
some more cleanup
wkerzendorf Jul 26, 2024
9f92256
fix benchmarks
wkerzendorf Jul 26, 2024
cd1badc
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 26, 2024
bd04642
Merge remote-tracking branch 'upstream/master' into restructure/base_…
wkerzendorf Jul 26, 2024
930462f
blackify
wkerzendorf Jul 27, 2024
9e47b81
reverse the import pygraphviz
wkerzendorf Jul 27, 2024
8d67db8
fix docstrings
wkerzendorf Jul 27, 2024
7d8e6e0
Refactor code to address comments
wkerzendorf Jul 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
Prev Previous commit
Next Next commit
trying to get rid of j_blues in plasma with MC restructure
  • Loading branch information
wkerzendorf committed Jun 21, 2024
commit e3f1819ce89f77db2448ef87ca6838d9471b44dd
18 changes: 0 additions & 18 deletions tardis/plasma/properties/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,3 @@ def __init__(self, plasma_parent):

def calculate(self, t_electrons):
return 1 / (self.k_B_cgs * t_electrons)


class LuminosityInner(ProcessingPlasmaProperty):
outputs = ("luminosity_inner",)

@staticmethod
def calculate(r_inner, t_inner):
return (
4 * np.pi * const.sigma_sb.cgs * r_inner[0] ** 2 * t_inner**4
).to("erg/s")


class TimeSimulation(ProcessingPlasmaProperty):
outputs = ("time_simulation",)

@staticmethod
def calculate(luminosity_inner):
return 1.0 * u.erg / luminosity_inner
11 changes: 0 additions & 11 deletions tardis/plasma/properties/plasma_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"JBlueEstimator",
"LinkTRadTElectron",
"HeliumTreatment",
"RInner",
"TInner",
"Volume",
"ContinuumInteractionSpecies",
"NLTEIonizationSpecies",
Expand Down Expand Up @@ -125,15 +123,6 @@ class LinkTRadTElectron(Input):
class HeliumTreatment(Input):
outputs = ("helium_treatment",)


class RInner(Input):
outputs = ("r_inner",)


class TInner(Input):
outputs = ("t_inner",)


class Volume(Input):
outputs = ("volume",)

Expand Down
37 changes: 27 additions & 10 deletions tardis/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,23 @@ def advance_state(self):
-------
converged : bool
"""
(
estimated_t_rad,
estimated_dilution_factor,
) = self.transport.transport_state.calculate_radiationfield_properties()
estimated_radfield_properties = (
self.transport.radfield_prop_solver.solve(
self.transport.transport_state.radfield_mc_estimators,
self.transport.transport_state.time_explosion,
self.transport.transport_state.time_of_simulation,
self.transport.transport_state.geometry_state.volume,
self.transport.transport_state.opacity_state.line_list_nu,
)
)

estimated_t_rad = (
estimated_radfield_properties.dilute_blackbody_radiationfield_state.temperature
)
estimated_dilution_factor = (
estimated_radfield_properties.dilute_blackbody_radiationfield_state.dilution_factor
)

estimated_t_inner = self.estimate_t_inner(
self.simulation_state.t_inner,
self.luminosity_requested,
Expand Down Expand Up @@ -334,18 +347,23 @@ def advance_state(self):
self.simulation_state.dilution_factor = next_dilution_factor
self.simulation_state.blackbody_packet_source.temperature = next_t_inner

# model.calculate_j_blues() equivalent
# model.update_plasmas() equivalent
# Bad test to see if this is a nlte run
if "nlte_data" in self.plasma.outputs_dict:
self.plasma.store_previous_properties()
radiation_field = DilutePlanckianRadiationField(
temperature=self.simulation_state.t_radiative,
dilution_factor=self.simulation_state.dilution_factor,
)
update_properties = dict(
dilute_planckian_radiation_field=radiation_field
)

# model.calculate_j_blues() equivalent
# model.update_plasmas() equivalent
# Bad test to see if this is a nlte run
if "nlte_data" in self.plasma.outputs_dict:
self.plasma.store_previous_properties()
update_properties = dict(
j_blues=estimated_radfield_properties.j_blues
)

# A check to see if the plasma is set with JBluesDetailed, in which
# case it needs some extra kwargs.

Expand Down Expand Up @@ -382,7 +400,6 @@ def iterate(self, no_of_packets, no_of_virtual_packets=0):

self.transport.run(
transport_state,
time_explosion=self.simulation_state.time_explosion,
iteration=self.iterations_executed,
total_iterations=self.iterations,
show_progress_bars=self.show_progress_bars,
Expand Down
14 changes: 12 additions & 2 deletions tardis/transport/montecarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
montecarlo_main_loop,
numba_config,
)
from tardis.transport.montecarlo.estimators.dilute_blackbody_properties import (
MCRadiationFieldPropertiesSolver,
)
from tardis.transport.montecarlo.estimators.radfield_mc_estimators import (
initialize_estimator_statistics,
)
Expand Down Expand Up @@ -49,6 +52,7 @@ class MonteCarloTransportSolver(HDFWriterMixin):

def __init__(
self,
radfield_prop_solver,
spectrum_frequency,
virtual_spectrum_spawn_range,
enable_full_relativity,
Expand All @@ -64,6 +68,7 @@ def __init__(
use_gpu=False,
montecarlo_configuration=None,
):
self.radfield_prop_solver = radfield_prop_solver
# inject different packets
self.spectrum_frequency = spectrum_frequency
self.virtual_spectrum_spawn_range = virtual_spectrum_spawn_range
Expand Down Expand Up @@ -124,6 +129,7 @@ def initialize_transport_state(
spectrum_frequency=self.spectrum_frequency,
geometry_state=geometry_state,
opacity_state=opacity_state,
time_explosion=simulation_state.time_explosion,
)

transport_state.enable_full_relativity = (
Expand All @@ -142,7 +148,6 @@ def initialize_transport_state(
def run(
self,
transport_state,
time_explosion,
iteration=0,
total_iterations=0,
show_progress_bars=True,
Expand Down Expand Up @@ -176,7 +181,7 @@ def run(
) = montecarlo_main_loop(
transport_state.packet_collection,
transport_state.geometry_state,
time_explosion.cgs.value,
transport_state.time_explosion.cgs.value,
transport_state.opacity_state,
self.montecarlo_configuration,
transport_state.radfield_mc_estimators,
Expand Down Expand Up @@ -289,7 +294,12 @@ def from_config(
config.montecarlo.tracking.initial_array_length
)

radfield_prop_solver = MCRadiationFieldPropertiesSolver(
config.plasma.w_epsilon
)

return cls(
radfield_prop_solver=radfield_prop_solver,
spectrum_frequency=spectrum_frequency,
virtual_spectrum_spawn_range=config.montecarlo.virtual_spectrum_spawn_range,
enable_full_relativity=config.montecarlo.enable_full_relativity,
Expand Down
3 changes: 3 additions & 0 deletions tardis/transport/montecarlo/estimators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from tardis.transport.montecarlo.estimators.base import (
EstimatedRadiationFieldProperties,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from tardis.plasma.radiation_field.planck_rad_field import (
DilutePlanckianRadiationField,
)
from tardis.transport.montecarlo.estimators.base import (
EstimatedRadiationFieldProperties,
)

DILUTION_FACTOR_ESTIMATOR_CONSTANT = (
(const.c**2 / (2 * const.h))
Expand All @@ -18,11 +21,20 @@
).cgs.value


class MCDiluteBlackBodyRadFieldSolver:
def __init__(self) -> None:
pass
class MCRadiationFieldPropertiesSolver:
wkerzendorf marked this conversation as resolved.
Show resolved Hide resolved
w_epsilon = 1e-10

def __init__(self, w_epsilon=1e-10) -> None:
self.w_epsilon = w_epsilon

def solve(self, radfield_mc_estimators, time_of_simulation, volume):
def solve(
self,
radfield_mc_estimators,
time_explosion,
time_of_simulation,
volume,
line_list_nu,
):
"""
Calculate an updated radiation field from the :math:
`\\bar{nu}_\\textrm{estimator}` and :math:`\\J_\\textrm{estimator}`
Expand All @@ -39,6 +51,26 @@ def solve(self, radfield_mc_estimators, time_of_simulation, volume):
t_radiative : astropy.units.Quantity (float)
dilution_factor : numpy.ndarray (float)
"""
dilute_planck_rad_field = self.estimate_dilute_planck_radiation_field(
radfield_mc_estimators, time_of_simulation, volume
)
j_blues = self.estimate_jblues(
radfield_mc_estimators.j_blue_estimator,
dilute_planck_rad_field,
time_explosion,
time_of_simulation,
volume,
line_list_nu,
)

return EstimatedRadiationFieldProperties(
dilute_blackbody_radiationfield_state=dilute_planck_rad_field,
j_blues=j_blues,
)

def estimate_dilute_planck_radiation_field(
self, radfield_mc_estimators, time_of_simulation, volume
):
temperature_radiative = (
T_RADIATIVE_ESTIMATOR_CONSTANT
* radfield_mc_estimators.nu_bar_estimator
Expand All @@ -51,7 +83,29 @@ def solve(self, radfield_mc_estimators, time_of_simulation, volume):
* time_of_simulation.value
* volume
)

return DilutePlanckianRadiationField(
temperature_radiative, dilution_factor
)

def estimate_jblues(
self,
j_blue_estimator,
estimated_radfield_state,
time_explosion,
time_of_simulation,
volume,
line_list_nu,
):
j_blues_norm_factor = (
const.c.cgs
* time_explosion
/ (4 * np.pi * time_of_simulation * volume)
)
j_blues = j_blue_estimator * j_blues_norm_factor.cgs.value
planck_j_blues = estimated_radfield_state.calculate_mean_intensity(
line_list_nu
)
zero_j_blues = j_blues == 0.0
j_blues[zero_j_blues] = self.w_epsilon * planck_j_blues[zero_j_blues]

return j_blues
33 changes: 3 additions & 30 deletions tardis/transport/montecarlo/montecarlo_transport_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from tardis.io.util import HDFWriterMixin
from tardis.transport.montecarlo.estimators.dilute_blackbody_properties import (
MCDiluteBlackBodyRadFieldSolver,
MCRadiationFieldPropertiesSolver,
)
from tardis.transport.montecarlo.formal_integral import IntegrationError
from tardis.spectrum import TARDISSpectrum
Expand Down Expand Up @@ -62,9 +62,11 @@ def __init__(
spectrum_frequency,
geometry_state,
opacity_state,
time_explosion,
rpacket_tracker=None,
vpacket_tracker=None,
):
self.time_explosion = time_explosion
wkerzendorf marked this conversation as resolved.
Show resolved Hide resolved
self.packet_collection = packet_collection
self.radfield_mc_estimators = radfield_mc_estimators
self.spectrum_frequency = spectrum_frequency
Expand All @@ -81,35 +83,6 @@ def __init__(
self.rpacket_tracker = rpacket_tracker
self.vpacket_tracker = vpacket_tracker

def calculate_radiationfield_properties(self):
"""
Calculate an updated radiation field from the :math:
`\\bar{nu}_\\textrm{estimator}` and :math:`\\J_\\textrm{estimator}`
calculated in the montecarlo simulation.
The details of the calculation can be found in the documentation.

Parameters
----------
nubar_estimator : np.ndarray (float)
j_estimator : np.ndarray (float)

Returns
-------
t_radiative : astropy.units.Quantity (float)
dilution_factor : numpy.ndarray (float)
"""
dilute_bb_solver = MCDiluteBlackBodyRadFieldSolver()
dilute_bb_radfield = dilute_bb_solver.solve(
self.radfield_mc_estimators,
self.time_of_simulation,
self.geometry_state.volume,
)

return (
dilute_bb_radfield.temperature,
dilute_bb_radfield.dilution_factor,
)

@property
def output_nu(self):
return self.packet_collection.output_nus * u.Hz
Expand Down
Loading