Skip to content
Snippets Groups Projects
Commit 98b86350 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

SNII yields are working

parent eefe0eda
Branches
No related tags found
1 merge request!10Update SWIFT calls
#!/usr/bin/env python3
# ########################################################################
# This file is part of PYSWIFT.
# Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ########################################################################
from pyswiftsim import libstellar
import pyswiftsim
import numpy as np
import matplotlib.pyplot as plt
from time import strftime, gmtime
plt.rc('text', usetex=True)
N = 1000
m_min = 0.08 # in solar mass
m_max = 50
m_wd = 1.4 # white dwarf mass
solMass_in_cgs = 1.989e33
pyswiftsim.downloadYieldsTable()
if __name__ == "__main__":
with pyswiftsim.ParameterFile() as filename:
parser = pyswiftsim.parseYamlFile(filename)
# Get masses
mass = np.logspace(np.log10(m_min), np.log10(m_max), N,
dtype=np.float32)
# transform into internal units
units = parser["InternalUnitSystem"]
unit_mass = units["UnitMass_in_cgs"]
unit_vel = units["UnitVelocity_in_cgs"]
unit_length = units["UnitLength_in_cgs"]
unit_time = unit_length / unit_vel
mass *= solMass_in_cgs / unit_mass
m1 = np.ones(N, dtype=np.float32) * 1e-20 # avoid log(0)
print("Computing supernovae yields...")
yields_snii = libstellar.supernovaeIIYields(filename, m1, mass)
mass_ejected_snii = libstellar.supernovaeIIMassEjected(
filename, m1, mass)
mass_ejected_np_snii = libstellar.supernovaeIIMassEjectedNonProcessed(
filename, m1, mass)
yields_snia = libstellar.supernovaeIaYields(filename)
elements = libstellar.getElements(filename)
# units
mass /= solMass_in_cgs / unit_mass
plt.figure()
date = strftime("%d %b %Y", gmtime())
plt.title("Date: {}".format(date))
for i in range(len(elements)):
p = plt.loglog(mass, yields_snii[:, i], label=elements[i])
plt.loglog(m_wd, yields_snia[i], "o", color=p[0].get_color())
plt.loglog(mass, mass_ejected_snii, label="Mass Ejected")
plt.loglog(mass, mass_ejected_np_snii,
label="Non Processed Mass Ejected")
plt.xlabel("$Mass [M_\odot]$")
plt.ylabel("Mass fraction")
plt.legend()
plt.show()
#!/bin/bash
python plot_yields.py
#!/usr/bin/env python3
# ########################################################################
# This file is part of PYSWIFT.
# Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ########################################################################
from pyswiftsim import libstellar
import pyswiftsim
import numpy as np
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)
N = 10
m_min = 1 # in solar mass
m_max = 50
solMass_in_cgs = 1.989e33
pyswiftsim.downloadYieldsTable()
if __name__ == "__main__":
with pyswiftsim.ParameterFile() as filename:
parser = pyswiftsim.parseYamlFile(filename)
# Get masses
mass = np.logspace(np.log10(m_min), np.log10(m_max), N + 1,
dtype=np.float32)
# transform into internal units
units = parser["InternalUnitSystem"]
unit_mass = units["UnitMass_in_cgs"]
unit_vel = units["UnitVelocity_in_cgs"]
unit_length = units["UnitLength_in_cgs"]
unit_time = unit_length / unit_vel
mass *= solMass_in_cgs / unit_mass
m1 = mass[:-1]
m2 = mass[1:]
print("Computing supernovae yields...")
yields_snii = libstellar.supernovaeIIYields(filename, m1, m2)
mass_ejected_snii = libstellar.supernovaeIIMassEjected(
filename, m1, m2)
mass_ejected_np_snii = libstellar.supernovaeIIMassEjectedNonProcessed(
filename, m1, m2)
m1 /= solMass_in_cgs / unit_mass
yields_snia = libstellar.supernovaeIaYields(filename)
print("Mass used: {}".format(m1))
print("SNII yields obtained: {}".format(yields_snii))
print("SNIa yields obtained: {}".format(yields_snia))
print("SNII mass ejected: {}".format(mass_ejected_snii))
print("SNII non processed mass ejected: {}".format(
mass_ejected_np_snii))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment