def pulseC(x, re=1., om=1., px=1.): h = x[-1] / 2 mu = sqrt(om * re / 2.) * h nu = sqrt(om * re / 2.) * (x - h) d = px / (om * (cos(mu)**2 * cosh(mu)**2 + sin(mu)**2 * sinh(mu)**2)) return (d * (cos(nu) * cosh(nu) * sin(mu) * sinh(mu) - sin(nu) * sinh(nu) * cos(mu) * cosh(mu)))
def rtc(self,z): "comoving transverse a.k.a. proper motion distance" Dh = self.cH Dc = self.rc(z) sqOmR = M.sqrt(abs(self.k0)) if self.k0 > 0: Dm = Dh / sqOmR * M.sinh(sqOmR*Dc/Dh) elif self.k0 < 0: Dm = Dh / sqOmR * M.sin (sqOmR*Dc/Dh); else: Dm = Dc return Dm
def main(): args = parseCMD() # Check if our data file exists, if not: write one. # Otherwise, open the file and plot. check = glob.glob('*JackKnifeData_Cv.dat*') if check == []: fileNames = args.fileNames skip = args.skip temps, Cvs, CvsErr = pl.array([]), pl.array([]), pl.array([]) timeSteps = pl.array([]) # open new data file, write headers fout = open('JackKnifeData_Cv.dat', 'w') fout.write('#%09s\t%10s\t%10s\t%10s\n' % ('T', 'tau', 'Cv', 'CvErr')) # perform jackknife analysis of data, writing to disk for fileName in fileNames: tau = float(fileName[-21:-14]) temp = float(fileName[-40:-34]) timeSteps = pl.append(timeSteps, tau) temps = pl.append(temps, temp) EEcv, Ecv, dEdB = pl.loadtxt(fileName, unpack=True, usecols=(11, 12, 13)) jkAve, jkErr = aTools.jackknife(EEcv[skip:], Ecv[skip:], dEdB[skip:]) print '<est> = ', jkAve, ' +/- ', jkErr Cvs = pl.append(Cvs, jkAve) CvsErr = pl.append(CvsErr, jkErr) fout.write('%10s\t%10s\t%10s\t%10s\n' % (temp, tau, jkAve, jkErr)) fout.close() else: print 'Found existing data file in CWD.' temps, timeSteps, Cvs, CvsErr = pl.loadtxt('JackKnifeData_Cv.dat', unpack=True) # make array of energies Es, EsErr = pl.array([]), pl.array([]) ET, ETerr = pl.array([]), pl.array([]) for fileName in args.fileNames: Ecv, Eth = pl.loadtxt(fileName, unpack=True, usecols=(4, -5)) Es = pl.append(Es, pl.average(Ecv)) ET = pl.append(ET, pl.average(Eth)) EsErr = pl.append(EsErr, pl.std(Ecv) / pl.sqrt(float(len(Ecv)))) ETerr = pl.append(ETerr, pl.std(Eth) / pl.sqrt(float(len(Eth)))) # plot specific heat for QHO tempRange = pl.arange(0.01, 1.0, 0.01) Eanalytic = 0.5 / pl.tanh(1.0 / (2.0 * tempRange)) CvAnalytic = 1.0 / (4.0 * (tempRange * pl.sinh(1.0 / (2.0 * tempRange)))**2) if args.timeStepScaling: pl.figure(1) pl.plot(timeSteps, 0.5 / pl.tanh(1.0 / (2.0 * (temps))), label='Exact') pl.errorbar(timeSteps, Es, EsErr, label='PIMC virial', color='Lime', fmt='o') pl.errorbar(timeSteps, ET, ETerr, label='PIMC therm.', color='Navy', fmt='o') pl.xlabel('Time Step [1/K]') pl.ylabel('Energy [K]') pl.title('1D QHO -- 1 boson -- T=%s' % temps[0]) pl.legend(loc=1) pl.figure(2) pl.plot(timeSteps, 1.0 / (4.0 * (temps * pl.sinh(1.0 / (2.0 * temps)))**2), label='Exact') pl.errorbar(timeSteps, Cvs, CvsErr, label='PIMC virial', color='Navy', fmt='o') pl.xlabel('Time Step [1/K]') pl.ylabel('Specific Heat [K]') pl.title('1D QHO -- 1 boson -- T=%s' % temps[0]) pl.legend(loc=1) else: pl.figure(1) pl.plot(tempRange, CvAnalytic, label='Exact') pl.errorbar(temps, Cvs, CvsErr, label='PIMC', color='Violet', fmt='o') pl.xlabel('Temperature [K]') pl.ylabel('Specific Heat') pl.title('1D QHO -- 1 boson') pl.legend(loc=2) pl.figure(2) pl.plot(tempRange, Eanalytic, label='Exact') pl.errorbar(temps, Es, EsErr, label='PIMC virial', color='Lime', fmt='o') pl.errorbar(temps, ET, ETerr, label='PIMC therm.', color='k', fmt='o') #pl.scatter(temps,Es, label='PIMC') pl.xlabel('Temperature [K]') pl.ylabel('Energy [K]') pl.title('1D QHO -- 1 boson') pl.legend(loc=2) pl.show()
def main(): args = parseCMD() # Check if our data file exists, if not: write one. # Otherwise, open the file and plot. check = glob.glob('*JackKnifeData_Cv.dat*') if check == []: fileNames = args.fileNames skip = args.skip temps,Cvs,CvsErr = pl.array([]),pl.array([]),pl.array([]) Es, EsErr = pl.array([]),pl.array([]) ET, ETerr = pl.array([]),pl.array([]) # open new data file, write headers fout = open('JackKnifeData_Cv.dat', 'w') fout.write('#%15s\t%16s\t%16s\t%16s\t%16s\t%16s\t%16s\n'% ( 'T', 'Ecv', 'EcvErr', 'Et', 'EtErr','Cv', 'CvErr')) # perform jackknife analysis of data, writing to disk for fileName in fileNames: temp = float(fileName[-40:-34]) temps = pl.append(temps, temp) # grab and analyze energy data Ecv,Eth = pl.loadtxt(fileName, unpack=True, usecols=(4,-5)) E = pl.average(Ecv) Et = pl.average(Eth) EErr = pl.std(Ecv)/pl.sqrt(float(len(Ecv))) EtErr = pl.std(Eth)/pl.sqrt(float(len(Eth))) Es = pl.append(Es,E) ET = pl.append(ET, Et) EsErr = pl.append(EsErr, EErr) ETerr = pl.append(ETerr, EtErr) # grab and analyze specific heat data EEcv, Ecv, dEdB = pl.loadtxt(fileName, unpack=True, usecols=(11,12,13)) jkAve, jkErr = jk.jackknife(EEcv[skip:],Ecv[skip:],dEdB[skip:]) Cvs = pl.append(Cvs,jkAve) CvsErr = pl.append(CvsErr,jkErr) fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %( temp, E, EErr, Et, EtErr, jkAve, jkErr)) print 'T = ',str(temp),' complete.' fout.close() else: print 'Found existing data file in CWD.' temps,Es,EsErr,ET,ETerr,Cvs,CvsErr = pl.loadtxt( 'JackKnifeData_Cv.dat', unpack=True) # plot specific heat for QHO tempRange = pl.arange(0.01,1.0,0.01) Eanalytic = 0.5/pl.tanh(1.0/(2.0*tempRange)) CvAnalytic = 1.0/(4.0*(tempRange*pl.sinh(1.0/(2.0*tempRange)))**2) pl.figure(1) ax1 = pl.subplot(211) pl.plot(tempRange,CvAnalytic, label='Exact') pl.errorbar(temps,Cvs,CvsErr, label='PIMC',color='Violet',fmt='o') pl.ylabel('Specific Heat',fontsize=20) pl.title('1D QHO -- 1 boson',fontsize=20) pl.legend(loc=2) pl.setp(ax1.get_xticklabels(), visible=False) ax2 = pl.subplot(212, sharex=ax1) pl.plot(tempRange,Eanalytic, label='Exact') pl.errorbar(temps,Es,EsErr, label='PIMC virial',color='Lime',fmt='o') pl.errorbar(temps,ET,ETerr, label='PIMC therm.',color='k',fmt='o') #pl.scatter(temps,Es, label='PIMC') pl.xlabel('Temperature [K]',fontsize=20) pl.ylabel('Energy [K]',fontsize=20) pl.legend(loc=2) pl.savefig('1Dqho_largerCOM_800000bins_CvANDenergy.pdf', format='pdf', bbox_inches='tight') pl.show()
Ts = [pl.around(0.01*(x+1),3) for x in range(0,500)] ns = [20] Js = [1] states = [1] #This is where results could be filtered according to parameters if necessary if fileio.checkparameters([ns,states,Js,Ts],[n,state,J,T]): print("Current file: %s" % f) sys.stdout.flush() Etotals,Stotals = fileio.readdata(join("results",f)) Eaverages = pl.array(Etotals) / n**2 Saverages = pl.array(Stotals) / n**2 chi.append(1/T*pl.var(Saverages)) Cv.append(1/T**2*pl.var(Eaverages)) Smean.append(pl.absolute(pl.mean(Saverages))) Emean.append(pl.mean(Eaverages)) Tc = 2*float(J1)/pl.log(1.+pl.sqrt(2.)) Stheory = [(1 - (pl.sinh(pl.log(1+pl.sqrt(2.))*Tc/T))**(-4))**(1./8) for T in Ts if T < Tc] Stheory += [0 for T in Ts if T >= Tc] time = datetime.datetime.now() filename = join("results","results_%s.txt" % time.strftime("%H:%M:%S_%d-%m-%Y")) fileio.writedata(filename,[Ts,Emean,Smean,Stheory,Cv,chi]) system("git add %s" % filename) system("git commit %s -m 'Added results'" % filename) system("git push origin master")
def phiPrime2(self,t): return 0.5*M.pi*t*M.cosh(t)/M.cosh(0.5*M.pi*M.sinh(t))**2+M.tanh(0.5*M.pi*M.sinh(t))
def phi2(self,t): return t*M.tanh(0.5*M.pi*M.sinh(t))
def eph2D(self,epoch): if self.ref == None: return ([0,0,0],[0,0,0]) dt = epoch-self.epoch #print "dT",dt # Step 1 - Determine mean anomaly at epoch if self.e == 0: M = self.M0 + dt * sqrt(self.ref.mu / self.a**3) M %= PI2 E = M ta = E r3 = (self.h**2/self.ref.mu) rv = r3 * array([cos(ta),sin(ta),0]) v3 = self.ref.mu / self.h vv = v3 * array([-sin(ta),self.e+cos(ta),0]) return (rv,vv) if self.e < 1: if epoch == self.epoch: M = self.M0 else: M = self.M0 + dt * sqrt(self.ref.mu / self.a**3) M %= PI2 # Step 2a - Eccentric anomaly try: E = so.newton(lambda x: x-self.e * sin(x) - M,M) except RuntimeError: # Debugging a bug here, disregard print "Eccentric anomaly failed for",self.obj.name print "On epoch",epoch print "Made error available at self.ERROR" self.ERROR = [lambda x: x-self.e * sin(x) - M,M] raise # Step 3a - True anomaly, method 1 ta = 2 * arctan2(sqrt(1+self.e)*sin(E/2.0), sqrt(1-self.e)*cos(E/2.0)) #print "Ta:",ta # Method b is faster cosE = cos(E) ta2 = arccos((cosE - self.e) / (1-self.e*cosE)) #print "e",self.e #print "M",M #print "E",E #print "TA:",ta #print "T2:",ta2 # Step 4a - distance to central body (eccentric anomaly). r = self.a*(1-self.e * cos(E)) # Alternative (true anomaly) r2 = (self.a*(1-self.e**2) / (1.0 + self.e * cos(ta))) # Things get crazy #h = sqrt(self.a*self.ref.mu*(1-self.e**2)) r3 = (self.h**2/self.ref.mu)*(1.0/(1.0+self.e*cos(ta))) #print "R1:",r #print "R2:",r2 #print "R3:",r3 rv = r3 * array([cos(ta),sin(ta),0]) #v1 = sqrt(self.ref.mu * (2.0/r - 1.0/self.a)) #v2 = sqrt(self.ref.mu * self.a) / r v3 = self.ref.mu / self.h #meanmotion = sqrt(self.ref.mu / self.a**3) #v2 = sqrt(self.ref.mu * self.a)/r #print "v1",v1 #print "v2",v2 #print "v3",v3 #print "mm",meanmotion # Velocity can be calculated from the eccentric anomaly #vv = v1 * array([-sin(E),sqrt(1-self.e**2) * cos(E),0]) # Or from the true anomaly (this one has an error..) #vv = sqrt(self.ref.mu * self.a)/r * array([-sin(ta),self.e+cos(ta),0]) vv = v3 * array([-sin(ta),self.e+cos(ta),0]) #print "rv",rv #print "vv",vv #print "check",E,-sin(E),v1*-sin(E) #print "V1:",vv #print "V2:",vv2 return (rv,vv) elif self.e > 1: # Hyperbolic orbits # Reference: Stephen Kemble: Interplanetary Mission Analysis and Design, Pg 220-221 M = self.M0 + dt * sqrt(-(self.ref.mu / self.a**3)) #print "M0",self.M0 #print "M",M #print "M",M #print "M0",self.M0 # Step 2b - Hyperbolic eccentric anomaly #print "Hyperbolic mean anomaly:",M F = so.newton(lambda x: self.e * sinh(x) - x - M,M,maxiter=1000) #F = -F H = M / (self.e-1) #print "AAAA"*10 #print "F:",F #print "H:",H #F=H #print "Hyperbolic eccentric anomaly:",F # Step 3b - Hyperbolic true anomaly? # This is wrong prooobably #hta = arccos((cosh(F) - self.e) / (1-self.e*cosh(F))) #hta = arccos((self.e-cosh(F)) / (self.e*cosh(F) - 1)) # TÄSSÄ ON BUGI hta = arccos((cosh(F) - self.e) / (1 - self.e*cosh(F))) hta2 = 2 * arctan2(sqrt(self.e+1)*sinh(F/2.0),sqrt(self.e-1)*cosh(F/2.0)) hta3 = 2 * arctan2(sqrt(1+self.e)*sinh(F/2.0),sqrt(self.e-1)*cosh(F/2.0)) hta4 = 2 * arctan2(sqrt(self.e-1)*cosh(F/2.0),sqrt(1+self.e)*sinh(F/2.0)) #print "Hyperbolic true anomaly:",degrees(hta) # This is wrong too #hta2 = 2 * arctan2(sqrt(1+self.e)*sin(F/2.0), sqrt(1-self.e)*cos(F/2.0)) if M == self.M0: print "HTA1:",degrees(hta) print "HTA2:",degrees(hta2) print "HTA3:",degrees(hta3) print "HTA4:",degrees(hta4) # According to http://mmae.iit.edu/~mpeet/Classes/MMAE441/Spacecraft/441Lecture17.pdf # this is right.. hta = hta2 #print cos(hta) #print cosh(hta) #####hta = arctan(sqrt((self.e-1.0)/self.e+1.0) * tanh(F/2.0)) / 2.0 #print "Mean anomaly:",M #print "Hyperbolic eccentric anomaly:",F #print "HTA:",hta #raise # Step 4b - Distance from central body? # Can calculate it from hyperbolic true anomaly.. #p = self.a*(1-self.e**2) #r = p / (1+self.e * cos(hta)) r3 = (self.h**2/self.ref.mu)*(1.0/(1.0+self.e*cos(hta))) v3 = self.ref.mu / self.h # But it's faster to calculate from eccentric anomaly #r = self.a*(1-self.e * cos(F)) #print "Hyper r1:",r #print "Hyper r2:",r2 rv = r3 * array([cos(hta),sin(hta),0]) #http://en.wikipedia.org/wiki/Hyperbola #rv = array([ r * sin(hta),-self.a*self.e + r * cos(hta), 0]) #sinhta = sin(hta) #coshta = cos(hta) #print self.ref.mu,r,self.a,hta #vv = sqrt(self.ref.mu *(2.0/r - 1.0/self.a)) * array([-sin(hta),self.e+cos(hta),0]) vv = v3 * array([-sin(hta),self.e+cos(hta),0]) return (rv,vv)
def initFromStateVectors(self,epoch,pV,vV): self.epoch = epoch # 1) Calculate auxilary vector h hV = cross(pV,vV) # 2) Normalize position,velocity, specific angular momentum, calculate radial velocity p = linalg.norm(pV) v = linalg.norm(vV) h = linalg.norm(hV) print "H:",h radv = pV.dot(vV) / p hVu = hV / h pVu = pV / p nV = cross(array([0,0,1]),hV) n = linalg.norm(nV) if n == 0: nVu = array([0,0,0]) else: nVu = nV/n # 3) Calculate inclination #self.i = arccos(hV[2]/h) self.i = arcsin(linalg.norm(cross(array([0,0,1]),hVu))) print "i1",self.i print "RADVEL",radv self.i = arccos(array([0,0,1]).dot(hV)/h) #if radv < 0: # self.i = PI2 - self.i print "i2",self.i # 4) Calculate node line # 5) Calculate longitude of ascending node = right ascension of ascending node ''' if self.i == 0: self.lan=0 elif nV[1] >= 0: self.lan = arccos(nV[0] / n) else: self.lan = PI2 - arccos(nV[0] / n) ''' if self.i == 0: self.lan = 0 else: self.lan = arcsin(cross(array([1,0,0]),nVu).dot(array([0,0,1]))) print "lan1",self.lan self.lan = arccos(array([1,0,0]).dot(nV)/n) if nV[1] < 0: self.lan = PI2-self.lan print "lan2",self.lan # 6) Eccentricity vector #eV = (1.0 / self.ref.mu)*((v**2 - (self.ref.mu / p))*pV - radv*vV) #eV2 = (1.0 / self.ref.mu) * ( hV - self.ref.mu * (pV/p)) #eV3 = hV/self.ref.mu - (pV/p) # Source: cdeagle eV = cross(vV,hV)/self.ref.mu - pVu #print "eV1:",eV,linalg.norm(eV) #print "eV2:",eV2,linalg.norm(eV2) #print "eV3:",eV3,linalg.norm(eV3) print "eV3:",eV,linalg.norm(eV) self._e = linalg.norm(eV) #eVu = eV / self.e print "h",h print "u",self.ref.mu print "v",v print "r",p print "alte:",sqrt(1+(h**2/self.ref.mu**2)*(v**2-(2*self.ref.mu)/p)**2) # 7) Argument of perigree ''' if self.e == 0: self.aop = 0 elif self.i == 0: self.aop = arccos(eV[0] / self.e) elif eV[2] >= 0: print "AOP AOP AOP" #self.aop = arccos(nV.dot(eV) / (n*self.e)) print cross(nV,eV).dot(hV) self.aop = arcsin(cross(nVu,eVu).dot(hVu)) #self.aop = arccos(n*self.e) else: self.aop = PI2 - arccos(nV.dot(eV) / (n*self.e)) ''' #CDEagle method # TODO CHECK how KSP handles this. if self.e == 0: self.aop = 0 elif self.i == 0 and self.e != 0: #self.aop = arccos(eV[0] / self.e) #self.aop = arctan2(eV[1],eV[0]) self.aop = arccos(array([1,0,0]).dot(eV) / self.e) print eV if eV[2] < 0: #self.aop = -self.aop self.aop = PI2-self.aop #print "BOOM",eV #if eV[2] < 0: # print "BAM N***A" # self.aop = PI2 - self.aop elif self.i == 0 and self.e == 0: #raise AttributeError("Perfectly circular orbits are not supported atm") self.aop = 0 else: #self.aop = arcsin(cross(nVu,eVu).dot(hVu)) self.aop = arccos(nV.dot(eV)/(n*self.e)) if eV[2] < 0: self.aop = PI2-self.aop # 8) Semi major axis aE = v**2/2.0 - self.ref.mu / p self._a = -self.ref.mu / (2*aE) print "Old method for semi-major",self.a self._a = h**2 / (self.ref.mu * (1-self.e**2)) print "New method for semi-major",self.a #if self.e > 1: # self._a = h**2 / (self.ref.mu * (self.e**2 - 1)) if self.e == 0: if self.i == 0: #TODO update document to this print "JEA JEA JEA JEA"*10 ta = arccos(array([1,0,0]).dot(pV) / p) if pV[1] < 0: # Vallado pg. 111 ta = PI2 - ta else: #TODO VERIFY THIS CASE ta = arccos((nV.dot(pV))/(n*p)) if pV[2] < 0: # Vallado pg. 110 ta = PI2 - ta E = ta self.M0 = E elif self.e < 1: # 9) True anomaly, eccentric anomaly and mean anomaly if radv >= 0: ta = arccos((eV / self.e).dot(pV/p)) else: ta = PI2 - arccos((eV / self.e).dot(pV/p)) E = arccos((self.e+cos(ta))/(1+ self.e*cos(ta))) if radv < 0: E = PI2 - E self.M0 = E - self.e * sin(E) elif self.e > 1: # 9) Hyperbolic True anomaly, eccentric anomaly and mean anomaly # http://scienceworld.wolfram.com/physics/HyperbolicOrbit.html V = arccos((abs(self.a)*(self.e**2 - 1)) /(self.e * p) - 1/self.e) ta = arccos((eV / self.e).dot(pV/p)) if radv < 0: #TODO: Should affect F too? # Negative = heading towards periapsis print "PI2" V = PI2 - V ta = PI2-ta print "V",V print "TA",ta # http://www.bogan.ca/orbits/kepler/orbteqtn.html In you I trust # Hyperbolic eccentric anomaly cosV = cos(V) F = arccosh((self.e+cosV)/(1+self.e*cosV)) if radv < 0: F = -F F2 = arcsinh((sqrt(self.e-1)*sin(V))/(1+self.e*cos(V))) ##F1 = F2 print "F1:",F print "F2:",F2 self.M0 = self.e * sinh(F) - F self.h = h print "Semi-major:",self.a print "Eccentricity:",self.e print "Inclination:",degrees(self.i),"deg" print "LAN:",degrees(self.lan),"deg" print "AoP:",degrees(self.aop),"deg" print "Mean anomaly:",self.M0 print "Specific angular momentum:",self.h if self.e < 1: print "Eccentric anomaly",E print "True anomaly",ta else: print "Hyperbolic eccentric anomaly",F print "Hyperbolic true anomaly",degrees(V) print "Distance from object:",p print "Velocity:",v
def main(): args = aTools.parseCMD() # Check if our data file exists, if not: write one. # Otherwise, open the file and plot. check = glob.glob('*JackKnifeData_Cv.dat*') fileNames = args.fileNames skip = args.skip # check which ensemble canonical=True if fileNames[0][0]=='g': canonical=False print fileNames if check == []: temps,Cvs,CvsErr = pl.array([]),pl.array([]),pl.array([]) Es, EsErr = pl.array([]), pl.array([]) rhos_rhos, rhos_rhoErr = pl.array([]), pl.array([]) # open energy/ specific heat data file, write headers fout = open('JackKnifeData_Cv.dat', 'w') fout.write('#%15s\t%16s\t%16s\t%16s\t%16s\n'% ( 'T', 'E', 'Eerr', 'Cv', 'CvErr')) # open superfluid stiffness data file, write headers foutSup = open('JackKnifeData_super.dat','w') foutSup.write('#%15s\t%16s\t%16s\n'%( 'T', 'rho_s/rho', 'rho_s/rhoErr')) # perform jackknife analysis of data, writing to disk if args.Crunched: # check if we have combined data tempList = aTools.getHeadersFromFile(fileNames[0]) for temp in tempList: temps = pl.append(temps,float(temp)) n,n2 = 0,0 for fileName in fileNames: print '\n\n---',fileName,'---\n' for temp in tempList: print n if 'Estimator' in fileName: E, EEcv, Ecv, dEdB = pl.loadtxt(fileName,\ unpack=True, usecols=(n,n+1,n+2,n+3), delimiter=',') EAve, Eerr = aTools.jackknife(E[skip:]) jkAve, jkErr = aTools.jackknife( EEcv[skip:],Ecv[skip:],dEdB[skip:]) print 'T = ',float(temp),':' print '<E> = ',EAve,' +/- ',Eerr print '<Cv> = ',jkAve,' +/- ',jkErr Es = pl.append(Es, EAve) Cvs = pl.append(Cvs, jkAve) EsErr = pl.append(EsErr, Eerr) CvsErr = pl.append(CvsErr, jkErr) fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %( float(temp), EAve, Eerr, jkAve, jkErr)) n += 4 elif 'Super' in fileName: rhos_rho = pl.loadtxt(fileName, \ unpack=True, usecols=(n2,), delimiter=',') superAve, superErr = aTools.jackknife(rhos_rho[skip:]) print 'rho_s/rho = ', superAve,' +/- ',superErr rhos_rhos = pl.append(rhos_rhos, superAve) rhos_rhoErr = pl.append(rhos_rhoErr, superErr) foutSup.write('%16.8E\t%16.8E\t%16.8E\n' %( float(temp), superAve, superErr)) n2 += 1 else: # otherwise just read in individual (g)ce-estimator files for fileName in fileNames: if canonical: temp = float(fileName[13:19]) else: temp = float(fileName[14:20]) temps = pl.append(temps, temp) E, EEcv, Ecv, dEdB = pl.loadtxt(fileName, unpack=True, usecols=(4,11,12,13)) jkAve, jkErr = aTools.jackknife( EEcv[skip:],Ecv[skip:],dEdB[skip:]) EAve, Eerr = aTools.jackknife(E[skip:]) print 'T = ',temp print '<Cv> = ',jkAve,' +/- ',jkErr print '<E> = ',EAve,' +/- ',Eerr Es = pl.append(Es, EAve) Cvs = pl.append(Cvs, jkAve) EsErr = pl.append(EsErr, Eerr) CvsErr = pl.append(CvsErr, jkErr) fout.write('%16.8E\t%16.8E\t%16.8E\t%16.8E\t%16.8E\n' %( float(temp), EAve, Eerr, jkAve, jkErr)) fout.close() else: print 'Found existing data file in CWD.' temps, Es, EsErr, Cvs, CvsErr = pl.loadtxt('JackKnifeData_Cv.dat', unpack=True) temps, rhos_rhos, rhos_rhoErr = pl.loadtxt('JackKnifeData_super.dat', unpack=True) errCheck = False if errCheck: EsNorm, EsErrNorm = pl.array([]), pl.array([]) for fileName in args.fileNames: #Ecv,Eth = pl.loadtxt(fileName, unpack=True, usecols=(4,-5)) Ecv = pl.loadtxt(fileName, unpack=True, usecols=(4,)) EsNorm = pl.append(EsNorm,pl.average(Ecv)) #ET = pl.append(ET, pl.average(Eth)) EsErrNorm = pl.append(EsErrNorm, pl.std(Ecv)/pl.sqrt(float(len(Ecv)))) #ETerr = pl.append(ETerr, pl.std(Eth)/pl.sqrt(float(len(Eth)))) pl.scatter(temps, EsErrNorm, label='Standard Error', color='Navy') pl.scatter(temps, EsErr, label='Jackknife Error', color='Orange') pl.grid() pl.legend() pl.show() QHO = False if QHO: # analytical solutions for 1D QHO with one particle tempRange = pl.arange(0.01,1.0,0.01) Eanalytic = 0.5/pl.tanh(1.0/(2.0*tempRange)) CvAnalytic = 1.0/(4.0*(tempRange*pl.sinh(1.0/(2.0*tempRange)))**2) ShareAxis=True # shared x-axis for Cv and Energy # plot the specific heat vs. temperature if ShareAxis: ax1 = pl.subplot(211) else: pl.figure(1) if QHO: # plot analytic result pl.plot(tempRange,CvAnalytic, label='Exact') pl.errorbar(temps,Cvs,CvsErr, label='PIMC',color='Violet',fmt='o') if not ShareAxis: pl.xlabel('Temperature [K]') pl.ylabel('Specific Heat', fontsize=20) pl.grid(True) pl.legend(loc=2) # plot the energy vs. temperature if ShareAxis: pl.setp(ax1.get_xticklabels(), visible=False) ax2 = pl.subplot(212, sharex=ax1) else: pl.figure(2) if QHO: # plot analytic result pl.plot(tempRange,Eanalytic, label='Exact') pl.errorbar(temps,Es,EsErr, label='PIMC virial',color='Lime',fmt='o') pl.xlabel('Temperature [K]', fontsize=20) pl.ylabel('Energy [K]', fontsize=20) pl.grid(True) pl.legend(loc=2) pl.savefig('Helium_critical_CVest.pdf', format='pdf', bbox_inches='tight') if ShareAxis: pl.figure(2) else: pl.figure(3) pl.errorbar(temps, rhos_rhos, rhos_rhoErr) pl.xlabel('Temperature [K]', fontsize=20) pl.ylabel('Superfluid Stiffness', fontsize=20) pl.grid(True) pl.show()
def lambert(r1vec,r2vec,tf,m,muC): # original documentation: # ············································· # # This routine implements a new algorithm that solves Lambert's problem. The # algorithm has two major characteristics that makes it favorable to other # existing ones. # # 1) It describes the generic orbit solution of the boundary condition # problem through the variable X=log(1+cos(alpha/2)). By doing so the # graph of the time of flight become defined in the entire real axis and # resembles a straight line. Convergence is granted within few iterations # for all the possible geometries (except, of course, when the transfer # angle is zero). When multiple revolutions are considered the variable is # X=tan(cos(alpha/2)*pi/2). # # 2) Once the orbit has been determined in the plane, this routine # evaluates the velocity vectors at the two points in a way that is not # singular for the transfer angle approaching to pi (Lagrange coefficient # based methods are numerically not well suited for this purpose). # # As a result Lambert's problem is solved (with multiple revolutions # being accounted for) with the same computational effort for all # possible geometries. The case of near 180 transfers is also solved # efficiently. # # We note here that even when the transfer angle is exactly equal to pi # the algorithm does solve the problem in the plane (it finds X), but it # is not able to evaluate the plane in which the orbit lies. A solution # to this would be to provide the direction of the plane containing the # transfer orbit from outside. This has not been implemented in this # routine since such a direction would depend on which application the # transfer is going to be used in. # # please report bugs to [email protected] # # adjusted documentation: # ······················· # # By default, the short-way solution is computed. The long way solution # may be requested by giving a negative value to the corresponding # time-of-flight [tf]. # # For problems with |m| > 0, there are generally two solutions. By # default, the right branch solution will be returned. The left branch # may be requested by giving a negative value to the corresponding # number of complete revolutions [m]. # Authors # .·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·.·`·. # Name : Dr. Dario Izzo # E-mail : [email protected] # Affiliation: ESA / Advanced Concepts Team (ACT) # Made readible and optimized for speed by Rody P.S. Oldenhuis # Code available in MGA.M on http://www.esa.int/gsp/ACT/inf/op/globopt.htm # last edited 12/Dec/2009 # ADJUSTED FOR EML-COMPILATION 24/Dec/2009 # initial values tol = 1e-12 bad = False days = 1 # work with non-dimensional units r1 = norm(r1vec) #sqrt(r1vec*r1vec.'); r1vec = r1vec/r1; r1vec = r1vec / r1 r2vec = r2vec / r1 V = sqrt(muC/r1) T = r1/V tf= tf*days/T # also transform to seconds # relevant geometry parameters (non dimensional) mr2vec = norm(r2vec) # make 100# sure it's in (-1 <= dth <= +1) dth = arccos( max(-1, min(1, (r1vec.dot(r2vec)/mr2vec)))) # decide whether to use the left or right branch (for multi-revolution # problems), and the long- or short way leftbranch = sign(m) longway = sign(tf) m = abs(m) tf = abs(tf) if (longway < 0): dth = 2*pi - dth # derived quantities c = sqrt(1.0 + mr2vec**2 - 2*mr2vec*cos(dth)) # non-dimensional chord s = (1.0 + mr2vec + c)/2.0 # non-dimensional semi-perimeter a_min = s/2.0 # minimum energy ellipse semi major axis Lambda = sqrt(mr2vec)*cos(dth/2.0)/s # lambda parameter (from BATTIN's book) crossprd = cross(r1vec,r2vec) mcr = norm(crossprd) # magnitues thereof nrmunit = crossprd/mcr # unit vector thereof # Initial values # ························································· # ELMEX requires this variable to be declared OUTSIDE the IF-statement logt = log(tf); # avoid re-computing the same value # single revolution (1 solution) if (m == 0): # initial values inn1 = -0.5233 # first initial guess inn2 = +0.5233 # second initial guess x1 = log(1 + inn1)# transformed first initial guess x2 = log(1 + inn2)# transformed first second guess # multiple revolutions (0, 1 or 2 solutions) # the returned soltuion depends on the sign of [m] else: # select initial values if (leftbranch < 0): inn1 = -0.5234 # first initial guess, left branch inn2 = -0.2234 # second initial guess, left branch else: inn1 = +0.7234 # first initial guess, right branch inn2 = +0.5234 # second initial guess, right branch x1 = tan(inn1*pi/2)# transformed first initial guess x2 = tan(inn2*pi/2)# transformed first second guess # since (inn1, inn2) < 0, initial estimate is always ellipse xx = array([inn1, inn2]) aa = a_min/(1 - xx**2) bbeta = longway * 2*arcsin(sqrt((s-c)/2./aa)) # make 100.4% sure it's in (-1 <= xx <= +1) if xx[0] > 1: xx[0] = 1 if xx[0] < -1: xx[0] = -1 if xx[1] > 1: xx[1] = 1 if xx[1] < -1: xx[1] = -1 aalfa = 2*arccos( xx ) # evaluate the time of flight via Lagrange expression y12 = aa*sqrt(aa)*((aalfa - sin(aalfa)) - (bbeta-sin(bbeta)) + 2*pi*m) # initial estimates for y if m == 0: y1 = log(y12[0]) - logt y2 = log(y12[1]) - logt else: y1 = y12[0] - tf y2 = y12[1] - tf # Solve for x # ························································· # Newton-Raphson iterations # NOTE - the number of iterations will go to infinity in case # m > 0 and there is no solution. Start the other routine in # that case err = 1e99 iterations = 0 xnew = 0 while (err > tol): # increment number of iterations iterations += 1 # new x xnew = (x1*y2 - y1*x2) / (y2-y1); # copy-pasted code (for performance) if m == 0: x = exp(xnew) - 1 else: x = arctan(xnew)*2/pi a = a_min/(1 - x**2); if (x < 1): # ellipse beta = longway * 2*arcsin(sqrt((s-c)/2/a)) # make 100.4% sure it's in (-1 <= xx <= +1) alfa = 2*arccos( max(-1, min(1, x)) ) else: # hyperbola alfa = 2*arccosh(x); beta = longway * 2*arcsinh(sqrt((s-c)/(-2*a))) # evaluate the time of flight via Lagrange expression if (a > 0): tof = a*sqrt(a)*((alfa - sin(alfa)) - (beta-sin(beta)) + 2*pi*m) else: tof = -a*sqrt(-a)*((sinh(alfa) - alfa) - (sinh(beta) - beta)) # new value of y if m ==0: ynew = log(tof) - logt else: ynew = tof - tf # save previous and current values for the next iterarion # (prevents getting stuck between two values) x1 = x2; x2 = xnew; y1 = y2; y2 = ynew; # update error err = abs(x1 - xnew); # escape clause if (iterations > 15): bad = True break # If the Newton-Raphson scheme failed, try to solve the problem # with the other Lambert targeter. if bad: # NOTE: use the original, UN-normalized quantities #[V1, V2, extremal_distances, exitflag] = ... # lambert_high_LancasterBlanchard(r1vec*r1, r2vec*r1, longway*tf*T, leftbranch*m, muC); print "FAILZ0r" return # convert converged value of x if m==0: x = exp(xnew) - 1 else: x = arctan(xnew)*2/pi #{ # The solution has been evaluated in terms of log(x+1) or tan(x*pi/2), we # now need the conic. As for transfer angles near to pi the Lagrange- # coefficients technique goes singular (dg approaches a zero/zero that is # numerically bad) we here use a different technique for those cases. When # the transfer angle is exactly equal to pi, then the ih unit vector is not # determined. The remaining equations, though, are still valid. #} # Solution for the semi-major axis a = a_min/(1-x**2); # Calculate psi if (x < 1): # ellipse beta = longway * 2*arcsin(sqrt((s-c)/2/a)) # make 100.4# sure it's in (-1 <= xx <= +1) alfa = 2*arccos( max(-1, min(1, x)) ) psi = (alfa-beta)/2 eta2 = 2*a*sin(psi)**2/s eta = sqrt(eta2); else: # hyperbola beta = longway * 2*arcsinh(sqrt((c-s)/2/a)) alfa = 2*arccosh(x) psi = (alfa-beta)/2 eta2 = -2*a*sinh(psi)**2/s eta = sqrt(eta2) # unit of the normalized normal vector ih = longway * nrmunit; # unit vector for normalized [r2vec] r2n = r2vec/mr2vec; # cross-products # don't use cross() (emlmex() would try to compile it, and this way it # also does not create any additional overhead) #crsprd1 = [ih(2)*r1vec(3)-ih(3)*r1vec(2),... # ih(3)*r1vec(1)-ih(1)*r1vec(3),... # ih(1)*r1vec(2)-ih(2)*r1vec(1)]; crsprd1 = cross(ih,r1vec) #crsprd2 = [ih(2)*r2n(3)-ih(3)*r2n(2),... # ih(3)*r2n(1)-ih(1)*r2n(3),... # ih(1)*r2n(2)-ih(2)*r2n(1)]; crsprd2 = cross(ih,r2n) # radial and tangential directions for departure velocity Vr1 = 1/eta/sqrt(a_min) * (2*Lambda*a_min - Lambda - x*eta) Vt1 = sqrt(mr2vec/a_min/eta2 * sin(dth/2)**2) # radial and tangential directions for arrival velocity Vt2 = Vt1/mr2vec Vr2 = (Vt1 - Vt2)/tan(dth/2) - Vr1 # terminal velocities V1 = (Vr1*r1vec + Vt1*crsprd1)*V V2 = (Vr2*r2n + Vt2*crsprd2)*V # exitflag #exitflag = 1 # (success) #print "V1:",V1 #print "V2:",V2 return V1,V2
Js = [1] states = [1] #This is where results could be filtered according to parameters if necessary if fileio.checkparameters([ns, states, Js, Ts], [n, state, J, T]): print("Current file: %s" % f) sys.stdout.flush() Etotals, Stotals = fileio.readdata(join("results", f)) Eaverages = pl.array(Etotals) / n**2 Saverages = pl.array(Stotals) / n**2 chi.append(1 / T * pl.var(Saverages)) Cv.append(1 / T**2 * pl.var(Eaverages)) Smean.append(pl.absolute(pl.mean(Saverages))) Emean.append(pl.mean(Eaverages)) Tc = 2 * float(J1) / pl.log(1. + pl.sqrt(2.)) Stheory = [(1 - (pl.sinh(pl.log(1 + pl.sqrt(2.)) * Tc / T))**(-4))**(1. / 8) for T in Ts if T < Tc] Stheory += [0 for T in Ts if T >= Tc] time = datetime.datetime.now() filename = join("results", "results_%s.txt" % time.strftime("%H:%M:%S_%d-%m-%Y")) fileio.writedata(filename, [Ts, Emean, Smean, Stheory, Cv, chi]) system("git add %s" % filename) system("git commit %s -m 'Added results'" % filename) system("git push origin master")
def ss(x): return sin(x) * sinh(x)