Esempio n. 1
0
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
Esempio n. 2
0
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 fun_UEqn( phi, U, p_rgh, turbulence, mesh, ghf, rhok, eqnResidual, maxResidual, momentumPredictor ):
    from Foam import fvm, fvc
    UEqn = fvm.div( phi, U ) + turbulence.divDevReff( U ) 
    UEqn.relax()
    
    if momentumPredictor:
       from Foam.finiteVolume import solve
       eqnResidual = solve( UEqn == fvc.reconstruct( ( - ghf * fvc.snGrad( rhok ) - fvc.snGrad( p_rgh ) )* mesh.magSf() ) ).initialResidual()
       maxResidual = max(eqnResidual, maxResidual)
       pass
       
    return UEqn, eqnResidual, maxResidual
def fun_UEqn( turbulence, phi, U, rho, g, p, ghf, p_rgh, mesh, eqnResidual, maxResidual, momentumPredictor ):
    from Foam import fvm, fvc 
    UEqn = fvm.div(phi, U) + turbulence.divDevRhoReff(U)

    UEqn.relax()
    if momentumPredictor:
       from Foam.finiteVolume import solve
       eqnResidual = solve( UEqn == fvc.reconstruct( (- ghf * fvc.snGrad( rho ) - fvc.snGrad( p_rgh ) ) * mesh.magSf() ) ).initialResidual()

       maxResidual = max(eqnResidual, maxResidual)
       pass
    
    return UEqn, eqnResidual, maxResidual
Esempio n. 5
0
def fun_UEqn( mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter, momentumPredictor ):
    
    from Foam import fvm, fvc    
    # Solve the Momentum equation
    UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )

    UEqn.relax()

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

    return UEqn
Esempio n. 6
0
def fun_UEqn( rho, U, phi, ghf, p_rgh, turb, mesh, momentumPredictor ) :
    # Solve the Momentum equation
    from Foam import fvm
    UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turb.divDevRhoReff( U )

    UEqn.relax()
    
    if momentumPredictor :
        from Foam import fvc
        from Foam.finiteVolume import solve
        solve( UEqn == fvc.reconstruct( ( -ghf * fvc.snGrad( rho ) - fvc.snGrad( p_rgh ) )*mesh.magSf() ) )
        pass
    
    return UEqn
Esempio n. 7
0
def fun_UEqn(rho, U, phi, ghf, p_rgh, turb, mesh, momentumPredictor):
    # Solve the Momentum equation
    from Foam import fvm
    UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) + turb.divDevRhoReff(U)

    UEqn.relax()

    if momentumPredictor:
        from Foam import fvc
        from Foam.finiteVolume import solve
        solve(UEqn == fvc.reconstruct((-ghf * fvc.snGrad(rho) -
                                       fvc.snGrad(p_rgh)) * mesh.magSf()))
        pass

    return UEqn
def fun_pEqn( runTime, thermo, UEqn, U, phi, rho, gh, pd, p, initialMass, mesh, pRef, nNonOrthCorr, \
              pdRefCell, pdRefValue, eqnResidual, maxResidual, cumulativeContErr ):
    
    rUA = 1.0/UEqn.A()
    U.ext_assign( rUA * UEqn().H() )
    
    UEqn.clear()
    from Foam import fvc
    phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) )
    
    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi(phi, U, p)
    
    phi.ext_assign( phi - fvc.interpolate( rho *gh * rUA ) * fvc.snGrad( rho ) * mesh.magSf() )
    
    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1):
        pdEqn = ( fvm.laplacian( rho * rUA, pd ) == fvc.div(phi) )
        
        pdEqn.setReference(pdRefCell, pdRefValue)
        # retain the residual from the first iteration    
        
        if nonOrth == 0:
           eqnResidual = pdEqn.solve().initialResidual()
           maxResidual = max(eqnResidual, maxResidual)
           pass
        else:
           pdEqn.solve()
           pass
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pdEqn.flux() )
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    pd.relax()
    
    p.ext_assign( pd + rho * gh + pRef )
    
    U.ext_assign( U- rUA * ( fvc.grad( pd ) + fvc.grad( rho ) * gh ) )
    U.correctBoundaryConditions()
    
    # 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() ) )
    
    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
