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
Exemple #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
Exemple #3
0
def main_standalone( argc, argv ):

    from Foam.OpenFOAM import argList, word
    argList.validOptions.fget().insert( word( "writep" ), "" )
    
    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 )
    
    p, U, phi, pRefCell, pRefValue = _createFields( runTime, mesh )
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << nl << "Calculating potential flow" << nl
        
    from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls
    simple, nNonOrthCorr, momentumPredictor, fluxGradp, transonic = readSIMPLEControls( mesh )
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phi, U, p)
    
    from Foam.OpenFOAM import dimensionedScalar, word, dimTime, dimensionSet
    from Foam import fvc, fvm
    for nonOrth in range( nNonOrthCorr + 1):
        pEqn = fvm.laplacian( dimensionedScalar( word( "1" ), dimTime / p.dimensions() * dimensionSet( 0.0, 2.0, -2.0, 0.0, 0.0 ), 1.0 ), p ) == fvc.div( phi )

        pEqn.setReference( pRefCell, pRefValue )
        pEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pEqn.flux() )
           pass
        pass
    
    ext_Info() << "continuity error = " << fvc.div( phi ).mag().weightedAverage( mesh.V() ).value() << nl

    U.ext_assign( fvc.reconstruct( phi ) )
    U.correctBoundaryConditions()
    ext_Info() << "Interpolated U error = " << ( ( ( fvc.interpolate( U ) & mesh.Sf() ) - phi ).sqr().sum().sqrt()  /mesh.magSf().sum() ).value() << nl

    # Force the write
    U.write()
    phi.write()
    
    if args.optionFound( word( "writep" ) ):
       p.write()
       pass
       
    ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
    ext_Info() << "End\n" << nl 

    import os
    return os.EX_OK
def _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g, initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ): 
    closedVolume = p.needReference()
    rho.ext_assign( thermo.rho() )

    # Thermodynamic density needs to be updated by psi*d(p) after the
    # pressure solution - done in 2 parts. Part 1:
    thermo.rho().ext_assign( thermo.rho() - psi * p )
    
    rUA = 1.0/UEqn.A()
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA * UEqn.H() )

    phiU = fvc.interpolate( rho ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) 

    phi.ext_assign( phiU + rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() ) )
    
    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm
        from Foam.finiteVolume import correction
        pEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p )
        
        if corr == nCorr-1  and nonOrth == nNonOrthCorr:
           pEqn.solve( mesh.solver( word( str( p.name() ) + "Final" ) ) )
           pass
        else:
           pEqn.solve( mesh.solver( p.name() ) )
           pass
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi + pEqn.flux() )
           pass

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

    U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) )
    U.correctBoundaryConditions()
    
    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )
    
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn  
    rhoEqn( rho, phi )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )

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

    return cumulativeContErr
def fun_pEqn( i, mesh, p, rho, turb, thermo, thermoFluid, K, UEqn, U, phi, psi, DpDt, initialMass, p_rgh, gh, ghf, \
              nNonOrthCorr, oCorr, nOuterCorr, corr, nCorr, cumulativeContErr ) :
    
    closedVolume = p_rgh.needReference()

    rho.ext_assign( thermo.rho() )
    
    rUA = 1.0 / UEqn.A()
    
    from Foam import fvc
    from Foam.OpenFOAM import word 
    from Foam.finiteVolume import surfaceScalarField
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ) , fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA * UEqn.H() ) 

    from Foam import fvc

    phiU = ( fvc.interpolate( rho ) *
                 (  ( fvc.interpolate( U ) & mesh.Sf() ) +
                      fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
    phi.ext_assign( phiU - rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() )
    from Foam import fvm
    for nonOrth in range ( nNonOrthCorr + 1 ):
        p_rghEqn = ( fvm.ddt( psi, p_rgh) + fvc.ddt( psi, rho ) * gh + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh ) )
        p_rghEqn.solve( mesh.solver( p_rgh.select( ( oCorr == nOuterCorr-1 and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) )
        
        if nonOrth == nNonOrthCorr :
            phi.ext_assign( phi + p_rghEqn.flux() )
            pass
        pass
    
    # Correct velocity field
    U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) )
    U.correctBoundaryConditions()
    
    p.ext_assign( p_rgh + rho * gh )

    #Update pressure substantive derivative
    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )
    
    # Solve continuity
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn( rho, phi )   
    
    # Update continuity errors
    cumulativeContErr = compressibleContinuityErrors( i, mesh, rho, thermo, cumulativeContErr )
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume :
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       rho.ext_assign( thermo.rho() )
       p_rgh.ext_assign( p - rho * gh )
       pass
    #Update thermal conductivity
    K.ext_assign( thermoFluid[ i ].Cp() * turb.alphaEff() )
        
    return cumulativeContErr
