def _UEqn(phi, U, p, turbulence, pZones, pressureImplicitPorosity, nUCorr, eqnResidual, maxResidual): from Foam import fvm, fvc # Construct the Momentum equation # The initial C++ expression does not work properly, because of # 1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries # 2. the order of expression arguments computation differs with C++ #UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U ) UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U)) UEqn.relax() # Include the porous media resistance and solve the momentum equation # either implicit in the tensorial resistance or transport using by # including the spherical part of the resistance in the momentum diagonal trAU = None trTU = None if pressureImplicitPorosity: from Foam.OpenFOAM import sphericalTensor, tensor tTU = tensor(sphericalTensor.I) * UEqn.A() pZones.addResistance(UEqn, tTU) trTU = tTU.inv() from Foam.OpenFOAM import word trTU.rename(word("rAU")) gradp = fvc.grad(p) for UCorr in range(nUCorr): U.ext_assign(trTU & (UEqn.H() - gradp)) pass U.correctBoundaryConditions() else: pZones.addResistance(UEqn) from Foam.finiteVolume import solve eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual() maxResidual = max(eqnResidual, maxResidual) trAU = 1.0 / UEqn.A() from Foam.OpenFOAM import word trAU.rename(word("rAU")) pass return UEqn, trTU, trAU, eqnResidual, maxResidual
def _hEqn( phi, h, turbulence, rho, p, thermo, eqnResidual, maxResidual ): from Foam import fvc, fvm hEqn = fvm.div( phi, h ) - fvm.Sp( fvc.div( phi ), h ) - fvm.laplacian( turbulence.alphaEff(), h ) \ == fvc.div( phi / fvc.interpolate( rho ) * fvc.interpolate( p ) ) - p * fvc.div( phi / fvc.interpolate( rho ) ) hEqn.relax() eqnResidual = hEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) thermo.correct() return hEqn, eqnResidual, maxResidual
def fun_UEqn(phi, U, p, turbulence, mesh, g, rhok, eqnResidual, maxResidual): from Foam import fvm, fvc UEqn = fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U) + turbulence.divDevReff(U) UEqn.relax() from Foam.finiteVolume import solve eqnResidual = solve(UEqn == fvc.reconstruct(( fvc.interpolate(rhok) * (g & mesh.Sf()) - fvc.snGrad(p) * mesh.magSf()))).initialResidual() maxResidual = max(eqnResidual, maxResidual) return UEqn, eqnResidual, maxResidual
def fun_pEqn( runTime, mesh, UEqn, p, p_rgh, phi, U, rho, rho1, rho2, rho10, rho20, gh, ghf, dgdt, pMin, \ psi1, psi2, alpha1, alpha2, interface, transonic, oCorr, nOuterCorr, corr, nCorr, nNonOrthCorr ): rUA = 1.0/UEqn.A() from Foam import fvc rUAf = fvc.interpolate( rUA ) p_rghEqnComp = None from Foam import fvm if transonic: p_rghEqnComp = fvm.ddt( p_rgh ) + fvm.div( phi, p_rgh ) - fvm.Sp( fvc.div( phi ), p_rgh ) pass else: p_rghEqnComp = fvm.ddt( p_rgh ) + fvc.div( phi, p_rgh ) - fvc.Sp( fvc.div( phi ), p_rgh ) pass U.ext_assign( rUA * UEqn.H() ) from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phiU = surfaceScalarField( word( "phiU" ), ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) phi.ext_assign(phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) ) * rUAf * mesh.magSf() ) from Foam.finiteVolume import solve from Foam.OpenFOAM import scalar for nonOrth in range( nNonOrthCorr +1 ): p_rghEqnIncomp = fvc.div( phi ) - fvm.laplacian( rUAf, p_rgh ) solve( ( alpha1.ext_max( scalar( 0 ) ) * ( psi1 / rho1 ) + alpha2.ext_max( scalar( 0 ) ) * ( psi2 / rho2 ) ) *p_rghEqnComp() + p_rghEqnIncomp, mesh.solver( p_rgh.select( oCorr == ( nOuterCorr - 1 ) and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) if nonOrth == nNonOrthCorr: dgdt.ext_assign( ( alpha2.pos() * ( psi2 / rho2 ) - alpha1.pos() * ( psi1 / rho1 ) ) * ( p_rghEqnComp & p_rgh ) ) phi.ext_assign( phi + p_rghEqnIncomp.flux() ) pass U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rUAf ) ) U.correctBoundaryConditions() p.ext_assign( ( ( p_rgh + gh * ( alpha1 * rho10 + alpha2 * rho20 ) ) /( 1.0 - gh * ( alpha1 * psi1 + alpha2 * psi2 ) ) ).ext_max( pMin ) ) rho1.ext_assign( rho10 + psi1 * p ) rho2.ext_assign( rho20 + psi2 * p ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "max(U) " << U.mag().ext_max().value() << nl ext_Info() << "min(p_rgh) " << p_rgh.ext_min().value() << nl pass
def fun_hEqn( turbulence, phi, h, rho, radiation, p, thermo, eqnResidual, maxResidual ): from Foam import fvc, fvm left_exp = fvm.div( phi, h ) - fvm.Sp( fvc.div( phi ), h ) - fvm.laplacian( turbulence.alphaEff(), h ) right_exp = fvc.div( phi/fvc.interpolate( rho )*fvc.interpolate( p ) ) - p*fvc.div( phi/fvc.interpolate( rho ) ) + radiation.Sh( thermo() ) hEqn = (left_exp == right_exp ) hEqn.relax() eqnResidual = hEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) thermo.correct() radiation.correct() return hEqn, eqnResidual, maxResidual
def _UEqn(phi, U, p, turbulence, eqnResidual, maxResidual): from Foam import fvm, fvc # Solve the Momentum equation # The initial C++ expression does not work properly, because of # 1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries # 2. the order of expression arguments computation differs with C++ #UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U ) UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U)) UEqn.relax() from Foam.finiteVolume import solve eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual() maxResidual = max(eqnResidual, maxResidual) return UEqn, eqnResidual, maxResidual
def _hEqn(thermo, phi, h, turbulence, p, rho, eqnResidual, maxResidual): from Foam.finiteVolume import fvScalarMatrix from Foam import fvc, fvm left_expr = fvm.div(phi, h) - fvm.Sp(fvc.div(phi), h) - fvm.laplacian( turbulence.alphaEff(), h) from Foam.OpenFOAM import word right_expr = fvc.div(phi / fvc.interpolate(rho) * fvc.interpolate( p, word("div(U,p)"))) - p * fvc.div(phi / fvc.interpolate(rho)) hEqn = (left_expr == right_expr) hEqn.relax() eqnResidual = hEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) thermo.correct() return hEqn, eqnResidual, maxResidual
def fun_TEqn(turbulence, phi, T, rhok, beta, TRef, Pr, Prt, eqnResidual, maxResidual): from Foam.OpenFOAM import word from Foam.finiteVolume import volScalarField kappaEff = volScalarField( word("kappaEff"), turbulence.nu() / Pr + turbulence.ext_nut() / Prt) from Foam import fvc, fvm TEqn = fvm.div(phi, T) - fvm.Sp(fvc.div(phi), T) - fvm.laplacian( kappaEff, T) TEqn.relax() eqnResidual = TEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) rhok.ext_assign(1.0 - beta * (T - TRef)) return TEqn, kappaEff