*APP REACT01
      SUBROUTINE INITAL
C...
C...  NONISOTHERMAL CATALYTIC TUBULAR REACTOR
C...
C...  DEVELOP A MATHEMATICAL MODEL AND SIMULATION TO STUDY THE RESPONSE
C...  OF AN ADIABATIC, GAS-PHASE, PACKED TUBULAR REACTOR.  THE REACTOR
C...  IS A CYLINDRICAL VESSEL, 1 M ID BY 6 M LONG, PACKED WITH A METAL
C...  CATALYST THAT OCCUPIES 5 PERCENT OF THE TOTAL VOLUME, PROVIDES
C...  150 M**2 OF AREA PER M**3 OF TOTAL VOLUME, WEIGHTS 6000 KG/M**3
C...  AND HAS A HEAT CAPACITY OF 400 J/(KG-C).  THE HEAT TRANSFER CO-
C...  EFFICIENT BETWEEN THE CATALYST AND THE GAS IS 60 J/(SEC-M**3-C).
C...  THE PRESSURE AT THE INLET OF THE REACTOR IS 7.0E+05 PA AND THE
C...  PRESSURE DROP OVER THE LENGTH OF THE REACTOR IS 3.0E+04 PA AT
C...  THE DESIGN SUPERFICIAL VELOCITY OF 0.3 M/SEC AT INLET CONDITIONS.
C...
C...  THE REACTION IS FIRST ORDER
C...
C...         K
C...     A -----+ B
C...
C...  THE HEAT OF REACTION IS -70000 J/MOLE AND THE REACTION RATE CON-
C...  STANT IS GIVEN BY K = 400*EXP(-7500/TC) (1/SEC) (TC IN K).  ASSUME
C...  PERFECT GASES WITH  MOLECULAR WEIGHTS OF 40 AND HEAT CAPACITIES OF
C...  OF 600 J/(KG-C).
C...
C...  THE MODEL FOR THE NONISOTHERMAL CATALYTIC TUBULAR REACTOR CODED
C...  IN SUBROUTINES INITAL, DERV AND PRINT INCLUDES
C...
C...  (1)  ENERGY BALANCE FOR THE CATALYST
C...       -------------------------------
C...
C...       RATE OF ACCUMULATION OF ENERGY WITHIN THE CATALYST =
C...
C...       HEAT TRANSFER RATE TO THE CATALYST
C...
C...       (S*DZ*(1-EPS)*RHOC*CPC*TC)  = H*AV*S*DZ*(TF - TC)
C...                                 T
C...
C...       DIVISION BY S*DZ*(1-EPS)*RHOC*CPC GIVES
C...
C...       TC  = H*AV/((1-EPS)*RHOC*CPC)*(TF - TC)                  (1)
C...         T
C...
C...       CHECK ON UNITS
C...
C...       (S*DZ*(1-EPS)*RHOC*CPC*TC)
C...                                 T
C...
C...       (M**2)*(M)*(KG/M**3)*(J/(KG-C))*(C)*(1/SEC) = J/SEC
C...
C...       H*AV*S*DZ*(TF - TC)
C...
C...       (J/(SEC-M**2-C))*(M**2/M**3)*(M**2)*(M)*(C) = J/SEC
C...
C...  (2)  ENERGY BALANCE FOR THE FLUID
C...       ----------------------------
C...
C...       RATE OF ACCUMULATION OF ENERGY WITHIN THE FLUID =
C...
C...       NET FLOW RATE OF ENERGY OF THE FLUID +
C...
C...       HEAT TRANSFER RATE TO THE FLUID +
C...
C...       RATE OF HEAT PRODUCTION BY THE REACTION
C...
C...       (S*DZ*EPS*RHOF*CVF*TF)  =
C...                             T
C...
C...       (V*S*RHOF*CPF*TF)     - (V*S*RHOF*CPF*TF)
C...                        AT Z                    AT Z+DZ
C...
C...       - H*AV*S*DZ*(TF - TC)
C...
C...       - S*DZ*EPS*DH*K*CA
C...
C...       DIVISION BY (S*DZ*EPS*CVF) WITH DZ ----+ 0 GIVES
C...
C...       (RHOF*TF)  = - (CPF/(EPS*CVF))*(RHOF*V*TF)
C...                T                                Z
C...                                                                (2)
C...                    - H*AV/(EPS*CVF)*(TF - TC) - (DH*K*CA)/CVF
C...
C...       CHECK ON UNITS
C...
C...       (S*DZ*EPS*RHOF*CVF*TF)
C...                             T
C...
C...       (M**2)*(M)*(KG/M**3)*(J/(KG-C))*(C)*(1/SEC) = J/SEC
C...
C...       (V*S*RHOF*CPF*TF)
C...
C...       (M/SEC)*(M**2)*(KG/M**3)*(J/(KG-C))*(C) = J/SEC
C...
C...       H*AV*S*DZ*(TF - TC)
C...
C...       (J/(SEC-M**2-C))*(M**2/M**3)*(M**2)*(M)*(C) = J/SEC
C...
C...       S*DZ*EPS*DH*K*CA
C...
C...       (M**2)*(M)*(J/MOLE)*(1/SEC)*(MOLES/M**3) = J/SEC
C...
C...  (3)  TOTAL MASS BALANCE FOR THE FLUID
C...       --------------------------------
C...
C...       RATE OF ACCUMULATION OF MASS WITHIN THE FLUID =
C...
C...       NET FLOW RATE OF MASS WITHIN THE FLUID
C...
C...       (S*DZ*EPS*RHOF)  = (V*S*RHOF)     - (V*S*RHOF)
C...                      T             AT Z             AT Z+DZ
C...
C...       DIVISION BY (S*DZ*EPS) WITH DZ ----+ 0 GIVES
C...
C...       RHOF  = -(1/EPS)*(V*RHOF)                                (3)
C...           T                   Z
C...
C...       CHECK ON UNITS
C...
C...       (S*DZ*EPS*RHOF)
C...                      T
C...
C...       (M**2)*(M)*(KG/MM**3)*(1/SEC) = KG/SEC
C...
C...       V*S*RHOF
C...
C...       (M/SEC)*(M**2)*(KG/M**3) = KG/SEC
C...
C...  (4)  COMPONENT BALANCE FOR THE FLUID
C...       -------------------------------
C...
C...       RATE OF ACCUMULATION OF A WITHIN THE FLUID =
C...
C...       NET FLOW OF A WITHIN THE FLUID -
C...
C...       RATE OF CONSUMPTION OF A WITHIN THE FLUID BY REACTION
C...
C...       (S*DZ*EPS*CA)  =
C...                    T
C...
C...       (V*S*CA)     - (V*S*CA)
C...               AT Z           AT Z+DZ
C...
C...       - S*DZ*EPS*K*CA
C...
C...       DIVISION BY (S*DZ*EPS) WITH DZ ----+ 0 GIVES
C...
C...       CA  = -(1/EPS)*(V*CA)  - K*CA                            (4)
C...         T                  Z
C...
C...       CHECK ON UNITS
C...
C...       (S*DZ*EPS*CA)
C...                    T
C...
C...       (M**2)*(M)*(MOLE/M**3)*(1/SEC) = MOLE/SEC
C...
C...       (V*S*CA)
C...
C...       (M/SEC)*(M**2)*(MOLE/M**3) = MOLE/SEC
C...
C...       (S*DZ*EPS*K*CA)
C...
C...       (M**2)*(M)*(1/SEC)*(MOLE/M**3) = MOLE/SEC
C...
C...  (5)  MOMENTUM BALANCE FOR THE FLUID
C...       ------------------------------
C...
C...       RATE OF ACCUMULATION OF MOMENTUM WITHIN THE FLUID =
C...       (SINCE THIS IS NEWTON*S SECOND LAW, THIS TERM
C...        COULD BE CALLED THE INERTIAL FORCE OR THE TIME
C...        RATE OF CHANGE OF MOMENTUM.  STILL ANOTHER WAY
C...        TO EXPRESS THIS TERM IS TO SAY THAT IT IS THE
C...        M*A IN F = M*A, IN WHICH CASE, THE RHS TERMS OF
C...        THE EQUATION ARE THE NET FORCES ACTING ON THE
C...        FLUID)
C...
C...       NET FLOW RATE OF MOMENTUM WITHIN THE FLUID +
C...
C...       NET PRESSURE FORCE ON THE FLUID
C...
C...       (S*DZ*RHOF*V)
C...                    T
C...
C...       (S*V*RHOF*(V/EPS))     - (S*V*RHOF*(V/EPS))
C...                         AT Z                     AT Z+DZ
C...
C...       - (S*DZ*(DP/DZ)*GC)
C...
C...
C...       DIVISION BY (S*DZ) WITH DZ ----+ 0 GIVES
C...
C...       (RHOF*V)  =
C...               T                                                (5)
C...
C...       - (1/EPS)*(RHOF*(V**2))  - (DP/DZ)*GC
C...                              Z
C...
C...       CHECK ON UNITS
C...
C...       (S*DZ*RHOF*V)
C...                    T
C...
C...       (M**2)*(M)*(KG/M**3)*(M/SEC)*(1/SEC) = KG-M/SEC**2
C...
C...       (S*V*RHOF*(V/EPS))
C...
C...       (M**2)*(M/SEC)*(KG/M**3)*(M/SEC) = KG-M/SEC**2
C...
C...       (S*DZ*(DP/DZ)*GC)
C...
C...       (M**2)*(M)*(N/M**2)*(1/M)*(KG-M/N-SEC**2) = KG-M/SEC**2
C...
C...       (NOTE - 1 N/M**2 = 1 NEWTON/M**2 = 1 PA = 1 PASCAL)
C...
C...  (6)  EQUATION OF STATE FOR THE FLUID
C...       -------------------------------
C...
C...       RHOF = (P*MW)/(R*TF)                                     (6)
C...
C...  (7)  PRESSURE DROP EQUATION
C...       ----------------------
C...
C...       DP/DZ = KL*V + KT*(V**2)                                 (7)
C...
C...       (NOTE - KL AND KT ARE COEFFICIENTS FOR LAMINAR AND
C...               TURBULENT FLOW, RESPECTIVELY)
C...
C...
C...       IF WE ASSUME TURBULENT FLOW, KL = 0 AND
C...
C...       KT = (DP/DZ)/V**2 = (-30000 PA/6 M)*(1/0.3 M/SEC)**2
C...
C...          = -55555.6 (PA-SEC**2)/(M**3)
C...
C...  THE CONSTANTS IN THE EQUATIONS CAN NOW BE EVALUATED FROM THE
C...  GIVEN MODEL PARAMETERS.
C...
C...  EQUATION (1)
C...
C...     H*AV/((1-EPS)*RHOC*CPC) = 60*150/((1-0.95)*6000*400) = 0.075
C...
C...  EQUATION (2)
C...
C...     CPF/(EPS*CVF) = 1.4/0.95 = 1.47
C...
C...     H*AV/(EPS*CVF) = 60*150/(0.95*600/1.4) = 22.105
C...
C...     K*DH/CVF = 400*70000/(600/1.4) = 65333.33
C...
C...  EQUATION (3)
C...
C...     1/EPS = 1/0.95 = 1.053
C...
C...  EQUATION (4)
C...
C...     1/EPS = 1/0.95 = 1.053
C...
C...     K = 400
C...
C...  EQUATION (5)
C...
C...     1/EPS = 1/0.95 = 1.053
C...
C...  EQUATION (6)
C...
C...     R/MW = 8212/40 = 205.3
C...
C...  EQUATION (7)
C...
C...     KL = 0, KT = 55555.6
C...
C...  THE AUXILIARY CONDITIONS FOR EQUATIONS (1) TO (5) ARE
C...
C...     INITIAL CONDITIONS
C...
C...        TC(Z,0) = 573 K
C...
C...        TF(Z,0) = 573 K
C...
C...        RHOF(Z,0) = 5.95 KG/M**3
C...
C...        CA(Z,0) = 0
C...
C...        V(Z,0) = 0
C...
C...     BOUNDARY CONDITIONS
C...
C...        TF(0,T) = 573 K
C...
C...        RHOF(0,T) = 5.95 KG/M**3
C...
C...        V(0,T) = 0.3 M/SEC
C...
C...        CA(0,T) = 20 MOLE/M**3
C...
C...  THE FOLLOWING CODING IMPLEMENTS THE PRECEDING MATHEMATICAL MODEL
C...  OVER A 13-POINT NUMERICAL METHOD OF LINES GRID
C...
C...  TEMPORAL COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(13),     R(13),    CA(13),   RTF(13),    RV(13)
     2      /F/ DTCDT(13),  DRDT(13), DCADT(13),DRTFDT(13), DRVDT(13)
C...
C...  SPATIAL COMMON AREA
      COMMON/S/    P1(13),    P2(13),    P3(13),    P4(13),
     1          DP1DZ(13), DP2DZ(13), DP3DZ(13), DP4DZ(13)
C...
C...  VARIABLE COMMON AREA
      COMMON/V/    TF(13),     V(13)
C...
C...  CONSTANT COMMON AREA
      COMMON/C/       TF0,       TC0,        R0,        V0,       CA0,
     1                TFE,                   RE,        VE,       CAE,
     2                  N,        ZL,        DZ
C...
C...  INPUT/OUTPUT DEVICE NUMBERS FOR PRINTING IN DERV
      COMMON/IO/       NI,        NO
C...
C...  GRID PARAMETERS
      N=13
      ZL=6.
      DZ=ZL/FLOAT(N-1)
C...
C...  INITIAL VALUES
      TF0=573.
      TC0=573.
       R0=5.95
       V0=0.3
      CA0=0.
C...
C...  BOUNDARY (ENTERING) VALUES
      TFE=573.
       RE=5.95
       VE=0.3
      CAE=20.
C...
C...  INITIAL CONDITONS
      DO 1 I=1,N
       TF(I)=TF0
       TC(I)=TC0
        R(I)=R0
        V(I)=V0
       CA(I)=CA0
      RTF(I)=R0*TF0
       RV(I)=R0*V0
1     CONTINUE
C...
C...  THE FOLLOWING CALL TO PRINT CAN BE USED TO CHECK THE
C...  INITIAL CONDITIONS SET IN INITAL
C...  CALL PRINT(NI,NO)
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
C...
C...  TEMPORAL COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(13),     R(13),    CA(13),   RTF(13),    RV(13)
     2      /F/ DTCDT(13),  DRDT(13), DCADT(13),DRTFDT(13), DRVDT(13)
C...
C...  SPATIAL COMMON AREA
      COMMON/S/    P1(13),    P2(13),    P3(13),    P4(13),
     1          DP1DZ(13), DP2DZ(13), DP3DZ(13), DP4DZ(13)
C...
C...  VARIABLE COMMON AREA
      COMMON/V/    TF(13),     V(13)
C...
C...  CONSTANT COMMON AREA
      COMMON/C/       TF0,       TC0,        R0,        V0,       CA0,
     1                TFE,                   RE,        VE,       CAE,
     2                  N,        ZL,        DZ
C...
C...  INPUT/OUTPUT DEVICE NUMBERS FOR PRINTING IN DERV
      COMMON/IO/       NI,        NO
C...
C...  MODEL CONSTRAINTS
      DO 1 I=1,N
      IF(TF(I).LT.TFE)TF(I)=TFE
      IF(TC(I).LT.TFE)TC(I)=TFE
      IF( R(I).LT. 0.) R(I)=0.
      IF( V(I).LT. 0.) V(I)=0.
      IF(CA(I).LT. 0.)CA(I)=0.
1     CONTINUE
C...
C...  MODEL ALGEBRA
      DO 2 I=1,N
      TF(I)=RTF(I)/R(I)
       V(I)= RV(I)/R(I)
      P1(I)=RTF(I)*V(I)
      P2(I)= RV(I)
      P3(I)= CA(I)*V(I)
      P4(I)= RV(I)*V(I)
2     CONTINUE
C...
C...  MODEL BOUNDARY CONDITIONS
      TF(1)=TFE
       R(1)=RE
       V(1)=VE
      CA(1)=CAE
      P1(1)=R(1)*V(1)*TF(1)
      P2(1)=R(1)*V(1)
      P3(1)=V(1)*CA(1)
      P4(1)=R(1)*V(1)**2
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS012(0.,ZL,N,P1,DP1DZ,1.)
      CALL DSS012(0.,ZL,N,P2,DP2DZ,1.)
      CALL DSS012(0.,ZL,N,P3,DP3DZ,1.)
      CALL DSS012(0.,ZL,N,P4,DP4DZ,1.)
C...
C...  MODEL TIME DERIVATIVE AT Z = 0
       DTCDT(1)=0.075*(TF(1)-TC(1))
      DRTFDT(1)=0.
        DRDT(1)=0.
       DCADT(1)=0.
       DRVDT(1)=0.
C...
C...  MODEL TIME DERIVATIVES FOR Z GT 0
      DO 3 I=2,N
       DTCDT(I)=0.075*(TF(I)-TC(I))
             RA=CA(I)*EXP(-7500./TF(I))
C...
C...  THE REACTION RATE IS VARIED BY THE FOLLOWING STATEMENT
             RA=30.*RA
      DRTFDT(I)=-1.474*DP1DZ(I)-22.105*(TF(I)-TC(I))+65333.3*RA
        DRDT(I)=-1.053*DP2DZ(I)
       DCADT(I)=-1.053*DP3DZ(I)-400.*RA
       DRVDT(I)=-1.053*DP4DZ(I)
3     CONTINUE
C...
C...  THE FOLLOWING CALL TO PRINT CAN BE USED TO CHECK THE
C...  CALCULATIONS IN DERV AS THE INTEGRATION PROCEEDS
C...  CALL PRINT(NI,NO)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
C...
C...  TEMPORAL COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(13),     R(13),    CA(13),   RTF(13),    RV(13)
     2      /F/ DTCDT(13),  DRDT(13), DCADT(13),DRTFDT(13), DRVDT(13)
C...
C...  SPATIAL COMMON AREA
      COMMON/S/    P1(13),    P2(13),    P3(13),    P4(13),
     1          DP1DZ(13), DP2DZ(13), DP3DZ(13), DP4DZ(13)
C...
C...  VARIABLE COMMON AREA
      COMMON/V/    TF(13),     V(13)
C...
C...  CONSTANT COMMON AREA
      COMMON/C/       TF0,       TC0,        R0,        V0,       CA0,
     1                TFE,                   RE,        VE,       CAE,
     2                  N,        ZL,        DZ
C...
C...  DIMENSION THE ARRAYS FOR STORING THE NUMERICAL SOLUTION
      DIMENSION TFP(3,101), CAP(3,101), TP(101)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY 10 CALLS TO PRINT
      IF((IP/10*10-IP).NE.0)GO TO 10
      WRITE(NO,1)T,
     1 (    TC(I),I=1,N),(     R(I),I=1,N),(    CA(I),I=1,N),
     2 (   RTF(I),I=1,N),(    RV(I),I=1,N),( DTCDT(I),I=1,N),
     3 (  DRDT(I),I=1,N),( DCADT(I),I=1,N)
      WRITE(NO,2)
     1 (DRTFDT(I),I=1,N),( DRVDT(I),I=1,N),(    P1(I),I=1,N),
     2 (    P2(I),I=1,N),(    P3(I),I=1,N),(    P4(I),I=1,N),
     3 ( DP1DZ(I),I=1,N),( DP2DZ(I),I=1,N),( DP3DZ(I),I=1,N)
      WRITE(NO,3)
     1 ( DP4DZ(I),I=1,N),(    TF(I),I=1,N),(     V(I),I=1,N)
1     FORMAT(1H1,
     1 11H          T,           F7.2,//,
     2 11H         TC,6E11.3,/,7E11.3,//,
     3 11H          R,6E11.3,/,7E11.3,//,
     4 11H         CA,6E11.3,/,7E11.3,//,
     5 11H        RTF,6E11.3,/,7E11.3,//,
     6 11H         RV,6E11.3,/,7E11.3,//,
     7 11H      DTCDT,6E11.3,/,7E11.3,//,
     8 11H       DRDT,6E11.3,/,7E11.3,//,
     9 11H      DCADT,6E11.3,/,7E11.3,//)
2     FORMAT(
     1 11H     DRTFDT,6E11.3,/,7E11.3,//,
     2 11H      DRVDT,6E11.3,/,7E11.3,//,
     3 11H         P1,6E11.3,/,7E11.3,//,
     4 11H         P2,6E11.3,/,7E11.3,//,
     5 11H         P3,6E11.3,/,7E11.3,//,
     6 11H         P4,6E11.3,/,7E11.3,//,
     7 11H      DP1DZ,6E11.3,/,7E11.3,//,
     8 11H      DP2DZ,6E11.3,/,7E11.3,//,
     9 11H      DP3DZ,6E11.3,/,7E11.3,//)
3     FORMAT(
     1 11H      DP4DZ,6E11.3,/,7E11.3,//,
     2 11H         TF,6E11.3,/,7E11.3,//,
     3 11H          V,6E11.3,/,7E11.3,//)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
10    IP=IP+1
      TFP(1,IP)=TF(5)
      TFP(2,IP)=TF(9)
      TFP(3,IP)=TF(13)
      CAP(1,IP)=CA(5)
      CAP(2,IP)=CA(9)
      CAP(3,IP)=CA(13)
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(3,IP,TP,TFP)
      WRITE(NO,11)
11    FORMAT(1H ,/,
     1 12H 1 - TF(2,T),/,
     2 12H 2 - TF(4,T),/,
     3 12H 3 - TF(6,T))
      CALL TPLOTS(3,IP,TP,CAP)
      WRITE(NO,12)
12    FORMAT(1H ,/,
     1 12H 1 - CA(2,T),/,
     2 12H 2 - CA(4,T),/,
     3 12H 3 - CA(6,T))
      END
NONISOTHERMAL CATALYTIC TUBULAR REACTOR
0.        300.      3.
   6510000    1    1  REL 0.001
END OF RUNS
*APP REACT02
      SUBROUTINE INITAL
C...
C...  DYNAMIC TWO-DIMENSIONAL TUBULAR REACTOR MODEL IN CYLINDRICAL
C...  COORDINATES
C...
C...  THE MATHEMATICAL MODEL FOR THE REACTOR CONSISTS OF THE FOLLOWING
C...  TWO-DIMENSIONAL PARTIAL DIFFERENTIAL EQUATIONS (PDES)
C...
C...     C  = -V(R)*C  + DC*(C   + (1/R)*C  + C  ) - RK*C        (1)
C...      T          Z        RR          R    ZZ
C...
C...     W  = -V(R)*W  + DW*(W   + (1/R)*W  + W  ) + 2*RK*C      (2)
C...      T          Z        RR          R    ZZ
C...
C...  WITH THE LAMINAR VELOCITY PROFILE
C...
C...     V(R) = 2*VAVG*(1 - R**2/RO**2)
C...
C...  THE CHEMICAL REACTION
C...
C...              KR
C...     E + A  ------+ 2A                                       (3)
C...          2
C...
C...  TAKES PLACE WHERE
C...
C...     E         ELECTRIC DISCHARGE
C...
C...     A         REACTANT
C...      2
C...
C...     A         PRODUCT
C...
C...     KR        FIRST-ORDER REACTION RATE CONSTANT
C...
C...  THE VARIABLES AND PARAMETERS IN EQUATIONS (1) AND (2) ARE
C...
C...     C(R,Z,T)  CONCENTRATION OF A
C...                                 2
C...
C...     W(R,Z,T)  CONCENTRATION OF A
C...
C...     R         RADIAL POSITION WITHIN THE REACTOR
C...
C...     Z         AXIAL POSITION WITHIN THE REACTOR
C...
C...     T         TIME
C...
C...     DC, DW    DIFFUSIVITIES FOR A  AND A, RESPECTIVELY
C...                                  2
C...
C...     VAVG      AVERAGE VELOCITY FOR LAMINAR FLOW IN THE Z
C...               DIRECTION
C...
C...     RO        RADIUS OF THE REACTOR
C...
C...     RK        VOLUMETRIC RATE CONSTANT FOR REACTION (3)
C...
C...  THE INITIAL CONDITIONS FOR EQUATIONS (1) AND (2) ARE
C...
C...     C(R,Z,0) = CI, W(R,Z,0) = 0                          (4)(5)
C...
C...  WHERE
C...
C...     CI        INITIAL CONCENTRATION OF A
C...                                         2
C...
C...  THE BOUNDARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     C (0,Z,T) = C (RO,Z,T) = 0                           (6)(7)
C...      R           R
C...
C...     C(R,0,T) = CI, C (R,ZL,T) = 0                        (8)(9)
C...                     Z
C...
C...  WHERE
C...
C...     CI        ENTERING CONCENTRATION OF A
C...                                          2
C...
C...     ZL        REACTOR LENGTH
C...
C...  THE BOUNDARY CONDITIONS FOR EQUATION (2) ARE
C...
C...     W (0,Z,T) = 0, -DW*W (RO,Z,T) = RD*W(RO,Z,T)**ND   (10)(11)
C...      R                  R
C...
C...     W(R,0,T) = 0, W (R,ZL,T) = 0                       (12)(13)
C...                    Z
C...
C...  WHERE
C...
C...     RD        RATE CONSTANT FOR THE DEPOSITION OF A ON THE
C...               REACTOR WALL
C...
C...     ND        POWER IN THE EQUATION FOR THE RATE OF DESPOSITION
C...               OF A ON THE REACTOR WALL
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   C(5,25),   W(5,25)
     2      /F/  CT(5,25),  WT(5,25)
     3      /S/  CR(5,25), CRR(5,25),  CZ(5,25), CZZ(5,25),
     4           WR(5,25), WRR(5,25),  WZ(5,25), WZZ(5,25)
     5      /C/        NR,        NZ,        RI,        RO,
     6                 ZO,        ZL,        DR,        DZ,
     7                 DC,        DW,        RK,        RD,
     8               VAVG,        CI,      R(5),      V(5),
     9                 NP,        IP,     X(25)
      COMMON/IO/       NI,        NO
C...
C...  SET THE NUMBER OF GRID POINTS IN THE RADIAL AND AXIAL
C...  DIRECTIONS
      NR=5
      NZ=25
C...
C...  SET THE REACTOR RADIAL DIMENSIONS
      RI=0.
      RO=1.0
C...
C...  SET THE REACTOR AXIAL DIMENSIONS
      ZO=0.
      ZL=48.
C...
C...  SET THE AVERAGE VELOCITY FOR LAMINAR FLOW, DIFFUSIVITIES
      VAVG=5.
      DC=10.
      DW=14.
C...
C...  SET THE REACTION, DEPOSITION RATE CONSTANTS, POWER FOR THE
C...  ORDER OF DEPOSITION
      RK=0.1
      RD=0.1
      NP=1
C...
C...  COMPUTE THE RADIAL POSITIONS, VELOCITY PROFILE
      DO 1 I=1,NR
      R(I)=(RO/FLOAT(NR-1))*FLOAT(I-1)
      V(I)=2.*VAVG*(1.-R(I)**2/RO**2)
1     CONTINUE
C...
C...  SET THE MODEL INITIAL CONDITIONS
      CI=1.0
      DO 2 J=1,NZ
      X(J)=(FLOAT(J)-1.)*2.
      DO 2 I=1,NR
      C(I,J)=CI
      W(I,J)=0.
2     CONTINUE
C...
C...  CALCULATE AND PRINT THE INITIAL DERIVATIVES
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   C(5,25),   W(5,25)
     2      /F/  CT(5,25),  WT(5,25)
     3      /S/  CR(5,25), CRR(5,25),  CZ(5,25), CZZ(5,25),
     4           WR(5,25), WRR(5,25),  WZ(5,25), WZZ(5,25)
     5      /C/        NR,        NZ,        RI,        RO,
     6                 ZO,        ZL,        DR,        DZ,
     7                 DC,        DW,        RK,        RD,
     8               VAVG,        CI,      R(5),      V(5),
     9                 NP,        IP,     X(25)
C...
C...  CONSTRAIN THE SOLUTION TO MEANINGFUL VALUES
      DO 8 I=1,NR
      DO 8 J=1,NZ
      IF(C(I,J).LT.0.)C(I,J)=0.
      IF(W(I,J).LT.0.)W(I,J)=0.
8     CONTINUE
C...
C...  SET THE BOUNDARY CONDITIONS AT Z = 0
      DO 1 I=1,NR
      C(I,1)=CI
      W(I,1)=0.
      CT(I,1)=0.
      WT(I,1)=0.
1     CONTINUE
C...
C...  COMPUTE THE FIRST-ORDER DERIVATIVES IN R
      CALL DSS034(RI,RO,NR,NZ,1,C,CR,0.)
      CALL DSS034(RI,RO,NR,NZ,1,W,WR,0.)
C...
C...  SET THE BOUNDARY CONDITIONS AT R = RI
      DO 2 J=1,NZ
      CR(1,J)=0.
      WR(1,J)=0.
2     CONTINUE
C...
C...  SET THE BOUNDARY CONDITIONS AT R = RO
      DO 3 J=1,NZ
      CR(NR,J)=0.
      WR(NR,J)=0.
      IF(W(NR,J).GT.0.)WR(NR,J)=-(1./DW)*W(NR,J)**NP
3     CONTINUE
C...
C...  COMPUTE THE SECOND-ORDER DERIVATIVES IN R
      CALL DSS034(RI,RO,NR,NZ,1,CR,CRR,0.)
      CALL DSS034(RI,RO,NR,NZ,1,WR,WRR,0.)
C...
C...  COMPUTE THE FIRST-ORDER DERIVATIVES IN Z FOR DIFFUSION
      CALL DSS034(ZO,ZL,NR,NZ,2,C,CZ,0.)
      CALL DSS034(ZO,ZL,NR,NZ,2,W,WZ,0.)
C...
C...  SET THE BOUNDARY CONDITIONS AT Z = ZL
      DO 4 I=1,NR
      CZ(I,NZ)=0.
      WZ(I,NZ)=0.
4     CONTINUE
C...
C...  COMPUTE THE SECOND-ORDER DERIVATIVES IN Z FOR DIFFUSION
      CALL DSS034(ZO,ZL,NR,NZ,2,CZ,CZZ,0.)
      CALL DSS034(ZO,ZL,NR,NZ,2,WZ,WZZ,0.)
C...
C...  COMPUTE THE FIRST-ORDER DERIVATIVES IN Z FOR CONVECTION
      CALL DSS034(ZO,ZL,NR,NZ,2,C,CZ,1.)
      CALL DSS034(ZO,ZL,NR,NZ,2,W,WZ,1.)
C...
C...  SET THE BOUNDARY CONDITIONS AT Z = ZL
      DO 5 I=1,NR
      CZ(I,NZ)=0.
      WZ(I,NZ)=0.
5     CONTINUE
C...
C...  ASSEMBLE EQUATION (1)
C...  ******************************************************************
      DO 6 I=1,NR
      DO 6 J=2,NZ
      RATE=0.
C...
C...  INCLUDE THE REACTION ZONE
      IF(J.EQ.11)RATE=-RK*C(I,J)/2.
      IF(J.EQ.16)RATE=-RK*C(I,J)/2.
      IF((J.GT.11).AND.(J.LT.16))RATE=-RK*C(I,J)
C...
C...  INDETERMINATE FORM AT R = 0
      IF(I.EQ.1)
     1 CT(I,J)=-V(I)*CZ(I,J)+DC*(2.*CRR(I,J)+CZZ(I,J))+RATE
C...
C...  INCLUDE THE TERM (1/R)*C  FOR R NE 0
C...                          R
      IF(I.GT.1)
     1 CT(I,J)=-V(I)*CZ(I,J)+DC*(CRR(I,J)+(1./R(I))*CR(I,J)+CZZ(I,J))
     2         +RATE
6     CONTINUE
C...
C...  ASSEMBLE EQUATION (2)
C...  ******************************************************************
      DO 7 I=1,NR
      DO 7 J=2,NZ
      RATE=0.
C...
C...  INCLUDE THE REACTION ZONE
      IF(J.EQ.11)RATE=RK*C(I,J)
      IF(J.EQ.16)RATE=RK*C(I,J)
      IF((J.GT.11).AND.(J.LT.16))RATE=2.*RK*C(I,J)
C...
C...  INDETERMINATE FORM AT R = 0
      IF(I.EQ.1)
     1 WT(I,J)=-V(I)*WZ(I,J)+DW*(2.*WRR(I,J)+WZZ(I,J))+RATE
C...
C...  INCLUDE THE TERM (1/R)*W  FOR R NE 0
C...                          R
      IF(I.GT.1)
     1 WT(I,J)=-V(I)*WZ(I,J)+DW*(WRR(I,J)+(1./R(I))*WR(I,J)+WZZ(I,J))
     2         +RATE
7     CONTINUE
C...  ******************************************************************
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   C(5,25),   W(5,25)
     2      /F/  CT(5,25),  WT(5,25)
     3      /S/  CR(5,25), CRR(5,25),  CZ(5,25), CZZ(5,25),
     4           WR(5,25), WRR(5,25),  WZ(5,25), WZZ(5,25)
     5      /C/        NR,        NZ,        RI,        RO,
     6                 ZO,        ZL,        DR,        DZ,
     7                 DC,        DW,        RK,        RD,
     8               VAVG,        CI,      R(5),      V(5),
     9                 NP,        IP,     X(25)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,((C(I,J),J=1,NZ,2),I=1,NR)
1     FORMAT(1H ,//,5H T = ,F7.2,/,9H C(R,Z,T),/,(13F9.4))
      WRITE(NO,2)  ((W(I,J),J=1,NZ,2),I=1,NR)
2     FORMAT(1H , /,              9H W(R,Z,T),/,(13F9.4))
C...
C...  PRINT THE INITIAL DERIVATIVES
      IF(IP.NE.-1)GO TO 100
      WRITE(NO,3)(( CR(I,J),J=1,NZ,2),I=1,NR)
3     FORMAT(1H , /,           11H  CR(R,Z,T),/,(13F9.4))
      WRITE(NO,4)((CRR(I,J),J=1,NZ,2),I=1,NR)
4     FORMAT(1H , /,           11H CRR(R,Z,T),/,(13F9.4))
      WRITE(NO,5)(( CZ(I,J),J=1,NZ,2),I=1,NR)
5     FORMAT(1H , /,           11H  CZ(R,Z,T),/,(13F9.4))
      WRITE(NO,6)((CZZ(I,J),J=1,NZ,2),I=1,NR)
6     FORMAT(1H , /,           11H CZZ(R,Z,T),/,(13F9.4))
      WRITE(NO,7)(( CT(I,J),J=1,NZ,2),I=1,NR)
7     FORMAT(1H , /,           11H  CT(R,Z,T),/,(13F9.4))
      WRITE(NO,8)(( WR(I,J),J=1,NZ,2),I=1,NR)
8     FORMAT(1H , /,           11H  WR(R,Z,T),/,(13F9.4))
      WRITE(NO,9)((WRR(I,J),J=1,NZ,2),I=1,NR)
9     FORMAT(1H , /,           11H WRR(R,Z,T),/,(13F9.4))
      WRITE(NO,10)(( WZ(I,J),J=1,NZ,2),I=1,NR)
10    FORMAT(1H , /,           11H  WZ(R,Z,T),/,(13F9.4))
      WRITE(NO,11)((WZZ(I,J),J=1,NZ,2),I=1,NR)
11    FORMAT(1H , /,           11H WZZ(R,Z,T),/,(13F9.4))
      WRITE(NO,12)(( WT(I,J),J=1,NZ,2),I=1,NR)
12    FORMAT(1H , /,           11H  WT(R,Z,T),/,(13F9.4))
100   IP=IP+1
C...
C...  ******************************************************************
C...  CALL SUBROUTINE PLOT3D TO PLOT C(R,Z,T) AND W(R,Z,T) VS R AND Z
C...  WITH T AS A PARAMETER.  PLOT3D IS A MACHINE-DEPENDENT ROUTINE AND
C...  WILL THEREFORE HAVE TO BE REPLACED FOR THREE-DIMENSIONAL PLOTTING
C...  ON A COMPUTER OTHER THAN THE LEHIGH CYBER DUAL 730
C...  CALL PLOT3D
C...  ******************************************************************
C...
      RETURN
      END
DYNAMIC TWO-DIMENSIONAL TUBULAR REACTOR
0.        3.0       1.0
  250 1000    1    1  ABS 0.001
END OF RUNS
*APP REACT03
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF AN ETHYLENE OXIDE REACTOR
C...
C...  THIS CODING IS FOR THE DYNAMIC SIMULATION OF A MOVING-BED
C...  ETHYLENE OXIDE REACTOR IN WHICH THE FOLLOWING REACTIONS TAKE
C...  PLACE
C...
C...                      K
C...                       1
C...     C H  + (1/2)O  -----+ C H O                             (1)
C...      2 4         2         2 4
C...
C...
C...                  K
C...                   2
C...     C H  + 3O  -----+ 2H O + 2CO                            (2)
C...      2 4     2          2       2
C...
C...  THE PRODUCTION OF ETHYLENE OXIDE BY REACTION (1) IS THE
C...  PREFERRED REACTION.  THE COMBUSTION OF ETHYLENE BY REACTION
C...  (2) IS UNDESIRED.  REACTION (2) HAS A LARGE HEAT RELEASE
C...  WHICH MAY PRODUCE SIGNIFICANT TEMPERATURE EXCURSIONS (EXO-
C...  THERMS) IN THE REACTOR.
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH MODEL THE
C...  REACTOR ARE
C...
C...     W1  = -W1  - B1*(REACT1 + REACT2)                       (1)
C...       T      X
C...
C...     W2  = -W2  - B1*(0.5*REACT1 + 3.*REACT2)                (2)
C...       T      X
C...
C...     W3  = -W3  + B1*REACT1                                  (3)
C...       T      X
C...
C...     TF  = -TF  + B2*(TS - TF)                               (4)
C...       T      X
C...
C...     TS  = -B5*TS  - B4*(TS - TF) + HEATS                    (5)
C...       T         X
C...
C...  WHERE
C...
C...     X        AXIAL DISTANCE DOWN THE REACTOR (DIMENSIONLESS)
C...
C...     T        TIME (DIMENSIONLESS)
C...
C...     W1       CONCENTRATION OF C H  (DIMENSIONLESS)
C...                                2 2
C...
C...     W2       CONCENTRATION OF O  (DIMENSIONLESS)
C...                                2
C...
C...     W3       CONCENTRATION OF C H O (DIMENSIONLESS)
C...                                2 2
C...
C...     TF       FLUID TEMPERATURE (DIMENSIONLESS)
C...
C...     TS       SOLID TEMPERATURE (DIMENSIONLESS)
C...
C...     REACT1   RATE OF REACTION 1 (DIMENSIONLESS)
C...
C...     REACT2   RATE OF REACTION 2 (DIMENSIONLESS)
C...
C...     HEATS    SUM OF THE VOLUMETRIC HEAT EFFECTS FOR REACTIONS
C...              1 AND 2 (DIMENSIONLESS)
C...
C...     B1,B2    DIMENSIONLESS CONSTANTS DEFINED IN THE CODING
C...     B31,B32  BELOW
C...     B4,B5
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATIONS (1) TO (5)
C...  ARE
C...
C...     W1(0,T) = 1, W1(X,0) = 0                             (6)(7)
C...
C...     W2(0,T) = 1, W2(X,0) = 0                             (8)(9)
C...
C...     W3(0,T) = 0, W3(X,0) = 0                           (10)(11)
C...
C...     TF(0,T) = 1, TF(X,0) = 1                           (12)(13)
C...
C...     TS(0,T) = 1, TS(X,0) = 1                           (14)(15)
C...
C...  NOTE THAT FOR W1, BOUNDARY AND INITIAL CONDITIONS (6) AND (7)
C...  CONSTITUTE A UNIT STEP CHANGE WHICH MAY PRESENT A DIFFICULT
C...  SITUATION FOR THE NUMERICAL INTEGRATION OF THE MODEL EQUATIONS.
C...  THUS, AN EXPONENTIAL CHANGE, RATHER THAN A STEP CHANGE, IN THE
C...  ENTERING VALUE OF W1 (W1(0,T)) IS PROGRAMMED IN SUBROUTINE
C...  DERV.  THE CONSTANT C IN THE EXPONENTIAL FUNCTION DETERMINES
C...  HOW RAPIDLY THE ENTERING VALUE OF W1 CHANGES FROM 0 TO 1, AND
C...  CAN BE VARIED TO DETERMINE THE EFFECT OF THE SUDDEN CHANGE IN
C...  THE ENTERING VALUE OF W1.  THE SAME SITUATION APPLIES TO W2
C...  THROUGH BOUNDARY AND INITIAL CONDITIONS (8) AND (9), SO THE
C...  EXPONENTIAL FUNCTION HAS ALSO BEEN APPLIED TO THE ENTERING
C...  VALUE OF W2.
C...
C...  SINCE THE ENTERING VALUE OF W3 REMAINS AT THE INITIAL VALUE
C...  OF 0 ACCORDING TO BOUNDARY AND INITIAL CONDITIONS (10) AND
C...  (11), THE EXPONENTIAL FUNCTION IS NOT APPLIED TO W3.  SIMI-
C...  LARLY, THE ENTERING VALUES OF TF AND TS REMAIN AT THE INITIAL
C...  VALUES OF 1 SO THAT THE EXPONENTIAL FUNCTION IS NOT APPLIED
C...  TO THESE TWO TEMPERATURES.
C...
      COMMON/T/       T,    NFIN,   NORUN
     1      /Y/  W1(41),  W2(41),  W3(41),  TF(41),  TS(41)
     2      /F/ W1T(41), W2T(41), W3T(41), TFT(41), TST(41)
     3      /S/ W1X(41), W2X(41), W3X(41), TFX(41), TSX(41)
     4      /C/      XL,      XU,      DX,      UF,     C10,       S,
     5             DENS,     EPS,      HT,  REACT1,  REACT2,   BHEATS,
     6             DENF,     CPF,      US,     CPS,      T0,    HTR1,
     7             HTR2,    ACT1,    ACT2,   PEXP1,   PEXP2,     W10,
     8              W20,     W30,     TS0,     TF0,   XLONG,      B1,
     9               B2,     B31,     B32,      B4,      B5,       N,
     A                C
C...
C...  SET THE MODEL PARAMETERS
C...
C...  NUMBER OF AXIAL GRID POINTS, LENGTH OF THE REACTOR
      N=41
      XLONG=100.
C...
C...  DIMENSIONLESS BOUNDARY COORDINATES OF THE REACTOR
      XL=0.
      XU=1.
C...
C...  REACTOR VOID FRACTION, FLUID VELOCITY, SOLID VELOCITY
      EPS=0.61
      UF=16.4/EPS
      US=5.
C...
C...  REACTOR PRESSURE, ENTERING TEMPERATURE, ENTERING MOLAR
C...  DENSITY
      PRES=31.74
      T0=523.
      C10=0.079*PRES/(T0*82.1)
C...
C...  VOLUMETRIC HEAT TRANSFER AREA, SOLID DENSITY, HEAT TRANSFER
C...  COEFFICIENT
      S=200.
      DENS=3.97
C...
C...  FLUID TO PARTICLE HEAT TRANSFER COEFFICIENT
      HT=0.0000002
C...
C...  FLUID DENSITY, FLUID HEAT CAPACITY, SOLID HEAT CAPACITY
      DENF=29.*PRES/(82.1*T0)
      CPF=0.3
      CPS=0.2
C...
C...  HEATS OF REACTION, ACTIVATION ENERGIES AND PRE-EXPONENTIAL
C...  FACTORS FOR REACTIONS 1 AND 2
      HTR1=25200.
      HTR2=316000.
      ACT1=21400.
      ACT2=29000.
      PEXP1=1.312E+05
      PEXP2=4.979E+07
C...
C...  ENTERING CONCENTRATIONS FOR COMPONENTS 1, 2 AND 3
      W10=1.
      W20=1.
      W30=0.
C...
C...  ENTERING SOLID, FLUID TEMPERATURES
      TS0=1.
      TF0=1.
C...
C...  AXIAL GRID SPACING, CONSTANT IN THE BOUNDARY CONDITION
C...  FUNCTION (SEE SUBROUTINE DERV)
      DX=(XU-XL)/FLOAT(N-1)
      C=5.
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN SUBROUTINE DERV
      B1=XLONG*S*DENS*(1.-EPS)/(EPS*UF)
      B2=S*DENS*HT*XLONG*(1.-EPS)/(DENF*EPS*UF*CPF)
      B31=S*HTR1*XLONG*C10/(CPS*UF*T0)
      B32=S*HTR2*XLONG*C10/(CPS*UF*T0)
      B4=S*XLONG*HT/(UF*CPS)
      B5=US/UF
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      W1(I)=0.
      W2(I)=0.
      W3(I)=0.
      TF(I)=TF0
      TS(I)=TS0
1     CONTINUE
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/       T,    NFIN,   NORUN
     1      /Y/  W1(41),  W2(41),  W3(41),  TF(41),  TS(41)
     2      /F/ W1T(41), W2T(41), W3T(41), TFT(41), TST(41)
     3      /S/ W1X(41), W2X(41), W3X(41), TFX(41), TSX(41)
     4      /C/      XL,      XU,      DX,      UF,     C10,       S,
     5             DENS,     EPS,      HT,  REACT1,  REACT2,   BHEATS,
     6             DENF,     CPF,      US,     CPS,      T0,    HTR1,
     7             HTR2,    ACT1,    ACT2,   PEXP1,   PEXP2,     W10,
     8              W20,     W30,     TS0,     TF0,   XLONG,      B1,
     9               B2,     B31,     B32,      B4,      B5,       N,
     A                C
C...
C...  SET THE BOUNDARY CONDITIONS
      W1(1)=W10
      W2(1)=W20
      IF((C*T).LT.50.)W1(1)=W10*(1.-EXP(-C*T))
      IF((C*T).LT.50.)W2(1)=W20*(1.-EXP(-C*T))
      W3(1)=W30
      TF(1)=TF0
      TS(1)=TS0
C...
C...  CONSTRAIN THE DEPENDENT VARIABLES TO MEANINGFUL VALUES
      DO 1 I=1,N
      IF(W1(I).LT.0.)W1(I)=0.
      IF(W2(I).LT.0.)W2(I)=0.
      IF(W3(I).LT.0.)W3(I)=0.
      IF(TF(I).LT.TF0)TF(I)=TF0
      IF(TS(I).LT.TS0)TS(I)=TS0
1     CONTINUE
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN THE PDES
      CALL DSS020(XL,XU,N,W1,W1X,1.)
      CALL DSS020(XL,XU,N,W2,W2X,1.)
      CALL DSS020(XL,XU,N,W3,W3X,1.)
      CALL DSS020(XL,XU,N,TF,TFX,1.)
      CALL DSS020(XL,XU,N,TS,TSX,1.)
C...
C...  ASSEMBLE THE PDES STARTING WITH GRID POINT 1
      W1T(1)=0.
      W2T(1)=0.
      IF((C*T).LT.50.)W1T(1)=C*W10*EXP(-C*T)
      IF((C*T).LT.50.)W2T(1)=C*W20*EXP(-C*T)
      W3T(1)=0.
      TFT(1)=0.
      TST(1)=0.
      DO 2 I=2,N
      RT=(-1./(1.987*T0*TS(I)))
      REACT1=PEXP1*EXP(ACT1*RT)*W2(I)
      REACT2=PEXP2*EXP(ACT2*RT)*W2(I)
      HEATS=B31*REACT1+B32*REACT2
      W1T(I)=-W1X(I)-B1*(REACT1+REACT2)
      W2T(I)=-W2X(I)-B1*(0.5*REACT1+3.*REACT2)
      W3T(I)=-W3X(I)+B1*REACT1
      TFT(I)=-TFX(I)+B2*(TS(I)-TF(I))
      TST(I)=-B5*TSX(I)-B4*(TS(I)-TF(I))+HEATS
2     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/       T,    NFIN,   NORUN
     1      /Y/  W1(41),  W2(41),  W3(41),  TF(41),  TS(41)
     2      /F/ W1T(41), W2T(41), W3T(41), TFT(41), TST(41)
     3      /S/ W1X(41), W2X(41), W3X(41), TFX(41), TSX(41)
     4      /C/      XL,      XU,      DX,      UF,     C10,       S,
     5             DENS,     EPS,      HT,  REACT1,  REACT2,   BHEATS,
     6             DENF,     CPF,      US,     CPS,      T0,    HTR1,
     7             HTR2,    ACT1,    ACT2,   PEXP1,   PEXP2,     W10,
     8              W20,     W30,     TS0,     TF0,   XLONG,      B1,
     9               B2,     B31,     B32,      B4,      B5,       N,
     A                C
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE NUMERICAL SOLUTION
      DIMENSION W1P(11,41), W2P(11,41), W3P(11,41),
     1          TFP(11,41), TSP(11,41), R1P(11,41),
     2          R2P(11,41), HRP(11,41), HTP(11,41),
     3          W1EP(2,11), W2EP(2,11), W3EP(2,11),
     4              XP(41),     TP(11)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      DATA IP/0/
C...
C...  THE FOLLOWING IF IS USED TO CIRCUMVENT PRINTING THE SOLUTION,
C...  ARRAYS W1, W2, W3, TF AND TS, BY PROCEEDING DIRECTLY TO THE
C...  STORING OF THE SOLUTION FOR PLOTTING.  THE SOLUTION CAN BE
C...  PRINTED BY CONVERTING THE IF STATEMENT TO A COMMENT OR BY
C...  REMOVING IT
C...  IF(IP.GT.-1)GO TO 20
C...
C...  PRINT THE SOLUTION VECTORS IN COMMON/Y/
      WRITE(NO,1)T
1     FORMAT(1H ,//,5H T = ,F7.3)
      WRITE(NO,2)( W1(I),I=1,N,4)
2     FORMAT(1H ,/,4H  W1,11E11.3)
      WRITE(NO,3)( W2(I),I=1,N,4)
3     FORMAT(1H ,/,4H  W2,11E11.3)
      WRITE(NO,4)( W3(I),I=1,N,4)
4     FORMAT(1H ,/,4H  W3,11E11.3)
      WRITE(NO,5)( TF(I),I=1,N,4)
5     FORMAT(1H ,/,4H  TF,11E11.3)
      WRITE(NO,6)( TS(I),I=1,N,4)
6     FORMAT(1H ,/,4H  TS,11E11.3)
C...
C...  THE FOLLOWING IF IS USED TO CIRCUMVENT PRINTING THE DERIVATIVES
C...  OF THE SOLUTION, ARRAYS W1X, W2X, W3X, TFX, TSX, W1T, W2T, W3T,
C...  TFT, TST, BY PROCEEDING DIRECTLY TO THE STORING OF THE SOLUTION
C...  FOR PLOTTING.  THE DERIVATIVES CAN BE PRINTED BY CONVERTING THE IF
C...  STATEMENT TO A COMMENT OR BY REMOVING IT
      IF(IP.GT.-1)GO TO 20
C...
C...  PRINT THE SPATIAL DERIVATIVE VECTORS IN COMMON/S/ AND THE
C...  TEMPORAL DERIVATIVE VECTORS IN COMMON/F/
      WRITE(NO,7)(W1X(I),I=1,N,4)
7     FORMAT(1H ,/,4H W1X,11E11.3)
      WRITE(NO,8)(W2X(I),I=1,N,4)
8     FORMAT(1H ,/,4H W2X,11E11.3)
      WRITE(NO,9)(W3X(I),I=1,N,4)
9     FORMAT(1H ,/,4H W3X,11E11.3)
      WRITE(NO,10)(TFX(I),I=1,N,4)
10    FORMAT(1H ,/,4H TFX,11E11.3)
      WRITE(NO,11)(TSX(I),I=1,N,4)
11    FORMAT(1H ,/,4H TSX,11E11.3)
      WRITE(NO,12)(W1T(I),I=1,N,4)
12    FORMAT(1H ,/,4H W1T,11E11.3)
      WRITE(NO,13)(W2T(I),I=1,N,4)
13    FORMAT(1H ,/,4H W2T,11E11.3)
      WRITE(NO,14)(W3T(I),I=1,N,4)
14    FORMAT(1H ,/,4H W3T,11E11.3)
      WRITE(NO,15)(TFT(I),I=1,N,4)
15    FORMAT(1H ,/,4H TFT,11E11.3)
      WRITE(NO,16)(TST(I),I=1,N,4)
16    FORMAT(1H ,/,4H TST,11E11.3)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
20    IP=IP+1
      DO 21 I=1,N
      XP(I)=DX*FLOAT(I-1)
      W1P(IP,I)=W1(I)
      W2P(IP,I)=W2(I)
      W3P(IP,I)=W3(I)
      TFP(IP,I)=TF(I)
      TSP(IP,I)=TS(I)
C...
C...  THE RATES OF REACTIONS 1 AND 2, THE TOTAL HEAT EFFECT FOR THE
C...  REACTIONS AND THE HEAT TRANSFER RATE FROM THE FLUID TO THE
C...  SOLID ARE COMPUTED AND STORED HERE FOR SUBSEQUENT PLOTTING
      RT=(-1./(1.987*T0*TS(I)))
      REACT1=PEXP1*EXP(ACT1*RT)*W2(I)
      REACT2=PEXP2*EXP(ACT2*RT)*W2(I)
      HEATS=B31*REACT1+B32*REACT2
      R1P(IP,I)=REACT1
      R2P(IP,I)=REACT2
      HRP(IP,I)=HEATS
      HTP(IP,I)=B2*(TF(I)-TS(I))
21    CONTINUE
C...
C...  THE ENTERING AND EXITING CONCENTRATIONS, W1(0,T), W1(1,T),
C...  W2(0,T), W2(1,T), W3(0,T), W3(1,T), ARE STORED VS T FOR
C...  SUBSEQUENT PLOTTING
      W1EP(1,IP)=W1(1)
      W1EP(2,IP)=W1(N)
      W2EP(1,IP)=W2(1)
      W2EP(2,IP)=W2(N)
      W3EP(1,IP)=W3(1)
      W3EP(2,IP)=W3(N)
      TP(IP)=T
C...
C...  AT THE END OF THE RUN, PLOT THE NUMERICAL SOLUTION.  FIRST,
C...  CONSTRAIN THE DEPENDENT VARIABLES SO THE SCALING BY QIKSET IS
C...  NOT VIOLATED
      IF(IP.LT.11)RETURN
      DO 22 I=1,IP
      DO 22 J=1,N
      IF(W1P(I,J).LT.0.)W1P(I,J)=0.
      IF(W2P(I,J).LT.0.)W2P(I,J)=0.
      IF(W3P(I,J).LT.0.)W3P(I,J)=0.
      IF(TFP(I,J).LT.1.)TFP(I,J)=1.
      IF(TSP(I,J).LT.1.)TSP(I,J)=1.
      IF(R1P(I,J).LT.0.)R1P(I,J)=0.
      IF(R2P(I,J).LT.0.)R2P(I,J)=0.
      IF(HRP(I,J).LT.0.)HRP(I,J)=0.
      IF(HTP(I,J).LT.0.)HTP(I,J)=ABS(HTP(I,J))
22    CONTINUE
      DO 23 I=1,2
      DO 23 J=1,IP
      IF(W1EP(I,J).LT.0.)W1EP(I,J)=0.
      IF(W2EP(I,J).LT.0.)W2EP(I,J)=0.
      IF(W3EP(I,J).LT.0.)W3EP(I,J)=0.
23    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...  PLOT W1(X,T) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,-0.1,0.2)
C...  CALL QIKPLT(XP,W1P,N,3H*X*,16H*W1(X,T) (C2H4)*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT W2(X,T) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,-0.1,0.2)
C...  CALL QIKPLT(XP,W2P,N,3H*X*,14H*W2(X,T) (O2)*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT W3(X,T) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,-0.1,0.2)
C...  CALL QIKPLT(XP,W3P,N,3H*X*,17H*W3(X,T) (C2H4O)*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT TF(X,T) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.99,0.01)
C...  CALL QIKPLT(XP,TFP,N,3H*X*,9H*TF(X,T)*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT TS(X,T) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.99,0.01)
C...  CALL QIKPLT(XP,TSP,N,3H*X*,9H*TS(X,T)*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT REACT1 VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.,-0.0)
C...  CALL QIKPLT(XP,R1P,N,3H*X*,8H*REACT1*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT REACT2 VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.,-0.0)
C...  CALL QIKPLT(XP,R2P,N,3H*X*,8H*REACT2*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT HEATS VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.,-0.0)
C...  CALL QIKPLT(XP,HRP,N,3H*X*,7H*HEATS*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT ABS(B2*(TF - TS)) VS X WITH T AS A PARAMETER
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,0.2,6.,0.,-0.0)
C...  CALL QIKPLT(XP,HTP,N,3H*X*,18H*ABS(B2(TF - TS))*,
C... 1 8H*RUN 1 *,IP)
C...
C...  PLOT W1(0,T), W1(1,T) VS T
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,1.0,6.,-0.1,0.2)
C...  CALL QIKPLT(TP,W1EP,IP,3H*T*,25H*W1(0,T), W1(1,T) (C2H4)*,
C... 1 8H*RUN 1 *,2)
C...
C...  PLOT W2(0,T), W2(1,T) VS T
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,1.0,6.,-0.1,0.2)
C...  CALL QIKPLT(TP,W2EP,IP,3H*T*,23H*W2(0,T), W2(1,T) (O2)*,
C... 1 8H*RUN 1 *,2)
C...
C...  PLOT W3(0,T), W3(1,T) VS T
C...  CALL QIKSAX(3,3)
C...  CALL QIKSET(5.,0.,1.0,6.,-0.1,0.2)
C...  CALL QIKPLT(TP,W3EP,IP,3H*T*,26H*W3(0,T), W3(1,T) (C2H4O)*,
C... 1 8H*RUN 1 *,2)
C...
C...  ******************************************************************
C...
      IP=0
      RETURN
      END
41-POINT REACTOR MODEL, EXTENDED TIME SCALE
0.        5.        0.5
  20510000    1    1  ABS 0.001
END OF RUNS
*APP REACT04
      SUBROUTINE INITAL
C...
C...  ETHANE PYROLYSIS IN A TUBULAR REACTOR
C...
C...  THE PYROLYSIS REACTION OF INTEREST IS
C...
C...                      +HEAT
C...               ETHANE   =   ETHYLENE + HYDROGEN
C...
C...  THE REACTION IS CARRIED OUT IN A HEATED TUBE THROUGH WHICH THE
C...  REACTING GAS STREAM FLOWS.  THE DIFFERENTIAL EQUATIONS WHICH GIVE
C...  THE CHANGE IN THE FRACTIONAL CONVERSION OF ETHANE, Z, AND TEMP-
C...  PERATURE, T, WITH DISTANCE DOWN THE TUBE, L, ARE DERIVED IN DETAIL
C...  IN THE REFERENCE CITED IN THE FIRST DATA LINE
C...
      COMMON/T/L,NFIN,NRUN/Y/Z,T/F/DZDL,DTDL
C...
C...  THE PROBLEM PARAMETERS IN COMMON/PARM/ ARE SET IN A BLOCK DATA
C...  ROUTINE
      COMMON/PARM/    TF,     P,RATEMS,    DI,QPERSF,  CONV,     Q,
     1            FACTOR
      REAL L
C...
C...  COMPUTE THE TWO CONSTANTS IN THE DIFFERENTIAL EQUATIONS
      Q=QPERSF*30./RATEMS*3.1415927*DI/12.
      FACTOR=2.07504E20*3.1415927*DI**2*P*30./(144.*4.*10.73*RATEMS)
C...
C...  INITIAL CONDITIONS
C...  Z(L) = 0, T(L) = TF + 460, L = 0
      Z=0.
      T=TF+460.
C...
C...  INITIALIZE THE OTHER VARIABLES IN THE MODEL
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/L,NFIN,NRUN/Y/Z,T/F/DZDL,DTDL
      COMMON/PARM/    TF,     P,RATEMS,    DI,QPERSF,  CONV,     Q,
     1            FACTOR
      REAL L
C...
C...  CONVERT TEMPERATURE FROM RANKIN TO KELVIN
      TK=T/1.8
C...
C...  MATERIAL BALANCE DIFFERENTIAL EQUATION
      DZDL=FACTOR*EXP(-41310./TK)*(1.-Z)/(T*(1.+Z))
C...
C...  HEAT BALANCE DIFFERENTIAL EQUATION
      DTDL=(Q-DH(TK)*DZDL)/CP(TK,Z)
C...
C...  TEST FOR THE REQUIRED CONVERSION
      IF(Z.GE.CONV)NFIN=1
      RETURN
      END
      FUNCTION DH(TK)
C...
C...  FUNCTION DH COMPUTES THE HEAT OF REACTION
C...
C...  ARGUMENT
C...
C...     TK  REACTION TEMPERATURE IN KELVIN
C...
      DH=1.8*(32732.+8.50*(TK-298.)-5.942E-3*(TK**2-298.**2)
     1  +1.28E-6*(TK**3-298.**3))
      RETURN
      END
      FUNCTION CP(TK,Z)
C...
C...  FUNCTION CP COMPUTES THE SPECIFIC HEAT OF THE GAS STREAM
C...
C...  ARGUMENTS
C...
C...     TK  REACTION TEMPERATURE IN KELVIN
C...
C...     Z   FRACTION OF ETHANE CONVERTED TO
C...         ETHYLENE AND HYDROGEN
C...
      CP=(1.-Z)*(3.75+35.7E-3*TK-10.12E-6*TK**2)
     1  +Z*(12.25+23.81E-3*TK-6.28E-6*TK**2)
      RETURN
      END
      BLOCK DATA
C...
C...  THE PROBLEM PARAMETERS ARE SET IN THIS ROUTINE AND PASSED THROUGH
C...  COMMON/PARM/
C...
      COMMON/PARM/    TF,     P,RATEMS,    DI,QPERSF,  CONV,     Q,
     1            FACTOR
      DATA            TF,     P,RATEMS,    DI,QPERSF,  CONV/
     1            1200.0,  30.0,1800.0,4.0260,5000.0, 0.750/
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/L,NFIN,NRUN/Y/Z,T/F/DZDL,DTDL
      COMMON/PARM/    TF,     P,RATEMS,    DI,QPERSF,  CONV,     Q,
     1            FACTOR
      REAL L
C...
C...  DIMENSION THE ARRAYS REQUIRED FOR PLOTTING THE NUMERICAL SOLUTION
      DIMENSION X1(30),Y1(2,30),X2(30),Y2(1,30)
C...
C...  INITIALIZE AN INDEX FOR PLOTTING
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.NE.0)GO TO 1
      WRITE(NO,2)
2     FORMAT(24X,1HL,14X,1HZ,14X,1HT)
C...
C...  PRINT THE NUMERICAL SOLUTION
1     TF=T-460.
      WRITE(NO,3)L,Z,TF
3     FORMAT(10X,E15.2,2E15.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      X1(IP)=L
      Y1(1,IP)=Z
      Y1(2,IP)=TF/1000.
      X2(IP)=TF
      Y2(1,IP)=Z
C...
C...  PLOT Z(L) AND T(L) VS L
      IF(NFIN.NE.1)RETURN
      CALL TPLOTS(2,IP,X1,Y1)
      WRITE(NO,5)L,CONV
5     FORMAT(//,12X,8H1 - Z(L),3X,13H2 - T(L)/1000,3X,9HLENGTH = ,F6.2,
     1          3X,13HCONVERSION = ,F6.4)
C...
C...  PLOT Z(L) VS T(L)
      CALL TPLOTS(1,IP,X2,Y2)
      WRITE(NO,6)
6     FORMAT(//,12X,34HZ(L)(VERTICAL) VS T(L)(HORIZONTAL))
      IP=0
      RETURN
      END
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, EX. 6.2, JOHN WILEY
0.        1000.     25.
    2  100    7    1  REL 0.001
END OF RUNS
*APP REACT05
      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 REACT06
      SUBROUTINE INITAL
C...
C...  HYDRODEALKYLATION OF TOLUENE TO BENZENE
C...
C...  THE BASIC REACTION IS
C...
C...  TOLUENE + HYDROGEN = BENZENE + METHANE
C...
C...  X     FRACTIONAL CONVERSION OF TOLUENE
C...
C...  T     REACTION TEMPERATURE R
C...
C...  V     POSITION ALONG THE REACTOR IN TERMS OF VOLUME FT**3
C...
C...  CA0   ENTERING CONCENTRATION OF TOLUENE = 0.006278 MOLS/FT**3
C...
C...  CB0   ENTERING CONCENTRATION OF HYDROGEN = 0.0314 MOLS/FT**3
C...
C...  T0    ENTERING TEMPERATURE = 1585 R
C...
C...  F     ENTERING MOLAR FLOW RATE = 1,303.9 LB-MOL/HR
C...
C...  Y0    ENTERING TOLUENE MOL FRACTION = 0.1525
C...
C...  E     ACTIVATION ENERGY = 78,500 BTU/LB-MOL
C...
C...  RG    GAS CONSTANT = 1.987 BTU/LB-MOL R
C...
C...  DH    HEAT OF REACTION = 21,500 BTU/LB-MOL
C...
C...  A     FREQUENCY FACTOR = 2.8E+12 (FT**3/LB-MOL)**0.5(1/HR)
C...
C...        ENTERING TOLUENE FLOW RATE = 198.9 LB-MOL/HR
C...
C...        ENTERING HYDROGEN FLOW RATE = 994.5 LB-MOL/HR
C...
C...        ENTERING METHANE FLOW RATE = 110.5 LB-MOL/HR
C...
C...  THE REACTOR PARAMETERS ARE SET IN A BLOCK DATA ROUTINE
C...
      COMMON/T/V,NFIN/Y/X,T/F/DXDV,DTDV
      COMMON/PARM/CA0,CB0,T0,F,Y0,E,RG,DH,A
C...
C...  REACTOR INLET CONDITIONS
      X=0.
      T=1585.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/V,NFIN/Y/X,T/F/DXDV,DTDV
      COMMON/PARM/CA0,CB0,T0,F,Y0,E,RG,DH,A
      REAL M1,M2,M3,M4
C...
C...  MATERIAL BALANCE
C...
C...  THE FRACTIONAL CONVERSION IS LIMITED TO THE INTERVAL 0 LE X LE 1
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
C...
C...  MATERIAL BALANCE DIFFERENTIAL EQUATION
      DXDV=A*CA0/(F*Y0)*(1.-X)*SQRT(ABS(CB0-CA0*X))*EXP(-E/(RG*T))
C...
C...  THE FRACTIONAL CONVERSION IS A MONOTONICALLY INCREASING FUNCTION
C...  OF POSITION ALONG THE REACTOR AND THEREFORE ITS DERIVATIVE IS
C...  ALWAYS POSITIVE
      IF(DXDV.LT.0.)DXDV=0.
C...
C...  ENERGY BALANCE
C...
C...  COMPUTE THE MOLAR FLOW RATES OF THE FOUR COMPONENTS ALONG THE
C...  REACTOR
      M1=198.9*(1.-X)
      M2=994.5*(1.-X)
      M3=198.9*X
      M4=110.5+198.9*X
C...
C...  COMPUTE THE ENTHALPY OF THE REACTING GAS ALONG THE REACTOR
      SUM=M1*( 0.019444*T+27.72)+
     1    M2*(           4.9680)+
     2    M3*( 0.015388*T+22.90)+
     3    M4*(0.00616667*T+6.30)
C...
C...  THE TEMPERATURE SHOULD NOT EXCEED 1635 TO AVOID THERMAL PROBLEMS
      IF(T.GE.1635.)NFIN=1
C...
C...  ENERGY BALANCE DIFFERENTIAL EQUATION
      DTDV=DXDV*F*Y0*DH/SUM
C...
C...  FOR AN ADIABTAIC REACTOR WITH AN EXOTHERMIC REACTION, THE TEMPERA-
C...  TURE IS A MONOTONICALLY INCREASING FUNCTION OF POSITION ALONG THE
C...  REACTOR AND THEREFORE ITS DERIVATIVE IS ALWAYS POSITIVE
      IF(DTDV.LT.0.)DTDV=0.
      RETURN
      END
      BLOCK DATA
C...
C...  THIS BLOCK DATA ROUTINE SETS THE REACTOR PARAMETERS IN COMMON
C...  /PARM/
      COMMON/PARM/CA0,CB0,T0,F,Y0,E,RG,DH,A
C...
C...  SET REACTOR PARAMETERS
      DATA       CA0,       CB0,        T0,         F,        Y0,
     1             E,        RG,        DH,         A/
     2     6.278E-03,  3.14E-02,     1585.,    1309.9,    0.1525,
     3        78500.,     1.987,    21500.,   2.8E+12/
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/V,NFIN/Y/X,T/F/DXDV,DTDV
      COMMON/PARM/CA0,CB0,T0,F,Y0,E,RG,DH,A
C...
C...  DIMENSION ARRAYS FOR PLOTTING
      DIMENSION VPLOT(31),XPLOT(31),TPLOT(31)
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,3)
3     FORMAT(14X,1HV,14X,1HX,14X,1HT)
C...
C...  PRINT SOLUTION
      WRITE(NO,1)V,X,T
1     FORMAT(F15.1,F15.5,F15.1)
C...
C...  STORE SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      VPLOT(IP)=V
      XPLOT(IP)=X
      TPLOT(IP)=T
C...
C...  PLOT SOLUTION
      IF((NFIN.EQ.0).AND.(IP.LT.31))RETURN
      CALL TPLOTS(1,IP,VPLOT,XPLOT)
      WRITE(NO,5)
5     FORMAT(//,16X,43HCONVERSION (X) VS REACTOR VOLUME (V, FT**3))
      CALL TPLOTS(1,IP,VPLOT,TPLOT)
      WRITE(NO,6)
6     FORMAT(//,16X,47HTEMPERATURE (T, R) VS REACTOR VOLUME (V, FT**3))
      IP=0
      RETURN
      END
HYDRODEALKYLATION OF TOLUENE TO BENZENE
0.        750.      25.
    2  100    3    1  REL 0.001
END OF RUNS
*APP REACT07
      SUBROUTINE INITAL
C...
C...  FIRST-ORDER KINETICS OF CONSECUTIVE, IRREVERSIBLE REACTIONS
C...
C...  THE RATES OF THE FIRST-ORDER, CONSECUTIVE, IRREVERSIBLE REACTIONS
C...
C...                A  --------+  B  --------+  C
C...                      (K1)          (K2)
C...
C...  ARE GIVEN BY THE DIFFERENTIAL EQUATIONS
C...
C...                         DX/DT = -K1*X
C...
C...                      DY/DT = K1*X - K2*Y                        (2)
C...
C...                          DZ/DT = K2*Y                           (3)
C...
C...                   X(0) = 1, Y(0) = Z(0) = 0               (4)(5)(6)
C...
C...  WHERE
C...
C...     X = A/A0
C...
C...     Y = B/A0
C...
C...     Z = C/A0
C...
C...     A,B,C  CONCENTRATIONS OF A, B AND C RESPECTIVELY
C...
C...     A0     INITIAL CONCENTRATION OF A
C...
C...     K1,K2  RATE CONSTANTS FOR THE FIRST AND SECOND REACTIONS
C...            RESPECTIVELY
C...
C...  THE NUMERICAL SOLUTIONS OF EQUATIONS (1) TO (3) ARE PLOTTED AND
C...  COMPARED WITH THE ANALYTICAL SOLUTIONS THROUGH PROGRAMMING IN
C...  SUBROUTINE PRINT
C...
      COMMON/T/T/Y/X,Y,Z/F/DXDT,DYDT,DZDT/PARM/K1,K2
      REAL K1,K2
C...
C...  SET THE RATE CONSTANTS
      K1=2.
      K2=1.
C...
C...  INITIAL CONDITIONS (4), (5) AND (6)
      X=1.
      Y=0.
      Z=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T/Y/X,Y,Z/F/DXDT,DYDT,DZDT/PARM/K1,K2
      REAL K1,K2
C...
C...  DIFFERENTIAL EQUATION (1)
C...  DX/DT = - K1*X
      DXDT=-K1*X
C...
C...  DIFFERENTIAL EQUATION (2)
C...  DY/DT = K1*X - K2*Y
      DYDT=K1*X-K2*Y
C...
C...  DIFFERENTIAL EQUATION (3)
C...  DZ/DT = K2*Y
      DZDT=K2*Y
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T/Y/X,Y,Z/F/DXDT,DYDT,DZDT/PARM/K1,K2
      REAL K1,K2
      DIMENSION TPLOT(51),CPLOT(3,51)
      DATA IP/0/
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(12H           T,12H           X,12H     X(ANAL),
     1                       12H           Y,12H     Y(ANAL),
     2                       12H           Z,12H     Z(ANAL))
C...
C...  COMPUTE THE ANALYTICAL SOLUTIONS
      EXPK1T=EXP(-K1*T)
      EXPK2T=EXP(-K2*T)
      XA=EXPK1T
      YA=K1/(K2-K1)*(EXPK1T-EXPK2T)
      ZA=1.-K2/(K2-K1)*EXPK1T+K1/(K2-K1)*EXPK2T
C...
C...  OTHER INTERESTING PROPERTIES OF THE ANALYTICAL SOLUTION WHICH
C...  CAN BE COMPARED WITH THE NUMERICAL SOLUTION INCLUDE
C...
C...     (1)  THE TIME FOR THE MAXIMUM VALUE OF Y IS
C...
C...          TMAX = (1/(K2-K1))*LN(K2/K1)
C...
C...     (2)  THE MAXIMUM VALUE OF Y FOR T = TMAX IS
C...
C...          YMAX = (K1/K2)**(K2/(K2-K1))
C...
C...     (3)  THE Z VS T CURVE HAS A POINT OF INFLECTION (I.E. D2Z/DT2
C...          = 0) AT T = TMAX
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      WRITE(NO,3)T,X,XA,Y,YA,Z,ZA
3     FORMAT(F12.2,6F12.4)
C...
C...  STORE THE NUMERICAL SOLUTIONS FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TPLOT(IP)=T
      CPLOT(1,IP)=X
      CPLOT(2,IP)=Y
      CPLOT(3,IP)=Z
      IF(IP.LT.51)RETURN
C...
C...  PLOT THE CONCENTRATIONS X, Y, Z VS T
      CALL PLOTS(3,IP,TPLOT,CPLOT)
C...
C...  PRINT A LABEL FOR THE PLOT INCLUDING TMAX AND YMAX
      TMAX=(1./(K2-K1))*ALOG(K2/K1)
      YMAX=(K1/K2)**(K2/(K2-K1))
      WRITE(NO,5)TMAX,YMAX
5     FORMAT(//,15X,9H 1 - X(T),3X,9H 2 - Y(T),3X,9H 3 - Z(T),
     1           3X,8H TMAX = ,E9.2,3X,8H YMAX = ,E9.2)
C...
C...  REPLOT THE CONCENTRATIONS X, Y, Z VS T IN A SMALLER FORMAT
      CALL TPLOTS(3,IP,TPLOT,CPLOT)
      WRITE(NO,6)TMAX,YMAX
6     FORMAT(//,25X,9H 1 - X(T),3X,9H 2 - Y(T),3X,9H 3 - Z(T),/,
     1          23X,8H TMAX = ,E9.2,3X,8H YMAX = ,E9.2)
      IP=0
      RETURN
      END
BOUDART, M., KINETICS OF CHEM PROCESSES, PP. 63-67, PRENTICE-HALL
0.        5.0       0.1
    3  100    3    1  ABS 0.00001
END OF RUNS
*APP REACT08
      SUBROUTINE INITAL
C...
C...  DECAY OF PLUTONIUM 239
C...
C...  THE CONTROVERSY SURROUNDING THE BREEDER REACTOR IS DUE IN LARGE
C...  PART TO THE NATURE OF THE PRINCIPAL PRODUCT OF THE BREEDING RE-
C...  TION, PLUTONIUM 239.  SPECIFICALLY, RELATIVELY PURE PLUTONIUM CAN
C...  BE USED IN THE PRODUCTION OF NUCLEAR WEAPONS, THEREBY INCREASING
C...  THE LIKELIHOOD OF NUCLEAR WAR OR BLACKMAIL.  ALSO, AS THIS PROGRAM
C...  DEMONSTRATES, THE HALF-LIFE OF PLUTONIUM IS EXTREMELY LONG SO
C...  THE QUANTITY OF THIS SUBSTANCE DOES NOT DECREASE SIGNIFICANTLY
C...  WITH TIME.  IN OTHER WORDS, THE THREAT OF PLUTONIUM COULD BE WITH
C...  US A VERY LONG TIME.
C...
      COMMON/T/T,NFIN,NORUN/Y/A/F/DADT/PARM/K,IP
      REAL K
      IP=0
C...
C...  SET THE DECAY CONSTANT, INITIAL QUANTITY OF PU(239)
      K=0.693/24400.
      A=1.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NORUN/Y/A/F/DADT/PARM/K,IP
      REAL K
C...
C...  COMPUTE THE RATE OF DECAY OF PU(239)
      DADT=-K*A
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NORUN/Y/A/F/DADT/PARM/K,IP
      REAL K
C...
C...  DIMENSION THE ARRAYS FOR STORING THE NUMERICAL SOLUTION, THE ERROR
C...  IN THE NUMERICAL SOLUTION
      DIMENSION TP(101),AP(101),EP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL OUTPUT
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(8X,4HTIME,5X,7HA (NUM),3X,9HA (EXACT),7X,5HERROR)
C...
C...  STORE THE NUMERICAL SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TP(IP)=T
      AP(IP)=A
C...
C...  COMPUTE THE EXACT SOLUTION SOLUTION AND THE ERROR IN THE NUMERICAL
C...  SOLUTION
      EX=AP(1)*EXP(-K*T)
      ERR=(A-EX)/EX
C...
C...  STORE THE ERROR IN THE NUMERICAL SOLUTION FOR SUBSEQUENT PLOTTING
      EP(IP)=ERR
C...
C...  PRINT THE NUMERICAL AND EXACT SOLUTIONS, THE ERROR IN THE NUMER-
C...  ICAL SOLUTION
      WRITE(NO,2)T,A,EX,ERR
2     FORMAT(F12.0,2F12.4,F12.6)
C...
C...  PLOT THE NUMERICAL SOLUTION, THE ERROR IN THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL PLOTS(1,IP,TP,AP)
      WRITE(NO,3)
3     FORMAT(//,16X,48HNUMERICAL SOLUTION (A) VS TIME (T) IN YEARS     )
      CALL PLOTS(1,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(//,16X,48HERROR IN NUMERICAL SOLUTION (ERR) VS TIME (T)   )
      IP=0
      RETURN
      END
RADIOACTIVE DECAY OF PLUTONIUM 239
0.        200000.   2000.
    1  100    1    1  REL 0.001
END OF RUNS
*APP REACT09
      SUBROUTINE INITAL
C...
C...  THREE CONTINUOUS STIRRED TANK REACTORS WITH PI CONTROL
C...
C...  THE PROBLEM IS COMPLETELY DEFINED IN THE REFERENCE CITED ON THE
C...  FIRST DATA LINE.  THEREFORE ONLY THE EQUATIONS ARE SUMMARIZED
C...  BELOW
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1, CA1(0) = 0.4      (1)(2)
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2, CA2(0) = 0.2      (3)(4)
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3, CA3(0) = 0.1      (5)(6)
C...
C...     DEI/DT = (1/TAUI)*E, EI(0) = 0                           (7)(8)
C...
C...     CA0 = CAD + CAM, CAM = 0.4 + KC*(E + EI)                (9)(10)
C...
C...  FOR WHICH THE MODEL PARAMETERS HAVE THE NUMERICAL VALUES
C...
C...     TAU     2 MINUTES
C...
C...     K       0.5 1/MIN
C...
C...     TAUI    4 MIN
C...
C...     KC      0, 20, 30, 40 (4 CASES TO BE RUN)
C...
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  SET THE MODEL PARAMETERS
      TAU=2.0
      K=0.5
      TAUI=4.0
      IF(NORUN.EQ.1)KC=0.0
      IF(NORUN.EQ.2)KC=20.
      IF(NORUN.EQ.3)KC=30.
      IF(NORUN.EQ.4)KC=40.
      IP=0
C...
C...  SET THE DISTURBANCE
      CAD=0.6
C...
C...  SET THE INITIAL CONDITIONS, EQUATIONS (2), (4), (6), (8)
      CA1=0.4
      CA2=0.2
      CA3=0.1
       EI=1.0E-10
C...
C...  SET THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  COMPUTE THE MODEL ALGEBRAIC VARIABLES
      E=0.1-CA3
      CAM=0.4+KC*(E+EI)
      CA0=CAD+CAM
C...
C...  COMPUTE THE MODEL DERIVATIVES DEFINED BY EQUATIONS (1), (3), (5),
C...  (7)
      DCA1DT=(1./TAU)*(CA0-CA1)-K*CA1
      DCA2DT=(1./TAU)*(CA1-CA2)-K*CA2
      DCA3DT=(1./TAU)*(CA2-CA3)-K*CA3
       DEIDT=(1./TAUI)*E
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON     /T/     T, NSTOP, NORUN
     1           /Y/   CA1,   CA2,   CA3,    EI
     2           /F/DCA1DT,DCA2DT,DCA3DT, DEIDT
     3           /C/   TAU,     K,  TAUI,    KC,   CAD,    IP,     E
      REAL               K,    KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51),CA3P(4,51),EP(4,51)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,9X,3HCA1,9X,3HCA2,9X,3HCA3,7X,5HERROR)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,CA1,CA2,CA3,E
2     FORMAT(F10.1,3F12.4,F12.5)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      CA3P(NORUN,IP)=CA3
        EP(NORUN,IP)=E
        TP(IP)=T
C...
C...  TEST FOR THE END OF A RUN
      IF(IP.LT.51)RETURN
C...
C...  TEST FOR THE END OF THE FOURTH RUN
      IF(NORUN.LT.4)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL PLOTS(4,IP,TP,CA3P)
      WRITE(NO,3)
3     FORMAT(1H ,//,48H CA3(T) VS T FOR KC = 0, 20, 30, 40             )
      CALL PLOTS(4,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,48H E(T) VS T FOR KC = 0, 20, 30, 40               )
      RETURN
      END
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
LUYBEN, W L, PROCESS MODELING, SIMULATION AND CONTROL FOR CHES, PROB 4-1
0.        10.0      0.2
    4 1000    1    1  REL 0.001
END OF RUNS
*APP REACT10
      SUBROUTINE INITAL
C...
C...  THREE CSTR*S WITH PROPORTIONAL-INTEGRAL CONTROL
C...
C...  THREE CSTR*S (CONTINUOUS-STIRRED-TANK REACTORS) ARE MODELLED
C...  BY THE FOLLOWING DIFFERENTIAL EQUATIONS
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION WHICH STEPS FROM 0.4 TO 0.6
C...               AT T = 0 (IF CAD REMAINS AT 0.4, THE ENTIRE SYSTEM
C...               REMAINS AT STEADY STATE, I.E., THE DERIVATIVES IN THE
C...               DIFFERENTIAL EQUATIONS REMAIN AT ZERO OR DCA1/DT =
C...               DCA2/DT = DCA3/DT = 0)
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM = CAMSS + AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     CAMSS     STEADY STATE VALUE OF CAM = 0.4
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION CA3 = CA3SET - CA3
C...
C...     CA3SET    SET POINT FOR CA3 = 0.1
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE TO BE SOLVED FOR THE FOLLOWING CASES
C...
C...     (1)  CAD = 0.4 (NORUN = 1)
C...          TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE.
C...          ALL SUBSEQUENT RUNS ARE FOR CAD = 0.6, I.E., A +0.2 STEP
C...          DISTURBANCE IN THE ENTERING CONCENTRATION
C...
C...     (2)  AK =  0, TAUI = INFINITY (NORUN = 2)
C...
C...     (3)  AK = 20, TAUI = INFINITY (NORUN = 3)
C...
C...     (4)  AK = 40, TAUI = INFINITY (NORUN = 4)
C...
C...     (5)  AK = 20, TAUI = 5        (NORUN = 5)
C...
C...     (6)  AK = 40, TAUI = 5        (NORUN = 6)
C...
C...  FOR ALL OF THE RUNS, THE INITIAL CONDITIONS FOR THE DIFFERENTIAL
C...  EQUATIONS ARE
C...
C...     CA1(0) = 0.4, CA2(0) = 0.2, CA3(0) = 0.1
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
C...
C...  THE FOLLOWING PARAMETERS VARY FROM RUN TO RUN
      GO TO(1,2,3,4,5,6),NORUN
C...
C...  RUN (1)
1     CAD=0.4
      AK=0.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (2)
2     CAD=0.6
      AK=0.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (3)
3     CAD=0.6
      AK=20.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (4)
4     CAD=0.6
      AK=40.
      TAUI=1.0E+10
      GO TO 10
C...
C...  RUN (5)
5     CAD=0.6
      AK=20.
      TAUI=5.
      GO TO 10
C...
C...  RUN (6)
6     CAD=0.6
      AK=40.
      TAUI=5.
      GO TO 10
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
10    CA(1)=0.4
      CA(2)=0.2
      CA(3)=0.1
      ERINT=0.
C...
C...  INITIALIZE THE REMAINDER OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  MODEL ALGEBRA
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
C...
C...  DIFFERENTIAL EQUATIONS
      DCADT(1)=(CA0  -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA(1)-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA(2)-CA(3))/TAU-RK*CA(3)
C...
C...  NOTE THAT THE DIFFERENTIAL EQUATION D(ERINT)/DT = E IS ALREADY
C...  PROGRAMMED BY SETTING E WHICH APPEARS IN THE DERIVATIVE SECTION
C...  (COMMON/F/ ABOVE).  THE INTEGRATED RESULT, ERINT, IN COMMON/Y/
C...  CAN THEN BE USED IN THE CONTROLLER EQUATION FOR CAM
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(6,101), EP(6,101),    TP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,11X,1HE,7X,5HERINT,7X,5HCA(1),4X,8HDCADT(1),
     1                                 7X,5HCA(2),4X,8HDCADT(2),
     2                                 7X,5HCA(3),4X,8HDCADT(3))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP)
     1  WRITE(NO,2)T,E,ERINT,(CA(I),DCADT(I),I=1,3)
2     FORMAT(F10.1,8F12.3)
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(NORUN,IP)=CA(3)
       EP(NORUN,IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      IF(NORUN.LT.6)RETURN
      CALL PLOTS(6,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,46H CA3(T) VS T FOR THE SIX RUNS LISTED IN INITAL)
      CALL PLOTS(6,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,44H E(T) VS T FOR THE SIX RUNS LISTED IN INITAL)
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        10.       0.1
    4  100    1    1  REL 0.001
END OF RUNS
*APP REACT11
      SUBROUTINE INITAL
C...
C...  TRANSIENT RESPONSE OF TWO CSTR*S WITH VARIABLE HOLDUP
C...
C...  THIS PROBLEM COULD ALTERNATIVELY BE CALLED
C...
C...  ERRORS INTRODUCED BY A NONCENTRALIZED INTEGRATION
C...
C...  THIS PROBLEM HAS A TWO-FOLD PURPOSE
C...
C...     (1)  DYNAMIC ANALYSIS OF TWO CONTINUOUS STIRRED TANK REACTORS
C...          (CSTR*S) WITH VARIABLE HOLDUP
C...
C...  AND
C...
C...     (2)  AN INVESTIGATION OF ERRORS INTRODUCED BY THE NONCENTRAL
C...          INTEGRATION OF ORDINARY DIFFERENTIAL EQUATIONS (ODES).
C...          NONCENTRAL INTEGRATION REFERS TO THE POSSIBILITY OF NOT
C...          ADVANCING THE DEPENDENT VARIABLES OF AN ODE SYSTEM SIMUL-
C...          TANEOUSLY AS THE NUMERICAL INTEGRATION PROCEEDS SO THAT
C...          SOME DEPENDENT VARIABLES ARE AHEAD OF OTHERS WITH RESPECT
C...          TO THE INDEPENDENT VARIABLE.  IN GENERAL THIS PRODUCES AN
C...          ERROR IN THE NUMERICAL DEPENDENT VARIABLE VECTOR SINCE
C...          THE SPECIFICATION OF SIMULTANEOUS ODES MEANS THAT THEY
C...          HAVE A COMMON INDEPENDENT VARIABLE, E.G., THEY MOVE ALONG
C...          A COMMON TIME AXIS AND SOME DEPENDENT VARIABLES SHOULD NOT
C...          MOVE AHEAD OF OTHER DEPENDENT VARIABLES WITH RESPECT TO
C...          TIME.
C...
C...  THE DYNAMIC MATERIAL BALANCE EQUATIONS FOR THE TWO CSTR*S WITH
C...  VARIABLE HOLDUPS ARE
C...
C...          DV1/DT = F0 - F1, V1(0) = 100                       (1)(2)
C...
C...          DV2/DT = F1 - F2, V2(0) = 25                        (3)(4)
C...
C...          D(V1*CA1)/DT = F0*CA0 - F1*CA1 - V1*RK1*CA1**2,        (5)
C...
C...                                        CA1(0) = 0               (6)
C...
C...          D(V2*CA2)/DT = F1*CA1 - F2*CA2 - V2*RK2*CA2**2,        (7)
C...
C...                                        CA2(0) = 0               (8)
C...
C...  THE CSTR*S ARE ASSUMED TO OPERATE ISOTHERMALLY WITH A SECOND-ORDER
C...  REACTION
C...
C...  THE PROGRAMMING OF EQUATIONS (1) TO (8) IS FOR BOTH A DSS/2 SOLU-
C...  TION AND AN EULER INTEGRATION WITH AND WITHOUT CENTRAL INTEGRATION
C...  FOR TWO TIME STEPS, DT = 5 AND 10.  THUS THERE ARE FOUR EULER
C...  INTEGRATIONS, DONE IN SUBROUTINE EULER, FOR COMPARISON WITH THE
C...  DSS/2 SOLUTION
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/        V1,        V2,     V1CA1,     V2CA2
     2      /F/     DV1DT,     DV2DT,    DV1CA1,    DV2CA2
     3      /C/        F0,       CA0,       RK1,       RK2,        S1,
     4                 S2,       VK1,       VK2,       CA1,       CA2,
     5                 H1,        H2,        F1,        F2
C...
C...  INITIALIZE THE PROBLEM PARAMETERS
         F0=1.
         CA0=0.005
         RK1=1.0
         RK2=1.0
         S1=10.0
         S2=10.0
         VK1=0.5
         VK2=0.5
         CA1=0.0
         CA2=0.0
C...
C...  PROBLEM INITIAL CONDITIONS
         V1=100.0
         V2=25.0
         V1CA1=V1*CA1
         V2CA2=V2*CA2
C...
C...  INITIALIZE THE REMAINING VARIABLES IN THE PROBLEM BY A CALL TO
C...  SUBROUTINE DERV
         CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/        V1,        V2,     V1CA1,     V2CA2
     2      /F/     DV1DT,     DV2DT,    DV1CA1,    DV2CA2
     3      /C/        F0,       CA0,       RK1,       RK2,        S1,
     4                 S2,       VK1,       VK2,       CA1,       CA2,
     5                 H1,        H2,        F1,        F2
C...
C...  COMPUTE SOME INTERMEDIATE ALGEBRAIC VARIABLES
         H1=V1/S1
         H2=V2/S2
         F1=VK1*SQRT(ABS(H1-H2))*(H1-H2)/ABS(H1-H2)
         F2=VK2*SQRT(H2)
C...
C...  COMPUTE THE CONCENTRATIONS CA1 AND CA2 EXPLICITLY
         CA1=V1CA1/V1
         CA2=V2CA2/V2
C...
C...  PROBLEM DIFFERENTIAL EQUATIONS
         DV1DT=F0-F1
         DV2DT=F1-F2
         DV1CA1=F0*CA0-F1*CA1-V1*RK1*CA1**2
         DV2CA2=F1*CA1-F2*CA2-V2*RK2*CA2**2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/        V1,        V2,     V1CA1,     V2CA2
     2      /F/     DV1DT,     DV2DT,    DV1CA1,    DV2CA2
     3      /C/        F0,       CA0,       RK1,       RK2,        S1,
     4                 S2,       VK1,       VK2,       CA1,       CA2,
     5                 H1,        H2,        F1,        F2
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
         IF(T.LT.5.)WRITE(NO,1)
1        FORMAT(11X,1HT,10X,2HV1,9X,3HCA1,10X,2HF1,10X,2HH1,
     2                  10X,2HV2,9X,3HCA2,10X,2HF2,10X,2HH2)
C...
C...  PRINT THE NUMERICAL SOLUTION
         WRITE(NO,2)T,V1,CA1,F1,H1,V2,CA2,F2,H2
2        FORMAT(F12.1,8E12.3)
C...
C...  AT THE END OF THE RUN, CALL SUBROUTINE EULER TO DO AN EULER INTE-
C...  GRATION WITH AND WITHOUT CENTRALIZED INTEGRATION
         IF(T.LT.295.)RETURN
         CALL EULER
      RETURN
      END
      SUBROUTINE EULER
C...
C...  SUBROUTINE EULER PERFORMS AN EULER INTEGRATION WITH AND WITHOUT
C...  CENTRALIZED INTEGRATION TO DEMONSTRATE THE CORRECT ORDERING OF
C...  THE STATEMENTS.  FOUR RUNS ARE PROGRAMMED
C...
C...     (1)  (NORUN = 1)
C...
C...          NONCENTRAL EULER INTEGRATION, STEP SIZE = 10
C...
C...     (2)  (NORUN = 2)
C...
C...          NONCENTRAL EULER INTEGRATION, STEP SIZE =  5
C...
C...     (3)  (NORUN = 3)
C...
C...             CENTRAL EULER INTEGRATION, STEP SIZE = 10
C...
C...     (4)  (NORUN = 4)
C...
C...             CENTRAL EULER INTEGRATION, STEP SIZE =  5
C...
C...  THUS THE QUALITY OF THE FOUR SOLUTIONS SHOULD INCREASE WITH NORUN,
C...  I.E., NORUN = 1 IS A NONCENTRAL INTEGRATION WITH THE LARGER IN-
C...  TEGRATION STEP SIZE WHILE NORUN = 4 IS A CENTRAL INTEGRATION WITH
C...  THE SMALLER STEP SIZE
C...
C...  THE FOLLOWING COMMON CARD IS REQUIRED TO ACCESS THE OUTPUT DEVICE
C...  NUMBER, NO, FROM THE DSS/2 MAIN PROGRAM FOR USE IN THE WRITE
C...  STATEMENTS IN THIS SUBROUTINE
      COMMON/IO/        NI,        NO
C...
C...  STEP THROUGH THE FOUR RUNS
         DO 12 NORUN=1,4
         IF((NORUN.EQ.1).OR.(NORUN.EQ.3))DT=10.
         IF((NORUN.EQ.2).OR.(NORUN.EQ.4))DT=5.0
C...
C...  INITIALIZE THE PROBLEM PARAMETERS
         F0=1.
         CA0=0.005
         RK1=1.0
         RK2=1.0
         S1=10.0
         S2=10.0
         VK1=0.5
         VK2=0.5
         CA1=0.0
         CA2=0.0
C...
C...  PROBLEM INITIAL CONDITIONS
         V1=100.0
         V2=25.0
         V1CA1=V1*CA1
         V2CA2=V2*CA2
C...
C...  INITIALIZE THE RUNNING VALUE OF THE INDEPENDENT VARIABLE
         T=-DT
C...
C...  PRINT A DESCRIPTIVE LABEL FOR EACH OF THE FOUR RUNS
         IF(NORUN.EQ.1)WRITE(NO,101)
         IF(NORUN.EQ.2)WRITE(NO,102)
         IF(NORUN.EQ.3)WRITE(NO,103)
         IF(NORUN.EQ.4)WRITE(NO,104)
101      FORMAT(1H ,//,45H NONCENTRAL EULER INTEGRATION, DT = 10       )
102      FORMAT(1H ,//,45H NONCENTRAL EULER INTEGRATION, DT = 5        )
103      FORMAT(1H ,//,45H    CENTRAL EULER INTEGRATION, DT = 10       )
104      FORMAT(1H ,//,45H    CENTRAL EULER INTEGRATION, DT = 5        )
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
         WRITE(NO,110)
110      FORMAT(11X,1HT,10X,2HV1,9X,3HCA1,10X,2HF1,10X,2HH1,
     2                  10X,2HV2,9X,3HCA2,10X,2HF2,10X,2HH2)
C...
C...  BEGIN THE EULER INTEGRATION BY INCREMENTING THE INDEPENDENT
C...  VARIABLE
11       T=T+DT
C...
C...  COMPUTE SOME INTERMEDIATE ALGEBRAIC VARIABLES
         H1=V1/S1
         H2=V2/S2
         F1=VK1*SQRT(ABS(H1-H2))*(H1-H2)/ABS(H1-H2)
         F2=VK2*SQRT(H2)
C...
C...  COMPUTE THE CONCENTRATIONS CA1 AND CA2 EXPLICITLY
         CA1=V1CA1/V1
         CA2=V2CA2/V2
C...
C...  PRINT THE NUMERICAL SOLUTION
         WRITE(NO,100)T,V1,CA1,F1,H1,V2,CA2,F2,H2
100      FORMAT(F12.1,8E12.3)
C...
C...  FOR NORUN = 1 AND 2, A NONCENTRAL INTEGRATION IS PERFORMED, I.E.,
C...  V1 AND V2 ARE ADVANCED IN T, THEN USED TO CALCULATE THE OTHER
C...  DEPENDENT VARIABLES V1CA1 AND V2CA2
         GO TO(1,1,2,2),NORUN
1        V1=V1+(F0-F1)*DT
         V2=V2+(F1-F2)*DT
         V1CA1=V1CA1+(F0*CA0-F1*CA1-V1*RK1*CA1**2)*DT
         V2CA2=V2CA2+(F1*CA1-F2*CA2-V2*RK2*CA2**2)*DT
         GO TO 10
C...
C...  FOR NORUN = 3 AND 4, A CENTRAL INTEGRATION IS PERFORMED, I.E.,
C...  ALL FOUR DEPENDENT VARIABLES, V1, V2, V1CA1, AND V2CA2, ADVANCE
C...  IN T TOGETHER
2        V1CA1=V1CA1+(F0*CA0-F1*CA1-V1*RK1*CA1**2)*DT
         V2CA2=V2CA2+(F1*CA1-F2*CA2-V2*RK2*CA2**2)*DT
         V1=V1+(F0-F1)*DT
         V2=V2+(F1-F2)*DT
10       IF(T.LT.300)GO TO 11
12       CONTINUE
C...
C...  AT THE END OF THE FOURTH RUN, THE FOUR EULER INTEGRATIONS CAN BE
C...  COMPARED WITH THE DSS/2 INTEGRATION PROGRAMMED IN THE USUAL WAY
C...  IN SUBROUTINES INITAL, DERV AND PRINT
      RETURN
      END
ERRORS IN A NONCENTRAL INTEGRATION
0.        300.      10.
    4  100    1    1  REL 0.001
END OF RUNS
*APP REACT12
      SUBROUTINE INITAL
C...
C...  POLYMERIZATION WITH TWO INITIATORS
C...
C...  THE FOLLOWING FIRST-ORDER, INITIAL-VALUE ORDINARY DIFFERENTIAL
C...  EQUATION GIVES THE RATE OF POLYMERIZATION WITH TWO INITIATORS
C...
C...     RP = -DM/DT = (KP/KT**0.5)*M*SUM
C...
C...     SUM = (F1*K1*I01)**0.5*(EXP(-0.5*K1*T)) +
C...
C...           (F2*K2*I02)**0.5*(EXP(-0.5*K2*T))
C...
C...     WHERE
C...
C...     RP       RATE OF POLYMERIZATION
C...
C...     M        MONOMER CONCENTRATION
C...
C...     T        TIME
C...
C...     KP       PROPAGATION RATE CONSTANT
C...
C...     KT       TERMINATION RATE CONSTANT
C...
C...     F1,F2    FRACTIONAL EFFICIENCY OF INITIATORS 1 AND 2
C...
C...     K1,K2    RATE CONSTANTS FOR INITIATORS 1 AND 2
C...
C...     I01,I02  INITIAL CONCENTRATIONS OF INITIATORS 1 AND 2
C...
C...  THE FOLLOWING CONSTANTS APPLY
C...
C...  F1 = F2 = 1, KP = 27300, KT**0.5 = 2830, K1 = 0.2465, K2 = 0.0947
C...
C...  THE INITIAL CONDITION FOR THE DIFFERENTIAL EQUATION (INITIAL
C...  CONCENTRATION OF MONOMER) IS: M(0) = 10.
C...
C...  THE SOLUTION OF INTEREST IS THE ONE FOR WHICH THE POLYMERIZATION
C...  RATE, -DM/DT, IS AS CONSTANT AS POSSIBLE (THIS MEANS THE RATE OF
C...  HEAT GENERATION IS ALSO NEARLY CONSTANT TO FACILITATE THE REMOVAL
C...  OF HEAT FROM THE POLYMERIZATION REACTOR).  TO INVESTIGATE THIS
C...  REQUIREMENT OF A RELATIVELY CONSTANT -DM/DT, THE DIFFERENTIAL
C...  EQUATION IS INTEGRATED FOR FOUR CASES, A LOW AND A HIGH VALUE
C...  OF EACH OF THE INITIAL INITIATOR CONCENTRATIONS, I01 AND I02.
C...  THE FEASIBLE RANGES OF I01 AND I02 ARE
C...
C...     0.001 LE I01 LE 0.5, 0.01 LE I02 LE 0.5
C...
C...  OBVIOUSLY, THERE IS NO UNIQUE SOLUTION TO THIS PROBLEM.  ALSO
C...  CONSIDERATION OF THE RIGHT HAND SIDE OF THE DIFFERENTIAL EQUATION
C...  INDICATES THERE IS NO SOLUTION FOR -DM/DT TRULY CONSTANT.  THUS,
C...  THE OPTIMUM SOLUTION IS ONE WHICH MAXIMIZES -DM/DT WITH A MINIMUM
C...  VARIATION IN TIME, T, OVER THE FULL INTERVAL IN TIME.
C...
C...  FOUR RUNS ARE PROGRAMMED WITH 0 LE T LE 1, AND FOUR RUNS ARE
C...  PROGRAMMED WITH 0 LE T LE 4.  THE PURPOSE OF THE SECOND SET
C...  OF FOUR RUNS IS TO ESTABLISH WHETHER THE FINDINGS FOR THE SHORT
C...  TIME SCALE (FIRST SET OF FOUR RUNS) ALSO APPLY TO THE LONG TIME
C...  SCALE (SECOND SET OF FOUR RUNS).
C...
C...  THE CONSTANTS IN THIS PROBLEM APPLY TO STYRENE AS THE MONOMER IN
C...  TOLUENE AS A SOLVENT, WITH T-BUTYL PEROXY PIUALATE AS INITIATOR
C...  1 AND BENZOYL PEROXIDE AS INITIATOR 2.
C...
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      M
     2      /F/   DMDT
     3      /C/     KP,    I01,    I02,     K1,     K2,     M0,     IP
      REAL          KP,    I01,    I02,     K1,     K2,     M0,      M
C...
C...  SET THE MODEL PARAMETERS
      F1=1.
      F2=1.
      KP=27300.
      KT=2830.
      K1=0.2465
      K2=0.0947
C...
C...  STEP THROUGH FOUR RUNS CORRESPONDING TO DIFFERENT INITIATOR
C...  CONCENTRATIONS
      IF((NORUN.EQ.1).OR.(NORUN.EQ.5))GO TO 1
      IF((NORUN.EQ.2).OR.(NORUN.EQ.6))GO TO 2
      IF((NORUN.EQ.3).OR.(NORUN.EQ.7))GO TO 3
      IF((NORUN.EQ.4).OR.(NORUN.EQ.8))GO TO 4
1     I01=0.5
      I02=0.5
      GO TO 10
2     I01=0.001
      I02=0.01
      GO TO 10
3     I01=0.5
      I02=0.01
      GO TO 10
4     I01=0.001
      I02=0.5
C...
C...  PRECOMPUTE SOME CONSTANTS TO SAVE COMPUTER TIME
10    KP=KP/KT
      I01=SQRT(F1*K1*I01)
      I02=SQRT(F2*K2*I02)
      K1=0.5*K1
      K2=0.5*K2
C...
C...  INITIAL CONDITION
      M0=10.
       M=M0
C...
C...  INITIALIZE THE DERIVATIVE, -DM/DT
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      M
     2      /F/   DMDT
     3      /C/     KP,    I01,    I02,     K1,     K2,     M0,     IP
      REAL          KP,    I01,    I02,     K1,     K2,     M0,      M
C...
C...  DIFFERENTIAL EQUATION
      DMDT=-KP*M*(I01*EXP(-K1*T)+I02*EXP(-K2*T))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,   NFIN,  NORUN
     1      /Y/      M
     2      /F/   DMDT
     3      /C/     KP,    I01,    I02,     K1,     K2,     M0,     IP
      REAL          KP,    I01,    I02,     K1,     K2,     M0,      M
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(21),P1(4,21),P2(4,21),P3(4,21)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(1H ,6X,4HTIME,11X,1HM,6X,6HF CONV,7X,5HDM/DT)
C...
C...  COMPUTE THE FRACTIONAL CONVERSION
      FR=(M0-M)/M0
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,M,FR,DMDT
2     FORMAT(F11.2,3F12.5)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      NSTOR=NORUN
      IF(NORUN.GT.4)NSTOR=NORUN-4
      P1(NSTOR,IP)=M
      P2(NSTOR,IP)=-DMDT
      P3(NSTOR,IP)=FR
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.21)RETURN
      IF((NORUN.NE.4).AND.(NORUN.NE.8))RETURN
      CALL TPLOTS(NSTOR,IP,TP,P1)
      WRITE(NO,11)
11    FORMAT(1H ,/,35H M(T) VS T                         )
      CALL TPLOTS(NSTOR,IP,TP,P2)
      WRITE(NO,12)
12    FORMAT(1H ,/,35H -DM(T)/DT VS T                    )
      CALL TPLOTS(NSTOR,IP,TP,P3)
      WRITE(NO,13)
13    FORMAT(1H ,/,35H (M(0) - M(T))/M(0) VS T           )
      RETURN
      END
POLYMERIZATION WITH TWO INITIATORS
0.        1.0       0.05
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        1.0       0.05
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        1.0       0.05
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        1.0       0.05
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        4.0       0.2
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        4.0       0.2
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        4.0       0.2
    1 1000    1    1  REL 0.001
POLYMERIZATION WITH TWO INITIATORS
0.        4.0       0.2
    1 1000    1    1  REL 0.001
END OF RUNS
*APP REACT13
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A CSTR WITH COMPETING REACTIONS
C...
C...  A CSTR (CONTINUOUS STIRRED TANK REACTOR) IS OPERATED WITH TWO
C...  CONSECUTIVE, COMPETING REACTIONS.  THE OVERALL OBJECTIVE IN
C...  OPERATING THE REACTOR IS TO CONTROL IT SO AS TO MAXIMIZE THE
C...  YIELD OF THE INTERMEDIATE PRODUCT, B.  A PI (PROPORTIONAL-
C...  INTEGRAL) CONTROLLER IS USED TO CONTROL THE REACTOR TEMPERATURE
C...  VIA A STEAM COIL.  THE OBJECTIVE OF THIS SIMULATION IS TO DETER-
C...  MINE THE CONTROLLER PARAMETERS WHICH WILL MINIMIZE UNDESIRABLE
C...  TRANSIENTS, AND IF POSSIBLE, MAXIMIZE THE YIELD OF B.
C...
C...          K       K
C...           1       2
C...       A ----+ B ----+ C
C...
C...  THE ALGEBRAIC/DIFFERENTIAL EQUATIONS WHICH MODEL THE CSTR ARE
C...
C...  COMPONENT A BALANCE
C...
C...     V1*DA1/DT = M*(A0 - A1) - V1*RATE1
C...
C...  COMPONENT B BALANCE
C...
C...     V1*DB1/DT = M*(B0 - B1) + V1*RATE1 - V1*RATE2
C...
C...  ENERGY BALANCE
C...
C...     V1*CP*DT1/DT = M*CP*(T0 - T1) - DH1*V1*RATE1 - DH2*V1*RATE2
C...
C...                  + QS1
C...
C...  RATES OF REACTION
C...
C...     RATE1 = A1*K10*EXP(-E1/(R*T1))
C...
C...     RATE2 = B1*K20*EXP(-E2/(R*T1))
C...
C...  CONTROLLER EQUATIONS
C...
C...                                  T
C...     X1 = XS1 + KC*(ER1 + (1/TI1)*INT(ER1*DT))
C...                                  0
C...
C...     ER1 = TR1 - T1
C...
C...  VALVE/STEAM COIL EQUATIONS
C...
C...     FS1 = CV*X1*(PS1**0.5)
C...
C...     QS1 = FS1*DHS
C...
C...  WHERE
C...
C...   A1      CONCENTRATION OF REACTANT A IN THE CSTR (LB MOL/FT**3)
C...
C...   B1      CONCENTRATION OF INTERMEDIATE PRODUCT B IN THE CSTR
C...           (LB MOL/FT**3)
C...
C...   T1      TEMPERATURE IN THE CSTR (R)
C...
C...   T       TIME (S)
C...
C...   QS1     STEAM RATE TO THE HEATING COIL (LB/S)
C...
C...   V1      VOLUME OF LIQUID IN THE CSTR (100 FT**3)
C...
C...   CP      HEAT CAPACITY OF THE LIQUID (60 BTU/FT**3-R)
C...
C...   M       VOLUMTERIC FLOW RATE THROUGH THE CSTR (0.1 FT**3/S)
C...
C...   K10     FREQUENCY FACTOR FOR THE FIRST REACTION (3.0E+13/S)
C...
C...   K20     FREQUENCY FACTOR FOR THE SECOND REACTION (5.0E+13/S)
C...
C...   E1      ACTIVATION ENERGY FOR THE FIRST REACTION (44,700 BTU/
C...           LB MOL)
C...
C...   E2      ACTIVATION ENERGY FOR THE SECOND REACTION (40,000 BTU/
C...           LB MOL)
C...
C...   TR1     REFERENCE TEMPERATURE (600 R)
C...
C...   T0      ENTERING TEMPERATURE (575 R)
C...
C...   A0      ENTERING CONCENTRATION OF REACTANT A (1 LB MOL/FT**3)
C...
C...   B0      ENTERING CONCENTRATION OF INTERMEDIATE PRODUCT B (0 LB
C...           MOL/FT**3)
C...
C...   DH1     HEAT OF REACTION OF THE FIRST REACTION (10,000 BTU/
C...           MOL A REACTED)
C...
C...   DH2     HEAT OF REACTION OF THE SECOND REACTION (12,000 BTU/
C...           MOL B REACTED)
C...
C...   FS1     FLOW RATE OF STEAM IN THE COIL (LB/S)
C...
C...   CV      CONSTANT FOR THE VALVE ON THE STEAM LINE (0.70 (LB/SEC)
C...           /((LB/IN**2)**0.5))
C...
C...   X1      VALVE STEM POSITION (DIMENSIONLESS)
C...
C...   XS1     STEADY STATE VALVE STEM POSITION (0.5 DIMENSIONLESS)
C...
C...   PS1     STEAM PRESSURE (100 LB/IN**2)
C...
C...   DHS     STEAM HEAT OF VAPORIZATION (960 BTU/LB)
C...
C...   KC      CONTROLLER GAIN (1/R)
C...
C...   TI1     CONTROLLER INTEGRAL TIME (1/S)
C...
C...   R       GAS CONSTANT (1.987 BTU/LB MOL-R)
C...
C...  THE INITIAL CONDITIONS FOR THE SYSTEM ARE
C...
C...     A1(0) = 1, B1(0) = 0, T1(0) = 575
C...
C...  THE OBJECTIVE OF THE SIMULATION IS TWO-FOLD
C...
C...     (1)  TO DETERMINE VALUES OF THE CONTROLLER GAIN, KC, AND
C...     INTEGRAL TIME, TI1, WHICH WILL BRING THE REACTOR TO THE
C...     REFERENCE TEMPERATURE, TR1, QUICKLY WITHOUT SIGNIFICANT
C...     OVERSHOOT, AND ELIMINATE OFFSET (STEADY STATE ERROR).
C...
C...     (2)  TO DETERMINE THE OPTIMUM OPERATING TEMPERATURE, TR1, TO
C...     MAXIMIZE THE YIELD OF INTERMEDIATE PRODUCT, B.
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  SET THE MODEL PARAMETERS
      V1=100.
      M=0.1
      CP=60.
      DH1=10000.
      DH2=12000.
      K10=3.0E+13
      K20=5.0E+13
      E1=44700.
      E2=40000.
      XS1=0.5
      CV=0.70
      PS1=100.
      DHS=960.
      A0=1.
      B0=0.
      T0=575.
      R=1.987
      IP=0
C...
C...  SET THE CONTROLLER PARAMETERS
      GO TO(1,2,3,4),NORUN
1     TR1=600.
      AKC=0.
      TI1=1.0E+2
      GO TO 10
2     TR1=600.
      AKC=0.01
      TI1=1.0E+2
      GO TO 10
3     TR1=600.
      AKC=0.1
      TI1=1.0E+2
      GO TO 10
4     TR1=600.
      AKC=1.0
      TI1=1.0E+2
10    CONTINUE
C...
C...  SET THE MODEL INITIAL CONDITIONS
      A1=1.
      B1=0.
      T1=575.
      ER1I=0.
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  MODEL ALGEBRA
      ER1=TR1-T1
      X1=XS1+AKC*(ER1+(1./TI1)*ER1I)
      IF(X1.LT.0.)X1=0.
      IF(X1.GT.1.)X1=1.
      FS1=CV*X1*SQRT(PS1)
      QS1=FS1*DHS
C...
C...  DIFFERENTIAL EQUATIONS
      RATE1=V1*A1*K10*EXP(-E1/(R*T1))
      RATE2=V1*B1*K20*EXP(-E2/(R*T1))
      DA1DT=(1./V1)*(M*(A0-A1)-RATE1)
      DB1DT=(1./V1)*(M*(B0-B1)+RATE1-RATE2)
      DT1DT=(1./(V1*CP))*(M*CP*(T0-T1)-DH1*RATE1-DH2*RATE2+QS1)
C...
C...  NOTE THAT THE FOURTH DIFFERENTIAL EQUATION IS PROGRAMMED ABOVE
C...  WITH THE CALCULATION OF ER1 (D(ER1I)/DT = ER1)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/    A1,    B1,    T1,  ER1I
     2      /F/ DA1DT, DB1DT, DT1DT,   ER1
     3      /C/    V1,     M, RATE1, RATE2,    CP,   DH1,   DH2,
     4            K10,   K20,    E1,    E2,   XS1,    CV,   AKC,
     5            TI1,   PS1,   DHS,   FS1,   QS1,    A0,    B0,
     6             T0,   TR1,    X1,     R,    IP
      REAL          M,   K10,   K20
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION    B1P(4,101),   T1P(4,101),  ER1P(4,101),
     1             X1P(4,101),  QS1P(4,101),      TP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HB1,8X,2HT1,7X,3HER1,8X,2HX1,7X,3HQS1)
C...
C...  PRINT THE NUMERICAL SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 2
      WRITE(NO,3)T,B1,T1,ER1,X1,QS1
3     FORMAT(F10.1,F10.4,2F10.1,F10.4,F10.1)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
2     B1P(NORUN,IP)=B1
      T1P(NORUN,IP)=T1
      ER1P(NORUN,IP)=ER1
      X1P(NORUN,IP)=X1
      QS1P(NORUN,IP)=QS1
      TP(IP)=T
      IF(IP.NE.101)RETURN
C...
C...  PLOT THE SOLUTION AT THE END OF THE FOURTH RUN
      IF(NORUN.EQ.4)GO TO 4
      IP=0
      RETURN
C...
C...  PLOT THE SOLUTION
4     CALL TPLOTS(NORUN,IP,TP,B1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,12H  B1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,T1P)
      WRITE(NO,12)
12    FORMAT(1H ,//,12H  T1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,ER1P)
      WRITE(NO,13)
13    FORMAT(1H ,//,12H ER1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,X1P)
      WRITE(NO,14)
14    FORMAT(1H ,//,12H  X1 VS TIME)
      CALL TPLOTS(NORUN,IP,TP,QS1P)
      WRITE(NO,15)
15    FORMAT(1H ,//,12H QS1 VS TIME)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MAY HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, B1P,IP,3H*T*,8H* B1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, T1P,IP,3H*T*,8H* T1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ER1P,IP,3H*T*,8H*ER1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, X1P,IP,3H*T*,8H* X1(T)*,2H**,NORUN)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QS1P,IP,3H*T*,8H*QS1(T)*,2H**,NORUN)
C...
C...  ******************************************************************
C...
      RETURN
      END
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
CSTR WITH COMPETING CONSECUTIVE REACTIONS
0.        1000.     10.
    410000    1    1  REL 0.001
END OF RUNS
*APP REACT14
      SUBROUTINE INITAL
C...
C...  BIOSYNTHESIS OF THE ANTIBIOTIC ERYTHROMYCIN
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED (1) FOR THE BIOSYNTHESIS OF
C...  THE ANTIBIOTIC ERYTHROMYCIN
C...
C...     DX1/DT = C*X1*(1. - (X1/X1F)**A)                            (1)
C...
C...     DX2/DT = B1*X1 - B2*X2                                      (2)
C...
C...  WHERE
C...
C...     X1      CONCENTRATION OF BIOMASS IN THE FERMENTATION MEDIUM
C...             (GM/LITER)
C...
C...     X1F     FINAL (STEADY STATE) CONCENTRATION OF BIOMASS IN THE
C...             FERMENTATION MEDIUM (GM/LITER)
C...
C...     X2      ERYTHROMYCIN CONCENTRATION (RELATIVE UNITS)
C...
C...     A, B,   EMPIRICALLY DETERMINED CONSTANTS WHICH ARE FUNCTIONS
C...     B1,B2   OF THE TEMPERATURE AND PH OF THE FERMENTATION MEDIUM
C...
C...  EQUATIONS (1) AND (2) ARE INTEGRATED SUBJECT TO THE INITIAL CONDI-
C...  TIONS
C...
C...     X1(0) = 0.5, X2(0) = 0                                   (3)(4)
C...
C...  OVER THE INTERVAL 0 LE T LE 180 HOURS.
C...
C...  NOTE THAT AN ANALYTICAL SOLUTION FOR THIS MODEL CAN BE DERIVED
C...  RELATIVELY EASILY TO CHECK THE NUMERICAL SOLUTION.  THIS IS POSSI-
C...  BLE SINCE EQUATION (1) CONTAINS ONLY X1 AND THEREFORE CAN BE INTE-
C...  GRATED BY ITSELF.  X1 CAN THEN BE SUBSTITUTED IN EQUATION (2) AND
C...  X2 CAN BE DETERMINED BY INTEGRATING EQUATION (2).
C...
C...  (1)  CHERUY, A., AND A. DURAND, OPTIMIZATION OF ERYTHROMYCIN BIO-
C...       SYNTHESIS PH AND TEMPERATURE, THEORETICAL ASPECTS AND PRACTI-
C...       CAL APPLICATION, IN COMPUTER APPLICATIONS IN FERMENTATION
C...       TECHNOLOGY, W. B. ARMIGER (ED), JOHN WILEY AND SONS, N.Y.,
C...       1978
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      X(2)
     2      /F/   DXDT(2)
     3      /C/         A,        B1,        B2,         C,       X1F
C...
C...  DEFINE THE MODEL CONSTANTS
      A=1.4752
      B1=0.00195
      B2=0.09428
      C=0.0707
      X1F=15.0558
C...
C...  INITIAL CONDITIONS (3) AND (4)
      X(1)=0.5
      X(2)=0.
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      X(2)
     2      /F/   DXDT(2)
     3      /C/         A,        B1,        B2,         C,       X1F
C...
C...  DIFFERENTIAL EQUATION (1)
      DXDT(1)=C*X(1)*(1.-(X(1)/X1F)**A)
C...
C...  DIFFERENTIAL EQUATION (2)
      DXDT(2)=B1*X(1)-B2*X(2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/      X(2)
     2      /F/   DXDT(2)
     3      /C/         A,        B1,        B2,         C,       X1F
C...
C...  DIMENSION THE ARRAYS FOR STORING THE NUMERICAL SOLUTION
      DIMENSION    TP(37),   X1P(37),   X2P(37)
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED OUTPUT
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(11X,4HTIME,8X,7HBIOMASS,3X,12HERYTHROMYCIN,/)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,X(1),X(2)
2     FORMAT(F15.1,2F15.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TP(IP)=T
      X1P(IP)=X(1)
      X2P(IP)=X(2)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.37)RETURN
      CALL PLOTS(1,IP,TP,X1P)
      WRITE(NO,3)
3     FORMAT(1H ,//,48H BIOMASS (GM/LITER) VS TIME (HR)                )
      CALL PLOTS(1,IP,TP,X2P)
      WRITE(NO,4)
4     FORMAT(1H ,//,48H ERYTHROMYCIN (RELATIVE UNITS) VS TIME (HR)     )
      IP=0
      RETURN
      END
BIOSYNTHESIS OF ERYTHROMYCIN
0.        180.      5.0
    2 1000    1    1  REL 0.001
END OF RUNS
*APP REACT15
      SUBROUTINE INITAL
C...
C...  OXIDATION OF NAPHTHALENE TO PHTHALIC ANHYDRIDE
C...
C...  MODEL NO. 1 - THE RESISTANCE TO HEAT AND MASS TRANSFER AT THE
C...  CATALYST SURFACE IS NEGLECTED I.E. THE REACTION RATES ARE
C...  EVALUATED FROM THE BULK FLUID TEMPERATURE AND CONCENTRATION
C...
C...  NAPHTHALENE + OXYGEN = PHTHALIC ANHYDRIDE + CARBON DIOXIDE + WATER
C...  (FIRST REACTION)
C...
C...  PHTHALIC ANHYDRIDE + OXYGEN = CARBON DIOXIDE + WATER
C...  (SECOND REACTION)
C...
C...  CARBERRY, J. J., AND DONALD WHITE, ON THE ROLE OF TRANSPORT
C...  PHENOMENA IN CATALYTIC REACTOR DESIGN, DIGITAL SIMULATION OF
C...  NAPHTHALENE OXIDATION OVER V2O5, IND. ENG. CHEM. VOL. 61, NO. 7,
C...  PP. 27-35, JULY, 1969
C...
C...  CARBERRY, J. J., DESIGNING LABORATORY CATALYTIC REACTORS, IND.
C...  ENG. CHEM. VOL. 56, NO. 11, PP. 39-46, NOVEMBER, 1964
C...
C...  THE MATHEMATICAL MODEL CONSISTS OF THE SIMULTANEOUS MATERIAL AND
C...  HEAT BALANCE EQUATIONS
C...
C...      PF/PZ = 1/PEM*(P2F/PR2 + (1/R)*PF/PR) - DP*R1/(C0*U)       (1)
C...
C...  PT/PZ = 1/PEH*(P2T/PR2 + (1/R)*PT/PR) + DHR*DP/(RHO*CP*U*T0)   (2)
C...
C...  THE ASSOCIATED BOUNDARY CONDITIONS ARE
C...
C...                  PF(0,Z)/PR = PT(0,Z)/PR = 0                 (3)(4)
C...
C...      PF(RW,Z)/PR = 0, PT(RW,Z)/PR = BIW*(TW - T(RW,Z))       (5)(6)
C...
C...                      F(R,0) = T(R,0) = 1                     (7)(8)
C...
C...  F     DIMENSIONLESS NAPHTHALENE CONCENTRATION (NORMALIZED WITH
C...        RESPECT TO THE ENTERING NAPHTHALENE CONCENTRATION)
C...
C...  T     DIMENSIONLESS TEMPERATURE (NORMALIZED WITH RESPECT TO THE
C...        ENTERING TEMPERATURE)
C...
C...  R     DIMENSIONLESS RADIAL POSITION (NORMALIZED WITH RESPECT TO
C...        THE CATALYST PARTICLE DIAMETER)
C...
C...  Z     DIMENSIONLESS AXIAL POSITION (NORMALIZED WITH RESPECT TO THE
C...        CATALYST PARTICLE DIAMETER)
C...
C...  PEM   PECLET NUMBER FOR MASS TRANSFER (DP*U/DR) = 10
C...
C...  DP    CATALYST PARTICLE DIAMETER = 0.5 CM
C...
C...  CP    FLUID HEAT CAPACITY = (7.28 CAL/GM-MOL K)*(1/M0 GM-MOL/GM)
C...
C...  U     FLUID VELOCITY = 100 CM/SEC
C...
C...  PEH   PECLET NUMBER FOR HEAT TRANSFER (DP*U/KR) = 7
C...
C...  T0    ENTERING REACTOR TEMPERATURE = JACKET TEMPERATURE =
C...        643.2 K
C...
C...  BIM   BIOT NUMBER FOR MASS TRANSFER = 58.3
C...
C...  BIW   BIOT NUMBER FOR HEAT TRANSFER AT THE REACTOR WALL
C...        (HW*DP/(RHO*CP*KR)) = 0.001104
C...
C...  D     INTRAPHASE DIFFUSIVITY = 0.1 CM**2/SEC
C...
C...  DBDA  RATIO OF THE DIFFUSIVITY FOR THE PRODUCT (DB) TO THE
C...        DIFFUSIVITY FOR THE REACTANT (DA) = 0.93
C...
C...  E1    ACTIVATION ENERGY FOR THE FIRST REACTION = 38,000
C...        CAL/GM-MOL
C...
C...  E2    ACTIVATION ENERGY FOR THE SECOND REACTION = 20,000
C...        CAL/GM-MOL
C...
C...  RG    GAS CONSTANT = 1.987 CAL/GM-MOL K
C...
C...  DH1   HEAT OF REACTION FOR THE FIRST REACTION = 43,000
C...        CAL/GM-MOL
C...
C...  DH2   HEAT OF REACTION FOR THE SECOND REACTION = 87,000
C...        CAL/GM-MOL
C...
C...  NR    NUMBER OF RADIAL INCREMENTS FOR THE FINITE DIFFERENCE
C...        APPROXIMATIONS OF THE PARTIAL DIFFERENTIAL EQUATIONS = 5
C...
C...  M0    ENTERING FLUID AVERAGE MOLECULAR WEIGHT = 29.65 (CASE 1),
C...        32.826 (CASE 2) GM/GM-MOL
C...
C...  C0    ENTERING REACTANT CONCENTRATION = 1.517E-07 (CASE 1),
C...        7.585E-07 (CASE 2) GM-MOL/CC
C...
C...  RHO   ENTERING FLUID DENSITY = 273.16*M0/(22400*T0) GM/CC.
C...        THE DENSITY AT ANY POINT IN THE REACTOR CAN BE CORRECTED
C...        FOR TEMPERATURE MERELY BY DIVIDING THE ENTERING DENSITY,
C...        RHO, BY T(I) (THE TEMPERATURE AT RADIAL GRID POINT I IN
C...        COMMON/Y/, WHICH IS THE RATIO OF THE ABSOLUTE TEMPERATURE
C...        AT THAT POINT TO THE ENTERING ABSOLUTE TEMPERATURE).  THIS
C...        CORRECTION TO THE DENSITY IS NOT PROGRAMMED, BUT CAN BE
C...        INCLUDED IN THE CALCUATION OF C2 IN SUBROUTINE DERV
C...
C...  A1    FREQUENCY FACTOR FOR THE FIRST REACTION = 10**13.787
C...        1/SEC
C...
C...  A2    FREQUENCY FACTOR FOR THE SECOND REACTION = 10**5.3626
C...        1/SEC
C...
C...  RW    DIMENSIONLESS RADIUS OF THE REACTOR = 5
C...
C...  TW    DIMENSIONLESS REACTOR WALL TEMPERATURE = 1
C...
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
C...
C...  CALCULATE A1, A2
      A1=10.**13.787
      A2=10.**5.3626
C...
C...  CALCULATE RHO, CP FOR CASES 1 AND 2
      GO TO(1,2),NRUN
1     M0=29.65
      C0=1.517E-07
      GO TO 3
2     M0=32.826
      C0=7.585E-07
3     RHO=273.16*M0/(22400.*T0)
      CP=CP/M0
C...
C...  REACTOR INLET CONDITIONS
C...  F(R,0) = Z(R,0) = 1
      DO 4 I=1,NR
      F(I)=1.
4     T(I)=1.
C...
C...  COMPUTE THE INITIAL DERIVATIVES THAT ARE PRINTED IN SUBROUTINE
C...  PRINT (AT Z = 0)
      CALL DERV
      RETURN
      END
      BLOCK DATA
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
C...
C...  SET REACTOR PARAMETERS
      DATA         PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR/
     4            10.0,    0.5,   7.28,  100.0,    7.0,  643.2,5.83E+1,
     5         1.10E-3,    0.1,   0.93, 3.8E+4, 2.0E+4,  1.987, 4.3E+4,
     6          8.7E+4,    5.0,     0.,     0.,     0.,     0.,     0.,
     7               6/
      END
      SUBROUTINE DERV
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
C...
C...  CHECK FOR PHYSICALLY REALISTIC CONCENTRATION OF REACTANT
      DO 1 I=1,NR
      IF(F(I).LT.0.)F(I)=0.
1     IF(F(I).GT.1.)F(I)=1.
C...
C...  MATERIAL BALANCE
C...  PF/PZ = 1/PEM*(P2F/PR2 + (1/R)*PF/PR) - DP*R1/(C0*U)
C...
C...     COMPUTE THE DERIVATIVE PF/PR
         CALL DSS004(0.,RW,NR,F,FR)
C...
C...     BOUNDARY CONDITIONS AT R = 0, RW
         FR( 1)=0.
         FR(NR)=0.
C...
C...     COMPUTE THE DERIVATIVE P2F/PR2
         CALL DSS004(0.,RW,NR,FR,FRR)
C...
C...     COMPUTE THE DERIVATIVE PF/PZ AT R = 0
         C1=DP/(C0*U)
         FZ(1)=(1./PEM)*2.*FRR(1)-R1(1)*C1
C...
C...     COMPUTE THE DERIVATIVE PF/PZ AT R NE 0
         DO 3 I=2,NR
         R=RW*FLOAT(I-1)/FLOAT(NR-1)
         FZ(I)=(1./PEM)*(FRR(I)+(1./R)*FR(I))-R1(I)*C1
3        CONTINUE
C...
C...  CHECK FOR PHYSICALLY REALISTIC TEMPERATURES
      DO 2 I=1,NR
2     IF(T(I).LT.1.)T(I)=1.
C...
C...  HEAT BALANCE
C...  PT/PZ = 1/PEH*(P2T/PR2 + (1/R)*PT/PR) + DHR*DP/(RHO*CP*U*T0)
C...
C...     COMPUTE THE DERIVATIVE PT/PR
         CALL DSS004(0.,RW,NR,T,TR)
C...
C...     BOUNDARY CONDITIONS AT R = 0, RW
         TR( 1)=0.
         TW=1.
         TR(NR)=BIW*(TW-T(NR))
C...
C...     COMPUTE THE DERIVATIVE P2T/PR2
         CALL DSS004(0.,RW,NR,TR,TRR)
C...
C...     COMPUTE THE DERIVATIVE PT/PZ AT R = 0
         C2=DP/(RHO*CP*U*T0)
         TZ(1)=(1./PEH)*2.*TRR(1)+DHR(1)*C2
C...
C...     COMPUTE THE DERIVATIVE PT/PZ AT R NE 0
         DO 4 I=2,NR
         R=RW*FLOAT(I-1)/FLOAT(NR-1)
         TZ(I)=(1./PEH)*(TRR(I)+(1./R)*TR(I))+DHR(I)*C2
4        CONTINUE
      RETURN
      END
      FUNCTION R1(I)
C...
C...  R1 IS THE RATE OF THE FIRST REACTION
      REAL K1
      R1=EFF1(I)*K1(I)*CS(I)
      RETURN
      END
      FUNCTION R2(I)
C...
C...  R2 IS THE RATE OF THE SECOND REACTION
      REAL K2
      R2=EFF2(I)*K2(I)*CB(I)
      RETURN
      END
      FUNCTION EFF1(I)
C...
C...  EFF1 IS THE EFFICIENCY FACTOR FOR THE FIRST REACTION
      PHI=PHI1(I)
      EFF1=TANH(PHI)/PHI
      RETURN
      END
      FUNCTION EFF2(I)
C...
C...  EFF2 IS THE EFFICIENCY FACTOR FOR THE SECOND REACTION
      PHI=PHI2(I)
      EFF2=TANH(PHI)/PHI
      RETURN
      END
      FUNCTION PHI1(I)
C...
C...  PHI1 IS THE THIELE MODULUS FOR THE FIRST REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0, K1
      PHI1=DP/6.*SQRT(K1(I)/D)
C...
C...  SET PHI1 TO A MINIMUM VALUE TO AVOID A NUMERICAL PROBLEM IN
C...  COMPUTING EFF1, SMMPM
      IF(PHI1.LT.1.0E-10)PHI1=1.0E-10
      RETURN
      END
      FUNCTION PHI2(I)
C...
C...  PHI2 IS THE THIELE MODULUS FOR THE SECOND REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0, K2
      PHI2=DP/6.*SQRT(K2(I)/D)
C...
C...  SET PHI2 TO A MINIMUM VALUE TO AVOID A NUMERICAL PROBLEM IN
C...  COMPUTING EFF2, SMMPM
      IF(PHI2.LT.1.0E-10)PHI2=1.0E-10
      RETURN
      END
      REAL FUNCTION K1(I)
C...
C...  K1 IS THE RATE CONSTANT FOR THE FIRST REACTION
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      K1=A1*EXP(-E1/(RG*T0*T(I)))
      RETURN
      END
      REAL FUNCTION K2(I)
C...
C...  K2 IS THE RATE CONSTANT FOR THE SECOND REACTION
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      K2=A2*EXP(-E2/(RG*T0*T(I)))
      RETURN
      END
      FUNCTION CS(I)
C...
C...  CS IS THE CATALYST SURFACE CONCENTRATION OF REACTANT
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      CS=F(I)*C0
      IF(CS.LT.0.)CS=0.
      RETURN
      END
      FUNCTION CB(I)
C...
C...  CB IS THE CATALYST SURFACE CONCENTRATION OF PRODUCT
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0, K1, K2
      RK1K2=K1(I)/K2(I)
      S=SMMPM(I)
      CSC0=CS(I)/C0
      CB=C0*((S-DBDA)/(S-1.))*(RK1K2/(RK1K2*DBDA-1.))*((CSC0**S)-CSC0)
      IF(CB.LT.0.)CB=0.
      RETURN
      END
      FUNCTION SMMPM(I)
C...
C...  SMMPM IS THE FACTOR S FOR THE MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0, M1, M2
      SMMPM=DBDA*M1(I)*(PHI2(I)**2)*EFF2(I)/
     1          (M2(I)*(PHI1(I)**2)*EFF1(I))
      RETURN
      END
      REAL FUNCTION M1(I)
C...
C...  M1 IS A FACTOR USED IN THE CALCULATION OF S FOR THE
C...  MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      PHI=PHI1(I)
      M1=1.+(PHI*TANH(PHI)/BIM)
      RETURN
      END
      REAL FUNCTION M2(I)
C...
C...  M2 IS A FACTOR USED IN THE CALCULATION OF S FOR THE
C...  MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      PHI=PHI2(I)
      M2=1.+(PHI*TANH(PHI)/BIM)
      RETURN
      END
      FUNCTION DHR(I)
C...
C...  DHR IS THE SUM OF THE PRODUCTS OF THE HEATS OF REACTION AND
C...  RATES OF REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0
      DHR=DH1*R1(I)+DH2*R2(I)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR
      REAL M0, K1, K2
C...
C...  PRINT SOLUTION
      WRITE(NO,1)Z
1     FORMAT(/,2X,4HZ = ,E9.2,/,
     111H     R=0   ,11H     R=1   ,11H     R=2   ,
     211H     R=3   ,11H     R=4   ,11H     R=5   )
      WRITE(NO,2)(  F(I),I=1,NR),(  T(I),I=1,NR),
     1           ( FR(I),I=1,NR),( TR(I),I=1,NR),
     2           (FRR(I),I=1,NR),(TRR(I),I=1,NR),
     3           ( FZ(I),I=1,NR),( TZ(I),I=1,NR)
2     FORMAT(19H   F(R,Z),   T(R,Z),/,6E11.4,/,6E11.4,//,
     1       19H  FR(R,Z),  TR(R,Z),/,6E11.4,/,6E11.4,//,
     2       19H FRR(R,Z), TRR(R,Z),/,6E11.4,/,6E11.4,//,
     3       19H  FZ(R,Z),  TZ(R,Z),/,6E11.4,/,6E11.4,/)
C...
C...  *****************************************************************
C...
C...  WRITE STATEMENTS 3, 4 AND 5 WHICH FOLLOW PRINT THIRTEEN
C...  ADDITIONAL VARIABLES OF THE SIMULATION AT THE CENTERLINE
C...  OF THE REACTOR (I.E. R = 0).  THE USER MAY WISH TO CONVERT
C...  THESE STATEMENTS TO COMMENTS (I.E., THE STATEMENTS BETWEEN
C...  THE ROWS OF ASTERISKS) IN WHICH CASE ONLY THE DIMENSIONLESS
C...  CONCENTRATION F(I) AND TEMPERATURE T(I), AND THEIR ASSOCIATED
C...  SPATIAL DEIVATIVES, WILL BE PRINTED AS A FUNCTION OF R AND Z.
      P1=K1(1)
      P2=EFF1(1)
      P3=CS(1)
      P4=R1(1)
      P5=-DP*P4/(C0*U)
      WRITE(NO,3)P1,P2,P3,P4,P5
3     FORMAT(11H      K1(1),11H    EFF1(1),11H      CS(1),
     1       11H      R1(1),11H REACT TERM,/,6E11.3)
      P6=K2(1)
      P7=EFF2(1)
      P8=CB(1)
      P9=DHR(1)
      P10=P9*DP/(RHO*CP*U*T0)
      WRITE(NO,4)P6,P7,P8,P9,P10
4     FORMAT(11H      K2(1),11H    EFF2(1),11H      CB(1),
     1       11H     DHR(1),11H  HEAT TERM,/,6E11.3)
      P11=SMMPM(1)
      P12=M1(1)
      P13=M2(1)
      WRITE(NO,5)P11,P12,P13
5     FORMAT(11H   SMMPM(1),11H      M1(1),11H      M2(1),
     1       /,3E11.3,///)
C...
C...  *****************************************************************
C...
      RETURN
      END
PHTHALIC ANHYDRIDE REACTOR
0.        70.0      5.0
   12   64    1    4  ABS 0.001
PHTHALIC ANHYDRIDE REACTOR
0.        70.0      5.0
   12    4    1    4  ABS 0.001
END OF RUNS
*APP REACT16
      SUBROUTINE INITAL
C...
C...  OXIDATION OF NAPHTHALENE TO PHTHALIC ANHYDRIDE
C...
C...  MODEL NO. 2 - THE RESISTANCE TO HEAT AND MASS TRANSFER AT THE
C...  CATALYST SURFACE IS ACCOUNTED FOR VIA HEAT AND MASS TRANSFER
C...  COEFFICIENTS
C...
C...  NOTE - ADDITIONAL PROGRANMING STATEMENTS (ADDED TO MODEL NO. 1)
C...  ARE IDENTIFIED WITH  2  IN COLUMN 73
C...
C...  NAPHTHALENE + OXYGEN = PHTHALIC ANHYDRIDE + CARBON DIOXIDE + WATER
C...  (FIRST REACTION)
C...
C...  PHTHALIC ANHYDRIDE + OXYGEN = CARBON DIOXIDE + WATER
C...  (SECOND REACTION)
C...
C...  CARBERRY, J. J., AND DONALD WHITE, ON THE ROLE OF TRANSPORT
C...  PHENOMENA IN CATALYTIC REACTOR DESIGN, DIGITAL SIMULATION OF
C...  NAPHTHALENE OXIDATION OVER V2O5, IND. ENG. CHEM. VOL. 61, NO. 7,
C...  PP. 27-35, JULY, 1969
C...
C...  CARBERRY, J. J., DESIGNING LABORATORY CATALYTIC REACTORS, IND.
C...  ENG. CHEM. VOL. 56, NO. 11, PP. 39-46, NOVEMBER, 1964
C...
C...  THE MATHEMATICAL MODEL CONSISTS OF THE SIMULTANEOUS MATERIAL AND
C...  HEAT BALANCE EQUATIONS
C...
C...      PF/PZ = 1/PEM*(P2F/PR2 + (1/R)*PF/PR) - DP*R1/(C0*U)       (1)
C...
C...  PT/PZ = 1/PEH*(P2T/PR2 + (1/R)*PT/PR) + DHR*DP/(RHO*CP*U*T0)   (2)
C...
C...  THE ASSOCIATED BOUNDARY CONDITIONS ARE
C...
C...                  PF(0,Z)/PR = PT(0,Z)/PR = 0                 (3)(4)
C...
C...      PF(RW,Z)/PR = 0, PT(RW,Z)/PR = BIW*(TW - T(RW,Z))       (5)(6)
C...
C...                      F(R,0) = T(R,0) = 1                     (7)(8)
C...
C...  F     DIMENSIONLESS NAPHTHALENE CONCENTRATION (NORMALIZED WITH
C...        RESPECT TO THE ENTERING NAPHTHALENE CONCENTRATION)
C...
C...  T     DIMENSIONLESS TEMPERATURE (NORMALIZED WITH RESPECT TO THE
C...        ENTERING TEMPERATURE)
C...
C...  R     DIMENSIONLESS RADIAL POSITION (NORMALIZED WITH RESPECT TO
C...        THE CATALYST PARTICLE DIAMETER)
C...
C...  Z     DIMENSIONLESS AXIAL POSITION (NORMALIZED WITH RESPECT TO THE
C...        CATALYST PARTICLE DIAMETER)
C...
C...  PEM   PECLET NUMBER FOR MASS TRANSFER (DP*U/DR) = 10
C...
C...  DP    CATALYST PARTICLE DIAMETER = 0.5 CM
C...
C...  CP    FLUID HEAT CAPACITY = (7.28 CAL/GM-MOL K)*(1/M0 GM-MOL/GM)
C...
C...  U     FLUID VELOCITY = 100 CM/SEC
C...
C...  PEH   PECLET NUMBER FOR HEAT TRANSFER (DP*U/KR) = 7
C...
C...  T0    ENTERING REACTOR TEMPERATURE = JACKET TEMPERATURE =
C...        643.2 K
C...
C...  BIM   BIOT NUMBER FOR MASS TRANSFER = 58.3
C...
C...  BIW   BIOT NUMBER FOR HEAT TRANSFER AT THE REACTOR WALL
C...        (HW*DP/(RHO*CP*KR)) = 0.001104
C...
C...  D     INTRAPHASE DIFFUSIVITY = 0.1 CM**2/SEC
C...
C...  DBDA  RATIO OF THE DIFFUSIVITY FOR THE PRODUCT (DB) TO THE
C...        DIFFUSIVITY FOR THE REACTANT (DA) = 0.93
C...
C...  E1    ACTIVATION ENERGY FOR THE FIRST REACTION = 38,000
C...        CAL/GM-MOL
C...
C...  E2    ACTIVATION ENERGY FOR THE SECOND REACTION = 20,000
C...        CAL/GM-MOL
C...
C...  RG    GAS CONSTANT = 1.987 CAL/GM-MOL K
C...
C...  DH1   HEAT OF REACTION FOR THE FIRST REACTION = 43,000
C...        CAL/GM-MOL
C...
C...  DH2   HEAT OF REACTION FOR THE SECOND REACTION = 87,000
C...        CAL/GM-MOL
C...
C...  NR    NUMBER OF RADIAL INCREMENTS FOR THE FINITE DIFFERENCE
C...        APPROXIMATIONS OF THE PARTIAL DIFFERENTIAL EQUATIONS = 5
C...
C...  M0    ENTERING FLUID AVERAGE MOLECULAR WEIGHT = 29.65 (CASE 1),
C...        32.826 (CASE 2) GM/GM-MOL
C...
C...  C0    ENTERING REACTANT CONCENTRATION = 1.517E-07 (CASE 1),
C...        7.585E-07 (CASE 2) GM-MOL/CC
C...
C...  RHO   ENTERING FLUID DENSITY = 273.16*M0/(22400*T0) GM/CC.
C...        THE DENSITY AT ANY POINT IN THE REACTOR CAN BE CORRECTED
C...        FOR TEMPERATURE MERELY BY DIVIDING THE ENTERING DENSITY,
C...        RHO, BY T(I) (THE TEMPERATURE AT RADIAL GRID POINT I IN
C...        COMMON/Y/, WHICH IS THE RATIO OF THE ABSOLUTE TEMPERATURE
C...        AT THAT POINT TO THE ENTERING ABSOLUTE TEMPERATURE).  THIS
C...        CORRECTION TO THE DENSITY IS NOT PROGRAMMED, BUT CAN BE
C...        INCLUDED IN THE CALCUATION OF C2 IN SUBROUTINE DERV
C...
C...  A1    FREQUENCY FACTOR FOR THE FIRST REACTION = 10**13.787
C...        1/SEC
C...
C...  A2    FREQUENCY FACTOR FOR THE SECOND REACTION = 10**5.3626
C...        1/SEC
C...
C...  RW    DIMENSIONLESS RADIUS OF THE REACTOR = 5
C...
C...  TW    DIMENSIONLESS REACTOR WALL TEMPERATURE = 1
C...                                                                    2
C...  KGA   MASS TRANSFER COEFFICIENT FOR THE CATALYST SURFACE          2
C...        1/SEC                                                       2
C...                                                                    2
C...  H     HEAT TRANSFER COEFFICIENT FOR THE CATALYST SURFACE          2
C...        CAL/SEC-CM**2-K                                             2
C...                                                                    2
C...  A     CATALYSTS MASS TRANSFER SURFACE AREA PER UNIT VOLUME OF     2
C...        BED = 12 1/CM                                               2
C...                                                                    2
C...  RE    REYNOLDS NUMBER = DP*G/VIS                                  2
C...                                                                    2
C...  PR    PRANDLT NUMBER = CP*VIS/LG                                  2
C...                                                                    2
C...  G     FLUID MASS VELOCITY = M0*C0*U                               2
C...                                                                    2
C...  VIS   FLUID VISCOSITY = 0.000305 GM/CM-SEC                        2
C...                                                                    2
C...  LG    FLUID PHASE THERMAL CONDUCTIVITY = 9.21E-05 CAL/SEC-CM-K    2
C...                                                                    2
C...  DLM   MOLECULAR DIFFUSION COEFFICIENT = 0.205 CM**2/SEC           2
C...                                                                    2
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
C...                                                                    2
C...  SET THE ADDITIONAL PARAMETERS REQUIRED FOR THE CALCULATION OF     2
C...  THE CATALYST SURFACE CONCENTRATION AND TEMPERATURE, CSI AND       2
C...  TSI                                                               2
      A=12.                                                             2
      VIS=3.05E-04                                                      2
      LG=9.21E-05                                                       2
      DLM=0.205                                                         2
C...
C...  CALCULATE A1, A2
      A1=10.**13.787
      A2=10.**5.3626
C...
C...  CALCULATE RHO, CP FOR CASES 1 AND 2
      GO TO(1,2),NRUN
1     M0=29.65
      C0=1.517E-07
      GO TO 3
2     M0=32.826
      C0=7.585E-07
3     RHO=273.16*M0/(22400.*T0)
      CP=CP/M0
C...
C...  REACTOR INLET CONDITIONS
C...  F(R,0) = Z(R,0) = 1
      DO 4 I=1,NR
      F(I)=1.
4     T(I)=1.
C...                                                                    2
C...  THE CATALYST SURFACE MASS AND HEAT TRANSFER COEFFICIENTS ARE      2
C...  GIVEN BY                                                          2
C...                                                                    2
C...     KGA = 1.15*A*RE**(-0.5)*U*(VIS/(RHO*DLM))**(-2./3.)            2
C...                                                                    2
C...       H = 1.15*RE**(-0.5)*U*RHO*CP*PR**(-2./3.)                    2
C...                                                                    2
C...  CALCULATE RE, PR, KGA, H, BIM                                     2
      RE=DP*M0*C0*U/VIS                                                 2
      PR=CP*VIS/LG                                                      2
      FACTOR=1.15/SQRT(RE)*U                                            2
      KGA=A*FACTOR*(VIS/(RHO*DLM))**(-2./3.)                            2
      H=FACTOR*RHO*CP*PR**(-2./3.)                                      2
      BIM=KGA/(D*A**2)                                                  2
C...                                                                    2
C...  INITIALIZE CSI, TSI VIA FUNCTION CS(I)                            2
      CSI=CS(1)                                                         2
C...
C...  COMPUTE THE INITIAL DERIVATIVES THAT ARE PRINTED IN SUBROUTINE
C...  PRINT (AT Z = 0)
      CALL DERV
      RETURN
      END
      BLOCK DATA
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
C...
C...  SET REACTOR PARAMETERS
      DATA         PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7              NR/
     4            10.0,    0.5,   7.28,  100.0,    7.0,  643.2,5.83E+1,
     5         1.10E-3,    0.1,   0.93, 3.8E+4, 2.0E+4,  1.987, 4.3E+4,
     6          8.7E+4,    5.0,     0.,     0.,     0.,     0.,     0.,
     7               6/
      END
      SUBROUTINE DERV
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
C...
C...  CHECK FOR PHYSICALLY REALISTIC CONCENTRATION OF REACTANT
      DO 1 I=1,NR
      IF(F(I).LT.0.)F(I)=0.
1     IF(F(I).GT.1.)F(I)=1.
C...
C...  MATERIAL BALANCE
C...  PF/PZ = 1/PEM*(P2F/PR2 + (1/R)*PF/PR) - DP*R1/(C0*U)
C...
C...     COMPUTE THE DERIVATIVE PF/PR
         CALL DSS004(0.,RW,NR,F,FR)
C...
C...     BOUNDARY CONDITIONS AT R = 0, RW
         FR( 1)=0.
         FR(NR)=0.
C...
C...     COMPUTE THE DERIVATIVE P2F/PR2
         CALL DSS004(0.,RW,NR,FR,FRR)
C...
C...     COMPUTE THE DERIVATIVE PF/PZ AT R = 0
         C1=DP/(C0*U)
         FZ(1)=(1./PEM)*2.*FRR(1)-R1(1)*C1
C...
C...     COMPUTE THE DERIVATIVE PF/PZ AT R NE 0
         DO 3 I=2,NR
         R=RW*FLOAT(I-1)/FLOAT(NR-1)
         FZ(I)=(1./PEM)*(FRR(I)+(1./R)*FR(I))-R1(I)*C1
3        CONTINUE
C...
C...  CHECK FOR PHYSICALLY REALISTIC TEMPERATURES
      DO 2 I=1,NR
2     IF(T(I).LT.1.)T(I)=1.
C...
C...  HEAT BALANCE
C...  PT/PZ = 1/PEH*(P2T/PR2 + (1/R)*PT/PR) + DHR*DP/(RHO*CP*U*T0)
C...
C...     COMPUTE THE DERIVATIVE PT/PR
         CALL DSS004(0.,RW,NR,T,TR)
C...
C...     BOUNDARY CONDITIONS AT R = 0, RW
         TR( 1)=0.
         TW=1.
         TR(NR)=BIW*(TW-T(NR))
C...
C...     COMPUTE THE DERIVATIVE P2T/PR2
         CALL DSS004(0.,RW,NR,TR,TRR)
C...
C...     COMPUTE THE DERIVATIVE PT/PZ AT R = 0
         C2=DP/(RHO*CP*U*T0)
         TZ(1)=(1./PEH)*2.*TRR(1)+DHR(1)*C2
C...
C...     COMPUTE THE DERIVATIVE PT/PZ AT R NE 0
         DO 4 I=2,NR
         R=RW*FLOAT(I-1)/FLOAT(NR-1)
         TZ(I)=(1./PEH)*(TRR(I)+(1./R)*TR(I))+DHR(I)*C2
4        CONTINUE
      RETURN
      END
      FUNCTION R1(I)
C...
C...  R1 IS THE RATE OF THE FIRST REACTION
      REAL K1
C...                                                                    2
C...  THE FOLLOWING STATEMENT IS PROGRAMMED TO FIRST ITERATIVELY        2
C...  CALCULATE THE CATALYST SURFACE CONCENTRATION AND TEMPERATURE,     2
C...  CSI AND TSI, VIA THE CALL TO CS(I)                                2
      CSI=CS(I)
      R1=EFF1(I)*K1(I)*CS(I)
      RETURN
      END
      FUNCTION R2(I)
C...
C...  R2 IS THE RATE OF THE SECOND REACTION
      REAL K2
      R2=EFF2(I)*K2(I)*CB(I)
      RETURN
      END
      FUNCTION EFF1(I)
C...
C...  EFF1 IS THE EFFICIENCY FACTOR FOR THE FIRST REACTION
      PHI=PHI1(I)
      EFF1=TANH(PHI)/PHI
      RETURN
      END
      FUNCTION EFF2(I)
C...
C...  EFF2 IS THE EFFICIENCY FACTOR FOR THE SECOND REACTION
      PHI=PHI2(I)
      EFF2=TANH(PHI)/PHI
      RETURN
      END
      FUNCTION PHI1(I)
C...
C...  PHI1 IS THE THIELE MODULUS FOR THE FIRST REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K1                          2
      PHI1=DP/6.*SQRT(K1(I)/D)
C...
C...  SET PHI1 TO A MINIMUM VALUE TO AVOID A NUMERICAL PROBLEM IN
C...  COMPUTING EFF1, SMMPM
      IF(PHI1.LT.1.0E-10)PHI1=1.0E-10
      RETURN
      END
      FUNCTION PHI2(I)
C...
C...  PHI2 IS THE THIELE MODULUS FOR THE SECOND REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K2                          2
      PHI2=DP/6.*SQRT(K2(I)/D)
C...
C...  SET PHI2 TO A MINIMUM VALUE TO AVOID A NUMERICAL PROBLEM IN
C...  COMPUTING EFF2, SMMPM
      IF(PHI2.LT.1.0E-10)PHI2=1.0E-10
      RETURN
      END
      REAL FUNCTION K1(I)
C...
C...  K1 IS THE RATE CONSTANT FOR THE FIRST REACTION
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
C...                                                                    2
C...  NOTE THAT K1 IS NOW BASED ON THE CATALYST SURFACE TEMPERATURE,    2
C...  TSI                                                               2
      K1=A1*EXP(-E1/(RG*TSI))                                           2
      RETURN
      END
      REAL FUNCTION K2(I)
C...
C...  K2 IS THE RATE CONSTANT FOR THE SECOND REACTION
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
C...                                                                    2
C...  NOTE THAT K2 IS NOW BASED ON THE CATALYST SURFACE TEMPERATURE,    2
C...  TSI                                                               2
      K2=A2*EXP(-E2/(RG*TSI))                                           2
      RETURN
      END
      FUNCTION CS(I)
C...
C...  CS IS THE CATALYST SURFACE CONCENTRATION COMPUTED VIA MASS        2
C...  AND HEAT TRANSFER COEFFICIENTS                                    2
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K1                          2
C...                                                                    2
C...  THE CATALYST SURFACE CONCENTRATION AND TEMPERATUTE, CSI AND       2
C...  TSI, ARE CALCULATED ITERATIVELY VIA THE EQUATIONS                 2
C...                                                                    2
C...     CSI = C0*F/(1 + EFF1*K1/KGA)                               (9) 2
C...                                                                    2
C...     TSI = T0*T + DHR/(H*A)                                    (10) 2
C...                                                                    2
C...  SET THE NUMBER OF ITERATIONS, THE INITIAL VALUES OF CSI, TSI TO   2
C...  THE BULK FLUID CONCENTRATION AND TEMPERATURE                      2
      NITER=3                                                           2
      CSI=C0*F(I)                                                       2
      TSI=T0*T(I)                                                       2
C...                                                                    2
C...  COMPUTE CSI AND TSI VIA EQUATIONS (9) AND (10)                    2
      DO 1 J=1,NITER                                                    2
      CSI=C0*F(I)/(1.+EFF1(I)*K1(I)/KGA)                                2
      TSI=T0*T(I)+DHR(I)/(H*A)                                          2
1     CONTINUE                                                          2
      CS=CSI                                                            2
      RETURN
      END
      FUNCTION CB(I)
C...
C...  CB IS THE CATALYST SURFACE CONCENTRATION OF PRODUCT
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K1,     K2                  2
      RK1K2=K1(I)/K2(I)
      S=SMMPM(I)
C...                                                                    2
C...  NOTE THAT CB IS NOW BASED ON THE CATALYST SURFACE CONCENTRATION,  2
C...  CSI                                                               2
      CSC0=CSI/C0                                                       2
      CB=C0*((S-DBDA)/(S-1.))*(RK1K2/(RK1K2*DBDA-1.))*((CSC0**S)-CSC0)
      IF(CB.LT.0.)CB=0.
      RETURN
      END
      FUNCTION SMMPM(I)
C...
C...  SMMPM IS THE FACTOR S FOR THE MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     M1,     M2                  2
      SMMPM=DBDA*M1(I)*(PHI2(I)**2)*EFF2(I)/
     1          (M2(I)*(PHI1(I)**2)*EFF1(I))
      RETURN
      END
      REAL FUNCTION M1(I)
C...
C...  M1 IS A FACTOR USED IN THE CALCULATION OF S FOR THE
C...  MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
      PHI=PHI1(I)
      M1=1.+(PHI*TANH(PHI)/BIM)
      RETURN
      END
      REAL FUNCTION M2(I)
C...
C...  M2 IS A FACTOR USED IN THE CALCULATION OF S FOR THE
C...  MACRO-MICRO-PORE-MODEL
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG                                  2
      PHI=PHI2(I)
      M2=1.+(PHI*TANH(PHI)/BIM)
      RETURN
      END
      FUNCTION DHR(I)
C...
C...  DHR IS THE SUM OF THE PRODUCTS OF THE HEATS OF REACTION AND
C...  RATES OF REACTION
      COMMON
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K1                          2
C...                                                                    2
C...  COMPUTE R1 IN DH1*R1 + DH2*R2 LOCALLY TO AVOID A RECURSIVE CALL   2
C...  TO FUNCTION CS (CSI IS USED IN PLACE OF CS(I))                    2
      R1I=EFF1(I)*K1(I)*CSI                                             2
      DHR=DH1*R1I+DH2*R2(I)                                             2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      Z,   NFIN,   NRUN
     1      /Y/   F(6),   T(6)
     2      /F/  FZ(6),  TZ(6)
     3      /S/  FR(6), FRR(6),  TR(6), TRR(6)
     4   /PARM/    PEM,     DP,     CP,      U,    PEH,     T0,    BIM,
     5             BIW,      D,   DBDA,     E1,     E2,     RG,    DH1,
     6             DH2,     RW,     M0,     C0,    RHO,     A1,     A2,
     7             CSI,    TSI,    KGA,      H,      A,     LG,     NR  2
      REAL          M0,    KGA,     LG,     K1,     K2                  2
C...
C...  PRINT SOLUTION
      WRITE(NO,1)Z
1     FORMAT(/,2X,4HZ = ,E9.2,/,
     111H     R=0   ,11H     R=1   ,11H     R=2   ,
     211H     R=3   ,11H     R=4   ,11H     R=5   )
      WRITE(NO,2)(  F(I),I=1,NR),(  T(I),I=1,NR),
     1           ( FR(I),I=1,NR),( TR(I),I=1,NR),
     2           (FRR(I),I=1,NR),(TRR(I),I=1,NR),
     3           ( FZ(I),I=1,NR),( TZ(I),I=1,NR)
2     FORMAT(19H   F(R,Z),   T(R,Z),/,6E11.4,/,6E11.4,//,
     1       19H  FR(R,Z),  TR(R,Z),/,6E11.4,/,6E11.4,//,
     2       19H FRR(R,Z), TRR(R,Z),/,6E11.4,/,6E11.4,//,
     3       19H  FZ(R,Z),  TZ(R,Z),/,6E11.4,/,6E11.4,/)
C...
C...  *****************************************************************
C...
C...  WRITE STATEMENTS 3, 4 AND 5 WHICH FOLLOW PRINT THIRTEEN
C...  ADDITIONAL VARIABLES OF THE SIMULATION AT THE CENTERLINE
C...  OF THE REACTOR (I.E. R = 0).  THE USER MAY WISH TO CONVERT
C...  THESE STATEMENTS TO COMMENTS (I.E., THE STATEMENTS BETWEEN
C...  THE ROWS OF ASTERISKS) IN WHICH CASE ONLY THE DIMENSIONLESS
C...  CONCENTRATION F(I) AND TEMPERATURE T(I), AND THEIR ASSOCIATED
C...  SPATIAL DEIVATIVES, WILL BE PRINTED AS A FUNCTION OF R AND Z.
      P1=K1(1)
      P2=EFF1(1)
      P3=CS(1)
      P4=R1(1)
      P5=-DP*P4/(C0*U)
      WRITE(NO,3)P1,P2,P3,P4,P5
3     FORMAT(11H      K1(1),11H    EFF1(1),11H      CS(1),
     1       11H      R1(1),11H REACT TERM,/,6E11.3)
      P6=K2(1)
      P7=EFF2(1)
      P8=CB(1)
      P9=DHR(1)
      P10=P9*DP/(RHO*CP*U*T0)
      WRITE(NO,4)P6,P7,P8,P9,P10
4     FORMAT(11H      K2(1),11H    EFF2(1),11H      CB(1),
     1       11H     DHR(1),11H  HEAT TERM,/,6E11.3)
      P11=SMMPM(1)
      P12=M1(1)
      P13=M2(1)
      WRITE(NO,5)P11,P12,P13
5     FORMAT(11H   SMMPM(1),11H      M1(1),11H      M2(1),
     1       /,3E11.3,///)
C...
C...  *****************************************************************
C...
      RETURN
      END
PHTHALIC ANHYDRIDE REACTOR
0.        70.0      5.0
   12   64    1    4  ABS 0.001
PHTHALIC ANHYDRIDE REACTOR
0.        70.0      5.0
   12    4    1    4  ABS 0.001
END OF RUNS
*APP REACT17
      SUBROUTINE INITAL
C...
C...  CSTR WITH PROPORTIONAL TEMPERATURE CONTROL
C...
C...  THE FOLLOWING PROGRAMMING IMPLEMENTS THE DIFFERENTIAL EQUATIONS
C...  FOR A CONTINUOUS STIRRED TANK REACTOR (CSTR) WITH PROPORTIONAL
C...  CONTROL OF THE OUTLET TEMPERATURE.  THE DETAILS OF THE MATHE-
C...  MATICAL MODEL ARE GIVEN IN THE COMMENTS.
C...
C...  CONTENTS OF THE USUAL DSS/2 COMMON AREAS
C...
C...     /T/   T       TIME (SEC)
C...
C...           NFIN    RUN TERMINATOR
C...
C...           NRUN    RUN COUNTER
C...
C...     /Y/   A       REACTANT CONCENTRATION (LB MOL/CU FT)
C...
C...           TE      REACTOR TEMPERATURE (R)
C...
C...     /F/   DADT    DERIVATIVE OF A WITH RESPECT TO T (LB MOL/CU FT
C...                   /SEC)
C...
C...           DTEDT   DERIVATIVE OF TE WITH RESPECT TO T (R/SEC)
C...
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
C...
C...  COMMON/C/ CONTAINS CONSTANTS AND VARIABLES OF THE MODEL
C...
C...           AKC      CONTROLLER GAIN (LB/SEC-R)
C...
C...           QS       STEAM FLOW RATE IN THE HEATING COIL (LB/SEC)
C...
      COMMON/C/AKC,QS
C...
C...  SET THE CONTROLLER GAIN FOR THREE RUNS OF THE MODEL
      IF(NRUN.EQ.1) AKC=0.
      IF(NRUN.EQ.2) AKC=0.03
      IF(NRUN.EQ.3) AKC=0.3
C...
C...  SET THE MODEL INITIAL CONDITIONS
      A=1.
      TE=575.
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
      COMMON/C/AKC,QS
C...
C...  ******************************************************************
C...
C...  MODEL ALGEBRA (CONTROLLER EQUATION)
C...
C...     QS = (MS + AKC*(TR - TE))*DHV
C...
C...        MS      STEADY-STATE STEAM FLOW RATE = 0.711 LB/SEC
C...
C...        AKC     PROPORTIONAL CONTROLLER GAIN (LB/SEC-R)
C...
C...        TR      REFERENCE (SET-POINT) TEMPERATURE = 600 R
C...
C...        DHV     HEAT OF VAPORIZATION OF STEAM AT 5 PSIG = 960
C...                BTU/LB
C...
C...  SUBSTITUTION OF THE PRECEDING CONSTANTS IN THE CONTROLLER EQUATION
C...  GIVES
      QS=682.+960.*AKC*(600.-TE)
C...
C...  ******************************************************************
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     MATERIAL BALANCE
C...
C...     V*DA/DT = M*(A0 - A) - V*(A**2)*K0*EXP(-E/(R*TE))
C...
C...        V       REACTOR VOLUME = 100 CU FT
C...
C...        M       FEED AND WITHDRAWAL RATES OF THE PROCESS MATERIAL
C...                = 0.1 CU FT/SEC
C...
C...        A0      REACTANT FEED CONCENTRATION = 1 LB MOL/CU FT
C...
C...        K0      FREQUENCY FACTOR IN SECOND-ORDER RATE EXPRESSION
C...                = 1.907E+13 CU FT/SEC-LB MOL
C...
C...        E       ACTIVATION ENERGY = 44,700 BTU/LB MOL A REACTED
C...
C...        R       GAS CONSTANT = 1.987 BTU/LB MOL-R
C...
C...  THE REACTION RATE GROUP IS FIRST CALCULATED SINCE IT IS USED IN
C...  BOTH DIFFERENTIAL EQUATIONS
      RATE=(A**2)*(1.907E+13)*EXP(-44700./(1.987*TE))
C...
C...  THE REACTION RATE IS THEN SUBSTITUTED IN THE MATERIAL BALANCE
C...  ALONG WITH THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY V)
      DADT=0.001*(1.-A)-RATE
C...
C...     ENERGY BALANCE
C...
C...     V*C*DTE/DT = M*C*(T0 - TE) - DH*V*(A**2)*K0*EXP(-E/(R*TE)) + QS
C...
C...        C       VOLUMETRIC SPECIFIC HEAT OF THE PROCESS = 60
C...                BTU/CU FT-R
C...
C...        T0      REACTOR FEED TEMPERATURE = 575 R
C...
C...        DH      HEAT OF REACTION = 10,000 BTU/LB MOL A REACTED
C...                (ENDOTHERMIC)
C...
C...  THE REACTION RATE IS SUBSTITUTED IN THE ENERGY BALANCE ALONG WITH
C...  THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY C*V)
      DTEDT=0.001*(575.-TE)-(10000./60.)*RATE+QS/(6.0E+03)
C...
C...  ALL OF THE MODEL DERIVATIVES HAVE BEEN DEFINED NUMERICALLY, SO
C...  RETURN FROM DERV
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NRUN/Y/A,TE/F/DADT,DTEDT
      COMMON/C/AKC,QS
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TEP(3,51),TDP(3,51),QSP(3,51),TP(51),AKCP(3)
C...
C...  INITIALIZE A COUNTER FOR THE PRINTED AND PLOTTED SOLUTIONS
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.10.)WRITE(NO,2)
2     FORMAT(11X,1HT,11X,1HA,10X,2HTE,7X,5HTR-TE,10X,2HQS)
C...
C...  STORE THE SOLUTION IN EACH CALL TO SUBROUTINE PRINT FOR SUBSEQUENT
C...  PLOTTING
      IP=IP+1
      TEP(NRUN,IP)=TE
      TDP(NRUN,IP)=600.-TE
      QSP(NRUN,IP)=QS
       TP(IP)=T
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY FIFTH CALL TO SUBROUTINE
C...  PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      TD=600.-TE
      WRITE(NO,1)T,A,TE,TD,QS
1     FORMAT(F12.0,4F12.3)
C...
C...  TEST FOR THE END OF A RUN
3     IF(IP.LT.51)RETURN
      AKCP(NRUN)=AKC
C...
C...  AT THE END OF THE THIRD RUN, PLOT THE THREE NUMERICAL SOLUTIONS
C...  TOGETHER
      IF(NRUN.EQ.3)GO TO 5
      IP=0
      RETURN
C...
C...  PLOT TE VS T
5     CALL TPLOTS(NRUN,IP,TP,TEP)
      WRITE(NO,10)
10    FORMAT(1H ,//,18H TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
4     FORMAT(1H , /,17H CONTROLLER GAINS,3F6.3)
C...
C...  PLOT TR-TE VS T
      CALL TPLOTS(NRUN,IP,TP,TDP)
      WRITE(NO,11)
11    FORMAT(1H ,//,21H TR-TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT QS VS T
      CALL TPLOTS(NRUN,IP,TP,QSP)
      WRITE(NO,12)
12    FORMAT(1H ,//,24H QS (BTU/SEC) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
      RETURN
      END
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP
0.        2000.     40.
    2 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        2000.     40.
    2 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        2000.     40.
    2 5000    1    1  REL  0.001
END OF RUNS
*APP REACT18
      SUBROUTINE INITAL
C...
C...  THREE-COMPONENT CSTR WITH TEMPERATURE CONTROL
C...
C...  THE FOLLOWING PROGRAMMING IMPLEMENTS THE DIFFERENTIAL EQUATIONS
C...  FOR A CONTINUOUS STIRRED TANK REACTOR (CSTR) WITH PROPORTIONAL
C...  CONTROL OF THE OUTLET TEMPERATURE.  THE DETAILS OF THE MATHE-
C...  MATICAL MODEL ARE GIVEN IN THE COMMENTS.
C...
C...  CONTENTS OF THE USUAL DSS/2 COMMON AREAS
C...
C...     /T/   T       TIME (SEC)
C...
C...           NFIN    RUN TERMINATOR
C...
C...           NRUN    RUN COUNTER
C...
C...     /Y/  BC(1)    CONCENTRATION OF COMPONENTS A, B AND C, RESPECT-
C...           C(2)    IVELY, IN THE REACTION A + B --+ C (LB MOL/CU FT)
C...           C(3)
C...
C...           TE      REACTOR TEMPERATURE (R)
C...
C...     /F/  DCDT(1)  DERIVATIVES OF C(1), C(2) AND C(3), RESPECTIVELY,
C...          DCDT(2)  WITH RESPECT TO T (LB MOL/CU FT/SEC)
C...          DCDT(3)
C...
C...           DTEDT   DERIVATIVE OF TE WITH RESPECT TO T (R/SEC)
C...
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
C...
C...  COMMON/C/ CONTAINS CONSTANTS AND VARIABLES OF THE MODEL
C...
C...           AKC  ECONTROLLER GAIN (LB/SEC-R)
C...
C...           QS       STEAM FLOW RATE IN THE HEATING COIL (LB/SEC)
C...
      COMMON/C/AKC,QS
C...
C...  SET THE CONTROLLER GAIN FOR THREE RUNS OF THE MODEL
      IF(NRUN.EQ.1) AKC=0.
      IF(NRUN.EQ.2) AKC=0.05
      IF(NRUN.EQ.3) AKC=0.5
C...
C...  SET THE MODEL INITIAL CONDITIONS
      C(1)=1.
      C(2)=0.
      C(3)=0.
      TE=575.
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
      COMMON/C/AKC,QS
C...
C...  ******************************************************************
C...
C...  MODEL ALGEBRA (CONTROLLER EQUATION)
C...
C...     QS = (MS + AKC*(TR - TE))*DHV
C...
C...        MS      STEADY-STATE STEAM FLOW RATE = 0.711 LB/SEC
C...
C...        AKC     PROPORTIONAL CONTROLLER GAIN (LB/SEC-R)
C...
C...        TR      REFERENCE (SET-POINT) TEMPERATURE = 600 R
C...
C...        DHV     HEAT OF VAPORIZATION OF STEAM AT 5 PSIG = 960
C...                BTU/LB
C...
C...  SUBSTITUTION OF THE PRECEDING CONSTANTS IN THE CONTROLLER EQUATION
C...  GIVES
      QS=682.+960.*AKC*(600.-TE)
C...
C...  ******************************************************************
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     MATERIAL BALANCES
C...
C...     V*DC(1)/DT = M*(C0(1) - C(1)) - V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...     V*DC(2)/DT = M*(C0(2) - C(2)) - V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...     V*DC(3)/DT = M*(C0(3) - C(3)) + V*C(1)*C(2)*K0*EXP(-E/(R*TE))
C...
C...        V       REACTOR VOLUME = 100 CU FT
C...
C...        M       FEED AND WITHDRAWAL RATES OF THE PROCESS MATERIAL
C...                = 0.1 CU FT/SEC
C...
C...        C0(1)   FEED COMPOSITIONS FOR COMPONENTS A, B AND C, RE-
C...        C0(2)   SPECTIVELY, = 1, 1, 0 LB MOL/CU FT
C...        C0(3)
C...
C...        K0      FREQUENCY FACTOR IN SECOND-ORDER RATE EXPRESSION
C...                = 1.907E+13 CU FT/SEC-LB MOL
C...
C...        E       ACTIVATION ENERGY = 44,700 BTU/LB MOL A REACTED
C...
C...        R       GAS CONSTANT = 1.987 BTU/LB MOL-R
C...
C...  THE REACTION RATE GROUP IS FIRST CALCULATED SINCE IT IS USED IN
C...  ALL FOUR DIFFERENTIAL EQUATIONS
      RATE=C(1)*C(2)*(1.907E+13)*EXP(-44700./(1.987*TE))
C...
C...  THE REACTION RATE IS THEN SUBSTITUTED IN THE MATERIAL BALANCES
C...  ALONG WITH THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY V)
      DCDT(1)=0.001*(1.-C(1))-RATE
      DCDT(2)=0.001*(1.-C(2))-RATE
      DCDT(3)=0.001*(0.-C(3))+RATE
C...
C...     ENERGY BALANCE
C...
C...     V*C*DTE/DT = M*C*(T0 - TE) - DH*V*(A**2)*K0*EXP(-E/(R*TE)) + QS
C...
C...        C       VOLUMETRIC SPECIFIC HEAT OF THE PROCESS = 60
C...                BTU/CU FT-R
C...
C...        T0      REACTOR FEED TEMPERATURE = 575 R
C...
C...        DH      HEAT OF REACTION = 10,000 BTU/LB MOL A REACTED
C...                (ENDOTHERMIC)
C...
C...  THE REACTION RATE IS SUBSTITUTED IN THE ENERGY BALANCE ALONG WITH
C...  THE OTHER CONSTANTS TO GIVE (AFTER DIVISION BY C*V)
      DTEDT=0.001*(575.-TE)-(10000./60.)*RATE+QS/(6.0E+03)
C...
C...  ALL OF THE MODEL DERIVATIVES HAVE BEEN DEFINED NUMERICALLY, SO
C...  RETURN FROM DERV
C...  ******************************************************************
C...
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NRUN/Y/C(3),TE/F/DCDT(3),DTEDT
      COMMON/C/AKC,QS
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION C1P(3,51),C2P(3,51),C3P(3,51),TEP(3,51),QSP(3,51),
     1             TP(51),  AKCP(3)
C...
C...  INITIALIZE A COUNTER FOR THE PRINTED AND PLOTTED SOLUTIONS
      DATA IP/0/
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.10.)WRITE(NO,2)
2     FORMAT(11X,1HT,10X,2HCA,10X,2HCB,10X,2HC3,10X,2HTE,10X,2HQS)
C...
C...  STORE THE SOLUTION IN EACH CALL TO SUBROUTINE PRINT FOR SUBSEQUENT
C...  PLOTTING
      IP=IP+1
      C1P(NRUN,IP)=C(1)
      C2P(NRUN,IP)=C(2)
      C3P(NRUN,IP)=C(3)
      TEP(NRUN,IP)=TE
      QSP(NRUN,IP)=QS
       TP(IP)=T
C...
C...  PRINT THE NUMERICAL SOLUTION IN EVERY FIFTH CALL TO SUBROUTINE
C...  PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      WRITE(NO,1)T,(C(I),I=1,3),TE,QS
1     FORMAT(F12.0,5F12.3)
C...
C...  TEST FOR THE END OF A RUN
3     IF(IP.LT.51)RETURN
      AKCP(NRUN)=AKC
C...
C...  AT THE END OF THE THIRD RUN, PLOT THE THREE NUMERICAL SOLUTIONS
C...  TOGETHER
      IF(NRUN.EQ.3)GO TO 5
      IP=0
      RETURN
C...
C...  PLOT C(1) VS T
5     CALL TPLOTS(NRUN,IP,TP,C1P)
      WRITE(NO,10)
10    FORMAT(1H ,//,29H C1 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT C(2) VS T
      CALL TPLOTS(NRUN,IP,TP,C2P)
      WRITE(NO,11)
11    FORMAT(1H ,//,29H C2 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT C(3) VS T
      CALL TPLOTS(NRUN,IP,TP,C3P)
      WRITE(NO,12)
12    FORMAT(1H ,//,29H C3 (LB MOL/CU FT) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
4     FORMAT(1H , /,17H CONTROLLER GAINS,3F6.3)
C...
C...  PLOT TE VS T
      CALL TPLOTS(NRUN,IP,TP,TEP)
      WRITE(NO,13)
13    FORMAT(1H ,//,18H TE (R) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
C...
C...  PLOT QS VS T
      CALL TPLOTS(NRUN,IP,TP,QSP)
      WRITE(NO,14)
14    FORMAT(1H ,//,24H QS (BTU/SEC) VS T (SEC))
      WRITE(NO,4)(AKCP(I),I=1,NRUN)
      RETURN
      END
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP
0.        4000.     80.
    4 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        4000.     80.
    4 5000    1    1  REL  0.001
NON-ISOTHERMAL CSTR WITH CONSTANT HOLDUP AND TEMP CONTROLLER
0.        4000.     80.
    4 5000    1    1  REL  0.001
END OF RUNS
*APP REACT19
      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 REACT20
      SUBROUTINE INITAL
C...
C...  NONLINEAR KINETICS OF CONSECUTIVE, IRREVERSIBLE REACTIONS
C...
C...  THE RATES OF THE FIRST-ORDER, CONSECUTIVE, IRREVERSIBLE REACTIONS
C...
C...                A  REACTS TO  B  REACTS TO  C
C...                      (K1)          (K2)
C...
C...  ARE GIVEN BY THE DIFFERENTIAL EQUATIONS
C...
C...                                      N
C...                         DX/DT = -K1*X                           (1)
C...
C...                                  N      N
C...                      DY/DT = K1*X - K2*Y                        (2)
C...
C...                                      N
C...                          DZ/DT = K2*Y                           (3)
C...
C...                   X(0) = 1, Y(0) = Z(0) = 0               (4)(5)(6)
C...
C...  WHERE
C...
C...     X = A/A0
C...
C...     Y = B/A0
C...
C...     Z = C/A0
C...
C...     A,B,C  CONCENTRATIONS OF A, B AND C RESPECTIVELY
C...
C...     A0     INITIAL CONCENTRATION OF A
C...
C...     K1,K2  RATE CONSTANTS FOR THE FIRST AND SECOND REACTIONS
C...            RESPECTIVELY
C...
C...     N      ORDER OF THE REACTIONS
C...
C...  THE NUMERICAL SOLUTIONS OF EQUATIONS (1) TO (3) ARE COMPUTED FOR
C...  THE THREE CASES N = 0.5, 1, 2 AND PLOTTED IN SUBROUTINE PRINT FOR
C...  COMPARISON
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/     X,     Y,     Z
     2      /F/  DXDT,  DYDT,  DZDT
     3      /C/    K1,     K2,    N, RATE1, RATE2,    IP
      REAL         K1,     K2,    N
C...
C...  SET THE RATE CONSTANTS, ORDER OF THE REACTIONS
      K1=1.0
      K2=0.5
      IF(NORUN.EQ.1)N=0.5
      IF(NORUN.EQ.2)N=1.0
      IF(NORUN.EQ.3)N=2.0
C...
C...  INITIAL CONDITIONS (4), (5) AND (6)
      X=1.
      Y=0.
      Z=0.
C...
C...  INITALIZE THE DERIVATIVES AND A COUNTER FOR THE PLOTTED
C...  SOLUTION
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/     X,     Y,     Z
     2      /F/  DXDT,  DYDT,  DZDT
     3      /C/    K1,     K2,    N, RATE1, RATE2,    IP
      REAL         K1,     K2,    N
C...
C...  CONTSRAIN THE CONCENTRATIONS TO NONNEGATIVE VALUES
      IF(X.LT.0.)X=0.
      IF(Y.LT.0.)Y=0.
      IF(Z.LT.0.)Z=0.
C...
C...  DIFFERENTIAL EQUATION (1)
      RATE1=K1*(X**N)
      RATE2=K2*(Y**N)
      DXDT=-RATE1
C...
C...  DIFFERENTIAL EQUATION (2)
      DYDT=RATE1-RATE2
C...
C...  DIFFERENTIAL EQUATION (3)
      DZDT=RATE2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/     X,     Y,     Z
     2      /F/  DXDT,  DYDT,  DZDT
     3      /C/    K1,     K2,    N, RATE1, RATE2,    IP
      REAL         K1,     K2,    N
      DIMENSION TP(51),CP(3,51),RATE1P(3,51),RATE2P(3,51),DYDTP(3,51)
C...
C...  PRINT A HEADING
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(11X,1HT,11X,1HX,11X,1HY,11X,1HZ)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,3)T,X,Y,Z
3     FORMAT(E12.2,3E12.3)
C...
C...  STORE THE NUMERICAL SOLUTIONS FOR SUBSEQUENT PLOTTING
      IP=IP+1
      TP(IP)=T
      CP(NORUN,IP)=Y
      RATE1P(NORUN,IP)=RATE1
      RATE2P(NORUN,IP)=RATE2
      DYDTP(NORUN,IP)=DYDT
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.3)RETURN
C...
C...  PLOT THE CONCENTRATION Y FOR THE THREE CASES
      CALL TPLOTS(3,IP,TP,CP)
      WRITE(NO,6)
6     FORMAT(1H ,/,12H Y(T) VS T  )
      WRITE(NO,7)
7     FORMAT(1H ,  12H 1 - N = 0.5,3X,
     1             12H 2 - N = 1.0,3X,
     2             12H 3 - N = 2.0)
C...
C...  PLOT THE RATE OF THE FIRST REACTION FOR THE THREE CASES
      CALL TPLOTS(3,IP,TP,RATE1P)
      WRITE(NO,8)
8     FORMAT(1H ,/,12H RATE1 VS T )
      WRITE(NO,7)
C...
C...  PLOT THE RATE OF THE SECOND REACTION FOR THE THREE CASES
      CALL TPLOTS(3,IP,TP,RATE2P)
      WRITE(NO,9)
9     FORMAT(1H ,/,12H RATE2 VS T )
      WRITE(NO,7)
C...
C...  PLOT THE RATE OF COMPONENT Y FOR THE THREE CASES
      CALL TPLOTS(3,IP,TP,DYDTP)
      WRITE(NO,10)
10    FORMAT(1H ,/,12H DY/DT VS T )
      WRITE(NO,7)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE DEPENDENT
C...  AND MUST BE CONVERTED FOR THE LOCAL PLOTTER OR CHANGED TO COMMENTS
C...
C...  CALL QIKPLT(TP,    CP,IP,3H*T*,6H*Y(T)* ,15H*N = 0.5, 1, 2*,3)
C...  CALL QIKPLT(TP,RATE1P,IP,3H*T*,7H*RATE1*,15H*N = 0.5, 1, 2*,3)
C...  CALL QIKPLT(TP,RATE2P,IP,3H*T*,7H*RATE2*,15H*N = 0.5, 1, 2*,3)
C...  CALL QIKPLT(TP,DYDTP ,IP,3H*T*,7H*DY/DT*,15H*N = 0.5, 1, 2*,3)
C...
C...  ******************************************************************
C...
      RETURN
      END
CONSECUTIVE, IRREVERSIBLE REACTIONS, N = 0.5
0.        5.0       0.1
    3  100    3    1  ABS 0.00001
CONSECUTIVE, IRREVERSIBLE REACTIONS, N = 1.0
0.        5.0       0.1
    3  100    3    1  ABS 0.00001
CONSECUTIVE, IRREVERSIBLE REACTIONS, N = 2.0
0.        5.0       0.1
    3  100    3    1  ABS 0.00001
END OF RUNS
*APP REACT21
      SUBROUTINE INITAL
C...
C...  EFFECT OF THE AXIAL PECLET NUMBER ON THE SOLUTION OF CONVECTIVE-
C...  DIFFUSIVE (HYPERBOLIC-PARABOLIC) PARTIAL DIFFERENTIAL EQUATIONS
C...
C...  CONSIDER THE FOLLOWING CONVECTIVE-DIFFUSION EQUATION
C...
C...     C  = D*C   - V*C  - K*C                                   (1)
C...      T      XX      X
C...
C...  WHERE
C...
C...     C       DEPENDENT VARAIABLE (E.G., A CONCENTRATION)
C...
C...     T       INITIAL-VALUE INDEPENDENT VARIABLE (E.G., TIME)
C...
C...     X       BOUNDARY-VALUE INDEPENDENT VARIABLE (E.G., AXIAL
C...             POSITION)
C...
C...     D,V,K   CONSTANTS (E.G., DIFFUSIVITY, VELOCITY AND RATE
C...             CONSTANT)
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATIONS (1) ARE
C...
C...     C(X,0) = 0                                                (2)
C...
C...     V*C0 = V*C(0,T) - D*C (0,T), C (L,T) = 0               (3)(4)
C...                          X        X
C...
C...  WHERE
C...
C...     C0      CONSTANT (E.G., ENTERING CONCENTRATION)
C...
C...     L       BOUNDARY VALUE OF X (E.G., LENGTH)
C...
C...  EQUATIONS (1) TO (4) ARE INTEGRATED BY USING FIVE-POINT APPROXI-
C...  MATIONS FOR THE CONVECTIVE TERM, V*C , AND FIVE-POINT CENTERED
C...                                      X
C...  APPROXIMATIONS FOR THE DIFFUSIVE TERM, D*U  .  THE STEADY STATE
C...                                            XX
C...  SOLUTION (FOR U  = 0) IS COMPARED WITH THE ANALYTICAL SOLUTION.
C...                 T
C...
C...  THE PROBLEM DEFINED BY EQUATIONS (1) TO (4) CHANGES CHARACTER
C...  CHANGING VALUES OF THE PECLET NUMBER, PE = V*L/D, AS OUTLINED
C...  BELOW
C...
C...      PE    PARABOLIC (DIFFUSIVE)    HYPERBOLIC (CONVECTIVE)
C...
C...      10          STRONG                      WEAK
C...
C...     100           MILD                       MILD
C...
C...    1000           WEAK                      STRONG
C...
C...  THE CASE PE = 10 GIVES A SMOOTH SOLUTION THAT IS EASILY APPROXI-
C...  MATED NUMERICALLY WHILE THE CASE PE = 1000 IS A DIFFICULT PROBLEM
C...  WITH THE PROPAGATION OF A STEEP MOVING FRONT FROM X = 0 TO X = L.
C...  THESE VARIOUS CASES CAN BE STUDIED WITH THIS PROGRAM.
C...
C...  IN FACT, THE PROBLEM BECOMES ESSENTIALLY IMPOSSIBLE TO SOLVE
C...  BY ANY NUMERICAL METHOD THAT CANNOT ACCOMMODATE DISCONTINUITIES
C...  IN THE LIMIT AS PE ---+ INFINITY.  THE EXACT ANALYTICAL SOLUTION
C...  IS A UNIT STEP FUNCTION THAT MOVES FROM X = 0 AT T = 0 TO X = L
C...  AT T = L/V.  BOUNDARY CONDITION (4), IN PARTICULAR, CREATES AN
C...  ESSENTIALLY IMPOSSIBLE CONDITION TO SATISFY.  ONE HINT OF THIS
C...  PROBLEM IS CLEAR FROM CONSIDERING THE CASE D ---+ 0 FOR WHICH THE
C...  PROBLEM REDUCES TO THE FIRST-ORDER ADVECTION (PURE HYPERBOLIC)
C...  EQUATION
C...
C...    U  + V*U  = 0                                             (5)
C...     T      X
C...
C...    U(0,T) = 1, U(X,0) = 0                                 (6)(7)
C...
C...  THE EXACT SOLUTION TO EQUATIONS (5) TO (7) IS
C...
C...    U(X,T) = S(T - X/V)
C...
C...  WHERE S(T) IS THE UNIT STEP FUNCTION
C...
C...          = 0, T LT 0
C...     S(T)
C...          = L, T GT 0
C...
C...  SO THAT A BOUNDARY CONDITION AT X = L IS NOT REQUIRED.  SPECIAL
C...  METHODS MUST BE USED TO HANDLE EQUATIONS (5), (6) AND (7), E.G.,
C...  UPWIND APPROXIMATIONS, METHOD OF CHARACTERISTICS.  MORE CONVEN-
C...  TIONAL METHODS, E.G., CENTERED APPROXIMATIONS, METHOD OF WEIGHTED
C...  RESDUALS SUCH AS COLLOCATION, GALERKIN*S METHOD, WILL FAIL BECAUSE
C...  THEY CANNOT ACCOMMODATE A MOVING DISCONTINUITY.
C...
C...  THE FOLLOWING COMMON AREAS ARE FOR A 41-POINT SPATIAL GRID
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(41)
     2      /F/ CT(41)
     3      /S/ CX(41),CXX(41)
     4      /C/      D,      V,      K,       L,      C0,     CA
     5      /I/      N,     IP
      REAL   K,      L
C...
C...  SET THE PARAMETERS IN EQUATIONS (1) TO (4)
      N=41
      D=1.
      V=1.
      K=0.
      L=10.
      C0=1.
C...
C...  SET THE INITIAL CONDITION, EQUATION (2)
      DO 11 I=1,N
      C(I)=0.
11    CONTINUE
C...
C...  COMPUTE THE INITIAL DERIVATIVES AND INITIALIZE A COUNTER FOR
C...  THE PLOTTED SOLUTION
      CALL DERV
      IP=0
C...
C...  COMPUTE THE ANALYTICAL SOLUTION AT X = L
      CALL CEXACT
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(41)
     2      /F/ CT(41)
     3      /S/ CX(41),CXX(41)
     4      /C/      D,      V,      K,       L,      C0,     CA
     5      /I/      N,     IP
      REAL   K,      L
C...
C...  FIRST-ORDER PARABOLIC DERIVATIVE
      CALL DSS004(0.,L,N,C,CX)
C...
C...  BOUNDARY CONDITION (3)
      CX(1)=(1./D)*V*(C(1)-C0)
C...
C...  BOUNDARY CONDITION (4)
      CX(N)=0.
C...
C...  SECOND-ORDER PARABOLIC DERIVATIVE
      CALL DSS004(0.,L,N,CX,CXX)
C...
C...  FIRST-ORDER HYPERBOLIC DERIVATIVE
      CALL DSS020(0.,L,N,C,CX,1.)
C...
C...  BOUNDARY CONDITION (3)
      CX(1)=(1./D)*V*(C(1)-C0)
C...
C...  BOUNDARY CONDITION (4)
      CX(N)=0.
C...
C...  EQUATION (1)
      DO 1 I=1,N
      CT(I)=-V*CX(I)+D*CXX(I)-K*C(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(41)
     2      /F/ CT(41)
     3      /S/ CX(41),CXX(41)
     4      /C/      D,      V,      K,       L,      C0,     CA
     5      /I/      N,     IP
      REAL   K,      L
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(1H ,//,4X,1HT,8X,  4HC(1),8X,  4HC(N),7X,5HCA(N),
     1                     7X, 5HCX(1),7X, 5HCX(N),
     2                     6X,6HCXX(1),6X,6HCXX(N))
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      WRITE(NO,2)T,C(1),C(N),CA,CX(1),CX(N),CXX(1),CXX(N)
2     FORMAT(F5.1,7F12.4)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IP=IP+1
      RETURN
      END
      SUBROUTINE CEXACT
C...
C...  FUNCTION CEXACT COMPUTES THE ANALYTICAL SOLUTION TO THE
C...  SECOND-ORDER, BOUNDARY-VALUE ODE
C...
C...        2    2
C...     D*D C/DX  - V*DC/DX - K*C = 0                          (1)
C...
C...     V*C0 = V*C(0) - D*DC(0)/DX, DC(L)/DX = 0            (2)(3)
C...
C...  THE ANALYTICAL SOLUTION TO EQUATIONS (1) TO (3) IS DERIVED
C...  IN THE USUAL WAY FOR A SECOND-ORDER, CONSTANT COEFFICIENT,
C...  LINEAR ORDINARY DIFFERENTIAL EQUATION.  THE ASSUMED SOLUTION
C...  C(X) = C0*EXP(M*X), WHEN SUBSTITUTED IN EQUATION (1), GIVES
C...
C...     D*C0*(M**2)EXP(M*X) - V*C0*M*EXP(M*X) - K*C0*EXP(M*X) = 0
C...
C...  AND THEREFORE THE CHARACTERISTIC EQUATION
C...
C...     D*(M**2) - V*M - K = 0
C...
C...  THE EIGENVALUES ARE
C...
C...     M1, M2 = (V - OR + (V**2 + 4*D*K)**0.5)/(2*D)
C...
C...  THE GENERAL SOLUTION TO EQUATION (1) IS THEREFORE
C...
C...     C(X) = C01*EXP(M1*X) + C02*EXP(M2*X)
C...
C...  THE CONSTANTS C01 AND C02 ARE EVALUATED FROM BOUNDARY CONDITIONS
C...  (2) AND (3).  THE REQUIRED DERIVATIVE IS
C...
C...     DC(X)/DX = C01*M1*EXP(M1*X) + C02*M2*EXP(M2*X)
C...
C...  SUBSTITUTION IN EQUATION (2) GIVES
C...
C...     V*C0 = V*(C01 + C02) - D*(C01*M1 + C02*M2)
C...
C...  AND IN EQUATION (3) GIVES
C...
C...     0 = C01*M1*EXP(M1*L) + C02*M2*EXP(M2*L)
C...
C...  THESE TWO EQUATIONS CAN BE SOLVED FOR C01 ANC C02
C...
C...     C02 = -C01*(M1/M2)*EXP((M1 - M2)*L)
C...
C...     V*C0 = (V - D*M1)*C01 + (V - D*M2)*(-C01)*(M1/M2)*
C...
C...                             EXP((M1 - M2)*L)
C...
C...  OR
C...
C...     C01 = V*C0/DENOM, DENOM =
C...
C...        (V - D*M1) - (V - D*M2)*(M1/M2)*EXP((M1 - M2)*L)
C...
C...     C02 = -C01*(M1/M2)*EXP((M1 - M2)*L)/DENOM
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(41)
     2      /F/ CT(41)
     3      /S/ CX(41),CXX(41)
     4      /C/      D,      V,      K,       L,      C0,     CA
     5      /I/      N,     IP
      REAL K,L,M1,M2
C...
C...  EIGENVALUES
      M1=(V-SQRT(V**2+4.*D*K))/(2.*D)
      M2=(V+SQRT(V**2+4.*D*K))/(2.*D)
C...
C...  CONSTANTS IN THE GENERAL SOLUTION
      DENOM=(V-D*M1)-(V-D*M2)*(M1/M2)*EXP((M1-M2)*L)
      C01=V*C0/DENOM
      C02=-C01*(M1/M2)*EXP((M1-M2)*L)
C...
C...  ANALYTICAL SOLUTION
      CA=C01*EXP(M1*L)+C02*EXP(M2*L)
      RETURN
      END
CONVECTIVE-DIFFUSION EQUATION
0.        100.        10.
   41 1000    1    1  REL 0.001
END OF RUNS
*APP 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
RECYCLE IN DYNAMIC SIMULATIONS
0.        20.       2.
    310000    3    1  REL 0.001
RECYCLE IN DYNAMIC SIMULATIONS
0.        20.       2.
    310000    3    1  REL 0.001
END OF RUNS
*APP REACT23
      SUBROUTINE INITAL
C...
C...  HYDROLYSIS OF ACETIC ANHYDRIDE
C...
C...  ACETIC ANHYDRIDE IS HYDROLYZED IN A CONTINUOUS STIRRED TANK
C...  REACTOR (CSTR) AT 40 C.  INITIALLY, 10 LITERS OF AN AQUEOUS
C...  SOLUTION OF 0.5E-04 G-MOL/CM**3 ANHYDRIDE IS CHARGED.  THE
C...  FEED SOLUTION CONTAINS 3.0E-04 G-MOL/CM**3 OF ANHYDRIDE AND
C...  FED AT THE RATE OF 2 LITER/MIN.  PRODUCT IS WITHDRAW AT THE
C...  SAME RATE.  TWO REACTION RATE EQUATIONS ARE TO BE CONSIDERED
C...
C...     R1 = 0.380*C
C...                         G-MOL/CM**3-SEC
C...     R2 = 0.380*C**2
C...
C...  ASSUME CONSTANT DENSITY.
C...
C...  (1)  NUMERICALLY COMPUTE THE EXITING ANHYDRIDE CONCENTRATION
C...       AND COMPARE IT WITH THE EXITING ANHYDRIDE CONCENTRATION
C...       COMPUTED FROM THE ANALYTICAL SOLUTION FOR RATE R1.
C...
C...  (2)  NUMERICALLY COMPUTE THE EXITING ANHYDRIDE CONCENTRATION
C...       FOR RATE R2 AND COMPARE IT WITH THE NUMERICAL SOLUTION
C...       FOR RATE R1 BY PLOTTING THE TWO NUMERICAL SOLUTIONS VS
C...       TIME.
C...
C...  THE DIFFERENTIAL EQUATION FOR THE REACTOR IS
C...
C...     V*DCA/DT = F*CA0 - F*CA - V*RA                            (1)
C...
C...  WHERE
C...
C...     CA     CONCENTRATION OF ACETIC ANHYDRIDE
C...
C...      T     TIME
C...
C...      V     VOLUME OF THE REACTOR
C...
C...      F     VOLUMETRIC FLOW RATE THROUGH THE REACTOR
C...
C...     RA     VOLUMETRIC RATE OF REACTION
C...
C...  THE INITIAL CONDITION FOR EQUATION (1) IS
C...
C...     CA(0) = CA                                                (2)
C...               CHARGE
C...
C...  THE ANALYTICAL SOLUTION TO EQUATIONS (1) AND (2) FOR A FIRST-
C...  ORDER REACTION (RA = K*CA) IS
C...
C...     CA(T) = (CA0/TAU)*(1/(K + 1/TAU))
C...                                                               (3)
C...           + I*EXP(-(K + 1/TAU)*T)
C...
C...  WHERE
C...
C...     TAU    V/F
C...
C...      I     CA       - (CA0/TAU)*(1/(K + 1/TAU))
C...              CHARGE
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    CA
     2      /F/ DCADT
     3      /C/   CA0,  CA0C,     K,     V,     F,     I,   TAU,    IP
      REAL          K,     I
C...
C...  SET THE PARAMETERS
      CA0=3.0E-04
      CA0C=5.0E-05
      K=0.38
      F=2.
      V=10.
      TAU=V/F
      I=CA0C-(CA0/TAU)*(1./(K+1./TAU))
C...
C...  EQUATION (2)
      CA=CA0C
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    CA
     2      /F/ DCADT
     3      /C/   CA0,  CA0C,     K,     V,     F,     I,   TAU,    IP
      REAL          K,     I
C...
C...  EQUATION (1)
      IF(NORUN.EQ.1)RA=K*CA
      IF(NORUN.EQ.2)RA=K*CA**2
      DCADT=(1./TAU)*(CA0-CA)-RA
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    CA
     2      /F/ DCADT
     3      /C/   CA0,  CA0C,     K,     V,     F,     I,   TAU,    IP
      REAL          K,     I
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION CAP(2,51),TP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTIONS, FIRST-ORDER KINETICS
      GO TO(1,2),NORUN
1     IF(T.LT.0.05)WRITE(NO,11)
11    FORMAT(11X,1HT,10X,2HCA,9X,3HCAA,6X,6HDCA/DT)
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      CAA=(CA0/TAU)*(1./(K+1./TAU))+I*EXP(-(K+1./TAU)*T)
      WRITE(NO,12)T,CA,CAA,DCADT
12    FORMAT(F12.2,3E12.4)
      GO TO 3
C...
C...  PRINT A HEADING FOR THE SOLUTION, SECOND-ORDER KINETICS
2     IF(T.LT.0.05)WRITE(NO,21)
21    FORMAT(11X,1HT,10X,2HCA,6X,6HDCA/DT)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,22)T,CA,DCADT
22    FORMAT(F12.2,2E12.4)
C...
C...  STORE THE SOLUTIONS FOR PLOTTING
3     IP=IP+1
      CAP(NORUN,IP)=CA
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTIONS
      IF((IP.LT.51).OR.(NORUN.NE.2))RETURN
      CALL TPLOTS(NORUN,IP,TP,CAP)
      WRITE(NO,4)
4     FORMAT(1H ,//,29H 1 - K*CA   B2 - K*CA**2 VS T)
      RETURN
      END
ACETIC ANHYDRIDE HYDROLYSIS, FIRST-ORDER KINETICS
0.        5.        0.1
    1 1000    1    1  REL 0.001
ACETIC ANHYDRIDE HYDROLYSIS, SECOND-ORDER KINETICS
0.        5.        0.1
    1 1000    1    1  REL 0.001
END OF RUNS
*APP REACT24
      SUBROUTINE INITAL
C...
C...  SIMULATION OF A LINEAR SYSTEM WITH A TIME DELAY
C...
C...  THE DIFFERENTIAL EQUATIONS FOR TWO CSTR*S WITH A LONG CONNECTING
C...  LINE ARE
C...
C...  DCA1/DT = (F0/V1)*CA0 - (F0/V1+K)*CA1, CA1(0) = 0        (1)(2)
C...
C...  DCA2/DT = (F0/V2)*CA1(T-D) - (F0/V2+K)*CA2, CA2(0) = 0   (3)(4)
C...
C...  WHERE
C...
C...     CA1     CONCENTRATION IN THE FIRST AND SECOND CSTR*S
C...     CA2     RESPECTIVELY
C...
C...     CA0     CONCENTRATION ENTERING THE FIRST CSTR
C...
C...     F0      FLOW RATE THROUGH THE SYSTEM
C...
C...     V1      VOLUMES OF THE FIRST AND SECOND CSTR*S, RESPECTIVELY
C...     V2      (V1 = V2 = V)
C...
C...     K       RATE CONSTANT FOR A FIRST-ORDER REACTION IN THE TWO
C...             CSTR*S
C...
C...     D       PURE TIME DELAY PRODUCED BY THE FLOW THROUGH THE LONG
C...             CONNECTING PIPE
C...
C...     T       TIME
C...
C...  THE NUMERICAL SOLUTION COMPUTED BY THE FOLLOWING CODE IS TO BE
C...  COMPARED WITH THE FOLLOWING ANALYTICAL SOLUTION TO EQUATIONS (1)
C...  TO (4) (WHICH CAN BE DERIVED BY THE LAPLACE TRANSFORM)
C...
C...  CA2(T) = C1*U(T-D)*(1 - EXP(-C2*(T-D)) - C3*EXP(-C2*(T-D)))
C...
C...     C1 = (F0/(F0+V*K))**2, C2 = (F0/V+K), C3 = (F0+V*K)
C...
C...            0, T LE 0
C...     U(T) =            (UNIT STEP FUNCTION)
C...            1, T GT 0
C...
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
C...
C...  SET THE MODEL CONSTANTS
      F0=0.1
      V=1.
      D=5.
      K=0.1
      CA0=1.
      C1=(F0/(F0+V*K))**2
      C2= F0/V+K
      C3= F0+V*K
      F0V=F0/V
      IS=0
C...
C...  SET THE INITIAL CONDITIONS
      CA1=0.
      CA2=0.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
C...
C...  DIFFERENTIAL EQUATIONS
      DCA1DT=F0V*CA0-(F0V+K)*CA1
      DCA2DT=F0V*CA1D(T-D)-(F0V+K)*CA2
      RETURN
      END
      FUNCTION CA1D(DT)
C...
C...  FUNCTION CA1D SIMULATES THE PURE TIME DELAY
C...
      COMMON/DELAY/CA1S(2,161)
      COMMON/C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
C...
C...  IF THE DELAYED TIME IS NEGATIVE, THE OUTPUT OF THE TIME DELAY
C...  IS THE INITIAL CONDITION (ZERO IN THE CASE OF EQUATIONS (2) AND
C...  (4))
      IF(DT.GT.0.)GO TO 1
      CA1D=0.
      RETURN
C...
C...  IF THE DELAYED TIME IS NONNEGATIVE, THE DELAYED VARIABLE IS
C...  IN ARRAY CA1S WHICH TO THIS POINT IN TIME HAS BEEN FILLED
C...  IN SUBROUTINE PRINT WITH THE SECOND SUBSCRIPT EQUAL TO IS, I.E.,
C...  THE CURRENT VALUE OF T CORRESPONDS TO IS FOR THE SECOND SUBSCRIPT
1     DO 2 I=1,IS
C...
C...  IF THE DELAYED TIME EXCEEDS THE STORED TIME CA1S(1,I), THE SEARCH
C...  IN THE ARRAY CA1S CONTINUES UNTIL THE DELAYED TIME IS LESS THAN
C...  THE STORED TIME.  FOR THIS LATTER CONDITION, THE DELAYED VARIABLE
C...  (CA1D) EQUALS THE STORED VARIABLE (CA1S(2,I))
      IF(DT.GE.CA1S(1,I))CA1D=CA1S(2,I)
C...
C...  SINCE THE DELAYED VARIABLE HAS BEEN DEFINED, THE SEARCH NEED NOT
C...  CONTINUE
C...  IF(DT.LT.CA1S(1,I))RETURN
2     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T, NSTOP, NORUN
     1      /Y/   CA1,   CA2
     2      /F/DCA1DT,DCA2DT
     3      /C/    C1,    C2,    C3,   F0V,   CA0,     D,     K,    IS
      REAL K
      COMMON/DELAY/CA1S(2,161)
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(41), CP(2,41)
      DATA IP/0/
C...
C...  STORE THE CURRENT VALUES OF T AND CA1 IN ARRAY CA1S FOR USE IN
C...  FUNCTION CA1D
      IS=IS+1
      CA1S(1,IS)=T
      CA1S(2,IS)=CA1
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS EVERY FOURTH CALL
C...  TO SUBROUTINE PRINT
      IF(((IS-1)/4*4).NE.(IS-1))RETURN
C...
C...  EVALUATE CA1(T-D) FOR PRINTING
      DELAY=CA1D(T-D)
C...
C...  EVALUATE THE ANALYTICAL SOLUTION TO EQUATIONS (1) TO (4) FOR
C...  PRINTING AND PLOTTING
      IF((T-D).LE.0.)CA2A=0.
      IF((T-D).GT.0.)CA2A=C1*(1.-EXP(-C2*(T-D))-C3*(T-D)*EXP(-C2*(T-D)))
C...
C...  PRINT THE NUMERICAL AND ANALYTICAL SOLUTIONS
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(9X,1HT,9X,3HCA1,5X,8HCA1(T-D),8X,3HCA2,4X,10HCA2 (ANAL))
      WRITE(NO,1)T,CA1,DELAY,CA2,CA2A
1     FORMAT(F10.2,4F12.4)
C...
C...  STORE THE NUMERICAL AND ANALYTICAL SOLUTIONS FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      CP(1,IP)=CA2
      CP(2,IP)=CA2A
C...
C...  PLOT THE NUMERICAL AND ANALYTICAL SOLUTIONS FOR COMPARISON
      IF(IP.LT.41)RETURN
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...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,CP,IP,3H*T*,16H*CA2, CA2(ANAL)*,2H**,2)
C...
C...  ******************************************************************
C...
      IP=0
      RETURN
      END
SIMULATION OF A LINEAR SYSTEM WITH A TIME DELAY
0.        40.       0.25
    2 1000    1    1  ABS 0.0001
END OF RUNS
*APP REACT25
      SUBROUTINE INITAL
C...
C...  EFFECT OF TIME DELAYS ON THE PERFORMANCE OF FEEDBACK CONTROL
C...  SYSTEMS
C...
C...  THREE CSTR*S (CONTINUOUS-STIRRED-TANK REACTORS) ARE MODELLED
C...  BY THE FOLLOWING DIFFERENTIAL EQUATIONS
C...
C...     DCA1/DT = (1/TAU)*(CA0(T)       - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1(T - TD1) - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2(T - TD2) - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     TD1       TIME DELAY FOR THE LINE CONNECTING THE FIRST AND
C...               SECOND CSTR*S
C...
C...     TD2       TIME DELAY FOR THE LINE CONNECTING THE SECOND AND
C...               THIRD CSTR*S
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION WHICH STEPS FROM 0.4 TO 0.6
C...               AT T = 0 (IF CAD REMAINS AT 0.4, THE ENTIRE SYSTEM
C...               REMAINS AT STEADY STATE, I.E., THE DERIVATIVES IN THE
C...               DIFFERENTIAL EQUATIONS REMAIN AT ZERO OR DCA1/DT =
C...               DCA2/DT = DCA3/DT = 0)
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM = CAMSS + AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     CAMSS     STEADY STATE VALUE OF CAM = 0.4
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION CA3 = CA3SET - CA3
C...
C...     CA3SET    SET POINT FOR CA3 = 0.1
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE TO BE SOLVED FOR THE FOLLOWING CASES
C...
C...     (1)  CAD = 0.4, AK = 20, TAUI = 5, TD1 = TD2 = 0 (NORUN = 1)
C...
C...         (TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE
C...          WITHOUT TIME DELAYS)
C...
C...     (2)  CAD = 0.4, AK = 20, TAUI = 5, TD1 = 2, TD2 = 4 (NORUN = 2)
C...
C...         (TO CONFIRM THAT THE ENTIRE SYSTEM REMAINS AT STEADY STATE
C...          WITH TIME DELAYS)
C...
C...     (3)  CAD = 0.6, AK = 20, TAUI = 5, TD1 = TD2 = 0 (NORUN = 3)
C...
C...         (WELL TUNED CONTROLLER WITHOUT TIME DELAYS)
C...
C...     (4)  CAD = 0.6, AK = 20, TAUI = 5, TD1 = 2, TD2 = 4 (NORUN = 4)
C...
C...         (EFFECT ON THE WELL TUNED CONTROLLER OF (3) WHEN TIME
C...          DELAYS ARE INTRODUCED)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
C...
C...  THE FOLLOWING PARAMETERS VARY FROM RUN TO RUN
C...
C...  NORUN = 1
      IF(NORUN.EQ.1)THEN
         CAD=0.4
         AK=20.
         TAUI=5.0
         TD1=0.
         TD2=0.
C...
C...  NORUN = 2
      ELSE IF(NORUN.EQ.2)THEN
         CAD=0.4
         AK=20.
         TAUI=5.0
         TD1=2.
         TD2=4.
C...
C...  NORUN = 3
      ELSE IF(NORUN.EQ.3)THEN
         CAD=0.6
         AK=20.
         TAUI=5.0
         TD1=0.
         TD2=0.
C...
C...  NORUN = 4
      ELSE
         CAD=0.6
         AK=20.
         TAUI=5.0
         TD1=2.
         TD2=4.
      END IF
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
      CA10=0.4
      CA20=0.2
      CA30=0.1
      CA(1)=CA10
      CA(2)=CA20
      CA(3)=CA30
      ERINT=0.
C...
C...  INITIALIZE TWO COUNTERS USED IN SUBROUTINE PRINT
      IP=0
      IS=0
C...
C...  INITIALIZE THE ALGEBRAIC VARIABLES COMPUTED IN SUBROUTINE
C...  DERV FOR PRINTING AT THE INITIAL CONDITION
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  CONTROLLER
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
C...
C...  CONSTRAIN THE CONCENTRATIONS TO MEANINGFUL VALUES
      IF(CA0  .LT.0.)CA0  =0.
      IF(CA(1).LT.0.)CA(1)=0.
      IF(CA(2).LT.0.)CA(2)=0.
      IF(CA(3).LT.0.)CA(3)=0.
C...
C...  THE REMAINDER OF SUBROUTINE DERV IS NOT EXECUTED THE FIRST
C...  TIME DERV IS CALLED FROM SUBROUTINE INITAL SINCE THE DELAYED
C...  DEPENDENT VARIABLES HAVE NOT BEEN STORED (IN SUBROUTINE
C...  PRINT) FOR USE IN THE FOLLOWING CALLS TO FUNCTION DELAY1
      IF(IS.EQ.0)RETURN
C...
C...  IN COMPUTING THE DELAYED VARIABLES, IF ANY TIME DELAY IS LESS
C...  THAN THE PRINT INTERVAL, 0.2 IN THIS CASE, WHICH IS THE RESOLU-
C...  TION OF FUNCTION DELAY1, THE VARIABLE IS ASSUMED TO BE UNDELAYED
C...
C...  DELAYED CA1(T)
      IF(TD1.LT.0.2)THEN
         CA1DEL=CA(1)
      ELSE
         CA1DEL=DELAY1(1,T-TD1)
      END IF
C...
C...  DELAYED CA2(T)
      IF(TD2.LT.0.2)THEN
         CA2DEL=CA(2)
      ELSE
         CA2DEL=DELAY1(2,T-TD2)
      END IF
C...
C...  DIFFERENTIAL EQUATIONS
      DCADT(1)=(CA0   -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA1DEL-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA2DEL-CA(3))/TAU-RK*CA(3)
      RETURN
      END
      FUNCTION DELAY1(I,DT)
C...
C...  FUNCTION DELAY1 SIMULATES A PURE TIME DELAY
C...
C...  ARGUMENT LIST
C...
C...     I       INDEX FOR THE DEPENDENT VARIABLE TO BE DELAYED (I = 1
C...             FOR THE FIRST VARIABLE TO BE DELAYED, I = 2 FOR THE
C...             SECOND VARIABLE TO BE DELAYED, ETC.) (INPUT)
C...
C...     DT      THE DELAY IN TIME OF DEPENDENT VARIABLE I (INPUT)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  IF THE DELAYED TIME IS NEGATIVE, THE OUTPUT OF THE TIME DELAY
C...  IS THE INITIAL CONDITION
      IF(DT.LT.0.)THEN
         IF(I.EQ.1)THEN
            DELAY1=CA10
            RETURN
         ELSE IF(I.EQ.2)THEN
            DELAY1=CA20
            RETURN
C...
C...     MORE DELAYED VARIABLES (I GT 2) CAN BE ADDED HERE
         ELSE
         END IF
C...
C...  IF THE DELAYED TIME IS NONNEGATIVE, THE DELAYED VARIABLES ARE
C...  IN ARRAYS IN COMMON/DELAY/, WHICH TO THIS POINT IN TIME HAVE
C...  BEEN FILLED IN SUBROUTINE PRINT WITH THE SUBSCRIPT IS, I.E.,
C...  THE CURRENT VALUE OF T CORRESPONDS TO IS
      ELSE
C...     STEP THROUGH THE IS STORED VALUES OF TIME TO FIND THE PAST
C...     TIME CORRESPONDING TO DT AND SET FUNCTION DELAY1 TO THE
C...     CORRESPONDING VALUE OF THE DELAYED VARIABLE
         DO 2 J=1,IS
C...        IF DT EXCEEDS THE TIME IN TIMED(J), A LATER STORED VALUE
C...        OF THE DELAYED VARIABLE IS REQUIRED
            IF(DT.GT.TIMED(J))GO TO 2
C...
C...        DT IS NOW EQUAL TO OR LESS THAN TIMED(J) SO SET FUNCTION
C...        DELAY1 TO THE DEPENDENT VARIABLE CORRESPONDING TO TIMED(J)
            IF(I.EQ.1)THEN
               DELAY1=CA1D(J)
               RETURN
            ELSE IF(I.EQ.2)THEN
               DELAY1=CA2D(J)
               RETURN
C...        MORE DELAYED VARIABLES (I GT 2) CAN BE ADDED HERE
            ELSE
            END IF
2        CONTINUE
      END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,       TD1,       TD2,      CA10,      CA20,
     6               CA30,        IP,        IS
     7  /DELAY/TIMED(101), CA1D(101), CA2D(101)
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(4,101), EP(4,101),    TP(101)
C...
C...  STORE THE CURRENT VALUES OF T, CA1 AND CA2 IN ARRAYS CA1D AND
C...  CA2D FOR USE IN FUNCTION DELAY1
      IS=IS+1
      TIMED(IS)=T
      CA1D(IS)=CA(1)
      CA2D(IS)=CA(2)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,11X,1HE,7X,5HERINT,6X,6HCA1(T),2X,10HCA1(T-TD1),
     1                                 6X,6HCA2(T),2X,10HCA2(T-TD2),
     2                                 6X,6HCA3(T),6X,6HCA0(T))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP) THEN
      CA1DEL=DELAY1(1,T-TD1)
      CA2DEL=DELAY1(2,T-TD2)
      WRITE(NO,2)T,E,ERINT,CA(1),CA1DEL,CA(2),CA2DEL,CA(3),CA0
2     FORMAT(F10.1,8F12.3)
      ELSE
      END IF
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(NORUN,IP)=CA(3)
       EP(NORUN,IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      IF(NORUN.LT.4)RETURN
      CALL TPLOTS(4,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,47H CA3(T) VS T FOR THE FOUR RUNS LISTED IN INITAL)
      CALL TPLOTS(4,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,47H E(T) VS T FOR THE FOUR RUNS LISTED IN INITAL  )
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
END OF RUNS
*APP REACT26
      SUBROUTINE INITAL
C...
C...  ROOT LOCUS PLOTTING FOR AN NTH-ORDER SYSTEM
C...
C...  THE FOLLOWING CODING ILLUSTRATES THE PLOTTING OF A ROOT LOCUS
C...  DIAGRAM FOR A FOURTH-ORDER SYSTEM.  HOWEVER, THE METHOD CAN BE
C...  APPLIED TO A SYSTEM OF NTH-ORDER (WITH N ESSENTIALLY UNLIMITED)
C...  IF THE CHARACTERISTIC CLOSED LOOP POLYNOMIAL IS OBTAINED BY
C...  EIGENVALUE ANALYSIS VIA CALLS TO SUBROUTINES JMAP AND EIGEN,
C...  RATHER THAN ANALYTICALLY AS DONE HERE FOR THE FOURTH-ORDER SYSTEM.
C...
C...  CONSIDER THE FOLLOWING DIFFERENTIAL EQUATIONS FOR THREE CSTR*S
C...  (CONTINUOUS STIRRED TANK REACTORS) WITH PI CONTROL OF THE CON-
C...  CENTRATION FROM THE THIRD CSTR
C...
C...     DCA1/DT = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...     DCA2/DT = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...     DCA3/DT = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  WHERE
C...
C...     CA1       CONCENTRATIONS IN THE FIRST, SECOND AND THIRD CSTR,
C...     CA2       RESPECTIVELY
C...     CA3
C...
C...     TAU       CSTR RESIDENCE TIME (VOLUME/FLOW RATE)
C...
C...     T         TIME
C...
C...     CA0       CONCENTRATION OF REACTANT ENTERING THE FIRST CSTR
C...
C...     K         REACTION RATE CONSTANT
C...
C...  THE CONCENTRATION TO THE FIRST CSTR IS GIVEN BY THE EQUATION
C...
C...     CA0 = CAD + CAM
C...
C...  WHERE
C...
C...     CAD       DISTURBANCE CONCENTRATION
C...
C...     CAM       MANIPULATED CONCENTRATION (I.E., THE CONCENTRATION
C...               WHICH IS ADJUSTED AUTOMATICALLY TO MAINTAIN CA3 AT
C...               THE DESIRED LEVEL)
C...
C...  CAM IS GIVEN BY THE CONTROLLER EQUATION
C...
C...     CAM =  AK*(E + (1/TAUI)*INT(E*DT))
C...
C...  WHERE
C...
C...     AK        CONTROLLER GAIN
C...
C...     TAUI      CONTROLLER INTEGRAL TIME
C...
C...     E         ERROR IN THE CONCENTRATION = -CA3
C...
C...     INT       INTEGRAL OPERATOR WITH RESPECT TO T
C...
C...  THE PRECEDING EQUATIONS ARE ENTIRELY LINEAR, SO A LINEARIZATION
C...  AND CONVERSION TO PERTURBATION VARIABLES IS NOT NECESSARY
C...  (ACTUALLY, EXPRESSION OF THE EQUATIONS IN TERMS OF PERTURBATIONS
C...  HAS ALREADY BEEN DONE AS INDICATED BY THE DEFINITION OF THE ERROR
C...  E = -CA3, FOR WHICH THE SET POINT IS ZERO, I.E., THE MORE GENERAL
C...  DEFINITION OF THE ERROR WOULD BE E = CA3SET - CA3).
C...
C...  THUS, BECAUSE PERTURBATION VARIABLES HAVE BEEN USED, THE INITIAL
C...  CONDITIONS FOR THE DEPENDENT VARIABLES, CA1(T), CA2(T) AND CA3(T),
C...  WILL BE TAKEN AS ZERO, I.E.,
C...
C...     CA1(0) = CA2(0) = CA3(0) = 0
C...
C...                                             ---    ---
C...  (A)  OBTAIN THE OVERALL TRANSFER FUNCTION, CA3(S)/CAD(S), FOR THIS
C...       SYSTEM (S IS THE LAPLACE TRANSFORM OPERATOR)
C...
C...  (B)  USE AN IMSL SUBROUTINE (E.G., ZPOLR, ZRPOLY) TO FACTOR THE
C...       CLOSED LOOP CHARACTERISTIC POLYNOMIAL OF THE SYSTEM FOR A
C...       SERIES OF VALUES OF KC WITH TAUI = 5.
C...
C...  (C)  PLOT THE ROOTS AS A ROOT LOCUS DIAGRAM (REAL PARTS OF THE
C...       ROOTS VS THE IMAGINARY PARTS OF THE ROOTS)
C...
C...  (D)  FROM THE ROOT LOCUS DIAGRAM, ESTIMATE THE ULTIMATE GAIN OF
C...       THE SYSTEM
C...
C...  (E)  CONFIRM THE ULTIMATE GAIN OF PART (4) WITH A SIMULATION OF
C...       THE SYSTEM.
C...
C...
C...  THE LAPLACE TRANSFORMS OF THE DIFFERENTIAL EQUATIONS AND INITIAL
C...  CONDITIONS ARE
C...
C...       ---            ---   ---      ---
C...     S*CA1 = (1/TAU)*(CA0 - CA1) - K*CA1
C...
C...       ---            ---   ---      ---
C...     S*CA2 = (1/TAU)*(CA1 - CA2) - K*CA2
C...
C...       ---            ---   ---      ---
C...     S*CA3 = (1/TAU)*(CA2 - CA3) - K*CA3
C...
C...  OR
C...
C...     --- ---
C...     CA1/CA0 = (1/TAU)/(S + (1/TAU) + K)
C...
C...     --- ---
C...     CA2/CA1 = (1/TAU)/(S + (1/TAU) + K)
C...
C...     --- ---
C...     CA3/CA2 = (1/TAU)/(S + (1/TAU) + K)
C...
C...  THESE ALGEBRAIC EQUATIONS CAN EASILY BE COMBINED TO OBTAIN THE
C...  TRANSFER FUNCTION FOR THE PROCESS (THREE CSTR*S)
C...
C...     --- ---
C...     CA3/CA0 = (1/TAU)**3/(S + (1/TAU) + K)**3
C...
C...             = 1/(TAU*S + K*TAU + 1)**3 = GP(S)
C...
C...  THE LAPLACE TRANSFORM OF THE CONTROLLER EQUATION IS
C...
C...     ---                         ---            ---
C...     CAM = AK*(1 + 1/(TAUI*S))*(-CA3) = GC(S)*(-CA3)
C...
C...  AND FOR CA0,
C...
C...     ---   ---   ---
C...     CA0 = CAD + CAM
C...
C...  IF THESE EQUATIONS ARE COMBINED, AND THE OVER BARS FOR LAPLACE
C...  TRANSFORMS DROPPED
C...
C...     CA3/CA0 = CA3/(CAD + CAM) = CA3 /(CAD + GC(S)*(-CA3)) = GP(S)
C...
C...  SOLVING FOR CA3/CAD GIVES
C...
C...     CA3*(1 + GC(S)*GP(S)) = GP(S)*CAD
C...
C...     CA3/CAD = GP(S)/(1 + GC(S)*GP(S))
C...
C...  WHICH IS A STANDARD FORM FOR THE CLOSED LOOP TRANSFER FUNCTION
C...  RELATING THE CONTROLLED VARIABLE (E.G., CA3), THE DISTURBANCE
C...  VARIABLE (E.G., CAD), AND THE CONTROLLER AND PROCESS TRANSFER
C...  FUNCTIONS (E.G., GC(S) AND GP(S)).
C...
C...  THE CLOSED LOOP CHARACTERISTIC EQUATION (THE DENOMINATOR OF THE
C...  TRANSFER FUNCTION CA3/CAD SET TO ZERO) IS
C...
C...     1 + GC(S)*GP(S) = 0
C...
C...  FOR WHICH THE ROOTS R1, R2, R3 AND R4 ARE TO BE COMPUTED AS A
C...  FUNCTION OF KC.  IN THE PRESENT CASE,
C...
C...     1 + AK*(1 + 1/(TAUI*S))*(1/(TAU*S + K*TAU + 1)**3) = 0
C...
C...  OR AFTER REARRANGEMENT
C...
C...     (TAU*S)*(TAU*S + K*TAU + 1)**3 + AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...  IF THE CUBIC TERM IS MULTIPLIED OUT
C...
C...     (TAU*S)*((TAU*S)**2 + 2*(TAU*S)*(K*TAU + 1) + (K*TAU + 1)**2)*
C...
C...     (TAU*S + K*TAU + 1) + AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...
C...     (TAU*S)*((TAU*S)**3 + 3*((TAU*S)**2)*(K*TAU + 1) +
C...
C...     3*(TAU*S)*((K*TAU + 1)**2) + (K*TAU + 1)**3) +
C...
C...     AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...
C...     (TAU*S)**4 + 3*((TAU*S)**3)*(K*TAU + 1) +
C...
C...     3*((TAU*S)**2)*(K*TAU + 1)**2) + (TAU*S)*(K*TAU + 1)**3) +
C...
C...     AK*(TAU*S + (TAU/TAUI)) = 0
C...
C...  WHICH CAN BE WRITTEN IN THE FINAL FORM
C...
C...     A4*S**4 + A3*S**3 + A2*S**2 + A1*S + A0 = 0
C...
C...  WHERE
C...
C...     A4 = TAU**4
C...
C...     A3 = 3*(TAU**3)*(K*TAU + 1)
C...
C...     A2 = 3*(TAU**2)*((K*TAU + 1)**2)
C...
C...     A1 = TAU*((K*TAU + 1)**3) + AK*TAU
C...
C...     A0 = AK*TAU/TAUI
C...
C...  OR IN FACTORED FORM
C...
C...     (TAU**4)*(S - R1)*(S - R2)*(S - R3)*(S - R4) = 0
C...
C...  R1, R2, R3 AND R4 ARE THEN TO BE PLOTTED AS A FUNCTION OF AK
C...  (WITH TAU = 2, K = 0.5, TAUI = 5).
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
      COMMON/IO/       NI,        NO
C...
C...  DIMENSION THE ARRAYS REQUIRED FOR COMPUTING THE ROOTS OF THE
C...  CHARACTERISTIC POLYNOMIAL
      REAL A(0:4), ZREAL(4), ZIMAG(4), ZR(303), ZI(303)
      COMPLEX Z(4)
C...
C...  SET THE MODEL PARAMETERS
      RK=0.5
      V=200.
      F0=100.
      TAU=V/F0
      CA3SET=0.1
      CAMSS=0.4
      CAD=0.6
      AK=51.
      TAUI=5.
C...
C...  SET THE MODEL INITIAL CONDITIONS (INCLUDING THE INITIAL CONDITION
C...  FOR THE INTEGRAL ACTION OF THE CONTROLLER)
      CA(1)=0.4
      CA(2)=0.2
      CA(3)=0.1
      ERINT=0.
C...
C...  INITIALIZE THE REMAINDER OF THE MODEL
      CALL DERV
      IP=0
C...
C...  ******************************************************************
C...
C...  STEP THROUGH A SERIES OF OF VALUES OF AK AND COMPUTE THE CORRES-
C...  PONDING ROOTS OF THE CHARACTERISTIC EQUATION
C...
C...  ******************************************************************
C...
C...  SET THE COEFFICIENTS OF THE CHARACTERISTIC POLYNOMIAL WHICH DO
C...  NOT DEPEND ON AK (NOTE THE SOMEWHAT UNEXPECTED ORDER FOR STORING
C...  THE POLYNOMIAL COEFFICIENTS REQUIRED BY IMSL ROUTINE ZPOLR)
      A(0)=TAU**4
      A(1)=3.*(TAU**3)* (RK*TAU+1.)
      A(2)=3.*(TAU**2)*((RK*TAU+1.)**2)
C...
C...  SET THE INITIAL VALUE OF AK
      AKO=-1.0
C...
C...  SET THE DEGREE OF THE CHARACTERISTIC POLYNOMIAL
      NDEG=4
C...
C...  PRINT A HEADING FOR THE COMPUTED ROOTS
      WRITE(NO,4)
4     FORMAT(1H ,7X,2HAK,
     1           5X,7HREAL R1,5X,7HIMAG R1,5X,7HREAL R2,5X,7HIMAG R2,
     2           5X,7HREAL R3,5X,7HIMAG R3,5X,7HREAL R4,5X,7HIMAG R4)
C...
C...  STEP THROUGH A SERIES OF VALUES OF AK
      DO 1 I=1,101
C...
C...  INCREMENT THE VALUE OF AK AND COMPUTE THE COEFFICIENTS OF THE
C...  CHARACTERISTIC POLYNOMIAL THAT DEPEND ON AK
      AKO=AKO+1.0
      A(3)=TAU*((RK*TAU+1.)**3)+AKO*TAU
      A(4)=AKO*TAU/TAUI
C...
C...  COMPUTE AND PRINT THE ROOTS OF THE CHARACTERISTIC POLYNOMIAL.  THE
C...  FOLLOWING CALL TO SUBROUTINE ZPOLR REQUIRES THE AVAILABILITY OF
C...  THE IMSL LIBRARY.  THIS CALL MUST BE REPLACED BY A CALL TO ANOTHER
C...  POLYNOMIAL ROOT FINDING ROUTINE IF THE IMSL LIBRARY IS NOT AVAIL-
C...  ABLE
      CALL ZPOLR(A,NDEG,Z,IER)
      DO 3 IR=1,NDEG
      ZREAL(IR)= REAL(Z(IR))
      ZIMAG(IR)=AIMAG(Z(IR))
3     CONTINUE
      WRITE(NO,2)AKO,(ZREAL(IR),ZIMAG(IR),IR=1,NDEG)
2     FORMAT(F10.1,8E12.4)
C...
C...  STORE THE ROOTS FOR SUBSEQUENT PLOTTING (ONLY THE SECOND, THIRD
C...  AND FOURTH ROOTS ARE STORED FOR PLOTTING.  THE FIRST ROOT IS REAL,
C...  LARGE AND NEGATIVE, AND WOULD THEREFORE DISTORT THE PLOT IF IN-
C...  CLUDED
      ZR(    I)=ZREAL(2)
      ZI(    I)=ZIMAG(2)
      ZR(101+I)=ZREAL(3)
      ZI(101+I)=ZIMAG(3)
      ZR(202+I)=ZREAL(4)
      ZI(202+I)=ZIMAG(4)
C...
C...  GO ON TO THE NEXT VALUE OF AK
1     CONTINUE
C...
C...  PLOT THE ROOT LOCUS PLOT
      CALL TPLOTS(1,303,ZR,ZI)
      WRITE(NO,5)
5     FORMAT(1H ,//,
     1 54H ROOT LOCUS DIAGRAM (ONLY THREE ROOT LOCI ARE PLOTTED))
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALL TO A CONTINUOUS PLOTTER IS MACHINE DEPENDENT
C...  AND MUST EITHER BE CONVERTED FOR OTHER COMPUTERS OR CHANGED TO A
C...  COMMENT
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZR,ZI,303,6H*REAL*,6H*IMAG*,2H**,1)
C...
C...  ******************************************************************
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  MODEL ALGEBRA
      E=CA3SET-CA(3)
      CAM=CAMSS+AK*(E+ERINT/TAUI)
      CA0=CAD+CAM
      DCADT(1)=(CA0  -CA(1))/TAU-RK*CA(1)
      DCADT(2)=(CA(1)-CA(2))/TAU-RK*CA(2)
      DCADT(3)=(CA(2)-CA(3))/TAU-RK*CA(3)
C...
C...  NOTE THAT THE DIFFERENTIAL EQUATION D(ERINT)/DT = E IS ALREADY
C...  PROGRAMMED BY SETTING E WHICH APPEARS IN THE DERIVATIVE SECTION
C...  (COMMON/F/ ABOVE).  THE INTEGRATED RESULT, ERINT, IN COMMON/Y/
C...  CAN THEN BE USED IN THE CONTROLLER EQUATION FOR CAM
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/     CA(3),     ERINT
     2      /F/  DCADT(3),         E
     3      /C/        RK,        AK,       TAU,      TAUI,    CA3SET,
     4              CAMSS,       CA0,       CAD,       CAM,        F0,
     5                  V,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION CAP(101), EP(101), TP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(1H1,8X,1HT,11X,1HE,7X,5HERINT,7X,5HCA(1),4X,8HDCADT(1),
     1                                     7X,5HCA(2),4X,8HDCADT(2),
     2                                     7X,5HCA(3),4X,8HDCADT(3))
C...
C...  PRINT THE NUMERICAL SOLUTION (NOTE - THE FOLLOWING WRITE STATEMENT
C...  IS EXECUTED EVERY FIVE CALLS TO PRINT TO REDUCE THE AMOUNT OF
C...  PRINTOUT
      IF((IP/5*5).EQ.IP)
     1  WRITE(NO,2)T,E,ERINT,(CA(I),DCADT(I),I=1,3)
2     FORMAT(F10.1,8F12.3)
C...
C...  STORE THE NUMERICAL SOLUTION
      IP=IP+1
      CAP(IP)=CA(3)
       EP(IP)=E
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,CAP)
      WRITE(NO,3)
3     FORMAT(1H ,//,46H CA3(T) VS T                                  )
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,46H   E(T) VS T                                  )
      RETURN
      END
LUYBEN, W L, PROCESS MODEL, SIMUL, CONTROL FOR CHE*S, EX. 5-4
0.        20.       0.2
    4  100    1    1  REL 0.001
END OF RUNS
*APP REACT27
      SUBROUTINE INITAL
C...
C...  MOVING BOUNDARY PROBLEM
C...
C...  A COAL PARTICLE OF RADIUS RP(T) UNDERGOES AN INSTANTANEOUS
C...  REACTION WITH O  TO FORM CO
C...                 2           2
C...
C...     C + 0  ----+ CO
C...          2         2
C...
C...  THE EQUATIONS DESCRIBING THIS SYSTEM ARE
C...
C...  Y  = (DAB/R**2)((R**2)Y )                                     (1)
C...                         R R
C...
C...  D((4/3)*PI*(RP**3)*RHOC/MC)/DT = - 4*PI*(RP**2)*C*DAB*(Y )    (2)
C...                                                          R R=RP
C...
C...  EQUATION (1) IS FICK*S SECOND LAW APPLIED AS AN OXYGEN BALANCE
C...  IN THE GAS PHASE.  EQUATION (2) IS A CARBON MASS BALANCE APPLIED
C...  TO THE COAL PARTICLE.
C...
C...     Y        MOLE FRACTION OF O
C...                                2
C...
C...     R        RADIAL POSITION (A SUBSCRIPT WITH R DENOTES A PARTIAL
C...              DERIVATIVE WITH RESPECT TO R)
C...
C...     T        TIME (A SUBSCRIPT WITH T DENOTES A PARTIAL DERIVATIVE
C...              WITH RESPECT TO T)
C...
C...     DAB      DIFFUSIVITY FOR O
C...                               2
C...
C...     RP       RADIUS OF THE GAS PARTICLE
C...
C...     RHOC     DENSITY OF THE COAL
C...
C...     MC       MOLECULAR WEIGHT OF THE COAL (CARBON)
C...
C...     C        MOLAR DENSITY OF THE CARBON IN THE GAS PHASE
C...
C...  THE BOUNDARY AND INITIAL CONDITIONS FOR EQUATION (1) ARE
C...
C...  Y(T,RP) = 0, Y(T,OO) = 1, Y(0,R) = 1                    (3)(4)(5)
C...
C...  RP(0) = R0                                                    (6)
C...
C...  THE QUESTION OF INTEREST IS TO DETERMINE HOW MUCH TIME IS REQUIRED
C...  FOR THE RADIUS OF THE COAL PARTICLE TO BE REDUCED TO ONE TENTH OF
C...  ITS INITIAL VALUE, R0 = 0.0005.  THE INFINITE DISTANCE IN EQUATION
C...  (4) WILL BE TAKEN AS 10*R0.
C...
C...  IF THE QUASI-STEADY STATE ASSUMPTION IS MADE SO THAT Y  = 0 IN
C...                                                        T
C...  EQUATION (1), THEN EQUATION (1) CAN EASILY BE INTEGRATED TO GIVE
C...  Y(R).  THIS SOLUTION CAN THEN BE SUBSTITUTED IN EQUATION (2),
C...  WHICH IN TURN CAN BE INTEGRATED TO GIVE RP(T).  THE FINAL RESULT
C...  IS
C...
C...  RP**2 = R0**2 - (C*DAB*MC/RHOC)*T                             (7)
C...
C...  THE TIME REQUIRED FOR THE PARTICLE TO REACH A RADIUS OF 0.1*R0
C...  CAN THEN BE COMPARED WITH THE TIME OBTAINED FROM THE NUMERICAL
C...  SOLUTION OF EQUATIONS (1) TO (6).  THIS COMPARISON IS MADE IN
C...  SUBROUTINE PRINT.
C...
C...  COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(10),     RP
     2      /F/ YT(10),    RPT
     3      /S/ YR(10),YRR(10),  R(10)
     4      /C/    DAB,   RHOC,     MC,      C,     R0,     RG,      N,
     5              IP
      REAL          MC
C...
C...  SET THE MODEL PARAMETERS
      DAB=4./3600.
      RHOC=80.
      MC=12.
      C=14.7/(10.7*2460.)
      R0=0.0005
      RG=10.*R0
C...
C...  INITIAL CONDITIONS
      N=10
      DO 1 I=1,N
      Y(I)=1.0
1     CONTINUE
      RP=R0
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(10),     RP
     2      /F/ YT(10),    RPT
     3      /S/ YR(10),YRR(10),  R(10)
     4      /C/    DAB,   RHOC,     MC,      C,     R0,     RG,      N,
     5              IP
      REAL          MC
C...
C...  BOUNDARY CONDITIONS
      Y(N)=1.0
      Y(1)=0.0
C...
C...  CONSTRAIN THE VARIABLES TO MEANINGFUL VALUES
      DO 3 I=1,N
      IF(Y(I).LT.0.)Y(I)=0.
      IF(Y(I).GT.1.)Y(I)=1.
3     CONTINUE
      IF(RP.LT.0.)RP=0.
C...
C...  THE FOLLOWING CALLS TO THE SPATIAL DIFFERENTIATION SUBROUTINE
C...  DSS002 INTRODUCE AN APPROXIMATION INTO THE NUMERICAL SOLUTION
C...  SINCE THE FORMULAS IN THE SUBROUTINE ARE FOR A FIXED GRID (A
C...  GRID WHICH DOES NOT CHANGE WITH TIME).  IN THE PRESENT PROBLEM,
C...  THE GRID CHANGES WITH TIME.
C...
C...  ALSO, THE USUAL PROCEDURE OF IMPROVING THE NUMERICAL SOLUTION
C...  BY INCREASING THE NUMBER OF GRID POINTS IN THIS CASE ACTUALLY
C...  MAKES THE SOLUTION WORSE.  THIS IS APPARENTLY DUE TO THE FACT
C...  THAT WHEN THE NUMBER OF GRID POINTS IS INCREASED, E.G., FROM 10
C...  20, THE GRID SPACING, DX, IN THE FORMULAS IN SUBROUTINE DSS002
C...  IS REDUCED.  THUS, THE PERCENTAGE CHANGE IN THE GRID SPACING DUE
C...  TO THE MOVING BOUNDARY IS GREATER FOR THE FINER GRID (WITH MORE
C...  GRID POINTS).
C...
C...  THE DISTORTIONS IN THE NUMERICAL SOLUTIONS DUE TO THE MOVING
C...  BOUNDARY ARE APPARENT IN THE PROFILES OF Y(R,T) PRINTED IN SUBROU-
C...  TINE PRINT.  UNREALISTIC OSCILLATION IS CLEARLY EVIDENT, WHICH
C...  IS WORSE WITH INCREASING NUMBERS OF GRID POINTS.  IN FACT THE
C...  AGREEMENT BETWEEN THE NUMERICAL SOLUTION AND THE QUASI STEADY
C...  STATE ANALYTICAL SOLUTION IS SURPRISING CONSIDERING THE APPROXI-
C...  MATIONS IN THE NUMERICAL AND QUASI STEADY STATE SOLUTIONS.
C...
C...  CALCULATE THE DERIVATIVE Y
C...                            R
      CALL DSS002(RP,RG,N,Y,YR)
C...
C...  CALCULATE THE DERIVATIVE Y
C...                            RR
      CALL DSS002(RP,RG,N,YR,YRR)
C...
C...  EQUATION (1)
      DO 2 I=2,N
      R(I)=RP+(RG-RP)*FLOAT(I-1)/FLOAT(N-1)
      YT(I)=DAB*(YRR(I)+2./R(I)*YR(I))
2     CONTINUE
C...
C...  THE CONCENTRATION OF OXYGEN AT THE PARTICLE SURFACE IS FIXED
C...  AT ZERO (SEE THE ABOVE BOUNDARY CONDITION), SO THE TIME DERI-
C...  VATIVE IS SET TO ZERO
      R(1)=RP
      YT(1)=0.
C...
C...  EQUATION (2)
      RPT=-(C*DAB*MC/RHOC)*YR(1)
C...
C...  THE PARTICLE CAN ONLY BE CONSUMED BY THE REACTION, SO THE DERI-
C...  VATIVE DRP/DT CANNOT BE POSITIVE
      IF(RPT.GT.0.)RPT=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(10),     RP
     2      /F/ YT(10),    RPT
     3      /S/ YR(10),YRR(10),  R(10)
     4      /C/    DAB,   RHOC,     MC,      C,     R0,     RG,      N,
     5              IP
      REAL          MC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(41), RPP(2,41)
C...
C...  COMPUTE AND PRINT THE TIME FROM EQUATION (6)
      IP=IP+1
      IF(IP.EQ.1)THEN
      TIME=(RHOC/(C*DAB*MC))*(R0**2-(0.1*R0)**2)
      WRITE(NO,2)TIME
2     FORMAT(1H ,//,' STEADY STATE TIME ',F6.3)
      END IF
C...
C...  CALCULATE THE PARTICLE RADIUS FROM EQUATION (7)
      ARG=R0**2-(C*DAB*MC/RHOC)*T
      IF(ARG.LE.0.)RPSS=0.
      IF(ARG.GT.0.)RPSS=SQRT(ARG)
C...
C...  PRINT THE SOLUTION EVERY FOURTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/4*4).EQ.(IP-1))THEN
      WRITE(NO,1)T,(Y(I),I=1,N),RP,RPSS
1     FORMAT(1H ,//,' T = ',F4.2,//,
     1        ' Y(T,R)',/,2(5E10.3,/),/,
     2        '     RP',E10.3,'   RPSS',E10.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      RPP(1,IP)=RP
      RPP(2,IP)=RPSS
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.41)RETURN
      CALL TPLOTS(2,IP,TP,RPP)
      WRITE(NO,3)
3     FORMAT(1H ,/,
     1 ' COAL PARTICLE RADIUS VS TIME',/,
     2 ' 1 - UNSTEADY STATE MODEL, 2 - QUASI STEADY STATE MODEL')
      RETURN
      END
MOVING BOUNDARY PROBLEM
0.        5.0       0.125
   11 1000    1    1  ABS 0.0001
END OF RUNS
*APP REACT28
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A TUBULAR REACTOR WITH AXIAL DISPERSION
C...
C...  THE FOLLOWING MATHEMATICAL MODEL HAS BEEN PROPOSED FOR A TUBULAR
C...  REACTOR WITH AXIAL DISPERSION
C...
C...     C  = -V*C  + D*C   - K*(C**2)                          (1)
C...      T       Z      ZZ
C...
C...  WHERE
C...
C...     C       CONCENTRATION OF REACTANT
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE REACTOR
C...
C...     V       AVERAGE VELOCITY THROUGH THE REACTOR
C...
C...     D       AXIAL DISPERSION COEFFICIENT
C...
C...     K       REACTION VELOCITY CONSTANT
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     C(Z,0) = C0, C(0,T) = CI, C (ZL,T) = 0           (2)(3)(4)
C...                                Z
C...
C...  COMPUTE A NUMERICAL SOLUTION TO EQUATIONS (1) TO (4) FOR THE
C...  FOLLOWING PARAMETERS
C...
C...     V = K = 1, C0 = CI = 1, ZL = 10
C...
C...     D = 1 (CASE 1), 0.1 (CASE 2)
C...
C...  EQUATION (1) IS TERMED A CONVECTIVE-DIFFUSION EQUATION BECAUSE
C...  OF THE OCCURENCE OF THE CONVECTIVE TERM, - V*C , AND THE DIFFUSION
C...                                                Z
C...  TERM, D*C  .  AS D BECOMES SMALL, THE PROBLEM BECOMES MORE CON-
C...           ZZ
C...  VECTIVE, AND GENERALLY MORE DIFFICULT TO SOLVE NUMERICALLY.  IN
C...  PARTICULAR, AS THE PECLET NUMBER, PE, DEFINED AS PE = V*ZL/D BE-
C...  COMES SMALL, COMPUTATIONAL PROBLEMS MAY ARISE.  IN THE PRESENT
C...  CASE, PE HAS THE TWO VALUES (1*10/1) = 10 AND (1*10/0.1) = 100.
C...  THESE VALUES OF PE REPRESENT A MODERATE BALANCE BETWEEN CONVECTION
C...  AND DIFFUSION.  FOR PE GT 1000, THE PROBLEM IS STRONGLY CONVECTIVE
C...  AND THE SOLUTION IS COMPUTATIONALLY DIFFICULT TO OBTAIN.  FOR EX-
C...  AMPLE, SPURIOUS NUMERICAL EFFECTS, SUCH AS UNREALISTIC OSCILLA-
C...  TIONS CAN OCCUR.  IN THE LIMIT AS PE APPROACHES INFINITY, THE
C...  BOUNDARY CONDITION AT Z = ZL CAN BE DROPPED (EQUATION (1) IS NOW
C...  FIRST-ORDER IN Z), AND THE CALCULATION OF THE SOLUTION BECOMES
C...  EASIER.  THUS, LARGE (I.E., PE GT 1000) BUT FINITE VALUES OF PE
C...  PRESENT THE GREATEST COMPUTATIONAL DIFFICULTIES.
C...
C...  COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(21)
     2      /F/    CT(21)
     3      /S/    CZ(21),   CZZ(21),         V,         K,         D,
     4                 C0,        CI,        ZL,         N,        IP
      REAL K
C...
C...  SET THE MODEL PARAMETERS
      V=1.
      K=1.
      C0=1.
      CI=1.
      ZL=10.
      IF(NORUN.EQ.1)THEN
         D=1.0
      ELSE IF(NORUN.EQ.2)THEN
         D=0.1
      END IF
C...
C...  MODEL INITIAL CONDITION
      N=21
      DO 1 I=1,N
      C(I)=C0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(21)
     2      /F/    CT(21)
     3      /S/    CZ(21),   CZZ(21),         V,         K,         D,
     4                 C0,        CI,        ZL,         N,        IP
      REAL K
C...
C...  BOUNDARY CONDITION AT Z = 0
      C(1)=CI
C...
C...  C  FOR THE DIFFUSION TERM
C...   Z
      CALL DSS004(0.,ZL,N,C,CZ)
C...
C...  BOUNDARY CONDITIION AT Z = ZL
      CZ(N)=0.
C...
C...  C   FOR THE DIFFUSION TERM
C...   ZZ
      CALL DSS004(0.,ZL,N,CZ,CZZ)
C...
C...  C  FOR THE CONVECTIVE TERM
C...   Z
      CALL DSS020(0.,ZL,N,C,CZ,V)
C...
C...  PDE
      DO 1 I=2,N
      CT(I)=-V*CZ(I)+D*CZZ(I)-K*C(I)**2
1     CONTINUE
      CT(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     C(21)
     2      /F/    CT(21)
     3      /S/    CZ(21),   CZZ(21),         V,         K,         D,
     4                 C0,        CI,        ZL,         N,        IP
      REAL K
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION ZP(21), CP(6,21), CZP(6,21), CZZP(6,21), CTP(6,21)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,(  C(I),I=1,N,4),
     1             ( CZ(I),I=1,N,4),
     2             (CZZ(I),I=1,N,4),
     3             ( CT(I),I=1,N,4)
1     FORMAT(' T = ',F5.1,/,
     1       '   C(Z,T)',6F10.4,/,
     2       '  CZ(Z,T)',6F10.4,/,
     3       ' CZZ(Z,T)',6F10.4,/,
     4       '  CT(Z,T)',6F10.4,//)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      DO 2 I=1,N
      Z=ZL*FLOAT(I-1)/FLOAT(N-1)
      ZP(I)=Z
        CP(IP,I)=  C(I)
       CZP(IP,I)= CZ(I)
      CZZP(IP,I)=CZZ(I)
       CTP(IP,I)= CT(I)
2     CONTINUE
C...
C...  PLOT THE SPATIAL PROFILES
      IF(IP.LT.6)RETURN
C...
C...  C(Z,T) VS Z FOR T = 0, 1, 2, 3, 4, 5
      CALL TPLOTS(IP,N,ZP,  CP)
      WRITE(NO,11)
11    FORMAT(1H ,/,'   C(Z,T) VS Z, T = 0, 1, 2, 3, 4, 5')
C...
C...  CZ(Z,T) VS Z FOR T = 0, 1, 2, 3, 4, 5
      CALL TPLOTS(IP,N,ZP, CZP)
      WRITE(NO,12)
12    FORMAT(1H ,/,'  CZ(Z,T) VS Z, T = 0, 1, 2, 3, 4, 5')
C...
C...  CZZ(Z,T) VS Z FOR T = 0, 1, 2, 3, 4, 5
      CALL TPLOTS(IP,N,ZP,CZZP)
      WRITE(NO,13)
13    FORMAT(1H ,/,' CZZ(Z,T) VS Z, T = 0, 1, 2, 3, 4, 5')
C...
C...  CT(Z,T) VS Z FOR T = 0, 1, 2, 3, 4, 5
      CALL TPLOTS(IP,N,ZP, CTP)
      WRITE(NO,14)
14    FORMAT(1H ,/,'  CT(Z,T) VS Z, T = 0, 1, 2, 3, 4, 5')
      END
TUBULAR REACTOR WITH AXIAL DISPERSION
0.        5.        1.
   21 1000    1    1  REL 0.001
END OF RUNS
*APP REACT29
      SUBROUTINE INITAL
C...
C...  KINETICS OF CATALYTIC CRACKING SELECTIVITY
C....
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED FOR THE KINETICS OF CATA-
C...  LYTIC CRACKING SELECTIVITY*
C....
C...  *WEEKMAN, VERN W., JR., AND DONALD M. NACE, KINETICS OF CATALYTIC
C...  CRACKING SELECTIVITY IN FIXED, MOVING, AND FLUID BED REACTORS,
C...  A.I.CH.E. JOURNAL, VOL 16, NO. 3, PP 397-404.
C....
C...  THE SPECTRUM OF CHEMICAL SPECIES IN CATALYTIC CRACKING IS REDUCED
C...  TO JUST THREE COMPONENTS
C....
C...  Y1(Z,T)    CONCENTRATION OF THE ORIGINAL GAS OIL CHARGE MATERIAL
C....
C...  Y2(Z,T)    CONCENTRATION OF THE GASOLINE BOILING FRACTION (C5 -
C...             410 F)
C....
C...  Y3(Z,T)    REMAINING C4*S (DRY GAS AND COKE)
C....
C...  THE OVERALL OBJECTIVE IN RUNNING THE CATALYTIC CRACKING PROCESS
C...  IS TO MAXIMIZE Y2(Z,T) AND MINIMIZE Y3(Z,T).  THE FOLLOWING
C...  COMMENTARY IS INCLUDED IN THE WEEKMAN AND NACE PAPER.
C....
C...  ON A PURELY ECONOMIC BASIS, THE GASOLINE FRACTION REPRESENTS THE
C...  MOST SIGNIFICANT CONTRIBUTION TO THE OVERALL PROFITABILITY OF THE
C...  CATALYTIC CRACKING REACTOR.  THIS SIMPLIFIED REACTION SYSTEM IS
C...  SHOWN BELOW AS EQUATION (1)
C....
C...         K0
C...     C1 ---+ A1 C2 + A2 C3                                    (1A)
C....
C...               K2
C...           C2 ---+ C3                                         (1B)
C....
C...  HERE, C1, REPRESENTS THE GAS OIL CHARGED, WHILE C2 REPRESENTS THE
C...  C5-410 F GASOLINE FRACTION AND C3 THE BUTANES, DRY GAS AND COKE.
C...  THE A1 AND A2 COEFFICIENTS REPRESENT THE MASS OF C2 AND C3 PRO-
C...  DUCED PER MASS OF C1 CONVERTED, RESPECTIVELY.
C....
C...  FOR AN ISOTHERMAL, VAPOR-PHASE, PLUG FLOW REACTOR WITH NEGLIGIBLE
C...  INTERPARTICLE DIFFUSION, IT IS POSSIBLE TO DESCRIBE THE REACTIONS
C...  SHOWN IN EQUATIONS (1) IN TERMS OF TWO COUPLED CONTINUITY EQUA-
C...  TIONS GIVEN BELOW
C....
C...     Y1  + UV*Y1  = -R1(Y1,T)                                 (2A)
C...       T        Z
C....
C...     Y2  + UV*Y2  = A1*R1(Y1,T) - R2(Y2,T)                    (2B)
C...       T        Z
C....
C...  WHERE
C....
C...     Z         AXIAL POSITION ALONG THE REACTOR
C....
C...     T         TIME
C....
C...     UV        VAPOR VELOCITY
C....
C...     R1(Y1,T)  TIME-DEPENDENT RATE OF REACTION FOR GAS OIL CRACKING
C....
C...     R2(Y2,T)  TIME-DEPENDENT RATE OF REACTION FOR GASOLINE CRACKING
C....
C...  THE REACTION RATES ARE GIVEN BY
C....
C...     R1(Y1,T) = K0*(Y1**2)
C....
C...     R2(Y2,T) = K2*Y2
C....
C...  COMPUTE SOLUTIONS TO EQUATIONS (1) AND (2) FOR THE FOLLOWING
C...  PARAMETERS AND AUXILIARY CONDITIONS
C....
C...     K0 = 22.9/60, K2 = 1.7/60, A1 = 0.5, A2 = 0.5, UV = 2, ZL = 100
C....
C...     Y1(Z,0) = Y2(Z,0) = 0, Y1(0,T) = 1, Y2(0,T) = 0
C....
C...  PLOT THE SOLUTIONS AS SPATIAL PROFILES (Y1(Z,T) AND Y2(Z,T) VS
C...  Z WITH T AS A PARAMETER).
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    Y1(21),    Y2(21)
     2      /F/   Y1T(21),   Y2T(21)
     3      /S/   Y1Z(21),   Y2Z(21)
     4      /C/        K0,        K2,        A1,        UV,        ZL,
     5                  N,        IP
      REAL             K0,        K1
C....
C...  SET THE MODEL PARAMETERS
      K0=22.7/60.
      K2=1.70/60.
      A1=0.5
      A2=0.5
      UV=2.
      ZL=100.
      N=21
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y1(I)=0.
      Y2(I)=0.
1     CONTINUE
C...
C...  INITIAL DERRVIATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    Y1(21),    Y2(21)
     2      /F/   Y1T(21),   Y2T(21)
     3      /S/   Y1Z(21),   Y2Z(21)
     4      /C/        K0,        K2,        A1,        UV,        ZL,
     5                  N,        IP
      REAL             K0,        K1
C...
C...  CONSTRAIN THE CONCENTRATIONS TO MEANINGFUL VALUES
      DO 1 I=1,N
      IF(Y1(I).LT.0.)Y1(I)=0.
      IF(Y1(I).GT.1.)Y1(I)=1.
      IF(Y2(I).LT.0.)Y2(I)=0.
      IF(Y2(I).GT.1.)Y2(I)=1.
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y1(1)=1.
      Y2(1)=0.
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,Y1,Y1Z,UV)
      CALL DSS020(0.,ZL,N,Y2,Y2Z,UV)
C...
C...  PDES
      DO 2 I=2,N
      R1=K0*(Y1(I)**2)
      R2=K2*Y2(I)
      Y1T(I)=-UV*Y1Z(I)-R1
      Y2T(I)=-UV*Y2Z(I)+A1*R1-R2
2     CONTINUE
      Y1T(1)=0.
      Y2T(1)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    Y1(21),    Y2(21)
     2      /F/   Y1T(21),   Y2T(21)
     3      /S/   Y1Z(21),   Y2Z(21)
     4      /C/        K0,        K2,        A1,        UV,        ZL,
     5                  N,        IP
      REAL             K0,        K1
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION ZP(21), Y1P(6,21), Y2P(6,21)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,5)T
5     FORMAT(1H ,//,' T = ',F5.0,/,
     1 11X,'Z',5X,'Y1(Z,T)',5X,'Y2(Z,T)')
      DO 2 I=1,N,5
      Z=ZL*FLOAT(I-1)/FLOAT(N-1)
      WRITE(NO,3)Z,Y1(I),Y2(I)
3     FORMAT(F12.1,2F12.5)
2     CONTINUE
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      DO 4 I=1,N
      ZP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
      Y1P(IP,I)=Y1(I)
      Y2P(IP,I)=Y2(I)
4     CONTINUE
C...
C...  AT THE END OF THE RUN, THE CONCENTRATION PROFILES ARE PLOTTED
      IF(IP.LT.6)RETURN
C...
C...  PLOT THE SPATIAL PROFILES OF Y1(Z,T)
      CALL TPLOTS(IP,N,ZP,Y1P)
      WRITE(NO,11)
11    FORMAT(1H ,/,16X,
     1 ' Y1(Z,T) VS Z, T = 0, 20, 40, 60, 80, 100',/)
C...
C...  PLOT THE SPATIAL PROFILES OF Y2(Z,T)
      CALL TPLOTS(IP,N,ZP,Y2P)
      WRITE(NO,12)
12    FORMAT(1H ,/,16X,
     1 ' Y2(Z,T) VS Z, T = 0, 20, 40, 60, 80, 100',/)
C...
      RETURN
      END
KINETICS OF CATALYTIC CRACKING SELECTIVITY
0.        100.      20.
   42 1000    1    1  ABS 0.001
END OF RUNS
*APP REACT30
      SUBROUTINE INITAL
C...
C...  CONDUCTION, DIFFUSION AND REACTION IN A CATALYST PARTICLE
C...
C...  THE FOLLOWING SYSTEM OF TWO PARTIAL DIFFERENTIAL EQUATIONS (PDES)
C...  MODELS HEAT CONDUCTION, DIFFUSION AND REACTION IS A SPHERICAL
C...  CATALYST PARTICLE
C...
C...     RHO*CP*T   = K*(T   + (2/R)*T )
C...             TM       RR          R
C...
C...                - DH*K0*C*EXP(-E/(RG*T))
C...
C...     C   = D*(C   + (2/R)*C )
C...      TM       RR          R
C...
C...                - K0*C*EXP(-E/(RG*T))
C...
C...     T(R,TM)     CATALYST TEMPERATURE (K)
C...
C...     C(R,TM)     REACTANT CONCENTRATION (GM-MOL/CM**3)
C...
C...     TM          TIME (SEC)
C...
C...     R           RADIAL POSITION WITHIN THE PARTICLE (CM)
C...
C...     RHO         CATALYST DENSITY (GM/CM**3)
C...
C...     CP          CATALYST HEAT CAPACITY (CAL/GM C)
C...
C...     K           EFFECTIVE CATALYST CONDUCTIVITY (CAL/SEC CM C)
C...
C...     D           EFFECTIVE CATALYST DIFFUSIVITY (CM**2/SEC)
C...
C...     DH          HEAT OF REACTION (CAL/GM-MOL)
C...
C...     RG          GAS CONSTANT (CAL/GM-MOL C)
C...
C...     K0          ARRHENIUS FREQUENCY FACTOR (1/SEC)
C...
C...     E           ACTIVATION ENERGY (CAL/GM-MOL)
C...
C...     R0          PARTICLE RADIUS (CM)
C...
C...  THE INITIAL CONDITIONS ARE
C...
C...     T(R,0) = T0, C(R,0) = C0
C...
C...  AND THE BOUNDARY CONDITIONS ARE
C...
C...     T(R0,TM) = T0, T (0,TM) = 0
C...                     R
C...
C...     C(R0,TM) = C0, C (0,TM) = 0
C...                     R
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     RHO = 0.5, CP = 0.3, K = 0.0001, D = 0.00001, DH = -10000,
C...
C...     K0 = 1.0E+07, E = 8000., R = 1.987, R0 = 1, T0 = 500, C0 =
C...
C...     0.01
C...
C...  AS A CONSEQUENCE OF THE BOUNDARY CONDITIONS AT R = 0, THE TERMS
C...  IN THE PDES
C...
C...     (2/R)*T  AND (2/R)*C
C...            R            R
C...
C...  ARE INDETERMINATE AND HAVE THE VALUES 0/0 (FOR R = 0).  IF
C...  L*HOSPITAL*S RULE IS APPLIED (DIFFERENTIATION OF THE NUMERATOR
C...  AND DENOMINATOR), THESE TERMS BECOME
C...
C...     2*T   AND 2*C
C...        RR        RR
C...
C...  THES RESULTS ARE USED IN THE PROGRAMMING IN SUBROUTINE DERV.
C...
      COMMON/T/        TM,     NSTOP,     NORUN
     1      /Y/     T(11),     C(11)
     2      /F/    TT(11),    CT(11)
     3      /S/    TR(11),    CR(11),   TRR(11),   CRR(11)
     4      /C/     R(11),       RHO,        CP,         K,         D,
     5                 DH,        K0,         E,        RG,        R0,
     6                 AD,        T0,        C0,         N,        IP
      REAL              K,        K0
C...
C...  SET THE MODEL PARAMETERS
      RHO=0.5
      CP=0.3
      K=1.0E-04
      D=1.0E-05
      DH=-1.0E+04
      K0=1.0E+07
      E=8000.
      RG=1.987
      R0=1.0
C...
C...  PRECOMPUTE THE THERMAL DIFFUSIVITY FOR USE IN SUBROUTINE DERV
      AD=K/(RHO*CP)
C...
C...  PRECOMPUTE THE CONSTANT IN THE ENERGY BALANCE REACTION RATE TERM
C...  (USED IN SUBROUTINE DERV IN PLACE OF THE HEAT OF REACTION, DH)
      DH=DH/(RHO*CP)
C...
C...  RADIAL GRID POINTS
      N=11
      DO 1 I=1,N
      R(I)=FLOAT(I-1)/FLOAT(N-1)*R0
1     CONTINUE
C...
C...  INITIAL CONDITIONS
      T0=500.
      C0=0.01
      DO 2 I=1,N
      T(I)=T0
      C(I)=C0
2     CONTINUE
C...
C...  T0 AND C0 NOW BECOME THE BOUNDARY VALUES (FOR USE IN SUBROUTINE
C...  DERV)
      T0=500.
      C0=0.01
C...
C...  INITIAL DERVIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/        TM,     NSTOP,     NORUN
     1      /Y/     T(11),     C(11)
     2      /F/    TT(11),    CT(11)
     3      /S/    TR(11),    CR(11),   TRR(11),   CRR(11)
     4      /C/     R(11),       RHO,        CP,         K,         D,
     5                 DH,        K0,         E,        RG,        R0,
     6                 AD,        T0,        C0,         N,        IP
      REAL              K,        K0
C...
C...  BOUNDARY CONDITIONS AT R = R0
      T(N)=T0
      C(N)=C0
C...
C...  DERIVATIVES T (R,TM), C (R,TM)
C...               R         R
      CALL DSS004(0.,R0,N,T,TR)
      CALL DSS004(0.,R0,N,C,CR)
C...
C...  BOUNDARY CONDITIONS AT R = 0
      TR(1)=0.
      CR(1)=0.
C...
C...  DERIVATIVES T  (0,TM), C  (R,TM)
C...               RR         RR
      CALL DSS004(0.,R0,N,TR,TRR)
      CALL DSS004(0.,R0,N,CR,CRR)
C...
C...  PDES
C...
C...  R = 0
      REACT=K0*C(1)*EXP(-E/(RG*T(1)))
      TT(1)=AD*3.0*TRR(1)-DH*REACT
      CT(1)= D*3.0*CRR(1)-   REACT
C...
C...  R NE 0
      DO 1 I=2,N-1
      REACT=K0*C(I)*EXP(-E/(RG*T(I)))
      TT(I)=AD*(TRR(I)+(2.0/R(I))*TR(I))-DH*REACT
      CT(I)= D*(CRR(I)+(2.0/R(I))*CR(I))-   REACT
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT R = R0
      TT(N)=0.
      CT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/        TM,     NSTOP,     NORUN
     1      /Y/     T(11),     C(11)
     2      /F/    TT(11),    CT(11)
     3      /S/    TR(11),    CR(11),   TRR(11),   CRR(11)
     4      /C/     R(11),       RHO,        CD,         K,         D,
     5                 DH,        K0,         E,        RG,        R0,
     6                 AD,        T0,        C0,         N,        IP
      REAL              K,        K0
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TMP(51), TP(2,51), CP(2,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',4X,' T(0,TM)',1X,' T(R0/2,TM)',3X,' T(R0,TM)',/,
     1         10X,    4X,'TT(0,TM)',1X,'TT(R0/2,TM)',3X,'TT(R0,TM)',/,
     2         10X,    4X,' C(0,TM)',1X,' C(R0/2,TM)',3X,' C(R0,TM)',/,
     3         10X,    4X,'CT(0,TM)',1X,'CT(R0/2,TM)',3X,'CT(R0,TM)',/)
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
        WRITE(NO,2)TM, T(1), T(N/2+1), T(N),
     1                TT(1),TT(N/2+1),TT(N),
     2                 C(1), C(N/2+1), C(N),
     3                CT(1),CT(N/2+1),CT(N)
2       FORMAT(E10.3,3E12.3,/,10X,3E12.3,/,10X,3E12.3,/,
     1                        10X,3E12.3,/,10X,3E12.3,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TMP(IP)=TM
      TP(1,IP)=T(1)
      TP(2,IP)=T(N)
      CP(1,IP)=C(1)
      CP(2,IP)=C(N)
C...
C...  PLOT THE SOLUTION
C...
      IF(IP.LT.51)RETURN
      CALL TPLOTS(2,IP,TMP,TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' 1 - T(0,TM), 2 - T(R0,TM) (K) VS TM (SEC)')
      CALL TPLOTS(2,IP,TMP,CP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' 1 - C(0,TM), 2 - C(R0,TM) (GM-MOL/CM**3)',/,
     1 ' VS TM (SEC)')
      RETURN
      END
CONDUCTION, DIFFUSION AND REACTION IN A CATALYST PARTICLE
0.           1.0E-04   2.0E-06
   22 1000    1    1  REL 0.001
END OF RUNS
*APP REACT31
      SUBROUTINE INITAL
C...
C...  RIVER POLLUTION MODEL
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED FOR POLLUTION TRANSPORT
C...  IN A RIVER (1):
C...
C...  U  = A*U   - B*U  - C*U + PS(X,T)                         (1)
C...   T      XX      X
C...
C...  WHERE
C...
C...  U       BIOCHEMICAL OXYGEN DEMAND (BOD) (M/L**3)
C...
C...  X       DISTANCE ALONG THE RIVER (L)
C...
C...  T       TIME (T)
C...
C...  A       DISPERSION COEFFICIENT (L**2/T)
C...
C...  B       VELOCITY OF FLOW (L/T)
C...
C...  C       BOD DECAY COEFFICIENT (1/T)
C...
C...  PS(X,T) POLLUTION SOURCES (M/L**3-T)
C...
C...  (1)  SHIBATA, Y., AND W. J. KARPLUS, DISTRIBUTED SOURCE IDENTIFI-
C...       CATION IN RIVER POLLUTION SYSTEMS BY PATTERN RECOGNITION,
C...       TRANS. SOCIETY FOR COMPUTER SIMULATION, VOL. 3, NO. 1, PP.
C...       1-29, JAN., 1986
C...
C...  EQAUTION (1) COULD, FOR EXAMPLE, BE USED TO SIMULATE THE POLLUTION
C...  OF THE RHINE RIVER ON NOVEMBER 10, 1986 RESULTING FROM A LARGE
C...  DISCHARGE OF PESTICIDE FROM A CHEMICAL PLANT IN SWITZERLAND.  THE
C...  SOURCE FUNCTION, PS(X,T), WOULD BE THE SPATIAL-TIME DESCRIPTION OF
C...  THE DISCHARGE.
C...
C...  THE FOLLOWING REFERENCES PERTAIN TO THE SPILL:
C...
C...  (2)  LEWIS, PAUL, 'HUGE CHEMICAL SPILL IN THE RHINE CREATES HAVOC
C...       IN FOUR COUNTRIES', THE NEW YORK TIMES, NOVEMBER 11, 1986
C...
C...  (3)  ROTH, TERRENCE, 'SWISS ACCIDENT THAT POLLUTED THE RHINE MAY
C...       HAVE HEAVIEST IMPACT ON GERMANY', THE WALL STREET JOURNAL,
C...       NOVEMBER 11, 1986
C...
C...  (4)  NETTER, THOMAS W., 'ANGER ALONG THE RHINE GROWS AFTER CHEMI-
C...       CAL SPILL', THE NEW YORK TIMES, NOVEMBER 12, 1986
C...
C...  (5)  STUDER, MARGARET A., 'SWISS NEVER THOUGHT SANDOZ DISASTER
C...       COULD HAPPEN IN THEIR ORDERLY WORLD', THE WALL STREET JOUR-
C...       NAL, NOVEMBER 13, 1986
C...
C...  (6)  'EUROPEAN OFFICIALS AGREE ON MEASURES TO PROTECT THE RHINE',
C...       THE WALL STREET JOURNAL, NOVEMBER 13, 1986
C...
C...  (7)  TAGLIABUE, JOHN, 'RHINE POISONING STRETCHING 185 MILES', THE
C...       NEW YORK TIMES, NOVEMBER 13, 1986
C...
C...  (8)  LEWIS, PAUL, 'SWISS WILL PAY COMPENSATION FOR SPILL', THE
C...       NEW YORK TIMES, NOVEMBER 13, 1986
C...
C...  (9)  MARCOM, JOHN, JR., 'EUROPE'S ENVIRONMENTAL POLICY FOUNDERS',
C...       THE WALL STREET JOURNAL, NOVEMBER 14, 1986
C...
C... (10)  'SWISS ANNOUNCE PROCEDURE FOR A CLEANUP OF THE RHINE', THE
C...       STREET JOURNAL, NOVEMBER 14, 1986
C...
C... (11)  NETTER, THOMAS W., 'MERCURY A KEY CONCERN IN RHINE SPILL',
C...       THE NEW YORK TIMES, NOVEMBER 15, 1986
C...
C...  THE INITIAL CONDITION FOR EQUATION (1) IS
C...
C...  U(X,0) = 0, X0 LE X LE XF                                 (2)
C...
C...  AND THE BOUNDARY CONDITIONS ARE
C...
C...  U(X0,T) = U(XF,T) = 0, T GT 0                          (3)(4)
C...
C...  WHERE
C...
C...  X0      X AT THE BEGINNING OF THE RIVER
C...
C...  XF      X AT THE END OF THE RIVER
C...
C...  COMPUTE A SOLUTION TO EQUATIONS (1) TO (4) BY THE NUMERICAL
C...  METHOD OF LINES ON A 51-POINT GRID (49 INTERIOR POINTS).  USE
C...  THE FOLLOWING NUMERICAL VALUES OF THE PARAMETERS
C...
C...  A      25 KM**2/HR
C...
C...  B      5 KM/HR
C...
C...  C      0 1/HR
C...
C...  X0     0 KM
C...
C...  XF     500 KM
C...
C...  PS(X,T)      0, X NE 250, T GE 0
C...
C...             100, X = 250, 0 LE T LE 10 HR
C...
C...               0, X = 250, T GT 10 HR
C...
C...  COMPUTE U(X,T) (U(X,T) AT THE 51 GRID POINTS) AND PLOT U(X,T)
C...  VS X FOR SIX VALUES OF T.
C...
C...  THE FOLLOWING CODING IS FOR THREE VARIATIONS OF THE MODEL.  IN
C...  PARTICULAR, THE EXIT BOUNDARY CONDITION (4) IS CHANGED, AS DES-
C...  CRIBED IN SUBROUTINE DERV.
C...
C...  DSS/2 COMMON
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  MODEL PARAMETERS
      A=25.
      B=5.
      C=0.
      X0=0.
      XF=500.
      N=51
C...
C...  SPATIAL GRID
      DX=(XF-X0)/FLOAT(N-1)
      DXS=DX*DX
      DO 1 I=1,N
      X(I)=X0+DX*FLOAT(I-1)
1     CONTINUE
      DX=2.0*DX
C...
C...  MODEL INITIAL CONDITION (2)
      DO 2 I=1,N
      U(I)=0.
2     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
C...
C...  SUBROUTINE DERV CALLS SUBROUTINES DERV1, DERV2 AND DERV3 FOR
C...  ALTERNATE BOUNDARY CONDITIONS AT X = XF
C...
      COMMON/T/      T,  NSTOP,  NORUN
C...
C...  *****************************************************************
C...
C...  DERV1 IMPLEMENTS THE DIRICHLET BOUNDARY CONDITION U(XF,T) = 0.
C...  THIS CONDITION REPRESENTS A CONDITION OF NO POLLUTION AT THE END
C...  OF THE RIVER.
      IF(NORUN.EQ.1)CALL DERV1
C...
C...  *****************************************************************
C...
C...  DERV2 IMPLEMENTS THE NEUMANN BOUNDARY CONDITION U (XF,T) = 0.
C...                                                   X
C...  THIS CONDITION REPRESENTS PURE CONVECTION (FLOW) FROM THE END OF
C...  THE RIVER.
      IF(NORUN.EQ.2)CALL DERV2
C...
C...  *****************************************************************
C...
C...  DERV3 IMPLEMENTS THE TIME-DEPENDENT BOUNDARY CONDITION U (XF,T)
C...                                                          T
C...  = -B*U (XF,T).  THIS CONDITION REPRESENTS CONVECTION (FLOW) PLUS
C...        X
C...  ACCUMULATION AT THE END OF THE RIVER.
      IF(NORUN.EQ.3)CALL DERV3
C...
C...  *****************************************************************
C...
      RETURN
      END
      SUBROUTINE DERV1
C...
C...  SUBROUTINE DERV1 IMPLEMENTS THE NUMERICAL METHOD OF LINES
C...  SOLUTION OF EQUATIONS (1) TO (4)
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  BOUNDARY CONDITION (3)
      U(1)=0.
      UT(1)=0.
C...
C...  BOUNDARY CONDITION (4)
      U(N)=0.
      UT(N)=0.
C...
C...  EQUATION (1)
      DO 1 I=2,N-1
      UT(I)=A*(U(I+1)-2.0*U(I)+U(I-1))/DXS
     1     -B*(U(I+1)-U(I-1))/DX
     2     -C*U(I)+PS(X(I),T)
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV2
C...
C...  SUBROUTINE DERV2 IMPLEMENTS THE NUMERICAL METHOD OF LINES
C...  SOLUTION OF EQUATIONS (1) TO (3) WITH BOUNDARY CONDITION (4)
C...  REPLACED BY THE NEUMANN BOUNDARY CONDITION U (XF,T) = 0
C...                                              X
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  BOUNDARY CONDITION (3)
      U(1)=0.
      UT(1)=0.
C...
C...  NEUMANN BOUNDARY CONDITION
      U(N)=(1.0/3.0)*(4.0*U(N-1)-U(N-2))
      UT(N)=0.
C...
C...  EQUATION (1)
      DO 1 I=2,N-1
      UT(I)=A*(U(I+1)-2.0*U(I)+U(I-1))/DXS
     1     -B*(U(I+1)-U(I-1))/DX
     2     -C*U(I)+PS(X(I),T)
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV3
C...
C...  SUBROUTINE DERV3 IMPLEMENTS THE NUMERICAL METHOD OF LINES
C...  SOLUTION OF EQUATIONS (1) TO (3) WITH BOUNDARY CONDITION (4)
C...  REPLACED BY THE TIME-DEPENDENT BOUNDARY CONDITION U (XF,T) =
C...  = -B*U (XF,T)                                      T
C...        X
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  BOUNDARY CONDITION (3)
      U(1)=0.
      UT(1)=0.
C...
C...  TIME-DEPENDENT BOUNDARY CONDITION
      UT(N)=-B*(1.0/DX)*(3.0*U(N)-4.0*U(N-1)+U(N-2))
C...
C...  EQUATION (1)
      DO 1 I=2,N-1
      UT(I)=A*(U(I+1)-2.0*U(I)+U(I-1))/DXS
     1     -B*(U(I+1)-U(I-1))/DX
     2     -C*U(I)+PS(X(I),T)
1     CONTINUE
      RETURN
      END
      FUNCTION PS(X,T)
C...
C...  FUNCTION PS(X,T) DEFINES THE POLLUTION SOURCE FUNCTION
C...
C...  POLLUTION ENTERS THE RIVER AT X = 250
      IF((X.GT.249.5).AND.(X.LT.250.5))THEN
C...
C...  THE POLLUTION ENTERS THE RIVER FOR 10 TIME UNITS
         IF(T.LE.10.0)THEN
            PS=100.
         ELSE
C...
C...  AFTER TEN TIME UNITS, THE POLLUTION IS ENDED
            PS=0.
         END IF
      ELSE
C...
C...  THE RIVER IS NOT POLLUTED AT OTHER LOCATIONS (THAN X = 250)
         PS=0.
      END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  ADDITIONAL ARRAY FOR PLOTTING
      COMMON/CAL/ UP(6,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',6X,'U(0,T)',4X,'U(100,T)',4X,'U(200,T)',
     1            4X,'U(300,T)',4X,'U(400,T)',4X,'U(500,T)')
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,U(1),U(11),U(21),U(31),U(41),U(51)
2     FORMAT(F10.2,6F12.4)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      DO 3 I=1,N
      UP(IP,I)=U(I)
3     CONTINUE
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.6)RETURN
      CALL TPLOTS(IP,N,X,UP)
      WRITE(NO,4)
4     FORMAT(1H ,/,' BIOCHEMICAL OXYGEN DEMAND (BOD) VS X',/,
     1             ' WITH T AS A PARAMETER, T = 0, 20,..., 100')
C...
C...  *****************************************************************
C...
C...  THE FOLLOWING CALL TO A CONTINUOUS PLOTTER IS MACHINE DEPENDENT
C...  AND MUST BE CHANGED FOR OTHER COMPUTERS OR CONVERTED TO COMMENTS.
C...  IF SUBROUTINE CALCOM IS NOT CALLED, SUBORDINATE ROUTINES QIKSAX,
C...  QIKSET, QIKPLT, LABEL AND SYMBOL ALSO WILL NOT BE CALLED
C...  CALL CALCOM
C...
C...  *****************************************************************
C...
      RETURN
      END
      SUBROUTINE CALCOM
C...
C...  SUBROUTINE CALCOM DRAWS THE PLOT OF THE NUMERICAL SOLUTION ON A
C...  CONTINUOUS PLOTTER
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(51)
     2      /F/ UT(51)
     3      /C/      A,      B,      C,     X0,     XF,     DX,    DXS,
     4           X(51),      N,     IP
C...
C...  ADDITIONAL ARRAY FOR PLOTTING
      COMMON/CAL/ UP(6,51)
C...
C...  PLOT U(X,T) VS X FOR T = 0, 20,..., 100
      CALL QIKSAX(3,3)
      CALL QIKSET(5.,0.,100.,8.,-10.,20.)
      CALL QIKPLT(X,UP,-N,8H*X (KM)*,14H*U(X,T) (BOD)*,
     1 33H*BIOCHEMICAL OXYGEN DEMAND (BOD)*,-6)
      CALL LABEL
      RETURN
      END
      SUBROUTINE LABEL
C...
C...  SUBROUTINE LABEL PRINTS LEGENDS ON THE PLOTS OF THE NUMERICAL
C...  SOLUTION DRAWN BY THE CONTINUOUS PLOTTER
C...
C...  DIMENSION THE ARRAY AND DEFINE THE NUMERICAL CODES FOR THE
C...  PLOTTED SYMBOLS
      DIMENSION ISYM(6)
      DATA ISYM/1,2,3,4,5,6/
C...
C...  PRINT THE FIRST LINE IN THE LEGEND
      X1=-5.25
      X2=-5.11
      Y1=8.5
      Y2=8.45
      CALL SYMBOL(X1,Y1,0.125,ISYM(1),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,13H - T = 0 (HR),0.,13)
C...
C...  PRINT THE SECOND LINE IN THE LEGEND
      Y1=Y1-0.35
      Y2=Y2-0.35
      CALL SYMBOL(X1,Y1,0.125,ISYM(2),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,9H - T = 20,0.,9)
C...
C...  PRINT THE THIRD LINE IN THE LEGEND
      Y1=Y1-0.35
      Y2=Y2-0.35
      CALL SYMBOL(X1,Y1,0.125,ISYM(3),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,9H - T = 40,0.,9)
C...
C...  PRINT THE FOURTH LINE IN THE LEGEND
      Y1=Y1-0.35
      Y2=Y2-0.35
      CALL SYMBOL(X1,Y1,0.125,ISYM(4),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,9H - T = 60,0.,9)
C...
C...  PRINT THE FIFTH LINE IN THE LEGEND
      Y1=Y1-0.35
      Y2=Y2-0.35
      CALL SYMBOL(X1,Y1,0.125,ISYM(5),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,9H - T = 80,0.,9)
C...
C...  PRINT THE SIXTH LINE IN THE LEGEND
      Y1=Y1-0.35
      Y2=Y2-0.35
      CALL SYMBOL(X1,Y1,0.125,ISYM(6),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,10H - T = 100,0.,10)
      RETURN
      END
RIVER POLLUTION MODEL, DIRICHLET BOUNDARY CONDITION
0.        100.0     20.0
   51 1000    1    1  ABS 0.001
RIVER POLLUTION MODEL, NEUMANN BOUNDARY CONDITION
0.        100.0     20.0
   51 1000    1    1  ABS 0.001
RIVER POLLUTION MODEL, TIME-DEPENDENT BOUNDARY CONDITION
0.        100.0     20.0
   51 1000    1    1  ABS 0.001
END OF RUNS
*APP REACT32
      SUBROUTINE INITAL
C...
C...  TEMPERATURE PROFILES IN A TUBULAR REACTOR
C...
C...  THE FOLLOWING INITIAL-VALUE ORDINARY DIFFERENTIAL EQUATIONS
C...  ARE GIVEN BY DAVIS (1)
C...
C...     DY/DZ = -DA*Y*EXP(DELTA*(1 - 1/THETA))                    (1)
C...
C...     DTHETA/DZ = BETA*DA*Y*EXP(DELTA*(1 - 1/THETA))
C...                                                               (2)
C...                - HW*(THETA - THETAW)
C...
C...  WHERE
C...
C...     Y        REACTANT CONCENTRATION, NORMALIZED WITH RESPECT TO
C...              THE ENTERING CONCENTRATION, C0 (DIMENSIONLESS)
C...
C...     THETA    FLUID TEMPERATURE, NORMALIZED WITH RESPECT TO THE
C...              ENTERING TEMPERATURE, T0 (DIMENSIONLESS)
C...
C...     Z        DISTANCE ALONG THE REACTOR, NORMALIZED WITH RESPECT
C...              TO THE REACTOR LENGTH, L (DIMENSIONLESS)
C...
C...     THETAW   REACTOR WALL TEMPERATURE, NORMALIZED WITH RESPECT TO
C...              ENTERING FLUID TEMPERATURE, T0 (DIMENSIONLESS)
C...
C...     DA       DIMENSIONLESS GROUPS OF CONSTANTS (SEE DAVIS FOR THE
C...     BETA     DETAILS)
C...     DELTA
C...     HW
C...
C...     (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR
C...          CHEMICAL ENGINEERS, JOHN WILEY AND SONS, INC., NEW
C...          YORK, 1984
C...
C...  THE INITIAL CONDITIONS FOR EQUATIONS (1) AND (2), WHICH FOLLOW
C...  FROM THE DEFINITIONS OF Y, THETA AND Z, ARE
C...
C...     Y(0) = 1, THETA(0) = 1                                 (3)(4)
C...
C...  THE VALUE OF THE GAS CONSTANT REQUIRED IN THE DIMENSIONLESS
C...  GROUP DELTA, RG, CAN BE COMPUTED FROM THE FOLLOWING INFORMATION
C...
C...     RG = 1.987 GM CAL/GM MOL-K
C...
C...     1 BTU = 1.055E+03 JOULES
C...
C...     1 BTU = 454/1.8 GM CAL = 252 GM CAL
C...
C...  THUS,
C...
C...     RG = (1.987 GM CAL/GM MOL-K)*(1.055E+03 J/252 GM CAL)*
C...
C...          (0.001 KJ/J)*(1 GM MOL/0.001 KMOLE)
C...
C...        = 8.3186 KJ/KMOLE-K
C...
C...  DSS/2 COMMON
      COMMON/T/      Z,  NSTOP,  NORUN
     1      /Y/      Y,     TH
     2      /F/   DYDZ,  DTHDZ
     3      /C/     DA,   BETA,  DELTA,     HW,    THW,     IP
      REAL           L,     K0
C...
C...  SET THE MODEL PARAMETERS (THESE VALUES ARE GIVEN IN DAVIS)
      L=2.
      R=0.1
      C0=0.03
      T0=700.
      DH=1.0E+04
      CP=1.0
      EA=100.
      RHO=1.2
      U0=3.0
      K0=5.0
      RG=8.3186
      THW=1.0
C...
C...  VARY THE HEAT TRANSFER COEFFICIENT AT THE REACTOR WALL TO
C...  DETERMINE WHETHER IT CAN BE OPERATED ESSENTIALLY ISOTHERMALLY
C...  (THESE VALUES ARE SUGGESTED BY PROBLEM 3, P46, DAVIS)
      IF(NORUN.EQ.1)U=0.
      IF(NORUN.EQ.2)U=0.07
      IF(NORUN.EQ.3)U=70.
C...
C...  COMPUTE VARIOUS CONSTANTS
      DA=L*K0/U0
      BETA=C0*DH/(RHO*CP*T0)
      DELTA=EA/(RG*T0)
      HW=(2.0*U/R)*(L/(RHO*CP*U0))
C...
C...  INITIAL (ENTRANCE) CONDITIONS
      Y=1.0
      TH=1.0
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      Z,  NSTOP,  NORUN
     1      /Y/      Y,     TH
     2      /F/   DYDZ,  DTHDZ
     3      /C/     DA,   BETA,  DELTA,     HW,    THW,     IP
      REAL           L,     K0
C...
C...  MODEL ALGEBRA
      EXPON=EXP(DELTA*(1.0-1.0/TH))
C...
C...  DIFFERENTIAL EQUATIONS
      DYDZ=-DA*Y*EXPON
      DTHDZ=BETA*DA*Y*EXPON-HW*(TH-THW)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      Z,  NSTOP,  NORUN
     1      /Y/      Y,     TH
     2      /F/   DYDZ,  DTHDZ
     3      /C/     DA,   BETA,  DELTA,     HW,    THW,     IP
      REAL           L,     K0
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION ZP(51), YP(3,51), THP(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'Z',11X,'Y',7X,'THETA')
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IP=IP+1
      WRITE(NO,2)Z,Y,TH
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
2     FORMAT(F10.2,2F12.5)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      ZP(IP)=Z
       YP(NORUN,IP)=Y
      THP(NORUN,IP)=TH
C...
C...  PLOT THE SOLUTIONS AT THE END OF THE THIRD RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.3)RETURN
C...
C...  CONCENTRATION PROFILES
      CALL TPLOTS(NORUN,IP,ZP,YP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' CONCENTRATION PROFILES, U = 0, 0.07, 70')
C...
C...  TEMPERATURE PROFILES
      CALL TPLOTS(NORUN,IP,ZP,THP)
      WRITE(NO,12)
12    FORMAT(1H ,/,' TEMPERATURE PROFILES, U = 0, 0.07, 70')
      RETURN
      END
NO HEAT TRANSFER AT THE WALL (U = 0)
0.        1.0       0.02
    2 1000    1    1  REL 0.001
MODERATE HEAT TRANSFER AT THE WALL (U = 0.07)
0.        1.0       0.02
    2 1000    1    1  REL 0.001
HIGH HEAT TRANSFER AT THE WALL (U = 70)
0.        1.0       0.02
    2 1000    1    1  REL 0.001
END OF RUNS
*APP REACT33
      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 REACT34
      SUBROUTINE INITAL
C...
C...  KINETICS OF A BIOCHEMICAL REACTION WHEN TWO ORGANISMS COMPETE
C...  FOR THE SAME SUBSTRATE
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED BY YANG AND HUMPHREY (1)
C...  FOR THE KINETICS OF A BIOCHEMICAL REACTION WHEN TWO ORGANISMS
C...  COMPETE FOR A COMMON SUBSTRATE:
C...
C...     DX1/DT = MU1*X1 - D*X1
C...
C...     DX2/DT = MU2*X2 - D*X2
C...
C...     DXS/DT = -MU1*X1/Y1 - MU2*X2/Y2 + D*(SR - S)
C...
C...     MU1 = MU1MAX/(1 + KS1/S + S/KI1)
C...
C...     MU2 = MU2MAX/(1 + KS2/S + S/KI2)
C...
C...  WHERE
C...
C...     X1,      CONCENTRATIONS OF THE TWO ORGANISMS
C...     X2
C...
C...     S        CONCENTRATION OF THE SUBSTRATE
C...
C...     T        TIME
C...
C...     MU1,     SPECIFIC GROWTH RATES
C...     MU2
C...
C...  (1)  YANG, R. D., AND A. E. HUMPHREY, (1975) BIOTECHN. AND
C...       BIOENG., 17, 1211
C...
C...  THE CONSTANTS IN THE ORDINARY DIFFERENTIAL EQUATIONS (ODES) ARE
C...
C...     MU1MAX,  MAXIMUM GROWTH RATES
C...     MU2MAX
C...
C...     KS1,     MICHAELIS CONSTANTS
C...     KS2
C...
C...     KI1,     INHIBITION CONSTANTS
C...     KI2
C...
C...     Y1,      YIELD COEFFICIENTS
C...     Y2
C...
C...     D        DILUTION RATE
C...
C...     SR       FEED CONCENTRATION OF THE NUTRIENT (SUBSTRATE)
C...
C...  IF THERE IS NO INHIBITION FOR EITHER OR BOTH SPECICIES, THE
C...  CORRESPONDING INHIBITION CONSTANTS ARE INFINITE.
C...
C...  THE NUMERICAL VALUES OF THE CONSTANTS IN THE ODES ARE
C...
C...     MU1MAX = MU2MAX = KS1 = KS2 = KI1 = KI2 = Y1 = Y2 = 1
C...
C...     SR = 0.1, D = 1, 0.1 (TWO CASES)
C...
C...  COMPUTE A SOLUTION TO THE THREE ODES SUBJECT TO THE INITIAL
C...  CONDITIONS
C...
C...     X1(0) = X2(0) = S(0) = 0.01
C...
      COMMON/T/      T,  NOSTOP,  NORUN
     1      /Y/     X1,      X2,      S
     2      /F/  DX1DT,   DX2DT,   DSDT
     3      /C/ MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     4              Y1,     Y2,      D,     SR,    MU1,    MU2,
     5              IP
      REAL      MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     1          MU1   , MU2
C...
C...  MODEL CONSTANTS
      MU1MAX=1.0
      MU2MAX=1.0
      KS1=1.0
      KS2=1.0
      KI1=1.0
      KI2=1.0
      Y1=1.0
      Y2=1.0
      SR=0.1
      IF(NORUN.EQ.1)D=1.0
      IF(NORUN.EQ.2)D=0.1
C...
C...  MODEL INITIAL CONDITIONS
      X1=0.01
      X2=0.01
      S=0.01
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NOSTOP,  NORUN
     1      /Y/     X1,      X2,      S
     2      /F/  DX1DT,   DX2DT,   DSDT
     3      /C/ MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     4              Y1,     Y2,      D,     SR,    MU1,    MU2,
     5              IP
      REAL      MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     1          MU1   , MU2
C...
C...  MODEL CONSTRAINTS
      IF(X1.LT.0.)X1=0.
      IF(X2.LT.0.)X2=0.
      IF(S .LT.0.)S =0.
C...
C...  MODEL ALGEBRA
      MU1=MU1MAX/(1.0+KS1/S+S/KI1)
      MU2=MU2MAX/(1.0+KS2/S+S/KI2)
C...
C...  MODEL ODES
      DX1DT=MU1*X1-D*X1
      DX2DT=MU2*X2-D*X2
      DSDT=-MU1*X1/Y1-MU2*X2/Y2+D*(SR-S)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NOSTOP,  NORUN
     1      /Y/     X1,      X2,      S
     2      /F/  DX1DT,   DX2DT,   DSDT
     3      /C/ MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     4              Y1,     Y2,      D,     SR,    MU1,    MU2,
     5              IP
      REAL      MU1MAX, MU2MAX,    KS1,    KS2,    KI1,    KI2,
     1          MU1   , MU2
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL TP(51), XP(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)THEN
         WRITE(NO,1)
1        FORMAT(11X,'T',10X,'X1',10X,'X2',11X,'S',9X,'MU1',9X,'MU2')
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         MU1=MU1MAX/(1.0+KS1/S+S/KI1)
         MU2=MU2MAX/(1.0+KS2/S+S/KI2)
         WRITE(NO,2)T,X1,X2,S,MU1,MU2
2        FORMAT(F12.2,5F12.4)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      XP(1,IP)=X1
      XP(2,IP)=X2
      XP(3,IP)=S
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.51)RETURN
      CALL TPLOTS(3,IP,TP,XP)
      WRITE(NO,3)
3     FORMAT(1H ,/,' 1 - X1, 2 - X2, 3 - S VS T')
      IP=0
      RETURN
      END
KINETICS OF A BIOCHEMICAL REACTION WITH COMMON SUBSTRATE
0.        0.2       0.004
    3 1000    1    1  REL 0.001
KINETICS OF A BIOCHEMICAL REACTION WITH COMMON SUBSTRATE
0.        0.2       0.004
    3 1000    1    1  REL 0.001
END OF RUNS
*APP REACT35
      SUBROUTINE INITAL
C...
C...  SOLUTION OF A SECOND ORDER, NONLINEAR, TWO POINT BOUNDARY VALUE
C...  ORDINARY DIFFERENTIAL EQUATION BY QUASILINEARIZATION AND THE
C...  METHOD OF FALSE TRANSIENTS - APPLICATION IN CHEMICAL KINETICS
C...
C...  CONSIDER THE HEATING OF A SOLID IN WHICH AN EXOTHERMIC REACTION
C...  TAKES PLACE.  A STEADY STATE ENERGY BALANCE ON A SECTION OF THE
C...  SOLID OF THICKNESS OF DX GIVES:
C...
C...     A*Q(X) - A*Q(X+DX) = HR*A*DX*RHO*K0*EXP(-E/(R*T))
C...
C...  WHERE
C...
C...     Q       HEAT FLUX BY CONDUCTION (CAL/CM**2-SEC)
C...
C...     T       ABSOLUTE TEMPERATURE (K)
C...
C...     X       DISTANCE ALONG THE SOLID (CM)
C...
C...     A       CROSS SECTIONAL AREA OF THE SECTION (CM**2)
C...
C...     HR      HEAT OF REACTION (CAL/GM)
C...
C...     RHO     DENSITY (GM/CM**3)
C...
C...     K0      PRE-EXPONENTIAL FACTOR (1/SEC)
C...
C...     E       ACTIVATION ENERGY (CAL/GM MOL)
C...
C...     R       GAS CONSTANT (CAL/GM MOL-K)
C...
C...  DIVISION BY A*DX, FOLLOWED BY DX ---> 0 GIVES
C...
C...     -Q  = HR*RHO*K0*EXP(-E/*R*T))                          (1)
C...       X
C...
C...  WHERE A LETTER SUBSCRIPT DENOTES A DERIVATIVE, E.G., Q  = DQ/DX.
C...                                                        X
C...
C...  EQUATION (1) CONTAINS TWO DEPENDENT VARIABLES, Q AND T, SO THAT
C...  A SECOND EQUATION IS REQUIRED
C...
C...     Q = -K*T                                               (2)
C...             X
C...
C...  EQUATION (2) IS FOURIER'S FIRST LAW.  SUBSTUTION OF EQUATION (2)
C...  IN (1) GIVES
C...
C...     T   = (HR*RHO/K)*K0*EXP(-E/(R*T))                      (3)
C...      XX
C...
C...  EQUATION (3) IS A NONLINEAR, BOUNDARY VALUE ORDINARY DIFFERENTIAL
C...  EQUATION, WHICH WILL BE INTEGRATED NUMERICALLY SUBJECT TO THE TWO
C...  BOUNDARY CONDITIONS
C...
C...     T(0) = TA, T (L) = 0                                (4)(5)
C...                 X
C...
C...     TA      AMBIENT TEMPERATURE (K)
C...
C...     L       LENGTH OF THE SOLID (CM)
C...
C...  IF THE SECOND DERIVATIVE IN EQUATION (3) IS REPLACED WITH A SECOND
C...  ORDER APPROXIMATION
C...
C...     T   = (T(I+1) - 2*T(I) + T(I-1))/DX**2
C...      XX
C...
C...  EQUATION (3) BECOMES
C...
C...     (T(I+1) - 2*T(I) + T(I-1))/DX**2 - D*EXP(-E/(R*T(I)) = 0    (6)
C...
C...  WHERE
C...
C...     D       HR*RHO*K0/K (K/CM**2)
C...
C...     DX      GRID SPACING (CM)
C...
C...  IF EQUATION (6) IS NOW WRITTEN FOR THE N+1 GRID POINTS, I = 0,
C...  1, 2,..., N, A SYSTEM OF NONLINEAR TRIDIAGONAL TRANSCENDENTAL
C...  EQUATIONS RESULTS, WHICH CAN BE APPROXIMATED BY LINEAR FUNCTIONS
C...  AS EXPLAINED IN CLASS.
C...
C...  COMPUTE A SOLUTION TO THE NONLINEAR PROBLEM, I.E., T(X), USING
C...  LEQT1B, FOR:
C...
C...     HR = -10000 CAL/GM, RHO = 1 GM/CM**3, K0 = 30.0 (1/SEC)
C...
C...     K = 0.01 CAL-CM/SEC-CM**2-K, E = 10000 CAL/GM MOL, R =
C...
C...     CAL/GM MOL-K, TA = 350 K, L = 1 CM
C...
C...  (6) IS A SET OF NONLINEAR, TRIDIAGONAL TRANSCENDENTAL EQUATIONS.
C...  WE WILL COMPUTE A SOLUTION BY NEWTON'S METHOD, WHICH IS ALSO
C...  CALLED QUASILINEARIZATION.  IF THE NONLINEAR EXPONENTIAL TERM
C...  IS EXPANDED IN A TAYLOR SERIES
C...
C...                   K+1                  K
C...     EXP(-E/(R*T(I)   ) = EXP(-E/(R*T(I) )) +
C...
C...                                          K            K+1       K
C...                        + D(EXP(-E/(R*T(I) )))/DT*(T(I)    - T(I) )
C...
C...                                          K+1
C...                        = A(I) + B(I)*T(I)    + C(I)
C...
C...  WHERE
C...
C...     K       ITERATION COUNTER
C...
C...                           K
C...     A(I)    EXP(-E/(R*T(I) ))
C...
C...                             K
C...     B(I)    D(EXP(-E/(R*T(I) )))/DT =
C...
C...                           K
C...             EXP(-E/(R*T(I) ))*(E/(R*T(I)**2))
C...
C...                        K
C...     C(I)    B(I)*(-T(I) )
C...
C...  THEN EQUATIONS (6) CAN BE WRITTEN IN APPROXIMATE LINEAR FORM AS
C...  (WITH THE ITERATION COUNTER K DROPPED)
C...
C...     - (2 + (DX**2)*D*B(1))*T(1) + T(2) =
C...
C...          - TA + (DX**2)*D*(A(1) + C(1))
C...
C...     T(1) - (2 + (DX**2)*D*B(2))*T(2) + T(3) =
C...
C...                (DX**2)*D*(A(2) + C(2))
C...       .                                      .
C...       .                                      .             (7)
C...       .                                      .
C...
C...     T(N-2) - (2 + (DX**2)*D*B(N-1))*T(N-1) + T(N) =
C...
C...                (DX**2)*D*(A(N-1) + C(N-1))
C...
C...     2*T(N-1) - (2 + (DX**2)*D*B(N))*T(N) =
C...
C...                (DX**2)*D*(A(N) + C(N))
C...
C...  NOTE THAT A, B AND C IN EACH EQUATION ARE FUNCTIONS OF I, AND
C...  THEREFORE MUST BE EVALUATED FOR EACH EQUATION.
C...
C...  (7) IS A SET OF LINEAR, TRIDIAGONAL ALGEBRAIC EQUATIONS WHICH
C...  CAN BE SOLVED BY A BANDED SOLVER.  IT WILL BE NECESSARY TO ASSUME
C...  A TRIAL SOLUTION FOR ITERATION K = 0.  THEN (7) CAN BE SOLVED
C...  FOR THE K = 1 SOLUTION, AND THIS SOLUTION CAN BE USED IN PLACE OF
C...  THE ASSUMED K = 0 SOLUTION TO COMPUTE THE K = 2 SOLUTION, ETC.,
C...  UNTIL CONVERGENCE IS ACHIEVED.
C...
C...  TWO SOLUTIONS TO EQUATION (3) ARE COMPUTED BY THIS METHOD FOR
C...  N = 10 AND N = 20.  SOLUTIONS ARE ALSO COMPUTED BY IMSL ROUTINE
C...  ZSPOW WHICH CAN ACCEPT THE NONLINEAR EQUATIONS (EQUATIONS (6))
C...  DIRECTLY.
C...
C...  A SECOND APPROACH TO THE SOLUTION OF EQUATION (3) IS TO CONVERT
C...  IT TO A TRANSIENT (TIME DEPENDENT) EQUATION BY ADDING A TIME
C...  DERIVATIVE
C...
C...     RHO*CP*T   = K*T   - (HR*RHO)*K0*EXP(-E/(R*T))       (8)
C...             TM      XX
C...
C...  WHICH CAN BE INTEGRATED UNTIL THE TIME DERIVATIVE, T  ---+ 0.
C...                                                      TM
C...  THIS APPROACH, WHICH IS ALSO IMPLEMENTED IN THE FOLLOWING
C...  CODING, IS CALLED THE METHOD OF FALSE TRANSIENTS.
C...
C...  INPUT/OUTPUT (I/O) UNIT NUMBERS ARE IN COMMON/IO/
      COMMON/IO/ NI, NO
C...
C...  DSS/2 COMMON AREA
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
C...
C...  COMMON AREA FOR ACCESS IN FUNCTIONS AND SUBROUTINES USED BY
C...  LEQT1B, ZSPOW, AND THE USUAL DSS/2 SUBROUTINES (INITAL, DERV,
C...  PRINT)
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  DIMENSION THE ARRAYS REQUIRED BY SUBROUTINE LEQT1B
      DIMENSION ABSM(20,3), BRHS(20), XL(40), X(20), II(20)
C...
C...  DIMENSION THE ARRAYS REQUIRED BY SUBROUTINE ZSPOW
      DIMENSION T(20), F(20), WK(750), PAR(1)
C...
C...  EXTERNAL THE ROUTINE CALLED BY ZSPOW TO EVALUATE THE FUNCTIONS
      EXTERNAL FCN
C...
C...  REAL SELECTED VARIABLES
      REAL K0, K, L
C...
C...  SET THE MODEL PARAMETERS
      HR=-10000.
      RHO=1.0
      CP=1.0
      K0=30.0
      K=0.01
      E=10000.
      R=1.987
      TA=350.
      L=1.
C...
C...  STEP THROUGH TWO CASES
      DO 7 NCASE=1,2
C...
C...  FOR THE FIRST CASE, N = 10
      IF(NCASE.EQ.1)N=10
C...
C...  FOR THE SECOND CASE, N = 20
      IF(NCASE.EQ.2)N=20
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY IMSL ROUTINE LEQT1B USING QUASILINEARIZATION
C...
C...  CONSTANT D IN EQUATIONS (7)
      D=HR*RHO*K0/K
C...
C...  GRID SPACING AND ITS SQUARE
      DX=L/FLOAT(N)
      DXS=DX*DX
C...
C...  DEFINE THE INITIAL TRIAL SOLUTION, SPATIAL GRID AND INDEX
      DO 6 I=1,N
      T0(I)=400.
      X(I)=DX*FLOAT(I)
      II(I)=I
6     CONTINUE
C...
C...  STEP THROUGH A SERIES OF ITERATIONS
      DO 8 ITER=1,100
C...
C...  SET UP THE COEFFICIENT MATRIX IN BAND STORAGE MODE (STORED IN
C...  ABSM)                            -    -       -
C...
C...  LOWER DIAGONAL
      DO 1 I=1,N
      IF(I.EQ.1)ABSM(1,1)=0.
      IF((I.GT.1).AND.(I.LT.N))ABSM(I,1)=1.0
      IF(I.EQ.N)ABSM(N,1)=2.0
1     CONTINUE
C...
C...  MAIN DIAGONAL
      DO 2 I=1,N
      ABSM(I,2)=-(2.0+DXS*D*B(I))
2     CONTINUE
C...
C...  UPPER DIAGONAL
      DO 3 I=1,N
      IF(I.NE.N)ABSM(I,3)=1.0
      IF(I.EQ.N)ABSM(N,3)=0.
3     CONTINUE
C...
C...  RIGHT HAND SIDE VECTOR
      DO 4 I=1,N
      IF(I.EQ.1)BRHS(1)=-TA+DXS*D*(A(I)+C(I))
      IF(I.NE.1)BRHS(I)=   +DXS*D*(A(I)+C(I))
4     CONTINUE
C...
C...  INPUT PARAMETERS FOR SUBROUTINE LEQT1B
      NLC=1
      NUC=1
      IA=20
      M=1
      IB=20
      IJOB=0
C...
C...  SOLVE THE LINEAR ALGEBRAIC EQUATIONS BY IMSL SUBROUTINE LEQT1B
      CALL LEQT1B(ABSM,N,NLC,NUC,IA,BRHS,M,IB,IJOB,XL,IER)
C...
C...  CHECK FOR CONVERGENCE
      DO 9 I=1,N
      IF(ABS(BRHS(I)-T0(I)).GT.0.001)GO TO 10
9     CONTINUE
C...
C...  CONVERGENCE HAS BEEN ACHIEVED, SO PRINT THE SOLUTION VECTOR
      WRITE(NO,5)N,ITER,IER,(II(I),X(I),BRHS(I),I=1,N)
5     FORMAT(1H ,//,
     1 ' N = ',I5,3X,' ITER = ',I5,3X,' IER = ',I5,//,
     2 9X,'I',9X,'X',11X,'T(X)',/,(I10,F10.3,F15.4))
      GO TO 12
C...
C...  CONVERGENCE HAS NOT BEEN ACHIEVED, SO CONTINUE THE ITERATIONS
10    DO 11 I=1,N
      T0(I)=BRHS(I)
11    CONTINUE
C...
C...  GO ON TO THE NEXT ITERATION
8     CONTINUE
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY IMSL ROUTINE ZSPOW
C...
C...  DEFINE THE PARAMETERS FOR ZSPOW
12    NSIG=4
      ITMAX=200
C...
C...  SET THE INITIAL ESTIMATE OF THE SOLUTION
      DO 100 I=1,N
      T(I)=400.0
100   CONTINUE
C...
C...  CALL SUBROUTINE ZSPOW TO COMPUTE A SOLUTION TO EQUATION (6)
      CALL ZSPOW(FCN,NSIG,N,ITMAX,PAR,T,FNORM,WK,IER)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,101)N,FNORM,IER,(II(I),X(I),T(I),I=1,N)
101   FORMAT(1H ,//,
     1 ' N = ',I5,3X,' FNORM = ',E11.3,3X,' IER = ',I5,//,
     2 9X,'I',9X,'X',11X,'T(X)',/,(I10,F10.3,F15.4))
C...
C...  GO ON TO THE NEXT CASE
7     CONTINUE
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY THE METHOD OF FALSE TRANSIENTS
C...
C...  INITIAL CONDITIONS
      N=21
      TC(1)=TA
      DO 102 I=2,N
C...
C...     CASE 1 (NORUN = 1), UNIFORM TEMPERATURE.  THIS INITIAL CONDI-
C...     GIVES A FINAL (STEADY STATE SOLUTION) WHICH IS SIGNIFICANTLY
C...     DIFFERENT THAN THE SOLUTION BY QUASILINEARIZATION
         IF(NORUN.EQ.1)TC(I)=400.
C...
C...     CASE 2 (NORUN = 2), TEMPERATURES FROM QUASILINEARIZATION.  THIS
C...     SOLUTION DOES NOT REMAIN AT THE QUASILINEARIZATION SOLUTION,
C...     BUT RATHER, CONVERGES TO THE SOLUTION OF CASE 1, INDICATING
C...     AN APPARENT INSTABILITY IN THE QUASILINEARIZATION SOLUTION.
C...
C...     FINALLY, IF THE INITIAL ESTIMATE OF THE SOLUTION IS CHANGED
C...     TO 350 (RATHER THAN 400), ALL THREE APPROACHES (LEQT1B, ZSPOW
C...     AND THE METHOD OF LINES) CONVERGE TO THE SAME SOLUTION (TO
C...     WITHIN 1 PART IN 1.0E+05).  THIS CAN EASILY BE VERIFIED BY
C...     USING AN EDITOR TO CHANGE =400 TO =350 IN THE THREE PRECEDING
C...     STATEMENTS
C...
C...                            T0(I)=400.
C...                            (FOR LEQT1B)
C...
C...                            T(I)=400.
C...                            (FOR LSPOW)
C...
C...                            IF(NORUN.EQ.1)TC(I)=400.
C...                            (FOR THE METHOD OF LINES)
C...
C...     THIS RESULT (THE SAME SOLUTIONS FOR AN INITIAL ESTIMATE OF
C...     350 AND DIFFERENT SOLUTIONS FOR AN INITIAL ESTIMATE OF 400,
C...     WITH THE LATTER PRODUCING AN UNSTABLE SOLUTION BY LEQT1B AND
C...     AND SUBROUTINE ZSPOW) GIVES SOME INDICATION OF THE INTERESTING
C...     AND FREQUENTLY UNPREDICTABLE PROPERTIES OF NONLINEAR SYSTEMS.
C...     ON THE OTHER HAND, WELL-CONDITIONED LINEAR PROBLEMS GENERALLY
C...     HAVE UNIQUE AND PREDICTABLE SOLUTIONS.
C...
         IF(NORUN.EQ.2)TC(I)=BRHS(I-1)
102   CONTINUE
C...
C...  RECOMPUTE CONSTANT D TO INCLUDE CP
      D=D*K/(RHO*CP)
C...
C...  THERMAL DIFFUSIVITY
      DF=K/(RHO*CP)
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      END
      FUNCTION A(I)
C...
C...  FUNCTION A COMPUTES THE FIRST TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      A=EXP(-E/(R*T0(I)))
      RETURN
      END
      FUNCTION B(I)
C...
C...  FUNCTION B COMPUTES THE SECOND TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      B=A(I)*(E/(R*(T0(I)**2)))
      RETURN
      END
      FUNCTION C(I)
C...
C...  FUNCTION C COMPUTES THE THIRD TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      C=B(I)*(-T0(I))
      RETURN
      END
      SUBROUTINE FCN(T,F,N,PAR)
C...
C...  SUBROUTINE IMPLEMENTS THE NONLINEAR EQUATIONS
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  DIMENSION THE ARRAYS USED BY FCN
      DIMENSION T(N), F(N), PAR(1)
C...
C...  IMPLEMENT THE NONLINEAR EQUATIONS
      DO 1 I=1,N
      IF(I.EQ.1)THEN
         F(1)=(T(2)-2.0*T(1)+TA)/DXS-D*EXP(-E/(R*T(1)))
      ELSE IF(I.EQ.N)THEN
         F(N)=(2.0*T(N-1)-2.0*T(N))/DXS-D*EXP(-E/(R*T(N)))
      ELSE
         F(I)=(T(I+1)-2.0*T(I)+T(I-1))/DXS-D*EXP(-E/(R*T(I)))
      END IF
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      REAL K0, K, L
C...
C...  BOUNDARY CONDITIONS
      TC(1)=TA
      TX(N)=0.
C...
C...  SECOND ORDER SPATIAL DERIVATIVE
      CALL DSS042(0.,1.,N,TC,TX,TXX,1,2)
C...
C...  PDE
      DO 1 I=1,N
      TT(I)=DF*TXX(I)-D*EXP(-E/(R*TC(I)))
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  REAL SELECTED VARIABLES
      REAL K0, K, L
C...
C...  DIMENSION THE ARRAY FOR THE ARRHENIUS TEMPERATURE DEPENDENCY
      DIMENSION EX(21)
C...
C...  PRINT THE SOLUTION, INCLUDING THE PARTIAL DERIVATIVES AND THE
C...  ARRHENIUS TEMPERATURE DEPENDENCY
      DO 3 I=1,N
      EX(I)=-D*EXP(-E/(R*TC(I)))
3     CONTINUE
         WRITE(NO,2)TIME,( TC(I),I=1,N,5),( TT(I),I=1,N,5),
     1                   (TXX(I),I=1,N,5),( EX(I),I=1,N,5)
2        FORMAT(1H ,//,' T = ',F10.2,/,
     1          '    TC(X,T)',5F10.2,/,
     2          '    TT(X,T)',5E10.2,/,
     3          '   TXX(X,T)',5F10.2,/,
     4          '    EX(X,T)',5F10.4,//)
      RETURN
      END
STEADY STATE ENERGY BALANCE FOR A REACTING SOLID
0.        1000.     200.
   2110000    1    1  REL 0.001
STEADY STATE ENERGY BALANCE FOR A REACTING SOLID
0.        1000.     200.
   2110000    1    1  REL 0.001
END OF RUNS
*APP REACT36
      SUBROUTINE INITAL
C...
C...  MULTIPLE STEADY STATES OF A NONLINEAR DISTRIBUTED (PDE) SYSTEM
C...
C...  CONSIDER THE HEATING OF A SOLID IN WHICH AN EXOTHERMIC REACTION
C...  TAKES PLACE.  A STEADY STATE ENERGY BALANCE ON A SECTION OF THE
C...  SOLID OF THICKNESS OF DX GIVES:
C...
C...     A*Q(X) - A*Q(X+DX) = HR*A*DX*RHO*K0*EXP(-E/(R*T))
C...
C...  WHERE
C...
C...     Q       HEAT FLUX BY CONDUCTION (CAL/CM**2-SEC)
C...
C...     T       ABSOLUTE TEMPERATURE (K)
C...
C...     X       DISTANCE ALONG THE SOLID (CM)
C...
C...     A       CROSS SECTIONAL AREA OF THE SECTION (CM**2)
C...
C...     HR      HEAT OF REACTION (CAL/GM)
C...
C...     RHO     DENSITY (GM/CM**3)
C...
C...     K0      PRE-EXPONENTIAL FACTOR (1/SEC)
C...
C...     E       ACTIVATION ENERGY (CAL/GM MOL)
C...
C...     R       GAS CONSTANT (CAL/GM MOL-K)
C...
C...  DIVISION BY A*DX, FOLLOWED BY DX ---> 0 GIVES
C...
C...     -Q  = HR*RHO*K0*EXP(-E/*R*T))                          (1)
C...       X
C...
C...  WHERE A LETTER SUBSCRIPT DENOTES A DERIVATIVE, E.G., Q  = DQ/DX.
C...                                                        X
C...
C...  EQUATION (1) CONTAINS TWO DEPENDENT VARIABLES, Q AND T, SO THAT
C...  A SECOND EQUATION IS REQUIRED
C...
C...     Q = -K*T                                               (2)
C...             X
C...
C...  EQUATION (2) IS FOURIER'S FIRST LAW.  SUBSTUTION OF EQUATION (2)
C...  IN (1) GIVES
C...
C...     T   = (HR*RHO/K)*K0*EXP(-E/(R*T))                      (3)
C...      XX
C...
C...  EQUATION (3) IS A NONLINEAR, BOUNDARY VALUE ORDINARY DIFFERENTIAL
C...  EQUATION, WHICH WILL BE INTEGRATED NUMERICALLY SUBJECT TO THE TWO
C...  BOUNDARY CONDITIONS
C...
C...     T(0) = TA, T (L) = 0                                (4)(5)
C...                 X
C...
C...     TA      AMBIENT TEMPERATURE (K)
C...
C...     L       LENGTH OF THE SOLID (CM)
C...
C...  IF THE SECOND DERIVATIVE IN EQUATION (3) IS REPLACED WITH A SECOND
C...  ORDER APPROXIMATION
C...
C...     T   = (T(I+1) - 2*T(I) + T(I-1))/DX**2
C...      XX
C...
C...  EQUATION (3) BECOMES
C...
C...     (T(I+1) - 2*T(I) + T(I-1))/DX**2 - D*EXP(-E/(R*T(I)) = 0    (6)
C...
C...  WHERE
C...
C...     D       HR*RHO*K0/K (K/CM**2)
C...
C...     DX      GRID SPACING (CM)
C...
C...  IF EQUATION (6) IS NOW WRITTEN FOR THE N+1 GRID POINTS, I = 0,
C...  1, 2,..., N, A SYSTEM OF NONLINEAR TRIDIAGONAL TRANSCENDENTAL
C...  EQUATIONS RESULTS, WHICH CAN BE APPROXIMATED BY LINEAR FUNCTIONS
C...  AS EXPLAINED IN CLASS.
C...
C...  COMPUTE A SOLUTION TO THE NONLINEAR PROBLEM, I.E., T(X), USING
C...  LEQT1B, FOR:
C...
C...     HR = -10000 CAL/GM, RHO = 1 GM/CM**3, K0 = 30.0 (1/SEC)
C...
C...     K = 0.01 CAL-CM/SEC-CM**2-K, E = 10000 CAL/GM MOL, R =
C...
C...     CAL/GM MOL-K, TA = 350 K, L = 1 CM
C...
C...  (6) IS A SET OF NONLINEAR, TRIDIAGONAL TRANSCENDENTAL EQUATIONS.
C...  WE WILL COMPUTE A SOLUTION BY NEWTON'S METHOD, WHICH IS ALSO
C...  CALLED QUASILINEARIZATION.  IF THE NONLINEAR EXPONENTIAL TERM
C...  IS EXPANDED IN A TAYLOR SERIES
C...
C...                   K+1                  K
C...     EXP(-E/(R*T(I)   ) = EXP(-E/(R*T(I) )) +
C...
C...                                          K            K+1       K
C...                        + D(EXP(-E/(R*T(I) )))/DT*(T(I)    - T(I) )
C...
C...                                          K+1
C...                        = A(I) + B(I)*T(I)    + C(I)
C...
C...  WHERE
C...
C...     K       ITERATION COUNTER
C...
C...                           K
C...     A(I)    EXP(-E/(R*T(I) ))
C...
C...                             K
C...     B(I)    D(EXP(-E/(R*T(I) )))/DT =
C...
C...                           K
C...             EXP(-E/(R*T(I) ))*(E/(R*T(I)**2))
C...
C...                        K
C...     C(I)    B(I)*(-T(I) )
C...
C...  THEN EQUATIONS (6) CAN BE WRITTEN IN APPROXIMATE LINEAR FORM AS
C...  (WITH THE ITERATION COUNTER K DROPPED)
C...
C...     - (2 + (DX**2)*D*B(1))*T(1) + T(2) =
C...
C...          - TA + (DX**2)*D*(A(1) + C(1))
C...
C...     T(1) - (2 + (DX**2)*D*B(2))*T(2) + T(3) =
C...
C...                (DX**2)*D*(A(2) + C(2))
C...       .                                      .
C...       .                                      .             (7)
C...       .                                      .
C...
C...     T(N-2) - (2 + (DX**2)*D*B(N-1))*T(N-1) + T(N) =
C...
C...                (DX**2)*D*(A(N-1) + C(N-1))
C...
C...     2*T(N-1) - (2 + (DX**2)*D*B(N))*T(N) =
C...
C...                (DX**2)*D*(A(N) + C(N))
C...
C...  NOTE THAT A, B AND C IN EACH EQUATION ARE FUNCTIONS OF I, AND
C...  THEREFORE MUST BE EVALUATED FOR EACH EQUATION.
C...
C...  (7) IS A SET OF LINEAR, TRIDIAGONAL ALGEBRAIC EQUATIONS WHICH
C...  CAN BE SOLVED BY A BANDED SOLVER.  IT WILL BE NECESSARY TO ASSUME
C...  A TRIAL SOLUTION FOR ITERATION K = 0.  THEN (7) CAN BE SOLVED
C...  FOR THE K = 1 SOLUTION, AND THIS SOLUTION CAN BE USED IN PLACE OF
C...  THE ASSUMED K = 0 SOLUTION TO COMPUTE THE K = 2 SOLUTION, ETC.,
C...  UNTIL CONVERGENCE IS ACHIEVED.
C...
C...  TWO SOLUTIONS TO EQUATION (3) ARE COMPUTED BY THIS METHOD FOR
C...  N = 10 AND N = 20.  SOLUTIONS ARE ALSO COMPUTED BY IMSL ROUTINE
C...  ZSPOW WHICH CAN ACCEPT THE NONLINEAR EQUATIONS (EQUATIONS (6))
C...  DIRECTLY.
C...
C...  A SECOND APPROACH TO THE SOLUTION OF EQUATION (3) IS TO CONVERT
C...  IT TO A TRANSIENT (TIME DEPENDENT) EQUATION BY ADDING A TIME
C...  DERIVATIVE
C...
C...     RHO*CP*T   = K*T   - (HR*RHO)*K0*EXP(-E/(R*T))       (8)
C...             TM      XX
C...
C...  WHICH CAN BE INTEGRATED UNTIL THE TIME DERIVATIVE, T  ---+ 0.
C...                                                      TM
C...  THIS APPROACH, WHICH IS ALSO IMPLEMENTED IN THE FOLLOWING
C...  CODING, IS CALLED THE METHOD OF FALSE TRANSIENTS.
C...
C...  INPUT/OUTPUT (I/O) UNIT NUMBERS ARE IN COMMON/IO/
      COMMON/IO/ NI, NO
C...
C...  DSS/2 COMMON AREA
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
C...
C...  COMMON AREA FOR ACCESS IN FUNCTIONS AND SUBROUTINES USED BY
C...  LEQT1B, ZSPOW, AND THE USUAL DSS/2 SUBROUTINES (INITAL, DERV,
C...  PRINT)
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  DIMENSION THE ARRAYS REQUIRED BY SUBROUTINE LEQT1B
      DIMENSION ABSM(20,3), BRHS(20), XL(40), X(20), II(20)
C...
C...  DIMENSION THE ARRAYS REQUIRED BY SUBROUTINE ZSPOW
      DIMENSION T(20), F(20), WK(750), PAR(1)
C...
C...  EXTERNAL THE ROUTINE CALLED BY ZSPOW TO EVALUATE THE FUNCTIONS
      EXTERNAL FCN
C...
C...  REAL SELECTED VARIABLES
      REAL K0, K, L
C...
C...  SET THE MODEL PARAMETERS
      HR=-10000.
      RHO=1.0
      CP=1.0
      K0=30.0
      K=0.01
      E=10000.
      R=1.987
      TA=350.
      L=1.
C...
C...  STEP THROUGH TWO CASES
      DO 7 NCASE=1,2
C...
C...  FOR THE FIRST CASE, N = 10
      IF(NCASE.EQ.1)N=10
C...
C...  FOR THE SECOND CASE, N = 20
      IF(NCASE.EQ.2)N=20
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY IMSL ROUTINE LEQT1B USING QUASILINEARIZATION
C...
C...  CONSTANT D IN EQUATIONS (7)
      D=HR*RHO*K0/K
C...
C...  GRID SPACING AND ITS SQUARE
      DX=L/FLOAT(N)
      DXS=DX*DX
C...
C...  DEFINE THE INITIAL TRIAL SOLUTION, SPATIAL GRID AND INDEX
      DO 6 I=1,N
      T0(I)=400.
      X(I)=DX*FLOAT(I)
      II(I)=I
6     CONTINUE
C...
C...  STEP THROUGH A SERIES OF ITERATIONS
      DO 8 ITER=1,100
C...
C...  SET UP THE COEFFICIENT MATRIX IN BAND STORAGE MODE (STORED IN
C...  ABSM)                            -    -       -
C...
C...  LOWER DIAGONAL
      DO 1 I=1,N
      IF(I.EQ.1)ABSM(1,1)=0.
      IF((I.GT.1).AND.(I.LT.N))ABSM(I,1)=1.0
      IF(I.EQ.N)ABSM(N,1)=2.0
1     CONTINUE
C...
C...  MAIN DIAGONAL
      DO 2 I=1,N
      ABSM(I,2)=-(2.0+DXS*D*B(I))
2     CONTINUE
C...
C...  UPPER DIAGONAL
      DO 3 I=1,N
      IF(I.NE.N)ABSM(I,3)=1.0
      IF(I.EQ.N)ABSM(N,3)=0.
3     CONTINUE
C...
C...  RIGHT HAND SIDE VECTOR
      DO 4 I=1,N
      IF(I.EQ.1)BRHS(1)=-TA+DXS*D*(A(I)+C(I))
      IF(I.NE.1)BRHS(I)=   +DXS*D*(A(I)+C(I))
4     CONTINUE
C...
C...  INPUT PARAMETERS FOR SUBROUTINE LEQT1B
      NLC=1
      NUC=1
      IA=20
      M=1
      IB=20
      IJOB=0
C...
C...  SOLVE THE LINEAR ALGEBRAIC EQUATIONS BY IMSL SUBROUTINE LEQT1B
      CALL LEQT1B(ABSM,N,NLC,NUC,IA,BRHS,M,IB,IJOB,XL,IER)
C...
C...  CHECK FOR CONVERGENCE
      DO 9 I=1,N
      IF(ABS(BRHS(I)-T0(I)).GT.0.001)GO TO 10
9     CONTINUE
C...
C...  CONVERGENCE HAS BEEN ACHIEVED, SO PRINT THE SOLUTION VECTOR
      WRITE(NO,5)N,ITER,IER,(II(I),X(I),BRHS(I),I=1,N)
5     FORMAT(1H ,//,
     1 ' N = ',I5,3X,' ITER = ',I5,3X,' IER = ',I5,//,
     2 9X,'I',9X,'X',11X,'T(X)',/,(I10,F10.3,F15.4))
      GO TO 12
C...
C...  CONVERGENCE HAS NOT BEEN ACHIEVED, SO CONTINUE THE ITERATIONS
10    DO 11 I=1,N
      T0(I)=BRHS(I)
11    CONTINUE
C...
C...  GO ON TO THE NEXT ITERATION
8     CONTINUE
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY IMSL ROUTINE ZSPOW
C...
C...  DEFINE THE PARAMETERS FOR ZSPOW
12    NSIG=4
      ITMAX=200
C...
C...  SET THE INITIAL ESTIMATE OF THE SOLUTION
      DO 100 I=1,N
      T(I)=400.0
100   CONTINUE
C...
C...  CALL SUBROUTINE ZSPOW TO COMPUTE A SOLUTION TO EQUATION (6)
      CALL ZSPOW(FCN,NSIG,N,ITMAX,PAR,T,FNORM,WK,IER)
C...
C...  PRINT THE SOLUTION
      WRITE(NO,101)N,FNORM,IER,(II(I),X(I),T(I),I=1,N)
101   FORMAT(1H ,//,
     1 ' N = ',I5,3X,' FNORM = ',E11.3,3X,' IER = ',I5,//,
     2 9X,'I',9X,'X',11X,'T(X)',/,(I10,F10.3,F15.4))
C...
C...  GO ON TO THE NEXT CASE
7     CONTINUE
C...
C...  ****************************************************************
C...
C...  COMPUTE A SOLUTION BY THE METHOD OF FALSE TRANSIENTS
C...
C...  INITIAL CONDITIONS
      N=21
      TC(1)=TA
      DO 102 I=2,N
C...
C...     CASE 1 (NORUN = 1), UNIFORM TEMPERATURE.  THIS INITIAL CONDI-
C...     GIVES A FINAL (STEADY STATE SOLUTION) WHICH IS SIGNIFICANTLY
C...     DIFFERENT THAN THE SOLUTION BY QUASILINEARIZATION
         IF(NORUN.EQ.1)TC(I)=400.
C...
C...     CASE 2 (NORUN = 2), TEMPERATURES FROM QUASILINEARIZATION.  THIS
C...     SOLUTION DOES NOT REMAIN AT THE QUASILINEARIZATION SOLUTION,
C...     BUT RATHER, CONVERGES TO THE SOLUTION OF CASE 1.  THIS INDICATES
C...     AN APPARENT INSTABILITY IN THE QUASILINEARIZATION SOLUTION,
C...     SO THAT THIS SOLUTION MOVES TO ANOTHER STABLE SOLUTION.  THUS,
C...     WE HAVE THE EVIDENCE FOR MULTIPLE STEADY STATE SOLUTIONS TO
C...     EQUATION (8), BOTH STABLE AND UNSTABLE.
C...
C...     FINALLY, IF THE INITIAL ESTIMATE OF THE SOLUTION IS CHANGED
C...     TO 350 (RATHER THAN 400), ALL THREE APPROACHES (LEQT1B, ZSPOW
C...     AND THE METHOD OF LINES) CONVERGE TO THE SAME SOLUTION (TO
C...     WITHIN 1 PART IN 1.0E+05).  THIS CAN EASILY BE VERIFIED BY
C...     USING AN EDITOR TO CHANGE =400 TO =350 IN THE THREE PRECEDING
C...     STATEMENTS
C...
C...                            T0(I)=400.
C...                            (FOR LEQT1B)
C...
C...                            T(I)=400.
C...                            (FOR LSPOW)
C...
C...                            IF(NORUN.EQ.1)TC(I)=400.
C...                            (FOR THE METHOD OF LINES)
C...
C...     THIS RESULT (THE SAME SOLUTIONS FOR AN INITIAL ESTIMATE OF
C...     350 AND DIFFERENT SOLUTIONS FOR AN INITIAL ESTIMATE OF 400,
C...     WITH THE LATTER PRODUCING AN UNSTABLE SOLUTION BY LEQT1B AND
C...     AND SUBROUTINE ZSPOW) GIVES SOME INDICATION OF THE INTERESTING
C...     AND FREQUENTLY UNPREDICTABLE PROPERTIES OF NONLINEAR SYSTEMS.
C...     ON THE OTHER HAND, WELL-CONDITIONED LINEAR PROBLEMS GENERALLY
C...     HAVE UNIQUE AND PREDICTABLE SOLUTIONS.
C...
         IF(NORUN.EQ.2)TC(I)=BRHS(I-1)
102   CONTINUE
C...
C...  RECOMPUTE CONSTANT D TO INCLUDE CP
      D=D*K/(RHO*CP)
C...
C...  THERMAL DIFFUSIVITY
      DF=K/(RHO*CP)
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      END
      FUNCTION A(I)
C...
C...  FUNCTION A COMPUTES THE FIRST TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      A=EXP(-E/(R*T0(I)))
      RETURN
      END
      FUNCTION B(I)
C...
C...  FUNCTION B COMPUTES THE SECOND TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      B=A(I)*(E/(R*(T0(I)**2)))
      RETURN
      END
      FUNCTION C(I)
C...
C...  FUNCTION C COMPUTES THE THIRD TERM IN THE LINEAR APPROXIMATION
C...  OF EXP(-E/(R*T)) AS DISCUSSED PREVIOUSLY
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      C=B(I)*(-T0(I))
      RETURN
      END
      SUBROUTINE FCN(T,F,N,PAR)
C...
C...  SUBROUTINE IMPLEMENTS THE NONLINEAR EQUATIONS
C...
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  DIMENSION THE ARRAYS USED BY FCN
      DIMENSION T(N), F(N), PAR(1)
C...
C...  IMPLEMENT THE NONLINEAR EQUATIONS
      DO 1 I=1,N
      IF(I.EQ.1)THEN
         F(1)=(T(2)-2.0*T(1)+TA)/DXS-D*EXP(-E/(R*T(1)))
      ELSE IF(I.EQ.N)THEN
         F(N)=(2.0*T(N-1)-2.0*T(N))/DXS-D*EXP(-E/(R*T(N)))
      ELSE
         F(I)=(T(I+1)-2.0*T(I)+T(I-1))/DXS-D*EXP(-E/(R*T(I)))
      END IF
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
      REAL K0, K, L
C...
C...  BOUNDARY CONDITIONS
      TC(1)=TA
      TX(N)=0.
C...
C...  SECOND ORDER SPATIAL DERIVATIVE
      CALL DSS042(0.,1.,N,TC,TX,TXX,1,2)
C...
C...  PDE
      DO 1 I=1,N
      TT(I)=DF*TXX(I)-D*EXP(-E/(R*TC(I)))
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/ TC(21)
     2      /F/ TT(21)
     3      /S/ TX(21),TXX(21)
     4      /C/      N,     IP
      COMMON/C1/ T0(20), D, E, R, DXS, TA, DF
C...
C...  REAL SELECTED VARIABLES
      REAL K0, K, L
C...
C...  DIMENSION THE ARRAY FOR THE ARRHENIUS TEMPERATURE DEPENDENCY
      DIMENSION EX(21)
C...
C...  PRINT THE SOLUTION, INCLUDING THE PARTIAL DERIVATIVES AND THE
C...  ARRHENIUS TEMPERATURE DEPENDENCY
      DO 3 I=1,N
      EX(I)=-D*EXP(-E/(R*TC(I)))
3     CONTINUE
         WRITE(NO,2)TIME,( TC(I),I=1,N,5),( TT(I),I=1,N,5),
     1                   (TXX(I),I=1,N,5),( EX(I),I=1,N,5)
2        FORMAT(1H ,//,' T = ',F10.2,/,
     1          '    TC(X,T)',5F10.2,/,
     2          '    TT(X,T)',5E10.2,/,
     3          '   TXX(X,T)',5F10.2,/,
     4          '    EX(X,T)',5F10.4,//)
      RETURN
      END
MULTIPLE STEADY STATES OF A DISTRIBUTED (PDE) SYSTEM
0.        1000.     200.
   2110000    1    1  REL 0.001
MULTIPLE STEADY STATES OF A DISTRIBUTED (PDE) SYSTEM
0.        1000.     200.
   2110000    1    1  REL 0.001
END OF RUNS
*APP REACT37
      SUBROUTINE INITAL
C...
C...  ESTERIFICATION OF ACETIC ACID AND ETHYL ALCOHOL
C...
C...  THE ESTERFICATION OF ACETIC ACID AND ETHYL ALCOHOL IS TO BE CARRIED
C...  OUT IN A SEMIBATCH STIRRED-TANK REACTOR AT A CONSTANT TEMPERATURE.
C...  OF 100 C.  THE ALCOHOL IS ADDED INITIALLY AS 400 LB OF PURE C2H5OH.
C...  AN AQUEOUS SOLUTION OF ACETIC ACID IS THEN ADDED AT A RATE OF 3.92
C...  LB/MIN FOR 120 MIN.  THE SOLUTION CONTAINS 42.6% BY WEIGHT ACID.
C...  ASSUME THAT THE DENSITY IS CONSTANT AND EQUAL TO THAT OF WATER.
C...
C...  THE REACTION IS REVERSIBLE:
C...
C...     CH COOH + C H OH +----+ CH COOC H  + H 0
C...       3        2 5            3    2 5    2
C...
C...  AND THE SPECIFIC REACTION RATES ARE FIRST ORDER IN EACH REACTANT:
C...
C...     FOR THE FORWARD REACTION: RF = KF*CA*CE
C...
C...     FOR THE REVERSE REACTION: RR = KR*CEA*CW
C...
C...  WHERE
C...
C...     CA, CE, CEA, CW - CONCENTRATIONS OF ACETIC ACID, ETHYL ALCOHOL,
C...                       ETHYL ACETATE AND WATER, RESPECTIVELY (GM MOL
C...                       /LITER)
C...
C...     KF = 4.76E-4 LITER/(GM MOL-MIN)
C...
C...     KR = 1.63E-4 LITER/(GM MOL-MIN)
C...
C...  DEVELOP A MATHEMATICAL MODEL TO COMPUTE THE CONCENTRATION OF ESTER
C...  AS A FUNCTION OF TIME FROM T = 0 UNTIL 30 MINUTES AFTER THE LAST
C...  AMOUNT OF ACID IS ADDED.  ASSUME THAT NO WATER IS VAPORIZED IN THE
C...  REACTOR.
C...
C...  THE MATHEMATICAL MODEL FOLLOWS:
C...
C...     BALANCE FOR ACETIC ACID
C...
C...        D(V*CA)/DT = (3.92*454*0.426)/60 + V*KR*CEA*CW - V*KF*CA*CE
C...
C...        V(0)*CA(0) = 0 (SINCE CA(0) = 0) (MOLECULAR WEIGHT = 60)
C...
C...     BALANCE FOR ETHYL ALCOHOL
C...
C...     D(V*CE)/DT = V*KR*CEA*CW - V*KF*CA*CE,
C...
C...        V(0)*CE(0) = 400*454/46 GM-MOL (MOLECULAR WEIGHT = 46)
C...
C...        (1 LB = 454 GM)
C...
C...     BALANCE FOR ETHYL ACETATE
C...
C...        D(V*CEA)/DT = V*KF*CA*CE - V*KR*CEA*CW
C...
C...        V(0)*CEA(0) = 0 (SINCE CEA(0) = 0)
C...
C...     BALANCE FOR WATER
C...
C...        D(V*CW)/DT = (3.92*454*0.574)/18 + V*KF*CA*CE - V*KR*CEA*CW
C...
C...        V(0)*CW(0) = 0 (SINCE CW(0) = 0) (MOLECULAR WIGHT = 18)
C...
C...     TOTAL BALANCE
C...
C...        DV/DT = 3.92*454/1000, V(0) = 400*454/1000
C...
C...        (DENSITY OF WATER = 1000 GM/LITER)
C...
C...  SIMULATE THIS SYSTEM, I.E., COMPUTE AND PLOT CA(T), CE(T), CEA(T)
C...  AND CW(T) VS T FOR 0 LE T LE 150 MIN.  PRINT THE  FOUR CONCENTRA-
C...  TIONS IN TABULAR FORM WITH HEADINGS, AND PLOT THE FOUR CONCENTRA-
C...  ON THE SAME GRAPH.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    VCA,    VCE,   VCEA,    VCW,      V
     2      /F/   DVCA,   DVCE,  DVCEA,   DVCW,     DV
     3      /C/     KF,     KR,     RF,     RR,     CA,     CE,    CEA,
     4              CW,     IP
      REAL          KF,     KR
C...
C...  MODEL PARAMETERS
      KF=4.76E-04
      KR=1.63E-04
C...
C...  MODEL INITIAL CONDITIONS
      VCA=0.
      VCE=400.0*454.0/46.0
      VCEA=0.
      VCW=0.
      V=400.*454.0/1000.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    VCA,    VCE,   VCEA,    VCW,      V
     2      /F/   DVCA,   DVCE,  DVCEA,   DVCW,     DV
     3      /C/     KF,     KR,     RF,     RR,     CA,     CE,    CEA,
     4              CW,     IP
      REAL          KF,     KR
C...
C...  MODEL ALGEBRA
C...
C...     CONCENTRATIONS
         CA=VCA/V
         CE=VCE/V
         CEA=VCEA/V
         CW=VCW/V
C...
C...  REACTION RATES
C...
C...     FORWARD RATE
         RF=V*KF*CA*CE
C...
C...     REVERSE RATE
         RR=V*KR*CEA*CW
C...
C...  MODEL ODES
C...
C...     ACETIC ACID BALANCE
         IF(T.LE.120.)THEN
            DVCA=3.92*454.0*0.426/60.0-RF+RR
         ELSE IF(T.GT.120.)THEN
            DVCA=-RF+RR
         END IF
C...
C...     ETHANOL BALANCE
         DVCE=-RF+RR
C...
C...     ETHYL ACETATE BALANCE
         DVCEA=RF-RR
C...
C...     WATER BALANCE
         IF(T.LE.120.)THEN
            DVCW=3.92*454.0*0.574/18.0+RF-RR
         ELSE IF(T.GT.120.)THEN
            DVCW=RF-RR
         END IF
C...
C...     TOTAL BALANCE
         IF(T.LE.120.)THEN
            DV=3.92*454.0/1000.0
         ELSE IF(T.GT.120.)THEN
            DV=0.
         END IF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    VCA,    VCE,   VCEA,    VCW,      V
     2      /F/   DVCA,   DVCE,  DVCEA,   DVCW,     DV
     3      /C/     KF,     KR,     RF,     RR,     CA,     CE,    CEA,
     4              CW,     IP
      REAL          KF,     KR
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL TP(51), CP(4,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(5X,'T',5X,'CH3COOH',6X,'C2H5OH',2X,'CH3C00C2H5',9X,'H20',
     1       9X,'V')
C...
C...  PRINT THE SOLUTION
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,CA,CE,CEA,CW,V
2        FORMAT(F6.1,4E12.3,F10.1)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      CP(1,IP)=CA
      CP(2,IP)=CE
      CP(3,IP)=CEA
      CP(4,IP)=CW
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      CALL SPLOTS(4,IP,TP,CP)
      WRITE(NO,3)
3     FORMAT(/,' 1 - ACETIC ACID, 2 - ETHANOL, 3 - ETHYL ACETATE,'
     1         ' 4 - WATER VS TIME')
      RETURN
      END
ESTERIFICATION OF ACETIC ACID AND ETHYL ALCOHOL
0.        150.      3.
    5 1000    1    1  REL 0.001
END OF RUNS
*APP REACT38
      SUBROUTINE INITAL
C...
C...  SEMIBATCH PRODUCTION OF HEXAMETHYLENETETRAMINE
C...
C...  HEXAMETHYLENETETRAMINE (HMT) IS TO BE PRODUCED IN A SEMIBATCH
C...  REACTOR BY ADDING AN AQUEOUS AMMONIA SOLUTION (25 WT% NH3) AT THE
C...  RATE OF 2 GPM TO AN INITIAL CHARGE OF 238 GAL (AT 25 C) OF FORMA-
C...  LIN SOLUTION CONTAINING 42% BY WEIGHT FORMALDEHYDE.  THE ORIGINAL
C...  TEMPERATURE OF THE FORMALIN SOLUTION IS RAISED TO 50 C IN ORDER
C...  TO START THE REACTION.  THE TEMPERATURE OF THE NH4OH SOLUTION IS
C...  25 C.  THE HEAT OF REACTION IN THE LIQUID PHASE MAY BE ASSUMED
C...  INDEPENDENT OF TEMPERATURE AND CONCENTRATION AND TAKEN AS -960
C...  BTU/LB OF HMT.  THE REACTION IS IRREVERSIBLE AND THE RATE OF
C...  REACTION IS FIRST ORDER IN EACH OF THE REACTANTS.  THE REACTOR
C...  CAN BE OPERATED AT A TEMPERATURE OF 80 C.  TEMPERATURES HIGHER
C...  THAN 80 ARE NOT DESIRABLE BECAUSE OF VAPORIZATION AND INCREASE OF
C...  PRESSURE.
C...
C...  IT IS PROPOSED TO COOL THE REACTOR BY COILS THROUGH WHICH WATER IS
C...  PASSED.  THE OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE STIRRED
C...  REACTION MIXTURE AND THE COOLING WATER WILL BE 85 BTU/HR-FT**2-F.
C...  THE WATER FLOW RATE THROUGH THE COILS IS SUCH THAT ITS TEMPERATURE
C...  VARIES LITTLE, AND AN AVERAGE VALUE OF 25 C MAY BE USED.  GIVEN THE
C..   FOLLOWING DATA, DEVELOP A MATHEMATICAL MODEL TO CALCULATE THE TEMP-
C...  ERATURE OF THE STIRRED REACTION MIXTURE AS A FUNCTION OF TIME.
C...
C...     DENSITY OF AMMONIA SOLUTION = 0.91 GM/CM**3
C...
C...     DENSITY OF FORMALIN (42%) AT 25 C = 1.10 GM/CM**3
C...
C...     SPECIFIC HEAT OF REACTION MIXTURE (ASSUME CONSTANT), CP = 1.0
C...     BTU/LB-F
C...
C...     SPECIFIC HEAT OF 25 WT% NH3 SOLUTION, CP = 1.0 BTU/LB-F
C...
C...     REACTION RATE CONSTANT = 4.48E+05*EXP(-8000/(R*T)) CM**3/SEC-
C...     GM-MOL
C...
C...     AREA OF HEAT TRANSFER = 25 FT**2
C...
C...  THE MATHEMATICAL MODEL FOLLOWS.  THE REACTION IS
C...
C...     6HCH0 + 4NH OH ----+ (CH ) N  + 10 H 0
C...                4            2 6 4       2
C...
C...  ENERGY BALANCE
C...
C...     D(M*CP*TC)/DT = W0*CP0*T0 - U*A*(TC - TW) - DH*V*K*CA*CF   (1)
C...
C...     M(0)*TC(0), V = M/RHO
C...
C...  TOTAL MASS BALANCE
C...
C...     DM/DT = W0, M(0)                                           (2)
C...
C...  AMMONIA BALANCE
C...
C...     D(V*CA)/DT = W0*WA0/MA - 4*V*K*CA*CF, V(0)*CA(0)           (3)
C...
C...  FORMALDEHYDE BALANCE
C...
C...     D(V*CF)/DT = -6*V*K*CA*CF, V(0)*CF(0)                      (4)
C...
C...  WHERE
C...
C...     TC      TEMPERATURE (C)
C...
C...     M       MASS OF LIQUID IN THE REACTOR (GM)
C...
C...     CA      CONCENTRATION OF AMMONIA (GM MOL/CM**3)
C...
C...     CF      CONCENTRAION OF FORMALDEHYDE (GM MOL/CM**3)
C...
C...     T       TIME (SEC)
C...
C...     V       VOLUME OF LIQUID IN THE REACTOR (CM**3)
C...
C...     CP      SPECIFIC HEAT OF LIQUID IN THE REACTOR (CAL/GM-C)
C...
C...     WA0     FEED MASS CONCENTRATION OF AMMONIA (GM/GM)
C...
C...     W0      FEED MASS FLOW RATE (GM/SEC)
C...
C...     MA      MOLECULAR WEIGHT OF AMMONIA (GM/GM MOL)
C...
C...     CP0     FEED SPECIFIC HEAT (CM/GM-C)
C...
C...     TO      FEED TEMPERATURE (C)
C...
C...     U       COIL HEAT TRANSFER COEFFICIENT (CAL/SEC-CM**2-C)
C...
C...     A       HEAT TRANSFER AREA (CM**2)
C...
C...     TW      COOLANT TEMPERATURE (C)
C...
C...     K       SPECIFIC REACTION RATE CONSTANT (CM**3/SEC-GM MOL)
C...             (THIS IS GIVEN BY AN ARRHENIUS TEMPERATURE DEPENDENCY
C...             AND THE TEMPERATURE MUST BE ABSOLUTE, I.E., KELVIN)
C...
C...     DH      HEAT OF REACTION (CAL/GM MOL HMT PRODUCED)
C...
C...  SIMULATE THE REACTOR FOR 30 MINUTES TO DETERMINE IF THE TEMPERA-
C...  TURE REMAINS BELOW 80 C.
C...
C...  THE FOLLOWING CONVERSION FACTORS CAN BE USED TO CONVERT THE MODEL
C...  CONSTANTS TO HAVE A CONSISTENT SET OF UNITS
C...
C...     1 GAL = 3.785 LITERS
C...
C...     1 BTU = 252 GM-CAL
C...
C...     1 LB = 454 GM
C...
C...     1 IN = 2.54 CM
C...
C...     1 BTU/LB-F = 1 CAL/GM-C
C...
C...     1 C = 1.8 F
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF
     2      /F/   DMTC,     DM,   DVCA,   DVCF
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K
C...
C...  CONVERT THE MODEL CONSTANTS
C...
C...     ENTERING MASS FLOW RATE (GPM TO GM/SEC)
         W0=2.0*3.785*1000.0*0.91/60.0
C...
C...     INITIAL MASS (GAL TO GM)
         M0=238.0*3.785*1000.0*1.10
C...
C...     HEAT TRANSFER COEFFICIENT (BTU/HR-FT**2-F TO CAL/SEC-CM**2-SEC)
         U=85.0*252.0/3600.0*(1.0/(2.54*12.0)**2)*1.8
C...
C...     HEAT OF REACTION (BTU/LB TO GM/GM MOL HMT PRODUCED)
         MWHMT=(12.0+2.0)*6.0+14.0*4.0
         DH=-960.0*252.0/454.0*MWHMT
C...
C...     HEAT TRANSFER AREA (FT**2 TO CM**2)
C...
C...        CASE 1 - NO COOLING
            IF(NORUN.EQ.1)A=0.
C...
C...        CASE 2 - COOLING
            IF(NORUN.EQ.2)A=25.0*(2.54*12.0)**2
C...
C...  SET OTHER MODEL CONSTANTS
      CP=1.0
      CP0=1.0
      T0=25.0
      TW=25.0
      RHO=1.10
      WA0=0.25
      MWA=17.0
      MWF=30.0
C...
C...  INITIAL CONDITIONS
      MTC=M0*50.0
      M=M0
      V=M0/RHO
      VCA=V*0.
      VCF=V*0.42*1.10/MWF
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF
     2      /F/   DMTC,     DM,   DVCA,   DVCF
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K
C...
C...  MODEL ALGEBRA
      TC=MTC/M
      V=M/RHO
      CA=VCA/V
      CF=VCF/V
      K=4.48E+05*EXP(-8000.0/(1.987*(TC+273.16)))
C...
C...  MODEL ODES
C...
C...     ENERGY BALANCE
         DMTC=W0*CP0*T0-U*A*(TC-TW)-DH*V*K*CA*CF
C...
C...     TOTAL MASS BALANCE
         DM=W0
C...
C...     AMMONIA BALANCE
         DVCA=W0*WA0/MWA-4.0*V*K*CA*CF
C...
C...     FORMALDEHYDE BALANCE
         DVCF=-6.0*V*K*CA*CF
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    MTC,      M,    VCA,    VCF
     2      /F/   DMTC,     DM,   DVCA,   DVCF
     3      /C/     W0,     M0,      U,  MWHMT,     DH,      A,     CP,
     4             CP0,     T0,     TW,    RHO,    WA0,    MWA,    MWF,
     5               V,     TC,     CA,     CF,      K,     IP
      REAL         MTC,      M,     M0,  MWHMT,    MWA,    MWF,      K
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL      TP(51),      TCP(2,51),      CAP(2,51),      CFP(2,51)
C...
C...  COMPUTE THE INDIVIDUAL TERMS IN THE ODES FOR PRINTING
C...
C...     ENERGY BALANCE
         E1=W0*CP0*T0
         E2=-U*A*(TC-TW)
         E3=-DH*V*K*CA*CF
         DMTC=E1+E2+E3
C...
C...     AMMONIA BALANCE
         A1=W0*WA0/MWA
         A2=-4.0*V*K*CA*CF
         DVCA=A1+A2
C...
C...     FORMALDEHYDE BALANCE
         F1=-6.0*V*K*CA*CF
C...
C...  PRINT THE DETAILED NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,1)      T,    MTC,      M,    VCA,    VCF,     TC,
     1                    V,     CA,     CF,      K,     E1,     E2,
     2                   E3,   DMTC,     A1,     A2,   DVCA,     F1,
     3                 DVCF
1        FORMAT(1H ,//,' T = ',F7.1,/,
     1   '                 MTC',E10.3,5X,'                   M',E10.3,/,
     2   '                 VCA',E10.3,5X,'                 VCF',E10.3,/,
     3   '                  TC',E10.3,5X,'                   V',E10.3,/,
     4   '                  CA',E10.3,5X,'                  CF',E10.3,/,
     5   '                   K',E10.3,5X,'           W0*CP0*T0',E10.3,/,
     6   '        -U*A*(TC-TW)',E10.3,5X,'       -DH*V*K*CA*CF',E10.3,/,
     7   '                DMTC',E10.3,5X,'           W0*WA0/MA',E10.3,/,
     8   '      -4.0*V*K*CA*CF',E10.3,5X,'                DVCA',E10.3,/,
     9   '      -6.0*V*K*CA*CF',E10.3,5X,'                DVCF',E10.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      TCP(NORUN,IP)=TC
      CAP(NORUN,IP)=CA
      CFP(NORUN,IP)=CF
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.51).OR.(NORUN.LT.2))RETURN
C...
C...     TC VS T
         CALL SPLOTS(NORUN,IP,TP,TCP)
         WRITE(NO,11)
11       FORMAT(1H ,/,' 1 - NO COOLING, 2 - COOLING, TC VS T')
C...
C...     CA VS T
         CALL SPLOTS(NORUN,IP,TP,CAP)
         WRITE(NO,12)
12       FORMAT(1H ,/,' 1 - NO COOLING, 2 - COOLING, CA VS T')
C...
C...     CF VS T
         CALL SPLOTS(NORUN,IP,TP,CFP)
         WRITE(NO,13)
13       FORMAT(1H ,/,' 1 - NO COOLING, 2 - COOLING, CF VS T')
      RETURN
      END
SEMI-BATCH PRODUCTION OF HMT, NO COOLING
0.        1800.0    36.0
    4 1000    1    1  REL 0.001
SEMI-BATCH PRODUCTION OF HMT, COOLING
0.        1800.0    36.0
    4 1000    1    1  REL 0.001
END OF RUNS