def fun_pEqn(runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual,
             nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue):

    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField(word("rUA"), 1.0 / UEqn().A())
    rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA))

    U.ext_assign(rUA * UEqn().H())
    UEqn.clear()

    from Foam import fvc
    phi.ext_assign(fvc.interpolate(U) & mesh.Sf())

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

    buoyancyPhi = rUAf * fvc.interpolate(rhok) * (g & mesh.Sf())

    phi.ext_assign(phi + buoyancyPhi)

    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm, fvc
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)

        pEqn.setReference(pRefCell, pRefValue)

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

        if (nonOrth == nNonOrthCorr):
            # Calculate the conservative fluxes
            phi.ext_assign(phi - pEqn.flux())

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

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U.ext_assign(U + rUA *
                         fvc.reconstruct((buoyancyPhi - pEqn.flux()) / rUAf))
            U.correctBoundaryConditions()
            pass

        pass

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

    return eqnResidual, maxResidual, cumulativeContErr
Exemple #7
0
def fun_pEqn(thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh,
             nNonOrthCorr, pRefCell, eqnResidual, maxResidual,
             cumulativeContErr):

    rho.ext_assign(thermo.rho())

    rUA = 1.0 / UEqn.A()

    from Foam.OpenFOAM import word
    from Foam import fvc, fvm
    from Foam.finiteVolume import surfaceScalarField
    rhorUAf = surfaceScalarField(word("(rho*(1|A(U)))"),
                                 fvc.interpolate(rho * rUA))
    U.ext_assign(rUA * UEqn.H())
    UEqn.clear()

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

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

    buoyancyPhi = surfaceScalarField(rhorUAf * fvc.interpolate(rho) *
                                     (g & mesh.Sf()))

    phi.ext_assign(phi + buoyancyPhi)

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

        pEqn.setReference(pRefCell, p[pRefCell])

        if (nonOrth == 0):
            eqnResidual = pEqn.solve().initialResidual()
            maxResidual = max(eqnResidual, maxResidual)
        else:
            pEqn.solve()

        if (nonOrth == nNonOrthCorr):
            if (closedVolume):
                p.ext_assign(p + (initialMass - fvc.domainIntegrate(psi * p)) /
                             fvc.domainIntegrate(psi))

            phi.ext_assign(phi - pEqn.flux())
            p.relax()
            U.ext_assign(U + rUA * fvc.reconstruct(
                (buoyancyPhi - pEqn.flux()) / rhorUAf))
            U.correctBoundaryConditions()

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

    ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << nl

    return eqnResidual, maxResidual, cumulativeContErr
def fun_pEqn( runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): 
    
    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField( word( "rUA" ), 1.0 / UEqn().A() )
    rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) )

    U.ext_assign( rUA * UEqn().H() )
    UEqn.clear()
    
    from Foam import fvc 
    phi.ext_assign( fvc.interpolate( U ) & mesh.Sf() )
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi( phi, U, p )
    
    buoyancyPhi = rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() )
    
    phi.ext_assign( phi + buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm, fvc
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)

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

        if ( nonOrth == nNonOrthCorr ):
           # Calculate the conservative fluxes
           phi.ext_assign( phi - pEqn.flux() )
           
           # Explicitly relax pressure for momentum corrector
           p.relax()

           # Correct the momentum source with the pressure gradient flux
           # calculated from the relaxed pressure
           U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rUAf ) )
           U.correctBoundaryConditions()
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    return eqnResidual, maxResidual, cumulativeContErr
def fun_pEqn( mesh, p, rho, psi, p_rgh, U, phi, ghf, gh, DpDt, UEqn, thermo, nNonOrthCorr, corr, nCorr, finalIter, cumulativeContErr ):
    
    rho.ext_assign( thermo.rho() )

    # Thermodynamic density needs to be updated by psi*d(p) after the
    # pressure solution - done in 2 parts. Part 1:
    thermo.rho().ext_assign( thermo.rho() - psi * p_rgh )

    rUA = 1.0 / UEqn.A()
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA*UEqn.H() )

    phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )

    buoyancyPhi = -rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf()
    phi.ext_assign( phi + buoyancyPhi )
    
    from Foam import fvm
    from Foam.finiteVolume import correction
    for nonOrth in range( nNonOrthCorr +1 ):
        p_rghEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p_rgh ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh )

        p_rghEqn.solve( mesh.solver( p_rgh.select( ( finalIter and corr == nCorr-1 and nonOrth == nNonOrthCorr ) ) ) )

        if nonOrth == nNonOrthCorr:
            # Calculate the conservative fluxes
            phi.ext_assign( phi + p_rghEqn.flux() )

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

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorUAf ) )
            U.correctBoundaryConditions()
            pass

    p.ext_assign( p_rgh + rho * gh )

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

    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )

    from Foam.finiteVolume.cfdTools.compressible import rhoEqn  
    rhoEqn( rho, phi )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )

    return cumulativeContErr