Esempio n. 9
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()

    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
Esempio n. 10
0
def fun_UEqn(mesh, rho, phi, U, p_rgh, ghf, turbulence, finalIter,
             momentumPredictor):

    from Foam import fvm, fvc
    # Solve the Momentum equation
    UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) + turbulence.divDevRhoReff(U)

    UEqn.relax()

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

    return UEqn
Esempio n. 11
0
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
Esempio n. 12
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
Esempio n. 13
0
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
Esempio n. 14
0
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 fun_UEqn(phi, U, p, turbulence, mesh, g, rhok, eqnResidual, maxResidual):
    from Foam import fvm, fvc
    UEqn = fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U) + turbulence.divDevReff(U)
    UEqn.relax()

    from Foam.finiteVolume import solve
    eqnResidual = solve(UEqn == fvc.reconstruct((
        fvc.interpolate(rhok) * (g & mesh.Sf()) -
        fvc.snGrad(p) * mesh.magSf()))).initialResidual()

    maxResidual = max(eqnResidual, maxResidual)

    return UEqn, eqnResidual, maxResidual
Esempio n. 16
0
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
Esempio n. 17
0
def _Ueqn( U, phi, turbulence, p, rho, g, mesh, momentumPredictor ):
    from Foam import fvm
    # Solve the momentum equation

    UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )
    
    
    UEqn.relax()

    from Foam.finiteVolume import solve
    from Foam import fvc
    if momentumPredictor:
       solve( UEqn == fvc.reconstruct( fvc.interpolate( rho ) * ( g & mesh.Sf() ) - fvc.snGrad( p ) * mesh.magSf() ) )
       pass
       
    return UEqn
def _Ueqn(U, phi, turbulence, p, rhok, g, mesh, momentumPredictor):
    from Foam import fvm
    # Solve the momentum equation

    UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U)

    UEqn.relax()

    from Foam.finiteVolume import solve
    from Foam import fvc
    if momentumPredictor:
        solve(UEqn == fvc.reconstruct((fvc.interpolate(rhok) *
                                       (g & mesh.Sf()) -
                                       fvc.snGrad(p) * mesh.magSf())))

    return UEqn
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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
Esempio n. 23
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()

    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 fun_pEqn(
    runTime,
    mesh,
    p,
    p_rgh,
    phi,
    U,
    UEqn,
    ghf,
    gh,
    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_rgh)

    buoyancyPhi = rUAf * ghf * fvc.snGrad(rhok) * mesh.magSf()

    phi.ext_assign(phi - buoyancyPhi)

    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm, fvc

        p_rghEqn = fvm.laplacian(rUAf, p_rgh) == fvc.div(phi)

        from Foam.finiteVolume import getRefCellValue

        p_rghEqn.setReference(pRefCell, getRefCellValue(p_rgh, pRefCell))

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

        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()) / rUAf))
            U.correctBoundaryConditions()
            pass

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    p.ext_assign(p_rgh + rhok * gh)

    if p_rgh.needReference():
        from Foam.OpenFOAM import dimensionedScalar

        p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell)))
        p_rgh.ext_assign(p - rhok * gh)
        pass

    return eqnResidual, maxResidual, cumulativeContErr
