#
#   Set up some Perl variables to allow easy change of fluids and components.
#
! $Lqx  = "Liquid" ;  # Liquid fluid
! $Gsx  = "Gas" ;     # Gas fluid
! $Cliq = "Steam3l" ;         # A liquid component
! $Cvap = "Steam3v" ;         # A vapour component
#
#########################################################################
#
LIBRARY:
  CEL:
    EXPRESSIONS:
#
#########################################################################
#               Basic data for liquid/gas interface.
#########################################################################
#
      srfTenCoef = 0.05 [N m^-1]      # Surface tension coefficient
#
      KinDiff = 1.0e-6 [m^2 s^-1]     # Component kinematic diffusivity.
#
      liqLength = 1.0e-5 [m]          # Length scale for liquid droplets
#
# Interfacial area density: It is assumed that the disperse 'particle'
#                           phase is the liquid and is everywhere dilute.
#
# Area density MUST go to zero as conservative volume fractions go to one or
# zero, note conservative vf not guaranteed to sum to one (PWG).
#
      swg = step($Gsx.vfc)*step(1.0-$Gsx.vfc)
      swl = step($Lqx.vfc)*step(1.0-$Lqx.vfc)
      AreaDensity = swg*swl*( 6*$Lqx.vfc/liqLength )
#
##############################################################################
#                  Interphase diffusive transport coef.
##############################################################################
#
#     Fluid slip speed.
#
      SlipSpd = sqrt (($Lqx.u-$Gsx.u)^2 + ($Lqx.v-$Gsx.v)^2 \
                                        + ($Lqx.w-$Gsx.w)^2 )
#
#     Slip Reynolds number.
#
      ReNo = SlipSpd * liqLength / $Gsx.visckin
#
#     Sherwood number and mass transfer coefficient for water.
#
      ShNowa = 2.0+0.0187*ReNo^0.77924    # Need a proper correlation here.
      CoefMTwa = ShNowa * KinDiff / liqLength
#
##############################################################################
#                          Heats of vaporisation.
##############################################################################
#
#     This is exact for evaporation but is not quite right for condensation
#     as this should really be computed at the temperature used for mass
#     transfer. Hopefully the latent heat does not vary too much with
#     temperature and pressure at about 1 bar.
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      HtVapwa = $Gsx.$Cvap.enthsaturation - $Lqx.$Cliq.enthsaturation
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
##############################################################################
#                  Liquid <-> gas mass transfer for water.
#
#     Mdot_l_to_g = Sh*Di,g*rho_g/d_l*(Xi,g - Xsati,g)
##############################################################################
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
      SatT  = $Lqx.Tsaturation   # Saturation temperature
      VpWat = $Lqx.psaturation   # Saturation pressure based on liquid temp.
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
      CMwa = CoefMTwa*AreaDensity*$Gsx.density*($Gsx.$Cvap.mw/$Gsx.mw)

      XGwa = $Gsx.$Cvap.Molar Fraction         # Water mole fraction in gas
#
      XGSwa = VpWat / Absolute Pressure        # Saturation gas mole fraction.
#
      dXwa = XGwa - XGSwa
#
      FLUXwa = CMwa * dXwa                       # Net IPMT mass flux.
      FLUXwa1 =  max(0.0 [kg m^-3 s^-1],FLUXwa)  # Gas to Liquid.
      FLUXwa2 = -min(0.0 [kg m^-3 s^-1],FLUXwa)  # Liquid to Gas.
#
#     Mass fraction rate derivative.
#
      dFLwadYG = -CMwa*XGwa*(1.0-XGwa)
#
##############################################################################
#              Continuity linearisation with respect to P.
##############################################################################
#
      dXRwadp = - XGSwa / Absolute Pressure
      dFLUXwadp = CMwa*dXRwadp
#
##############################################################################
#               Local False step linearisation of the IPMT
#
#     The algorithm is that the transfer is bounded to ensure that you cannot
#     take more than is available and you cannot give more than there is room
#     for. A minimum false time step is applied to avoid completely freezing
#     the mass fraction - this should be set to a sensible value based on the
#     physics. To avoid a divide by zero the mass transfer also has a
#     minimum absolute value - this should be set to a sensible value based
#     on the physics.
#
##############################################################################
#
      DtFalseMin = 1.0e-8 [s]                # Is this a sensible value ?
      absFluxMin = 1.0e-10 [kg s^-1 m^-3]    # Is this a sensible value ?
      DtFac = 1.0
#
      SwitchFWa = step( FLUXwa / 1.0 [kg s^-1 m^-3] )
#     massLiqWa = max( $Lqx.density * ( SwitchFWa*$Lqx.$Cliq.mfc \
#                                   + (1.0-SwitchFWa) ) , 0.0 [kg m^-3] )
      massLiqWa = $Lqx.density
      massGasWa = max( $Gsx.density * ( SwitchFWa \
                + (1.0-SwitchFWa)*$Gsx.$Cvap.mfc ) , 0.0 [kg m^-3] )
      DtFalseWa = max( DtFalseMin , \
                       min( $Lqx.vf*massLiqWa , $Gsx.vf*massGasWa ) \
                       / max( abs(FLUXwa) , absFluxMin ) )
#
      DtFalseMf = DtFac*DtFalseWa
##############################################################################
    END
  END
END
