Esempio n. 1
0
def fun_pEqn( mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, mrfZones, turbulence, UEqn, DpDt, cumulativeContErr, corr, rhoMax, rhoMin ):

    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()

    rAU = 1.0 / UEqn.A()
    U << rAU() * UEqn.H()

    if pimple.transonic():
        phid = ref.surfaceScalarField( ref.word( "phid" ), ref.fvc.interpolate( psi ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) \
                                                                                          + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) ) );
        mrfZones.relativeFlux( ref.fvc.interpolate( psi ), phid )
        
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p) + ref.fvm.div( phid, p ) - ref.fvm.laplacian( rho() * rAU, p ) # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )

            if nonOrth == pimple.nNonOrthCorr():
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi << ref.fvc.interpolate( rho ) * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )
        
        mrfZones.relativeFlux( ref.fvc.interpolate( rho ), phi )
        
        for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
            pEqn = ref.fvm.ddt( psi, p ) + ref.fvc.div( phi ) - ref.fvm.laplacian( rho()*rAU, p )  # mixed calculations
            
            pEqn.solve( mesh.solver( p.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )
            
            if nonOrth == pimple.nNonOrthCorr():
                phi += pEqn.flux()
                pass
            pass    
        pass

    ref.rhoEqn( rho, phi )
    cumulativeContErr = ref.compressibleContinuityErrs( rho(), thermo, cumulativeContErr ) # mixed calculations
    # Explicitly relax pressure for momentum corrector
    p.relax()
    
    # Recalculate density from the relaxed pressure
    rho << thermo.rho()
    rho << rho().ext_max( rhoMin )
    rho << rho().ext_min( rhoMax )
    rho.relax()
    ref.ext_Info()<< "rho max/min : " << rho.ext_max().value()  << " " << rho.ext_min().value() << ref.nl

    U -= rAU * ref.fvc.grad( p )
    U.correctBoundaryConditions()

    DpDt << ref.fvc.DDt( ref.surfaceScalarField( ref.word( "phiU" ), phi() / ref.fvc.interpolate( rho ) ), p ) # mixed calculations
    
    return cumulativeContErr
Esempio n. 2
0
def fun_pEqn(mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, turbulence,
             gh, ghf, p_rgh, UEqn, DpDt, cumulativeContErr, corr):
    rho << thermo.rho()

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

    rAU = 1.0 / UEqn.A()
    rhorAUf = ref.surfaceScalarField(ref.word("(rho*(1|A(U)))"),
                                     ref.fvc.interpolate(rho * rAU))

    U << rAU * UEqn.H()

    phi << ref.fvc.interpolate(rho) * ((ref.fvc.interpolate(U) & mesh.Sf()) +
                                       ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

    buoyancyPhi = -rhorAUf * ghf * ref.fvc.snGrad(rho) * mesh.magSf()

    phi += buoyancyPhi

    p_rghDDtEqn = ref.fvc.ddt(rho) + psi * ref.correction(
        ref.fvm.ddt(p_rgh)) + ref.fvc.div(phi)

    for nonOrth in range(pimple.nNonOrthCorr() + 1):
        p_rghEqn = p_rghDDtEqn - ref.fvm.laplacian(rhorAUf, p_rgh)

        p_rghEqn.solve(
            mesh.solver(p_rgh.select(pimple.finalInnerIter(corr, nonOrth))))

        if nonOrth == pimple.nNonOrthCorr():
            # Calculate the conservative fluxes
            phi += p_rghEqn.flux()
            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U += rAU * ref.fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rhorAUf)
            U.correctBoundaryConditions()
            pass
        pass

    p << p_rgh + rho * gh

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

    DpDt << ref.fvc.DDt(
        ref.surfaceScalarField(ref.word("phiU"),
                               phi() / ref.fvc.interpolate(rho)),
        p)  # mixed calculations

    ref.rhoEqn(rho, phi)
    cumulativeContErr = ref.compressibleContinuityErrs(
        rho(), thermo, cumulativeContErr)  #mixed calculations

    return cumulativeContErr
Esempio n. 3
0
def fun_pEqn( mesh, runTime, thermo, rho, p, psi, U, phi, turbulence, UEqn, cumulativeContErr, nNonOrthCorr ):
      
     rho<<thermo.rho()
 
     rAU = 1.0 / UEqn.A()
  
     U<< rAU * UEqn.H()
     
     phid = ref.surfaceScalarField( ref.word( "phid" ),
                                    ref.fvc.interpolate( psi ) * 
                                             ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) ) )

     for nonOrth in range( nNonOrthCorr + 1 ):
         pEqn = ref.fvm.ddt( psi, p ) + ref.fvm.div( phid, p ) - ref.fvm.laplacian( rho * rAU, p )
         
         pEqn.solve()
         pass

     if nonOrth == nNonOrthCorr:
         phi<<  pEqn.flux()
         pass
         
     ref.rhoEqn( rho, phi )
  
     cumulativeContErr = ref.compressibleContinuityErrs( rho(), thermo, cumulativeContErr ) #it is necessary to force "mixed calculations" implementation

     U -= rAU * ref.fvc.grad( p )
     U.correctBoundaryConditions()
      
     return cumulativeContErr
Esempio n. 4
0
def fun_pEqn( mesh, runTime, simple, thermo, rho, p, h, psi, U, phi, turbulence, \
                      gh, ghf, p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr, initialMass):

    rho << thermo.rho()
    rho.relax()

    rAU = 1.0 / UEqn.A()
    rhorAUf = ref.surfaceScalarField(ref.word("(rho*(1|A(U)))"),
                                     ref.fvc.interpolate(rho() * rAU))

    U << rAU * UEqn.H()

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

    closedVolume = ref.adjustPhi(phi, U, p_rgh)

    buoyancyPhi = rhorAUf * ghf * ref.fvc.snGrad(rho) * mesh.magSf()
    phi -= buoyancyPhi

    while simple.correctNonOrthogonal():

        p_rghEqn = (ref.fvm.laplacian(rhorAUf, p_rgh) == ref.fvc.div(phi))
        p_rghEqn.setReference(pRefCell, ref.getRefCellValue(p_rgh, pRefCell))
        p_rghEqn.solve()

        if simple.finalNonOrthogonalIter():
            # Calculate the conservative fluxes
            phi -= p_rghEqn.flux()

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

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U -= rAU * ref.fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rhorAUf)
            U.correctBoundaryConditions()
            pass
        pass

    cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh,
                                           cumulativeContErr)

    p << p_rgh + rho * gh

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

    rho << thermo.rho()
    rho.relax()

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

    return cumulativeContErr
Esempio n. 5
0
def _UEqn(mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, pimple):
    muEff = ref.surfaceScalarField(
        ref.word("muEff"), twoPhaseProperties.muf() + ref.fvc.interpolate(rho * turbulence.ext_nut())
    )

    UEqn = (
        ref.fvm.ddt(rho, U)
        + ref.fvm.div(rhoPhi, U)
        - ref.fvm.laplacian(muEff, U)
        - (ref.fvc.grad(U) & ref.fvc.grad(muEff))
    )

    UEqn.relax()

    if pimple.momentumPredictor():
        ref.solve(
            UEqn
            == ref.fvc.reconstruct(
                (
                    ref.fvc.interpolate(interface.sigmaK()) * ref.fvc.snGrad(alpha1)
                    - ghf * ref.fvc.snGrad(rho)
                    - ref.fvc.snGrad(p_rgh)
                )
                * mesh.magSf()
            )
        )
        pass

    return UEqn
Esempio n. 6
0
def fun_pEqn(mesh, runTime, thermo, rho, p, psi, U, phi, turbulence, UEqn,
             cumulativeContErr, nNonOrthCorr):

    rho << thermo.rho()

    rAU = 1.0 / UEqn.A()

    U << rAU * UEqn.H()

    phid = ref.surfaceScalarField(
        ref.word("phid"),
        ref.fvc.interpolate(psi) * ((ref.fvc.interpolate(U) & mesh.Sf()) +
                                    ref.fvc.ddtPhiCorr(rAU, rho, U, phi)))

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

        pEqn.solve()
        pass

    if nonOrth == nNonOrthCorr:
        phi << pEqn.flux()
        pass

    ref.rhoEqn(rho, phi)

    cumulativeContErr = ref.compressibleContinuityErrs(
        rho(), thermo, cumulativeContErr
    )  #it is necessary to force "mixed calculations" implementation

    U -= rAU * ref.fvc.grad(p)
    U.correctBoundaryConditions()

    return cumulativeContErr
def fun_pEqn( mesh, runTime, simple, thermo, rho, p, h, psi, U, phi, turbulence, \
                      gh, ghf, p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr, initialMass):
      
      rho << thermo.rho()
      rho.relax()

      rAU = 1.0 / UEqn.A()
      rhorAUf = ref.surfaceScalarField( ref.word( "(rho*(1|A(U)))" ), ref.fvc.interpolate( rho() * rAU ) )
      
      U << rAU * UEqn.H()
      
      #UEqn.clear()
      
      phi << ref.fvc.interpolate( rho ) * ( ref.fvc.interpolate( U() ) & mesh.Sf() )
      
      closedVolume = ref.adjustPhi( phi, U, p_rgh )
      
      buoyancyPhi = rhorAUf * ghf * ref.fvc.snGrad( rho ) * mesh.magSf()
      
      phi -= buoyancyPhi

      for nonOrth in range( simple.nNonOrthCorr() + 1 ):

          p_rghEqn = ( ref.fvm.laplacian( rhorAUf, p_rgh ) == ref.fvc.div( phi ) )
          
          p_rghEqn.setReference( pRefCell, ref.getRefCellValue( p_rgh, pRefCell ) )
          p_rghEqn.solve()

          if nonOrth == simple.nNonOrthCorr():
              # Calculate the conservative fluxes
              phi -= p_rghEqn.flux()
              
              # Explicitly relax pressure for momentum corrector
              p_rgh.relax()
              
              # Correct the momentum source with the pressure gradient flux
              # calculated from the relaxed pressure
              U -= rAU * ref.fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorAUf )
              U.correctBoundaryConditions()
              pass
          pass
  
      cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
      
      p << p_rgh + rho * gh

      # For closed-volume cases adjust the pressure level
      # to obey overall mass continuity
      if closedVolume:
          p += ( initialMass - ref.fvc.domainIntegrate( psi * p ) ) / ref.fvc.domainIntegrate( psi ) 
          p_rgh << p - rho * gh
          pass
      rho << thermo.rho()
      rho.relax()
      
      ref.ext_Info() << "rho max/min : " <<  rho.ext_max().value() << " " << rho.ext_min().value() << ref.nl
      
      return cumulativeContErr
def fun_pEqn( runTime, mesh, pimple, UEqn, p, p_rgh, phi, U, rho, rho1, rho2, rho10, rho20, gh, ghf, dgdt, pMin, \
              psi1, psi2, alpha1, alpha2, interface, corr ):
    rAU = 1.0 / UEqn.A()

    rAUf = ref.fvc.interpolate(rAU)

    p_rghEqnComp = None

    if pimple.transonic():
        p_rghEqnComp = ref.fvm.ddt(p_rgh) + ref.fvm.div(
            phi, p_rgh) - ref.fvm.Sp(ref.fvc.div(phi), p_rgh)
        pass
    else:
        p_rghEqnComp = ref.fvm.ddt(p_rgh) + ref.fvc.div(
            phi, p_rgh) - ref.fvc.Sp(ref.fvc.div(phi), p_rgh)
        pass

    U << rAU * UEqn.H()

    phiU = ref.surfaceScalarField(ref.word("phiU"),
                                  (ref.fvc.interpolate(U) & mesh.Sf()) +
                                  ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

    phi << (phiU +
            (ref.fvc.interpolate(interface.sigmaK()) * ref.fvc.snGrad(alpha1) -
             ghf * ref.fvc.snGrad(rho)) * rAUf * mesh.magSf())

    for nonOrth in range(pimple.nNonOrthCorr() + 1):
        p_rghEqnIncomp = ref.fvc.div(phi) - ref.fvm.laplacian(rAUf, p_rgh)

        ref.solve(
            (alpha1.ext_max(0.0) * (psi1 / rho1) + alpha2.ext_max(0.0) *
             (psi2 / rho2)) * p_rghEqnComp() + p_rghEqnIncomp,  ##
            mesh.solver(p_rgh.select(pimple.finalInnerIter(corr, nonOrth))))

        if nonOrth == pimple.nNonOrthCorr():
            dgdt << (alpha2.pos() * (psi2 / rho2) - alpha1.pos() *
                     (psi1 / rho1)) * (p_rghEqnComp & p_rgh)
            phi += p_rghEqnIncomp.flux()
            pass

    U += rAU * ref.fvc.reconstruct((phi() - phiU) / rAUf)  # mixed calculations
    U.correctBoundaryConditions()

    p << ((p_rgh() + gh * (alpha1() * rho10 + alpha2 * rho20)) /
          (1.0 - gh * (alpha1() * psi1 + alpha2 * psi2))).ext_max(pMin)  #

    rho1 << rho10 + psi1 * p
    rho2 << rho20 + psi2 * p

    ref.ext_Info() << "max(U) " << U.mag().ext_max().value() << ref.nl
    ref.ext_Info() << "min(p_rgh) " << p_rgh.ext_min().value() << ref.nl
    pass
def fun_pEqn(mesh, runTime, simple, p, rhok, U, phi, turbulence, gh, ghf,
             p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr):

    rAU = ref.volScalarField(ref.word("rAU"), 1.0 / UEqn.A())

    rAUf = ref.surfaceScalarField(ref.word("(1|A(U))"),
                                  ref.fvc.interpolate(rAU))

    U << rAU * UEqn.H()

    phi << (ref.fvc.interpolate(U) & mesh.Sf())

    ref.adjustPhi(phi, U, p_rgh)

    buoyancyPhi = rAUf * ghf() * ref.fvc.snGrad(rhok) * mesh.magSf()
    phi -= buoyancyPhi

    for nonOrth in range(simple.nNonOrthCorr() + 1):
        p_rghEqn = ref.fvm.laplacian(rAUf, p_rgh) == ref.fvc.div(phi)

        p_rghEqn.setReference(pRefCell, ref.getRefCellValue(p_rgh, pRefCell))

        p_rghEqn.solve()

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

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

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U -= rAU * ref.fvc.reconstruct(
                (buoyancyPhi + p_rghEqn.flux()) / rAUf)
            U.correctBoundaryConditions()
            pass
        pass

    cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh,
                                           cumulativeContErr)

    p << p_rgh + rhok * gh

    if p_rgh.needReference():
        p += ref.dimensionedScalar(
            ref.word("p"), p.dimensions(),
            pRefValue - ref.getRefCellValue(p, pRefCell))
        p_rgh << p - rhok * gh
        pass

    return cumulativeContErr
Esempio n. 10
0
def fun_pEqn(
    mesh, runTime, pimple, thermo, rho, p, h, psi, U, phi, turbulence, gh, ghf, p_rgh, UEqn, dpdt, K, cumulativeContErr
):
    rho << thermo.rho()

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

    rAU = 1.0 / UEqn.A()
    rhorAUf = ref.surfaceScalarField(ref.word("(rho*(1|A(U)))"), ref.fvc.interpolate(rho * rAU))

    U << rAU * UEqn.H()

    phi << ref.fvc.interpolate(rho) * ((ref.fvc.interpolate(U) & mesh.Sf()) + ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

    buoyancyPhi = -rhorAUf * ghf * ref.fvc.snGrad(rho) * mesh.magSf()

    phi += buoyancyPhi

    p_rghDDtEqn = ref.fvc.ddt(rho) + psi * ref.correction(ref.fvm.ddt(p_rgh)) + ref.fvc.div(phi)

    while pimple.correctNonOrthogonal():
        p_rghEqn = p_rghDDtEqn - ref.fvm.laplacian(rhorAUf, p_rgh)

        p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter())))

        if pimple.finalNonOrthogonalIter():
            # Calculate the conservative fluxes
            phi += p_rghEqn.flux()
            # Explicitly relax pressure for momentum corrector
            p_rgh.relax()

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U += rAU * ref.fvc.reconstruct((buoyancyPhi + p_rghEqn.flux()) / rhorAUf)
            U.correctBoundaryConditions()
            K << 0.5 * U.magSqr()
            pass
        pass

    p << p_rgh + rho * gh

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

    dpdt << ref.fvc.ddt(p)  # mixed calculations

    ref.rhoEqn(rho, phi)
    cumulativeContErr = ref.compressibleContinuityErrs(rho(), thermo, cumulativeContErr)  # mixed calculations

    return cumulativeContErr
def setrDeltaT( runTime, mesh, pimple, phi, psi, U, rho, rDeltaT, maxDeltaT ):
    pimpleDict = pimple.dict()

    maxCo = pimpleDict.lookupOrDefault( ref.word( "maxCo" ), ref.scalar( 0.8 ) ) 
    rDeltaTSmoothingCoeff = pimpleDict.lookupOrDefault( ref.word( "rDeltaTSmoothingCoeff" ) , ref.scalar( 0.02 ) )
    rDeltaTDampingCoeff = pimpleDict.lookupOrDefault( ref.word( "rDeltaTDampingCoeff" ), ref.scalar( 1.0 ) )

    maxDeltaT = pimpleDict.lookupOrDefault( ref.word( "maxDeltaT" ), ref.GREAT )

    rDeltaT0 = ref.volScalarField( ref.word( "rDeltaT0" ), rDeltaT )

    # Set the reciprocal time-step from the local Courant number
    tmp = ref.fvc.surfaceSum( phi.mag() )
    tmp1= ( tmp.dimensionedInternalField() / ( ( 2 * maxCo ) * mesh.V() * rho.dimensionedInternalField() ) )
    print tmp1

    rDeltaT.dimensionedInternalField() << tmp1().max( 1.0 / ref.dimensionedScalar( ref.word( "maxDeltaT" ), ref.dimTime, maxDeltaT ) )
    

    if pimple.transonic():
        phid = ref.surfaceScalarField( ref.word( "phid" ),
                                       ref.fvc.interpolate( psi ) * ( ref.fvc.interpolate( U ) & mesh.Sf() ) )

        rDeltaT.dimensionedInternalField() << rDeltaT.dimensionedInternalField().max( ref.fvc.surfaceSum( phid.mag() ).dimensionedInternalField() / 
                                                                                      ( ( 2 * maxCo ) * mesh.V() * psi.dimensionedInternalField() ) )
        pass

    # Update tho boundary values of the reciprocal time-step
    rDeltaT.correctBoundaryConditions()

    ref.ext_Info() << "Flow time scale min/max = " << ( 1 / rDeltaT.internalField() ).gMin() << ", " << ( 1 / rDeltaT.internalField() ).gMax() << ref.nl

    if rDeltaTSmoothingCoeff < 1.0:
        ref.fvc.smooth( rDeltaT, rDeltaTSmoothingCoeff )
        pass

    ref.ext_Info() << "Smoothed flow time scale min/max = " << ( 1 / rDeltaT.internalField() ).gMin() << ", " << ( 1 / rDeltaT.internalField() ).gMax() << ref.nl

    # Limit rate of change of time scale
    # - reduce as much as required
    # - only increase at a fraction of old time scale
    if rDeltaTDampingCoeff < 1.0 and runTime.timeIndex() > ( runTime.startTimeIndex() + 1 ) :
        rDeltaT = rDeltaT0 * ( rDeltaT / rDeltaT0 ).max( ref.scalar( 1.0 ) - rDeltaTDampingCoeff )

        Info<< "Damped flow time scale min/max = " << ( 1 / rDeltaT.internalField() ).gMin() << ", " << ( 1 / rDeltaT.internalField() ).gMax() << ref.nl
        pass
    pass
def fun_pEqn( mesh, runTime, simple, p, rhok, U, phi, turbulence, gh, ghf, p_rgh, UEqn, pRefCell, pRefValue, cumulativeContErr ):

  rAU = ref.volScalarField( ref.word( "rAU" ), 1.0 / UEqn.A() )
  
  rAUf = ref.surfaceScalarField( ref.word( "(1|A(U))" ), ref.fvc.interpolate( rAU ) )

  U << rAU * UEqn.H()

  phi << ( ref.fvc.interpolate( U ) & mesh.Sf() )

  ref.adjustPhi( phi, U, p_rgh );

  buoyancyPhi = rAUf * ghf() * ref.fvc.snGrad( rhok ) * mesh.magSf()
  phi -= buoyancyPhi

  while simple.correctNonOrthogonal():
    p_rghEqn = ref.fvm.laplacian( rAUf, p_rgh ) == ref.fvc.div( phi )

    p_rghEqn.setReference( pRefCell, ref.getRefCellValue( p_rgh, pRefCell ) )
    
    p_rghEqn.solve()

    if simple.finalNonOrthogonalIter():
      # Calculate the conservative fluxes
      phi -= p_rghEqn.flux()
      
      # Explicitly relax pressure for momentum corrector
      p_rgh.relax()

      # Correct the momentum source with the pressure gradient flux
      # calculated from the relaxed pressure
      U -= rAU * ref.fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rAUf )
      U.correctBoundaryConditions()
      pass
    pass

  cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )

  p << p_rgh + rhok * gh

  if p_rgh.needReference():
    p += ref.dimensionedScalar( ref.word( "p" ), p.dimensions(), pRefValue - ref.getRefCellValue( p, pRefCell ) )
    p_rgh << p - rhok * gh
    pass
  
  return cumulativeContErr
