Ejemplo n.º 1
0
def fun_UEqn(mesh, pZones, rho, U, phi, turbulence, mrfZones, p,
             momentumPredictor, oCorr, nOuterCorr):

    from Foam import fvm
    UEqn = pZones.ddt(rho, U) + fvm.div(phi, U) + turbulence.divDevRhoReff(U)

    if oCorr == nOuterCorr - 1:
        UEqn.relax(1.0)
        pass
    else:
        UEqn.relax()
        pass

    mrfZones.addCoriolis(rho, UEqn)
    pZones.addResistance(UEqn)

    rUA = 1.0 / UEqn.A()

    if momentumPredictor:
        from Foam import fvc
        from Foam.finiteVolume import solve
        if oCorr == nOuterCorr - 1:
            from Foam.OpenFOAM import word
            solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal")))
            pass
        else:
            solve(UEqn == -fvc.grad(p))
            pass
    else:
        U.ext_assign(rUA * (UEqn.H() - fvc.grad(p)))
        U.correctBoundaryConditions()
        pass

    return UEqn
Ejemplo n.º 2
0
def Ueqn( mesh, phi, U, p, turbulence, oCorr, nOuterCorr, momentumPredictor ):
    from Foam import fvm, fvc
    UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U)
    
    if ( oCorr == nOuterCorr - 1 ):
       UEqn.relax( 1.0 )
       pass
    else:
       UEqn.relax()
       pass
    
    rUA = 1.0/UEqn.A()
    
    from Foam.finiteVolume import solve
    if momentumPredictor:
       if ( oCorr == nOuterCorr - 1 ):
          from Foam.OpenFOAM import word
          solve( UEqn == -fvc.grad(p), mesh.solver( word( "UFinal" ) ) )
          pass
       else:
          solve( UEqn == -fvc.grad(p))
          pass
    else:
       U.ext_assign( rUA * ( UEqn.H() - fvc.grad( p ) ) )
       U.correctBoundaryConditions()
       pass
    
    return UEqn, rUA
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
def Ueqn(mesh, phi, U, p, turbulence, oCorr, nOuterCorr, momentumPredictor):
    from Foam import fvm, fvc
    UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U)

    if (oCorr == nOuterCorr - 1):
        UEqn.relax(1.0)
        pass
    else:
        UEqn.relax()
        pass

    rUA = 1.0 / UEqn.A()

    from Foam.finiteVolume import solve
    if momentumPredictor:
        if (oCorr == nOuterCorr - 1):
            from Foam.OpenFOAM import word
            solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal")))
            pass
        else:
            solve(UEqn == -fvc.grad(p))
            pass
    else:
        U.ext_assign(rUA * (UEqn.H() - fvc.grad(p)))
        U.correctBoundaryConditions()
        pass

    return UEqn, rUA
Ejemplo n.º 5
0
def fun_UEqn( mesh, pZones, rho, U, phi, turbulence, mrfZones, p, momentumPredictor, oCorr, nOuterCorr ):
    
    from Foam import fvm
    UEqn = pZones.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )
    
    if oCorr == nOuterCorr-1:
       UEqn.relax( 1.0 )
       pass
    else:
       UEqn.relax()
       pass
    
    mrfZones.addCoriolis( rho, UEqn )
    pZones.addResistance( UEqn )
    
    rUA = 1.0 / UEqn.A()
    
    if momentumPredictor:
       from Foam import fvc
       from Foam.finiteVolume import solve
       if oCorr == nOuterCorr-1:
          from Foam.OpenFOAM import word
          solve( UEqn == -fvc.grad( p ), mesh.solver( word( "UFinal" ) ) )
          pass
       else:
          solve( UEqn == -fvc.grad( p ) )
          pass
    else:
       U.ext_assign( rUA * ( UEqn.H() - fvc.grad( p ) ) )
       U.correctBoundaryConditions()
       pass
    
    return UEqn
