def correction(Temp, num, chempot, i1, i2): return RG.phi(Temp, num, chempot, i1) - RG.phi(Temp, num, chempot, i2)
def npart(iterations): # Initial conditions; dependent on you system T = 0.5 mu = -5.751 # I found this by plotting. It is good for T=0.5; i=0 nmid = 0.0439651327587 # I found this from running the code with the above mu mu = -RG.df_dn(T, nmid, iterations) Tc = 1.3295 # Rough estimate based on previous plots Tlow = T # Bounds of minimization. # Use range that works for many temperatures # Outside bounds a_vap = 1e-10 / (RG.sigma ** 3 * np.pi / 6) c_liq = 0.75 / (RG.sigma ** 3 * np.pi / 6) # Use the central max as the inside bound nmid = 0.2 / (RG.sigma ** 3 * np.pi / 6) # ad-hoc for now # nmid = minmax_RG.maximize(RG.phi,T,a_vap,c_liq,mu,iterations) ############################### # Open file for output fout = open("figs/coexistence_RG-i%d-out.dat" % iterations, "w") # label the columns of the output fout.write("#T nvapor nmid nliquid phi(nvap) phi(nmid) phi(nliq) mu\n") sys.stdout.flush() # Do first temperature before the loop nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) print " initial nvap,phi_vap", nvapor, phi_vapor print " initial nmid,phi_mid", nmid, RG.phi(T, nmid, mu, iterations) print " initial nliq,phi_liq", nliquid, phi_liquid print " initial mu", mu # while T < 1.4: for j in xrange(0, N + 1): # Temp points get closer as we near the critical point T = (Tc - Tlow) * (1 - ((N - j) / N) ** 4) + Tlow print " T =", T fout.flush() # I'm looking at the minima of RG.phi # Use the local max between vapor and liquid to set the boundary for each minimization # nmid = minmax_RG.maximize(RG.phi,T,nvapor, nliquid, mu,iterations) mu = -RG.df_dn(T, nmid, iterations) # a_vap = max(nmid - 2.0*(nmid - nvapor), a_vap) # c_liq = nmid + 2.0*(nliquid - nmid) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) phi_mid = RG.phi(T, nmid, mu, iterations) tol = 1e-9 # Compare the two minima in RG.phi # print ' entering while loop' while np.fabs(phi_vapor - phi_liquid) / np.fabs(phi_mid) > tol: # np.fabs casts output as float # print ' whilecond =',np.fabs(phi_vapor - phi_liquid)/np.fabs(phi_mid) delta_mu = (phi_liquid - phi_vapor) / (nliquid - nvapor) # print ' delta_mu=',delta_mu # Change mu mu += delta_mu # find new values for nvap, nmid, nliq and phi_vap, phi_mid, phi_liq nmid, phi_mid = ( minmax_RG.maximize(RG.phi, T, nvapor, nliquid, mu, iterations), RG.phi(T, nmid, mu, iterations), ) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) # print ' nvap,phi(nvap)',nvapor,phi_vapor # print ' etavap',nvapor*RG.sigma**3*np.pi/6 # print ' nmid,phi(nmid)',nmid,phi_mid # print ' etamid',nmid*RG.sigma**3*np.pi/6 # print ' nliq,phi(nliq)',nliquid,phi_liquid # print ' etaliq',nliquid*RG.sigma**3*np.pi/6 # print '\n' # if j > N - 20: # plt.figure() # delta_n = nliquid - nvapor # nvals = np.arange(max(nvapor - delta_n, a_vap), min(nliquid + delta_n, c_liq), 0.01*delta_n) # phivals = np.zeros_like(nvals) # for i in range(len(nvals)): # phivals[i] = RG.phi(T,nvals[i],mu,iterations) # plt.plot(nvals*np.pi*RG.sigma**3/6, phivals, 'b-') # plt.plot(nliquid*np.pi*RG.sigma**3/6, RG.phi(T,nliquid,mu,iterations), 'o') # plt.plot(nvapor*np.pi*RG.sigma**3/6, RG.phi(T,nvapor,mu,iterations), 'o') # plt.plot(nmid*np.pi*RG.sigma**3/6, RG.phi(T,nmid,mu,iterations), '+') # plt.title('T = %.14g' % T) if nmid == nvapor or nmid == nliquid: print "I have achieved silliness!" print "This occurred at T =", T # break # print ' left while loop' fout.write(str(T)) fout.write(" ") fout.write(str(nvapor)) fout.write(" ") fout.write(str(nmid)) fout.write(" ") fout.write(str(nliquid)) fout.write(" ") fout.write(str(phi_vapor)) fout.write(" ") fout.write(str(phi_mid)) fout.write(" ") fout.write(str(phi_liquid)) fout.write(" ") fout.write(str(mu)) fout.write("\n") sys.stdout.flush() # print ' T, etaVap, etaLiq, mu',T,nvapor/(RG.sigma**3*np.pi/6),nliquid/(RG.sigma**3*np.pi/6),mu # print '\n' fout.close()
def npart(iterations): # Initial conditions; dependent on you system T = 0.5 mu = -5.751 # I found this by plotting. It is good for T=0.5; i=0 nmid = 0.0439651327587 # I found this from running the code with the above mu mu = -RG.df_dn(T, nmid, iterations) Tc = 1.3295 # Rough estimate based on previous plots Tlow = T # Bounds of minimization. # Use range that works for many temperatures # Outside bounds a_vap = 1e-10/(RG.sigma**3*np.pi/6) c_liq = 0.75/(RG.sigma**3*np.pi/6) # Use the central max as the inside bound nmid = 0.2/(RG.sigma**3*np.pi/6) # ad-hoc for now # nmid = minmax_RG.maximize(RG.phi,T,a_vap,c_liq,mu,iterations) ############################### # Open file for output fout = open('figs/coexistence_RG-i%d-out.dat'%iterations, 'w') # label the columns of the output fout.write('#T nvapor nmid nliquid phi(nvap) phi(nmid) phi(nliq) mu\n') sys.stdout.flush() # Do first temperature before the loop nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) print(' initial nvap,phi_vap', nvapor, phi_vapor) print(' initial nmid,phi_mid', nmid, RG.phi(T, nmid, mu, iterations)) print(' initial nliq,phi_liq', nliquid, phi_liquid) print(' initial mu', mu) #while T < 1.4: for j in range(0, N+1): # Temp points get closer as we near the critical point T = (Tc - Tlow)*(1 - ((N-j)/N)**4) + Tlow print(' T =', T) fout.flush() # I'm looking at the minima of RG.phi # Use the local max between vapor and liquid to set the boundary for each minimization #nmid = minmax_RG.maximize(RG.phi,T,nvapor, nliquid, mu,iterations) mu = -RG.df_dn(T, nmid, iterations) #a_vap = max(nmid - 2.0*(nmid - nvapor), a_vap) #c_liq = nmid + 2.0*(nliquid - nmid) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) phi_mid = RG.phi(T, nmid, mu, iterations) tol = 1e-9 # Compare the two minima in RG.phi # print ' entering while loop' while np.fabs(phi_vapor - phi_liquid)/np.fabs(phi_mid) > tol: # np.fabs casts output as float # print ' whilecond =',np.fabs(phi_vapor - phi_liquid)/np.fabs(phi_mid) delta_mu = (phi_liquid - phi_vapor)/(nliquid - nvapor) # print ' delta_mu=',delta_mu # Change mu mu += delta_mu # find new values for nvap, nmid, nliq and phi_vap, phi_mid, phi_liq nmid, phi_mid = minmax_RG.maximize(RG.phi, T, nvapor, nliquid, mu, iterations), RG.phi(T, nmid, mu, iterations) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, nmid, mu, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, nmid, c_liq, mu, iterations) # print ' nvap,phi(nvap)',nvapor,phi_vapor # print ' etavap',nvapor*RG.sigma**3*np.pi/6 # print ' nmid,phi(nmid)',nmid,phi_mid # print ' etamid',nmid*RG.sigma**3*np.pi/6 # print ' nliq,phi(nliq)',nliquid,phi_liquid # print ' etaliq',nliquid*RG.sigma**3*np.pi/6 # print '\n' # if j > N - 20: # plt.figure() # delta_n = nliquid - nvapor # nvals = np.arange(max(nvapor - delta_n, a_vap), min(nliquid + delta_n, c_liq), 0.01*delta_n) # phivals = np.zeros_like(nvals) # for i in range(len(nvals)): # phivals[i] = RG.phi(T,nvals[i],mu,iterations) # plt.plot(nvals*np.pi*RG.sigma**3/6, phivals, 'b-') # plt.plot(nliquid*np.pi*RG.sigma**3/6, RG.phi(T,nliquid,mu,iterations), 'o') # plt.plot(nvapor*np.pi*RG.sigma**3/6, RG.phi(T,nvapor,mu,iterations), 'o') # plt.plot(nmid*np.pi*RG.sigma**3/6, RG.phi(T,nmid,mu,iterations), '+') # plt.title('T = %.14g' % T) if nmid == nvapor or nmid == nliquid: print('I have achieved silliness!') print('This occurred at T =', T) #break # print ' left while loop' fout.write(str(T)) fout.write(' ') fout.write(str(nvapor)) fout.write(' ') fout.write(str(nmid)) fout.write(' ') fout.write(str(nliquid)) fout.write(' ') fout.write(str(phi_vapor)) fout.write(' ') fout.write(str(phi_mid)) fout.write(' ') fout.write(str(phi_liquid)) fout.write(' ') fout.write(str(mu)) fout.write('\n') sys.stdout.flush(); # print ' T, etaVap, etaLiq, mu',T,nvapor/(RG.sigma**3*np.pi/6),nliquid/(RG.sigma**3*np.pi/6),mu # print '\n' fout.close()
T = 1.31705231562 mu = -6.21486388264 T = 1.18142906562 mu = -6.02699427421 T = 1.2219968 mu = -6.08764244458 T = 0.5 mu = -5.75178857763 #plt.plot(ns*np.pi*RG.sigma**3/6, correction(T,ns,mu,1,0), label=r'$(T,\mu)=$ (%g,%g) difference'%(T,mu)) plt.plot(ns * np.pi * RG.sigma**3 / 6, RG.phi(T, ns, mu, 0), label=r'$\phi(%g,\eta,%g,0)$' % (T, mu)) plt.plot(ns * np.pi * RG.sigma**3 / 6, RG.phi(T, ns, mu, 1), label=r'$\phi(%g,\eta,%g,1)$' % (T, mu)) # The following is very slow, uncomment if you want to see the result. # plt.plot(ns*np.pi*RG.sigma**3/6, RG.phi(T, ns, mu, 2), label=r'$\phi(%g,\eta,%g,2)$'%(T, mu)) plt.xlabel(r'$\eta$') plt.ylabel(r'$\phi(T,\eta,\mu,i)$') plt.legend(loc=0) plt.savefig('figs/RG_comparison.pdf') # plt.show()
def plotPress(T, n, i): plt.plot(n * eta_conv, RG.P(T, n, i))
def plotphi(T, n, mu, i, label): plt.plot(n * eta_conv, RG.phi(T, n, mu, i), label=label)
def plotphi(T,n,mu,i,label): plt.plot(n*eta_conv,RG.phi(T,n,mu,i),label=label)
def correction(Temp,num,chempot,i1,i2): return RG.phi(Temp,num,chempot,i1) - RG.phi(Temp,num,chempot,i2)
def correction(Temp,num,chempot,i1,i2): return RG.phi(Temp,num,chempot,i1) - RG.phi(Temp,num,chempot,i2) ns = np.arange(1e-10,0.6/(np.pi*RG.sigma**3/6),1e-3/(np.pi*RG.sigma**3/6)) T = 1.31705231562 mu = -6.21486388264 T = 1.18142906562 mu = -6.02699427421 T = 1.2219968 mu = -6.08764244458 T = 0.5 mu = -5.75178857763 #plt.plot(ns*np.pi*RG.sigma**3/6, correction(T,ns,mu,1,0), label=r'$(T,\mu)=$ (%g,%g) difference'%(T,mu)) plt.plot(ns*np.pi*RG.sigma**3/6, RG.phi(T,ns,mu,0), label=r'$\phi(%g,\eta,%g,0)$'%(T,mu)) plt.plot(ns*np.pi*RG.sigma**3/6, RG.phi(T,ns,mu,1), label=r'$\phi(%g,\eta,%g,1)$'%(T,mu)) plt.plot(ns*np.pi*RG.sigma**3/6, RG.phi(T,ns,mu,2), label=r'$\phi(%g,\eta,%g,2)$'%(T,mu)) plt.xlabel(r'$\eta$') plt.ylabel(r'$\phi(T,\eta,\mu,i)$') plt.legend(loc=0) plt.savefig('figs/RG_comparison.pdf') # plt.show()