コード例 #1
0
ファイル: __init__.py プロジェクト: asimurzin/buoyantPisoFlux
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
コード例 #2
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
コード例 #3
0
def fun_pEqn( runTime, thermo, UEqn, U, phi, rho, gh, pd, p, initialMass, mesh, pRef, nNonOrthCorr, \
              pdRefCell, pdRefValue, eqnResidual, maxResidual, cumulativeContErr ):
    
    rUA = 1.0/UEqn.A()
    U.ext_assign( rUA * UEqn().H() )
    
    UEqn.clear()
    from Foam import fvc
    phi.ext_assign( fvc.interpolate( rho )*(fvc.interpolate(U) & mesh.Sf()) )
    
    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi(phi, U, p)
    
    phi.ext_assign( phi - fvc.interpolate( rho *gh * rUA ) * fvc.snGrad( rho ) * mesh.magSf() )
    
    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1):
        pdEqn = ( fvm.laplacian( rho * rUA, pd ) == fvc.div(phi) )
        
        pdEqn.setReference(pdRefCell, pdRefValue)
        # retain the residual from the first iteration    
        
        if nonOrth == 0:
           eqnResidual = pdEqn.solve().initialResidual()
           maxResidual = max(eqnResidual, maxResidual)
           pass
        else:
           pdEqn.solve()
           pass
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - pdEqn.flux() )
           pass
        
        pass

    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    pd.relax()
    
    p.ext_assign( pd + rho * gh + pRef )
    
    U.ext_assign( U- rUA * ( fvc.grad( pd ) + fvc.grad( rho ) * gh ) )
    U.correctBoundaryConditions()
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + ( initialMass - fvc.domainIntegrate( thermo.psi() * p ) ) / fvc.domainIntegrate( thermo.psi() ) )
    
    rho.ext_assign( thermo.rho() )
    rho.relax()
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info()<< "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    return eqnResidual, maxResidual, cumulativeContErr
コード例 #4
0
def fun_pEqn(thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh,
             nNonOrthCorr, pRefCell, 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, p[pRefCell])

        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
コード例 #5
0
def fun_pEqn( thermo, g, rho, UEqn, p, U, psi, phi, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, 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, p[pRefCell]);


        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
コード例 #6
0
def fun_pEqn( i, fluidRegions, Uf, pdf, rhof, thermof, phif, ghf, Kf, DpDtf, turb, initialMassf, UEqn, pRef, corr, nCorr, nNonOrthCorr, cumulativeContErr ) :
    
    closedVolume = False

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

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

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

    return cumulativeContErr
コード例 #7
0
ファイル: __init__.py プロジェクト: alexey4petrov/pythonFlu
def compressibleContinuityErrs( rho, thermo, cumulativeContErr ):
    from Foam import fvc
    totalMass = fvc.domainIntegrate( rho )

    sumLocalContErr = ( fvc.domainIntegrate( ( rho - thermo.rho() ).mag() ) / totalMass ).value()

    globalContErr = ( fvc.domainIntegrate( rho - thermo.rho() ) / totalMass ).value()

    cumulativeContErr += globalContErr

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr\
               << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl

    return cumulativeContErr
コード例 #8
0
ファイル: __init__.py プロジェクト: giovastabile/pythonFlu
def compressibleContinuityErrs(rho, thermo, cumulativeContErr):
    from Foam import fvc
    totalMass = fvc.domainIntegrate(rho)

    sumLocalContErr = (fvc.domainIntegrate(
        (rho - thermo.rho()).mag()) / totalMass).value()

    globalContErr = (fvc.domainIntegrate(rho - thermo.rho()) /
                     totalMass).value()

    cumulativeContErr += globalContErr

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "time step continuity errors : sum local = " << sumLocalContErr\
               << ", global = " << globalContErr \
               << ", cumulative = " << cumulativeContErr << nl

    return cumulativeContErr
コード例 #9
0
def compressibleContinuityErrors( cumulativeContErr, rho, thermo ) :
    from Foam import fvc
    totalMass = fvc.domainIntegrate(rho)
       
    sumLocalContErr =  (fvc.domainIntegrate( ( rho - thermo.rho()  ).mag() )  / totalMass ).value()
    
    globalContErr =  ( fvc.domainIntegrate( rho - thermo.rho() ) / totalMass ).value()

    cumulativeContErr = cumulativeContErr + globalContErr
    
    regionName = rho.mesh().name()
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info()<< "time step continuity errors (" << regionName << ")" \
        << ": sum local = " << sumLocalContErr \
        << ", global = " << globalContErr \
        << ", cumulative = " << cumulativeContErr \
        << nl
        
    return cumulativeContErr
コード例 #10
0
def createFields(runTime, mesh, g):
    ext_Info() << "Reading thermophysical properties\n" << nl

    from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo

    thermo = basicPsiThermo.New(mesh)

    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName
    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh,
                 IOobject.NO_READ, IOobject.NO_WRITE), thermo.rho())
    p = thermo.p()
    h = thermo.h()
    psi = thermo.psi()

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

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

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

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

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

    #Force p_rgh to be consistent with p
    p_rgh.ext_assign(p - rho * gh)

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

    from Foam import fvc
    initialMass = fvc.domainIntegrate(rho)
    totalVolume = mesh.V().ext_sum()

    return thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
コード例 #11
0
ファイル: __init__.py プロジェクト: asimurzin/rhoSimpleFlux
def _createFields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl
    
    from Foam.thermophysicalModels import basicPsiThermo
    thermo = basicPsiThermo.New( mesh )

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

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

    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi( runTime, mesh, rho, U )
    
    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )
    
    from Foam.OpenFOAM import dimensionedScalar
    pMin = dimensionedScalar( mesh.solutionDict().subDict( word( "SIMPLE" ) ).lookup( word( "pMin" ) ) )
    
    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import compressible
    turbulence = compressible.RASModel.New( rho,
                                            U,
                                            phi,
                                            thermo() )
    
    from Foam.OpenFOAM import dimensionedScalar
    from Foam import fvc   
    initialMass = fvc.domainIntegrate( rho )
    
    return thermo, rho, p, h, psi, U, phi, pRefCell, pRefValue, turbulence, initialMass, pMin
コード例 #12
0
ファイル: __init__.py プロジェクト: asimurzin/buoyantPisoFlux
def _createFields( runTime, mesh, g ):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl 

    from Foam.thermophysicalModels import basicRhoThermo
    thermo = basicRhoThermo.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.turbulenceModel.New( rho, U, phi, thermo() )
    
    ext_Info() << "Creating field DpDt\n" << nl
    from Foam import fvc
    from Foam.finiteVolume import surfaceScalarField
    DpDt = volScalarField( word( "DpDt" ),
                           fvc.DDt( surfaceScalarField( word( "phiU" ), phi / fvc.interpolate( rho ) ), p ) )
    
    thermo.correct()

    initialMass = fvc.domainIntegrate(rho);
    
    totalVolume = mesh.V().ext_sum()
    
    return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
コード例 #13
0
ファイル: mapFields.py プロジェクト: giovastabile/pythonFlu
def __mapVolField__( theSourceField, meshToMeshInterp, patchMap, cuttingPatches ) :
    aTargetField = None
    
    meshTarget = meshToMeshInterp.toMesh()
    aFieldName = theSourceField.name()

    aFieldClass = getFieldClass( theSourceField )
    if aFieldClass.ext_foundObject( meshTarget, aFieldName ) :
        aTargetField = aFieldClass.ext_lookupObject( meshTarget, aFieldName )
    else:
        from Foam.OpenFOAM import IOobject, fileName    
        aTargetIOobject = IOobject( aFieldName,
                                    fileName( meshTarget.time().timeName() ),
                                    meshTarget,
                                    IOobject.READ_IF_PRESENT,
                                    IOobject.AUTO_WRITE )
        if aTargetIOobject.headerOk() :
            aTargetField = aFieldClass( aTargetIOobject, meshTarget )
            pass
        pass
    
    from Foam import fvc
    meshSource = meshToMeshInterp.fromMesh()
    ext_Info() << tab <<"interpolating \"" << aFieldName << "\"" << nl
    ext_Info() << tab << tab << "source : \"" << meshSource.time().path() << "\"" << nl
    ext_Info() << tab << tab << tab << fvc.domainIntegrate( theSourceField ) << nl
    ext_Info() << tab << tab << tab << theSourceField.ext_min() << nl
    ext_Info() << tab << tab << tab << theSourceField.ext_max() << nl

    from Foam.sampling import meshToMesh
    meshToMeshInterp.interpolate( aTargetField, theSourceField, meshToMesh.INTERPOLATE )

    ext_Info() << tab << tab << "target : \"" << meshTarget.time().path() << "\"" << nl
    ext_Info() << tab << tab << tab << fvc.domainIntegrate( aTargetField ) << nl
    ext_Info() << tab << tab << tab << aTargetField.ext_min() << nl
    ext_Info() << tab << tab << tab << aTargetField.ext_max() << nl
   
    return aTargetField
