Exemplo n.º 1
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
Exemplo n.º 2
0
def _createFields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
        
    ext_Info() << "Reading field T\n" << nl

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

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

    ext_Info() << "Reading diffusivity DT\n" << nl
    from Foam.OpenFOAM import dimensionedScalar
    DT = dimensionedScalar( transportProperties.lookup( word( "DT" ) ) )
        
    return T, transportProperties, DT
Exemplo n.º 3
0
def readThermodynamicProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl

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

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

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

    from Foam.OpenFOAM import dimensionedScalar

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

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

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

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

    return thermodynamicProperties, rho0, p0, psi, rhoO
Exemplo n.º 4
0
 def __init__(self, runTime):
     from Foam.OpenFOAM import IOobject, word, fileName
     IOdictionary.__init__(
         self,
         IOobject(word("regionProperties"),
                  fileName(runTime.time().constant()), runTime.db(),
                  IOobject.MUST_READ, IOobject.NO_WRITE))
     from Foam.OpenFOAM import wordList
     self.fluidRegionNames = wordList(self.lookup(word("fluidRegionNames")))
     self.solidRegionNames = wordList(self.lookup(word("solidRegionNames")))
     pass
Exemplo n.º 5
0
    def __init__( self, runTime ):
        from Foam.OpenFOAM import IOobject, word, fileName
        IOdictionary.__init__( self, IOobject( word( "regionProperties" ), 
                                               fileName( runTime.time().constant() ), 
                                               runTime.db(), 
                                               IOobject.MUST_READ, 
                                               IOobject.NO_WRITE  ) )
        from Foam.OpenFOAM import wordList
        self.fluidRegionNames = wordList( self.lookup( word( "fluidRegionNames" ) ) )
        self.solidRegionNames = wordList( self.lookup( word( "solidRegionNames" ) ) )
	pass
Exemplo n.º 6
0
def readTransportProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading transportProperties\n" << nl

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

    return transportProperties, mu
