def alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr ): from Foam.OpenFOAM import word alphaScheme = word( "div(phi,alpha)" ) alpharScheme = word( "div(phirb,alpha)" ) phir = phic*interface.nHatf() from Foam.finiteVolume import volScalarField from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar, scalar, ext_Info, nl for gCorr in range( nAlphaCorr ): Sp = volScalarField.DimensionedInternalField( IOobject( word( "Sp" ), fileName( runTime.timeName() ), mesh ), mesh, dimensionedScalar( word( "Sp" ), dgdt.dimensions(), 0.0 ) ) Su = volScalarField.DimensionedInternalField( IOobject( word( "Su" ), fileName( runTime.timeName() ), mesh ), # Divergence term is handled explicitly to be # consistent with the explicit transport solution divU * alpha1.ext_min( scalar( 1 ) ) ) for celli in range( dgdt.size() ): if dgdt[ celli ] > 0.0 and alpha1[ celli ] > 0.0: Sp[ celli ] -= dgdt[ celli ] * alpha1[ celli ] Su[ celli ] += dgdt[ celli ] * alpha1[ celli ] pass elif dgdt[ celli ] < 0.0 and alpha1[ celli ] < 1.0: Sp[ celli ] += dgdt[ celli ] * ( 1.0 - alpha1[ celli ] ) pass pass from Foam import fvc phiAlpha1 = fvc.flux( phi, alpha1, alphaScheme ) + fvc.flux( - fvc.flux( -phir, alpha2, alpharScheme ), alpha1, alpharScheme ) from Foam import MULES from Foam.OpenFOAM import geometricOneField MULES.explicitSolve( geometricOneField(), alpha1, phi, phiAlpha1, Sp, Su, 1.0, 0.0 ) rho1f = fvc.interpolate( rho1 ) rho2f = fvc.interpolate( rho2 ) rhoPhi.ext_assign( phiAlpha1 * ( rho1f - rho2f ) + phi * rho2f ) alpha2.ext_assign( scalar( 1 ) - alpha1 ) 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() << " Min(alpha2) = " << alpha2.ext_min().value() << nl pass
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 alphaEqn(mesh, phi, alpha1, alphatab, Dab, rhoPhi, rho, rho1, rho2, turbulence): from Foam import fvm from Foam.OpenFOAM import word alpha1Eqn = ( fvm.ddt(alpha1) + fvm.div(phi, alpha1) - fvm.laplacian(Dab + alphatab * turbulence.ext_nut(), alpha1, word("laplacian(Dab,alpha1)")) ) alpha1Eqn.solve() rhoPhi.ext_assign(alpha1Eqn.flux() * (rho1 - rho2) + phi * rho2) from Foam.OpenFOAM import scalar rho.ext_assign(alpha1 * rho1 + (scalar(1) - alpha1) * rho2) from Foam.OpenFOAM import ext_Info, nl ext_Info() << "Phase 1 volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() << " Min(alpha1) = " << alpha1.ext_min().value() << " Max(alpha1) = " << alpha1.ext_max().value() << nl pass
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 field p_rgh\n" << nl p_rgh = volScalarField( IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh ) ext_Info() << "Reading field alpha1\n" << nl alpha1 = volScalarField( IOobject(word("alpha1"), 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) ext_Info() << "Reading transportProperties\n" << nl from Foam.transportModels import twoPhaseMixture twoPhaseProperties = twoPhaseMixture(U, phi) rho1 = twoPhaseProperties.rho1() rho2 = twoPhaseProperties.rho2() from Foam.OpenFOAM import dimensionedScalar Dab = dimensionedScalar(twoPhaseProperties.lookup(word("Dab"))) # Read the reciprocal of the turbulent Schmidt number alphatab = dimensionedScalar(twoPhaseProperties.lookup(word("alphatab"))) # Need to store rho for ddt(rho, U) from Foam.OpenFOAM import scalar rho = volScalarField(word("rho"), alpha1 * rho1 + (scalar(1) - alpha1) * rho2) rho.oldTime() # Mass flux # Initialisation does not matter because rhoPhi is reset after the # alpha1 solution before it is used in the U equation. from Foam.finiteVolume import surfaceScalarField rhoPhi = surfaceScalarField( IOobject(word("rho*phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho1 * phi ) # Construct incompressible turbulence model from Foam import incompressible turbulence = incompressible.turbulenceModel.New(U, phi, twoPhaseProperties) ext_Info() << "Calculating field g.h\n" << nl gh = volScalarField(word("gh"), g & mesh.C()) ghf = surfaceScalarField(word("ghf"), g & mesh.Cf()) p = volScalarField( IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), p_rgh + rho * gh ) pRefCell = 0 pRefValue = 0.0 from Foam.finiteVolume import setRefCell, getRefCellValue pRefCell, pRefValue = setRefCell(p, p_rgh, mesh.solutionDict().subDict(word("PIMPLE")), pRefCell, pRefValue) if p_rgh.needReference(): p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell))) p_rgh.ext_assign(p - rho * gh) pass return ( p_rgh, alpha1, U, phi, twoPhaseProperties, rho1, rho2, Dab, alphatab, rho, rhoPhi, turbulence, gh, ghf, p, pRefCell, pRefValue, )
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 field p_rgh\n" << nl p_rgh = volScalarField( IOobject( word( "p_rgh" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Reading field alpha1\n" << nl alpha1 = volScalarField( IOobject( word( "alpha1" ), fileName( runTime.timeName() ), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE ), mesh ) ext_Info() << "Calculating field alpha1\n" << nl from Foam.OpenFOAM import scalar alpha2 = volScalarField( word( "alpha2" ), scalar( 1 ) - alpha1 ) 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 ) ext_Info() << "Reading transportProperties\n" << nl from Foam.transportModels import twoPhaseMixture twoPhaseProperties = twoPhaseMixture (U, phi) from Foam.OpenFOAM import dimensionedScalar rho10 = dimensionedScalar( twoPhaseProperties.subDict( twoPhaseProperties.phase1Name() ).lookup( word( "rho0" ) ) ) rho20 = dimensionedScalar( twoPhaseProperties.subDict( twoPhaseProperties.phase2Name() ).lookup( word( "rho0" ) ) ) psi1 = dimensionedScalar( twoPhaseProperties.subDict( twoPhaseProperties.phase1Name() ).lookup( word( "psi" ) ) ) psi2 = dimensionedScalar( twoPhaseProperties.subDict( twoPhaseProperties.phase2Name() ).lookup( word( "psi" ) ) ) pMin = dimensionedScalar( twoPhaseProperties.lookup( word( "pMin" ) ) ) 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() ) p = volScalarField( IOobject( word( "p" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE ), ( ( p_rgh + gh * ( alpha1 * rho10 + alpha2 * rho20 ) ) / ( 1.0 - gh * ( alpha1 * psi1 + alpha2 * psi2 ) ) ).ext_max( pMin ) ) rho1 = rho10 + psi1 * p rho2 = rho20 + psi2 * p rho = volScalarField( IOobject( word( "rho" ), fileName( runTime.timeName() ), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE ), alpha1 * rho1 + alpha2 * rho2 ) # Mass flux # Initialisation does not matter because rhoPhi is reset after the # alpha1 solution before it is used in the U equation. from Foam import fvc rhoPhi = surfaceScalarField( IOobject( word( "rho*phi" ), fileName( runTime.timeName() ), mesh, IOobject.NO_READ, IOobject.NO_WRITE ), fvc.interpolate( rho ) * phi ) dgdt = alpha2.pos() * fvc.div( phi ) / alpha2.ext_max( scalar( 0.0001 ) ) # Construct interface from alpha1 distribution from Foam.transportModels import interfaceProperties interface = interfaceProperties( alpha1, U, twoPhaseProperties ) # Construct incompressible turbulence model from Foam import incompressible turbulence = incompressible.turbulenceModel.New( U, phi, twoPhaseProperties ) return p_rgh, alpha1, alpha2, U, phi, twoPhaseProperties, rho10, rho20, psi1, psi2, pMin, \ gh, ghf, p, rho1, rho2, rho, rhoPhi, dgdt, interface, turbulence