Example #1
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

    p = thermo.p()
    e = thermo.e()
    psi = thermo.psi()
    rho = thermo.rho()

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh), rho())

    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.turbulenceModel.New(rho, U, phi, thermo())

    return p, e, psi, rho, U, phi, turbulence, thermo
Example #2
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 T\n" << nl

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

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

    ext_Info() << "Reading diffusivity DT\n" << nl
    from Foam.OpenFOAM import dimensionedScalar
    DT = dimensionedScalar( transportProperties.lookup( word( "DT" ) ) )
        
    return T, transportProperties, DT
Example #3
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 #4
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 #5
0
def write( runTime, mesh, T ):
    if runTime.outputTime():
       from Foam import fvc
       gradT = fvc.grad(T)
       
       from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
       from Foam.finiteVolume import volScalarField
       from Foam.OpenFOAM import vector
       gradTx = volScalarField( IOobject( word( "gradTx" ), 
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                          gradT.component( vector.X ) )
       gradTy = volScalarField( IOobject( word( "gradTy" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Y ) )

       gradTz = volScalarField( IOobject( word( "gradTz" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Z ) )
       runTime.write()
       pass
Example #6
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
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 #8
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 #9
0
def create_fields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

    p = thermo.p()
    h = thermo.h()
    psi = thermo.psi()

    from Foam.OpenFOAM import IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho())

    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)

    from Foam.OpenFOAM import dimensionedScalar
    pMin = dimensionedScalar(mesh.solutionDict().subDict(
        word("PIMPLE")).lookup(word("pMin")))

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

    # initialMass = fvc.domainIntegrate(rho)

    ext_Info() << "Creating field DpDt\n" << nl
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    DpDt = fvc.DDt(
        surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)

    from Foam.finiteVolume import MRFZones
    mrfZones = MRFZones(mesh)
    mrfZones.correctBoundaryVelocity(U)

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

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

    return thermo, turbulence, p, h, psi, rho, U, phi, pMin, DpDt, mrfZones, pZones, pressureImplicitPorosity
Example #10
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 #11
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 #12
0
def create_fields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

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

    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.turbulenceModel.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)

    ext_Info() << "Creating field DpDt\n" << nl
    from Foam import fvc
    DpDt = volScalarField(
        word("DpDt"),
        fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)),
                p))

    return thermo, p, rho, h, psi, U, phi, turbulence, gh, ghf, p_rgh, DpDt
Example #13
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
Example #14
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 )
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    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() )
    
    thermo.correct()

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

    from Foam import fvc
    initialMass = fvc.domainIntegrate(rho)
    
    return thermo, rho, p, h, psi, U, phi, turbulence, initialMass, pRefCell, pRefValue
Example #15
0
    def rho(self, *args):
        if len(args) > 1:
            raise AttributeError("len(args) > 1")
        if len(args) == 1:
            try:
                arg = float(args[0])
            except ValueError:
                raise AttributeError("The arg is not float")

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

        result = volScalarField(
            IOobject(word("rho"), fileName(self.mesh().time().timeName()),
                     self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE),
            self.mesh(), dimensionedScalar(word("zeroRho"), dimDensity, 0.0),
            zeroGradientFvPatchScalarField.typeName)

        #Accumulate data for all fields
        from Foam.OpenFOAM import ext_Info

        for lawI in self:
            # Python does not wait for evaluation of the closure expression, it destroys return values if it is no more in use
            lawI_rho = lawI.rho()
            result.internalField().ext_assign(
                result.internalField() +
                self.indicator(self.index(lawI)) * lawI_rho.internalField())

        result.correctBoundaryConditions()

        return result