def fun_pEqn( runTime, thermo, UEqn, U, phi, rho, gh, pd, p, initialMass, mesh, pRef, nNonOrthCorr, \
              pdRefCell, pdRefValue, eqnResidual, maxResidual, cumulativeContErr ):
    
    rUA = 1.0/UEqn.A()
    U.ext_assign( rUA * UEqn().H() )
    
    UEqn.clear()
    from Foam import fvc
    phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) )
    
    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi(phi, U, p)
    
    phi.ext_assign( phi - fvc.interpolate( rho *gh * rUA ) * fvc.snGrad( rho ) * mesh.magSf() )
    
    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1):
        pdEqn = ( fvm.laplacian( rho * rUA, pd ) == fvc.div(phi) )
        
        pdEqn.setReference(pdRefCell, pdRefValue)
        # retain the residual from the first iteration    
        
        if nonOrth == 0:
           eqnResidual = pdEqn.solve().initialResidual()
           maxResidual = max(eqnResidual, maxResidual)
           pass
        else:
           pdEqn.solve()
           pass
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pdEqn.flux() )
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    pd.relax()
    
    p.ext_assign( pd + rho * gh + pRef )
    
    U.ext_assign( U- rUA * ( fvc.grad( pd ) + fvc.grad( rho ) * gh ) )
    U.correctBoundaryConditions()
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( thermo.psi() * p ) ) / fvc.domainIntegrate( thermo.psi() ) )
    
    rho.ext_assign( thermo.rho() )
    rho.relax()
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
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
Ejemplo n.º 12
0
def globalProperties(runTime, U, nu, force):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam import fvc
    ext_Info() << "k(" << runTime.timeName(
    ) << ") = " << 3.0 / 2.0 * U.magSqr().average().value() << nl

    ext_Info() << "epsilon(" << runTime.timeName() << ") = " << (0.5 * nu * (
        (fvc.grad(U) + fvc.grad(U).T()).magSqr()).average()).value() << nl

    ext_Info() << "U.f(" << runTime.timeName() << ") = " << 181.0 * (
        U & force).average().value() << nl
    pass
Ejemplo n.º 13
0
def solveMomentumEquation( momentumPredictor, U, rho, phi, pd, gh, turb ):
    # 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.grad(pd) - fvc.grad(rho) * gh )
        pass
    
    return UEqn
Ejemplo n.º 14
0
def fun_pEqn( i, fluidRegions, Uf, pdf, rhof, thermof, phif, ghf, Kf, DpDtf, turb, initialMassf, UEqn, pRef, corr, nCorr, nNonOrthCorr, cumulativeContErr ) :
    
    closedVolume = False

    rhof[ i ].ext_assign( thermof[ i ].rho() )
    rUA = 1.0 / UEqn.A()
    Uf[ i ].ext_assign( rUA * UEqn.H() )

    from Foam import fvc
    phif[ i ] .ext_assign( fvc.interpolate( rhof[ i ] ) * ( ( fvc.interpolate( Uf[ i ] ) & fluidRegions[ i ].Sf() ) + 
                                                                      fvc.ddtPhiCorr( rUA, rhof[ i ], Uf[ i ], phif[ i ] ) ) - 
                                            fvc.interpolate( rhof[ i ] * rUA * ghf[ i ] ) * fvc.snGrad( rhof[ i ] ) * fluidRegions[ i ].magSf() )
    
    # Solve pressure difference
    pdEqn, closedVolume = fun_pdEqn( corr, nCorr, nNonOrthCorr, closedVolume, pdf[i], pRef, rhof[i], thermof[i].psi(), rUA, ghf[i], phif[i] )
    
    # Solve continuity
    rhoEqn( rhof[i], phif[i] )
    
    # Update pressure field (including bc)
    from Foam.OpenFOAM import word
    thermof[i].p() == pdf[ i ] + rhof[ i ] * ghf[ i ] + pRef
    
    from Foam.finiteVolume import surfaceScalarField
    DpDtf[i].ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phif[ i ] / fvc.interpolate( rhof[ i ] ) ), thermof[i].p() ) )

    # Update continuity errors
    cumulativeContErr = compressibleContinuityErrors( cumulativeContErr, rhof[i], thermof[i] )
        
    # Correct velocity field
    Uf[ i ].ext_assign( Uf[i] - rUA * ( fvc.grad( pdf[ i ] ) + fvc.grad( rhof[ i ] ) * ghf[ i ] ) )
    Uf[ i ].correctBoundaryConditions()
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if (closedVolume):
       from Foam.OpenFOAM import dimensionedScalar, dimMass
       thermof[i].p().ext_assign( thermof[i].p() + 
                                  ( dimensionedScalar( word( "massIni" ),
                                                       dimMass,
                                                       initialMassf[ i ] ) - fvc.domainIntegrate( thermof[ i ].psi() * thermof[ i ].p() ) )
                                  / fvc.domainIntegrate( thermof[ i ].psi() ) )
       rhof[ i ].ext_assign( thermof[ i ].rho() )
    
    # Update thermal conductivity
    Kf[i].ext_assign( rhof[ i ] * thermof[ i ].Cp() * turb[ i ].alphaEff() )

    return cumulativeContErr
Ejemplo n.º 15
0
def write( runTime, mesh, T ):
    if runTime.outputTime():
       from Foam import fvc
       gradT = fvc.grad(T)
       
       from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
       from Foam.finiteVolume import volScalarField
       from Foam.OpenFOAM import vector
       gradTx = volScalarField( IOobject( word( "gradTx" ), 
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                          gradT.component( vector.X ) )
       gradTy = volScalarField( IOobject( word( "gradTy" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Y ) )

       gradTz = volScalarField( IOobject( word( "gradTz" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Z ) )
       runTime.write()
       pass
Ejemplo n.º 16
0
def fun_UEqn(mesh, U, p_rgh, ghf, rho, rhoPhi, turbulence, twoPhaseProperties, momentumPredictor, finalIter):
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc

    muEff = surfaceScalarField(word("muEff"), twoPhaseProperties.muf() + fvc.interpolate(rho * turbulence.ext_nut()))

    from Foam import fvm, fvc

    UEqn = fvm.ddt(rho, U) + fvm.div(rhoPhi, U) - fvm.laplacian(muEff, U) - (fvc.grad(U) & fvc.grad(muEff))

    if finalIter:
        UEqn.relax(1.0)
        pass
    else:
        UEqn.relax()
        pass

    if momentumPredictor:
        from Foam.finiteVolume import solve

        solve(
            UEqn == fvc.reconstruct((-ghf * fvc.snGrad(rho) - fvc.snGrad(p_rgh)) * mesh.magSf()),
            mesh.solver(U.select(finalIter)),
        )
        pass

    return UEqn
Ejemplo n.º 17
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
Ejemplo n.º 18
0
def _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr ):
    from Foam.finiteVolume import volScalarField
    rUA = 1.0/UEqn.A()
    U.ext_assign( rUA*UEqn.H() )
            
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phid = surfaceScalarField( word( "phid" ), 
                               fvc.interpolate( thermo.psi() ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
    
    
    for nonOrth in range( nNonOrthCorr + 1 ) :
        from Foam import fvm
        pEqn = ( fvm.ddt(psi, p) + fvm.div(phid, word( "div(phid,p)" ) ) - fvm.laplacian(rho*rUA, p) )
        pEqn.solve()
        if (nonOrth == nNonOrthCorr) :
           phi.ext_assign( 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 )
           
    U.ext_assign( U - rUA * fvc.grad(p) )
    U.correctBoundaryConditions()
    
    return cumulativeContErr
Ejemplo n.º 19
0
def _pEqn(rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p,
          cumulativeContErr):
    from Foam.finiteVolume import volScalarField
    rUA = 1.0 / UEqn.A()
    U.ext_assign(rUA * UEqn.H())

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

    for nonOrth in range(nNonOrthCorr + 1):
        from Foam import fvm
        pEqn = (fvm.ddt(psi, p) + fvm.div(phid, word("div(phid,p)")) -
                fvm.laplacian(rho * rUA, p))
        pEqn.solve()
        if (nonOrth == nNonOrthCorr):
            phi.ext_assign(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)

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

    return cumulativeContErr
Ejemplo n.º 20
0
def Ueqn( phi, U, p, turbulence ):
    from Foam import fvm, fvc
    UEqn = fvm.div( phi, U ) + turbulence.divR( U ) 
    UEqn.relax()
    from Foam.finiteVolume import solve
    solve( UEqn == -fvc.grad(p) )
           
    return UEqn
Ejemplo n.º 21
0
def _UEqn(U, rho, phi, turbulence, p):
    from Foam import fvm
    UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) + turbulence.divDevRhoReff(U)

    from Foam import fvc
    from Foam.finiteVolume import solve
    solve(UEqn == -fvc.grad(p))
    return UEqn
Ejemplo n.º 22
0
def _UEqn( U, rho, phi, turbulence, p ):
    from Foam import fvm    
    UEqn = fvm.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )
    
    from Foam import fvc
    from Foam.finiteVolume import solve
    solve( UEqn == -fvc.grad( p ) )
    return UEqn
Ejemplo n.º 23
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
Ejemplo n.º 24
0
def globalProperties( runTime, U, nu, force ):
    from Foam.OpenFOAM import ext_Info, nl    
    from Foam import fvc
    ext_Info() << "k(" << runTime.timeName()  << ") = " << 3.0 / 2.0 * U.magSqr().average().value() << nl

    ext_Info() << "epsilon(" << runTime.timeName() << ") = " << ( 0.5 * nu * ( ( fvc.grad( U ) + fvc.grad( U ).T() ).magSqr() ).average() ).value() << nl

    ext_Info() << "U.f(" << runTime.timeName() << ") = " << 181.0 * ( U & force ).average().value() << nl
    pass
Ejemplo n.º 25
0
def Ueqn(phi, U, p, turbulence):
    from Foam import fvm, fvc

    UEqn = fvm.div(phi, U) + turbulence.divR(U)
    UEqn.relax()
    from Foam.finiteVolume import solve

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

    return UEqn
Ejemplo n.º 26
0
def Ueqn(phi, U, p, turbulence, eqnResidual, maxResidual):
    from Foam import fvm, fvc
    UEqn = fvm.div(phi, U) + turbulence.divDevReff(U)

    UEqn.relax()

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

    return UEqn, eqnResidual, maxResidual
Ejemplo n.º 27
0
def Ueqn( phi, U, p, turbulence, eqnResidual, maxResidual ):
    from Foam import fvm, fvc
    UEqn = fvm.div( phi, U ) + turbulence.divDevReff( U ) 

    UEqn.relax()
    
    from Foam.finiteVolume import solve
    eqnResidual = solve( UEqn == -fvc.grad(p) ).initialResidual()
    maxResidual = max(eqnResidual, maxResidual)
      
    return UEqn, eqnResidual, maxResidual
Ejemplo n.º 28
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
Ejemplo n.º 29
0
def _UEqn(mesh, alpha1, U, pd, rho, rhoPhi, turbulence, ghf,
          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( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) - fvc.snGrad( pd ) ) * mesh.magSf() ) )
        pass

    return UEqn
Ejemplo n.º 30
0
def _UEqn(mesh, U, rho, phi, turbulence, p, oCorr, nOuterCorr, momentumPredictor):
    from Foam import fvm

    # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )

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

    if oCorr == nOuterCorr - 1:
        UEqn().relax(1.0)
        pass
    else:
        UEqn().relax()
        pass

    rUA = 1.0 / UEqn.A()

    from Foam.finiteVolume import solve
    from Foam.OpenFOAM import word
    from Foam import fvc

    if momentumPredictor:
        if oCorr == nOuterCorr - 1:
            solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal")))
            pass
        else:
            solve(UEqn == -fvc.grad(p))
            pass
    else:
        U.ext_assign(rUA * (UEqn.H() - fvc.grad(p)))
        U.correctBoundaryConditions()
        pass

    return UEqn
Ejemplo n.º 31
0
def _UEqn(mesh, U, rho, phi, turbulence, p, oCorr, nOuterCorr,
          momentumPredictor):
    from Foam import fvm
    # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )

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

    if oCorr == nOuterCorr - 1:
        UEqn().relax(1.0)
        pass
    else:
        UEqn().relax()
        pass

    rUA = 1.0 / UEqn.A()

    from Foam.finiteVolume import solve
    from Foam.OpenFOAM import word
    from Foam import fvc
    if momentumPredictor:
        if oCorr == nOuterCorr - 1:
            solve(UEqn == -fvc.grad(p), mesh.solver(word("UFinal")))
            pass
        else:
            solve(UEqn == -fvc.grad(p))
            pass
    else:
        U.ext_assign(rUA * (UEqn.H() - fvc.grad(p)))
        U.correctBoundaryConditions()
        pass

    return UEqn
