示例#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
示例#2
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
示例#3
0
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

    ext_Info() << "Reading field p_rgh\n" << nl
    p_rgh = volScalarField(
        IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field alpha1\n" << nl
    alpha1 = volScalarField(
        IOobject(word("alpha1"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField

    U = volVectorField(
        IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    from Foam.finiteVolume.cfdTools.incompressible import createPhi

    phi = createPhi(runTime, mesh, U)

    ext_Info() << "Reading transportProperties\n" << nl
    from Foam.transportModels import twoPhaseMixture

    twoPhaseProperties = twoPhaseMixture(U, phi)

    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()

    from Foam.OpenFOAM import dimensionedScalar

    Dab = dimensionedScalar(twoPhaseProperties.lookup(word("Dab")))

    # Read the reciprocal of the turbulent Schmidt number
    alphatab = dimensionedScalar(twoPhaseProperties.lookup(word("alphatab")))

    # Need to store rho for ddt(rho, U)

    from Foam.OpenFOAM import scalar

    rho = volScalarField(word("rho"), alpha1 * rho1 + (scalar(1) - alpha1) * rho2)
    rho.oldTime()

    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    from Foam.finiteVolume import surfaceScalarField

    rhoPhi = surfaceScalarField(
        IOobject(word("rho*phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho1 * phi
    )

    # Construct incompressible turbulence model
    from Foam import incompressible

    turbulence = incompressible.turbulenceModel.New(U, phi, twoPhaseProperties)

    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField(word("gh"), g & mesh.C())
    ghf = surfaceScalarField(word("ghf"), g & mesh.Cf())

    p = volScalarField(
        IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), p_rgh + rho * gh
    )

    pRefCell = 0
    pRefValue = 0.0
    from Foam.finiteVolume import setRefCell, getRefCellValue

    pRefCell, pRefValue = setRefCell(p, p_rgh, mesh.solutionDict().subDict(word("PIMPLE")), pRefCell, pRefValue)

    if p_rgh.needReference():
        p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell)))
        p_rgh.ext_assign(p - rho * gh)
        pass

    return (
        p_rgh,
        alpha1,
        U,
        phi,
        twoPhaseProperties,
        rho1,
        rho2,
        Dab,
        alphatab,
        rho,
        rhoPhi,
        turbulence,
        gh,
        ghf,
        p,
        pRefCell,
        pRefValue,
    )
def createFields( runTime, mesh, g ):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    
    ext_Info() << "Reading thermophysical properties\n" << nl 

    ext_Info() << "Reading field T\n" << nl 
    T = volScalarField( IOobject( word( "T" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )

    ext_Info() << "Reading field p_rgh\n" << nl
    p_rgh = volScalarField( IOobject( word( "p_rgh" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )

    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
    
  
    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi( runTime, mesh, U )
    
    laminarTransport, beta, TRef,Pr, Prt = readTransportProperties( U, phi )
    
    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import incompressible
    turbulence = incompressible.RASModel.New( U, phi, laminarTransport )
    
    # Kinematic density for buoyancy force
    rhok = volScalarField( IOobject( word( "rhok" ),
                                     fileName( runTime.timeName() ),
                                     mesh ),
                           1.0 - beta * ( T - TRef ) )
    
    # kinematic turbulent thermal thermal conductivity m2/s
    ext_Info() << "Reading field kappat\n" << nl
    kappat = volScalarField( IOobject( word( "kappat" ),
                                       fileName( runTime.timeName() ),
                                       mesh,
                                       IOobject.MUST_READ,
                                       IOobject.AUTO_WRITE ),
                             mesh )
    
    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField( word( "gh" ), g & mesh.C() )
    from Foam.finiteVolume import surfaceScalarField
    ghf = surfaceScalarField( word( "ghf" ), g & mesh.Cf() )

    p = volScalarField( IOobject( word( "p" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.NO_READ,
                                  IOobject.AUTO_WRITE ),
                        p_rgh + rhok * gh )
    
    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, p_rgh, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )
    
    if p_rgh.needReference():
       from Foam.finiteVolume import getRefCellValue
       from Foam.OpenFOAM import dimensionedScalar
       p.ext_assign( p + dimensionedScalar( word( "p" ), p.dimensions(), pRefValue - getRefCellValue( p, pRefCell) ) )
       pass
    
    return T, p, p_rgh, U, phi, laminarTransport, gh, ghf, TRef,Pr, Prt, turbulence, beta, pRefCell, pRefValue, rhok, kappat
def fun_pEqn( runTime, mesh, p, p_rgh, phi, U, UEqn, ghf, gh, 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_rgh )
    
    buoyancyPhi = rUAf * ghf * fvc.snGrad( rhok ) * mesh.magSf()
    
    phi.ext_assign( phi - buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm, fvc
        p_rghEqn = fvm.laplacian( rUAf, p_rgh ) == fvc.div(phi)
        
        from Foam.finiteVolume import getRefCellValue
        p_rghEqn.setReference( pRefCell, getRefCellValue( p_rgh, pRefCell ) )
        
        # retain the residual from the first iteration
        if ( nonOrth == 0 ):
              eqnResidual = p_rghEqn.solve().initialResidual()
              maxResidual = max( eqnResidual, maxResidual )
              pass
        else:
              p_rghEqn.solve()
              pass
        

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

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

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    p.ext_assign( p_rgh + rhok * gh )

    if p_rgh.needReference():
       from Foam.OpenFOAM import dimensionedScalar
       p.ext_assign( p + dimensionedScalar( word( "p" ), p.dimensions(), pRefValue - getRefCellValue( p, pRefCell ) ) )
       p_rgh.ext_assign( p - rhok * gh )
       pass

    return eqnResidual, maxResidual, cumulativeContErr
示例#6
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)

    from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration
    g = readGravitationalAcceleration(runTime, mesh)

    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, pd, gh, ghf, alpha1, U, phi, rho1, rho2, rho, rhoPhi,\
    twoPhaseProperties, pdRefCell, pdRefValue, pRefValue, interface, turbulence = _createFields( runTime, mesh, g )

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

    correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr,
               pdRefCell, pdRefValue)

    from Foam.finiteVolume.cfdTools.incompressible import CourantNo
    CoNum, meanCoNum, velMag = 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():

        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls(
            mesh)
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)
        CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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

        twoPhaseProperties.correct()

        alphaEqnSubCycle(runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1,
                         rho2, interface)

        UEqn = _UEqn(mesh, alpha1, U, pd, rho, rhoPhi, turbulence, ghf,
                     twoPhaseProperties, interface, momentumPredictor)

        # --- PISO loop
        for corr in range(nCorr):
            _pEqn(mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr,
                  nCorr, nNonOrthCorr, pdRefCell, pdRefValue)
            pass

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

        p.ext_assign(pd + rho * gh)

        if pd.needReference():
            from Foam.OpenFOAM import dimensionedScalar
            from Foam.finiteVolume import getRefCellValue

            p.ext_assign(
                p +
                dimensionedScalar(word("p"), p.dimensions(), pRefValue -
                                  getRefCellValue(p, pdRefCell)))
            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
示例#7
0
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

    ext_Info() << "Reading field pd\n" << nl
    pd = volScalarField(
        IOobject(word("pd"), fileName(runTime.timeName()), mesh,
                 IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh)

    ext_Info() << "Reading field alpha1\n" << nl
    alpha1 = volScalarField(
        IOobject(word("alpha1"), fileName(runTime.timeName()), mesh,
                 IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh)

    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField(
        IOobject(word("U"), fileName(runTime.timeName()), mesh,
                 IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh)

    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi(runTime, mesh, U)

    ext_Info() << "Reading transportProperties\n" << nl
    from Foam.transportModels import twoPhaseMixture
    twoPhaseProperties = twoPhaseMixture(U, phi, word("alpha1"))

    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()

    # Need to store rho for ddt(rho, U)
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT),
        alpha1 * rho1 + (1.0 - alpha1) * rho2,
        alpha1.ext_boundaryField().types())
    rho.oldTime()

    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    from Foam.finiteVolume import surfaceScalarField
    rhoPhi = surfaceScalarField(
        IOobject(word("rho*phi"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE), rho1 * phi)

    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField(word("gh"), g & mesh.C())
    ghf = surfaceScalarField(word("gh"), g & mesh.Cf())

    p = volScalarField(
        IOobject(word("p"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.AUTO_WRITE), pd + rho * gh)

    pdRefCell = 0
    pdRefValue = 0.0

    from Foam.finiteVolume import setRefCell
    pdRefCell, pdRefValue = setRefCell(
        pd,
        mesh.solutionDict().subDict(word("PISO")), pdRefCell, pdRefValue)

    pRefValue = 0.0

    if pd.needReference():
        from Foam.OpenFOAM import readScalar, dimensionedScalar
        from Foam.finiteVolume import getRefCellValue
        pRefValue = readScalar(mesh.solutionDict().subDict(
            word("PISO")).lookup(word("pRefValue")))
        p.ext_assign(
            p + dimensionedScalar(word("p"), p.dimensions(), pRefValue -
                                  getRefCellValue(p, pdRefCell)))
        pass

    # Construct interface from alpha1 distribution
    from Foam.transportModels import interfaceProperties
    interface = interfaceProperties(alpha1, U, twoPhaseProperties)

    # Construct incompressible turbulence model
    from Foam import incompressible
    turbulence = incompressible.turbulenceModel.New(U, phi, twoPhaseProperties)

    return p, pd, gh, ghf, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pdRefCell, pdRefValue, pRefValue, interface, turbulence
def createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

    ext_Info() << "Reading thermophysical properties\n" << nl

    ext_Info() << "Reading field T\n" << nl
    T = volScalarField(
        IOobject(word("T"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field p_rgh\n" << nl
    p_rgh = volScalarField(
        IOobject(word("p_rgh"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField

    U = volVectorField(
        IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    from Foam.finiteVolume.cfdTools.incompressible import createPhi

    phi = createPhi(runTime, mesh, U)

    laminarTransport, beta, TRef, Pr, Prt = readTransportProperties(U, phi)

    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import incompressible

    turbulence = incompressible.RASModel.New(U, phi, laminarTransport)

    # Kinematic density for buoyancy force
    rhok = volScalarField(IOobject(word("rhok"), fileName(runTime.timeName()), mesh), 1.0 - beta * (T - TRef))

    # kinematic turbulent thermal thermal conductivity m2/s
    ext_Info() << "Reading field kappat\n" << nl
    kappat = volScalarField(
        IOobject(word("kappat"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField(word("gh"), g & mesh.C())
    from Foam.finiteVolume import surfaceScalarField

    ghf = surfaceScalarField(word("ghf"), g & mesh.Cf())

    p = volScalarField(
        IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE),
        p_rgh + rhok * gh,
    )

    pRefCell = 0
    pRefValue = 0.0

    from Foam.finiteVolume import setRefCell

    pRefCell, pRefValue = setRefCell(p, p_rgh, mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue)

    if p_rgh.needReference():
        from Foam.finiteVolume import getRefCellValue
        from Foam.OpenFOAM import dimensionedScalar

        p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell)))
        pass

    return (
        T,
        p,
        p_rgh,
        U,
        phi,
        laminarTransport,
        gh,
        ghf,
        TRef,
        Pr,
        Prt,
        turbulence,
        beta,
        pRefCell,
        pRefValue,
        rhok,
        kappat,
    )
def fun_pEqn(
    runTime,
    mesh,
    p,
    p_rgh,
    phi,
    U,
    UEqn,
    ghf,
    gh,
    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_rgh)

    buoyancyPhi = rUAf * ghf * fvc.snGrad(rhok) * mesh.magSf()

    phi.ext_assign(phi - buoyancyPhi)

    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm, fvc

        p_rghEqn = fvm.laplacian(rUAf, p_rgh) == fvc.div(phi)

        from Foam.finiteVolume import getRefCellValue

        p_rghEqn.setReference(pRefCell, getRefCellValue(p_rgh, pRefCell))

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

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

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

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

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    p.ext_assign(p_rgh + rhok * gh)

    if p_rgh.needReference():
        from Foam.OpenFOAM import dimensionedScalar

        p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pRefCell)))
        p_rgh.ext_assign(p - rhok * gh)
        pass

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

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

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

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

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

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

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

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

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

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

    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
示例#11
0
def _createFields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
        
    ext_Info() << "Reading field p\n" << nl
    p_rgh = volScalarField( IOobject( word( "p_rgh" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
    
    ext_Info() << "Reading field alpha1\n" << nl
    alpha1 = volScalarField( IOobject( word( "alpha1" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                                mesh )
    
    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
                        
    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi( runTime, mesh, U )
    
    
    ext_Info() << "Reading transportProperties\n" << nl
    from Foam.transportModels import twoPhaseMixture
    twoPhaseProperties = twoPhaseMixture(U, phi)
    
    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()
    
    # Need to store rho for ddt(rho, U)
    rho = volScalarField( IOobject( word( "rho" ),
                                    fileName( runTime.timeName() ),
                                    mesh,
                                    IOobject.READ_IF_PRESENT ),
                          alpha1 * rho1 + ( 1.0 - alpha1 ) * rho2,
                          alpha1.ext_boundaryField().types() )
    rho.oldTime()
    
    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    from Foam.finiteVolume import surfaceScalarField
    rhoPhi = surfaceScalarField( IOobject( word( "rho*phi" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.NO_WRITE ),
                                 rho1 * phi )
    
    # Construct interface from alpha1 distribution
    from Foam.transportModels import interfaceProperties
    interface = interfaceProperties( alpha1, U, twoPhaseProperties )


    # Construct incompressible turbulence model
    from Foam import incompressible
    turbulence = incompressible.turbulenceModel.New( U, phi, twoPhaseProperties ) 
    
    from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration
    g = readGravitationalAcceleration( runTime, mesh)

    
    #dimensionedVector g0(g);

    #Read the data file and initialise the interpolation table
    #interpolationTable<vector> timeSeriesAcceleration( runTime.path()/runTime.caseConstant()/"acceleration.dat" );
    
    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField( word( "gh" ), g & mesh.C() )
    ghf = surfaceScalarField( word( "ghf" ), g & mesh.Cf() )
    
    p = volScalarField( IOobject( word( "p" ),
                        fileName( runTime.timeName() ),
                        mesh,
                        IOobject.NO_READ,
                        IOobject.AUTO_WRITE ),
                        p_rgh + rho * gh )

    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell, getRefCellValue
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue )
    
    if p_rgh.needReference():
       p.ext_assign( p + dimensionedScalar( word( "p" ),
                                           p.dimensions(),
                                           pRefValue - getRefCellValue(p, pRefCell) ) )
       p_rgh.ext_assign( p - rho * gh )
       pass

    return p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, pRefValue, interface, turbulence, g, gh, ghf
示例#12
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)

    from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration

    g = readGravitationalAcceleration(runTime, mesh)

    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, pd, gh, ghf, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pdRefCell, pdRefValue, pRefValue, interface, turbulence = _createFields(
        runTime, mesh, g
    )

    from Foam.finiteVolume.cfdTools.general.include import readTimeControls

    adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

    correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue)

    from Foam.finiteVolume.cfdTools.incompressible import CourantNo

    CoNum, meanCoNum, velMag = 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():

        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls(mesh)
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)
        CoNum, meanCoNum, velMag = CourantNo(mesh, phi, 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

        twoPhaseProperties.correct()

        alphaEqnSubCycle(runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface)

        UEqn = _UEqn(
            mesh, alpha1, U, pd, rho, rhoPhi, turbulence, ghf, twoPhaseProperties, interface, momentumPredictor
        )

        # --- PISO loop
        for corr in range(nCorr):
            _pEqn(
                mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr, nNonOrthCorr, pdRefCell, pdRefValue
            )
            pass

        from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

        p.ext_assign(pd + rho * gh)

        if pd.needReference():
            from Foam.OpenFOAM import dimensionedScalar
            from Foam.finiteVolume import getRefCellValue

            p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell)))
            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
示例#13
0
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

    ext_Info() << "Reading field pd\n" << nl
    pd = volScalarField(
        IOobject(word("pd"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field alpha1\n" << nl
    alpha1 = volScalarField(
        IOobject(word("alpha1"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField

    U = volVectorField(
        IOobject(word("U"), fileName(runTime.timeName()), mesh, IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh
    )

    from Foam.finiteVolume.cfdTools.incompressible import createPhi

    phi = createPhi(runTime, mesh, U)

    ext_Info() << "Reading transportProperties\n" << nl
    from Foam.transportModels import twoPhaseMixture

    twoPhaseProperties = twoPhaseMixture(U, phi, word("alpha1"))

    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()

    # Need to store rho for ddt(rho, U)
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT),
        alpha1 * rho1 + (1.0 - alpha1) * rho2,
        alpha1.ext_boundaryField().types(),
    )
    rho.oldTime()

    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    from Foam.finiteVolume import surfaceScalarField

    rhoPhi = surfaceScalarField(
        IOobject(word("rho*phi"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE), rho1 * phi
    )

    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField(word("gh"), g & mesh.C())
    ghf = surfaceScalarField(word("gh"), g & mesh.Cf())

    p = volScalarField(
        IOobject(word("p"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.AUTO_WRITE), pd + rho * gh
    )

    pdRefCell = 0
    pdRefValue = 0.0

    from Foam.finiteVolume import setRefCell

    pdRefCell, pdRefValue = setRefCell(pd, mesh.solutionDict().subDict(word("PISO")), pdRefCell, pdRefValue)

    pRefValue = 0.0

    if pd.needReference():
        from Foam.OpenFOAM import readScalar, dimensionedScalar
        from Foam.finiteVolume import getRefCellValue

        pRefValue = readScalar(mesh.solutionDict().subDict(word("PISO")).lookup(word("pRefValue")))
        p.ext_assign(p + dimensionedScalar(word("p"), p.dimensions(), pRefValue - getRefCellValue(p, pdRefCell)))
        pass

    # Construct interface from alpha1 distribution
    from Foam.transportModels import interfaceProperties

    interface = interfaceProperties(alpha1, U, twoPhaseProperties)

    # Construct incompressible turbulence model
    from Foam import incompressible

    turbulence = incompressible.turbulenceModel.New(U, phi, twoPhaseProperties)

    return (
        p,
        pd,
        gh,
        ghf,
        alpha1,
        U,
        phi,
        rho1,
        rho2,
        rho,
        rhoPhi,
        twoPhaseProperties,
        pdRefCell,
        pdRefValue,
        pRefValue,
        interface,
        turbulence,
    )