Пример #1
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()
Пример #2
0
def main_standalone( argc, argv ):

    from Foam.OpenFOAM import argList, word
    argList.validOptions.fget().insert( word( "writep" ), "" )
    
    from Foam.OpenFOAM.include import setRootCase
    args = setRootCase( argc, argv )

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

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

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

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

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

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

    import os
    return os.EX_OK
Пример #3
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
Пример #4
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
def fun_pEqn(runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual,
             nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue):

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

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

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

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

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

    phi.ext_assign(phi + buoyancyPhi)

    for nonOrth in range(nNonOrthCorr + 1):

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

        pEqn.setReference(pRefCell, pRefValue)

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

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

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

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

        pass

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

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

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

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

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

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

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

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    return eqnResidual, maxResidual, cumulativeContErr
Пример #7
0
def correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue):

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

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

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

    from Foam.finiteVolume import fixedValueFvPatchScalarField

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

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

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

    from Foam.OpenFOAM import dimTime

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

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phi, U, pcorr)

    from Foam import fvc, fvm

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

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

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

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    pass
Пример #8
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
Пример #9
0
def _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ):
    rAU = 1.0/UEqn.A()
     
    from Foam import fvc
    rAUf = fvc.interpolate( rAU )
    
    U.ext_assign( rAU * UEqn.H() )
    
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phiU = surfaceScalarField( word( "phiU" ),  fvc.interpolate( U ) & mesh.Sf() )
    
    if p_rgh.needReference():
        fvc.makeRelative( phiU, U )
        from Foam.finiteVolume import adjustPhi
        adjustPhi( phiU, U, p )
        fvc.makeAbsolute( phiU, U )
        pass
    
    phi.ext_assign( phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) )*rAUf*mesh.magSf() )

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

        p_rghEqn.solve( mesh.solver( p_rgh.select(corr == nCorr-1 and nonOrth == nNonOrthCorr) ) )
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - p_rghEqn.flux() )
           pass
        pass
    
    U.ext_assign( U + rAU * fvc.reconstruct( ( phi - phiU ) / rAUf ) )
    U.correctBoundaryConditions()

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    # Make the fluxes relative to the mesh motion
    fvc.makeRelative( phi, U )
    
    p == p_rgh + rho * gh

    if p_rgh.needReference():
       from Foam.OpenFOAM import pRefValue
       p.ext_assign( p + dimensionedScalar( word( "p" ),
                                            p.dimensions(),
                                            pRefValue - getRefCellValue(p, pRefCell) ) )
       p_rgh.ext_assign( p - rho * gh )
       pass
    
    return cumulativeContErr
Пример #10
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
Пример #11
0
def _pEqn(mesh, UEqn, U, p, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue):
    rUA = 1.0 / UEqn.A()

    from Foam import fvc

    rUAf = fvc.interpolate(rUA)

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

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

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

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phiU, U, p)

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

    from Foam import fvm

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

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

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

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

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

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi  - pcorrEqn.flux() )
           pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    pass
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
Пример #15
0
def fun_pEqn(thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh,
             nNonOrthCorr, pRefCell, eqnResidual, maxResidual,
             cumulativeContErr):

    rho.ext_assign(thermo.rho())

    rUA = 1.0 / UEqn.A()

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

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

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

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

    phi.ext_assign(phi + buoyancyPhi)

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

        pEqn.setReference(pRefCell, p[pRefCell])

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

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

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

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

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

    return eqnResidual, maxResidual, cumulativeContErr
Пример #16
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
Пример #17
0
def _pEqn(mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr,
          nNonOrthCorr, pdRefCell, pdRefValue):
    rUA = 1.0 / UEqn.A()

    from Foam import fvc
    rUAf = fvc.interpolate(rUA)

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

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

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

    phi.ext_assign(phiU +
                   (fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) -
                    ghf * fvc.snGrad(rho)) * rUAf * mesh.magSf())

    from Foam import fvm
    for nonOrth in range(nNonOrthCorr + 1):
        pdEqn = fvm.laplacian(rUAf, pd) == fvc.div(phi)
        pdEqn.setReference(pdRefCell, pdRefValue)

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

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

    pass
def fun_pEqn( thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ):

    rho.ext_assign( thermo.rho() )

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

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

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

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

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


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

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

    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
Пример #19
0
def pEqn( runTime, mesh, p, phi, psi, U, UEqn, g, rho, thermo, initialMass, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): 
    rho.ext_assign( thermo.rho() )
    
    from Foam import fvc
    rUA = 1.0 / UEqn().A()

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

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

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

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

        pEqn.setReference( pRefCell, pRefValue )

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

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

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

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

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

    rho.ext_assign( thermo.rho() )
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    
    return eqnResidual, maxResidual, cumulativeContErr
Пример #20
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
Пример #21
0
def fun_pEqn(thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass,
             runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual,
             cumulativeContErr):

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

    rUA = 1.0 / UEqn.A()

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

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

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

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

    phi.ext_assign(phi - buoyancyPhi)

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

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

        eqnResidual = p_rghEqn.solve().initialResidual()

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

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

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

    p.ext_assign(p_rgh + rho * gh)

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

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

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

    return eqnResidual, maxResidual, cumulativeContErr
Пример #22
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
Пример #23
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
Пример #24
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign(thermo.rho())

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

    closedVolume = False

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

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

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

            pEqn.setReference(pRefCell, pRefValue)

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

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

        pass

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

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

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

            pEqn.setReference(pRefCell, pRefValue)

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

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

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

    # Explicitly relax pressure for momentum corrector
    p.relax()
    rho.ext_assign(thermo.rho())
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << nl

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

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

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

    return eqnResidual, maxResidual, cumulativeContErr
Пример #25
0
def main_standalone(argc, argv):

    from Foam.OpenFOAM.include import setRootCase

    args = setRootCase(argc, argv)

    from Foam.OpenFOAM.include import createTime

    runTime = createTime(args)

    from Foam.OpenFOAM.include import createMesh

    mesh = createMesh(runTime)

    transportProperties, nu, p, U, phi, 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"

    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 = CourantNo(mesh, phi, runTime)

        from Foam import fvm

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

        from Foam import fvc
        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"

    import os

    return os.EX_OK
Пример #26
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 )
    
    transportProperties, nu, Ubar, magUbar, flowDirection = readTransportProperties( runTime, mesh)
    
    p, U, phi, laminarTransport, sgsModel, pRefCell, pRefValue = _createFields( runTime, mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
    cumulativeContErr = initContinuityErrs()
    
    gradP, gradPFile = createGradP( runTime)
    
    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 = CourantNo( mesh, phi, runTime )

        sgsModel.correct()

        from Foam import fvm
        UEqn = fvm.ddt( U ) + fvm.div( phi, U ) + sgsModel.divDevBeff( U ) == flowDirection * gradP

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

        rUA = 1.0 / UEqn.A()

        for corr in range( nCorr ):
            U.ext_assign( rUA * UEqn.H() )
            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)

            from Foam.OpenFOAM import word

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

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

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

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

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

        # Correct driving force for a constant mass flow rate

        # Extract the velocity in the flow direction
        magUbarStar = ( flowDirection & U ).weightedAverage( mesh.V() )

        # Calculate the pressure gradient increment needed to
        # adjust the average flow-rate to the correct value
        gragPplus = ( magUbar - magUbarStar ) / rUA.weightedAverage( mesh.V() )

        U.ext_assign( U + flowDirection * rUA * gragPplus )

        gradP +=gragPplus
        ext_Info() << "Uncorrected Ubar = " << magUbarStar.value() << " " << "pressure gradient = " << gradP.value() << nl

        runTime.write()

        writeGradP( runTime, gradP )

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

        pass

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

    import os
    return os.EX_OK
Пример #27
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign( thermo.rho() )

    rUA = 1.0 / UEqn.A()
    U.ext_assign( rUA * UEqn.H() )
    UEqn.clear()
    
    closedVolume = False
    
    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    if transonic: 
       phid = surfaceScalarField( word( "phid" ), 
                                  fvc.interpolate( psi ) * ( fvc.interpolate( U ) & mesh.Sf() ) )


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

           pEqn.setReference( pRefCell, pRefValue )
           
           # retain the residual from the first iteration
           if nonOrth == 0:
              eqnResidual = pEqn.solve().initialResidual()
              maxResidual = max( eqnResidual, maxResidual )
              pass
           else:
              pEqn.solve()
              pass
           
           if nonOrth == nNonOrthCorr:
              phi == pEqn.flux()
              pass
           pass
       
       pass
       
    else:
       phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate(U) & mesh.Sf() ) ) )
       
       from Foam.finiteVolume import adjustPhi
       closedVolume = adjustPhi( phi, U, p )
       
       
       for nonOrth in range( nNonOrthCorr + 1 ) :
           # Pressure corrector
           pEqn = fvm.laplacian( rho * rUA, p ) == fvc.div( phi )
           
           pEqn.setReference( pRefCell, pRefValue )
           
           # Retain the residual from the first iteration
           if nonOrth == 0:
              eqnResidual = pEqn.solve().initialResidual()
              maxResidual = max(eqnResidual, maxResidual)
              pass
           else:
              pEqn.solve()
              pass
           
           if nonOrth == nNonOrthCorr:
              phi.ext_assign( phi - pEqn.flux() )
              pass
           pass
       pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    p.relax()
    rho.ext_assign( thermo.rho() )
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    U.ext_assign( U - rUA * fvc.grad( p ) )
    U.correctBoundaryConditions()
    
    from Foam.finiteVolume import bound
    bound(p, pMin);
        
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       pass
    
    return eqnResidual, maxResidual, cumulativeContErr
Пример #28
0
def main_standalone( argc, argv ):

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

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

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

    p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport = _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 = CourantNo( mesh, phi, runTime )

        # Pressure-velocity PISO corrector

        from Foam import fvm        
        #Momentum predictor

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

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

        UEqn.relax()

        from Foam.finiteVolume import solve
        from Foam import fvc
        if momentumPredictor :
           solve( UEqn == -fvc.grad( p ) )
           pass
           
        # --- 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 )
            
            #Non-orthogonal pressure corrector loop
            for nonOrth in range( nNonOrthCorr + 1 ):
                #Pressure corrector
                pEqn = fvm.laplacian( rUA, p ) == fvc.div( phi )

                pEqn.setReference( pRefCell, pRefValue )

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

            U.ext_assign( U - rUA * fvc.grad( p ) )
            U.correctBoundaryConditions()
            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
Пример #29
0
def main_standalone(argc, argv):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    import os
    return os.EX_OK
def fun_pEqn( thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ):

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

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

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

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

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

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

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

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

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

    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
Пример #31
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)

    p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport = _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 = CourantNo(mesh, phi, runTime)

        # Pressure-velocity PISO corrector

        from Foam import fvm
        #Momentum predictor

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

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

        UEqn.relax()

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

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

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

                pEqn.setReference(pRefCell, pRefValue)

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

            U.ext_assign(U - rUA * fvc.grad(p))
            U.correctBoundaryConditions()
            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