Esempio n. 1
0
def main_standalone( argc, argv ):

    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )

    mesh = man.createMesh( runTime )
    
    thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, \
                          neg, inviscid, phi, turbulence = _createFields( runTime, mesh )
    
    thermophysicalProperties, Pr = readThermophysicalProperties( runTime, mesh )
    
    fluxScheme = readFluxScheme( mesh )
    
    v_zero = ref.dimensionedScalar( ref.word( "v_zero" ), ref.dimVolume / ref.dimTime, 0.0)
    
    ref.ext_Info() << "\nStarting time loop\n" << ref.nl
    
    while runTime.run() :
        # --- upwind interpolation of primitive fields on faces
        rho_pos = ref.fvc.interpolate( rho, pos, ref.word( "reconstruct(rho)" ) )
        rho_neg = ref.fvc.interpolate( rho, neg, ref.word( "reconstruct(rho)" ) )
        
        rhoU_pos = ref.fvc.interpolate( rhoU, pos, ref.word( "reconstruct(U)" ) )
        rhoU_neg = ref.fvc.interpolate( rhoU, neg, ref.word( "reconstruct(U)" ) )

        rPsi = 1.0 / psi
        rPsi_pos = ref.fvc.interpolate( rPsi, pos, ref.word( "reconstruct(T)" ) )
        rPsi_neg = ref.fvc.interpolate( rPsi, neg, ref.word( "reconstruct(T)" ) )

        e_pos = ref.fvc.interpolate( e, pos, ref.word( "reconstruct(T)" ) )
        e_neg = ref.fvc.interpolate( e, neg, ref.word( "reconstruct(T)" ) )

        U_pos = rhoU_pos / rho_pos
        U_neg = rhoU_neg / rho_neg

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

        phiv_pos = U_pos & mesh.Sf()
        phiv_neg = U_neg & mesh.Sf()

        c = ( thermo.Cp() / thermo.Cv() * rPsi ).sqrt()
        cSf_pos = ref.fvc.interpolate( c, pos, ref.word( "reconstruct(T)" ) ) * mesh.magSf()
        cSf_neg = ref.fvc.interpolate( c, neg, ref.word( "reconstruct(T)" ) ) * mesh.magSf()
   
        ap = ( phiv_pos + cSf_pos ).ext_max( phiv_neg + cSf_neg ).ext_max( v_zero )
        am = ( phiv_pos - cSf_pos ).ext_min( phiv_neg - cSf_neg ).ext_min( v_zero )

        a_pos = ap / ( ap - am )
        
        amaxSf = ref.surfaceScalarField( ref.word( "amaxSf" ), am.mag().ext_max( ap.mag() ) )
        
        aSf = am * a_pos

        if str( fluxScheme ) == "Tadmor":
           aSf << -0.5 * amaxSf
           a_pos << 0.5
           pass

        a_neg = 1.0 - a_pos
        
        phiv_pos *= a_pos
        phiv_neg *= a_neg
        
        aphiv_pos = phiv_pos - aSf
        aphiv_neg = phiv_neg + aSf
        
        # Reuse amaxSf for the maximum positive and negative fluxes
        # estimated by the central scheme
        amaxSf << aphiv_pos.mag().ext_max(  aphiv_neg.mag() )

        CoNum, meanCoNum = compressibleCourantNo( mesh, amaxSf, runTime )
        
        adjustTimeStep, maxCo, maxDeltaT = ref.readTimeControls( runTime )
        
        runTime = ref.setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum )
        
        runTime.increment()
        
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl
        phi << aphiv_pos * rho_pos + aphiv_neg * rho_neg

        phiUp = ( aphiv_pos * rhoU_pos + aphiv_neg * rhoU_neg) + ( a_pos * p_pos + a_neg * p_neg ) * mesh.Sf()

        phiEp = aphiv_pos * ( rho_pos * ( e_pos + 0.5*U_pos.magSqr() ) + p_pos ) + aphiv_neg * ( rho_neg * ( e_neg + 0.5 * U_neg.magSqr() ) + p_neg )\
                + aSf * p_pos - aSf * p_neg
        
   
        muEff = turbulence.muEff()
        tauMC = ref.volTensorField( ref.word( "tauMC" ) , muEff * ref.fvc.grad(U).T().dev2() ) 

        # --- Solve density
        ref.solve( ref.fvm.ddt( rho ) + ref.fvc.div( phi ) )
        
        # --- Solve momentum
        ref.solve( ref.fvm.ddt( rhoU ) + ref.fvc.div( phiUp ) )
        
        U.dimensionedInternalField() << rhoU.dimensionedInternalField() / rho.dimensionedInternalField()
        U.correctBoundaryConditions()
        
        rhoU.ext_boundaryField() << rho.ext_boundaryField() * U.ext_boundaryField()
        
        rhoBydt = rho / runTime.deltaT()
        
        if not inviscid:
           solve( fvm.ddt( rho, U ) - fvc.ddt( rho, U ) - fvm.laplacian( muEff, U ) - fvc.div( tauMC ) )
           rhoU << rho * U
           pass
        
        # --- Solve energy
        sigmaDotU = ( ref.fvc.interpolate( muEff ) * mesh.magSf() * ref.fvc.snGrad( U ) + 
                      ( mesh.Sf() & ref.fvc.interpolate( tauMC ) ) ) & ( a_pos * U_pos + a_neg * U_neg )

        ref.solve( ref.fvm.ddt( rhoE ) + ref.fvc.div( phiEp ) - ref.fvc.div( sigmaDotU ) )
        
        e << rhoE() / rho() - 0.5 * U.magSqr() # mixed calculations
        e.correctBoundaryConditions()
        thermo.correct()

        rhoE.ext_boundaryField() << rho.ext_boundaryField() * ( e.ext_boundaryField() + 0.5 * U.ext_boundaryField().magSqr() )
        
        if not inviscid :
           k = man.volScalarField( ref.word( "k" ) , thermo.Cp() * muEff / Pr )

           # The initial C++ expression does not work properly, because of
           #  1. the order of expression arguments computation differs with C++
           #solve( fvm.ddt( rho, e ) - fvc.ddt( rho, e ) - fvm.laplacian( thermo.alpha(), e ) \
           #                                             + fvc.laplacian( thermo.alpha(), e ) - fvc.laplacian( k, T ) )

           solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( turbulence.alpha(), e ) \
                                         + (- fvm.laplacian( turbulence.alphaEff(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )
           
           thermo.correct()
           rhoE << rho * ( e + 0.5 * U.magSqr() )
           pass
        
        p.dimensionedInternalField() << rho.dimensionedInternalField() / psi.dimensionedInternalField()
        p.correctBoundaryConditions()

        rho.ext_boundaryField() << psi.ext_boundaryField() * p.ext_boundaryField() 
        
        turbulence.correct()
        runTime.write()

        ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << ref.nl << ref.nl
        
        pass

    ref.ext_Info() << "End\n"

    import os
    return os.EX_OK
Esempio n. 2
0
def main_standalone( argc, argv ):

    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 )
    
    thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid = _createFields( runTime, mesh )
    
    thermophysicalProperties, Pr = readThermophysicalProperties( runTime, mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
    
    fluxScheme = readFluxScheme( mesh )
    
    from Foam.OpenFOAM import dimensionedScalar, dimVolume, dimTime, word
    v_zero = dimensionedScalar( word( "v_zero" ) ,dimVolume/dimTime, 0.0)
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl
    
    while runTime.run() :
        # --- upwind interpolation of primitive fields on faces
        from Foam import fvc
        rho_pos = fvc.interpolate( rho, pos, word( "reconstruct(rho)" ) )
        rho_neg = fvc.interpolate( rho, neg, word( "reconstruct(rho)" ) )
        
        rhoU_pos = fvc.interpolate( rhoU, pos, word( "reconstruct(U)" ) )
        rhoU_neg = fvc.interpolate( rhoU, neg, word( "reconstruct(U)" ) )
        
        rPsi = 1.0 / psi
        rPsi_pos = fvc.interpolate( rPsi, pos, word( "reconstruct(T)" ) )
        rPsi_neg = fvc.interpolate( rPsi, neg, word( "reconstruct(T)" ) )
        
        e_pos = fvc.interpolate( e, pos, word( "reconstruct(T)" ) )
        e_neg = fvc.interpolate( e, neg, word( "reconstruct(T)" ) )
        
        U_pos = rhoU_pos / rho_pos
        U_neg = rhoU_neg / rho_neg

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

        phiv_pos = U_pos & mesh.Sf()
        phiv_neg = U_neg & mesh.Sf()
        
        c = ( thermo.Cp() / thermo.Cv() * rPsi ).sqrt()
        cSf_pos = fvc.interpolate( c, pos, word( "reconstruct(T)" ) ) * mesh.magSf()
        cSf_neg = fvc.interpolate( c, neg, word( "reconstruct(T)" ) ) * mesh.magSf()
        
        ap = ( phiv_pos + cSf_pos ).ext_max( phiv_neg + cSf_neg ).ext_max( v_zero )
        am = ( phiv_pos - cSf_pos ).ext_min( phiv_neg - cSf_neg ).ext_min( v_zero )

        a_pos = ap / ( ap - am )
        
        from Foam.finiteVolume import surfaceScalarField
        amaxSf = surfaceScalarField( word( "amaxSf" ), am.mag().ext_max( ap.mag() ) )
        
        CoNum, meanCoNum = compressibleCourantNo( mesh, amaxSf, runTime )
        
        from Foam.finiteVolume.cfdTools.general.include import readTimeControls
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
        
        from Foam.finiteVolume.cfdTools.general.include import setDeltaT
        runTime = setDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum )
        
        runTime.increment()
        
        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        
        aSf = am * a_pos

        if str( fluxScheme ) == "Tadmor":
           aSf.ext_assign( -0.5 * amaxSf )
           a_pos.ext_assign( 0.5 )
           pass
        
        a_neg = 1.0 - a_pos
        
        phiv_pos *= a_pos
        phiv_neg *= a_neg
        
        aphiv_pos = phiv_pos - aSf
        
        aphiv_neg = phiv_neg + aSf

        phi = None

        phi = surfaceScalarField( word( "phi" ), aphiv_pos * rho_pos + aphiv_neg * rho_neg )

        phiUp = ( aphiv_pos * rhoU_pos + aphiv_neg * rhoU_neg) + ( a_pos * p_pos + a_neg * p_neg ) * mesh.Sf()

        phiEp = aphiv_pos * ( rho_pos * ( e_pos + 0.5*U_pos.magSqr() ) + p_pos ) + aphiv_neg * ( rho_neg * ( e_neg + 0.5 * U_neg.magSqr() ) + p_neg )\
                + aSf * p_pos - aSf * p_neg
        
        from Foam.finiteVolume import volTensorField
        from Foam import fvc
        tauMC = volTensorField( word( "tauMC" ) , mu * fvc.grad(U).T().dev2() ) 
        
        # --- Solve density
        from Foam.finiteVolume import solve
        from Foam import fvm
        solve( fvm.ddt( rho ) + fvc.div( phi ) )
        
        # --- Solve momentum
        solve( fvm.ddt( rhoU ) + fvc.div( phiUp ) )
        
        U.dimensionedInternalField().ext_assign( rhoU.dimensionedInternalField() / rho.dimensionedInternalField() )
        U.correctBoundaryConditions()
        rhoU.ext_boundaryField().ext_assign( rho.ext_boundaryField() * U.ext_boundaryField() )
        
        rhoBydt = rho / runTime.deltaT()
        
        if not inviscid:
           solve( fvm.ddt( rho, U ) - fvc.ddt( rho, U ) - fvm.laplacian( mu, U ) - fvc.div( tauMC ) )
           rhoU.ext_assign( rho * U )
           pass
        
        # --- Solve energy
        sigmaDotU = ( fvc.interpolate( mu ) * mesh.magSf() * fvc.snGrad( U ) + ( mesh.Sf() & fvc.interpolate( tauMC ) ) ) & ( a_pos * U_pos + a_neg * U_neg )

        solve( fvm.ddt( rhoE ) + fvc.div( phiEp ) - fvc.div( sigmaDotU ) )
        
        e.ext_assign( rhoE / rho - 0.5 * U.magSqr() )
        e.correctBoundaryConditions()
        thermo.correct()
        from Foam.finiteVolume import volScalarField
        rhoE.ext_boundaryField().ext_assign( rho.ext_boundaryField() * ( e.ext_boundaryField() + 0.5 * U.ext_boundaryField().magSqr() ) )
        
        if not inviscid:
           k = volScalarField( word( "k" ) , thermo.Cp() * mu / Pr )

           # The initial C++ expression does not work properly, because of
           #  1. the order of expression arguments computation differs with C++
           #solve( fvm.ddt( rho, e ) - fvc.ddt( rho, e ) - fvm.laplacian( thermo.alpha(), e ) \
           #                                             + fvc.laplacian( thermo.alpha(), e ) - fvc.laplacian( k, T ) )

           solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( thermo.alpha(), e ) \
                                         + (- fvm.laplacian( thermo.alpha(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )
           
           thermo.correct()
           rhoE.ext_assign( rho * ( e + 0.5 * U.magSqr() ) )
           pass
        
        p.dimensionedInternalField().ext_assign( rho.dimensionedInternalField() / psi.dimensionedInternalField() )
        p.correctBoundaryConditions()
        rho.ext_boundaryField().ext_assign( psi.ext_boundaryField() * p.ext_boundaryField() )
        
        runTime.write()

        ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
        pass

    ext_Info() << "End\n"

    import os
    return os.EX_OK
Esempio n. 3
0
def main_standalone(argc, argv):

    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)

    thermo, p, e, T, psi, mu, U, pbf, rhoBoundaryTypes, rho, rhoU, rhoE, pos, neg, inviscid = _createFields(
        runTime, mesh)

    thermophysicalProperties, Pr = readThermophysicalProperties(runTime, mesh)

    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

    fluxScheme = readFluxScheme(mesh)

    from Foam.OpenFOAM import dimensionedScalar, dimVolume, dimTime, word
    v_zero = dimensionedScalar(word("v_zero"), dimVolume / dimTime, 0.0)

    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl

    while runTime.run():
        # --- upwind interpolation of primitive fields on faces
        from Foam import fvc
        rho_pos = fvc.interpolate(rho, pos, word("reconstruct(rho)"))
        rho_neg = fvc.interpolate(rho, neg, word("reconstruct(rho)"))

        rhoU_pos = fvc.interpolate(rhoU, pos, word("reconstruct(U)"))
        rhoU_neg = fvc.interpolate(rhoU, neg, word("reconstruct(U)"))

        rPsi = 1.0 / psi
        rPsi_pos = fvc.interpolate(rPsi, pos, word("reconstruct(T)"))
        rPsi_neg = fvc.interpolate(rPsi, neg, word("reconstruct(T)"))

        e_pos = fvc.interpolate(e, pos, word("reconstruct(T)"))
        e_neg = fvc.interpolate(e, neg, word("reconstruct(T)"))

        U_pos = rhoU_pos / rho_pos
        U_neg = rhoU_neg / rho_neg

        p_pos = rho_pos * rPsi_pos
        p_neg = rho_neg * rPsi_neg

        phiv_pos = U_pos & mesh.Sf()
        phiv_neg = U_neg & mesh.Sf()

        c = (thermo.Cp() / thermo.Cv() * rPsi).sqrt()
        cSf_pos = fvc.interpolate(c, pos,
                                  word("reconstruct(T)")) * mesh.magSf()
        cSf_neg = fvc.interpolate(c, neg,
                                  word("reconstruct(T)")) * mesh.magSf()

        ap = (phiv_pos + cSf_pos).ext_max(phiv_neg + cSf_neg).ext_max(v_zero)
        am = (phiv_pos - cSf_pos).ext_min(phiv_neg - cSf_neg).ext_min(v_zero)

        a_pos = ap / (ap - am)

        from Foam.finiteVolume import surfaceScalarField
        amaxSf = surfaceScalarField(word("amaxSf"), am.mag().ext_max(ap.mag()))

        aSf = am * a_pos

        if str(fluxScheme) == "Tadmor":
            aSf.ext_assign(-0.5 * amaxSf)
            a_pos.ext_assign(0.5)
            pass

        a_neg = 1.0 - a_pos

        phiv_pos *= a_pos
        phiv_neg *= a_neg

        aphiv_pos = phiv_pos - aSf

        aphiv_neg = phiv_neg + aSf

        # Reuse amaxSf for the maximum positive and negative fluxes
        # estimated by the central scheme
        amaxSf.ext_assign(aphiv_pos.mag().ext_max(aphiv_neg.mag()))

        CoNum, meanCoNum = compressibleCourantNo(mesh, amaxSf, runTime)

        from Foam.finiteVolume.cfdTools.general.include import readTimeControls
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls(runTime)

        from Foam.finiteVolume.cfdTools.general.include import setDeltaT
        runTime = setDeltaT(runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum)

        runTime.increment()

        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        phi = None

        phi = surfaceScalarField(word("phi"),
                                 aphiv_pos * rho_pos + aphiv_neg * rho_neg)

        phiUp = (aphiv_pos * rhoU_pos + aphiv_neg *
                 rhoU_neg) + (a_pos * p_pos + a_neg * p_neg) * mesh.Sf()

        phiEp = aphiv_pos * ( rho_pos * ( e_pos + 0.5*U_pos.magSqr() ) + p_pos ) + aphiv_neg * ( rho_neg * ( e_neg + 0.5 * U_neg.magSqr() ) + p_neg )\
                + aSf * p_pos - aSf * p_neg

        from Foam.finiteVolume import volTensorField
        from Foam import fvc
        tauMC = volTensorField(word("tauMC"), mu * fvc.grad(U).T().dev2())

        # --- Solve density
        from Foam.finiteVolume import solve
        from Foam import fvm
        solve(fvm.ddt(rho) + fvc.div(phi))

        # --- Solve momentum
        solve(fvm.ddt(rhoU) + fvc.div(phiUp))

        U.dimensionedInternalField().ext_assign(
            rhoU.dimensionedInternalField() / rho.dimensionedInternalField())
        U.correctBoundaryConditions()
        rhoU.ext_boundaryField().ext_assign(rho.ext_boundaryField() *
                                            U.ext_boundaryField())

        rhoBydt = rho / runTime.deltaT()

        if not inviscid:
            solve(
                fvm.ddt(rho, U) - fvc.ddt(rho, U) - fvm.laplacian(mu, U) -
                fvc.div(tauMC))
            rhoU.ext_assign(rho * U)
            pass

        # --- Solve energy
        sigmaDotU = (fvc.interpolate(mu) * mesh.magSf() * fvc.snGrad(U) +
                     (mesh.Sf() & fvc.interpolate(tauMC))) & (a_pos * U_pos +
                                                              a_neg * U_neg)

        solve(fvm.ddt(rhoE) + fvc.div(phiEp) - fvc.div(sigmaDotU))

        e.ext_assign(rhoE / rho - 0.5 * U.magSqr())
        e.correctBoundaryConditions()
        thermo.correct()
        from Foam.finiteVolume import volScalarField
        rhoE.ext_boundaryField().ext_assign(
            rho.ext_boundaryField() *
            (e.ext_boundaryField() + 0.5 * U.ext_boundaryField().magSqr()))

        if not inviscid:
            k = volScalarField(word("k"), thermo.Cp() * mu / Pr)

            # The initial C++ expression does not work properly, because of
            #  1. the order of expression arguments computation differs with C++
            #solve( fvm.ddt( rho, e ) - fvc.ddt( rho, e ) - fvm.laplacian( thermo.alpha(), e ) \
            #                                             + fvc.laplacian( thermo.alpha(), e ) - fvc.laplacian( k, T ) )

            solve( -fvc.laplacian( k, T ) + ( fvc.laplacian( thermo.alpha(), e ) \
                                          + (- fvm.laplacian( thermo.alpha(), e ) + (- fvc.ddt( rho, e ) + fvm.ddt( rho, e ) ) ) ) )

            thermo.correct()
            rhoE.ext_assign(rho * (e + 0.5 * U.magSqr()))
            pass

        p.dimensionedInternalField().ext_assign(
            rho.dimensionedInternalField() / psi.dimensionedInternalField())
        p.correctBoundaryConditions()
        rho.ext_boundaryField().ext_assign(psi.ext_boundaryField() *
                                           p.ext_boundaryField())

        runTime.write()

        ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl

        pass

    ext_Info() << "End\n"

    import os
    return os.EX_OK