Esempio n. 13
0
def _pEqn(runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g,
          interface, corr, pimple, pRefCell, pRefValue, cumulativeContErr):
    rAU = 1.0 / UEqn.A()

    rAUf = ref.fvc.interpolate(rAU)

    U << rAU * UEqn.H()

    phiU = ref.surfaceScalarField(ref.word("phiU"),
                                  (ref.fvc.interpolate(U) & mesh.Sf()) +
                                  ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

    ref.adjustPhi(phiU, U, p)

    phi << (phiU +
            (ref.fvc.interpolate(interface.sigmaK()) * ref.fvc.snGrad(alpha1) -
             ghf * ref.fvc.snGrad(rho)) * rAUf * mesh.magSf())

    for nonOrth in range(pimple.nNonOrthCorr() + 1):
        p_rghEqn = ref.fvm.laplacian(rAUf, p_rgh) == ref.fvc.div(phi)
        p_rghEqn.setReference(pRefCell, pRefValue)

        p_rghEqn.solve(
            mesh.solver(p_rgh.select(pimple.finalInnerIter(corr, nonOrth))))

        if nonOrth == pimple.nNonOrthCorr():
            phi -= p_rghEqn.flux()
            pass
        pass

    U += rAU * ref.fvc.reconstruct((phi() - phiU) / rAUf)  # mixed calculations
    U.correctBoundaryConditions()

    cumulativeContErr = ref.ContinuityErrs(phi, runTime, mesh,
                                           cumulativeContErr)

    p == p_rgh + rho * gh

    if p_rgh.needReference():
        p += ref.dimensionedScalar(
            ref.word("p"), p.dimensions(),
            pRefValue - ref.getRefCellValue(p, pRefCell))
        p_rgh << p - rho * gh
        pass
    return cumulativeContErr
Esempio n. 14
0
def fun_pEqn( runTime, mesh, pimple, UEqn, p, p_rgh, phi, U, rho, rho1, rho2, rho10, rho20, gh, ghf, dgdt, pMin, \
              psi1, psi2, alpha1, alpha2, interface ):
    rAU = 1.0/UEqn.A()
    
    rAUf = ref.fvc.interpolate( rAU )

    p_rghEqnComp = None

    if pimple.transonic():
        p_rghEqnComp = ref.fvm.ddt( p_rgh ) + ref.fvm.div( phi, p_rgh ) - ref.fvm.Sp( ref.fvc.div( phi ), p_rgh )
        pass
    else:
        p_rghEqnComp = ref.fvm.ddt( p_rgh ) + ref.fvc.div( phi, p_rgh ) - ref.fvc.Sp( ref.fvc.div( phi ), p_rgh ) 
        pass

    U << rAU * UEqn.H()

    phiU = ref.surfaceScalarField( ref.word( "phiU" ),
                                   ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )

    phi << (phiU + ( ref.fvc.interpolate( interface.sigmaK() ) * ref.fvc.snGrad( alpha1 ) - ghf * ref.fvc.snGrad( rho ) ) * rAUf * mesh.magSf() )

    while (pimple.correctNonOrthogonal()):
        p_rghEqnIncomp = ref.fvc.div( phi ) - ref.fvm.laplacian( rAUf, p_rgh ) 
        
        ref.solve( ( alpha1.ext_max( 0.0 ) * ( psi1 / rho1 ) + alpha2.ext_max( 0.0 ) * ( psi2 / rho2 ) ) *p_rghEqnComp() + p_rghEqnIncomp,   ##
               mesh.solver( p_rgh.select( pimple.finalInnerIter() ) ) )

        if pimple.finalNonOrthogonalIter():
            dgdt << ( alpha2.pos() * ( psi2 / rho2 ) - alpha1.pos() * ( psi1 / rho1 ) ) * ( p_rghEqnComp & p_rgh )
            phi += p_rghEqnIncomp.flux()
            pass

    U += rAU * ref.fvc.reconstruct( ( phi() - phiU ) / rAUf ) # mixed calculations
    U.correctBoundaryConditions()

    p << ( ( p_rgh() + gh * ( alpha1() * rho10 + alpha2 * rho20 ) ) /( 1.0 - gh * ( alpha1() * psi1 + alpha2 * psi2 ) ) ).ext_max( pMin ) #

    rho1 << rho10 + psi1 * p
    rho2 << rho20 + psi2 * p

    ref.ext_Info() << "max(U) " << U.mag().ext_max().value() << ref.nl
    ref.ext_Info() << "min(p_rgh) " << p_rgh.ext_min().value() << ref.nl
    pass
Esempio n. 15
0
def _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, pimple, pRefCell, pRefValue, cumulativeContErr ):
    rAU = 1.0 / UEqn.A()
    rAUf = ref.fvc.interpolate( rAU )

    U << rAU * UEqn.H()
    phiU = ref.surfaceScalarField( ref.word( "phiU" ), ( ref.fvc.interpolate( U ) & mesh.Sf() ) );

    if p_rgh.needReference():
        ref.fvc.makeRelative( phiU, U )
        ref.adjustPhi( phiU, U, p_rgh )
        ref.fvc.makeAbsolute( phiU, U )
        pass
    phi << phiU + ( ref.fvc.interpolate( interface.sigmaK() ) * ref.fvc.snGrad( alpha1 ) - ghf * ref.fvc.snGrad( rho ) ) * rAUf * mesh.magSf()

    for nonOrth in range( pimple.nNonOrthCorr() + 1 ):
        p_rghEqn = ( ref.fvm.laplacian( rAUf, p_rgh ) == ref.fvc.div( phi ) )

        p_rghEqn.setReference( pRefCell, ref.getRefCellValue( p_rgh, pRefCell ) )

        p_rghEqn.solve( mesh.solver( p_rgh.select( pimple.finalInnerIter( corr, nonOrth ) ) ) )
        
        if nonOrth == pimple.nNonOrthCorr():
            phi -= p_rghEqn.flux()
            pass
        pass

    U += rAU * ref.fvc.reconstruct( ( phi() - phiU ) / rAUf ) # mixed calculations
    U.correctBoundaryConditions()

    cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )

    # Make the fluxes relative to the mesh motion
    ref.fvc.makeRelative( phi, U )

    p == p_rgh + rho * gh

    if p_rgh.needReference():
        p += ref.dimensionedScalar( ref.word( "p" ),
                                    p.dimensions(),
                                    pRefValue - ref.getRefCellValue( p, pRefCell ) );
        p_rgh << p - rho * gh
        pass
    
    return cumulativeContErr
Esempio n. 16
0
def fun_UEqn(mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g,
             twoPhaseProperties, interface, pimple):
    muEff = ref.surfaceScalarField(
        ref.word("muEff"),
        twoPhaseProperties.muf() +
        ref.fvc.interpolate(rho * turbulence.ext_nut()))

    UEqn = ref.fvm.ddt(rho, U) + ref.fvm.div(rhoPhi, U) - ref.fvm.laplacian(
        muEff, U) - (ref.fvc.grad(U) & ref.fvc.grad(muEff))

    UEqn.relax()

    if pimple.momentumPredictor():
        ref.solve( UEqn == \
                    ref.fvc.reconstruct( ( ref.fvc.interpolate( interface.sigmaK() ) * ref.fvc.snGrad( alpha1 ) - ghf * ref.fvc.snGrad( rho ) \
                                                                                                  - ref.fvc.snGrad( p_rgh ) ) * mesh.magSf() ) )
        pass

    return UEqn
Esempio n. 17
0
def alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ):
    alphaScheme = ref.word( "div(phi,alpha)" )
    alpharScheme = ref.word( "div(phirb,alpha)" )
    
    phic = ref.surfaceScalarField( ( phi() / mesh.magSf() ).mag() ) # mixed calculations
    phic << ( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    phir = phic * interface.nHatf()
    

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

       pass
    ref.ext_Info() << "Phase-1 volume fraction = " << alpha1.weightedAverage( mesh.ext_Vsc() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() \
               << "  Max(alpha1) = " << alpha1.ext_max().value() << ref.nl
    pass
Esempio n. 18
0
def fun_pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, rho, pimple, pRefCell, pRefValue, cumulativeContErr ):
    rAU = 1.0/UEqn.A()
     
    rAUf = ref.fvc.interpolate( rAU )
    
    U << rAU * UEqn.H()

    phiU = ref.surfaceScalarField( ref.word( "phiU" ),
                                   ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho, U, phi ) )
                               
    ref.adjustPhi( phiU, U, p )
    
    phi << phiU - ghf * ref.fvc.snGrad( rho ) * rAUf * mesh.magSf()

    while pimple.correctNonOrthogonal():
        p_rghEqn = ref.fvm.laplacian( rAUf, p_rgh ) == ref.fvc.div( phi ) 
        p_rghEqn.setReference(pRefCell, ref.getRefCellValue( p_rgh, pRefCell ) )

        p_rghEqn.solve( mesh.solver( p_rgh.select( pimple.finalInnerIter() ) ) )
        
        if pimple.finalNonOrthogonalIter():
           phi -= p_rghEqn.flux()
           pass
        pass
    
    U += rAU * ref.fvc.reconstruct( ( phi() - phiU ) / rAUf ) # mixed calculations
    U.correctBoundaryConditions()

    cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    p == p_rgh + rho * gh

    if p_rgh.needReference():
       p += ref.dimensionedScalar( ref.word( "p" ),
                                   p.dimensions(),
                                   pRefValue - ref.getRefCellValue( p, pRefCell ) )
       p_rgh << p - rho * gh
       pass
    
    return cumulativeContErr
Esempio n. 19
0
def setrDeltaT(runTime, mesh, pimple, phi, psi, U, rho, rDeltaT, maxDeltaT):
    pimpleDict = pimple.dict()

    maxCo = pimpleDict.lookupOrDefault(ref.word("maxCo"), ref.scalar(0.8))
    rDeltaTSmoothingCoeff = pimpleDict.lookupOrDefault(
        ref.word("rDeltaTSmoothingCoeff"), ref.scalar(0.02))
    rDeltaTDampingCoeff = pimpleDict.lookupOrDefault(
        ref.word("rDeltaTDampingCoeff"), ref.scalar(1.0))

    maxDeltaT = pimpleDict.lookupOrDefault(ref.word("maxDeltaT"), ref.GREAT)

    rDeltaT0 = ref.volScalarField(ref.word("rDeltaT0"), rDeltaT)

    # Set the reciprocal time-step from the local Courant number
    tmp = ref.fvc.surfaceSum(phi.mag())
    tmp1 = (tmp.dimensionedInternalField() /
            ((2 * maxCo) * mesh.V() * rho.dimensionedInternalField()))
    print tmp1

    rDeltaT.dimensionedInternalField() << tmp1().max(
        1.0 /
        ref.dimensionedScalar(ref.word("maxDeltaT"), ref.dimTime, maxDeltaT))

    if pimple.transonic():
        phid = ref.surfaceScalarField(
            ref.word("phid"),
            ref.fvc.interpolate(psi) * (ref.fvc.interpolate(U) & mesh.Sf()))

        rDeltaT.dimensionedInternalField() << rDeltaT.dimensionedInternalField(
        ).max(
            ref.fvc.surfaceSum(phid.mag()).dimensionedInternalField() /
            ((2 * maxCo) * mesh.V() * psi.dimensionedInternalField()))
        pass

    # Update tho boundary values of the reciprocal time-step
    rDeltaT.correctBoundaryConditions()

    ref.ext_Info() << "Flow time scale min/max = " << (
        1 / rDeltaT.internalField()).gMin() << ", " << (
            1 / rDeltaT.internalField()).gMax() << ref.nl

    if rDeltaTSmoothingCoeff < 1.0:
        ref.fvc.smooth(rDeltaT, rDeltaTSmoothingCoeff)
        pass

    ref.ext_Info() << "Smoothed flow time scale min/max = " << (
        1 / rDeltaT.internalField()).gMin() << ", " << (
            1 / rDeltaT.internalField()).gMax() << ref.nl

    # Limit rate of change of time scale
    # - reduce as much as required
    # - only increase at a fraction of old time scale
    if rDeltaTDampingCoeff < 1.0 and runTime.timeIndex() > (
            runTime.startTimeIndex() + 1):
        rDeltaT = rDeltaT0 * (
            rDeltaT / rDeltaT0).max(ref.scalar(1.0) - rDeltaTDampingCoeff)

        Info << "Damped flow time scale min/max = " << (
            1 / rDeltaT.internalField()).gMin() << ", " << (
                1 / rDeltaT.internalField()).gMax() << ref.nl
        pass
    pass
Esempio n. 20
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration(runTime, mesh)

    h, h0, U, hU, hTotal, phi, F = _createFields(runTime, mesh, Omega, gHat)

    pimple = man.pimpleControl(mesh)

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.loop():
        ref.ext_Info() << "\n Time = " << runTime.timeName() << ref.nl << ref.nl

        CourantNo(runTime, mesh, h, phi, magg)

        pimple.start()
        while pimple.loop():

            phiv = ref.surfaceScalarField(ref.word("phiv"), phi() / ref.fvc.interpolate(h))  # mixed calculations

            hUEqn = ref.fvm.ddt(hU) + ref.fvm.div(phiv, hU)

            hUEqn.relax()

            if pimple.momentumPredictor():

                if rotating:
                    ref.solve(hUEqn + (F ^ hU) == -magg * h * ref.fvc.grad(h + h0))
                    pass
                else:
                    ref.solve(hUEqn == -magg * h * ref.fvc.grad(h + h0))
                    pass

                # Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU -= (gHat & hU) * gHat
                    hU.correctBoundaryConditions()
                    pass

            for corr in range(pimple.nCorr()):
                hf = ref.fvc.interpolate(h)
                rUA = 1.0 / hUEqn.A()
                ghrUAf = magg * ref.fvc.interpolate(h * rUA)

                phih0 = ghrUAf * mesh.magSf() * ref.fvc.snGrad(h0)
                if rotating:
                    hU << rUA * (hUEqn.H() - (F ^ hU))
                    pass
                else:
                    hU << rUA * hUEqn.H()
                    pass

                phi << (ref.fvc.interpolate(hU) & mesh.Sf()) + ref.fvc.ddtPhiCorr(rUA, h, hU, phi) - phih0

                for nonOrth in range(pimple.nNonOrthCorr() + 1):
                    hEqn = ref.fvm.ddt(h) + ref.fvc.div(phi) - ref.fvm.laplacian(ghrUAf, h)

                    hEqn.solve(mesh.solver(h.select(pimple.finalInnerIter(corr, nonOrth))))

                    if nonOrth == pimple.nNonOrthCorr():
                        phi += hEqn.flux()
                    pass

                hU -= rUA * h * magg * ref.fvc.grad(h + h0)

                # Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU -= (gHat & hU) * gHat
                    pass

                hU.correctBoundaryConditions()
                pass

            pimple.increment()
            pass

        U == hU / h
        hTotal == h + h0

        runTime.write()

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

        pass

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

    import os

    return os.EX_OK