Example #16
0
    def mu( self, *args ):
        if len(args) > 1:
            raise AttributeError("len(args) > 1")
        flag = False
        if len(args) == 1:
            try:
                t = float(args[0])
                flag = True
            except ValueError:
                raise AttributeError ("The arg is not float")
                
        if flag: 
            lawE = self.lawPtr_.E( t )
            lawNu = self.lawPtr_.nu( t )
        else:
            lawE = self.lawPtr_.E()
            lawNu = self.lawPtr_.nu()

        
        from Foam.finiteVolume import volScalarField
        from Foam.OpenFOAM import word, fileName, IOobject
        result  = volScalarField( IOobject( word( "mu" ),
                                            fileName( self.sigma_.time().timeName() ),
                                            self.sigma_.db(),
                                            IOobject.NO_READ,
                                            IOobject.NO_WRITE ),
                                  lawE / ( 2.0 * ( 1.0 + lawNu ) ) )
        return result
Example #17
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 #18
0
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

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

    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.turbulenceModel.New(rho, U, phi, thermo())

    ext_Info() << "Creating field DpDt\n" << nl
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    DpDt = volScalarField(
        word("DpDt"),
        fvc.DDt(surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)),
                p))

    thermo.correct()

    initialMass = fvc.domainIntegrate(rho)

    totalVolume = mesh.V().ext_sum()

    return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
Example #19
0
def _createFields(runTime, mesh, Omega, gHat):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

    ext_Info() << "Reading field h\n" << nl
    h = volScalarField(
        IOobject(word("h"), fileName(runTime.timeName()), mesh,
                 IOobject.MUST_READ, IOobject.AUTO_WRITE), mesh)
    from Foam.OpenFOAM import dimLength, dimensionedScalar
    ext_Info() << "Reading field h0 if present\n" << nl
    h0 = volScalarField(
        IOobject(
            word("h0"),
            fileName(
                runTime.findInstance(fileName(word("polyMesh")),
                                     word("points"))), mesh,
            IOobject.READ_IF_PRESENT), mesh,
        dimensionedScalar(word("h0"), dimLength, 0.0))

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

    ext_Info() << "Creating field hU\n" << nl
    hU = volVectorField(
        IOobject(word("hU"), fileName(runTime.timeName()), mesh), h * U,
        U.ext_boundaryField().types())

    ext_Info() << "Creating field hTotal for post processing\n" << nl
    hTotal = volScalarField(
        IOobject(word("hTotal"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), h + h0)

    hTotal.write()

    phi = createPhi(runTime, hU, mesh)

    ext_Info() << "Creating Coriolis Force" << nl
    from Foam.OpenFOAM import dimensionedVector
    F = dimensionedVector(word("F"), ((2.0 * Omega) & gHat) * gHat)

    return h, h0, U, hU, hTotal, phi, F
Example #20
0
def _createFields( runTime, mesh, R, Cv ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading field p\n" << nl
    from Foam.OpenFOAM import IOdictionary, 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 T\n" << nl
    T = volScalarField( IOobject( word( "T" ),
                                  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 )

    psi = volScalarField( IOobject( word( "psi" ),
                                    fileName( runTime.timeName() ),
                                    mesh,
                                    IOobject.NO_READ,
                                    IOobject.NO_WRITE ),
                          1.0 / ( R * T ) )
    psi.oldTime()
    
    rho = volScalarField( IOobject( word( "rho" ),
                                    fileName( runTime.timeName() ),
                                    mesh ),
                          psi * p,
                          p.ext_boundaryField().types() )
    
    rhoU = volVectorField( IOobject( word( "rhoU" ),
                                     fileName( runTime.timeName() ) , 
                                     mesh,
                                     IOobject.NO_READ,
                                     IOobject.NO_WRITE ),
                           rho * U,
                           U.ext_boundaryField().types() )

    rhoE = volScalarField( IOobject( word( "rhoE" ),
                                     fileName( runTime.timeName() ),
                                     mesh,
                                     IOobject.NO_READ,
                                     IOobject.NO_WRITE ),
                           rho * Cv * T + 0.5 * rho * ( rhoU / rho ).magSqr(),
                           T.ext_boundaryField().types() )
    
    return p, T, U, psi, rho, rhoU, rhoE
Example #21
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 #22
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)

    return p, U, phi
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 #24
0
 def __init__(self, runTime):
     from Foam.OpenFOAM import IOobject, word, fileName
     IOdictionary.__init__(
         self,
         IOobject(word("regionProperties"),
                  fileName(runTime.time().constant()), runTime.db(),
                  IOobject.MUST_READ, IOobject.NO_WRITE))
     from Foam.OpenFOAM import wordList
     self.fluidRegionNames = wordList(self.lookup(word("fluidRegionNames")))
     self.solidRegionNames = wordList(self.lookup(word("solidRegionNames")))
     pass
Example #25
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())

    from Foam.finiteVolume import volVectorField
    ext_Info() << "Reading field U\n" << nl
    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("PIMPLE")), pRefCell, pRefValue)

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

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

    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    ext_Info() << "Reading field rAU if present\n" << nl
    rAU = volScalarField(
        IOobject(word("rAU"), fileName(runTime.timeName()), mesh(),
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), mesh(),
        runTime.deltaT(), zeroGradientFvPatchScalarField.typeName)

    return p, U, phi, laminarTransport, turbulence, rAU, pRefCell, pRefValue
Example #26
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

    p = thermo.p()
    h = thermo.h()
    psi = thermo.psi()

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE), thermo.rho())

    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)

    from Foam.OpenFOAM import dimensionedScalar
    pMin = dimensionedScalar(mesh.solutionDict().subDict(
        word("PIMPLE")).lookup(word("pMin")))

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

    ext_Info() << "Creating field DpDt\n" << nl
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    DpDt = fvc.DDt(
        surfaceScalarField(word("phiU"), phi / fvc.interpolate(rho)), p)

    return p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt
Example #27
0
    def sigmaY(self):
        from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField
        from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimForce, dimArea, GREAT
        tresult = volScalarField(
            IOobject(word("sigmaY"), fileName(self.mesh().time().timeName()),
                     self.mesh(), IOobject.NO_READ, IOobject.NO_WRITE),
            self.mesh(),
            dimensionedScalar(word("zeroSigmaY"), dimForce / dimArea, GREAT),
            zeroGradientFvPatchScalarField.typeName)
        tresult().correctBoundaryConditions()

        return tresult
Example #28
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 #29
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 #30
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 #31
0
def __mapVolField__( theSourceField, meshToMeshInterp, patchMap, cuttingPatches ) :
    aTargetField = None
    
    meshTarget = meshToMeshInterp.toMesh()
    aFieldName = theSourceField.name()

    aFieldClass = getFieldClass( theSourceField )
    if aFieldClass.ext_foundObject( meshTarget, aFieldName ) :
        aTargetField = aFieldClass.ext_lookupObject( meshTarget, aFieldName )
    else:
        from Foam.OpenFOAM import IOobject, fileName    
        aTargetIOobject = IOobject( aFieldName,
                                    fileName( meshTarget.time().timeName() ),
                                    meshTarget,
                                    IOobject.READ_IF_PRESENT,
                                    IOobject.AUTO_WRITE )
        if aTargetIOobject.headerOk() :
            aTargetField = aFieldClass( aTargetIOobject, meshTarget )
            pass
        pass
    
    from Foam import fvc
    meshSource = meshToMeshInterp.fromMesh()
    ext_Info() << tab <<"interpolating \"" << aFieldName << "\"" << nl
    ext_Info() << tab << tab << "source : \"" << meshSource.time().path() << "\"" << nl
    ext_Info() << tab << tab << tab << fvc.domainIntegrate( theSourceField ) << nl
    ext_Info() << tab << tab << tab << theSourceField.ext_min() << nl
    ext_Info() << tab << tab << tab << theSourceField.ext_max() << nl

    from Foam.sampling import meshToMesh
    meshToMeshInterp.interpolate( aTargetField, theSourceField, meshToMesh.INTERPOLATE )

    ext_Info() << tab << tab << "target : \"" << meshTarget.time().path() << "\"" << nl
    ext_Info() << tab << tab << tab << fvc.domainIntegrate( aTargetField ) << nl
    ext_Info() << tab << tab << tab << aTargetField.ext_min() << nl
    ext_Info() << tab << tab << tab << aTargetField.ext_max() << nl
   
    return aTargetField
Example #32
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