def compressibleCreatePhi(runTime, mesh, rhoU): from Foam.OpenFOAM import IOobject, word, fileName phiHeader = IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ) from Foam.OpenFOAM import ext_Info, nl if phiHeader.headerOk(): ext_Info() << "Reading face flux field phi\n" << nl from Foam.finiteVolume import surfaceScalarField phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) pass else: ext_Info() << "Calculating face flux field phi\n" << nl from Foam.OpenFOAM import wordList from Foam.finiteVolume import calculatedFvPatchScalarField phiTypes = wordList(2, calculatedFvPatchScalarField.typeName) from Foam.finiteVolume import surfaceScalarField, linearInterpolate phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), linearInterpolate(rhoU) & mesh.Sf(), phiTypes) pass return phiHeader, phi, phiTypes
def _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g, initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ): closedVolume = p.needReference() rho.ext_assign( thermo.rho() ) # Thermodynamic density needs to be updated by psi*d(p) after the # pressure solution - done in 2 parts. Part 1: thermo.rho().ext_assign( thermo.rho() - psi * p ) rUA = 1.0/UEqn.A() from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) ) U.ext_assign( rUA * UEqn.H() ) phiU = fvc.interpolate( rho ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) phi.ext_assign( phiU + rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() ) ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm from Foam.finiteVolume import correction pEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p ) if corr == nCorr-1 and nonOrth == nNonOrthCorr: pEqn.solve( mesh.solver( word( str( p.name() ) + "Final" ) ) ) pass else: pEqn.solve( mesh.solver( p.name() ) ) pass if nonOrth == nNonOrthCorr: phi.ext_assign( phi + pEqn.flux() ) pass # Second part of thermodynamic density update thermo.rho().ext_assign( thermo.rho() + psi * p ) U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) ) U.correctBoundaryConditions() DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr ) # For closed-volume cases adjust the pressure and density levels # to obey overall mass continuity if closedVolume: p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) thermo.rho().ext_assign( psi * p ) rho.ext_assign( rho + ( initialMass - fvc.domainIntegrate( rho ) ) / totalVolume ) pass return cumulativeContErr
def fun_pEqn( i, mesh, p, rho, turb, thermo, thermoFluid, K, UEqn, U, phi, psi, DpDt, initialMass, p_rgh, gh, ghf, \ nNonOrthCorr, oCorr, nOuterCorr, corr, nCorr, cumulativeContErr ) : closedVolume = p_rgh.needReference() rho.ext_assign( thermo.rho() ) rUA = 1.0 / UEqn.A() from Foam import fvc from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ) , fvc.interpolate( rho * rUA ) ) U.ext_assign( rUA * UEqn.H() ) from Foam import fvc phiU = ( fvc.interpolate( rho ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) ) phi.ext_assign( phiU - rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() ) from Foam import fvm for nonOrth in range ( nNonOrthCorr + 1 ): p_rghEqn = ( fvm.ddt( psi, p_rgh) + fvc.ddt( psi, rho ) * gh + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh ) ) p_rghEqn.solve( mesh.solver( p_rgh.select( ( oCorr == nOuterCorr-1 and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) ) if nonOrth == nNonOrthCorr : phi.ext_assign( phi + p_rghEqn.flux() ) pass pass # Correct velocity field U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) ) U.correctBoundaryConditions() p.ext_assign( p_rgh + rho * gh ) #Update pressure substantive derivative DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) # Solve continuity from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn( rho, phi ) # Update continuity errors cumulativeContErr = compressibleContinuityErrors( i, mesh, rho, thermo, cumulativeContErr ) # For closed-volume cases adjust the pressure and density levels # to obey overall mass continuity if closedVolume : p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) rho.ext_assign( thermo.rho() ) p_rgh.ext_assign( p - rho * gh ) pass #Update thermal conductivity K.ext_assign( thermoFluid[ i ].Cp() * turb.alphaEff() ) return cumulativeContErr
def create_fields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New( mesh ) from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField( word( "gh" ), g & mesh.C() ) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField( word( "ghf" ), g & mesh.Cf() ) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject( word( "p_rgh" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) # Force p_rgh to be consistent with p p_rgh.ext_assign( p - rho * gh ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc DpDt = volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) return thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt
def _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, cumulativeContErr, corr, nCorr, nOuterCorr, transonic): rho.ext_assign(thermo.rho()) rUA = 1.0 / UEqn.A() U.ext_assign(rUA * UEqn.H()) from Foam import fvc, fvm from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField if transonic: phid = surfaceScalarField( word("phid"), fvc.interpolate(psi) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvm.div(phid, p) - fvm.laplacian( rho * rUA, p) pEqn.solve() if nonOrth == nNonOrthCorr: phi == pEqn.flux() pass pass pass else: phi.ext_assign( fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))) for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.ddt(psi, p) + fvc.div(phi) - fvm.laplacian(rho * rUA, p) pEqn.solve() if nonOrth == nNonOrthCorr: phi.ext_assign(phi + pEqn.flux()) pass pass pass from Foam.finiteVolume.cfdTools.compressible import rhoEqn rhoEqn(rho, phi) from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs cumulativeContErr = compressibleContinuityErrs(rho, thermo, cumulativeContErr) U.ext_assign(U - rUA * fvc.grad(p)) U.correctBoundaryConditions() DpDt.ext_assign( fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) return cumulativeContErr
def fun_pEqn(thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr): rho.ext_assign(thermo.rho()) rUA = 1.0 / UEqn.A() from Foam.OpenFOAM import word from Foam import fvc, fvm from Foam.finiteVolume import surfaceScalarField rhorUAf = surfaceScalarField(word("(rho*(1|A(U)))"), fvc.interpolate(rho * rUA)) U.ext_assign(rUA * UEqn.H()) UEqn.clear() phi.ext_assign(fvc.interpolate(rho) * (fvc.interpolate(U) & mesh.Sf())) from Foam.finiteVolume import adjustPhi closedVolume = adjustPhi(phi, U, p) buoyancyPhi = surfaceScalarField(rhorUAf * fvc.interpolate(rho) * (g & mesh.Sf())) phi.ext_assign(phi + buoyancyPhi) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm pEqn = fvm.laplacian(rhorUAf, p) == fvc.div(phi) pEqn.setReference(pRefCell, p[pRefCell]) if (nonOrth == 0): eqnResidual = pEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) else: pEqn.solve() if (nonOrth == nNonOrthCorr): if (closedVolume): p.ext_assign(p + (initialMass - fvc.domainIntegrate(psi * p)) / fvc.domainIntegrate(psi)) phi.ext_assign(phi - pEqn.flux()) p.relax() U.ext_assign(U + rUA * fvc.reconstruct( (buoyancyPhi - pEqn.flux()) / rhorUAf)) U.correctBoundaryConditions() from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr) rho.ext_assign(thermo.rho()) rho.relax() ext_Info() << "rho max/min : " << rho.ext_max().value( ) << " " << rho.ext_min().value() << nl return eqnResidual, maxResidual, 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 create_fields(runTime, mesh, g): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New(mesh) from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField(word("gh"), g & mesh.C()) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField(word("ghf"), g & mesh.Cf()) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) # Force p_rgh to be consistent with p p_rgh.ext_assign(p - rho * gh) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc DpDt = volScalarField( word("DpDt"), fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) return thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt
def fun_pEqn( thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ): rho.ext_assign( thermo.rho() ) rUA = 1.0/UEqn.A() from Foam.OpenFOAM import word from Foam import fvc,fvm from Foam.finiteVolume import surfaceScalarField rhorUAf = surfaceScalarField(word( "(rho*(1|A(U)))" ) , fvc.interpolate(rho*rUA)); U.ext_assign(rUA*UEqn.H()) UEqn.clear() phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) ) from Foam.finiteVolume import adjustPhi closedVolume = adjustPhi(phi, U, p); buoyancyPhi =surfaceScalarField( rhorUAf * fvc.interpolate( rho )*( g & mesh.Sf() ) ) phi.ext_assign( phi+buoyancyPhi ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm pEqn = fvm.laplacian(rhorUAf, p) == fvc.div(phi) pEqn.setReference(pRefCell, p[pRefCell]); if (nonOrth == 0): eqnResidual = pEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) else: pEqn.solve() if (nonOrth == nNonOrthCorr): if (closedVolume): p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) phi.ext_assign( phi - pEqn.flux() ) p.relax() U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rhorUAf ) ) U.correctBoundaryConditions(); from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr ) rho.ext_assign( thermo.rho() ) rho.relax() ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl return eqnResidual, maxResidual, cumulativeContErr
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() e = thermo.e() T = thermo.T() psi = thermo.psi() mu = thermo.mu() inviscid = True if mu.internalField().max() > 0.0: inviscid = False pass ext_Info() << "Reading field U\n" << nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) pbf, rhoBoundaryTypes = _rhoBoundaryTypes(p) from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), thermo.rho(), rhoBoundaryTypes) rhoU = volVectorField( IOobject(word("rhoU"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho * U) rhoE = volScalarField( IOobject(word("rhoE"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho * (e + 0.5 * U.magSqr())) from Foam.OpenFOAM import dimensionedScalar, dimless from Foam.finiteVolume import surfaceScalarField pos = surfaceScalarField( IOobject(word("pos"), fileName(runTime.timeName()), mesh), mesh, dimensionedScalar(word("pos"), dimless, 1.0)) neg = surfaceScalarField( IOobject(word("neg"), fileName(runTime.timeName()), mesh), mesh, dimensionedScalar(word("neg"), dimless, -1.0)) return thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid
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 _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 alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ): from Foam.OpenFOAM import word alphaScheme = word( "div(phi,alpha)" ) alpharScheme = word( "div(phirb,alpha)" ) from Foam.finiteVolume import surfaceScalarField phic = surfaceScalarField( ( phi / mesh.magSf() ).mag() ) phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) ) phir = phic * interface.nHatf() from Foam import fvc from Foam import MULES for aCorr in range( nAlphaCorr ): phiAlpha = fvc.flux( phi, alpha1, alphaScheme ) + fvc.flux( -fvc.flux( -phir, 1.0 - alpha1, alpharScheme ), alpha1, alpharScheme ) MULES.explicitSolve( alpha1, phi, phiAlpha, 1.0, 0.0 ) rhoPhi.ext_assign( phiAlpha * ( rho1 - rho2 ) + phi * rho2 ) pass from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \ << " Min(alpha1) = " << alpha1.ext_min().value() \ << " Max(alpha1) = " << alpha1.ext_max().value() << nl pass
def _UEqn(mesh, alpha1, U, p, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField(word("muEff"), twoPhaseProperties.muf() + fvc.interpolate(rho * turbulence.ext_nut())) from Foam import fvm UEqn = fvm.ddt(rho, U) + fvm.div(rhoPhi, U) - fvm.laplacian(muEff, U) - (fvc.grad(U) & fvc.grad(muEff)) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct( fvc.interpolate(rho) * (g & mesh.Sf()) + (fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) - fvc.snGrad(p)) * mesh.magSf() ) ) pass return UEqn
def _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 alphaEqn(mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr): from Foam.OpenFOAM import word alphaScheme = word("div(phi,alpha)") alpharScheme = word("div(phirb,alpha)") from Foam.finiteVolume import surfaceScalarField phic = surfaceScalarField((phi / mesh.magSf()).mag()) phic.ext_assign((interface.cAlpha() * phic).ext_min(phic.ext_max())) phir = phic * interface.nHatf() from Foam import fvc from Foam import MULES for aCorr in range(nAlphaCorr): phiAlpha = fvc.flux(phi, alpha1, alphaScheme) + fvc.flux( -fvc.flux(-phir, 1.0 - alpha1, alpharScheme), alpha1, alpharScheme) MULES.explicitSolve(alpha1, phi, phiAlpha, 1.0, 0.0) rhoPhi.ext_assign(phiAlpha * (rho1 - rho2) + phi * rho2) pass from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \ << " Min(alpha1) = " << alpha1.ext_min().value() \ << " Max(alpha1) = " << alpha1.ext_max().value() << nl pass
def fun_UEqn(mesh, U, p_rgh, ghf, rho, rhoPhi, turbulence, twoPhaseProperties, momentumPredictor, finalIter): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField(word("muEff"), twoPhaseProperties.muf() + fvc.interpolate(rho * turbulence.ext_nut())) from Foam import fvm, fvc UEqn = fvm.ddt(rho, U) + fvm.div(rhoPhi, U) - fvm.laplacian(muEff, U) - (fvc.grad(U) & fvc.grad(muEff)) if finalIter: UEqn.relax(1.0) pass else: UEqn.relax() pass if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == fvc.reconstruct((-ghf * fvc.snGrad(rho) - fvc.snGrad(p_rgh)) * mesh.magSf()), mesh.solver(U.select(finalIter)), ) pass return UEqn
def createFields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading thermophysical properties\n" << nl ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject( word( "T" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi( runTime, mesh, U ) laminarTransport, beta, TRef,Pr, Prt = readTransportProperties( U, phi ) ext_Info() << "Creating turbulence model\n" << nl from Foam import incompressible turbulence = incompressible.RASModel.New( U, phi, laminarTransport ) ext_Info() << "Calculating field beta*(g.h)\n" << nl from Foam.finiteVolume import surfaceScalarField betaghf = surfaceScalarField( word( "betagh" ), beta * ( g & mesh.Cf() ) ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) # Kinematic density for buoyancy force rhok = volScalarField( IOobject( word( "rhok" ), fileName( runTime.timeName() ), mesh ), 1.0 - beta * ( T - TRef ) ) return T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, betaghf, pRefCell, pRefValue, rhok
def create_fields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New( mesh ) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), thermo.rho() ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar( mesh.solutionDict().subDict( word( "PIMPLE" ) ).lookup( word( "pMin" ) ) ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) # initialMass = fvc.domainIntegrate(rho) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) from Foam.finiteVolume import MRFZones mrfZones = MRFZones( mesh ) mrfZones.correctBoundaryVelocity( U ) from Foam.finiteVolume import porousZones pZones = porousZones( mesh ) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch( False ) return thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity
def fun_pEqn(runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField(word("rUA"), 1.0 / UEqn().A()) rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA)) U.ext_assign(rUA * UEqn().H()) UEqn.clear() from Foam import fvc phi.ext_assign(fvc.interpolate(U) & mesh.Sf()) from Foam.finiteVolume import adjustPhi adjustPhi(phi, U, p) buoyancyPhi = rUAf * fvc.interpolate(rhok) * (g & mesh.Sf()) phi.ext_assign(phi + buoyancyPhi) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm, fvc pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi) pEqn.setReference(pRefCell, pRefValue) # retain the residual from the first iteration if (nonOrth == 0): eqnResidual = pEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) pass else: pEqn.solve() pass if (nonOrth == nNonOrthCorr): # Calculate the conservative fluxes phi.ext_assign(phi - pEqn.flux()) # Explicitly relax pressure for momentum corrector p.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign(U + rUA * fvc.reconstruct((buoyancyPhi - pEqn.flux()) / rUAf)) U.correctBoundaryConditions() pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) return eqnResidual, maxResidual, cumulativeContErr
def fun_pEqn( runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField( word( "rUA" ), 1.0 / UEqn().A() ) rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) ) U.ext_assign( rUA * UEqn().H() ) UEqn.clear() from Foam import fvc phi.ext_assign( fvc.interpolate( U ) & mesh.Sf() ) from Foam.finiteVolume import adjustPhi adjustPhi( phi, U, p ) buoyancyPhi = rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() ) phi.ext_assign( phi + buoyancyPhi ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm, fvc pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi) pEqn.setReference( pRefCell, pRefValue ) # retain the residual from the first iteration if ( nonOrth == 0 ): eqnResidual = pEqn.solve().initialResidual() maxResidual = max( eqnResidual, maxResidual ) pass else: pEqn.solve() pass if ( nonOrth == nNonOrthCorr ): # Calculate the conservative fluxes phi.ext_assign( phi - pEqn.flux() ) # Explicitly relax pressure for momentum corrector p.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rUAf ) ) U.correctBoundaryConditions() pass pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) return eqnResidual, maxResidual, cumulativeContErr
def create_fields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho()) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar(mesh.solutionDict().subDict( word("PIMPLE")).lookup(word("pMin"))) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) # initialMass = fvc.domainIntegrate(rho) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) from Foam.finiteVolume import MRFZones mrfZones = MRFZones(mesh) mrfZones.correctBoundaryVelocity(U) from Foam.finiteVolume import porousZones pZones = porousZones(mesh) from Foam.OpenFOAM import Switch pressureImplicitPorosity = Switch(False) return thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity
def createFields(runTime, mesh, g): ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo thermo = basicPsiThermo.New(mesh) from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOobject, word, fileName rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New(rho, U, phi, thermo()) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField(word("gh"), g & mesh.C()) from Foam.finiteVolume import surfaceScalarField ghf = surfaceScalarField(word("ghf"), g & mesh.Cf()) ext_Info() << "Reading field p_rgh\n" << nl p_rgh = volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) #Force p_rgh to be consistent with p p_rgh.ext_assign(p - rho * gh) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, p_rgh, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue) from Foam import fvc initialMass = fvc.domainIntegrate(rho) totalVolume = mesh.V().ext_sum() return thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
def _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ): rAU = 1.0/UEqn.A() from Foam import fvc rAUf = fvc.interpolate( rAU ) U.ext_assign( rAU * UEqn.H() ) from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phiU = surfaceScalarField( word( "phiU" ), fvc.interpolate( U ) & mesh.Sf() ) if p_rgh.needReference(): fvc.makeRelative( phiU, U ) from Foam.finiteVolume import adjustPhi adjustPhi( phiU, U, p ) fvc.makeAbsolute( phiU, U ) pass phi.ext_assign( phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) )*rAUf*mesh.magSf() ) from Foam import fvm for nonOrth in range( nNonOrthCorr + 1 ): p_rghEqn = fvm.laplacian( rAUf, p_rgh ) == fvc.div( phi ) p_rghEqn.setReference( pRefCell, pRefValue ) p_rghEqn.solve( mesh.solver( p_rgh.select(corr == nCorr-1 and nonOrth == nNonOrthCorr) ) ) if nonOrth == nNonOrthCorr: phi.ext_assign( phi - p_rghEqn.flux() ) pass pass U.ext_assign( U + rAU * fvc.reconstruct( ( phi - phiU ) / rAUf ) ) U.correctBoundaryConditions() from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) # Make the fluxes relative to the mesh motion fvc.makeRelative( phi, U ) p == p_rgh + rho * gh if p_rgh.needReference(): from Foam.OpenFOAM import pRefValue p.ext_assign( p + dimensionedScalar( word( "p" ), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell) ) ) p_rgh.ext_assign( p - rho * gh ) pass return cumulativeContErr
def createPhi(runTime, hU, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import surfaceScalarField ext_Info() << "Reading/calculating face flux field phi\n" << nl from Foam.finiteVolume import linearInterpolate phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), linearInterpolate(hU) & mesh.Sf()) return phi
def fun_pEqn( runTime, mesh, UEqn, p, p_rgh, phi, U, rho, rho1, rho2, rho10, rho20, gh, ghf, dgdt, pMin, \ psi1, psi2, alpha1, alpha2, interface, transonic, oCorr, nOuterCorr, corr, nCorr, nNonOrthCorr ): rUA = 1.0/UEqn.A() from Foam import fvc rUAf = fvc.interpolate( rUA ) p_rghEqnComp = None from Foam import fvm if transonic: p_rghEqnComp = fvm.ddt( p_rgh ) + fvm.div( phi, p_rgh ) - fvm.Sp( fvc.div( phi ), p_rgh ) pass else: p_rghEqnComp = fvm.ddt( p_rgh ) + fvc.div( phi, p_rgh ) - fvc.Sp( fvc.div( phi ), p_rgh ) pass U.ext_assign( rUA * UEqn.H() ) from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phiU = surfaceScalarField( word( "phiU" ), ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) phi.ext_assign(phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) ) * rUAf * mesh.magSf() ) from Foam.finiteVolume import solve from Foam.OpenFOAM import scalar for nonOrth in range( nNonOrthCorr +1 ): p_rghEqnIncomp = fvc.div( phi ) - fvm.laplacian( rUAf, p_rgh ) solve( ( alpha1.ext_max( scalar( 0 ) ) * ( psi1 / rho1 ) + alpha2.ext_max( scalar( 0 ) ) * ( psi2 / rho2 ) ) *p_rghEqnComp() + p_rghEqnIncomp, mesh.solver( p_rgh.select( oCorr == ( nOuterCorr - 1 ) and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) if nonOrth == nNonOrthCorr: dgdt.ext_assign( ( alpha2.pos() * ( psi2 / rho2 ) - alpha1.pos() * ( psi1 / rho1 ) ) * ( p_rghEqnComp & p_rgh ) ) phi.ext_assign( phi + p_rghEqnIncomp.flux() ) pass U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rUAf ) ) U.correctBoundaryConditions() p.ext_assign( ( ( p_rgh + gh * ( alpha1 * rho10 + alpha2 * rho20 ) ) /( 1.0 - gh * ( alpha1 * psi1 + alpha2 * psi2 ) ) ).ext_max( pMin ) ) rho1.ext_assign( rho10 + psi1 * p ) rho2.ext_assign( rho20 + psi2 * p ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "max(U) " << U.mag().ext_max().value() << nl ext_Info() << "min(p_rgh) " << p_rgh.ext_min().value() << nl pass
def _createFields( runTime, mesh, g ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New( mesh ) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho= volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), thermo.rho() ) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New( rho, U, phi, thermo() ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) ) thermo.correct() initialMass = fvc.domainIntegrate(rho); totalVolume = mesh.V().ext_sum() return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
def createPhi( runTime, hU, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import surfaceScalarField ext_Info() << "Reading/calculating face flux field phi\n" << nl from Foam.finiteVolume import linearInterpolate phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), linearInterpolate( hU ) & mesh.Sf() ) return phi
def createFields(runTime, mesh, g): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading thermophysical properties\n" << nl ext_Info() << "Reading field T\n" << nl T = volScalarField( IOobject(word("T"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.incompressible import createPhi phi = createPhi(runTime, mesh, U) laminarTransport, beta, TRef, Pr, Prt = readTransportProperties(U, phi) ext_Info() << "Creating turbulence model\n" << nl from Foam import incompressible turbulence = incompressible.RASModel.New(U, phi, laminarTransport) ext_Info() << "Calculating field beta*(g.h)\n" << nl from Foam.finiteVolume import surfaceScalarField betaghf = surfaceScalarField(word("betagh"), beta * (g & mesh.Cf())) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue) # Kinematic density for buoyancy force rhok = volScalarField( IOobject(word("rhok"), fileName(runTime.timeName()), mesh), 1.0 - beta * (T - TRef)) return T, p, U, phi, laminarTransport, beta, TRef, Pr, Prt, turbulence, betaghf, pRefCell, pRefValue, rhok
def compressibleCreatePhi( runTime, mesh, rhoU ): from Foam.OpenFOAM import IOobject, word, fileName phiHeader = IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ ) from Foam.OpenFOAM import ext_Info, nl if phiHeader.headerOk(): ext_Info() << "Reading face flux field phi\n" << nl from Foam.finiteVolume import surfaceScalarField phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) pass else: ext_Info() << "Calculating face flux field phi\n" << nl from Foam.OpenFOAM import wordList from Foam.finiteVolume import calculatedFvPatchScalarField phiTypes =wordList( 2, calculatedFvPatchScalarField.typeName ) from Foam.finiteVolume import surfaceScalarField, linearInterpolate phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), linearInterpolate( rhoU ) & mesh.Sf(), phiTypes ) pass return phiHeader, phi, phiTypes
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho(), ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar(mesh.solutionDict().subDict(word("PIMPLE")).lookup(word("pMin"))) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) return p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt
def _pEqn(mesh, UEqn, U, p, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue): rUA = 1.0 / UEqn.A() from Foam import fvc rUAf = fvc.interpolate(rUA) U.ext_assign(rUA * UEqn.H()) from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phiU = surfaceScalarField(word("phiU"), (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi)) from Foam.finiteVolume import adjustPhi adjustPhi(phiU, U, p) phi.ext_assign( phiU + ( fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) * mesh.magSf() + fvc.interpolate(rho) * (g & mesh.Sf()) ) * rUAf ) from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): pEqn = fvm.laplacian(rUAf, 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 U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf)) U.correctBoundaryConditions() pass
def fun_pEqn( i, fluidRegions, Uf, pdf, rhof, thermof, phif, ghf, Kf, DpDtf, turb, initialMassf, UEqn, pRef, corr, nCorr, nNonOrthCorr, cumulativeContErr ) : closedVolume = False rhof[ i ].ext_assign( thermof[ i ].rho() ) rUA = 1.0 / UEqn.A() Uf[ i ].ext_assign( rUA * UEqn.H() ) from Foam import fvc phif[ i ] .ext_assign( fvc.interpolate( rhof[ i ] ) * ( ( fvc.interpolate( Uf[ i ] ) & fluidRegions[ i ].Sf() ) + fvc.ddtPhiCorr( rUA, rhof[ i ], Uf[ i ], phif[ i ] ) ) - fvc.interpolate( rhof[ i ] * rUA * ghf[ i ] ) * fvc.snGrad( rhof[ i ] ) * fluidRegions[ i ].magSf() ) # Solve pressure difference pdEqn, closedVolume = fun_pdEqn( corr, nCorr, nNonOrthCorr, closedVolume, pdf[i], pRef, rhof[i], thermof[i].psi(), rUA, ghf[i], phif[i] ) # Solve continuity rhoEqn( rhof[i], phif[i] ) # Update pressure field (including bc) from Foam.OpenFOAM import word thermof[i].p() == pdf[ i ] + rhof[ i ] * ghf[ i ] + pRef from Foam.finiteVolume import surfaceScalarField DpDtf[i].ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phif[ i ] / fvc.interpolate( rhof[ i ] ) ), thermof[i].p() ) ) # Update continuity errors cumulativeContErr = compressibleContinuityErrors( cumulativeContErr, rhof[i], thermof[i] ) # Correct velocity field Uf[ i ].ext_assign( Uf[i] - rUA * ( fvc.grad( pdf[ i ] ) + fvc.grad( rhof[ i ] ) * ghf[ i ] ) ) Uf[ i ].correctBoundaryConditions() # For closed-volume cases adjust the pressure and density levels # to obey overall mass continuity if (closedVolume): from Foam.OpenFOAM import dimensionedScalar, dimMass thermof[i].p().ext_assign( thermof[i].p() + ( dimensionedScalar( word( "massIni" ), dimMass, initialMassf[ i ] ) - fvc.domainIntegrate( thermof[ i ].psi() * thermof[ i ].p() ) ) / fvc.domainIntegrate( thermof[ i ].psi() ) ) rhof[ i ].ext_assign( thermof[ i ].rho() ) # Update thermal conductivity Kf[i].ext_assign( rhof[ i ] * thermof[ i ].Cp() * turb[ i ].alphaEff() ) return cumulativeContErr
def _createFields(runTime, mesh, g): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicRhoThermo thermo = basicRhoThermo.New(mesh) from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho()) p = thermo.p() h = thermo.h() psi = thermo.psi() ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = volScalarField( word("DpDt"), fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)) thermo.correct() initialMass = fvc.domainIntegrate(rho) totalVolume = mesh.V().ext_sum() return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
def createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo thermo = basicThermo.New( mesh ) p = thermo.p() h = thermo.h() psi = thermo.psi() rho = thermo.rho() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh ), rho ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi( runTime, mesh, rho, U ) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField(word( "phiU" ), phi / fvc.interpolate( rho ) ), p ); return thermo, p, h, psi, rho, U, phi, turbulence, DpDt
def createPhi(runTime, mesh, U): print "Reading/calculating face flux field phi\n" from Foam.OpenFOAM import Time from Foam.OpenFOAM import word from Foam.OpenFOAM import fileName from Foam.OpenFOAM import IOobject from Foam.finiteVolume import fvMesh from Foam.finiteVolume import volScalarField from Foam.finiteVolume import surfaceScalarField from Foam.finiteVolume import linearInterpolate phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), linearInterpolate(U) & mesh.Sf()) return phi
def _createFields( runTime, mesh ): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.NO_WRITE ), mesh ) from Foam.OpenFOAM import dimensionedScalar p.ext_assign( dimensionedScalar( word( "zero" ), p.dimensions(), 0.0 ) ) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) from Foam.OpenFOAM import dimensionedVector, vector U.ext_assign( dimensionedVector( word( "0" ), U.dimensions(), vector.zero ) ) from Foam.finiteVolume import surfaceScalarField from Foam import fvc phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), fvc.interpolate( U ) & mesh.Sf() ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue ) return p, U, phi, pRefCell, pRefValue
def createPhi( runTime, mesh, U ): print "Reading/calculating face flux field phi\n" from Foam.OpenFOAM import Time from Foam.OpenFOAM import word from Foam.OpenFOAM import fileName from Foam.OpenFOAM import IOobject from Foam.finiteVolume import fvMesh from Foam.finiteVolume import volScalarField from Foam.finiteVolume import surfaceScalarField from Foam.finiteVolume import linearInterpolate phi = surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), linearInterpolate( U ) & mesh.Sf() ) return phi
def _UEqn( mesh, alpha1, U, p, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor ): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField( word( "muEff" ), twoPhaseProperties.muf() + fvc.interpolate( rho * turbulence.ext_nut() ) ) from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( rhoPhi, U ) - fvm.laplacian( muEff, U ) - ( fvc.grad( U ) & fvc.grad( muEff ) ) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == \ fvc.reconstruct( fvc.interpolate( rho ) * ( g & mesh.Sf() ) + \ ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - fvc.snGrad( p ) ) * mesh.magSf() ) ) pass return UEqn
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Reading thermophysical properties\n" << nl from Foam.thermophysicalModels import basicPsiThermo, autoPtr_basicPsiThermo thermo = basicPsiThermo.New(mesh) p = thermo.p() h = thermo.h() psi = thermo.psi() from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField rho = volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho()) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi phi = compressibleCreatePhi(runTime, mesh, rho, U) from Foam.OpenFOAM import dimensionedScalar pMin = dimensionedScalar(mesh.solutionDict().subDict( word("PIMPLE")).lookup(word("pMin"))) ext_Info() << "Creating turbulence model\n" << nl from Foam import compressible turbulence = compressible.turbulenceModel.New(rho, U, phi, thermo()) ext_Info() << "Creating field DpDt\n" << nl from Foam import fvc from Foam.finiteVolume import surfaceScalarField DpDt = fvc.DDt( surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p) return p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt
def _pEqn(mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr, nNonOrthCorr, pdRefCell, pdRefValue): rUA = 1.0 / UEqn.A() from Foam import fvc rUAf = fvc.interpolate(rUA) U.ext_assign(rUA * UEqn.H()) from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import word phiU = surfaceScalarField(word("phiU"), (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi)) from Foam.finiteVolume import adjustPhi adjustPhi(phiU, U, p) phi.ext_assign(phiU + (fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) - ghf * fvc.snGrad(rho)) * rUAf * mesh.magSf()) from Foam import fvm for nonOrth in range(nNonOrthCorr + 1): pdEqn = fvm.laplacian(rUAf, pd) == fvc.div(phi) pdEqn.setReference(pdRefCell, pdRefValue) if corr == nCorr - 1 and nonOrth == nNonOrthCorr: pdEqn.solve(mesh.solver(word(str(pd.name()) + "Final"))) pass else: pdEqn.solve(mesh.solver(pd.name())) pass if nonOrth == nNonOrthCorr: phi.ext_assign(phi - pdEqn.flux()) pass pass U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf)) U.correctBoundaryConditions() pass
def fun_UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor, oCorr, nOuterCorr ): from Foam.OpenFOAM import word from Foam.finiteVolume import surfaceScalarField from Foam import fvc muEff = surfaceScalarField( word( "muEff" ), twoPhaseProperties.muf() + fvc.interpolate( rho * turbulence.ext_nut() ) ) from Foam import fvm UEqn = fvm.ddt( rho, U ) + fvm.div( rhoPhi, U ) - fvm.laplacian( muEff, U ) - ( fvc.grad( U ) & fvc.grad( muEff ) ) UEqn.relax() if momentumPredictor: from Foam.finiteVolume import solve solve( UEqn == \ fvc.reconstruct( ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) \ - fvc.snGrad( p_rgh ) ) * mesh.magSf(), mesh.solver( U.select( oCorr == nOuterCorr-1 ) ) ) ) pass return UEqn
def _pEqn(runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr, cumulativeContErr): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField(word("rUA"), 1.0 / UEqn.A()) rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA)) U.ext_assign(rUA * UEqn.H()) phiU = (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi) phi.ext_assign(phiU + rUAf * fvc.interpolate(rhok) * (g & mesh.Sf())) for nonOrth in range(nNonOrthCorr + 1): from Foam import fvm pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi) if (corr == nCorr - 1) and (nonOrth == nNonOrthCorr): from Foam.OpenFOAM import word 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 U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf)) U.correctBoundaryConditions() from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr) return pEqn
def _pEqn( runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr, cumulativeContErr ): from Foam.finiteVolume import volScalarField, surfaceScalarField from Foam.OpenFOAM import word from Foam import fvc rUA = volScalarField( word( "rUA" ), 1.0 / UEqn.A() ) rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) ) U.ext_assign( rUA * UEqn.H() ) phiU = ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) phi.ext_assign( phiU + rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() ) ) for nonOrth in range( nNonOrthCorr+1 ): from Foam import fvm pEqn = fvm.laplacian( rUAf, p ) == fvc.div( phi ) if ( corr == nCorr-1 ) and (nonOrth == nNonOrthCorr): from Foam.OpenFOAM import word 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 U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rUAf ) ) U.correctBoundaryConditions() from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) return pEqn
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volScalarField ext_Info() << "Reading field p\n" << nl p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE), mesh) from Foam.OpenFOAM import dimensionedScalar p.ext_assign(dimensionedScalar(word("zero"), p.dimensions(), 0.0)) ext_Info() << "Reading field U\n" << nl from Foam.finiteVolume import volVectorField U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) from Foam.OpenFOAM import dimensionedVector, vector U.ext_assign(dimensionedVector(word("0"), U.dimensions(), vector.zero)) from Foam.finiteVolume import surfaceScalarField from Foam import fvc phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), fvc.interpolate(U) & mesh.Sf()) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue) return p, U, phi, pRefCell, pRefValue
def _createFields(runTime, mesh): from Foam.OpenFOAM import ext_Info, nl from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName from Foam.finiteVolume import volVectorField ext_Info() << "Reading field U\n" << nl U = volVectorField( IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh) ext_Info() << "Creating face flux\n" << nl from Foam.OpenFOAM import dimensionedScalar from Foam.finiteVolume import surfaceScalarField phi = surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), mesh, dimensionedScalar(word("zero"), mesh.Sf().dimensions() * U.dimensions(), 0.0)) from Foam.transportModels import singlePhaseTransportModel laminarTransport = singlePhaseTransportModel(U, phi) from Foam import incompressible turbulence = incompressible.RASModel.New(U, phi, laminarTransport) transportProperties = IOdictionary( IOobject(word("transportProperties"), fileName(runTime.constant()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE)) from Foam.OpenFOAM import dimensionedVector, vector Ubar = dimensionedVector(transportProperties.lookup(word("Ubar"))) flowDirection = (Ubar / Ubar.mag()).ext_value() flowMask = flowDirection.sqr() nWallFaces = 0.0 from Foam.OpenFOAM import vector wallNormal = vector.zero patches = mesh.boundary() for patchi in range(mesh.boundary().size()): currPatch = patches[patchi] from Foam.finiteVolume import wallFvPatch if wallFvPatch.ext_isA(currPatch): for facei in range(currPatch.size()): nWallFaces = nWallFaces + 1 if nWallFaces == 1: wallNormal = -mesh.Sf().ext_boundaryField( )[patchi][facei] / mesh.magSf().ext_boundaryField( )[patchi][facei] pass elif nWallFaces == 2: wallNormal2 = mesh.Sf().ext_boundaryField( )[patchi][facei] / mesh.magSf().ext_boundaryField( )[patchi][facei] #- Check that wall faces are parallel from Foam.OpenFOAM import mag if mag(wallNormal & wallNormal2) > 1.01 or mag(wallNormal & wallNormal2) < 0.99: ext_Info( ) << "boundaryFoam: wall faces are not parallel" << nl import os os.abort() pass pass else: ext_Info( ) << "boundaryFoam: number of wall faces > 2" << nl import os os.abort() pass pass pass #- create position array for graph generation y = wallNormal & mesh.C().internalField() from Foam.OpenFOAM import dimensionSet, vector, word gradP = dimensionedVector(word("gradP"), dimensionSet(0.0, 1.0, -2.0, 0.0, 0.0), vector(0.0, 0.0, 0.0)) return U, phi, laminarTransport, turbulence, Ubar, wallNormal, flowDirection, flowMask, y, gradP
def createFluidFields( fluidRegions, runTime ) : # Load boundary conditions from .. import derivedFvPatchFields # Initialise fluid field pointer lists from Foam.finiteVolume import PtrList_volScalarField rhoFluid = PtrList_volScalarField( fluidRegions.size() ) KFluid = PtrList_volScalarField( fluidRegions.size() ) from Foam.finiteVolume import PtrList_volVectorField UFluid = PtrList_volVectorField( fluidRegions.size() ) from Foam.finiteVolume import PtrList_surfaceScalarField phiFluid = PtrList_surfaceScalarField( fluidRegions.size() ) DpDtFluid = PtrList_volScalarField( fluidRegions.size() ) from Foam.OpenFOAM import PtrList_uniformDimensionedVectorField gFluid = PtrList_uniformDimensionedVectorField( fluidRegions.size() ) from Foam.compressible import PtrList_compressible_turbulenceModel turbulence = PtrList_compressible_turbulenceModel( fluidRegions.size() ) from Foam.thermophysicalModels import PtrList_basicRhoThermo thermoFluid = PtrList_basicRhoThermo( fluidRegions.size() ) p_rghFluid = PtrList_volScalarField( fluidRegions.size() ) ghFluid = PtrList_volScalarField( fluidRegions.size() ) ghfFluid = PtrList_surfaceScalarField(fluidRegions.size()) from Foam.OpenFOAM import scalarList initialMassFluid = scalarList( fluidRegions.size() ) #Populate fluid field pointer lists for index in range( fluidRegions.size() ) : from Foam.OpenFOAM import ext_Info, nl ext_Info() << "*** Reading fluid mesh thermophysical properties for region " \ << fluidRegions[ index ].name() << nl << nl ext_Info()<< " Adding to thermoFluid\n" << nl from Foam.thermophysicalModels import autoPtr_basicRhoThermo, basicRhoThermo thermo= basicRhoThermo.New( fluidRegions[ index ] ) thermoFluid.ext_set( index, thermo ) ext_Info()<< " Adding to rhoFluid\n" << nl from Foam.OpenFOAM import word, fileName, IOobject from Foam.finiteVolume import volScalarField rhoFluid.ext_set( index, volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), fluidRegions[ index ], IOobject.NO_READ, IOobject.AUTO_WRITE ), thermoFluid[ index ].rho() ) ) ext_Info()<< " Adding to KFluid\n" << nl KFluid.ext_set( index, volScalarField( IOobject( word( "K" ), fileName( runTime.timeName() ), fluidRegions[ index ], IOobject.NO_READ, IOobject.NO_WRITE ), thermoFluid[ index ].Cp().ptr() * thermoFluid[ index ].alpha() ) ) ext_Info()<< " Adding to UFluid\n" << nl from Foam.finiteVolume import volVectorField UFluid.ext_set( index, volVectorField( IOobject( word( "U" ), fileName( runTime.timeName() ), fluidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), fluidRegions[ index ] ) ) ext_Info()<< " Adding to phiFluid\n" << nl from Foam.finiteVolume import surfaceScalarField from Foam.finiteVolume import linearInterpolate phiFluid.ext_set( index, surfaceScalarField( IOobject( word( "phi" ), fileName( runTime.timeName() ), fluidRegions[ index ], IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), linearInterpolate( rhoFluid[ index ] * UFluid[ index ] ) & fluidRegions[ index ].Sf() ) ) ext_Info()<< " Adding to gFluid\n" << nl from Foam.OpenFOAM import uniformDimensionedVectorField gFluid.ext_set( index, uniformDimensionedVectorField( IOobject( word( "g" ), fileName( runTime.constant() ), fluidRegions[ index ], IOobject.MUST_READ, IOobject.NO_WRITE ) ) ) ext_Info()<< " Adding to turbulence\n" << nl from Foam import compressible turbulence.ext_set( index, compressible.turbulenceModel.New( rhoFluid[ index ], UFluid[ index ], phiFluid[ index ], thermoFluid[ index ] ) ) ext_Info() << " Adding to ghFluid\n" << nl ghFluid.ext_set( index, volScalarField( word( "gh" ) , gFluid[ index ] & fluidRegions[ index ].C() ) ) ext_Info() << " Adding to ghfFluid\n" << nl ghfFluid.ext_set( index, surfaceScalarField( word( "ghf" ), gFluid[ index ] & fluidRegions[ index ].Cf() ) ) p_rghFluid.ext_set( index, volScalarField( IOobject( word( "p_rgh" ), fileName( runTime.timeName() ), fluidRegions[ index ], IOobject.MUST_READ, IOobject.AUTO_WRITE ), fluidRegions[ index ] ) ) # Force p_rgh to be consistent with p p_rghFluid[ index ].ext_assign( thermoFluid[ index ].p() - rhoFluid[ index ] * ghFluid[ index ] ) from Foam import fvc initialMassFluid[ index ] = fvc.domainIntegrate( rhoFluid[ index ] ).value() ext_Info()<< " Adding to DpDtFluid\n" << nl DpDtFluid.ext_set( index, volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), phiFluid[ index ] / fvc.interpolate( rhoFluid[ index ] ) ), thermoFluid[ index ].p() ) ) ) return thermoFluid, rhoFluid, KFluid, UFluid, phiFluid, gFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid
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 ) thermodynamicProperties, R, Cv = readThermodynamicProperties( runTime, mesh ) p, T, U, psi, rho, rhoU, rhoE = _createFields( runTime, mesh, R, Cv ) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "\nStarting time loop\n" << nl while runTime.loop() : ext_Info() << "Time = " << runTime.timeName() << nl << nl from Foam.finiteVolume import surfaceScalarField from Foam.OpenFOAM import IOobject, word, fileName from Foam import fvc phiv = surfaceScalarField( IOobject( word( "phiv" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() ) CoNum = ( mesh.deltaCoeffs() * phiv.mag() / mesh.magSf() ).ext_max().value()*runTime.deltaT().value(); ext_Info() << "\nMax Courant Number = " << CoNum << nl from Foam import fvm from Foam.finiteVolume import solve solve( fvm.ddt(rho) + fvm.div( phiv, rho ) ) p.ext_assign( rho / psi ) solve( fvm.ddt( rhoU ) + fvm.div( phiv, rhoU ) == - fvc.grad( p ) ) U == rhoU / rho phiv2 = surfaceScalarField( IOobject( word( "phiv2" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() ) solve( fvm.ddt( rhoE ) + fvm.div( phiv, rhoE ) == - fvc.div( phiv2, p ) ) T.ext_assign( ( rhoE - 0.5 * rho * ( rhoU / rho ).magSqr() ) / Cv / rho ) psi.ext_assign( 1.0 / ( R * T ) ) runTime.write() ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \ " ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl pass ext_Info() << "End\n" import os return os.EX_OK
def pEqn( runTime, mesh, p, phi, psi, U, UEqn, g, rho, thermo, initialMass, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): rho.ext_assign( thermo.rho() ) from Foam import fvc 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() ) UEqn.clear(); phi.ext_assign( fvc.interpolate( rho ) * ( fvc.interpolate( U ) & mesh.Sf() ) ) from Foam.finiteVolume import adjustPhi closedVolume = adjustPhi( phi, U, p ) buoyancyPhi = rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() ) phi.ext_assign( phi + buoyancyPhi ) from Foam import fvm for nonOrth in range( nNonOrthCorr + 1): pEqn = fvm.laplacian( rhorUAf, p ) == fvc.div( phi ) pEqn.setReference( pRefCell, pRefValue ) # retain the residual from the first iteration if nonOrth == 0: eqnResidual = pEqn.solve().initialResidual() maxResidual = max(eqnResidual, maxResidual) pass else: pEqn.solve() pass if nonOrth == nNonOrthCorr: # 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 ) ) pass # Calculate the conservative fluxes phi.ext_assign( phi - pEqn.flux() ) # Explicitly relax pressure for momentum corrector p.relax() # Correct the momentum source with the pressure gradient flux # calculated from the relaxed pressure U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rhorUAf ) ) U.correctBoundaryConditions() pass from Foam.finiteVolume.cfdTools.incompressible import continuityErrs cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr ) 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 return eqnResidual, maxResidual, cumulativeContErr
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 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) 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 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 createFluidFields(fluidRegions, runTime): # Load boundary conditions from .. import derivedFvPatchFields # Initialise fluid field pointer lists from Foam.finiteVolume import PtrList_volScalarField rhoFluid = PtrList_volScalarField(fluidRegions.size()) KFluid = PtrList_volScalarField(fluidRegions.size()) from Foam.finiteVolume import PtrList_volVectorField UFluid = PtrList_volVectorField(fluidRegions.size()) from Foam.finiteVolume import PtrList_surfaceScalarField phiFluid = PtrList_surfaceScalarField(fluidRegions.size()) DpDtFluid = PtrList_volScalarField(fluidRegions.size()) from Foam.OpenFOAM import PtrList_uniformDimensionedVectorField gFluid = PtrList_uniformDimensionedVectorField(fluidRegions.size()) from Foam.compressible import PtrList_compressible_turbulenceModel turbulence = PtrList_compressible_turbulenceModel(fluidRegions.size()) from Foam.thermophysicalModels import PtrList_basicPsiThermo thermoFluid = PtrList_basicPsiThermo(fluidRegions.size()) p_rghFluid = PtrList_volScalarField(fluidRegions.size()) ghFluid = PtrList_volScalarField(fluidRegions.size()) ghfFluid = PtrList_surfaceScalarField(fluidRegions.size()) from Foam.OpenFOAM import scalarList initialMassFluid = scalarList(fluidRegions.size()) #Populate fluid field pointer lists for index in range(fluidRegions.size()): from Foam.OpenFOAM import ext_Info, nl ext_Info() << "*** Reading fluid mesh thermophysical properties for region " \ << fluidRegions[ index ].name() << nl << nl ext_Info() << " Adding to thermoFluid\n" << nl from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo thermo = basicPsiThermo.New(fluidRegions[index]) thermoFluid.ext_set(index, thermo) ext_Info() << " Adding to rhoFluid\n" << nl from Foam.OpenFOAM import word, fileName, IOobject from Foam.finiteVolume import volScalarField rhoFluid.ext_set( index, volScalarField( IOobject(word("rho"), fileName(runTime.timeName()), fluidRegions[index], IOobject.NO_READ, IOobject.AUTO_WRITE), thermoFluid[index].rho())) ext_Info() << " Adding to KFluid\n" << nl KFluid.ext_set( index, volScalarField( IOobject(word("K"), fileName(runTime.timeName()), fluidRegions[index], IOobject.NO_READ, IOobject.NO_WRITE), thermoFluid[index].Cp().ptr() * thermoFluid[index].alpha())) ext_Info() << " Adding to UFluid\n" << nl from Foam.finiteVolume import volVectorField UFluid.ext_set( index, volVectorField( IOobject(word("U"), fileName(runTime.timeName()), fluidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), fluidRegions[index])) ext_Info() << " Adding to phiFluid\n" << nl from Foam.finiteVolume import surfaceScalarField from Foam.finiteVolume import linearInterpolate phiFluid.ext_set( index, surfaceScalarField( IOobject(word("phi"), fileName(runTime.timeName()), fluidRegions[index], IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), linearInterpolate(rhoFluid[index] * UFluid[index]) & fluidRegions[index].Sf())) ext_Info() << " Adding to gFluid\n" << nl from Foam.OpenFOAM import uniformDimensionedVectorField gFluid.ext_set( index, uniformDimensionedVectorField( IOobject(word("g"), fileName(runTime.constant()), fluidRegions[index], IOobject.MUST_READ, IOobject.NO_WRITE))) ext_Info() << " Adding to turbulence\n" << nl from Foam import compressible turbulence.ext_set( index, compressible.turbulenceModel.New(rhoFluid[index], UFluid[index], phiFluid[index], thermoFluid[index])) ext_Info() << " Adding to ghFluid\n" << nl ghFluid.ext_set( index, volScalarField(word("gh"), gFluid[index] & fluidRegions[index].C())) ext_Info() << " Adding to ghfFluid\n" << nl ghfFluid.ext_set( index, surfaceScalarField(word("ghf"), gFluid[index] & fluidRegions[index].Cf())) p_rghFluid.ext_set( index, volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), fluidRegions[index], IOobject.MUST_READ, IOobject.AUTO_WRITE), fluidRegions[index])) # Force p_rgh to be consistent with p p_rghFluid[index].ext_assign(thermoFluid[index].p() - rhoFluid[index] * ghFluid[index]) from Foam import fvc initialMassFluid[index] = fvc.domainIntegrate(rhoFluid[index]).value() ext_Info() << " Adding to DpDtFluid\n" << nl DpDtFluid.ext_set( index, volScalarField( word("DpDt"), fvc.DDt( surfaceScalarField( word("phiU"), phiFluid[index] / fvc.interpolate(rhoFluid[index])), thermoFluid[index].p()))) return thermoFluid, rhoFluid, KFluid, UFluid, phiFluid, gFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid