def test_one_phase_dP_dz_acceleration_example(): # This requires thermo! from thermo import Stream, Vm_to_rho from fluids import one_phase_dP, one_phase_dP_acceleration import numpy as np from scipy.integrate import odeint from fluids.numerics import assert_close P0 = 1E5 s = Stream(['nitrogen', 'methane'], T=300, P=P0, zs=[0.5, 0.5], m=1) rho0 = s.rho D = 0.1 def dP_dz(P, L, acc=False): s.flash(P=float(P), Hm=s.Hm) dPf = one_phase_dP(m=s.m, rho=s.rhog, mu=s.rhog, D=D, roughness=0, L=1.0) if acc: G = 4.0 * s.m / (pi * D * D) der = s.VolumeGasMixture.property_derivative_P(P=s.P, T=s.T, zs=s.zs, ws=s.ws) der = 1 / Vm_to_rho(der, s.MW) factor = G * G * der dP = dPf / (1.0 + factor) return -dP return -dPf ls = linspace(0, .01) dP_noacc = odeint(dP_dz, s.P, ls, args=(False, ))[-1] s.flash(P=float(P0), Hm=s.Hm) # Reset the stream object profile = odeint(dP_dz, s.P, ls, args=(True, )) dP_acc = profile[-1] s.flash(P=dP_acc, Hm=s.Hm) rho1 = s.rho dP_acc_numerical = dP_noacc - dP_acc dP_acc_basic = one_phase_dP_acceleration(m=s.m, D=D, rho_o=rho1, rho_i=rho0) assert_close(dP_acc_basic, dP_acc_numerical, rtol=1E-4)
def test_one_phase_dP_dz_acceleration_example(): # This requires thermo! from thermo import Stream, Vm_to_rho from fluids import one_phase_dP, one_phase_dP_acceleration import numpy as np from scipy.integrate import odeint from numpy.testing import assert_allclose P0 = 1E5 s = Stream(['nitrogen', 'methane'], T=300, P=P0, zs=[0.5, 0.5], m=1) rho0 = s.rho D = 0.1 def dP_dz(P, L, acc=False): s.flash(P=float(P), Hm=s.Hm) dPf = one_phase_dP(m=s.m, rho=s.rhog, mu=s.rhog, D=D, roughness=0, L=1) if acc: G = 4.0*s.m/(np.pi*D*D) der = s.VolumeGasMixture.property_derivative_P(P=s.P, T=s.T, zs=s.zs, ws=s.ws) der = 1/Vm_to_rho(der, s.MW) factor = G*G*der dP = dPf/(1.0 + factor) return -dP return -dPf ls = np.linspace(0, .01) dP_noacc = odeint(dP_dz, s.P, ls, args=(False,))[-1] s.flash(P=float(P0), Hm=s.Hm) # Reset the stream object profile = odeint(dP_dz, s.P, ls, args=(True,)) dP_acc = profile[-1] s.flash(P=dP_acc, Hm=s.Hm) rho1 = s.rho dP_acc_numerical = dP_noacc - dP_acc dP_acc_basic = one_phase_dP_acceleration(m=s.m, D=D, rho_o=rho1, rho_i=rho0) assert_allclose(dP_acc_basic, dP_acc_numerical, rtol=1E-4)