Exemplo n.º 7
0
def readEnvironmentalProperties(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nReading environmentalProperties" << nl

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

    return g, environmentalProperties
Exemplo n.º 8
0
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
Exemplo n.º 9
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
Exemplo n.º 10
0
def readEnvironmentalProperties( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nReading environmentalProperties" << nl
    
    from Foam.OpenFOAM import IOdictionary, fileName, word, IOobject
    environmentalProperties = IOdictionary( IOobject( word( "environmentalProperties" ),
                                                      fileName( runTime.constant() ),
                                                      mesh,
                                                      IOobject.MUST_READ,
                                                      IOobject.NO_WRITE ) )
    from Foam.OpenFOAM import dimensionedVector
    g = dimensionedVector( environmentalProperties.lookup( word( "g" ) ) )
    
    return g, environmentalProperties
    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
Exemplo n.º 12
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
Exemplo n.º 13
0
    def updateCoeffs(self):
        try:
           if self.updated():
              return

           from Foam.OpenFOAM import IOdictionary
           rheology = IOdictionary.ext_lookupObject( self.db(), self.rheologyName_ )
           from Foam.OpenFOAM import scalarField
           
           # Python does not wait for evaluation of the closure expression, it destroys return values if it is no more in use
           a_rheology_mu = rheology.mu()
           a_rheology_mu_boundaryField = a_rheology_mu.ext_boundaryField()
           mu = scalarField( a_rheology_mu_boundaryField[self.patch().index()] )
           
           a_rheology_lambda = rheology._lambda()
           a_rheology_lambda_boundaryField = a_rheology_lambda.ext_boundaryField()
           lambda_ = scalarField( a_rheology_lambda_boundaryField[ self.patch().index() ] )

           n = self.patch().nf()
           from Foam.finiteVolume import volTensorField
           from Foam.OpenFOAM import word
           gradU =volTensorField.ext_lookupPatchField( self.patch(), word( "grad(" +str( self.UName_ ) + ")" ) )
           
           from Foam.OpenFOAM import ext_Info
           self.gradient().ext_assign( ( ( self.traction_ -  self.pressure_ * n ) - ( n & ( mu * gradU.ext_T() - ( mu + lambda_ ) * gradU ) ) \
                                          - n * lambda_ * gradU.tr() ) / ( 2.0 * mu + lambda_) )
           
           from Foam.finiteVolume import fixedGradientFvPatchVectorField
           fixedGradientFvPatchVectorField.updateCoeffs( self )
        except Exception, exc:
            import sys, traceback
            traceback.print_exc( file = sys.stdout )
            raise exc   
Exemplo n.º 14
0
def createFluidMeshes( rp, runTime ) :

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

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

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

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

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

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

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

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

    return thermodynamicProperties, rho0, p0, psi, rhoO
Exemplo n.º 19
0
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
Exemplo n.º 20
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
Exemplo n.º 21
0
    def __init__(self, sigma):
        from Foam.finiteVolume import volSymmTensorField
        try:
            volSymmTensorField.ext_isinstance( sigma )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != volSymmTensorField" )
        
        from Foam.OpenFOAM import IOobject, word, fileName
        IOdictionary.__init__(self, IOobject( word( "rheologyProperties" ),
                                              fileName( sigma.time().constant() ),
                                              sigma.db(),
                                              IOobject.MUST_READ,
                                              IOobject.NO_WRITE ) )
        self.sigma_ = sigma
        
        self.typeName = word( "rheologyModel" )
        from Foam.OpenFOAM import Switch
        self.planeStress_ = Switch( self.lookup( word( "planeStress" ) ) )

        from materialModels.rheologyModel.rheologyLaws import rheologyLaw
        self.lawPtr_ = rheologyLaw.New( word( "law" ), self.sigma_, self.subDict( word( "rheology" ) ) )
        pass
Exemplo n.º 22
0
def readGravitationalAcceleration(runTime, mesh):
    from Foam.OpenFOAM import IOdictionary, word, fileName, IOobject
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nReading gravitationalProperties" << nl

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

    from Foam.OpenFOAM import dimensionedVector, Switch, dimTime
    g = dimensionedVector(gravitationalProperties.lookup(word("g")))
    rotating = Switch(gravitationalProperties.lookup(word("rotating")))

    if rotating:
        Omega = dimensionedVector(gravitationalProperties.lookup(
            word("Omega")))
    else:
        Omega = dimensionedVector(word("Omega"), -dimTime, vector(0, 0, 0))

    magg = g.mag()
    gHat = g / magg

    return gravitationalProperties, g, rotating, Omega, magg, gHat
Exemplo n.º 23
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
Exemplo n.º 24
0
def readGravitationalAcceleration( runTime, mesh ):
    from Foam.OpenFOAM import IOdictionary, word, fileName, IOobject
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nReading gravitationalProperties" << nl
    
    gravitationalProperties = IOdictionary( IOobject( word( "gravitationalProperties" ),
                                            fileName( runTime.constant() ),
                                            mesh,
                                            IOobject.MUST_READ,
                                            IOobject.NO_WRITE ) )
    
    from Foam.OpenFOAM import dimensionedVector,Switch, dimTime
    g = dimensionedVector( gravitationalProperties.lookup( word( "g" ) ) )
    rotating = Switch( gravitationalProperties.lookup( word( "rotating" ) ) )
    
    if rotating:
       Omega = dimensionedVector( gravitationalProperties.lookup( word( "Omega" ) ) )
    else:
       Omega = dimensionedVector( word( "Omega" ), -dimTime, vector( 0,0,0 ) )
    
    magg = g.mag()
    gHat = g / magg
    
    return gravitationalProperties, g, rotating, Omega, magg, gHat
Exemplo n.º 25
0
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
Exemplo n.º 26
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
Exemplo n.º 27
0
    def updateCoeffs(self):
        try:
            if self.updated():
                return

            from Foam.OpenFOAM import IOdictionary
            rheology = IOdictionary.ext_lookupObject(self.db(),
                                                     self.rheologyName_)
            from Foam.OpenFOAM import scalarField

            # Python does not wait for evaluation of the closure expression, it destroys return values if it is no more in use
            a_rheology_mu = rheology.mu()
            a_rheology_mu_boundaryField = a_rheology_mu.ext_boundaryField()
            mu = scalarField(a_rheology_mu_boundaryField[self.patch().index()])

            a_rheology_lambda = rheology._lambda()
            a_rheology_lambda_boundaryField = a_rheology_lambda.ext_boundaryField(
            )
            lambda_ = scalarField(
                a_rheology_lambda_boundaryField[self.patch().index()])

            n = self.patch().nf()
            from Foam.finiteVolume import volTensorField
            from Foam.OpenFOAM import word
            gradU = volTensorField.ext_lookupPatchField(
                self.patch(), word("grad(" + str(self.UName_) + ")"))

            from Foam.OpenFOAM import ext_Info
            self.gradient().ext_assign( ( ( self.traction_ -  self.pressure_ * n ) - ( n & ( mu * gradU.ext_T() - ( mu + lambda_ ) * gradU ) ) \
                                           - n * lambda_ * gradU.tr() ) / ( 2.0 * mu + lambda_) )

            from Foam.finiteVolume import fixedGradientFvPatchVectorField
            fixedGradientFvPatchVectorField.updateCoeffs(self)
        except Exception, exc:
            import sys, traceback
            traceback.print_exc(file=sys.stdout)
            raise exc
Exemplo n.º 28
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
Exemplo n.º 29
0
                                                           IOobject.AUTO_WRITE ),
                                                 linearInterpolate( rhof[ index ]*Uf[ index ] ) & fluidRegions[ index ].Sf() ) )

         
        ext_Info() << "    Adding to turb\n" << nl
        from Foam import compressible
        turb.ext_set( index, compressible.RASModel.New( rhof[ index ], Uf[ index ], phif[ index ], thermof[ index ] ) )
        
        ext_Info() << "    Adding to DpDtf\n" << nl
        from Foam import fvc
        DpDtf.ext_set( index, volScalarField( fvc.DDt( surfaceScalarField( word( "phiU" ),
                                                                           phif[ index ] / fvc.interpolate( rhof[ index ] ) ),
                                                       thermof[ index ].p() ) ) )
        
        from Foam.OpenFOAM import IOdictionary
        environmentalProperties = IOdictionary.ext_lookupObject( fluidRegions[ index ], word( "environmentalProperties" ) )
        
        from Foam.OpenFOAM import dimensionedVector
        g = dimensionedVector( environmentalProperties.lookup( word( "g" ) ) )
        ext_Info() << "    Adding to ghf\n" << nl
        ghf.ext_set( index, volScalarField( word( "gh" ),
                                            g & fluidRegions[ index ].C() ) )
        
        ext_Info() << "    Updating p from pd\n" << nl
        thermof[ index ].p() == pdf[ index ] + rhof[ index ] * ghf[ index ] + pRef
        thermof[ index ].correct() 

        initialMassf[ index ] = fvc.domainIntegrate( rhof[ index ] ).value()
    
    
    return pdf, thermof, rhof, Kf, Uf, phif, turb, DpDtf, ghf, initialMassf, pRef
Exemplo n.º 30
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_isType( 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