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 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 #3
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 #4
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
Example #5
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 #6
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 #7
0
def createFluidFields(fluidRegions, runTime):

    # Load boundary conditions
    from .. import derivedFvPatchFields

    # Initialise fluid field pointer lists
    from Foam.finiteVolume import PtrList_volScalarField
    rhoFluid = PtrList_volScalarField(fluidRegions.size())
    KFluid = PtrList_volScalarField(fluidRegions.size())

    from Foam.finiteVolume import PtrList_volVectorField
    UFluid = PtrList_volVectorField(fluidRegions.size())

    from Foam.finiteVolume import PtrList_surfaceScalarField
    phiFluid = PtrList_surfaceScalarField(fluidRegions.size())

    DpDtFluid = PtrList_volScalarField(fluidRegions.size())

    from Foam.OpenFOAM import PtrList_uniformDimensionedVectorField
    gFluid = PtrList_uniformDimensionedVectorField(fluidRegions.size())

    from Foam.compressible import PtrList_compressible_turbulenceModel
    turbulence = PtrList_compressible_turbulenceModel(fluidRegions.size())

    from Foam.thermophysicalModels import PtrList_basicPsiThermo
    thermoFluid = PtrList_basicPsiThermo(fluidRegions.size())

    p_rghFluid = PtrList_volScalarField(fluidRegions.size())

    ghFluid = PtrList_volScalarField(fluidRegions.size())

    ghfFluid = PtrList_surfaceScalarField(fluidRegions.size())

    from Foam.OpenFOAM import scalarList
    initialMassFluid = scalarList(fluidRegions.size())

    #Populate fluid field pointer lists

    for index in range(fluidRegions.size()):
        from Foam.OpenFOAM import ext_Info, nl
        ext_Info() << "*** Reading fluid mesh thermophysical properties for region " \
            << fluidRegions[ index ].name() << nl << nl

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

        from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo

        thermo = basicPsiThermo.New(fluidRegions[index])
        thermoFluid.ext_set(index, thermo)

        ext_Info() << "    Adding to rhoFluid\n" << nl
        from Foam.OpenFOAM import word, fileName, IOobject
        from Foam.finiteVolume import volScalarField
        rhoFluid.ext_set(
            index,
            volScalarField(
                IOobject(word("rho"), fileName(runTime.timeName()),
                         fluidRegions[index], IOobject.NO_READ,
                         IOobject.AUTO_WRITE), thermoFluid[index].rho()))

        ext_Info() << "    Adding to KFluid\n" << nl
        KFluid.ext_set(
            index,
            volScalarField(
                IOobject(word("K"), fileName(runTime.timeName()),
                         fluidRegions[index], IOobject.NO_READ,
                         IOobject.NO_WRITE),
                thermoFluid[index].Cp().ptr() * thermoFluid[index].alpha()))

        ext_Info() << "    Adding to UFluid\n" << nl
        from Foam.finiteVolume import volVectorField
        UFluid.ext_set(
            index,
            volVectorField(
                IOobject(word("U"), fileName(runTime.timeName()),
                         fluidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), fluidRegions[index]))

        ext_Info() << "    Adding to phiFluid\n" << nl
        from Foam.finiteVolume import surfaceScalarField
        from Foam.finiteVolume import linearInterpolate

        phiFluid.ext_set(
            index,
            surfaceScalarField(
                IOobject(word("phi"), fileName(runTime.timeName()),
                         fluidRegions[index], IOobject.READ_IF_PRESENT,
                         IOobject.AUTO_WRITE),
                linearInterpolate(rhoFluid[index] * UFluid[index])
                & fluidRegions[index].Sf()))

        ext_Info() << "    Adding to gFluid\n" << nl
        from Foam.OpenFOAM import uniformDimensionedVectorField
        gFluid.ext_set(
            index,
            uniformDimensionedVectorField(
                IOobject(word("g"), fileName(runTime.constant()),
                         fluidRegions[index], IOobject.MUST_READ,
                         IOobject.NO_WRITE)))

        ext_Info() << "    Adding to turbulence\n" << nl
        from Foam import compressible
        turbulence.ext_set(
            index,
            compressible.turbulenceModel.New(rhoFluid[index], UFluid[index],
                                             phiFluid[index],
                                             thermoFluid[index]))
        ext_Info() << "    Adding to ghFluid\n" << nl
        ghFluid.ext_set(
            index,
            volScalarField(word("gh"),
                           gFluid[index] & fluidRegions[index].C()))

        ext_Info() << "    Adding to ghfFluid\n" << nl
        ghfFluid.ext_set(
            index,
            surfaceScalarField(word("ghf"),
                               gFluid[index] & fluidRegions[index].Cf()))

        p_rghFluid.ext_set(
            index,
            volScalarField(
                IOobject(word("p_rgh"), fileName(runTime.timeName()),
                         fluidRegions[index], IOobject.MUST_READ,
                         IOobject.AUTO_WRITE), fluidRegions[index]))
        # Force p_rgh to be consistent with p
        p_rghFluid[index].ext_assign(thermoFluid[index].p() -
                                     rhoFluid[index] * ghFluid[index])

        from Foam import fvc
        initialMassFluid[index] = fvc.domainIntegrate(rhoFluid[index]).value()

        ext_Info() << "    Adding to DpDtFluid\n" << nl
        DpDtFluid.ext_set(
            index,
            volScalarField(
                word("DpDt"),
                fvc.DDt(
                    surfaceScalarField(
                        word("phiU"),
                        phiFluid[index] / fvc.interpolate(rhoFluid[index])),
                    thermoFluid[index].p())))

    return thermoFluid, rhoFluid, KFluid, UFluid, phiFluid, gFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid
Example #8
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)

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

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

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

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

    from Foam import fvc
    initialMass = fvc.domainIntegrate(rho)

    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, h, psi, rho, U, phi, turbulence, thermo, pZones, pMin, pressureImplicitPorosity, initialMass, nUCorr, pRefCell, pRefValue