コード例 #14
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
コード例 #15
0
ファイル: __init__.py プロジェクト: asimurzin/buoyantPisoFlux
def _createFields(runTime, mesh, g):
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Reading thermophysical properties\n" << nl

    from Foam.thermophysicalModels import basicRhoThermo
    thermo = basicRhoThermo.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.turbulenceModel.New(rho, U, phi, thermo())

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

    thermo.correct()

    initialMass = fvc.domainIntegrate(rho)

    totalVolume = mesh.V().ext_sum()

    return thermo, p, h, psi, phi, rho, U, turbulence, DpDt, initialMass, totalVolume
コード例 #16
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign(thermo.rho())

    rUA = 1.0 / UEqn.A()
    U.ext_assign(rUA * UEqn.H())
    UEqn.clear()

    closedVolume = False

    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    if transonic:
        phid = surfaceScalarField(
            word("phid"),
            fvc.interpolate(psi) * (fvc.interpolate(U) & mesh.Sf()))

        for nonOrth in range(nNonOrthCorr + 1):
            pEqn = fvm.div(phid, p) - fvm.laplacian(rho * rUA, p)

            # Relax the pressure equation to ensure diagonal-dominance
            pEqn.relax(mesh.relaxationFactor(word("pEqn")))

            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:
                phi == pEqn.flux()
                pass
            pass

        pass

    else:
        phi.ext_assign(
            fvc.interpolate(rho) * ((fvc.interpolate(U) & mesh.Sf())))

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

        for nonOrth in range(nNonOrthCorr + 1):
            # Pressure corrector
            pEqn = fvm.laplacian(rho * rUA, 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:
                phi.ext_assign(phi - pEqn.flux())
                pass
            pass
        pass

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

    # Explicitly relax pressure for momentum corrector
    p.relax()
    rho.ext_assign(thermo.rho())
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << nl

    U.ext_assign(U - rUA * fvc.grad(p))
    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound
    bound(p, pMin)

    # 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))
        pass

    return eqnResidual, maxResidual, cumulativeContErr
コード例 #17
0
def createFluidFields(fluidRegions, runTime):

    # Load boundary conditions
    from .. import derivedFvPatchFields

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

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

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

    DpDtFluid = PtrList_volScalarField(fluidRegions.size())

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

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

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

    p_rghFluid = PtrList_volScalarField(fluidRegions.size())

    ghFluid = PtrList_volScalarField(fluidRegions.size())

    ghfFluid = PtrList_surfaceScalarField(fluidRegions.size())

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

    #Populate fluid field pointer lists

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

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

        from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo

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

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

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

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

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

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

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

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

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

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

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

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

    return thermoFluid, rhoFluid, KFluid, UFluid, phiFluid, gFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid
コード例 #18
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
コード例 #19
0
def fun_pEqn( thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass, runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual, cumulativeContErr ):

    rho.ext_assign( thermo.rho() )
    rho.relax()

    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_rgh );

    buoyancyPhi =surfaceScalarField( rhorUAf * ghf * fvc.snGrad( rho ) * mesh.magSf() )
    
    phi.ext_assign( phi - buoyancyPhi )

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

        eqnResidual = p_rghEqn.solve().initialResidual()
        
        if (nonOrth == 0):
            maxResidual = max(eqnResidual, maxResidual)
            pass

        if (nonOrth == nNonOrthCorr):
           # Calculate the conservative fluxes
           phi.ext_assign( phi - p_rghEqn.flux() )
           # Explicitly relax pressure for momentum corrector
           p_rgh.relax()
           U.ext_assign( U - rUA * fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorUAf ) )
           U.correctBoundaryConditions()
           pass
    
    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    p.ext_assign( p_rgh + rho * gh )

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume:
       p.ext_assign( p + (initialMass - fvc.domainIntegrate( psi * p ) ) / fvc.domainIntegrate( psi ) )
       p_rgh.ext_assign( p - rho * gh )

    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