Ejemplo n.º 32
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
Ejemplo n.º 33
0
def _UEqn( mesh, phi, U, p, turbulence, ocorr, nOuterCorr, momentumPredictor ):
    from Foam import fvm
    UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff( U ) 
    
    if ocorr != nOuterCorr - 1:
       UEqn.relax()
       pass
    
    if momentumPredictor:
       from Foam.finiteVolume import solve
       from Foam import fvc
       solve( UEqn == -fvc.grad( p ) )
       pass
    
    return UEqn
Ejemplo n.º 34
0
def _UEqn(mesh, phi, U, p, turbulence, ocorr, nOuterCorr, momentumPredictor):
    from Foam import fvm
    UEqn = fvm.ddt(U) + fvm.div(phi, U) + turbulence.divDevReff(U)

    if ocorr != nOuterCorr - 1:
        UEqn.relax()
        pass

    if momentumPredictor:
        from Foam.finiteVolume import solve
        from Foam import fvc
        solve(UEqn == -fvc.grad(p))
        pass

    return UEqn
Ejemplo n.º 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
Ejemplo n.º 36
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
Ejemplo n.º 37
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
Ejemplo n.º 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
Ejemplo n.º 39
0
def _UEqn( U, rho, phi, turbulence, p, momentumPredictor ):
    from Foam import fvm
    # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )
    
    UEqn = turbulence.divDevRhoReff( U ) + ( fvm.ddt( rho, U ) + fvm.div( phi, U ) )

    from Foam.finiteVolume import solve
    if momentumPredictor:
       from Foam.finiteVolume import solve
       from Foam import fvc
       solve( UEqn == -fvc.grad( p ) )
       pass
   
    return UEqn
Ejemplo n.º 40
0
def _UEqn(U, rho, phi, turbulence, p, momentumPredictor):
    from Foam import fvm
    # 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.ddt( rho, U ) + fvm.div( phi, U ) + turbulence.divDevRhoReff( U )

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

    from Foam.finiteVolume import solve
    if momentumPredictor:
        from Foam.finiteVolume import solve
        from Foam import fvc
        solve(UEqn == -fvc.grad(p))
        pass

    return UEqn
Ejemplo n.º 41
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
Ejemplo n.º 42
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
Ejemplo n.º 43
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
Ejemplo n.º 44
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
Ejemplo n.º 45
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)

    transportProperties, mu = readingTransportProperties(runTime, mesh)

    p, T, e, U, psi, rho, phi = _createFields(runTime, mesh, R, Cv)

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

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

    runTime.increment()
    while not runTime.end():
        ext_Info() << "Time = " << runTime.timeName() << nl << nl

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

        from Foam.finiteVolume.cfdTools.compressible import compressibleCourantNo
        CoNum, meanCoNum = compressibleCourantNo(mesh, phi, rho, runTime)

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

        from Foam import fvm
        UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) - fvm.laplacian(mu, U)

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

        solve( fvm.ddt( rho, e ) + fvm.div( phi, e ) - fvm.laplacian( mu, e ) == \
               - p * fvc.div( phi / fvc.interpolate( rho ) ) + mu * fvc.grad( U ).symm().magSqr() )

        T.ext_assign(e / Cv)

        psi.ext_assign(1.0 / (R * T))

        # --- PISO loop
        for corr in range(nCorr):
            rUA = 1.0 / UEqn.A()
            U.ext_assign(rUA * UEqn.H())

            from Foam.OpenFOAM import word
            phid = ((fvc.interpolate(rho * U) & mesh.Sf()) +
                    fvc.ddtPhiCorr(rUA, rho, U, phi)) / fvc.interpolate(p)
            print "111111111111"
            for nonOrth in range(nNonOrthCorr + 1):
                pEqn = fvm.ddt(psi, p) + fvm.div(
                    phid, p, word("div(phid,p)")) - fvm.laplacian(
                        rho * rUA, p)

                pEqn.solve()
                phi = pEqn.flux()
                pass

            cumulativeContErr = compressibleContinuityErrs(
                p, rho, phi, psi, cumulativeContErr)

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

            pass

        rho.ext_assign(psi * p)

        runTime.write()

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

        runTime.increment()
        pass

    ext_Info() << "End\n"

    import os
    return os.EX_OK
Ejemplo n.º 46
0
def _pEqn(
    rho,
    thermo,
    UEqn,
    nNonOrthCorr,
    psi,
    U,
    mesh,
    phi,
    p,
    DpDt,
    pMin,
    corr,
    cumulativeContErr,
    nCorr,
    oCorr,
    nOuterCorr,
    transonic,
):
    rho.ext_assign(thermo.rho())

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

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

    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField

    if transonic:

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

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

            if oCorr == nOuterCorr - 1 and corr == nCorr - 1 and nonOrth == nNonOrthCorr:
                pEqn.solve(mesh.solver(word("pFinal")))
                pass
            else:
                pEqn.solve()
                pass
            if nonOrth == nNonOrthCorr:
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi.ext_assign(fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf())))

        for nonOrth in range(nNonOrthCorr + 1):
            # Pressure corrector
            pEqn = fvm.ddt(psi, p) + fvc.div(phi) - fvm.laplacian(rho * rUA, p)
            if oCorr == nOuterCorr - 1 and corr == nCorr - 1 and nonOrth == nNonOrthCorr:
                pEqn.solve(mesh.solver(word("pFinal")))
                pass
            else:
                pEqn.solve()
                pass

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

    from Foam.finiteVolume.cfdTools.compressible import rhoEqn

    rhoEqn(rho, phi)

    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs

    cumulativeContErr = compressibleContinuityErrs(rho, thermo, cumulativeContErr)

    p.relax()

    rho.ext_assign(thermo.rho())
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl

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

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

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

    from Foam.finiteVolume import bound

    bound(p, pMin)

    return cumulativeContErr
Ejemplo n.º 47
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
Ejemplo n.º 48
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, rho0, p0, psi, rhoO = readThermodynamicProperties(
        runTime, mesh)

    transportProperties, mu = readTransportProperties(runTime, mesh)

    p, U, rho, phi = _createFields(runTime, mesh, rhoO, psi)

    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.compressible import compressibleCourantNo
        CoNum, meanCoNum, velMag = compressibleCourantNo(
            mesh, phi, rho, runTime)

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

        from Foam import fvm, fvc
        from Foam.finiteVolume import solve
        UEqn = fvm.ddt(rho, U) + fvm.div(phi, U) - fvm.laplacian(mu, U)

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

        for corr in range(nCorr):
            rUA = 1.0 / UEqn.A()
            U.ext_assign(rUA * UEqn.H())

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

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

            phi.ext_assign((rhoO / psi) * phid)

            pEqn = fvm.ddt(psi, p) + fvc.div(phi) + fvm.div(
                phid, p) - fvm.laplacian(rho * rUA, p)

            pEqn.solve()

            phi.ext_assign(phi + pEqn.flux())

            cumulativeContErr = compressibleContinuityErrs(
                rho, phi, psi, rho0, p, p0, cumulativeContErr)

            U.ext_assign(U - rUA * fvc.grad(p))
            U.correctBoundaryConditions()
            pass
        rho.ext_assign(rhoO + psi * p)

        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
Ejemplo n.º 49
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)

    transportProperties, nu = readTransportProperties(runTime, mesh)

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

    turbulenceProperties, force, K, forceGen = readTurbulenceProperties(
        runTime, mesh, U)

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

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

    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.randomProcesses import fft
        from Foam.OpenFOAM import ReImSum
        force.internalField().ext_assign(
            ReImSum(
                fft.reverseTransform(
                    K / (K.mag() + 1.0e-6) ^ forceGen.newField(), K.nn())))

        globalProperties(runTime, U, nu, force)

        from Foam import fvm
        UEqn = fvm.ddt(U) + fvm.div(phi, U) - fvm.laplacian(nu, U) == force

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

        # --- PISO loop

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

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

            pEqn = fvm.laplacian(rUA, p) == fvc.div(phi)

            pEqn.solve()

            phi.ext_assign(phi - pEqn.flux())

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

        if runTime.outputTime():
            from Foam.randomProcesses import calcEk
            from Foam.OpenFOAM import word, fileName
            calcEk(U, K).write(fileName(runTime.timePath() / fileName("Ek")),
                               runTime.graphFormat())
            pass

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

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

    import os
    return os.EX_OK
Ejemplo n.º 50
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
Ejemplo n.º 51
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
Ejemplo n.º 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 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
Ejemplo n.º 53
0
def main_standalone( argc, argv ):

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

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

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

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

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

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

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

        phi = None

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

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

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

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

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

           solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( thermo.alpha(), e ) \
                                         + (- fvm.laplacian( thermo.alpha(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )
           
           thermo.correct()
           rhoE.ext_assign( rho * ( e + 0.5 * U.magSqr() ) )
           pass
        
        p.dimensionedInternalField().ext_assign( rho.dimensionedInternalField() / psi.dimensionedInternalField() )
        p.correctBoundaryConditions()
        rho.ext_boundaryField().ext_assign( psi.ext_boundaryField() * p.ext_boundaryField() )
        
        runTime.write()

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

    ext_Info() << "End\n"

    import os
    return os.EX_OK
Ejemplo n.º 54
0
def _pEqn(
    mesh,
    rho,
    thermo,
    p,
    U,
    trTU,
    trAU,
    UEqn,
    phi,
    runTime,
    pMin,
    pressureImplicitPorousity,
    nNonOrthCorr,
    eqnResidual,
    maxResidual,
    cumulativeContErr,
    initialMass,
    pRefCell,
    pRefValue,
):

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

    UEqn.clear()

    from Foam import fvc, fvm

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

    from Foam.finiteVolume import adjustPhi

    closedVolume = adjustPhi(phi, U, p)

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

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

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

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

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

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

    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound

    bound(p, pMin)

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

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

    from Foam.OpenFOAM import ext_Info, nl

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

    return eqnResidual, maxResidual
Ejemplo n.º 55
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)

    U, phi, laminarTransport, turbulence, Ubar, wallNormal, flowDirection, flowMask, y, gradP = _createFields(
        runTime, mesh)

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

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

        divR = turbulence.divDevReff(U)
        from Foam.OpenFOAM import vectorField
        tmp = flowMask & divR.source()
        divR.source().ext_assign(tmp)

        UEqn = divR == gradP
        UEqn.relax()

        UEqn.solve()

        # Correct driving force for a constant mass flow rate

        UbarStar = flowMask & U.weightedAverage(mesh.V())

        U.ext_assign(U + (Ubar - UbarStar))
        gradP += (Ubar - UbarStar) / (1.0 / UEqn.A()).weightedAverage(mesh.V())

        id_ = y.size() - 1

        wallShearStress = flowDirection & turbulence.R()()[id_] & wallNormal
        from Foam.OpenFOAM import mag
        from math import sqrt
        yplusWall = sqrt(
            mag(wallShearStress)) * y()[id_] / turbulence.nuEff()()[id_]

        ext_Info() << "Uncorrected Ubar = " << ( flowDirection & UbarStar.value() )<< "       " \
            << "pressure gradient = " << ( flowDirection & gradP.value() ) << "      " \
            << "min y+ = " << yplusWall << nl

        turbulence.correct()

        if runTime.outputTime():
            from Foam.finiteVolume import volSymmTensorField
            from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
            R = volSymmTensorField(
                IOobject(word("R"), fileName(runTime.timeName()),
                         mesh, IOobject.NO_READ, IOobject.AUTO_WRITE),
                turbulence.R())

            runTime.write()

            gFormat = runTime.graphFormat()

            from Foam.sampling import makeGraph

            makeGraph(y, flowDirection & U, word("Uf"), gFormat)

            makeGraph(y, laminarTransport.ext_nu(), gFormat)

            makeGraph(y, turbulence.ext_k(), gFormat)

            makeGraph(y, turbulence.ext_epsilon(), gFormat)

            from Foam.OpenFOAM import tensor
            makeGraph(y, R.component(tensor.XY), word("uv"), gFormat)
            from Foam import fvc
            makeGraph(y, fvc.grad(U).mag(), word("gammaDot"), gFormat)

            runTime.write()

            pass

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

        pass

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

    import os
    return os.EX_OK
Ejemplo n.º 56
0
def _pEqn( mesh, rho, thermo, p, U, trTU, trAU, UEqn, phi, \
           runTime, pMin, pressureImplicitPorosity, nNonOrthCorr, eqnResidual, maxResidual, cumulativeContErr, initialMass, pRefCell, pRefValue ):

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

    UEqn.clear()

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

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

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

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

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

        pass

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

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

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

    U.correctBoundaryConditions()

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

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

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

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

    return eqnResidual, maxResidual