def f_ext(numdensity): # Fsolve might need to go outside of our minimum or maximum density that RG was used with, thus this function... # ... sets the values of the free energy outside those bounds. if numdensity > 0.0001 and numdensity < max_fillingfraction_handled / ( 4 * np.pi / 3): return finterp(numdensity) return RG.fiterative(temp, numdensity, 0)
def _create_colors(self, number_of_items): """Returning a list of lists with RGB code, where the size of the list is equals the number_of_items""" colors = [] for i in range(number_of_items): value = float(i) / float(number_of_items) colors.append(RG.rg(value)) return colors
def firstPass(): global f01interp f01interp=lambda n: RG.fiterative(temp,n,0) data=[] t = time.time() lastprint = t for i in range(numdata): n = numdensity[i] print "%d of %d: "%(i,numdata), free_energy = RG_first_pass(temp,n,1) data.append([n,free_energy]) elapsed = time.time() - t print(elapsed) np.savetxt(fsave,data)
def RG_dfi(n): maxn = (max_fillingfraction_handled+0.0001)/sphere_volume # warning: Forte defines x as a density, we define it # as a dimensionless quantity that scales the density. maxx = np.minimum(1,maxn/n-1) if abs(maxx) < 1e-42: print 'maxx is zero' print 'maxx is zero' print 'maxx is zero' print 'maxx is zero' print 'maxx is zero' T=temp # eqn (5) from Forte 2011: IDvalue = ID2(n, maxx) IDvalueStar = ID2star(n, maxx) return -k_B*T*(IDvalue-IDvalueStar)/RG.VD(fn) # eqn (7), Forte 2011
def get_data(year, month, var, depth, title_name = 'ESTOCver03'): import ESTOCver01 import ESTOCver02 import ESTOCver03 import ORAS4 import MOAA_GPV import GECCO2 import WOA01 import HadISST import ERSST import COBESST import RG import ERA if title_name == 'ESTOCver01': data = ESTOCver01.masuda_data_read(year, month, var, depth) elif title_name == 'ESTOCver02': data = ESTOCver02.nc_read(year, month, var, depth) elif title_name == 'ESTOCver03': data = ESTOCver03.masuda_data_read(year, month, var, depth) elif title_name == 'MOAA_GPV': data = MOAA_GPV.nc_read(year, month, var, depth) elif title_name == 'ORAS4': data = ORAS4.nc_read(year, month, var, depth) elif title_name == 'GECCO2': data = GECCO2.grib_read(year, month, var, depth) elif title_name == 'WOA01': data = WOA01.nc_read(month, var, depth) elif title_name == 'COBESST': data = COBESST.nc_read(year, month) elif title_name == 'HadISST': data = HadISST.nc_read(year, month) elif title_name == 'ERSST': data = ERSST.nc_read(year, month) elif title_name == 'Roemmich_Gilson': data = RG.nc_read(year, month, var, depth) elif title_name == 'ERA': data = ERA.get_data(year, month, var) # これで得られるデータはインド洋領域のみなので注意。 else: raise Exception('error! your product_n is not valid!') return data
def f01_ext(numdensity): if numdensity > 0.0008 and numdensity < max_fillingfraction_handled/sphere_volume: return f01interp(numdensity) return RG.fiterative(temp,numdensity,0)
def integrand_ID2star(n,maxpower,x): argument = np.exp(-maxpower-RG.VD(fn)/k_B/temp*fbarD(temp,n,x,fn)) return argument
def f0(n): return RG.fiterative(temp,n,0)
def integrand_ID2(n,maxpower,x): argument = np.exp(-maxpower-RG.VD(fn)/k_B/temp*(fbarD(temp,n,x,fn) + ubarD(temp,n,x,fn))) ## integrandIDlistn.append(n) ## integrandIDlistx.append(x) ## integrandIDlistarg.append(argument) return argument
def f_ext(numdensity): # Fsolve might need to go outside of our minimum or maximum density that RG was used with, thus this function... # ... sets the values of the free energy outside those bounds. if numdensity > 0.0001 and numdensity < 0.2: return finterp(numdensity) return RG.fiterative(temp,numdensity,0)
def f05_ext(numdensity): if numdensity > 0.0001 and numdensity < 0.2: return f05interp(numdensity) return RG.fiterative(temp, numdensity, 0)
def plotphi(T, n, npart, i): plt.plot(n * RG.sigma ** 3 * np.pi / 6, RG.phi(T, n, npart, i)) plt.ylabel(r"$\phi$") plt.xlabel(r"$\eta$")
def plotID_integrand(x): plt.plot(x, RG.integrand_ID(T, x, 0)) plt.ylabel("integrand of ID") plt.xlabel("amplitude of wave-packet")
from __future__ import division import SW import RG T = 5 n = 0.02 print ' SW; T = %d; n = %0.2f; f = %0.4f'%(T,n,SW.f(T,n)) print '\n' for i in range (2): print ' RG; i = %d; T = %d; n = %0.2f; f = %0.4f'%(i,T,n,RG.ftot(T,n,i))
def f00_tot(n): return RG.ftot(temp, n, 0)
def f05_ext(numdensity): if numdensity > 0.0001 and numdensity < 0.2: return f05interp(numdensity) return RG.fiterative(temp,numdensity,0)
def f05_tot(n): return f05_ext(n) + RG.a1SW(n)*n
def f00_tot(n): return RG.ftot(temp,n,0)
def f05_tot(n): return f05_ext(n) + RG.a1SW(n) * n
import pylab as plt import SW import RG eta_conv = SW.sigma**3 * plt.pi / 6 n = plt.linspace(1e-8, 0.2, 10000) ### Low temp ### T = 0.3 npart0 = 0.0462316928818 npart1 = 0.0776670124628 plt.figure() plt.plot(n * eta_conv, RG.phi(T, n, npart0, 0), label='i=0') plt.plot(n * eta_conv, RG.phi(T, n, npart1, 1), label='i=1') plt.title('T = %0.2f' % T) plt.ylabel(r'$\phi$') plt.xlabel(r'$\eta$') plt.ylim(-0.04, 0.1) plt.xlim(0, 0.7) plt.legend(loc=0) plt.savefig('figs/phi-RG-lowT.pdf') ### High Temp ### T = 1.32 npart0 = 0.0360850913603
def fns_ext(numdensity,i): if numdensity > 0.0001 and numdensity < 0.2: return fns[i](numdensity) return RG.fiterative(temp[i],numdensity,0)
import matplotlib, sys if 'show' not in sys.argv: matplotlib.use('Agg') import pylab import SW import RG eta_conv = SW.sigma**3*pylab.pi/6 n = pylab.linspace(0,0.2,10000) T = 0.3 npart = 0.0462316928818 pylab.plot(n*eta_conv,SW.phi(T,n,npart),'g-',label='SW') pylab.plot(n*eta_conv,RG.phi(T,n,npart,0),'r-',label='SW+RG; i=0') pylab.plot(n*eta_conv,RG.phi(T,n,npart,1),'b--',label='SW+RG; i=1') # pylab.plot(n*eta_conv,SW.f(T,n),'g-',label='SW') # pylab.plot(n*eta_conv,RG.ftot(T,n,0),'r--',label='SW+RG; i=0') # pylab.plot(n*eta_conv,RG.ftot(T,n,1),'b--',label='SW+RG; i=1') pylab.title('T = %0.2f'%T) pylab.ylabel(r'$\phi$') # pylab.ylabel(r'$f$') pylab.xlabel(r'$\eta$') pylab.legend(loc=0) pylab.savefig('figs/SW-RG-compare.pdf') pylab.show()
def plotID_ref_integrand(x): plt.plot(x, RG.integrand_ID_ref(x)) plt.ylabel("integrand of ID_ref") plt.xlabel("amplitude of wave-packet")
def f_tot(n): # Returns total free energy data with the missing a1SW(n) term that was not used in RG process return f_ext(n) + RG.a1SW(n)*n
import pylab as plt import SW import RG eta_conv = SW.sigma**3*plt.pi/6 n = plt.linspace(1e-8,0.2,10000) ### Low temp ### T = 0.3 npart0 = 0.0462316928818 npart1 = 0.0776670124628 plt.figure() plt.plot(n*eta_conv,RG.phi(T,n,npart0,0),label='i=0') plt.plot(n*eta_conv,RG.phi(T,n,npart1,1),label='i=1') plt.title('T = %0.2f'%T) plt.ylabel(r'$\phi$') plt.xlabel(r'$\eta$') plt.ylim(-0.04,0.1) plt.xlim(0,0.7) plt.legend(loc=0) plt.savefig('figs/phi-RG-lowT.pdf') ### High Temp ### T = 1.32 npart0 = 0.0360850913603
def plotphi_old(T,n,npart,i,label): plt.plot(n*eta_conv,RG1.phi(T,n,npart,i),label=label)
) exit() print(" Calculating coplannarity...") #mod_curv=classifier(25*curvatures) mod_curv = curvatures inp = input( "Do you want to do the region growing? (If this is the first time you are running the code, press y ) (y/n) " ) if (inp == 'y'): import RG RG.main() """ plane_normal, plane_seed, grand_nei=region_growing2(normals, indices, mod_curv, total, curvatures, k) np.savetxt('Pnormal3.out', plane_normal, delimiter=',') #np.savetxt('Gnei.out', grand_nei, delimiter=',') try: os.unlink('Gnei3.txt') except: print("could not delete") try: os.unlink('Pseed3.txt') except: print()
def newphi(T, n, npart, i): return RG.phi(T, n, npart, i) - delta_mu * n
def f_tot(n): # Returns total free energy data with the missing a1SW(n) term that was not used in RG process return f_ext(n) + RG.a1SW(n) * n
def npart(iterations): # Initial conditions; dependent on you system T = 0.1 nparticular = 0.08 / (RG.sigma**3 * np.pi / 6 ) # using finite differences df_dn # nparticular = 0.155/(RG.sigma**3*np.pi/6) # using analytic df_nd # T = 0.68 # nparticular = 0.0414/(RG.sigma**3*np.pi/6) N = 20 # For publication plots, make this bigger (40? 80? 100? You decide!) Tc = 1.33 Tlow = T # Bounds of minimization. # Use range that works for many temperatures # Left (vapor) a_vap = 1e-10 / (RG.sigma**3 * np.pi / 6) c_vap = nparticular # Right (liquid) a_liq = nparticular c_liq = 0.75 / (RG.sigma**3 * np.pi / 6) ############################### # Open file for output fout = open('figs/npart_RG-i%d-out.dat' % iterations, 'w') # label the columns of the output fout.write( '#T nvapor nliquid phi(nvap) phi(nliq) nparticular\n' ) # phi_avg') sys.stdout.flush() # Do first temperature before the loop nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, c_vap, nparticular, iterations) print 'initial nvap,phi_vap', nvapor, phi_vapor nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, a_liq, c_liq, nparticular, iterations) print 'initial nliq,phi_liq', nliquid, phi_liquid print 'initial npart', nparticular * (RG.sigma**3 * np.pi / 6) #while T < 1.4: for j in xrange(0, N + 1): T = (Tc - Tlow) * (1 - ((N - j) / N)**4) + Tlow fout.flush() # Starting point for new nparticular is abscissa of max RG.phi with old nparticular nparticular = minmax_RG.maximize(RG.phi, T, nvapor, nliquid, nparticular, iterations) # I'm looking at the minima of RG.phi c_vap = nparticular a_liq = nparticular nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, c_vap, a_vap, nparticular, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, a_liq, c_liq, nparticular, iterations) tol = 1e-5 fnpart = RG.phi(T, nparticular, nparticular, iterations) # Compare the two minima in RG.phi while np.fabs(phi_vapor - phi_liquid) / np.fabs(fnpart) > tol: delta_mu = (phi_liquid - phi_vapor) / (nliquid - nvapor) def newphi(T, n, npart, i): return RG.phi(T, n, npart, i) - delta_mu * n nparticular = minmax_RG.maximize(newphi, T, nvapor, nliquid, nparticular, iterations) fnpart = RG.phi(T, nparticular, nparticular, iterations) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, c_vap, nparticular, iterations) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, a_liq, c_liq, nparticular, iterations) fout.write(str(T)) fout.write(' ') fout.write(str(nvapor)) fout.write(' ') fout.write(str(nliquid)) fout.write(' ') fout.write(str(phi_vapor)) fout.write(' ') fout.write(str(phi_liquid)) fout.write(' ') fout.write(str(nparticular)) fout.write('\n') sys.stdout.flush() print ' T, etaVap, etaLiq', T, nvapor / ( RG.sigma**3 * np.pi / 6), nliquid / (RG.sigma**3 * np.pi / 6) fout.close()
print(" Calculating coplannarity...") #mod_curv=classifier(25*curvatures) mod_curv=curvatures inp=input("Do you want to do the region growing? (If this is the first time you are running the code, press y ) (y/n) ") if (inp=='y'): import RG RG.main() """ plane_normal, plane_seed, grand_nei=region_growing2(normals, indices, mod_curv, total, curvatures, k) np.savetxt('Pnormal3.out', plane_normal, delimiter=',') #np.savetxt('Gnei.out', grand_nei, delimiter=',') try: os.unlink('Gnei3.txt') except: print("could not delete") try: os.unlink('Pseed3.txt') except: print()
def plotphi_old(T, n, npart, i, label): plt.plot(n * eta_conv, RG1.phi(T, n, npart, i), label=label)
def onlyPower(n,x,i): return (-RG.VD(i)/k_B/temp*(fbarD(temp,n,x,i) + ubarD(temp,n,x,i)))
def fns_tot(n, i): return fns_ext(n, i) + RG.a1SW(n) * n
def ubarD(T,n,x,i): return (RG.u(temp,n*(1+x),0,i) + RG.u(temp,n*(1-x),0,i))/2 - RG.u(temp,n,0,i)
def fns_ext(numdensity, i): if numdensity > 0.0001 and numdensity < 0.2: return fns[i](numdensity) return RG.fiterative(temp[i], numdensity, 0)
def onlyPowerStar(n,x,i): return (-RG.VD(i)/k_B/temp*fbarD(temp,n,x,i))
for i in xrange(0, N + 1): T = (Tc - Tlow) * (1 - ((N - i) / N) ** 4) + Tlow fout.flush() # Starting point for new nparticular is abscissa of max RG.phi with old nparticular nparticular = minmax_RG.maximize(RG.phi, T, nvapor, nliquid, nparticular, i) # I'm looking at the minima of RG.phi c_vap = nparticular a_liq = nparticular nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, c_vap, a_vap, nparticular, i) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, a_liq, c_liq, nparticular, i) tol = 1e-5 fnpart = RG.phi(T, nparticular, nparticular, i) # Compare the two minima in RG.phi while np.fabs(phi_vapor - phi_liquid) / np.fabs(fnpart) > tol: delta_mu = (phi_liquid - phi_vapor) / (nliquid - nvapor) def newphi(T, n, npart, i): return RG.phi(T, n, npart, i) - delta_mu * n nparticular = minmax_RG.maximize(newphi, T, nvapor, nliquid, nparticular, i) fnpart = RG.phi(T, nparticular, nparticular, i) nvapor, phi_vapor = minmax_RG.minimize(RG.phi, T, a_vap, c_vap, nparticular, i) nliquid, phi_liquid = minmax_RG.minimize(RG.phi, T, a_liq, c_liq, nparticular, i) fout.write(str(T))
def RG_first_pass(T,n,i): fnaught = RG.SWfid(T,n) + RG.SWfhs(T,n) + RG.a2(n)/k_B/T*n # SW (and Hughes) a2/kT is the same as Forte's f2 f = fnaught return f + RG_dfi(n)
def npart(iterations): # Initial conditions; dependent on you system T = 0.1 nparticular = 0.08/(RG.sigma**3*np.pi/6) # using finite differences df_dn # nparticular = 0.155/(RG.sigma**3*np.pi/6) # using analytic df_nd # T = 0.68 # nparticular = 0.0414/(RG.sigma**3*np.pi/6) N = 20 # For publication plots, make this bigger (40? 80? 100? You decide!) Tc = 1.33 Tlow = T # Bounds of minimization. # Use range that works for many temperatures # Left (vapor) a_vap = 1e-10/(RG.sigma**3*np.pi/6) c_vap = nparticular # Right (liquid) a_liq = nparticular c_liq = 0.75/(RG.sigma**3*np.pi/6) ############################### # Open file for output fout = open('figs/npart_RG-i%d-out.dat'%iterations,'w') # label the columns of the output fout.write('#T nvapor nliquid phi(nvap) phi(nliq) nparticular\n')# phi_avg') sys.stdout.flush() # Do first temperature before the loop nvapor,phi_vapor = minmax_RG.minimize(RG.phi,T,a_vap,c_vap,nparticular,iterations) print 'initial nvap,phi_vap',nvapor,phi_vapor nliquid,phi_liquid = minmax_RG.minimize(RG.phi,T,a_liq,c_liq,nparticular,iterations) print 'initial nliq,phi_liq',nliquid,phi_liquid print 'initial npart',nparticular*(RG.sigma**3*np.pi/6) #while T < 1.4: for j in xrange(0,N+1): T = (Tc - Tlow)*(1 - ((N-j)/N)**4) + Tlow fout.flush() # Starting point for new nparticular is abscissa of max RG.phi with old nparticular nparticular = minmax_RG.maximize(RG.phi,T,nvapor, nliquid, nparticular,iterations) # I'm looking at the minima of RG.phi c_vap = nparticular a_liq = nparticular nvapor,phi_vapor = minmax_RG.minimize(RG.phi,T,c_vap,a_vap,nparticular,iterations) nliquid,phi_liquid = minmax_RG.minimize(RG.phi,T,a_liq,c_liq,nparticular,iterations) tol = 1e-5 fnpart = RG.phi(T, nparticular, nparticular, iterations) # Compare the two minima in RG.phi while np.fabs(phi_vapor - phi_liquid)/np.fabs(fnpart) > tol: delta_mu = (phi_liquid - phi_vapor)/(nliquid - nvapor) def newphi(T, n, npart, i): return RG.phi(T, n, npart, i) - delta_mu*n nparticular = minmax_RG.maximize(newphi,T,nvapor,nliquid,nparticular,iterations) fnpart = RG.phi(T, nparticular, nparticular, iterations) nvapor,phi_vapor = minmax_RG.minimize(RG.phi,T,a_vap,c_vap,nparticular,iterations) nliquid,phi_liquid = minmax_RG.minimize(RG.phi,T,a_liq,c_liq,nparticular,iterations) fout.write(str(T)) fout.write(' ') fout.write(str(nvapor)) fout.write(' ') fout.write(str(nliquid)) fout.write(' ') fout.write(str(phi_vapor)) fout.write(' ') fout.write(str(phi_liquid)) fout.write(' ') fout.write(str(nparticular)) fout.write('\n') sys.stdout.flush(); print ' T, etaVap, etaLiq',T,nvapor/(RG.sigma**3*np.pi/6),nliquid/(RG.sigma**3*np.pi/6) fout.close()
def newphi(T, n, npart, i): return RG.phi(T, n, npart, i) - delta_mu*n
def fns_tot(n,i): return fns_ext(n,i) + RG.a1SW(n)*n