コード例 #1
0
ファイル: __init__.py プロジェクト: asimurzin/sonicLiquidFlux
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
コード例 #2
0
 def __init__( self, name, sigma, dict_ ):
     
     from Foam.OpenFOAM import word, dictionary
     from Foam.finiteVolume import volSymmTensorField
     try:
         name = word( str( name ) )
     except ValueError:
        raise AttributeError("The second arg is not string")
    
     try:
         volSymmTensorField.ext_isinstance( sigma )
     except TypeError:
         raise AssertionError( "sigma != volSymmTensorField" )
        
     from Foam.OpenFOAM import dictionary
     try:
         dictionary.ext_isinstance( dict_ )
     except TypeError:
         raise AssertionError( "dict_ != dictionary" )
                 
     rheologyLaw.__init__( self, name, sigma, dict_ )
     
     from Foam.OpenFOAM import dimensionedScalar
     self.rho_ = dimensionedScalar( dict_.lookup(word( "rho" ) ) )
     self.E_ = dimensionedScalar( dict_.lookup( word( "E" ) ) )
     self.nu_ = dimensionedScalar( dict_.lookup( word( "nu" ) ) )
     pass
コード例 #3
0
ファイル: __init__.py プロジェクト: asimurzin/rhopSonicFlux
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
コード例 #4
0
    def __init__(self, name, sigma, dict_):

        from Foam.OpenFOAM import word, dictionary
        from Foam.finiteVolume import volSymmTensorField
        try:
            name = word(str(name))
        except ValueError:
            raise AttributeError("The second arg is not string")

        try:
            volSymmTensorField.ext_isinstance(sigma)
        except TypeError:
            raise AssertionError("sigma != volSymmTensorField")

        from Foam.OpenFOAM import dictionary
        try:
            dictionary.ext_isinstance(dict_)
        except TypeError:
            raise AssertionError("dict_ != dictionary")

        rheologyLaw.__init__(self, name, sigma, dict_)

        from Foam.OpenFOAM import dimensionedScalar
        self.rho_ = dimensionedScalar(dict_.lookup(word("rho")))
        self.E_ = dimensionedScalar(dict_.lookup(word("E")))
        self.nu_ = dimensionedScalar(dict_.lookup(word("nu")))
        pass
コード例 #5
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
コード例 #6
0
ファイル: __init__.py プロジェクト: asimurzin/interFlux
def correctPhi(runTime, mesh, phi, pd, rho, U, cumulativeContErr, nNonOrthCorr, pdRefCell, pdRefValue):

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField

    pcorrTypes = wordList(pd.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName)

    from Foam.finiteVolume import fixedValueFvPatchScalarField

    for i in range(pd.ext_boundaryField().size()):
        if pd.ext_boundaryField()[i].fixesValue():
            pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
            pass
        pass

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

    pcorr = volScalarField(
        IOobject(word("pcorr"), fileName(runTime.timeName()), mesh, IOobject.NO_READ, IOobject.NO_WRITE),
        mesh,
        dimensionedScalar(word("pcorr"), pd.dimensions(), 0.0),
        pcorrTypes,
    )

    from Foam.OpenFOAM import dimTime

    rUAf = dimensionedScalar(word("(1|A(U))"), dimTime / rho.dimensions(), 1.0)

    from Foam.finiteVolume import adjustPhi

    adjustPhi(phi, U, pcorr)

    from Foam import fvc, fvm

    for nonOrth in range(nNonOrthCorr + 1):
        pcorrEqn = fvm.laplacian(rUAf, pcorr) == fvc.div(phi)

        pcorrEqn.setReference(pdRefCell, pdRefValue)
        pcorrEqn.solve()

        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - pcorrEqn.flux())
            pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

    pass
コード例 #7
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
コード例 #8
0
def readThermodynamicProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermodynamicProperties\n" << nl

    from Foam.OpenFOAM import IOdictionary, IOobject, fileName, word
    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")))

    return thermodynamicProperties, R, Cv
