Exemple #1
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
Exemple #2
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
Exemple #3
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, velMag = 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
        
        meshChanged = mesh.update()
        
        if correctPhi and ( mesh.moving() or meshChanged ) :
           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.moving() 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
           turbulence.correct()   
           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
Exemple #4
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 readPISOControls
    piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh() )
    
    from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
    cumulativeContErr = initContinuityErrs()
    
    p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, \
                                    pRefValue, interface, turbulence, g, gh, ghf = _createFields( runTime, mesh() )

    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
    
    cumulativeContErr = fun_correctPhi( runTime, mesh(), phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue)
    
    from Foam.finiteVolume.cfdTools.incompressible import CourantNo
    CoNum, meanCoNum = CourantNo( mesh(), phi, runTime )
    
    from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT
    runTime = setInitialDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum )
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl
    
    while runTime.run() :
        
        adjustTimeStep, maxCo, maxDeltaT, piso, nCorr, nNonOrthCorr, \
            momentumPredictor, transonic, nOuterCorr, correctPhi, checkMeshCourantNo = readControls( runTime, mesh() )
        
        maxAlphaCo, alphaCoNum, meanAlphaCoNum = alphaCourantNo( runTime, mesh(), alpha1, phi )
        
        CoNum, meanCoNum = CourantNo( mesh(), phi, runTime )
        
        from Foam import fvc
        # Make the fluxes absolute
        fvc.makeAbsolute( phi, U )
        
        runTime = setDeltaT(  runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT )
        
        runTime.increment()
        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        
        timeBeforeMeshUpdate = runTime.elapsedCpuTime()

        # Do any mesh changes
        mesh.update()
        
        if mesh.changing():
            ext_Info() << "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << nl
            gh.ext_assign( g & mesh.C() )
            ghf.ext_assign( g & mesh.Cf() )
            pass
        
        if mesh.changing() and correctPhi:
            cumulativeContErr = fun_correctPhi( runTime, mesh(), phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue)
            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

        twoPhaseProperties.correct()
     
        alphaEqnSubCycle( runTime, piso, mesh(), phi, alpha1, rho, rhoPhi, rho1, rho2, interface )
        
        UEqn = _UEqn( mesh(), alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor )

        # --- PISO loop
        for corr in range( nCorr ):
            cumulativeContErr = _pEqn( runTime, mesh(), UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, \
                                       interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr )
            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