예제 #1
0
def fun_pEqn( mesh, p, U, trTU, trAU, UEqn, phi, runTime, pressureImplicitPorosity, nNonOrthCorr, \
              eqnResidual, maxResidual, cumulativeContErr, pRefCell, pRefValue, ):

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

    UEqn.clear()

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

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

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

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

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

        pass

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

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

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

    U.correctBoundaryConditions()

    return eqnResidual, maxResidual
예제 #2
0
def fun_pEqn( mesh, p, U, trTU, trAU, UEqn, phi, runTime, pressureImplicitPorosity, nNonOrthCorr, \
              eqnResidual, maxResidual, cumulativeContErr, pRefCell, pRefValue, ):
   
    if pressureImplicitPorosity :
       U.ext_assign( trTU & UEqn.H() )
       pass
    else:
       U.ext_assign( trAU * UEqn.H() )
       pass
    
    UEqn.clear() 
    
    from Foam import fvc, fvm
    phi.ext_assign( fvc.interpolate( U ) & mesh.Sf() )

    from Foam.finiteVolume import adjustPhi
    adjustPhi( phi, U, p )
    
    for nonOrth in range( nNonOrthCorr + 1 ) :
        tpEqn = None
        if pressureImplicitPorosity :
            tpEqn = ( fvm.laplacian( trTU, p ) == fvc.div( phi ) )
            pass
        else:
            tpEqn = ( fvm.laplacian( trAU, p ) == fvc.div( phi ) )
            pass
        
        tpEqn.setReference( pRefCell, pRefValue )
        # retain the residual from the first iteration
        if nonOrth == 0 :
            eqnResidual = tpEqn.solve().initialResidual()
            maxResidual = max( eqnResidual, maxResidual )
            pass
        else:
            tpEqn.solve()
            pass
        
        if nonOrth == nNonOrthCorr :
            phi.ext_assign( phi - tpEqn.flux() )
            pass
        
        pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )

    # Explicitly relax pressure for momentum corrector
    p.relax()
           
    if pressureImplicitPorosity :
        U.ext_assign( U - ( trTU & fvc.grad( p ) ) )
    else:
        U.ext_assign( U - ( trAU * fvc.grad( p ) ) )
        pass
       
    U.correctBoundaryConditions()

    return eqnResidual, maxResidual
예제 #3
0
def _hEqn( phi, h, turbulence, rho, p, thermo, eqnResidual, maxResidual ):
    from Foam import fvc, fvm
    hEqn = fvm.div( phi, h ) - fvm.Sp( fvc.div( phi ), h ) - fvm.laplacian( turbulence.alphaEff(), h ) \
            ==  fvc.div( phi / fvc.interpolate( rho ) * fvc.interpolate( p ) ) - p * fvc.div( phi / fvc.interpolate( rho ) ) 

    hEqn.relax()

    eqnResidual = hEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    thermo.correct()
    
    return hEqn, eqnResidual, maxResidual
예제 #4
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
예제 #5
0
    def step(self, getPISOControls):
        from Foam.OpenFOAM import ext_Info, nl

        ext_Info() << "Time = " << self.runTime.timeName() << nl << nl

        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = getPISOControls(self.mesh)

        from Foam.finiteVolume.cfdTools.incompressible import CourantNo

        CoNum, meanCoNum = CourantNo(self.mesh, self.phi, self.runTime)

        from Foam import fvm

        UEqn = fvm.ddt(self.U) + fvm.div(self.phi, self.U) - fvm.laplacian(self.nu, self.U)

        from Foam import fvc
        from Foam.finiteVolume import solve

        solve(UEqn == -fvc.grad(self.p))

        # --- PISO loop

        for corr in range(nCorr):
            rUA = 1.0 / UEqn.A()

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

            from Foam.finiteVolume import adjustPhi

            adjustPhi(self.phi, self.U, self.p)

            for nonOrth in range(nNonOrthCorr + 1):
                pEqn = fvm.laplacian(rUA, self.p) == fvc.div(self.phi)

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

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

                pass

            from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

            self.U.ext_assign(self.U - rUA * fvc.grad(self.p))
            self.U.correctBoundaryConditions()

            pass

        self.runTime.write()

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

        self.runTime += self.runTime.deltaT()

        return self.runTime.value()
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
예제 #7
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
예제 #8
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
예제 #9
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
예제 #10
0
def _eEqn( rho, e, phi, turbulence, p, thermo ):
    from Foam import fvm, fvc
    from Foam.finiteVolume import solve
    solve( fvm.ddt( rho, e ) + fvm.div( phi, e ) - fvm.laplacian( turbulence.alphaEff(), e )
           == - p * fvc.div( phi / fvc.interpolate( rho ) ) )

    thermo.correct()
    pass