コード例 #9
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
コード例 #10
0
ファイル: __init__.py プロジェクト: asimurzin/laplacianFlux
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
コード例 #11
0
    def updateCoeffs( self ) :
        try:
            
            if self.updated() :
               return
            from Foam.finiteVolume import volScalarField
            from Foam.OpenFOAM import word
            rhop = volScalarField.ext_lookupPatchField( self.patch(), word( "rho" ) )
            from Foam.finiteVolume import volVectorField            
            rhoUp =volVectorField.ext_lookupPatchField( self.patch(), word( "rhoU" ) )
            
            T = volScalarField.ext_lookupObject( self.db(), word( "T" ) )
            patchi = self.patch().index()
            Tp = T.ext_boundaryField()[patchi] 
            
            Tp.evaluate()

            from Foam.OpenFOAM import IOdictionary
            thermodynamicProperties = IOdictionary.ext_lookupObject( self.db(), word( "thermodynamicProperties" ) )
            
            from Foam.OpenFOAM import dimensionedScalar
            Cv = dimensionedScalar( thermodynamicProperties.lookup( word( "Cv" ) ) )
                   
            self.valueFraction().ext_assign( rhop.ext_snGrad() / ( rhop.ext_snGrad() -  rhop * self.patch().deltaCoeffs()  ) )
            self.refValue().ext_assign( 0.5 * rhop * ( rhoUp / rhop ).magSqr() )

            self.refGrad().ext_assign( rhop * Cv.value() * Tp.ext_snGrad() +\
                                       ( self.refValue() - ( 0.5 * rhop.patchInternalField()\
                                                          * ( rhoUp.patchInternalField() /rhop.patchInternalField() ).magSqr() ) ) * self.patch().deltaCoeffs() )
            mixedFvPatchScalarField.updateCoeffs( self )
            pass
        except Exception, exc:
            import sys, traceback
            traceback.print_exc( file = sys.stdout )
            raise exc
コード例 #12
0
 def nu( 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, dimless
     
     result = volScalarField( IOobject( word( "nu" ),
                                        fileName( self.mesh().time().timeName() ),
                                        self.mesh(),
                                        IOobject.NO_READ,
                                        IOobject.NO_WRITE ),
                              self.mesh(),
                              dimensionedScalar( word( "zeroE" ), dimless, 0.0 ),
                              zeroGradientFvPatchScalarField.typeName )
     
     #Accumulate data for all fields
     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_nu =lawI.nu()
         result.internalField().ext_assign( result.internalField() + \
                                            self.indicator( self.index( lawI ) ) * lawI_nu.internalField()  )
         
     result.correctBoundaryConditions()
     
     return result
コード例 #13
0
def setRegionFluidFields( i, fluidRegions, thermoFluid, rhoFluid, KFluid, UFluid, \
                          phiFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid ):
    mesh = fluidRegions[i]

    thermo = thermoFluid[i]
    rho = rhoFluid[i]
    K = KFluid[i]
    U = UFluid[i]
    phi = phiFluid[i]

    turb = turbulence[i]
    DpDt = DpDtFluid[i]

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

    p_rgh = p_rghFluid[i]
    gh = ghFluid[i]
    ghf = ghfFluid[i]

    from Foam.OpenFOAM import dimensionedScalar, word, dimMass
    initialMass = dimensionedScalar(word("massIni"), dimMass,
                                    initialMassFluid[i])

    return mesh, thermo, rho, K, U, phi, turb, DpDt, p, psi, h, initialMass, p_rgh, gh, ghf
コード例 #14
0
def setRegionFluidFields( i, fluidRegions, thermoFluid, rhoFluid, KFluid, UFluid, \
                          phiFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid ):
    mesh = fluidRegions[ i ]

    thermo = thermoFluid[ i ]
    rho = rhoFluid[ i ]
    K = KFluid[ i ]
    U = UFluid[ i ]
    phi = phiFluid[ i ]
    
    turb = turbulence[ i ]
    DpDt = DpDtFluid[ i ]

    p = thermo.p()
    psi = thermo.psi()
    h = thermo.h()
    
    p_rgh = p_rghFluid[ i ]
    gh = ghFluid[ i ]
    ghf = ghfFluid[ i ]
    
    from Foam.OpenFOAM import dimensionedScalar, word, dimMass
    initialMass = dimensionedScalar( word( "massIni" ), dimMass, initialMassFluid[ i ] )

    return mesh, thermo, rho, K, U, phi, turb, DpDt, p, psi, h, initialMass, p_rgh, gh, ghf
コード例 #15
0
ファイル: __init__.py プロジェクト: asimurzin/sonicFlux
def readThermodynamicProperties( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermodynamicProperties\n" << nl
    
    from Foam.OpenFOAM import IOdictionary, IOobject, fileName, word
    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" ) ) )
    
    return thermodynamicProperties, R, Cv
コード例 #16
0
ファイル: __init__.py プロジェクト: asimurzin/interFlux
def correctPhi( runTime, mesh, phi, p, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue ):
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName )
    
    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range( p.ext_boundaryField().size() ):
       if p.ext_boundaryField()[i].fixesValue():
          pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
          pass
       pass
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar
    from Foam.finiteVolume import volScalarField
    pcorr = volScalarField( IOobject( word( "pcorr" ),
                                      fileName( runTime.timeName() ),
                                      mesh,
                                      IOobject.NO_READ,
                                      IOobject.NO_WRITE ),
                            mesh,
                            dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0 ),
                            pcorrTypes  )
    
    from Foam.OpenFOAM import dimTime
    rUAf = dimensionedScalar( word( "(1|A(U))" ), dimTime / rho.dimensions(), 1.0)
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phi, U, pcorr)
    
    from Foam import fvc, fvm
    for nonOrth in range( nNonOrthCorr + 1 ):
        pcorrEqn = fvm.laplacian( rUAf, pcorr ) == fvc.div( phi )

        pcorrEqn.setReference(pRefCell, pRefValue)
        pcorrEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi  - pcorrEqn.flux() )
           pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    pass