コード例 #20
0
def fun_pEqn(thermo, g, rho, UEqn, p, p_rgh, U, psi, phi, ghf, gh, initialMass,
             runTime, mesh, nNonOrthCorr, pRefCell, eqnResidual, maxResidual,
             cumulativeContErr):

    rho.ext_assign(thermo.rho())
    rho.relax()

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

    buoyancyPhi = surfaceScalarField(rhorUAf * ghf * fvc.snGrad(rho) *
                                     mesh.magSf())

    phi.ext_assign(phi - buoyancyPhi)

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

        from Foam.finiteVolume import getRefCellValue
        p_rghEqn.setReference(pRefCell, getRefCellValue(p_rgh, pRefCell))

        eqnResidual = p_rghEqn.solve().initialResidual()

        if (nonOrth == 0):
            maxResidual = max(eqnResidual, maxResidual)
            pass

        if (nonOrth == nNonOrthCorr):
            # Calculate the conservative fluxes
            phi.ext_assign(phi - p_rghEqn.flux())
            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()
            U.ext_assign(U - rUA * fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rhorUAf))
            U.correctBoundaryConditions()
            pass

    from Foam.finiteVolume.cfdTools.general.include import ContinuityErrs
    cumulativeContErr = ContinuityErrs(phi, runTime, mesh, cumulativeContErr)

    p.ext_assign(p_rgh + rho * gh)

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume:
        p.ext_assign(p + (initialMass - fvc.domainIntegrate(psi * p)) /
                     fvc.domainIntegrate(psi))
        p_rgh.ext_assign(p - rho * gh)

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

    from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo
    thermo = basicThermo.New(mesh)

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

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

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

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

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

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

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

    from Foam.finiteVolume import porousZones
    pZones = porousZones(mesh)

    from Foam.OpenFOAM import Switch
    pressureImplicitPorosity = Switch(False)

    nUCorr = 0

    if pZones.size():
        # nUCorrectors for pressureImplicitPorosity
        if (mesh.solutionDict().subDict(word("SIMPLE")).found(
                word("nUCorrectors"))):
            from Foam.OpenFOAM import readInt
            nUCorr = readInt(mesh.solutionDict().subDict(
                word("SIMPLE")).lookup(word("nUCorrectors")))
            pass
        if nUCorr > 0:
            pressureImplicitPorosity = True
            pass
        pass

    return turbulence, p, h, rho, U, phi, thermo, pZones, pMin, pressureImplicitPorosity, initialMass, nUCorr, pRefCell, pRefValue
コード例 #22
0
def _createFields(runTime, mesh):
    from Foam.OpenFOAM import ext_Info, nl

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

    from Foam.thermophysicalModels import basicThermo, autoPtr_basicThermo

    thermo = basicThermo.New(mesh)

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

    rho = volScalarField(
        IOobject(word("rho"), fileName(runTime.timeName()), mesh, IOobject.READ_IF_PRESENT, IOobject.AUTO_WRITE),
        thermo.rho(),
    )
    p = thermo.p()
    h = thermo.h()

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

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

    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi

    phi = compressibleCreatePhi(runTime, mesh, rho, U)

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

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

    from Foam.OpenFOAM import dimensionedScalar

    pMin = dimensionedScalar(mesh.solutionDict().subDict(word("SIMPLE")).lookup(word("pMin")))

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

    from Foam import fvc

    initialMass = fvc.domainIntegrate(rho)

    from Foam.finiteVolume import porousZones

    pZones = porousZones(mesh)

    from Foam.OpenFOAM import Switch

    pressureImplicitPorousity = Switch(False)

    nUCorr = 0

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

    return p, h, rho, U, phi, thermo, pZones, pMin, pressureImplicitPorousity, initialMass, nUCorr, pRefCell, pRefValue
