Exemplo n.º 1
0
def createGradP( runTime ):
    from Foam.OpenFOAM import dimensionedScalar, dimensionSet, IFstream, word
    gradP = dimensionedScalar( word( "gradP" ),
                               dimensionSet( 0.0, 1.0, -2.0, 0.0, 0.0 ),
                               0.0 )
    from Foam.OpenFOAM import word, fileName, ext_Info, nl
    gradPFile = IFstream( runTime.path()/fileName( runTime.timeName() )/fileName( "uniform" )/ fileName( "gradP.raw" ) )
    
    if gradPFile.good():
       gradPFile >> gradP
       ext_Info() << "Reading average pressure gradient" << nl << nl
       pass
    else:
       ext_Info() << "Initializing with 0 pressure gradient" << nl << nl
       pass
    
    return gradP, gradPFile
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 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.º 3
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
Exemplo n.º 4
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, 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
Exemplo n.º 5
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
Exemplo n.º 6
0
 phif = PtrList_surfaceScalarField( fluidRegions.size() )
 
 from Foam.compressible import PtrList_compressible_RASModel
 turb = PtrList_compressible_RASModel( fluidRegions.size() )
 
 DpDtf = PtrList_volScalarField( fluidRegions.size() )
 
 ghf = PtrList_volScalarField( fluidRegions.size() )
 pdf = PtrList_volScalarField( fluidRegions.size() )
 
 from Foam.OpenFOAM import scalarList
 initialMassf = scalarList( fluidRegions.size() )
 
 from Foam.OpenFOAM import dimensionedScalar, word, dimensionSet
 pRef = dimensionedScalar( word( "pRef" ),
                           dimensionSet( 1.0, -1.0, -2.0, 0.0, 0.0 ),
                           rp.lookup( word( "pRef" ) ) )
 
 from Foam.OpenFOAM import ext_Info, nl
 from Foam.finiteVolume import volScalarField, volVectorField, surfaceScalarField 
 from Foam.OpenFOAM import fileName, IOobject
 for index in range( fluidRegions.size() ) :
     ext_Info() << "*** Reading fluid mesh thermophysical properties for region " << fluidRegions[ index ].name() << nl << nl
     
     ext_Info() << "    Adding to pdf\n" << nl
     pdf.ext_set( index, volScalarField( IOobject( word( "pd" ),
                                               fileName( runTime.timeName() ),
                                               fluidRegions[ index ],
                                               IOobject.MUST_READ,
                                               IOobject.AUTO_WRITE ),
                                     fluidRegions[ index ] ) )