Esempio n. 25
0
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
Esempio n. 26
0
def fun_pEqn(thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass,
             runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual,
             cumulativeContErr):

    rho.ext_assign(thermo.rho())
    rho.relax()

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

    buoyancyPhi = surfaceScalarField(rhorUAf * ghf * fvc.snGrad(rho) *
                                     mesh.magSf())

    phi.ext_assign(phi - buoyancyPhi)

    for nonOrth in range(nNonOrthCorr + 1):
        from Foam import fvm
        p_rghEqn = fvm.laplacian(rhorUAf, p_rgh) == fvc.div(phi)

        from Foam.finiteVolume import getRefCellValue
        p_rghEqn.setReference(pRefCell, getRefCellValue(p_rgh, pRefCell))

        eqnResidual = p_rghEqn.solve().initialResidual()

        if (nonOrth == 0):
            maxResidual = max(eqnResidual, maxResidual)
            pass

        if (nonOrth == nNonOrthCorr):
            # Calculate the conservative fluxes
            phi.ext_assign(phi - p_rghEqn.flux())
            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()
            U.ext_assign(U - rUA * fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rhorUAf))
            U.correctBoundaryConditions()
            pass

    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr)

    p.ext_assign(p_rgh + rho * gh)

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume:
        p.ext_assign(p + (initialMass - fvc.domainIntegrate(psi * p)) /
                     fvc.domainIntegrate(psi))
        p_rgh.ext_assign(p - rho * gh)

    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( thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ):

    rho.ext_assign( thermo.rho() )
    rho.relax()

    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_rgh );

    buoyancyPhi =surfaceScalarField( rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() )
    
    phi.ext_assign( phi - buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        from Foam import fvm
        p_rghEqn = fvm.laplacian(rhorUAf, p_rgh) == fvc.div(phi)
        
        from Foam.finiteVolume import getRefCellValue
        p_rghEqn.setReference(pRefCell, getRefCellValue( p_rgh, pRefCell ) )

        eqnResidual = p_rghEqn.solve().initialResidual()
        
        if (nonOrth == 0):
            maxResidual = max(eqnResidual, maxResidual)
            pass

        if (nonOrth == nNonOrthCorr):
           # Calculate the conservative fluxes
           phi.ext_assign( phi - p_rghEqn.flux() )
           # Explicitly relax pressure for momentum corrector
           p_rgh.relax()
           U.ext_assign( U - rUA * fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorUAf ) )
           U.correctBoundaryConditions()
           pass
    
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    p.ext_assign( p_rgh + rho * gh )

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + (initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       p_rgh.ext_assign( p - rho * gh )

    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
Esempio n. 28
0
def main_standalone(argc, argv):

    from Foam.OpenFOAM.include import setRootCase
    args = setRootCase(argc, argv)

    from Foam.OpenFOAM.include import createTime
    runTime = createTime(args)

    from Foam.OpenFOAM.include import createMesh
    mesh = createMesh(runTime)

    gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration(
        runTime, mesh)

    h, h0, U, hU, hTotal, phi, F = _createFields(runTime, mesh, Omega, gHat)

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl

    while runTime.loop():
        ext_Info() << "\nTime = " << runTime.timeName() << nl << nl

        from Foam.finiteVolume.cfdTools.general.include import readPISOControls
        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls(
            mesh)

        CoNum, meanCoNum, waveCoNum = CourantNo(runTime, mesh, h, phi, magg)

        for ucorr in range(nOuterCorr):
            from Foam.finiteVolume import surfaceScalarField
            from Foam import fvc
            from Foam.OpenFOAM import word

            phiv = surfaceScalarField(word("phiv"), phi / fvc.interpolate(h))

            from Foam import fvm
            hUEqn = fvm.ddt(hU) + fvm.div(phiv, hU)

            hUEqn.relax()

            if momentumPredictor:
                from Foam.finiteVolume import solve
                from Foam import fvc
                if rotating:
                    solve(hUEqn + (F ^ hU) == -magg * h * fvc.grad(h + h0))
                    pass
                else:
                    solve(hUEqn == -magg * h * fvc.grad(h + h0))
                    pass

                # Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU.ext_assign(hU - (gHat & hU) * gHat)
                    hU.correctBoundaryConditions()
                    pass

            for corr in range(nCorr):
                hf = fvc.interpolate(h)
                rUA = 1.0 / hUEqn.A()
                ghrUAf = magg * fvc.interpolate(h * rUA)

                phih0 = ghrUAf * mesh.magSf() * fvc.snGrad(h0)
                if rotating:
                    hU.ext_assign(rUA * (hUEqn.H() - (F ^ hU)))
                    pass
                else:
                    hU = rUA * hUEqn.H()
                    pass

                phi.ext_assign((fvc.interpolate(hU) & mesh.Sf()) +
                               fvc.ddtPhiCorr(rUA, h, hU, phi) - phih0)

                for nonOrth in range(nNonOrthCorr + 1):
                    hEqn = fvm.ddt(h) + fvc.div(phi) - fvm.laplacian(ghrUAf, h)

                    if ucorr < nOuterCorr - 1 or corr < nCorr - 1:
                        hEqn.solve()
                        pass
                    else:
                        hEqn.solve(mesh.solver(word(str(h.name()) + "Final")))
                        pass
                    if nonOrth == nNonOrthCorr:
                        phi.ext_assign(phi + hEqn.flux())
                    pass

                hU.ext_assign(hU - rUA * h * magg * fvc.grad(h + h0))

                #Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU.ext_assign(hU - (gHat & hU) * gHat)
                    pass

                hU.correctBoundaryConditions()
                pass
            pass

        U == hU / h
        hTotal == h + h0

        runTime.write()

        ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl

        pass

    ext_Info() << "End\n" << nl

    import os
    return os.EX_OK
Esempio n. 29
0
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, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid = _createFields(
        runTime, mesh)

    thermophysicalProperties, Pr = readThermophysicalProperties(runTime, mesh)

    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

    fluxScheme = readFluxScheme(mesh)

    from Foam.OpenFOAM import dimensionedScalar, dimVolume, dimTime, word
    v_zero = dimensionedScalar(word("v_zero"), dimVolume / dimTime, 0.0)

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl

    while runTime.run():
        # --- upwind interpolation of primitive fields on faces
        from Foam import fvc
        rho_pos = fvc.interpolate(rho, pos, word("reconstruct(rho)"))
        rho_neg = fvc.interpolate(rho, neg, word("reconstruct(rho)"))

        rhoU_pos = fvc.interpolate(rhoU, pos, word("reconstruct(U)"))
        rhoU_neg = fvc.interpolate(rhoU, neg, word("reconstruct(U)"))

        rPsi = 1.0 / psi
        rPsi_pos = fvc.interpolate(rPsi, pos, word("reconstruct(T)"))
        rPsi_neg = fvc.interpolate(rPsi, neg, word("reconstruct(T)"))

        e_pos = fvc.interpolate(e, pos, word("reconstruct(T)"))
        e_neg = fvc.interpolate(e, neg, word("reconstruct(T)"))

        U_pos = rhoU_pos / rho_pos
        U_neg = rhoU_neg / rho_neg

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

        phiv_pos = U_pos & mesh.Sf()
        phiv_neg = U_neg & mesh.Sf()

        c = (thermo.Cp() / thermo.Cv() * rPsi).sqrt()
        cSf_pos = fvc.interpolate(c, pos,
                                  word("reconstruct(T)")) * mesh.magSf()
        cSf_neg = fvc.interpolate(c, neg,
                                  word("reconstruct(T)")) * mesh.magSf()

        ap = (phiv_pos + cSf_pos).ext_max(phiv_neg + cSf_neg).ext_max(v_zero)
        am = (phiv_pos - cSf_pos).ext_min(phiv_neg - cSf_neg).ext_min(v_zero)

        a_pos = ap / (ap - am)

        from Foam.finiteVolume import surfaceScalarField
        amaxSf = surfaceScalarField(word("amaxSf"), am.mag().ext_max(ap.mag()))

        aSf = am * a_pos

        if str(fluxScheme) == "Tadmor":
            aSf.ext_assign(-0.5 * amaxSf)
            a_pos.ext_assign(0.5)
            pass

        a_neg = 1.0 - a_pos

        phiv_pos *= a_pos
        phiv_neg *= a_neg

        aphiv_pos = phiv_pos - aSf

        aphiv_neg = phiv_neg + aSf

        # Reuse amaxSf for the maximum positive and negative fluxes
        # estimated by the central scheme
        amaxSf.ext_assign(aphiv_pos.mag().ext_max(aphiv_neg.mag()))

        CoNum, meanCoNum = compressibleCourantNo(mesh, amaxSf, runTime)

        from Foam.finiteVolume.cfdTools.general.include import readTimeControls
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

        from Foam.finiteVolume.cfdTools.general.include import setDeltaT
        runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum)

        runTime.increment()

        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        phi = None

        phi = surfaceScalarField(word("phi"),
                                 aphiv_pos * rho_pos + aphiv_neg * rho_neg)

        phiUp = (aphiv_pos * rhoU_pos + aphiv_neg *
                 rhoU_neg) + (a_pos * p_pos + a_neg * p_neg) * mesh.Sf()

        phiEp = aphiv_pos * ( rho_pos * ( e_pos + 0.5*U_pos.magSqr() ) + p_pos ) + aphiv_neg * ( rho_neg * ( e_neg + 0.5 * U_neg.magSqr() ) + p_neg )\
                + aSf * p_pos - aSf * p_neg

        from Foam.finiteVolume import volTensorField
        from Foam import fvc
        tauMC = volTensorField(word("tauMC"), mu * fvc.grad(U).T().dev2())

        # --- Solve density
        from Foam.finiteVolume import solve
        from Foam import fvm
        solve(fvm.ddt(rho) + fvc.div(phi))

        # --- Solve momentum
        solve(fvm.ddt(rhoU) + fvc.div(phiUp))

        U.dimensionedInternalField().ext_assign(
            rhoU.dimensionedInternalField() / rho.dimensionedInternalField())
        U.correctBoundaryConditions()
        rhoU.ext_boundaryField().ext_assign(rho.ext_boundaryField() *
                                            U.ext_boundaryField())

        rhoBydt = rho / runTime.deltaT()

        if not inviscid:
            solve(
                fvm.ddt(rho, U) - fvc.ddt(rho, U) - fvm.laplacian(mu, U) -
                fvc.div(tauMC))
            rhoU.ext_assign(rho * U)
            pass

        # --- Solve energy
        sigmaDotU = (fvc.interpolate(mu) * mesh.magSf() * fvc.snGrad(U) +
                     (mesh.Sf() & fvc.interpolate(tauMC))) & (a_pos * U_pos +
                                                              a_neg * U_neg)

        solve(fvm.ddt(rhoE) + fvc.div(phiEp) - fvc.div(sigmaDotU))

        e.ext_assign(rhoE / rho - 0.5 * U.magSqr())
        e.correctBoundaryConditions()
        thermo.correct()
        from Foam.finiteVolume import volScalarField
        rhoE.ext_boundaryField().ext_assign(
            rho.ext_boundaryField() *
            (e.ext_boundaryField() + 0.5 * U.ext_boundaryField().magSqr()))

        if not inviscid:
            k = volScalarField(word("k"), thermo.Cp() * mu / Pr)

            # The initial C++ expression does not work properly, because of
            #  1. the order of expression arguments computation differs with C++
            #solve( fvm.ddt( rho, e ) - fvc.ddt( rho, e ) - fvm.laplacian( thermo.alpha(), e ) \
            #                                             + fvc.laplacian( thermo.alpha(), e ) - fvc.laplacian( k, T ) )

            solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( thermo.alpha(), e ) \
                                          + (- fvm.laplacian( thermo.alpha(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )

            thermo.correct()
            rhoE.ext_assign(rho * (e + 0.5 * U.magSqr()))
            pass

        p.dimensionedInternalField().ext_assign(
            rho.dimensionedInternalField() / psi.dimensionedInternalField())
        p.correctBoundaryConditions()
        rho.ext_boundaryField().ext_assign(psi.ext_boundaryField() *
                                           p.ext_boundaryField())

        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
Esempio n. 30
0
def Ueqn( mesh, phi, U, rho, p, g, turbulence, eqnResidual, maxResidual ):
    from Foam import fvm, fvc
    UEqn = fvm.div( phi, U ) + turbulence.divDevRhoReff( U )
    UEqn.relax()
    
    from Foam.finiteVolume import solve
    eqnResidual = solve( UEqn() == fvc.reconstruct( fvc.interpolate( rho )*( g & mesh.Sf() ) - fvc.snGrad( p ) * mesh.magSf() ) ).initialResidual()
    
    maxResidual = max(eqnResidual, maxResidual)
       
    return UEqn, eqnResidual, maxResidual
def fun_pEqn( runTime, mesh, p, p_rgh, phi, U, UEqn, ghf, gh, 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_rgh )
    
    buoyancyPhi = rUAf * ghf * fvc.snGrad( rhok ) * mesh.magSf()
    
    phi.ext_assign( phi - buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm, fvc
        p_rghEqn = fvm.laplacian( rUAf, p_rgh ) == fvc.div(phi)
        
        from Foam.finiteVolume import getRefCellValue
        p_rghEqn.setReference( pRefCell, getRefCellValue( p_rgh, pRefCell ) )
        
        # retain the residual from the first iteration
        if ( nonOrth == 0 ):
              eqnResidual = p_rghEqn.solve().initialResidual()
              maxResidual = max( eqnResidual, maxResidual )
              pass
        else:
              p_rghEqn.solve()
              pass
        

        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() ) / rUAf ) )
           U.correctBoundaryConditions()
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    p.ext_assign( p_rgh + rhok * gh )

    if p_rgh.needReference():
       from Foam.OpenFOAM import dimensionedScalar
       p.ext_assign( p + dimensionedScalar( word( "p" ), p.dimensions(), pRefValue - getRefCellValue( p, pRefCell ) ) )
       p_rgh.ext_assign( p - rhok * gh )
       pass

    return eqnResidual, maxResidual, cumulativeContErr
Esempio n. 32
0
def main_standalone( argc, argv ):

    from Foam.OpenFOAM.include import setRootCase
    args = setRootCase( argc, argv )

    from Foam.OpenFOAM.include import createTime
    runTime = createTime( args )

    from Foam.OpenFOAM.include import createMesh
    mesh = createMesh( runTime )
    
    gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration( runTime, mesh )

    h, h0, U, hU, hTotal, phi, F = _createFields( runTime, mesh, Omega, gHat )

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl 
    
    while runTime.loop() :
        ext_Info() << "\nTime = " << runTime.timeName() << nl << nl
        
        from Foam.finiteVolume.cfdTools.general.include import readPISOControls
        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) 
        
        CoNum, meanCoNum, waveCoNum = CourantNo( runTime, mesh, h, phi, magg )
        
        for ucorr in range( nOuterCorr ):
           from Foam.finiteVolume import surfaceScalarField
           from Foam import fvc
           from Foam.OpenFOAM import word
           
           phiv = surfaceScalarField( word( "phiv" ), phi / fvc.interpolate( h ) )
           
           from Foam import fvm
           hUEqn = fvm.ddt( hU ) + fvm.div( phiv, hU ) 
           
           hUEqn.relax()
           
           if momentumPredictor:
              from Foam.finiteVolume import solve
              from Foam import fvc
              if rotating:
                  solve( hUEqn + ( F ^ hU ) == -magg * h * fvc.grad( h + h0 ) )
                  pass
              else:
                  solve( hUEqn == -magg * h * fvc.grad( h + h0 ) ) 
                  pass
              
              # Constrain the momentum to be in the geometry if 3D geometry
              if mesh.nGeometricD() == 3 :
                 hU.ext_assign( hU - ( gHat & hU ) * gHat )
                 hU.correctBoundaryConditions();
                 pass
           
           for corr in range( nCorr ): 
               hf = fvc.interpolate( h )
               rUA = 1.0 / hUEqn.A()
               ghrUAf = magg * fvc.interpolate( h * rUA )
               
               phih0 = ghrUAf * mesh.magSf() * fvc.snGrad( h0 )
               if rotating:
                  hU.ext_assign( rUA * ( hUEqn .H() - ( F ^ hU ) ) )
                  pass
               else:
                  hU = rUA * hUEqn.H()
                  pass
               
               phi.ext_assign( ( fvc.interpolate( hU ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, h, hU, phi )- phih0 )
               
               for nonOrth in range(nNonOrthCorr + 1):
                   hEqn = fvm.ddt( h ) + fvc.div( phi ) - fvm.laplacian( ghrUAf, h )
                   
                   if ucorr < nOuterCorr-1 or corr < nCorr-1 :
                      hEqn.solve()
                      pass
                   else:
                      hEqn.solve( mesh.solver( word( str( h.name() ) + "Final" ) ) )
                      pass
                   if nonOrth == nNonOrthCorr:
                      phi.ext_assign( phi + hEqn.flux() )
                   pass
               
               hU.ext_assign( hU - rUA * h * magg * fvc.grad( h + h0 ) )
               
               #Constrain the momentum to be in the geometry if 3D geometry
               if mesh.nGeometricD() == 3:
                  hU.ext_assign( hU - ( gHat & hU ) * gHat )
                  pass
               
               hU.correctBoundaryConditions()
               pass
           pass
        
        U == hU / h
        hTotal == h + h0

        runTime.write()
        
        ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
        pass

    ext_Info() << "End\n" << nl 

    import os
    return os.EX_OK
Esempio n. 33
0
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, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid = _createFields( runTime, mesh )
    
    thermophysicalProperties, Pr = readThermophysicalProperties( runTime, mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
    
    fluxScheme = readFluxScheme( mesh )
    
    from Foam.OpenFOAM import dimensionedScalar, dimVolume, dimTime, word
    v_zero = dimensionedScalar( word( "v_zero" ) ,dimVolume/dimTime, 0.0)
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl
    
    while runTime.run() :
        # --- upwind interpolation of primitive fields on faces
        from Foam import fvc
        rho_pos = fvc.interpolate( rho, pos, word( "reconstruct(rho)" ) )
        rho_neg = fvc.interpolate( rho, neg, word( "reconstruct(rho)" ) )
        
        rhoU_pos = fvc.interpolate( rhoU, pos, word( "reconstruct(U)" ) )
        rhoU_neg = fvc.interpolate( rhoU, neg, word( "reconstruct(U)" ) )
        
        rPsi = 1.0 / psi
        rPsi_pos = fvc.interpolate( rPsi, pos, word( "reconstruct(T)" ) )
        rPsi_neg = fvc.interpolate( rPsi, neg, word( "reconstruct(T)" ) )
        
        e_pos = fvc.interpolate( e, pos, word( "reconstruct(T)" ) )
        e_neg = fvc.interpolate( e, neg, word( "reconstruct(T)" ) )
        
        U_pos = rhoU_pos / rho_pos
        U_neg = rhoU_neg / rho_neg

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

        phiv_pos = U_pos & mesh.Sf()
        phiv_neg = U_neg & mesh.Sf()
        
        c = ( thermo.Cp() / thermo.Cv() * rPsi ).sqrt()
        cSf_pos = fvc.interpolate( c, pos, word( "reconstruct(T)" ) ) * mesh.magSf()
        cSf_neg = fvc.interpolate( c, neg, word( "reconstruct(T)" ) ) * mesh.magSf()
        
        ap = ( phiv_pos + cSf_pos ).ext_max( phiv_neg + cSf_neg ).ext_max( v_zero )
        am = ( phiv_pos - cSf_pos ).ext_min( phiv_neg - cSf_neg ).ext_min( v_zero )

        a_pos = ap / ( ap - am )
        
        from Foam.finiteVolume import surfaceScalarField
        amaxSf = surfaceScalarField( word( "amaxSf" ), am.mag().ext_max( ap.mag() ) )
        
        CoNum, meanCoNum = compressibleCourantNo( mesh, amaxSf, runTime )
        
        from Foam.finiteVolume.cfdTools.general.include import readTimeControls
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
        
        from Foam.finiteVolume.cfdTools.general.include import setDeltaT
        runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum )
        
        runTime.increment()
        
        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        
        aSf = am * a_pos

        if str( fluxScheme ) == "Tadmor":
           aSf.ext_assign( -0.5 * amaxSf )
           a_pos.ext_assign( 0.5 )
           pass
        
        a_neg = 1.0 - a_pos
        
        phiv_pos *= a_pos
        phiv_neg *= a_neg
        
        aphiv_pos = phiv_pos - aSf
        
        aphiv_neg = phiv_neg + aSf

        phi = None

        phi = surfaceScalarField( word( "phi" ), aphiv_pos * rho_pos + aphiv_neg * rho_neg )

        phiUp = ( aphiv_pos * rhoU_pos + aphiv_neg * rhoU_neg) + ( a_pos * p_pos + a_neg * p_neg ) * mesh.Sf()

        phiEp = aphiv_pos * ( rho_pos * ( e_pos + 0.5*U_pos.magSqr() ) + p_pos ) + aphiv_neg * ( rho_neg * ( e_neg + 0.5 * U_neg.magSqr() ) + p_neg )\
                + aSf * p_pos - aSf * p_neg
        
        from Foam.finiteVolume import volTensorField
        from Foam import fvc
        tauMC = volTensorField( word( "tauMC" ) , mu * fvc.grad(U).T().dev2() ) 
        
        # --- Solve density
        from Foam.finiteVolume import solve
        from Foam import fvm
        solve( fvm.ddt( rho ) + fvc.div( phi ) )
        
        # --- Solve momentum
        solve( fvm.ddt( rhoU ) + fvc.div( phiUp ) )
        
        U.dimensionedInternalField().ext_assign( rhoU.dimensionedInternalField() / rho.dimensionedInternalField() )
        U.correctBoundaryConditions()
        rhoU.ext_boundaryField().ext_assign( rho.ext_boundaryField() * U.ext_boundaryField() )
        
        rhoBydt = rho / runTime.deltaT()
        
        if not inviscid:
           solve( fvm.ddt( rho, U ) - fvc.ddt( rho, U ) - fvm.laplacian( mu, U ) - fvc.div( tauMC ) )
           rhoU.ext_assign( rho * U )
           pass
        
        # --- Solve energy
        sigmaDotU = ( fvc.interpolate( mu ) * mesh.magSf() * fvc.snGrad( U ) + ( mesh.Sf() & fvc.interpolate( tauMC ) ) ) & ( a_pos * U_pos + a_neg * U_neg )

        solve( fvm.ddt( rhoE ) + fvc.div( phiEp ) - fvc.div( sigmaDotU ) )
        
        e.ext_assign( rhoE / rho - 0.5 * U.magSqr() )
        e.correctBoundaryConditions()
        thermo.correct()
        from Foam.finiteVolume import volScalarField
        rhoE.ext_boundaryField().ext_assign( rho.ext_boundaryField() * ( e.ext_boundaryField() + 0.5 * U.ext_boundaryField().magSqr() ) )
        
        if not inviscid:
           k = volScalarField( word( "k" ) , thermo.Cp() * mu / Pr )

           # The initial C++ expression does not work properly, because of
           #  1. the order of expression arguments computation differs with C++
           #solve( fvm.ddt( rho, e ) - fvc.ddt( rho, e ) - fvm.laplacian( thermo.alpha(), e ) \
           #                                             + fvc.laplacian( thermo.alpha(), e ) - fvc.laplacian( k, T ) )

           solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( thermo.alpha(), e ) \
                                         + (- fvm.laplacian( thermo.alpha(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )
           
           thermo.correct()
           rhoE.ext_assign( rho * ( e + 0.5 * U.magSqr() ) )
           pass
        
        p.dimensionedInternalField().ext_assign( rho.dimensionedInternalField() / psi.dimensionedInternalField() )
        p.correctBoundaryConditions()
        rho.ext_boundaryField().ext_assign( psi.ext_boundaryField() * p.ext_boundaryField() )
        
        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
Esempio n. 34
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