*DECK REACT22
      SUBROUTINE INITAL
C...
C...  RECYCLE IN DYNAMIC SIMULATIONS
C...
C...  THE FOLLOWING SERIES OF THREE CONTINUOUS STIRRED TANK REACTORS
C...  (CSTR*S) IS SIMULATED DYNAMICALLY BY SOLUTION OF THE UNSTEADY
C...  STATE MATERIAL BALANCE EQUATIONS.  NOTE THAT A RECYCLE FROM THE
C...  THIRD REACTOR BACK TO THE FEED TO THE FIRST REACTOR IS INCLUDED
C
C     ..............................................................
C     .F*C3(T)                                                     .
C     .         .                    .                    .        .
C     .         .                    .                    .        .
C     .    .    .    .          .    .    .          .    .    .   .
C     .    ...........          ...........          ...........   .
C     ....+.    .    .          .    .    .          .    .    .   .
C   C0(T)  .    .    .   C1(T)  .    .    .   C2(T)  .    .    . C3(T)
C  .......+.    .    ..........+.    .    ..........+.    .    ........+
C          .    .    .          .    .    .          .    .    .
C          .   ...   .          .   ...   .          .   ...   .
C          .   ...   .          .   ...   .          .   ...   .
C          ...........          ...........          ...........
C
C...  THE DIFFERENTIAL EQUATIONS TO BE INTEGRATED ARE
C...
C...     DC1/DT = F*C3 + (1 - F)*C0 - C1 - R*C1**2, C1(0) = 0        (1)
C...
C...     DC2/DT = C1 - C2 - R*C2**2, C2(0) = 0                       (2)
C...
C...     DC3/DT = C2 - C3 - R*C3**2, C3(0) = 0                       (3)
C...
C...  WHERE
C...
C...     C1(T)  CONCENTRATIONS OF REACTANT FROM THE FIRST, SECOND AND
C...     C2(T)  THIRD REACTORS RESPECTIVELY
C...     C3(T)
C...
C...     T      TIME
C...
C...     R      REACTION RATE CONSTANT
C...
C...     F      FRACTION OF THE FEED FROM THE RECYCLE
C...
C...  NOTE THAT WHEN EQUATIONS (1) TO (3) ARE INTEGRATED TO STEADY STATE
C...  I.E., DC1/DT = DC2/DT = DC3/DT = 0, THE NUMERICAL SOLUTION IS FOR
C...  THE FOLLOWING SYSTEM OF THREE NONLINEAR ALGEBRAIC EQUATIONS
C...
C...     0 = F*C3 + (1 - F)*C0 - C1 - R*C1**2
C...
C...     0 = C1 - C2 - R*C2**2
C...
C...     0 = C2 - C3 - R*C3**2
C...
C...  IN THIS SENSE, THE STEADY STATE SIMULATION IS A SPECIAL CASE OF
C...  THE DYNAMIC SIMULATION, YET THE LATTER IS EASIER TO COMPUTE.
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/  C(3)
     2      /F/DCT(3)
     3      /C/     F,    C0,     R
C...
C...  SET THE INITIAL CONDITIONS
      DO 1 I=1,3
      C(I)=0.
1     CONTINUE
C...
C...  SET THE RECYCLE FRACTION, ENTERING CONCENTRATION, REACTION RATE
C...  CONSTANT
      F=0.5
      C0=1.0
      IF(NORUN.EQ.1)R=0.
      IF(NORUN.EQ.2)R=1.0
C...
C...  INITIALIZE THE DERIVATIVE VECTOR IN COMMON/F/ FOR PRINTING IN
C...  SUBROUTINE PRINT
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/  C(3)
     2      /F/DCT(3)
     3      /C/     F,    C0,     R
C...
C...  FIRST STIRRED TANK
      DCT(1) = F*C(3) + (1.-F)*C0 - C(1) -R*C(1)**2
C...
C...  SECOND AND THIRD STIRRED TANKS
      DCT(2) = C(1) - C(2) - R*C(2)**2
      DCT(3) = C(2) - C(3) - R*C(3)**2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/  C(3)
     2      /F/DCT(3)
     3      /C/     F,    C0,     R
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.0.01)WRITE(NO,2)
2     FORMAT(9X,1HT,7X,5HC1(T),7X,5HC2(T),7X,5HC3(T),
     1              6X,6HDC1/DT,6X,6HDC2/DT,6X,6HDC3/DT)
C...
C...  PRINT THE NUMERICAL SOLUTION, INCLUDING THE TEMPORAL DERIVATIVES
C...  TO INDICATE THE APPROACH TO THE STEADY STATE SOLUTION
      WRITE(NO,1)T,(C(I),I=1,3),(DCT(I),I=1,3)
1     FORMAT(F10.2,3F12.4,3F12.6)
      RETURN
      END
