*DECK THMJLC
      SUBROUTINE THMJLC(NZ,AGM,ENTH,SAH,ACOOL,P,S,XFL,EPS)
*
*-----------------------------------------------------------------------
*
*Purpose:
* compute the void fraction and the steam flow quality distribution in
* channel using the Saha-Zuber correlation.
*
*Copyright:
* Copyright (C) 2014 Ecole Polytechnique de Montreal.
*
*Author(s): A. Hernandez Solis (KTH)
*
*Parameters: input
* NZ      number of points in channel.
* AGM     massic coolant flow rate in Kg/m^2/s.
* ENTH    axial enthalpy distribution in J/Kg.
* SAH     critical subcooling difference in J/Kg.
* ACOOL   assembly coolant cross section in m^2.
* P       pressure distribution in channel in Pa.
*
*Parameters: output
* S       slip ratio of vapor phase speed to liquid phase speed.
* XFL     steam flow quality distribution in channel.
* EPS     void fraction distribution in channel.
*
*Remarks:
* without taking into account subcooled boiling, the thermodynamic
* quality should be given by QUAL = (HCOOL(K)-HL)/HLV
* in this commented subsection, the quality and void fraction based
* on the hem th model and thermodynamic quality are computed.
* under the next subsection, a drfit-flux model is shown where
* subcooled boiling is taken into account by the saha correlation and
* based on the real flow quality (i.e. not the thermodynamic one)
* the axial dependance of the mixture enthalpy is carried out by the
* ENTH(K) variable
*
*             XFL(K) = (ENTH(K)-HL)/HLV
*             F3=S*RV*(1-XFL(K))/(RL*XFL(K))
*             EPS(K)=1/(1+F3)
* this model will give an over-prediction of void fraction at high
* values (i.e. slug, annular flow )
*
* in this subsection, true flow quality is computed both at subcooled
* boiling and saturated conditions.
* the sah term (J/Kg) corresponds to the saha correlation for
* subcooled boiling for PE > 70000 (i.e. normal reactor conditions)              
* also, a drift-flux model is proposed by means of the concentration
* parameter CO and the drift velocity VGJ (their correspondent corre-
* lations are supposed to work fine under different flow regimes
*
*-----------------------------------------------------------------------
*
      IMPLICIT NONE
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER NZ
      REAL P(NZ),XFL(NZ),EPS(NZ),AGM(NZ),ENTH(NZ),SAH(NZ),ACOOL,S(NZ)
*----
*  LOCAL VARIABLES
*----
      INTEGER K
      REAL TSAT,HLV,RL,HL,RV,HV,F1,F2,F3,F4,CO,VGJ,JL,JG
*
      DO K=1,NZ
        IF(SAH(K).GT.0.0)THEN
*           compute the value of the enthalpy of vaporisation
            CALL THMSAT(P(K),TSAT)
            CALL THMTX(TSAT,0.0,RL,HL)
            CALL THMTX(TSAT,1.0,RV,HV)
            HLV=HV-HL
*           compute the value of the steam flow quality
            F1=(ENTH(K)-HL)/SAH(K)
            IF(F1.LT.-1.0) THEN
              XFL(K)=0.0
            ELSE
              F2=((ENTH(K)-HL)/HLV)
              F3=(SAH(K)/HLV)*EXP((-1.0*((ENTH(K)-HL)/SAH(K)))-1.0)
              XFL(K)=(F2+F3)
            ENDIF
*           compute the value of the void fraction
            CO=1.13
            VGJ=1.18*((0.012*9.81*(RL-RV))/RL**2)**0.25
            F4=CO*((XFL(K)*RL)+((1.0-XFL(K))*RV))+(RL*RV*VGJ/AGM(K))
            EPS(K)=(XFL(K)*RL)/F4
            JL=(1.0-XFL(K))*(AGM(K)/(ACOOL*RL))
            JG=XFL(K)*(AGM(K)/(ACOOL*RV))
            IF(EPS(K).EQ.0) THEN
              S(K)=1.0
            ELSE
              S(K)=JG*(1.0-EPS(K))/(JL*EPS(K))
            ENDIF
         ENDIF
      ENDDO
      RETURN
      END
