示例#1
0
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
示例#2
0
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
示例#3
0
def _pEqn( mesh, rho, thermo, p, U, trTU, trAU, UEqn, phi, \
           runTime, pMin, pressureImplicitPorosity, nNonOrthCorr, eqnResidual, maxResidual, cumulativeContErr, initialMass, pRefCell, pRefValue ):

    if pressureImplicitPorosity:
        U.ext_assign(trTU & UEqn.H())
    else:
        U.ext_assign(trAU * UEqn.H())
        pass

    UEqn.clear()

    from Foam import fvc, fvm
    phi.ext_assign(fvc.interpolate(rho * U) & mesh.Sf())

    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi(phi, U, p)

    for nonOrth in range(nNonOrthCorr + 1):
        tpEqn = None
        if pressureImplicitPorosity:
            tpEqn = (fvm.laplacian(rho * trTU, p) == fvc.div(phi))
        else:
            tpEqn = (fvm.laplacian(rho * trAU, p) == fvc.div(phi))
            pass

        tpEqn.setReference(pRefCell, pRefValue)
        # retain the residual from the first iteration
        if nonOrth == 0:
            eqnResidual = tpEqn.solve().initialResidual()
            maxResidual = max(eqnResidual, maxResidual)
        else:
            tpEqn.solve()
            pass

        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - tpEqn.flux())
            pass

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr)

    # Explicitly relax pressure for momentum corrector
    p.relax()

    if pressureImplicitPorosity:
        U.ext_assign(U - (trTU & fvc.grad(p)))
    else:
        U.ext_assign(U - (trAU * fvc.grad(p)))
        pass

    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound
    bound(p, pMin)

    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
        p.ext_assign(p +
                     (initialMass - fvc.domainIntegrate(thermo.psi() * p)) /
                     fvc.domainIntegrate(thermo.psi()))
        pass

    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
示例#4
0
def _pEqn(
    mesh,
    rho,
    thermo,
    p,
    U,
    trTU,
    trAU,
    UEqn,
    phi,
    runTime,
    pMin,
    pressureImplicitPorousity,
    nNonOrthCorr,
    eqnResidual,
    maxResidual,
    cumulativeContErr,
    initialMass,
    pRefCell,
    pRefValue,
):

    if pressureImplicitPorousity:
        U.ext_assign(trTU & UEqn.H())
    else:
        U.ext_assign(trAU * UEqn.H())
        pass

    UEqn.clear()

    from Foam import fvc, fvm

    phi.ext_assign(fvc.interpolate(rho * U) & mesh.Sf())

    from Foam.finiteVolume import adjustPhi

    closedVolume = adjustPhi(phi, U, p)

    for nonOrth in range(nNonOrthCorr + 1):
        tpEqn = None
        if pressureImplicitPorosity:
            tpEqn = fvm.laplacian(rho * trTU, p) == fvc.div(phi)
        else:
            tpEqn = fvm.laplacian(rho * trAU, p) == fvc.div(phi)
            pass

        tpEqn.setReference(pRefCell, pRefValue)
        # retain the residual from the first iteration
        tpEqn.solve()

        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - tpEqn.flux())
            pass

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

    cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr)

    # Explicitly relax pressure for momentum corrector
    p.relax()

    if pressureImplicitPorousity:
        U.ext_assign(U - (trTU & fvc.grad(p)))
    else:
        U.ext_assign(U - (trAU * fvc.grad(p)))
        pass

    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound

    bound(p, pMin)

    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
        p.ext_assign(p + (initialMass - fvc.domainIntegrate(thermo.psi() * p)) / fvc.domainIntegrate(thermo.psi()))
        pass

    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
示例#5
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign( thermo.rho() )

    rUA = 1.0 / UEqn.A()
    U.ext_assign( rUA * UEqn.H() )
    UEqn.clear()
    
    closedVolume = False
    
    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() ) )


       for nonOrth in range( nNonOrthCorr + 1 ) :
           pEqn = fvm.div( phid, p ) - fvm.laplacian( rho * rUA, p )
           
           # Relax the pressure equation to ensure diagonal-dominance
           pEqn.relax( mesh.relaxationFactor( word( "pEqn" ) ) )

           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:
              phi == pEqn.flux()
              pass
           pass
       
       pass
       
    else:
       phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate(U) & mesh.Sf() ) ) )
       
       from Foam.finiteVolume import adjustPhi
       closedVolume = adjustPhi( phi, U, p )
       
       
       for nonOrth in range( nNonOrthCorr + 1 ) :
           # Pressure corrector
           pEqn = fvm.laplacian( rho * rUA, 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:
              phi.ext_assign( phi - pEqn.flux() )
              pass
           pass
       pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, 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 bound
    bound(p, pMin);
        
    # 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
    
    return eqnResidual, maxResidual, cumulativeContErr
示例#6
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign(thermo.rho())

    rUA = 1.0 / UEqn.A()
    U.ext_assign(rUA * UEqn.H())
    UEqn.clear()

    closedVolume = False

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

        for nonOrth in range(nNonOrthCorr + 1):
            pEqn = fvm.div(phid, p) - fvm.laplacian(rho * rUA, p)

            # Relax the pressure equation to ensure diagonal-dominance
            pEqn.relax(mesh.relaxationFactor(word("pEqn")))

            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:
                phi == pEqn.flux()
                pass
            pass

        pass

    else:
        phi.ext_assign(
            fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf())))

        from Foam.finiteVolume import adjustPhi
        closedVolume = adjustPhi(phi, U, p)

        for nonOrth in range(nNonOrthCorr + 1):
            # Pressure corrector
            pEqn = fvm.laplacian(rho * rUA, 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:
                phi.ext_assign(phi - pEqn.flux())
                pass
            pass
        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs(mesh, phi, runTime, 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 bound
    bound(p, pMin)

    # 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

    return eqnResidual, maxResidual, cumulativeContErr