Example #1
0
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
Example #2
0
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
Example #3
0
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()
    
    from Foam import fvc
    compressibility = fvc.domainIntegrate( psi )
    
    from Foam.OpenFOAM import SMALL
    compressible = ( compressibility.value() > SMALL )

    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
    
    from Foam.finiteVolume import correction
    p_rghDDtEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p_rgh ) ) + fvc.div( phi )
    
    # 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 )

    for nonOrth in range ( nNonOrthCorr + 1 ):
        p_rghEqn = p_rghDDtEqn - 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
    
    # Second part of thermodynamic density update
    thermo.rho().ext_assign( thermo.rho() + psi * p_rgh )
    
    # 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 and compressible:
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( thermo.rho() ) ) / compressibility )
       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
Example #4
0
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
Example #5
0
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
Example #6
0
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()

    from Foam import fvc
    compressibility = fvc.domainIntegrate(psi)

    from Foam.OpenFOAM import SMALL
    compressible = (compressibility.value() > SMALL)

    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

    from Foam.finiteVolume import correction
    p_rghDDtEqn = fvc.ddt(rho) + psi * correction(
        fvm.ddt(p_rgh)) + fvc.div(phi)

    # 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)

    for nonOrth in range(nNonOrthCorr + 1):
        p_rghEqn = p_rghDDtEqn - 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

    # Second part of thermodynamic density update
    thermo.rho().ext_assign(thermo.rho() + psi * p_rgh)

    # 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 and compressible:
        p.ext_assign(p + (initialMass - fvc.domainIntegrate(thermo.rho())) /
                     compressibility)
        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