-
-
Notifications
You must be signed in to change notification settings - Fork 410
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
Decay energy chain #2448
Merged
wkerzendorf
merged 35 commits into
tardis-sn:master
from
Knights-Templars:decay_energy_chain
Nov 27, 2023
Merged
Decay energy chain #2448
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fc42f85
Added a function to calculate shell masses
Knights-Templars 52faa24
Added a function to calculate shell masses
Knights-Templars d0e9e23
changed shell masses with the new function
Knights-Templars f77e720
Changed mass fraction to masses in to_inventories()
Knights-Templars f0b7572
Co-authored-by: Wolfgang Kerzendorf <[email protected]…
Knights-Templars 4a5bc6f
Added a function to calculate total decays
Knights-Templars ae66f13
Added a function to calculate energies from gamma rays and positrons.
Knights-Templars 8f46268
added a function to calculate average energies of gamma rays and posi…
Knights-Templars b2a951a
Added a fucntion to calculate each decay chain energies
Knights-Templars adc1ea9
Added dictionaries to handle multiple isotopes
Knights-Templars d19b559
Merge branch 'master' into decay_energy_chain
Knights-Templars 7c76a7f
Changed value to values
Knights-Templars 809cf33
added tests for gamma_ray_transport
Knights-Templars c65626c
Added tests for calculating activity
Knights-Templars ec64ddf
Added test for activity
Knights-Templars c057a02
Added tests for two isotope
Knights-Templars 28b4103
Changed Ni_isotope_mass
Knights-Templars 0d28444
Added pytest paramterize
Knights-Templars 76f30db
Added test for calculating shell masses
Knights-Templars 48eb360
Ran test for checking activity of parent nuclide with analytical solu…
Knights-Templars bdc68e0
The function test_activity matches with the radioactivedecay output u…
Knights-Templars 6b3d9a4
Added tests for checking if iso_dict is returning the right key.
Knights-Templars 0c7521c
Added test for inventories dictionary.
Knights-Templars b06c0e6
Added a test to check if the calculate_average_energy function passes…
Knights-Templars 170d0d1
Added new function for testing energy budget from each decay chain.
Knights-Templars 17a6233
Added a new function for energy per mass
Knights-Templars 56a6d30
Reading in decay radiation data in atom data
Knights-Templars f62643b
Merge branch 'atom_data/nndc' into decay_energy_chain
Knights-Templars 442bcc4
Add
Knights-Templars f2c3122
Added tests for gamma ray transport.
Knights-Templars 3714d87
Added tests for all functions for gamma_ray_transport. Added docstrings.
Knights-Templars 8d97457
Changing decay energy chain
Knights-Templars 17954c5
Added a function to get taus
Knights-Templars fb0d32f
Added tests for multiple isotopes
Knights-Templars 32bd989
Fixes the test calculate shell masses with hand calculated values
Knights-Templars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import pytest | ||
import numpy as np | ||
import numpy.testing as npt | ||
|
||
from tardis.model import SimulationState | ||
from tardis.io.configuration import config_reader | ||
from tardis.energy_input.gamma_ray_transport import ( | ||
calculate_shell_masses, | ||
create_isotope_dicts, | ||
get_all_isotopes, | ||
create_inventories_dict, | ||
calculate_total_decays, | ||
) | ||
import astropy.units as u | ||
import astropy.constants as c | ||
|
||
# pytest.fixtures. | ||
# Return the simulation object. | ||
|
||
|
||
@pytest.fixture() | ||
def config(): | ||
return config_reader.Configuration.from_yaml( | ||
"/Users/anirbandutta/Projects/gamma_ray_tardis/tardis_configv1_density_exponential_nebular.yml" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def simulation_setup(config): | ||
config.model.structure.velocity.start = 1.0 * u.km / u.s | ||
config.model.structure.density.rho_0 = 5.0e2 * u.g / (u.cm**3) | ||
config.supernova.time_explosion = 1.0 * (u.d) | ||
model = SimulationState.from_config(config) | ||
return model | ||
|
||
|
||
def test_activity(simulation_setup): | ||
""" | ||
ni_mass : mass of 56Ni in grams. | ||
Knights-Templars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
model = simulation_setup | ||
t_half = 6.075 * u.d.to(u.s) # day | ||
decay_constant = 0.693 / t_half # sec^-1 | ||
time_delta = 80.0 * u.d.to(u.s) # day | ||
shell_masses = calculate_shell_masses(model) | ||
raw_isotope_abundance = model.raw_isotope_abundance | ||
raw_isotope_abundance_mass = raw_isotope_abundance.apply( | ||
lambda x: x * shell_masses, axis=1 | ||
) | ||
ni_mass = raw_isotope_abundance_mass.loc[28, 56][0] | ||
iso_dict = create_isotope_dicts(raw_isotope_abundance, shell_masses) | ||
inv_dict = create_inventories_dict(iso_dict) | ||
total_decays = calculate_total_decays(inv_dict, time_delta) | ||
simulated_activity = total_decays[0][28, 56]["Ni-56"] | ||
|
||
isotopic_mass = 55.942132 * (u.g) # g | ||
number_of_moles = ni_mass * (u.g) / isotopic_mass | ||
number_of_atoms = number_of_moles * c.N_A | ||
|
||
# Use the radioactivity formula | ||
# N = N_0 e-(lambda * t) | ||
N = number_of_atoms.value * np.exp(-decay_constant * time_delta) | ||
|
||
actual_activity = decay_constant * N | ||
npt.assert_almost_equal(actual_activity, simulated_activity) | ||
|
||
|
||
@pytest.mark.xfail(reason="To be implemented") | ||
def test_calculate_shell_masses(simulation_setup): | ||
model = simulation_setup | ||
volume = 4.2006589e21 * (u.cm**3) | ||
density = 3.3848916e9 * u.g / (u.cm**3) | ||
|
||
shell_masses = calculate_shell_masses() | ||
actual = shell_masses[0].value | ||
desired = (volume * density).value | ||
npt.assert_almost_equal(actual, desired) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The for loop here might be easier to do using the dataframe methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonachitchyan. Do you mean pandas dataframe? Since radioactivedecay gives output as dictionaries. I created dictionaries, as they are easy to manipulate with key, value pairs. Later I convert them to dataframe.