コード例 #17
0
ファイル: __init__.py プロジェクト: asimurzin/potentialFlux
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
コード例 #18
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
コード例 #19
0
def readTransportProperties( U, phi ):
    from Foam.transportModels import singlePhaseTransportModel
    laminarTransport = singlePhaseTransportModel( U, phi )
    
    from Foam.OpenFOAM import dimensionedScalar, word
    # Thermal expansion coefficient [1/K]
    beta = dimensionedScalar( laminarTransport.lookup( word( "beta" ) ) )

    # Reference temperature [K]
    TRef = dimensionedScalar( laminarTransport.lookup( word( "TRef" ) ) )

    # Laminar Prandtl number
    Pr = dimensionedScalar( laminarTransport.lookup( word( "Pr" ) ) )

    # Turbulent Prandtl number
    Prt = dimensionedScalar( laminarTransport.lookup( word( "Prt" ) ) )
    
    return laminarTransport, beta, TRef,Pr, Prt
コード例 #20
0
def readTransportProperties(U, phi):
    from Foam.transportModels import singlePhaseTransportModel
    laminarTransport = singlePhaseTransportModel(U, phi)

    from Foam.OpenFOAM import dimensionedScalar, word
    # Thermal expansion coefficient [1/K]
    beta = dimensionedScalar(laminarTransport.lookup(word("beta")))

    # Reference temperature [K]
    TRef = dimensionedScalar(laminarTransport.lookup(word("TRef")))

    # Laminar Prandtl number
    Pr = dimensionedScalar(laminarTransport.lookup(word("Pr")))

    # Turbulent Prandtl number
    Prt = dimensionedScalar(laminarTransport.lookup(word("Prt")))

    return laminarTransport, beta, TRef, Pr, Prt
コード例 #21
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
コード例 #22
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
コード例 #23
0
ファイル: __init__.py プロジェクト: asimurzin/sonicLiquidFlux
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
コード例 #24
0
ファイル: __init__.py プロジェクト: asimurzin/sonicLiquidFlux
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
コード例 #25
0
ファイル: __init__.py プロジェクト: asimurzin/interDyMFlux
def _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ):
    rAU = 1.0/UEqn.A()
     
    from Foam import fvc
    rAUf = fvc.interpolate( rAU )
    
    U.ext_assign( rAU * UEqn.H() )
    
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phiU = surfaceScalarField( word( "phiU" ),  fvc.interpolate( U ) & mesh.Sf() )
    
    if p_rgh.needReference():
        fvc.makeRelative( phiU, U )
        from Foam.finiteVolume import adjustPhi
        adjustPhi( phiU, U, p )
        fvc.makeAbsolute( phiU, U )
        pass
    
    phi.ext_assign( phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) )*rAUf*mesh.magSf() )

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

        p_rghEqn.solve( mesh.solver( p_rgh.select(corr == nCorr-1 and nonOrth == nNonOrthCorr) ) )
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - p_rghEqn.flux() )
           pass
        pass
    
    U.ext_assign( U + rAU * fvc.reconstruct( ( phi - phiU ) / rAUf ) )
    U.correctBoundaryConditions()

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    # Make the fluxes relative to the mesh motion
    fvc.makeRelative( phi, U )
    
    p == p_rgh + rho * gh

    if p_rgh.needReference():
       from Foam.OpenFOAM import pRefValue
       p.ext_assign( p + dimensionedScalar( word( "p" ),
                                            p.dimensions(),
                                            pRefValue - getRefCellValue(p, pRefCell) ) )
       p_rgh.ext_assign( p - rho * gh )
       pass
    
    return cumulativeContErr
