Ejemplo n.º 1
0
def readFluidMultiRegionPISOControls( mesh ) :
    
    from Foam.OpenFOAM import word, readInt, Switch
    piso = mesh.solutionDict().subDict( word( "PISO" ) )
    
    nCorr = readInt( piso.lookup( word( "nCorrectors" ) ) )

    nNonOrthCorr = 0
    if piso.found( word( "nNonOrthogonalCorrectors" ) ):
       nNonOrthCorr = readInt( piso.lookup( word( "nNonOrthogonalCorrectors" ) ) )
       pass
    
    momentumPredictor = True
    if piso.found( word( "momentumPredictor" ) ):
       momentumPredictor = Switch( piso.lookup( word( "momentumPredictor" ) ) )
       pass
    
    transonic = False
    if piso.found( word( "transonic" ) ):
       transonic = Switch(piso.lookup( word( "transonic" ) ) )
       pass
    
    nOuterCorr = 1
    if piso.found( word( "nOuterCorrectors" ) ):
       nOuterCorr = readInt(piso.lookup( word( "nOuterCorrectors" ) ) )

    return piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr
Ejemplo n.º 2
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
    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
Ejemplo n.º 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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def write( runTime, mesh, T ):
    if runTime.outputTime():
       from Foam import fvc
       gradT = fvc.grad(T)
       
       from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
       from Foam.finiteVolume import volScalarField
       from Foam.OpenFOAM import vector
       gradTx = volScalarField( IOobject( word( "gradTx" ), 
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                          gradT.component( vector.X ) )
       gradTy = volScalarField( IOobject( word( "gradTy" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Y ) )

       gradTz = volScalarField( IOobject( word( "gradTz" ),
                                          fileName( runTime.timeName() ),
                                          mesh,
                                          IOobject.NO_READ,
                                          IOobject.AUTO_WRITE ),
                                gradT.component( vector.Z ) )
       runTime.write()
       pass
Ejemplo n.º 7
0
    def _init__fvPatch__DimensionedField_scalar_volMesh( self, *args ) :
        if len( args ) != 2 :
            raise AssertionError( "len( args ) != 2" )
        argc = 0

        from Foam.finiteVolume import fvPatch
        try:
            fvPatch.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != fvPatch" )
        p = args[ argc ]; argc += 1
        
        from Foam.finiteVolume import DimensionedField_scalar_volMesh
        try:
            DimensionedField_scalar_volMesh.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != DimensionedField_scalar_volMesh" )
        iF = args[ argc ]; argc += 1
        
        mixedFvPatchScalarField.__init__( self, p, iF )
        
        from Foam.OpenFOAM import word
        self.neighbourFieldName_ = word( "undefined-neighbourFieldName" ) 
        self.KName_ = word( "undefined-K" )
        
        self.refValue().ext_assign( 0.0 )
        self.refGrad().ext_assign( 0.0 )
        self.valueFraction().ext_assign( 1.0 )
        self.fixesValue_ = True
        
        return self
Ejemplo n.º 8
0
def alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ):
    from Foam.OpenFOAM import word 
    alphaScheme = word( "div(phi,alpha)" )
    alpharScheme = word( "div(phirb,alpha)" )
    
    from Foam.finiteVolume import surfaceScalarField
    phic = surfaceScalarField( ( phi / mesh.magSf() ).mag() )
    phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    phir = phic * interface.nHatf()
    
    from Foam import fvc
    from Foam import MULES

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

       pass
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() \
               << "  Max(alpha1) = " << alpha1.ext_max().value() << nl
    pass
Ejemplo n.º 9
0
    def _init__fvPatch__DimensionedField_vector_volMesh( self, *args ) :
        if len( args ) != 2 :
            raise AssertionError( "len( args ) != 2" )
        argc = 0

        from Foam.finiteVolume import fvPatch
        try:
            fvPatch.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != fvPatch" )
        p = args[ argc ]; argc += 1
        
        from Foam.finiteVolume import DimensionedField_vector_volMesh
        try:
            DimensionedField_vector_volMesh.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != DimensionedField_Vector_volMesh" )
        iF = args[ argc ]; argc += 1
        
        fixedGradientFvPatchVectorField.__init__( self, p, iF )
        
        from Foam.OpenFOAM import word
        from Foam.OpenFOAM import vectorField, vector, scalarField
        self.UName_ = word( "undefined" )
        self.rheologyName_ = word( "undefined" )
        self.traction_ = vectorField( p.size(), vector.zero)
        self.pressure_ = scalarField(p.size(), 0.0)
                
        return self
Ejemplo n.º 10
0
 def _init__with_2_param( self, *args ):
     if len(args) != 2:
        raise AssertionError( "len( args ) != 2" )
     argc = 0
     
     from Foam.finiteVolume import fvMesh
     try:
         fvMesh.ext_isinstance( args[ argc ] )
     except TypeError:
         raise AssertionError( "args[ argc ].__class__ != fvMesh" )
     mesh = args[ argc ]; argc +=1
     
     from Foam.OpenFOAM import dictionary
     try:
         dictionary.ext_isinstance( args[ argc ] )
     except TypeError:
         raise AssertionError( "args[ argc ].__class__ != dictionary" )
     dict_ = args[ argc ]
     PtrList_TypeBase.__init__( self )
     from Foam.OpenFOAM import polyPatchID, word, readLabel, readScalar
     self.patchID_ = polyPatchID( dict_.lookup( word( "patch" ) ), mesh.boundaryMesh() )
     self.faceIndex_ = readLabel( dict_.lookup( word( "face" ) ) )
     self.dir_ = self.getDir( dict_ )
     self.value_ = readScalar( dict_.lookup( word( "value" ) ) )
     self.checkPatchFace(mesh)
Ejemplo n.º 11
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

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

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

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

    from Foam.finiteVolume.cfdTools.incompressible import createPhi

    phi = createPhi(runTime, mesh, U)

    from Foam.transportModels import singlePhaseTransportModel

    fluid = singlePhaseTransportModel(U, phi)

    pRefCell = 0
    pRefValue = 0.0

    from Foam.finiteVolume import setRefCell

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

    return p, U, phi, fluid, pRefCell, pRefValue
Ejemplo n.º 12
0
    def _readCode( self, the_dict, the_prefix ) :
        from Foam.OpenFOAM import word
        a_code_prefix = word( the_prefix + 'Code' )
        an_is_string = the_dict.found( a_code_prefix )

        from Foam.OpenFOAM import word
        a_file_prefix = word( the_prefix + 'File' )
        an_is_file = the_dict.found( a_file_prefix )

        if an_is_string and an_is_file :
            raise AssertionError()

        a_string = ''
        if an_is_string :
            from Foam.src.OpenFOAM.primitives.strings.string import string
            a_string = str( string( the_dict.lookup( a_code_prefix ) ) )
        elif an_is_file :
            from Foam.src.OpenFOAM.primitives.strings.string import string
            a_filename = str( string( the_dict.lookup( a_file_prefix ) ) )
            import os.path
            if not os.path.isfile( a_filename ) :
                raise AssertionError()
            a_file = open( a_filename )
            a_string = a_file.readlines().join( '\n' )
            pass
        
        return a_string
Ejemplo n.º 13
0
def _createFields( runTime, mesh, rhoO, psi ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading field p\n" << nl
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    p = volScalarField( IOobject( word( "p" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )

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

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

    return p, U, rho, phi
Ejemplo n.º 14
0
def _pEqn( rho, thermo, UEqn, nNonOrthCorr, psi, U, mesh, phi, p, cumulativeContErr ):
    from Foam.finiteVolume import volScalarField
    rUA = 1.0/UEqn.A()
    U.ext_assign( rUA*UEqn.H() )
            
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phid = surfaceScalarField( word( "phid" ), 
                               fvc.interpolate( thermo.psi() ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
    
    
    for nonOrth in range( nNonOrthCorr + 1 ) :
        from Foam import fvm
        pEqn = ( fvm.ddt(psi, p) + fvm.div(phid, word( "div(phid,p)" ) ) - fvm.laplacian(rho*rUA, p) )
        pEqn.solve()
        if (nonOrth == nNonOrthCorr) :
           phi.ext_assign( pEqn.flux() )
           pass
        pass
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn( rho, phi )               
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )
           
    U.ext_assign( U - rUA * fvc.grad(p) )
    U.correctBoundaryConditions()
    
    return cumulativeContErr
Ejemplo n.º 15
0
def createFields( runTime, mesh ):
    ext_Info() << "Reading field U\n" << nl
    
    from Foam.finiteVolume import volVectorField
    from Foam.OpenFOAM import IOobject, fileName, word
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )

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

    return U, sigma, rheology
Ejemplo n.º 16
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
Ejemplo n.º 17
0
    def write( self, os ) :
        mixedFvPatchScalarField.write( self, os )

        from Foam.OpenFOAM import keyType, word, token
        os.writeKeyword( keyType( word( "neighbourFieldName" ) ) ) << self.neighbourFieldName_ << token( token.END_STATEMENT ) << nl
        os.writeKeyword( keyType( word( "K" ) ) ) << self.KName_ << token( token.END_STATEMENT ) << nl
        pass
Ejemplo n.º 18
0
def alphaEqnSubCycle( runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface ):
    from Foam.OpenFOAM import word,readLabel
    nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) )
    nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) )
    if (nAlphaSubCycles > 1):
       totalDeltaT = runTime.deltaT()
       rhoPhiSum = 0.0 * rhoPhi
       from Foam.finiteVolume import subCycle_volScalarField
       alphaSubCycle = subCycle_volScalarField(alpha1, nAlphaSubCycles)
       for item in alphaSubCycle: 
           alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr )
           rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi )
           pass
       # To make sure that variable in the local scope will be destroyed
       # - during destruction of this variable it performs some important actions
       # - there is a difference between C++ and Python memory management, namely
       # if C++ automatically destroys stack variables when they exit the scope,
       # Python relay its memory management of some "garbage collection" algorithm
       # that do not provide predictable behavior on the "exit of scope"
       del alphaSubCycle
       
       rhoPhi.ext_assign( rhoPhiSum )
    else:
       alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr )
       pass
    interface.correct()
    
    rho == alpha1 * rho1 + ( 1.0 - alpha1 ) * rho2

    pass
