From b5d74bd3766987510c23335ce8aac1f93235cef9 Mon Sep 17 00:00:00 2001 From: Knights-Templars Date: Tue, 9 Apr 2024 14:20:28 -0400 Subject: [PATCH] Added old functions --- tardis/energy_input/gamma_ray_transport.py | 89 ++++++++++++++++++++++ tardis/energy_input/main_gamma_ray_loop.py | 12 ++- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/tardis/energy_input/gamma_ray_transport.py b/tardis/energy_input/gamma_ray_transport.py index a7e342daa9b..0412195e1e0 100644 --- a/tardis/energy_input/gamma_ray_transport.py +++ b/tardis/energy_input/gamma_ray_transport.py @@ -88,6 +88,95 @@ def calculate_ejecta_velocity_volume(model): return ejecta_velocity_volume +def calculate_total_decays_old(inventories, time_delta): + """Function to create inventories of isotope + + Parameters + ---------- + model : tardis.Radial1DModel + The tardis model to calculate gamma ray propagation through + + time_end : float + End time of simulation in days + + Returns + ------- + Total decay list : List + list of total decays for x g of isotope for time 't' + """ + time_delta = u.Quantity(time_delta, u.s) + total_decays = {} + for shell, isotopes in inventories.items(): + total_decays[shell] = {} + for isotope, name in isotopes.items(): + # decays = name.decay(time_delta.value, "s") + total_decays[shell][isotope] = name.cumulative_decays( + time_delta.value + ) + return total_decays + + +def create_isotope_dicts_old(raw_isotope_abundance, cell_masses): + """ + Function to create a dictionary of isotopes for each shell with their masses. + + Parameters + ---------- + raw_isotope_abundance : pd.DataFrame + isotope abundance in mass fractions. + cell_masses : numpy.ndarray + shell masses in units of g + + Returns + ------- + isotope_dicts : Dict + dictionary of isotopes for each shell with their ``masses``. + For eg: {0: {(28, 56): {'Ni56': 0.0001}, (27, 57): {'Co56': 0.0001}} + {1: {(28, 56): {'Ni56': 0.0001}, (27, 57): {'Co56': 0.0001}}} etc + + """ + isotope_dicts = {} + for i in range(len(raw_isotope_abundance.columns)): + isotope_dicts[i] = {} + for ( + atomic_number, + mass_number, + ), abundances in raw_isotope_abundance.iterrows(): + isotope_dicts[i][atomic_number, mass_number] = {} + nuclear_symbol = f"{rd.utils.Z_to_elem(atomic_number)}{mass_number}" + isotope_dicts[i][atomic_number, mass_number][nuclear_symbol] = ( + abundances[i] * cell_masses[i].to(u.g).value + ) + + return isotope_dicts + + +def create_inventories_dict_old(isotope_dict): + """Function to create dictionary of inventories for each shell + + Parameters + ---------- + isotope_dict : Dict + dictionary of isotopes for each shell with their ``masses``. + + Returns + ------- + inv : Dict + dictionary of inventories for each shell + For eg: {0: {'Ni56': , + 'Co56': }, + {1: {'Ni56': , + 'Co56': }} etc + """ + inv = {} + for shell, isotopes in isotope_dict.items(): + inv[shell] = {} + for isotope, name in isotopes.items(): + inv[shell][isotope] = rd.Inventory(name, "g") + + return inv + + def calculate_average_energies(raw_isotope_abundance, gamma_ray_lines): """ Function to calculate average energies of positrons and gamma rays diff --git a/tardis/energy_input/main_gamma_ray_loop.py b/tardis/energy_input/main_gamma_ray_loop.py index 8ec0e3faab1..654656300ad 100644 --- a/tardis/energy_input/main_gamma_ray_loop.py +++ b/tardis/energy_input/main_gamma_ray_loop.py @@ -13,6 +13,12 @@ create_inventories_dict, create_isotope_dicts, ) + +from tardis.energy_input.gamma_ray_transport import ( + calculate_total_decays_old, + create_isotope_dicts_old, + create_inventories_dict_old, +) from tardis.energy_input.gamma_ray_packet_source import RadioactivePacketSource from tardis.energy_input.gamma_ray_transport import ( calculate_average_energies, @@ -104,9 +110,9 @@ def run_gamma_ray_loop( mass_density_time = shell_masses[:, np.newaxis] * inv_volume_time gamma_ray_lines = get_nuclear_lines_database(path_to_decay_data) - isotope_dict = create_isotope_dicts(raw_isotope_abundance, shell_masses) - inventories_dict = create_inventories_dict(isotope_dict) - total_decays = calculate_total_decays( + isotope_dict = create_isotope_dicts_old(raw_isotope_abundance, shell_masses) + inventories_dict = create_inventories_dict_old(isotope_dict) + total_decays = calculate_total_decays_old( inventories_dict, time_end - time_start )