*APP SEP01
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A BINARY BATCH DISTILLATION SYSTEM
C...
C...  THE FOLLOWING CODING SIMULATES A TEN-TRAY BATCH DISTILLATION
C...  COLUMN.  INITIALLY, 100 MOLES OF A 50/50 MOLAR MIXTURE OF
C...  ETHANOL AND WATER (RELATIVE VOLATILITY = 1.4) ARE CHARGED TO
C...  THE COLUMN.  IN SO DOING, 0.5 MOLE REMAIN ON EACH TRAY OF THE
C...  COLUMN.  HEAT IS THEN APPLIED TO THE KETTLE TO MAINTAIN A CONSTANT
C...  BOILUP OF 10 MOLES/HR.  VAPOR LEAVING THE TOP OF THE COLUMN IS
C...  CONDENSED SO THAT A REFLUX RATE OF 7.5 MOLES/HR IS MAINTAINED,
C...  AND THUS 2.5 MOLES/HR OF PRODUCT IS WITHDRAWN.
C...
C...  THE PURPOSE OF THIS CASE STUDY IS TO INTEGRATE THE MATERIAL
C...  BALANCE EQUATIONS FOR THE DISTILLATION COLUMN TO DETERMINE XD(T)
C...  AND XB(T) (THE DISTILLATE AND BOTTOMS PRODUCT COMPOSITIONS AS A
C...  FUNCTION OF TIME) OVER A 7 HOUR PERIOD
C...
C...  THE FOLLOWING VARIABLES ARE USED IN THE DIFFERENTIAL EQUATIONS
C...  WHICH DESCRIBE THE DISTILLATION PROCESS
C...
C...     MB      TOTAL MOLES IN THE REBOILER
C...
C...     XB      LIQUID MOLE FRACTION OF ETHANOL IN THE REBOILER
C...
C...     YB      VAPOR MOLE FRACTION OF ETHANOL FROM THE REBOILER
C...             (ASSUMED TO BE IN EQUILIBRIUM WITH XB)
C...
C...     X(I)    LIQUID MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...
C...     Y(I)    VAPOR MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...             (ASSUMED TO BE IN EQUILBRIUM WITH X(I))
C...
C...     REFLUX  REFLUX RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     VAPOR   VAPOR RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     ALPHA   RELATIVE VOLATILITY OF ETHANOL WITH RESPECT TO WATER
C...
C...     DISTIL  DISTILLED (TOPS) PRODUCT RATE = VAPOR - REFLUX MOLES/HR
C...
C...     N       TOTAL NUMBER OF TRAYS IN THE COLUMN
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  SET THE SYSTEM PARAMETERS
      VAPOR=10.0
      REFLUX=7.5
      ALPHA=1.4
      DISTIL=VAPOR-REFLUX
      N=10
C...
C...  INITIAL CONDITONS (T = 0)
C...  MB(T) = 95.0, XB(T) = 0.5, X(I) = 0.5, I = 1, 2, 3,..., N
      MB=95.0
      XB=0.5
      DO 1 I=1,N
1     X(I)=0.5
C...
C...  CALCULATE THE INITIAL EQUILBRIUM VAPOR COMPOSITIONS
      YB=ALPHA*XB/(1.+(ALPHA-1.)*XB)
      DO 2 I=1,N
2     Y(I)=YB
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  CALCULATE THE EQUILIBRIUM VAPOR COMPOSITIONS
      YB=ALPHA*XB/(1.+(ALPHA-1.)*XB)
      DO 1 I=1,N
1     Y(I)=ALPHA*X(I)/(1.+(ALPHA-1.)*X(I))
C...
C...  TOTAL MATERIAL BALANCE FOR THE ENTIRE COLUMN
C...  DMB/DT = -DISTIL
      DMBDT=-DISTIL
C...
C...  ETHANOL MATERIAL BALANCE FOR THE REBOILER
C...  D(MB*XB)/DT = MB*DXB/DT + XB*DMB/DT = REFLUX*X(1) - VAPOR*YB
      DXBDT=(REFLUX*X(1)-VAPOR*YB-XB*DMBDT)/MB
C...
C...  ETHANOL MATERIAL BALANCE FOR THE FIRST PLATE
C...  0.5*DX(1)/DT = VAPOR*(YB - Y(1)) + REFLUX*(X(2) - X(1))
      DXDT(1)=2.0*(VAPOR*(YB-Y(1))+REFLUX*(X(2)-X(1)))
C...
C...  ETHANOL MATERIAL BALANCES FOR THE INTERMEDIATE PLATES, I = 2, 3,
C...  ..., N-1
C...  0.5*DX(I)/DT = VAPOR*(Y(I-1) - Y(I)) + REFLUX*(X(I+1) - X(I))
      NM1=N-1
      DO 2 I=2,NM1
2     DXDT(I)=2.0*(VAPOR*(Y(I-1)-Y(I))+REFLUX*(X(I+1)-X(I)))
C...
C...  ETHANOL MATERIAL BALANCE FOR THE TOP PLATE
C...  0.5*DX(N)/DT = VAPOR*(Y(N-1) - Y(N)) + REFLUX*(Y(N) - X(N))
      DXDT(N)=2.0*(VAPOR*(Y(N-1)-Y(N))+REFLUX*(Y(N)-X(N)))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TPLOT(41),XPLOT(2,41)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED POINTS
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,1)VAPOR,REFLUX,DISTIL,ALPHA,N
1     FORMAT(1H1,//,36H BATCH DISTILLATION OF ETHANOL-WATER,//,
     1              36H INITIAL CHARGE = 100 MOLES         ,//,
     2              36H INITIAL COMPOSITION = 50/50        ,//,
     3              26H BOILUP RATE (MOLES/HR) = ,F5.1     ,//,
     4              26H REFLUX RATE (MOLES/HR) = ,F5.1     ,//,
     5              27H PRODUCT RATE (MOLES/HR) = ,F4.1    ,//,
     6              23H RELATIVE VOLATILITY = ,F4.1        ,//,
     7              19H NUMBER OF TRAYS = ,I2              ,//)
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(14X,4HTIME,10X,8HMOLES IN,6X,12HETHANOL CONC,6X,12HETHANOL
     1CONC,6X,12HETHANOL CONC,5X,16HETHANOL CONC VAP,/,13X,5HHOURS,11X,6
     2HKETTLE,9X,9HIN KETTLE,8X,10HIN PRODUCT,6X,14HLEAVING KETTLE,4X,15
     3HLEAVING PLATE 5)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,4)T,MB,XB,Y(N),YB,Y(5)
4     FORMAT(13X,F5.2,11X,F5.1,10X,F7.4,11X,F7.4,11X,F7.4,12X,F7.4)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TPLOT(IP)=T
      XPLOT(1,IP)=XB
      XPLOT(2,IP)=Y(N)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.41)RETURN
      CALL PLOTS(2,41,TPLOT,XPLOT)
C...
C...  LABEL THE PLOT
      WRITE(NO,6)
6     FORMAT(//,11X,9H1 - XB(T),3X,9H2 - XD(T))
      IP=0
      RETURN
      END
BATCH DISTILLATION OF AN ETHANOL-WATER MIXTURE
0.        10.       0.25
   12  200    2    1  REL 0.001
END OF RUNS
*APP SEP02
      SUBROUTINE INITAL
C...
C...  DYNAMIC SIMULATION OF A DEISOBUTANIZER
C...
C...  THIS SIMULATION INCLUDES THE FOLLOWING DETAILS
C...
C...     (1)  FOUR COMPONENTS - (1) PROPANE
C...                            (2) ISOBUTANE
C...                            (3) NORMAL BUTANE
C...                            (4) OCTANE
C...
C...     (2)  NONLINEAR, BUT IDEALIZED VAPOR-LIQUID EQUILBRIUM
C...          RELATIONSHIPS
C...
C...     (3)  PRINCIPAL HEAT EFFECTS
C...
C...     (4)  TRAY HYDRAULICS
C...
C...     (5)  FEEDBACK CONTROL OF THE REFLUX
C...
C...  THE EQUATIONS WHICH MODEL THE DEISOBUTANIZER ARE SUMMARIZED BELOW
C...  FOLLOWED BY A TABLE OF NOMENCLATURE WHICH DEFINES THE SYSTEM
C...  VARIABLES
C...
C...  (1)  REBOILER (REBOILER HOLDUP, XMB, ASSUMED CONSTANT)
C...
C...       (1.1)  HEAT BALANCE
C...
C...       VB = (QB - XL(1)*(HLIQB - HLIQ(1)))/(HVAPB - HLIQB)       (1)
C...
C...       (1.2)  TOTAL MATERIAL BALANCE
C...
C...       B = XL(1) - VB                                            (2)
C...
C...       (1.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DXB(J)/DT = (XL(1)*X(1,J) - VB*YB(J) - B*XB(J))/XMB       (3)
C...
C...  (2)  TRAY 1
C...
C...       (2.1)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(1) = (VB*HVAPB + XL(2)*HLIQ(2) - XL(1)*HLIQ(1))/HVAP(1) (4)
C...
C...       (2.2)  TOTAL MATERIAL BALANCE
C...
C...       DM(1)/DT = XL(2) - XL(1) + VB - V(1)                      (5)
C...
C...       (2.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(1,J)/DT = XL(2)*X(2,J) - XL(1)*X(1,J) +
C...                                                                 (6)
C...                     VB*YB(J)     - V(1)*Y(1,J)
C...
C...  (3)  STRIPPING SECTION (2 LE N LE 18)
C...
C...       (3.1)  HEAT BALANCES (TIME DERIVATIVES NEGLECTED)
C...
C...       V(N) = (V(N-1)*HVAP(N-1) + XL(N+1)*HLIQ(N+1) -
C...                                                                 (7)
C...              XL(N)*HLIQ(N))/HVAP(N)
C...
C...       (3.3)  TOTAL MATERIAL BALANCES
C...
C...       DM(N)/DT = XL(N+1) - XL(N) + V(N-1) - V(N)                (8)
C...
C...       (3.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(N,J)/DT = XL(N+1)*X(N+1,J) - XL(N)*X(N,J) +
C...                                                                 (9)
C...                     V(N-1)*Y(N-1,J)  - V(N)*Y(N,J)
C...
C...  (4)  FEED PLATE (NF = 19)
C...
C...       (4.1)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(NF) = (V(NF-1)*HVAP(NF-1) + XL(NF+1)*HLIQ(NF+1) -
C...                                                                (10)
C...               XL(NF)*HLIQ(NF)     + FL*HLF)/HVAP(NF)
C...
C...       (4.2)  TOTAL MATERIAL BALANCE
C...
C...       DM(NF)/DT = XL(NF+1) - XL(NF) + V(NF-1) - V(NF) + FL     (11)
C...
C...       (4.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(NF,J)/DT = XL(NF+1)*X(NF+1,J) - XL(NF)*X(NF,J) +
C...
C...                      V(NF-1)*Y(NF-1,J)  - V(NF)*Y(NF,J) +      (12)
C...
C...                      FL*XF(J)
C...
C...  (5)  RECTIFYING SECTION (20 LE N LE 24)
C...
C...       (5.1)  HEAT BALANCES (TIME DERIVATIVES NEGLECTED)
C...
C...       V(N) = (V(N-1)*HVAP(N-1) + XL(N+1)*HLIQ(N+1) -
C...                                                                (13)
C...              XL(N)*HLIQ(N))/HVAP(N)
C...
C...       (5.2)  TOTAL MATERIAL BALANCES
C...
C...       DM(N)/DT = XL(N+1) - XL(N) + V(N-1) - V(N)               (14)
C...
C...       (5.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(N,J)/DT = XL(N+1)*X(N+1,J) - XL(N)*X(N,J) +
C...                                                                (15)
C...                     V(N-1)*Y(N-1,J)  - V(N)*Y(N,J)
C...
C...  (6)  TOP TRAY
C...
C..        (6.1)  ERROR FOR THE PROPORTIONAL-INTEGRAL CONTROLLER
C...              BASED ON THE MEASUREMENT OF PLATE 21 TEMPERATURE
C...
C...       ERROR = T0(21) - T(21)                                   (16)
C...
C...       (6.2)  MANIPULATION OF REFLUX RATE BY PROPORTIONAL-INTEGRAL
C...              CONTROLLER
C...
C...       R = R0 - XKC*(ERROR + ERINT/TAU1)
C...
C...       (6.3)  HEAT BALANCE (TIME DERIVATIVE NEGLECTED)
C...
C...       V(NT) = (V(NT-1)*HVAP(NT-1) + R*HLIQD -
C...                                                                (18)
C...               XL(NT)*HLIQ(NT))/HVAP(NT)
C...
C...       (6.4)  TOTAL MATERIAL BALANCE
C...
C...       DM(NT)/DT = R - XL(NT) + V(NT-1) - V(NT)                 (19)
C...
C...       (6.5)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DMX(NT,J)/DT = R*XD(J)           - XL(NT)*X(NT,J) +
C...                                                                (20)
C...                      V(NT-1)*Y(NT-1,J) - V(NT)*Y(NT,J)
C...
C...  (7)  CONDENSER (CONDENSER HOLDUP, XMD, ASSUMED CONSTANT)
C...
C...       (7.1)  HEAT BALANCE
C...
C...       QD = V(NT)*(HVAP(NT) - HLIQD)                            (21)
C...
C...       (7.2)  TOTAL MATERIAL BALANCE
C...
C...       D = V(NT) - R
C...
C...       (7.3)  COMPONENT MATERIAL BALANCES (J = 1, 2, 3, 4)
C...
C...       DXD(J)/DT = V(NT)*(Y(NT,J) - XD(J))/XMD                  (23)
C...
C...  (8)  LIQUID PHASE COMPOSITIONS (1 LE N LE 25, J = 1, 2, 3, 4)
C...
C...       X(N,J) = XMX(N,J)/XM(N)
C...
C...  (9)  EQUILBRIUM VAPOR COMPOSITIONS
C...
C...       (9.1)  REBOILER
C...
C...       YB = EQUIL(XB,TB)                                        (25)
C...
C...       (9.2)  TRAYS (1 LE N LE 25)
C...
C...       YY = EQUIL(XX,T(N))                                      (26)
C...
C... (10)  LIQUID ENTHALPIES
C...
C...       (10.1)  REBOILER
C...
C...       HLIQB = ENTHL(XB,TB)                                     (27)
C...
C...       (10.2)  TRAYS (1 LE N LE 25)
C...
C...       HLIQ(N) = ENTHL(XX,T(N))                                 (28)
C...
C...       (10.3)  CONDENSER
C...
C...       HLIQD = ENTHL(XD,TD)                                     (29)
C...
C...       (10.4)  FEED
C...
C...       HLF = ENTHL(XF,TF)                                       (30)
C...
C... (11)  VAPOR ENTHALPIES
C...
C...       (11.1)  REBOILER
C...
C...       HVAPB = ENTHV(YB,TB)                                     (31)
C...
C...       (11.2)  TRAYS (1 LE N LE 25)
C...
C...       HVAP(N) = ENTHV(YY,T(N))                                 (32)
C...
C... (12)  TRAY HYDRAULICS
C...
C...       (12.1)  STRIPPING SECTION (1 LE N LE 19)
C...
C...       XL(N) = 1800*(XM(N)/127.0 - 0.1667)**(3/2)               (33)
C...
C...       (12.1)  RECTIFYING SECTION (20 LE N LE 25)
C...
C...       XL(N) = 1200*(XM(N)/127.0 - 0.1667)**(3/2)               (34)
C...
C...
C...  TABEL OF NOMENCLATURE
C...
C...     B          BOTTOMS FLOW RATE (MOLES/MIN)
C...
C...     D          DISTILLATE FLOW RATE (MOLES/MIN)
C...
C...     DM(N)      TIME DERIVATIVE OF TOTAL LIQUID MOLAR FLOW RATE ON
C...                NTH PLATE (= DM(N)/DT) (MOLES/MIN)
C...
C...     DMX(N,J)   TIME DERIVATIVE OF JTH COMPONENT LIQUID MOLAR
C...                HOLDUP ON NTH PLATE (I.E. PRODUCT OF JTH COMPONENT
C...                MOLE FRACTION AND TOTAL LIQUID MOLAR HOLDUP ON NTH
C...                PLATE) (= DMX(N,J)/DT) (MOLES/MIN)
C...
C...     DXB(J)     TIME DERIVATIVE OF JTH COMPONENT MOLE FRACTION IN
C...                BOTTOMS (= DXB(J)/DT) (1/MIN)
C...
C...     DXD(J)     TIME DERIVATIVE OF JTH COMPONENT MOLE FRACTION IN
C...                DISTILLATE (= DXD(J)/DT) (1/MIN)
C...
C...     ERINT      INTEGRATED OUTPUT ERROR FROM FEEDBACK CONTROLLER
C...                (F-MIN)
C...
C...     ERROR      OUTPUT ERROR FROM FEEDBACK CONTROLLER (F)
C...
C...     FL         FEED FLOW RATE (MOLES/MIN)
C...
C...     HLF        FEED ENTHALPY (BTU/MOLE)
C...
C...     HLIQB      BOTTOMS LIQUID ENTHALPY (BTU/MOLE)
C...
C...     HLIQD      DISTILLATE ENTHALPY (BTU/MOLE)
C...
C...     HLIQ(N)    ENTHALPY OF LIQUID FROM NTH PLATE (BTU/MOLE)
C...
C...     HVAPB      BOTTOMS EQUILIBRIUM VAPOR ENTHALPY (BTU/MOLE)
C...
C...     HVAP(N)    ENTHALPY OF VAPOR FROM NTH PLATE (BTU/MOLE)
C...
C...     J          INDEX INDICATING JTH COMPONENT (J = 1, 2, 3, 4)
C...
C...     N          INDEX INDICATING PLATE NUMBER
C...
C...     NF         NUMBER OF FEED PLATE
C...
C...     NT         TOTAL NUMBER OF PLATES IN COLUMN
C...
C...     QB         REBOILER HEAT DUTY (BTU/MIN)
C...
C...     QD         CONDENSER HEAT DUTY (BTU/MIN)
C...
C...     R          REFLUX FLOW RATE (MOLES/MIN)
C...
C...     RO         INITIAL REFLUX FLOW RATE (MOLES/MIN)
C...
C...     T(N)       EQUILIBRIUM TEMPERATURE ON NTH PLATE (F)
C...
C...     TAU1       INTEGRAL TIME OF FEEDBACK CONTROLLER (MIN)
C...
C...     TB         REBOILER TEMPERATURE (F)
C...
C...     TBO        INITIAL REBOILER TEMPERATURE (F)
C...
C...     TD         DISTILLATE TEMPERATURE (F)
C...
C...     TDO        INITIAL DISTILLATE TEMPERATURE (F)
C...
C...     TF         FEED TEMPERATURE (F)
C...
C...     TO(N)      INITIAL TEMPERATURE ON NTH PLATE (F)
C...
C...     V(N)       VAPOR FLOW RATE FROM NTH PLATE (MOLES/MIN)
C...
C...     VB         VAPOR FLOW RATE FROM REBOILER (MOLES/MIN)
C...
C...     X(N,J)     MOLE FRACTION OF JTH COMPONENT IN LIQUID ON NTH
C...                PLATE
C...
C...     XB(J)      MOLE FRACTION OF JTH COMPONENT IN REBOILER
C...
C...     XBO(J)     INITIAL MOLE FRACTION OF JTH COMPONENT IN REBOILER
C...
C...     XD(J)      MOLE FRACTION OF JTH COMPONENT IN CONDENSER
C...
C...     XDO(J)     INITIAL MOLE FRACTION OF JTH COMPONENT IN CONDENSER
C...
C...     XF(J)      MOLE FRACTION OF JTH COMPONENT IN FEED
C...
C...     XKC        GAIN OF FEEDBACK CONTROLLER (MOLES/(MIN-F))
C...
C...     XL(N)      MOLAR LIQUID FLOW RATE FROM NTH PLATE (MOLES/HR)
C...
C...     XLO(N)     INITIAL MOLAR LIQUID FLOW RATE FROMNTH PLATE
C...                (MOLES/MIN)
C...
C...     XM(N)      TOTAL MOLAR LIQUID HOLDUP ON NTH PLATE (MOLES)
C...
C...     XMB        TOTAL MOLAR LIQUID HOLDUP IN REBOILER (MOLES)
C...
C...     XMD        TOTAL MOLAR LIQUID HOLDUP IN CONDENSER (MOLES)
C...
C...     XMO(N)     INITIAL TOTAL MOLAR LIQUID HOLDUP ON NTH PLATE
C...                (MOLES)
C...
C...     XO(N,J)    INITIAL MOLE FRACTION OF JTH COMPONENT IN LIQUID
C...                ON NTH PLATE
C...
C...     XX(J)      ONE-DIMENSIONAL WORKING VECTOR OF LIQUID MOLE
C...                FRACTIONS USED FOR TEMPORARY STORAGE
C...
C...     Y(N,J)     MOLE FRACTION OF JTH COMPONENT IN VAPOR FROM NTH
C...                PLATE
C...
C...     YB(J)      MOLE FRACTION OF JTH COMPONENT IN VAPOR FROM
C...                REBOILER
C...
C...     YY(J)      ONE-DIMENSIONAL WORKING VECTOR OF VAPOR MOLE
C...                FRACTIONS USED FOR TEMPORARY STORAGE
C...
C...  /T/, /Y/ AND /F/ COMMON AREAS
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
C...
C...  COMMON TO PASS MODEL PARAMETERS, VARIABLES BETWEEN SUBROUTINES
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  COMMON AREA WITH THE INPUT/OUTPUT UNIT (DEVICE) NUMBERS
      COMMON/IO/NI,NO
C...
C...  THE MODEL PARAMETERS, INITIALIZED VARIABLES ARE SET IN A BLOCK
C...  DATA ROUTINE
C...
C...
C...  CALCULATE INITIAL PLATE HOLDUPS (XMO(N)) BY INVERTING EQUATIONS
C...  (33) AND (34)
      DO 2 N=1,NT
C...
C...  CONSTANT IN HYDRAULIC EQUATIONS (33) AND (34) IS 1800 AND 1200
C...  RESPECTIVELY
      CONST=1800.
      IF(N.GT.NF)CONST=1200.
2     XMO(N)=127.*((XLO(N)/CONST)**.667+.1667)
C...
C...  INITIALIZE BOTTOMS COMPOSITION (XB(J)), DISTILLATE COMPOSITION
C...  (XD(J))
      DO 6 J=1,4
      XB(J)=XBO(J)
6     XD(J)=XDO(J)
C...
C...  INITIALIZE ON EACH PLATE VAPOR FLOW (V(N)), LIQUID FLOW (XL(N)),
C...  TEMPERATURE (T(N)), TOTAL LIQUID HOLDUP (XM(N)), LIQUID COMPOSI-
C...  TION (X(N,J)), HOLDUP OF EACH COMPONENT (XMX(N,J))
      DO 8 N=1,NT
      V(N)=0.
      XL(N)=XLO(N)
      T(N)=TO(N)
      XM(N)=XMO(N)
      DO 8 J=1,4
      X(N,J)=XO(N,J)
8     XMX(N,J)=XM(N)*X(N,J)
C...
C...  INITIALIZE BOTTOMS TEMPERATURE (TB), DISTILLATE TEMPERATURE (TD),
C...  REFLUX RATIO (R), INTEGRATED ERROR FROM FEEDBACK CONTROLLER
C...  (ERINT)
      TB=TBO
      TD=TDO
      R=RO
      ERINT=1.0E-05
C...
C...  READ AND PRINT FEED PARAMETERS - TEMPERATURE (TF), COMPOSITION
C...  (XF(J)), FLOW RATE (FL)
       READ(NI,1)TF,(XF(J),J=1,4),FL
1     FORMAT(8E10.3)
      WRITE(NO,3)TF,(XF(J),J=1,4),FL
3     FORMAT(//,10X,15HFEED CONDITIONS,/,15X,14HTEMPERATURE = ,E10.3,/,
     115X,24HCOMPOSITION - PROPANE = ,E10.3,/,29X,12HISOBUTANE = ,E10.3,
     2/,29X,16HNORMAL BUTANE = ,E10.3,/,29X,9HOCTANE = ,E10.3,/,15X,
     47HFLOW = ,E10.3)
C...
C...  CALCULATE FEED ENTHALPY (HLF), EQUATION (30)
      CALL ENTHL(XF,TF,HLF)
C...
C...  READ AND PRINT CONTROLLER GAIN (XKC), CONTROLLER INTEGRAL TIME
C...  (TAU1)
       READ(NI,1)XKC,TAU1
      WRITE(NO,4)XKC,TAU1
4     FORMAT(//,10X,21HCONTROLLER PARAMETERS,/,15X,7HGAIN = ,E10.3,/,
     115X,16HINTEGRAL TIME = ,E10.3)
      RETURN
      END
      SUBROUTINE DERV
C...
C...  SUBROUTINE DERV INPUTS LIQUID COMPOSITIONS, TOTAL LIQUID HOLDUPS
C...  AND COMPONENT LIQUID HOLDUPS TO COMPUTE THE TIME DERIVATIVES OF
C...  THESE VARIABLES VIA THE ENTHALPY, TOTAL MOLAR AND COMPONENT MOLAR
C...  BALANCES FOR THE COLUMN
C...
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
      DIMENSION HLIQ(25),HVAP(25),Y(25,4),YB(4),YD(4),XX(4),YY(4)
C...
C...  CALCULATE THE LIQUID COMPOSITION ON EACH PLATE (X(N,J)), EQUATION
C...  (24)
      DO 1 N=1,NT
      DO 1 J=1,4
1     X(N,J)=XMX(N,J)/XM(N)
C...
C...  CALCULATE THE EQUILIBRIUM VAPOR COMPOSITION (YB), EQUATION (25),
C...  LIQUID ENTHALPY (HLIQB), EQUATION (27), AND VAPOR ENTHALPY
C...  (HVAPB), EQUATION (31), OF THE BOTTOMS
      CALL EQUIL(XB,TB,YB)
      CALL ENTHL(XB,TB,HLIQB)
      CALL ENTHV(YB,TB,HVAPB)
C...
C...  CALCULATE THE LIQUID ENTHALPY (HLIQD) OF THE DISTILLATE, EQUATION
C...  (29)
      CALL ENTHL(XD,TD,HLIQD)
C...
C...  PUT THE LIQUID COMPOSITION FOR EACH PLATE (X(N,J)) IN A ONE-
C...  DIMENSIONAL ARRAY (XX(J)) FOR CALCULATION OF THE EQUILBRIUM VAPOR
C...  COMPOSITION (YY(J) = Y(N,J)), EQUATION (26), LIQUID AND VAPOR
C...  ENTHALPHIES (HLIQ(N), HVAP(N)), EQUATIONS (28), (32)
      DO 20 N=1,NT
      DO 21 J=1,4
21    XX(J)=X(N,J)
      CALL EQUIL(XX,T(N),YY)
      DO 22 J=1,4
22    Y(N,J)=YY(J)
      CALL ENTHL(XX,T(N),HLIQ(N))
      CALL ENTHV(YY,T(N),HVAP(N))
20    CONTINUE
C...
C...  IF THE DYNAMIC LIQUID HEAD ON THE TRAYS IS NEGATIVE, SET THE HEAD
C...  TO ZERO BEFORE CALCULATING THE LIQUID FLOW RATES FROM THE PLATES
C...  ABOVE AND BELOW THE FEED PLATE, EQUATIONS (33), (34)
      DO 23 N=1,NF
      HEAD=XM(N)/127.-.1667
      IF(HEAD.LE.0.)HEAD=0.
23    XL(N)=1800.*HEAD**1.5
      NFP1=NF+1
      DO 24 N=NFP1,NT
      HEAD=XM(N)/127.-.1667
      IF(HEAD.LE.0.)HEAD=0.
24    XL(N)=1200.*HEAD**1.5
C...
C...
C...  REBOILER
C...     REBOILER VAPOR RATE (VB), EQUATION (1)
      VB=(QB-XL(1)*(HLIQB-HLIQ(1)))/(HVAPB-HLIQB)
C...
C...     BOTTOMS RATE (B), EQUATION (2)
      B=XL(1)-VB
      IF(B.LT.0.)B=0.
C...
C...     BOTTOMS COMPOSITION DERIVATIVES (DXB(J)), EQUATION (3)
      DO 30 J=1,4
30    DXB(J)=(XL(1)*X(1,J)-VB*YB(J)-B*XB(J))/XMB
C...
C...
C...  TRAY 1
C...     VAPOR RATE (V(1)), EQUATION (4)
      V(1)=(VB*HVAPB+XL(2)*HLIQ(2)-XL(1)*HLIQ(1))/HVAP(1)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(1)), EQUATION (5)
      DM(1)=XL(2)-XL(1)+VB-V(1)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(1,J)), EQUATION (6)
      DO 31 J=1,4
31    DMX(1,J)=XL(2)*X(2,J)-XL(1)*X(1,J)+VB*YB(J)-V(1)*Y(1,J)
C...
C...
C...  STRIPPING SECTION
      NFM1=NF-1
      DO 40 N=2,NFM1
C...
C...     VAPOR RATES (V(N)), EQUATION (7)
      V(N)=(V(N-1)*HVAP(N-1)+XL(N+1)*HLIQ(N+1)-XL(N)*HLIQ(N))/HVAP(N)
C...
C...     MOLAR HOLDUP DERIVATIVES (DM(N)), EQUATION (8)
      DM(N)=XL(N+1)-XL(N)+V(N-1)-V(N)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(N,J)), EQUATION (9)
      DO 40 J=1,4
40    DMX(N,J)=XL(N+1)*X(N+1,J)-XL(N)*X(N,J)+V(N-1)*Y(N-1,J)-V(N)*Y(N,J)
C...
C...
C...  FEED PLATE
C...     VAPOR RATE (V(NF)), EQUATION (10)
      V(NF)=(V(NF-1)*HVAP(NF-1)+XL(NF+1)*HLIQ(NF+1)-XL(NF)*HLIQ(NF)
     1+FL*HLF)/HVAP(NF)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(NF)), EQUATION (11)
      DM(NF)=XL(NF+1)-XL(NF)+V(NF-1)-V(NF)+FL
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(NF,J)), EQUATION (12)
      DO 50 J=1,4
50    DMX(NF,J)=XL(NF+1)*X(NF+1,J)-XL(NF)*X(NF,J)+V(NF-1)*Y(NF-1,J)
     1-V(NF)*Y(NF,J)+FL*XF(J)
C...
C...
C...  RECTIFYING SECTION
      NTM1=NT-1
      DO 60 N=NFP1,NTM1
C...
C...     VAPOR RATES (V(N)), EQUATION (13)
      V(N)=(V(N-1)*HVAP(N-1)+XL(N+1)*HLIQ(N+1)-XL(N)*HLIQ(N))/HVAP(N)
C...
C...     MOLAR HOLDUP DERIVATIVES (DM(N)), EQUATION (14)
      DM(N)=XL(N+1)-XL(N)+V(N-1)-V(N)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(N,J)), EQUATION (15)
      DO 60 J=1,4
60    DMX(N,J)=XL(N+1)*X(N+1,J)-XL(N)*X(N,J)+V(N-1)*Y(N-1,J)-V(N)*Y(N,J)
C...
C...
C...  TOP TRAY
C...     ERROR FOR PROPORTIONAL-INTEGRAL CONTROLLER (ERROR) BASED ON THE
C...     MEASUREMENT OF PLATE 21 TEMPERATURE (T(21)), EQUATION (16)
      ERROR=TO(21)-T(21)
C...
C...     MANIPULATION OF REFLUX RATE (R) BY CONTROLLER WITH GAIN XKC
C...     AND RESET TIME TAU1, EQUATION (17)
      R=RO-XKC*(ERROR+ERINT/TAU1)
C...
C...     VAPOR RATE (V(NT)), EQUATION (18)
      V(NT)=(V(NT-1)*HVAP(NT-1)+R*HLIQD-XL(NT)*HLIQ(NT))/HVAP(NT)
C...
C...     MOLAR HOLDUP DERIVATIVE (DM(NT)), EQUATION (19)
      DM(NT)=R-XL(NT)+V(NT-1)-V(NT)
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DMX(NT,J)), EQUATION (20)
      DO 70 J=1,4
70    DMX(NT,J)=R*XD(J)-XL(NT)*X(NT,J)+V(NT-1)*Y(NT-1,J)-V(NT)*Y(NT,J)
C...
C...
C...  CONDENSER
C...     CONDENSER HEAT DUTY (QD), EQUATION (21)
      QD=V(NT)*(HVAP(NT)-HLIQD)
C...
C...     DISTILLATE RATE (D), EQUATION (22)
      D=V(NT)-R
      IF(D.LT.0.)D=0.
C...
C...     COMPONENT MOLAR HOLDUP DERIVATIVES (DXD(J)), EQUATION (23)
      DO 71 J=1,4
71    DXD(J)=V(NT)*(Y(NT,J)-XD(J))/XMD
      RETURN
      END
      BLOCK DATA
C...
C...  THE MODEL PARAMETERS, INITIALIZE VARIABLES ARE SET IN THIS BLOCK
C...  DATA ROUTINE
C...
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  INITIALIZE TOTAL NUMBER OF PLATES (NT), NUMBER OF FEED PLATE (NF)
      DATA NT,NF/25,19/
C...
C...  INITIALIZE REFLUX (RO), REBOILER HEAT DUTY (QB)
      DATA RO/8.580E+01/,QB/8.500E+05/
C...
C...  INITIALIZE BOTTOMS TEMPERATURE (TBO), BOTTOMS COMPOSITION (XBO),
C...  BOTTOMS FLOW (B), REBOILER HOLDUP (XMB)
      DATA TBO/1.780E+02/,XBO(1),XBO(2),XBO(3),XBO(4)/
     15.604E-09,9.910E-02,6.459E-01,2.550E-01/,B/9.471E+00/
     2,XMB/3.200E+02/
C...
C...  INITIALIZE TEMPERATURE (TO), LIQUID COMPOSITION (XO), LIQUID FLOW
C...  (XLO) FOR EACH PLATE
      DATA TO( 1)/1.502E+02/,XO( 1,1),XO( 1,2),XO( 1,3),XO( 1,4)/
     11.560E-08,1.487E-01,8.185E-01,3.280E-02/,XLO( 1)/1.100E+02/
      DATA TO( 2)/1.485E+02/,XO( 2,1),XO( 2,2),XO( 2,3),XO( 2,4)/
     13.568E-08,1.736E-01,8.058E-01,2.052E-02/,XLO( 2)/1.240E+02/
      DATA TO( 3)/1.479E+02/,XO( 3,1),XO( 3,2),XO( 3,3),XO( 3,4)/
     18.003E-08,1.985E-01,7.815E-01,1.999E-02/,XLO( 3)/1.248E+02/
      DATA TO( 4)/1.474E+02/,XO( 4,1),XO( 4,2),XO( 4,3),XO( 4,4)/
     11.782E-07,2.248E-01,7.553E-01,1.995E-02/,XLO( 4)/1.250E+02/
      DATA TO( 5)/1.469E+02/,XO( 5,1),XO( 5,2),XO( 5,3),XO( 5,4)/
     13.946E-07,2.524E-01,7.277E-01,1.992E-02/,XLO( 5)/1.251E+02/
      DATA TO( 6)/1.463E+02/,XO( 6,1),XO( 6,2),XO( 6,3),XO( 6,4)/
     18.694E-07,2.810E-01,6.991E-01,1.990E-02/,XLO( 6)/1.252E+02/
      DATA TO( 7)/1.458E+02/,XO( 7,1),XO( 7,2),XO( 7,3),XO( 7,4)/
     11.906E-06,3.103E-01,6.698E-01,1.987E-02/,XLO( 7)/1.253E+02/
      DATA TO( 8)/1.452E+02/,XO( 8,1),XO( 8,2),XO( 8,3),XO( 8,4)/
     14.158E-06,3.401E-01,6.401E-01,1.985E-02/,XLO( 8)/1.254E+02/
      DATA TO( 9)/1.446E+02/,XO( 9,1),XO( 9,2),XO( 9,3),XO( 9,4)/
     19.030E-06,3.699E-01,6.102E-01,1.982E-02/,XLO( 9)/1.255E+02/
      DATA TO(10)/1.440E+02/,XO(10,1),XO(10,2),XO(10,3),XO(10,4)/
     11.951E-05,3.995E-01,5.807E-01,1.979E-02/,XLO(10)/1.256E+02/
      DATA TO(11)/1.435E+02/,XO(11,1),XO(11,2),XO(11,3),XO(11,4)/
     14.197E-05,4.285E-01,5.517E-01,1.977E-02/,XLO(11)/1.258E+02/
      DATA TO(12)/1.429E+02/,XO(12,1),XO(12,2),XO(12,3),XO(12,4)/
     18.985E-05,4.565E-01,5.236E-01,1.974E-02/,XLO(12)/1.259E+02/
      DATA TO(13)/1.424E+02/,XO(13,1),XO(13,2),XO(13,3),XO(13,4)/
     11.915E-04,4.833E-01,4.968E-01,1.972E-02/,XLO(13)/1.260E+02/
      DATA TO(14)/1.419E+02/,XO(14,1),XO(14,2),XO(14,3),XO(14,4)/
     14.063E-04,5.087E-01,4.713E-01,1.969E-02/,XLO(14)/1.261E+02/
      DATA TO(15)/1.414E+02/,XO(15,1),XO(15,2),XO(15,3),XO(15,4)/
     18.583E-04,5.322E-01,4.473E-01,1.967E-02/,XLO(15)/1.263E+02/
      DATA TO(16)/1.409E+02/,XO(16,1),XO(16,2),XO(16,3),XO(16,4)/
     11.805E-03,5.538E-01,4.248E-01,1.965E-02/,XLO(16)/1.264E+02/
      DATA TO(17)/1.402E+02/,XO(17,1),XO(17,2),XO(17,3),XO(17,4)/
     13.781E-03,5.729E-01,4.038E-01,1.963E-02/,XLO(17)/1.265E+02/
      DATA TO(18)/1.394E+02/,XO(18,1),XO(18,2),XO(18,3),XO(18,4)/
     17.877E-03,5.888E-01,3.838E-01,1.961E-02/,XLO(18)/1.266E+02/
      DATA TO(19)/1.382E+02/,XO(19,1),XO(19,2),XO(19,3),XO(19,4)/
     11.629E-02,5.999E-01,3.642E-01,1.958E-02/,XLO(19)/1.266E+02/
      DATA TO(20)/1.362E+02/,XO(20,1),XO(20,2),XO(20,3),XO(20,4)/
     11.666E-02,6.250E-01,3.576E-01,7.198E-04/,XLO(20)/8.370E+01/
      DATA TO(21)/1.358E+02/,XO(21,1),XO(21,2),XO(21,3),XO(21,4)/
     11.713E-02,6.425E-01,3.403E-01,2.538E-05/,XLO(21)/8.470E+01/
      DATA TO(22)/1.353E+02/,XO(22,1),XO(22,2),XO(22,3),XO(22,4)/
     11.828E-02,6.623E-01,3.195E-01,8.872E-07/,XLO(22)/8.483E+01/
      DATA TO(23)/1.346E+02/,XO(23,1),XO(23,2),XO(23,3),XO(23,4)/
     12.130E-02,6.841E-01,2.946E-01,3.069E-08/,XLO(23)/8.494E+01/
      DATA TO(24)/1.333E+02/,XO(24,1),XO(24,2),XO(24,3),XO(24,4)/
     12.927E-02,7.061E-01,2.646E-01,1.045E-09/,XLO(24)/8.508E+01/
      DATA TO(25)/1.307E+02/,XO(25,1),XO(25,2),XO(25,3),XO(25,4)/
     15.028E-02,7.220E-01,2.277E-01,3.432E-11/,XLO(25)/8.530E+01/
C...
C...  INITIALIZE DISTILLATE TEMPERATURE (TDO), DISTILLATE COMPOSITION
C...  (XDO), DISTILLATE FLOW (D), CONDENSER HOLDUP (XMD)
      DATA TDO/1.252E+02/,XDO(1),XDO(2),XDO(3),XDO(4)/
     11.030E-01,7.118E-01,1.853E-01,8.410E-13/,D/2.423E+01/
     2,XMD/5.600E+02/
      END
      SUBROUTINE EQUIL(XX,TEMP,YY)
C...
C...  SUBROUTINE EQUIL COMPUTES THE EQUILBRIUM TEMPERATURE AND VAPOR
C...  COMPOSITION CORRESPONDING TO A GIVEN LIQUID COMPOSITION
C...
C...  SOURCE OF EQUILBRIUM DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     XX    ONE-DIMENSIONAL INPUT ARRAY OF LIQUID COMPOSITIONS
C...
C...     TEMP  OUTPUT EQUILIBRIUM TEMPERATURE (F)
C...
C...     YY    ONE-DIMENSIONAL OUTPUT ARRAY OF VAPOR COMPOSITIONS
C...
      DIMENSION XX(4),YY(4)
C...
C...  THE K VS T CURVE FOR EACH PURE COMPONENT IS APPROXIMATED BY A
C...  LINEAR RELATIONSHIP OF THE FORM K = A + B*T OVER A TEMPERATURE
C...  RANGE OF 100 TO 200 F, 120 PSIA
C...
C...  PROPANE - MAXWELL, PAGE 53
      A1=-.492
      B1=.01956
C...
C...  ISOBUTANE - MAXWELL, PAGE 54
      A2=-.478
      B2=.01124
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 55
      A3=-.573
      B3=.01049
C...
C...  OCTANE - MAXWELL, PAGE 60
      A4=-.04916
      B4=.0005623
C...
C...  THE TEMPERATURE IS COMPUTED EXPLICITLY FROM
C...
C...     (1)  THE LINEAR APPROXIMATION OF K VS T
C...
C...     (2)  ASSUMED IDEAL SOLUTIONS
C...
C...     (3)  SUM OF VAPOR MOLE FRACTIONS IS UNITY
C...
C...  I.E. SUM(YY) = 1 OR SUM((A + B*T)*XX) = 1 SOLVED EXPLICITLY FOR T
      TEMP=(1.-A1*XX(1)-A2*XX(2)-A3*XX(3)-A4*XX(4))/(B1*XX(1)+B2*XX(2)+
     1B3*XX(3)+B4*XX(4))
C...
C...  THE VAPOR MOLE FRACTION OF EACH COMPONENT IS GIVEN BY YY = K*XX =
C...  (A + B*T)*XX
      YY(1)=(A1+B1*TEMP)*XX(1)
      YY(2)=(A2+B2*TEMP)*XX(2)
      YY(3)=(A3+B3*TEMP)*XX(3)
      YY(4)=(A4+B4*TEMP)*XX(4)
      RETURN
      END
      SUBROUTINE ENTHL(XX,TEMP,HL)
C...
C...  SUBROUTINE ENTHL COMPUTES THE LIQUID ENTHALPY CORRESPONDING TO A
C...  GIVEN LIQUID COMPOSITION AND TEMPERATURE
C...
C...  SOURCE OF ENTHALPY DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     XX    ONE-DIMENSIONAL INPUT ARRAY OF LIQUID COMPOSITIONS
C...
C...     TEMP  INPUT TEMPERATURE (F)
C...
C...     HL    OUTPUT LIQUID ENTHALPY (BTU/MOLE)
C...
      DIMENSION XX(4),CHL(4)
C...
C...  THE LIQUID ENTHALPY (CHL) VS T CURVES FOR THE PURE COMPONENTS ARE
C...  APPROXIMATED BY A LINEAR RELATIONSHIP OF THE FORM CHL = B*T OVER A
C...  TEMPERATURE RANGE OF 100 TO 200 F.  NOTE THAT T = 0 CORRESPONDS TO
C...  CHL = 0 (I.E. THE REFERENCE STATE OF THE ENTHALPY CURVES GIVEN BY
C...  MAXWELL HAS BEEN REDEFINED)
C...
C...  PROPANE - MAXWELL, PAGE 100
      CHL(1)=31.*TEMP
C...
C...  ISOBUTANE - MAXWELL, PAGE 101
      CHL(2)=35.*TEMP
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 101
      CHL(3)=35.*TEMP
C...
C...  OCTANE - MAXWELL, PAGE 105
      CHL(4)=63.*TEMP
C...
C...  THE LIQUID ENTHALPY IS COMPUTED FROM
C...
C...     (1)  THE LINEAR APPROXIMATION OF CHL VS T
C...
C...     (2)  ASSUMED IDEAL SOLUTIONS
C...
C...     (3)  SUM OF ENTHALPIES OF THE PURE COMPONENTS
      HL=0.
      DO1 J=1,4
    1 HL=HL+XX(J)*CHL(J)
      RETURN
      END
      SUBROUTINE ENTHV(YY,TEMP,HV)
C...
C...  SUBROUTINE ENTHV COMPUTES THE VAPOR ENTHALPY CORRESPONDING TO A
C...  GIVEN VAPOR COMPOSITION
C...
C...  SOURCE OF ENTHALPY DATA
C...
C...     MAXWELL, J. B., DATA BOOK ON HYDROCARBONS, D. VAN NOSTRAND CO.,
C...     INC., N.Y., 1950
C...
C...  ARGUMENT LIST
C...
C...     YY    ONE-DIMENSIONAL INPUT ARRAY OF VAPOR COMPOSITIONS
C...
C...     TEMP  INPUT TEMPERATURE (F)
C...
C...     HV    OUTPUT VAPOR ENTHALPY (BTU/MOLE)
C...
      DIMENSION     YY(4),CHV(4)
C...
C...  THE VAPOR ENTHALPY (CHV) VS T RELATIONSHIPS FOR THE PURE COM-
C...  PONENTS ARE THE CORRESPONDING LIQUID RELATIONSHIPS USED IN
C...  SUBROUTINE ENTHL PLUS AN AVERAGE HEAT OF VAPORIZATION FOR THE
C...  TEMPERATURE RANGE 100 TO 200 F
C...
C...  PROPANE - MAXWELL, PAGE 100
      CHV(1)=31.*TEMP+5070.
C...
C...  ISOBUTANE - MAXWELL, PAGE 101
      CHV(2)=35.*TEMP+7000.
C...
C...  NORMAL BUTANE - MAXWELL, PAGE 101
      CHV(3)=35.*TEMP+7300.
C...
C...  OCTANE - MAXWELL, PAGE 105
      CHV(4)=63.*TEMP+16000.
C...
C...  THE VAPOR ENTHALPY IS COMPUTED FROM
C...
C...     (1)  THE LINEAR APPROXIMATIONS FOR THE LIQUID COMPONENTS PLUS
C...          AN AVERAGE HEAT OF VAPORIZATION
C...
C...     (2)  ASSUMED IDEAL GAS MIXTURE
C...
C...     (3)  SUM OF ENTHALPIES OF THE PURE COMPONENTS
      HV=0.
      DO 1 J=1,4
    1 HV=HV+YY(J)*CHV(J)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/TIME/Y/ XB(4), XD(4),XM(25),XMX(25,4),ERINT
     1             /F/DXB(4),DXD(4),DM(25),DMX(25,4),ERROR
      COMMON/VAR/
     1    T(25),  TO(25),      TD,      TB,   XF(4),      FL,       B,
     2       VB,     XMB,       D,       R,     XMD,  XL(25),   V(25),
     3  X(25,4),     HLF,      QB,      QD,      NT,      NF,      RO,
     4      XKC,    TAU1,  XBO(4),  XDO(4), XMO(25), XLO(25),XO(25,4),
     5      TBO,     TDO
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TPLOT(31),XBPLOT(4,31),XDPLOT(4,31)
C...
C...  INITIALIZE A COUNTER FOR PRINTED LINES, PLOTTED SOLUTION
      DATA NLINE,IP/0,0/
C...
C...  PRINT TIME, HEADING FOR THE COMPUTED RESPONSE
      WRITE(NO,12)TIME
12    FORMAT(/,3X,7HTIME = ,E9.2)
      WRITE(NO,7)
7     FORMAT(3X,9HPLATE NO.,8X,2HX1,10X,2HX2,10X,2HX3,10X,2HX4,8X,4HTEMP
     1,6X,9HLIQ  FLOW,3X,9HVAP  FLOW,3X,9HLIQ  HOLD,3X,9HHEAT DUTY)
C...
C...  PRINT RESPONSE OF THE REBOILER
      WRITE(NO,13)(XB(J),J=1,4),TB,B,VB,XMB,QB
13    FORMAT(3X,8HREBOILER,2X,9E12.3)
C...
C...  PRINT RESPONSE OF PLATES 1, 7, 13, 19, 25
      DO 14 N=1,NT,6
      WRITE(NO,15)N,(X(N,J),J=1,4),T(N),XL(N),V(N),XM(N)
15    FORMAT(6X,I2,5X,9E12.3)
14    CONTINUE
C...
C...  PRINT RESPONSE OF THE CONDENSER
      WRITE(NO,16)(XD(J),J=1,4),TD,D,R,XMD,QD
16    FORMAT(2X,9HCONDENSER,2X,9E12.3)
      NLINE=NLINE+10
      IF(NLINE.LT.50)GO TO 18
      WRITE(NO,17)
17    FORMAT(1H1)
      NLINE=0
C...
C...  STORE THE BOTTOMS AND DISTILLATE COMPOSITIONS FOR SUBSEQUENT
C...  PLOTTING
18    IP=IP+1
      TPLOT(IP)=TIME
      DO 1 J=1,4
      XBPLOT(J,IP)=XB(J)
1     XDPLOT(J,IP)=XD(J)
C...
C...  PLOT THE TRANSIENT RESPONSE OF THE BOTTOMS AND DISTILLATE
C...  COMPOSITIONS
      IF(IP.LT.31)RETURN
      CALL PLOTS(4,31,TPLOT,XBPLOT)
      WRITE(NO,3)
3     FORMAT(//,16X,27HBOTTOMS COMPOSITION VS TIME,/,
     1          16X,11H1 - PROPANE,3X,13H2 - ISOBUTANE,3X,
     2              17H3 - NORMAL BUTANE,3X,10H4 - OCTANE)
      CALL PLOTS(4,31,TPLOT,XDPLOT)
      WRITE(NO,4)
4     FORMAT(//,16X,30HDISTILLATE COMPOSITION VS TIME,/,
     1          16X,11H1 - PROPANE,3X,13H2 - ISOBUTANE,3X,
     2              17H3 - NORMAL BUTANE,3X,10H4 - OCTANE)
      IP=0
      RETURN
      END
DEISOBUTANIZER SIMULATION, RESPONSE TO STEP CHANGE IN FEED FLOW RATE
0.        60.0      2.0
  134  100    1    1  REL 0.005
 8.200E+01 7.410E-02 5.380E-01 3.162E-01 7.170E-02 4.000E+01
 0.000E+00 5.000E+00
END OF RUNS
*APP SEP03
      SUBROUTINE INITAL
C...
C...  DIFFUSION AND NONLINEAR ADSORPTION IN A PORE
C...
C...  CONSIDER DIFFUSION INTO AND ADSORPTION ONTO AN IDEALIZED PORE
C...
C             .............................................
C                                                         .
C     C(0,T) = CS                  C(X,T)                 .C (L,T) = 0
C                                  G(X,T)                 . X
C             .............................................
C           X = 0                                       X = L
C             +..................... L ...................+
C
C...  A MATERIAL BALANCE ON THE FLUID PHASE IN A DIFFERENTIAL LENGTH OF
C...  THE PORE GIVES
C...
C...          C  = D*C  - (2/(R0*SM))*(KA*(1 - G)*C - KD*G)          (1)
C...           T      XX
C...
C...  SIMILARLY, A MATERIAL BALANCE ON A DIFFERENTIAL LENGTH OF THE PORE
C...  WALL GIVES
C...
C...          G  = KA*(1 - G)*C - KD*G                               (2)
C...           T
C...
C...  WHERE
C...
C...     C(X,T)    CONCENTRATION OF ADSORBATE IN THE FLUID AT POSITION X
C...               ALONG THE PORE AND TIME T
C...
C...     G(X,T)    FRACTION OF THE PORE WALL COVERED AT POSITION X ALONG
C...               THE PORE AND TIME T
C...
C...     R0        RADIUS OF THE PORE
C...
C...     L         LENGTH OF THE PORE
C...
C...     SM        SURFACE AREA OF THE PORE OCCUPIED BY ONE MOLE OF
C...               ADSORBATE
C...
C...     D         DIFFUSIVITY OF THE ADSORBATE IN THE FLUID WITHIN THE
C...               PORE
C...
C...     KA,KD     KINETIC CONSTANTS FOR ADSORPTION AND DESORPTION,
C...               RESPECTIVELY
C...
C...     CS        CONCENTRATION OF ADSORBATE AT THE MOUTH (X = 0) OF
C...               THE PORE
C...
C...  THE BOUNDARY CONDITIONS FOR EQUATION (1) REFLECT THE CONCENTRATION
C...  CS AT THE MOUTH OF THE PORE AND NO DIFFUSION THROUGH THE END OF
C...  THE PORE
C...
C...          C(0,T) = CS, C (L,T) = 0                            (3)(4)
C...                        X
C...
C...  INITIALLY, THE FLUID WITHIN THE PORE AND THE PORE WALL ARE FREE OF
C...  ADSORBATE
C...
C...          C(X,0) = 0, G(X,0) = 0                              (5)(6)
C...
C...  EQUATIONS (1) TO (6) CONSTITUTE THE PROBLEM TO BE SOLVED, I.E.,
C...  C(X,T) AND G(X,T) ARE TO BE COMPUTED NUMERICALLY.
C...
C...  TO FACILITATE THE SOLUTION, DIMENSIONLESS VARIABLES ARE DEFINED AS
C...
C...          F = C/CS, Z = X/L, T = T*D/L**2
C...
C...  NOTE THAT T NOW REPRESENTS DIMENSIONLESS TIME.  EQUATIONS (1) TO
C...  (6) CAN BE STATED IN TERMS OF F, Z AND T AS
C...
C...          F  = F   + HD*G - HA*(1 - G)*F                         (7)
C...           T    ZZ
C...
C...          G  = H*(HA*(1 - G)*F - HD*G)                           (8)
C...           T
C...
C...          F(0,T) = 1, F (1,T) = 0   0(9)(10)
C...                       Z
C...
C...          F(Z,0) = 0, G(Z,0) = 0                            (11)(12)
C...
C...  WHERE
C...
C...     HA        2*(L**2)*KA/(D*R0*SM)
C...
C...     HD        2*(L**2)*KD/(CS*D*R0*SM)
C...
C...     H         CS*R0*SM/2
C...
C...  THE METHOD OF LINES IS IMPLEMENTED VIA THREE APPROACHES (NCASE =
C...  1, 2, 3).  THE DERIVATIVE F   IN EQUATION (7) IS COMPUTED VIA
C...                             ZZ
C...
C...     (1)  A THREE-POINT CENTRAL DIFFERENCE APPROXIMATION EXPLICITLY
C...          PROGRAMMED IN SUBROUTINE DERV1.
C...
C...     (2)  THE THREE-POINT CENTRAL DIFFERENCE APPROXIMATION IN
C...          SUBROUTINE DSS002.
C...
C...     (3)  THE  FIVE-POINT CENTRAL DIFFERENCE APPROXIMATION IN
C...          SUBROUTINE DSS004.
C...
C...  AN INTERESTING INFINITE-TIME (STEADY STATE) SOLUTION TO EQUATIONS
C...  (7) TO (12) CAN ALSO BE DERIVED AS A CHECK ON THE NUMERICAL SOLU-
C...  TION.  THUS, FOR F  = 0, G  = 0, EQUATION (8) CAN BE SOLVED
C...                    T       T
C...  EXPLICITLY FOR G (NOTE THAT THIS IS POSSIBLE BECAUSE EQUATION (8)
C...  DOES NOT HAVE ANY DERIVATIVES WITH RESPECT TO Z)
C...
C...          G = HA*F/(HD + HA*F)                                  (13)
C...
C...  EQUATION (13) CAN THEN BE SUBSTITUTED IN EQUATION (7) (WITH
C...  F  = 0)
C...   T
C...
C...          F   = -(HA*F + HD)*HA*F/(HD + HA*F) + HA*F            (14)
C...           ZZ
C...
C...  WHERE THE DERIVATIVE F   IN EQUATION (14) IS NOW AN ORDINARY OR
C...                        ZZ
C...  TOTAL DERIVATIVE SINCE TIME HAS BEEN REMOVED FROM THE PROBLEM.
C...  THUS EQUATION (14) IS A BOUNDARY-VALUE ORDINARY DIFFERENTIAL
C...  EQUATION WHICH IS TO BE INTEGRATED SUBJECT TO BOUNDARY CONDITIONS
C...  (9) AND (10).  TYPICALLY THIS WOULD BE A RELATIVELY DIFFICULT
C...  BOUNDARY-VALUE PROBLEM, BUT NOTE THAT F(Z) = 1 IS A SOLUTION IN
C...  THIS CASE IN THE SENSE THAT IT SATISFIES EQUATIONS (9), (10) AND
C...  (14).  IT ALSO MAKES SENSE PHYSICALLY SINCE AT INFINITE TIME, THE
C...  FLUID IN THE PORE ACHIEVES A UNIFORM CONCENTRATION EQUAL TO THE
C...  CONCENTRATION AT Z = 0.  THUS FOR THE STEADY STATE, THE ENTIRE
C...  PROBLEM HAS THE SIMPLE SOLUTION
C...
C...          F(Z) = 1, G(Z) = HA/(HD + HA)                     (15)(16)
C...
C...  FOR THE NUMERICAL SOLUTION TO BE COMPUTED, HA = HD = H = 1, SO THE
C...  STEADY STATE SOLUTION REDUCES TO
C...
C...          F(Z) = 1, G(Z) = 0.5                              (17)(18)
C...
C...  THE NUMERICAL SOLUTION SHOULD GIVE AN INDICATION OF AGREEMENT
C...  WITH EQUATIONS (17) AND (18) FOR LARGE T.
C...
      COMMON/T/      T,  NSTOP,  NCASE
     1      /Y/  F(11),  G(11)
     2      /F/ FT(11), GT(11)
     3     /SD/ FZ(11),FZZ(11)
     4      /C/      H,     HA,     HD,      N,     IP
C...
C...  SET THE NUMBER OF GRID POINTS IN Z, INDEX FOR THE PLOTTED SOLUTION
      N=11
      IP=0
C...
C...  SET THE CONSTANTS IN EQUATIONS (7) AND (8)
      H =1.
      HA=1.
      HD=1.
C...
C...  INITIAL CONDITIONS (11) AND (12)
      DO 1 I=1,N
      F(I)=1.0E-10
      G(I)=1.0E-10
1     CONTINUE
C...
C...  CALL SUBROUTINE DERV TO INITIALZE ALL DERIVATIVES FOR PLOTTING
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NCASE
     1      /Y/  F(11),  G(11)
     2      /F/ FT(11), GT(11)
     3     /SD/ FZ(11),FZZ(11)
     4      /C/      H,     HA,     HD,      N,     IP
C...
C...  SELECT ONE OF THREE METHODS FOR EQUATION (7)
      GO TO(1,2,2),NCASE
C...
C...  CASE 1 - EXPLICIT CALCULATION OF THE DERIVATIVE F   IN SUBROUTINE
C...  DERV1                                            ZZ
1        CALL DERV1
         GO TO 4
C...
C...  APPLY BOUNDARY CONDITION (9) AS A CONSTRAINT
2         F(1)=1.
         FT(1)=0.
C...
C...  CALCULATION OF THE DERIVATIVE F  VIA DSS002 OR DSS004 (CASES 2
C...  AND 3 RESPECTIVELY)            Z
         IF(NCASE.EQ.2)CALL DSS002(0.,1.,N,F,FZ)
         IF(NCASE.EQ.3)CALL DSS004(0.,1.,N,F,FZ)
C...
C...  APPLY BOUNDARY CONDITION (10) AS A CONSTRAINT
         FZ(N)=0.
C...
C...  CALCULATION OF THE DERIVATIVE F   VIA DSS002 OR DSS004 (CASES 2
C...  AND 3 RESPECTIVELY)            ZZ
         IF(NCASE.EQ.2)CALL DSS002(0.,1.,N,FZ,FZZ)
         IF(NCASE.EQ.3)CALL DSS004(0.,1.,N,FZ,FZZ)
C...
C...  ASSEMBLE THE PARTIAL DIFFERENTIAL EQUATIONS
4     DO 5 I=1,N
C...
C...     EQUATION (7)
         IF(I.EQ.1)GO TO 3
         FT(I)=FZZ(I)+HD*G(I)-HA*(1.-G(I))*F(I)
C...
C...     EQUATION (8)
3        GT(I)=H*(HA*(1.-G(I))*F(I)-HD*G(I))
5     CONTINUE
      RETURN
      END
      SUBROUTINE DERV1
      COMMON/T/      T,  NSTOP,  NCASE
     1      /Y/  F(11),  G(11)
     2      /F/ FT(11), GT(11)
     3     /SD/ FZ(11),FZZ(11)
     4      /C/      H,     HA,     HD,      N,     IP
C...
C...  THE PARTIAL DERIVATIVE F   IN EQUATION (7) IS CALCULATED EX-
C...                          ZZ
C...  PLICITY BY SECOND-ORDER CENTRAL DIFFERENCE APPROXIMATIONS
C...
C...  COMPUTE THE SPATIAL INCREMENT IN Z
      DZ=1./FLOAT(N-1)
C...
C...  STEP THROUGH THE N GRID POINTS
      DO 1 I=1,N
C...
C...  AT Z = 0, THE DERIVATIVE NEED NOT BE CALCULATED BECAUSE OF
C...  BOUNDARY CONDITION (9)
      IF(I.EQ.1)GO TO 1
C...
C...  AT Z = 1, THE DERIVATIVE MUST BE CALCULATED TO REFLECT BOUNDARY
C...  CONDITION (10).  IN THIS CASE, A SECOND-ORDER DIFFERENCE APPROXI-
C...  MATION IS APPLIED TO BOUNDARY CONDITION (10) WITH THE RESULT
C...  F(N+1) = F(N-1).  THIS RESULT CAN THEN BE USED TO ELIMINATE F(N+1)
C...  FROM THE FINITE DIFFERENCE APPROXIMATION FOR F   AT Z = 1
C...                                                ZZ
      IF(I.NE.N)GO TO 2
      FZZ(N)=2.*(F(N-1)-F(N))/DZ**2
      GO TO 1
C...
C...  ALL OF THE INTERIOR GRID POINTS CAN BE HANDLED BY THE SAME CENTRAL
C...  DIFFERENCE APPROXIMATION
2     FZZ(I)=(F(I+1)-2.*F(I)+F(I-1))/DZ**2
1     CONTINUE
C...
C...  APPLY BOUNDARY CONDITION (9)
       F(1)=1.
      FT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NCASE
     1      /Y/  F(11),  G(11)
     2      /F/ FT(11), GT(11)
     3     /SD/ FZ(11),FZZ(11)
     4      /C/      H,     HA,     HD,      N,     IP
C...
C...  DIMENSION THE ARRAYS TO STORE THE NUMERICAL SOLUTION FOR PLOTTING
      DIMENSION   FP(6,11),  GP(6,11),
     1           FTP(6,11), GTP(6,11),
     2           FZP(6,11),FZZP(6,11),
     3            ZP(11)
C...
C...  SELECT THE VALUES OF T AT WHICH THE NUMERICAL SOLUTION IS STORED
C...  FOR SUBSEQUENT PLOTTING
      IF((T.GT.0.195).AND.(T.LT.0.205))GO TO 1
      IF((T.GT.0.395).AND.(T.LT.0.405))GO TO 1
      IF((T.GT.0.595).AND.(T.LT.0.605))GO TO 1
      IF((T.GT.0.795).AND.(T.LT.0.805))GO TO 1
      IF((T.GT.0.995).AND.(T.LT.1.005))GO TO 1
      IF((T.GT.9.995).AND.(T.LT.10.05))GO TO 1
      RETURN
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
1     IP=IP+1
      DO 2 I=1,N
        FP(IP,I)=  F(I)
        GP(IP,I)=  G(I)
       FTP(IP,I)= FT(I)
       GTP(IP,I)= GT(I)
       FZP(IP,I)= FZ(I)
      FZZP(IP,I)=FZZ(I)
        ZP(I)=(1./FLOAT(N-1))*FLOAT(I-1)
2     CONTINUE
C...
C...  PRINT THE NUMERICAL SOLUTION AT THE SELECTED VALUES OF T SO THAT
C...  A COMPARISON CAN BE MADE BETWEEN THE THREE CASES
      WRITE(NO,3)T,(ZP(I),I=1,N,2),(F(I),I=1,N,2),(G(I),I=1,N,2)
3     FORMAT(1H ,//,5H T = ,F7.2,/,7H      Z,6F12.3,/,
     1                             7H F(Z,T),6F12.5,/,
     2                             7H G(Z,T),6F12.5)
C...
C...  PLOT THE NUMERICAL SOLUTION AT THE FINAL VALUE OF T
      IF(IP.LT.6)RETURN
      CALL PLOTS(IP,N,ZP,  FP)
      WRITE(NO,10)
10    FORMAT(///,76H   F(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
      CALL PLOTS(IP,N,ZP,  GP)
      WRITE(NO,11)
11    FORMAT(///,76H   G(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
      CALL PLOTS(IP,N,ZP, FTP)
      WRITE(NO,12)
12    FORMAT(///,76H  FT(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
      CALL PLOTS(IP,N,ZP, GTP)
      WRITE(NO,13)
13    FORMAT(///,76H  GT(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
C...
C...  SINCE THE DERIVATIVES F  AND F   ARE NOT COMPUTED THROUGHOUT THE
C...                         Z      ZZ
C...  DOMAIN 0 LE Z LE 1 IN SUBROUTINE DERV1, THESE DERIVATIVES ARE NOT
C...  PLOTTED IN THE FIRST RUN
      IF(NCASE.EQ.1)RETURN
      CALL PLOTS(IP,N,ZP, FZP)
      WRITE(NO,14)
14    FORMAT(///,76H  FZ(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
      CALL PLOTS(IP,N,ZP,FZZP)
      WRITE(NO,15)
15    FORMAT(///,76H FZZ(Z,T) VS Z FOR T = 0.2 (1), 0.4 (2), 0.6 (3), 0.
     18 (4), 1.0 (5), 10.0 (6))
      RETURN
      END
MARROQUIN, G, ET AL, J COLLOID INTERFACE SCI, V 35, N 4, 601-611, DERV1
0.        10.0      0.2
   22 5000    1    1  REL 0.005
MARROQUIN, G, ET AL, J COLLOID INTERFACE SCI, V 35, N 4, 601-611, DSS002
0.        10.0      0.2
   22 5000    1    1  REL 0.005
MARROQUIN, G, ET AL, J COLLOID INTERFACE SCI, V 35, N 4, 601-611, DSS004
0.        10.0      0.2
   22 5000    1    1  REL 0.005
END OF RUNS
*APP SEP04
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A COUNTERCURRENT MIXER-SETTLER SYSTEM
C...
C...  DIETHYLENE (DEA) IS TO BE EXTRACTED FROM AN AQUEOUS SOLUTION BY
C...  COUNTERCURRENT EXTRACTION WITH TOLUENE IN A THREE-STATE EXTRACTION
C...  UNIT.  THE AQUEOUS SOLUTION IS FED TO THE FIRST STAGE AT A FLOW
C...  RATE OF 0.1 FT**3/SEC (FW0) AND ANALYZES 0.03 LB. MOLE DEA/FT**3
C...  FT**3/SEC (FTNT1).  THE HOLDUP VOLUMES IN EACH STAGE ARE MAINTAIN-
C...  ED CONSTANT WITH VT = 30 FT**3 (TOLUENE PHASE) AND VW = 30 FT**3
C...  (AQUEOUS PHASE).  INITIALLY THE CONCENTRATION OF DEA IN EACH STAGE
C...  AND EACH PHASE IS ZERO.  ASSUME THAT WATER AND TOLUENE ARE COM-
C...  PLETELY IMMISCIBLE AND THAT EQUILIBRIUM IS ATTAINED IN EACH STAGE
C...  WITH THE FOLLOWING EQUILIBRIUM RELATIONSHIP
C...
C...                  CAW(N) = 1.2*CAT(N), N = 1, 2, 3
C...
C...  WHERE
C...
C...     CAT = LB. MOLE DEA IN TOLUENE PHASE/FT**3
C...
C...     CAW = LB. MOLE DEA IN WATER PHASE/FT**3
C...
C...  THE CONSTANT HOLDUP ASSUMPTION REQUIRES THAT THE TOLUENE AND WATER
C...  FLOWRATES BE UNIFORM THROUGHOUT THE SYSTEM AND EQUAL TO THE ENTER-
C...  FLOWRATES, FWO AND FTNT1
C...
C...                      FW(N) = FW0, N = 1, 2, 3
C...
C...                    FT(N) = FTNT1, N = 1, 2, 3
C...
C...  A DEA MATERIAL BALANCE ON STAGE N GIVES
C...
C...          D(VT(N)*CAT(N)+VW(N)*CAW(N))/DT =
C...
C...                FW(N-1)*CAW(N-1) + FT(N+1)*CAW(N+1)
C...
C...              - FW(N)*CAW(N) - FT(N)*CAT(N), N = 1, 2, 3
C...
C...  NOTE THAT THE CODING OF THE MODEL DIFFERENTIAL EQUATIONS IN SUB-
C...  ROUTINE DERV IS GENERAL IN THE SENSE THAT ANY NUMBER OF MIXER-
C...  SETTLER STAGES CAN BE SIMULATED BY SETTING NT (AND INCREASING THE
C...  ARRAYS IN COMMON/Y/, /F/ AND /C/).  ALSO, BECAUSE OF THE SUB-
C...  SCRIPTING LIMITATIONS OF FORTRAN, THE FIRST STAGE (N = 1) AND
C...  THE LAST STAGE (N = NT) ARE PROGRAMMED SPECIFICALLY.  THE INTER-
C...  MEDIATE STAGES CAN ALL BE PROGRAMMED WITH A SINGLE GENERAL STATE-
C...  MENT.  THE DEPENDENT VARIABLES IN COMMON/Y/ ARE CONTAINED IN A
C...  SINGLE ARRAY DV, I.E., DV(N) = VT(N)*CAT(N) + VW(N)*CAW(N).  THE
C...  CORRESPONDING DERIVATIVES IN COMMON/F/ ARE CONTAINED IN THE ARRAY
C...  DVDT
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),     FTNT1,       FW0,    CATNT1,      CAW0,
     5                 NT,        IP
C...
C...  SET THE MODEL PARAMETERS
      FTNT1=0.1
      FW0=0.1
      CATNT1=0.
      CAW0=0.03
C...
C...  THE MODEL PARAMETERS AND INITIAL CONDITIONS ARE SET FOR NT STAGES
      NT=3
      DO 1 N=1,NT
      VT(N)=30.
      VW(N)=30.
      FT(N)=0.1
      FW(N)=0.1
      CAT(N)=0.
      CAW(N)=0.
C...
C...  NOTE THAT THE DEPENDENT VARIABLES IN COMMON/Y ARE THE TOTAL MOLAR
C...  HOLDUPS, DV(N), IN THE NT STAGES WHICH ARE INITIALIZED AT THIS
C...  POINT.  THESE TOTAL MOLAR HOLDUPS CONTAIN THE TOLUENE-PHASE AND
C...  WATER-PHASE COMPOSITIONS, CAT(N) AND CAW(N), WHICH ARE THE PRINCI-
C...  PAL MODEL OUTPUTS.  THESE CONCENTRATIONS ARE COMPUTED FROM THE
C...  TOTAL MOLAR HOLDUPS IN SUBROUTINE DERV BY USING THE NUMERICAL
C...  VALUES OF DV(N)
      DV(N)=VT(N)*CAT(N)+VW(N)*CAW(N)
1     CONTINUE
C...
C...  INITIALIZE THE REMAINING MODEL VARIABLES BY A CALL TO SUBROUTINE
C...  DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),     FTNT1,       FW0,    CATNT1,      CAW0,
     5                 NT,        IP
C...
C...  THE DEPENDENT VARIABLE FOR EACH STAGE IS THE TOTAL MOLAR HOLDUP OF
C...  DEA.  THE CONCENTRATIONS IN THE TOLUENE AND WATER PHASES, CAT(N)
C...  AND CAW(N), CAN BE COMPUTED FROM THE TOTAL MOLAR HOLDUP AND
C...  TOLUENE AND WATER HOLDUPS, VT AND VW, BY STRAIGHTFORWARD ALGEBRA
C...  AND THE EQUILIBRIUM RELATIONSHIP
      DO 2 N=1,NT
      CAT(N)=DV(N)/(1.2*VW(N)+VT(N))
      CAW(N)=1.2*CAT(N)
2     CONTINUE
C...
C...  COMPUTE THE TEMPORAL DERIVATIVES FOR THE NT MIXER-SETTLER STAGES
      DO 1 N=1,NT
C...
C...  FIRST STAGE WITH INLET FLOWRATE AND COMPOSITION FW0 AND CAW0
      IF(N.EQ.1)
     1   DVDT(N)=FW0*CAW0+FT(2)*CAT(2)
     2          -FW(1)*CAW(1)-FT(1)*CAT(1)
C...
C...  NT-TH STAGE WITH INLET FLOWRATE AND COMPOSITION FTNT1 AND CATNT1
      IF(N.EQ.NT)
     1   DVDT(NT)=FW(NT-1)*CAW(NT-1)+FTNT1*CATNT1
     2          -FW(NT)*CAW(NT)-FT(NT)*CAT(NT)
C...
C...  STAGES 2 TO NT-1
      IF((N.NE.1).AND.(N.NE.NT))
     1   DVDT(N)=FW(N-1)*CAW(N-1)+FT(N+1)*CAT(N+1)
     2          -FW(N)*CAW(N)-FT(N)*CAT(N)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),     FTNT1,       FW0,    CATNT1,      CAW0,
     5                 NT,        IP
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      WRITE(NO,1)T
1     FORMAT(1H ,//,5H T = ,F7.1,/,9X,1HN,4X,6HCAT(N),4X,6HCAW(N),5X,
     1 5HDV(N),3X,7HDVDT(N))
C...
C...  PRINT THE NUMERICAL SOLUTION.  THE MODEL DERIVATIVES, DVDT(N),
C...  IN COMMON/F/ ARE ALSO PRINTED TO GIVE SOME INDICATION OF THE
C...  RESPONSE DEFINED BY THE MODEL DIFFERENTIAL EQUATIONS
      WRITE(NO,2)(N,CAT(N),CAW(N),DV(N),DVDT(N),N=1,NT)
2     FORMAT(I10,4E10.3,/,I10,4E10.3,/,I10,4E10.3)
      RETURN
      END
DYNAMICS OF A COUNTERCURRENT MIXER-SETTLER SYSTEM
0.        4000.     200.
    3  100    1    1  REL 0.001
END OF RUNS
*APP SEP05
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A DECANTER
C...
C...  A DECANTER, WHICH SEPARATES TWO IMMISCIBLE LIQUIDS, DESIGNATED
C...  A AND B, IS INITIALLY OPERATING AT STEADY STATE WITH A TOTAL FEED
C...  RATE W0 = 100 LB/MIN, CONTAINING 40 0/0 BY WEIGHT OF A.  TWO FLOW
C...  CONTROL SYSTEMS ARE USED TO MAINTAIN THE HEIGHTS OF THE LIQUID
C...  PHASES BY SENSING THE HEIGHTS AND REGULATING THE FLOWS OF THE TWO
C...  PHASES FROM THE DECANTER.  THE GOVERNING CONTROLLER EQUATIONS ARE
C...
C...          FA = KA*HA
C...
C...          FB = KB*(HA + HB)
C...
C...  THE CONTROLLER GAINS ARE KA = 0.4 FT**2/MIN AND KB = 0.3 FT**2/
C...  MIN.  THE CROSS SECTIONAL AREA OF THE DECANTER IS 10FT**2 AND THE
C...  DENSITIES OF THE TWO LIQUIDS ARE RHOA = 60 LB/FT**3 AND RHOB = 50
C...  LB/FT**3.  SUDDENLY THE TOTAL FEED RATE IS CHANGED TO 150 LB/MIN
C...  AND MAINTAINED AT THIS VALUE FOR 5 MIN, THEN IT IS BROUGHT BACK TO
C...  100 LB/MIN.  THE HEIGHTS ANF FLOWS OF THE TWO PHASES ARE TO BE
C...  COMPUTED AS A FUNCTION OF TIME.  THE DYNAMIC DIFFERENTIAL MATERIAL
C...  BALANCES TO BE INTEGRATED ARE
C...
C...          (RHOA*S)*DHA/DT = W0*XA - FA*RHOA
C...
C...          (RHOB*S)*DHB/DT = W0*(1 - XA) - FB*RHOB
C...
C...  THE INITIAL CONDITIONS ARE COMPUTED FROM THESE DIFFERENTIAL EQUA-
C...  TIONS BY SETTING THE DERIVATIVES TO ZERO (INITIAL STEADY STATE
C...  OPERATION), AND SOLVING THE RESULTING ALGEBRAIC SYSTEM FOR HA
C...  AND HB.  THUS
C...
C...          0 = W0*XA - FA*RHOA
C...
C...          0 = W0*(1 - XA) - FB*RHOB
C...
C...  THIS TWO ALGEBRAIC EQUATIONS, IN COMBINATION WITH THE CONTROLLER
C...  EQUATIONS FOR FA AND FB, CAN EASILY BE SOLVED TO GIVE THE FOLLOW-
C...  ING INITIAL CONDITIONS CORRESPONDING TO W0 = 100
C...
C...          HA = 1 2/3, HA = 2 1/3
C...
C...  THESE INITIAL CONDITIONS ARE THEN SET BELOW.
C...
C...  TWO RUNS ARE PROGRAMMED IN SUBROUTINE DERV
C...
C...     (1)  (NORUN = 1) - W0 REMAINS AT 100 SO THERE IS NO DYNAMIC
C...                        RESPONSE, I.E., DHA/DT AND DHB/DT REMAIN AT
C...                        ZERO THROUGHOUT THE RUN AND THEREFORE HA AND
C...                        HB REMAIN AT 1 2/3 AND 2 1/3, RESPECTIVELY
C...
C...     (2)  (NORUN = 2) - W0 IS STEPPED TO 150 FOR 5 MINUTES, THEN
C...                        STEPPED BACK TO 100 FOR THE REMAINDER OF THE
C...                        RUN
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    HA,    HB
     2      /F/ DHADT, DHBDT
     3      /C/    W0,    XA,  RHOA,  RHOB,     S,    KA,    KB,    FA,
     4             FB
      REAL         KA,    KB
C...
C...  SET THE MODEL PARAMETERS
      XA=0.40
      RHOA=60.
      RHOB=50.
      S=10.
      KA=0.4
      KB=0.3
      W0=100.
C...
C...  DEFINE THE MODEL INITIAL CONDITIONS
      HA=1.+2./3.
      HB=2.+1./3.
C...
C...  INITIALIZE THE REMAINDER OF THE MODEL
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    HA,    HB
     2      /F/ DHADT, DHBDT
     3      /C/    W0,    XA,  RHOA,  RHOB,     S,    KA,    KB,    FA,
     4             FB
      REAL         KA,    KB
C...
C...  SET THE ENTERING FLOW RATE WHICH DISTURBS THE SYSTEM
      GO TO(1,2),NORUN
C...
C...  RUN NO. 1 - NO DISTURBANCE
1     GO TO 10
C...
C...  RUN NO. 2 - W0 = 150 LB/MIN FOR 5 MIN
2     IF(T.GE.0.)W0=150.
      IF(T.GT.5.)W0=100.
C...
C...  COMPUTE THE FLOWS FROM THE DECANTER
10    FA=KA*HA
      FB=KB*(HA+HB)
C...
C...  COMPUTE THE DERIVATIVES FOR THE HEIGHTS, HA AND HB
      DHADT=(W0*XA-FA*RHOA)*(1./(RHOA*S))
      DHBDT=(W0*(1.-XA)-FB*RHOB)*(1./(RHOB*S))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    HA,    HB
     2      /F/ DHADT, DHBDT
     3      /C/    W0,    XA,  RHOA,  RHOB,     S,    KA,    KB,    FA,
     4             FB
      REAL         KA,    KB
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.0.1)WRITE(NO,1)
1     FORMAT(9X,1HT,10X,2HHA,7X,5HDHADT,10X,2HFA,10X,2HHB,7X,5HDHBDT,10X
     2,2HFB,10X,2HW0)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,HA,DHADT,FA,HB,DHBDT,FB,W0
2     FORMAT(F10.1,7E12.3)
      RETURN
      END
DYNAMICS OF A DECANTER - NO DISTURBANCE
0.        25.       0.25
    2  500    8    1  REL 0.001
DYNAMICS OF A DECANTER - STEP CHANGE AT T = 0 AND 5 MIN
0.        25.       0.25
    2  500    8    1  REL 0.001
END OF RUNS
*APP SEP06
      SUBROUTINE INITAL
C...
C...  DYNAMIC MODEL OF A THREE-STAGE MIXER-SETTLER SYSTEM
C...
C...  CONSIDER THE THREE-STAGE MIXER-SETTLER SYSTEM DIAGRAMMED BELOW
C...
C
C                      CH2                   CH3
C       CL0 ......  ..........            ..........        ....... CH4
C                .  .        .  CL1       .        .  CL2   .
C                .  .     .. . .....      .     .. . .....  .
C                .  .     .  .     .      .     .  .     .  .
C                +  +     .  .     +      +     .  .     +  +
C           .         .   .  .   .          .   .  .   .         .
C           .         .   .  .   .          .   .  .   .         .
C           .    .    .   .  .   .     .    .   .  .   .    .    .
C           ...........   .  .   ............   .  .   ...........
C           .    .    .   .  .   .     .    .   .  .   .    .    .
C           .    .    .   .  .   .     .    .   .  .   .    .    .
C   MIXERS  .    .    .   .  .   .     .    .   .  .   .    .    .
C           .   ...   .   .  .   .    ...   .   .  .   .   ...   .
C           .   ...   .   .  .   .    ...   .   .  .   .   ...   .
C           ...........   .  .   ............   .  .   ...........
C                .        .  .         .        .  .        .
C                .        .  .         .        .  .        .
C                .        .  .         .        .  .        .
C                .        .  .         .        .  .        .
C                +        .  .         +        .  .        +
C           .         .   .  .   .          .   .  .   .         .
C           .         .   .  .   .          .   .  .   .         .
C  SETTLERS .         .   .  .   .          .   .  .   .         .
C           ...........   .  .   ............   .  .   ...........  CL3
C           .         .....  .   .          .....  .   .         ....+
C      CH1  ...........      .   ............      .   ...........
C       +....         .      .....          .      .....         .
C           ...........          ............          ...........
C
C...
C...  THE DIFFERENTIAL EQUATIONS WHICH MODEL THE SYSTEM ARE
C...
C...
C...     D(VL1*CL1 + VH1*CH1)/DT = FL0*CL0 + FH2*CH2
C...                                                                 (1)
C...                             - FL1*CL1 - FH1*CH1
C...
C...     D(VL2*CL2 + VH2*CH2)/DT = FL1*CL1 + FH3*CH3
C...                                                                 (2)
C...                             - FL2*CL2 - FH2*CH2
C...
C...     D(VL3*CL3 + VH3*CH3)/DT = FL2*CL2 + FH4*CH4
C...                                                                 (3)
C...                             - FL3*CL3 - FH3*CH3
C...
C...  A SIMPLE LINEAR EQUILIBRIUM RELATIONSHIP IS ASSUMED FOR THE
C...  LIGHT AND HEAVY PHASES
C...
C...     CL1 = D*CH1, CL2 = D*CH2, CL3 = D*CH3                       (4)
C...
C...  ALSO, THE FLOW RATE OF THE LIGHT AND HEAVY PHASES IS ASSUMED
C...  CONSTANT THROUGHOUT THE SYSTEM SO THAT THE VOLUME (HOLDUP) OF
C...  THE LIGHT AND HEAVY PHASES WITHIN THE SYSTEM IS CONSTANT, I.E.,
C...
C...     FL0 = FL1 = FL2 = FL3                                       (5)
C...
C...     FH1 = FH2 = FH3 = FH4                                       (6)
C...
C...     VL1 = VL2 = VL3                                             (7)
C...
C...     VH1 = VH2 = VH3                                             (8)
C...
C...  THE INITIAL CONDITIONS FOR EQUATIONS (1), (2) AND (3) (ASSUMING
C...  THE HEAVY PHASE CONCENTRATIONS ARE THE ODE DEPENDENT VARIABLES)
C...  ARE
C...
C...     CH1(0) = CH2(0) = CH3(0) = 0                                (9)
C...
C...  I.E., THE SYSTEM STARTS OUT WITH NO SOLUTE.
C...
C...  TWO CASES ARE PROGRAMMED
C...
C...     (1)  D = 0 (NORUN = 1)
C...
C...     (2)  D = 1 (NORUN = 2)
C...
C...  COMMON AREA FOR THREE DEPENDENT VARIABLES
      COMMON/T/    T,     NSTOP,     NORUN
     1 /Y/       CH1,       CH2,       CH3
     2 /F/    DCH1DT,    DCH2DT,    DCH3DT
     3 /C/       FL0,       FL1,       FL2,       FL3,
     4           FH1,       FH2,       FH3,       FH4,
     5           VL1,       VL2,       VL3,
     6           VH1,       VH2,       VH3,
     7             D,       CL0,       CH4,        IP
C...
C...  SET THE MODEL PARAMETERS
C...
C...  FLOW RATES OF THE LIGHT PHASE
      FL0=1.
      FL1=1.
      FL2=1
      FL3=1.
C...
C...  FLOW RATES OF THE HEAVY PHASE
      FH1=1.5
      FH2=1.5
      FH3=1.5
      FH4=1.5
C...
C...  VOLUMES OF THE LIGHT PHASE
      VL1=1.
      VL2=1.
      VL3=1.
C...
C...  VOLUMES OF THE HEAVY PHASE
      VH1=1.
      VH2=1.
      VH3=1.
C...
C...  SET THE INPUT CONCENTRATIONS (NOTE THAT CH4 IS THE DISTURBANCE TO
C...  THE SYSTEM)
      CL0=0.
      CH4=1.
C...
C...  SET THE DISTRIBUTION COEFFICIENT FOR TWO CASES
      IF(NORUN.EQ.1)D=0.
      IF(NORUN.EQ.2)D=1.0
C...
C...  SET THE MODEL INITIAL CONDITIONS
      CH1=0.
      CH2=0.
      CH3=0.
C...
C...  PERFORM THE INITIAL CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
C...
C...  INITIALIZE THE COUNTER FOR THE PLOTTED OUTPUT USED IN
C...  SUBROUTINE PRINT
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/    T,     NSTOP,     NORUN
     1 /Y/       CH1,       CH2,       CH3
     2 /F/    DCH1DT,    DCH2DT,    DCH3DT
     3 /C/       FL0,       FL1,       FL2,       FL3,
     4           FH1,       FH2,       FH3,       FH4,
     5           VL1,       VL2,       VL3,
     6           VH1,       VH2,       VH3,
     7             D,       CL0,       CH4,        IP
C...
C...  MODEL ALGEBRA
      CL1=D*CH1
      CL2=D*CH2
      CL3=D*CH3
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DCH1DT=(1./(VL1*D+VH1))*(FL0*CL0+FH2*CH2-FL1*CL1-FH1*CH1)
      DCH2DT=(1./(VL2*D+VH2))*(FL1*CL1+FH3*CH3-FL2*CL2-FH2*CH2)
      DCH3DT=(1./(VL3*D+VH3))*(FL2*CL2+FH4*CH4-FL3*CL3-FH3*CH3)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/    T,     NSTOP,     NORUN
     1 /Y/       CH1,       CH2,       CH3
     2 /F/    DCH1DT,    DCH2DT,    DCH3DT
     3 /C/       FL0,       FL1,       FL2,       FL3,
     4           FH1,       FH2,       FH3,       FH4,
     5           VL1,       VL2,       VL3,
     6           VH1,       VH2,       VH3,
     7             D,       CL0,       CH4,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED OUTPUT
      DIMENSION TP(41),CP(4,41)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(11X,1HT,6X,6HCL0(T),6X,6HCH4(T),6X,6HCH1(T),6X,6HCL3(T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      CL3=D*CH3
      WRITE(NO,2)T,CL0,CH4,CH1,CL3
2     FORMAT(5F12.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      CP(1,IP)=CL0
      CP(2,IP)=CH4
      CP(3,IP)=CH1
      CP(4,IP)=CL3
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION AT THE END OF THE RUN
      IF(IP.LT.41)RETURN
      CALL TPLOTS(4,IP,TP,CP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,//,11H 1 - CL0(T),5X,11H 2 - CH4(T),
     1           5X,11H 3 - CH1(T),5X,11H 4 - CL3(T))
      RETURN
      END
THREE-STAGE MIXER SETTLER, D = 0
0.        10.0      0.25
    3 1000    1    1  REL 0.001
THREE-STAGE MIXER SETTLER, D = 1
0.        10.0      0.25
    3 1000    1    1  REL 0.001
END OF RUNS
*APP SEP07
      SUBROUTINE INITAL
C...
C...  MULTICOMPONENT CHROMATOGRAPHIC SEPARATION
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) ARE DERIVED
C...  FOR AN ISOTHERMAL CHROMATOGRAPHIC COLUMN WHICH IS INTENDED FOR
C...  THE SEPARATION OF TWO COMPONENTS INJECTED AT THE ENTRANCE OF THE
C...  COLUMN
C...
C...  COMPONENT 1 FLUID BALANCE
C...
C...     A*DZ*EPS*RHOF*C1  = -V*A*EPS*RHOF*(C1     - C1 )
C...                     T                    Z+DZ     Z
C...                                                                (1)
C...                                                         E
C...                         -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...  THIS EQUATION IS A COMPONENT 1 FLUID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*EPS*RHOF*C1
C...                     T
C...
C...        ACCUMULATION OF COMPONENT 1 IN THE FLUID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 FLUID/CM**3 COLUM
C...                  (MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/MOL FLUID)*
C...                  (1/SEC) = MOLS COMP 1/SEC
C...
C...     -V*A*EPS*RHOF*(C1     - C1 )
C...                      Z+DZ     Z
C...
C...        NET FLOW OF COMPONENT 1 INTO THE SECTION OF LENGTH DZ
C...
C...        UNITS     (M COLUMN/SEC)*(CM**2 COLUMN)*(CM**3 FLUID/CM**3
C...                  COLUMN)*(MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/
C...                  MOLS FLUID) = MOLS COMP 1/SEC
C...
C...                                     E
C...     -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...        NET TRANSFER OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUM
C...                  *(GM SOLID/CM**3 SOLID)*(MOLS COMP 1/GM COMP 1)
C...                  *(GM COMP 1/GM SOLID) = MOLS COMP 1/SEC
C...
C...  WHERE
C...
C...     C1     MOLAR CONCENTRATION OF COMPONENT 1 (MOLS COMP 1/MOL
C...            FLUID)
C...
C...     Z      AXIAL POSITION ALONG THE COLUMN (M COLUMN)
C...
C...     T      TIME (SEC)
C...
C...     A      COLUMN CROSS SECTIONAL AREA (CM**2 COLUMN)
C...
C...     EPS    COLUMN VOID FRACTION (CM**3 FLUID/CM**3 COLUMN)
C...
C...     RHOF   FLUID MOLAR DENSITY (MOLS FLUID/CM**3 FLUID)
C...
C...     RHOS   SOLID MASS DENSITY (GM SOLID/CM**3 SOLID)
C...
C...     V      FLUID VELOCITY (M COLUMN/SEC)
C...
C...     KP1    FLUID TO SOLID MASS TRANSFER COEFFICIENT FOR COMPONENT 1
C...            (1/SEC)
C...
C...     MW1    MOLECULAR WEIGHT OF COMPONENT 1 (GM COMP 1/MOL COMP 1)
C...
C...       E    EQUILIBRIUM SOLID CONCENTRATION OF COMPONENT 1 (GM COMP
C...     Q1     1/GM SOLID)
C...
C...     Q1     SOLID CONCENTRATION OF COMPONENT 1 (GM COMP 1/GM SOLID)
C...
C...  DIVISION BY A*DZ*EPS*RHOF, FOLLOWED BY DZ ---+ 0 GIVES
C...
C...                                                       E
C...     C1  = -V*C1  - (1-EPS)*RHOS/(EPS*RHOF*MW1)*KP1*(Q1  - Q1)  (2)
C...       T        Z
C...
C...  COMPONENT 1 SOLID BALANCE
C...
C...                                                     E
C...    A*DZ*(1-EPS)*RHOS*Q1  = A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)    (3)
C...                        T
C...
C...  THIS EQUATION IS A COMPONENT 1 SOLID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*(1-EPS)*RHOS*Q1
C...                         T
C...
C...        ACCUMULATION OF COMPONENT 1 ON THE SOLID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(GM COMP 1/GM SOLID)*(1/SEC)
C...                 = GM COMP 1/SEC
C...
C...                              E
C...     A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)
C...
C...        NET FLOW OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(1/SEC)*(GM COMP 1/GM SOLID)
C...                 = GM COMP 1/SEC
C...
C...  WHERE ALL OF THE PARAMETERS AND VARIABLES WERE DEFINED PREVIOUSLY.
C...
C...  DIVISION BY A*DZ*(1-EPS)*RHOS GIVES
C...
C...                  E
C...     Q1  = KP1*(Q1  - Q1)                                       (4)
C...       T
C...
C...  EQUATION (2) REQUIRES AN INITIAL CONDITION AND A BOUNDARY
C...  CONDITION
C...
C...     C1(0,T) = F1(T), C1(Z,0) = C10                          (5)(6)
C...
C...  WHILE EQUATION (4) REQUIRES AN INITIAL CONDITION
C...
C...     Q1(Z,0) = Q10    (7)
C...
C...  ALSO, THE EQUILIBRIUM SOLID CONCENTRATION IS GIVEN BY A LINEAR
C...  ISOTHERM
C...
C...       E
C...     Q1  = QA1*K1*C1                                            (8)
C...
C...  A SIMILAR SET OF EQUATIONS CAN BE WRITTEN FOR COMPONENT 2.  THEN
C...  THE MODEL FOR THE CHROMATOGRAPHIC SYSTEM CONSISTS OF TWO PARTIAL
C...  DIFFERENTIAL EQUATIONS (PDES) FOR THE FLUID, TWO PDES FOR THE
C...  SOLID, TWO BOUNDARY CONDITIONS, FOUR INITIAL CONDITIONS AND TWO
C...  EQUILIBRIUM RELATIONSHIPS.
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     EPS = 0.360, ZL = 100, V = 1.0, RHOF = 0.01, RHOS = 0.8,
C...
C...     KP1 = KP2 = 1, K1 = 1, K2 = 0.3, QA1 = 2.90, QA2 = 3.67
C...
C...     C10 = C20 = 1.0E-15, Q10 = Q20 = 1.0E-15, MW1 = MW2 = 142
C...
C...     N = 21
C...
C...     F1(T) = F2(T) = 0.03, 0 LE T LE 30
C...
C...     F1(T) = F2(T) = 0, T GT 30
C...
C...  THE EXITING CONCENTRATIONS, C1(ZL,T) AND C2(ZL,T), ARE OF PARTI-
C...  CULAR INTEREST IN THIS SIMULATION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2,
     1                MW1,       MW2
C...
C...  SET THE MODEL PARAMETERS
      EPS=0.360
      ZL=100.
      V=1.
      RHOF=0.01
      RHOS=0.8
      KP1=1.0
      KP2=1.0
      K1=1.0
      K2=0.3
      QA1=2.90
      QA2=3.67
      MW1=142.
      MW2=142.
      C10=1.0E-15
      C20=1.0E-15
      Q10=1.0E-15
      Q20=1.0E-15
      N=21
      IP=0
C...
C...  COMPUTE SOME CONSTANTS TO BE USED IN DERV
      P1=(1.-EPS)*RHOS/(EPS*RHOF*MW1)*KP1
      P2=(1.-EPS)*RHOS/(EPS*RHOF*MW2)*KP2
      P3=KP1
      P4=KP2
      QA1=QA1*K1
      QA2=QA2*K2
C...
C...  SET THE INITIAL FLUID CONCENTRATIONS
      DO 1 I=1,N
      C1(I)=C10
      C2(I)=C20
      Q1(I)=Q10
      Q2(I)=Q20
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2
C...
C...  MODEL BOUNDARY CONDITIONS
      C1(1)=0.
      C2(1)=0.
      IF(T.LE.30.)C1(1)=0.03
      IF(T.LE.30.)C2(1)=0.03
C...
C...  SET CONSTRAINTS ON THE CONCENTRATIONS
      DO 1 I=1,N
      IF(C1(I).LT.0.)C1(I)=0.
      IF(C2(I).LT.0.)C2(I)=0.
      IF(Q1(I).LT.0.)Q1(I)=0.
      IF(Q2(I).LT.0.)Q2(I)=0.
1     CONTINUE
C...
C...  COMPUTE THE EQUILIBRIUM SOLID CONCENTRATIONS
      CALL EQUIL(N,C1,QE1,QA1,K1)
      CALL EQUIL(N,C2,QE2,QA2,K2)
C...
C...  COMPUTE THE SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,C1,DC1DZ,1.)
      CALL DSS020(0.,ZL,N,C2,DC2DZ,1.)
C...
C...  MODEL PDES
      DO 2 I=1,N
      DC1DT(I)=-V*DC1DZ(I)-P1*(QE1(I)-Q1(I))
      DC2DT(I)=-V*DC2DZ(I)-P2*(QE2(I)-Q2(I))
      DQ1DT(I)=P3*(QE1(I)-Q1(I))
      DQ2DT(I)=P4*(QE2(I)-Q2(I))
2     CONTINUE
      DC1DT(1)=0.
      DC2DT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   TP(101), CP(4,101)
C...
C...  PRINT THE SOLUTION AT THE BEGINNING AND END OF EACH RUN
      IF((IP.NE.0).AND.(IP.NE.100))GO TO 2
      N2=1
      WRITE(NO,1)T,(C1(I),I=1,N,N2),(C2(I),I=1,N,N2),
     1             (Q1(I),I=1,N,N2),(Q2(I),I=1,N,N2)
1     FORMAT(11H          T,F7.1,//,
     1       11H    C1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     2                              5E11.3,/,5E11.3,//,
     3       11H    C2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     4                              5E11.3,/,5E11.3,//,
     5       11H    Q1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     6                              5E11.3,/,5E11.3,//,
     7       11H    Q2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     8                              5E11.3,/,5E11.3,//)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2     IP=IP+1
      CP(1,IP)=C1(1)
      CP(2,IP)=C2(1)
      CP(3,IP)=C1(N)
      CP(4,IP)=C2(N)
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(4,IP,TP,CP)
      WRITE(NO,3)
3     FORMAT(1H ,//,13H 1 - C1(0.,T),3X,13H 2 - C2(0.,T),/,
     1              13H 3 - C1(ZL,T),3X,13H 4 - C2(ZL,T))
5     CONTINUE
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR THE USER*S LOCAL COMPUTER OR DE-
C...  ACTIVATED (CONVERTED TO COMMENTS)
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,100.,7.,-0.005,0.005)
C...  CALL QIKPLT(TP,CP,101,12H*TIME (SEC)*,
C... 1            29H*C1(Z,T), C2(Z,T), Z = 0, ZL*,2H**,4)
C...
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE EQUIL(N,C,QE,QA,K)
C...
C...  SUBROUTINE COMPUTES THE EQUILIBRIUM SOLID CONCENTRATION
C...
C...  ARGUMENT LIST
C...
C...     N        NUMBER OF COMPONENTS (INPUT)
C...
C...     C        ONE-DIMENSIONAL ARRAY OF FLUID CONCENTRATIONS
C...              (INPUT)
C...
C...     QE       ONE-DIMENSIONAL ARRAY OF EQUILIBRIUM SOLID
C...              CONCENTRATIONS (OUTPUT)
C...
C...     QA       SOLID CAPACITANCE (INPUT)
C...
C...     K        CONSTANT IN THE ADSORPTION ISOTHERM (INPUT)
C...

      DIMENSION C(N),QE(N)
      REAL K
C...
C...  COMPUTE THE EQUILIBRIUM SOLID CONCENTRATIONS FOR THE N COMPONENTS
C...  (NOTE - A SIMPLE LINEAR EQUILIBRIUM ISOTHERM IS USED IN DO LOOP
C...  1.  HOWEVER, ANY ADSORPTION ISOTHERM CAN BE PROGRAMMED, INCLUDING
C...  A MULTICOMPONENT, NONLINEAR ISOTHERM.  PERHAPS ADDITIONAL ADSORP-
C...  TION CONSTANTS WILL HAVE TO BE PASSED TO THE SUBROUTINE FROM THE
C...  CALLING PROGRAM, BUT THE COMPLEXITY OF THE ISOTHERM IS, IN PRIN-
C...  CIPLE, ESSENTIALLY UNLIMITED)
      DO 1 I=1,N
      QE(I)=QA*C(I)
1     CONTINUE
      RETURN
      END
MULTICOMPONENT CHROMATOGRAPHIC SEPARATION
0.        500.      5.
   8410000    1    1  ABS 0.001
END OF RUNS
*APP SEP08
      SUBROUTINE INITAL
C...
C...  STARTUP AND CONTROL OF A PLATE ABSORBER
C...
C...  AN 8-TRAY TOWER IS BEING PLANNED TO REMOVE NH3 FROM AIR USING
C...  WATER AT A RATE OF 0.1 LB MOL/SEC.  THE ENTERING GAS CONTAINS
C...  4 O/O NH3 AND ITS FLOW RATE IS REGULATED WITH A PI CONTROLLER
C...  SO THAT THE NH3 CONCENTRATION IN THE EXITING GAS IS 0.1 O/O.
C...  INITIALLY, THERE ARE 0.1 LB MOLS OF WATER ON EACH TRAY.  THE
C...  MOLAR LIQUID FLOW RATE, LN, OUT OF EACH TRAY IS GIVEN BY
C...
C...               LN = 0.2*(HN - 2.5)**1.5
C...
C...  WHERE HN IS THE MOLAR LIQUID HOLDUP ON TRAY N.  THUS A MINIMUM
C...  OF 2.5 LB MOLS OF LIQUID IS NEEDED ON EACH TRAY BEFORE LIQUID
C...  STARTS FLOWING FROM EACH TRAY.  THE EQUILIBRIUM RELATIONSHIP
C...  AT THE CONDITIONS IN THE COLUMN IS
C...
C...                      Y = 0.78*X
C...
C...  THE MOLAR FLOW RATE OF THE ENTERING GAS IS GIVEN BY
C...
C...                      VO = 0.2*Z
C...
C...           Z = 0.5 + 10*(E + (1/20)*INT(E*DT))
C...
C...                     E = YSET - Y8
C...
C...  THUS, THE CONTROLLER GAIN, AKC, INTEGRAL TIME, TI, AND SET
C...  POINT, YSET, ARE 10, 20 AND 0.001, RESPECTIVELY.  INT(E*DT)
C...  DENOTES THE INTEGRAL OF E WITH RESPECT TO T.  THE MODEL PRO-
C...  GRAMMED IN SUBROUTINE DERV IS BASED ON THE ASSUMPTIONS
C...
C...                    IDEAL TRAYS
C...
C...                    NEGLIGIBLE GAS HOLDUP
C...
C...                    ISOTHERMAL OPERATION
C...
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  SET THE MODEL PARAMETERS
      FN=0.1
      HMIN=2.5
      YSET=0.001
      WEIR=0.2
      AKC=10.
      RTI=1./20.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 K=1,8
C...
C...  SET THE INITIAL TOTAL LIQUID HOLDUPS ON THE TRAYS
      H(K)=0.1
C...
C...  SET THE INITIAL NH3 HOLDUPS ON THE TRAYS ((TOTAL HOLDUP)*
C...  NH3 MOL FRACTION IN THE LIQUID) = HX)
      HX(K)=0.
    1 CONTINUE
C...
C...  SET THE INITIAL INTEGRAL OF THE ERROR, INT(E*DT)
      EI=0.
C...
C...  SET THE ENTERING GAS AND LIQUID COMPOSITIONS
      YO=0.04
      XN=0.
C...
C...  INITIALIZE THE CALCULATIONS IN DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  MODEL ALGEBRA
      DO 2 K=1,8
C...
C...  LIQUID COMPOSITIONS, X(K), FROM THE PRODUCTS H(K)*X(K) (=
C...  HX(K)) AND THE LIQUID HOLDUPS, H(K)
      X(K)=HX(K)/H(K)
C...
C...  GAS COMPOSITIONS
      Y(K)=0.78*X(K)
C...
C...  LIQUID FLOW RATES
      FL(K)=0.
      IF(H(K).GT.HMIN)FL(K)=WEIR*(SQRT(H(K)-HMIN))**3
2     CONTINUE
C...
C...  CONTROLLER ERROR, DERIVATIVE OF THE INTEGRAL INT(E*DT)
      ERROR=YSET-Y(8)
      DEIDT=ERROR
C...
C...  GAS FLOW RATE ENTERING THE TOWER
      VO=0.2*(0.5+AKC*(ERROR+RTI*EI))
      IF(VO.LT.0.)VO=0.
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MATERIAL BALANCE
C...
C...        DH(N)/DT = L(N+1) - L(N)
C...
C...     COMPONENT (NH3) BALANCE
C...
C...        D(H(N)*X(N))/DT = L(N+1)*X(N+1) + VO*Y(N-1)
C...
C...                        - L(N)*X(N) - VO*Y(N)
C...
C...     WHERE N = 1, 2,..., 8 FOR THE EIGHT TRAYS
C...
C...  TRAY 1
      DHDT(1)=FL(2)-FL(1)
      DHXDT(1)=FL(2)*X(2)+VO*YO-FL(1)*X(1)-VO*Y(1)
C...
C...  TRAY 8
      DHDT(8)=FN-FL(8)
      DHXDT(8)=FN*XN+VO*Y(7)-FL(8)*X(8)-VO*Y(8)
C...
C...  TRAYS 2 TO 7
      DO 1 K=2,7
      DHDT(K)=FL(K+1)-FL(K)
      DHXDT(K)=FL(K+1)*X(K+1)+VO*Y(K-1)-FL(K)*X(K)-VO*Y(K)
    1 CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NF,NR/Y/HX(8),H(8),EI/F/DHXDT(8),DHDT(8),DEIDT
      COMMON/C/VO,FN,HMIN,YSET,AKC,RTI,WEIR,YO,XN,Y(8),X(8),FL(8)
C...
C...  DIMENSION THE ARRAYS FOR STORING THE PLOTTED SOLUTION
      DIMENSION EP(101), X1P(101), VP(101), Y8P(101), TP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY SECOND CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/2*2).NE.(IP-1))GO TO 2
      WRITE(NO,1)T,VO,(Y(I),I=1,8),(X(I),I=1,8),(H(I),I=1,8),
     1                (FL(I),I=1,8)
1     FORMAT(1H ,//,5H T = ,F5.0,5X,5HVO = ,F8.5,/,
     1              5H Y = ,8E11.3,/,
     2              5H X = ,8E11.3,/,
     3              5H H = ,8E11.3,/,
     4              5H L = ,8E11.3,/)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2      EP(IP)=DEIDT
      X1P(IP)=X(1)
       VP(IP)=VO
      Y8P(IP)=Y(8)
       TP(IP)=T
C...
C...  AT THE END OF THE RUN, PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,26H ERROR (MOL FR) VS T (SEC))
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,23H X1 (MOL FR) VS T (SEC))
      CALL TPLOTS(1,IP,TP,VP)
      WRITE(NO,12)
12    FORMAT(1H ,//,24H V (MOLS/SEC) VS T (SEC))
      CALL TPLOTS(1,IP,TP,Y8P)
      WRITE(NO,13)
13    FORMAT(1H ,//,23H Y8 (MOL FR) VS T (SEC))
      IP=0
      RETURN
      END
PLATE ABSORBER
0.        3000.     30.
   17 1000    1    1  REL 0.001
END OF RUNS
*APP SEP09
      SUBROUTINE INITAL
C...
C...  ABSORPTION WITH CHEMICAL REACTION IN A TRAY COLUMN
C...
C...   THE FOLLOWING EQUATIONS MODEL A TRAY ABSORBER IN WHICH A
C...   FIRST-ORDER REACTION TAKES PLACE WITHIN THE LIQUID PHASE
C...
C...          K
C...      A -----+ B
C...
C...      TOTAL MATERIAL BALANCE ON TRAY N
C...
C...      D(H  + G )/DT = L    - L  + V    - V                       (1)
C...         N    N        N+1    N    N-1    N
C...
C...      COMPONENT A BALANCE
C...
C...      D(H XA  + G YA )/DT = L   BXA   - L XA
C...         N  N    N  N        N+1   N+1   N  N
C...                                                                 (2)
C...                          + V  BYA    - V YA  - H KXA
C...                             N-1  N-1    N  N    N   N
C...
C...      COMPONENT B BALANCE
C...
C...      D(H XB  + G YB )/DT = L   BXB   - L XB
C...         N  N    N  N        N+1   N+1   N  N
C...                                                                 (3)
C...                          + V  BYB    - V YB  + H KXA
C...                             N-1  N-1    N  N    N   N
C...
C...   THE LIQUID FLOW FROM PLATE N, L , IS GIVEN BY THE WEIR EQUATION
C...                                  N
C...                       3/2
C...      L  = K1*(H  - H*)                                          (4)
C...       N        N
C...
C...   WHERE H* IS THE MINIMUM LIQUID HOLDUP ON THE TRAY FOR FLOW OVER
C...   THE WEIR TO OCCUR.
C...
C...   THE GAS LEAVING ANY TRAY CAN BE ASSUMED TO BE IN EQUILIBRIUM WITH
C...   THE LIQUID LEAVING THE TRAY ACCORDING TO THE EQUILIBRIUM RELA-
C...   TIONSHIPS
C...
C...      YA  = ALPHA*XA                                             (5)
C...        N           N
C...
C...      YB  =  BETA*XB                                             (6)
C...        N           N
C...
C...   ASSUME THAT THE GAS PHASE HOLDUP, G , IS NEGLIGIBLE IN COMPARISON
C...                                      N
C...   WITH THE LIQUID PHASE HOLDUP, H , AND THEREFORE THE GAS FLOW RATE
C...                                  N
C...   THROUGH THE COLUMN IS CONSTANT, I.E., V  = V  = ... V  = V .
C...                                          1    2        N    0
C...
C...   THE MODEL VARIABLES, PARAMETERS AND CONSTANTS ARE SUMMARIZED
C...   BELOW
C...
C...    K        REACTION RATE CONSTANT (1/SEC)
C...
C...    H        LIQUID HOLDUP ON TRAY N (MOLS)
C...     N
C...
C...    G        GAS HOLDUP ABOVE TRAY N (MOLS)
C...     N
C...
C...    L        LIQUID FLOWRATE FROM TRAY N (MOLS/SEC)
C...     N
C...
C...    V        GAS FLOWRATE FROM TRAY N (MOLS/SEC)
C...     N
C...
C...    XA       CONCENTRATION OF COMPONENT A IN THE LIQUID ON
C...             TRAY N (MOLS A/MOL LIQUID)
C...
C...    YA       CONCENTRATION OF COMPONENT A IN THE GAS LEAVING
C...      N      TRAY N (MOLS A/MOLD GAS)
C...
C...    XB       CONCENTRATION OF COMPONENT B IN THE LIQUID ON
C...      N      TRAY N (MOLS A/MOL LIQUID)
C...
C...    YB       CONCENTRATION OF COMPONENT B IN THE GAS LEAVING
C...      N      TRAY N (MOLS B/MOL GAS)
C...
C...    T        TIME (SEC)
C...
C...    K1       PROPORTIONALITY CONSTANT IN THE WEIR EQUATION
C...             (MOLS/SEC)/(MOLS**1.5)
C...
C...    H*       MINIMUM LIQUID HOLDUP ON A TRAY FOR FLOW FROM THE
C...             TRAY TO OCCUR (MOLS)
C...
C...    ALPHA    CONSTANT IN THE COMPONENT A EQUILIBRIUM RELATIONSHIP
C...
C...    BETA     CONSTANT IN THE COMPONENT B EQUILIBRIUM RELATIONSHIP
C...
C...    V        MOLAR GAS RATE THROUGH THE TOWER (MOLS/SEC)
C...     0
C...
C...   THE NUMERICAL VALUES OF THE MODEL CONSTANTS AND PARAMETERS ARE
C...
C...      ENTERING GAS COMPOSITIONS - YA = 0.01, YB = 0
C...
C...      ENTERING LIQUID COMPOSITIONS - XA = 0, XB = 0
C...
C...      K1 = 0.1, H* = 1, ALPHA = 1.5, BETA = 2.0, K = 1, V0 = 1
C...
C...   THE ENTERING LIQUID FLOW RATE IS L(NT+1) = 1 WHERE NT = 15 IS
C...   THE TOTAL NUMBER OF TRAYS.  INITIALLY THE HOLDUP ON EACH TRAY
C...   IS 0.01 AND THE GAS AND LIQUID HAVE NO A OR B.
C...
C...   THE EXITING LIQUID AND GAS COMPOSITIONS AS A FUNCTION OF TIME
C...   ARE THE MODEL OUTPUTS OF PARTICULAR INTEREST.
C...
      COMMON/T/           T,       NSTOP,       NORUN
     1      /Y/       H(15),     HXA(15),     HXB(15)
     2      /F/    DHDT(15),  DHXADT(15),  DHXBDT(15)
     3      /C/      XA(15),      XB(15),      YA(15),     YB(15),
     4                  YA0,         YB0,         XAN,        XBN,
     5                   K1,          HS,       ALPHA,       BETA,
     6                    K,          V0,          LN,      L(15),
     7                    N,          IP
      REAL               K1,           K,          LN,          L
C...
C...  SET THE MODEL CONSTANTS
      YA0=0.01
      YB0=0.
      XAN=0.
      XBN=0.
      K1=0.1
      HS=1.0
      ALPHA=1.5
      BETA =2.0
      K=1.0
      V0=1.0
      LN=1.0
      N=15
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      H(I)=0.01
      HXA(I)=0.
      HXB(I)=0.
1     CONTINUE
      IP=0
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/           T,       NSTOP,       NORUN
     1      /Y/       H(15),     HXA(15),     HXB(15)
     2      /F/    DHDT(15),  DHXADT(15),  DHXBDT(15)
     3      /C/      XA(15),      XB(15),      YA(15),     YB(15),
     4                  YA0,         YB0,         XAN,        XBN,
     5                   K1,          HS,       ALPHA,       BETA,
     6                    K,          V0,          LN,      L(15),
     7                    N,          IP
      REAL               K1,           K,          LN,          L
C...
C...  MODEL ALGEBRA
C...
C...  LIQUID COMPOSITIONS
      DO 1 I=1,N
      XA(I)=HXA(I)/H(I)
      XB(I)=HXB(I)/H(I)
      IF(XA(I).LT.0.)XA(I)=0.
      IF(XA(I).GT.1.)XA(I)=1.
      IF(XB(I).LT.0.)XB(I)=0.
      IF(XB(I).GT.1.)XB(I)=1.
1     CONTINUE
C...
C...  GAS COMPOSITIONS
      DO 2 I=1,N
      YA(I)=ALPHA*XA(I)
      YB(I)= BETA*XB(I)
2     CONTINUE
C...
C...  LIQUID FLOW RATES
      DO 3 I=1,N
      IF(H(I).LT.HS)L(I)=0.
      IF(H(I).GE.HS)L(I)=K1*(H(I)-HS)**1.5
3     CONTINUE
C...
C...  TWO STARTUP CONDITIONS ARE SIMULATED
      IF(NORUN.EQ.1)GO TO 5
      IF(NORUN.EQ.2)LN=FLOWIN(H(1))
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...  TRAY 1
5     DHDT(1)=L(2)-L(1)
      DHXADT(1)=L(2)*XA(2)-L(1)*XA(1)+V0*YA0-V0*YA(1)-H(1)*K*XA(1)
      DHXBDT(1)=L(2)*XB(2)-L(1)*XB(1)+V0*YB0-V0*YB(1)+H(1)*K*XA(1)
C...
C...  TRAYS 2 TO N-1
      NM1=N-1
      DO 4 I=2,NM1
      DHDT(I)=L(I+1)-L(I)
      DHXADT(I)=L(I+1)*XA(I+1)-L(I)*XA(I)+V0*YA(I-1)-V0*YA(I)
     1         -H(I)*K*XA(I)
      DHXBDT(I)=L(I+1)*XB(I+1)-L(I)*XB(I)+V0*YB(I-1)-V0*YB(I)
     1         +H(I)*K*XA(I)
4     CONTINUE
C...
C...  TRAY N
      DHDT(N)=LN-L(N)
      DHXADT(N)=LN*XAN-L(N)*XA(N)+V0*YA(N-1)-V0*YA(N)-H(N)*K*XA(N)
      DHXBDT(N)=LN*XBN-L(N)*XB(N)+V0*YB(N-1)-V0*YB(N)+H(N)*K*XA(N)
      RETURN
      END
      FUNCTION FLOWIN(H1)
C...
C...  FUNCTION FLOWIN SIMULATES THE STARTUP OF THE ABSORPTION TOWER BY
C...  SETTING A HIGH INLET LIQUID FLOWRATE UNTIL THE HOLDUP ON THE
C...  BOTTOM TRAY EXCEEDS THE MINIMUM VALUE FOR LIQUID FLOW FROM THE
C...  BOTTOM TRAY.
C...
C...  ARGUMENT LIST
C...
C...     H1  HOLDUP ON THE BOTTOM TRAY (TRAY 1) (INPUT)
C...
      IF(H1.LE.1.0)FLOWIN=10.
      IF(H1.GT.1.0)FLOWIN=1.0
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/           T,       NSTOP,       NORUN
     1      /Y/       H(15),     HXA(15),     HXB(15)
     2      /F/    DHDT(15),  DHXADT(15),  DHXBDT(15)
     3      /C/      XA(15),      XB(15),      YA(15),     YB(15),
     4                  YA0,         YB0,         XAN,        XBN,
     5                   K1,          HS,       ALPHA,       BETA,
     6                    K,          V0,          LN,      L(15),
     7                    N,          IP
      REAL               K1,           K,          LN,          L
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION     TP(101),  XAP(2,101),  XBP(2,101),
     1                        YAP(2,101),  YBP(2,101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,3)
3     FORMAT(9X,1HT,7X,5HXA(1),7X,5HXB(1),7X,5HYA(N),7X,5HYB(N),/,
     1      10X,7X,5H H(1),7X,5H H(5),7X,5HH(10),7X,5HH(15),/,
     2      10X,7X,5H L(1),7X,5H L(5),7X,5HL(10),7X,5HL(15),//)
      IP=IP+1
C...
C...  PRINT THE NUMERICAL SOLUTION
      IF((IP-1)/10*10.NE.(IP-1))GO TO 2
      WRITE(NO,1)T,XA(1),XB(1),YA(N),YB(N),
     1              H(1), H(5),H(10), H(N),
     2              L(1), L(5),L(10), L(N)
1     FORMAT(F10.1,4F12.7,/,10X,4F12.7,/,10X,4F12.7,/)
C...
C...  STORE THE SOLUTION FOR PLOTTING
2     TP(IP)=T
      XAP(1,IP)=XA(N)
      XBP(1,IP)=XB(N)
      XAP(2,IP)=XA(1)
      XBP(2,IP)=XB(1)
      YAP(1,IP)=YA(1)
      YBP(1,IP)=YB(1)
      YAP(2,IP)=YA(N)
      YBP(2,IP)=YB(N)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(2,IP,TP,XAP)
      WRITE(NO,11)
11    FORMAT(1H ,//,27H 1 - XA(N)   2 - XA(1) VS T)
      CALL TPLOTS(2,IP,TP,XBP)
      WRITE(NO,12)
12    FORMAT(1H ,//,27H 1 - XB(N)   2 - XB(1) VS T)
      CALL TPLOTS(2,IP,TP,YAP)
      WRITE(NO,13)
13    FORMAT(1H ,//,27H 1 - YA(1)   2 - YA(N) VS T)
      CALL TPLOTS(2,IP,TP,YBP)
      WRITE(NO,14)
14    FORMAT(1H ,//,27H 1 - YB(1)   2 - YB(N) VS T)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR USE ON OTHER COMPUTERS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,XAP,IP,3H*T*,4H*XA*,2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,XBP,IP,3H*T*,4H*XB*,2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YAP,IP,3H*T*,4H*YA*,2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,YBP,IP,3H*T*,4H*YB*,2H**,2)
C...
C...  ******************************************************************
C...
      RETURN
      END
ABSORPTION WITH CHEMICAL REACTION IN A TRAY TOWER
0.        20.0      0.2
   45 1000    1    1  REL 0.001
ABSORPTION WITH CHEMICAL REACTION IN A TRAY TOWER
0.        150.      1.5
   45 1000    1    1  REL 0.001
END OF RUNS
*APP SEP10
      SUBROUTINE INITAL
C...
C...  PACKED COLUMN ABSORBER DYNAMICS
C...
C...  32 LB MOLS/HR OF A GAS MIXTURE CONTAINING 6 PERCENT SO2 AND
C...  94 PERCENT DRY AIR IS TO BE SCRUBBED COUNTERCURRENTLY WITH
C...  2170 LB MOLS/HR OF FRESH WATER IN A PACKED COLUMN.  INITIALLY,
C...  THE CONCENTRATION OF SO2 IN THE GAS AND LIQUID PHASES IN THE
C...  COLUMN IS ZERO.  THE COLUMN OPERATES ISOTHERMALLY AT 87 F AND
C...  1 ATM.  TWO EQUILBRIUM RELATIONS ARE TO BE INVESTIGATED
C...
C...      *
C...     Y  = 296*X**1.33 (NONLINEAR EQUILIBRIUM)
C...
C...      *
C...     Y  = 25.7*X - 0.00063 (LINEAR EQUILIBRIUM)
C...
C...                                  *
C...  THUS, TWO RUNS ARE PROGRAMMED (Y  IS THE GAS COMPOSITION IN
C...  EQUILIBRIUM WITH THE LIQUID COMPOSITION X).
C...
C...  THE PACKED COLUMN IS 10 FT HIGH AND HAS A CROSS-SECTIONAL AREA
C...  OF 5 FT**2.  THE MOLAR LIQUID AND GAS HOLDUPS PER UNIT VOLUME
C...  OF COLUMN ARE 0.5 AND 0.01 LB MOLS/FT**3, RESPECTIVELY.  THE
C...  OVERALL MASS TRANSFER COEFFICIENT AT THESE CONDITIONS IS
C...
C...     KY*AV = 5.8 LB MOLS/(HR-MOL FRACTION-FT**3 COLUMN)
C...
C...  THE EXITING CONCENTRATIONS, X(0,T) AND Y(ZL,T), ARE TO BE
C...  COMPUTED AS A FUNCTION OF TIME.
C...
C...  THE MATHEMATICAL MODEL FOR THE COLUMN CONSISTS OF TWO SIMUL-
C...  TANEOUS MATERIAL BALANCE PDES
C...
C...     H*X  = (L/S)*X  - KY*AV*(Y* - Y)                       (1)
C...        T          Z
C...
C...     G*Y  = (V/S)*Y  + KY*AV*(Y* - Y)                       (2)
C...        T          Z
C...
C...  WHERE
C...
C...     T     TIME, HR
C...
C...     Z     DISTANCE FROM THE GAS INLET, FT
C...
C...     Y     MOL FRACTION OF SOLUTE (SO2) IN THE GAS
C...
C...     X     MOL FRACTION OF SOLUTE (SO2) IN THE LIQUID
C...
C...     S     COLUMN CROSS-SECTIONAL AREA, FT**2
C...
C...     V     GAS MOLAR FLOW RATE, LB MOL/HR
C...
C...     L     LIQUID MOLAR FLOW RATE, LB MOL/HR
C...
C...     G     GAS MOLAR HOLDUP PER UNIT VOLUME OF COLUMN,
C...           LB MOLS/FT**3
C...
C...     H     LIQUID MOLAR HOLDUP PER UNIT VOLUME OF COLUMN,
C...           LB MOLS/FT**3
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATIONS (1) AND (2)
C...  ARE
C...
C...     X(Z,0) = X1(Z), X(ZL,T) = X2(T)                        (3)(4)
C...
C...     Y(Z,0) = Y1(Z), Y( 0,T) = Y2(T)                        (5)(6)
C...
C...  WHERE X1(Z) AND Y1(Z) ARE FUNCTIONS OF Z DEFINED BY THE PROBLEM
C...  STATEMENT, AND X2(T) AND Y2(T) ARE FUNCTIONS OF T DEFINED BY THE
C...  PROBLEM STATEMENT, I.E.,
C...
C...     X1(Z) = 0, X2(T) = 0
C...
C...     Y1(Z) = 0, Y2(T) = 0.06
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     X(11),     Y(11)
     2      /F/  DXDT(11),  DYDT(11)
     3      /S/  DXDZ(11),  DYDZ(11)
     4      /P/         A,         B,         C,         D,        Y1,
     5                 XN,        ZL,         N,        IP
C...
C...  SET THE COLUMN LENGTH
      ZL=10.
C...
C...  SET THE ENTERING LIQUID AND GAS COMPOSITIONS
      XN=0.
      Y1=0.06
C...
C...  SET THE INITIAL LIQUID AND GAS COMPOSITIONS
      N=11
      DO 1 J=1,N
      X(J)=0.
      Y(J)=0.
1     CONTINUE
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN THE PDES IN SUBROUTINE DERV
      A=2170./(3600.*5.*0.5)
      B=5.8/(3600.*0.5)
      C=32./(3600.*5.*0.01)
      D=5.8/(3600.*0.01)
C...
C...  CALL SUBROUTINE DERV TO INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
C...
C...  INITIALIZE THE COUNTER FOR THE PLOTTED SOLUTION
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     X(11),     Y(11)
     2      /F/  DXDT(11),  DYDT(11)
     3      /S/  DXDZ(11),  DYDZ(11)
     4      /P/         A,         B,         C,         D,        Y1,
     5                 XN,        ZL,         N,        IP
C...
C...  DIMENSION THE ARRAY FOR THE EQUILIBRIUM GAS COMPOSITIONS
      DIMENSION YE(11)
C...
C...  SET ANY NEGATIVE LIQUID OR GAS COMPOSITIONS TO ZERO
      DO 3 J=1,N
      IF(X(J).LT.0.)X(J)=0.
      IF(Y(J).LT.0.)Y(J)=0.
3     CONTINUE
C...
C...  SET THE BOUNDARY (ENTERING) COMPOSITIONS
      X(N)=XN
      Y(1)=Y1
C...
C...  COMPUTE THE EQUILIBRIUM GAS COMPOSITIONS
      DO 1 J=1,N
C...
C...  USE A NONLINEAR (NORUN = 1) OR LINEAR (NORUN = 2) EQUILBRIUM
C...  RELATIONSHIP
      GO TO (11,12),NORUN
11    YE(J)=296.*X(J)**1.33
      GO TO 1
12    YE(J)=25.7*X(J)-0.00063
      IF(YE(J).LT.0.)YE(J)=0.
1     CONTINUE
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN THE PDES
      CALL DSS020(0.,ZL,N,X,DXDZ,-1)
      CALL DSS020(0.,ZL,N,Y,DYDZ, 1)
C...
C...  ASSEMBLE THE PDES
      DO 2 J=1,N
      DXDT(J)= A*DXDZ(J)-B*(YE(J)-Y(J))
      DYDT(J)=-C*DYDZ(J)+D*(YE(J)-Y(J))
2     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      DXDT(N)=0.
      DYDT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     X(11),     Y(11)
     2      /F/  DXDT(11),  DYDT(11)
     3      /S/  DXDZ(11),  DYDZ(11)
     4      /P/         A,         B,         C,         D,        Y1,
     5                 XN,        ZL,         N,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION   TP(101),  X1P(101),  YNP(101)
C...
C...  PRINT A HEADING AT THE BEGINNING OF THE RUN
      IF(IP.EQ.0)WRITE(NO,4)
4     FORMAT(1H ,/,2H T,/,5H X(J),/,5H Y(J))
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY FIFTH CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))
     1 WRITE(NO,1)T,(X(J),J=1,N),(Y(J),J=1,N)
1     FORMAT(1H ,//,F10.1,//,6F10.6,/,10X,5F10.6,
     1                    //,6F10.6,/,10X,5F10.6)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING.  ANY VALUES OF X AND Y
C...  WHICH ARE SLIGHTLY NEGATIVE ARE CONVERTED TO ZERO BY THE CALL TO
C...  AMAX1
      X1P(IP)=AMAX1(0.,X(1))
      YNP(IP)=AMAX1(0.,Y(N))
       TP(IP)=T
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,X1P)
      WRITE(NO,2)
2     FORMAT(1H ,//,28H  X(0,T) (MOL FR) VS T (SEC))
      CALL TPLOTS(1,IP,TP,YNP)
      WRITE(NO,3)
3     FORMAT(1H ,//,28H Y(ZL,T) (MOL FR) VS T (SEC))
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR USE ON THE LOCAL PLOTTER OR CONVERTED
C...  TO COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(6.,0.,50.,6.,0.,0.00015)
C...  CALL QIKPLT(TP,X1P,IP,9H*T (SEC)*,9H* X(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(6.,0.,50.,6.,0.,0.000006)
C...  CALL QIKPLT(TP,YNP,IP,9H*T (SEC)*,9H*Y(ZL,T)*,2H**,1)
C...  CALL QIKSET(3,3)
C...  CALL QIKSET(6.,0.,50.,6.,0.,0.01)
C...  CALL QIKPLT(TP,YNP,IP,9H*T (SEC)*,9H*Y(ZL,T)*,2H**,1)
C...
C...  ******************************************************************
C...
      RETURN
      END
PACKED COLUMN ABSORBER DYNAMICS, NONLINEAR EQUILIBRIUM RELATIONSHIP
0.        300.      3.
   22 1000    1    1  ABS 0.000001
PACKED COLUMN ABSORBER DYNAMICS, LINEAR EQUILIBRIUM RELATIONSHIP
0.        300.      3.
   22 1000    1    1  ABS 0.000001
END OF RUNS
*APP SEP11
      SUBROUTINE INITAL
C...
C...  MULTICOMPONENT CHROMATOGRAPHIC SEPARATION WITH COSINE PULSE INPUT
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) ARE DERIVED
C...  FOR AN ISOTHERMAL CHROMATOGRAPHIC COLUMN WHICH IS INTENDED FOR
C...  THE SEPARATION OF TWO COMPONENTS INJECTED AT THE ENTRANCE OF THE
C...  COLUMN
C...
C...  COMPONENT 1 FLUID BALANCE
C...
C...     A*DZ*EPS*RHOF*C1  = -V*A*EPS*RHOF*(C1     - C1 )
C...                     T                    Z+DZ     Z
C...                                                                (1)
C...                                                         E
C...                         -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...  THIS EQUATION IS A COMPONENT 1 FLUID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*EPS*RHOF*C1
C...                     T
C...
C...        ACCUMULATION OF COMPONENT 1 IN THE FLUID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 FLUID/CM**3 COLUM
C...                  (MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/MOL FLUID)*
C...                  (1/SEC) = MOLS COMP 1/SEC
C...
C...     -V*A*EPS*RHOF*(C1     - C1 )
C...                      Z+DZ     Z
C...
C...        NET FLOW OF COMPONENT 1 INTO THE SECTION OF LENGTH DZ
C...
C...        UNITS     (M COLUMN/SEC)*(CM**2 COLUMN)*(CM**3 FLUID/CM**3
C...                  COLUMN)*(MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/
C...                  MOLS FLUID) = MOLS COMP 1/SEC
C...
C...                                     E
C...     -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...        NET TRANSFER OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUM
C...                  *(GM SOLID/CM**3 SOLID)*(MOLS COMP 1/GM COMP 1)
C...                  *(GM COMP 1/GM SOLID) = MOLS COMP 1/SEC
C...
C...  WHERE
C...
C...     C1     MOLAR CONCENTRATION OF COMPONENT 1 (MOLS COMP 1/MOL
C...            FLUID)
C...
C...     Z      AXIAL POSITION ALONG THE COLUMN (M COLUMN)
C...
C...     T      TIME (SEC)
C...
C...     A      COLUMN CROSS SECTIONAL AREA (CM**2 COLUMN)
C...
C...     EPS    COLUMN VOID FRACTION (CM**3 FLUID/CM**3 COLUMN)
C...
C...     RHOF   FLUID MOLAR DENSITY (MOLS FLUID/CM**3 FLUID)
C...
C...     RHOS   SOLID MASS DENSITY (GM SOLID/CM**3 SOLID)
C...
C...     V      FLUID VELOCITY (M COLUMN/SEC)
C...
C...     KP1    FLUID TO SOLID MASS TRANSFER COEFFICIENT FOR COMPONENT 1
C...            (1/SEC)
C...
C...     MW1    MOLECULAR WEIGHT OF COMPONENT 1 (GM COMP 1/MOL COMP 1)
C...
C...       E    EQUILIBRIUM SOLID CONCENTRATION OF COMPONENT 1 (GM COMP
C...     Q1     1/GM SOLID)
C...
C...     Q1     SOLID CONCENTRATION OF COMPONENT 1 (GM COMP 1/GM SOLID)
C...
C...  DIVISION BY A*DZ*EPS*RHOF, FOLLOWED BY DZ ---+ 0 GIVES
C...
C...                                                       E
C...     C1  = -V*C1  - (1-EPS)*RHOS/(EPS*RHOF*MW1)*KP1*(Q1  - Q1)  (2)
C...       T        Z
C...
C...  COMPONENT 1 SOLID BALANCE
C...
C...                                                     E
C...    A*DZ*(1-EPS)*RHOS*Q1  = A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)    (3)
C...                        T
C...
C...  THIS EQUATION IS A COMPONENT 1 SOLID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*(1-EPS)*RHOS*Q1
C...                         T
C...
C...        ACCUMULATION OF COMPONENT 1 ON THE SOLID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(GM COMP 1/GM SOLID)*(1/SEC)
C...                 = GM COMP 1/SEC
C...
C...                              E
C...     A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)
C...
C...        NET FLOW OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(1/SEC)*(GM COMP 1/GM SOLID)
C...                 = GM COMP 1/SEC
C...
C...  WHERE ALL OF THE PARAMETERS AND VARIABLES WERE DEFINED PREVIOUSLY.
C...
C...  DIVISION BY A*DZ*(1-EPS)*RHOS GIVES
C...
C...                  E
C...     Q1  = KP1*(Q1  - Q1)                                       (4)
C...       T
C...
C...  EQUATION (2) REQUIRES AN INITIAL CONDITION AND A BOUNDARY
C...  CONDITION
C...
C...     C1(0,T) = F1(T), C1(Z,0) = C10                          (5)(6)
C...
C...  WHILE EQUATION (4) REQUIRES AN INITIAL CONDITION
C...
C...     Q1(Z,0) = Q10    (7)
C...
C...  ALSO, THE EQUILIBRIUM SOLID CONCENTRATION IS GIVEN BY A LINEAR
C...  ISOTHERM
C...
C...       E
C...     Q1  = QA1*K1*C1                                            (8)
C...
C...  A SIMILAR SET OF EQUATIONS CAN BE WRITTEN FOR COMPONENT 2.  THEN
C...  THE MODEL FOR THE CHROMATOGRAPHIC SYSTEM CONSISTS OF TWO PARTIAL
C...  DIFFERENTIAL EQUATIONS (PDES) FOR THE FLUID, TWO PDES FOR THE
C...  SOLID, TWO BOUNDARY CONDITIONS, FOUR INITIAL CONDITIONS AND TWO
C...  EQUILIBRIUM RELATIONSHIPS.
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     EPS = 0.360, ZL = 100, V = 1.0, RHOF = 0.01, RHOS = 0.8,
C...
C...     KP1 = KP2 = 1, K1 = 1, K2 = 0.3, QA1 = 2.90, QA2 = 3.67,
C...
C...     C10 = C20 = 1.0E-15, Q10 = Q20 = 1.0E-15, MW1 = MW2 = 142,
C...
C...     N=21
C...
C...     F1(T) = F2(T) = COSINE, 0 LE T LE 30
C...                      PULSE
C...
C...     F1(T) = F2(T) = 0, T GT 30
C...
C...  THE ENTERING CONCENTRAIONS, C1(0,T) AND C2(0,T), THEREFORE ARE
C...  A PULSE IN TIME, T, CONSISTING OF TWO COSINES PIECED TOGETHER
C...  AND COVERING THE INTERVAL 0 LE T LE 30.  THE COSINE PULSE IS COM-
C...  PUTED BY THE FUNCTION FXPC CALLED IN SUBROUTINE DERV, AND IS PLOT-
C...  TED IN SUBROUTINE PRINT.
C...
C...  THE EXITING CONCENTRATIONS, C1(ZL,T) AND C2(ZL,T), ARE OF PARTI-
C...  CULAR INTEREST IN THIS SIMULATION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2,
     1                MW1,       MW2
C...
C...  SET THE MODEL PARAMETERS
      EPS=0.360
      ZL=100.
      V=1.
      RHOF=0.01
      RHOS=0.8
      KP1=1.0
      KP2=1.0
      MW1=142.
      MW2=142.
      K1=1.0
      K2=0.3
      QA1=2.90
      QA2=3.67
      C10=1.0E-15
      C20=1.0E-15
      Q10=1.0E-15
      Q20=1.0E-15
      N=21
      IP=0
C...
C...  COMPUTE SOME CONSTANTS TO BE USED IN DERV
      P1=(1.-EPS)*RHOS/(EPS*RHOF*MW1)*KP1
      P2=(1.-EPS)*RHOS/(EPS*RHOF*MW2)*KP2
      P3=KP1
      P4=KP2
      QA1=QA1*K1
      QA2=QA2*K2
C...
C...  SET THE INITIAL FLUID CONCENTRATIONS
      DO 1 I=1,N
      C1(I)=C10
      C2(I)=C20
      Q1(I)=Q10
      Q2(I)=Q20
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2
C...
C...  MODEL BOUNDARY CONDITIONS
      C1(1)=0.03*FXPC(0.,30.,0.,T)
      C2(1)=0.03*FXPC(0.,30.,0.,T)
C...
C...  SET CONSTRAINTS ON THE CONCENTRATIONS
      DO 1 I=1,N
      IF(C1(I).LT.0.)C1(I)=0.
      IF(C2(I).LT.0.)C2(I)=0.
      IF(Q1(I).LT.0.)Q1(I)=0.
      IF(Q2(I).LT.0.)Q2(I)=0.
1     CONTINUE
C...
C...  COMPUTE THE EQUILIBRIUM SOLID CONCENTRATIONS
      CALL EQUIL(N,C1,QE1,QA1,K1)
      CALL EQUIL(N,C2,QE2,QA2,K2)
C...
C...  COMPUTE THE SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,C1,DC1DZ,1.)
      CALL DSS020(0.,ZL,N,C2,DC2DZ,1.)
C...
C...  MODEL PDES
      DO 2 I=1,N
      DC1DT(I)=-V*DC1DZ(I)-P1*(QE1(I)-Q1(I))
      DC2DT(I)=-V*DC2DZ(I)-P2*(QE2(I)-Q2(I))
      DQ1DT(I)=P3*(QE1(I)-Q1(I))
      DQ2DT(I)=P4*(QE2(I)-Q2(I))
2     CONTINUE
      DC1DT(1)=0.
      DC2DT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/ DC1DT(21), DC2DT(21), DQ1DT(21), DQ2DT(21)
     3      /S/ DC1DZ(21), DC2DZ(21),   QE1(21),   QE2(21)
     4      /C/         N,        ZL,       QA1,       QA2,
     5                 P1,        P2,        P3,        P4,
     6                 K1,        K2,         V,        IP
      REAL            KP1,       KP2,        K1,        K2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   TP1(101),   TP2(101),
     1          CP1(2,101), CP2(4,101),
     2           QP(2,101)
C...
C...  PRINT THE SOLUTION AT THE BEGINNING AND END OF EACH RUN
      IF((IP.NE.0).AND.(IP.NE.100))GO TO 2
      N2=1
      WRITE(NO,1)T,(C1(I),I=1,N,N2),(C2(I),I=1,N,N2),
     1             (Q1(I),I=1,N,N2),(Q2(I),I=1,N,N2)
1     FORMAT(11H          T,F7.1,//,
     1       11H    C1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     2                              5E11.3,/,5E11.3,//,
     3       11H    C2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     4                              5E11.3,/,5E11.3,//,
     5       11H    Q1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     6                              5E11.3,/,5E11.3,//,
     7       11H    Q2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     8                              5E11.3,/,5E11.3,//)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2     IP=IP+1
      CP2(1,IP)=C1(1)
      CP2(2,IP)=C2(1)
      CP2(3,IP)=C1(N)
      CP2(4,IP)=C2(N)
      QP(1,IP)=Q1(N)
      QP(2,IP)=Q2(N)
      TP2(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(4,IP,TP2,CP2)
      WRITE(NO,3)
3     FORMAT(1H ,/,13H 1 - C1( 0,T),3X,13H 2 - C2( 0,T)
     1          ,/,13H 3 - C1(ZL,T),3X,13H 4 - C2(ZL,T))
      CALL TPLOTS(2,IP,TP2,QP)
      WRITE(NO,4)
4     FORMAT(1H ,//,13H 1 - Q1(ZL,T),/,
     1              13H 2 - Q2(ZL,T))
C...
C...  STORE THE INPUT FUNCTIONS, C1(0,T) AND C2(0,T), FOR SUBSEQUENT
C...  PLOTTING
      DO 5 I=1,101
      TP1(I)=100.*FLOAT(I-1)/FLOAT(101-1)
      CP1(1,I)=0.03*FXPC(0.,30.,40.,TP1(I))
      CP1(2,I)=0.03*FXPC(0.,30.,40.,TP1(I))
5     CONTINUE
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND WILL HAVE TO BE CONVERTED FOR USE ON THE LOCAL PLOTTER OR
C...  CONVERTED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0., 20.,7.,-0.005,0.005)
C...  CALL QIKPLT(TP1,CP1,101,12H*TIME (SEC)*,
C... 1            18H*C1(0,T), C2(0,T)*,2H**,2)
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,100.,7.,-0.005,0.005)
C...  CALL QIKPLT(TP2,CP2,101,12H*TIME (SEC)*,
C... 1            29H*C1(Z,T), C2(Z,T), Z = 0, ZL*,2H**,4)
C...
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE EQUIL(N,C,QE,QA,K)
C...
C...  SUBROUTINE EQUIL CALCULATES THE EQUILIBRIUM SOLID CONCENTRATION
C...  FROM A LINEAR ISOTHERM.
C...
C...  ARGUMENT LIST
C...
C...     N         NUMBER OF SPATIAL GRID POINTS (USED IN THE VARIABLE
C...               DIMENSION) (INPUT)
C...
C...     C         ONE-DIMENSIONAL ARRAY CONTAINING THE FLUID CONCEN-
C...               TRATIONS (INPUT)
C...
C...     QE        ONE-DIMENSIONAL ARRAY CONTAINING THE EQUILIBRIUM
C...               SOLID CONCENTRATIONS (INPUTS)
C...
C...     QA        SOLID CAPACITANCE (INPUT)
C...
C...     K         EQUILIBRIUM ISOTHERM CONSTANT (INPUT)
C...
      DIMENSION C(N),QE(N)
      REAL K
C...
C...  STEP THROUGH THE N SPATIAL GRID POINTS
      DO 1 I=1,N
C...
C...  CALCULATE THE EQUILBRIUM SOLID CONCENTRATION AT GRID POINT I
C...  (NOTE CONSTANT K, WHICH APPEARS IN THE DEMONINATOR OF A NON-
C...  LINEAR ISOTHERM, E.G., A LANGMUIR ISOTHERM, IS NOT USED HERE
C...  BECAUSE THIS IS AN APPROXIMATE LINEAR ISOTHERM.  THE ISOTHERM
C...  COULD BE EXTENDED AS QE(I)=QA*C(I)/(1 + K*C(I)), BUT FOR THIS
C...  PROBLEM, THE LINEAR ISOTHERM IS A GOOD APPROXIMATION, AND SAVES
C...  COMPUTER TIME (SINCE THE DENOMINATOR 1 + K*C(I) IS NOT USED))
      QE(I)=QA*C(I)
1     CONTINUE
      RETURN
      END
      REAL FUNCTION FXPC(S,F,G,X)
C...
C...  FXPC = FUNCTION OF X FOR A PULSE FORMED FROM A COSINE
C...         -           -       -                   -
C...
C...  FUNCTION FXPC COMPUTES A PULSE BASED ON A COSINE
C...
C...  ARGUMENT LIST
C...
C...     S         THE DISPLACEMENT OF THE PULSE IN X AND T (SEE THE
C...               CALCULATION OF S IN FUNCTIONS FXAC AND FXDC) (INPUT)
C...
C...     F         WIDTH OF THE TWO COSINE SECTIONS OF THE PULSE (INPUT)
C...
C...     G         WIDTH OF THE CONSTANT SECTION OF THE PULSE (INPUT)
C...
C...     X         ARGUMENT OF THE COSINE PULSE (INPUT)
C...
C...  CALCULATE THE TOTAL WIDTH OF THE DISPLACED PULSE UP TO THE END
C...  OF THE CONSTANT SECTION
      D=S+F+G
C...
C...  IF X LE D, THE ASCENDING PORTION OF THE COSINE PULSE IS USED
C...  VIA FUNCTION FXAC
      IF(X.LE.D) FXPC=FXAC(S,F,X)
C...
C...  IF X GT D, THE DESCENDING PORTION OF THE COSINE PULSE IS USED
C...  VIA FUNCTION FXDC (BY GOING TO 10)
      IF(X.GT.D) GO TO 10
      RETURN
C...
C...  COMPUTE THE DISPLACEMENT OF THE DESCENDING PORTION OF THE COSINE
C...  PULSE
10    E=D+F
      FXPC=FXDC(E,F,X)
      RETURN
      END
      REAL FUNCTION FXAC(S,F,X)
C...
C...  FXAC = FUNCTION OF X FOR AN ASCENDING STEP BY A COSINE
C...         -           -        -                   -
C...
C...  FUNCTION FXAC COMPUTES AN ASCENDING STEP FUNCTION BASED ON A
C...  COSINE
C...
C...  ARGUMENT LIST
C...
C...     S         CURRENT VALUE OF T USED IN THE COSINE STEP (INPUT)
C...
C...     F         LENGTH OF THE COSINE SECTION OF THE STEP (INPUT)
C...
C...     X         CURRENT VALUE OF X USED IN THE COSINE STEP (INPUT)
C...
      PI=3.1415927
C...
C...  COMPUTE THE DISPLACEMENT OF THE STEP IN X AND T
      T=X-S
C...
C...  IF T LT 0, THE STEP IS STILL AT ITS INITIAL VALUE OF ZERO
C...  (OR 1.0E-20)
      IF(T.LE.0.) FXAC=1.E-20
C...
C...  IF T GE F, THE STEP HAS REACHED THE FINAL VALUE OF ONE
      IF(T.GE.F) FXAC=1.
C...
C...  IF T GT O AND LT F, THE COSINE SECTION OF THE STEP IS USED BY
C...  GOING TO 10
      IF(T.GT.0..AND.T.LT.F) GO TO 10
      RETURN
C...
C...  COMPUTE THE COSINE SECTION OF THE STEP
10    FXAC=0.5+COS(T*PI/F+PI)/2.
      RETURN
      END
      REAL FUNCTION FXDC(S,F,X)
C...
C...  FXDC = FUNCTION OF X FOR A DESCENDING STEP BY A COSINE
C...         -           -       -                    -
C...
C...  FUNCTION FXDC COMPUTES A DESCENDING STEP FUNCTION BASED ON A
C...  COSINE
C...
C...  ARGUMENT LIST
C...
C...     S         CURRENT VALUE OF T USED IN THE COSINE STEP (INPUT)
C...
C...     F         LENGTH OF THE COSINE SECTION OF THE STEP (INPUT)
C...
C...     X         CURRENT VALUE OF X USED IN THE COSINE STEP (INPUT)
C...
      PI=3.1415927
C...
C...  COMPUTE THE DISPLACEMENT OF THE STEP IN X AND T.  NOTE THAT
C...  IT IS OPPOSITE IN SIGN TO THE DISPLACEMENT USED IN FUNCTION
C...  FXAC SO THAT ESSENTIALLY THE SAME CODING CAN BE USED IN
C...  FUNCTIONS FXAC AND FXDC
      T=S-X
C...
C...  IF T LE O, THE COSINE STEP HAS REACHED ITS FINAL VALUE OF ZERO
C...  (OR 1.0E-20)
      IF(T.LE.0.) FXDC=1.E-20
C...
C...  IF T GE F, THE COSINE STEP STILL HAS ITS INITIAL VALUE OF ONE
      IF(T.GE.F) FXDC=1.
C...
C...  IF T GT 0 AND LT F, THE COSINE SECTION OF THE STEP IS USED BY
C...  GOING TO 10
      IF(T.GT.0..AND.T.LT.F) GO TO 10
      RETURN
C...
C...  COMPUTE THE COSINE SECTION OF THE STEP
10    FXDC=0.5+COS(T*PI/F+PI)/2.
      RETURN
      END
MULTICOMPONENT CHROMATOGRAPHIC SEPARATION
0.        500.      5.
   8410000    1    1  ABS 0.0001
END OF RUNS
*APP SEP12
      SUBROUTINE INITAL
C...
C...  PERFORMANCE OF A MOVING-BED ADSORPTION COLUMN
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) ARE DERIVED
C...  FOR AN ISOTHERMAL ADSORPTION COLUMN WHICH IS INTENDED FOR
C...  THE SEPARATION OF TWO COMPONENTS IN THE FEED TO THE COLUMN
C...
C...  COMPONENT 1 FLUID BALANCE
C...
C...     A*DZ*EPS*RHOF*C1  = -V*A*EPS*RHOF*(C1     - C1 )
C...                     T                    Z+DZ     Z
C...                                                                (1)
C...                                                         E
C...                         -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...  THIS EQUATION IS A COMPONENT 1 FLUID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*EPS*RHOF*C1
C...                     T
C...
C...        ACCUMULATION OF COMPONENT 1 IN THE FLUID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 FLUID/CM**3 COLUM
C...                  (MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/MOL FLUID)*
C...                  (1/SEC) = MOLS COMP 1/SEC
C...
C...     -V*A*EPS*RHOF*(C1     - C1 )
C...                      Z+DZ     Z
C...
C...        NET FLOW OF COMPONENT 1 INTO THE SECTION OF LENGTH DZ
C...
C...        UNITS     (M COLUMN/SEC)*(CM**2 COLUMN)*(CM**3 FLUID/CM**3
C...                  COLUMN)*(MOLS FLUID/CM**3 FLUID)*(MOLS COMP 1/
C...                  MOLS FLUID) = MOLS COMP 1/SEC
C...
C...                                     E
C...     -A*DZ*(1-EPS)*(RHOS/MW1)*KP1*(Q1  - Q1)
C...
C...        NET TRANSFER OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS     (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUM
C...                  *(GM SOLID/CM**3 SOLID)*(MOLS COMP 1/GM COMP 1)
C...                  *(GM COMP 1/GM SOLID) = MOLS COMP 1/SEC
C...
C...  WHERE
C...
C...     C1     MOLAR CONCENTRATION OF COMPONENT 1 (MOLS COMP 1/MOL
C...            FLUID)
C...
C...     Z      AXIAL POSITION ALONG THE COLUMN (M COLUMN)
C...
C...     T      TIME (SEC)
C...
C...     A      COLUMN CROSS SECTIONAL AREA (CM**2 COLUMN)
C...
C...     EPS    COLUMN VOID FRACTION (CM**3 FLUID/CM**3 COLUMN)
C...
C...     RHOF   FLUID MOLAR DENSITY (MOLS FLUID/CM**3 FLUID)
C...
C...     RHOS   SOLID MASS DENSITY (GM SOLID/CM**3 SOLID)
C...
C...     V      FLUID VELOCITY (M COLUMN/SEC)
C...
C...     KP1    FLUID TO SOLID MASS TRANSFER COEFFICIENT FOR COMPONENT 1
C...            (1/SEC)
C...
C...     MW1    MOLECULAR WEIGHT OF COMPONENT 1 (GM COMP 1/MOL COMP 1)
C...
C...       E    EQUILIBRIUM SOLID CONCENTRATION OF COMPONENT 1 (GM COMP
C...     Q1     1/GM SOLID)
C...
C...     Q1     SOLID CONCENTRATION OF COMPONENT 1 (GM COMP 1/GM SOLID)
C...
C...  DIVISION BY A*DZ*EPS*RHOF, FOLLOWED BY DZ ---+ 0 GIVES
C...
C...                                                       E
C...     C1  = -V*C1  - (1-EPS)*RHOS/(EPS*RHOF*MW1)*KP1*(Q1  - Q1)  (2)
C...       T        Z
C...
C...  COMPONENT 1 SOLID BALANCE
C...
C...     A*DZ*(1-EPS)*RHOS*Q1  = VS*A*(1-EPS)*RHOS*(Q1     - Q1 )
C...                         T                        Z+DZ     Z
C...                                                                (3)
C...                                                      E
C...                           + A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)
C...
C...  THIS EQUATION IS A COMPONENT 1 SOLID BALANCE ON A SECTION OF THE
C...  COLUMN OF LENGTH DZ.  THE TERMS IN THE EQUATION ARE
C...
C...     A*DZ*(1-EPS)*RHOS*Q1
C...                         T
C...
C...        ACCUMULATION OF COMPONENT 1 ON THE SOLID IN THE SECTION OF
C...        LENGTH DZ
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(GM COMP 1/GM SOLID)*(1/SEC)
C...                 = GM COMP 1/SEC
C...
C...     VS*A*(1-EPS)*RHOS*(Q1     - Q1 )
C...                          Z+DZ     Z
C...
C...        NET FLOW OF COMPONENT 1 INTO THE SECTION OF LENGTH DZ
C...
C...        UNITS    (M COLUMN/SEC)*(CM**2 COLUMN)*(CM**3 SOLID/CM**3
C...                 COLUMN)*(GM SOLID/CM**3 SOLID)*(GM COMP 1/GM
C...                 SOLID) = GM COMP 1/SEC
C...
C...                              E
C...     A*DZ*(1-EPS)*RHOS*KP1*(Q1  - Q1)
C...
C...        NET FLOW OF COMPONENT 1 FROM THE SOLID TO THE FLUID
C...
C...        UNITS    (CM**2 COLUMN)*(M COLUMN)*(CM**3 SOLID/CM**3 COLUMN
C...                 (GM SOLID/CM**3 SOLID)*(1/SEC)*(GM COMP 1/GM SOLID)
C...                 = GM COMP 1/SEC
C...
C...  WHERE
C...
C...     VS     VELOCITY OF THE SOLID (M COLUMN/SEC)
C...
C...  DIVISION BY A*DZ*(1-EPS)*RHOS, FOLLOWED BY DZ ---+ 0 GIVES
C...
C...                           E
C...     Q1  = VS*Q1  + KP1*(Q1  - Q1)                              (4)
C...       T        Z
C...
C...  EQUATION (2) REQUIRES AN INITIAL CONDITION AND A BOUNDARY
C...  CONDITION
C...
C...     C1(0,T) = F1(T), C1(Z,0) = C10                          (5)(6)
C...
C...  SIMILARLY, EQUATION (4) REQUIRES AN INITIAL CONDITION AND A
C...  BOUNDARY CONDITION
C...
C...     Q1(ZL,0) = F2(T), Q1(Z,0) = Q10                         (7)(8)
C...
C...  ALSO, THE EQUILIBRIUM SOLID CONCENTRATION IS GIVEN BY A LINEAR
C...  ISOTHERM
C...
C...       E
C...     Q1  = QA1*K1*C1                                            (9)
C...
C...  ALTHOUGH A NONLINEAR EQUILIBRIUM RELATIONSHIP COULD BE USED JUST
C...  AS EASILY BECAUSE OF THE NUMERICAL PROCEDURE USED IN THE SOLUTION
C...  OF THE MODEL EQUATIONS, E.G., A NONLINEAR, MULTICOMPONENT LANGMUIR
C...  ISOTHERM.
C...
C...  A SIMILAR SET OF EQUATIONS CAN BE WRITTEN FOR COMPONENT 2.  THEN
C...  THE MODEL FOR THE ADSORPTION SYSTEM CONSISTS OF TWO PARTIAL
C...  DIFFERENTIAL EQUATIONS (PDES) FOR THE FLUID, TWO PDES FOR THE
C...  SOLID, FOUR BOUNDARY CONDITIONS, FOUR INITIAL CONDITIONS AND TWO
C...  EQUILIBRIUM RELATIONSHIPS.
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     EPS = 0.360, ZL = 100, V = 1, RHOF = 0.01, RHOS = 0.8,
C...
C...     KP1 = KP2 = 1, K1 = 1, K2 = 0.3, QA1 = 2.90, QA2 = 3.67
C...
C...     C10 = C20 = 1.0E-15, Q10 = Q20 = 1.0E-15, MW1 = MW2 = 142,
C...
C..      N = 21, VS TO BE INVESTIGATED
C...
C...     F1(T) = 0.03, F2(T) = 0
C...
C...  THE EXITING CONCENTRATIONS C1(ZL,T), C2(ZL,T), Q1(ZL,T) AND
C...  Q2(ZL,T) ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/   C1T(21),   C2T(21),   Q1T(21),   Q2T(21)
     3      /S/   C1Z(21),   C2Z(21),   Q1Z(21),   Q2Z(21)
     4      /C/   QE1(21),   QE2(21),         V,        VS,
     5                 ZL,       QA1,       QA2,        P1,
     6                 P2,        P3,        P4,       KP1,
     7                KP2,        K1,        K2,        IP,
     8                  N
      REAL            KP1,       KP2,        K1,        K2,
     1                MW1,       MW2
C...
C...  SET THE MODEL PARAMETERS
      EPS=0.360
      ZL=100.
      V=1.
C...
C...  THE SOLIDS VELOCITY IS CHANGED IN THREE RUNS
      IF(NORUN.EQ.1)VS=0.
      IF(NORUN.EQ.2)VS=0.1
      IF(NORUN.EQ.3)VS=1.0
      RHOF=0.01
      RHOS=0.8
      KP1=1.0
      KP2=1.0
      MW1=142.
      MW2=142.
      K1=1.0
      K2=0.3
      QA1=2.90
      QA2=3.67
      C10=1.0E-15
      C20=1.0E-15
      Q10=1.0E-15
      Q20=1.0E-15
      N=21
      IP=0
C...
C...  COMPUTE SOME CONSTANTS TO BE USED IN DERV
      P1=(1.-EPS)*RHOS/(EPS*RHOF*MW1)*KP1
      P2=(1.-EPS)*RHOS/(EPS*RHOF*MW2)*KP2
      P3=KP1
      P4=KP2
      QA1=QA1*K1
      QA2=QA2*K2
C...
C...  SET THE INITIAL FLUID CONCENTRATIONS
      DO 1 I=1,N
      C1(I)=C10
      C2(I)=C20
      Q1(I)=Q10
      Q2(I)=Q20
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/   C1T(21),   C2T(21),   Q1T(21),   Q2T(21)
     3      /S/   C1Z(21),   C2Z(21),   Q1Z(21),   Q2Z(21)
     4      /C/   QE1(21),   QE2(21),         V,        VS,
     5                 ZL,       QA1,       QA2,        P1,
     6                 P2,        P3,        P4,       KP1,
     7                KP2,        K1,        K2,        IP,
     8                  N
      REAL            KP1,       KP2,        K1,        K2,
     1                MW1,       MW2
C...
C...  MODEL BOUNDARY CONDITIONS
      C1(1)=0.03
      C2(1)=0.03
C...
C...  IF THE SOLIDS VELOCITY, VS, IS ZERO, A BOUNDARY CONDITION IS
C...  NOT REQUIRED FOR EQUATION (4)
      IF(VS.LT.1.0E-06)GO TO 3
      Q1(N)=0.
      Q2(N)=0.
C...
C...  SET CONSTRAINTS ON THE CONCENTRATIONS
3     DO 1 I=1,N
      IF(C1(I).LT.0.)C1(I)=0.
      IF(C2(I).LT.0.)C2(I)=0.
      IF(Q1(I).LT.0.)Q1(I)=0.
      IF(Q2(I).LT.0.)Q2(I)=0.
1     CONTINUE
C...
C...  COMPUTE THE EQUILIBRIUM SOLID CONCENTRATIONS
      CALL EQUIL(N,C1,QE1,QA1,K1)
      CALL EQUIL(N,C2,QE2,QA2,K2)
C...
C...  COMPUTE THE SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,C1,C1Z, 1.)
      CALL DSS020(0.,ZL,N,C2,C2Z, 1.)
      CALL DSS020(0.,ZL,N,Q1,Q1Z,-1.)
      CALL DSS020(0.,ZL,N,Q2,Q2Z,-1.)
C...
C...  MODEL PDES
      DO 2 I=1,N
      C1T(I)=-V*C1Z(I)-P1*(QE1(I)-Q1(I))
      C2T(I)=-V*C2Z(I)-P2*(QE2(I)-Q2(I))
      Q1T(I)=VS*Q1Z(I)+P3*(QE1(I)-Q1(I))
      Q2T(I)=VS*Q2Z(I)+P4*(QE2(I)-Q2(I))
2     CONTINUE
      C1T(1)=0.
      C2T(1)=0.
C...
C...  IF THE SOLIDS VELOCITY, VS, IS ZERO, A BOUNDARY CONDITION IS
C...  NOT REQUIRED FOR EQUATION (4)
      IF(VS.LT.1.0E-06)RETURN
      Q1T(N)=0.
      Q2T(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    C1(21),    C2(21),    Q1(21),    Q2(21)
     2      /F/   C1T(21),   C2T(21),   Q1T(21),   Q2T(21)
     3      /S/   C1Z(21),   C2Z(21),   Q1Z(21),   Q2Z(21)
     4      /C/   QE1(21),   QE2(21),         V,        VS,
     5                 ZL,       QA1,       QA2,        P1,
     6                 P2,        P3,        P4,       KP1,
     7                KP2,        K1,        K2,        IP,
     8                  N
      REAL            KP1,       KP2,        K1,        K2,
     1                MW1,       MW2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   TP(101), CP(4,101), QP(4,101)
C...
C...  PRINT THE SOLUTION AT THE BEGINNING AND END OF EACH RUN
      IF((IP.NE.0).AND.(IP.NE.100))GO TO 2
      N2=1
      WRITE(NO,1)T,(C1(I),I=1,N,N2),(C2(I),I=1,N,N2),
     1             (Q1(I),I=1,N,N2),(Q2(I),I=1,N,N2)
1     FORMAT(11H          T,F7.1,//,
     1       11H    C1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     2                              5E11.3,/,5E11.3,//,
     3       11H    C2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     4                              5E11.3,/,5E11.3,//,
     5       11H    Q1(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     6                              5E11.3,/,5E11.3,//,
     7       11H    Q2(Z,T),E11.3,/,5E11.3,/,5E11.3,/,
     8                              5E11.3,/,5E11.3,//)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2     IP=IP+1
      CP(1,IP)=C1(1)
      CP(2,IP)=C2(1)
      CP(3,IP)=C1(N)
      CP(4,IP)=C2(N)
      QP(1,IP)=Q1(N)
      QP(2,IP)=Q2(N)
      QP(3,IP)=Q1(1)
      QP(4,IP)=Q2(1)
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(4,IP,TP,CP)
      WRITE(NO,3)
3     FORMAT(1H ,//,13H 1 - C1(0.,T),3X,13H 2 - C2(0.,T),/,
     1              13H 3 - C1(ZL,T),3X,13H 4 - C2(ZL,T))
      CALL TPLOTS(4,IP,TP,QP)
      WRITE(NO,4)
4     FORMAT(1H ,//,13H 1 - Q1(ZL,T),3X,13H 2 - Q2(ZL,T),/,
     1              13H 3 - Q1(0.,T),3X,13H 2 - Q2(0.,T))
5     CONTINUE
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER PLOTTERS OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,100.,8.,-0.005,0.005)
C...  CALL QIKPLT(TP,CP,101,12H*TIME (SEC)*,
C... 1            29H*C1(Z,T), C2(Z,T), Z = 0, ZL*,2H**,4)
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,100.,8.,-0.015,0.015)
C...  CALL QIKPLT(TP,QP,101,12H*TIME (SEC)*,
C... 1            29H*Q1(Z,T), Q2(Z,T), Z = 0, ZL*,2H**,4)
C...
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE EQUIL(N,C,QE,QA,K)
C...
C...  SUBROUTINE EQUIL CALCULATES THE EQUILIBRIUM SOLID CONCENTRATION
C...  FROM A LINEAR ISOTHERM.
C...
C...  ARGUMENT LIST
C...
C...     N         NUMBER OF SPATIAL GRID POINTS (USED IN THE VARIABLE
C...               DIMENSION) (INPUT)
C...
C...     C         ONE-DIMENSIONAL ARRAY CONTAINING THE FLUID CONCEN-
C...               TRATIONS (INPUT)
C...
C...     QE        ONE-DIMENSIONAL ARRAY CONTAINING THE EQUILIBRIUM
C...               SOLID CONCENTRATIONS (INPUTS)
C...
C...     QA        SOLID CAPACITANCE (INPUT)
C...
C...     K         EQUILIBRIUM ISOTHERM CONSTANT (INPUT)
C...
      DIMENSION C(N),QE(N)
      REAL K
C...
C...  STEP THROUGH THE N SPATIAL GRID POINTS
      DO 1 I=1,N
C...
C...  CALCULATE THE EQUILBRIUM SOLID CONCENTRATION AT GRID POINT I
C...  (NOTE CONSTANT K, WHICH APPEARS IN THE DEMONINATOR OF A NON-
C...  LINEAR ISOTHERM, E.G., A LANGMUIR ISOTHERM, IS NOT USED HERE
C...  BECAUSE THIS IS AN APPROXIMATE LINEAR ISOTHERM.  THE ISOTHERM
C...  COULD BE EXTENDED AS QE(I)=QA*C(I)/(1 + K*C(I)), BUT FOR THIS
C...  PROBLEM, THE LINEAR ISOTHERM IS A GOOD APPROXIMATION, AND SAVES
C...  COMPUTER TIME (SINCE THE DENOMINATOR 1 + K*C(I) IS NOT USED))
      QE(I)=QA*C(I)
1     CONTINUE
      RETURN
      END
MOVING-BED ADSORPTION COLUMN
0.        500.      5.
   8410000    1    1  ABS 0.0001
MOVING-BED ADSORPTION COLUMN
0.        500.      5.
   8410000    1    1  ABS 0.0001
MOVING-BED ADSORPTION COLUMN
0.        500.      5.
   8410000    1    1  ABS 0.0001
END OF RUNS
*APP SEP13
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
C...
C...  THE FOLLOWING EQUATIONS MODEL A BATCH DISTILLATION COLUMN WITH
C...  PI CONTROL OF THE DISTILLATE RATE
C...
C...  KETTLE       HB*DXB/DT = R*X1 - V*YB, XB(0) = XB0
C...
C...  PLATE 1      H*DX1/DT = R*X2 + V*YB - R*X1 - V*Y1, X1(0) = X10
C...
C...  PLATE 2      H*DX2/DT = R*X3 + V*Y1 - R*X2 - V*Y2, X2(0) = X20
C...
C...  PLATE N      H*DXN/DT = R*XD + V*YN-1 - R*XN - V*YN, XN(0) = XN0
C...
C...  CONDENSER    HC*DXD/DT = V*YN - R*XD - D*XD, XD(0) = XD0
C...
C...  EQUILIBRIUM  YN = A*XN/(1 + (A - 1)*XN)
C...
C...                                        T
C...  CONTROLLER   Z = ZS + KC*(E + (1/TI)*INT E*DT)
C...                                        0
C...               E = XD - XDSET
C...
C...               D = CV*Z*(HC**0.5)
C...
C...               R = V - D
C...
C...  WHERE
C...
C...     X1,X2,    LIQUID COMPOSITIONS ON TRAYS 1, 2 ..., N
C...     ...,XN
C...
C...     Y1,Y2,    VAPOR COMPOSITIONS ABOVE TRAYS 1, 2,..., N
C...     ...,YN
C...
C...     A         RELATIVE VOLATILITY
C...
C...     XB,XD     REBOILER, CONDENSER LIQUID COMPOSITIONS, RESPECTIVELY
C...
C...     XDSET     CONDENSER LIQUID COMPOSITION SET POINT
C...
C...     YB        COMPOSITION OF VAPOR FROM THE REBOILER
C...
C...     T         TIME
C...
C...     HB,H,HC   REBOILER HOLDUP, HOLDUPS ON TRAYS 1 TO N, CONDENSER
C...               HOLDUP, RESPECTIVELY
C...
C...     V         VAPOR BOILUP RATE
C...
C...     R         REFLUX RATE (LIQUID RATE)
C...
C...     D         DISTILLATE RATE
C...
C...     CV        CONTROL VALVE CONSTANT
C...
C...     Z         VALVE STEM POSITION
C...
C...     ZS        STEADY STATE VALVE STEM POSITION
C...
C...     KC        CONTROLLER GAIN
C...
C...     TI        CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN DISTILLATE COMPOSITION = XD - XDSET
C...
C...  THE PROBLEM IS BASICALLY TO SELECT THE CONTROLLER GAIN AND
C...  INTEGRAL TIME TO MAINTAIN SATISFACTORY CONTROL OF THE DISTILLATE
C...  COMPOSITION.  TWO FIGURES OF MERIT FOR THE CONTROLLER PERFORMANCE
C...  ARE TO BE COMPUTED
C...
C...           T              T
C...     I1 = INT D*DT, I2 = INT (XD*D)*DT
C...           0              0
C...
C...  INTEGRAL I2 GIVES THE TOTAL YIELD OF THE LIGHT COMPONENT (WITH
C...  MOL FRACTION XD IN THE DISTLLATE), AND THE RATIO I2/I1 GIVES THE
C...  TIME AVERAGE DISTILLATE COMPOSITION.  THESE INTEGRALS CAN BE
C...  EVALUATED BY PROGRAMMING THEM AS DIFFERENTIAL EQUATIONS, I.E.,
C...
C...    DI1/DT = D, I1(0) = 0, DI2/DT = XD*D, I2(0) = 0
C...
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  SET THE MODEL PARAMETERS
      N=10
      A=2.5
      V=5.
      H=0.5
      HC=3.
      HB=100.
      CV=2.309
      ZS=0.5
      XDSET=0.85
C...
C...  SET THE CONTROLLER CONSTANTS
      IF(NORUN.EQ.1)THEN
      KC=0.
      TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
      KC=10.
      TI=25.
      END IF
C...
C...  SET THE INITIAL CONDITIONS
10    XD=0.5
      DO 11 I=1,N
      X(I)=0.5
11    CONTINUE
      XB=0.5
      IE=0.
      I1=0.
      I2=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  MODEL ALGEBRA
C...
C...  VAPOR COMPOSITIONS
      DO 1 I=1,N
      Y(I)=EQUIL(A,X(I))
1     CONTINUE
      YB=EQUIL(A,XB)
C...
C...  CONTROLLER EQUATIONS
      E=XD-XDSET
      Z=ZS+KC*(E+(1./TI)*IE)
      IF(Z.LT.0.)Z=0.
      IF(Z.GT.1.)Z=1.
      D=CV*Z*SQRT(HC)
      R=V-D
C...
C...  CONDENSER
      XDT=(1./HC)*(V*Y(N)-R*XD-D*XD)
C...
C...  PLATE N
      XT(N)=(1./H)*(R*XD+V*Y(N-1)-R*X(N)-V*Y(N))
C...
C...  PLATES 2 TO N-1
      NM1=N-1
      DO 2 I=2,NM1
      XT(I)=(1./H)*(R*X(I+1)+V*Y(I-1)-R*X(I)-V*Y(I))
2     CONTINUE
C...
C...  PLATE 1
      XT(1)=(1./H)*(R*X(2)+V*YB-R*X(1)-V*Y(1))
C...
C...  KETTLE
      XBT=(1./HB)*(R*X(1)-V*YB)
C...
C...  TIME INTEGRALS
      DIEDT=E
      DI1DT=D
      DI2DT=XD*D
      RETURN
      END
      FUNCTION EQUIL(A,X)
C...
C...  FUNCTION EQUIL CALCULATES THE EQUILIBRIUM VAPOR COMPOSITION
C...  FROM ROAULT*S LAW
C...
C...  ARGUMENT LIST
C...
C...     A     RELATIVE VOLATILITY (INPUT)
C...
C...     X     LIQUID MOL FRACTION, FOR WHICH THE EQUILIBRIUM VAPOR
C...           COMPOSITION IS TO BE COMPUTED (INPUT)
C...
      EQUIL=A*X/(1.+(A-1.)*X)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/  TIME, NSTOP, NORUN
     1      /Y/    XD, X(10),    XB,    IE,    I1,    I2
     2      /F/   XDT,XT(10),   XBT, DIEDT, DI1DT, DI2DT
     3      /V/     A,     V,     R,     H,    HC,    HB,    YB,
     4          Y(10),    CV,    ZS,     Z,     E,    KC,    TI,
     5          XDSET, RATIO,     D,     N
      REAL         IE,    I1,    I2,    KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION PT(51), PXD(51), PD(51), PZ(51), PE(51), PI1(51),
     1         PI2(51),  PR(51)
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,10X,2HXD,11X,1HD,11X,1HZ,11X,1HE,10X,2HIE,
     1      10X,2HI1,10X,2HI2,7X,5HI2/I1)
C...
C...  RPINT THE NUMERICAL SOLUTION.  NOTE - THE RATIO I2/I1 CAN BE
C...  INDETERMINATE (0/0).  IF THIS OCCURS, THIS RATIO IS ARBITRARILY
C...  SET TO ZERO
      IF((I1.EQ.0.).AND.(I2.EQ.0.))RATIO=0.
      IF((I1.EQ.0.).AND.(I2.NE.0.))STOP
      IF((I1.NE.0.).AND.(I2.NE.0.))RATIO=I2/I1
      WRITE(NO,2)TIME,XD,D,Z,E,IE,I1,I2,RATIO
2     FORMAT(F10.2,8F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
       IP=IP+1
       PT(IP)=TIME
      PXD(IP)=XD
       PD(IP)=D
       PZ(IP)=Z
       PE(IP)=E
      PI1(IP)=I1
      PI2(IP)=I2
       PR(IP)=RATIO
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL SPLOTS(1,IP,PT,PXD)
      WRITE(NO,10)
10    FORMAT(1H ,//,8H XD VS T)
      CALL SPLOTS(1,IP,PT,PD )
      WRITE(NO,11)
11    FORMAT(1H ,//,8H  D VS T)
      CALL SPLOTS(1,IP,PT,PZ )
      WRITE(NO,12)
12    FORMAT(1H ,//,8H  Z VS T)
      CALL SPLOTS(1,IP,PT,PE )
      WRITE(NO,13)
13    FORMAT(1H ,//,8H  E VS T)
      CALL SPLOTS(1,IP,PT,PI1)
      WRITE(NO,14)
14    FORMAT(1H ,//,8H I1 VS T)
      CALL SPLOTS(1,IP,PT,PI2)
      WRITE(NO,15)
15    FORMAT(1H ,//,8H I2 VS T)
      CALL SPLOTS(1,IP,PT,PR )
      WRITE(NO,16)
16    FORMAT(1H ,//,11H I2/I1 VS T)
      IP=0
      RETURN
      END
PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
0.        50.       1.
   15 1000    1    1  REL 0.001
PI CONTROL OF A BINARY BATCH DISTILLATION COLUMN
0.        50.       1.
   15 1000    1    1  REL 0.001
END OF RUNS
*APP SEP14
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A DOUBLE EFFECT EVAPORATOR
C...
C...  CONSIDER THE FOLLOWING DOUBLE EFFECT EVAPORATOR
C...
C...                          WS1                    WS2
C...                      ............           ..........+
C...                      .          .           .
C...                   ......        .        ......
C...                  .      .       .       .      .
C...                 .        .      .      .        .
C...                .          .     .     .          .
C...                .          .     .     .          .
C...                .  EVAP 1  .     .     .  EVAP 2  .
C...                .          .     .     .          .
C...                .          .     .     .          .
C...                ............     .     ............
C...                .       M1 .     .     .       M2 .
C...                .          .     .     .          .
C...      WS0 ............  T1 .     ............  T2 .+....... WF
C...                .   .      +...        .   .      .
C...                .    .  A1 .  .        .    .  A2 .
C...                .   .      .  .        .   .      .
C...                .    .  X1 .  .        .    .  X2 .
C...          ...........      .  .  ...........      .
C...          .     .          .  .  .     .          .
C...          +      .        .   .  +      .        .
C...                  .      .    .          .      .
C...                   ......     .           ......
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...                      .       .              .
C...               ...    .       .     ...      .
C...          +..... ......       ....... ........
C...               ...                  ...
C...                .                    .
C...               ...                  ...
C...            (PUMP FOR            (PUMP FOR
C...               W1)                  W2)
C...  WHERE
C...
C...     M1,M2       MASS HOLDUP IN EVAPORATORS 1 AND 2, RESPECTIVELY
C...
C...     T1,T2       SOLUTION TEMPERATURES IN EVAPORATORS 1 AND 2
C...
C...     H1,H2       SOLUTION ENTHALPIES IN EVAPORATORS 1 AND 2
C...
C...     X1,X2       SOLUTE MASS FRACTIONS IN EVAPORATORS 1 AND 2
C...
C...     WS1,WS2     STEAM MASS FLOW RATES FROM EVAPORATORS 1 AND 2
C...
C...     W1,W2       SOLUTION MASS FLOW RATES FROM EVAPORATORS 1 AND 2
C...
C...     WF          FEED MASS FLOW RATE TO EVAPORATOR 2
C...
C...     WS0         STEAM MASS FLOW RATE THROUGH THE COIL IN EVAPORATOR
C...                 1 (WS1 IS THE STEAM MASS FLOW RATE THROUGH THE COIL
C...                 IN EVAPORATOR 2)
C...
C...     TS0,TS1     STEAM TEMPERATURES IN THE COILS IN EVAPORATORS 1
C...                 AND 2
C...
C...     HS1,HS2     ENTHALPY OF THE VAPOR LEAVING EVAPORATORS 1 AND 2
C...
C...     H1,H2       ENTHALPY OF THE SOLUTION IN EVAPORATORS 1 AND 2
C...
C...     DVS0,       HEAT OF VAPORIZATION OF STEAM IN THE COILS OF
C...     DVS1        EVAPORATORS 1 AND 2
C...
C...     HF          ENTHALPY OF THE FEED
C...
C...     TF,TS0      TEMPERATURE OF THE FEED AND ENTERING STEAM
C...
C...     XF          MASS FRACTION OF THE FEED
C...
C...     A1,A2       HEAT TRANSFER AREAS OF THE COILS IN EVAPORATOR 1
C...                 AND 2
C...
C...     U1,U2       HEAT TRANSFER COEFFICIENTS FOR THE COILS IN
C...                 EVAPORATORS 1 AND 2
C...
C...     X1SET       SET POINT FOR X1
C...
C...     M1SET,      SET POINTS FOR M1, M2
C...     M2SET
C...
C...     T2SET       SET POINT FOR T2
C...
C...     EX1  HX1 - X1SET
C...
C...     EM1  HM1 - M1SET
C...
C...     EM2  HM2 - M2SET
C...
C...     ET2  HT2 - T2SET
C...
C...     WFSS        WF AT STEADY STATE
C...
C...     W1SS,       W1 AND W2 AT STEADY STATE
C...     W2SS
C...
C...     WS2SS       WS2 AT STEADY STATE
C...
C...     KCF,KC1     GAINS FOR THE FEED FLOW RATE CONTROLLER, M1 AND M2
C...     KC2,KCS     LIQUID LEVEL CONTROLLERS, STEAM FLOW RATE (FROM THE
C...                 SECOND EVAPORATOR) CONTROLLER
C...
C...     TIF,TI1     INTEGRAL TIMES FOR THE FEED FLOW RATE CONTROLLER,
C...     TI2,TIS     M1 AND M2 LIQUID LEVEL CONTROLLERS, STEAM FLOW RATE
C...                 (FROM THE SECOND EVAPORATOR) CONTROLLER
C...
C...  THE MODEL FOR THIS SYSTEM CONSISTS OF THE FOLLOWING EQUATIONS
C...
C...     (A)  TOTAL MASS BALANCE AROUND EACH EVAPORATOR
C...
C...          DM1/DT = W2 - W1 - WS1, M1(0)                       (1)
C...
C...          DM2/DT = WF - W2 - WS2, M2(0)                       (2)
C...
C...     (B)  COMPONENT BALANCE AROUND EACH EVAPORATOR
C...
C...          D(M1*X1)/DT = W2*X2 - W1*X1, M1(0)*X1(0)            (3)
C...
C...          D(M2*X2)/DT = WF*XF - W2*X2, M2(0)*X2(0)            (4)
C...
C...     (C)  EQUATION FOR THE OUTLET VALVE OF EACH EVAPORATOR
C...
C...          W1 = CV1*SQRT(M1), W2 = CV2*SQRT(M2)             (5)(6)
C...
C...     (D)  ENERGY BALANCE ON THE COILS IN EACH EVAPORATOR
C...          (NEGLECTING VAPOR DYNAMICS)
C...
C...          WS1*HVS1 = U2*A2*(TS1 - T2)                         (7)
C...
C...          WS0*HVS0 = U1*A1*(TS0 - T1)                         (8)
C...
C...     (E)  ENERGY BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*H1)/DT = W2*H2 - W1*H1 - WS1*HS1 + U1*A1*(TS0 - T1)
C...                                                              (9)
C...                        M1(0)*H1(0)
C...
C...          D(M2*H2)/DT = WF*HF - W2*H2 - WS2*HS2 + U2*A2*(TS1 - T2)
C...                                                             (10)
C...                        M2(0)*H2(0)
C...
C...     (F)  AUXILIARY EQUATIONS
C...
C...          TS1 = T1, TS2 = T2 (ASSUMING NO BOILING        (11)(12)
C...                                  POINT RISE)
C...
C...          LIQUID ENTHALPY
C...
C...             H1 = CP*(T1 - TR), H2 = CP*(T2 - TR)
C...
C...             OR FOR WATER (CP = 1) WITH TR = 32
C...
C...             H1 = T1 - 32, H2 = T2 - 32                  (13)(14)
C...
C...          VAPOR ENTHALPY
C...
C...             HS1 = 0.42*TS1 + 1062, HS2 = 0.42*TS2 + 1062 (15)(16)
C...
C...          HEAT OF VAPORIZATION
C...
C...             HVS0 = 1092 - 0.57*TS0, HVS1 = 1092 - 0.57*TS1 (17)(18)
C...
C...     (G)  CONTROLLER EQUATIONS
C...
C...                                          T
C...          WF = WFSS + KCF*(EX1 + (1/TIF)*INT EX1*DT)         (19)
C...                                          0
C...
C...                                          T
C...          W1 = W1SS + KC1*(EM1 + (1/TI1)*INT EM1*DT)         (20)
C...                                          0
C...
C...                                          T
C...          W2 = W2SS + KC2*(EM2 + (1/TI2)*INT EM2*DT)         (21)
C...                                          0
C...
C...                                            T
C...          WS2 = WS2SS + KCS*(ET2 + (1/TIS)*INT ET2*DT)       (22)
C...                                            0
C...
C...          NOTE THAT THE FEED FLOW RATE, WF, THE VAPOR RATE FROM THE
C...          SECOND EVAPORATOR, WS2, AND THE MASS HOLDUPS IN THE TWO
C...          EVAPORATORS, M1 AND M2, ARE CONTROLLED TO BRING THE SYSTEM
C...          TO A STEADY STATE CONDITION (BECAUSE OF THE INTEGRAL
C...          ACTION IN THE PI CONTROLLERS).  THE CONTROLLERS ARE NOT
C...          SHOWN IN THE PRECEDING DIAGRAM, BUT THEIR OPERATION IS
C...          CLEAR FROM EQUATIONS (19) TO (22).
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  MODEL CONSTANTS
      A1=2000.
      A2=2000.
      U1=500./3600.
      U2=700./3600.
      TS0=328.
      TF=100.
      XF=0.02
      WFSS=40.
      W1SS=30.
      W2SS=30.
      WS2SS=10.
      X1SET=0.25
      M1SET=250.
      M2SET=250.
      T2SET=101.
      KCF=100.
      KC1=1.
      KC2=1.
      KCS=1.
      TIF=250.
      TI1=250.
      TI2=250.
      TIS=250.
C...
C...  INITIAL CONDITIONS
      M1=250.
      M2=250.
      M1X1=250.*0.1
      M2X2=250.*0.1
      M1H1=250.*(95.-32.)
      M2H2=250.*(95.-32.)
      EX1INT=0.
      EM1INT=0.
      EM2INT=0.
      ET2INT=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  MODEL ALGEBRA
C...
C...     THE MASS OF LIQUID IN EACH EVAPORATOR MUST BE NONNEGATIVE
         IF(M1.LT.0.)M1=0.
         IF(M2.LT.0.)M2=0.
C...
C...     MASS FRACTION IN EACH EVAPORATOR
         X1=M1X1/M1
         X2=M2X2/M2
C...
C...     THE MASS FRACTION IN EACH EVAPORATOR MUST BE NONNEGATIVE
         IF(X1.LT.0.)X1=0.
         IF(X2.LT.0.)X2=0.
C...
C...     LIQUID TEMPERATURE IN EACH EVAPORATOR
         H1=M1H1/M1
         H2=M2H2/M2
         T1=H1+32.
         T2=H2+32.
C...
C...     TEMPERATURE OF VAPOR FROM EACH EVAPORATOR
         TS1=T1
         TS2=T2
C...
C...     HEAT OF VAPORIZATION OF THE STEAM IN EACH EVAPORATOR COIL
         HVS0=1092.-0.57*TS0
         HVS1=1092.-0.57*TS1
C...
C...     VAPOR FLOW IN THE COIL OF EACH EVAPORATOR
         WS0=(U1*A1/HVS0)*(TS0-T1)
         WS1=(U2*A2/HVS1)*(TS1-T2)
C...
C...     CONTROLLER ERRORS
         EX1=X1-X1SET
         EM1=M1-M1SET
         EM2=M2-M2SET
         ET2=T2-T2SET
C...
C...     CONTROLLER EQUATIONS
         WF=WFSS+KCF*(EX1+(1./TIF)*EX1INT)
         W1=W1SS+KC1*(EM1+(1./TI1)*EM1INT)
         W2=W2SS+KC2*(EM2+(1./TI2)*EM2INT)
         WS2=WS2SS+KCS*(ET2+(1./TIS)*ET2INT)
C...
C...     THE MANIPULATED VARIABLES MUST BE NONNEGATIVE
         IF(WF.LT.0.)WF=0.
         IF(W1.LT.0.)W1=0.
         IF(W2.LT.0.)W2=0.
         IF(WS2.LT.0.)WS2=0.
C...
C...     VAPOR ENTHALPIES
         HS1=0.42*TS1+1062.
         HS2=0.42*TS2+1062.
C...
C...     FEED ENTHALPY
         HF=TF-32.
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MASS BALANCES
         M1T=W2-W1-WS1
         M2T=WF-W2-WS2
C...
C...     COMPONENT MASS BALANCES
         M1X1T=W2*X2-W1*X1
         M2X2T=WF*XF-W2*X2
C...
C...     ENERGY BALANCES
         M1H1T=W2*H2-W1*H1-WS1*HS1+U1*A1*(TS0-T1)
         M2H2T=WF*HF-W2*H2-WS2*HS2+U2*A2*(TS1-T2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     2          EX1INT, EM1INT, EM2INT, ET2INT
     3      /F/    M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     4             EX1,    EM1,    EM2,    ET2
     5      /V/     W1,     W2,     WF,    WS0,    WS1,    WS2,
     6      XF,     X1,     X2,     T1,     T2,    TS0,    TS1,
     7     TS2,     TF,     HF,     H1,     H2,    HS1,    HS2,
     8    HVS0,   HVS1,     U1,     U2,     A1,     A2,   WFSS,
     9    W1SS,   W2SS,  WS2SS,    KCF,    KC1,    KC2,    KCS,
     A     TIF,    TI1,    TI2,    TIS,  X1SET,  M1SET,  M2SET,
     B   T2SET
      REAL          M1,     M2,   M1X1,   M2X2,   M1H1,   M2H2,
     1             M1T,    M2T,  M1X1T,  M2X2T,  M1H1T,  M2H2T,
     2             KCF,    KC1,    KC2,  M1SET,  M2SET
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE SOLUTION
      DIMENSION   TMP(51),  XP(2,51),  TP(2,51),  MP(2,51),
     1            WFP(51),  WP(2,51), WSP(3,51)
      REAL MP
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF((IP/5*5).NE.IP)GO TO 3
      WRITE(NO,1)
1     FORMAT(1H ,/,
     1 9X,1HT,10X,2HM1,10X,2HM2,10X,2HX1,10X,2HX2,10X,2HT1,10X,2HT2,
     2      /,20X,2HWF,10X,2HW1,10X,2HW2,9X,3HWS0,9X,3HWS1,9X,3HWS2,
     3      /,19X,3HM1T,9X,3HM2T,7X,5HM1X1T,7X,5HM2X2T,7X,5HM1H1T,
     4       7X,5HM2H2T)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,2)T,M1,M2,X1,X2,T1,T2,
     1          WF,W1,W2,WS0,WS1,WS2,
     2         M1T,M2T,M1X1T,M2X2T,M1H1T,M2H2T
2     FORMAT(F10.2,2F12.1,2F12.4,2F12.1,/,
     1       10X,6F12.1,/,10X,4F12.4,2F12.1)
3     IP=IP+1
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TMP(IP)=T
      XP(1,IP)=X1
      XP(2,IP)=X2
      TP(1,IP)=T1
      TP(2,IP)=T2
      MP(1,IP)=M1
      MP(2,IP)=M2
      WFP(IP)=WF
      WP(1,IP)=W1
      WP(2,IP)=W2
      WSP(1,IP)=WS0
      WSP(2,IP)=WS1
      WSP(3,IP)=WS2
      IF(IP.LT.51)RETURN
C...
C...  PLOT THE SOLUTION
      CALL TPLOTS(2,IP,TMP, XP)
      WRITE(NO,10)
10    FORMAT(1H ,//,35H X1, X2 VS T                       )
      CALL TPLOTS(2,IP,TMP, TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,35H T1, T2 VS T                       )
      CALL TPLOTS(2,IP,TMP, MP)
      WRITE(NO,12)
12    FORMAT(1H ,//,35H M1, M2 VS T                       )
      CALL TPLOTS(1,IP,TMP,WFP)
      WRITE(NO,13)
13    FORMAT(1H ,//,35H WF VS T                           )
      CALL TPLOTS(2,IP,TMP, WP)
      WRITE(NO,14)
14    FORMAT(1H ,//,35H W1, W2 VS T                       )
      CALL TPLOTS(3,IP,TMP,WSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,35H WS0, WS1, WS2 VS T                )
      IP=0
      RETURN
      END
PI CONTROL OF A DOUBLE EFFECT EVAPORATOR
0.        2500.     50.
   10 9999    1    1  REL 0.001
END OF RUNS
*APP SEP15
      SUBROUTINE INITAL
C...
C...  JACOBIAN MATRIX MAP AND TEMPORAL EIGENVALUES OF THE MODEL
C...  FOR A BATCH DISTILLATION COLUMN
C...
C...  THE MODEL OF A BATCH DISTILLATION COLUMN IS EXAMINED IN TERMS
C...  OF (1) A MAP OF THE JACOBIAN MATRIX OF THE MODEL ORDINARY DIFFER-
C...  ENTIAL EQUATIONS (ODES) AND (2) THE TEMPORAL EIGENVALUES OF THE
C...  ODES.  THIS ANALYSIS IS DONE BY THE CALLS TO SUBROUTINES JMAP AND
C...  EIGEN IN SUBROUTINE PRINT.  THE MAP IS USEFUL FOR PICTURING THE
C...  STRUCTURE OF THE ODES, E.G., TRIDIAGONAL STRUCTURE.  THE EIGEN-
C...  VALUES CAN BE USED TO DETERMINE THE MODEL TIME SCALE AND STIFFNESS
C...  WHICH IN TURN CAN BE USED TO SELECT AN INTEGRATOR FOR THE ODES.
C...
C...  THE FOLLOWING CODING SIMULATES A TEN-TRAY BATCH DISTILLATION
C...  COLUMN.  INITIALLY, 100 MOLES OF A 50/50 MOLAR MIXTURE OF
C...  ETHANOL AND WATER (RELATIVE VOLATILITY = 1.4) ARE CHARGED TO
C...  THE COLUMN.  IN SO DOING, 0.5 MOLE REMAIN ON EACH TRAY OF THE
C...  COLUMN.  HEAT IS THEN APPLIED TO THE KETTLE TO MAINTAIN A CONSTANT
C...  BOILUP OF 10 MOLES/HR.  VAPOR LEAVING THE TOP OF THE COLUMN IS
C...  CONDENSED SO THAT A REFLUX RATE OF 7.5 MOLES/HR IS MAINTAINED,
C...  AND THUS 2.5 MOLES/HR OF PRODUCT IS WITHDRAWN.
C...
C...  THE PURPOSE OF THIS CASE STUDY IS TO INTEGRATE THE MATERIAL
C...  BALANCE EQUATIONS FOR THE DISTILLATION COLUMN, AND TO DEMONSTRATE
C...  SOME PROPERTIES OF THE JACOBIAN MATRIX OF THE DIFFERENTIAL EQUA-
C...  TIONS.  IN PARTICULAR, THE JACOBIAN MATRIX IS MAPPED THROUGH TIME
C...  BY CALLS TO SUBROUTINE JMAP IN SUBROUTINE EIGEN, AND THE TEMPORAL
C...  EIGENVALUES OF THE JACOBIAN MATRIX ARE COMPUTED BY CALLS TO SUB-
C...  ROUTINE EIGEN IN SUBROUTINE PRINT.
C...
C...  ALSO, PLEASE NOTE THAT SUBROUTINE EIGEN CALLED FROM SUBROUTINE
C...  PRINT IN TURN CALLS IMSL ROUTINE EIGRF TO COMPUTE THE TEMPORAL
C...  EIGENVALUES OF THE DIFFERENTIAL EQUATIONS.  SINCE THERE IS A
C...  POSSIBILITY THE USER MIGHT NOT HAVE ACCESS TO IMSL (IMSL, THE
C...  INTERNATIONAL MATHEMATICS AND STATISTICS LIBRARY, IS A COMMER-
C...  CIALLY AVAILABLE LIBRARY OF HIGH-QUALITY FORTRAN SUBROUTINES
C...  FOR A SPECTRUM OF MATHEMATICAL AND STATISTICAL CALCULATIONS),
C...  THE CALL TO SUBROUTINE EIGEN CAN BE CONVERTED TO A COMMENT.
C...
C...  THE FOLLOWING VARIABLES ARE USED IN THE DIFFERENTIAL EQUATIONS
C...  WHICH DESCRIBE THE DISTILLATION PROCESS
C...
C...     MB      TOTAL MOLES IN THE REBOILER
C...
C...     XB      LIQUID MOLE FRACTION OF ETHANOL IN THE REBOILER
C...
C...     YB      VAPOR MOLE FRACTION OF ETHANOL FROM THE REBOILER
C...             (ASSUMED TO BE IN EQUILIBRIUM WITH XB)
C...
C...     X(I)    LIQUID MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...
C...     Y(I)    VAPOR MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...             (ASSUMED TO BE IN EQUILBRIUM WITH X(I))
C...
C...     REFLUX  REFLUX RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     VAPOR   VAPOR RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     ALPHA   RELATIVE VOLATILITY OF ETHANOL WITH RESPECT TO WATER
C...
C...     DISTIL  DISTILLED (TOPS) PRODUCT RATE = VAPOR - REFLUX MOLES/HR
C...
C...     N       TOTAL NUMBER OF TRAYS IN THE COLUMN
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  SET THE SYSTEM PARAMETERS
      VAPOR=10.0
      REFLUX=7.5
      ALPHA=1.4
      DISTIL=VAPOR-REFLUX
      N=10
C...
C...  INITIAL CONDITONS (T = 0)
C...  MB(T) = 95.0, XB(T) = 0.5, X(I) = 0.5, I = 1, 2, 3,..., N
      MB=95.0
      XB=0.5
      DO 1 I=1,N
1     X(I)=0.5
C...
C...  CALCULATE THE REMAINING INITIAL MODEL VARIABLES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  CALCULATE THE EQUILIBRIUM VAPOR COMPOSITIONS
      YB=ALPHA*XB/(1.+(ALPHA-1.)*XB)
      DO 1 I=1,N
1     Y(I)=ALPHA*X(I)/(1.+(ALPHA-1.)*X(I))
C...
C...  TOTAL MATERIAL BALANCE FOR THE ENTIRE COLUMN
C...  DMB/DT = -DISTIL
      DMBDT=-DISTIL
C...
C...  ETHANOL MATERIAL BALANCE FOR THE REBOILER
C...  D(MB*XB)/DT = MB*DXB/DT + XB*DMB/DT = REFLUX*X(1) - VAPOR*YB
      DXBDT=(REFLUX*X(1)-VAPOR*YB-XB*DMBDT)/MB
C...
C...  ETHANOL MATERIAL BALANCE FOR THE FIRST PLATE
C...  0.5*DX(1)/DT = VAPOR*(YB - Y(1)) + REFLUX*(X(2) - X(1))
      DXDT(1)=2.0*(VAPOR*(YB-Y(1))+REFLUX*(X(2)-X(1)))
C...
C...  ETHANOL MATERIAL BALANCES FOR THE INTERMEDIATE PLATES, I = 2, 3,
C...  ..., N-1
C...  0.5*DX(I)/DT = VAPOR*(Y(I-1) - Y(I)) + REFLUX*(X(I+1) - X(I))
      NM1=N-1
      DO 2 I=2,NM1
2     DXDT(I)=2.0*(VAPOR*(Y(I-1)-Y(I))+REFLUX*(X(I+1)-X(I)))
C...
C...  ETHANOL MATERIAL BALANCE FOR THE TOP PLATE
C...  0.5*DX(N)/DT = VAPOR*(Y(N-1) - Y(N)) + REFLUX*(Y(N) - X(N))
      DXDT(N)=2.0*(VAPOR*(Y(N-1)-Y(N))+REFLUX*(Y(N)-X(N)))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TPLOT(41),XPLOT(2,41)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINE JMAP, EIGEN
      DIMENSION  A(12,12),     WF(12),
     1             SV(12),  SVOLD(12),
     2              F(12),   FOLD(12)
      COMPLEX  EIGENV(12)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, SV(12), TO THE DEPENDENT
C...  VARIABLE VECTOR IN COMMON/Y/, AND EQUIVALENCE THE CORRESPONDING
C...  DERIVATIVE VECTORS
      EQUIVALENCE (MB,SV(1)), (DMBDT,F(1))
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED POINTS
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)VAPOR,REFLUX,DISTIL,ALPHA,N
1     FORMAT(1H1,//,36H BATCH DISTILLATION OF ETHANOL-WATER,//,
     1              36H INITIAL CHARGE = 100 MOLES         ,//,
     2              36H INITIAL COMPOSITION = 50/50        ,//,
     3              26H BOILUP RATE (MOLES/HR) = ,F5.1     ,//,
     4              26H REFLUX RATE (MOLES/HR) = ,F5.1     ,//,
     5              27H PRODUCT RATE (MOLES/HR) = ,F4.1    ,//,
     6              23H RELATIVE VOLATILITY = ,F4.1        ,//,
     7              19H NUMBER OF TRAYS = ,I2              )
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(
     1    //,14X,4HTIME,10X,8HMOLES IN,6X,12HETHANOL CONC,6X,12HETHANOL
     2CONC,6X,12HETHANOL CONC,5X,16HETHANOL CONC VAP,/,13X,5HHOURS,11X,6
     3HKETTLE,9X,9HIN KETTLE,8X,10HIN PRODUCT,6X,14HLEAVING KETTLE,4X,15
     4HLEAVING PLATE 5)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,4)T,MB,XB,Y(N),YB,Y(5)
4     FORMAT(13X,F5.2,11X,F5.1,10X,F7.4,11X,F7.4,11X,F7.4,12X,F7.4)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TPLOT(IP)=T
      XPLOT(1,IP)=XB
      XPLOT(2,IP)=Y(N)
C...
C...  MAP THE JACOBIAN MATRIX OF THE 12 ODES DEFINED IN COMMON/Y/ AND
C...  /F/ EVERY TENTH CALL TO SUBROUTINE PRINT
      IF((IP-1)/10*10.NE.(IP-1))RETURN
      WRITE(NO,8)T
8     FORMAT(1H ,//,35H MAP OF THE JACOBIAN MATRIX AT T = ,F5.2)
      NODE=12
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  PRINT THE JACOBIAN MATRIX COMPUTED BY SUBROUTINE JMAP
      WRITE(NO,7)((A(I,J),J=1,NODE),I=1,NODE)
7     FORMAT(1H ,//,32H ELEMENTS OF THE JACOBIAN MATRIX,//,
     1 (4E12.3,/,4E12.3,/,4E12.3,//))
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 12 ODES DEFINED IN
C...  COMMON/Y/ AND /F/
C...
C...  *****************************************************************
C...
C...  SUBROUTINE EIGEN IN TURN CALLS IMSL ROUTINE EIGRF TO COMPUTE THE
C...  EIGENVALUES.  IF THE IMSL IS NOT AVAILABLE, THE FOLLOWING CALL TO
C...  EIGEN SHOULD BE CONVERTED TO A COMMENT
      CALL EIGEN(NODE,A,EIGENV,WF)
C...
C...  *****************************************************************
C...
C...  PRINT A LABEL FOR THE NUMERICAL SOLUTION (ADDITIONAL LABELS ARE
C...  REQUIRED AT THIS POINT BECAUSE OF THE INTERMITTENT PRINTING OF
C...  THE JACOBIAN MATRIX MAP AND ELEMENTS)
      WRITE(NO,2)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.41)RETURN
      CALL TPLOTS(2,41,TPLOT,XPLOT)
C...
C...  LABEL THE PLOT
      WRITE(NO,6)
6     FORMAT(//,11X,9H1 - XB(T),3X,9H2 - XD(T))
      IP=0
      RETURN
      END
BATCH DISTILLATION OF AN ETHANOL-WATER MIXTURE
0.        10.       0.25
   12  200    2    1  REL 0.001
END OF RUNS
*APP SEP16
      SUBROUTINE INITAL
C...
C...  NONLINEAR DIFFUSION
C...
C...  THE ONE-DIMENSIONAL DIFFUSION EQUATION WITH TWO NONLINEAR COEFFI-
C...  CIENTS
C...
C...          (D(U)U )  = C(U)U                                      (1)
C...                X X        T
C...
C...  IS TO BE INTEGRATED SUBJECT TO THE AUXILIARY CONDITIONS
C...
C...          U (0,T) = 0, U(1,T) = 1                             (2)(3)
C...           X
C...
C...          U(X,0) = 0                                             (4)
C...
C...  THE TWO NONLINEAR COEFFICIENTS IN THIS CASE ARE
C...
C...          D(U) = C(U) = 1 + U                                 (5)(6)
C...
C...  THE FOLLOWING NUMERICAL SOLUTION WAS REPORTED BY ZELLNER FOR
C...  COMPARISON WITH THE METHOD OF LINES SOLUTION
C...
C...          U(0.0,0.2)     0.29738
C...
C...          U(0.2,0.2)     0.33817
C...
C...          U(0.4,0.2)     0.45173
C...
C...          U(0.6,0.2)     0.61651
C...
C...          U(0.8,0.2)     0.80710
C...
C...          U(1.0,0.2)     1.00000
C...
C...  (ZELLNER, M. G., PH.D. DISSERTATION, LEHIGH UNIVERSITY, BETHLEHEM,
C...  PA).  EQUATION (1) CAN ALSO BE LINEARIZED BY A KIRCHOFF TRANS-
C...  FORMATION AND THE RESULTING LINEAR EQUATION SOLVED ANALYTICALLY.
C...  THIS LINEARIZATION THEREFORE PROVIDES A RIGOROUS TEST OF THE
C...  NUMERICAL SOLUTION.  THE DETAILS ARE GIVEN BY ZELLNER.
C...
C...  EQUATION (1) IS INTEGRATED WITH THREE AND FIVE-POINT CENTERED
C...  DIFFERENCES.  ALSO, THE LEFT HAND SIDE OF EQUATION (1) CAN BE
C...  EXPANDED TO GIVE
C...
C...          D(U)U   + D(U) U  = C(U)U                              (7)
C...               XX       X X        T
C...
C...  EQUATION (7) IS ALSO INTEGRATED BY THREE AND FIVE-POINT CENTERED
C...  DIFFERENCES SO THAT A TOTAL OF FOUR RUNS IS PROGRAMMED.  A COMPAR-
C...  ISON OF THE NUMERICAL SOLUTIONS FOR EQUATIONS (1) AND (7) WILL
C...  GIVE SOME INDICATION WHETHER THE PARTICULAR FORM OF THE DIFFER-
C...  ERENTIAL EQUATION AFFECTS THE SOLUTION SIGNIFICANTLY.
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(11)
     2      /F/ UT(11)
     3     /SD/ UX(11),UXX(11)
     4      /P/      N,     IP
C...
C...  SET THE NUMBER OF GRID POINTS, COUNTER FOR THE PLOTTED SOLUTION
      N=11
      IP=0
C...
C...  INITIAL CONDITION (4)
      DO 1 I=1,N
      U(I)=0.
1     CONTINUE
C...
C...  CALL SUBROUTINE DERV TO INITIALIZE ALL OF THE DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(11)
     2      /F/ UT(11)
     3     /SD/ UX(11),UXX(11)
     4      /P/      N,     IP
C...
C...  BOUNDARY CONDITION (3)
      U(N)=1.
C...
C...  FOUR RUNS ARE PROGRAMMED AS OUTLINED IN SUBROUTINE INITAL
      GO TO(1,2,3,4),NORUN
C...
C...  EQUATION (1) WITH THREE-POINT CENTERED DIFFERENCES
1     CALL DSS002(0.,1.,N,U ,UX )
      UX(1)=0.
      DO 11 I=1,N
      UX(I)=(1.+U(I))*UX(I)
11    CONTINUE
      CALL DSS002(0.,1.,N,UX,UXX)
      DO 12 I=1,N
      UT(I)=(1./(1.+U(I)))*UXX(I)
12    CONTINUE
      RETURN
C...
C...  EQUATION (1) WITH FIVE-POINT CENTERED DIFFERENCES
2     CALL DSS004(0.,1.,N,U ,UX)
      UX(1)=0.
      DO 21 I=1,N
      UX(I)=(1.+U(I))*UX(I)
21    CONTINUE
      CALL DSS004(0.,1.,N,UX,UXX)
      DO 22 I=1,N
      UT(I)=(1./(1.+U(I)))*UXX(I)
22    CONTINUE
      RETURN
C...
C...  EQUATION (7) WITH THREE-POINT CENTERED DIFFERENCES
3     CALL DSS002(0.,1.,N,U ,UX )
      UX(1)=0.
      CALL DSS004(0.,1.,N,UX,UXX)
      DO 31 I=1,N
      UT(I)=(1./(1.+U(I)))*((1.+U(I))*UXX(I)+UX(I)**2)
31    CONTINUE
      RETURN
C...
C...  EQUATION (7) WITH FIVE-POINT CENTERED DIFFERENCES
4     CALL DSS004(0.,1.,N,U ,UX )
      UX(1)=0.
      CALL DSS004(0.,1.,N,UX,UXX)
      DO 41 I=1,N
      UT(I)=(1./(1.+U(I)))*((1.+U(I))*UXX(I)+UX(I)**2)
41    CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(11)
     2      /F/ UT(11)
     3     /SD/ UX(11),UXX(11)
     4      /P/      N,     IP
      IP=IP+1
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(1H ,9H        T,3X,9H U(T,0.0),3X,9H U(T,0.2),3X,
     1                          9H U(T,0.4),3X,9H U(T,0.6),3X,
     2                          9H U(T,0.8),3X,9H U(T,1.0))
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,(U(I),I=1,N,2)
2     FORMAT(1X,F9.3,6(3X,F9.6))
      RETURN
      END
NONLINEAR DIFFUSION
0.        1.        0.1
   11 1000    1    1  ABS 0.0001
NONLINEAR DIFFUSION
0.        1.        0.1
   11 1000    1    1  ABS 0.0001
NONLINEAR DIFFUSION
0.        1.        0.1
   11 1000    1    1  ABS 0.0001
NONLINEAR DIFFUSION
0.        1.        0.1
   11 1000    1    1  ABS 0.0001
END OF RUNS
*APP SEP17
      SUBROUTINE INITAL
C...
C...  PROPORTIONAL-INTEGRAL CONTROL OF A HUMIDIFICATION COLUMN
C...
C...  A HUMIDIFICATION COLUMN (A PACKED COLUMN WITH WATER FLOWING DOWN
C...  AND AIR FLOWING UP) IS DIAGRAMMED BELOW
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE VARIABLES AND PARAMETERS FOR THIS SYSTEM ARE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     ZL      LENGTH OF THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...  THE DEPENDENT VARIABLES OF PARTICULAR INTEREST ARE Y(Z,T), TG(Z,T)
C...  TL(Z,T).  IN ORDER TO COMPUTE THESE VARIABLES, BASIC CONSERVATION
C...  PRINCIPLES ARE APPLIED TO THE AIR AND WATER STREAMS WITHIN THE
C...  COLUMN OVER THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE DIAGRAM)
C...  AND THEN THE LIMIT OF DZ ---+ 0 GIVES THE MODEL DIFFERENTIAL EQUA-
C...  TIONS.  SINCE THE MODEL IS DYNAMIC, TIME, T, AND AXIAL POSITION,
C...  Z, APPEAR IN THE EQUATIONS AS INDEPENDENT VARIABLES AND THEREFORE
C...  PARTIAL DIFFERENTIAL EQUATIONS (PDES) MUST BE USED.
C...
C...  THE PDES ARE DERIVED AS FOLLOWS.  A H20 BALANCE ON THE GAS PHASE
C...  GIVES
C...
C...     (Y*G*S*DZ)  = V*Y  - V*Y     + KY*AV*(YS - Y)*S*DZ     (1A)
C...               T      Z      Z+DZ
C...
C...  WHERE THE SUBSCRIPT T ON THE LHS DENOTES A PARTIAL DERIVATIVE WITH
C...  RESPECT TO TIME, T.
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (1A) IS INDICATED BELOW
C...
C...     (Y*G*S*DZ)
C...               T
C...
C...        = (MOLS H20/MOL DRY AIR)*(MOLS DRY AIR/CM**3)*(CM**2)*
C...          CM*(1/HR) = MOLS H20/HR ACCUMULATING IN THE GAS PHASE
C...          WITHIN THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE
C...          DIAGRAM BELOW)
C...
C...     V*Y
C...        Z
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DRY AIR) = MOLS H20/HR
C...          FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     V*Y
C...        Z+DZ
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DAY AIR) = MOLS H20/HR
C..           FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     KY*AV*(YS - Y)*S*DZ
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...           AIR)*(CM**2)*(CM) = MOLS H20/HR TRANSFERRED TO OR FROM
C...           THE AIR STREAM IN THE INCREMENTAL SECTION (THE DIRECTION
C...           OF TRANSFER DEPENDS ON THE SIGN OF (YS - Y))
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (1A) BECOMES
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                (1)
C...      T                Z
C...
C...  AN ENERGY BALANCE ON THE GAS PHASE GIVES
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))*G*S*DZ)  =
C...                                          T
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V  -
C...                                    Z                       (2A)
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V     -
C...                                    Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ + KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (2A) IS INDICATED BELOW
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))G*S*DZ
C...                                        T
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/
C...          CM**3)*(CM**2)*CM*(1/HR) = CAL/HR ACCUMULATING IN THE
C...          GAS PHASE WITHIN THE INCREMENTAL SECTION
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z+DZ
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (2A) BECOMES
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                    (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THERE THE ENERGY GROUPS, EV (ENERGY AT CONSTANT VOLUME) AND EP
C...  (ENERGY AT CONSTANT PRESSURE) HAVE BEEN USED TO SIMPLIFY THE
C...  TERMS IN EQUATION (2).  EV AND EP ARE DEFINED IN THE TABLE OF
C...  NOMENCLATURE GIVEN EARLIER.
C...
C...  AN ENERGY BALANCE ON THE LIQUID GIVES
C...
C...     (CL*TL*H*S*DZ)  = (CL*TL*L)     - (CL*TL*L)
C...                   T            Z+DZ            Z           (3A)
C...
C...     -H*AV*(TL - TG)*S*DZ - KY(AV*(YS - Y)*S*DZ*(CVV*TG + HDVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (3A) IS GIVEN BELOW
C...
C...     (CL*TL*H*S*DZ)
C...                   T
C...
C...        (CAL/MOL H20-C)*(C)*(MOLS H20/CM**3)*(CM**2)*CM*(1/HR)
C...        = CAL/HR ACCUMULATING IN THE H20 PHASE WITHIN THE
C...        INCREMENTAL SECTION OF LENGTH DZ
C...
C...     (CL*TL*L)
C...              Z+DZ
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING INTO
C...          THE INCREMENTAL SECTION AT Z+DZ
C...
C...     (CL*TL*L)
C...              Z
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING OUT OF
C...          THE INCREMENTAL SECTION AT Z
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (3A) BECOMES
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                    (3)
C...
C...            - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  AN EXTENSION OF THE PRECEDING SYSTEM IS ALSO SIMULATED IN THE
C...  FOLLOWING CODING.  SPECIFICALLY, THE EXITING WATER TEMPERATURE
C...  TL(0,T), IS SENSED, COMPARED WITH A SET POINT VALUE, TLSET,
C...  AND THE DIFFERENCE (ERROR), E = TL(0,T) - TLSET, IS USED TO
C...  ADJUST THE ENTERING AIR FLOW RATE, V, TO MOVE TL(0,T) TO TLSET.
C...  THE ADJUSTMENT OF V IS ACHIEVED WITH A PROPORTIONAL-INTEGRAL (PI)
C...  CONTROLLER.  THE FOLLOWING DIAGRAM ILLUSTRATES THE CONTROLLER
C...  AT THE BOTTOM OF THE HUMIDIFICATION COLUMN
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +             PI
C...                          .           .         CONTROLLER
C...                          .           .          .........
C...            TEMPERATURE .....         .          .       .
C...              SENSOR    .   .......... ........... KC,TI .+--- TLSET
C...                        .....         .          .       .
C...                          .           .          .........
C...                          .           .              .
C...                          .          ...   ..        .
C...                          .           ...... .........
C...                          .          ...   ..
C...                          .           . CONTROL VALVE
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE PURPOSE OF THE SIMULATION IS ESSENTIALLY TO DETERMINE, THE
C...  VALUES OF THE CONTROLLER GAIN, KC, AND INTEGRAL TIME, TI, SO
C...  THAT THE EXITING LIQUID TEMPERATURE, TL(0,T), IS CONTROLLED CLOSE
C...  TO THE SET POINT, TLSET.
C...
C...  THE CONTROLLER EQUATIONS ARE
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TLSET
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TLSET   CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS IN ENGLISH UNITS ARE
C...  LISTED BELOW, FOLLOWED BY EQUIVALENT VALUES IN METRIC UNITS.  THE
C...  CAN BE EXECUTED WITH EITHER SET BY SELECTING THE VALUE OF THE
C...  VARIABLE METRIC IN THE PROGRAM (METRIC = 0 FOR ENGLISH UNITS,
C...  METRIC = 1 FOR METRIC UNITS)
C...
C...  ******************************************************************
C...
C...   ENGLISH UNITS
C...
C...   H*AV = 50 BTU/(HR-FT**3-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2
C...
C...   H = 0.5 LB MOLS/FT**3 , G = 0.01 LB MOLS/FT**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TLSET = 90 F
C...
C...  ******************************************************************
C...
C...   METRIC UNITS
C...
C...   H*AV = 0.8015 CAL/(HR-CM**3-C)
C...
C...   KY*AV = 0.06573 GM MOLS DRY AIR/(HR-CM**3)
C...
C...   Z = 243.8 CM, CL = 18 CAL/(GM MOL-C), DHVAP = 9443.6 CAL/GM MOL
C...
C...   CPV = 7.3 CAL/(GM MOL-C), CPA = 7.3 CAL/(GM MOL-C)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   L = 22700 GM MOLS/HR, S = 929.03 CM**2
C...
C...   H = 0.008015 GM MOLS/CM**3, G = 0.0001603 GM MOLS/CM**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + 1.8*TL + 32)) MM HG
C...                                                    (TL IS IN C)
C...
C...   YS = P/(760 - P) GM MOLS H20/GM MOL DRY AIR
C...
C...   TG(0,T) = 43.33 C, TL(8,T) = 43.33 C, Y(0,T) = 0.01 GM MOL H20/
C...                                                  GM MOL DRY AIR)
C...
C...   TG(Z,0) = TL(Z,0) = 43.33 C, Y(Z,0) = 0.01
C...
C...   KC = 0.036 (1/C), TI = 0.1 HR, CV*(DP**0.5) = 22700 GM MOLS/HR
C...
C...   XSS = 0.5, TLSET = 32.22 C
C...
C...  ******************************************************************
C...
C...  THE CONVERSION FACTORS USED TO GO FROM ONE SET OF UNITS TO THE
C...  OTHER ARE
C...
C...     1 BTU = 252.2 CAL
C...
C...     1 BTU/LB MOL-F = 1 CAL/GM MOL-C
C...
C...     1 LB = 454 GM
C...
C...     1 LB MOL = 454 GM MOL
C...
C...     1 F = 1/1.8 C
C...
C...     1 FT = 30.48 CM
C...
C...     1 FT**3 = 28316.8 CM**3
C...
C...     TF = 1.8*TC + 32
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  SELECT ENGLISH (METRIC = 0) OR METRIC (METRIC = 1) UNITS
      IF(NORUN.EQ.1)METRIC=0
      IF(NORUN.EQ.2)METRIC=1
C...
C...  SET THE MODEL PARAMETERS IN THE UNITS SELECTED
C...
C...  ENGLISH UNITS
      IF(METRIC.EQ.0)THEN
      N=11
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.02
      TI=0.1
      CVDP=50.
      XSS=0.5
      TLSET=90.
C...
C...  METRIC UNITS
      ELSE
      N=11
      L=22700.
      G=0.0001603
      H=0.008015
      HLAV=0.8015
      KYAV=0.06573
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=243.8
      DHVAP=9443.6
      S=929.03
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.036
      TI=0.1
      CVDP=22700.
      XSS=0.5
      TLSET=32.22
      END IF
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      IF(METRIC.EQ.0)THEN
      TL(I)=110.
      TG(I)=110.
      ELSE
      TL(I)=43.33
      TG(I)=43.33
      END IF
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TLSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      IF(METRIC.EQ.0)THEN
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      ELSE
      P=10.**(7.96681-3002.4/(378.4+1.8*TL(I)+32.))
      END IF
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      IF(METRIC.EQ.0)THEN
      TL(N)=110.
      TG(1)=110.
      ELSE
      TL(N)=43.33
      TG(1)=43.33
      END IF
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
C...
C...  ZERO THE TIME DERIVATIVES TO MAINTAIN THE BOUNDARY CONDITIONS
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINE JMAP AND EIGEN
      DIMENSION       A(34,34),         WR(34),         WI(34),
     1                Z(34,34),         RW(34),         IW(34),
     2                                  SV(34),      SVOLD(34),
     3                                   F(34),       FOLD(34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  PRINT A DETAILED SOLUTION (THE INDIVIDUAL TERMS IN THE PDES AND
C...  THE DEPENDENT VARIABLES) FOR IP = 1, 51, 101 CALLS TO SUBROUTINE
C...  PRINT.  FIRST, UPDATE ALL OF THE MODEL CALCULATIONS BY A CALL
C...  TO SUBROUTINE DERV (THE INITIAL-VALUE INTEGRATION THROUGH COMMON
C...  /Y/ AND /F/ IS DONE CORRECTLY WITHOUT THIS UPDATE, BUT SOME OF THE
C...  MODEL VARIABLES MAY BE ONE INTEGRATION TIME STEP BEHIND IN TIME,
C...  T, WHEN THEY ARE PRINTED OUT IN SUBROUTINE PRINT IF THE FOLLOWING
C...  CALL TO SUBROUTINE DERV IS NOT EXECUTED)
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  ***************************************************************
C...  GAS-PHASE MATERIAL BALANCE
C...  ************************************************************(1)
C...
C...     -(V/(G*S))*Y
C...                 Z
         DO 1 I=1,N
         TEP(I)=-P1*EPZ(I)
1        CONTINUE
         N2=1
         WRITE(NO,2)T,(TEP(I),I=1,N,N2)
2        FORMAT( 1H1,5H T = ,F7.3,//,
     1          25H -(V/(G*S))*YZ           ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(2)
C...
C...     (KY*AV/G)*(YS - Y)
         DO 3 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
3        CONTINUE
         WRITE(NO,4)(TEP(I),I=1,N,N2)
4        FORMAT(25H (KA*AV/G)*(YS - Y)      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(3)
C...
C...     Y
C...      T
         WRITE(NO,5)(YT(I),I=1,N,N2)
5        FORMAT(25H YT                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(4)
C...
C...     Y
         WRITE(NO,6)(Y(I),I=1,N,N2)
6        FORMAT(25H Y                       ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  EQUILIBRIUM RELATIONSHIP
C...  ************************************************************(5)
C...
C...     YS
         WRITE(NO,7)(YS(I),I=1,N,N2)
7        FORMAT(25H YS                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  GAS-PHASE ENERGY BALANCE
C...  ************************************************************(6)
C...
C...     -(V/(G*S))*EP  = -(V/(G*S))*(CPA*TG + Y*(CPV*TG + DHVAP))
C...                  Z                                           Z
         DO 8 I=1,N
         TEP(I)=-P1*EPZ(I)
8        CONTINUE
         WRITE(NO,9)(TEP(I),I=1,N,N2)
9        FORMAT(25H -(V/(G*S))*EPZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(7)
C...
C...     (H*AV/G)*(TL - TG)
         DO 10 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
10       CONTINUE
         WRITE(NO,11)(TEP(I),I=1,N,N2)
11       FORMAT(25H -(H*AV/G)*(TL - TG)     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(8)
C...
C...     (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
         DO 12 I=1,N
         TEP(I)=-P2*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
12       CONTINUE
         WRITE(NO,13)(TEP(I),I=1,N,N2)
13       FORMAT(25H (KY*AV/G)*(YS - Y)*(...),5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(9)
C...
C...     EV  = (CVA*TG + Y*(CVV*TG + DHVAP))
C...       T                                T
         WRITE(NO,14)(EVT(I),I=1,N,N2)
14       FORMAT(25H EVT                     ,5E12.4,/,13X,6E12.4,//)
C...  ************************************************************(10)
C...
C...     TG
         WRITE(NO,15)(TG(I),I=1,N,N2)
15       FORMAT(25H TG                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...  LIQUID-PHASE ENERGY BALANCE
C...  ************************************************************(11)
C...
C...     -(L/(H*S))*TL
C...                  Z
         DO 16 I=1,N
         TEP(I)=P4*TLZ(I)
16       CONTINUE
         WRITE(NO,17)(TEP(I),I=1,N,N2)
17       FORMAT(25H -(L/(H*S))*TLZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(12)
C...
C...     -(H*AV/(CL*H))*(TL - TG)
         DO 18 I=1,N
         TEP(I)=-P5*(TL(I)-TG(I))
18       CONTINUE
         WRITE(NO,19)(TEP(I),I=1,N,N2)
19       FORMAT(25H -(H*AV/(CL*H))*(TL-TG)  ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(13)
C...
C...     -(KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
         DO 20 I=1,N
         TEP(I)=-P6*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
20       CONTINUE
         WRITE(NO,21)(TEP(I),I=1,N,N2)
21       FORMAT(25H -(KY*AV/(CL*H))*(YS-Y)..,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(14)
C...
C...     TL
C...       T
         WRITE(NO,22)(TLT(I),I=1,N,N2)
22       FORMAT(25H TLT                     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(15)
C...
C...     TL
         WRITE(NO,23)(TL(I),I=1,N,N2)
23       FORMAT(25H TL                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,WR,WI,Z,RW,IW)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
PI CONTROL OF A HUMIDIFICATION COLUMN - ENGLISH UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
PI CONTROL OF A HUMIDIFICATION COLUMN - METRIC UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP SEP18
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A BINARY BATCH DISTILLATION SYSTEM
C...
C...  TO PREPARE FOR AN UP-COMING CONFRONTATION WITH THE HATFIELDS,
C...  GRANPA MCCOY IS PLANNING TO DISTILL A BATCH OF HIS CORN WHISKEY.
C...  THE STILL CONSISTS OF A KETTLE ABOVE WHICH IS A TEN-TRAY DIS-
C...  TILLATION COLUMN.  HE FILLS THE STILL FROM THE TOP WITH 100 MOLES
C...  OF A 50/50 MOLAR MIXTURE OF ETHANOL AND WATER (RELATIVE VOLATILITY
C...  = 1.4).  IN SO DOING, 0.5 MOLE REMAINS ON EACH TRAY OF THE DIS-
C...  TILLATION COLUMN.  HE THEN BUILDS A HICKORY-WOOD FIRE UNDER THE
C...  KETTLE AND ADDS FRESH LOGS AT A RATE THAT MAINTAINS A CONSTANT
C...  VAPOR BOILUP OF 10 MOLES/HR.  VAPOR LEAVING THE TOP OF THE COLUMN
C...  IS CONDENSED IN AN OLD AUTOMOBILE RADIATOR.  LIQUID REFLUX IS
C...  RETURNED ON TO THE TOP PLATE AT A RATE OF 7.5 MOLES/HR, LEAVING
C...  2.5 MOLES/HR OF LIQUID LIGHTNING PRODUCT.
C...
C...  THE PURPOSE OF THIS CASE STUDY IS TO INTEGRATE THE MATERIAL
C...  BALANCE EQUATIONS FOR THE DISTILLATION COLUMN TO DETERMINE XD(T)
C...  AND XB(T) (THE DISTILLATE AND BOTTOMS PRODUCT COMPOSITIONS AS A
C...  FUNCTION OF TIME) OVER A 7 HOUR PERIOD
C...
C...  THE FOLLOWING VARIABLES ARE USED IN THE DIFFERENTIAL EQUATIONS
C...  WHICH DESCRIBE THE DISTILLATION PROCESS
C...
C...     MB      TOTAL MOLES IN THE REBOILER
C...
C...     XB      LIQUID MOLE FRACTION OF ETHANOL IN THE REBOILER
C...
C...     YB      VAPOR MOLE FRACTION OF ETHANOL FROM THE REBOILER
C...             (ASSUMED TO BE IN EQUILIBRIUM WITH XB)
C...
C...     X(I)    LIQUID MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...
C...     Y(I)    VAPOR MOLE FRACTION OF ETHANOL FROM THE ITH PLATE
C...             (ASSUMED TO BE IN EQUILBRIUM WITH X(I))
C...
C...     REFLUX  REFLUX RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     VAPOR   VAPOR RATE (ASSUMED TO BE CONSTANT THROUGHOUT THE
C...             COLUMN AND INVARIANT WITH TIME) MOLES/HR
C...
C...     ALPHA   RELATIVE VOLATILITY OF ETHANOL WITH RESPECT TO WATER
C...
C...     DISTIL  DISTILLED (TOPS) PRODUCT RATE = VAPOR - REFLUX MOLES/HR
C...
C...     N       TOTAL NUMBER OF TRAYS IN THE COLUMN
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  SET THE SYSTEM PARAMETERS
      VAPOR=10.0
      REFLUX=7.5
      ALPHA=1.4
      DISTIL=VAPOR-REFLUX
      N=10
C...
C...  INITIAL CONDITONS (T = 0)
C...  MB(T) = 95.0, XB(T) = 0.5, X(I) = 0.5, I = 1, 2, 3,..., N
      MB=95.0
      XB=0.5
      DO 1 I=1,N
1     X(I)=0.5
C...
C...  CALCULATE THE INITIAL EQUILBRIUM VAPOR COMPOSITIONS
      YB=ALPHA*XB/(1.+(ALPHA-1.)*XB)
      DO 2 I=1,N
2     Y(I)=YB
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  CALCULATE THE EQUILIBRIUM VAPOR COMPOSITIONS
      YB=ALPHA*XB/(1.+(ALPHA-1.)*XB)
      DO 1 I=1,N
1     Y(I)=ALPHA*X(I)/(1.+(ALPHA-1.)*X(I))
C...
C...  TOTAL MATERIAL BALANCE FOR THE ENTIRE COLUMN
C...  DMB/DT = -DISTIL
      DMBDT=-DISTIL
C...
C...  ETHANOL MATERIAL BALANCE FOR THE REBOILER
C...  D(MB*XB)/DT = MB*DXB/DT + XB*DMB/DT = REFLUX*X(1) - VAPOR*YB
      DXBDT=(REFLUX*X(1)-VAPOR*YB-XB*DMBDT)/MB
C...
C...  ETHANOL MATERIAL BALANCE FOR THE FIRST PLATE
C...  0.5*DX(1)/DT = VAPOR*(YB - Y(1)) + REFLUX*(X(2) - X(1))
      DXDT(1)=2.0*(VAPOR*(YB-Y(1))+REFLUX*(X(2)-X(1)))
C...
C...  ETHANOL MATERIAL BALANCES FOR THE INTERMEDIATE PLATES, I = 2, 3,
C...  ..., N-1
C...  0.5*DX(I)/DT = VAPOR*(Y(I-1) - Y(I)) + REFLUX*(X(I+1) - X(I))
      NM1=N-1
      DO 2 I=2,NM1
2     DXDT(I)=2.0*(VAPOR*(Y(I-1)-Y(I))+REFLUX*(X(I+1)-X(I)))
C...
C...  ETHANOL MATERIAL BALANCE FOR THE TOP PLATE
C...  0.5*DX(N)/DT = VAPOR*(Y(N-1) - Y(N)) + REFLUX*(Y(N) - X(N))
      DXDT(N)=2.0*(VAPOR*(Y(N-1)-Y(N))+REFLUX*(Y(N)-X(N)))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        MB,        XB,     X(10)
     2      /F/     DMBDT,     DXBDT,  DXDT(10)
     3      /C/     VAPOR,    REFLUX,     ALPHA,    DISTIL,         N
     4      /V/        YB,      Y(10)
      REAL MB
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TPLOT(41),XPLOT(2,41)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED POINTS
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,1)VAPOR,REFLUX,DISTIL,ALPHA,N
1     FORMAT(26H DISTILLATION OF MOONSHINE,//,4X,62HINITIAL CHARGE = 100
     1 MOLES, 50/50 MOLAR SOLUTION ETHANOL/WATER,/,4X,14HBOILUP RATE = ,
     2F5.1,9H MOLES/HR,/,4X,14HREFLUX RATE = ,F5.1,9H MOLES/HR,/,4X,15HP
     3RODUCT RATE = ,F4.1,9H MOLES/HR,/,4X,22HRELATIVE VOLATILITY = ,F4.
     41,/,4X,18HNUMBER OF TRAYS = ,I2,//)
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(14X,4HTIME,10X,8HMOLES IN,6X,12HETHANOL CONC,6X,12HETHANOL
     1CONC,6X,12HETHANOL CONC,5X,16HETHANOL CONC VAP,/,13X,5HHOURS,11X,6
     2HKETTLE,9X,9HIN KETTLE,8X,10HIN PRODUCT,6X,14HLEAVING KETTLE,4X,15
     3HLEAVING PLATE 5)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,4)T,MB,XB,Y(N),YB,Y(5)
4     FORMAT(13X,F5.2,11X,F5.1,10X,F7.4,11X,F7.4,11X,F7.4,12X,F7.4)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TPLOT(IP)=T
      XPLOT(1,IP)=XB
      XPLOT(2,IP)=Y(N)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.41)RETURN
      CALL PLOTS(2,41,TPLOT,XPLOT)
C...
C...  LABEL THE PLOT
      WRITE(NO,6)
6     FORMAT(//,11X,9H1 - XB(T),3X,9H2 - XD(T))
      IP=0
      RETURN
      END
GRANPA MCCOY*S LIQUID LIGHTNING
0.        10.       0.25
   12  200    2    1  REL 0.001
END OF RUNS
*APP SEP19
      SUBROUTINE INITAL
C...
C...  EVAPORATION FROM A TANK
C...
C...  EVAPORATION FROM A TANK DEPICTED BELOW IS TO BE SIMULATED
C...
C...                                          CONVECTION
C...                         EVAPORATION         AND
C...                              +         . RADIATION
C...  AMBIENT TEMPERATURE = TA   .         .
C...  AMBIENT HUMIDITY = YA     .         .
C...                           .         .
C...              + .    TF   .         +   YI   .
C...              . ..............................
C...              . .                            .
C...              . .                            .
C...              Z .             TF             .+...........
C...              . .                            .           .
C...              . .                            .           .
C...              . .                            .           .
C...              + ..............................           .
C...                              .         RECIRCULATION .......
C...                              .              PUMP     .     .
C...                              .                       .......
C...                              .                          +
C...                              ............................
C...
C...  THE LIQUID (WATER) IN THE TANK CAN BE ASSUMED TO BE AT A UNIFORM
C...  TEMPERATURE, TF, THROUGHOUT THE TANK (PERFECTLY MIXED).
C...
C...  AN ENERGY BALANCE ON THE TANK GIVES
C...
C...     D(V*RHO*CP*TF)/DT = -KY*A*HVAP*(YI - YA) + H*A*(TA - TF)
C...                                                                (1)
C...                        + U*P*Z*(TA - TF)
C...
C...  WHERE
C...
C...     TF     TEMPERATURE OF LIQUID IN THE TANK
C...
C...     TA     AMBIENT TEMPERATURE
C...
C...     YA     AMBIENT HUMIDITY
C...
C...     YI     HUMIDITY AT THE LIQUID SURFACE (SATURATION HUMIDITY
C...            AT TEMPERATURE TF)
C...
C...     T      TIME
C...
C...     V      VOLUME OF LIQUID IN THE TANK
C...
C...     RHO    LIQUID DENSITY
C...
C...     CP     LIQUID HEAT CAPACITY
C...
C...     KY     MASS TRANSFER COEFFICIENT FOR EVAPORATION
C...
C...     A      TANK CROSS SECTIONAL AREA (AREA FOR HEAT AND MASS
C...            TRANSFER FROM THE SURFACE OF THE LIQUID TO THE
C...            SURROUNDING AIR)
C...
C...     HVAP   HEAT OF VAPORIZATION OF THE LIQUID
C...
C...     H      COEFFICIENT FOR HEAT TRANSFER FROM THE LIQUID SURFACE
C...
C...     U      COEFFICIENT FOR HEAT TRANSFER FROM THE WALL OF THE TANK
C...
C...     P      PERIMETER OF THE TANK
C...
C...     Z      HEIGHT OF THE TANK
C...
C...  THE INITIAL CONDITION FOR EQUATION (1) IS
C...
C...     TF(0) = 65 F                                               (2)
C...
C...  TWO CASES ARE PROGRAMMED
C...
C...     (1)  THE AMBIENT TEMPERATURE AND HUMIDITY, TA AND YA, ARE
C...          CONSTANT AT 80 F AND 44 PERCENT, RESPECTIVELY.
C...
C...     (2)  THE AMBIENT TEMPERATURE AND HUMIDITY, TA AND YA, VARY
C...          SINUSOIDALLY WITH TIME, WITH THE PERIOD OF OSCILLATION
C...          APPROXIMATELY 24 HOURS TO REFLECT NORMAL DAILY VARIATIONS
C...          AROUND THE CONSTANT LEVELS OF CASE (1).
C...
C...  THE VAPOR PRESSURE OF WATER IS GIVEN BY THE EQUATION
C...
C...     PV = 51.7*3206.7*EXP(6.53247 - 7173.79/(T + 389.4747))     (3)
C...
C...  WHICH IS USED IN THE CALCUATION OF THE HUMIDITIES, YA AND YI
C...  (SEE THE CODING IN SUBROUTINE DERV FOR THE DETAILS).  T IS THE
C...  TEMPERATURE IN F (T = TA OR TF WHEN THE AMBIENT HUMIDITY OR
C...  HUMIDITY AT THE LIQUID SURFACE ARE COMPUTED, RESPECTIVELY).
C...
C...  PLOTTING OF THE NUMERICAL SOLUTION IN SUBROUTINE PRINT GIVES AN
C...  INDICATION OF HOW TF AND YI VARY WITH TIME, PARTICULARLY FOR THE
C...  SECOND CASE (SINUSOIDAL VARIATION OF TA AND YA).
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  SET THE MODEL PARAMETERS
      V=808.
      RHO=62.3
      CP=1.0
      KYA=7.69*200.
      H=2.0
      A=200.
      U=H
      P=60.
      Z=4.
      HVAP=970.
C...
C...  SET THE MODEL INITIAL CONDITION
      TF=65.
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  AMBIENT TEMPERATURE
      TA=TAMB(T)
C...
C...  VAPOR PRESSURE IN ATMOSPHERES AT TEMPERATURES TF AND TA
      PVTF=51.7*3206.7*EXP(6.53247-7173.79/(TF+389.4747))/760.0
      PVTA=51.7*3206.7*EXP(6.53247-7173.79/(TA+389.4747))/760.0
C...
C...  CONVERSION OF PERCENT RELATIVE HUMIDITY TO RELATIVE HUMIDITY
      RH=PRH(T)/100.
C...
C...  HUMIDITIES AS WEIGHT OF WATER/UNIT WEIGHT OF AIR
      YI=PVTF*1./(1.0-PVTF*1.)*18./29.
      YA=PVTA*RH/(1.0-PVTA*RH)*18./29.
C...
C...  MODEL DIFFERENTIAL EQUATION
      DTFDT=(1./(V*RHO*CP))*(-KYA*HVAP*(YI-YA)+H*A*(TA-TF)
     1                     +U*P*Z*(TA-TF))
      RETURN
      END
      FUNCTION TAMB(T)
C...
C...  FUNCTION TAMB COMPUTES THE AMBIENT TEMPERATURE AS A FUNCTION OF
C...  TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=0.
      IF(NORUN.EQ.2)FREQ=4.
      PI=3.1415927
      TAMB=80.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      FUNCTION PRH(T)
C...
C...  FUNCTION PRH COMPUTES THE PERCENT RELATIVE HUMIDITY AS A FUNCTION
C...  OF TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=0.
      IF(NORUN.EQ.2)FREQ=4.
      PI=3.1415927
      PRH=44.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TIMEP(51), TP(2,51), YP(2,51), EP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HTF,4X,6HDTF/DT,8X,2HTA,8X,2HRH,8X,2HYI,8X,2HYA)
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      WRITE(NO,2)T,TF,DTFDT,TA,RH,YI,YA
2     FORMAT(1H ,/,7E10.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TIMEP(IP)=T
      TP(1,IP)=TA
      TP(2,IP)=TF
      YP(1,IP)=YA
      YP(2,IP)=YI
      EP(IP)=KYA*(YI-YA)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.51)RETURN
C...
C...  TA AND TF VS T
      CALL TPLOTS(2,IP,TIMEP,TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,48H 1 - TA, 2 - TF VS T                            )
C...
C...  YA AND YI VS T
      CALL TPLOTS(2,IP,TIMEP,YP)
      WRITE(NO,12)
12    FORMAT(1H ,//,48H 1 - YA, 2 - YI VS T                            )
C...
C...  KYA*(YI - YA) VS T
      CALL TPLOTS(1,IP,TIMEP,EP)
      WRITE(NO,13)
13    FORMAT(1H ,//,48H KYA*(YI - YA) VS T                             )
      IP=0
      RETURN
      END
EVAPORATION FROM A TANK, CONSTANT TA AND YA
0.        50.       1.
    1 1000    1    1  REL 0.001
EVAPORATION FROM A TANK, SINUSOIDAL TA AND YA
0.        50.       1.
    1 1000    1    1  REL 0.001
END OF RUNS
*APP SEP20
      SUBROUTINE INITAL
C...
C...  COUNTERCURRENT LIQUID-LIQUID EXTRACTOR FOR A PARTIALLY MISCIBLE
C...  SYSTEM
C...
C...  ACETONE IS TO BE RECOVERED FROM AN ACETONE-METHYLISOBUTYL-KETONE
C...  (MIK) SOLUTION IN A SIX-STAGE COUNTERCURRENT LIQUID-LIQUID EX-
C...  TRACTOR USING WATER (THAT ALSO CONTAINS SMALL AMOUNTS OF ACETONE
C...  AND MIK) AS A SOLVENT.  THE FEED ENTERS THE FIRST STAGE AT A MASS
C...  FLOW RATE FL0 AND ANALYZES W1L0 AND W2L0 MASS FRACTIONS OF WATER
C...  AND ACETONE, RESPECTIVELY.  THE SOLVENT ENTERS THE SIXTH STAGE AT
C...  A MASS FLOW RATE FH7 AND ANALYZES W1H7 AND W2H7 MASS FRACTIONS OF
C...  WATER AND ACETONE, RESPECTIVELY.
C...
C...  INITIALLY, THE CONCENTRATION OF EACH PHASE IN EACH STAGE CORRES-
C...  PONDS TO THAT OF THE FEED AND THE SOLVENT.  IN THIS SYSTEM, THE
C...  WATER AND MIK ARE PARTIALLY MISCIBLE.  THE MASS FLOW RATES OF THE
C...  TWO PHASES EXITING EACH STAGE ARE GIVEN BY
C...
C...     FHN = K1*MHN, FLN = K2*(MHN + MLN)                    (1)(2)
C...
C...  WHERE MHN AND MLN ARE THE MASSES OF THE HEAVY AND LIGHT PHASES
C...  IN STAGE N.
C...
C...  ASSUME THAT EQUILIBRIUM IS ATTAINED IN EACH STAGE WITH THE
C...  FOLLOWING EQUILBRIUM RELATIONSHIPS
C...
C...     W2H = A + B*W1L + C*W1L**2                               (3)
C...
C...     W1H = M + N*W2H + P*W2H**2                               (4)
C...
C...     W2L = D + E*W1L + F*W1L**2                               (5)
C...
C...  THE DETAILS OF THE MATHEMATICAL MODEL FOLLOW.
C...
C...  THE VARIABLES FOR STAGE N ARE INDICATED IN THE FOLLOWING DIAGRAM
C...  STAGE N ARE INDICATED IN THE FOLLOWING DIAGRAM
C...
C...                      ...............
C...             FLN-1    .  W1LN W2LN  .     FLN
C...          ............+     W3LN    .............+
C...                      .      LN     .
C...                      ...............
C...              FHN     .  W1HN W2HN  .    FHN+1
C...          +............     W3HN    +.............
C...                      .      HN     .
C...                      ...............
C...
C...  A TOTAL MATERIAL BALANCE FOR STAGE N GIVES
C...
C...     D(LN + HN)/DT = FLN-1 + FHN+1 - FLN - FHN                (6)
C...
C...  BALANCES FOR COMPONENTS 1 (WATER) AND 2 (ACETONE) GIVE
C...                                                              (7)
C...     D(LN*W1LN + HN*W1HN)/DT = FLN-1*W1LN-1 + FHN+1*W1HN+1
C...
C...                             - FLN*W1LN - FHN*W1HN
C...
C...     D(LN*W2LN + HN*W2HN)/DT = FLN-1*W2LN-1 + FHN+1*W2HN+1
C...                                                              (8)
C...                             - FLN*W2LN - FHN*W2HN
C...
C...  IF WE SET
C...
C...     MN = LN + HN                                             (9)
C...
C...     MN*W1MN = LN*W1LN + HN*W1HN                             (10)
C...
C...     MN*W2MN = LN*W2LN + HN*W2HN
C...
C...  EQUATIONS (9), (10) AND (11) CAN THEN BE SUBSTITUTED IN THE
C...  DERIVATIVES OF EQUATIONS (6), (7) AND (8) TO DEFINE THREE
C...  DEPENDENT VARIABLES OF THE ODES, MN, MN*W1MN AND MN*W2MN.  THE
C...  VARIABLES IN THESE EQUATIONS ARE
C...
C...     W1LN     MASS FRACTION OF COMPONENT 1   (WATER) IN THE LIGHT
C...              (MIK) PHASE IN STAGE N
C...
C...     W2LN     MASS FRACTION OF COMPONENT 2 (ACETONE) IN THE LIGHT
C...              (MIK) PHASE IN STAGE N
C...
C...     W3LN     MASS FRACTION OF COMPONENT 3     (MIK) IN THE LIGHT
C...              (MIK) PHASE IN STAGE N
C...
C...     W1HN     MASS FRACTION OF COMPONENT 1   (WATER) IN THE HEAVY
C...              (WATER) PHASE IN STAGE N
C...
C...     W2HN     MASS FRACTION OF COMPONENT 2 (ACETONE) IN THE HEAVY
C...              (WATER) PHASE IN STAGE N
C...
C...     W3HN     MASS FRACTION OF COMPONENT 3     (MIK) IN THE HEAVY
C...              (WATER) PHASE IN STAGE N
C...
C...     W1MN     MASS FRACTION OF COMPONENT 1   (WATER) IN THE COMBINED
C...              (MIK + WATER) PHASES IN STAGE N
C...
C...     W2MN     MASS FRACTION OF COMPONENT 2 (ACETONE) IN THE COMBINED
C...              (MIK + WATER) PHASES IN STAGE N
C...
C...     W3MN     MASS FRACTION OF COMPONENT 3     (MIK) IN THE COMBINED
C...              (MIK + WATER) PHASES IN STAGE N
C...
C...     FLN      MASS FLOW RATE OF THE LIGHT   (MIK) PHASE FROM STAGE N
C...
C...     FHN      MASS FLOW RATE OF THE HEAVY (WATER) PHASE FROM STAGE N
C...
C...     LN       HOLDUP OF THE LIGHT   (MIK) PHASE IN STAGE N
C...
C...     HN       HOLDUP OF THE HEAVY (WATER) PHASE IN STAGE N
C...
C...     MN       COMBINED HOLDUP OF THE LIGHT AND HEAVY PHASES (MIK +
C...              WATER) PHASES IN STAGE N
C...
C...  WE WILL ALSO NEED AN EQUATION DERIVED BY ELIMINATING MN, HN AND
C...  LN FROM EQUATIONS (9), (10) AND (11)
C...
C...     MN*W2MN = HN*W2HN + (MN - HN)*W2LN
C...
C...     MN*W1MN = HN*W1HN + (MN - HN)*W1LN
C...
C...  OR
C...
C...     (W2MN - W2LN)*MN = (W2HN - W2LN)*HN
C...
C...     (W1MN - W1LN)*MN = (W1HN - W1LN)*HN
C...
C...  DIVISION OF ONE EQUATION BY THE OTHER GIVES
C...
C...     (W2MN - W2LN)/(W1MN - W1LN) = (W2HN - W2LN)/(W1HN - W1LN)
C...
C...  OR SOLVING FOR W2MN
C...
C...     W2MN = W2LN + ((W2LN - W2HN)/(W1LN - W1HN))*(W1MN - W1LN)  (12)
C...
C...  THE POINTS (W1LN,W2LN), (W1HN,W2HN) AND (W1MN,W2MN) LIE ON A
C...  STRAIGHT LINE.  FURTHERMORE, THE FIRST TWO POINTS WILL BE ON THE
C...  EQUIULIBRIUM CURVES FOR EACH PHASE.  THUS, IF WE KNOW ONE POINT,
C...  THE OTHER TWO CAN BE CALCULATED (FROM THE LINEAR EQUATIONS AND
C...  THE EQUILIBRIUM RELATIONSHIPS).
C...
C...  IF WE ASSUME THAT THE POINT (W1MN,W2MN) HAS BEEN DETERMINED BY
C...  INTEGRATING THE ODES NUMERICALLY, IN ORDER TO COMPUTE THE OTHER
C...  TWO POINTS WE NEED THE EQUILIBRIUM RELATIONSHIPS.  AN ALGORITHM
C...  FOR THE CALCULATIONS FOLLOWS
C...
C...     (1)  ASSUME W2LN = 0.5*W2MN
C...
C...     (2)  CALCULATE W1LN (USING THE EQUILIBRIUM RELATIONSHIP FOR
C...                          THE LIGHT PHASE, EQUATION (15))
C...
C...     (3)  CALCULATE W1HN (USING THE EQUILIBRIUM RELATIONSHIP FOR
C...                          THE CONJUGATE LINE, EQUATION (17))
C...
C...     (4)  CALCULATE W2HN (USING THE EQUILIBRIUM RELATIONSHIP FOR
C...                          THE HEAVY PHASE, EQUATION (16))
C...
C...                        (C)
C...     (5)  CALCULATE W2MN   (USING EQUATION (12))
C...
C...                     (C)
C...     (6)  IF ABS(W2MN    - W2MN) LE 0.001, EXIT THE ALGORITHM
C...             (SINCE THE CALCULATION HAS CONVERGED)
C...
C...                     (C)
C...          IF ABS(W2MN    - W2MN) GT 0.001
C...                                        (C)
C...             SET W2LN = W2LN - 0.5*(W2MN    - W2M(N)) AND GO TO (2)
C...
C...          THE LAST STEP IN (6) FOR THE CALCULATION OF A NEW W2LN IS
C...          BASED ON INTERVAL HALVING.
C...
C...  ONCE THE CALCULATION HAS CONVERGED, WE HAVE THE THREE COMPOSITION
C...  POINTS AND THEREFORE HN AND LN CAN BE COMPUTED FROM
C...
C...     LN = (W1MN - W1HN)/(W1LN - W1HN)*MN                      (13)
C...
C...     HN = MN - LN                                             (14)
C...
C...  THE EQUILIBRIUM RELATIONSHIPS FOR THE WATER-ACETONE-MIK SYSTEM
C...  ARE
C...
C...  MIK PHASE                                                   (15)
C...
C...     W2LN =  0.38658 + 0.66147*W1LN - 1.255*W1LN**2,  W2LN GT 0.4345
C...
C...     W2LN = -0.22626 + 12.852*W1LN - 60.356*W1LN**2,  W2LN LE 0.4345
C...
C...  WATER PHASE                                                 (16)
C...
C...     W2HN = 0.67714 - 0.37644*W1HN - 0.3233*W1HN**2,  W2HN LE 0.35
C...
C...     W2HN = 0.38658 + 0.66147*W1HN - 1.255*W1HN**2,   W2HN GT 0.35
C...
C...  CONJUGATE
C...
C...     W2LN = 0.16279 + 1.4376*W1HN - 1.6344*W1HN**2            (17)
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     FEED COMPOSITION AND FLOW
C...
C...        W1L0 = 0, W2L0 = 0.4, W3L0 = 0.6, FL0 = 5
C...
C...     SOLVENT COMPOSITION AND FLOW
C...
C...        W1H7 = 0.98, W2H7 = 0.02, W3H7 = 0., FH7 = 4
C...
C...     INITIAL CONDITIONS
C...
C...        W1LN(0) = 0, W2LN(0) = 0.4, W1HN(0) = 0.98, W2HN(0) = 0.02
C...
C...        LN(0) = HN(0) = 500, N = 1, 2, ..., 6
C...
C...     FLOWS
C...
C...        FHN = 0.01*HN, FLN = 0.005*(HN + LN), N = 1, 2, ..., 6
C...
C...  SIMULATE THIS SYSTEM TO DETERMINE
C...
C...     (1)  CONCENTRATIONS OF STREAMS EXITING FROM THE EXTRACTION
C...          UNIT
C...
C...     (2)  PERCENT RECOVERY OF ACETONE
C...
C...     (3)  FLOW RATES OUT OF EACH STAGE
C...
C...  COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...
C...  NUMBER OF STAGES
      NS=6
C...
C...  FEED COMPOSITION AND FLOW
      W1L(0)=0.
      W2L(0)=0.4
      FL(0)=5.
C...
C...  SOLVENT COMPOSITION AND FLOW
      W1H(NS+1)=0.98
      W2H(NS+1)=0.02
      FH(NS+1)=4.
C...
C...  INITIAL CONDITIONS
C...
C...  LIGHT PHASE
      DO 1 N=1,NS
      L(N)=500.
      W1L(N)=0.
      W2L(N)=0.4
C...
C...  HEAVY PHASE
      H(N)=500.
      W1H(N)=0.98
      W2H(N)=0.02
C...
C...  MIXED PHASE
      MW1M(N)=L(N)*W1L(N)+H(N)*W1H(N)
      MW2M(N)=L(N)*W2L(N)+H(N)*W2H(N)
      M(N)=L(N)+H(N)
1     CONTINUE
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...  MODEL ALGEBRA
C...
C...     MIXED PHASE COMPOSITIONS
         DO 2 N=1,NS
         W1M(N)=MW1M(N)/M(N)
         W2M(N)=MW2M(N)/M(N)
2        CONTINUE
C...
C...     EQUILIBRIUM LIGHT AND HEAVY PHASE COMPOSITIONS
         CALL EQUIL
C...
C...     LIGHT PHASE HOLDUP
         CALL LN
C...
C...     HEAVY PHASE HOLDUP
         CALL HN
C...
C...     LIGHT PHASE FLOW RATE
         CALL FLN
C...
C...     HEAVY PHASE FLOW RATE
         CALL FHN
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DO 1 N=1,NS
      DMDT(N)  =FL(N-1)         +FH(N+1)
     1         -FL(N  )         -FH(N  )
      DMW1DT(N)=FL(N-1)*W1L(N-1)+FH(N+1)*W1H(N+1)
     1         -FL(N  )*W1L(N  )-FH(N  )*W1H(N  )
      DMW2DT(N)=FL(N-1)*W2L(N-1)+FH(N+1)*W2H(N+1)
     1         -FL(N  )*W2L(N  )-FH(N  )*W2H(N  )
1     CONTINUE
      RETURN
      END
      SUBROUTINE EQUIL
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
      COMMON/IO/       NI,        NO
C...
C...  SUBROUTINE EQUIL CALCULATES THE LIGHT AND HEAVY PHASE EQUILIBRIUM
C...  COMPOSITIONS
C...
C...  SET THE MAXIMUM NUMBER OF ITERATIONS AND TOLERANCE IN THE CAL-
C...  CULATION OF THE LIGHT AND HEAVY PHASE COMPOSITIONS
      NMAX=25
      TOL=0.001
C...
C...  STEP THROUGH THE NS STAGES
      DO 1 N=1,NS
C...
C...  INITIALIZE THE ITERATION COUNTER
      ITER=0
C...
C...  INITIAL ESTIMATE OF W2L(N)
      W2L(N)=0.5*W2M(N)
C...
C...  W1L(N) FROM THE LIGHT PHASE EQUILIBRIUM RELATIONSHIP
2     W1L(N)=ELIGHT(W2L(N))
C...
C...  W1H(N) FROM THE CONJUGATE LINE EQUILIBRIUM RELATIONSHIP
      W1H(N)=ECONJG(W2L(N))
C...
C...  W2H(N) FROM THE HEAVY PHASE EQUILIBRIUM RELATIONSHIP
      W2H(N)=EHEAVY(W1H(N))
C...
C...        (C)
C...  W2M(N)    FROM THE DEFINITIONS OF M(N), W1M(N) AND W2M(N)
      W2MC=W2L(N)+(W2L(N)-W2H(N))/(W1L(N)-W1H(N))*(W1M(N)-W1L(N))
C...
C...  CHECK FOR CONVERGENCE
      IF(ABS(W2MC-W2M(N)).LE.0.001)THEN
C...
C...     CONVERGENCE HAS BEEN ACHIEVED AND THE LIGHT AND HEAVY PHASE
C...     COMPOSITIONS ARE AVAILABLE FOR SUBSEQUENT CALCULATIONS
         GO TO 1
C...
C...     CONVERGENCE HAS NOT BEEN ACHIEVED, SO CONTINUE THE ITERATIVE
C...     CALCULATION OF THE LIGHT AND HEAVY PHASE COMPOSITIONS
      ELSE
         W2L(N)=W2L(N)-0.5*(W2MC-W2M(N))
         ITER=ITER+1
         IF(ITER.LT.NMAX)GO TO 2
         WRITE(NO,3)N
3        FORMAT(1H ,//,30H CONVERENCE FAILURE FOR STAGE ,I2)
         GO TO 1
      END IF
C...
C...  CONVERGENCE OCCURRED IN ITERATION NMAX
1        CONTINUE
      RETURN
      END
      FUNCTION ELIGHT(W2LN)
C...
C...  FUNCTION ELIGHT COMPUTES W1L(N) FROM W2L(N)
      IF(W2LN.GT.0.4345)THEN
         A=-1.255
         B=0.66147
         C=0.38658-W2LN
         ELIGHT=(-B+SQRT(B**2-4.0*A*C))/(2.0*A)
         IF(ELIGHT.LT.0.)ELIGHT=0.
         IF(ELIGHT.GT.1.)ELIGHT=1.
         RETURN
      ELSE
         A=-60.356
         B= 12.852
         C=-0.22626-W2LN
         ELIGHT=(-B+SQRT(B**2-4.0*A*C))/(2.0*A)
         IF(ELIGHT.LT.0.)ELIGHT=0.
         IF(ELIGHT.GT.1.)ELIGHT=1.
         RETURN
      END IF
      END
      FUNCTION ECONJG(W2LN)
C...
C...  FUNCTION ECONJG COMPUTES W1H(N) FROM W2L(N)
         A=-1.6344
         B= 1.4367
         C=0.16279-W2LN
         ECONJG=(-B-SQRT(B**2-4.0*A*C))/(2.0*A)
         IF(ECONJG.LT.0.)ECONJG=0.
         IF(ECONJG.GT.1.)ECONJG=1.
         RETURN
      END
      FUNCTION EHEAVY(W1HN)
C...
C...  FUNCTION EHEAVY COMPUTES W2H(N) FROM W1H(N)
      COMMON/IO/NI,NO
      W2HNA=0.67714-0.37644*W1HN-0.3233*W1HN**2
      W2HNB=0.38658+0.66147*W1HN-1.255 *W1HN**2
      IF(W2HNA.LE.0.35)THEN
         EHEAVY=W2HNA
         GO TO 1
      ELSE IF(W2HNB.GT.0.35)THEN
         EHEAVY=W2HNB
         GO TO 1
      ELSE
         WRITE(NO,2)
2        FORMAT(1H ,//,
     1   51H WH2N NOT CALCULATED CORRECTLY FROM THE HEAVY PHASE,/,
     2   51H EQUILIBRIUM EQUATIONS SO RUN IS TERMINATED        )
         STOP
      END IF
C...
C...  CONSTRAIN THE MASS FRACTIONS TO MEANINGFUL VALUES
1     IF(EHEAVY.LT.0.)EHEAVY=0.
      IF(EHEAVY.GT.1.)EHEAVY=1.
      RETURN
      END
      SUBROUTINE LN
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...  SUBROUTINE LN CALCULATES THE LIGHT PHASE HOLDUP
      DO 1 N=1,NS
      L(N)=(W1M(N)-W1H(N))/(W1L(N)-W1H(N))*M(N)
1     CONTINUE
      RETURN
      END
      SUBROUTINE HN
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...  SUBROUTINE HN CALCULATES THE HEAVY PHASE HOLDUP
      DO 1 N=1,NS
      H(N)=M(N)-L(N)
1     CONTINUE
      RETURN
      END
      SUBROUTINE FLN
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...  SUBROUTINE FLN COMPUTES FL(N)
      DO 1 N=1,NS
      FL(N)=0.005*(H(N)+L(N))
1     CONTINUE
      RETURN
      END
      SUBROUTINE FHN
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
      REAL              M,      MW1M,      MW2M,         L
C...
C...  SUBROUTINE FHN COMPUTES FH(N)
      DO 1 N=1,NS
      FH(N)=0.01*H(N)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      M(6),   MW1M(6),   MW2M(6)
     2      /F/   DMDT(6), DMW1DT(6), DMW2DT(6)
     3      /V/   FL(0:6),   FH(1:7),
     4           W1L(0:6),  W2L(0:6),
     5           W1H(1:7),  W2H(1:7),
     6           W1M(1:6),  W2M(1:6),
     7             L(1:6),    H(1:6),
     8                 NS,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION    TP(51),W2HP(2,51),    RP(51)
      REAL              M,      MW1M,      MW2M,         L
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).NE.(IP-1))GO TO 2
      WRITE(NO,1)T,    W1L(0),   W1L(NS),    W1H(1), W1H(NS+1),
     1                 W2L(0),   W2L(NS),    W2H(1), W2H(NS+1),
     2                  FL(0),    FL(NS),     FH(1),  FH(NS+1),
     3                   L(1),     L(NS),      H(1),     H(NS)
1     FORMAT(1H ,//,9X,1HT,
     1       4X,6HW1L(0),3X,7HW1L(NS),4X,6HW1H(1),1X,9HW1H(NS+1),/,
     2      14X,6HW2L(0),3X,7HW2L(NS),4X,6HW2H(1),1X,9HW2H(NS+1),/,
     3      14X,6H FL(0),3X,7H FL(NS),4X,6H FH(1),1X,9H FH(NS+1),/,
     4      14X,6H  L(1),3X,7H  L(NS),4X,6H  H(1),1X,9H    H(NS),/,
     5 F10.3,4F10.4,/,10X,4F10.4,/,10X,4F10.4,/,10X,4F10.4)
C...
C...  STORE THE SOLUTION FOR PLOTTING
2     TP(IP)=T
      W2HP(1,IP)=W2H(NS+1)
      W2HP(2,IP)=W2H(   1)
      RP(IP)=(W2H(1)*FH(1))/(W2L(0)*FL(0)+W2H(NS+1)*FH(NS+1))*100.
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL TPLOTS(2,IP,TP,W2HP)
      WRITE(NO,10)
10    FORMAT(1H ,//,43H 1 - W2H(NS+1), 2 - W2H(1) VS T            )
      CALL TPLOTS(1,IP,TP,  RP)
      WRITE(NO,11)
11    FORMAT(1H ,//,43H PERCENT RECOVERY OF ACETONE VS T          )
      RETURN
      END
EXTRACTOR FOR A PARTIALLY MISCIBLE SYSTEM
0.        500.      10.
   18 1000    1    1  REL 0.001
END OF RUNS
*APP SEP21
      SUBROUTINE INITAL
C...
C...  EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
C...
C...  THE FOLLOWING EQUATIONS DESCRIBE THE DYNAMICS OF A HUMIDIFIER
C...  (A PACKED COLUMN WITH WATER AND AIR FLOWING COUNTERCURRENTLY)
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                  (1)
C...      T                Z
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                      (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                      (3)
C...
C...                          - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THE GAS FLOW RATE, V, IS TO BE CONTROLLED BY A PROPORTIONAL-
C...  INTEGRAL CONTROLLER ACCORDING TO THE EQUATIONS
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TSET
C...
C...  WHERE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TSET    CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS ARE
C...
C...   H*AV = 50 BTU/(HR-FT**3 OF COLUMN-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3 COLUMN)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2 COLUMN
C...
C...   H = 0.5 LB MOLS/(FT**3 COLUMN), G = 0.01 LB MOLS/(FT**3 COLUMN)
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TSET = 90 F
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  ALSO, THREE RUNS  ARE PROGRAMMED
C...
C...     (1)  KC AND TI ARE SELECTED FOR A WELL-TUNED CONTROLLER
C...          SO THE HUMIDIFICATION COLUMN RESPONDS NEARLY OPTIMALLY
C...          (FAST RESPONSE WITH LITTLE OVERSHOOT).
C...
C...     (2)  PROPORTIONAL CONTROL ONLY WITH THE GAIN NEAR THE
C...          ULTIMATE VALUE FOR SUSTAINED OSCILLATION.
C...
C...     (3)  ONE HALF THE GAIN OF (2) WITH INTEGRAL ACTION ADDED
C...          TO AGAIN PRODUCE NEARLY SUSTAINED OSCILLATION.
C...
C...  AS THE SYSTEM MOVES CLOSER TO SUSTAINED OSCILLATION, I.E., CASES
C...  (2) AND (3), THE TEMPORAL EIGENVALUES COMPUTED BY CALLS TO SUB-
C...  ROUTINE EIGEN IN SUBROUTINE PRINT, SHOULD MOVE CLOSER TO PURE
C...  IMAGINARY VALUES.  THIS EFFECT CAN BE CHECKED BY COMPARING THE
C...  EIGENVALUES COMPUTED AND PRINTED FOR THE THREE RUNS.
C...
C...  THESE THREE RUNS CAN BE RUN CONSECUTIVELY, BUT THE TOTAL RUN
C...  TIME IS RATHER LARGE.  THEREFORE, THEY ARE PROGRAMMED TO RUN
C...  INDIVIDUALLY (SEE THE SUBSEQUENT CODING FOR SETTING KC AND TI
C...  IN SUBROUTINE INITIAL), AND ONLY ONE SET OF DATA IS USED.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  SET THE COLUMN PARAMETERS
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS (NOTE THAT THE CONTROLLER PARA-
C...  METERS ARE SELECTED FOR A SINGLE RUN BY REMOVING COMMENTS
C...  RATHER THAN EXECUTION OF THREE SUCCESSIVE RUNS VIA THE IF-
C...  THEN-ELSE CONSTRUCT)
C...
C...  WELL TUNED CONTROLLER
C...  IF(NORUN.EQ.1)THEN
         KC=0.02
         TI=0.1
C...
C...  ULTIMATE GAIN
C...  ELSE IF(NORUN.EQ.2)THEN
C...     KC=0.4
C...     TI=1.0E+10
C...
C...  ULTIMATE PERIOD (WITH INTEGRAL ACTION)
C...  ELSE
C...     KC=0.2
C...     TI=0.02
C...  END IF
      CVDP=50.
      XSS=0.5
      TSET=90.
      IP=0
      N=11
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      TL(I)=110.
      TG(I)=110.
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      TL(N)=110.
      TG(1)=110.
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  ABSOLUTE DIMENSIONING OF THE ARRAYS REQUIRED BY SUBROUTINE JMAP
C...  (A, Y, YOLD, F, FOLD) AND SUBROUTINE EIGEN (WI, WR, Z, RW, IW)
      REAL
     1       A( 34, 34), WR( 34), WI( 34), Z( 34, 34), RW( 34),
     2                            SV( 34), SVOLD( 34),
     3                             F( 34),  FOLD( 34)
      INTEGER                     IW( 34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  MAP THE ODE JACOBIAN MATRIX AND COMPUTE THE TEMPORAL EIGENVALUES
C...  AT T = 0, 0.25, 0.5 TO OBSERVE THE CHANGE IN THE MODEL STRUCTURE
C...  AND EIGENVALUES DUE TO THE NONLINEARITIES
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,WR,WI,Z,RW,IW)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP SEP22
      SUBROUTINE INITAL
C...
C...  NON-EQUILIBRIUM MODEL FOR FIXED-BED MULTI-COMPONENT ADIABATIC
C...  ADSORPTION (CHROMATOGRAPHY)
C...
C...  THE FOLLOWING ADSORPTION MODEL WAS TAKEN FROM
C...
C...  HARWELL, JEFF H., ATHANASIOS I. LIAPIS, R. LITCHFIELD AND DANIEL
C...  T. HANSON, A NON-EQUILIBRIUM MODEL FOR FIXED-BED MULTI-COMPONENT
C...  ADIABATIC ADSORPTION, CHEM. ENG. SCI., VOL. 35, PP 2287-2296, 1980
C...
C...  EQUATIONS (6), (7), (8), (9), (10) AND (11) ARE PROGRAMMED WITH
C...  THE PARAMETERS IN TABLE 1, DIMENSIONLESS DISTANCE X/L AND TIME
C...  T*V/L.  DIMENSIONLESS FLUID CONCENTRATION, SOLID CONCENTRATION,
C...  EQUILBIRUM SOLID CONCENTRATION, FLUID TEMPERATURE AND SOLID TEMP-
C...  PERATURE WERE NOT USED PRIMARILY BECAUSE EQUATIONS (10) AND (11)
C...  WOULD THEN HAVE TO BE EXPRESSED IN TERMS OF DIMENSIONLESS CON-
C...  CENTRATIONS AND TEMPERATURES.
C...
C...  REFERENCES TO THE EQUATIONS IN THE HARWELL PAPER APPEAR WHEN THEY
C...  ARE PROGRAMMED.
C...
      COMMON/T/         T,    NOSTOP,     NORUN
     1      /Y/    TG(21),    TS(21),    C1(21),
     2             Q1(21),    C2(21),    Q2(21)
     3      /F/   TGT(21),   TST(21),   C1T(21),
     4            Q1T(21),   C2T(21),   Q2T(21)
     5      /C/         N,         L,         V,    CIN(2),        A,
     6     EPS,    RHOGIN,       CPG,       CPS,      RHOS,        H,
     7   KP(2),     DH(2),      TGIN,       PT,      QL(2),   KOL(2),
     8      NG,     QE(2),      C(2),     KL(2),     D1(2),       D2,
     9      D3,     D4(2),     D5(2),        C0,        Q0,       T0
      REAL L,KP,KOL,KL
C...
C...  SET THE MODEL PARAMETERS, PRIMARILY FROM TABLE 1, HARWELL ET AL.
C...  UNITS FOR THE MODEL PARAMETERS ARE LISTED IN TABLE 1
C...
C...     NUMBER OF COMPONENTS
         N=2
C...
C...     COLUMN LENGTH, FLUID VELOCITY
         L=0.5
         V=0.0015
C...
C...     ENTERING CONCENTRATIONS
         CIN(1)=0.020
         CIN(2)=0.030
C...
C...     HEAT AND MASS TRANSFER AREA PER UNIT VOLUME OF COLUMN, VOID
C...     FRACTION
         A=60.0
         EPS=0.360
C...
C...     ENTERING GAS DENSITY, GAS HEAT CAPACITY
         RHOGIN=1.41E+03
         CPG=37.7
C...
C...     SOLID DENSITY, SOLID HEAT CAPACITY
         RHOS=1.30E+06
         CPS=1.05
C...
C...     HEAT TRANSFER COEFFICIENT, MASS TRANSFER COEFFICIENTS  Q
         H=41.9
         KP(1)=1.00
         KP(2)=0.800
C...
C...     HEATS OF ADSORPTION
         DH(1)=-3.27E+04
         DH(2)=-4.35E+04
C...
C...     ENTERING GAS TEMPERATURE, COLUMN PRESSURE
         TGIN=293.
         PT=34.
C...
C...     CONSTANTS IN THE LANGMUIR ISOTHERM
         QL(1)=2.90E-03
         QL(2)=3.67E-03
         KOL(1)=1.26E-02
         KOL(2)=4.73E-02
C...
C...
C...  COMPUTE THE CONSTANTS IN EQUATIONS (6), (7), (8) AND (9) WITH THE
C...  USE OF DIMENSIONLESS DISTANCE X/L AND TIME T*V/L
         D1(1)=(L/V)*(RHOS/RHOGIN)*((EPS-1.)/EPS)*(KP(1)*A/RHOS)
         D1(2)=(L/V)*(RHOS/RHOGIN)*((EPS-1.)/EPS)*(KP(2)*A/RHOS)
         D2   =(L/V)*(H*A*(1.-EPS)/(RHOGIN*CPG*EPS))
         D3   =(L/V)*(H*A)/(RHOS*CPS)
         D4(1)=(L/V)*(1./CPS)*DH(1)*KP(1)*A/RHOS
         D4(2)=(L/V)*(1./CPS)*DH(2)*KP(2)*A/RHOS
         D5(1)=(L/V)*(KP(1)*A/RHOS)
         D5(2)=(L/V)*(KP(2)*A/RHOS)
C...
C...  SET THE MODEL INITIAL CONDITIONS OVER NG SPATIAL GRID POINTS IN Z
         NG=21
         C0=1.0E-15
         Q0=1.0E-15
         T0=293.
         DO 1 I=1,NG
         C1(I)=C0
         C2(I)=C0
         Q1(I)=Q0
         Q2(I)=Q0
         TG(I)=T0
         TS(I)=T0
1        CONTINUE
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE EQUIL1(QE,C,QL,KL,N)
C...
C...  SUBROUTINE EQUIL1 COMPUTES THE SOLID CONCENTRATION IN EQUILBRIUM
C...  WITH THE GAS
C...
C...  ARGUMENT LIST
C...
C...     QE      EQUILBRIUM SOLID CONCENTRATIONS (MOLS OF COMPONENT I/G
C...             OF SOLID) (OUTPUT)
C...
C...     C       GAS CONCENTRATIONS (MOLS OF COMPONENT I/MOL OF GAS)
C...             (INPUT)
C...
C...     QL      Q CONSTANTS IN THE LANGMUIR ISOTHERM, EQUATION (10)
C...             (MOLS OF COMPONENT I/G OF SOLID) (INPUT)
C...
C...     KL      K CONSTANTS IN THE LANGMUIR ISOTHERM, EQUATION (10)
C...             (MOLS OF GAS/MOL OF COMPONENT I) (INPUT)
C...
C...     N       NUMBER OF COMPONENTS IN THE GAS (INPUT)
C...
      DIMENSION      QE(N),   C(N),     QL(N),     KL(N)
      REAL KL
C...
C...  EQUATION (10)
      SUM=1.
      DO 1 I=1,N
      SUM=SUM+KL(I)*C(I)
1     CONTINUE
      DO 2 I=1,N
      QE(I)=QL(I)*KL(I)*C(I)/SUM
2     CONTINUE
      RETURN
      END
      SUBROUTINE EQUIL2(KL,KOL,TS,PT,DH,N)
C...
C...  SUBROUTINE EQUIL2 COMPUTES THE LANGMUIR CONSTANTS, KI, IN EQUATION
C...  (11)
C...
C...  ARGUMENT LIST
C...
C...     KL      LANGMUIR CONSTANTS, KI, IN EQUATION (11) (MOLS OF GAS/
C...             MOL OF COMPONENT I) (OUTPUT)
C...
C...     KOL     CONSTANTS KOI IN EQUATION (11) (MOLS OF GAS K**0.5/
C...             MOL OF COMPONENT I ATM) (INPUT)
C...
C...     TS      SOLID TEMPERATURE (K) (INPUT)
C...
C...     PT      TOTAL COLUMN PRESSURE (ATM) (INPUT)
C...
C...     DH      MOLAR HEATS OF ADSORPTION (J/MOL) (INPUT)
C...
C...     N       NUMBER OF COMPONENTS IN THE GAS (INPUT)
C...
      DIMENSION      KL(N),   KOL(N),     DH(N)
      REAL KL,KOL
      DATA R/8.314/
C...
C...  EQUATION (10)
      DO 1 I=1,N
      KL(I)=KOL(I)*(1./SQRT(TS))*PT*EXP((-DH(I))/(R*TS))
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,    NOSTOP,     NORUN
     1      /Y/    TG(21),    TS(21),    C1(21),
     2             Q1(21),    C2(21),    Q2(21)
     3      /F/   TGT(21),   TST(21),   C1T(21),
     4            Q1T(21),   C2T(21),   Q2T(21)
     5      /C/         N,         L,         V,    CIN(2),        A,
     6     EPS,    RHOGIN,       CPG,       CPS,      RHOS,        H,
     7   KP(2),     DH(2),      TGIN,       PT,      QL(2),   KOL(2),
     8      NG,     QE(2),      C(2),     KL(2),     D1(2),       D2,
     9      D3,     D4(2),     D5(2),        C0,        Q0,       T0
C...
C...  DIMENSION THE ARRAYS FOR THE SPATIAL DERIVATIVES IN Z  T
      COMMON/S/   TGZ(21),  TGZZ(21),
     1            C1Z(21),  C1ZZ(21),   C2Z(21),  C2ZZ(21)
      REAL L,KP,KOL,KL
C...
C...  CONSTRAIN THE CONCENTRATIONS TO SMALL POSITIVE VALUES
         DO 2 I=1,NG
         IF(C1(I).LT.C0)C1(I)=C0
         IF(C2(I).LT.C0)C2(I)=C0
         IF(Q1(I).LT.Q0)Q1(I)=Q0
         IF(Q2(I).LT.Q0)Q2(I)=Q0
2        CONTINUE
C...
C...  SET THE BOUNDARY CONDITIONS AT Z = 0
         C1(1)=CIN(1)
         C2(1)=CIN(2)
         TG(1)=TGIN
C...
C...  COMPUTE THE FIRST-ORDER SPATIAL DERIVATIVES IN Z BY TWO-POINT
C...  UPWIND APPROXIMATIONS
         CALL DSS012(0.,L,NG,C1,C1Z,1.)
         CALL DSS012(0.,L,NG,C2,C2Z,1.)
         CALL DSS012(0.,L,NG,TG,TGZ,1.)
C...
C...  ASSEMBLE THE PDES
         DO 1 I=1,NG
C...
C...     COMPUTE THE EQUILBRIUM SOLID CONCENTRATIONS AT GRID POINT I
         TSL=TS(I)
         CALL EQUIL2(KL,KOL,TSL,PT,DH,N)
         C(1)=C1(I)
         C(2)=C2(I)
         CALL EQUIL1(QE,C,QL,KL,N)
C...
C...     EQUATIONS (6)
         C1T(I)=-C1Z(I)+D1(1)*(QE(1)-Q1(I))
         C2T(I)=-C2Z(I)+D1(2)*(QE(2)-Q2(I))
C...
C...     EQUATION (7)
         TGT(I)=-TGZ(I)+D2*(TS(I)-TG(I))
C...
C...     EQUATION (8)
         TST(I)=D3*(TG(I)-TS(I))
     1         -(D4(1)*(QE(1)-Q1(I))+D4(2)*(QE(2)-Q2(I)))
C...
C...     EQUATIONS (9)
         Q1T(I)=D5(1)*(QE(1)-Q1(I))
         Q2T(I)=D5(2)*(QE(2)-Q2(I))
1        CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES FOR THE CONSTANT BOUNDARY CONDITIONS
C...  AT Z = 0
         C1T(1)=0.
         C2T(1)=0.
         TGT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,    NOSTOP,     NORUN
     1      /Y/    TG(21),    TS(21),    C1(21),
     2             Q1(21),    C2(21),    Q2(21)
     3      /F/   TGT(21),   TST(21),   C1T(21),
     4            Q1T(21),   C2T(21),   Q2T(21)
     5      /C/         N,         L,         V,    CIN(2),        A,
     6     EPS,    RHOGIN,       CPG,       CPS,      RHOS,        H,
     7   KP(2),     DH(2),      TGIN,       PT,      QL(2),   KOL(2),
     8      NG,     QE(2),      C(2),     KL(2),     D1(2),       D2,
     9      D3,     D4(2),     D5(2),        C0,        Q0,       T0
      COMMON/S/   TGZ(21),  TGZZ(21),
     1            C1Z(21),  C1ZZ(21),   C2Z(21),  C2ZZ(21)
      REAL L,KP,KOL,KL
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTIONS
      DIMENSION CTP(2,15),QTP(2,15),TTP(2,15),
     1          CZP(6,21),QZP(6,21),TZP(6,21),
     2          TP(15),ZP(21)
C...
C...  INITIALIZE A COUNTER FOR THE CALLS TO SUBROUTINE PRINT
      DATA IT/0/
C...
C...  IN THE FIRST CALL TO PRINT, PRINT THE CONSTANTS D1 TO D5
      IF(IT.EQ.0)WRITE(NO,1)
     1 (D1(I),I=1,N),D2,D3,(D4(I),I=1,N),(D5(I),I=1,N)
1     FORMAT(1H ,43H CONSTANTS D1 TO D5 IN EQUATIONS (6) TO (9),//,
     1 2E12.3,/,E12.3,/,E12.3,/,2E12.3,/,2E12.3,//)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,(C1(I),I=1,NG,2),(C2(I),I=1,NG,2),
     1             (Q1(I),I=1,NG,2),(Q2(I),I=1,NG,2),
     2             (TG(I),I=1,NG,2),(TS(I),I=1,NG,2)
2     FORMAT(1H ,//,5H T = ,F7.1,/,
     190H C1(Z,T) / C2(Z,T) / Q1(Z,T) / Q2(Z,T) / TG(Z,T) / TS(Z,T) / Z
     2= 0, 0.1, 0.2, ,,, 0.9, 1.0,/,
     3             11E12.3,//,11E12.3,//,11E12.3,//,
     4             11E12.3,//,11E12.3,//,11E12.3)
C...
C...  STORE THE NUMERICAL SOLUTIONS FOR PLOTTING
      IT=IT+1
      CTP(1,IT)=C1(NG)
      CTP(2,IT)=C2(NG)
      QTP(1,IT)=Q1(NG)
      QTP(2,IT)=Q2(NG)
      TTP(1,IT)=TG(NG)
      TTP(2,IT)=TS(NG)
      TP(IT)=T
C...
C...  THE AXIAL PROFILES ARE STORED ONLY FOR T = 0, 70, 140
      IF((IT-1)*(IT-8)*(IT-15).NE.0)RETURN
      IF(IT.EQ.1)IZ=1
      IF(IT.EQ.8)IZ=3
      IF(IT.EQ.15)IZ=5
      DO 3 I=1,NG
      CZP(IZ  ,I)=C1(I)
      CZP(IZ+1,I)=C2(I)
      QZP(IZ  ,I)=Q1(I)
      QZP(IZ+1,I)=Q2(I)
      TZP(IZ  ,I)=TG(I)
      TZP(IZ+1,I)=TS(I)
      ZP(I)=0.05*FLOAT(I-1)
3     CONTINUE
C...
C...  PLOT THE NUMERICAL SOLUTIONS
      IF(IT.LT.15)RETURN
C...
C...     EXIT FLUID CONCENTRATIONS, SOLID CONCENTRATIONS, TEMPERATURES
C...     VS TIME
         CALL TPLOTS(2,IT,TP,CTP)
         WRITE(NO,11)
         CALL TPLOTS(2,IT,TP,QTP)
         WRITE(NO,12)
         CALL TPLOTS(2,IT,TP,TTP)
         WRITE(NO,13)
11    FORMAT(1H ,//,61H FLUID CONCENTRATIONS VS T AT Z = 1, 1 - C1(1,T)
     1 2 - C2(1,T))
12    FORMAT(1H ,//,61H SOLID CONCENTRATIONS VS T AT Z = 1, 1 - Q1(1,T)
     1 2 - Q2(1,T))
13    FORMAT(1H ,//,53H TEMPERATURES VS T AT Z = 1, 1 - TG(1,T)  2 - TS(
     11,T))
C...
C...     FLUID CONCENTRATIONS, SOLID CONCENTRATIONS, TEMPERATURES VS Z
C...     AT T = 0, 70, 140
         CALL TPLOTS(6,NG,ZP,CZP)
         WRITE(NO,14)
         CALL TPLOTS(6,NG,ZP,QZP)
         WRITE(NO,15)
         CALL TPLOTS(6,NG,ZP,TZP)
         WRITE(NO,16)
14    FORMAT(1H ,//,109H FLUID CONCENTRATIONS V Z, 1 - C1(Z,0), 2 - C2(Z
     1,0), 3 - C1(Z,70), 4 - C2(Z,70), 5 - C1(Z,140), 6 - C2(Z,140))
15    FORMAT(1H ,//,109H SOLID CONCENTRATIONS V Z, 1 - Q1(Z,0), 2 - Q2(Z
     1,0), 3 - Q1(Z,70), 4 - Q2(Z,70), 5 - Q1(Z,140), 6 - Q2(Z,140))
16    FORMAT(1H ,//,102H TEMPERATURES VS Z, 1 - TG(Z,0), 2 - TS(Z,0), 3
     1- TG(Z,70), 4 - TS(Z,70), 5 - TG(Z,140), 6 - TS(Z,140))
      IT=0
      RETURN
      END
HARWELL NON-EQUILIBRIUM, MULTI-COMPONENT, ADIABATIC ADSORPTION MODEL
0.        140.      10.
  126 1000    1    1  ABS 0.005
END OF RUNS
*APP SEP23
      SUBROUTINE INITAL
C...
C...  DIFFUSION IN A POROUS SOLID, LINEAR CASE
C...
C...  A SLAB OF POROUS SOLID 1 CM THICK IS SOAKED IN PURE ETHANOL.  THE
C...  VOID SPACE IN THE SOLID OCCUPIES 50 PERCENT OF ITS VOLUME.  THE
C...  PORES ARE FINE, SO THAT MOLECULAR DIFFUSION CAN TAKE PLACE THROUGH
C..   THE LIQUID IN THE PASSAGES.  THERE IS NO CONVECTIVE MIXING.  THE
C...  EFFECTIVE DIFFUSIVITY OF THE SYSTEM ETHANOL-WATER IN THE PORES IS
C...  ONE TENTH THAT IN THE FREE LIQUID.
C...
C...  THE QUESTION OF INTEREST IS IF THE SLAB IS PLACED IN A LARGE WELL-
C...  AGITATED RESERVOIR OF PURE WATER AT 25 C, HOW LONG WILL IT TAKE
C...  FOR THE MASS FRACTION OF ETHANOL AT THE CENTER OF THE SLAB TO FALL
C...  TO 0.009.  ASSUME THAT THERE IS NO RESISTANCE TO MASS TRANSFER IN
C...  THE WATER PHASE AND THAT THE CONCENTRATION OF ETHANOL IN WATER,
C...  AND THUS AT THE SURFACE OF THE SLAB, IS CONSTANT AT ZERO.
C...
C...  THE GOVERNING PARTIAL DIFFERENTIAL EQUATION (PDE) IS FICK*S SECOND
C...  LAW
C...
C...    XA  = D*XA                                                 (1)
C...      T       ZZ
C...
C...  WHERE
C...
C...     XA     MOLE FRACTION OF ETHANOL
C...
C...     T      TIME
C...
C...     Z      POSITION WITHIN THE SLAB, MEASURED FROM THE CENTERLINE
C...
C...     D      DIFFUSIVITY
C...
C...  NOTE - THE SUBSCRIPTS IN EQUATION (1) DENOTE PARTIAL DERIVATIVES
C...  WITH RESPECT TO T (FIRST-ORDER) AND Z (SECOND-ORDER).
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     XA(Z,0) = 1.0, XA (0,T) = 0, XA(Z0,T) = 0           (2)(3)(4)
C...                      Z
C...
C...  ALSO, D = 1.0E-10, Z0 = 0.005.
C...
C...  THE ANALYTICAL SOLUTION TO EQUATIONS (1) TO (4) IS
C...
C...               INF  -2*(-1)**I
C...     XA(Z,T) = SUM ----------- EXPON(I)*COSINE(I)              (5)
C...               I=1   2*I - 1
C...                     ------- PI
C...                        2
C...
C...  WHERE
C...                    -((2*I - 1)**2)*(PI**2)*D*T)
C...     EXPON(I) = EXP(----------------------------)
C...                             4*(Z0**2)
C...
C...                     (2*I - 1)*PI*Z
C...     COSINE(I) = COS(--------------)
C...                          2*Z0
C...
C...  THIS PROBLEM IS TAKEN FROM BENNETT, C. O. AND J. E. MYERS, MOMEN-
C...  TUM, HEAT, AND MASS TRANSFER, THIRD EDITION, MCGRAW-HILL BOOK CO.,
C...  NY, PP 521-523.
C...
C...  COMMON AREA TO LINK THE DSS SUBROUTINES
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  SET THE NUMBER OF GRID POINTS IN Z
      N=21
C...
C...  SET THE PROBLEM PARAMETERS
      D=1.0E-10
      Z0=0.005
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      XA(I)=1.0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  BOUNDARY CONDITION AT Z = Z0
      XA(N)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE XA
C...                                   Z
      CALL DSS004(0.,Z0,N, XA, XAZ)
C...
C...  BOUNDARY CONDITION AT Z = 0
      XAZ(1)=0.
C...
C...  COMPUTE THE SPATIAL DEIVATIVE XA
C...                                  ZZ
      CALL DSS004(0.,Z0,N,XAZ,XAZZ)
C...
C...  EQUATION (1)
      DO 1 I=1,N-1
      XAT(I)=D*XAZZ(I)
1     CONTINUE
C...
C...  THE BOUNDARY CONCENTRATION, XA(Z0,T), DOES NOT CHANGE WITH T
      XAT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), XP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(14X,'T',8X,'XA(0,T)',8X,'XA(0,T)',/,39X,'(ANAL)')
      END IF
C...
C...  EVALUATE THE ANALYTICAL SOLUTION
      XAE=SUM(D,Z0,T)
C...
C...  PRINT THE SOLUTION AT Z = 0
      WRITE(NO,2)T,XA(1),XAE
2     FORMAT(F15.0,2F15.5)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      XP(IP)=XA(1)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,XP)
      WRITE(NO,3)
3     FORMAT(1H ,//,' XA(0,T) VS T')
      RETURN
      END
      FUNCTION SUM(D,Z0,T)
C...
C...  FUNCTION SUM EVALUATES THE ANALYTICAL SOLUTION TO EQUATIONS (1)
C...  TO (4) FOR Z = Z0
C...
      REAL I
      SUM=0.
      I=0.
      PI=3.1415927
C...
C...  COMPUTE 100 TERMS IN THE ANALYTICAL (SERIES) SOLUTION
      DO 1 J=1,100
      I=I+1.0
      C1=-2.*(-1.)**J/((2.*I-1.)*PI/2.)
      C2=(-((2.*I-1.)**2)*(PI**2)*D*T/(4.0*(Z0**2)))
C...
C...  THE FOLLOWING IF STATEMENT AVOIDS AN UNDERFLOW IN THE EXP FUNCTION
      IF(C2.LT.-100.0)THEN
         EXPON=0.
      ELSE
         EXPON=EXP(C2)
      END IF
C...
C...  ADD THE NEXT TERM IN THE ANALYTICAL SOLUTION
      SUM=SUM+C1*EXPON
1     CONTINUE
      RETURN
      END
DIFFUSION IN A POROUS SLAB
0.        600000.   6000.
   21 1000    1    1  ABS 0.00001
END OF RUNS
*APP SEP24
      SUBROUTINE INITAL
C...
C...  DIFFUSION IN A POROUS SOLID, NONLINEAR CASE
C...
C...  A SLAB OF POROUS SOLID 1 CM THICK IS SOAKED IN PURE ETHANOL.  THE
C...  VOID SPACE IN THE SOLID OCCUPIES 50 PERCENT OF ITS VOLUME.  THE
C...  PORES ARE FINE, SO THAT MOLECULAR DIFFUSION CAN TAKE PLACE THROUGH
C..   THE LIQUID IN THE PASSAGES.  THERE IS NO CONVECTIVE MIXING.  THE
C...  EFFECTIVE DIFFUSIVITY OF THE SYSTEM ETHANOL-WATER IN THE PORES IS
C...  ONE TENTH THAT IN THE FREE LIQUID.
C...
C...  THE QUESTION OF INTEREST IS IF THE SLAB IS PLACED IN A LARGE WELL-
C...  AGITATED RESERVOIR OF PURE WATER AT 25 C, HOW LONG WILL IT TAKE
C...  FOR THE MASS FRACTION OF ETHANOL AT THE CENTER OF THE SLAB TO FALL
C...  TO 0.009.  ASSUME THAT THERE IS NO RESISTANCE TO MASS TRANSFER IN
C...  THE WATER PHASE AND THAT THE CONCENTRATION OF ETHANOL IN WATER,
C...  AND THUS AT THE SURFACE OF THE SLAB, IS CONSTANT AT ZERO.
C...
C...  THE GOVERNING PARTIAL DIFFERENTIAL EQUATION (PDE) IS FICK*S SECOND
C...  LAW
C...
C...    XA  = D*XA                                                 (1)
C...      T       ZZ
C...
C...  WHERE
C...
C...     XA     MOLE FRACTION OF ETHANOL
C...
C...     T      TIME
C...
C...     Z      POSITION WITHIN THE SLAB, MEASURED FROM THE CENTERLINE
C...
C...     D      DIFFUSIVITY
C...
C...  NOTE - THE SUBSCRIPTS IN EQUATION (1) DENOTE PARTIAL DERIVATIVES
C...  WITH RESPECT TO T (FIRST-ORDER) AND Z (SECOND-ORDER).
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     XA(Z,0) = 1.0, XA (0,T) = 0, XA(Z0,T) = 0           (2)(3)(4)
C...                      Z
C...
C...  ALSO, D = 1.0E-10, Z0 = 0.005.
C...
C...  THE ANALYTICAL SOLUTION TO EQUATIONS (1) TO (4) IS
C...
C...               INF  -2*(-1)**I
C...     XA(Z,T) = SUM ----------- EXPON(I)*COSINE(I)              (5)
C...               I=1   2*I - 1
C...                     ------- PI
C...                        2
C...
C...  WHERE
C...                    -((2*I - 1)**2)*(PI**2)*D*T)
C...     EXPON(I) = EXP(----------------------------)
C...                             4*(Z0**2)
C...
C...                     (2*I - 1)*PI*Z
C...     COSINE(I) = COS(--------------)
C...                          2*Z0
C...
C...  THIS PROBLEM IS TAKEN FROM BENNETT, C. O. AND J. E. MYERS, MOMEN-
C...  TUM, HEAT, AND MASS TRANSFER, THIRD EDITION, MCGRAW-HILL BOOK CO.,
C...  NY, PP 521-523.
C...
C...  A SECOND NONLINEAR FORM OF FICK*S SECOND LAW IS ALSO PROGRAMMED
C...
C...     XA  = (D*XA )                                             (6)
C...       T        Z Z
C...
C...  WHERE THE DIFFUSIVITY IS NOW A FUNCTION OF CONCENTRATION, E.G.,
C...  D = D0*(1 + D1*XA).  THE ANALYTICAL SOLUTION TO THIS NONLINEAR
C...  PROBLEM WOULD BE DIFFICULT TO DERIVE, AND MAY BE UNKNOWN.  THE
C...  NUMERICAL SOLUTION, HOWEVER, IS EASILY COMPUTED.
C...
C...  COMMON AREA TO LINK THE DSS SUBROUTINES
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  SET THE NUMBER OF GRID POINTS IN Z
      N=21
C...
C...  SET THE PROBLEM PARAMETERS
      D=1.0E-10
      Z0=0.005
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      XA(I)=1.0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  LINEAR PROBLEM
      IF(NORUN.EQ.1)CALL DERV1
C...
C...  NONLINEAR PROBLEM
      IF(NORUN.EQ.2)CALL DERV2
      RETURN
      END
      SUBROUTINE DERV1
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  BOUNDARY CONDITION AT Z = Z0
      XA(N)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE XA
C...                                   Z
      CALL DSS004(0.,Z0,N, XA, XAZ)
C...
C...  BOUNDARY CONDITION AT Z = 0
      XAZ(1)=0.
C...
C...  COMPUTE THE SPATIAL DEIVATIVE XA
C...                                  ZZ
      CALL DSS004(0.,Z0,N,XAZ,XAZZ)
C...
C...  EQUATION (1)
      DO 1 I=1,N-1
      XAT(I)=D*XAZZ(I)
1     CONTINUE
C...
C...  THE BOUNDARY CONCENTRATION, XA(Z0,T), DOES NOT CHANGE WITH T
      XAT(N)=0.
      RETURN
      END
      SUBROUTINE DERV2
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  BOUNDARY CONDITION AT Z = Z0
      XA(N)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE XA
C...                                   Z
      CALL DSS004(0.,Z0,N, XA, XAZ)
C...
C...  BOUNDARY CONDITION AT Z = 0
      XAZ(1)=0.
C...
C...  COMPUTE THE GROUP D0*(1 + D1*XA)*XA
C...                                     Z
      D0=D
      D1=3.
      DO 2 I=1,N
      XAZ(I)=D0*(1.+D1*XA(I))*XAZ(I)
2     CONTINUE
C...
C...  COMPUTE THE SPATIAL DERIVATIVE (D0*(1 + D1*XA)*XA )
C...                                                   Z Z
      CALL DSS004(0.,Z0,N,XAZ,XAZZ)
C...
C...  EQUATION (1)
      DO 1 I=1,N-1
      XAT(I)=XAZZ(I)
1     CONTINUE
C...
C...  THE BOUNDARY CONCENTRATION, XA(Z0,T), DOES NOT CHANGE WITH T
      XAT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), XAP(2,101)
C...
C...  PRINT, PLOT AND STORE THE LINEAR SOLUTION
      IF(NORUN.EQ.1)THEN
         CALL PRINT1(NI,NO)
         TP(IP)=T
         XAP(NORUN,IP)=XA(1)
C...
C...  PRINT, PLOT AND STORE THE NONLINEAR SOLUTION
      ELSE IF(NORUN.EQ.2)THEN
         CALL PRINT2(NI,NO)
         TP(IP)=T
         XAP(NORUN,IP)=XA(1)
      END IF
C...
C...  PLOT BOTH SOLUTIONS AT THE END OF THE SECOND RUN
      IF(IP.NE.101) RETURN
      IF(NORUN.NE.2)RETURN
      CALL TPLOTS(2,IP,TP,XAP)
      WRITE(NO,1)
1     FORMAT(1H ,//,' XA(0,T) VS T, 1 - LINEAR, 2 - NONLINEAR')
      RETURN
      END
      SUBROUTINE PRINT1(NI,NO)
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), XP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(14X,'T',8X,'XA(0,T)',8X,'XA(0,T)',/,39X,'(ANAL)')
      END IF
C...
C...  EVALUATE THE ANALYTICAL SOLUTION
      XAE=SUM(D,Z0,T)
C...
C...  PRINT THE SOLUTION AT Z = 0
      WRITE(NO,2)T,XA(1),XAE
2     FORMAT(F15.0,2F15.5)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      XP(IP)=XA(1)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,XP)
      WRITE(NO,3)
3     FORMAT(1H ,//,' XA(0,T) VS T')
      RETURN
      END
      SUBROUTINE PRINT2(NI,NO)
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  XA(21)
     2      /F/ XAT(21)
     3      /S/ XAZ(21),XAZZ(21)
     4      /C/       D,      Z0,       N,      IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), XP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(14X,'T',8X,'XA(0,T)')
      END IF
C...
C...  PRINT THE SOLUTION AT Z = 0
      WRITE(NO,2)T,XA(1)
2     FORMAT(F15.0,1F15.5)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      XP(IP)=XA(1)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,XP)
      WRITE(NO,3)
3     FORMAT(1H ,//,' XA(0,T) VS T, NONLINEAR CASE')
      RETURN
      END
      FUNCTION SUM(D,Z0,T)
C...
C...  FUNCTION SUM EVALUATES THE ANALYTICAL SOLUTION TO EQUATIONS (1)
C...  TO (4) FOR Z = Z0
C...
      REAL I
      SUM=0.
      I=0.
      PI=3.1415927
C...
C...  COMPUTE 100 TERMS IN THE ANALYTICAL (SERIES) SOLUTION
      DO 1 J=1,100
      I=I+1.0
      C1=-2.*(-1.)**J/((2.*I-1.)*PI/2.)
      C2=(-((2.*I-1.)**2)*(PI**2)*D*T/(4.0*(Z0**2)))
C...
C...  THE FOLLOWING IF STATEMENT AVOIDS AN UNDERFLOW IN THE EXP FUNCTION
      IF(C2.LT.-100.0)THEN
         EXPON=0.
      ELSE
         EXPON=EXP(C2)
      END IF
C...
C...  ADD THE NEXT TERM IN THE ANALYTICAL SOLUTION
      SUM=SUM+C1*EXPON
1     CONTINUE
      RETURN
      END
DIFFUSION IN A POROUS SLAB
0.        600000.   6000.
   21 1000    1    1  ABS 0.00001
DIFFUSION IN A POROUS SLAB
0.        600000.   6000.
   21 1000    1    1  ABS 0.00001
END OF RUNS
*APP SEP25
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TRIPLE-EFFECT EVAPORATOR
C...
C...  CONSIDER A TRIPLE-EFFECT EVAPORATOR, DIAGRAMMED BELOW
C
C                    WS1,T1             WS2,T2         WS3,T3
C                 ............       ............       .....+
C                 .          .       .          .       .
C                 .          .       .          .       .
C               .....        .     .....        .     .....
C              .     .       .    .     .       .    .     .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .........      .   .........      .   .........
C             . M1,T1 .      .   . M2,T2 .      .   . M3,T3 .
C       .....+.....   .      ...+.....   .      ...+.....   .
C        WS0  .  .   .....       .  .   .....       .  .   .....
C             .   .   .  .       .   .   .  .       .   .   .  .
C       .....+.  .    .  .       .  .    .  .       .  .    .  .
C       WF,CF .   .   .  .       .   .   .  .       .   .   .  .
C             .  .    .  .       .  .    .  .       .  .    .  .
C             .   .   .  .       .   .   .  .       .   .   .  .
C          .......    .  .    .......    .  .    .......    .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          +  .       .  .    +  .       .  .    +  .       .  .
C         TL0 .       .  .   TL1 .       .  .   TL2 .       .  .
C              .     .   .      .+.     .   .      .+.     .   .
C               .....    .      .  .....    .      .  .....    .
C                 .      .      .    .      .      .    .      .
C                 .    .....    .    .    .....    .    .    .....
C                 .    .LLC.    .    .    .LLC.    .    .    .LLC.
C                 .    .....    .    .    .....    .    .    .....
C                 .      .      .    .      .      .    .      .
C                 .      .      .    .      .      .    .      .
C                ...    ...     .   ...    ...     .   ...    ...
C                .P....+.V.......   .P....+.V.......   .P....+.V......+
C                ...    ... W1,C1   ...    ... W2,C2   ...    ... W3,C3
C
C    .....
C    .LLC. - LIQUID LEVEL CONTROLLER
C    .....
C
C     ...
C     .P.  - PUMP
C     ...
C
C     ...
C     .V.  - CONTROL VALVE
C     ...
C...
C...  FIVE FEEDBACK CONTROL SYSTEMS ARE INCLUDED, PRIMARILY TO MAINTAIN
C...  THE CONCENTRATION OF THE LIQUID IN THE THIRD EFFECT.  THE PURPOSE
C...  OF THE SIMULATION IS TO DETERMINE HOW WELL THE CONTROLS WORK IN
C...  REGULATING THIS PRODUCT COMPOSITION.
C
C...  THE EQUATIONS WHICH MODEL THIS SYSTEM ARE
C...
C...     (1)  TOTAL MASS BALANCE FOR EACH EVAPORATOR
C...
C...          DM1/DT = WF - W1 - WS1, M1(0) = M10
C...
C...          DM2/DT = W1 - W2 - WS2, M2(0) = M20
C...
C...          DM3/DT = W2 - W3 - WS3, M3(0) = M30
C...
C...     (2)  COMPONENT (SOLUTE) BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*C1)/DT = WF*CF - W1*C1, M1(0)*C1(0) = M10*C10
C...
C...          D(M2*C2)/DT = W1*C1 - W2*C2, M2(0)*C2(0) = M20*C20
C...
C...          D(M3*C3)/DT = W2*C2 - W3*C3, M3(0)*C3(0) = M30*C30
C...
C...     (3)  CONTROLLER FOR THE LIQUID LEVEL IN EACH EVAPORATOR
C...
C...          W1 = W1SS + KC1*(M1 - M1SET)
C...
C...          W2 = W2SS + KC2*(M2 - M2SET)
C...
C...          W3 = W3SS + KC3*(M3 - M3SET)
C...
C...     (4)  ENTHALPY BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*HL1)/DT = WF*HF  + WS0*(HVS0 -HLS0)
C...
C...                       - W1*HL1 - WS1*HVS1, M1(0)*HL1(0) = M10*HL10
C...
C...          D(M2*HL2)/DT = W1*HL1 + WS1*(HVS1 - HLS1)
C...
C...                       - W2*HL2 - WS2*HVS2, M2(0)*HL2(0) = M20*HL20
C...
C...          D(M3*HL3)/DT = W2*HL2 + WS2*(HVS2 - HLS2)
C...
C...                       - W3*HL3 - WS3*HVS3, M3(0)*HL3(0) = M30*HL30
C...
C...     (5)  ENERGY BALANCE FOR THE VAPOR (NEGLECTING VAPOR DYNAMICS)
C...
C...          WS1 = U2*A2*(TL1 - T2)/(HVS1 - HLS1)
C...
C...          WS2 = U3*A3*(TL2 - T3)/(HVS2 - HLS2)
C...
C...     (6)  ENTHALPY EQUATIONS
C...
C...          HLI = HL(TI,CI), I = 1, 2, 3
C...
C...          HVSI = HVS(TI),  I = 1, 2, 3
C...
C...     (7)  CONTROLLERS FOR WS3 AND WS0 (NOT SHOWN IN THE DIAGRAM)
C...
C...          WS3 = WS3SS + KCS3*((T3 - T3SET)
C...
C...                                 T
C...                      + (1/TI3)*INT (T3 - T3SET)*DT)
C...                                 0
C...
C...          WS0 = WS0SS + KCS0*((BPRSET - BPR3)
C...
C...                                 T
C...                      + (1/TI0)*INT (BPRSET - BPR3)*DT)
C...                                 0
C...  WHERE
C...
C...     M1,M2,M3        LIQUID HOLDUPS IN EVAPORATORS 1, 2, 3
C...
C...     T               TIME
C...
C...     W1,W2,W3        LIQUID FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     WS1,WS2,WS3     VAPOR FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     C1,C2,C2        LIQUID CONCENTRATIONS IN EVAPORATORS 1, 2, 3
C...
C...     W1SS,W2SS,W3SS  STEADY STATE VAPOR RATES FROM EVAPORATORS 1,
C...                     2, 3
C...
C...     KC1,KC2,KC3     GAINS OF THE LIQUID LEVEL CONTROLLERS ON
C...                     EVAPORATORS 1, 2, 3
C...
C...     M1SET,M2SET,    SET POINTS FOR THE LIQUID LEVEL CONTROLLERS
C...     M3SET           ON EVAPORATORS 1, 2, 3
C...
C...     HL1,HL2,HL3     ENTHALPIES OF THE LIQUIDS IN EVAPORATORS 1, 2,
C...                     3
C...
C...     WF,TF,HF,CF     FLOW RATE, TEMPARATURE, ENTHALPY, COMPOSITION
C...                     OF THE FEED TO EVAPORATOR 1
C...
C...     WS0,HVS0,HLS0   FLOW RATE, VAPOR AND LIQUID (CONDENSATE) ENTHA-
C...                     LPIES OF THE STEAM TO EVAPORATOR 1
C...
C...     HVS1,HVS2,HVS3  ENTHALPIES OF THE VAPOR FROM EVAPORATORS 1, 2,
C...                     3
C...
C...     HLS1,HLS2       ENTHALPIES OF THE LIQUID (CONDENSATE) IN EVAP-
C...                     ORATORS 2, 3
C...
C...     T1,T2,T3        TEMPERATURES OF THE LIQUID AND VAPOR IN EVAP-
C...                     ORATORS 1, 2, 3
C...
C...     TL0,TL1,TL2     TEMPERATURES OF THE LIQUID (CONDENSATE) IN
C...                     EVAPORATORS 1, 2, 3
C...
C...     TS0             TEMPERATURE OF THE STEAM TO EVAPORATOR 1
C...
C...     U1,U2,U3        HEAT TRANSFER COEFFICIENTS FOR EVAPORATORS 1,
C...                     2, 3
C...
C...     A1,A2,A3        HEAT TRANSFER AREAS FOR EVAPORATORS 1, 2, 3
C...
C...     WS3SS, WS0SS    STEADY STATE VAPOR RATE FROM EVAPORATOR 3,
C...                     STEADY STATE STEAM RATE TO EVAPORATOR 1
C...
C...     KCS3,KCS0       CONTROLLERS GAINS FOR WS3 AND WS0
C...
C...     TI3,TI0         CONTROLLER INTEGRAL TIMES FOR WS3 AND WS0
C...
C...     T3SET, BPRSET   SET POINTS FOR T3 AND BPR (BOILING POINT RISE)
C...
C...     BPR1,BPR2,BPR3  BOILING POINT RISES FOR EVAPORATORS 1, 2, 3,
C...                     I.E., BPR1 = T1 - TL1, ETC.
C...
C...  THE NUMERICAL PARAMETERS FOR THE SYSTEM (NAOH IN WATER) ARE
C...
C...     HLI = (TI - 32)*(1 - 1.2*CI + 2.4*CI**2) BTU/LB
C...
C...         0 LE CI LE 0.3, (CI IS THE WEIGHT FRACTION OF NAOH IN THE
C...                          LIQUID IN EVAPORATOR I, I = 1, 2, 3)
C...
C...     HLI = (TI - 32)*(2.83*CI - 0.56*CI**2)
C...
C...         CI GT 0.3
C...
C...     BPRI = 36*CI + 250*CI**2 (BPRI IS THE BOILING POINT RISE IN
C...                               EVAPORATOR I, I = 1, 2, 3)
C...
C...     TLI = TI - BPRI (I = 1, 2, 3)
C...
C...     HLSI = TLI - 32 (I = 1, 2, 3)
C...
C...     HVSI = 0.45*(TI  - 32) + 1075 (I = 1, 2, 3)
C...
C...     WF = 200000 LB/HR, CF = 0.05, TF = 102 F, T3SET = 182 F
C...
C...     BPRSET = 80.5 F, A1 = A2 = A3 = 2900 FT**2, TS0 = 350 F,
C...
C...     U1 = 800 BTU/HR-FT**2-F, U2 = 500 BTU/HR-FT**2-F, U3 = 300
C...
C...     BTU/HR-FT**2-F, WS0SS = 30000 LB/HR, WS3SS = 10000 LB/HR
C...
C...     W1SS = 100000 LB/HR, W2SS = 50000 LB/HR, W3SS = 25000 LB/HR
C...
C...     KC1 = 100, KC2 = 100, KC3 = 50, M1SET = M2SET = M3SET = 2000 LB
C...
C...     KCS0 = 500, KCS3 = 500, TI0 = 0.1, TI3 = 0.1
C...
C...     INITIAL CONDITIONS
C...
C...     M1 = M2 = M3 = 2000 LB, T1 = T2 = T3 = 102 F, C1 = C2 = C3 =
C...
C...     0.05
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
C...
C...  COMMON BLOCK FOR OTHER MODEL VARIABLES, MODEL PARAMETERS
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL PARAMETERS
C...
C...     STEADY STATE VAPOR RATES
         W1SS=100000.
         W2SS= 50000.
         W3SS= 25000.
C...
C...     LIQUID LEVEL CONTROLLER GAINS
         KC1=100.
         KC2=100.
         KC3=50.
C...
C...     LIQUID LEVEL CONTROLLER SET POINTS
         M1SET=2000.
         M2SET=2000.
         M3SET=2000.
C...
C...     FEED FLOW RATE, TEMPERATURE, COMPOSITION
         WF=200000.
         TF=102.
         CF=0.05
C...
C...     HEAT TRANSFER COEFFICIENTS
         U1=800.
         U2=500.
         U3=300.
C...
C...     HEAT TRANSFER AREAS
         A1=2900.
         A2=2900.
         A3=2900.
C...
C...     STEADY STATE VAPOR RATES OF PI CONTROLLERS
         WS0SS=30000.
         WS3SS=10000.
C...
C...     GAINS OF PI CONTROLLERS
         KCS0=500.
         KCS3=500.
C...
C...     INTEGRAL TIMES OF PI CONTROLLERS
         TI0=0.1
         TI3=0.1
C...
C...     SET POINTS FOR PI CONTROLLERS
         BPRSET=80.5
         T3SET=182.0
C...
C...     STEAM TEMPERATURE
         TS0=350.
C...
C...  INITIAL CONDITIONS
C...
C...     TOTAL MASS BALANCES
         M1=2000.
         M2=2000.
         M3=2000.
C...
C...     COMPONENT BALANCES
         M1C1=2000.*0.05
         M2C2=2000.*0.05
         M3C3=2000.*0.05
C...
C...     ENTHALPY BALANCES
         M1HL1=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M2HL2=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M3HL3=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
C...
C...     PI CONTROLLERS
         E1INT=0.
         E2INT=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL ALGEBRA
C...
C...     LIQUID COMPOSITIONS
         C1=M1C1/M1
         C2=M2C2/M2
         C3=M3C3/M3
C...
C...     LIQUID ENTHALPIES
         HL1=M1HL1/M1
         HL2=M2HL2/M2
         HL3=M3HL3/M3
C...
C...     VAPOR RATES IN THE EVAPORATORS
         W1=W1SS+KC1*(M1-M1SET)
         W2=W2SS+KC2*(M2-M2SET)
         W3=W3SS+KC3*(M3-M3SET)
C...
C...     LIQUID TEMPERATURES
C...
C...     T1
         IF(C1.LE.0.3)THEN
            T1=HL1/(1.0-1.2*C1+2.4*C1**2)+32.0
         ELSE IF(C1.GT.0.3)THEN
            T1=HL1/(2.83*C1-0.56*C1**2)+32.0
         END IF
C...
C...     T2
         IF(C2.LE.0.3)THEN
            T2=HL2/(1.0-1.2*C2+2.4*C2**2)+32.0
         ELSE IF(C2.GT.0.3)THEN
            T2=HL2/(2.83*C2-0.56*C2**2)+32.0
         END IF
C...
C...     T3
         IF(C3.LE.0.3)THEN
            T3=HL3/(1.0-1.2*C3+2.4*C3**2)+32.0
         ELSE IF(C3.GT.0.3)THEN
            T3=HL3/(2.83*C3-0.56*C3**2)+32.0
         END IF
C...
C...     BOILING POINT RISES
         BPR1=36.0*C1+250.0*C1**2
         BPR2=36.0*C2+250.0*C2**2
         BPR3=36.0*C3+250.0*C3**2
C...
C...     CONDENSATE TEMPERATURES
         TL1=T1-BPR1
         TL2=T2-BPR2
         TL3=T3-BPR3
C...
C...     CONDENSATE ENTHALPIES
         HLS0=TS0-32.0
         HLS1=TL1-32.0
         HLS2=TL2-32.0
         HLS3=TL3-32.0
C...
C...     VAPOR ENTHALPIES
         HVS0=0.45*(TS0-32.0)+1075.
         HVS1=0.45*(T1-32.0)+1075.
         HVS2=0.45*(T2-32.0)+1075.
         HVS3=0.45*(T3-32.0)+1075.
C...
C...     VAPOR RATES IN THE HEATING COILS
         WS1=U2*A2*(TL1-T2)/(HVS1-HLS1)
         WS2=U3*A3*(TL2-T3)/(HVS2-HLS2)
C...
C...     FEED ENTHALPY
         HF=(TF-32.0)*(1.0-1.2*CF+2.4*CF**2)
C...
C...     PI CONTROLLERS
         E1=BPRSET-BPR3
         WS0=WS0SS+KCS0*(E1+(1./TI0)*E1INT)
         E2=T3-T3SET
         WS3=WS3SS+KCS3*(E2+(1./TI3)*E2INT)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MASS BALANCES
         M1T=WF-W1-WS1
         M2T=W1-W2-WS2
         M3T=W2-W3-WS3
C...
C...     COMPONENT BALANCES
         M1C1T=WF*CF-W1*C1
         M2C2T=W1*C1-W2*C2
         M3C3T=W2*C2-W3*C3
C...
C...     ENTHALPY BALANCES
         M1HL1T=WF*HF +WS0*(HVS0-HLS0)
     1         -W1*HL1-WS1*HVS1
         M2HL2T=W1*HL1+WS1*(HVS1-HLS1)
     1         -W2*HL2-WS2*HVS2
         M3HL3T=W2*HL2+WS2*(HVS2-HLS2)
     1         -W3*HL3-WS3*HVS3
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), CP(3,101)
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,1)T,M1,M2,M3,C1,C2,C3,T1,T2,T3
1        FORMAT(' T = ',F6.3,/,
     1   10X,'M1',10X,'M2',10X,'M3',/,3F12.1,/,
     1   10X,'C1',10X,'C2',10X,'C3',/,3F12.4,/,
     1   10X,'T1',10X,'T2',10X,'T3',/,3F12.1,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      CP(1,IP)=C1
      CP(2,IP)=C2
      CP(3,IP)=C3
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(3,IP,TP,CP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' 1 - C1   2 - C2   3 - C3 VS T')
      RETURN
      END
CONTROL OF A TRIPLE-EFFECT EVAPORATOR
0.        1.        0.01
   11 1000    1    1  REL 0.001
END OF RUNS
*APP SEP26
      SUBROUTINE INITAL
C...
C...  INTEGRATION OF THE GIBBS-DUHEM EQUATION
C...
C...  THE ISOTHERMAL GIBBS-DUHEM EQUATION CAN BE USED TO COMPUTE THE
C...  EQUILIBRIUM VAPOR COMPOSITION OF A BINARY SYSTEM FROM EXPERIMENTAL
C...  TOTAL PRESSURE VS LIQUID COMPOSITION DATA.  FOR THIS STUDY, THE
C...  FOLLOWING VERSIONS OF THE GIBBS-DUHEM EQUATION ARE INTEGRATED
C...
C...        DY1/DX1 = (1/P)*(DP/DX1)*(1 - Y1)/(1 - X1/Y1)            (1)
C...
C...        DY2/DX2 = (1/P)*(DP/DX2)*(1 - Y2)/(1 - X2/Y2)            (2)
C...
C...  EQUATIONS (1) AND (2) ARE BASED ON THE ASSUMPTIONS
C...
C...     (1)  IDEAL GAS VAPOR PHASE
C...
C...     (2)  THE TERM (EXCESS VOL*DP)/RT IN THE EXACT, ISOTHERMAL GIBBS
C...          DUHEM EQUATION MAY BE NEGLECTED.  THIS IS AN EXCELLENT
C...          ASSUMPTION HERE AND IN MOST CASES AWAY FROM THE CRITICAL
C...          REGION AND IN THE ABSENCE OF VERY HIGH PRESSURES.
C...
C...  EQUATIONS (1) AND (2) ARE INTEGRATED FOR THE ETHYL ALCOHOL (1)
C...  CHLOROFORM (2) SYSTEM FOR WHICH
C...
C...     X1  MOLE FRACTION OF ETHYL ALCOHOL IN THE LIQUID PHASE
C...
C...     X2  MOLE FRACTION OF CHLOROFORM IN THE LIQUID PHASE
C...
C...     Y1  MOLE FRACTION OF ETHYL ALCOHOL IN THE EQUILIBRIUM VAPOR
C...         PHASE
C...
C...     Y2  MOLE FRACTION OF CHLOROFORM IN THE EQUILIBRIUM VAPOR
C...         PHASE
C...
C...     P   TOTAL PRESSURE MEASURED EXPERIMENTALLY AS A FUNCTION OF
C...         X1 AND X2
C...
C...  THE FOLLOWING DATA ARE GIVEN IN PRAUSNITZ, J. M., MOLECULAR
C...  THERMODYNAMICS OF FLUID-PHASE EQUILBRIA, P. 260, PROB. 7,
C...  PRENTICE-HALL, INC. ENGLEWOOD CLIFFS, N. J.  3
C...
C...            TOTAL PRESSURE DATA FOR THE SYSTEM
C...              ETHYL ALCOHOL(1)/CHLOROFORM(2)
C...                         AT 45 C
C...
C...               X2    P(MM HG)   X1   P(MM HG)
C...                0      172.      0     433.5
C...              0.05     200     0.01    438.5
C...              0.10     233.8   0.02    442.0
C...              0.15     266     0.03    444.9
C...              0.20     298     0.04    447.4
C...              0.25     326     0.05    449.3
C...              0.30     351     0.06    450.9
C...              0.35     372     0.07    452.3
C...              0.45     403.5   0.09    454.5
C...              0.50     416     0.10    455.2
C...              0.55     426.5
C...
C...  THESE DATA WERE FITTED TO REGRESSION POLYNOMIALS WITH THE FOLLOW-
C...  ING RESULTS
C...
C...
C...      P = 4.335524475527E+02 +
C...
C...          5.434965034889E+02*X1    - 6.918997668803E+03*X1**2 +  (3)
C...
C...          5.687645687223E+04*X1**3 - 2.309627039370E+05*X1**4
C...
C...
C...      P = 1.723532051343E+02 +
C...
C...          5.194413688298E+02*X2    + 1.266380147487E+03*X2**2 -  (4)
C...
C...          4.399313649081E+03*X2**3 + 3.469696969444E+03*X2**4
C...
C...
C...  THUS EQUATIONS (3) AND (4) CAN BE SUBSTITUTED IN EQUATIONS (1) AND
C...  (2) TO ELIMINATE P.  THE RESULTING EQUATIONS CAN THEN BE INTEGRAT-
C...  ED OVER THE INTERVALS 0 LE X1 LE 0.1, 0 LE X2 LE 0.55 TO OBTAIN Y1
C...  AND Y2.  THE INITIAL CONDITIONS ARE
C...
C...                        Y1 = 0, X1 = 0                           (5)
C...
C...                        Y2 = 0, X2 = 0                           (6)
C...
C...  A REFERENCE CONTAINING EXPERIMENTAL VAPOR PHASE COMPOSITIONS FOR
C...  COMPARISON WITH THE CALCULATED VAPOR PHASE COMPOSITIONS IS GIVEN
C...  BY PRAUSNITZ.
C...
      COMMON/T/X,NFIN,NRUN/Y/Y/F/DYDX
C...
C...  INITIAL CONDITION (A SMALL NONZERO VALUE OF THE INITIAL CONDITION
C...  IS USED TO AVOID A DIVISION BY ZERO IN THE CALCULATION OF DY/DX
C...  IN SUBROUTINE DERV)
      Y=1.0E-05
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/X,NFIN,NRUN/Y/Y/F/DYDX
C...
C...  DIFFERENTIAL EQUATION FOR DY/DX
      DYDX=1./P(NRUN)*(DPDX(NRUN))*(1.-Y)/(1.-X/Y)
      RETURN
      END
      FUNCTION P(NRUN)
C...
C...  FUNCTION P COMPUTES THE TOTAL PRESSURE FROM THE REGRESSION
C...  POLYNOMIALS, EQUATIONS (3) AND (4)
C...
      COMMON/T/X
      GO TO(1,2),NRUN
1     P  = 4.335524475527E+02
     1    +5.434965034889E+02*X      -6.918997668803E+03*X**2
     2    +5.687645687223E+04*X**3   -2.039627039370E+05*X**4
      RETURN
2     P  = 1.723532051343E+02
     1    +5.194413688298E+02*X      +1.266380147487E+03*X**2
     2    -4.399313649081E+03*X**3   +3.469696969444E+03*X**4
      RETURN
      END
      FUNCTION DPDX(NRUN)
C...
C...  FUNCTION DPDX COMPUTES THE DERIVATIVE OF THE PRESSURE, DP/DX, FROM
C...  THE REGRESSION POLYNOMIALS, EQUATIONS (3) AND (4)
C...
      COMMON/T/X
      GO TO(1,2),NRUN
1     DPDX=
     1    +5.434965034889E+02        -6.918997668803E+03*X*2.
     2    +5.687645687223E+04*X**2*3.-2.039627039370E+05*X**3*4.
      RETURN
2     DPDX=
     1    +5.194413688298E+02        +1.266380147487E+03*X*2.
     2    -4.399313649081E+03*X**2*3.+3.469696969444E+03*X**3*4.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/X,NFIN,NRUN/Y/Y/F/DYDX
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION XPLOT(45),YPLOT(2,45)
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(13X,2HX1,13X,2HY1,13X,2HX2,13X,2HY2,14X,1HP)
C...
C...  PRINT THE NUMERICAL SOLUTION
1     PRESS=P(NRUN)
      OMX=1.-X
      OMY=1.-Y
      GO TO(3,4),NRUN
3     WRITE(NO,5)X,Y,OMX,OMY,PRESS
5     FORMAT(4F15.4,F15.1)
      GO TO 6
4     WRITE(NO,5)OMX,OMY,X,Y,PRESS
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
6     IP=IP+1
      GO TO(7,8),NRUN
7     XPLOT(IP)=X
      YPLOT(1,IP)=Y
      YPLOT(2,IP)=X
      GO TO 9
8     XPLOT(IP)=OMX
      YPLOT(1,IP)=OMY
      YPLOT(2,IP)=OMX
C...
C...  PLOT THE EQUILIBRIUM DIAGRAM Y1 VS X1
9     IF((NRUN.NE.2).OR.(X.LT.0.549))RETURN
      CALL TPLOTS(2,IP,XPLOT,YPLOT)
      WRITE(NO,11)
11    FORMAT(//,16X,87HY1 (MOLE FRACTION ETHYL ALCOHOL IN VAPOR) VS X1 (
     1MOLE FRACTION ETHYL ALCOHOL IN LIQUID))
      RETURN
      END
ETHYL ALCOHOL/CHLOROFORM SYSTEM, 0 LE X1 LE 0.10
0.        0.1       0.025
    1 1000    3    1  REL 0.0001
ETHYL ALCOHOL/CHLOROFORM SYSTEM, 0 LE X2 LE 0.55
0.        0.55      0.025
    1 1000    3    1  REL 0.0001
END OF RUNS
*APP SEP27
      SUBROUTINE INITAL
C...
C...  SOLUTION OF THE BEATTIE-BRIDGEMAN EQUATION OF STATE VIA THE
C...  DAVIDENKO ALGORITHM
C...
C...  THE FOLLOWING REFERENCE HAS AN INTRODUCTORY DISCUSSION OF THE
C...  DAVIDENKO METHOD (A CONTINUOUS FORM OF NEWTON*S METHOD)
C...
C...  BRENT, R. P., ON THE DAVIDENKO-BRANIN METHOD FOR SOLVING SIMULTAN-
C...  EOUS NONLINEAR EQUATIONS, IBM J. RES. DEVELOP., VOL. 16, NO. 4,
C...  434-436, JULY, 1972
C...
C...  THE BEATTIE-BRIDGEMAN EQUATION OF STATE IS
C...
C...       P = R*T/V + BETA/V**2 + GAMMA/V**3 + DELTA/V**4           (1)
C...
C...  WHERE
C...
C...     P      GAS PRESSURE (ATM)
C...
C...     T      GAS TEMPERATURE (K)
C...
C...     V      MOLAR GAS VOLUME (LITER/GM-MOLE)
C...
C...     R      UNIVERSAL GAS CONSTANT = 0.08205 LITER ATM/K GM-MOLE
C...
C...     BETA   TEMPERATURE-DEPENDENT PARAMETERS CHARACTERISTIC OF
C...     GAMMA  THE GAS AND GIVEN BY THE FOLLOWING EQUATIONS
C...     DELTA
C...
C...            BETA = R*T*B0 - A0 - R*C/T**2
C...
C...            GAMMA = -R*T*B0*B + A0*A - R*C*B0/T**2
C...
C...            DELTA = R*B0*B*C/T**2
C...
C...            WHERE A0, B0, A, B AND C ARE CONSTANTS FOR A
C...            PARTICULAR GAS
C...
C...  THE PROBLEM IS TO COMPUTE THE MOLAR VOLUME, V, GIVEN THE PRESSURE,
C...  P, AND TEMPERATURE, T, PLUS THE CONSTANTS APPROPRIATE FOR THE GAS
C...  OF INTEREST.
C...
C...  EQUATION (1) IS SOLVED VIA AN ASSOCIATED DIFFERENTIAL EQUATION.
C...  IF AN ERROR, E(V), IS DEFINED AS THE DIFFERENCE BETWEEN THE LHS
C...  AND THE RHS OF EQUATION (1)
C...
C...    E(V) = R*T/V + BETA/V**2 + GAMMA/V**3 + DELTA/V**4 - P       (2)
C...
C...  THEN THE ASSOCIATED DIFFERENTIAL EQUATION IS
C...
C...                   DV/DX = -E(V)/(DE(V)/DV)                      (3)
C...
C...  EQUATION (3) IS INTEGRATED UNTIL DV/DX = 0 AT WHICH POINT THE
C...  SOLUTION, V, IS SUCH THAT E(V) = 0 (I.E. THE VALUE OF V WHICH
C...  SATISFIES EQUATION (1)).
C...
C...  THE INITIAL CONDITION FOR EQUATION (3) IS
C...
C...                        V = V0, X = 0  0(4)
C...
C...  WHERE V0 IS AN INITIAL ESTIMATE OF THE SOLUTION OF EQUATION (1)
C...  GIVEN BY THE IDEAL GAS LAW
C...
C...                          V0 = R*T/P                             (5)
C...
C...  THE MOLAR VOLUME OF METHANE IS TO BE COMPUTED FOR THREE CASES
C...
C...                CASE 1 - T = 473.16, P = 1 ATM
C...
C...                CASE 2 - T = 473.16, P = 100 ATM
C...
C...                CASE 3 - T = 473.16, P = 200 ATM
C...
C...  ADDITIONALLY, THE COMPRESSIBILITY FACTOR
C...
C...                         Z = P*V/(R*T)  Z(6)
C...
C...  IS TO BE COMPUTED FOR EACH CASE TO DEMONSTRATE DEPARTURE FROM AN
C...  IDEAL GAS (Z = 1).  EXPERIMENTAL VALUES OF Z ARE REPORTED IN
C...  CARNAHAN ET AL (FIGURE 3.3.1, P. 177) FOR COMPARISON WITH THE
C...  CALCULATED VALUES.
C...
C...  FINALLY, THE ANALYTICAL SOLUTION TO EQUATIONS (3) AND (4)
C...
C...                     E(V) = E(V0)*EXP(-X)                        (7)
C...
C...  IS ALSO PLOTTED AS LN(E(V)) VS X FOR THE THREE CASES.  HOWEVER,
C...  THE DERIVATIVE DE(V)/DX IS NOT RELATED TO X BY AN EQUATION OF THE
C...  OF THE FORM OF (7).  THIS IS CONFIRMED NUMERICALLY BY PLOTTING
C...  LN(DE(V)/DV) VS X.
C...
C...
C...  THE PARAMETERS FOR THE PROBLEM ARE SET IN A BLOCK DATA ROUTINE
C...
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P,
     1                                      A0,B0,A,B,C
C...
C...  SET THE TEMPERATURE AND PRESSURE FOR THE THREE CASES
      T=473.16
      GO TO(1,2,3),NCASE
1     P=1.
      GO TO 4
2     P=100.
      GO TO 4
3     P=200.
C...
C...  PARAMETERS IN EQUATION (1)
4     BETA=R*T*B0-A0-R*C/T**2
      GAMMA=-R*T*B0*B+A0*A-R*C*B0/T**2
      DELTA=R*B0*B*C/T**2
C...
C...  INITIAL CONDITION (4)
      V=R*T/P
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  DV/DX IN EQUATION (3)
      DVDX=-E(V)/DEDV(V)
      RETURN
      END
      FUNCTION E(V)
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  E(V) IN EQUATIONS (2) AND (3)
      E=R*T/V+BETA/V**2+GAMMA/V**3+DELTA/V**4-P
      RETURN
      END
      FUNCTION DEDV(V)
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  DE(V)/DV IN EQUATION (3)
      DEDV=-R*T/V**2-2.*BETA/V**3-3.*GAMMA/V**4-4.*DELTA/V**5
      RETURN
      END
      BLOCK DATA
C...
C...  THE PROBLEM PARAMETERS ARE SET IN THIS BLOCK DATA ROUTINE, THEN
C...  SENT TO THE OTHER ROUTINES THROUGH COMMON/PARM/
C...
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P,A0,B0,A,B,C
C...
C...  SET THE PARAMETERS FOR METHANE
      DATA
     1        A0,        B0,         A,         B,         C,         R/
     2    2.2769,   0.05587,   0.01855,  -0.01587, 12.83E+04,   0.08205/
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION XPLOT(26),EPLOT(26),DEPLOT(26)
C...
C...  SET AN INDEX FOR PLOTTING
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,2)NCASE,T,P
2     FORMAT(4X,7HMETHANE,2X,9HCASE NO. ,I1,3X,14HTEMPERATURE = ,F6.2,
     1 2X,11HPRESSURE = ,F6.2,//,12X,1HV,12X,1HZ,9X,4HE(V),5X,8HDE(V)/DV
     2 ,8X,5HDV/DX,/)
C...
C...  COMPRESSIBILITY FACTOR
1     Z=P*V/(R*T)
C...
C...  PRINT V, Z, E(V), DE(V)/DV, DV/DX
      EP=E(V)
      DEDVP=DEDV(V)
      WRITE(NO,3)V,Z,EP,DEDVP,DVDX
3     FORMAT(E13.3,E13.4,3E13.2)
C...
C...  STORE LN(E(V)) AND LN(DE(V)/DV) FOR SUBSEQUENT PLOTTING VS X
      IP=IP+1
      XPLOT(IP)=X
      EPLOT(IP)=ALOG(ABS(EP))
      DEPLOT(IP)=ALOG(ABS(DEDVP))
C...
C...  PLOT LN(E(V)) AND LN(DE(V)/DV) VS X
      IF(IP.LT.26)RETURN
      CALL PLOTS(1,26,XPLOT,EPLOT)
      WRITE(NO,5)
5     FORMAT(//,16X,13HLN(E(V)) VS X)
      CALL PLOTS(1,26,XPLOT,DEPLOT)
      WRITE(NO,6)
6     FORMAT(//,16X,17HLN(DE(V)/DV) VS X)
      IP=0
      RETURN
      END
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 1
0.        12.5      0.5
    1  250    3    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 100
0.        12.5      0.5
    1  250    3    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 200
0.        12.5      0.5
    1  250    3    1  REL 0.001
END OF RUNS
*APP SEP28
      SUBROUTINE INITAL
C...
C...  SOLUTION OF THE BEATTIE-BRIDGEMAN EQUATION VIA MINIMUM SQUARED
C...  ERROR
C...
C...  THE BEATTIE-BRIDGEMAN EQUATION OF STATE IS
C...
C...       P = R*T/V + BETA/V**2 + GAMMA/V**3 + DELTA/V**4           (1)
C...
C...  WHERE
C...
C...     P      GAS PRESSURE (ATM)
C...
C...     T      GAS TEMPERATURE (K)
C...
C...     V      MOLAR GAS VOLUME (LITER/GM-MOLE)
C...
C...     R      UNIVERSAL GAS CONSTANT = 0.08205 LITER ATM/K GM-MOLE
C...
C...     BETA   TEMPERATURE-DEPENDENT PARAMETERS CHARACTERISTIC OF
C...     GAMMA  THE GAS AND GIVEN BY THE FOLLOWING EQUATIONS
C...     DELTA
C...
C...            BETA = R*T*B0 - A0 - R*C/T**2
C...
C...            GAMMA = -R*T*B0*B + A0*A - R*C*B0/T**2
C...
C...            DELTA = R*B0*B*C/T**2
C...
C...            WHERE A0, B0, A, B AND C ARE CONSTANTS FOR A
C...            PARTICULAR GAS
C...
C...  THE PROBLEM IS TO COMPUTE THE MOLAR VOLUME, V, GIVEN THE PRESSURE,
C...  P, AND TEMPERATURE, T, PLUS THE CONSTANTS APPROPRIATE FOR THE GAS
C...  OF INTEREST.
C...
C...  EQUATION (1) IS SOLVED VIA AN ASSOCIATED DIFFERENTIAL EQUATION.
C...  IF AN ERROR, E(V), IS DEFINED AS THE DIFFERENCE BETWEEN THE LHS
C...  AND THE RHS OF EQUATION (1)
C...
C...    E(V) = R*T/V + BETA/V**2 + GAMMA/V**3 + DELTA/V**4 - P       (2)
C...
C...  THEN THE ASSOCIATED DIFFERENTIAL EQUATION IS
C...
C...                    DV/DX = -E(V)*DE(V)/DV                       (3)
C...
C...  EQUATION (3) IS INTEGRATED UNTIL DV/DX = 0 AT WHICH POINT THE
C...  SOLUTION, V, IS SUCH THAT E(V) = 0 (I.E. THE VALUE OF V WHICH
C...  SATISFIES EQUATION (1)).
C...
C...  THE INITIAL CONDITION FOR EQUATION (3) IS
C...
C...                        V = V0, X = 0  0(4)
C...
C...  WHERE V0 IS AN INITIAL ESTIMATE OF THE SOLUTION OF EQUATION (1)
C...  GIVEN BY THE IDEAL GAS LAW
C...
C...                          V0 = R*T/P                             (5)
C...
C...  THE MOLAR VOLUME OF METHANE IS TO BE COMPUTED FOR THREE CASES
C...
C...                CASE 1 - T = 473.16, P = 1 ATM
C...
C...                CASE 2 - T = 473.16, P = 100 ATM
C...
C...                CASE 3 - T = 473.16, P = 200 ATM
C...
C...  ADDITIONALLY, THE COMPRESSIBILITY FACTOR
C...
C...                         Z = P*V/(R*T)  Z(6)
C...
C...  IS TO BE COMPUTED FOR EACH CASE TO DEMONSTRATE DEPARTURE FROM AN
C...  IDEAL GAS (Z = 1).  EXPERIMENTAL VALUES OF Z ARE REPORTED IN
C...  CARNAHAN ET AL (FIGURE 3.3.1, P. 177) FOR COMPARISON WITH THE
C...  CALCULATED VALUES.
C...
C...  THE PROBLEM PARAMETERS ARE SET IN A BLOCK DATA ROUTINE, THEN
C...  PASSED TO THE OTHER ROUTINES VIA COMMON/PARM/
C...
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P,
     1                                      A0,B0,A,B,C
C...
C...  SET THE TEMPERATURE AND PRESSURE FOR THE THREE CASES
      T=473.16
      GO TO(1,2,3),NCASE
1     P=1.
      GO TO 4
2     P=100.
      GO TO 4
3     P=200.
C...
C...  PARAMETERS IN EQUATION (1)
4     BETA=R*T*B0-A0-R*C/T**2
      GAMMA=-R*T*B0*B+A0*A-R*C*B0/T**2
      DELTA=R*B0*B*C/T**2
C...
C...  INITIAL CONDITION (4)
      V=R*T/P
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  DV/DX IN EQUATION (3)
      DVDX=-E(V)*DEDV(V)
      RETURN
      END
      FUNCTION E(V)
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  E(V) IN EQUATIONS (2) AND (3)
      E=R*T/V+BETA/V**2+GAMMA/V**3+DELTA/V**4-P
      RETURN
      END
      FUNCTION DEDV(V)
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  DE(V)/DV IN EQUATION (3)
      DEDV=-R*T/V**2-2.*BETA/V**3-3.*GAMMA/V**4-4.*DELTA/V**5
      RETURN
      END
      BLOCK DATA
C...
C...  THE PROBLEM PARAMETERS ARE SET IN THIS BLOCK DATA ROUTINE
C...
      COMMON/PARM/BETA,GAMMA,DELTA,R,T,P,A0,B0,A,B,C
C...
C...  SET THE PARAMETERS FOR METHANE
      DATA
     1        A0,        B0,         A,         B,         C,         R/
     2    2.2769,   0.05587,   0.01855,  -0.01587, 12.83E+04,   0.08205/
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/X,NFIN,NCASE/Y/V/F/DVDX/PARM/BETA,GAMMA,DELTA,R,T,P
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,2)NCASE,T,P
2     FORMAT(4X,7HMETHANE,2X,9HCASE NO. ,I1,3X,14HTEMPERATURE = ,F6.2,
     1 2X,11HPRESSURE = ,F6.2,//,12X,1HV,12X,1HZ,9X,4HE(V),5X,8HDE(V)/DV
     2 ,8X,5HDV/DX,/)
C...
C...  COMPRESSIBILITY FACTOR
1     Z=P*V/(R*T)
C...
C...  PRINT V, Z, E(V), DE(V)/DV, DV/DX
      EP=E(V)
      DEDVP=DEDV(V)
      WRITE(NO,3)V,Z,EP,DEDVP,DVDX
3     FORMAT(E13.3,E13.4,3E13.2)
      RETURN
      END
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 1
0.           4.0E+03   2.0E+02
    1  250    3    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 100
0.           2.0E-04   1.0E-05
    1  250    3    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 3.3, T = 473.16, P = 200
0.           8.0E-06   4.0E-07
    1  250    3    1  REL 0.001
END OF RUNS
*APP SEP29
      SUBROUTINE INITAL
C...
C...  OXYGEN TRANSFER IN A RED BLOOD CELL
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED* FOR OXYGEN TRANSFER OUT
C...  OF RED BLOOD CELLS INCLUDING THE EFFECT OF AGING OF THE CELLS
C...
C...     C  = D*C                                                (1)
C...      T      XX
C...
C...     C(X,0) = C0                                             (2)
C...
C...     C (0,T) = 0, -D*C (B,T) = KL*(C(B,T) - CP(T))        (3)(4)
C...      X               X
C...
C...  WHERE
C...
C...  C(X,T)   OXYGEN CONCENTRATION INSIDE THE RED CELL, MOL/CM**3
C...
C...  X        SPATIAL COORDINATE, CM
C...
C...  T        TIME, SEC
C...
C...  B        ONE-HALF OF THE AVERAGE THICKNESS OF THE RED CELL, CM
C...
C...  KL       GLOBAL MASS TRANSFER COEFFICIENT, CM/SEC
C...
C...  * MERCHUK, JOSE C., ZEEV TSUR AND ELI HORN, OXYGEN TRANSFER
C...    RESISTANCE OF BLOOD AGEING, CHEM. ENG. SCI., V. 40, NO. 7,
C...    PP 1101-1107, 1985
C...
C...  THE OXYGEN TRANSFER PROCESS IS ILLUSTRATED BELOW
C...
C... X=(B+A) ----------------------------------------------------------
C...
C...                              LIQUID MATRIX
C...                   + O                             + O
C...                   .  2                            .  2
C...                   .                               .
C...                   .                               .
C...     -----------------------------------------------------------
C...  X=B              .           MEMBRANE            .
C...     -----------------------------------------------------------
C...                   .                               .
C...                   .                               .
C...
C...  X=0                      RED CELL INTERIOR
C...
C...                   .                               .
C...                   .                               .
C...     -----------------------------------------------------------
C... X=-B              .           MEMBRANE            .
C...     -----------------------------------------------------------
C...                   .                               .
C...                   .                               .
C...                   + O                             + O
C...                      2                               2
C...                              LIQUID MATRIX
C...
C... X=-(B+A) ---------------------------------------------------------
C...
C...  THE PARAMETERS FOR THIS MODEL ARE
C...
C...  D = 3.6E-06 CM**2/SEC, B = 0.7E-04 CM, C0 = 0.001 MOLS/CM**2,
C...
C...                         CP(T) = 0
C...
C...  KL = 0.1 CM/SEC (CASE 1), KL = 0.1 - (0.06/50)*T (CASE 2)
C...
C...  COMPUTE THE OXYGEN TRANSFER RATE, KL*(C(B,T) - CP(T)) AS A
C...  FUNCTION OF TIME TO DETERMINE THE EFFECT OF AGING.  NOTE THAT
C...  T IN THE EQUATION FOR KL IS IN DAYS.
C...
C...  THIS MODEL CANNOT BE RUN CONTINUOUSLY FOR 50 DAYS BECAUSE OF
C...  THE LARGE TIME DERIVATIVES (C  IN EQUATION (1)).  RATHER, THE
C...                               T
C...  SIMULATION IS RUN FOR SIX VALUES OF KL (CASE 2) CORRESPONDING
C...  TO DIFFERENT AGING TIMES TO OBSERVE THE EFFECT OF KL ON THE
C...  SHORT TERM OXYGEN TRANSFER RATES.
C...
C...  ALSO, THE CALCULATIONS ARE FACILITATED BY WORKING IN TERMS OF
C...  DIMENSIONLESS VARIABLES (DUE TO, FOR EXAMPLE, THE SMALL VALUE OF
C...  THE CELL HALF WIDTH, B).  THESE DIMENSIONLESS VARIABLES ARE
C...  DEFINED BELOW
C...
C...              NEW                      ORIGINAL
C...         DIMENSIONLESS                DIMENSIONAL
C...           VARIABLES                   VARIABLES
C...
C...           C(Z,T)/C0                    C(Z,T)
C...
C...           CP(T)/C0                      CP(T)
C...
C...              Z/B                          Z
C...
C...           T*D/B**2                        T
C...
C...  THE ORIGINAL EQUATIONS, WHEN EXPRESSED IN TERMS OF THE NEW
C...  DIMENSIONLESS VARIABLES, BECOME (WITH C(Z,T) AND CP(T) NOW DE-
C...  NOTING DIMENSIONLESS VARIABLES C, CP, Z AND T)
C...
C...     C  = C                                                     (1)
C...      T    ZZ
C...
C...     C(Z,0) = 1                                                 (2)
C...
C...     C (0,T) = 0, -C (1,T) = BI*(C(1,T) - CP(T))             (3)(4)
C...      Z             Z
C...
C...  BI = KL*B/D IS THE DIMENSIONLESS BIOT NUMBER.
C...
C...  THE USE OF THESE DIMENSIONLESS VARIABLES HAS THE ADVANTAGES OF (1)
C...  THE VARIABLES HAVE A CONVENIENT RANGE, E.G., Z HAS THE RANGE
C...  0 LE Z LE 1 RATHER THAN 0 LE Z LE 0.0004, AND (2) SIGNIFICANT
C...  DIMENSIONLESS NUMBERS NATURALLY APPEAR IN THE DIMENSIONLESS
C...  EQUATIONS, E.G., THE BIOT NUMBER.
C...
C...  THE FOLLOWING CODING IS FOR SIX RUNS CORRESPONDING TO 0, 10, 20,
C...  30, 40 AND 50 DAYS.  THE CORRESPONDING VALUES OF KL ARE USED IN
C...  THE SIX RUNS OF THE MODEL.
C...
C...  ALSO, TO FACILITATE COMPARISON OF THE NUMERICAL SOLUTION FOR
C...  THE SIX RUNS, THE TIME INTEGRAL OF THE OXYGEN MASS TRANSFER RATE
C...  IS COMPUTED AND PLOTTED AS A FUNCTION OF TIME.  THIS GIVES THE
C...  TOTAL AMOUNT OF OXYGEN TRANSFERRED AS A FUNCTION OF TIME.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11),        RI
     2      /F/    CT(11),         R
     3      /S/    CZ(11),   CZZ(11)
     4      /C/         D,         B,       AGE,        KL,        BI,
     5                 C0,         N,        IP
      REAL KL
C...
C...  SET THE MODEL PARAMETERS
      D=3.6E-06
      B=0.0004
      AGE=10.0*FLOAT(NORUN-1)
      KL=0.1-(0.06/50.0)*AGE
      C0=0.001
C...
C...  BIOT NUMBER
      BI=KL*B/D
C...
C...  INITIAL CONDITION
      N=11
      DO 1 I=1,N
      C(I)=1.0
1     CONTINUE
      RI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11),        RI
     2      /F/    CT(11),         R
     3      /S/    CZ(11),   CZZ(11)
     4      /C/         D,         B,       AGE,        KL,        BI,
     5                 C0,         N,        IP
      REAL KL
C...
C...  DERIVATIVE C
C...              Z
      CALL DSS004(0.,1.,N,C,CZ)
C...
C...  BOUNDARY CONDITIONS
      CZ(1)=0.
      CZ(N)=-BI*(C(N)-0.)
C...
C...  DERVIATIVE C
C...              ZZ
      CALL DSS004(0.,1.,N,CZ,CZZ)
C...
C...  PDE
      DO 1 I=1,N
      CT(I)=CZZ(I)
1     CONTINUE
C...
C...  INTEGRATED RATE
      R=BI*C(N)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11),        RI
     2      /F/    CT(11),         R
     3      /S/    CZ(11),   CZZ(11)
     4      /C/         D,         B,       AGE,        KL,        BI,
     5                 C0,         N,        IP
      REAL KL
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), RATEP(6,51), RINTP(6,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(10X,'T',2X,7X,'T',3X,7X,'O2 RATE',6X,'O2 RATE',
     1       7X,'INT RATE',/,
     2       8X,'(DIM)',5X,'(SEC)',9X,'(DIM)',4X,'(MOL/S-CM**2)',
     3       2X,'(MOL/CM**2)')
C...
C...  COMPUTE THE DIMENSIONAL TIME, O2 TRANSFER RATE, INTEGRATED O2
C...  TRANSFER RATE
      TIME=T*(B**2)/D
      RATE= R*KL/BI*C0
      RINT=RI*KL/BI*C0
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,2)T,TIME,R,RATE,RINT
2     FORMAT(F12.2,E12.3,F14.4,E14.4,E14.4)
C...
C...  STORE THE (DIMENSIONAL) SOLUTION FOR PLOTTING
      TP(IP)=TIME
      RATEP(NORUN,IP)=RATE
      RINTP(NORUN,IP)=RINT
C...
C...  PLOT THE SOLUTIONS AT THE END OF THE SIXTH RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.6)RETURN
C...
C...  RATE VS TIME
      CALL TPLOTS(NORUN,IP,TP,RATEP)
      WRITE(NO,10)
10    FORMAT(1H ,/,
     1 'OXYGEN RATE (MOL/S-CM**2) VS TIME (SEC)',/,
     2 ' 1, 2, 3, 4, 5, 6 - 0, 10, 20, 30, 40, 50 DAYS')
C...
C...  INTEGRATED RATE VS TIME
      CALL TPLOTS(NORUN,IP,TP,RINTP)
      WRITE(NO,11)
11    FORMAT(1H ,/,
     1 'INTEGRATED OXYGEN RATE (MOL/CM**2) VS TIME (SEC)',/,
     2 ' 1, 2, 3, 4, 5, 6 - 0, 10, 20, 30, 40, 50 DAYS')
C...
C...  COMPUTE AND PRINT THE CHANGE IN THE INTEGRATED OXYGEN RATE
C...  RELATIVE TO THE VALUE FOR NO AGING
      DO 20 I=1,NORUN
      PCRINT=(RINTP(I,51)-RINTP(1,51))/RINTP(1,51)*100.
      WRITE(NO,21)I,PCRINT
21    FORMAT(1H ,//,
     1 ' RUN NO ',I2,' PERCENT CHANGE IN O2 TRANSFER ',F7.3)
20    CONTINUE
      RETURN
      END
OXYGEN TRANSFER IN AGING BLOOD
0.        1.0       0.02
   12 1000    1    1  REL 0.001
REPEATS
    5
END OF RUNS
*APP SEP30
      SUBROUTINE INITAL
C...
C...  FLOW THROUGH POROUS MEDIA
C...
C...  THE FOLLOWING MODEL FOR THE MOVEMENT OF WATER THROUGH VERY DRY
C...  SOIL IS DISCUSSED BY FINLAYSON (1)
C...
C...     (-S  )*P  = (KR(PC)*P ) , PC = - P                  (1)(2)
C...        PC   T            X X
C...
C...     P(0,T) = BP1, P (1,T) = 0                           (3)(4)
C...                    X
C...
C...     P(X,0) = BP0                                           (5)
C...
C...  (1)  FINLAYSON, B. A., FLOW THROUGH POROUS MEDIA, IN STIFF
C...       COMPUTATION (R. C. AIKEN, ED), OXFORD UNIVERSITY PRESS,
C...       1985, PP. 130-134
C...
C...  WHERE
C...
C...     P     WATER PRESSURE
C...
C...     PC    CAPILLARY PRESSURE
C...
C...     T     TIME
C...
C...     X     POSITION
C...
C...     S     SATURATION
C...
C...     KR    RELATIVE PERMEABILITY
C...
C...     BP0,  CONSTANT INITIAL AND BOUNDARY VALUES OF P(X,T),
C...     BP1   RESPECTIVELY
C...
C...  AN ALPHABETIC SUBSCRIPT IN THE PRECEDING EQUATIONS INDICATES A
C...  PARTIAL DERIVATIVE, E.G., P  IS THE FIRST-ORDER PARTIAL DERIVATIVE
C...                             T
C...  OF P WITH RESPECT TO T.
C...
C...  KR AND S ARE GIVEN BY THE FOLLOWING EQUATIONS
C...
C...     KR = 1/(1 + PC*L/146)**6.65                            (6)
C...
C...     S = 0.32 + 0.68/(1 + PC*L/231)**3.65                   (7)
C...
C...  WHERE L = 300 CM.
C...
C...  THE NUMERICAL VALUES OF THE MODELS PARAMETERS ARE SET IN SUBROU-
C...  TINE INITAL, AND THE MODEL EQUATIONS, (1) TO (7), ARE PROGRAMMED
C...  IN SUBROUTINE DERV.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     P(51)
     2      /F/    PT(51)
     3      /S/    PX(51),   KPX(51),  KPXX(51)
     4      /C/        C1,        C2,         L,         N,        IP
      REAL              L,         K,       KPX,      KPXX
C...
C...  SET THE MODEL PARAMETERS
C...
C...  THE FOLLOWING VALUES OF C1 AND C2 WERE SELECTED ARBITRARILY.
C...  FINLAYSON'S FIGURE 3.4 SUGGESTS C1 = 0, C2 = -1, BUT WHEN THESE
C...  VALUES WERE USED, STRANGE NUMBERS WERE COMPUTED IN FUNCTION K
C...  WHICH APPEARS TO HAPPEN WHEN P AND PC ARE CLOSE TO 0.  THEREFORE,
C...  VALUES OF C1 AND C2 WERE SELECTED TO KEEP P AND PC AWAY FROM 0
      C1=-1.0
      C2=-2.0
      L=300.
      N=51
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      P(I)=C2
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     P(51)
     2      /F/    PT(51)
     3      /S/    PX(51),   KPX(51),  KPXX(51)
     4      /C/        C1,        C2,         L,         N,        IP
      REAL              L,         K,       KPX,      KPXX
C...
C...  CONSTRAIN THE PRESSURE TO PHYSICALLY MEANINGFUL VALUES
      DO 3 I=1,N
      IF(P(I).GT.0.)P(I)=0.
3     CONTINUE
C...
C...  BOUNDARY CONDITION AT X = 0
      P(1)=C1
      PT(1)=0.
C...
C...  SPATIAL DERIVATIVE P
C...                      X
      CALL DSS004(0.,1.,N,P,PX)
C...
C...  BOUNDARY CONDITION AT X = 1
      PX(N)=0.
C...
C...  PRODUCT K(P)*P
C...                X
      DO 1 I=1,N
      KPX(I)=K(I)*PX(I)
1     CONTINUE
C...
C...  DERIVATIVE (K(P)*P )
C...                    X X
      CALL DSS004(0.,1.,N,KPX,KPXX)
C...
C...  PDE
      DO 2 I=2,N
      PT(I)=-(1./SP(I))*KPXX(I)
2     CONTINUE
      RETURN
      END
      REAL FUNCTION K(I)
C...
C...  FUNCTION K COMPUTES THE RELATIVE PERMEABILITY ACCORDING TO
C...  EQUATION (6)
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     P(51)
     2      /F/    PT(51)
     3      /S/    PX(51),   KPX(51),  KPXX(51)
     4      /C/        C1,        C2,         L,         N,        IP
      COMMON/IO/       NI,        NO
      REAL              L,       DUM,       KPX,      KPXX
      PC=-P(I)
      IF(PC.LT.0.)PC=0.
      ARG=1.+PC*L/146.
      K=1./ARG**6.65
      RETURN
      END
      REAL FUNCTION SP(I)
C...
C...  FUNCTION SP COMPUTES THE DERIVATIVE S  ACCORDING TO EQUATION
C...  (7)                                  P
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     P(51)
     2      /F/    PT(51)
     3      /S/    PX(51),   KPX(51),  KPXX(51)
     4      /C/        C1,        C2,         L,         N,        IP
      COMMON/IO/       NI,        NO
      REAL              L,         K,       KPX,      KPXX
      PC=-P(I)
      IF(PC.LT.0.)PC=0.
      ARG=1.+PC*L/231.
      SP=(0.68)*(-3.65)*(ARG**(-4.65))*(L/231.)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     P(51)
     2      /F/    PT(51)
     3      /S/    PX(51),   KPX(51),  KPXX(51)
     4      /C/        C1,        C2,         L,         N,        IP
      REAL              L,         K,       KPX,      KPXX,
     1                                     KPXP,     KPXXP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION             PP(3,51),            PXP(3,51),
     1                    KPXP(3,51),          KPXXP(3,51),
     2                     PTP(3,51),               XP(51)
C...
C...  PRINT THE NUMERICAL SOLUTION
      NS=10
      WRITE(NO,1)T,(   P(I),I=1,N,NS),(  PX(I),I=1,N,NS),
     1             ( KPX(I),I=1,N,NS),(KPXX(I),I=1,N,NS),
     2             (  PT(I),I=1,N,NS)
1     FORMAT(1H ,//,5H T = ,F10.3,/,
     1 5H    P,6E11.3,/,5H   PX,6E11.3,/,
     2 5H  KPX,6E11.3,/,5H KPXX,6E11.3,/,
     3 5H   PT,6E11.3,/)
C...
C...  INITIALIZE A SECOND COUNTER FOR THE PLOTTED SOLUTION
      IF(IP.EQ.0)IP1=0
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      IF(((IP-1)/10*10).NE.(IP-1))RETURN
      IP1=IP1+1
      DO 2 I=1,N
      XP(I)=FLOAT(I-1)/FLOAT(N-1)
         PP(IP1,I)=P(I)
        PXP(IP1,I)=PX(I)
       KPXP(IP1,I)=KPX(I)
      KPXXP(IP1,I)=KPXX(I)
        PTP(IP1,I)=PT(I)
2     CONTINUE
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP1.LT.3)RETURN
C...
C...  P VS X WITH T AS A PARAMETER
      CALL TPLOTS(3,IP,XP,   PP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' P(X,T) VS X, T = 0, 1, 2')
C...
C...  PX VS X WITH T AS A PARAMETER
      CALL TPLOTS(3,IP,XP,  PXP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' PX VS X, T = 0, 1, 2')
C...
C...  KR*PX VS X WITH T AS A PARAMETER
      CALL TPLOTS(3,IP,XP, KPXP)
      WRITE(NO,13)
13    FORMAT(1H ,//,' KR*PX VS X, T = 0, 1, 2')
C...
C...  (KR*PX)X VS X WITH T AS A PARAMETER
      CALL TPLOTS(3,IP,XP,KPXXP)
      WRITE(NO,14)
14    FORMAT(1H ,//,' (KR*PX)X VS X, T = 0, 1, 2')
C...
C...  PT VS X WITH T AS A PARAMETER
      CALL TPLOTS(3,IP,XP,  PTP)
      WRITE(NO,15)
15    FORMAT(1H ,//,' PT VS T, T = 0, 1, 2')
      IP=0
      IP1=0
      RETURN
      END
MOVEMENT OF WATER IN DRY SOIL
0.        2.0       0.1
   51 1000    1    1  ABS  0.01
END OF RUNS
*APP SEP31
      SUBROUTINE INITAL
C...
C...  BATCH DISTILLATION SEPARATION OF N-HEPTANE FROM N-OCTANE
C...  WITHOUT AUTOMATIC CONTROL
C...
C...  THE FOLLOWING MODEL IS AN EXTENSION OF THE BATCH DISTILLATION
C...  MODEL REPORTED BY DAVIS (1).  ESSENTIALLY, FIVE TRAYS HAVE BEEN
C...  ADDED TO THE DAVIS MODEL TO IMPROVE THE PERFORMANCE OF THE BATCH
C...  COLUMN.  THUS, AN INTERESTING VARIANT OF THE PROBLEM WOULD BE
C...  TO RUN THE FOLLOWING PROGRAM WITH AND WITHOUT THE FIVE TRAYS
C...  TO DETERMINE THEIR EFFECT ON THE BATCH COLUMN PERFORMANCE.
C...
C...  (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR CHEMICAL
C...       ENGINEERING, JOHN WILEY AND SONS, INC., NY, 1984, PROB. 4,
C...       PP 46-47
C...
C...  MASS BALANCE ON THE POT
C...
C...     DS/DT = L - V
C...
C...  COMPONENT BALANCE ON THE POT
C...
C...     D(S*XH0)/DT = L*XH1 - V*YH0
C...
C...  COMPONENT BALANCE ON TRAY 1
C...
C...     HM*DXH1/DT = V*YH0 + L*XH2 - V*YH1 - L*XH1
C...
C...  COMPONENT BALANCE ON TRAY 2
C...
C...     HM*DXH2/DT = V*YH1 + L*XH3 - V*YH2 - L*XH2
C...
C...  COMPONENT BALANCE ON TRAY 3
C...
C...     HM*DXH3/DT = V*YH2 + L*XH4 - V*YH3 - L*XH3
C...
C...  COMPONENT BALANCE ON TRAY 4
C...
C...     HM*DXH4/DT = V*YH3 + L*XH4 - V*YH4 - L*XH4
C...
C...  COMPONENT BALANCE ON TRAY 5
C...
C...     HM*DXH5/DT = V*YH4 + L*XHC - V*YH5 - L*XH5
C...
C...  COMPONENT BALANCE ON THE CONDENSER
C...
C...     M*DXHC/DT = V*YH5 - L*XHC - D*XHC
C...
C...  ASSUME THAT V IS CONSTANT, AS SET BY THE HEAT INPUT RATE TO THE
C...  STILL (POT).  THEN DEFINE A REFLUX RATIO BY THE EQUATIONS
C...
C...     V = L + D
C...
C...     R = D/L
C...
C...  THUS
C...
C...     V = L + L*R = L*(1 + R)
C...
C...  OR
C...
C...     L = (1/(1 + R))*V
C...
C...     D = (R/(1 + R))*V
C...
C...  ALSO, THE VAPOR IS ASSUMED TO BE IN EQUILBRIUM WITH ITS ASSOCIATED
C...  LIQUID, SO THAT
C...
C...     YHI = 2.16*XHI/(1 + 1.16*XHI), I = 0, 1, 2, 3, 4, 5
C...
C...  THE DEPENDENT VARIABLES OF THE PROBLEMS (I.E., VARIABLES DEFINED
C...  BY DIFFERENTIAL EQUATIONS) ARE XH0, XH1, XH2, XH3, XH4, XH5, XHC
C...  AND S, EACH OF WHICH REQUIRES AN INITIAL CONDITION.
C...
C...  THE FOLLOWING CONSTANTS ARE USED IN THE PROGRAMMING
C...
C....   R = 0.3, M = 10, HM = 1, V = 2
C...
C....   S(0) = 100, XHC(0) = 0.5
C...
C....   XH0(0) = XH1(0) = XH2(0) = XH3(0) = XH4(0) = XH5(0) = 0.5
C...
C...  THE SOLUTION IS PRINTED AND PLOTTED IN SUBROUTINE PRINT.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S
     2      /F/ DXHDT(0:5),      DXCDT,       DSDT
     3      /C/          R,          M,         HM,          V,
     4                   L,        XH0,          D,    YH(0:5),
     5                   N,         IP
      REAL               M,          L
C...
C...  MODEL PARAMETERS
      R=0.3
      M=10.
      HM=1.0
      V=2.0
      N=5
C...
C...  INITIAL CONDITIONS
      DO 1 I=0,N
      XH(I)=0.5
1     CONTINUE
      XC=0.5
      S=100.
      XH(0)=S*XH(0)
C...
C...  INITIAL DERIVATIVES
      IP=0
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S
     2      /F/ DXHDT(0:5),      DXCDT,       DSDT
     3      /C/          R,          M,         HM,          V,
     4                   L,        XH0,          D,    YH(0:5),
     5                   N,         IP
      REAL               M,          L
C...
C...  MODEL ALGEBRA
C...
C...     FLOW RATES L AND D
         L=(1.0/(1.0+R))*V
         D=(  R/(1.0+R))*V
C...
C...     BOTTOMS COMPOSITION
         XH0=XH(0)/S
C...
C...     PLACE CONSTRAINS ON THE LIQUID COMPOSITIONS
         DO 3 I=1,N
         IF(XH(I).LT.0.)XH(I)=0.
         IF(XH(I).GT.1.)XH(I)=1.
3        CONTINUE
         IF(XH0.LT.0.)XH0=0.
         IF(XH0.GT.1.)XH0=1.
         IF(XC.LT.0.)XC=0.
         IF(XC.GT.1.)XC=1.
C...
C...     VAPOR COMPOSITIONS
         DO 1 I=1,N
         YH(I)=2.16*XH(I)/(1.0+1.16*XH(I))
1        CONTINUE
         YH(0)=2.16*XH0  /(1.0+1.16*XH0  )
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DO 2 I=0,N
      IF(I.EQ.0)DXHDT(0)=L*XH(1)-V*YH(0)
      IF(I.EQ.N)DXHDT(N)=(1.0/M)*( L*XC   +V*YH(N-1)
     1                            -L*XH(N)-V*YH(N  ))
      IF((I.NE.0).AND.(I.NE.N))
     1          DXHDT(I)=(1.0/HM)*(L*XH(I+1)+V*YH(I-1)
     2                           - L*XH(I  )-V*YH(I  ))
2     CONTINUE
      DXCDT=(1.0/M)*(V*YH(N)-L*XC-D*XC)
      DSDT=L-V
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S
     2      /F/ DXHDT(0:5),      DXCDT,       DSDT
     3      /C/          R,          M,         HM,          V,
     4                   L,        XH0,          D,    YH(0:5),
     5                   N,         IP
      REAL               M,          L
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), XP(2,51)
C...
C...  INCREMENT THE COUNTER FOR PLOTTING
      IP=IP+1
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,  XH0,( XH  (I),I=1,N),  XC  ,  S  ,
     1             DXHDT(0),(DXHDT(I),I=1,N), DXCDT, DSDT
2        FORMAT(F10.1,/,8F9.3,/,8F9.5,/)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      XP(1,IP)=XH0
      XP(2,IP)=XC
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL SPLOTS(2,IP,TP,XP)
      WRITE(NO,3)
3     FORMAT(1H ,/,' 1 - XHO, 2 - XC VS T')
      RETURN
      END
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
    8 1000    1    1  REL 0.001
END OF RUNS
*APP SEP32
      SUBROUTINE INITAL
C...
C...  BATCH DISTILLATION SEPARATION OF N-HEPTANE FROM N-OCTANE
C...  WITH AUTOMATIC CONTROL
C...
C...  THE FOLLOWING MODEL IS AN EXTENSION OF THE BATCH DISTILLATION
C...  MODEL REPORTED BY DAVIS (1).  ESSENTIALLY, FIVE TRAYS HAVE BEEN
C...  ADDED TO THE DAVIS MODEL TO IMPROVE THE PERFORMANCE OF THE BATCH
C...  COLUMN.  THUS, AN INTERESTING VARIANT OF THE PROBLEM WOULD BE
C...  TO RUN THE FOLLOWING PROGRAM WITH AND WITHOUT THE FIVE TRAYS
C...  TO DETERMINE THEIR EFFECT ON THE BATCH COLUMN PERFORMANCE.
C...
C...  (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR CHEMICAL
C...       ENGINEERING, JOHN WILEY AND SONS, INC., NY, 1984, PROB. 4,
C...       PP 46-47
C...
C...  MASS BALANCE ON THE POT
C...
C...     DS/DT = L - V
C...
C...  COMPONENT BALANCE ON THE POT
C...
C...     D(S*XH0)/DT = L*XH1 - V*YH0
C...
C...  COMPONENT BALANCE ON TRAY 1
C...
C...     HM*DXH1/DT = V*YH0 + L*XH2 - V*YH1 - L*XH1
C...
C...  COMPONENT BALANCE ON TRAY 2
C...
C...     HM*DXH2/DT = V*YH1 + L*XH3 - V*YH2 - L*XH2
C...
C...  COMPONENT BALANCE ON TRAY 3
C...
C...     HM*DXH3/DT = V*YH2 + L*XH4 - V*YH3 - L*XH3
C...
C...  COMPONENT BALANCE ON TRAY 4
C...
C...     HM*DXH4/DT = V*YH3 + L*XH4 - V*YH4 - L*XH4
C...
C...  COMPONENT BALANCE ON TRAY 5
C...
C...     HM*DXH5/DT = V*YH4 + L*XHC - V*YH5 - L*XH5
C...
C...  COMPONENT BALANCE ON THE CONDENSER
C...
C...     M*DXHC/DT = V*YH5 - L*XHC - D*XHC
C...
C...  ASSUME THAT V IS CONSTANT, AS SET BY THE HEAT INPUT RATE TO THE
C...  STILL (POT).  THEN DEFINE A REFLUX RATIO BY THE EQUATIONS
C...
C...     V = L + D
C...
C...     R = D/L
C...
C...  THUS
C...
C...     V = L + L*R = L*(1 + R)
C...
C...  OR
C...
C...     L = (1/(1 + R))*V
C...
C...     D = (R/(1 + R))*V
C...
C...  ALSO, THE VAPOR IS ASSUMED TO BE IN EQUILBRIUM WITH ITS ASSOCIATED
C...  LIQUID, SO THAT
C...
C...     YHI = 2.16*XHI/(1 + 1.16*XHI), I = 0, 1, 2, 3, 4, 5
C...
C...  THE DEPENDENT VARIABLES OF THE PROBLEMS (I.E., VARIABLES DEFINED
C...  BY DIFFERENTIAL EQUATIONS) ARE XH0, XH1, XH2, XH3, XH4, XH5, XHC
C...  AND S, EACH OF WHICH REQUIRES AN INITIAL CONDITION.
C...
C...  THE FOLLOWING CONSTANTS ARE USED IN THE PROGRAMMING
C...
C...     M = 10, HM = 1, V = 2
C...
C...     S(0) = 100, XHC(0) = 0.5
C...
C...     XH0(0) = XH1(0) = XH2(0) = XH3(0) = XH4(0) = XH5(0) = 0.5
C...
C...  THE SOLUTION IS PRINTED AND PLOTTED IN SUBROUTINE PRINT.
C...
C...  IN ADDITION TO THE PRECEDING BASIC MODEL, THE FOLLOWING EQUATIONS
C...  FOR AN AUTOMATIC CONTROL SYSTEM ARE ALSO TO BE INCLUDED.  A PI
C...  CONTROLLER HAS BEEN PROPOSED WHICH WILL GIVE A TIME-AVERAGE PRO-
C...  DUCT COMPOSITION OF 0.8 MOLE FRACTION N-HEPTANE IN THE DISTILLATE
C...  PRODUCT.  THE PROPOSED CONTROL SYSTEM HAS THE EQUATIONS
C...
C...                             T
C...     D = DS +KP*(E + (1/TI)*INT E*DT)
C...                             O
C...
C...     E = I1/I2 - 0.8
C...
C...  WHERE
C...
C...           T
C...     I1 = INT D*XC*DT
C...           0
C...
C...           T
C...     I2 = INT D*DT
C...           0
C...
C...  THE PROPOSED CONTROL SYSTEM IS SIMULATED TO DETERMINE IF IT IS
C...  FEASIBLE.  SPECIFICALLY, THE VALUES OF THE PARAMETERS DS, KP
C...  AND TI ARE DETERMINED SO THAT E IS MINIMIZED OVER TIME WHILE I1,
C...  THE TOTAL AMOUNT OF N-HEPTANE PRODUCED IN THE DISTILLATE, IS
C...  MAXIMIZED.
C...
C...  NOTE THAT V = 2 (THE VAPOR BOILUP RATE REMAINS CONSTANT), BUT
C...  THE DISTILLATE RATE, D, NOW VARIES WITH TIME DUE TO THE CON-
C...  TROLLER.  THUS R (THE REFLUX RATIO) AND L (THE LIQUID RATE DOWN
C...  THROUGH THE COLUMN) ALSO VARY WITH TIME.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  MODEL PARAMETERS
      M=10.
      HM=1.0
      V=2.0
      N=5
C...
C...  CONTROLLER PARAMETERS
C...
C...  NO CONTROL
      IF(NORUN.EQ.1)THEN
         R=0.3
         DS=R/(1.0+R)*V
         AKC=0.
         TI=1.0E+10
C...
C...  PROPORTIONAL CONTROL
      ELSE IF(NORUN.EQ.2)THEN
         DS=0.4
         AKC=1.0
         TI=1.0E+10
C...
C...  PI CONTROL
      ELSE IF(NORUN.EQ.3)THEN
         DS=0.4
         AKC=1.0
         TI=50.
      END IF
C...
C...  INITIAL CONDITIONS
      DO 1 I=0,N
      XH(I)=0.5
1     CONTINUE
      XC=0.5
      S=100.
      XH(0)=S*XH(0)
      I1=0.
      I2=0.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      IP=0
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  MODEL ALGEBRA
C...
C...     CONTROLLER EQUATIONS
         IF(I2.LT.1.0E-10)THEN
C...        FOR JUST PROPORTIONAL CONTROL, A LARGE INITIAL ERROR
C...        PRODUCES A REASONABLE INITIAL CONTROL ACTION
            IF(NORUN.LE.2)E=-0.8
C...
C...        FOR PI CONTROL, A SMALLER INITIAL ERROR IS USED SO THAT
C...        THE INTEGRAL OF THIS ERROR IS REASONABLE
            IF(NORUN.GT.2)E= 0.
            D=DS
         ELSE IF(I2.GT.1.0E-10)THEN
            RI1I2=I1/I2
            E=RI1I2-0.8
            D=DS+AKC*(E+(1.0/TI)*EI)
         END IF
         IF(D.LT.0.)D=0.
C...
C...     LIQUID FLOW RATE
         L=V-D
C...
C...     BOTTOMS COMPOSITION
         XH0=XH(0)/S
C...
C...     PLACE CONSTRAINS ON THE LIQUID COMPOSITIONS
         DO 3 I=1,N
         IF(XH(I).LT.0.)XH(I)=0.
         IF(XH(I).GT.1.)XH(I)=1.
3        CONTINUE
         IF(XH0.LT.0.)XH0=0.
         IF(XH0.GT.1.)XH0=1.
         IF(XC.LT.0.)XC=0.
         IF(XC.GT.1.)XC=1.
C...
C...     VAPOR COMPOSITIONS
         DO 1 I=1,N
         YH(I)=2.16*XH(I)/(1.0+1.16*XH(I))
1        CONTINUE
         YH(0)=2.16*XH0  /(1.0+1.16*XH0  )
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DO 2 I=0,N
      IF(I.EQ.0)DXHDT(0)=L*XH(1)-V*YH(0)
      IF(I.EQ.N)DXHDT(N)=(1.0/M)*( L*XC   +V*YH(N-1)
     1                            -L*XH(N)-V*YH(N  ))
      IF((I.NE.0).AND.(I.NE.N))
     1          DXHDT(I)=(1.0/HM)*(L*XH(I+1)+V*YH(I-1)
     2                           - L*XH(I  )-V*YH(I  ))
2     CONTINUE
      DXCDT=(1.0/M)*(V*YH(N)-L*XC-D*XC)
      DSDT=L-V
      DI1DT=D*XC
      DI2DT=D
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/          T,      NSTOP,      NORUN
     1      /Y/    XH(0:5),         XC,          S,        I1,       I2,
     2                  EI
     3      /F/ DXHDT(0:5),      DXCDT,       DSDT,     DI1DT,    DI2DT,
     4                   E
     5      /C/          R,          M,         HM,         V,        L,
     6                 XH0,          D,    YH(0:5),     RI1I2,       DS,
     7                 AKC,         TI,          N,        IP
      REAL               M,          L,         I1,        I2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), XCP(3,51), EP(4,51), DP(3,51)
C...
C...  INCREMENT THE COUNTER FOR PLOTTING
      IP=IP+1
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.1)THEN
         WRITE(NO,4)
4        FORMAT(' T',/,' XH0, (XH(I),I=1,N), XC, S',/,
     1          ' DXHDT(0), (DXHDT(I),I=1,N), DXCDT, DSDT',/,
     2          ' I1, I2, I1/I2, E, D',/)
C...
C...     SET RI1I2 SO THAT IT CAN BE PRINTED AT T = 0
         RI1I2=0.
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,  XH0,( XH  (I),I=1,N),  XC  ,  S  ,
     1             DXHDT(0),(DXHDT(I),I=1,N), DXCDT, DSDT
2        FORMAT(F10.1,/,8F9.3,/,8F9.5)
         WRITE(NO,3)I1, I2, RI1I2, E, D
3        FORMAT(5F9.5,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING.  ZEROS ARE STORED IN EP(4,IP)
C...  TO PRODUCE A ZERO ERROR LINE ON THE PLOT OF E VS T
      EP(     4,IP)=0.
      TP(IP)=T
      XCP(NORUN,IP)=XC
       EP(NORUN,IP)=E
       DP(NORUN,IP)=D
C...
C...  PLOT THE SOLUTION AT THE END OF THE THIRD RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.NE.3)RETURN
C...
C...  XC VS T
      CALL SPLOTS(NORUN,IP,TP,XCP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' XC VS T')
C...
C...  E VS T
      CALL SPLOTS(NORUN+1,IP,TP,EP)
      WRITE(NO,12)
12    FORMAT(1H ,/,' E VS T')
C...
C...  D VS T
      CALL SPLOTS(NORUN,IP,TP,DP)
      WRITE(NO,13)
13    FORMAT(1H ,/,' D VS T')
      RETURN
      END
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
BATCH DISTILLATION OF N-HEPTANE FROM N-OCTANE
0.        200.0     4.0
   11 1000    1    1  REL 0.001
END OF RUNS
*APP SEP33
      SUBROUTINE INITAL
C...
C...  DIFFUSION AND REACTION IN AN IMMOBILIZED ENZYME CATALYST
C...
C...  CONSIDER THE FOLLOWING MODEL FOR DIFFUSION AND REACTION IN A
C...  SPHERICAL CATALYST PARTICLE CONTAINING AN IMMOBILIZED ENZYME:
C...
C...  C  = D*(C   + (2/R)*C ) - K*C
C...   T       RR          R
C...
C...  C(R,0) = C0, C (0,T) = 0, -D*C (R0,T) = KY*(C(R0,T) - CS)
C...                R               R
C...
C...  WHERE
C...
C...  C        CONCENTRATION OF THE SUBSTRATE (REACTANT)
C...
C...  R        RADIAL POSITION WITHIN THE PARTICLE
C...
C...  T        TIME
C...
C...  D        DIFFUSIVITY WITHIN THE PARTICLE
C...
C...  K        FIRST-ORDER REACTION RATE CONSTANT
C...
C...  R0       RADIUS OF THE PARTICLE
C...
C...  KY       MASS TRANSFER COEFFICIENT
C...
C...  CS       SUBSTRATE CONCENTRATION IN THE LIQUID SURROUNDING THE
C...           PARTICLE
C...
C...  C0       INITIAL SUBSTRATE CONCENTRATION
C...
C...  (A)  EXPRESS THE PRECEDING SET OF EQUATIONS IN TERMS OF THE
C...       DIMENSIONLESS VARIABLES
C...
C...       CD = C/CS, TD = T*D/R0**2, RD = R/R0
C...
C...  (B)  COMPUTE A SOLUTION TO THE DIMENSIONLESS EQUATIONS FOR
C...       C0 = 0, CS = 0.001, K = D = 1, R0 = 0.1, KY = 0.1.  PLOT
C...       CD(RD,TD) VS RD FOR A SERIES OF DIMENSIONLESS TIMES, TD.
C...       USE SUBROUTINE DSS004 FOR FIRST-ORDER DERIVATIVES AND DSS042
C...       FOR SECOND-ORDER DERIVATIVES IN RD.
C...
C...  THE SYSTEM WHEN WRITTEN IN TERMS OF THE DIMENSIONLESS VARIABLES
C...  IS
C...
C...  CD  = (CD     + (2/RD)*CD  ) - K*(R0**2)/D*CD
C...    TD     RDRD            RD
C...
C...  CD(RD,0) = C0/CS, CD  (0,TD) = 0
C...                      RD
C...
C...  -CD  (1,T) = KY*R0/D*(CD(1,T) - 1)
C...     RD
C...
C...  NOTE THE IMPORTANT DIMENSIONLESS GROUPS K*(R0**2)/D AND KY*R0/D,
C...  WHICH WILL BE DESIGNATED A1 AND A2, RESPECTIVELY, IN THE FOLLOW-
C...  ING CODING.  ALSO, THE DIMENSIONLESS DESIGNATION, D, FOR THE
C...  VARIABLES WILL BE DROPPED TO SIMPLIFY THE CODING, E.G., CD WILL
C...  BE REPLACED WITH C, WITH THE UNDERSTANDING THAT THIS IS A DI-
C...  MENSIONLESS CONCENTRATION.  THE SAME APPLIES TO TD (NOW T) AND
C...  RD (NOW R).  AN ADVANTAGE OF USING DIMENSIONLESS VARIABLES IS
C...  THE RANGE OVER WHICH THEY VARY, E.G., 0 LE R LE 1 REGARDLESS OF
C...  THE VALUE OF R0.
C...
C...  FINALLY, NOTE ONE OTHER IMPORTANT CHARACTERISTIC OF THIS SYSTEM:
C...  THE CONCENTRATION CS USED TO DEFINE THE DIMENSIONLESS CONCENTRA-
C...  TION, DOES NOT APPEAR IN THE FINAL DIMENSIONLESS EQUATIONS.  THIS
C...  IS BECAUSE THE PROBLEM IS ENTIRELY LINEAR.  IF THE PROBLEM HAD
C...  BEEN NONLINEAR, CS WOULD APPEAR SOMEWHERE IN THE EQUATIONS, I.E.,
C...  A FUNDAMENTAL PROPERTY OF NONLINEAR SYSTEMS IS THE DEPENDENCE ON
C...  THE ABSOLUTE VALUES OF THE STATE VARIABLES.  TO GIVE A SPECIFIC
C...  EXAMPLE, CONSIDER THE FIRST EQUATION IF THE REACTION HAD BEEN
C...  SECOND ORDER, SO THAT THE REACTION TERM WAS -K*(C**2).  NOW IF
C...  THE SAME DIMENSIONLESS VARIABLES ARE USED, CS WILL APPEAR IN THE
C...  DIMENSIONLESS PDE.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  SET THE MODEL PARAMETERS
      C0=0.
      CS=0.001
      R0=0.1
C...
C...  SLOW MASS TRANSFER, SLOW REACTION, FAST DIFFUSION
      IF(NORUN.EQ.1)THEN
      KY=0.1
      K =1.0
      D =1.0
C...
C...  FAST MASS TRANSFER, FAST REACTION, SLOW DIFFUSION
      ELSE IF(NORUN.EQ.2)THEN
      KY=5.0
      K =50.0
      D =0.1
      END IF
C...
C...  DIMENSIONLESS GROUPS
      A1=K*(R0**2)/D
      A2=KY*R0/D
C...
C...  INITIAL CONDITION
      N11=11
      DO 1 I=1,N11
      C(I)=0.
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  FIRST-ORDER SPATIAL DERIVATIVE
      CALL DSS004(0.,1.,N11,C,CR)
C...
C...  BOUNDARY CONDITIONS
      CR(1)=0.
      CR(N11)=-A2*(C(N11)-1.0)
C...
C...  SECOND-ORDER SPATIAL DERIVATIVE
      NL=2
      NU=2
      CALL DSS042(0.,1.,N11,C,CR,CRR,NL,NU)
C...
C...  PDE, R NE 0
      DO 1 I=2,N11
      R=FLOAT(I-1)/10.
      CT(I)=(CRR(I)+(2.0/R)*CR(I))-A1*C(I)
1     CONTINUE
C...
C...  PDE, R = 0
      CT(1)=3.0*CRR(1)-A1*C(1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION RP(11), CP(2,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T','   (0.0,T)','   (0.2,T)','   (0.4,T)',
     1                 '   (0.6,T)','   (0.8,T)','   (1.0,T)')
      END IF
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,2)T,(  C(I),I=1,N11,2),
     1                ( CR(I),I=1,N11,2),
     2                (CRR(I),I=1,N11,2),
     3                ( CT(I),I=1,N11,2)
2     FORMAT(F10.2,/,'    C(R,T)',6F10.4,/,
     1               '   CR(R,T)',6F10.4,/,
     2               '  CRR(R,T)',6F10.4,/,
     3               '   CT(R,T)',6F10.4,/)
      END IF
C...
C...  STORE THE CONCENTRATION PROFILE AT THE END OF THE RUN FOR
C...  PLOTTING
      IF(IP.EQ.101)THEN
         DO 3 I=1,N11
         CP(NORUN,I)=C(I)
         RP(I)=FLOAT(I-1)/10.0
         IF(NORUN.EQ.2)B2=A2
3        CONTINUE
C...
C...     STORE THE DAMKOHLER AND BIOT NUMBERS FOR SUBSEQUENT PRINTING
         IF(NORUN.EQ.1)D1=A1
         IF(NORUN.EQ.1)B1=A2
         IF(NORUN.EQ.2)D2=A1
         IF(NORUN.EQ.2)B2=A2
      END IF
C...
C...  PLOT THE CONCENTRATION PROFILES AT THE END OF THE SECOND RUN
      IF((IP.EQ.101).AND.(NORUN.EQ.2))THEN
      CALL SPLOTS(NORUN,N11,RP,CP)
      WRITE(NO,11)D1,D2,B1,B2
11    FORMAT(' C(R,T) VS R',
     1       '   1 - MASS TRANSFER AND REACTION LIMITED',
     2       '   2 - DIFFUSION LIMITED',/,
     3       ' DAMKOHLER NUMBERS = ',2E10.3,
     4       '   BIOT NUMBERS = '   ,2E10.3)
      END IF
      RETURN
      END
DIFFUSION AND REACTION IN AN IMMOBILIZED ENZYME CATALYST
0.        20.0      0.2
   11 1000    1    1  ABS 0.0001
DIFFUSION AND REACTION IN AN IMMOBILIZED ENZYME CATALYST
0.        20.0      0.2
   11 1000    1    1  ABS 0.0001
END OF RUNS
*APP SEP34
      SUBROUTINE INITAL
C...
C...  RELATIVE EFFECTS OF SURFACE MASS TRANSFER RESISTANCE, INTERNAL
C...  DIFFUSION AND INTERNAL REACTION ON THE PERFORMANCE OF A SPHERICAL
C...  CATALYST PARTICLE
C...
C...  CONSIDER THE FOLLOWING MODEL FOR DIFFUSION AND REACTION IN A
C...  SPHERICAL CATALYST PARTICLE CONTAINING AN IMMOBILIZED ENZYME:
C...
C...  C  = D*(C   + (2/R)*C ) - K*C
C...   T       RR          R
C...
C...  C(R,0) = C0, C (0,T) = 0, -D*C (R0,T) = KY*(C(R0,T) - CS)
C...                R               R
C...
C...  WHERE
C...
C...  C        CONCENTRATION OF THE SUBSTRATE (REACTANT)
C...
C...  R        RADIAL POSITION WITHIN THE PARTICLE
C...
C...  T        TIME
C...
C...  D        DIFFUSIVITY WITHIN THE PARTICLE
C...
C...  K        FIRST-ORDER REACTION RATE CONSTANT
C...
C...  R0       RADIUS OF THE PARTICLE
C...
C...  KY       MASS TRANSFER COEFFICIENT
C...
C...  CS       SUBSTRATE CONCENTRATION IN THE LIQUID SURROUNDING THE
C...           PARTICLE
C...
C...  C0       INITIAL SUBSTRATE CONCENTRATION
C...
C...  (A)  EXPRESS THE PRECEDING SET OF EQUATIONS IN TERMS OF THE
C...       DIMENSIONLESS VARIABLES
C...
C...       CD = C/CS, TD = T*D/R0**2, RD = R/R0
C...
C...  (B)  COMPUTE A SOLUTION TO THE DIMENSIONLESS EQUATIONS FOR
C...       C0 = 0, CS = 0.001, K = D = 1, R0 = 0.1, KY = 0.1.  PLOT
C...       CD(RD,TD) VS RD FOR A SERIES OF DIMENSIONLESS TIMES, TD.
C...       USE SUBROUTINE DSS004 FOR FIRST-ORDER DERIVATIVES AND DSS042
C...       FOR SECOND-ORDER DERIVATIVES IN RD.
C...
C...  THE SYSTEM WHEN WRITTEN IN TERMS OF THE DIMENSIONLESS VARIABLES
C...  IS
C...
C...  CD  = (CD     + (2/RD)*CD  ) - K*(R0**2)/D*CD
C...    TD     RDRD            RD
C...
C...  CD(RD,0) = C0/CS, CD  (0,TD) = 0
C...                      RD
C...
C...  -CD  (1,T) = KY*R0/D*(CD(1,T) - 1)
C...     RD
C...
C...  NOTE THE IMPORTANT DIMENSIONLESS GROUPS K*(R0**2)/D AND KY*R0/D,
C...  WHICH WILL BE DESIGNATED A1 AND A2, RESPECTIVELY, IN THE FOLLOW-
C...  ING CODING.  ALSO, THE DIMENSIONLESS DESIGNATION, D, FOR THE
C...  VARIABLES WILL BE DROPPED TO SIMPLIFY THE CODING, E.G., CD WILL
C...  BE REPLACED WITH C, WITH THE UNDERSTANDING THAT THIS IS A DI-
C...  MENSIONLESS CONCENTRATION.  THE SAME APPLIES TO TD (NOW T) AND
C...  RD (NOW R).  AN ADVANTAGE OF USING DIMENSIONLESS VARIABLES IS
C...  THE RANGE OVER WHICH THEY VARY, E.G., 0 LE R LE 1 REGARDLESS OF
C...  THE VALUE OF R0.
C...
C...  FINALLY, NOTE ONE OTHER IMPORTANT CHARACTERISTIC OF THIS SYSTEM:
C...  THE CONCENTRATION CS USED TO DEFINE THE DIMENSIONLESS CONCENTRA-
C...  TION, DOES NOT APPEAR IN THE FINAL DIMENSIONLESS EQUATIONS.  THIS
C...  IS BECAUSE THE PROBLEM IS ENTIRELY LINEAR.  IF THE PROBLEM HAD
C...  BEEN NONLINEAR, CS WOULD APPEAR SOMEWHERE IN THE EQUATIONS, I.E.,
C...  A FUNDAMENTAL PROPERTY OF NONLINEAR SYSTEMS IS THE DEPENDENCE ON
C...  THE ABSOLUTE VALUES OF THE STATE VARIABLES.  TO GIVE A SPECIFIC
C...  EXAMPLE, CONSIDER THE FIRST EQUATION IF THE REACTION HAD BEEN
C...  SECOND ORDER, SO THAT THE REACTION TERM WAS -K*(C**2).  NOW IF
C...  THE SAME DIMENSIONLESS VARIABLES ARE USED, CS WILL APPEAR IN THE
C...  DIMENSIONLESS PDE.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  SET THE MODEL PARAMETERS
      C0=0.
      CS=0.001
      R0=0.1
C...
C...  SLOW MASS TRANSFER, SLOW REACTION, FAST DIFFUSION
      IF(NORUN.EQ.1)THEN
      KY=0.1
      K =1.0
      D =1.0
C...
C...  FAST MASS TRANSFER, FAST REACTION, SLOW DIFFUSION
      ELSE IF(NORUN.EQ.2)THEN
      KY=5.0
      K =50.0
      D =0.1
      END IF
C...
C...  DIMENSIONLESS GROUPS
      A1=K*(R0**2)/D
      A2=KY*R0/D
C...
C...  INITIAL CONDITION
      N11=11
      DO 1 I=1,N11
      C(I)=0.
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  FIRST-ORDER SPATIAL DERIVATIVE
      CALL DSS004(0.,1.,N11,C,CR)
C...
C...  BOUNDARY CONDITIONS
      CR(1)=0.
      CR(N11)=-A2*(C(N11)-1.0)
C...
C...  SECOND-ORDER SPATIAL DERIVATIVE
      NL=2
      NU=2
      CALL DSS042(0.,1.,N11,C,CR,CRR,NL,NU)
C...
C...  PDE, R NE 0
      DO 1 I=2,N11
      R=FLOAT(I-1)/10.
      CT(I)=(CRR(I)+(2.0/R)*CR(I))-A1*C(I)
1     CONTINUE
C...
C...  PDE, R = 0
      CT(1)=3.0*CRR(1)-A1*C(1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(11)
     2      /F/    CT(11)
     3      /S/    CR(11),   CRR(11)
     4      /C/        A1,        A2,       N11,        IP
      REAL              K,        KY
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION RP(11), CP(2,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T','   (0.0,T)','   (0.2,T)','   (0.4,T)',
     1                 '   (0.6,T)','   (0.8,T)','   (1.0,T)')
      END IF
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,2)T,(  C(I),I=1,N11,2),
     1                ( CR(I),I=1,N11,2),
     2                (CRR(I),I=1,N11,2),
     3                ( CT(I),I=1,N11,2)
2     FORMAT(F10.2,/,'    C(R,T)',6F10.4,/,
     1               '   CR(R,T)',6F10.4,/,
     2               '  CRR(R,T)',6F10.4,/,
     3               '   CT(R,T)',6F10.4,/)
      END IF
C...
C...  STORE THE CONCENTRATION PROFILE AT THE END OF THE RUN FOR
C...  PLOTTING
      IF(IP.EQ.101)THEN
         DO 3 I=1,N11
         CP(NORUN,I)=C(I)
         RP(I)=FLOAT(I-1)/10.0
3        CONTINUE
C...
C...     STORE THE DAMKOHLER AND BIOT NUMBERS FOR SUBSEQUENT PRINTING
         IF(NORUN.EQ.1)D1=A1
         IF(NORUN.EQ.1)B1=A2
         IF(NORUN.EQ.2)D2=A1
         IF(NORUN.EQ.2)B2=A2
      END IF
C...
C...  PLOT THE CONCENTRATION PROFILES AT THE END OF THE SECOND RUN
      IF((IP.EQ.101).AND.(NORUN.EQ.2))THEN
      CALL SPLOTS(NORUN,N11,RP,CP)
      WRITE(NO,11)D1,D2,B1,B2
11    FORMAT(' C(R,T) VS R',
     1       '   1 - MASS TRANSFER AND REACTION LIMITED',
     2       '   2 - DIFFUSION LIMITED',/,
     3       ' DAMKOHLER NUMBERS = ',2E10.3,
     4       '   BIOT NUMBERS = '   ,2E10.3)
      END IF
      RETURN
      END
MASS TRANSFER, DIFFUSION AND REACTION IN A CATALYST PARTICLE
0.        20.0      0.2
   11 1000    1    1  ABS 0.0001
MASS TRANSFER, DIFFUSION AND REACTION IN A CATALYST PARTICLE
0.        20.0      0.2
   11 1000    1    1  ABS 0.0001
END OF RUNS
*APP SEP35
      SUBROUTINE INITAL
C...
C...  DYNAMIC SIMULATION OF A PACKED COLUMN ADSORBER
C...
C...  Develop a dynamic simulation for a packed colum adsorber using
C...  the following variables:
C...
C...  y(z,t)      gas phase mole fraction of component to be adsorbed
C...              (gm mol adsorbate/mol gas)
C...
C...  q(z,t)      solid phase concentration of component to be adsorbed
C...              (gm mol adsorbate/gm solid)
C...
C...  g           molar flow rate of gas through the adsorber (gm mol
C...              gas/sec)
C...
C...  eps         fraction of solid adsorbent in the column (cm**3
C...              solid/cm**3 column)
C...
C...  rhog        molar density of the gas (gm mol gas/cm**3)
C...
C...  rhos        density of the solid adsorbent (gm solid/cm**3 solid)
C...
C...  A           cross sectional area of the column (cm**2 column)
C...
C...  z           axial position along the adsorber (cm column)
C...
C...  t           time (sec)
C...
C...  zl          length of the adsorber (cm column)
C...
C...  The rate of mass transfer from the gas to the solid phase is given
C...  by
C...
C...     r = c1*y*(qe - q) - c2*q  (gm mol adsorbate/gm solid-sec)
C...
C...  where c1 and c2 are given rate constants for the solid adsorption
C...  and qe is the solid concentration in equilibrium with the gas of
C...  composition y given by the nonlinear adsorption isotherm:
C...
C...     qe = c3*y/(1 + c4*y) (gm mol adsorbate/gm solid)
C...
C...  c3 and c4 are given adsorption isotherm constants.
C...
C...  The model should consist of the partial differential equations
C...  (PDEs) for y(z,t) and q(z,t) with the appropriate initial and
C...  boundary conditions.  Initially, the column starts out with no
C...  gas to be adsorbed in either the gas or solid phases.
C...
C...  A gas-phase balance on a section of the column of length dz gives
C...
C...     (1 - eps)*A*dz*rhog*y  = g*y  - g*y     - A*dz*eps*rhos*r
C...                          t      z      z+dz
C...
C...  Division by the coefficient of the time derivative, followed by
C...  dz ---+ 0 gives
C...
C...     y  = -v*y  - (eps*rhos/((1 - eps)*rhog))*r                (1)
C...      t       z
C...
C...     v = g/((1 - eps)*A*rhog) (A = column cross sectional area)
C...
C...  Similarly, a balance on the solid phase gives
C...
C...     A*dz*eps*rhos*q  = A*dz*eps*rhos*r
C...                    t
C...
C...  or, after dividing by the coefficient of the time derivative
C...
C...     q  = r                                                    (2)
C...      t
C...
C...  The initial and boundary conditions for equations (1) and (2) are
C...
C...     y(z,0) = y0, y(0,t) = yin(t), q(z,0) = q0           (3)(4)(5)
C...
C...  Equations (1) to (5) are programmed in the following coding:
C...
C...  DSS/2 common area
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     Y(21),     Q(21)
     2      /F/    YT(21),    QT(21)
     3      /S/    YZ(21)
     4      /C/         V,        C1,        C2,        C3,        C4,
     5                 C5,       YIN,    QE(21),     R(21),        ZL,
     6                  N,        IP
C...
C...  SET THE MODEL PARAMETERS
      A=100.
      ZL=100.
      RHOG=0.1
      RHOS=1.0
      EPS=0.6
      C1=100.
      C2=10.
      C3=100.
      C4=1000.
      G=30.
      V=G/((1.0-EPS)*A*RHOG)
      C5=EPS*RHOS/((1.0-EPS)*RHOG)
      YIN=0.01
C...
C...  INITIAL CONDITIONS (3) AND (5)
      N=21
      Y0=0.
      Q0=0.
      DO 1 I=1,N
      Y(I)=Y0
      Q(I)=Q0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     Y(21),     Q(21)
     2      /F/    YT(21),    QT(21)
     3      /S/    YZ(21)
     4      /C/         V,        C1,        C2,        C3,        C4,
     5                 C5,       YIN,    QE(21),     R(21),        ZL,
     6                  N,        IP
C...
C...  LIMIT THE CONCENTRATIONS TO NON-NEGATIVE VALUES
      CALL LIMITS
C...
C...  BOUNDARY CONDITION (4)
      Y(1)=YIN
C...
C...  DERIVATIVE Y
C...              Z
      CALL DSS020(0.,ZL,N,Y,YZ,1.0)
C...
C...  EQUATIONS (1) AND (2)
      DO 1 I=1,N
C...
C...     EQUILIBRIUM SOLID CONCENTRATION
         QE(I)=C3*Y(I)/(1.0+C4*Y(I))
C...
C...     RATE OF ADSORPTION
         R(I)=C1*Y(I)*(QE(I)-Q(I))-C2*Q(I)
C...
C...     YT AT Z = 0
            IF(I.EQ.1)THEN
               YT(1)=0.
C...
C...     YT AT Z NE 0
            ELSE IF (I.NE.1)THEN
               YT(I)=-V*YZ(I)-C5*R(I)
            END IF
C...
C...     QT
            QT(I)=R(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE LIMITS
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     Y(21),     Q(21)
     2      /F/    YT(21),    QT(21)
     3      /S/    YZ(21)
     4      /C/         V,        C1,        C2,        C3,        C4,
     5                 C5,       YIN,    QE(21),     R(21),        ZL,
     6                  N,        IP
C...
C...  LIMIT THE CONCENTRATIONS TO NON-NEGATIVE VALUES
      DO 1 I=1,N
      IF( Y(I).LT.0.) Y(I)=0.
      IF( Q(I).LT.0.) Q(I)=0.
      IF(QE(I).LT.0.)QE(I)=0.
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     Y(21),     Q(21)
     2      /F/    YT(21),    QT(21)
     3      /S/    YZ(21)
     4      /C/         V,        C1,        C2,        C3,        C4,
     5                 C5,       YIN,    QE(21),     R(21),        ZL,
     6                  N,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL TP(101), YP(2,101)
C...
C...  PRINT THE SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,1)T,( Y(I),I=1,N,1),( Q(I),I=1,N,1),(QE(I),I=1,N,1),
     1                ( R(I),I=1,N,1),(YT(I),I=1,N,1),(QT(I),I=1,N,1)
1     FORMAT(1H ,////,' T = ',F5.1,//,
     1 '   Y',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//,
     1 '   Q',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//,
     1 '  QE',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//,
     1 '   R',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//,
     1 '  YT',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//,
     1 '  QT',5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,5E10.3,/,4X,E10.3,//)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      YP(1,IP)=Y(1)
      YP(2,IP)=Y(N)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(2,IP,TP,YP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' 1 - Y(0,T)   2 - Y(ZL,T) VS T')
      END IF
      RETURN
      END
COLUMN ADSORBER
0.        400.      4.0
   42 9999    1    1  ABS 0.00001
END OF RUNS