Ejemplo n.º 19
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
Ejemplo n.º 20
0
def main_standalone( argc, argv ):

    from Foam.OpenFOAM import argList, word
    argList.validOptions.fget().insert( word( "writep" ), "" )
    
    from Foam.OpenFOAM.include import setRootCase
    args = setRootCase( argc, argv )

    from Foam.OpenFOAM.include import createTime
    runTime = createTime( args )

    from Foam.OpenFOAM.include import createMesh
    mesh = createMesh( runTime )
    
    p, U, phi, pRefCell, pRefValue = _createFields( runTime, mesh )
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << nl << "Calculating potential flow" << nl
        
    from Foam.finiteVolume.cfdTools.general.include import readSIMPLEControls
    simple, nNonOrthCorr, momentumPredictor, fluxGradp, transonic = readSIMPLEControls( mesh )
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phi, U, p)
    
    from Foam.OpenFOAM import dimensionedScalar, word, dimTime, dimensionSet
    from Foam import fvc, fvm
    for nonOrth in range( nNonOrthCorr + 1):
        pEqn = fvm.laplacian( dimensionedScalar( word( "1" ), dimTime / p.dimensions() * dimensionSet( 0.0, 2.0, -2.0, 0.0, 0.0 ), 1.0 ), p ) == fvc.div( phi )

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

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pEqn.flux() )
           pass
        pass
    
    ext_Info() << "continuity error = " << fvc.div( phi ).mag().weightedAverage( mesh.V() ).value() << nl

    U.ext_assign( fvc.reconstruct( phi ) )
    U.correctBoundaryConditions()
    ext_Info() << "Interpolated U error = " << ( ( ( fvc.interpolate( U ) & mesh.Sf() ) - phi ).sqr().sum().sqrt()  /mesh.magSf().sum() ).value() << nl

    # Force the write
    U.write()
    phi.write()
    
    if args.optionFound( word( "writep" ) ):
       p.write()
       pass
       
    ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
    ext_Info() << "End\n" << nl 

    import os
    return os.EX_OK
Ejemplo n.º 21
0
def _pEqn( runTime, mesh, UEqn, thermo, p, psi, U, rho, phi, DpDt, g, initialMass, totalVolume, corr, nCorr, nNonOrthCorr, cumulativeContErr ): 
    closedVolume = p.needReference()
    rho.ext_assign( thermo.rho() )

    # Thermodynamic density needs to be updated by psi*d(p) after the
    # pressure solution - done in 2 parts. Part 1:
    thermo.rho().ext_assign( thermo.rho() - psi * p )
    
    rUA = 1.0/UEqn.A()
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA * UEqn.H() )

    phiU = fvc.interpolate( rho ) * ( (fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) 

    phi.ext_assign( phiU + rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() ) )
    
    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm
        from Foam.finiteVolume import correction
        pEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p )
        
        if corr == nCorr-1  and nonOrth == nNonOrthCorr:
           pEqn.solve( mesh.solver( word( str( p.name() ) + "Final" ) ) )
           pass
        else:
           pEqn.solve( mesh.solver( p.name() ) )
           pass
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi + pEqn.flux() )
           pass

    # Second part of thermodynamic density update
    thermo.rho().ext_assign( thermo.rho() + psi * p )

    U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) )
    U.correctBoundaryConditions()
    
    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )
    
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn  
    rhoEqn( rho, phi )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )

    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       thermo.rho().ext_assign(  psi * p )
       rho.ext_assign( rho + ( initialMass - fvc.domainIntegrate( rho ) ) / totalVolume )
       pass

    return cumulativeContErr
Ejemplo n.º 22
0
def fun_pEqn( i, mesh, p, rho, turb, thermo, thermoFluid, K, UEqn, U, phi, psi, DpDt, initialMass, p_rgh, gh, ghf, \
              nNonOrthCorr, oCorr, nOuterCorr, corr, nCorr, cumulativeContErr ) :
    
    closedVolume = p_rgh.needReference()

    rho.ext_assign( thermo.rho() )
    
    rUA = 1.0 / UEqn.A()
    
    from Foam import fvc
    from Foam.OpenFOAM import word 
    from Foam.finiteVolume import surfaceScalarField
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ) , fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA * UEqn.H() ) 

    from Foam import fvc

    phiU = ( fvc.interpolate( rho ) *
                 (  ( fvc.interpolate( U ) & mesh.Sf() ) +
                      fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
    phi.ext_assign( phiU - rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() )
    from Foam import fvm
    for nonOrth in range ( nNonOrthCorr + 1 ):
        p_rghEqn = ( fvm.ddt( psi, p_rgh) + fvc.ddt( psi, rho ) * gh + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh ) )
        p_rghEqn.solve( mesh.solver( p_rgh.select( ( oCorr == nOuterCorr-1 and corr == ( nCorr-1 ) and nonOrth == nNonOrthCorr ) ) ) )
        
        if nonOrth == nNonOrthCorr :
            phi.ext_assign( phi + p_rghEqn.flux() )
            pass
        pass
    
    # Correct velocity field
    U.ext_assign( U + rUA * fvc.reconstruct( ( phi - phiU ) / rhorUAf ) )
    U.correctBoundaryConditions()
    
    p.ext_assign( p_rgh + rho * gh )

    #Update pressure substantive derivative
    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )
    
    # Solve continuity
    from Foam.finiteVolume.cfdTools.compressible import rhoEqn
    rhoEqn( rho, phi )   
    
    # Update continuity errors
    cumulativeContErr = compressibleContinuityErrors( i, mesh, rho, thermo, cumulativeContErr )
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume :
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       rho.ext_assign( thermo.rho() )
       p_rgh.ext_assign( p - rho * gh )
       pass
    #Update thermal conductivity
    K.ext_assign( thermoFluid[ i ].Cp() * turb.alphaEff() )
        
    return cumulativeContErr
Ejemplo n.º 23
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
Ejemplo n.º 24
0
def _UEqn(phi, U, p, turbulence, pZones, pressureImplicitPorosity, nUCorr, eqnResidual, maxResidual):

    from Foam import fvm, fvc

    # Construct the Momentum equation

    # The initial C++ expression does not work properly, because of
    #  1. turbulence.divDevRhoReff( U ) - changes values for the U boundaries
    #  2. the order of expression arguments computation differs with C++
    # UEqn = fvm.div( phi, U ) - fvm.Sp( fvc.div( phi ), U ) + turbulence.divDevRhoReff( U )

    UEqn = turbulence.divDevRhoReff(U) + (fvm.div(phi, U) - fvm.Sp(fvc.div(phi), U))

    UEqn.relax()

    # Include the porous media resistance and solve the momentum equation
    # either implicit in the tensorial resistance or transport using by
    # including the spherical part of the resistance in the momentum diagonal

    trAU = None
    trTU = None
    if pressureImplicitPorosity:
        from Foam.OpenFOAM import sphericalTensor, tensor

        tTU = tensor(sphericalTensor.I) * UEqn.A()

        pZones.addResistance(UEqn, tTU)

        trTU = tTU.inv()

        from Foam.OpenFOAM import word

        trTU.rename(word("rAU"))

        for UCorr in range(nUCorr):
            U.ext_assign(trTU & (UEqn.H() - fvc.grad(p)))
            pass

        U.correctBoundaryConditions()
    else:
        pZones.addResistance(UEqn)

        from Foam.finiteVolume import solve

        eqnResidual = solve(UEqn == -fvc.grad(p)).initialResidual()

        maxResidual = max(eqnResidual, maxResidual)

        trAU = 1.0 / UEqn.A()

        from Foam.OpenFOAM import word

        trAU.rename(word("rAU"))

        pass

    return UEqn, trTU, trAU, eqnResidual, maxResidual
Ejemplo n.º 25
0
def readSolidMultiRegionPISOControls( mesh ):
    from Foam.OpenFOAM import word, readInt
    piso = mesh.solutionDict().subDict( word( "PISO" ) )
    
    nNonOrthCorr = 0
    if piso.found( word( "nNonOrthogonalCorrectors" ) ):
       nNonOrthCorr = readInt( piso.lookup( word( "nNonOrthogonalCorrectors" ) ) )

    return piso, nNonOrthCorr
Ejemplo n.º 26
0
def readFluidMultiRegionPIMPLEControls( mesh ) :
    
    from Foam.OpenFOAM import word, readInt, Switch
    pimple = mesh.solutionDict().subDict( word( "PIMPLE" ) )
    nCorr = readInt( pimple.lookup( word( "nCorrectors" ) ) )
    nNonOrthCorr = pimple.lookupOrDefault( word( "nNonOrthogonalCorrectors" ), 0 )
    momentumPredictor =pimple.lookupOrDefault( word( "momentumPredictor" ), Switch( True ) )
    
    return pimple, nCorr, nNonOrthCorr, momentumPredictor
def fun_pEqn( runTime, mesh, p, phi, U, UEqn, g, rhok, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): 
    
    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField( word( "rUA" ), 1.0 / UEqn().A() )
    rUAf = surfaceScalarField(word( "(1|A(U))" ), fvc.interpolate( rUA ) )

    U.ext_assign( rUA * UEqn().H() )
    UEqn.clear()
    
    from Foam import fvc 
    phi.ext_assign( fvc.interpolate( U ) & mesh.Sf() )
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi( phi, U, p )
    
    buoyancyPhi = rUAf * fvc.interpolate( rhok ) * ( g & mesh.Sf() )
    
    phi.ext_assign( phi + buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        
        from Foam import fvm, fvc
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)

        pEqn.setReference( pRefCell, pRefValue )
        
        # retain the residual from the first iteration
        if ( nonOrth == 0 ):
              eqnResidual = pEqn.solve().initialResidual()
              maxResidual = max( eqnResidual, maxResidual )
              pass
        else:
              pEqn.solve()
              pass
        

        if ( nonOrth == nNonOrthCorr ):
           # Calculate the conservative fluxes
           phi.ext_assign( phi - pEqn.flux() )
           
           # Explicitly relax pressure for momentum corrector
           p.relax()

           # Correct the momentum source with the pressure gradient flux
           # calculated from the relaxed pressure
           U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rUAf ) )
           U.correctBoundaryConditions()
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    return eqnResidual, maxResidual, cumulativeContErr
def readTimeControls_010600_dev( runTime ):
    from Foam.OpenFOAM import Switch, word, readScalar, GREAT
    
    adjustTimeStep = Switch( runTime.controlDict().lookup( word( "adjustTimeStep" ) ) )
    maxCo = readScalar( runTime.controlDict().lookup( word( "maxCo" ) ) )
    
    maxDeltaT = runTime.controlDict().lookupOrDefault( word( "maxDeltaT" ), GREAT, 0, 1 )

    return adjustTimeStep, maxCo, maxDeltaT
Ejemplo n.º 29
0
def readPIMPLEControls( runTime ):

    from Foam.finiteVolume import fvSolution
    solutionDict = fvSolution( runTime )
    
    from Foam.OpenFOAM import word,readInt
    pimple = solutionDict.subDict( word( "PIMPLE" ) )
    nOuterCorr = readInt( pimple.lookup( word( "nOuterCorrectors" ) ) )
    
    return nOuterCorr
Ejemplo n.º 30
0
def fun_pEqn( mesh, p, rho, psi, p_rgh, U, phi, ghf, gh, DpDt, UEqn, thermo, nNonOrthCorr, corr, nCorr, finalIter, cumulativeContErr ):
    
    rho.ext_assign( thermo.rho() )

    # Thermodynamic density needs to be updated by psi*d(p) after the
    # pressure solution - done in 2 parts. Part 1:
    thermo.rho().ext_assign( thermo.rho() - psi * p_rgh )

    rUA = 1.0 / UEqn.A()
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rhorUAf = surfaceScalarField( word( "(rho*(1|A(U)))" ), fvc.interpolate( rho * rUA ) )

    U.ext_assign( rUA*UEqn.H() )

    phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )

    buoyancyPhi = -rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf()
    phi.ext_assign( phi + buoyancyPhi )
    
    from Foam import fvm
    from Foam.finiteVolume import correction
    for nonOrth in range( nNonOrthCorr +1 ):
        p_rghEqn = fvc.ddt( rho ) + psi * correction( fvm.ddt( p_rgh ) ) + fvc.div( phi ) - fvm.laplacian( rhorUAf, p_rgh )

        p_rghEqn.solve( mesh.solver( p_rgh.select( ( finalIter and corr == nCorr-1 and nonOrth == nNonOrthCorr ) ) ) )

        if nonOrth == nNonOrthCorr:
            # Calculate the conservative fluxes
            phi.ext_assign( phi + p_rghEqn.flux() )

            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorUAf ) )
            U.correctBoundaryConditions()
            pass

    p.ext_assign( p_rgh + rho * gh )

    # Second part of thermodynamic density update
    thermo.rho().ext_assign( thermo.rho() + psi * p_rgh )

    DpDt.ext_assign( fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )

    from Foam.finiteVolume.cfdTools.compressible import rhoEqn  
    rhoEqn( rho, phi )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleContinuityErrs
    cumulativeContErr = compressibleContinuityErrs( rho, thermo, cumulativeContErr )

    return cumulativeContErr
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
def initConvergenceCheck( simple ):
    eqnResidual = 1
    maxResidual = 0
    convergenceCriterion = 0
    
    from Foam.OpenFOAM import word
    tmp, convergenceCriterion = simple.readIfPresent( word( "convergence" ), convergenceCriterion )
    
    return eqnResidual, maxResidual, convergenceCriterion
Ejemplo n.º 33
0
    def write(self, os):
        try:
            from Foam.finiteVolume import fvPatchVectorField
            fvPatchVectorField.write(self, os)

            from Foam.OpenFOAM import word, token
            os.writeKeyword(word("U")) << self.UName_ << token(
                token.END_STATEMENT) << nl
            os.writeKeyword(word("rheology")) << self.rheologyName_ << token(
                token.END_STATEMENT) << nl
            self.traction_.writeEntry(word("traction"), os)
            self.pressure_.writeEntry(word("pressure"), os)
            self.writeEntry(word("value"), os)
            pass
        except Exception, exc:
            import sys, traceback
            traceback.print_exc(file=sys.stdout)
            raise exc
Ejemplo n.º 34
0
def readGravitationalAcceleration(runTime, mesh):
    ext_Info() << "\nReading g" << nl

    from Foam.OpenFOAM import uniformDimensionedVectorField
    from Foam.OpenFOAM import word, IOobject, fileName
    g = uniformDimensionedVectorField(
        IOobject(word("g"), fileName(runTime.constant()), mesh,
                 IOobject.MUST_READ, IOobject.NO_WRITE))
    return g
Ejemplo n.º 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.NO_READ, IOobject.NO_WRITE), thermo.rho())

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

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

    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi(runTime, mesh, rho, U)

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

    thermo.correct()

    pRefCell = 0
    pRefValue = 0.0

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

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

    return thermo, rho, p, h, psi, U, phi, turbulence, initialMass, pRefCell, pRefValue
Ejemplo n.º 36
0
def read_controls( args, runTime, mesh ):
    from Foam.finiteVolume.cfdTools.general.include import readPISOControls
    piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )

    from Foam.OpenFOAM import word, readLabel
    nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) )

    nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) )

    if nAlphaSubCycles > 1 and nOuterCorr != 1:
        from Foam.OpenFOAM import ext_Info, nl
        ext_Info() << args.executable() << "FATAL ERROR: Sub-cycling alpha is only allowed for PISO, i.e. when the number of outer-correctors = 1" << nl;
        import os; os_exit( 1 ) 
        pass
    
    return piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr, adjustTimeStep, maxCo, maxDeltaT, nAlphaCorr, nAlphaSubCycles
Ejemplo n.º 37
0
def readFluxScheme(mesh):
    from Foam.OpenFOAM import word
    fluxScheme = word("Kurganov")
    if mesh.schemesDict().found(word("fluxScheme")):
        fluxScheme = word(mesh.schemesDict().lookup(word("fluxScheme")))
        from Foam.OpenFOAM import ext_Info, nl
        if str(fluxScheme) == "Tadmor" or str(fluxScheme) == "Kurganov":
            ext_Info() << "fluxScheme: " << fluxScheme << nl
            pass
        else:
            ext_Info() << "rhoCentralFoam::readFluxScheme" \
                       << "fluxScheme: " << fluxScheme \
                       << " is not a valid choice. " \
                       << "Options are: Tadmor, Kurganov" <<nl
            import os
            os.abort()
            pass
        pass
    return fluxScheme
Ejemplo n.º 38
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
Ejemplo n.º 39
0
def readStressedFoamControls(mesh):
    from Foam.OpenFOAM import word
    stressControl = mesh.solutionDict().subDict(word("stressedFoam"))

    from Foam.OpenFOAM import readInt
    nCorr = readInt(stressControl.lookup(word("nCorrectors")))

    from Foam.OpenFOAM import readScalar
    convergenceTolerance = readScalar(stressControl.lookup(word("U")))

    from materialModels.componentReference import componentReference
    #    from Foam.template import PtrList
    #    cr = PtrList( componentReference )( stressControl.lookup( word( "componentReference" ) ), componentReference.iNew(mesh) )

    from Foam.template import PtrList
    cr = PtrList(stressControl.lookup(word("componentReference")),
                 componentReference.iNew(mesh))

    return stressControl, nCorr, convergenceTolerance, cr
Ejemplo n.º 40
0
    def _init__fvPatch__DimensionedField_scalar_volMesh__dictionary( self, *args ) :
        if len( args ) != 3 :
            raise AssertionError( "len( args ) != 3" )
        argc = 0
        
        from Foam.finiteVolume import fvPatch        
        try:
            fvPatch.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != fvPatch" )
        p = args[ argc ]; argc += 1
        
        from Foam.finiteVolume import DimensionedField_scalar_volMesh
        try:
            DimensionedField_scalar_volMesh.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != DimensionedField_scalar_volMesh" )
        iF = args[ argc ]; argc += 1
        
        from Foam.OpenFOAM import dictionary
        try:
            dictionary.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != dictionary" )
        dict_ = args[ argc ]; argc += 1
        
        mixedFvPatchScalarField.__init__( self, p, iF )
        from Foam.OpenFOAM import word
        self.neighbourFieldName_ = word( dict_.lookup( word( "neighbourFieldName" ) ) )
        self.KName_ = word( dict_.lookup( word( "K" ) ) )
       
        from Foam.finiteVolume import fvPatchScalarField
        from Foam.OpenFOAM import word, scalarField, readBool
        fvPatchScalarField.ext_assign( self, scalarField( word( "value" ), dict_, p.size() ) )
        
        if dict_.found( word( "refValue" ) ) :
            #Full restart
            self.refValue().ext_assign( scalarField( word( "refValue" ), dict_, p.size() ) )
            self.refGrad().ext_assign( scalarField( word( "refGradient" ), dict_, p.size() ) )
            self.valueFraction().ext_assign( scalarField( word( "valueFraction" ), dict_, p.size() ) )
        else:
            # Start from user entered data. Assume fixedValue.
            self.refValue().ext_assign( self )
            self.refGrad().ext_assign( 0.0 )
            self.valueFraction().ext_assign( 1.0 )
            pass

        return self
Ejemplo n.º 41
0
def alphaEqnsSubCycle( runTime, piso, mesh, phi, alpha1, alpha2, rho, rho1, rho2, rhoPhi, dgdt, interface, oCorr ):
    
    from Foam.OpenFOAM import word,readLabel
    nAlphaCorr = readLabel( piso.lookup( word( "nAlphaCorr" ) ) )
    nAlphaSubCycles = readLabel( piso.lookup( word( "nAlphaSubCycles" ) ) )
    
    from Foam.finiteVolume import surfaceScalarField
    phic = ( phi / mesh.magSf() ).mag()
    phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    
    from Foam import fvc
    divU = fvc.div( phi )
    
    if nAlphaSubCycles > 1:

        totalDeltaT = runTime.deltaT()
        rhoPhiSum = 0.0 * rhoPhi

        from Foam.finiteVolume import subCycle_volScalarField
        alphaSubCycle = subCycle_volScalarField( alpha1, nAlphaSubCycles )
        for item in alphaSubCycle: 
            alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr )
            rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi )
            pass
       # To make sure that variable in the local scope will be destroyed
       # - during destruction of this variable it performs some important actions
       # - there is a difference between C++ and Python memory management, namely
       # if C++ automatically destroys stack variables when they exit the scope,
       # Python relay its memory management of some "garbage collection" algorithm
       # that do not provide predictable behavior on the "exit of scope"
        del alphaSubCycle

        rhoPhi.ext_assign( rhoPhiSum )
        pass
    else:
        alphaEqns( runTime, mesh, rho1, rho2, rhoPhi, phic, dgdt, divU, alpha1, alpha2, phi, interface, nAlphaCorr )
        pass

    if oCorr == 0:
       interface.correct()
       pass
    
    pass
Ejemplo n.º 42
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 IOobject, fileName
        from Foam.finiteVolume import volScalarField
        self.materials_ = volScalarField(
            IOobject(word("materials"),
                     fileName(self.mesh().time().timeName()), self.mesh(),
                     IOobject.MUST_READ, IOobject.AUTO_WRITE), self.mesh())

        from Foam.OpenFOAM import PtrList_entry
        lawEntries = PtrList_entry(dict_.lookup(word("laws")))

        for lawI in range(lawEntries.size()):
            self.append(
                rheologyLaw.New(lawEntries[lawI].keyword(), sigma,
                                lawEntries[lawI].dict()))

        from Foam.OpenFOAM import SMALL
        if self.materials_.ext_min().value() < 0 or self.materials_.ext_max(
        ).value() > (len(self) + SMALL):
            raise IOError(" Invalid definition of material indicator field.")

        pass
