def _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, cumulativeContErr, corr, nCorr, nOuterCorr, transonic): rho.ext_assign(thermo.rho()) rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) from Foam import fvc, fvm from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField if transonic: phid = surfaceScalarField( word("phid"), fvc.interpolate(psi) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvm.div(phid, p) - fvm.laplacian( rho * rUA, p) pEqn.solve() if nonOrth == nNonOrthCorr: phi == pEqn.flux() pass pass pass else: phi.ext_assign( fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvc.div(phi) - fvm.laplacian(rho * rUA, p) pEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign(phi + pEqn.flux()) pass pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs(rho, thermo, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() DpDt.ext_assign( fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) return cumulativeContErr
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 _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, cumulativeContErr, corr, nCorr, nOuterCorr, transonic ): rho.ext_assign( thermo.rho() ) rUA = 1.0/UEqn.A() U.ext_assign( rUA * UEqn.H() ) from Foam import fvc, fvm from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField if transonic: phid = surfaceScalarField( word( "phid" ), fvc.interpolate( psi ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) for nonOrth in range( nNonOrthCorr + 1 ) : pEqn = fvm.ddt( psi, p ) + fvm.div( phid, p ) - fvm.laplacian( rho * rUA, p ) pEqn.solve() if nonOrth == nNonOrthCorr: phi == pEqn.flux() pass pass pass else: phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate(U) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) for nonOrth in range( nNonOrthCorr + 1 ) : pEqn = fvm.ddt( psi, p ) + fvc.div( phi ) - fvm.laplacian( rho * rUA, p ) pEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign( phi + pEqn.flux() ) pass pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) return cumulativeContErr
def fun_UEqn(mesh, U, p_rgh, ghf, rho, rhoPhi, turbulence, twoPhaseProperties, momentumPredictor, finalIter): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField(word("muEff"), twoPhaseProperties.muf() + fvc.interpolate(rho * turbulence.ext_nut())) from Foam import fvm, fvc UEqn = fvm.ddt(rho, U) + fvm.div(rhoPhi, U) - fvm.laplacian(muEff, U) - (fvc.grad(U) & fvc.grad(muEff)) if finalIter: UEqn.relax(1.0) pass else: UEqn.relax() pass if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct((-ghf * fvc.snGrad(rho) - fvc.snGrad(p_rgh)) * mesh.magSf()), mesh.solver(U.select(finalIter)), ) pass return UEqn
def _hEqn( rho, h, phi, turbulence, DpDt, thermo ): from Foam import fvm from Foam.finiteVolume import solve solve( fvm.ddt(rho, h) + fvm.div( phi, h ) - fvm.laplacian( turbulence.alphaEff(), h ) == DpDt ) thermo.correct() pass
def _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr): from Foam.finiteVolume import volScalarField rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) from Foam import fvc from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phid = surfaceScalarField( word("phid"), fvc.interpolate(thermo.psi()) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm pEqn = (fvm.ddt(psi, p) + fvm.div(phid, word("div(phid,p)")) - fvm.laplacian(rho * rUA, p)) pEqn.solve() if (nonOrth == nNonOrthCorr): phi.ext_assign(pEqn.flux()) pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs(rho, thermo, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() return cumulativeContErr
def Ueqn(mesh, phi, U, p, turbulence, oCorr, nOuterCorr, momentumPredictor): from Foam import fvm, fvc UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U) if (oCorr == nOuterCorr - 1): UEqn.relax(1.0) pass else: UEqn.relax() pass rUA = 1.0 / UEqn.A() from Foam.finiteVolume import solve if momentumPredictor: if (oCorr == nOuterCorr - 1): from Foam.OpenFOAM import word solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal"))) pass else: solve(UEqn == -fvc.grad(p)) pass else: U.ext_assign(rUA * (UEqn.H() - fvc.grad(p))) U.correctBoundaryConditions() pass return UEqn, rUA
def _UEqn(mesh, alpha1, U, p, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField(word("muEff"), twoPhaseProperties.muf() + fvc.interpolate(rho * turbulence.ext_nut())) from Foam import fvm UEqn = fvm.ddt(rho, U) + fvm.div(rhoPhi, U) - fvm.laplacian(muEff, U) - (fvc.grad(U) & fvc.grad(muEff)) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( fvc.interpolate(rho) * (g & mesh.Sf()) + (fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) - fvc.snGrad(p)) * mesh.magSf() ) ) pass return UEqn
def Ueqn( mesh, phi, U, p, turbulence, oCorr, nOuterCorr, momentumPredictor ): from Foam import fvm, fvc UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U) if ( oCorr == nOuterCorr - 1 ): UEqn.relax( 1.0 ) pass else: UEqn.relax() pass rUA = 1.0/UEqn.A() from Foam.finiteVolume import solve if momentumPredictor: if ( oCorr == nOuterCorr - 1 ): from Foam.OpenFOAM import word solve( UEqn == -fvc.grad(p), mesh.solver( word( "UFinal" ) ) ) pass else: solve( UEqn == -fvc.grad(p)) pass else: U.ext_assign( rUA * ( UEqn.H() - fvc.grad( p ) ) ) U.correctBoundaryConditions() pass return UEqn, rUA
def _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr ): from Foam.finiteVolume import volScalarField rUA = 1.0/UEqn.A() U.ext_assign( rUA*UEqn.H() ) from Foam import fvc from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phid = surfaceScalarField( word( "phid" ), fvc.interpolate( thermo.psi() ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) for nonOrth in range( nNonOrthCorr + 1 ) : from Foam import fvm pEqn = ( fvm.ddt(psi, p) + fvm.div(phid, word( "div(phid,p)" ) ) - fvm.laplacian(rho*rUA, p) ) pEqn.solve() if (nonOrth == nNonOrthCorr) : phi.ext_assign( pEqn.flux() ) pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad(p) ) U.correctBoundaryConditions() return cumulativeContErr
def step(self, getPISOControls): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Time = " << self.runTime.timeName() << nl << nl piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = getPISOControls(self.mesh) from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum = CourantNo(self.mesh, self.phi, self.runTime) from Foam import fvm UEqn = fvm.ddt(self.U) + fvm.div(self.phi, self.U) - fvm.laplacian(self.nu, self.U) from Foam import fvc from Foam.finiteVolume import solve solve(UEqn == -fvc.grad(self.p)) # --- PISO loop for corr in range(nCorr): rUA = 1.0 / UEqn.A() self.U.ext_assign(rUA * UEqn.H()) self.phi.ext_assign((fvc.interpolate(self.U) & self.mesh.Sf()) + fvc.ddtPhiCorr(rUA, self.U, self.phi)) from Foam.finiteVolume import adjustPhi adjustPhi(self.phi, self.U, self.p) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.laplacian(rUA, self.p) == fvc.div(self.phi) pEqn.setReference(self.pRefCell, self.pRefValue) pEqn.solve() if nonOrth == nNonOrthCorr: self.phi.ext_assign(self.phi - pEqn.flux()) pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(self.mesh, self.phi, self.runTime, self.cumulativeContErr) self.U.ext_assign(self.U - rUA * fvc.grad(self.p)) self.U.correctBoundaryConditions() pass self.runTime.write() ext_Info() << "ExecutionTime = " << self.runTime.elapsedCpuTime() << " s" << " ClockTime = " << self.runTime.elapsedClockTime() << " s" << nl << nl self.runTime += self.runTime.deltaT() return self.runTime.value()
def _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g, initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ): closedVolume = p.needReference() rho.ext_assign( thermo.rho() ) # Thermodynamic density needs to be updated by psi*d(p) after the # pressure solution - done in 2 parts. Part 1: thermo.rho().ext_assign( thermo.rho() - psi * p ) rUA = 1.0/UEqn.A() from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) ) U.ext_assign( rUA * UEqn.H() ) phiU = fvc.interpolate( rho ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) phi.ext_assign( phiU + rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() ) ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm from Foam.finiteVolume import correction pEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p ) if corr == nCorr-1 and nonOrth == nNonOrthCorr: pEqn.solve( mesh.solver( word( str( p.name() ) + "Final" ) ) ) pass else: pEqn.solve( mesh.solver( p.name() ) ) pass if nonOrth == nNonOrthCorr: phi.ext_assign( phi + pEqn.flux() ) pass # Second part of thermodynamic density update thermo.rho().ext_assign( thermo.rho() + psi * p ) U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) ) U.correctBoundaryConditions() DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr ) # For closed-volume cases adjust the pressure and density levels # to obey overall mass continuity if closedVolume: p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) thermo.rho().ext_assign( psi * p ) rho.ext_assign( rho + ( initialMass - fvc.domainIntegrate( rho ) ) / totalVolume ) pass return cumulativeContErr
def fun_pEqn( i, mesh, p, rho, turb, thermo, thermoFluid, K, UEqn, U, phi, psi, DpDt, initialMass, p_rgh, gh, ghf, \ nNonOrthCorr, oCorr, nOuterCorr, corr, nCorr, cumulativeContErr ) : closedVolume = p_rgh.needReference() rho.ext_assign( thermo.rho() ) rUA = 1.0 / UEqn.A() from Foam import fvc from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ) , fvc.interpolate( rho * rUA ) ) U.ext_assign( rUA * UEqn.H() ) from Foam import fvc phiU = ( fvc.interpolate( rho ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) phi.ext_assign( phiU - rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() ) from Foam import fvm for nonOrth in range ( nNonOrthCorr + 1 ): p_rghEqn = ( fvm.ddt( psi, p_rgh) + fvc.ddt( psi, rho ) * gh + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh ) ) p_rghEqn.solve( mesh.solver( p_rgh.select( ( oCorr == nOuterCorr-1 and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) ) if nonOrth == nNonOrthCorr : phi.ext_assign( phi + p_rghEqn.flux() ) pass pass # Correct velocity field U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) ) U.correctBoundaryConditions() p.ext_assign( p_rgh + rho * gh ) #Update pressure substantive derivative DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) # Solve continuity from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) # Update continuity errors cumulativeContErr = compressibleContinuityErrors( i, mesh, rho, thermo, cumulativeContErr ) # For closed-volume cases adjust the pressure and density levels # to obey overall mass continuity if closedVolume : p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) rho.ext_assign( thermo.rho() ) p_rgh.ext_assign( p - rho * gh ) pass #Update thermal conductivity K.ext_assign( thermoFluid[ i ].Cp() * turb.alphaEff() ) return cumulativeContErr
def _UEqn(U, rho, phi, turbulence, p): from Foam import fvm UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) + turbulence.divDevRhoReff(U) from Foam import fvc from Foam.finiteVolume import solve solve(UEqn == -fvc.grad(p)) return UEqn
def solveSolid(i, rhosCps, Ks, Ts, nNonOrthCorr): for nonOrth in range(nNonOrthCorr + 1): from Foam.finiteVolume import solve from Foam import fvm solve(fvm.ddt(rhosCps[i], Ts[i]) - fvm.laplacian(Ks[i], Ts[i])) pass pass
def _UEqn( U, rho, phi, turbulence, p ): from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U ) from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == -fvc.grad( p ) ) return UEqn
def _eEqn( rho, e, phi, turbulence, p, thermo ): from Foam import fvm, fvc from Foam.finiteVolume import solve solve( fvm.ddt( rho, e ) + fvm.div( phi, e ) - fvm.laplacian( turbulence.alphaEff(), e ) == - p * fvc.div( phi / fvc.interpolate( rho ) ) ) thermo.correct() pass
def solveSolid( i, rhosCps, Ks, Ts, nNonOrthCorr ): for nonOrth in range( nNonOrthCorr +1 ): from Foam.finiteVolume import solve from Foam import fvm solve( fvm.ddt( rhosCps[ i ], Ts[ i ]) - fvm.laplacian( Ks[ i ], Ts[ i ] ) ) pass pass
def _hEqn(rho, h, phi, turbulence, DpDt, thermo): from Foam import fvm from Foam.finiteVolume import solve solve( fvm.ddt(rho, h) + fvm.div(phi, h) - fvm.laplacian(turbulence.alphaEff(), h) == DpDt) thermo.correct() pass
def fun_hEqn( mesh, rho, h, phi, DpDt, thermo, turbulence, finalIter ): from Foam import fvm hEqn = fvm.ddt( rho, h ) + fvm.div( phi, h ) - fvm.laplacian( turbulence.alphaEff(), h ) == DpDt hEqn.relax() hEqn.solve( mesh.solver( h.select( finalIter ) ) ) thermo.correct() pass
def _eEqn(rho, e, phi, turbulence, p, thermo): from Foam import fvm, fvc from Foam.finiteVolume import solve solve( fvm.ddt(rho, e) + fvm.div(phi, e) - fvm.laplacian(turbulence.alphaEff(), e) == -p * fvc.div(phi / fvc.interpolate(rho))) thermo.correct() pass
def _hEqn( rho, h, phi, turbulence, thermo, DpDt ): from Foam import fvm hEqn = fvm.ddt( rho, h ) + fvm.div(phi, h) - fvm.laplacian( turbulence.alphaEff(), h ) == DpDt hEqn.relax() hEqn.solve() thermo.correct() return hEqn
def fun_pEqn( mesh, p, rho, psi, p_rgh, U, phi, ghf, gh, DpDt, UEqn, thermo, nNonOrthCorr, corr, nCorr, finalIter, cumulativeContErr ): rho.ext_assign( thermo.rho() ) # Thermodynamic density needs to be updated by psi*d(p) after the # pressure solution - done in 2 parts. Part 1: thermo.rho().ext_assign( thermo.rho() - psi * p_rgh ) rUA = 1.0 / UEqn.A() from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) ) U.ext_assign( rUA*UEqn.H() ) phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) buoyancyPhi = -rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() phi.ext_assign( phi + buoyancyPhi ) from Foam import fvm from Foam.finiteVolume import correction for nonOrth in range( nNonOrthCorr +1 ): p_rghEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p_rgh ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh ) p_rghEqn.solve( mesh.solver( p_rgh.select( ( finalIter and corr == nCorr-1 and nonOrth == nNonOrthCorr ) ) ) ) if nonOrth == nNonOrthCorr: # Calculate the conservative fluxes phi.ext_assign( phi + p_rghEqn.flux() ) # Explicitly relax pressure for momentum corrector p_rgh.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorUAf ) ) U.correctBoundaryConditions() pass p.ext_assign( p_rgh + rho * gh ) # Second part of thermodynamic density update thermo.rho().ext_assign( thermo.rho() + psi * p_rgh ) DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr ) return cumulativeContErr
def fun_hEqn(mesh, rho, h, phi, DpDt, thermo, turbulence, finalIter): from Foam import fvm hEqn = fvm.ddt(rho, h) + fvm.div(phi, h) - fvm.laplacian( turbulence.alphaEff(), h) == DpDt hEqn.relax() hEqn.solve(mesh.solver(h.select(finalIter))) thermo.correct() pass
def solveSolid( mesh, rho, cp, K, T, nNonOrthCorr ): for index in range( nNonOrthCorr + 1 ): from Foam import fvm TEqn = fvm.ddt( rho * cp, T ) - fvm.laplacian( K, T ) TEqn.relax() TEqn.solve() pass from Foam.OpenFOAM import ext_Info, nl ext_Info()<< "Min/max T:" << T.ext_min() << ' ' << T.ext_max() << nl pass
def _hEqn(rho, h, phi, turbulence, thermo, DpDt): from Foam import fvm hEqn = fvm.ddt(rho, h) + fvm.div(phi, h) - fvm.laplacian( turbulence.alphaEff(), h) == DpDt hEqn.relax() hEqn.solve() thermo.correct() return hEqn
def solveMomentumEquation( momentumPredictor, U, rho, phi, pd, gh, turb ): # Solve the Momentum equation from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turb.divDevRhoReff( U ) UEqn.relax() if momentumPredictor : from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == -fvc.grad(pd) - fvc.grad(rho) * gh ) pass return UEqn
def _Ueqn( U, phi, turbulence, p, rhok, g, mesh, momentumPredictor ): from Foam import fvm # Solve the momentum equation UEqn = fvm.ddt( U ) + fvm.div( phi, U ) + turbulence.divDevReff( U ) UEqn.relax() from Foam.finiteVolume import solve from Foam import fvc if momentumPredictor: solve( UEqn == fvc.reconstruct( ( fvc.interpolate( rhok ) * ( g & mesh.Sf() ) - fvc.snGrad( p ) * mesh.magSf() ) ) ) return UEqn
def fun_UEqn( rho, U, phi, g, p, turb, mesh, momentumPredictor ) : # Solve the Momentum equation from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turb.divDevRhoReff( U ) UEqn.relax() if momentumPredictor : from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( fvc.interpolate( rho ) * ( g & mesh.Sf() ) - fvc.snGrad( p ) * mesh.magSf() ) ) pass return UEqn
def fun_UEqn( rho, U, phi, ghf, p_rgh, turb, mesh, momentumPredictor ) : # Solve the Momentum equation from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turb.divDevRhoReff( U ) UEqn.relax() if momentumPredictor : from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( ( -ghf * fvc.snGrad( rho ) - fvc.snGrad( p_rgh ) )*mesh.magSf() ) ) pass return UEqn
def fun_UEqn( mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter, momentumPredictor ): from Foam import fvm, fvc # Solve the Momentum equation UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U ) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( ( - ghf * fvc.snGrad( rho ) - fvc.snGrad( p_rgh ) ) * mesh.magSf() ), mesh.solver( U.select( finalIter) ) ); return UEqn
def solveEnthalpyEquation( rho, DpDt, phi, turb, thermo ): h = thermo.h() from Foam import fvm hEqn = ( ( fvm.ddt( rho, h ) + fvm.div( phi, h ) - fvm.laplacian( turb.alphaEff(), h ) ) == DpDt ) hEqn.relax() hEqn.solve() thermo.correct() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Min/max T:" << thermo.T().ext_min() << ' ' \ << thermo.T().ext_max() << nl return hEqn
def _UEqn( mesh, phi, U, p, turbulence, ocorr, nOuterCorr, momentumPredictor ): from Foam import fvm UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff( U ) if ocorr != nOuterCorr - 1: UEqn.relax() pass if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc solve( UEqn == -fvc.grad( p ) ) pass return UEqn
def _TEqn( turbulence, T, phi, rhok, beta, TRef, Pr, Prt ): 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.ddt( T ) + fvm.div( phi, T ) - fvm.laplacian( kappaEff, T ) TEqn.relax() TEqn.solve() rhok.ext_assign( 1.0 - beta * ( T - TRef ) ) return TEqn, kappaEff
def _UEqn(mesh, phi, U, p, turbulence, ocorr, nOuterCorr, momentumPredictor): from Foam import fvm UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U) if ocorr != nOuterCorr - 1: UEqn.relax() pass if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc solve(UEqn == -fvc.grad(p)) pass return UEqn
def fun_UEqn(mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter, momentumPredictor): from Foam import fvm, fvc # Solve the Momentum equation UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) + turbulence.divDevRhoReff(U) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( (-ghf * fvc.snGrad(rho) - fvc.snGrad(p_rgh)) * mesh.magSf()), mesh.solver(U.select(finalIter))) return UEqn
def fun_hEqn( mesh, rho, h, phi, turbulence, DpDt, thermo, oCorr, nOuterCorr ): from Foam import fvm hEqn = fvm.ddt(rho, h) + fvm.div( phi, h ) - fvm.laplacian( turbulence.alphaEff(), h ) == DpDt if oCorr == nOuterCorr-1: hEqn.relax() from Foam.OpenFOAM import word hEqn.solve(mesh.solver( word( "hFinal" ) ) ) pass else: hEqn.relax() hEqn.solve() pass thermo.correct() pass return hEqn
def fun_hEqn(mesh, rho, h, phi, turbulence, DpDt, thermo, oCorr, nOuterCorr): from Foam import fvm hEqn = fvm.ddt(rho, h) + fvm.div(phi, h) - fvm.laplacian( turbulence.alphaEff(), h) == DpDt if oCorr == nOuterCorr - 1: hEqn.relax() from Foam.OpenFOAM import word hEqn.solve(mesh.solver(word("hFinal"))) pass else: hEqn.relax() hEqn.solve() pass thermo.correct() pass return hEqn
def _UEqn( U, rho, phi, turbulence, p, momentumPredictor ): from Foam import fvm # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U ) UEqn = turbulence.divDevRhoReff( U ) + ( fvm.ddt( rho, U ) + fvm.div( phi, U ) ) from Foam.finiteVolume import solve if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc solve( UEqn == -fvc.grad( p ) ) pass return UEqn
def _UEqn(U, rho, phi, turbulence, p, momentumPredictor): from Foam import fvm # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U ) UEqn = turbulence.divDevRhoReff(U) + (fvm.ddt(rho, U) + fvm.div(phi, U)) from Foam.finiteVolume import solve if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc solve(UEqn == -fvc.grad(p)) pass return UEqn
def _UEqn( mesh, alpha1, U, p, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor ): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField( word( "muEff" ), twoPhaseProperties.muf() + fvc.interpolate( rho * turbulence.ext_nut() ) ) from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( rhoPhi, U ) - fvm.laplacian( muEff, U ) - ( fvc.grad( U ) & fvc.grad( muEff ) ) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == \ fvc.reconstruct( fvc.interpolate( rho ) * ( g & mesh.Sf() ) + \ ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - fvc.snGrad( p ) ) * mesh.magSf() ) ) pass return UEqn
def fun_pdEqn( corr, nCorr, nNonOrthCorr, closedVolume, pd, pRef, rho, psi, rUA, gh, phi ): closedVolume = pd.needReference() for nonOrth in range( nNonOrthCorr + 1): from Foam import fvc, fvm pdEqn = fvm.ddt( psi, pd ) + fvc.ddt( psi ) * pRef + fvc.ddt(psi, rho) * gh + fvc.div( phi ) - fvm.laplacian( rho * rUA, pd ) pdEqn.solve() if corr == nCorr-1 and nonOrth == nNonOrthCorr : from Foam.OpenFOAM import word pdEqn.solve( pd.mesh().solver( word( str( pd.name() ) + "Final" ) ) ) pass else: pdEqn.solve( pd.mesh().solver( pd.name() ) ) pass if nonOrth == nNonOrthCorr: phi.ext_assign(phi + pdEqn.flux() ) return pdEqn, closedVolume
def fun_hEqn( rho, h, phi, turb, DpDt, thermo, mesh, oCorr, nOuterCorr ) : from Foam import fvm hEqn = ( ( fvm.ddt( rho, h ) + fvm.div( phi, h ) - fvm.laplacian( turb.alphaEff(), h ) ) == DpDt ) if oCorr == nOuterCorr - 1 : hEqn.relax() from Foam.OpenFOAM import word hEqn.solve( mesh.solver( word( "hFinal" ) ) ) else: hEqn.relax() hEqn.solve() pass thermo.correct() from Foam.OpenFOAM import ext_Info, nl ext_Info()<< "Min/max T:" << thermo.T().ext_min().value() << ' ' \ << thermo.T().ext_max().value() << nl return hEqn
def fun_UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor, oCorr, nOuterCorr ): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField( word( "muEff" ), twoPhaseProperties.muf() + fvc.interpolate( rho * turbulence.ext_nut() ) ) from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( rhoPhi, U ) - fvm.laplacian( muEff, U ) - ( fvc.grad( U ) & fvc.grad( muEff ) ) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == \ fvc.reconstruct( ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) \ - fvc.snGrad( p_rgh ) ) * mesh.magSf(), mesh.solver( U.select( oCorr == nOuterCorr-1 ) ) ) ) pass return UEqn
def main_standalone(argc, argv): from Foam.OpenFOAM.include import setRootCase args = setRootCase(argc, argv) from Foam.OpenFOAM.include import createTime runTime = createTime(args) from Foam.OpenFOAM.include import createMesh mesh = createMesh(runTime) T, transportProperties, DT = _createFields(runTime, mesh) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nCalculating temperature distribution\n" << nl while runTime.loop(): ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls simple, nNonOrthCorr, momentumPredictor, fluxGradp, transonic = readSIMPLEControls( mesh) from Foam.finiteVolume import solve from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): solve(fvm.ddt(T) - fvm.laplacian(DT, T)) pass write(runTime, mesh, T) ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl pass ext_Info() << "End\n" << nl import os return os.EX_OK
def main_standalone(argc, argv): from Foam.OpenFOAM.include import setRootCase args = setRootCase(argc, argv) from Foam.OpenFOAM.include import createTime runTime = createTime(args) from Foam.OpenFOAM.include import createMesh mesh = createMesh(runTime) T, U, transportProperties, DT, phi = _createFields(runTime, mesh) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nCalculating scalar transport\n" << nl from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum, velMag = CourantNo(mesh, phi, runTime) while runTime.loop(): ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls simple, nNonOrthCorr, momentumPredictor, fluxGradp, transonic = readSIMPLEControls( mesh) from Foam.finiteVolume import solve from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): solve(fvm.ddt(T) + fvm.div(phi, T) - fvm.laplacian(DT, T)) pass runTime.write() pass ext_Info() << "End\n" << nl import os return os.EX_OK
def main_standalone( argc, argv ): from Foam.OpenFOAM.include import setRootCase args = setRootCase( argc, argv ) from Foam.OpenFOAM.include import createTime runTime = createTime( args ) from Foam.OpenFOAM.include import createMesh mesh = createMesh( runTime ) T, transportProperties, DT = _createFields( runTime, mesh ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nCalculating temperature distribution\n" << nl while runTime.loop() : ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls simple, nNonOrthCorr, momentumPredictor, transonic = readSIMPLEControls( mesh ) from Foam.finiteVolume import solve from Foam import fvm for nonOrth in range( nNonOrthCorr + 1 ): solve( fvm.ddt( T ) - fvm.laplacian( DT, T ) ) pass write( runTime, mesh, T ) ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl pass ext_Info() << "End\n" << nl import os return os.EX_OK
def _UEqn(mesh, U, rho, phi, turbulence, p, oCorr, nOuterCorr, momentumPredictor): from Foam import fvm # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U ) UEqn = turbulence.divDevRhoReff(U) + (fvm.ddt(rho, U) + fvm.div(phi, U)) if oCorr == nOuterCorr - 1: UEqn().relax(1.0) pass else: UEqn().relax() pass rUA = 1.0 / UEqn.A() from Foam.finiteVolume import solve from Foam.OpenFOAM import word from Foam import fvc if momentumPredictor: if oCorr == nOuterCorr - 1: solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal"))) pass else: solve(UEqn == -fvc.grad(p)) pass else: U.ext_assign(rUA * (UEqn.H() - fvc.grad(p))) U.correctBoundaryConditions() pass return UEqn
def fun_pEqn(mesh, thermo, p, rho, psi, U, phi, DpDt, pMin, UEqn, mrfZones, nNonOrthCorr, nCorr, oCorr, nOuterCorr, corr, transonic, cumulativeContErr): rho.ext_assign(thermo.rho()) rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) if nCorr <= 1: UEqn.clear() pass if transonic: from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phid = surfaceScalarField( word("phid"), fvc.interpolate(psi) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) mrfZones.relativeFlux(fvc.interpolate(psi), phid) from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvm.div(phid, p) - fvm.laplacian( rho * rUA, p) if oCorr == (nOuterCorr - 1) and (corr == nCorr - 1) and (nonOrth == nNonOrthCorr): from Foam.OpenFOAM import word pEqn.solve(mesh.solver(word("pFinal"))) pass else: pEqn.solve() pass if nonOrth == nNonOrthCorr: phi == pEqn.flux() pass else: from Foam import fvc phi.ext_assign( fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf()))) mrfZones.relativeFlux(fvc.interpolate(rho), phi) from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): # Pressure corrector pEqn = fvm.ddt(psi, p) + fvc.div(phi) - fvm.laplacian(rho * rUA, p) if oCorr == (nOuterCorr - 1) and corr == ( nCorr - 1) and nonOrth == nNonOrthCorr: from Foam.OpenFOAM import word pEqn.solve(mesh.solver(word("pFinal"))) pass else: pEqn.solve() pass if nonOrth == nNonOrthCorr: phi.ext_assign(phi + pEqn.flux()) pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs(rho, thermo, cumulativeContErr) # Explicitly relax pressure for momentum corrector p.relax() rho.ext_assign(thermo.rho()) rho.relax() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "rho max/min : " << rho.ext_max().value( ) << " " << rho.ext_min().value() << nl U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word DpDt.ext_assign( fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) from Foam.finiteVolume import bound bound(p, pMin) pass
def rhoEqn(rho, phi): from Foam import fvm, fvc from Foam.finiteVolume import solve solve(fvm.ddt(rho) + fvc.div(phi)) pass
def main_standalone( argc, argv ): from Foam.OpenFOAM.include import setRootCase args = setRootCase( argc, argv ) from Foam.OpenFOAM.include import createTime runTime = createTime( args ) from Foam.OpenFOAM.include import createMesh mesh = createMesh( runTime ) thermodynamicProperties, R, Cv = readThermodynamicProperties( runTime, mesh ) p, T, U, psi, rho, rhoU, rhoE = _createFields( runTime, mesh, R, Cv ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.loop() : ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import IOobject, word, fileName from Foam import fvc phiv = surfaceScalarField( IOobject( word( "phiv" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() ) CoNum = ( mesh.deltaCoeffs() * phiv.mag() / mesh.magSf() ).ext_max().value()*runTime.deltaT().value(); ext_Info() << "\nMax Courant Number = " << CoNum << nl from Foam import fvm from Foam.finiteVolume import solve solve( fvm.ddt(rho) + fvm.div( phiv, rho ) ) p.ext_assign( rho / psi ) solve( fvm.ddt( rhoU ) + fvm.div( phiv, rhoU ) == - fvc.grad( p ) ) U == rhoU / rho phiv2 = surfaceScalarField( IOobject( word( "phiv2" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() ) solve( fvm.ddt( rhoE ) + fvm.div( phiv, rhoE ) == - fvc.div( phiv2, p ) ) T.ext_assign( ( rhoE - 0.5 * rho * ( rhoU / rho ).magSqr() ) / Cv / rho ) psi.ext_assign( 1.0 / ( R * T ) ) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl pass ext_Info() << "End\n" import os return os.EX_OK