def convergenceCheck(runTime, maxResidual, convergenceCriterion):
    if (maxResidual < convergenceCriterion):
       ext_Info()<< "reached convergence criterion: " << convergenceCriterion << nl
       runTime.writeAndEnd()
       ext_Info()<< "latestTime = " << runTime.timeName() << nl
       pass
    pass
Example #2
0
def alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ):
    from Foam.OpenFOAM import word 
    alphaScheme = word( "div(phi,alpha)" )
    alpharScheme = word( "div(phirb,alpha)" )
    
    from Foam.finiteVolume import surfaceScalarField
    phic = surfaceScalarField( ( phi / mesh.magSf() ).mag() )
    phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    phir = phic * interface.nHatf()
    
    from Foam import fvc
    from Foam import MULES

    for aCorr in range( nAlphaCorr ):
       phiAlpha = fvc.flux( phi, alpha1, alphaScheme ) + fvc.flux( -fvc.flux( -phir, 1.0 - alpha1, alpharScheme ), alpha1, alpharScheme )
       MULES.explicitSolve( alpha1, phi, phiAlpha, 1.0, 0.0 )
       
       rhoPhi.ext_assign( phiAlpha * ( rho1 - rho2 ) + phi * rho2 )

       pass
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() \
               << "  Max(alpha1) = " << alpha1.ext_max().value() << nl
    pass
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 )
    
    # All "IOobject" (fvMesh, for example)  should overlive all its dependency IOobjects (fields, for exmaple)
    def runSeparateNamespace( runTime, mesh ):
        from Foam.finiteVolume.cfdTools.general.include  import readEnvironmentalProperties
        g, environmentalProperties = readEnvironmentalProperties( runTime, mesh )
    
        thermo, rho, p, h, T, U, phi, turbulence, gh, pRef, pd, p, pdRefCell, pdRefValue, radiation, initialMass  = createFields( runTime, mesh, g )
    
        from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
        cumulativeContErr = initContinuityErrs()
    
        ext_Info() << "\nStarting time loop\n" << nl;
    
        runTime.increment()
    
        while not runTime.end():
           ext_Info()<< "Time = " << runTime.timeName() << nl << nl

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

           eqnResidual, maxResidual, convergenceCriterion = initConvergenceCheck( simple )
        
           pd.storePrevIter()
           rho.storePrevIter()
           # Pressure-velocity SIMPLE corrector
           UEqn, eqnResidual, maxResidual = fun_UEqn( phi, U, turbulence, pd, rho, gh, eqnResidual, maxResidual )
       
           hEqn, eqnResidual, maxResidual = fun_hEqn( turbulence, phi, h, rho, radiation, p, thermo, eqnResidual, maxResidual )
       
           eqnResidual, maxResidual, cumulativeContErr = fun_pEqn( runTime, thermo, UEqn, U, phi, rho, gh, pd, p, initialMass, mesh, pRef, \
                                                               nNonOrthCorr, pdRefCell, pdRefValue, eqnResidual, maxResidual, cumulativeContErr )
           
           turbulence.correct()

           runTime.write()

           ext_Info()<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" \
                     << "  ClockTime = " << runTime.elapsedClockTime() << " s" \
                     << nl << nl
                 
           convergenceCheck( runTime, maxResidual, convergenceCriterion)          
       
           runTime.increment()
           pass
    #-----------------------------------------------------------------------------   
    runSeparateNamespace( runTime, mesh )
        
    ext_Info() << "End\n"
    import os
    return os.EX_OK
Example #4
0
def readThermodynamicProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl

    ext_Info() << "Reading thermodynamicProperties\n" << nl

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName

    thermodynamicProperties = IOdictionary(
        IOobject(
            word("thermodynamicProperties"), fileName(runTime.constant()), mesh, IOobject.MUST_READ, IOobject.NO_WRITE
        )
    )

    from Foam.OpenFOAM import dimensionedScalar

    rho0 = dimensionedScalar(thermodynamicProperties.lookup(word("rho0")))

    p0 = dimensionedScalar(thermodynamicProperties.lookup(word("p0")))

    psi = dimensionedScalar(thermodynamicProperties.lookup(word("psi")))

    # Density offset, i.e. the constant part of the density
    rhoO = dimensionedScalar(word("rhoO"), rho0 - psi * p0)

    return thermodynamicProperties, rho0, p0, psi, rhoO
Example #5
0
def _createFields( runTime, mesh, rhoO, psi ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading field p\n" << nl
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    p = volScalarField( IOobject( word( "p" ),
                                  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 )

    rho = volScalarField( IOobject( word( "rho" ),
                                    fileName( runTime.timeName() ),
                                    mesh,
                                    IOobject.NO_READ,
                                    IOobject.AUTO_WRITE ),
                          rhoO + psi * p )
    
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi( runTime, mesh, rho, U )
    

    return p, U, rho, phi
Example #6
0
def CourantNo(runTime, mesh, h, phi, magg):
    CoNum = 0.0
    meanCoNum = 0.0
    waveCoNum = 0.0

    if mesh.nInternalFaces():
        from Foam import fvc
        SfUfbyDelta = mesh.deltaCoeffs() * phi.mag() / fvc.interpolate(h)

        CoNum = (SfUfbyDelta /
                 mesh.magSf()).ext_max().value() * runTime.deltaT().value()

        meanCoNum = (SfUfbyDelta.sum() /
                     mesh.magSf().sum()).value() * runTime.deltaT().value()

        # Gravity wave Courant number
        waveCoNum = 0.5 * (mesh.deltaCoeffs() * fvc.interpolate(h).sqrt(
        )).ext_max().value() * magg.sqrt().value() * runTime.deltaT().value()

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info(
    ) << "Courant number mean: " << meanCoNum << " max: " << CoNum << nl
    ext_Info() << "Gravity wave Courant number max: " << waveCoNum << nl

    return CoNum, meanCoNum, waveCoNum
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 = volScalarField(
        IOobject(word("p"), 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)

    from Foam.transportModels import singlePhaseTransportModel

    fluid = singlePhaseTransportModel(U, phi)

    pRefCell = 0
    pRefValue = 0.0

    from Foam.finiteVolume import setRefCell

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

    return p, U, phi, fluid, pRefCell, pRefValue
Example #8
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()
Example #9
0
def compressibleCourantNo_010600_dev(mesh, phi, rho, runTime):

    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    CoNum = 0.0
    meanCoNum = 0.0
    velMag = 0.0

    if mesh.nInternalFaces():

        from Foam import fvc
        phiOverRho = phi.mag() / fvc.interpolate(rho)

        SfUfbyDelta = mesh.deltaCoeffs() * phiOverRho

        CoNum = (SfUfbyDelta /
                 mesh.magSf()).ext_max().value() * runTime.deltaT().value()
        meanCoNum = (SfUfbyDelta.sum() /
                     mesh.magSf().sum()).value() * runTime.deltaT().value()

        velMag = (phiOverRho / mesh.magSf()).ext_max().value()

        pass

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info(
    ) << "Courant Number mean: " << meanCoNum << " max: " << CoNum << " velocity magnitude: " << velMag << nl

    return CoNum, meanCoNum, velMag
Example #10
0
def compressibleCreatePhi(runTime, mesh, rhoU):
    from Foam.OpenFOAM import IOobject, word, fileName
    phiHeader = IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                         IOobject.NO_READ)

    from Foam.OpenFOAM import ext_Info, nl
    if phiHeader.headerOk():
        ext_Info() << "Reading face flux field phi\n" << nl
        from Foam.finiteVolume import surfaceScalarField
        phi = surfaceScalarField(
            IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                     IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh)
        pass
    else:
        ext_Info() << "Calculating face flux field phi\n" << nl

        from Foam.OpenFOAM import wordList
        from Foam.finiteVolume import calculatedFvPatchScalarField
        phiTypes = wordList(2, calculatedFvPatchScalarField.typeName)
        from Foam.finiteVolume import surfaceScalarField, linearInterpolate
        phi = surfaceScalarField(
            IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                     IOobject.NO_READ, IOobject.AUTO_WRITE),
            linearInterpolate(rhoU) & mesh.Sf(), phiTypes)
        pass

    return phiHeader, phi, phiTypes
Example #11
0
def readThermodynamicProperties( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermodynamicProperties\n" << nl
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    thermodynamicProperties = IOdictionary( IOobject( word( "thermodynamicProperties" ),
                                                      fileName( runTime.constant() ),
                                                      mesh,
                                                      IOobject.MUST_READ,
                                                      IOobject.NO_WRITE ) )

    from Foam.OpenFOAM import dimensionedScalar
    R = dimensionedScalar( thermodynamicProperties.lookup( word( "R" ) ) )
    
    Cv = dimensionedScalar( thermodynamicProperties.lookup( word( "Cv" ) ) )

    Cp = Cv + R

    gamma = Cp / Cv
    
    from Foam.OpenFOAM import dimless
    Pr = dimensionedScalar( word( "Pr" ), dimless, 1.0 )
    if thermodynamicProperties.found( word( "Pr" ) ) :
       Pr = dimensionedScalar( thermodynamicProperties.lookup( "Pr" ) )
       pass

    return thermodynamicProperties, R, Cv, Cp, gamma, Pr
Example #12
0
def createFluidMeshes( rp, runTime ) :

    from Foam.finiteVolume import fvMesh, PtrList_fvMesh
    fluidRegions = PtrList_fvMesh( rp.fluidRegionNames.size() )
    from Foam.OpenFOAM import word, fileName, IOobject
    for index in range( rp.fluidRegionNames.size() ) :

        from Foam.OpenFOAM import ext_Info, nl
        ext_Info()<< "Create fluid mesh for region " << rp.fluidRegionNames[ index ] \
                  << " for time = " << runTime.timeName() << nl << nl
        mesh = fvMesh( IOobject( rp.fluidRegionNames[ index ],
                                 fileName( runTime.timeName() ),
                                 runTime,
                                 IOobject.MUST_READ ) ) 

        fluidRegions.ext_set( index, mesh )
        # Force calculation of geometric properties to prevent it being done
        # later in e.g. some boundary evaluation
        # (void)fluidRegions[i].weights();
        # (void)fluidRegions[i].deltaCoeffs();
        
        from Foam.OpenFOAM import IOdictionary, autoPtr_IOdictionary
        # Attach environmental properties to each region
        environmentalProperties = autoPtr_IOdictionary( IOdictionary( IOobject( word( "environmentalProperties" ),
                                                                                fileName( runTime.constant() ),
                                                                                fluidRegions[ index ],
                                                                                IOobject.MUST_READ,
                                                                                IOobject.NO_WRITE ) ) )
        
        environmentalProperties.ptr().store()
                
    return fluidRegions
Example #13
0
def readThermodynamicProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermodynamicProperties\n" << nl

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    thermodynamicProperties = IOdictionary(
        IOobject(word("thermodynamicProperties"), fileName(runTime.constant()),
                 mesh, IOobject.MUST_READ, IOobject.NO_WRITE))

    from Foam.OpenFOAM import dimensionedScalar
    R = dimensionedScalar(thermodynamicProperties.lookup(word("R")))

    Cv = dimensionedScalar(thermodynamicProperties.lookup(word("Cv")))

    Cp = Cv + R

    gamma = Cp / Cv

    from Foam.OpenFOAM import dimless
    Pr = dimensionedScalar(word("Pr"), dimless, 1.0)
    if thermodynamicProperties.found(word("Pr")):
        Pr = dimensionedScalar(thermodynamicProperties.lookup("Pr"))
        pass

    return thermodynamicProperties, R, Cv, Cp, gamma, Pr
Example #14
0
def compressibleCourantNo_020000(mesh, phi, rho, runTime):

    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    CoNum = 0.0
    meanCoNum = 0.0

    if mesh.nInternalFaces():
        from Foam import fvc
        tmp = fvc.surfaceSum(phi.mag())
        sumPhi = tmp.internalField() / rho.internalField()

        CoNum = 0.5 * (sumPhi /
                       mesh.V().field()).gMax() * runTime.deltaTValue()

        meanCoNum = 0.5 * (sumPhi.gSum() /
                           mesh.V().field().gSum()) * runTime.deltaTValue()

        pass

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info(
    ) << "Courant Number mean: " << meanCoNum << " max: " << CoNum << nl

    return CoNum, meanCoNum
Example #15
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 = volScalarField(
        IOobject(word("p"), 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)

    pRefCell = 0
    pRefValue = 0.0

    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell(p,
                                     mesh.solutionDict().subDict(word("PISO")),
                                     pRefCell, pRefValue)

    from Foam.transportModels import singlePhaseTransportModel
    laminarTransport = singlePhaseTransportModel(U, phi)

    from Foam import incompressible
    turbulence = incompressible.turbulenceModel.New(U, phi, laminarTransport)

    return p, U, phi, turbulence, pRefCell, pRefValue, laminarTransport
Example #16
0
def alphaEqn(mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr):
    from Foam.OpenFOAM import word
    alphaScheme = word("div(phi,alpha)")
    alpharScheme = word("div(phirb,alpha)")

    from Foam.finiteVolume import surfaceScalarField
    phic = surfaceScalarField((phi / mesh.magSf()).mag())
    phic.ext_assign((interface.cAlpha() * phic).ext_min(phic.ext_max()))
    phir = phic * interface.nHatf()

    from Foam import fvc
    from Foam import MULES

    for aCorr in range(nAlphaCorr):
        phiAlpha = fvc.flux(phi, alpha1, alphaScheme) + fvc.flux(
            -fvc.flux(-phir, 1.0 - alpha1, alpharScheme), alpha1, alpharScheme)
        MULES.explicitSolve(alpha1, phi, phiAlpha, 1.0, 0.0)

        rhoPhi.ext_assign(phiAlpha * (rho1 - rho2) + phi * rho2)

        pass
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() \
               << "  Max(alpha1) = " << alpha1.ext_max().value() << nl
    pass
Example #17
0
def createFields( runTime, mesh ):
    ext_Info() << "Reading field U\n" << nl
    
    from Foam.finiteVolume import volVectorField
    from Foam.OpenFOAM import IOobject, fileName, word
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )

    from Foam.finiteVolume import volSymmTensorField
    from Foam.OpenFOAM import dimensionedSymmTensor, symmTensor
    from Foam.OpenFOAM import dimForce, dimArea
    sigma = volSymmTensorField( IOobject( word( "sigma" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.READ_IF_PRESENT,
                                          IOobject.AUTO_WRITE ),
                                mesh,
                                dimensionedSymmTensor( word( "zero" ), dimForce/dimArea, symmTensor.zero)
                              )
    
    from materialModels.rheologyModel import rheologyModel
    rheology = rheologyModel( sigma )

    return U, sigma, rheology
def compressibleCourantNo_010600_dev( mesh, phi, rho, runTime ):
    
    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    CoNum = 0.0
    meanCoNum = 0.0
    velMag = 0.0
    
    if mesh.nInternalFaces() :
        
        from Foam import fvc
        phiOverRho = phi.mag() / fvc.interpolate( rho )
        
        SfUfbyDelta = mesh.deltaCoeffs() * phiOverRho

        CoNum = ( SfUfbyDelta / mesh.magSf() ).ext_max().value() * runTime.deltaT().value()
        meanCoNum = ( SfUfbyDelta.sum() / mesh.magSf().sum() ).value() * runTime.deltaT().value();
        
        velMag = ( phiOverRho / mesh.magSf() ).ext_max().value()
        
        pass

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Courant Number mean: " << meanCoNum << " max: " << CoNum  << " velocity magnitude: " << velMag << nl 

    return CoNum, meanCoNum, velMag
Example #19
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)

    def runSeparateNamespace(runTime, mesh):
        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 readSIMPLEControls
            simple, nNonOrthCorr, momentumPredictor, transonic = readSIMPLEControls(
                mesh)

            eqnResidual, maxResidual, convergenceCriterion = initConvergenceCheck(
                simple)

            p.storePrevIter()

            UEqn, eqnResidual, maxResidual = Ueqn(phi, U, p, turbulence,
                                                  eqnResidual, maxResidual)

            eqnResidual, maxResidual, cumulativeContErr = pEqn( runTime, mesh, p, phi, U, UEqn, \
                                                                eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue )

            turbulence.correct()

            runTime.write()

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

            convergenceCheck(maxResidual, convergenceCriterion)

            pass

        #--------------------------------------------------------------------------------------

    runSeparateNamespace(runTime, mesh)

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "End\n" << nl

    import os
    return os.EX_OK
Example #20
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
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
Example #22
0
def convergenceCheck( maxResidual, convergenceCriterion ):
    from Foam.OpenFOAM import ext_Info, nl
    
    if (maxResidual < convergenceCriterion):
       ext_Info() << "reached convergence criterion: " << convergenceCriterion << nl
       runTime.writeAndEnd();
       ext_Info   << "latestTime = " << runTime.timeName() << nl
       pass
Example #23
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
Example #24
0
def calculateStress( runTime, mesh, sigma, _lambda ):
    if (runTime.outputTime()):
       from Foam.finiteVolume import volScalarField
       from Foam.OpenFOAM import word, IOobject, fileName
       sigmaEq = volScalarField( IOobject( word( "sigmaEq" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                  (  (3.0/2.0)*sigma.dev() .magSqr() ).sqrt() )
       ext_Info() << "Max sigmaEq = " << sigmaEq.ext_max().value() << nl
       
       from Foam.OpenFOAM import symmTensor
       sigmaxx = volScalarField( IOobject( word( "sigmaxx" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.XX) )
       
       sigmayy = volScalarField( IOobject( word( "sigmayy" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.YY) )

       sigmazz = volScalarField( IOobject( word( "sigmazz" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.ZZ) )
       ext_Info() << "Max sigmazz = " << sigmazz.ext_max().value() << nl
       
       sigmaxy = volScalarField( IOobject( word( "sigmaxy" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.XY) )

       sigmaxz = volScalarField( IOobject( word( "sigmaxz" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.XZ) )

       sigmayz = volScalarField( IOobject( word( "sigmayz" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.AUTO_WRITE ),
                                 sigma.component(symmTensor.YZ) )
       
       runTime.write()
    pass
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 )

    def runSeparateNamespace( runTime, mesh ):
        from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration
        g = readGravitationalAcceleration( runTime, mesh)
        
        T, p, p_rgh, U, phi, laminarTransport, gh, ghf, TRef,Pr, Prt, turbulence, beta, pRefCell, pRefValue, rhok, kappat = createFields( runTime, mesh, g )
        
        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 readSIMPLEControls
            simple, nNonOrthCorr, momentumPredictor, transonic = readSIMPLEControls( mesh )
        
            eqnResidual, maxResidual, convergenceCriterion = initConvergenceCheck( simple )
                
            p_rgh.storePrevIter()
        
            UEqn, eqnResidual, maxResidual = fun_UEqn( phi, U, p_rgh, turbulence, mesh, ghf, rhok, eqnResidual, maxResidual, momentumPredictor )
        
            TEqn, kappaEff = fun_TEqn( turbulence, phi, T, rhok, beta, TRef, Pr, Prt, kappat, eqnResidual, maxResidual )
            
            eqnResidual, maxResidual, cumulativeContErr = fun_pEqn( runTime, mesh, p, p_rgh, phi, U, UEqn, ghf, gh, rhok, eqnResidual, \
                                                                   maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue )
        
            turbulence.correct()

            runTime.write()
        
            ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
                          "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
            convergenceCheck( maxResidual, convergenceCriterion ) 
        
            pass
    
    runSeparateNamespace( runTime, mesh )    
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "End\n" << nl 

    import os
    return os.EX_OK
Example #26
0
def createTime_020000(args):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Create time\n" << nl

    from Foam.OpenFOAM import Time

    runTime = Time(Time.controlDictName.fget(), args)

    return runTime
def createTime_020000( args ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Create time\n" << nl
    
    from Foam.OpenFOAM import Time

    runTime = Time( Time.controlDictName.fget(), args )

    return runTime
Example #28
0
def readGravitationalAcceleration(runTime, mesh):
    ext_Info() << "\nReading g" << nl

    from Foam.OpenFOAM import uniformDimensionedVectorField
    from Foam.OpenFOAM import word, IOobject, fileName
    g = uniformDimensionedVectorField(
        IOobject(word("g"), fileName(runTime.constant()), mesh,
                 IOobject.MUST_READ, IOobject.NO_WRITE))
    return g
Example #29
0
def create_fields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading field p\n" << nl
    
    from Foam.OpenFOAM import IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    p = volScalarField( IOobject( word( "p" ),
                                  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 )

    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )

    from Foam.transportModels import singlePhaseTransportModel
    laminarTransport = singlePhaseTransportModel( U, phi )

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

    from Foam.finiteVolume import porousZones
    pZones = porousZones( mesh )
    
    from Foam.OpenFOAM import Switch
    pressureImplicitPorosity = Switch( False )

    nUCorr = 0
    if pZones.size():
       # nUCorrectors for pressureImplicitPorosity
       if (mesh.solutionDict().subDict( word( "SIMPLE" ) ).found( word( "nUCorrectors" ) ) ) :
          from Foam.OpenFOAM import readInt
          nUCorr = readInt( mesh.solutionDict().subDict( word( "SIMPLE" ) ).lookup( word( "nUCorrectors" ) ) )
          pass
       if nUCorr > 0 :
          pressureImplicitPorosity = True
          pass
       pass

    return p, U, phi, pRefCell, pRefValue, laminarTransport, turbulence, pZones, pressureImplicitPorosity, nUCorr
Example #30
0
def entry_point():
    from Foam import FOAM_VERSION
    if FOAM_VERSION( "<", "010500" ):
       import sys; argv = sys.argv
       return main_standalone( len( argv ), argv )
    else:
       from Foam.OpenFOAM import ext_Info
       ext_Info() << "\n\n To use this solver it is necessary to SWIG OpenFOAM-1.4.X\n"
       pass
    pass
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\n" << nl
    p = volScalarField( IOobject( word( "p" ),
                                  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 )
    
    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue )

    # Kinematic density for buoyancy force
    rhok = volScalarField( IOobject( word( "rhok" ),
                                     fileName( runTime.timeName() ),
                                     mesh ),
                           1.0 - beta * ( T - TRef ) )
    
    return T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, pRefCell, pRefValue, rhok
Example #32
0
def createSolidField(solidRegions, runTime):

    #Initialise solid field pointer lists
    from Foam.finiteVolume import PtrList_volScalarField, volScalarField
    rhos = PtrList_volScalarField(solidRegions.size())
    cps = PtrList_volScalarField(solidRegions.size())
    rhosCps = PtrList_volScalarField(solidRegions.size())
    Ks = PtrList_volScalarField(solidRegions.size())
    Ts = PtrList_volScalarField(solidRegions.size())

    from Foam.OpenFOAM import ext_Info, nl

    #Populate solid field pointer lists
    from Foam.OpenFOAM import word, IOobject, fileName
    for index in range(solidRegions.size()):
        ext_Info()<< "*** Reading solid mesh thermophysical properties for region " \
            << solidRegions[ index ].name() << nl << nl

        ext_Info() << "    Adding to rhos\n" << nl
        rhos.ext_set(
            index,
            volScalarField(
                IOobject(word("rho"), fileName(runTime.timeName()),
                         solidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), solidRegions[index]))

        ext_Info() << "    Adding to cps\n" << nl
        cps.ext_set(
            index,
            volScalarField(
                IOobject(word("cp"), fileName(runTime.timeName()),
                         solidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), solidRegions[index]))

        rhosCps.ext_set(
            index, volScalarField(word("rhosCps"), rhos[index] * cps[index]))

        ext_Info() << "    Adding to Ks\n" << nl
        Ks.ext_set(
            index,
            volScalarField(
                IOobject(word("K"), fileName(runTime.timeName()),
                         solidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), solidRegions[index]))

        ext_Info() << "    Adding to Ts\n" << nl

        Ts.ext_set(
            index,
            volScalarField(
                IOobject(word("T"), fileName(runTime.timeName()),
                         solidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), solidRegions[index]))

    return rhos, cps, rhosCps, Ks, Ts
Example #33
0
def createSolidField( solidRegions, runTime ):

    #Initialise solid field pointer lists
    from Foam.finiteVolume import PtrList_volScalarField, volScalarField
    rhos = PtrList_volScalarField( solidRegions.size() )
    cps = PtrList_volScalarField( solidRegions.size() )
    rhosCps = PtrList_volScalarField( solidRegions.size() )
    Ks = PtrList_volScalarField( solidRegions.size() )
    Ts = PtrList_volScalarField( solidRegions.size() )
    
        
    from Foam.OpenFOAM import ext_Info, nl
    
    #Populate solid field pointer lists    
    from Foam.OpenFOAM import word, IOobject, fileName
    for index in range( solidRegions.size() ):
        ext_Info()<< "*** Reading solid mesh thermophysical properties for region " \
            << solidRegions[ index ].name() << nl << nl

        ext_Info()<< "    Adding to rhos\n" << nl
        
        rhos.ext_set( index, volScalarField( IOobject ( word( "rho" ), 
                                                        fileName( runTime.timeName() ), 
                                                        solidRegions[ index ], 
                                                        IOobject.MUST_READ, 
                                                        IOobject.AUTO_WRITE ),
                                             solidRegions[ index ] )  )
        
        ext_Info()<< "    Adding to cps\n" << nl
        cps.ext_set( index, volScalarField( IOobject( word( "cp" ),
                                                      fileName( runTime.timeName() ),
                                                      solidRegions[ index ],
                                                      IOobject.MUST_READ,
                                                      IOobject.AUTO_WRITE ),
                                            solidRegions[ index ] ) )
        
        rhosCps.ext_set( index, volScalarField( word( "rhosCps" ), rhos[ index ] * cps[ index ]  ) )
        
        ext_Info()<< "    Adding to Ks\n" << nl
        Ks.ext_set( index, volScalarField( IOobject( word( "K" ),
                                                     fileName( runTime.timeName() ),
                                                     solidRegions[ index ],
                                                     IOobject.MUST_READ,
                                                     IOobject.AUTO_WRITE ),
                                           solidRegions[ index ] ) )
                
        ext_Info()<< "    Adding to Ts\n" << nl
        Ts.ext_set( index, volScalarField( IOobject( word( "T" ),
                                                     fileName( runTime.timeName() ),
                                                     solidRegions[ index ],
                                                     IOobject.MUST_READ,
                                                     IOobject.AUTO_WRITE ),
                                           solidRegions[ index ] ) )
   
    return rhos, cps, rhosCps, Ks, Ts
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\n" << nl
    p = volScalarField( IOobject( word( "p" ),
                                  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.turbulenceModel.New( U, phi, laminarTransport )
    
    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue )

    # Kinematic density for buoyancy force
    rhok = volScalarField( IOobject( word( "rhok" ),
                                     fileName( runTime.timeName() ),
                                     mesh ),
                           1.0 - beta * ( T - TRef ) )
    
    return T, p, U, phi, laminarTransport, beta, TRef,Pr, Prt, turbulence, pRefCell, pRefValue, rhok
Example #35
0
def create_fields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading field p\n" << nl

    from Foam.OpenFOAM import IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    p = volScalarField(
        IOobject(word("p"), 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)

    pRefCell = 0
    pRefValue = 0.0

    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell(
        p,
        mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue)

    from Foam.transportModels import singlePhaseTransportModel
    laminarTransport = singlePhaseTransportModel(U, phi)

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

    from Foam.finiteVolume import porousZones
    pZones = porousZones(mesh)

    from Foam.OpenFOAM import Switch
    pressureImplicitPorosity = Switch(False)

    nUCorr = 0
    if pZones.size():
        # nUCorrectors for pressureImplicitPorosity
        if (mesh.solutionDict().subDict(word("SIMPLE")).found(
                word("nUCorrectors"))):
            from Foam.OpenFOAM import readInt
            nUCorr = readInt(mesh.solutionDict().subDict(
                word("SIMPLE")).lookup(word("nUCorrectors")))
            pass
        if nUCorr > 0:
            pressureImplicitPorosity = True
            pass
        pass

    return p, U, phi, pRefCell, pRefValue, laminarTransport, turbulence, pZones, pressureImplicitPorosity, nUCorr
def createDynamicFvMesh_010600(runTime):

    from Foam.OpenFOAM import ext_Info, nl, IOobject, fileName
    ext_Info() << "Create mesh for time = " << runTime.timeName() << nl << nl

    from Foam.dynamicFvMesh import dynamicFvMesh
    mesh = dynamicFvMesh.New(
        IOobject(dynamicFvMesh.defaultRegion, fileName(runTime.timeName()),
                 runTime))

    return mesh
Example #37
0
def solveSolid( mesh, rho, cp, K, T, nNonOrthCorr ):
    for index in range( nNonOrthCorr + 1 ):
       from Foam import fvm
       TEqn = fvm.ddt( rho * cp, T ) - fvm.laplacian( K, T )
       TEqn.relax()
       TEqn.solve()
       pass
    from Foam.OpenFOAM import ext_Info, nl   
    ext_Info()<< "Min/max T:" << T.ext_min() << ' ' << T.ext_max() << nl
    
    pass
Example #38
0
def createTime_010500_free(args):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Create time\n" << nl

    from Foam.OpenFOAM import Time
    from Foam.OpenFOAM import argList

    runTime = Time(Time.controlDictName.fget(), args.rootPath(),
                   args.caseName())

    return runTime
Example #39
0
def setDeltaT( runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT ):
    from Foam.OpenFOAM import SMALL
    if adjustTimeStep:
       maxDeltaTFact = min( maxCo / ( CoNum + SMALL ), maxAlphaCo / ( alphaCoNum + SMALL ) )
       deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2);
       
       runTime.setDeltaT( min( deltaTFact * runTime.deltaT().value(), maxDeltaT ) )
       from Foam.OpenFOAM import ext_Info, nl
       ext_Info() << "deltaT = " <<  runTime.deltaT().value() << nl
       pass
    return runTime
def createDynamicFvMesh_010600( runTime ):
    
    from Foam.OpenFOAM import ext_Info, nl, IOobject, fileName
    ext_Info() << "Create mesh for time = " << runTime.timeName() << nl << nl
    
    from Foam.dynamicFvMesh import dynamicFvMesh
    mesh = dynamicFvMesh.New( IOobject( dynamicFvMesh.defaultRegion,
                                        fileName( runTime.timeName() ),
                                        runTime ) ) 

    return mesh
Example #41
0
def readGravitationalAcceleration( runTime, mesh):
    from Foam.OpenFOAM import ext_Info,  nl
    ext_Info() << "\nReading g" << nl
    from Foam.OpenFOAM import uniformDimensionedVectorField, IOobject, fileName, word
    
    g = uniformDimensionedVectorField( IOobject( word( "g" ),
                                                 fileName( runTime.constant() ),
                                                 mesh,
                                                 IOobject.MUST_READ,
                                                 IOobject.NO_WRITE ) )
    return g
Example #42
0
def createFields(runTime, mesh, g):
    ext_Info() << "Reading thermophysical properties\n" << nl

    from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo

    thermo = basicPsiThermo.New(mesh)

    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho())
    p = thermo.p()
    h = thermo.h()
    psi = thermo.psi()

    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.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi(runTime, mesh, rho, U)

    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import compressible
    turbulence = compressible.RASModel.New(rho, U, phi, thermo())

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

    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)

    #Force p_rgh to be consistent with p
    p_rgh.ext_assign(p - rho * gh)

    pRefCell = 0
    pRefValue = 0.0
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell(
        p, p_rgh,
        mesh.solutionDict().subDict(word("SIMPLE")), pRefCell, pRefValue)

    from Foam import fvc
    initialMass = fvc.domainIntegrate(rho)
    totalVolume = mesh.V().ext_sum()

    return thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
Example #43
0
def solveSolid( mesh, rho, cp, K, T, nNonOrthCorr ):
    for index in range( nNonOrthCorr + 1 ):
       from Foam import fvm
       TEqn = fvm.ddt( rho * cp, T ) - fvm.laplacian( K, T )
       TEqn.relax()
       TEqn.solve()
       pass
    from Foam.OpenFOAM import ext_Info, nl   
    ext_Info()<< "Min/max T:" << T.ext_min() << ' ' << T.ext_max() << nl
    
    pass
Example #44
0
def setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum ):
    from Foam.OpenFOAM import SMALL

    if adjustTimeStep :
        maxDeltaTFact = maxCo/(CoNum + SMALL)
        deltaTFact = min( min( maxDeltaTFact, 1.0 + 0.1 * maxDeltaTFact ), 1.2 )
        runTime.setDeltaT( min( deltaTFact * runTime.deltaT().value(), maxDeltaT ) )
        from Foam.OpenFOAM import ext_Info, nl
        ext_Info() << "deltaT = " << runTime.deltaT().value() << nl
        pass
    
    return runTime
Example #45
0
def readTransportProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading transportProperties\n" << nl

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    transportProperties = IOdictionary(
        IOobject(word("transportProperties"), fileName(runTime.constant()),
                 mesh, IOobject.MUST_READ, IOobject.NO_WRITE))
    from Foam.OpenFOAM import dimensionedScalar
    mu = dimensionedScalar(transportProperties.lookup(word("mu")))

    return transportProperties, mu
Example #46
0
    def run( self, getPISOControls ):
        from Foam.OpenFOAM import ext_Info, nl
        ext_Info() << "\nStarting time loop\n" << nl
        
        while not self.runTime.end() :
            self.step( getPISOControls )
            pass

        from Foam.OpenFOAM import ext_Info, nl
        ext_Info() << "End\n"

        return True
def createTime_010500_free( args ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Create time\n" << nl
    
    from Foam.OpenFOAM import Time
    from Foam.OpenFOAM import argList
    
    runTime = Time( Time.controlDictName.fget(),
                    args.rootPath(),
                    args.caseName() )

    return runTime
Example #48
0
def createPhi(runTime, hU, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import surfaceScalarField
    ext_Info() << "Reading/calculating face flux field phi\n" << nl

    from Foam.finiteVolume import linearInterpolate
    phi = surfaceScalarField(
        IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE),
        linearInterpolate(hU) & mesh.Sf())
    return phi
Example #49
0
def readEnvironmentalProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nReading environmentalProperties" << nl

    from Foam.OpenFOAM import IOdictionary, fileName, word, IOobject
    environmentalProperties = IOdictionary(
        IOobject(word("environmentalProperties"), fileName(runTime.constant()),
                 mesh, IOobject.MUST_READ, IOobject.NO_WRITE))
    from Foam.OpenFOAM import dimensionedVector
    g = dimensionedVector(environmentalProperties.lookup(word("g")))

    return g, environmentalProperties
Example #50
0
def entry_point():
    from Foam import FOAM_VERSION
    if FOAM_VERSION("<", "010500"):
        import sys
        argv = sys.argv
        return main_standalone(len(argv), argv)
    else:
        from Foam.OpenFOAM import ext_Info
        ext_Info(
        ) << "\n\n To use this solver it is necessary to SWIG OpenFOAM-1.4.X\n"
        pass
    pass
Example #51
0
def alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr ):

    from Foam.OpenFOAM import word 
    alphaScheme = word( "div(phi,alpha)" )
    alpharScheme = word( "div(phirb,alpha)" )

    phir = phic*interface.nHatf()
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar, scalar, ext_Info, nl
    for gCorr in range( nAlphaCorr ):
        Sp = volScalarField.DimensionedInternalField( IOobject( word( "Sp" ),
                                                                fileName( runTime.timeName() ),
                                                                mesh ),
                                                      mesh,
                                                      dimensionedScalar( word( "Sp" ), dgdt.dimensions(), 0.0 ) )

        Su = volScalarField.DimensionedInternalField( IOobject( word( "Su" ),
                                                                fileName( runTime.timeName() ),
                                                                mesh ),
                                                      # Divergence term is handled explicitly to be
                                                      # consistent with the explicit transport solution
                                                      divU * alpha1.ext_min( scalar( 1 ) ) )
        for celli in range( dgdt.size() ):
            if dgdt[ celli ] > 0.0 and alpha1[ celli ] > 0.0:
                Sp[ celli ] -= dgdt[ celli ] * alpha1[ celli ]
                Su[ celli ] += dgdt[ celli ] * alpha1[ celli ]
                pass
            elif dgdt[ celli ] < 0.0 and alpha1[ celli ] < 1.0:
                Sp[ celli ] += dgdt[ celli ] * ( 1.0 - alpha1[ celli ] )
                pass
            pass

        from Foam import fvc
        phiAlpha1 = fvc.flux( phi, alpha1, alphaScheme ) + fvc.flux( - fvc.flux( -phir, alpha2, alpharScheme ), alpha1, alpharScheme )
        
        from Foam import MULES
        from Foam.OpenFOAM import geometricOneField
        MULES.explicitSolve( geometricOneField(), alpha1, phi, phiAlpha1, Sp, Su, 1.0, 0.0 )
        
        rho1f = fvc.interpolate( rho1 )
        rho2f = fvc.interpolate( rho2 )
        rhoPhi.ext_assign( phiAlpha1 * ( rho1f - rho2f ) + phi * rho2f )

        alpha2.ext_assign( scalar( 1 ) - alpha1 )

        pass

    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() << "  Min(alpha2) = " << alpha2.ext_min().value() << nl
    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
Example #53
0
def ContinuityErrs( phi, runTime, mesh, cumulativeContErr ):
    from Foam import fvc
    contErr = fvc.div(phi)

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

    globalContErr = runTime.deltaT().value() * contErr.weightedAverage( mesh.V() ).value();
        
    cumulativeContErr += globalContErr
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl
    return cumulativeContErr
Example #54
0
def ContinuityErrs( phi, runTime, mesh, cumulativeContErr ):
    from Foam import fvc
    contErr = fvc.div(phi)

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

    globalContErr = runTime.deltaT().value() * contErr.weightedAverage( mesh.V() ).value();
        
    cumulativeContErr += globalContErr
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl
    return cumulativeContErr
Example #55
0
def writeGradP( runTime, gradP ):
    if runTime.outputTime():
       from Foam.OpenFOAM import OFstream, fileName
       gradPFile = OFstream( runTime.path()/fileName( runTime.timeName() )/fileName( "uniform" )/fileName( "gradP.raw" ) )
       
       from Foam.OpenFOAM import nl, ext_Info
       if gradPFile.good():
          gradPFile << gradP << nl
          pass
       else:
          ext_Info() << "Cannot open file " << runTime.path()/fileName( runTime.timeName() )/fileName( "uniform" )/fileName( "gradP.raw" )
          import os
          os.abort()
Example #56
0
def compressibleCourantNo( mesh, amaxSf, runTime ):
    CoNum = 0.0
    meanCoNum = 0.0
    
    if mesh.nInternalFaces():
       amaxSfbyDelta = mesh.deltaCoeffs() * amaxSf 
       CoNum = ( amaxSfbyDelta / mesh.magSf() ).ext_max().value() * runTime.deltaT().value()
       meanCoNum = ( amaxSfbyDelta.sum() / mesh.magSf().sum() ).value() * runTime.deltaT().value()
       pass
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Mean and max Courant Numbers = " << meanCoNum << " " << CoNum << nl
    
    return CoNum, meanCoNum
Example #57
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

    from Foam.thermophysicalModels import basicPsiThermo
    thermo = basicPsiThermo.New(mesh)

    p = thermo.p()
    e = thermo.e()
    T = thermo.T()
    psi = thermo.psi()
    mu = thermo.mu()

    inviscid = True
    if mu.internalField().max() > 0.0:
        inviscid = False
        pass

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

    pbf, rhoBoundaryTypes = _rhoBoundaryTypes(p)

    from Foam.finiteVolume import volScalarField
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.AUTO_WRITE), thermo.rho(),
        rhoBoundaryTypes)
    rhoU = volVectorField(
        IOobject(word("rhoU"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE), rho * U)
    rhoE = volScalarField(
        IOobject(word("rhoE"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE),
        rho * (e + 0.5 * U.magSqr()))

    from Foam.OpenFOAM import dimensionedScalar, dimless
    from Foam.finiteVolume import surfaceScalarField
    pos = surfaceScalarField(
        IOobject(word("pos"), fileName(runTime.timeName()), mesh), mesh,
        dimensionedScalar(word("pos"), dimless, 1.0))

    neg = surfaceScalarField(
        IOobject(word("neg"), fileName(runTime.timeName()), mesh), mesh,
        dimensionedScalar(word("neg"), dimless, -1.0))

    return thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid