home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / oilfield / spe-31.lzh / FLASH.FOR < prev    next >
Text File  |  1987-08-11  |  5KB  |  122 lines

  1.         SUBROUTINE flash(NumComp,z,K,MaxError,V,x,y,NumIter,F)
  2.  
  3. c***********************************************************************
  4. c       This subroutine calculates the compositions of the liquid and
  5. c          vapor phases resulting when a mixture is flashed utilizing
  6. c          specified equilibrium ratios.
  7.  
  8. c       Author: Scott K. Laudeman
  9. c       Date: June 20, 1987
  10.  
  11. c       The derivation of the flash calculation equation is described
  12. c          in Amyx, James W.,Bass, Daniel M., Jr., and Whiting,
  13. c          Robert L., Petroleum Reservoir Engineering, McGraw-Hill,
  14. c          1960, pp.342-343.  The resulting equation is solved using
  15. c          Newton's method (see any text on numerical analysis, for
  16. c          example, Gerald, Curtis F. and Wheatly, Patrick O., Applied
  17. c          Numerical Analysis, Addison-Wesley, 1984, pp. 15-16.
  18.  
  19. c       Input variables.
  20.  
  21. c          NumComp: Number of components.
  22. c          z: Array containing mole fraction of each component in
  23. c             mixture.
  24. c          K: Array containing equilibrium ratio of each component.
  25. c          MaxError: Error tolerance for total mole fraction of vapor
  26. c             phase.
  27.  
  28. c       Output variables.
  29.  
  30. c          V: Total mole fraction of vapor phase.
  31. c          x: Array containing mole fraction of each component in liquid
  32. c             phase.
  33. c          y: Array containing mole fraction of each component in vapor
  34. c             phase.
  35. c          NumIter: Iterations required for calculation.
  36. c          F: Function to be solved for total mole fraction of vapor
  37. c             phase.
  38.  
  39. c       Other variables.
  40.  
  41. c          dFdV: Derivative of function to be solved for total mole
  42. c             fraction of vapor phase.
  43. c          i: loop counter
  44. c          MaxIter: Maximum iterations permitted before error message.
  45. c          TermUnit: Number identifying unit for screen input/output.
  46. c          Vold: Value of V from previous iteration.
  47.  
  48. c***********************************************************************
  49.  
  50.  
  51. c***********************************************************************
  52. c       Declarations
  53. c***********************************************************************
  54.  
  55. c=======================================================================
  56. c       Constants
  57. c=======================================================================
  58.  
  59.         PARAMETER (MaxIter=20)
  60.  
  61. c=======================================================================
  62. c       Variables
  63. c=======================================================================
  64.  
  65.  
  66.         REAL    K(NumComp),MaxError,x(NumComp),y(NumComp),z(NumComp)
  67.  
  68. c***********************************************************************
  69. c       Main Program
  70. c***********************************************************************
  71.  
  72.         NumIter = 0
  73.         V       = 0.5
  74.         Vold    = 0.0
  75.  
  76. c=======================================================================
  77. c       Loop for calculating vapor phase mole fraction using Newton's
  78. c          method.  Iteration continues until difference between
  79. c          iterations is acceptable or until number of iterations exceeds
  80. c          maximum.
  81. c=======================================================================
  82.  
  83. 10      IF (ABS(V - Vold).GT.MaxError .AND. NumIter.LE.MaxIter) THEN
  84.            NumIter = NumIter + 1
  85.            Vold    = V
  86.  
  87.            F       = 0.0
  88.            dFdV    = 0.0
  89.            DO 20 i = 1,NumComp
  90.               F    =    F + (K(i) - 1.0)*z(i)/((K(i) - 1.0)*V + 1.0)
  91.               dFdV = dFdV - (K(i) - 1.0)**2*z(i)/((K(i) - 1.0)*V
  92.      1                 + 1.0)**2
  93. 20         CONTINUE
  94.  
  95.            V = Vold - F/dFdV
  96.  
  97. c----------------------------------------------------------------------
  98. c       Reset vapor phase mole fraction if calculated value is
  99. c          unrealistic.  If calculation fails to converge after maximum
  100. c          iterations then single phase is assumed and the following
  101. c          conditional is used to assign the phase.
  102. c----------------------------------------------------------------------
  103.  
  104.           IF (V.GT.1.0) V = 1.0
  105.           IF (V.LT.0.0) V = 0.0
  106.  
  107.           GO TO 10
  108.         ENDIF
  109.  
  110. c=======================================================================
  111. c       Calculate liquid and vapor compositions.
  112. c=======================================================================
  113.  
  114.         DO 30 i = 1,NumComp
  115.            x(i) = z(i)/((K(i) - 1.0)*V + 1.0)
  116.            y(i) = K(i)*x(i)
  117. 30      CONTINUE
  118.  
  119.         RETURN
  120.  
  121.         END
  122.