コード例 #26
0
ファイル: __init__.py プロジェクト: asimurzin/rhoSimpleFlux
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.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.OpenFOAM import dimensionedScalar
    from Foam import fvc   
    initialMass = fvc.domainIntegrate( rho )
    
    return thermo, rho, p, h, psi, U, phi, pRefCell, pRefValue, turbulence, initialMass, pMin
コード例 #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
コード例 #28
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
コード例 #29
0
def _correctPhi(runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue,
                cumulativeContErr):
    if mesh.changing():
        for patchi in range(U.boundaryField().size()):
            if U.boundaryField()[patchi].fixesValue():
                U.boundaryField()[patchi].initEvaluate()
                pass
            pass
        for patchi in range(U.boundaryField().size()):
            if U.boundaryField()[patchi].fixesValue():
                U.boundaryField()[patchi].evaluate()
                phi.boundaryField()[patchi].ext_assign(
                    U.boundaryField()[patchi]
                    & mesh.Sf().boundaryField()[patchi])
                pass
            pass
        pass

    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList(p.ext_boundaryField().size(),
                          zeroGradientFvPatchScalarField.typeName)

    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range(p.ext_boundaryField().size()):
        if p.ext_boundaryField()[i].fixesValue():
            pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
            pass
        pass

    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar
    pcorr = volScalarField(
        IOobject(word("pcorr"), fileName(runTime.timeName()), mesh(),
                 IOobject.NO_READ, IOobject.NO_WRITE), mesh(),
        dimensionedScalar(word("pcorr"), p.dimensions(), 0.0), pcorrTypes)

    for nonOrth in range(nNonOrthCorr + 1):
        from Foam import fvm, fvc
        pcorrEqn = (fvm.laplacian(rAU, pcorr) == fvc.div(phi))

        pcorrEqn.setReference(pRefCell, pRefValue)
        pcorrEqn.solve()

        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - pcorrEqn.flux())
            pass
        pass
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr)

    return cumulativeContErr
コード例 #30
0
ファイル: __init__.py プロジェクト: asimurzin/pimpleDyMFlux
def _correctPhi( runTime, mesh, p, rAU, phi, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ):
    if mesh.changing():
       for patchi in range( U.boundaryField().size() ):
           if U.boundaryField()[patchi].fixesValue():
              U.boundaryField()[patchi].initEvaluate()
              pass
           pass
       for patchi in range( U.boundaryField().size() ):
           if U.boundaryField()[patchi].fixesValue():
              U.boundaryField()[patchi].evaluate()
              phi.boundaryField()[patchi].ext_assign( U.boundaryField()[patchi] & mesh.Sf().boundaryField()[patchi] )
              pass
           pass
       pass
       
    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList( p.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName )
    
    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range( p.ext_boundaryField().size() ):
        if p.ext_boundaryField()[i].fixesValue():
           pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
           pass
        pass
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName, dimensionedScalar
    pcorr = volScalarField( IOobject( word( "pcorr" ),
                                      fileName( runTime.timeName() ),
                                      mesh(),
                                      IOobject.NO_READ,
                                      IOobject.NO_WRITE ),
                            mesh(),
                            dimensionedScalar( word( "pcorr" ), p.dimensions(), 0.0),
                            pcorrTypes )
     
    for nonOrth in range( nNonOrthCorr + 1 ):
        from Foam import fvm,fvc
        pcorrEqn = ( fvm.laplacian( rAU, pcorr ) == fvc.div( phi ) )

        pcorrEqn.setReference(pRefCell, pRefValue)
        pcorrEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pcorrEqn.flux() )
           pass
        pass
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )     

    return cumulativeContErr
コード例 #31
0
ファイル: __init__.py プロジェクト: asimurzin/sonicFlux
def readingTransportProperties( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading transportProperties\n" << nl
    
    from Foam.OpenFOAM import IOdictionary, IOobject, fileName, word
    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
コード例 #32
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
コード例 #33
0
ファイル: __init__.py プロジェクト: asimurzin/rhoPimpleFlux
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
コード例 #34
0
def fun_pEqn( i, fluidRegions, Uf, pdf, rhof, thermof, phif, ghf, Kf, DpDtf, turb, initialMassf, UEqn, pRef, corr, nCorr, nNonOrthCorr, cumulativeContErr ) :
    
    closedVolume = False

    rhof[ i ].ext_assign( thermof[ i ].rho() )
    rUA = 1.0 / UEqn.A()
    Uf[ i ].ext_assign( rUA * UEqn.H() )

    from Foam import fvc
    phif[ i ] .ext_assign( fvc.interpolate( rhof[ i ] ) * ( ( fvc.interpolate( Uf[ i ] ) & fluidRegions[ i ].Sf() ) + 
                                                                      fvc.ddtPhiCorr( rUA, rhof[ i ], Uf[ i ], phif[ i ] ) ) - 
                                            fvc.interpolate( rhof[ i ] * rUA * ghf[ i ] ) * fvc.snGrad( rhof[ i ] ) * fluidRegions[ i ].magSf() )
    
    # Solve pressure difference
    pdEqn, closedVolume = fun_pdEqn( corr, nCorr, nNonOrthCorr, closedVolume, pdf[i], pRef, rhof[i], thermof[i].psi(), rUA, ghf[i], phif[i] )
    
    # Solve continuity
    rhoEqn( rhof[i], phif[i] )
    
    # Update pressure field (including bc)
    from Foam.OpenFOAM import word
    thermof[i].p() == pdf[ i ] + rhof[ i ] * ghf[ i ] + pRef
    
    from Foam.finiteVolume import surfaceScalarField
    DpDtf[i].ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phif[ i ] / fvc.interpolate( rhof[ i ] ) ), thermof[i].p() ) )

    # Update continuity errors
    cumulativeContErr = compressibleContinuityErrors( cumulativeContErr, rhof[i], thermof[i] )
        
    # Correct velocity field
    Uf[ i ].ext_assign( Uf[i] - rUA * ( fvc.grad( pdf[ i ] ) + fvc.grad( rhof[ i ] ) * ghf[ i ] ) )
    Uf[ i ].correctBoundaryConditions()
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if (closedVolume):
       from Foam.OpenFOAM import dimensionedScalar, dimMass
       thermof[i].p().ext_assign( thermof[i].p() + 
                                  ( dimensionedScalar( word( "massIni" ),
                                                       dimMass,
                                                       initialMassf[ i ] ) - fvc.domainIntegrate( thermof[ i ].psi() * thermof[ i ].p() ) )
                                  / fvc.domainIntegrate( thermof[ i ].psi() ) )
       rhof[ i ].ext_assign( thermof[ i ].rho() )
    
    # Update thermal conductivity
    Kf[i].ext_assign( rhof[ i ] * thermof[ i ].Cp() * turb[ i ].alphaEff() )

    return cumulativeContErr
コード例 #35
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.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.OpenFOAM import dimensionedScalar
    from Foam import fvc
    initialMass = fvc.domainIntegrate(rho)

    return thermo, rho, p, h, psi, U, phi, pRefCell, pRefValue, turbulence, initialMass, pMin
コード例 #36
0
ファイル: __init__.py プロジェクト: asimurzin/dnsFlux
def readTurbulenceProperties(runTime, mesh, U):
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, ext_Info, nl

    ext_Info() << "Reading turbulenceProperties\n" << nl
    turbulenceProperties = IOdictionary(
        IOobject(word("turbulenceProperties"), fileName(runTime.constant()),
                 mesh, IOobject.MUST_READ, IOobject.NO_WRITE))

    from Foam.OpenFOAM import dimensionedScalar, dimTime
    force = U / dimensionedScalar(word("dt"), dimTime,
                                  runTime.deltaT().value())

    from Foam.randomProcesses import Kmesh, UOprocess
    K = Kmesh(mesh)
    forceGen = UOprocess(K, runTime.deltaT().value(), turbulenceProperties)

    return turbulenceProperties, force, K, forceGen
コード例 #37
0
ファイル: __init__.py プロジェクト: asimurzin/channelFlux
def createGradP( runTime ):
    from Foam.OpenFOAM import dimensionedScalar, dimensionSet, IFstream, word
    gradP = dimensionedScalar( word( "gradP" ),
                               dimensionSet( 0.0, 1.0, -2.0, 0.0, 0.0 ),
                               0.0 )
    from Foam.OpenFOAM import word, fileName, ext_Info, nl
    gradPFile = IFstream( runTime.path()/fileName( runTime.timeName() )/fileName( "uniform" )/ fileName( "gradP.raw" ) )
    
    if gradPFile.good():
       gradPFile >> gradP
       ext_Info() << "Reading average pressure gradient" << nl << nl
       pass
    else:
       ext_Info() << "Initializing with 0 pressure gradient" << nl << nl
       pass
    
    return gradP, gradPFile
コード例 #38
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
コード例 #39
0
ファイル: __init__.py プロジェクト: asimurzin/dnsFlux
def readTurbulenceProperties( runTime, mesh, U ):
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, ext_Info, nl
    
    ext_Info() << "Reading turbulenceProperties\n" << nl
    turbulenceProperties = IOdictionary( IOobject( word( "turbulenceProperties" ),
                                                   fileName( runTime.constant() ),
                                                   mesh,
                                                   IOobject.MUST_READ,
                                                   IOobject.NO_WRITE ) )

    from Foam.OpenFOAM import dimensionedScalar, dimTime
    force = U / dimensionedScalar( word( "dt" ), dimTime, runTime.deltaT().value() )

    from Foam.randomProcesses import Kmesh, UOprocess
    K = Kmesh( mesh )
    forceGen = UOprocess( K, runTime.deltaT().value(), turbulenceProperties )
    
    return turbulenceProperties, force, K, forceGen
コード例 #40
0
def readThermophysicalProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysicalProperties\n" << nl

    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    # Pr defined as a separate constant to enable calculation of k, currently
    # inaccessible through thermo
    thermophysicalProperties = IOdictionary(
        IOobject(word("thermophysicalProperties"),
                 fileName(runTime.constant()), mesh, IOobject.MUST_READ,
                 IOobject.NO_WRITE))

    from Foam.OpenFOAM import dimensionedScalar, dimless
    Pr = dimensionedScalar(word("Pr"), dimless, 1.0)

    if thermophysicalProperties.found(word("Pr")):
        Pr = thermophysicalProperties.lookup(word("Pr"))
        pass
    return thermophysicalProperties, Pr
コード例 #41
0
ファイル: __init__.py プロジェクト: asimurzin/potentialFlux
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.NO_WRITE ),
                        mesh )
    
    from Foam.OpenFOAM import dimensionedScalar
    p.ext_assign( dimensionedScalar( word( "zero" ), p.dimensions(), 0.0 ) )

    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.OpenFOAM import dimensionedVector, vector
    U.ext_assign( dimensionedVector( word( "0" ), U.dimensions(), vector.zero ) )

    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc
    phi = surfaceScalarField( IOobject( word( "phi" ),
                                        fileName( runTime.timeName() ),
                                        mesh,
                                        IOobject.NO_READ,
                                        IOobject.AUTO_WRITE ),
                              fvc.interpolate( U ) & mesh.Sf() )


    pRefCell = 0
    pRefValue = 0.0
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )
           
    return p, U, phi, pRefCell, pRefValue
コード例 #42
0
def readTransportProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    ext_Info() << "\nReading transportProperties\n" << nl

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

    from Foam.OpenFOAM import dimensionedScalar, dimensionedVector
    nu = dimensionedScalar(transportProperties.lookup(word("nu")))

    #  Read centerline velocity for channel simulations
    Ubar = dimensionedVector(transportProperties.lookup(word("Ubar")))

    magUbar = Ubar.mag()
    from Foam.OpenFOAM import vector
    flowDirection = (Ubar / magUbar).ext_value()

    return transportProperties, nu, Ubar, magUbar, flowDirection
コード例 #43
0
ファイル: __init__.py プロジェクト: asimurzin/rhoCentralFlux
def readThermophysicalProperties( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysicalProperties\n" << nl
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    # Pr defined as a separate constant to enable calculation of k, currently
    # inaccessible through thermo
    thermophysicalProperties = IOdictionary( IOobject( word( "thermophysicalProperties" ),
                                                       fileName( runTime.constant() ),
                                                       mesh,
                                                       IOobject.MUST_READ,
                                                       IOobject.NO_WRITE ) )
    
    from Foam.OpenFOAM import dimensionedScalar, dimless
    Pr = dimensionedScalar(word( "Pr" ), dimless, 1.0)
    
    if thermophysicalProperties.found( word( "Pr" ) ):
       Pr = thermophysicalProperties.lookup( word( "Pr" ) )
       pass
    return thermophysicalProperties, Pr
コード例 #44
0
ファイル: __init__.py プロジェクト: asimurzin/rhoPimpleFlux
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
コード例 #45
0
ファイル: __init__.py プロジェクト: asimurzin/icoFlux
def createFields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading transportProperties\n"

    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
    nu = dimensionedScalar( transportProperties.lookup( word( "nu" ) ) );

    ext_Info() << "Reading field p\n" << nl
    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( "PISO" ) ), pRefCell, pRefValue )

    return transportProperties, nu, p, U, phi, pRefCell, pRefValue
