fout.write( '#T nvapor nliquid phi(nvap) phi(nliq) nparticular\n' ) # phi_avg') # Do first temperature before the loop nvapor, phi_vapor = minmax.minimize(SW.phi, T, a_vap, c_vap, nparticular) nliquid, phi_liquid = minmax.minimize(SW.phi, T, a_liq, c_liq, nparticular) sys.stdout.flush() #while T < 1.4: 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 SW.phi with old nparticular nparticular = minmax.maximize(SW.phi, T, nvapor, nliquid, nparticular) # I'm looking at the minima of SW.phi c_vap = nparticular a_liq = nparticular nvapor, phi_vapor = minmax.minimize(SW.phi, T, c_vap, a_vap, nparticular) nliquid, phi_liquid = minmax.minimize(SW.phi, T, a_liq, c_liq, nparticular) if abs(T - 0.8) < 0.05: print "\n\nT =", T print 'npart', nparticular print 'nv', nvapor print 'nl', nliquid tol = 1e-5
# label the columns of the output fout.write('#T nvapor nliquid phi(nvap) phi(nliq) nparticular\n')# phi_avg') # Do first temperature before the loop nvapor,phi_vapor = minmax.minimize(SW.phi,T,a_vap,c_vap,nparticular) nliquid,phi_liquid = minmax.minimize(SW.phi,T,a_liq,c_liq,nparticular) sys.stdout.flush() #while T < 1.4: 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 SW.phi with old nparticular nparticular = minmax.maximize(SW.phi,T,nvapor, nliquid, nparticular) # I'm looking at the minima of SW.phi c_vap = nparticular a_liq = nparticular nvapor,phi_vapor = minmax.minimize(SW.phi,T,c_vap,a_vap,nparticular) nliquid,phi_liquid = minmax.minimize(SW.phi,T,a_liq,c_liq,nparticular) if abs(T - 0.8) < 0.05: print "\n\nT =", T print 'npart', nparticular print 'nv', nvapor print 'nl', nliquid tol = 1e-5
# Do first temperature before the loop leftmin_n, leftmin_phi = minmax.minimize(H.Phi_alt, T, a_vap, c_vap, nparticular) rightmin_n, rightmin_phi = minmax.minimize(H.Phi_alt, T, a_liq, c_liq, nparticular) leftmin_n = a_vap rightmin_n = c_liq # while T < 800: 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 H.Phi_alt with old nparticular nparticular = minmax.maximize(H.Phi_alt, T, leftmin_n, rightmin_n, nparticular) tol_nparticular = 1e-2 / H.conv_n # I'm looking at the minima of H.Phi_alt c_vap = nparticular a_liq = nparticular leftmin_n, leftmin_phi = minmax.minimize(H.Phi_alt, T, c_vap, a_vap, nparticular) rightmin_n, rightmin_phi = minmax.minimize(H.Phi_alt, T, a_liq, c_liq, nparticular) tol_min = 0.5 / H.conv_p # Compare the two minima in H.Phi_alt while np.fabs(leftmin_phi - rightmin_phi) > tol_min: delta_mu = (rightmin_phi - leftmin_phi) / (rightmin_n - leftmin_n)
# Do first temperature before the loop leftmin_n,leftmin_phi = minmax.minimize(H.Phi_alt,T,a_vap,c_vap,nparticular) rightmin_n,rightmin_phi = minmax.minimize(H.Phi_alt,T,a_liq,c_liq,nparticular) leftmin_n = a_vap rightmin_n = c_liq # while T < 800: 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 H.Phi_alt with old nparticular nparticular = minmax.maximize(H.Phi_alt,T,leftmin_n, rightmin_n, nparticular) tol_nparticular = 1e-2/H.conv_n # I'm looking at the minima of H.Phi_alt c_vap = nparticular a_liq = nparticular leftmin_n,leftmin_phi = minmax.minimize(H.Phi_alt,T,c_vap,a_vap,nparticular) rightmin_n,rightmin_phi = minmax.minimize(H.Phi_alt,T,a_liq,c_liq,nparticular) tol_min = 0.5/H.conv_p # Compare the two minima in H.Phi_alt while np.fabs(leftmin_phi - rightmin_phi) > tol_min: delta_mu = (rightmin_phi - leftmin_phi)/(rightmin_n - leftmin_n) def newphi(T, n, npart): return H.Phi_alt(T, n, npart) - delta_mu*n