예제 #11
0
def _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt,
          cumulativeContErr, corr, nCorr, nOuterCorr, transonic):
    rho.ext_assign(thermo.rho())

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

    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    if transonic:
        phid = surfaceScalarField(
            word("phid"),
            fvc.interpolate(psi) * ((fvc.interpolate(U) & mesh.Sf()) +
                                    fvc.ddtPhiCorr(rUA, rho, U, phi)))

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

            pEqn.solve()

            if nonOrth == nNonOrthCorr:
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi.ext_assign(
            fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf()) +
                                    fvc.ddtPhiCorr(rUA, rho, U, phi)))

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

            pEqn.solve()

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

    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn(rho, phi)

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

    U.ext_assign(U - rUA * fvc.grad(p))
    U.correctBoundaryConditions()

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

    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
예제 #13
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_hEqn( turbulence, phi, h, rho, radiation, p, thermo, eqnResidual, maxResidual  ):
    
    from Foam import fvc, fvm    
    left_exp = fvm.div( phi, h ) - fvm.Sp( fvc.div( phi ), h ) - fvm.laplacian( turbulence.alphaEff(), h )
    right_exp = fvc.div( phi/fvc.interpolate( rho )*fvc.interpolate( p ) ) - p*fvc.div( phi/fvc.interpolate( rho ) ) + radiation.Sh( thermo() )
    
    hEqn = (left_exp == right_exp )

    hEqn.relax()

    eqnResidual = hEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    thermo.correct()

    radiation.correct()
    
    return hEqn, eqnResidual, maxResidual
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
예제 #16
0
def _UEqn(phi, U, p, turbulence, pZones, pressureImplicitPorosity, nUCorr, eqnResidual, maxResidual):

    from Foam import fvm, fvc

    # Construct the Momentum equation

    # The initial C++ expression does not work properly, because of
    #  1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries
    #  2. the order of expression arguments computation differs with C++
    # UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U )

    UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U))

    UEqn.relax()

    # Include the porous media resistance and solve the momentum equation
    # either implicit in the tensorial resistance or transport using by
    # including the spherical part of the resistance in the momentum diagonal

    trAU = None
    trTU = None
    if pressureImplicitPorosity:
        from Foam.OpenFOAM import sphericalTensor, tensor

        tTU = tensor(sphericalTensor.I) * UEqn.A()

        pZones.addResistance(UEqn, tTU)

        trTU = tTU.inv()

        from Foam.OpenFOAM import word

        trTU.rename(word("rAU"))

        for UCorr in range(nUCorr):
            U.ext_assign(trTU & (UEqn.H() - fvc.grad(p)))
            pass

        U.correctBoundaryConditions()
    else:
        pZones.addResistance(UEqn)

        from Foam.finiteVolume import solve

        eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual()

        maxResidual = max(eqnResidual, maxResidual)

        trAU = 1.0 / UEqn.A()

        from Foam.OpenFOAM import word

        trAU.rename(word("rAU"))

        pass

    return UEqn, trTU, trAU, eqnResidual, maxResidual
예제 #17
0
def fun_hEqn( turbulence, phi, h, rho, radiation, p, thermo, eqnResidual, maxResidual  ):
    
    from Foam import fvc, fvm    
    left_exp = fvm.div( phi, h ) - fvm.Sp( fvc.div( phi ), h ) - fvm.laplacian( turbulence.alphaEff(), h )
    right_exp = fvc.div( phi/fvc.interpolate( rho )*fvc.interpolate( p ) ) - p*fvc.div( phi/fvc.interpolate( rho ) ) + radiation.Sh( thermo() )
    
    hEqn = (left_exp == right_exp )

    hEqn.relax()

    eqnResidual = hEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    thermo.correct()

    radiation.correct()
    
    return hEqn, eqnResidual, maxResidual
예제 #18
0
def _UEqn(phi, U, p, turbulence, pZones, pressureImplicitPorosity, nUCorr,
          eqnResidual, maxResidual):

    from Foam import fvm, fvc
    # Construct the Momentum equation

    # The initial C++ expression does not work properly, because of
    #  1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries
    #  2. the order of expression arguments computation differs with C++
    #UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U )

    UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) -
                                          fvm.Sp(fvc.div(phi), U))

    UEqn.relax()

    # Include the porous media resistance and solve the momentum equation
    # either implicit in the tensorial resistance or transport using by
    # including the spherical part of the resistance in the momentum diagonal

    trAU = None
    trTU = None
    if pressureImplicitPorosity:
        from Foam.OpenFOAM import sphericalTensor, tensor
        tTU = tensor(sphericalTensor.I) * UEqn.A()

        pZones.addResistance(UEqn, tTU)

        trTU = tTU.inv()

        from Foam.OpenFOAM import word
        trTU.rename(word("rAU"))

        gradp = fvc.grad(p)

        for UCorr in range(nUCorr):
            U.ext_assign(trTU & (UEqn.H() - gradp))
            pass

        U.correctBoundaryConditions()
    else:
        pZones.addResistance(UEqn)

        from Foam.finiteVolume import solve
        eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual()

        maxResidual = max(eqnResidual, maxResidual)

        trAU = 1.0 / UEqn.A()

        from Foam.OpenFOAM import word
        trAU.rename(word("rAU"))

        pass

    return UEqn, trTU, trAU, eqnResidual, maxResidual
예제 #19
0
def _hEqn(thermo, phi, h, turbulence, p, rho):
    from Foam.finiteVolume import fvScalarMatrix
    from Foam import fvc, fvm

    left_expr = fvm.div(phi, h) - fvm.Sp(fvc.div(phi), h) - fvm.laplacian(turbulence.alphaEff(), h)
    from Foam.OpenFOAM import word

    right_expr = fvc.div(phi / fvc.interpolate(rho) * fvc.interpolate(p, word("div(U,p)"))) - p * fvc.div(
        phi / fvc.interpolate(rho)
    )

    hEqn = left_expr == right_expr

    hEqn.relax()

    hEqn.solve()
    thermo.correct()

    return hEqn
예제 #20
0
def _eEqn(rho, e, phi, turbulence, p, thermo):
    from Foam import fvm, fvc
    from Foam.finiteVolume import solve
    solve(
        fvm.ddt(rho, e) + fvm.div(phi, e) -
        fvm.laplacian(turbulence.alphaEff(), e) == -p *
        fvc.div(phi / fvc.interpolate(rho)))

    thermo.correct()
    pass
예제 #21
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
예제 #22
0
def _hEqn(thermo, phi, h, turbulence, p, rho, eqnResidual, maxResidual):
    from Foam.finiteVolume import fvScalarMatrix
    from Foam import fvc, fvm

    left_expr = fvm.div(phi, h) - fvm.Sp(fvc.div(phi), h) - fvm.laplacian(
        turbulence.alphaEff(), h)
    from Foam.OpenFOAM import word
    right_expr = fvc.div(phi / fvc.interpolate(rho) * fvc.interpolate(
        p, word("div(U,p)"))) - p * fvc.div(phi / fvc.interpolate(rho))

    hEqn = (left_expr == right_expr)

    hEqn.relax()

    eqnResidual = hEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    thermo.correct()

    return hEqn, eqnResidual, maxResidual
예제 #23
0
def correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue):

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField

    pcorrTypes = wordList(pd.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName)

    from Foam.finiteVolume import fixedValueFvPatchScalarField

    for i in range(pd.ext_boundaryField().size()):
        if pd.ext_boundaryField()[i].fixesValue():
            pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
            pass
        pass

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar
    from Foam.finiteVolume import volScalarField

    pcorr = volScalarField(
        IOobject(word("pcorr"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE),
        mesh,
        dimensionedScalar(word("pcorr"), pd.dimensions(), 0.0),
        pcorrTypes,
    )

    from Foam.OpenFOAM import dimTime

    rUAf = dimensionedScalar(word("(1|A(U))"), dimTime / rho.dimensions(), 1.0)

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phi, U, pcorr)

    from Foam import fvc, fvm

    for nonOrth in range(nNonOrthCorr + 1):
        pcorrEqn = fvm.laplacian(rUAf, pcorr) == fvc.div(phi)

        pcorrEqn.setReference(pdRefCell, pdRefValue)
        pcorrEqn.solve()

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

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    pass
예제 #24
0
def Ueqn( mesh, phi, U, rho, p, g, turbulence, eqnResidual, maxResidual ):
    from Foam import fvm, fvc
    UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.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
예제 #25
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, turbulence, pd, rho, gh, eqnResidual, maxResidual ):
    from Foam import fvm, fvc 
    UEqn = fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U)+ turbulence.divDevRhoReff(U)

    UEqn.relax();

    from Foam.finiteVolume import solve
    eqnResidual = solve( UEqn == -fvc.grad( pd ) - fvc.grad( rho ) * gh ).initialResidual()

    maxResidual = max(eqnResidual, maxResidual);
    
    return UEqn, eqnResidual, maxResidual
예제 #27
0
def pEqn(
    runTime, mesh, p, phi, U, UEqn, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue
):

    p.ext_boundaryField().updateCoeffs()

    AU = UEqn.A()
    U.ext_assign(UEqn.H() / AU)
    UEqn.clear()

    from Foam import fvc

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

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phi, U, p)

    # Non-orthogonal pressure corrector loop
    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm, fvc

        pEqn = fvm.laplacian(1.0 / AU, p) == fvc.div(phi)
        pEqn.setReference(pRefCell, pRefValue)

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

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

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

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

    # Momentum corrector
    U.ext_assign(U - fvc.grad(p) / AU)
    U.correctBoundaryConditions()

    return eqnResidual, maxResidual, cumulativeContErr
