Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106492513
ComputeIntegrals.py.svn-base
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 26, 08:14
Size
4 KB
Mime Type
text/x-python
Expires
Fri, Mar 28, 08:14 (2 d)
Engine
blob
Format
Raw Data
Handle
25197976
Attached To
rGEAR Gear
ComputeIntegrals.py.svn-base
View Options
#!/usr/bin/env python
import Ptools as pt
from pNbody import myNumeric
from numpy import *
from scipy.integrate import cumtrapz
######################################################
# Parameters
######################################################
# IMF
Mmin = 0.05
Mmax = 50.
a = -1.35
# files
MetalFile = 'MetalEjection.dat'
HeliumCoreFile = 'HeliumCore.dat'
OutputFile = 'chemyves.dat'
# number of elements to follow
nelts = 4
# masses for metal injection
Mmin1 = 10.
Mmax1 = Mmax*1.5
# masses for helium core
Mmin2 = Mmin
Mmax2 = Mmax*1.5
# resolution in mass for integration
dM = 0.001
# number of output points
n = 200
lStep1 = (log10(Mmax*1.25) - log10(Mmin1) )/float(n-1)
lStep2 = (log10(Mmax*1.25) - log10(Mmin2) )/float(n-1)
b = (a+1)/( Mmax**(a+1) - Mmin**(a+1) )
######################################################
#
######################################################
M1,Fe,Mg,Ox,Me = pt.io.read_ascii(MetalFile,[0,1,2,3,4])
Fe = Fe/M1
Mg = Mg/M1
Ox = Ox/M1
Me = Me/M1
# read residual and helium core
M2,Res,Hco = pt.io.read_ascii(HeliumCoreFile,[0,1,2])
Res = Res/M2
Hco = Hco/M2
# linear interpolation
Mi1 = arange(Mmin1,Mmax1+dM,dM)
Mi2 = arange(Mmin2,Mmax2+dM,dM)
#myNumeric.lininterp1d = myNumeric.quadinterp1d
Fei = myNumeric.lininterp1d(Mi1.astype(float32),M1.astype(float32),Fe.astype(float32))
Mgi = myNumeric.lininterp1d(Mi1.astype(float32),M1.astype(float32),Mg.astype(float32))
Oxi = myNumeric.lininterp1d(Mi1.astype(float32),M1.astype(float32),Ox.astype(float32))
Mei = myNumeric.lininterp1d(Mi1.astype(float32),M1.astype(float32),Me.astype(float32))
Resi = myNumeric.lininterp1d(Mi2.astype(float32),M2.astype(float32),Res.astype(float32))
Hcoi = myNumeric.lininterp1d(Mi2.astype(float32),M2.astype(float32),Hco.astype(float32))
Fei = where(Fei<=0,0,Fei)
Mgi = where(Mgi<=0,0,Mgi)
Oxi = where(Oxi<=0,0,Oxi)
Mei = where(Mei<=0,0,Mei)
Resi = where(Resi<=0,0,Resi)
Hcoi = where(Hcoi<=0,0,Hcoi)
# compute integral
IFe = cumtrapz(b*Mi1**a * Fei,Mi1)
IMg = cumtrapz(b*Mi1**a * Mgi,Mi1)
IOx = cumtrapz(b*Mi1**a * Oxi,Mi1)
IMe = cumtrapz(b*Mi1**a * Mei,Mi1)
IRes = cumtrapz(b*Mi2**a * (1-Resi),Mi2)
IHco = cumtrapz(b*Mi2**a * (1-Hcoi),Mi2)
###############################################
# output
###############################################
Ms1 = 10**(arange(n)*lStep1 + log10(Mmin1))
Ms2 = 10**(arange(n)*lStep2 + log10(Mmin2))
# find corresponding values
IFes = myNumeric.lininterp1d(Ms1.astype(float32),Mi1.astype(float32),IFe.astype(float32))
IMgs = myNumeric.lininterp1d(Ms1.astype(float32),Mi1.astype(float32),IMg.astype(float32))
IOxs = myNumeric.lininterp1d(Ms1.astype(float32),Mi1.astype(float32),IOx.astype(float32))
IMes = myNumeric.lininterp1d(Ms1.astype(float32),Mi1.astype(float32),IMe.astype(float32))
IRess = myNumeric.lininterp1d(Ms2.astype(float32),Mi2.astype(float32),IRes.astype(float32))
IHcos = myNumeric.lininterp1d(Ms2.astype(float32),Mi2.astype(float32),IHco.astype(float32))
f = open(OutputFile,'w')
f.write("###########################################\n")
f.write("# Metal Injection #\n")
f.write("###########################################\n")
f.write("\n# Number of points / Number of elements\n")
f.write("%d %d\n"%(n,nelts))
f.write("\n# Int ( 1- Residual ) m^a\n")
f.write("\n%g %g\n"%(Mmin2,lStep2))
for i in range(len(IRess)):
f.write("%e\n"%IRess[i])
f.write("\n# Int ( 1- Helium Core ) m^a\n")
f.write("\n%g %g\n"%(Mmin2,lStep2))
for i in range(len(IHcos)):
f.write("%e\n"%IHcos[i])
f.write("\n# Int ( Fe ) m^a\n")
f.write("\n%g %g\n"%(Mmin1,lStep1))
for i in range(len(IFes)):
f.write("%e\n"%IFes[i])
f.write("\n# Int ( Mg ) m^a\n")
f.write("\n%g %g\n"%(Mmin1,lStep1))
for i in range(len(IMgs)):
f.write("%e\n"%IMgs[i])
f.write("\n# Int ( O ) m^a\n")
f.write("\n%g %g\n"%(Mmin1,lStep1))
for i in range(len(IOxs)):
f.write("%e\n"%IOxs[i])
f.write("\n# Int ( Metals ) m^a\n")
f.write("\n%g %g\n"%(Mmin1,lStep1))
for i in range(len(IMes)):
f.write("%e\n"%IMes[i])
f.close()
###############################################
# plot
###############################################
# plot 1
pt.subplot(211)
pt.plot(M2,Res,'ko')
pt.plot(Mi2,Resi,'k-')
pt.plot(M2,Hco,'ro')
pt.plot(Mi2,Hcoi,'r-')
pt.plot(M1,Fe,'yo')
pt.plot(Mi1,Fei,'y-')
pt.plot(M1,Mg,'go')
pt.plot(Mi1,Mgi,'g-')
pt.plot(M1,Ox,'bo')
pt.plot(Mi1,Oxi,'b-')
pt.plot(M1,Me,'co')
pt.plot(Mi1,Mei,'c-')
pt.semilogx()
pt.semilogy()
pt.axis([Mmin,Mmax1,1e-4,1e0])
# plot 2
pt.subplot(212)
pt.plot(Mi1[1:],IFe*500,'y')
pt.plot(Mi1[1:],IMg*500,'g')
pt.plot(Mi1[1:],IOx*10,'b')
pt.plot(Mi1[1:],IMe*10,'c')
pt.plot(Mi2[1:],IRes,'k')
pt.plot(Mi2[1:],IHco,'r')
'''
pt.plot(Ms1,IFes*500,'o')
pt.plot(Ms1,IMgs*500,'o')
pt.plot(Ms1,IOxs*10 ,'o')
pt.plot(Ms1,IMes*10 ,'o')
pt.plot(Ms2,IRess,'o')
pt.plot(Ms2,IHcos,'o')
'''
pt.semilogx()
pt.axis([Mmin,Mmax1,0.,4*b])
pt.show()
Event Timeline
Log In to Comment