コード例 #46
0
    def sigmaY(self):
        from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField
        from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimForce, dimArea, GREAT

        result = 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)

        #Accumulate data for all fields
        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_sigmaY = lawI.sigmaY()
            result.internalField().ext_assign( result.internalField() + \
                                               self.indicator( lawI ) * lawI_sigmaY.internalField()  )

        result.correctBoundaryConditions()

        return result
コード例 #47
0
    def updateCoeffs(self):
        try:

            if self.updated():
                return
            from Foam.finiteVolume import volScalarField
            from Foam.OpenFOAM import word
            rhop = volScalarField.ext_lookupPatchField(self.patch(),
                                                       word("rho"))
            from Foam.finiteVolume import volVectorField
            rhoUp = volVectorField.ext_lookupPatchField(
                self.patch(), word("rhoU"))

            T = volScalarField.ext_lookupObject(self.db(), word("T"))
            patchi = self.patch().index()
            Tp = T.ext_boundaryField()[patchi]

            Tp.evaluate()

            from Foam.OpenFOAM import IOdictionary
            thermodynamicProperties = IOdictionary.ext_lookupObject(
                self.db(), word("thermodynamicProperties"))

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

            self.valueFraction().ext_assign(
                rhop.ext_snGrad() /
                (rhop.ext_snGrad() - rhop * self.patch().deltaCoeffs()))
            self.refValue().ext_assign(0.5 * rhop * (rhoUp / rhop).magSqr())

            self.refGrad().ext_assign( rhop * Cv.value() * Tp.ext_snGrad() +\
                                       ( self.refValue() - ( 0.5 * rhop.patchInternalField()\
                                                          * ( rhoUp.patchInternalField() /rhop.patchInternalField() ).magSqr() ) ) * self.patch().deltaCoeffs() )
            mixedFvPatchScalarField.updateCoeffs(self)
            pass
        except Exception, exc:
            import sys, traceback
            traceback.print_exc(file=sys.stdout)
            raise exc
コード例 #48
0
ファイル: __init__.py プロジェクト: asimurzin/channelFlux
def readTransportProperties( runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    ext_Info() << "\nReading transportProperties\n" << nl
    
    transportProperties = IOdictionary( IOobject( word( "transportProperties" ),
                                                  fileName( runTime.constant() ),
                                                  mesh,
                                                  IOobject.MUST_READ,
                                                  IOobject.NO_WRITE,
                                                  False ) )
    
    from Foam.OpenFOAM import dimensionedScalar, dimensionedVector
    nu = dimensionedScalar( transportProperties.lookup( word( "nu" ) ) )
    
    #  Read centerline velocity for channel simulations
    Ubar = dimensionedVector( transportProperties.lookup( word( "Ubar" ) ) )

    magUbar = Ubar.mag()
    from Foam.OpenFOAM import vector
    flowDirection = ( Ubar / magUbar ).ext_value()
    
    return transportProperties, nu, Ubar, magUbar, flowDirection
コード例 #49
0
 def sigmaY( self ):
     from Foam.finiteVolume import volScalarField, zeroGradientFvPatchScalarField
     from Foam.OpenFOAM import word, fileName, IOobject, dimensionedScalar, dimForce, dimArea, GREAT
     
     result =  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 )
     
     #Accumulate data for all fields
     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_sigmaY = lawI.sigmaY()
         result.internalField().ext_assign( result.internalField() + \
                                            self.indicator( lawI ) * lawI_sigmaY.internalField()  )
         
     result.correctBoundaryConditions()
     
     return result
コード例 #50
0
ファイル: __init__.py プロジェクト: asimurzin/potentialFlux
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.NO_WRITE), mesh)

    from Foam.OpenFOAM import dimensionedScalar
    p.ext_assign(dimensionedScalar(word("zero"), p.dimensions(), 0.0))

    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.OpenFOAM import dimensionedVector, vector
    U.ext_assign(dimensionedVector(word("0"), U.dimensions(), vector.zero))

    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc
    phi = surfaceScalarField(
        IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.AUTO_WRITE),
        fvc.interpolate(U) & mesh.Sf())

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

    return p, U, phi, pRefCell, pRefValue
