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 _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 _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 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) p, e, psi, rho, U, phi, turbulence, thermo = _createFields(runTime, mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() 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.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo( mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) UEqn = _UEqn(U, rho, phi, turbulence, p) _eEqn(rho, e, phi, turbulence, p, thermo) # --- PISO loop for corr in range(nCorr): cumulativeContErr = _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr) pass turbulence.correct() rho.ext_assign(thermo.rho()) 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
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 _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 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 ) p, e, psi, rho, U, phi, turbulence, thermo = _createFields( runTime, mesh ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() 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.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) UEqn = _UEqn( U, rho, phi, turbulence, p ) _eEqn( rho, e, phi, turbulence, p, thermo ) # --- PISO loop for corr in range( nCorr ) : cumulativeContErr = _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr ) pass turbulence.correct(); rho.ext_assign( thermo.rho() ) 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
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 _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 compressibleContinuityErrs(p, rho, phi, psi, cumulativeContErr): from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) sumLocalContErr = ((rho - psi * p).mag().sum() / rho.sum()).value() globalContErr = ((rho - psi * p).sum() / rho.sum()).value() cumulativeContErr += globalContErr from Foam.OpenFOAM import ext_Info, nl ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr\ << ", global = " << globalContErr \ << ", cumulative = " << cumulativeContErr << nl return cumulativeContErr
def compressibleContinuityErrs( p, rho, phi, psi, cumulativeContErr ): from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) sumLocalContErr = ( (rho - psi * p ).mag().sum() / rho.sum()).value() globalContErr = ( ( rho - psi * p ).sum() /rho.sum() ).value() cumulativeContErr += globalContErr from Foam.OpenFOAM import ext_Info, nl ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr\ << ", global = " << globalContErr \ << ", cumulative = " << cumulativeContErr << nl return cumulativeContErr
def solveFluid( i, mesh, thermo, thermoFluid, rho, K, U, phi, g, h, turb, DpDt, p, psi, massIni,\ oCorr, nCorr, nOuterCorr, nNonOrthCorr, momentumPredictor,cumulativeContErr ) : if oCorr == 0 : from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) pass UEqn = fun_UEqn( rho, U, phi, g, p, turb, mesh, momentumPredictor ) hEqn = fun_hEqn( rho, h, phi, turb, DpDt, thermo, mesh, oCorr, nOuterCorr ) # --- PISO loop for corr in range( nCorr ): cumulativeContErr = fun_pEqn( i, mesh, p, g, rho, turb, thermo, thermoFluid, K, UEqn, U, phi, psi, DpDt, massIni, nNonOrthCorr, oCorr, nOuterCorr, corr, nCorr, cumulativeContErr ) pass turb.correct() rho.ext_assign( thermo.rho() ) return cumulativeContErr
def solveFluid( i, mesh, thermo, thermoFluid, rho, K, U, phi, h, turb, DpDt, p, psi, initialMass, p_rgh, gh, ghf,\ oCorr, nCorr, nOuterCorr, nNonOrthCorr, momentumPredictor,cumulativeContErr ) : if oCorr == 0 : from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) pass UEqn = fun_UEqn( rho, U, phi, ghf, p_rgh, turb, mesh, momentumPredictor ) hEqn = fun_hEqn( rho, h, phi, turb, DpDt, thermo, mesh, oCorr, nOuterCorr ) # --- PISO loop for corr in range( nCorr ): cumulativeContErr = 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 ) pass turb.correct() rho.ext_assign( thermo.rho() ) return cumulativeContErr
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) p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt = _createFields(runTime, mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.run(): from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.general.include import readPIMPLEControls pimple, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic = readPIMPLEControls(mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl if nOuterCorr != 1: p.storePrevIter() rho.storePrevIter() pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) # --- Pressure-velocity PIMPLE corrector loop for oCorr in range(nOuterCorr): UEqn = _UEqn(mesh, U, rho, phi, turbulence, p, oCorr, nOuterCorr, momentumPredictor) hEqn = _hEqn(mesh, rho, h, phi, turbulence, DpDt, thermo, oCorr, nOuterCorr) # --- PISO loop for corr in range(nCorr): cumulativeContErr = _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, pMin, corr, cumulativeContErr, nCorr, oCorr, nOuterCorr, transonic, ) pass turbulence.correct() pass 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
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 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 ) thermo, p, h, psi, rho, U, phi, turbulence, DpDt = createFields( runTime, mesh ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl runTime.increment() while not runTime.end() : ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, ddtPhiCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) UEqn = _UEqn( U, rho, phi, turbulence, p ) _hEqn( rho, h, phi, turbulence, DpDt,thermo ) # -------PISO loop for corr in range( nCorr ): cumulativeContErr = _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr ) pass from Foam import fvc from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word DpDt = fvc.DDt( surfaceScalarField( word("phiU"), phi / fvc.interpolate( rho ) ), p ) turbulence.correct() rho.ext_assign( psi * p ) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl runTime.increment() pass ext_Info() << "End\n" import os return os.EX_OK
def _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, pMin, corr, cumulativeContErr, nCorr, oCorr, nOuterCorr, transonic, ): rho.ext_assign(thermo.rho()) rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) if nCorr <= 1: UEqn.clear() pass 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) if oCorr == nOuterCorr - 1 and corr == nCorr - 1 and nonOrth == nNonOrthCorr: pEqn.solve(mesh.solver(word("pFinal"))) pass else: pEqn.solve() pass if nonOrth == nNonOrthCorr: phi == pEqn.flux() pass pass pass else: phi.ext_assign(fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf()))) 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: pEqn.solve(mesh.solver(word("pFinal"))) pass else: pEqn.solve() pass 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) 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() DpDt.ext_assign(fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) from Foam.finiteVolume import bound bound(p, pMin) return cumulativeContErr
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 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) thermo, p, h, psi, rho, U, phi, turbulence, DpDt = createFields( runTime, mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl runTime.increment() while not runTime.end(): ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, ddtPhiCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) UEqn = _UEqn(U, rho, phi, turbulence, p) _hEqn(rho, h, phi, turbulence, DpDt, thermo) # -------PISO loop for corr in range(nCorr): cumulativeContErr = _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr) pass from Foam import fvc from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word DpDt = fvc.DDt( surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) turbulence.correct() rho.ext_assign(psi * p) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl runTime.increment() pass ext_Info() << "End\n" 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 ) from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration g = readGravitationalAcceleration( runTime, mesh) thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt = create_fields( runTime, mesh, g ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT runTime = setInitialDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) from Foam.OpenFOAM import ext_Info, nl ext_Info()<< "\nStarting time loop\n" << nl while runTime.run() : from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.finiteVolume.cfdTools.general.include import readPIMPLEControls pimple, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic = readPIMPLEControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) # --- Pressure-velocity PIMPLE corrector loop for oCorr in range( nOuterCorr ): finalIter = oCorr == ( nOuterCorr-1 ) if nOuterCorr != 1: p_rgh.storePrevIter() pass UEqn = fun_UEqn( mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter, momentumPredictor ) fun_hEqn( mesh, rho, h, phi, DpDt, thermo, turbulence, finalIter ) # --- PISO loop for corr in range( nCorr ): cumulativeContErr = fun_pEqn( mesh, p, rho, psi, p_rgh, U, phi, ghf, gh, DpDt, UEqn, \ thermo, nNonOrthCorr, corr, nCorr, finalIter, cumulativeContErr ) pass turbulence.correct() rho.ext_assign( thermo.rho() ) pass 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
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) transportProperties, mu = readingTransportProperties(runTime, mesh) p, T, e, U, psi, rho, phi = _createFields(runTime, mesh, R, Cv) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl runTime.increment() while not runTime.end(): ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transSonic, nOuterCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam import fvm UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) - fvm.laplacian(mu, U) from Foam import fvc from Foam.finiteVolume import solve solve(UEqn == -fvc.grad(p)) solve( fvm.ddt( rho, e ) + fvm.div( phi, e ) - fvm.laplacian( mu, e ) == \ - p * fvc.div( phi / fvc.interpolate( rho ) ) + mu * fvc.grad( U ).symm().magSqr() ) T.ext_assign(e / Cv) psi.ext_assign(1.0 / (R * T)) # --- PISO loop for corr in range(nCorr): rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) from Foam.OpenFOAM import word phid = ((fvc.interpolate(rho * U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi)) / fvc.interpolate(p) print "111111111111" for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvm.div( phid, p, word("div(phid,p)")) - fvm.laplacian( rho * rUA, p) pEqn.solve() phi = pEqn.flux() pass cumulativeContErr = compressibleContinuityErrs( p, rho, phi, psi, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() pass rho.ext_assign(psi * p) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl runTime.increment() pass ext_Info() << "End\n" 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) from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration g = readGravitationalAcceleration(runTime, mesh) thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume = _createFields( runTime, mesh, g) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT runTime = setInitialDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.run(): from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) UEqn = _Ueqn(U, phi, turbulence, p, rho, g, mesh, momentumPredictor) hEqn = _hEqn(rho, h, phi, turbulence, thermo, DpDt) # --- PISO loop for corr in range(nCorr): cumulativeContErr = _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g,\ initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ) pass turbulence.correct() rho.ext_assign(thermo.rho()) runTime.write() 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) from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration g = readGravitationalAcceleration(runTime, mesh) thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt = create_fields( runTime, mesh, g) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT runTime = setInitialDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.run(): from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.general.include import readPIMPLEControls pimple, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic = readPIMPLEControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) # --- Pressure-velocity PIMPLE corrector loop for oCorr in range(nOuterCorr): finalIter = oCorr == (nOuterCorr - 1) if nOuterCorr != 1: p_rgh.storePrevIter() pass UEqn = fun_UEqn(mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter, momentumPredictor) fun_hEqn(mesh, rho, h, phi, DpDt, thermo, turbulence, finalIter) # --- PISO loop for corr in range(nCorr): cumulativeContErr = fun_pEqn( mesh, p, rho, psi, p_rgh, U, phi, ghf, gh, DpDt, UEqn, \ thermo, nNonOrthCorr, corr, nCorr, finalIter, cumulativeContErr ) pass turbulence.correct() rho.ext_assign(thermo.rho()) pass 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
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 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, rho0, p0, psi, rhoO = readThermodynamicProperties( runTime, mesh) transportProperties, mu = readTransportProperties(runTime, mesh) p, U, rho, phi = _createFields(runTime, mesh, rhoO, psi) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() 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.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo( mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam import fvm, fvc from Foam.finiteVolume import solve UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) - fvm.laplacian(mu, U) solve(UEqn == -fvc.grad(p)) for corr in range(nCorr): rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField phid = surfaceScalarField( word("phid"), psi * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) phi.ext_assign((rhoO / psi) * phid) pEqn = fvm.ddt(psi, p) + fvc.div(phi) + fvm.div( phid, p) - fvm.laplacian(rho * rUA, p) pEqn.solve() phi.ext_assign(phi + pEqn.flux()) cumulativeContErr = compressibleContinuityErrs( rho, phi, psi, rho0, p, p0, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() pass rho.ext_assign(rhoO + psi * p) 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
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 ) transportProperties, mu = readingTransportProperties( runTime, mesh ) p, T, e, U, psi, rho, phi = _createFields( runTime, mesh, R, Cv ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl runTime.increment() while not runTime.end() : ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transSonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) - fvm.laplacian( mu, U ) from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == -fvc.grad( p ) ) solve( fvm.ddt( rho, e ) + fvm.div( phi, e ) - fvm.laplacian( mu, e ) == \ - p * fvc.div( phi / fvc.interpolate( rho ) ) + mu * fvc.grad( U ).symm().magSqr() ) T.ext_assign( e / Cv ) psi.ext_assign( 1.0 / ( R * T ) ) # --- PISO loop for corr in range( nCorr ): rUA = 1.0/UEqn.A() U.ext_assign( rUA * UEqn.H() ) from Foam.OpenFOAM import word phid = ( ( fvc.interpolate( rho * U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) / fvc.interpolate( p ) print "111111111111" for nonOrth in range( nNonOrthCorr + 1 ): pEqn = fvm.ddt( psi, p ) + fvm.div( phid, p, word( "div(phid,p)" ) ) - fvm.laplacian( rho * rUA, p ) pEqn.solve() phi = pEqn.flux() pass cumulativeContErr = compressibleContinuityErrs( p, rho, phi, psi, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass rho.ext_assign( psi * p ) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl runTime.increment() pass ext_Info() << "End\n" 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) thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity = create_fields( runTime, mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.run(): from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) from Foam.finiteVolume.cfdTools.general.include import readPIMPLEControls pimple, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic = readPIMPLEControls( mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl if nOuterCorr != 1: p.storePrevIter() rho.storePrevIter() pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) for oCorr in range(nOuterCorr): UEqn = fun_UEqn(mesh, pZones, rho, U, phi, turbulence, mrfZones, p, momentumPredictor, oCorr, nOuterCorr) hEqn = fun_hEqn(mesh, rho, h, phi, turbulence, DpDt, thermo, oCorr, nOuterCorr) for corr in range(nCorr): fun_pEqn(mesh, thermo, p, rho, psi, U, phi, DpDt, pMin, UEqn, mrfZones, nNonOrthCorr, nCorr, oCorr, nOuterCorr, corr, transonic, cumulativeContErr) pass turbulence.correct() pass 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
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 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, rho0, p0, psi, rhoO = readThermodynamicProperties( runTime, mesh ) transportProperties, mu = readTransportProperties( runTime, mesh ) p, U, rho, phi = _createFields( runTime, mesh, rhoO, psi ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() 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.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam import fvm, fvc from Foam.finiteVolume import solve UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) - fvm.laplacian(mu, U) solve( UEqn == -fvc.grad( p ) ) for corr in range( nCorr ): rUA = 1.0 / UEqn.A() U.ext_assign( rUA * UEqn.H() ) from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField phid = surfaceScalarField( word( "phid" ), psi * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) phi.ext_assign( ( rhoO / psi ) * phid ) pEqn = fvm.ddt( psi, p ) + fvc.div( phi ) + fvm.div( phid, p ) - fvm.laplacian( rho * rUA, p ) pEqn.solve() phi.ext_assign( phi + pEqn.flux() ) cumulativeContErr = compressibleContinuityErrs( rho, phi, psi, rho0, p, p0, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass rho.ext_assign( rhoO + psi*p ) 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
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 ) from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration g = readGravitationalAcceleration( runTime, mesh) thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume = _createFields( runTime, mesh, g ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT runTime = setInitialDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" <<nl while runTime.run(): from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo CoNum, meanCoNum, velMag = compressibleCourantNo( mesh, phi, rho, runTime ) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) UEqn = _Ueqn( U, phi, turbulence, p, rho, g, mesh, momentumPredictor ) hEqn = _hEqn( rho, h, phi, turbulence, thermo, DpDt ) # --- PISO loop for corr in range( nCorr ): cumulativeContErr = _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g,\ initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ) pass turbulence.correct() rho.ext_assign( thermo.rho() ) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl pass ext_Info() << "End\n" << nl import os return os.EX_OK