コード例 #23
0
def _pEqn(
    mesh,
    rho,
    thermo,
    p,
    U,
    trTU,
    trAU,
    UEqn,
    phi,
    runTime,
    pMin,
    pressureImplicitPorousity,
    nNonOrthCorr,
    eqnResidual,
    maxResidual,
    cumulativeContErr,
    initialMass,
    pRefCell,
    pRefValue,
):

    if pressureImplicitPorousity:
        U.ext_assign(trTU & UEqn.H())
    else:
        U.ext_assign(trAU * UEqn.H())
        pass

    UEqn.clear()

    from Foam import fvc, fvm

    phi.ext_assign(fvc.interpolate(rho * U) & mesh.Sf())

    from Foam.finiteVolume import adjustPhi

    closedVolume = adjustPhi(phi, U, p)

    for nonOrth in range(nNonOrthCorr + 1):
        tpEqn = None
        if pressureImplicitPorosity:
            tpEqn = fvm.laplacian(rho * trTU, p) == fvc.div(phi)
        else:
            tpEqn = fvm.laplacian(rho * trAU, p) == fvc.div(phi)
            pass

        tpEqn.setReference(pRefCell, pRefValue)
        # retain the residual from the first iteration
        tpEqn.solve()

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

        pass

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs

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

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

    if pressureImplicitPorousity:
        U.ext_assign(U - (trTU & fvc.grad(p)))
    else:
        U.ext_assign(U - (trAU * fvc.grad(p)))
        pass

    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound

    bound(p, pMin)

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

    rho.ext_assign(thermo.rho())
    rho.relax()

    from Foam.OpenFOAM import ext_Info, nl

    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl

    return eqnResidual, maxResidual
コード例 #24
0
ファイル: __init__.py プロジェクト: asimurzin/buoyantPisoFlux
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
コード例 #25
0
def createFields( runTime, mesh, g ):
    ext_Info() << "Reading thermophysical properties\n" << nl
    
    from Foam.thermophysicalModels import autoPtr_basicPsiThermo, basicPsiThermo

    thermo = basicPsiThermo.New(mesh)
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName
    rho =  volScalarField( IOobject( word( "rho" ),
                                     fileName( runTime.timeName() ),
                                     mesh,
                                     IOobject.NO_READ,
                                     IOobject.NO_WRITE),
                           thermo.rho() )
    p = thermo.p()
    h = thermo.h()
    psi = thermo.psi()

    ext_Info()<< "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi( runTime, mesh, rho, U )
    
    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import compressible
    turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) 

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

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

    #Force p_rgh to be consistent with p
    p_rgh.ext_assign( p - rho*gh )

    pRefCell = 0
    pRefValue = 0.0
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( p, p_rgh, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pRefCell, pRefValue )
    
    from Foam import fvc
    initialMass = fvc.domainIntegrate( rho )
    totalVolume = mesh.V().ext_sum()
    
                        
    return thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, pRefCell, pRefValue, initialMass, totalVolume
コード例 #26
0
ファイル: __init__.py プロジェクト: asimurzin/rhoSimpleFlux
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, pMin, nNonOrthCorr, \
           pRefCell, pRefValue, eqnResidual, maxResidual, cumulativeContErr, transonic  ):
    rho.ext_assign( thermo.rho() )

    rUA = 1.0 / UEqn.A()
    U.ext_assign( rUA * UEqn.H() )
    UEqn.clear()
    
    closedVolume = False
    
    from Foam import fvc, fvm
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    if transonic: 
       phid = surfaceScalarField( word( "phid" ), 
                                  fvc.interpolate( psi ) * ( fvc.interpolate( U ) & mesh.Sf() ) )


       for nonOrth in range( nNonOrthCorr + 1 ) :
           pEqn = fvm.div( phid, p ) - fvm.laplacian( rho * rUA, p )
           
           # Relax the pressure equation to ensure diagonal-dominance
           pEqn.relax( mesh.relaxationFactor( word( "pEqn" ) ) )

           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:
              phi == pEqn.flux()
              pass
           pass
       
       pass
       
    else:
       phi.ext_assign( fvc.interpolate( rho ) * ( ( fvc.interpolate(U) & mesh.Sf() ) ) )
       
       from Foam.finiteVolume import adjustPhi
       closedVolume = adjustPhi( phi, U, p )
       
       
       for nonOrth in range( nNonOrthCorr + 1 ) :
           # Pressure corrector
           pEqn = fvm.laplacian( rho * rUA, 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:
              phi.ext_assign( phi - pEqn.flux() )
              pass
           pass
       pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    p.relax()
    rho.ext_assign( thermo.rho() )
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    U.ext_assign( U - rUA * fvc.grad( p ) )
    U.correctBoundaryConditions()
    
    from Foam.finiteVolume import bound
    bound(p, pMin);
        
    # 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 ) )
       pass
    
    return eqnResidual, maxResidual, cumulativeContErr
コード例 #27
0
def pEqn( runTime, mesh, p, phi, psi, U, UEqn, g, rho, thermo, initialMass, eqnResidual, maxResidual, nNonOrthCorr, cumulativeContErr, pRefCell, pRefValue ): 
    rho.ext_assign( thermo.rho() )
    
    from Foam import fvc
    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() )
    UEqn.clear();

    phi.ext_assign( fvc.interpolate( rho ) * ( fvc.interpolate( U ) & mesh.Sf() ) )
    
    from Foam.finiteVolume import adjustPhi
    closedVolume = adjustPhi( phi, U, p )

    buoyancyPhi = rhorUAf * fvc.interpolate( rho ) * (g & mesh.Sf() )
    phi.ext_assign( phi + buoyancyPhi )
    
    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1): 
        pEqn = fvm.laplacian( rhorUAf, 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:
           # 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 ) )
              pass

           # 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() ) / rhorUAf ) )
           U.correctBoundaryConditions()
           pass

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

    rho.ext_assign( thermo.rho() )
    rho.relax()
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << nl
    
    
    return eqnResidual, maxResidual, cumulativeContErr
コード例 #28
0
def _pEqn( mesh, rho, thermo, p, U, trTU, trAU, UEqn, phi, \
           runTime, pMin, pressureImplicitPorosity, nNonOrthCorr, eqnResidual, maxResidual, cumulativeContErr, initialMass, pRefCell, pRefValue ):

    if pressureImplicitPorosity:
        U.ext_assign(trTU & UEqn.H())
    else:
        U.ext_assign(trAU * UEqn.H())
        pass

    UEqn.clear()

    from Foam import fvc, fvm
    phi.ext_assign(fvc.interpolate(rho * U) & mesh.Sf())

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

    for nonOrth in range(nNonOrthCorr + 1):
        tpEqn = None
        if pressureImplicitPorosity:
            tpEqn = (fvm.laplacian(rho * trTU, p) == fvc.div(phi))
        else:
            tpEqn = (fvm.laplacian(rho * trAU, p) == fvc.div(phi))
            pass

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

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

        pass

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

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

    if pressureImplicitPorosity:
        U.ext_assign(U - (trTU & fvc.grad(p)))
    else:
        U.ext_assign(U - (trAU * fvc.grad(p)))
        pass

    U.correctBoundaryConditions()

    from Foam.finiteVolume import bound
    bound(p, pMin)

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

    rho.ext_assign(thermo.rho())
    rho.relax()

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "rho max/min : " << rho.ext_max().value(
    ) << " " << rho.ext_min().value() << nl

    return eqnResidual, maxResidual
コード例 #29
0
def createFields( runTime, mesh, g ):
    ext_Info() << "Reading thermophysical properties\n" << nl
    
    from Foam.thermophysicalModels import autoPtr_basicThermo, basicThermo
    thermo = basicThermo.New( mesh )
    
    from Foam.finiteVolume import volScalarField
    from Foam.OpenFOAM import IOobject, word, fileName
    rho =  volScalarField( IOobject( word( "rho" ),
                                     fileName( runTime.timeName() ),
                                     mesh,
                                     IOobject.NO_READ,
                                     IOobject.NO_WRITE),
                           thermo.rho() )
    p = thermo.p()
    h = thermo.h()
    T = thermo.T()

    ext_Info()<< "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
    
    from Foam.finiteVolume.cfdTools.compressible import compressibleCreatePhi
    phi = compressibleCreatePhi( runTime, mesh, rho, U )
    
    ext_Info() << "Creating turbulence model\n" << nl
    from Foam import compressible
    turbulence = compressible.RASModel.New( rho, U, phi, thermo() ) 

    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField ( word( "gh" ), g & mesh.C() )
    
    from Foam.OpenFOAM import dimensionedScalar
    pRef = dimensionedScalar( word( "pRef" ), p.dimensions(), thermo.lookup( word( "pRef" ) ) )
    
    ext_Info() << "Creating field pd\n" << nl
    pd = volScalarField( IOobject( word( "pd" ),
                                   fileName( runTime.timeName() ),
                                   mesh,
                                   IOobject.MUST_READ,
                                   IOobject.AUTO_WRITE ),
                         mesh )
    
    p.ext_assign( pd + rho * gh + pRef )
    thermo.correct()
    
    pdRefCell = 0
    pdRefValue = 0.0
    from Foam.finiteVolume import setRefCell
    pRefCell, pRefValue = setRefCell( pd, mesh.solutionDict().subDict( word( "SIMPLE" ) ), pdRefCell, pdRefValue )
    
    ext_Info() << "Creating radiation model\n" << nl
    
    from Foam.radiation import radiationModel
    radiation =radiationModel.New( T )
    
    from Foam import fvc
    initialMass = fvc.domainIntegrate( rho )
    
                        
    return thermo, rho, p, h, T, U, phi, turbulence, gh, pRef, pd, p, pdRefCell, pdRefValue, radiation, initialMass 
コード例 #30
0
def createFluidFields( fluidRegions, runTime ) :

    # Load boundary conditions
    from .. import derivedFvPatchFields

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

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

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

    DpDtFluid = PtrList_volScalarField( fluidRegions.size() )
     
    from Foam.OpenFOAM import PtrList_uniformDimensionedVectorField
    gFluid = PtrList_uniformDimensionedVectorField( fluidRegions.size() )
 
    from Foam.compressible import PtrList_compressible_turbulenceModel
    turbulence = PtrList_compressible_turbulenceModel( fluidRegions.size() ) 
    
    from Foam.thermophysicalModels import PtrList_basicRhoThermo
    thermoFluid = PtrList_basicRhoThermo( fluidRegions.size() ) 
    
    p_rghFluid = PtrList_volScalarField( fluidRegions.size() )
    
    ghFluid = PtrList_volScalarField( fluidRegions.size() )
    
    ghfFluid = PtrList_surfaceScalarField(fluidRegions.size())
    
    from Foam.OpenFOAM import scalarList
    initialMassFluid = scalarList( fluidRegions.size() )
    
    #Populate fluid field pointer lists

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

        ext_Info()<< "    Adding to thermoFluid\n" << nl
        
        from Foam.thermophysicalModels import autoPtr_basicRhoThermo, basicRhoThermo
 
        thermo= basicRhoThermo.New( fluidRegions[ index ] )
        thermoFluid.ext_set( index, thermo )
        
        ext_Info()<< "    Adding to rhoFluid\n" << nl
        from Foam.OpenFOAM import word, fileName, IOobject
        from Foam.finiteVolume import volScalarField
        rhoFluid.ext_set( index, volScalarField( IOobject( word( "rho" ), 
                                                           fileName( runTime.timeName() ), 
                                                           fluidRegions[ index ], 
                                                           IOobject.NO_READ, 
                                                           IOobject.AUTO_WRITE ),
                                                 thermoFluid[ index ].rho() ) )
        
        ext_Info()<< "    Adding to KFluid\n" << nl
        KFluid.ext_set( index, volScalarField( IOobject( word( "K" ),
                                                         fileName( runTime.timeName() ),
                                                         fluidRegions[ index ],
                                                         IOobject.NO_READ,
                                                         IOobject.NO_WRITE ),
                                               thermoFluid[ index ].Cp().ptr() * thermoFluid[ index ].alpha() ) )
                                                       
        ext_Info()<< "    Adding to UFluid\n" << nl
        from Foam.finiteVolume import volVectorField
        UFluid.ext_set( index, volVectorField( IOobject( word( "U" ),
                                                         fileName( runTime.timeName() ),
                                                         fluidRegions[ index ],
                                                         IOobject.MUST_READ,
                                                         IOobject.AUTO_WRITE ),
                                               fluidRegions[ index ] ) )
        
        ext_Info()<< "    Adding to phiFluid\n" << nl
        from Foam.finiteVolume import surfaceScalarField
        from Foam.finiteVolume import linearInterpolate

        phiFluid.ext_set( index, surfaceScalarField( IOobject( word( "phi" ),
                                                               fileName( runTime.timeName() ),
                                                               fluidRegions[ index ],
                                                               IOobject.READ_IF_PRESENT,
                                                               IOobject.AUTO_WRITE),
                                                     linearInterpolate( rhoFluid[ index ] * UFluid[ index ] ) & fluidRegions[ index ].Sf() ) )
        
        ext_Info()<< "    Adding to gFluid\n" << nl
        from Foam.OpenFOAM import uniformDimensionedVectorField
        gFluid.ext_set( index, uniformDimensionedVectorField( IOobject( word( "g" ),
                                                                        fileName( runTime.constant() ),
                                                                        fluidRegions[ index ],
                                                                        IOobject.MUST_READ,
                                                                        IOobject.NO_WRITE ) ) )        
        
        ext_Info()<< "    Adding to turbulence\n" << nl
        from Foam import compressible
        turbulence.ext_set( index, compressible.turbulenceModel.New( rhoFluid[ index ],
                                                                     UFluid[ index ],
                                                                     phiFluid[ index ],
                                                                     thermoFluid[ index ] ) )
        ext_Info() << "    Adding to ghFluid\n" << nl
        ghFluid.ext_set( index, volScalarField( word( "gh" ) , gFluid[ index ] & fluidRegions[ index ].C() ) )

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

        p_rghFluid.ext_set( index, volScalarField( IOobject( word( "p_rgh" ),
                                                         fileName( runTime.timeName() ),
                                                         fluidRegions[ index ],
                                                         IOobject.MUST_READ,
                                                         IOobject.AUTO_WRITE ),
                                               fluidRegions[ index ] ) )
        # Force p_rgh to be consistent with p
        p_rghFluid[ index ].ext_assign( thermoFluid[ index ].p() - rhoFluid[ index ] * ghFluid[ index ] )
        
        from Foam import fvc
        initialMassFluid[ index ] = fvc.domainIntegrate( rhoFluid[ index ] ).value() 
        
        ext_Info()<< "    Adding to DpDtFluid\n" << nl
        DpDtFluid.ext_set( index, volScalarField( word( "DpDt" ), fvc.DDt( surfaceScalarField( word( "phiU" ), 
                                                                                               phiFluid[ index ] / fvc.interpolate( rhoFluid[ index ] ) ),
                                                                           thermoFluid[ index ].p() ) ) )

    
    return thermoFluid, rhoFluid, KFluid, UFluid, phiFluid, gFluid, turbulence, DpDtFluid, initialMassFluid, ghFluid, ghfFluid, p_rghFluid
コード例 #31
0
                                                       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
        

#-----------------------------------------------------------------------------------------------------------------------
def compressibleCourantNo( mesh, runTime, rho, phi) :
    
    from Foam.OpenFOAM import Time
    from Foam.finiteVolume import fvMesh
    from Foam.finiteVolume import surfaceScalarField

    CoNum = 0.0;
    meanCoNum = 0.0;