Ejemplo n.º 43
0
    def _init__fvPatch(self, *args):
        if len(args) != 1:
            raise AssertionError("len( args ) != 1")
        argc = 0

        from Foam.finiteVolume import fvPatch
        try:
            fvPatch.ext_isinstance(args[argc])
        except TypeError:
            raise AssertionError("args[ argc ].__class__ != fvPatch")
        patch = args[argc]

        self.patch_ = patch
        from Foam.OpenFOAM import word
        self.neighbourRegionName_ = word("undefined-neighbourRegionName")
        self.neighbourPatchName_ = word("undefined-neighbourPatchName")
        self.neighbourFieldName_ = word("undefined-neighbourFieldName")
        self.localRegion_ = self.patch_.boundaryMesh().mesh()

        return self
Ejemplo n.º 44
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

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

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

    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi(runTime, mesh, U)

    return p, U, phi
Ejemplo n.º 45
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
Ejemplo n.º 46
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
Ejemplo n.º 47
0
    def read( self ):
        from Foam.OpenFOAM import regIOobject
        if regIOobject.read( self ):
           self.lookup("planeStress") >> self.planeStress_
           from Foam.OpenFOAM import word
           from materialModels.rheologyModel.rheologyLaws import rheologyLaw
           self.lawPtr_ = rheologyLaw.New( word( "law" ), self.sigma_, self.subDict("rheology"));

           return True 
        else:
           return False
Ejemplo n.º 48
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
Ejemplo n.º 49
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

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

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

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

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

    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi(runTime, mesh, rho, U)

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

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

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

    return p, h, psi, rho, U, phi, turbulence, thermo, pMin, DpDt
Ejemplo n.º 50
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField

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

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

    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi(runTime, mesh(), U)

    pRefCell = 0
    pRefValue = 0.0

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

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

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

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

    return p, U, phi, laminarTransport, turbulence, rAU, pRefCell, pRefValue
Ejemplo n.º 51
0
def _pEqn(mesh, UEqn, U, p, pd, phi, alpha1, rho, ghf, interface, corr, nCorr,
          nNonOrthCorr, pdRefCell, pdRefValue):
    rUA = 1.0 / UEqn.A()

    from Foam import fvc
    rUAf = fvc.interpolate(rUA)

    U.ext_assign(rUA * UEqn.H())

    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phiU = surfaceScalarField(word("phiU"), (fvc.interpolate(U) & mesh.Sf()) +
                              fvc.ddtPhiCorr(rUA, rho, U, phi))

    from Foam.finiteVolume import adjustPhi
    adjustPhi(phiU, U, p)

    phi.ext_assign(phiU +
                   (fvc.interpolate(interface.sigmaK()) * fvc.snGrad(alpha1) -
                    ghf * fvc.snGrad(rho)) * rUAf * mesh.magSf())

    from Foam import fvm
    for nonOrth in range(nNonOrthCorr + 1):
        pdEqn = fvm.laplacian(rUAf, pd) == fvc.div(phi)
        pdEqn.setReference(pdRefCell, pdRefValue)

        if corr == nCorr - 1 and nonOrth == nNonOrthCorr:
            pdEqn.solve(mesh.solver(word(str(pd.name()) + "Final")))
            pass
        else:
            pdEqn.solve(mesh.solver(pd.name()))
            pass
        if nonOrth == nNonOrthCorr:
            phi.ext_assign(phi - pdEqn.flux())
            pass
        pass

    U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf))
    U.correctBoundaryConditions()

    pass
Ejemplo n.º 52
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
Ejemplo n.º 53
0
def readControls(runTime, mesh):
    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

    from Foam.finiteVolume.cfdTools.general.include import readPIMPLEControls
    pimple, nOuterCorr, nCorr, nNonOrthCorr, momentumPredictor, transonic = readPIMPLEControls(
        mesh)

    correctPhi = False
    from Foam.OpenFOAM import word
    if (pimple.found(word("correctPhi"))):
        correctPhi = Switch(pimple.lookup(word("correctPhi")))
        pass

    checkMeshCourantNo = False
    if (pimple.found(word("checkMeshCourantNo"))):
        checkMeshCourantNo = Switch(pimple.lookup("checkMeshCourantNo"))
        pass

    return adjustTimeStep, maxCo, maxDeltaT, pimple, nOuterCorr, nCorr, nNonOrthCorr, \
           momentumPredictor, transonic, correctPhi, checkMeshCourantNo
Ejemplo n.º 54
0
def createPhi(runTime, hU, mesh):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import surfaceScalarField
    ext_Info() << "Reading/calculating face flux field phi\n" << nl

    from Foam.finiteVolume import linearInterpolate
    phi = surfaceScalarField(
        IOobject(word("phi"), fileName(runTime.timeName()), mesh,
                 IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE),
        linearInterpolate(hU) & mesh.Sf())
    return phi
