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

Gamma ray propagation #1698

Merged
merged 147 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
56b5952
Radioactive decay product propagation
andrewfullard Apr 15, 2021
4fbbdb0
Docstrings
andrewfullard Apr 15, 2021
372950d
reworked gamma-ray deposition
afloers Apr 27, 2021
a8845ca
Fixes and improvements for pair creation
andrewfullard Apr 28, 2021
f9167e6
Hidden a lot of prints, more explicit positron opacity energies
andrewfullard Apr 28, 2021
4a4e57e
Fixed some function calls, incorporated X-rays
andrewfullard Apr 28, 2021
1cbbf06
More vector normalization
andrewfullard Apr 28, 2021
9b2ec52
Fix E-R formula, little cleanup
andrewfullard May 3, 2021
f1659d3
Existing tests fixed
andrewfullard May 3, 2021
ea211c5
Removed prints
andrewfullard May 3, 2021
bc8af63
Renamed GammaRay object to GXPacket, refactoring
andrewfullard May 4, 2021
1538c99
More renaming and refactoring
andrewfullard May 4, 2021
0d9206d
Removed unneeded tau subtraction
andrewfullard May 5, 2021
cfc18e4
Improved deposition time calculation
andrewfullard May 5, 2021
a93abcd
Added energy deposition time of zero for beta decay
andrewfullard May 5, 2021
b428e78
added decay scheme using tardis nuclear and streamlined spawning process
afloers May 7, 2021
29961e9
Added todo comment
andrewfullard May 25, 2021
b064919
Refactoring
andrewfullard May 26, 2021
8206574
Calculate energy per shell per gram
andrewfullard Jun 7, 2021
8ecac63
Docstrings and cleanup
andrewfullard Jun 7, 2021
e4da46b
Cleaned up unused imports
andrewfullard Jun 7, 2021
edbc192
Fixed main loop docstring
andrewfullard Jun 7, 2021
9503598
Added calculated iron group fraction and log packet index in plotting…
andrewfullard Jun 14, 2021
c64cba8
Fix moving packets to interaction being slightly too far
andrewfullard Jun 14, 2021
d2f50f2
Addressing most comments
andrewfullard Jul 1, 2021
5628dda
Fixec circular dependency and other minor items
andrewfullard Jul 1, 2021
0f419d7
Docstring for escaping energy output
andrewfullard Jul 1, 2021
51af6ac
Radioactive decay product propagation
andrewfullard Apr 15, 2021
d7cf21b
Docstrings
andrewfullard Apr 15, 2021
7b06f18
reworked gamma-ray deposition
afloers Apr 27, 2021
c5ae8ad
Fixes and improvements for pair creation
andrewfullard Apr 28, 2021
1dea466
Hidden a lot of prints, more explicit positron opacity energies
andrewfullard Apr 28, 2021
31c5a5d
Fixed some function calls, incorporated X-rays
andrewfullard Apr 28, 2021
ec52380
More vector normalization
andrewfullard Apr 28, 2021
45f1e61
Fix E-R formula, little cleanup
andrewfullard May 3, 2021
a538fb3
Existing tests fixed
andrewfullard May 3, 2021
72a25c2
Removed prints
andrewfullard May 3, 2021
94c9471
Renamed GammaRay object to GXPacket, refactoring
andrewfullard May 4, 2021
4d91c61
More renaming and refactoring
andrewfullard May 4, 2021
85b16ab
Removed unneeded tau subtraction
andrewfullard May 5, 2021
50407d8
Improved deposition time calculation
andrewfullard May 5, 2021
691afbc
Added energy deposition time of zero for beta decay
andrewfullard May 5, 2021
abf5cde
added decay scheme using tardis nuclear and streamlined spawning process
afloers May 7, 2021
0be51fd
Added todo comment
andrewfullard May 25, 2021
39d76cb
Refactoring
andrewfullard May 26, 2021
4a9f002
Calculate energy per shell per gram
andrewfullard Jun 7, 2021
04097c9
Docstrings and cleanup
andrewfullard Jun 7, 2021
533e70b
Cleaned up unused imports
andrewfullard Jun 7, 2021
0e867b9
Fixed main loop docstring
andrewfullard Jun 7, 2021
823e8ee
Added calculated iron group fraction and log packet index in plotting…
andrewfullard Jun 14, 2021
0231310
Fix moving packets to interaction being slightly too far
andrewfullard Jun 14, 2021
a48516d
Addressing most comments
andrewfullard Jul 1, 2021
396b607
Fixec circular dependency and other minor items
andrewfullard Jul 1, 2021
a1387a5
Docstring for escaping energy output
andrewfullard Jul 1, 2021
1b735bf
Merge branch 'gamma_ray_propagation' of github.com:andrewfullard/tard…
andrewfullard Jul 7, 2021
07e6834
Added chvogl comments as TODO comments in code.
andrewfullard Jul 7, 2021
58b3b51
Increased boundary crossing factor to prevent boundary sticking
andrewfullard Jul 8, 2021
72d4392
Refactoring of CDFs and improved compton angle sampling
andrewfullard Jul 8, 2021
49dc72a
Restructuring and cleanup. Some better tests
andrewfullard Jul 12, 2021
499bc54
Tests now pass with refdata
andrewfullard Jul 14, 2021
be1d1b0
Normalized energy deposition rate to decay rate
andrewfullard Jul 26, 2021
d2fe8cc
Addressing review comments
andrewfullard Aug 2, 2021
1c72b63
[build docs]
andrewfullard Aug 6, 2021
c3a5f99
[build docs]
andrewfullard Aug 6, 2021
562aa3c
Addressed more comments
andrewfullard Aug 16, 2021
44b4154
Refactoring a little, addressed some comments
andrewfullard Aug 30, 2021
c37e46f
Corrected sampling of photon initial radius, and added nuclear to env
andrewfullard Sep 28, 2021
1f28f0a
Added a simple pynonthermal connector that will solve the SF equation…
andrewfullard Oct 25, 2021
906083d
Added scaled_decay_rate_per_shell output
andrewfullard Nov 8, 2021
ed9d9a6
Major update
andrewfullard Nov 24, 2021
a351cda
Latest changes to scaling factors
andrewfullard Dec 13, 2021
15f25c7
Energy deposition comparison
andrewfullard Dec 13, 2021
f065e63
Adding secondary gamma-ray from beta decay annihilation
andrewfullard Dec 13, 2021
ebc8b9d
Normalized decays by number of nuclides per shell
andrewfullard Dec 13, 2021
9453b5b
Fix dataframe copy fail, return to abundance-scaled decays
andrewfullard Dec 14, 2021
f9f1fa9
Removed quantity objects from internal calculations
andrewfullard Dec 14, 2021
e1860fe
Removed astropy coord transform
andrewfullard Dec 14, 2021
10a0b37
Decay product energy scaled by activity when created
andrewfullard Dec 14, 2021
41eb63f
Fixed Compton angle sampling, electron radius squared and photoabsorp…
andrewfullard Dec 15, 2021
342c9c5
Applied numba where easiest
andrewfullard Dec 16, 2021
90049b8
Added frame transformations that are hopefully correct, improved some…
andrewfullard Dec 21, 2021
3ea9005
Commentary on doppler effects, improved some tests
andrewfullard Jan 14, 2022
1a4f291
Cleaned up some output
andrewfullard Jan 26, 2022
994ea89
Updated GXPhoton to be a jitclass, cleaned up Compton scattering
andrewfullard Jan 27, 2022
509876a
Frame transformation adjustments, renamed methods
andrewfullard Feb 10, 2022
7e53e04
Opacities to rest frame
andrewfullard Feb 10, 2022
f233a13
Indivisible packet formalism version
andrewfullard Feb 15, 2022
4053b85
Corrected frame transform in photon version
andrewfullard Feb 15, 2022
183f17e
Pair creation frame transform freq after scatter
andrewfullard Feb 16, 2022
ff52b1d
Correct use of packet frequency instead of energy to calculate opacities
andrewfullard Feb 16, 2022
fdd4e1f
Change to compton fraction calculation instead of energy loss
andrewfullard Feb 18, 2022
bc2acb5
Added rf/cmf packet properties and using artis data
andrewfullard Feb 25, 2022
22ba220
Possibly some progress
andrewfullard Feb 25, 2022
e8d0290
Corrected some doppler factors, correctly scaled activity per shell
andrewfullard Feb 28, 2022
c4c6fcf
Changes to opacities and transport to closely match artis
andrewfullard Mar 1, 2022
8b9b4e6
Returned to standard K-N formulation and added some useful comments
andrewfullard Mar 2, 2022
979d6a5
Small performance gain, using nuclear for isotopes
andrewfullard Mar 8, 2022
697b5a3
Added grey opacity option
andrewfullard Mar 9, 2022
7bbf131
Estimator scaffolding
andrewfullard Mar 10, 2022
bf9405e
Parallel gamma-ray loop, performance improvements
andrewfullard Mar 10, 2022
4a38412
Added packet tracking back with good performance
andrewfullard Mar 11, 2022
fb862f5
Logging positrons again
andrewfullard Mar 16, 2022
18dfa52
Time dependence
andrewfullard Apr 4, 2022
167ba6f
More time dependent work
andrewfullard Apr 13, 2022
52efdc2
Merge branch 'master' into gamma_ray_propagation
andrewfullard Apr 14, 2022
5ae327b
Merge branch 'master' into gamma_ray_propagation
andrewfullard Apr 14, 2022
7f98541
Packets constant with time
andrewfullard Apr 18, 2022
6e13935
Matching Urilight to 20 days or so
andrewfullard Apr 22, 2022
93fa0c7
artis-type pair creation opacity and inverse volume with time
andrewfullard Apr 25, 2022
2a4d4cb
Added isotope_mass as a plasma property similar to atomic_mass
andrewfullard Apr 25, 2022
1beea4c
Added isotope number density calculation
andrewfullard Apr 25, 2022
9cf41b4
Added simple (currently failing) test
andrewfullard Apr 26, 2022
ff05a21
Working tests
andrewfullard Apr 26, 2022
d69f929
Merge branch 'plasma_isotope_properties' into gamma_ray_propagation
andrewfullard Apr 26, 2022
93de083
Revert "Merge branch 'plasma_isotope_properties' into gamma_ray_propa…
andrewfullard Apr 26, 2022
8e6fc0c
Added isotope_mass as a plasma property similar to atomic_mass
andrewfullard Apr 25, 2022
cba7e82
Added isotope number density calculation
andrewfullard Apr 25, 2022
5dad990
Added simple (currently failing) test
andrewfullard Apr 26, 2022
b128e03
Working tests
andrewfullard Apr 26, 2022
efc37b2
Fixes for Compton fraction
andrewfullard May 2, 2022
b38eabc
Docstrings and cleanup
andrewfullard May 3, 2022
0583ba8
Corrected doppler factor vectors
andrewfullard May 4, 2022
5bad076
Gamma packets to cartesian vector space
andrewfullard May 9, 2022
82b2230
Fixed (probably) shell location after moving packet
andrewfullard May 9, 2022
c741591
Removed multi-threading
andrewfullard May 10, 2022
394131a
Fixed relativistic aberration returning non-unit vectors
andrewfullard May 10, 2022
3f01e1d
Added expanding shell distance option, some cleanup
andrewfullard May 10, 2022
b814517
Spectrum output, linear time step option, cleanup
andrewfullard May 11, 2022
fd4dfaa
Docstring cleanup
andrewfullard May 11, 2022
aa6363b
Cleaned out some old code, most tests pass again
andrewfullard May 13, 2022
981aa9b
Documentation
andrewfullard May 13, 2022
8e2506a
njit_dict_no_parallel applied, removed old unused functions
andrewfullard May 16, 2022
40e2c23
Applied black to new files
andrewfullard May 16, 2022
5733a96
Merge branch 'master' into gamma_ray_propagation
andrewfullard May 16, 2022
4b0fa85
Test fix to remove excess file changes
andrewfullard May 16, 2022
db88760
Fix excess PR changes
andrewfullard May 16, 2022
57e12e7
Final cleanup
andrewfullard May 16, 2022
275ee02
Updated docs to support updates to astropy units
andrewfullard May 16, 2022
61b5eae
Split out nuclear dependence
andrewfullard May 16, 2022
2fb417a
Black, again
andrewfullard May 16, 2022
d31e39d
Numba based packet init
andrewfullard May 17, 2022
95ae319
Fix missing intensity multiplication
andrewfullard May 17, 2022
7a3a532
Updated docs, added WIP deposition estimator
andrewfullard May 20, 2022
5501215
Estimator sort of working
andrewfullard May 20, 2022
b4219e4
Address comments
andrewfullard Jun 6, 2022
d377a45
Fix tests
andrewfullard Jun 6, 2022
ee905cb
More test fixes and docstrings
andrewfullard Jun 6, 2022
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
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Mission Statement
physics/montecarlo/index
physics/est_and_conv/index
physics/spectrum/index
physics/energy_input/index


.. toctree::
Expand Down
306 changes: 306 additions & 0 deletions docs/physics/energy_input/gammaray_deposition.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Gamma-ray energy deposition\n",
"\n",
"This notebook provides the initial implementation of Gamma-ray energy deposition into an arbitrary ejecta.\n",
"It is a WORK IN PROGRESS and should NOT be used for any science work until further notice."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Main loop\n",
"\n",
"Generates a simple 1D ejecta and a list of gamma-ray objects.\n",
"\n",
"Runs packets of gamma-rays through the ejecta. Handles interactions by calling the appropriate function. \n",
"\n",
"Adds deposited energy and output energy to 2 different dataframes."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false,
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"import astropy as apy\n",
"\n",
"from tardis.energy_input.indivisible_packets import main_gamma_ray_loop\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from tardis.model import Radial1DModel\n",
"from tardis.io.config_reader import Configuration\n",
"\n",
"# Set up packet count\n",
"num_packets = 50000\n",
"\n",
"# Lock seed\n",
"np.random.seed(1)\n",
"\n",
"# Adjust model\n",
"config = Configuration.from_yaml(\"../../tardis/io/tests/data/tardis_configv1_density_exponential_nebular.yml\")\n",
"config.model.structure.velocity.start = 1 * apy.units.km / apy.units.s\n",
"config.model.structure.density.rho_0 = 5e2 * apy.units.g / (apy.units.cm ** 3)\n",
"config.supernova.time_explosion = 2.0 * apy.units.d\n",
"\n",
"config.atom_data = \"kurucz_cd23_chianti_H_He.h5\"\n",
"\n",
"# Create model\n",
"model = Radial1DModel.from_config(config)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate plasma"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"from tardis.plasma.properties import Density, Abundance, IsotopeAbundance, IsotopeNumberDensity, AtomicData, AtomicMass, IsotopeMass, NumberDensity, SelectedAtoms\n",
"from tardis.plasma.base import BasePlasma\n",
"from tardis.io.atom_data import AtomData\n",
"\n",
"input = [Density, Abundance, IsotopeAbundance, AtomicData, AtomicMass, IsotopeNumberDensity, NumberDensity, SelectedAtoms, IsotopeMass]\n",
"\n",
"plasma = BasePlasma(\n",
" plasma_properties=input,\n",
" density = model.density,\n",
" abundance = model.abundance,\n",
" isotope_abundance = model.raw_isotope_abundance,\n",
" atomic_data = AtomData.from_hdf(config.atom_data)\n",
" )\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Compute energy deposition rate\n",
"# ejecta_energy_df is the deposited energy\n",
"# ejecta_plot_energy_df is information for plotting\n",
"# escape_energy is the escaping energy\n",
"# decayed_packet_count is the number of packets created per shell\n",
"# energy_plot_positrons is the deposited energy from positrons\n",
"# estimated_deposition is the deposited energy from the Kasen (2006) estimator (currently not functional)\n",
"(\n",
" energy_df,\n",
" energy_plot_df,\n",
" escape_energy,\n",
" decayed_packet_count,\n",
" energy_plot_positrons,\n",
" estimated_deposition\n",
") = main_gamma_ray_loop(\n",
" num_packets,\n",
" model,\n",
" plasma,\n",
" time_steps=50,\n",
" time_end=50.0,\n",
")\n",
"\n",
"ejecta_energy = energy_plot_df[\"energy_input\"]\n",
"ejecta_energy_r = energy_plot_df[\"energy_input_r\"]\n",
"energy_input_time = energy_plot_df[\"energy_input_time\"]\n",
"energy_input_type = energy_plot_df[\"energy_input_type\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotting results\n",
"\n",
"Energy deposited at a given radius"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(dpi=150, facecolor='w')\n",
"ax = fig.add_subplot(111)\n",
"\n",
"scatter = ax.scatter(np.array(ejecta_energy_r)/np.max(model.v_outer.value), np.array(ejecta_energy), s=1, alpha=0.1)\n",
"ax.set_xlabel(\"r/R\")\n",
"ax.set_ylabel(\"E (keV)\")\n",
"ax.semilogy();"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Interactions binned by radius"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(dpi=150, facecolor='w')\n",
"ax = fig.add_subplot(111)\n",
"ax.hist(np.array(ejecta_energy_r), bins=200)\n",
"#ax.set_xlim(0, 1)\n",
"ax.set_xlabel(\"r (cm)\")\n",
"ax.set_ylabel(\"Interaction count\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Density Profile"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(dpi=150, facecolor='w')\n",
"plt.semilogy(model.r_middle/np.max(model.r_outer), model.density)\n",
"plt.plot(0,0)\n",
"plt.ylabel(\"Density g cm$^{-3}$\")\n",
"plt.xlabel(\"r/R\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fraction of energy escaping from the ejecta"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.sum(np.sum(escape_energy) / (np.sum(escape_energy) + np.sum(energy_df)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Spectrum of escape energy at the final time step"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tardis.energy_input.energy_source import read_artis_lines\n",
"\n",
"ni56_lines = read_artis_lines(\"ni56\")\n",
"co56_lines = read_artis_lines(\"co56\")\n",
"\n",
"plt.figure(figsize=(12, 6), dpi=150)\n",
"plt.step(escape_energy.index, escape_energy.iloc[:,49], label=\"$\\gamma$-spectrum\", where=\"post\")\n",
"plt.xlabel(\"Energy (keV)\")\n",
"plt.ylabel(\"keV/keV/s\");\n",
"plt.loglog()\n",
"plt.xlim(100, 4000)\n",
"#plt.ylim(0.01, 100)\n",
"plt.vlines(ni56_lines.energy*1000, 0.01, 0.02, color=\"k\", label=\"Ni56\")\n",
"plt.vlines(co56_lines.energy*1000, 0.01, 0.02, color=\"r\", label=\"Co56\")\n",
"plt.legend()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Energy deposition rate\n",
"\n",
"Dataframe index is the radial grid location. Columns are time steps in seconds"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"energy_df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Energy deposition rate versus radius at time_explosion"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(dpi=150, facecolor='w')\n",
"plt.semilogy(model.v_middle/np.max(model.v_outer), energy_df.iloc[:, 0])\n",
"plt.xlabel(\"r/R\")\n",
"plt.ylabel(\"Energy deposition rate [eV/s$]\");"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "1d9f0af959d2c458edd906b0042305fe807dd53effdb40eb4325690d1852d0c6"
},
"kernelspec": {
"display_name": "Python 3.8.13 ('tardis_new')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
6 changes: 6 additions & 0 deletions docs/physics/energy_input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
***************************
Gamma Ray Energy Deposition
***************************

.. toctree::
gammaray_deposition
70 changes: 70 additions & 0 deletions tardis/energy_input/GXPacket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from enum import IntEnum
import numpy as np
from numba import int64, float64
from numba.experimental import jitclass


class GXPacketStatus(IntEnum):
BETA_DECAY = -1
COMPTON_SCATTER = 0
PHOTOABSORPTION = 1
PAIR_CREATION = 2
IN_PROCESS = 3
END = 4


gxpacket_spec = [
("location", float64[:]),
("direction", float64[:]),
("energy_rf", float64),
("energy_cmf", float64),
("nu_rf", float64),
("nu_cmf", float64),
("status", int64),
("shell", int64),
("time_current", float64),
("tau", float64),
]


@jitclass(gxpacket_spec)
class GXPacket(object):
"""
Indivisible gamma-ray packet
"""

def __init__(
self,
location,
direction,
energy_rf,
energy_cmf,
nu_rf,
nu_cmf,
status,
shell,
time_current,
):
self.location = location
self.direction = direction
self.energy_rf = energy_rf
self.energy_cmf = energy_cmf
self.nu_rf = nu_rf
self.nu_cmf = nu_cmf
self.status = status
self.shell = shell
self.time_current = time_current
# TODO: rename to tau_event
self.tau = -np.log(np.random.random())

def get_location_r(self):
"""Calculate radius of the packet

Returns:
float: packet radius
"""
return np.sqrt(
self.location[0] ** 2.0
+ self.location[1] ** 2.0
+ self.location[2] ** 2.0
)
Loading