Skip to content
Snippets Groups Projects

New implementation

Merged Loic Hausammann requested to merge new_implementation into master
7 files
+ 248
5
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 57
0
#!/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 = 1000
solar_metallicity = 0.02041
if __name__ == "__main__":
with pyswiftsim.ParameterFile() as filename:
parser = pyswiftsim.parseYamlFile(filename)
# Get masses
imf = parser["GEARInitialMassFunction"]
mass_limits = imf["mass_limits"]
mass_min = np.log10(mass_limits[0])
mass_max = np.log10(mass_limits[-1])
mass = np.logspace(mass_min, mass_max, N, dtype=np.float32)
# get metallicity
Z = solar_metallicity * np.ones(N, dtype=np.float32)
print("Computing lifetime...")
lifetime = libstellar.lifetimeFromMass(filename, mass, Z)
lifetime /= 1e6
plt.loglog(mass, lifetime)
plt.xlabel("Mass [Msun]")
plt.ylabel("Lifetime [Myr]")
plt.show()
Loading