Ejemplo n.º 55
0
def _pEqn(runTime, mesh, U, UEqn, phi, p, rhok, g, corr, nCorr, nNonOrthCorr,
          cumulativeContErr):

    from Foam.finiteVolume import volScalarField, surfaceScalarField
    from Foam.OpenFOAM import word
    from Foam import fvc
    rUA = volScalarField(word("rUA"), 1.0 / UEqn.A())

    rUAf = surfaceScalarField(word("(1|A(U))"), fvc.interpolate(rUA))

    U.ext_assign(rUA * UEqn.H())

    phiU = (fvc.interpolate(U) & mesh.Sf()) + fvc.ddtPhiCorr(rUA, U, phi)

    phi.ext_assign(phiU + rUAf * fvc.interpolate(rhok) * (g & mesh.Sf()))

    for nonOrth in range(nNonOrthCorr + 1):

        from Foam import fvm
        pEqn = fvm.laplacian(rUAf, p) == fvc.div(phi)

        if (corr == nCorr - 1) and (nonOrth == nNonOrthCorr):
            from Foam.OpenFOAM import word
            pEqn.solve(mesh.solver(word(str(p.name()) + "Final")))
            pass
        else:
            pEqn.solve(mesh.solver(p.name()))
            pass

        if (nonOrth == nNonOrthCorr):
            phi.ext_assign(phi - pEqn.flux())
            pass
        pass
    U.ext_assign(U + rUA * fvc.reconstruct((phi - phiU) / rUAf))
    U.correctBoundaryConditions()

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs(mesh, phi, runTime, cumulativeContErr)

    return pEqn
Ejemplo n.º 56
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
Ejemplo n.º 57
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
Ejemplo n.º 58
0
    def _init__fvPatch__dictionary(self, *args):
        if len(args) != 2:
            raise AssertionError("len( args ) != 1")
        argc = 0

        from Foam.finiteVolume import fvPatch
        try:
            fvPatch.ext_isinstance(args[argc])
        except TypeError:
            raise AssertionError("args[ argc ].__class__ != fvPatch")
        patch = args[argc]
        argc = argc + 1

        from Foam.OpenFOAM import dictionary
        try:
            dictionary.ext_isinstance(args[argc])
        except TypeError:
            raise AssertionError("args[ argc ].__class__ != dictionary")
        dict_ = args[argc]

        self.patch_ = patch
        from Foam.OpenFOAM import word
        self.neighbourRegionName_ = word(
            dict_.lookup(word("neighbourRegionName")))
        self.neighbourPatchName_ = word(
            dict_.lookup(word("neighbourPatchName")))
        self.neighbourFieldName_ = word(
            dict_.lookup(word("neighbourFieldName")))
        self.localRegion_ = self.patch_.boundaryMesh().mesh()

        return self
    def _init__fvPatch__DimensionedField_scalar_volMesh__dictionary( self, *args ):
        if len( args ) != 3 :
           raise AssertionError( "len( args ) != 3" )
        argc = 0
        
        from Foam.finiteVolume import fvPatch        
        try:
            fvPatch.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != fvPatch" )
        p = args[ argc ]; argc += 1
        
        from Foam.finiteVolume import DimensionedField_scalar_volMesh
        try:
            DimensionedField_scalar_volMesh.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != DimensionedField_scalar_volMesh" )
        iF = args[ argc ]; argc += 1
        
        from Foam.OpenFOAM import dictionary
        try:
            dictionary.ext_isinstance( args[ argc ] )
        except TypeError:
            raise AssertionError( "args[ argc ].__class__ != dictionary" )
        dict_ = args[ argc ]
        
        fixedGradientFvPatchScalarField.__init__( self, p, iF )
        
        if dict_.found( word( "gradient" ) ):
           from Foam.OpenFOAM import scalarField
           self.gradient().ext_assign( scalarField( word( "gradient" ) , dict_, p.size() ) )
           fixedGradientFvPatchScalarField.updateCoeffs( self )
           fixedGradientFvPatchScalarField.evaluate()
           pass
        else:
           self.ext_assign( self.patchInternalField() )
           self.gradient().ext_assign( 0.0 )
           pass

        return self
Ejemplo n.º 60
0
def fun_pEqn( thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr ):

    rho.ext_assign( thermo.rho() )

    rUA = 1.0/UEqn.A()
    
    from Foam.OpenFOAM import word
    from Foam import fvc,fvm
    from Foam.finiteVolume import surfaceScalarField
    rhorUAf = surfaceScalarField(word( "(rho*(1|A(U)))" ) , fvc.interpolate(rho*rUA));
    U.ext_assign(rUA*UEqn.H())
    UEqn.clear()
    
    phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) )

    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi(phi, U, p);

    buoyancyPhi =surfaceScalarField( rhorUAf * fvc.interpolate( rho )*( g & mesh.Sf() ) )
    
    phi.ext_assign( phi+buoyancyPhi )

    for nonOrth in range( nNonOrthCorr+1 ):
        from Foam import fvm
        pEqn = fvm.laplacian(rhorUAf, p) == fvc.div(phi)

        pEqn.setReference(pRefCell, pRefValue )


        if (nonOrth == 0):
            eqnResidual = pEqn.solve().initialResidual()
            maxResidual = max(eqnResidual, maxResidual)
        else:
            pEqn.solve()

        if (nonOrth == nNonOrthCorr):
           if (closedVolume):
              p.ext_assign( p + ( initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) ) 
           
           phi.ext_assign( phi - pEqn.flux() )
           p.relax()
           U.ext_assign( U + rUA * fvc.reconstruct( ( buoyancyPhi - pEqn.flux() ) / rhorUAf ) )
           U.correctBoundaryConditions();
    
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    rho.ext_assign( thermo.rho() )
    rho.relax()

    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr