def test_stratified_angle_array(self): alphaL = np.array([0, 0.25, 0.5, 0.75, 1]) betha = np.array([0, 2.30988146, np.pi, 3.97330385, 2 * np.pi]) betha_calc = Geometry.stratified_angle(alphaL) np.testing.assert_almost_equal(betha_calc, betha, decimal=1)
def model_closure(obj, t, qL, qG, alphaL, P): D = obj.parameters['D']() g = obj.parameters['g']() epw = obj.parameters['epw']() rhoL = obj.parameters['rhoL']() muL = obj.parameters['muL']() rhoG = obj.parameters['rhoG']() muG = obj.parameters['muG']() tetha = obj.parameters['tetha']() alphaG = 1-alphaL A = Geometry.area(D) betha = Geometry.stratified_angle(alphaL) #betha = 2 * np.pi * alphaL hD = 0.5 * (1 - np.cos(0.5 * betha)) perL, perG, perI = Geometry.stratified_perimeters(D, betha) vL = Hydraulics.velocity(qL, rhoL, alphaL*A) vG = Hydraulics.velocity(qG, rhoG, alphaG*A) DL = 4. * alphaL * A / perL DG = 4. * alphaG * A / (perG + perI) ReL = Dimensionless.reynolds(DL, vL, rhoL, muL) ReG = Dimensionless.reynolds(DG, vG, rhoG, muG) _, fDL = Hydraulics.ff_via_churchill(ReL, epw, DL) _, fDG = Hydraulics.ff_via_churchill(ReG, epw, DG) tauL = Hydraulics.shear_stress(fDL, rhoL, vL) tauG = Hydraulics.shear_stress(fDG, rhoG, vG) tauI = Hydraulics.shear_stress(fDG, rhoG, vG-vL) zcml = D * (0.5 - 1 / 3 / np.pi / alphaL * np.sin(betha / 2) ** 3) zcmg = D * (0.5 + 1 / 3 / np.pi / alphaG * np.sin(betha / 2) ** 3) if qL.ndim == 2: tetha = np.repeat(np.array([tetha]), qL.shape[1], axis=0).T dPLG = ((rhoL - rhoG) * hD * D - rhoL * zcml + rhoG * zcmg) * g * np.cos(tetha) dPL = alphaG * dPLG dPG = -alphaL * dPLG dPI = (alphaL * rhoL * (zcml - hD * D) + alphaG * rhoG * (zcmg - hD * D)) * g * np.cos(tetha) return tauL*perL, tauG*perG, tauI*perI, dPL, dPG, dPI
def model_closure(obj, t, qL, qG, alphaL, P): D = obj.parameters['D']() g = obj.parameters['g']() epw = obj.parameters['epw']() rhoL = obj.parameters['rhoL']() muL = obj.parameters['muL']() rhoG = obj.parameters['rhoG']() muG = obj.parameters['muG']() tetha = obj.parameters['tetha']() tension = obj.parameters['tension']() alphaG = 1 - alphaL A = Geometry.area(D) vL = Hydraulics.velocity(qL, rhoL, alphaL * A) vG = Hydraulics.velocity(qG, rhoG, alphaG * A) vLS = Hydraulics.velocity(qL, rhoL, A) vGS = Hydraulics.velocity(qG, rhoG, A) vM = vGS + vLS ReL = Dimensionless.reynolds(D, vL, rhoL, muL) ReM = Dimensionless.reynolds(D, vM, rhoL, muL) _, fDL = Hydraulics.ff_via_churchill(ReL, epw, D) _, fDM = Hydraulics.ff_via_churchill(ReM, epw, D) fDG = 0.0 dbmax = (0.725 + 4.15 * (vGS / vM)**0.5) * (tension / rhoL)**( 3 / 5) * (2 * fDM * vM**3 / D)**(-2 / 5) db = (16. * tension / g / (rhoL - rhoG))**0.5 db = np.fmax(db, dbmax) vb = (0.51 * db + 2.14 / db)**0.5 CDb = 4 / 3 * ((rhoL - rhoG) / rhoL) * g * db / (vb**2) fDI = 1.5 * alphaG * rhoL * CDb / db perL = np.pi * D * alphaL perG = np.pi * D * alphaG perI = np.pi * D**2 * alphaG / db tauL = Hydraulics.shear_stress(fDL, rhoL, vL) tauG = Hydraulics.shear_stress(fDG, rhoG, vG) tauI = Hydraulics.shear_stress(fDI, rhoG, vG - vL) dPL = 1 / 4. * rhoL * (vG - vL)**2 dPG = 0 dPI = 0 return tauL * perL, tauG * perG, tauI * perI, dPL, dPG, dPI
def residue(self, t: float, y: np.ndarray, yp: np.ndarray, par=None): D = self.parameters['D']() epw = self.parameters['epw']() rho = self.parameters['rho']() mu = self.parameters['mu']() drhodP = self.parameters['drhodP']() z = self.parameters['z']() g = self.parameters['g']() q_lb = self.parameters['q_lb'](t) P_ub = self.parameters['P_ub'](t) q = self.variables["q"].parse(y) dqdt = self.variables["q"].parse(yp) P = self.variables["P"].parse(y) dPdt = self.variables["P"].parse(yp) A = Geometry.area(D) per = np.pi * D v = Hydraulics.velocity(q, rho, A) Re = Dimensionless.reynolds(D, v, rho, mu) _, fD = Hydraulics.ff_via_churchill(Re, epw, D) tau = Hydraulics.shear_stress(fD, rho, v) res_1 = drhodP * dPdt + 1 / A * self.grad_x(q) res_2 = dqdt + A * self.grad_x(P) + self.grad_x_hrs( q * v, q) + tau * per + rho * g * A * self.grad_x(z) eq1 = Equation(res_1, regions=(RegionEnum.OPEN_CLOSED, )) eq2 = Equation(res_2, regions=(RegionEnum.CLOSED_OPEN, )) bc1 = BoundaryCondition(q, q_lb, kind=BoundaryConditionEnum.DIRICHLET, regions_1=(RegionEnum.LOWER, )) bc2 = BoundaryCondition(P, P_ub, kind=BoundaryConditionEnum.DIRICHLET, regions_1=(RegionEnum.UPPER, )) eqs = Equations((eq1, eq2, bc1, bc2)) res = eqs() ires = 0 return res, ires
def model_closure(obj, t, qL, qG, alphaL, P): D = obj.parameters['D']() g = obj.parameters['g']() epw = obj.parameters['epw']() rhoL = obj.parameters['rhoL']() muL = obj.parameters['muL']() rhoG = obj.parameters['rhoG']() muG = obj.parameters['muG']() alphaG = 1 - alphaL A = Geometry.area(D) perG = 0 perL = np.pi * D perI = np.pi * D * alphaG**0.5 vL = Hydraulics.velocity(qL, rhoL, alphaL * A) vG = Hydraulics.velocity(qG, rhoG, alphaG * A) DL = 4. * alphaL * A / perL DG = 4. * alphaG * A / (perG + perI) ReL = Dimensionless.reynolds(DL, vL, rhoL, muL) ReG = Dimensionless.reynolds(DG, vG, rhoG, muG) _, fDL = Hydraulics.ff_via_churchill(ReL, epw, DL) _, fDG = Hydraulics.ff_via_churchill(ReG, epw, DG) tauL = Hydraulics.shear_stress(fDL, rhoL, vL) tauG = Hydraulics.shear_stress(fDG, rhoG, vG) tauI = Hydraulics.shear_stress(fDG, rhoG, vG - vL) dPL = 0.0 dPG = 0.0 dPI = 0.0 return tauL * perL, tauG * perG, tauI * perI, dPL, dPG, dPI
def residue(self, t: float, y: np.ndarray, yp: np.ndarray, par=None): #print(int(t*100)/100) D = self.parameters['D']() rhoL = self.parameters['rhoL']() drhoLdP = self.parameters['drhoLdP']() rhoG = self.parameters['rhoG']() drhoGdP = self.parameters['drhoGdP']() tetha = self.parameters['tetha']() Pr = self.parameters['Pr']() g = self.parameters['g']() if y.ndim == 2: tetha = np.repeat(np.array([tetha]), y.shape[1], axis=0).T qL_lb = self.parameters['qL_lb'](t) qG_lb = self.parameters['qG_lb'](t) P_ub = self.parameters['P_ub'](t) qL = self.variables["qL"].parse(y) dqLdt = self.variables["qL"].parse(yp) qG = self.variables["qG"].parse(y) dqGdt = self.variables["qG"].parse(yp) alphaL = self.variables["alphaL"].parse(y) dalphaLdt = self.variables["alphaL"].parse(yp) P = self.variables["P"].parse(y) * Pr dPdt = self.variables["P"].parse(yp) * Pr #alphaL = np.fmin(np.fmax(alphaL, 1e-6),1 -1e-6) bc1 = BoundaryCondition(qL, qL_lb, kind=BoundaryConditionEnum.DIRICHLET, regions_1=(RegionEnum.LOWER, )) bc2 = BoundaryCondition(qG, qG_lb, kind=BoundaryConditionEnum.DIRICHLET, regions_1=(RegionEnum.LOWER, )) bc3 = BoundaryCondition(P / Pr, P_ub / Pr, kind=BoundaryConditionEnum.DIRICHLET, regions_1=(RegionEnum.UPPER, )) bc4 = BoundaryCondition(alphaL, 0.0, kind=BoundaryConditionEnum.NEUMANN, regions_1=(RegionEnum.LOWER, ), regions_2=(RegionEnum.LOWER_PLUS_ONE, )) alphaG = 1 - alphaL dalphaGdt = -dalphaLdt A = Geometry.area(D) vL = Hydraulics.velocity(qL, rhoL, alphaL * A) vG = Hydraulics.velocity(qG, rhoG, alphaG * A) gammaL, gammaG, gammaI, dPL, dPG, dPI = self.model_closure( self, t, qL, qG, alphaL, P) dqLdx = self.grad_x(qL) dqGdx = self.grad_x(qG) cM = (alphaL / rhoL * drhoLdP + alphaG / rhoG * drhoGdP) res_1 = dPdt + (dqLdx / rhoL + dqGdx / rhoG) / A / cM res_2 = dalphaLdt + ( 1 - 1 / cM * alphaL / rhoL * drhoLdP ) / A / rhoL * dqLdx - 1 / A / rhoG / cM * alphaL / rhoL * drhoLdP * dqGdx res_3 = dqLdt + A * (dPL - rhoL * vL**2) * self.grad_x( alphaL) + A * alphaL * (1 - drhoLdP * vL**2) * self.grad_x( P) + A * alphaL * self.grad_x(dPL) + 2 * vL * self.grad_x_hrs( qL, qL) + gammaL - gammaI + alphaL * rhoL * g * A * np.sin( tetha) res_4 = dqGdt + A * (dPG - rhoG * vG**2) * self.grad_x( alphaG) + A * alphaG * (1 - drhoGdP * vG**2) * self.grad_x( P) + A * alphaG * self.grad_x(dPG) + 2 * vG * self.grad_x_hrs( qG, qG) + gammaG + gammaI + alphaG * rhoG * g * A * np.sin( tetha) #res_3 = dqLdt + A * alphaL*(1 - drhoLdP * vL**2) * self.grad_x(P + dPL) + 2*vL * self.grad_x_hrs(qL, qL) + gammaL - gammaI + alphaL * rhoL * g * A * np.sin(tetha) #res_4 = dqGdt + A * alphaG*(1 - drhoGdP * vG**2) * self.grad_x(P + dPG) + 2*vG * self.grad_x_hrs(qG, qG) + gammaG + gammaI + alphaG * rhoG * g * A * np.sin(tetha) eq1 = Equation(res_1, regions=(RegionEnum.CLOSED_OPEN, )) eq2 = Equation(res_2, regions=(RegionEnum.OPEN_CLOSED, )) eq3 = Equation(res_3, regions=(RegionEnum.OPEN_CLOSED, )) eq4 = Equation(res_4, regions=(RegionEnum.OPEN_CLOSED, )) eqs = Equations(( eq1, eq2, eq3, eq4, bc1, bc2, bc3, bc4, )) res = eqs() ires = 0 return res, ires
def model_closure(obj, t, qL, qG, alphaL, P): D = obj.parameters['D']() g = obj.parameters['g']() epw = obj.parameters['epw']() rhoL = obj.parameters['rhoL']() muL = obj.parameters['muL']() rhoG = obj.parameters['rhoG']() muG = obj.parameters['muG']() tetha = obj.parameters['tetha']() tension = obj.parameters['tension']() alphaG = 1 - alphaL A = Geometry.area(D) vL = Hydraulics.velocity(qL, rhoL, alphaL * A) vG = Hydraulics.velocity(qG, rhoG, alphaG * A) vLS = Hydraulics.velocity(qL, rhoL, A) vGS = Hydraulics.velocity(qG, rhoG, A) vM = vGS + vLS ReL = Dimensionless.reynolds(D, vL, rhoL, muL) ReLS = Dimensionless.reynolds(D, vLS, rhoL, muL) ReM = Dimensionless.reynolds(D, vM, rhoL, muL) ffL, fDL = Hydraulics.ff_via_churchill(ReL, epw, D) ffLS, fDLS = Hydraulics.ff_via_churchill(ReLS, epw, D) ffM, fDM = Hydraulics.ff_via_churchill(ReM, epw, D) # Gas Fraction in Slug alphaS = 0.058 * (2 * (0.4 * tension / g / (rhoL - rhoG))**0.5 * (2. * ffM / D * vM**3)**(2 / 5) * (rhoL / tension)**(3 / 5) - 0.725)**2 alphaS = np.fmax(alphaS, np.zeros_like(alphaS)) alphaS = np.fmin(alphaS, np.ones_like(alphaS) - 0.48) Rs = 1 - alphaS # Slug length if D > 0.038: ls = np.exp(-3.287 + 4.589 * (np.log(D / 0.0254))**0.5) else: ls = 18.1 * D # Slug frequency Eo = np.sqrt(9.81 * D**2. * (rhoL - rhoG) / tension) Nf = ((D**1.5) * (rhoL * (rhoL - rhoG) * g)**0.5) / muL n = Nf / (260 + 0.85 * Nf) wS = vGS / D * (0.0323 / 2. * vLS / vGS * ((rhoL / (rhoL - rhoG))**0.5) * (fDLS**-0.5) / (Eo**0.2))**n # Slug Translational Velocity C = 1.2 gD = (9.81 * D)**0.5 vD = 0.35 * gD * np.sin(tetha) + 0.54 * gD * np.cos(tetha) vT = C * vM + vD # Slug region lengths lu = vT / wS ls = np.fmin(ls, lu) lf = lu - ls lf = np.fmax(lf, ls * 1e-3) lu = lf + ls # Taylor Bubble holdup alphaF = lu / lf * alphaG - ls / lf * alphaS alphaF = np.fmax(1e-6, alphaF) alphaF = min(1 - 1e-6, alphaF) Rf = 1 - alphaF # Slug Speeds uL = (vLS + vT * (alphaG - alphaS)) / Rs ub = (vGS - vT * (alphaG - alphaS)) / alphaS # Taylor Bubble Speed uf = vT - (vT - uL) * Rs / Rf uG = vT - (vT - ub) * alphaS / alphaF gammaL1, gammaG1, gammaI1, dPL1, dPG1, dPI1 = StratifiedClosure.model_closure( obj, qL * uL / vL, qG * ub / vG, Rf, P) gammaL2, gammaG2, gammaI2, dPL2, dPG2, dPI2 = BubbleClosure.model_closure( obj, qL * uf / vL, qG * uG / vG, Rs, P) gammaL = (gammaL1 * ls + gammaL2 * lf) / lu gammaG = (gammaG1 * ls + gammaG2 * lf) / lu gammaI = (gammaI1 * ls + gammaI2 * lf) / lu dPL = (dPL1 * ls + dPL2 * lf) / lu dPG = (dPG1 * ls + dPG2 * lf) / lu dPI = (dPI1 * ls + dPI2 * lf) / lu return gammaL, gammaG, gammaI, dPL, dPG, dPI