Esempio n. 21
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()
    
    compressibility = ref.fvc.domainIntegrate( psi )
    
    compressible = ( compressibility.value() > ref.SMALL )

    rho << thermo.rho()
    
    rUA = 1.0 / UEqn.A()
    
    rhorUAf = ref.surfaceScalarField( ref.word( "(rho*(1|A(U)))" ) , ref.fvc.interpolate( rho * rUA ) )

    U << rUA * UEqn.H() 

    phiU = ( ref.fvc.interpolate( rho ) *
                 (  ( ref.fvc.interpolate( U ) & mesh.Sf() ) +
                      ref.fvc.ddtPhiCorr( rUA, rho, U, phi ) ) )
    phi << phiU - rhorUAf * ghf * ref.fvc.snGrad( rho ) * mesh.magSf()

    p_rghDDtEqn = ref.fvc.ddt( rho ) + psi * ref.correction( ref.fvm.ddt( p_rgh ) ) + ref.fvc.div( phi )
    
    # Thermodynamic density needs to be updated by psi*d(p) after the
    # pressure solution - done in 2 parts. Part 1:
    thermo.rho() << thermo.rho() - psi * p_rgh

    for nonOrth in range ( nNonOrthCorr + 1 ):
        p_rghEqn = p_rghDDtEqn - ref.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 += p_rghEqn.flux()
           pass
        pass
    
    # Second part of thermodynamic density update
    thermo.rho() << thermo.rho() + psi * p_rgh
    
    # Correct velocity field
    U += rUA * ref.fvc.reconstruct( ( phi() - phiU ) / rhorUAf ) # mixed calculations
    U.correctBoundaryConditions()
    
    p << p_rgh + rho * gh

    #Update pressure substantive derivative
    DpDt << ref.fvc.DDt( ref.surfaceScalarField( ref.word( "phiU" ), phi() / ref.fvc.interpolate( rho ) ), p ) # mixed calculations
    
    # Solve continuity
    ref.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 and compressible:
       p += ( initialMass - ref.fvc.domainIntegrate( thermo.rho() ) ) / compressibility
       rho << thermo.rho()
       p_rgh << p - rho * gh()
       pass
    #Update thermal conductivity
    K << thermoFluid[ i ].Cp() * turb.alphaEff()
        
    return cumulativeContErr
Esempio n. 22
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. 23
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()

    compressibility = ref.fvc.domainIntegrate(psi)

    compressible = (compressibility.value() > ref.SMALL)

    rho << thermo.rho()

    rUA = 1.0 / UEqn.A()

    rhorUAf = ref.surfaceScalarField(ref.word("(rho*(1|A(U)))"),
                                     ref.fvc.interpolate(rho * rUA))

    U << rUA * UEqn.H()

    phiU = (ref.fvc.interpolate(rho) * ((ref.fvc.interpolate(U) & mesh.Sf()) +
                                        ref.fvc.ddtPhiCorr(rUA, rho, U, phi)))
    phi << phiU - rhorUAf * ghf * ref.fvc.snGrad(rho) * mesh.magSf()

    p_rghDDtEqn = ref.fvc.ddt(rho) + psi * ref.correction(
        ref.fvm.ddt(p_rgh)) + ref.fvc.div(phi)

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

    for nonOrth in range(nNonOrthCorr + 1):
        p_rghEqn = p_rghDDtEqn - ref.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 += p_rghEqn.flux()
            pass
        pass

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

    # Correct velocity field
    U += rUA * ref.fvc.reconstruct(
        (phi() - phiU) / rhorUAf)  # mixed calculations
    U.correctBoundaryConditions()

    p << p_rgh + rho * gh

    #Update pressure substantive derivative
    DpDt << ref.fvc.DDt(
        ref.surfaceScalarField(ref.word("phiU"),
                               phi() / ref.fvc.interpolate(rho)),
        p)  # mixed calculations

    # Solve continuity
    ref.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 and compressible:
        p += (initialMass -
              ref.fvc.domainIntegrate(thermo.rho())) / compressibility
        rho << thermo.rho()
        p_rgh << p - rho * gh()
        pass
    #Update thermal conductivity
    K << thermoFluid[i].Cp() * turb.alphaEff()

    return cumulativeContErr
Esempio n. 24
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createDynamicFvMesh(runTime)

    cumulativeContErr = ref.initContinuityErrs()

    p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, pRefValue, interface, turbulence, g, gh, ghf = _createFields(
        runTime, mesh
    )

    adjustTimeStep, maxCo, maxDeltaT = ref.readTimeControls(runTime)

    pimple = man.pimpleControl(mesh)

    phiAbs = ref.surfaceScalarField(ref.word("phiAbs"), phi)
    ref.fvc.makeAbsolute(phiAbs, U)

    cumulativeContErr = fun_correctPhi(
        runTime, mesh, phi, phiAbs, p, p_rgh, rho, U, cumulativeContErr, pimple, pRefCell, pRefValue
    )

    CoNum, meanCoNum = ref.CourantNo(mesh, phi, runTime)

    runTime = ref.setInitialDeltaT(runTime, adjustTimeStep, maxCo, CoNum)

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.run():

        adjustTimeStep, maxCo, maxDeltaT, correctPhi, checkMeshCourantNo = readControls(runTime, mesh, pimple)

        maxAlphaCo, alphaCoNum, meanAlphaCoNum = alphaCourantNo(runTime, mesh, alpha1, phi)

        CoNum, meanCoNum = ref.CourantNo(mesh, phi, runTime)

        runTime = setDeltaT(runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT)

        runTime.increment()
        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl

        timeBeforeMeshUpdate = runTime.elapsedCpuTime()

        fun_Urel(mesh, U)

        if mesh.changing():
            ref.ext_Info() << "Execution time for mesh.update() = " << runTime.elapsedCpuTime() - timeBeforeMeshUpdate << " s" << ref.nl
            gh << (g & mesh.C())
            ghf << (g & mesh.Cf())
            pass

        if mesh.changing() and correctPhi:
            cumulativeContErr = fun_correctPhi(
                runTime, mesh(), phi, phiAbs, p, p_rgh, rho, U, cumulativeContErr, pimple, pRefCell, pRefValue
            )
            pass

        if mesh.changing() and checkMeshCourantNo:
            meshCoNum, meanMeshCoNum = ref.meshCourantNo(runTime, mesh(), phi)
            pass

        twoPhaseProperties.correct()

        alphaEqnSubCycle(runTime, pimple, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface)

        # --- Pressure-velocity PIMPLE corrector loop
        while pimple.loop():
            UEqn = _UEqn(
                mesh(), alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, pimple
            )

            # --- PISO loop
            while pimple.correct():
                cumulativeContErr = _pEqn(
                    runTime,
                    mesh,
                    UEqn,
                    U,
                    p,
                    p_rgh,
                    gh,
                    ghf,
                    phi,
                    phiAbs,
                    alpha1,
                    rho,
                    g,
                    interface,
                    pimple,
                    pRefCell,
                    pRefValue,
                    cumulativeContErr,
                )
                pass
            if pimple.turbCorr():
                turbulence.correct()
                pass
            pass

        runTime.write()

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

        pass

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

    import os

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

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    gravitationalProperties, g, rotating, Omega, magg, gHat = readGravitationalAcceleration(
        runTime, mesh)

    h, h0, U, hU, hTotal, phi, F = _createFields(runTime, mesh, Omega, gHat)

    pimple = man.pimpleControl(mesh)

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.loop():
        ref.ext_Info() << "\n Time = " << runTime.timeName(
        ) << ref.nl << ref.nl

        CourantNo(runTime, mesh, h, phi, magg)

        pimple.start()
        while pimple.loop():

            phiv = ref.surfaceScalarField(
                ref.word("phiv"),
                phi() / ref.fvc.interpolate(h))  # mixed calculations

            hUEqn = ref.fvm.ddt(hU) + ref.fvm.div(phiv, hU)

            hUEqn.relax()

            if pimple.momentumPredictor():

                if rotating:
                    ref.solve(hUEqn + (F ^ hU) == -magg * h *
                              ref.fvc.grad(h + h0))
                    pass
                else:
                    ref.solve(hUEqn == -magg * h * ref.fvc.grad(h + h0))
                    pass

                # Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU -= (gHat & hU) * gHat
                    hU.correctBoundaryConditions()
                    pass

            for corr in range(pimple.nCorr()):
                hf = ref.fvc.interpolate(h)
                rUA = 1.0 / hUEqn.A()
                ghrUAf = magg * ref.fvc.interpolate(h * rUA)

                phih0 = ghrUAf * mesh.magSf() * ref.fvc.snGrad(h0)
                if rotating:
                    hU << rUA * (hUEqn.H() - (F ^ hU))
                    pass
                else:
                    hU << rUA * hUEqn.H()
                    pass

                phi << (ref.fvc.interpolate(hU) & mesh.Sf()
                        ) + ref.fvc.ddtPhiCorr(rUA, h, hU, phi) - phih0

                for nonOrth in range(pimple.nNonOrthCorr() + 1):
                    hEqn = ref.fvm.ddt(h) + ref.fvc.div(
                        phi) - ref.fvm.laplacian(ghrUAf, h)

                    hEqn.solve(
                        mesh.solver(
                            h.select(pimple.finalInnerIter(corr, nonOrth))))

                    if nonOrth == pimple.nNonOrthCorr():
                        phi += hEqn.flux()
                    pass

                hU -= rUA * h * magg * ref.fvc.grad(h + h0)

                #Constrain the momentum to be in the geometry if 3D geometry
                if mesh.nGeometricD() == 3:
                    hU -= (gHat & hU) * gHat
                    pass

                hU.correctBoundaryConditions()
                pass

            pimple.increment()
            pass

        U == hU / h
        hTotal == h + h0

        runTime.write()

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

        pass

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

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

    args = ref.setRootCase( argc, argv )
   
    runTime = man.createTime( args )
    
    mesh = man.createMesh( runTime )
  
    thermodynamicProperties, rho0, p0, psi, rhoO =  readThermodynamicProperties( runTime, mesh )
    
    transportProperties, mu = readTransportProperties( runTime, mesh )
    
    p, U, rho, phi = createFields( runTime, mesh, rhoO, psi )
  
    cumulativeContErr = ref.initContinuityErrs()
  
    #// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    ref.ext_Info()<< "\nStarting time loop\n" << ref.nl

    while runTime.loop():
 
        ref.ext_Info()<< "Time = " << runTime.timeName() << ref.nl << ref.nl
       
        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = ref.readPISOControls( mesh )

        CoNum, meanCoNum = ref.compressibleCourantNo( mesh, phi, rho, runTime )

        ref.rhoEqn( rho, phi )

        UEqn = man.fvm.ddt( rho, U ) + man.fvm.div( phi, U ) - man.fvm.laplacian( mu, U )
        
        ref.solve( UEqn == -man.fvc.grad( p ) )

        # --- PISO loop
        for corr in range( nCorr ):
               
            rAU = 1.0 / UEqn.A()
            U << rAU * UEqn.H()

            phid = ref.surfaceScalarField( ref.word( "phid" ), 
                                           psi * ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) + ref.fvc.ddtPhiCorr( rAU, rho(), U(), phi() ) ) )

            phi << ( rhoO / psi ) * phid
            pEqn = ref.fvm.ddt( psi, p() ) + ref.fvc.div( phi() ) + ref.fvm.div( phid, p() ) - ref.fvm.laplacian( rho() * rAU, p() )
 
            pEqn.solve()

            phi += pEqn.flux()
        
            cumulativeContErr = compressibleContinuityErrs( rho, phi,p, rho0, p0, psi, cumulativeContErr )
        
            U -= rAU * ref.fvc.grad( p )
            U.correctBoundaryConditions()
            pass
        rho << rhoO + psi * p

        runTime.write()

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

    ref.ext_Info()<< "End\n" << ref.nl
    
    import os
    return os.EX_OK
Esempio n. 27
0
def _pEqn( runTime,mesh, UEqn, rho, thermo, psi, U, p, phi, \
           pRefCell, pRefValue, cumulativeContErr, simple, rhoMin, rhoMax  ):
   
    rho << thermo.rho()
    rho << rho.ext_max( rhoMin )
    rho << rho.ext_min( rhoMax )
    rho.relax()

    p0 = ref.volScalarField(p)
    
    AU = ref.volScalarField( UEqn.A() )
    AtU = AU - UEqn.H1()
    U << UEqn.H() / AU
    
    # UEqn.clear()
    
    closedVolume = False
    
    if simple.transonic(): 
       while simple.correctNonOrthogonal():
           phid = ref.surfaceScalarField( ref.word( "phid" ),
                                          ref.fvc.interpolate( psi * U ) & mesh.Sf() )

           phic = ref.surfaceScalarField( ref.word( "phic" ),
                                          ref.fvc.interpolate( rho() / AtU - rho() / AU ) * ref.fvc.snGrad( p ) * mesh.magSf() + \
                                          phid * ( ref.fvc.interpolate( p ) - ref.fvc.interpolate( p, ref.word( "UD" ) ) ) ) # mixed calcutions

           #refCast<mixedFvPatchScalarField>(p.boundaryField()[1]).refValue()
           #    = p.boundaryField()[1];
           
           pEqn = ref.fvm.div( phid, p ) + ref.fvc.div( phic ) - ref.fvm.Sp( ref.fvc.div( phid ), p ) + \
                  ref.fvc.div( phid ) * p - ref.fvm.laplacian( rho() / AtU, p ) # mixed calcutions
           # pEqn.relax();

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

           if simple.finalNonOrthogonalIter():
               phi == phic + pEqn.flux()
               pass
           pass
    else:
        
        while simple.correctNonOrthogonal():
            phi << ( ref.fvc.interpolate( rho * U ) & mesh.Sf() )
            closedVolume = ref.adjustPhi( phi, U, p )
            
            phi += ref.fvc.interpolate( rho / AtU - rho / AU ) * ref.fvc.snGrad( p ) * mesh.magSf()
            pEqn = ref.fvc.div( phi ) - ref.fvm.laplacian( rho / AtU, p )
            pEqn.setReference( pRefCell, pRefValue )
            
            pEqn.solve()
            if simple.finalNonOrthogonalIter():
                phi += pEqn.flux()
                pass
            pass
            
    # The incompressibe for of the continuity error check is appropriate for
    # steady-state compressible also.
    cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )
    
    # Explicitly relax pressure for momentum corrector
    p.relax()
    
    U -= ( ref.fvc.grad( p0 ) * ( 1.0 / AU - 1.0 / AtU ) + ref.fvc.grad( p ) / AtU )
    # U -= fvc::grad(p)/AU;
    
    U.correctBoundaryConditions()
    
    # For closed-volume cases adjust the pressure and density levels
    # to obey overall mass continuity
    if closedVolume:
        p += ( initialMass - ref.fvc.domainIntegrate( psi * p ) ) / ref.fvc.domainIntegrate( psi )
        pass
    
    rho << thermo.rho()
    rho << rho.ext_max( rhoMin )
    rho << rho.ext_min( rhoMax )
    
    if not simple.transonic():
        rho.relax()
        pass

    ref.ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << ref.nl
    
    pass
    
    return cumulativeContErr