def 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
Exemple #11
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_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_pEqn( thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ):

    rho.ext_assign( thermo.rho() )

    rUA = 1.0/UEqn.A()
    
    from Foam.OpenFOAM import word
    from Foam import fvc,fvm
    from Foam.finiteVolume import surfaceScalarField
    rhorUAf = surfaceScalarField(word( "(rho*(1|A(U)))" ) , fvc.interpolate(rho*rUA));
    U.ext_assign(rUA*UEqn.H())
    UEqn.clear()
    
    phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) )

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

    buoyancyPhi =surfaceScalarField( rhorUAf * fvc.interpolate( rho )*( g & mesh.Sf() ) )
    
    phi.ext_assign( phi+buoyancyPhi )

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

        pEqn.setReference(pRefCell, p[pRefCell]);


        if (nonOrth == 0):
            eqnResidual = pEqn.solve().initialResidual()
            maxResidual = max(eqnResidual, maxResidual)
        else:
            pEqn.solve()

        if (nonOrth == nNonOrthCorr):
           if (closedVolume):
              p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) 
           
           phi.ext_assign( phi - pEqn.flux() )
           p.relax()
           U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rhorUAf ) )
           U.correctBoundaryConditions();
    
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    rho.ext_assign( thermo.rho() )
    rho.relax()

    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
def fun_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
Exemple #15
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
def fun_UEqn( rho, U, phi, g, p, 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( 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
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 _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
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
Exemple #21
0
def _pEqn(mesh, UEqn, U, p, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue):
    rUA = 1.0 / UEqn.A()

    from Foam import fvc

    rUAf = fvc.interpolate(rUA)

    U.ext_assign(rUA * UEqn.H())

    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word

    phiU = surfaceScalarField(word("phiU"), (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, rho, U, phi))

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phiU, U, p)

    phi.ext_assign(
        phiU
        + (
            fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) * mesh.magSf()
            + fvc.interpolate(rho) * (g & mesh.Sf())
        )
        * rUAf
    )

    from Foam import fvm

    for nonOrth in range(nNonOrthCorr + 1):
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)
        pEqn.setReference(pRefCell, pRefValue)

        if corr == nCorr - 1 and nonOrth == nNonOrthCorr:
            pEqn.solve(mesh.solver(word(str(p.name()) + "Final")))
            pass
        else:
            pEqn.solve(mesh.solver(p.name()))
            pass
        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - pEqn.flux())
            pass
        pass

    U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf))
    U.correctBoundaryConditions()

    pass
def fun_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
Exemple #23
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
Exemple #24
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
Exemple #25
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
def _pEqn(runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr,
          cumulativeContErr):

    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField(word("rUA"), 1.0 / UEqn.A())

    rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA))

    U.ext_assign(rUA * UEqn.H())

    phiU = (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi)

    phi.ext_assign(phiU + rUAf * fvc.interpolate(rhok) * (g & mesh.Sf()))

    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)

        if (corr == nCorr - 1) and (nonOrth == nNonOrthCorr):
            from Foam.OpenFOAM import word
            pEqn.solve(mesh.solver(word(str(p.name()) + "Final")))
            pass
        else:
            pEqn.solve(mesh.solver(p.name()))
            pass

        if (nonOrth == nNonOrthCorr):
            phi.ext_assign(phi - pEqn.flux())
            pass
        pass
    U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf))
    U.correctBoundaryConditions()

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

    return pEqn
def _pEqn( runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr, cumulativeContErr ): 
    
    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField( word( "rUA" ), 1.0 / UEqn.A() )

    rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) )

    U.ext_assign( rUA * UEqn.H() )
    
    phiU = ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi )
    
    phi.ext_assign( phiU + rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() ) )
    
    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm
        pEqn = fvm.laplacian( rUAf, p ) == fvc.div( phi )

        if ( corr == nCorr-1 ) and (nonOrth == nNonOrthCorr):
           from Foam.OpenFOAM import word
           pEqn.solve(mesh.solver( word( str( p.name() ) + "Final" ) ) )
           pass
        else:
           pEqn.solve( mesh.solver( p.name() ) )
           pass

        if (nonOrth == nNonOrthCorr):
           phi.ext_assign( phi - pEqn.flux() )
           pass
        pass
    U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rUAf ) )
    U.correctBoundaryConditions() 

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    return pEqn
def pEqn( runTime, mesh, p, phi, psi, U, UEqn, g, rho, thermo, initialMass, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): 
    rho.ext_assign( thermo.rho() )
    
    from Foam import fvc
    rUA = 1.0 / UEqn().A()

    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ) , fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA * UEqn().H() )
    UEqn.clear();

    phi.ext_assign( fvc.interpolate( rho ) * ( fvc.interpolate( U ) & mesh.Sf() ) )
    
    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi( phi, U, p )

    buoyancyPhi = rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() )
    phi.ext_assign( phi + buoyancyPhi )
    
    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1): 
        pEqn = fvm.laplacian( rhorUAf, p ) == fvc.div( phi )

        pEqn.setReference( pRefCell, pRefValue )

        # retain the residual from the first iteration
        if nonOrth == 0:
           eqnResidual = pEqn.solve().initialResidual()
           maxResidual = max(eqnResidual, maxResidual)
           pass
        else:
           pEqn.solve()
           pass
        
        if nonOrth == nNonOrthCorr:
           # For closed-volume cases adjust the pressure and density levels
           # to obey overall mass continuity
           if closedVolume:
              p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
              pass

           # Calculate the conservative fluxes
           phi.ext_assign( phi - pEqn.flux() )

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

           # Correct the momentum source with the pressure gradient flux
           # calculated from the relaxed pressure
           U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rhorUAf ) )
           U.correctBoundaryConditions()
           pass

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

    rho.ext_assign( thermo.rho() )
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    
    return eqnResidual, maxResidual, cumulativeContErr
def 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( 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
Exemple #32
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
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
Exemple #34
0
def main_standalone(argc, argv):

    from Foam.OpenFOAM import argList, word
    argList.validOptions.fget().insert(word("writep"), "")

    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)

    p, U, phi, pRefCell, pRefValue = _createFields(runTime, mesh)

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << nl << "Calculating potential flow" << nl

    from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls
    simple, nNonOrthCorr, momentumPredictor, transonic = readSIMPLEControls(
        mesh)

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

    from Foam.OpenFOAM import dimensionedScalar, word, dimTime, dimensionSet
    from Foam import fvc, fvm
    for nonOrth in range(nNonOrthCorr + 1):
        pEqn = fvm.laplacian(
            dimensionedScalar(
                word("1"), dimTime / p.dimensions() *
                dimensionSet(0.0, 2.0, -2.0, 0.0, 0.0), 1.0),
            p) == fvc.div(phi)

        pEqn.setReference(pRefCell, pRefValue)
        pEqn.solve()

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

    ext_Info() << "continuity error = " << fvc.div(phi).mag().weightedAverage(
        mesh.V()).value() << nl

    U.ext_assign(fvc.reconstruct(phi))
    U.correctBoundaryConditions()
    ext_Info() << "Interpolated U error = " << (
        ((fvc.interpolate(U) & mesh.Sf()) - phi).sqr().sum().sqrt() /
        mesh.magSf().sum()).value() << nl

    # Force the write
    U.write()
    phi.write()

    if args.optionFound(word("writep")):
        p.write()
        pass

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

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

    import os
    return os.EX_OK