예제 #28
0
def _correctPhi(runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue,
                cumulativeContErr):
    if mesh.changing():
        for patchi in range(U.boundaryField().size()):
            if U.boundaryField()[patchi].fixesValue():
                U.boundaryField()[patchi].initEvaluate()
                pass
            pass
        for patchi in range(U.boundaryField().size()):
            if U.boundaryField()[patchi].fixesValue():
                U.boundaryField()[patchi].evaluate()
                phi.boundaryField()[patchi].ext_assign(
                    U.boundaryField()[patchi]
                    & mesh.Sf().boundaryField()[patchi])
                pass
            pass
        pass

    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList(p.ext_boundaryField().size(),
                          zeroGradientFvPatchScalarField.typeName)

    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range(p.ext_boundaryField().size()):
        if p.ext_boundaryField()[i].fixesValue():
            pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
            pass
        pass

    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar
    pcorr = volScalarField(
        IOobject(word("pcorr"), fileName(runTime.timeName()), mesh(),
                 IOobject.NO_READ, IOobject.NO_WRITE), mesh(),
        dimensionedScalar(word("pcorr"), p.dimensions(), 0.0), pcorrTypes)

    for nonOrth in range(nNonOrthCorr + 1):
        from Foam import fvm, fvc
        pcorrEqn = (fvm.laplacian(rAU, pcorr) == fvc.div(phi))

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

        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - pcorrEqn.flux())
            pass
        pass
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr)

    return cumulativeContErr
예제 #29
0
def _correctPhi( runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ):
    if mesh.changing():
       for patchi in range( U.boundaryField().size() ):
           if U.boundaryField()[patchi].fixesValue():
              U.boundaryField()[patchi].initEvaluate()
              pass
           pass
       for patchi in range( U.boundaryField().size() ):
           if U.boundaryField()[patchi].fixesValue():
              U.boundaryField()[patchi].evaluate()
              phi.boundaryField()[patchi].ext_assign( U.boundaryField()[patchi] & mesh.Sf().boundaryField()[patchi] )
              pass
           pass
       pass
       
    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName )
    
    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range( p.ext_boundaryField().size() ):
        if p.ext_boundaryField()[i].fixesValue():
           pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
           pass
        pass
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar
    pcorr = volScalarField( IOobject( word( "pcorr" ),
                                      fileName( runTime.timeName() ),
                                      mesh(),
                                      IOobject.NO_READ,
                                      IOobject.NO_WRITE ),
                            mesh(),
                            dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0),
                            pcorrTypes )
     
    for nonOrth in range( nNonOrthCorr + 1 ):
        from Foam import fvm,fvc
        pcorrEqn = ( fvm.laplacian( rAU, pcorr ) == fvc.div( phi ) )

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

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pcorrEqn.flux() )
           pass
        pass
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )     

    return cumulativeContErr
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
예제 #31
0
def ContinuityErrs( phi, runTime, mesh, cumulativeContErr ):
    from Foam import fvc
    contErr = fvc.div(phi)

    sumLocalContErr = runTime.deltaT().value() * contErr.mag().weightedAverage( mesh.V() ).value()

    globalContErr = runTime.deltaT().value() * contErr.weightedAverage( mesh.V() ).value();
        
    cumulativeContErr += globalContErr
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl
    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
예제 #33
0
def ContinuityErrs( phi, runTime, mesh, cumulativeContErr ):
    from Foam import fvc
    contErr = fvc.div(phi)

    sumLocalContErr = runTime.deltaT().value() * contErr.mag().weightedAverage( mesh.V() ).value()

    globalContErr = runTime.deltaT().value() * contErr.weightedAverage( mesh.V() ).value();
        
    cumulativeContErr += globalContErr
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl
    return cumulativeContErr
예제 #34
0
def _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, DpDt, cumulativeContErr, corr, nCorr, nOuterCorr, transonic ):
    rho.ext_assign( thermo.rho() )

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

    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    if transonic: 
       phid = surfaceScalarField( word( "phid" ), 
                                  fvc.interpolate( psi ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
       
       for nonOrth in range( nNonOrthCorr + 1 ) :
           pEqn = fvm.ddt( psi, p ) + fvm.div( phid, p ) - fvm.laplacian( rho * rUA, p )
           
           pEqn.solve()
           
           if nonOrth == nNonOrthCorr:
              phi == pEqn.flux()
              pass
           pass
       pass
    else:
       phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate(U) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
       
       for nonOrth in range( nNonOrthCorr + 1 ) :
           pEqn = fvm.ddt( psi, p ) + fvc.div( phi ) - fvm.laplacian( rho * rUA, p )
           
           pEqn.solve()
                      
           if nonOrth == nNonOrthCorr:
              phi.ext_assign( phi + pEqn.flux() )
              pass
           pass
       pass
        
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn( rho, phi )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )

    U.ext_assign( U - rUA * fvc.grad( p ) )
    U.correctBoundaryConditions()
    
    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )

    return cumulativeContErr
예제 #35
0
def pEqn(runTime, mesh, p, phi, U, UEqn, eqnResidual, maxResidual,
         nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue):

    p.ext_boundaryField().updateCoeffs()

    AU = UEqn.A()
    U.ext_assign(UEqn.H() / AU)
    UEqn.clear()

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

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

    # Non-orthogonal pressure corrector loop
    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm, fvc
        pEqn = fvm.laplacian(1.0 / AU, p) == fvc.div(phi)
        pEqn.setReference(pRefCell, pRefValue)

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

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

        pass

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

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

    #Momentum corrector
    U.ext_assign(U - fvc.grad(p) / AU)
    U.correctBoundaryConditions()

    return eqnResidual, maxResidual, cumulativeContErr
예제 #36
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
예제 #37
0
def correctPhi( runTime, mesh, phi, p, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue ):
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName )
    
    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range( p.ext_boundaryField().size() ):
       if p.ext_boundaryField()[i].fixesValue():
          pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
          pass
       pass
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar
    from Foam.finiteVolume import volScalarField
    pcorr = volScalarField( IOobject( word( "pcorr" ),
                                      fileName( runTime.timeName() ),
                                      mesh,
                                      IOobject.NO_READ,
                                      IOobject.NO_WRITE ),
                            mesh,
                            dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0 ),
                            pcorrTypes  )
    
    from Foam.OpenFOAM import dimTime
    rUAf = dimensionedScalar( word( "(1|A(U))" ), dimTime / rho.dimensions(), 1.0)
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phi, U, pcorr)
    
    from Foam import fvc, fvm
    for nonOrth in range( nNonOrthCorr + 1 ):
        pcorrEqn = fvm.laplacian( rUAf, pcorr ) == fvc.div( phi )

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

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi  - pcorrEqn.flux() )
           pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    pass
예제 #38
0
def pEqn(runTime, mesh, U, rUA, UEqn, phi, p, nCorr, nOuterCorr, nNonOrthCorr,
         oCorr, corr, pRefCell, pRefValue, cumulativeContErr):

    U.ext_assign(rUA * UEqn.H())
    if (nCorr <= 1):
        UEqn.clear()
        pass

    from Foam import fvc
    phi.ext_assign((fvc.interpolate(U) & mesh.Sf()) +
                   fvc.ddtPhiCorr(rUA, U, phi))

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

    # Non-orthogonal pressure corrector loop
    for nonOrth in range(nNonOrthCorr + 1):
        #Pressure corrector
        from Foam import fvm
        pEqn = fvm.laplacian(rUA, p) == fvc.div(phi)
        pEqn.setReference(pRefCell, pRefValue)

        if (oCorr == nOuterCorr - 1) and (corr == nCorr -
                                          1) and (nonOrth == nNonOrthCorr):
            from Foam.OpenFOAM import word
            pEqn.solve(mesh.solver(word("pFinal")))
            pass
        else:
            pEqn.solve()
            pass

        if (nonOrth == nNonOrthCorr):
            phi.ext_assign(phi - pEqn.flux())
            pass
        pass
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr)

    # Explicitly relax pressure for momentum corrector except for last corrector
    if (oCorr != nOuterCorr - 1):
        p.relax()
        pass

    U.ext_assign(U - rUA * fvc.grad(p))
    U.correctBoundaryConditions()

    return cumulativeContErr
def fun_TEqn( turbulence, phi, T, rhok, beta, TRef, Pr, Prt, eqnResidual, maxResidual ):
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import volScalarField
    kappaEff = volScalarField( word( "kappaEff" ),
                               turbulence.nu() / Pr + turbulence.ext_nut() / Prt )

    from Foam import fvc, fvm
    TEqn = fvm.div( phi, T ) - fvm.Sp( fvc.div( phi ), T ) - fvm.laplacian( kappaEff, T ) 

    TEqn.relax()

    eqnResidual = TEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    rhok.ext_assign( 1.0 - beta * ( T - TRef ) )
    
    return TEqn, kappaEff
예제 #40
0
def _UEqn( phi, U, p, turbulence, eqnResidual, maxResidual ):
    from Foam import fvm, fvc
    # Solve the Momentum equation
    
    # The initial C++ expression does not work properly, because of
    #  1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries
    #  2. the order of expression arguments computation differs with C++
    #UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U ) 
    UEqn = turbulence.divDevRhoReff( U ) + ( fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) )
    
    UEqn.relax()
    
    from Foam.finiteVolume import solve
    eqnResidual = solve( UEqn == -fvc.grad( p ) ).initialResidual() 

    maxResidual = max( eqnResidual, maxResidual )
   
    return UEqn, eqnResidual, maxResidual
예제 #41
0
def continuityErrs( mesh, phi, runTime, cumulativeContErr ):
    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    from Foam import fvm, fvc

    contErr = fvc.div( phi )
    sumLocalContErr = runTime.deltaT().value() * contErr.mag().weightedAverage( mesh.V() ).value()
    globalContErr = runTime.deltaT().value() * contErr.weightedAverage( mesh.V() ).value()
    cumulativeContErr += globalContErr

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr \
               << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl
               
    return cumulativeContErr
예제 #42
0
def pEqn( runTime, mesh, U, rUA, UEqn, phi, p, nCorr, nOuterCorr, nNonOrthCorr, oCorr, corr, pRefCell, pRefValue, cumulativeContErr ): 

    U.ext_assign( rUA * UEqn.H() )
    if ( nCorr <= 1 ):
       UEqn.clear()
       pass
       
    from Foam import fvc 
    phi.ext_assign( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) )
 
    from Foam.finiteVolume import adjustPhi
    adjustPhi( phi, U, p )

    # Non-orthogonal pressure corrector loop
    for nonOrth in range( nNonOrthCorr + 1):
        #Pressure corrector
        from Foam import fvm
        pEqn = fvm.laplacian( rUA, p ) == fvc.div( phi )
        pEqn.setReference( pRefCell, pRefValue )
        
        if ( oCorr == nOuterCorr-1 ) and ( corr == nCorr-1 ) and ( nonOrth == nNonOrthCorr ) :
           from Foam.OpenFOAM import word
           pEqn.solve( mesh.solver( word( "pFinal" ) ) )
           pass
        else:
           pEqn.solve()
           pass
           
        if ( nonOrth == nNonOrthCorr ) :
           phi.ext_assign( phi - pEqn.flux() )
           pass
        pass
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector except for last corrector
    if ( oCorr != nOuterCorr-1 ):
       p.relax()
       pass
       
    U.ext_assign(  U - rUA * fvc.grad( p ) )
    U.correctBoundaryConditions()

    return cumulativeContErr
예제 #43
0
def _UEqn(phi, U, p, turbulence, eqnResidual, maxResidual):
    from Foam import fvm, fvc
    # Solve the Momentum equation

    # The initial C++ expression does not work properly, because of
    #  1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries
    #  2. the order of expression arguments computation differs with C++
    #UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U )
    UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) -
                                          fvm.Sp(fvc.div(phi), U))

    UEqn.relax()

    from Foam.finiteVolume import solve
    eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual()

    maxResidual = max(eqnResidual, maxResidual)

    return UEqn, eqnResidual, maxResidual
예제 #44
0
def alphaEqnsSubCycle( runTime, piso, mesh, phi, alpha1, alpha2, rho, rho1, rho2, rhoPhi, dgdt, interface, oCorr ):
    
    from Foam.OpenFOAM import word,readLabel
    nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) )
    nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) )
    
    from Foam.finiteVolume import surfaceScalarField
    phic = ( phi / mesh.magSf() ).mag()
    phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    
    from Foam import fvc
    divU = fvc.div( phi )
    
    if nAlphaSubCycles > 1:

        totalDeltaT = runTime.deltaT()
        rhoPhiSum = 0.0 * rhoPhi

        from Foam.finiteVolume import subCycle_volScalarField
        alphaSubCycle = subCycle_volScalarField( alpha1, nAlphaSubCycles )
        for item in alphaSubCycle: 
            alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr )
            rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi )
            pass
       # To make sure that variable in the local scope will be destroyed
       # - during destruction of this variable it performs some important actions
       # - there is a difference between C++ and Python memory management, namely
       # if C++ automatically destroys stack variables when they exit the scope,
       # Python relay its memory management of some "garbage collection" algorithm
       # that do not provide predictable behavior on the "exit of scope"
        del alphaSubCycle

        rhoPhi.ext_assign( rhoPhiSum )
        pass
    else:
        alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr )
        pass

    if oCorr == 0:
       interface.correct()
       pass
    
    pass
예제 #45
0
def continuityErrs(mesh, phi, runTime, cumulativeContErr):
    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    from Foam import fvm, fvc

    contErr = fvc.div(phi)
    sumLocalContErr = runTime.deltaT().value() * contErr.mag().weightedAverage(
        mesh.V()).value()
    globalContErr = runTime.deltaT().value() * contErr.weightedAverage(
        mesh.V()).value()
    cumulativeContErr += globalContErr

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr \
               << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl

    return cumulativeContErr
def fun_TEqn(turbulence, phi, T, rhok, beta, TRef, Pr, Prt, eqnResidual,
             maxResidual):
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import volScalarField
    kappaEff = volScalarField(
        word("kappaEff"),
        turbulence.nu() / Pr + turbulence.ext_nut() / Prt)

    from Foam import fvc, fvm
    TEqn = fvm.div(phi, T) - fvm.Sp(fvc.div(phi), T) - fvm.laplacian(
        kappaEff, T)

    TEqn.relax()

    eqnResidual = TEqn.solve().initialResidual()
    maxResidual = max(eqnResidual, maxResidual)

    rhok.ext_assign(1.0 - beta * (T - TRef))

    return TEqn, kappaEff
예제 #47
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
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
예제 #50
0
def fun_pEqn(mesh, thermo, p, rho, psi, U, phi, DpDt, pMin, UEqn, mrfZones,
             nNonOrthCorr, nCorr, oCorr, nOuterCorr, corr, transonic,
             cumulativeContErr):

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

    if nCorr <= 1:
        UEqn.clear()
        pass

    if transonic:
        from Foam.finiteVolume import surfaceScalarField
        from Foam.OpenFOAM import word
        phid = surfaceScalarField(
            word("phid"),
            fvc.interpolate(psi) * ((fvc.interpolate(U) & mesh.Sf()) +
                                    fvc.ddtPhiCorr(rUA, rho, U, phi)))
        mrfZones.relativeFlux(fvc.interpolate(psi), phid)

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

            if oCorr == (nOuterCorr - 1) and (corr == nCorr -
                                              1) and (nonOrth == nNonOrthCorr):
                from Foam.OpenFOAM import word
                pEqn.solve(mesh.solver(word("pFinal")))
                pass
            else:
                pEqn.solve()
                pass

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

    else:
        from Foam import fvc
        phi.ext_assign(
            fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf())))
        mrfZones.relativeFlux(fvc.interpolate(rho), phi)

        from Foam import fvm
        for nonOrth in range(nNonOrthCorr + 1):
            # Pressure corrector
            pEqn = fvm.ddt(psi, p) + fvc.div(phi) - fvm.laplacian(rho * rUA, p)

            if oCorr == (nOuterCorr - 1) and corr == (
                    nCorr - 1) and nonOrth == nNonOrthCorr:
                from Foam.OpenFOAM import word
                pEqn.solve(mesh.solver(word("pFinal")))
                pass
            else:
                pEqn.solve()
                pass

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

    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn(rho, phi)

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

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

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

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << nl

    U.ext_assign(U - rUA * fvc.grad(p))
    U.correctBoundaryConditions()

    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    DpDt.ext_assign(
        fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)),
                p))

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

    pass
예제 #51
0
def rhoEqn(rho, phi):
    from Foam import fvm, fvc
    from Foam.finiteVolume import solve
    solve(fvm.ddt(rho) + fvc.div(phi))

    pass
예제 #52
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 = readThermodynamicProperties( runTime, mesh )

    p, T, U, psi, rho, rhoU, rhoE = _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.timeName() << nl << nl
        
        from Foam.finiteVolume import surfaceScalarField
        from Foam.OpenFOAM import IOobject, word, fileName
        from Foam import fvc
        phiv = surfaceScalarField( IOobject( word( "phiv" ),
                                             fileName( runTime.timeName() ),
                                             mesh,
                                             IOobject.NO_READ,
                                             IOobject.NO_WRITE ),
                                   fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() )
        
        CoNum = ( mesh.deltaCoeffs() * phiv.mag() / mesh.magSf() ).ext_max().value()*runTime.deltaT().value();
        ext_Info() << "\nMax Courant Number = " << CoNum << nl
        
        from Foam import fvm
        
        from Foam.finiteVolume import solve
        solve( fvm.ddt(rho) + fvm.div( phiv, rho ) )
        
        p.ext_assign( rho / psi )
        
        solve( fvm.ddt( rhoU ) + fvm.div( phiv, rhoU ) == - fvc.grad( p ) )

        U == rhoU / rho
        
        phiv2 = surfaceScalarField( IOobject( word( "phiv2" ),
                                              fileName( runTime.timeName() ),
                                              mesh,
                                              IOobject.NO_READ,
                                              IOobject.NO_WRITE ),
                                    fvc.interpolate( rhoU ) / fvc.interpolate( rho ) & mesh.Sf() )
        
        solve( fvm.ddt( rhoE ) + fvm.div( phiv, rhoE ) == - fvc.div( phiv2, p ) )
        
        T.ext_assign( ( rhoE - 0.5 * rho * ( rhoU / rho ).magSqr() ) / Cv / rho )
        
        psi.ext_assign( 1.0 / ( R * T ) )
        
        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
예제 #53
0
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
예제 #54
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.dynamicFvMesh import createDynamicFvMesh
    mesh = createDynamicFvMesh(runTime)

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

    from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
    cumulativeContErr = initContinuityErrs()

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

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

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

    while runTime.run():

        adjustTimeStep, maxCo, maxDeltaT, pimple, nOuterCorr, nCorr, nNonOrthCorr, \
                        momentumPredictor, transonic, correctPhi, checkMeshCourantNo = readControls( runTime, mesh )

        from Foam.finiteVolume.cfdTools.general.include import CourantNo
        CoNum, meanCoNum = CourantNo(mesh, phi, runTime)

        # Make the fluxes absolute
        from Foam import fvc
        fvc.makeAbsolute(phi, U)

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

        runTime.increment()

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

        mesh.update()

        if mesh.changing() and correctPhi:
            cumulativeContErr = _correctPhi(runTime, mesh, p, rAU, phi,
                                            nNonOrthCorr, pRefCell, pRefValue,
                                            cumulativeContErr)
            pass

        # Make the fluxes relative to the mesh motion
        fvc.makeRelative(phi, U)

        if mesh.changing() and checkMeshCourantNo:
            from Foam.dynamicFvMesh import meshCourantNo
            meshCoNum, meanMeshCoNum = meshCourantNo(runTime, mesh, phi)
            pass

        from Foam import fvm
        #PIMPLE loop
        for ocorr in range(nOuterCorr):
            if nOuterCorr != 1:
                p.storePrevIter()
                pass
            UEqn = _UEqn(mesh, phi, U, p, turbulence, ocorr, nOuterCorr,
                         momentumPredictor)

            # --- PISO loop
            for corr in range(nCorr):
                rAU.ext_assign(1.0 / UEqn.A())

                U.ext_assign(rAU * UEqn.H())
                phi.ext_assign(fvc.interpolate(U) & mesh.Sf())

                if p.needReference():
                    fvc.makeRelative(phi, U)
                    adjustPhi(phi, U, p)
                    fvc.makeAbsolute(phi, U)
                    pass

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

                    pEqn.setReference(pRefCell, pRefValue)

                    if ocorr == nOuterCorr - 1 and 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

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

                # Explicitly relax pressure for momentum corrector
                if ocorr != nOuterCorr - 1:
                    p.relax()
                    pass

                # Make the fluxes relative to the mesh motion
                fvc.makeRelative(phi, U)
                U.ext_assign(U - rAU * fvc.grad(p))
                U.correctBoundaryConditions()
                pass
            pass

        turbulence.correct()

        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
예제 #55
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
예제 #56
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
예제 #57
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 createMeshNoClear
    mesh = createMeshNoClear( runTime )
    
    p, U, phi, fluid, pRefCell, pRefValue = _createFields( runTime, mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
    cumulativeContErr = initContinuityErrs()
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl 
    
    while runTime.loop() :
        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        
        from Foam.finiteVolume.cfdTools.general.include import readPISOControls
        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh ) 
        
        from Foam.finiteVolume.cfdTools.incompressible import CourantNo
        CoNum, meanCoNum, velMag = CourantNo( mesh, phi, runTime )
        
        fluid.correct()
        from Foam import fvm, fvc
        
        UEqn = fvm.ddt( U ) + fvm.div( phi, U ) - fvm.laplacian( fluid.ext_nu(), U )
        
        from Foam.finiteVolume import solve
        solve( UEqn == -fvc.grad( p ) )
        
        # --- PISO loop

        for corr in range( nCorr ):
            rUA = 1.0 / UEqn.A()
            U.ext_assign( rUA * UEqn.H() )
            phi.ext_assign( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, U, phi ) )
            
            from Foam.finiteVolume import adjustPhi
            adjustPhi(phi, U, p)
            
            for nonOrth in range( nNonOrthCorr + 1): 
                
                pEqn = ( fvm.laplacian( rUA, p ) == fvc.div( phi ) )
                
                pEqn.setReference( pRefCell, pRefValue )
                pEqn.solve()

                if nonOrth == nNonOrthCorr:
                   phi.ext_assign( phi - pEqn.flux() )
                   pass
                
                pass
                
            from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
            cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )     
               
            U.ext_assign( U - rUA * fvc.grad( p ) )
            U.correctBoundaryConditions()
            pass
        
        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