Esempio n. 28
0
def fun_pEqn(
    mesh,
    runTime,
    pimple,
    thermo,
    rho,
    p,
    h,
    psi,
    U,
    phi,
    turbulence,
    UEqn,
    rAU,
    dpdt,
    K,
    cumulativeContErr,
    rhoMax,
    rhoMin,
):

    rho << thermo.rho()
    rho << rho().ext_max(rhoMin)
    rho << rho().ext_min(rhoMax)
    rho.relax()

    U << rAU() * UEqn.H()

    if pimple.transonic():
        phid = ref.surfaceScalarField(
            ref.word("phid"),
            ref.fvc.interpolate(psi) * ((ref.fvc.interpolate(U) & mesh.Sf()) + ref.fvc.ddtPhiCorr(rAU, rho, U, phi)),
        )
        while pimple.correctNonOrthogonal():
            pEqn = ref.fvm.ddt(psi, p) + ref.fvm.div(phid, p) - ref.fvm.laplacian(rho() * rAU, p)  # mixed calculations

            pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())))

            if pimple.finalNonOrthogonalIter():
                phi == pEqn.flux()
                pass
            pass
        pass
    else:
        phi << ref.fvc.interpolate(rho) * ((ref.fvc.interpolate(U) & mesh.Sf()) + ref.fvc.ddtPhiCorr(rAU, rho, U, phi))

        while pimple.correctNonOrthogonal():
            pEqn = ref.fvm.ddt(psi, p) + ref.fvc.div(phi) - ref.fvm.laplacian(rho() * rAU, p)  # mixed calculations

            pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())))

            if pimple.finalNonOrthogonalIter():
                phi += pEqn.flux()
                pass
            pass
        pass

    ref.rhoEqn(rho, phi)
    cumulativeContErr = ref.compressibleContinuityErrs(rho(), thermo, cumulativeContErr)  # mixed calculations
    # Explicitly relax pressure for momentum corrector
    p.relax()

    # Recalculate density from the relaxed pressure
    rho << thermo.rho()
    rho << rho().ext_max(rhoMin)
    rho << rho().ext_min(rhoMax)
    rho.relax()
    ref.ext_Info() << "rho max/min : " << rho.ext_max().value() << " " << rho.ext_min().value() << ref.nl

    U -= rAU * ref.fvc.grad(p)
    U.correctBoundaryConditions()

    K << 0.5 * U.magSqr()
    dpdt << ref.fvc.ddt(p)

    return cumulativeContErr
def fun_pEqn( runTime, i, mesh, p, rho, turb, thermo, thermoFluid, kappa, UEqn, U, phi, psi, \
              initialMass, p_rgh, gh, ghf, nNonOrthCorr, cumulativeContErr, rhoMax, rhoMin, pRefCell, pRefValue ):
    
    rho << thermo.rho()
    rho << rho.ext_max( rhoMin[ i ] )
    rho << rho.ext_min( rhoMax[ i ] )
    rho.relax()

    rAU = 1.0 / UEqn.A()
    rhorAUf = ref.surfaceScalarField( ref.word( "(rho*(1|A(U)))" ), ref.fvc.interpolate( rho * rAU ) )

    U << rAU * UEqn.H()
    #UEqn.clear()

    phi << ref.fvc.interpolate( rho ) * ( ref.fvc.interpolate( U ) & mesh.Sf() )
    closedVolume = ref.adjustPhi( phi, U, p_rgh )
    compressibility = ref.fvc.domainIntegrate( psi )
    compressible = ( compressibility.value() > ref.SMALL)

    buoyancyPhi = rhorAUf * ghf * ref.fvc.snGrad( rho ) * mesh.magSf()
    phi -= buoyancyPhi

    # Solve pressure
    for nonOrth in range( nNonOrthCorr + 1 ):
        p_rghEqn = ref.fvm.laplacian( rhorAUf, p_rgh ) == ref.fvc.div( phi ) 

        if compressible:
            tmp = ref.getRefCellValue(p_rgh, pRefCell)
            pass
        else:
            tmp = pRefValue
            pass
        p_rghEqn.setReference( pRefCell, tmp )

        p_rghEqn.solve()

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

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

            # Correct the momentum source with the pressure gradient flux
            # calculated from the relaxed pressure
            U -= rAU * ref.fvc.reconstruct( ( buoyancyPhi + p_rghEqn.flux() ) / rhorAUf )
            U.correctBoundaryConditions()
            pass
        pass

    p << p_rgh + rho * gh
    
    cumulativeContErr = ref.ContinuityErrs( phi, runTime, mesh, cumulativeContErr )

    # For closed-volume cases adjust the pressure level
    # to obey overall mass continuity
    if closedVolume and compressible:
        p += ( initialMass - ref.fvc.domainIntegrate( thermo.rho() ) ) / compressibility
        p_rgh << p() - rho * gh
        pass

    rho << thermo.rho();
    rho << rho.ext_max( rhoMin[ i ] )
    rho << rho.ext_min( rhoMax[ i ] )
    rho.relax()

    ref.ext_Info() << "Min/max rho:" << rho.ext_min().value() << ' ' << rho.ext_max().value() << ref.nl

    # Update thermal conductivity
    kappa << thermo.Cp() * turb.alphaEff()
    
    return cumulativeContErr
Esempio n. 30
0
def main_standalone(argc, argv):

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    thermodynamicProperties, rho0, p0, psi, rhoO = readThermodynamicProperties(
        runTime, mesh)

    transportProperties, mu = readTransportProperties(runTime, mesh)

    p, U, rho, phi = createFields(runTime, mesh, rhoO, psi)

    cumulativeContErr = ref.initContinuityErrs()

    #// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    ref.ext_Info() << "\nStarting time loop\n" << ref.nl

    while runTime.loop():

        ref.ext_Info() << "Time = " << runTime.timeName() << ref.nl << ref.nl

        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = ref.readPISOControls(
            mesh)

        CoNum, meanCoNum = ref.compressibleCourantNo(mesh, phi, rho, runTime)

        ref.rhoEqn(rho, phi)

        UEqn = man.fvm.ddt(rho, U) + man.fvm.div(phi, U) - man.fvm.laplacian(
            mu, U)

        ref.solve(UEqn == -man.fvc.grad(p))

        # --- PISO loop
        for corr in range(nCorr):

            rAU = 1.0 / UEqn.A()
            U << rAU * UEqn.H()

            phid = ref.surfaceScalarField(
                ref.word("phid"),
                psi * ((ref.fvc.interpolate(U) & mesh.Sf()) +
                       ref.fvc.ddtPhiCorr(rAU, rho(), U(), phi())))

            phi << (rhoO / psi) * phid
            pEqn = ref.fvm.ddt(psi, p()) + ref.fvc.div(phi()) + ref.fvm.div(
                phid, p()) - ref.fvm.laplacian(rho() * rAU, p())

            pEqn.solve()

            phi += pEqn.flux()

            cumulativeContErr = compressibleContinuityErrs(
                rho, phi, p, rho0, p0, psi, cumulativeContErr)

            U -= rAU * ref.fvc.grad(p)
            U.correctBoundaryConditions()
            pass
        rho << rhoO + psi * p

        runTime.write()

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

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

    import os
    return os.EX_OK