コード例 #51
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    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 face flux\n" << nl
    from Foam.OpenFOAM import dimensionedScalar
    from Foam.finiteVolume import surfaceScalarField
    phi = surfaceScalarField(
        IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE), mesh,
        dimensionedScalar(word("zero"),
                          mesh.Sf().dimensions() * U.dimensions(), 0.0))

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

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

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

    flowDirection = (Ubar / Ubar.mag()).ext_value()
    flowMask = flowDirection.sqr()

    nWallFaces = 0.0
    from Foam.OpenFOAM import vector
    wallNormal = vector.zero

    patches = mesh.boundary()

    for patchi in range(mesh.boundary().size()):
        currPatch = patches[patchi]

        from Foam.finiteVolume import wallFvPatch
        if wallFvPatch.ext_isA(currPatch):

            for facei in range(currPatch.size()):
                nWallFaces = nWallFaces + 1

                if nWallFaces == 1:
                    wallNormal = -mesh.Sf().ext_boundaryField(
                    )[patchi][facei] / mesh.magSf().ext_boundaryField(
                    )[patchi][facei]
                    pass
                elif nWallFaces == 2:
                    wallNormal2 = mesh.Sf().ext_boundaryField(
                    )[patchi][facei] / mesh.magSf().ext_boundaryField(
                    )[patchi][facei]

                    #- Check that wall faces are parallel
                    from Foam.OpenFOAM import mag
                    if mag(wallNormal
                           & wallNormal2) > 1.01 or mag(wallNormal
                                                        & wallNormal2) < 0.99:
                        ext_Info(
                        ) << "boundaryFoam: wall faces are not parallel" << nl
                        import os
                        os.abort()
                        pass
                    pass
                else:
                    ext_Info(
                    ) << "boundaryFoam: number of wall faces > 2" << nl
                    import os
                    os.abort()
                pass
            pass
        pass
    #- create position array for graph generation
    y = wallNormal & mesh.C().internalField()

    from Foam.OpenFOAM import dimensionSet, vector, word
    gradP = dimensionedVector(word("gradP"),
                              dimensionSet(0.0, 1.0, -2.0, 0.0, 0.0),
                              vector(0.0, 0.0, 0.0))

    return U, phi, laminarTransport, turbulence, Ubar, wallNormal, flowDirection, flowMask, y, gradP
コード例 #52
0
def createFields( runTime, mesh, g ):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
    
    ext_Info() << "Reading thermophysical properties\n" << nl 

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

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

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

    p = volScalarField( IOobject( word( "p" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.NO_READ,
                                  IOobject.AUTO_WRITE ),
                        p_rgh + rhok * gh )
    
    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, p_rgh, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )
    
    if p_rgh.needReference():
       from Foam.finiteVolume import getRefCellValue
       from Foam.OpenFOAM import dimensionedScalar
       p.ext_assign( p + dimensionedScalar( word( "p" ), p.dimensions(), pRefValue - getRefCellValue( p, pRefCell) ) )
       pass
    
    return T, p, p_rgh, U, phi, laminarTransport, gh, ghf, TRef,Pr, Prt, turbulence, beta, pRefCell, pRefValue, rhok, kappat
コード例 #53
0
ファイル: __init__.py プロジェクト: asimurzin/potentialFlux
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, 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
コード例 #54
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl

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

    from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo

    thermo = basicThermo.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()

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

    pressureImplicitPorousity = Switch(False)

    nUCorr = 0

    if pZones.size():
        mesh.solutionDict().subDict(word("SIMPLE")).lookup(
            word("pressureImplicitPorousity")
        ) >> pressureImplicitPorousity
        pass

    return p, h, rho, U, phi, thermo, pZones, pMin, pressureImplicitPorousity, initialMass, nUCorr, pRefCell, pRefValue
コード例 #55
0
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

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

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

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

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

    from Foam.finiteVolume.cfdTools.incompressible import createPhi

    phi = createPhi(runTime, mesh, U)

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

    twoPhaseProperties = twoPhaseMixture(U, phi)

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

    from Foam.OpenFOAM import dimensionedScalar

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

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

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

    from Foam.OpenFOAM import scalar

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

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

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

    # Construct incompressible turbulence model
    from Foam import incompressible

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

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

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

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

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

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

    return (
        p_rgh,
        alpha1,
        U,
        phi,
        twoPhaseProperties,
        rho1,
        rho2,
        Dab,
        alphatab,
        rho,
        rhoPhi,
        turbulence,
        gh,
        ghf,
        p,
        pRefCell,
        pRefValue,
    )
コード例 #56
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

    from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo
    thermo = basicThermo.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()

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