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 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 read_controls( args, runTime, mesh ): from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) from Foam.OpenFOAM import word, readLabel nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) ) nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) ) if nAlphaSubCycles > 1 and nOuterCorr != 1: from Foam.OpenFOAM import ext_Info, nl ext_Info() << args.executable() << "FATAL ERROR: Sub-cycling alpha is only allowed for PISO, i.e. when the number of outer-correctors = 1" << nl; import os; os_exit( 1 ) pass return piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles
def readControls( runTime, mesh): 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 ) correctPhi = True from Foam.OpenFOAM import word, Switch if piso.found( word( "correctPhi" ) ): correctPhi = Switch(piso.lookup( word( "correctPhi" ) ) ) pass checkMeshCourantNo = False if piso.found( word( "checkMeshCourantNo" ) ): checkMeshCourantNo = Switch( piso.lookup( word( "checkMeshCourantNo" ) ) ) pass return adjustTimeStep, maxCo, maxDeltaT, piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, correctPhi, checkMeshCourantNo
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) T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, pRefCell, pRefValue, rhok = _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.general.include import CourantNo CoNum, meanCoNum, velMag = CourantNo( mesh, phi, 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.loop(): ext_Info() << "Time = " << runTime.timeName() << nl << nl 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.general.include import CourantNo CoNum, meanCoNum, velMag = CourantNo( mesh, phi, runTime ) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) UEqn = _Ueqn( U, phi, turbulence, p, rhok, g, mesh, momentumPredictor ) TEqn, kappaEff = _TEqn( turbulence, T, phi, rhok, beta, TRef, Pr, Prt ) # --- PISO loop for corr in range( nCorr ): pEqn = _pEqn( runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr, cumulativeContErr ) pass turbulence.correct() 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 ) thermodynamicProperties, R, Cv, Cp, gamma, Pr = readThermodynamicProperties( runTime, mesh ) p, T, psi, pbf, rhoBoundaryTypes, rho, U, Ubf, rhoUboundaryTypes, \ rhoU, Tbf, rhoEboundaryTypes, rhoE, phi, phiv, rhoU, fields, magRhoU, H = _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.value() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.OpenFOAM import readScalar, word HbyAblend = readScalar( piso.lookup( word( "HbyAblend" ) ) ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) CoNum = ( mesh.deltaCoeffs() * phiv.mag() / mesh.magSf() ).ext_max().value() * runTime.deltaT().value() ext_Info() << "Max Courant Number = " << CoNum << nl from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ) for outerCorr in range( nOuterCorr): magRhoU.ext_assign( rhoU.mag() ) H.ext_assign( ( rhoE + p ) / rho ) from Foam.fv import multivariateGaussConvectionScheme_scalar mvConvection = multivariateGaussConvectionScheme_scalar( mesh, fields, phiv, mesh.divScheme( word( "div(phiv,rhoUH)" ) ) ) from Foam.finiteVolume import solve from Foam import fvm solve( fvm.ddt( rho ) + mvConvection.fvmDiv( phiv, rho ) ) tmp = mvConvection.interpolationScheme()()( magRhoU ) rhoUWeights = tmp.ext_weights( magRhoU ) from Foam.finiteVolume import weighted_vector rhoUScheme = weighted_vector(rhoUWeights) from Foam import fv, fvc rhoUEqn = fvm.ddt(rhoU) + fv.gaussConvectionScheme_vector( mesh, phiv, rhoUScheme ).fvmDiv( phiv, rhoU ) solve( rhoUEqn == -fvc.grad( p ) ) solve( fvm.ddt( rhoE ) + mvConvection.fvmDiv( phiv, rhoE ) == - mvConvection.fvcDiv( phiv, p ) ) T.ext_assign( (rhoE - 0.5 * rho * ( rhoU / rho ).magSqr() ) / Cv / rho ) psi.ext_assign( 1.0 / ( R * T ) ) p.ext_assign( rho / psi ) for corr in range( nCorr ): rrhoUA = 1.0 / rhoUEqn.A() from Foam.finiteVolume import surfaceScalarField rrhoUAf = surfaceScalarField( word( "rrhoUAf" ), fvc.interpolate( rrhoUA ) ) HbyA = rrhoUA * rhoUEqn.H() from Foam.finiteVolume import LimitedScheme_vector_MUSCLLimiter_NVDTVD_limitFuncs_magSqr from Foam.OpenFOAM import IStringStream, word HbyAWeights = HbyAblend * mesh.weights() + ( 1.0 - HbyAblend ) * \ LimitedScheme_vector_MUSCLLimiter_NVDTVD_limitFuncs_magSqr( mesh, phi, IStringStream( "HbyA" )() ).weights( HbyA ) from Foam.finiteVolume import surfaceInterpolationScheme_vector phi.ext_assign( ( surfaceInterpolationScheme_vector.ext_interpolate(HbyA, HbyAWeights) & mesh.Sf() ) \ + HbyAblend * fvc.ddtPhiCorr( rrhoUA, rho, rhoU, phi ) ) p.ext_boundaryField().updateCoeffs() phiGradp = rrhoUAf * mesh.magSf() * fvc.snGrad( p ) phi.ext_assign( phi - phiGradp ) resetPhiPatches( phi, rhoU, mesh ) rhof = mvConvection.interpolationScheme()()(rho).interpolate(rho) phiv.ext_assign( phi/rhof ) pEqn = fvm.ddt( psi, p ) + mvConvection.fvcDiv( phiv, rho ) + fvc.div( phiGradp ) - fvm.laplacian( rrhoUAf, p ) pEqn.solve() phi.ext_assign( phi + phiGradp + pEqn.flux() ) rho.ext_assign( psi * p ) rhof.ext_assign( mvConvection.interpolationScheme()()( rho ).interpolate(rho) ) phiv.ext_assign( phi / rhof ) rhoU.ext_assign( HbyA - rrhoUA * fvc.grad(p) ) rhoU.correctBoundaryConditions() pass pass U.ext_assign( rhoU / 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 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) transportProperties, nu, p, U, phi, pRefCell, pRefValue = 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" 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.incompressible import CourantNo CoNum, meanCoNum = CourantNo(mesh, phi, runTime) from Foam import fvm UEqn = fvm.ddt(U) + fvm.div(phi, U) - fvm.laplacian(nu, U) from Foam import fvc from Foam.finiteVolume import solve solve(UEqn == -fvc.grad(p)) # --- PISO loop for corr in range(nCorr): rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) phi.ext_assign((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi)) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.laplacian(rUA, p) == fvc.div(phi) pEqn.setReference(pRefCell, pRefValue) pEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign(phi - pEqn.flux()) pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() 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, 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 readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, \ pRefValue, interface, turbulence, g, gh, ghf = _createFields( runTime, mesh ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) correctPhi( runTime, mesh, phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue) from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum = CourantNo( mesh, phi, 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() : piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) CoNum, meanCoNum = CourantNo( mesh, phi, runTime ) maxAlphaCo, alphaCoNum, meanAlphaCoNum = alphaCourantNo( runTime, mesh, alpha1, phi ) runTime = setDeltaT( runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT ) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl twoPhaseProperties.correct() alphaEqnSubCycle( runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface ) UEqn = _UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor ) # --- PISO loop for corr in range( nCorr ): _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ) pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) turbulence.correct() 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 ) 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) from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls(mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() p, pd, gh, ghf, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pdRefCell, pdRefValue, pRefValue, interface, turbulence = _createFields( runTime, mesh, g ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue) from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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(): piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls(mesh) adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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 twoPhaseProperties.correct() alphaEqnSubCycle(runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface) UEqn = _UEqn( mesh, alpha1, U, pd, rho, rhoPhi, turbulence, ghf, twoPhaseProperties, interface, momentumPredictor ) # --- PISO loop for corr in range(nCorr): _pEqn( mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr, nNonOrthCorr, pdRefCell, pdRefValue ) pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) p.ext_assign(pd + rho * gh) if pd.needReference(): from Foam.OpenFOAM import dimensionedScalar from Foam.finiteVolume import getRefCellValue p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell))) pass 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.dynamicFvMesh import createDynamicFvMesh mesh = createDynamicFvMesh( runTime ) from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh() ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, \ pRefValue, interface, turbulence, g, gh, ghf = _createFields( runTime, mesh() ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime ) cumulativeContErr = fun_correctPhi( runTime, mesh(), phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue) from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum = CourantNo( mesh(), phi, 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() : adjustTimeStep, maxCo, maxDeltaT, piso, nCorr, nNonOrthCorr, \ momentumPredictor, transonic, nOuterCorr, correctPhi, checkMeshCourantNo = readControls( runTime, mesh() ) maxAlphaCo, alphaCoNum, meanAlphaCoNum = alphaCourantNo( runTime, mesh(), alpha1, phi ) CoNum, meanCoNum = CourantNo( mesh(), phi, runTime ) from Foam import fvc # Make the fluxes absolute fvc.makeAbsolute( phi, U ) runTime = setDeltaT( runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT ) runTime.increment() ext_Info() << "Time = " << runTime.timeName() << nl << nl timeBeforeMeshUpdate = runTime.elapsedCpuTime() # Do any mesh changes mesh.update() if mesh.changing(): ext_Info() << "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << nl gh.ext_assign( g & mesh.C() ) ghf.ext_assign( g & mesh.Cf() ) pass if mesh.changing() and correctPhi: cumulativeContErr = fun_correctPhi( runTime, mesh(), phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue) pass # Make the fluxes relative to the mesh motion fvc.makeRelative( phi, U ) if mesh.changing() and checkMeshCourantNo: from Foam.dynamicFvMesh import meshCourantNo meshCoNum, meanMeshCoNum = meshCourantNo( runTime, mesh(), phi ) pass twoPhaseProperties.correct() alphaEqnSubCycle( runTime, piso, mesh(), phi, alpha1, rho, rhoPhi, rho1, rho2, interface ) UEqn = _UEqn( mesh(), alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor ) # --- PISO loop for corr in range( nCorr ): cumulativeContErr = _pEqn( runTime, mesh(), UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, \ interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ) pass turbulence.correct() 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, 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
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, 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 ) p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport = _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.incompressible import CourantNo CoNum, meanCoNum = CourantNo( mesh, phi, runTime ) # Pressure-velocity PISO corrector from Foam import fvm #Momentum predictor # 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( U ) + fvm.div( phi, U ) + turbulence.divDevReff( U ) UEqn = turbulence.divDevReff( U ) + ( fvm.ddt( U ) + fvm.div( phi, U ) ) UEqn.relax() from Foam.finiteVolume import solve from Foam import fvc if momentumPredictor : solve( UEqn == -fvc.grad( p ) ) pass # --- PISO loop for corr in range( nCorr ) : rUA = 1.0 / UEqn.A() U.ext_assign( rUA * UEqn.H() ) phi.ext_assign( ( fvc.interpolate(U) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) ) from Foam.finiteVolume import adjustPhi adjustPhi( phi, U, p ) #Non-orthogonal pressure corrector loop for nonOrth in range( nNonOrthCorr + 1 ): #Pressure corrector pEqn = fvm.laplacian( rUA, p ) == fvc.div( phi ) pEqn.setReference( pRefCell, pRefValue ) if 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.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass turbulence.correct() 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 ) transportProperties, nu, Ubar, magUbar, flowDirection = readTransportProperties( runTime, mesh) p, U, phi, laminarTransport, sgsModel, pRefCell, pRefValue = _createFields( runTime, mesh ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() gradP, gradPFile = createGradP( runTime) 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.incompressible import CourantNo CoNum, meanCoNum = CourantNo( mesh, phi, runTime ) sgsModel.correct() from Foam import fvm UEqn = fvm.ddt( U ) + fvm.div( phi, U ) + sgsModel.divDevBeff( U ) == flowDirection * gradP if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc solve( UEqn == -fvc.grad( p ) ) pass rUA = 1.0 / UEqn.A() for corr in range( nCorr ): U.ext_assign( rUA * UEqn.H() ) from Foam import fvc phi.ext_assign( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) ) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) from Foam.OpenFOAM import word for nonOrth in range( nNonOrthCorr + 1 ): pEqn = fvm.laplacian( rUA, p ) == fvc.div( phi ) pEqn.setReference( pRefCell, pRefValue ) 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 pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass # Correct driving force for a constant mass flow rate # Extract the velocity in the flow direction magUbarStar = ( flowDirection & U ).weightedAverage( mesh.V() ) # Calculate the pressure gradient increment needed to # adjust the average flow-rate to the correct value gragPplus = ( magUbar - magUbarStar ) / rUA.weightedAverage( mesh.V() ) U.ext_assign( U + flowDirection * rUA * gragPplus ) gradP +=gragPplus ext_Info() << "Uncorrected Ubar = " << magUbarStar.value() << " " << "pressure gradient = " << gradP.value() << nl runTime.write() writeGradP( runTime, gradP ) 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) 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) gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration( runTime, mesh) h, h0, U, hU, hTotal, phi, F = _createFields(runTime, mesh, Omega, gHat) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.loop(): ext_Info() << "\nTime = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) CoNum, meanCoNum, waveCoNum = CourantNo(runTime, mesh, h, phi, magg) for ucorr in range(nOuterCorr): from Foam.finiteVolume import surfaceScalarField from Foam import fvc from Foam.OpenFOAM import word phiv = surfaceScalarField(word("phiv"), phi / fvc.interpolate(h)) from Foam import fvm hUEqn = fvm.ddt(hU) + fvm.div(phiv, hU) hUEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc if rotating: solve(hUEqn + (F ^ hU) == -magg * h * fvc.grad(h + h0)) pass else: solve(hUEqn == -magg * h * fvc.grad(h + h0)) pass # Constrain the momentum to be in the geometry if 3D geometry if mesh.nGeometricD() == 3: hU.ext_assign(hU - (gHat & hU) * gHat) hU.correctBoundaryConditions() pass for corr in range(nCorr): hf = fvc.interpolate(h) rUA = 1.0 / hUEqn.A() ghrUAf = magg * fvc.interpolate(h * rUA) phih0 = ghrUAf * mesh.magSf() * fvc.snGrad(h0) if rotating: hU.ext_assign(rUA * (hUEqn.H() - (F ^ hU))) pass else: hU = rUA * hUEqn.H() pass phi.ext_assign((fvc.interpolate(hU) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, h, hU, phi) - phih0) for nonOrth in range(nNonOrthCorr + 1): hEqn = fvm.ddt(h) + fvc.div(phi) - fvm.laplacian(ghrUAf, h) if ucorr < nOuterCorr - 1 or corr < nCorr - 1: hEqn.solve() pass else: hEqn.solve(mesh.solver(word(str(h.name()) + "Final"))) pass if nonOrth == nNonOrthCorr: phi.ext_assign(phi + hEqn.flux()) pass hU.ext_assign(hU - rUA * h * magg * fvc.grad(h + h0)) #Constrain the momentum to be in the geometry if 3D geometry if mesh.nGeometricD() == 3: hU.ext_assign(hU - (gHat & hU) * gHat) pass hU.correctBoundaryConditions() pass pass U == hU / h hTotal == h + h0 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 createMeshNoClear mesh = createMeshNoClear(runTime) transportProperties, nu = readTransportProperties(runTime, mesh) p, U, phi = _createFields(runTime, mesh) turbulenceProperties, force, K, forceGen = readTurbulenceProperties( runTime, mesh, U) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" 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.randomProcesses import fft from Foam.OpenFOAM import ReImSum force.internalField().ext_assign( ReImSum( fft.reverseTransform( K / (K.mag() + 1.0e-6) ^ forceGen.newField(), K.nn()))) globalProperties(runTime, U, nu, force) from Foam import fvm UEqn = fvm.ddt(U) + fvm.div(phi, U) - fvm.laplacian(nu, U) == force from Foam import fvc from Foam.finiteVolume import solve solve(UEqn == -fvc.grad(p)) # --- PISO loop for corr in range(1): rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) phi.ext_assign((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi)) pEqn = fvm.laplacian(rUA, p) == fvc.div(phi) pEqn.solve() phi.ext_assign(phi - pEqn.flux()) from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() pass runTime.write() if runTime.outputTime(): from Foam.randomProcesses import calcEk from Foam.OpenFOAM import word, fileName calcEk(U, K).write(fileName(runTime.timePath() / fileName("Ek")), runTime.graphFormat()) pass ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" \ << " ClockTime = " << runTime.elapsedClockTime() << " s" << 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) from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() p, pd, gh, ghf, alpha1, U, phi, rho1, rho2, rho, rhoPhi,\ twoPhaseProperties, pdRefCell, pdRefValue, pRefValue, interface, turbulence = _createFields( runTime, mesh, g ) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue) from Foam.finiteVolume.cfdTools.incompressible import CourantNo CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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(): piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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 twoPhaseProperties.correct() alphaEqnSubCycle(runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface) UEqn = _UEqn(mesh, alpha1, U, pd, rho, rhoPhi, turbulence, ghf, twoPhaseProperties, interface, momentumPredictor) # --- PISO loop for corr in range(nCorr): _pEqn(mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr, nNonOrthCorr, pdRefCell, pdRefValue) pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) p.ext_assign(pd + rho * gh) if pd.needReference(): from Foam.OpenFOAM import dimensionedScalar from Foam.finiteVolume import getRefCellValue p.ext_assign( p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell))) pass 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 createMeshNoClear mesh = createMeshNoClear( runTime ) p, U, phi, fluid, pRefCell, pRefValue = _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.incompressible import CourantNo CoNum, meanCoNum, velMag = CourantNo( mesh, phi, runTime ) fluid.correct() from Foam import fvm, fvc UEqn = fvm.ddt( U ) + fvm.div( phi, U ) - fvm.laplacian( fluid.ext_nu(), U ) from Foam.finiteVolume import solve solve( UEqn == -fvc.grad( p ) ) # --- PISO loop for corr in range( nCorr ): rUA = 1.0 / UEqn.A() U.ext_assign( rUA * UEqn.H() ) phi.ext_assign( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) ) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) for nonOrth in range( nNonOrthCorr + 1): pEqn = ( fvm.laplacian( rUA, p ) == fvc.div( phi ) ) pEqn.setReference( pRefCell, pRefValue ) pEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign( phi - pEqn.flux() ) pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass 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) p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport = _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.incompressible import CourantNo CoNum, meanCoNum = CourantNo(mesh, phi, runTime) # Pressure-velocity PISO corrector from Foam import fvm #Momentum predictor # 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( U ) + fvm.div( phi, U ) + turbulence.divDevReff( U ) UEqn = turbulence.divDevReff(U) + (fvm.ddt(U) + fvm.div(phi, U)) UEqn.relax() from Foam.finiteVolume import solve from Foam import fvc if momentumPredictor: solve(UEqn == -fvc.grad(p)) pass # --- PISO loop for corr in range(nCorr): rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) phi.ext_assign((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi)) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) #Non-orthogonal pressure corrector loop for nonOrth in range(nNonOrthCorr + 1): #Pressure corrector pEqn = fvm.laplacian(rUA, p) == fvc.div(phi) pEqn.setReference(pRefCell, pRefValue) if 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.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() pass turbulence.correct() 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) thermodynamicProperties, R, Cv, Cp, gamma, Pr = readThermodynamicProperties( runTime, mesh) p, T, psi, pbf, rhoBoundaryTypes, rho, U, Ubf, rhoUboundaryTypes, \ rhoU, Tbf, rhoEboundaryTypes, rhoE, phi, phiv, rhoU, fields, magRhoU, H = _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.value() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh) from Foam.OpenFOAM import readScalar, word HbyAblend = readScalar(piso.lookup(word("HbyAblend"))) from Foam.finiteVolume.cfdTools.general.include import readTimeControls adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime) CoNum = (mesh.deltaCoeffs() * phiv.mag() / mesh.magSf()).ext_max().value() * runTime.deltaT().value() ext_Info() << "Max Courant Number = " << CoNum << nl from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) for outerCorr in range(nOuterCorr): magRhoU.ext_assign(rhoU.mag()) H.ext_assign((rhoE + p) / rho) from Foam.fv import multivariateGaussConvectionScheme_scalar mvConvection = multivariateGaussConvectionScheme_scalar( mesh, fields, phiv, mesh.divScheme(word("div(phiv,rhoUH)"))) from Foam.finiteVolume import solve from Foam import fvm solve(fvm.ddt(rho) + mvConvection.fvmDiv(phiv, rho)) tmp = mvConvection.interpolationScheme()()(magRhoU) rhoUWeights = tmp.ext_weights(magRhoU) from Foam.finiteVolume import weighted_vector rhoUScheme = weighted_vector(rhoUWeights) from Foam import fv, fvc rhoUEqn = fvm.ddt(rhoU) + fv.gaussConvectionScheme_vector( mesh, phiv, rhoUScheme).fvmDiv(phiv, rhoU) solve(rhoUEqn == -fvc.grad(p)) solve( fvm.ddt(rhoE) + mvConvection.fvmDiv(phiv, rhoE) == -mvConvection.fvcDiv(phiv, p)) T.ext_assign((rhoE - 0.5 * rho * (rhoU / rho).magSqr()) / Cv / rho) psi.ext_assign(1.0 / (R * T)) p.ext_assign(rho / psi) for corr in range(nCorr): rrhoUA = 1.0 / rhoUEqn.A() from Foam.finiteVolume import surfaceScalarField rrhoUAf = surfaceScalarField(word("rrhoUAf"), fvc.interpolate(rrhoUA)) HbyA = rrhoUA * rhoUEqn.H() from Foam.finiteVolume import LimitedScheme_vector_MUSCLLimiter_NVDTVD_limitFuncs_magSqr from Foam.OpenFOAM import IStringStream, word HbyAWeights = HbyAblend * mesh.weights() + ( 1.0 - HbyAblend ) * \ LimitedScheme_vector_MUSCLLimiter_NVDTVD_limitFuncs_magSqr( mesh, phi, IStringStream( "HbyA" )() ).weights( HbyA ) from Foam.finiteVolume import surfaceInterpolationScheme_vector phi.ext_assign( ( surfaceInterpolationScheme_vector.ext_interpolate(HbyA, HbyAWeights) & mesh.Sf() ) \ + HbyAblend * fvc.ddtPhiCorr( rrhoUA, rho, rhoU, phi ) ) p.ext_boundaryField().updateCoeffs() phiGradp = rrhoUAf * mesh.magSf() * fvc.snGrad(p) phi.ext_assign(phi - phiGradp) resetPhiPatches(phi, rhoU, mesh) rhof = mvConvection.interpolationScheme()()(rho).interpolate( rho) phiv.ext_assign(phi / rhof) pEqn = fvm.ddt(psi, p) + mvConvection.fvcDiv( phiv, rho) + fvc.div(phiGradp) - fvm.laplacian(rrhoUAf, p) pEqn.solve() phi.ext_assign(phi + phiGradp + pEqn.flux()) rho.ext_assign(psi * p) rhof.ext_assign( mvConvection.interpolationScheme()()(rho).interpolate(rho)) phiv.ext_assign(phi / rhof) rhoU.ext_assign(HbyA - rrhoUA * fvc.grad(p)) rhoU.correctBoundaryConditions() pass pass U.ext_assign(rhoU / 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 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 ) gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration( runTime, mesh ) h, h0, U, hU, hTotal, phi, F = _createFields( runTime, mesh, Omega, gHat ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.loop() : ext_Info() << "\nTime = " << runTime.timeName() << nl << nl from Foam.finiteVolume.cfdTools.general.include import readPISOControls piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) CoNum, meanCoNum, waveCoNum = CourantNo( runTime, mesh, h, phi, magg ) for ucorr in range( nOuterCorr ): from Foam.finiteVolume import surfaceScalarField from Foam import fvc from Foam.OpenFOAM import word phiv = surfaceScalarField( word( "phiv" ), phi / fvc.interpolate( h ) ) from Foam import fvm hUEqn = fvm.ddt( hU ) + fvm.div( phiv, hU ) hUEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve from Foam import fvc if rotating: solve( hUEqn + ( F ^ hU ) == -magg * h * fvc.grad( h + h0 ) ) pass else: solve( hUEqn == -magg * h * fvc.grad( h + h0 ) ) pass # Constrain the momentum to be in the geometry if 3D geometry if mesh.nGeometricD() == 3 : hU.ext_assign( hU - ( gHat & hU ) * gHat ) hU.correctBoundaryConditions(); pass for corr in range( nCorr ): hf = fvc.interpolate( h ) rUA = 1.0 / hUEqn.A() ghrUAf = magg * fvc.interpolate( h * rUA ) phih0 = ghrUAf * mesh.magSf() * fvc.snGrad( h0 ) if rotating: hU.ext_assign( rUA * ( hUEqn .H() - ( F ^ hU ) ) ) pass else: hU = rUA * hUEqn.H() pass phi.ext_assign( ( fvc.interpolate( hU ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, h, hU, phi )- phih0 ) for nonOrth in range(nNonOrthCorr + 1): hEqn = fvm.ddt( h ) + fvc.div( phi ) - fvm.laplacian( ghrUAf, h ) if ucorr < nOuterCorr-1 or corr < nCorr-1 : hEqn.solve() pass else: hEqn.solve( mesh.solver( word( str( h.name() ) + "Final" ) ) ) pass if nonOrth == nNonOrthCorr: phi.ext_assign( phi + hEqn.flux() ) pass hU.ext_assign( hU - rUA * h * magg * fvc.grad( h + h0 ) ) #Constrain the momentum to be in the geometry if 3D geometry if mesh.nGeometricD() == 3: hU.ext_assign( hU - ( gHat & hU ) * gHat ) pass hU.correctBoundaryConditions() pass pass U == hU / h hTotal == h + h0 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) T, p, U, phi, laminarTransport, beta, TRef, Pr, Prt, turbulence, pRefCell, pRefValue, rhok = _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.general.include import CourantNo CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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.loop(): ext_Info() << "Time = " << runTime.timeName() << nl << nl 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.general.include import CourantNo CoNum, meanCoNum, velMag = CourantNo(mesh, phi, runTime) from Foam.finiteVolume.cfdTools.general.include import setDeltaT runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum) UEqn = _Ueqn(U, phi, turbulence, p, rhok, g, mesh, momentumPredictor) TEqn, kappaEff = _TEqn(turbulence, T, phi, rhok, beta, TRef, Pr, Prt) # --- PISO loop for corr in range(nCorr): pEqn = _pEqn(runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr, cumulativeContErr) pass turbulence.correct() 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 createMeshNoClear mesh = createMeshNoClear( runTime ) transportProperties, nu = readTransportProperties( runTime, mesh ) p, U, phi = _createFields( runTime, mesh ) turbulenceProperties, force, K, forceGen = readTurbulenceProperties( runTime, mesh, U ) from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs cumulativeContErr = initContinuityErrs() # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" 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.randomProcesses import fft from Foam.OpenFOAM import ReImSum force.internalField().ext_assign( ReImSum( fft.reverseTransform( K / ( K.mag() + 1.0e-6 ) ^ forceGen.newField(), K.nn() ) ) ) globalProperties( runTime, U, nu, force ) from Foam import fvm UEqn = fvm.ddt( U ) + fvm.div( phi, U ) - fvm.laplacian( nu, U ) == force from Foam import fvc from Foam.finiteVolume import solve solve( UEqn == -fvc.grad( p ) ) # --- PISO loop for corr in range( 1 ): rUA = 1.0 / UEqn.A() U.ext_assign( rUA*UEqn.H() ) phi.ext_assign( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) ) pEqn = fvm.laplacian( rUA, p ) == fvc.div( phi ) pEqn.solve() phi.ext_assign( phi - pEqn.flux() ) from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) U.ext_assign( U - rUA * fvc.grad( p ) ) U.correctBoundaryConditions() pass runTime.write() if runTime.outputTime(): from Foam.randomProcesses import calcEk from Foam.OpenFOAM import word, fileName calcEk( U, K ).write( fileName( runTime.timePath() / fileName( "Ek" ) ), runTime.graphFormat() ) pass ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" \ << " ClockTime = " << runTime.elapsedClockTime() << " s" << nl pass ext_Info() << "End\n" << nl import os return os.EX_OK