*APP HEAT01
      SUBROUTINE INITAL
C...
C...  PROPORTIONAL-INTEGRAL CONTROL OF A HUMIDIFICATION COLUMN
C...
C...  A HUMIDIFICATION COLUMN (A PACKED COLUMN WITH WATER FLOWING DOWN
C...  AND AIR FLOWING UP) IS DIAGRAMMED BELOW
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE VARIABLES AND PARAMETERS FOR THIS SYSTEM ARE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     ZL      LENGTH OF THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...  THE DEPENDENT VARIABLES OF PARTICULAR INTEREST ARE Y(Z,T), TG(Z,T)
C...  TL(Z,T).  IN ORDER TO COMPUTE THESE VARIABLES, BASIC CONSERVATION
C...  PRINCIPLES ARE APPLIED TO THE AIR AND WATER STREAMS WITHIN THE
C...  COLUMN OVER THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE DIAGRAM)
C...  AND THEN THE LIMIT OF DZ ---+ 0 GIVES THE MODEL DIFFERENTIAL EQUA-
C...  TIONS.  SINCE THE MODEL IS DYNAMIC, TIME, T, AND AXIAL POSITION,
C...  Z, APPEAR IN THE EQUATIONS AS INDEPENDENT VARIABLES AND THEREFORE
C...  PARTIAL DIFFERENTIAL EQUATIONS (PDES) MUST BE USED.
C...
C...  THE PDES ARE DERIVED AS FOLLOWS.  A H20 BALANCE ON THE GAS PHASE
C...  GIVES
C...
C...     (Y*G*S*DZ)  = V*Y  - V*Y     + KY*AV*(YS - Y)*S*DZ     (1A)
C...               T      Z      Z+DZ
C...
C...  WHERE THE SUBSCRIPT T ON THE LHS DENOTES A PARTIAL DERIVATIVE WITH
C...  RESPECT TO TIME, T.
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (1A) IS INDICATED BELOW
C...
C...     (Y*G*S*DZ)
C...               T
C...
C...        = (MOLS H20/MOL DRY AIR)*(MOLS DRY AIR/CM**3)*(CM**2)*
C...          CM*(1/HR) = MOLS H20/HR ACCUMULATING IN THE GAS PHASE
C...          WITHIN THE INCREMENTAL SECTION OF LENGTH DZ (SEE THE
C...          DIAGRAM BELOW)
C...
C...     V*Y
C...        Z
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DRY AIR) = MOLS H20/HR
C...          FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     V*Y
C...        Z+DZ
C...
C...        = (MOLS DRY AIR/HR)*(MOLS H20/MOL DAY AIR) = MOLS H20/HR
C..           FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     KY*AV*(YS - Y)*S*DZ
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...           AIR)*(CM**2)*(CM) = MOLS H20/HR TRANSFERRED TO OR FROM
C...           THE AIR STREAM IN THE INCREMENTAL SECTION (THE DIRECTION
C...           OF TRANSFER DEPENDS ON THE SIGN OF (YS - Y))
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (1A) BECOMES
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                (1)
C...      T                Z
C...
C...  AN ENERGY BALANCE ON THE GAS PHASE GIVES
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))*G*S*DZ)  =
C...                                          T
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V  -
C...                                    Z                       (2A)
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V     -
C...                                    Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ + KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (2A) IS INDICATED BELOW
C...
C...     (CVA*TG + Y*(CVV*TG + DHVAP))G*S*DZ
C...                                        T
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/
C...          CM**3)*(CM**2)*CM*(1/HR) = CAL/HR ACCUMULATING IN THE
C...          GAS PHASE WITHIN THE INCREMENTAL SECTION
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING INTO THE INCREMENTAL SECTION AT Z
C...
C...     (CPA*TG + Y*(CPV*TG + DHVAP))*V
C...                                    Z+DZ
C...
C...        = (CAL/MOL DRY AIR-C)*(C) + (MOLS H20/MOL DRY AIR)*
C...          (CAL/MOL H20-C)*(C) + CAL/MOL H20))*(MOLS DRY AIR/HR)
C...          = CAL/HR FLOWING OUT OF THE INCREMENTAL SECTION AT Z+DZ
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (2A) BECOMES
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                    (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THERE THE ENERGY GROUPS, EV (ENERGY AT CONSTANT VOLUME) AND EP
C...  (ENERGY AT CONSTANT PRESSURE) HAVE BEEN USED TO SIMPLIFY THE
C...  TERMS IN EQUATION (2).  EV AND EP ARE DEFINED IN THE TABLE OF
C...  NOMENCLATURE GIVEN EARLIER.
C...
C...  AN ENERGY BALANCE ON THE LIQUID GIVES
C...
C...     (CL*TL*H*S*DZ)  = (CL*TL*L)     - (CL*TL*L)
C...                   T            Z+DZ            Z           (3A)
C...
C...     -H*AV*(TL - TG)*S*DZ - KY(AV*(YS - Y)*S*DZ*(CVV*TG + HDVAP)
C...
C...  THE PHYSICAL INTERPRETATION AND UNITS OF EACH OF THE TERMS IN
C...  EQUATION (3A) IS GIVEN BELOW
C...
C...     (CL*TL*H*S*DZ)
C...                   T
C...
C...        (CAL/MOL H20-C)*(C)*(MOLS H20/CM**3)*(CM**2)*CM*(1/HR)
C...        = CAL/HR ACCUMULATING IN THE H20 PHASE WITHIN THE
C...        INCREMENTAL SECTION OF LENGTH DZ
C...
C...     (CL*TL*L)
C...              Z+DZ
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING INTO
C...          THE INCREMENTAL SECTION AT Z+DZ
C...
C...     (CL*TL*L)
C...              Z
C...
C...        = (CAL/MOL H20-C)*(C)*(MOLS H20/HR) = CAL/HR FLOWING OUT OF
C...          THE INCREMENTAL SECTION AT Z
C...
C...     H*AV*(TL - TG)*S*DZ
C...
C...        = (CAL/HR-CM**2-C)*(CM**2/CM**3)*(C)*(CM**2)*CM = CAL/HR
C...          TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO TEMP-
C...          ERATURE DIFFERENCES (THE DIRECTION OF TRANSFER DEPENDS
C...          ON THE SIGN OF (TL - TG))
C...
C...     KY*AV*(YS - Y)*S*DZ*(CVV*TG + DHVAP)
C...
C...        = (MOLS DRY AIR/HR-CM**2)*(CM**2/CM**3)*(MOLS H20/MOL DRY
C...          AIR)*(CM**2)*(CM)*((CAL/MOL H20-C)*C + CAL/MOL H20) =
C...          CAL/HR TRANSFERRED BETWEEN THE H20 AND GAS PHASES DUE TO
C...          DIFFERENCES IN HUMIDITY
C...
C...  IN THE LIMIT AS DZ ---+ 0, EQUATION (3A) BECOMES
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                    (3)
C...
C...            - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  AN EXTENSION OF THE PRECEDING SYSTEM IS ALSO SIMULATED IN THE
C...  FOLLOWING CODING.  SPECIFICALLY, THE EXITING WATER TEMPERATURE
C...  TL(0,T), IS SENSED, COMPARED WITH A SET POINT VALUE, TLSET,
C...  AND THE DIFFERENCE (ERROR), E = TL(0,T) - TLSET, IS USED TO
C...  ADJUST THE ENTERING AIR FLOW RATE, V, TO MOVE TL(0,T) TO TLSET.
C...  THE ADJUSTMENT OF V IS ACHIEVED WITH A PROPORTIONAL-INTEGRAL (PI)
C...  CONTROLLER.  THE FOLLOWING DIAGRAM ILLUSTRATES THE CONTROLLER
C...  AT THE BOTTOM OF THE HUMIDIFICATION COLUMN
C...
C...                     L,TL(ZL,T)   V,Y(ZL,T),
C...                                   TG(ZL,T)
C...                          .           +
C...                          .           .
C...                          .           .
C...                          +           .
C...                          .  .  .  .  . Z = ZL
C...                        .              .
C...                       .                .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      . L,TL       V,Y,TG.
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      .................... Z+DZ
C...                      .      .           .
C...                      . H20  .           .
C...                      .PHASE . ----+ H20 .
C...                      .      .    AIR    .
C...                      .      .   PHASE   .
C...                      ....................  Z
C...                      .  .            +  .
C...                      .  .            .  .
C...                      .  +            .  .
C...                      . H20          AIR .
C...                      .STREAM      STREAM.
C...                      .(DOWN)       (UP) .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                      .                  .
C...                       .                .
C...                        .              .
C...                          .  .  .  .  . Z = 0
C...                          .           +             PI
C...                          .           .         CONTROLLER
C...                          .           .          .........
C...            TEMPERATURE .....         .          .       .
C...              SENSOR    .   .......... ........... KC,TI .+--- TLSET
C...                        .....         .          .       .
C...                          .           .          .........
C...                          .           .              .
C...                          .          ...   ..        .
C...                          .           ...... .........
C...                          .          ...   ..
C...                          .           . CONTROL VALVE
C...                          +           .
C...                      L,TL(0,T)   V,Y(0,T),
C...                                   TG(0,T)
C...
C...  THE PURPOSE OF THE SIMULATION IS ESSENTIALLY TO DETERMINE, THE
C...  VALUES OF THE CONTROLLER GAIN, KC, AND INTEGRAL TIME, TI, SO
C...  THAT THE EXITING LIQUID TEMPERATURE, TL(0,T), IS CONTROLLED CLOSE
C...  TO THE SET POINT, TLSET.
C...
C...  THE CONTROLLER EQUATIONS ARE
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TLSET
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TLSET   CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS IN ENGLISH UNITS ARE
C...  LISTED BELOW, FOLLOWED BY EQUIVALENT VALUES IN METRIC UNITS.  THE
C...  CAN BE EXECUTED WITH EITHER SET BY SELECTING THE VALUE OF THE
C...  VARIABLE METRIC IN THE PROGRAM (METRIC = 0 FOR ENGLISH UNITS,
C...  METRIC = 1 FOR METRIC UNITS)
C...
C...  ******************************************************************
C...
C...   ENGLISH UNITS
C...
C...   H*AV = 50 BTU/(HR-FT**3-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOL-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2
C...
C...   H = 0.5 LB MOLS/FT**3 , G = 0.01 LB MOLS/FT**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TLSET = 90 F
C...
C...  ******************************************************************
C...
C...   METRIC UNITS
C...
C...   H*AV = 0.8015 CAL/(HR-CM**3-C)
C...
C...   KY*AV = 0.06573 GM MOLS DRY AIR/(HR-CM**3)
C...
C...   Z = 243.8 CM, CL = 18 CAL/(GM MOL-C), DHVAP = 9443.6 CAL/GM MOL
C...
C...   CPV = 7.3 CAL/(GM MOL-C), CPA = 7.3 CAL/(GM MOL-C)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 CAL/(GM MOL-C)
C...
C...   L = 22700 GM MOLS/HR, S = 929.03 CM**2
C...
C...   H = 0.008015 GM MOLS/CM**3, G = 0.0001603 GM MOLS/CM**3
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + 1.8*TL + 32)) MM HG
C...                                                    (TL IS IN C)
C...
C...   YS = P/(760 - P) GM MOLS H20/GM MOL DRY AIR
C...
C...   TG(0,T) = 43.33 C, TL(8,T) = 43.33 C, Y(0,T) = 0.01 GM MOL H20/
C...                                                  GM MOL DRY AIR)
C...
C...   TG(Z,0) = TL(Z,0) = 43.33 C, Y(Z,0) = 0.01
C...
C...   KC = 0.036 (1/C), TI = 0.1 HR, CV*(DP**0.5) = 22700 GM MOLS/HR
C...
C...   XSS = 0.5, TLSET = 32.22 C
C...
C...  ******************************************************************
C...
C...  THE CONVERSION FACTORS USED TO GO FROM ONE SET OF UNITS TO THE
C...  OTHER ARE
C...
C...     1 BTU = 252.2 CAL
C...
C...     1 BTU/LB MOL-F = 1 CAL/GM MOL-C
C...
C...     1 LB = 454 GM
C...
C...     1 LB MOL = 454 GM MOL
C...
C...     1 F = 1/1.8 C
C...
C...     1 FT = 30.48 CM
C...
C...     1 FT**3 = 28316.8 CM**3
C...
C...     TF = 1.8*TC + 32
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  SELECT ENGLISH (METRIC = 0) OR METRIC (METRIC = 1) UNITS
      IF(NORUN.EQ.1)METRIC=0
      IF(NORUN.EQ.2)METRIC=1
C...
C...  SET THE MODEL PARAMETERS IN THE UNITS SELECTED
C...
C...  ENGLISH UNITS
      IF(METRIC.EQ.0)THEN
      N=11
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.02
      TI=0.1
      CVDP=50.
      XSS=0.5
      TLSET=90.
C...
C...  METRIC UNITS
      ELSE
      N=11
      L=22700.
      G=0.0001603
      H=0.008015
      HLAV=0.8015
      KYAV=0.06573
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=243.8
      DHVAP=9443.6
      S=929.03
C...
C...  SET THE CONTROLLER PARAMETERS
      KC=0.036
      TI=0.1
      CVDP=22700.
      XSS=0.5
      TLSET=32.22
      END IF
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      IF(METRIC.EQ.0)THEN
      TL(I)=110.
      TG(I)=110.
      ELSE
      TL(I)=43.33
      TG(I)=43.33
      END IF
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TLSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      IF(METRIC.EQ.0)THEN
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      ELSE
      P=10.**(7.96681-3002.4/(378.4+1.8*TL(I)+32.))
      END IF
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      IF(METRIC.EQ.0)THEN
      TL(N)=110.
      TG(1)=110.
      ELSE
      TL(N)=43.33
      TG(1)=43.33
      END IF
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
C...
C...  ZERO THE TIME DERIVATIVES TO MAINTAIN THE BOUNDARY CONDITIONS
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,  TLSET,      X,
     9              IP,      N, METRIC
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  ABSOLUTE DIMENSIONING OF THE ARRAYS REQUIRED BY SUBROUTINE JMAP
C...  (A, Y, YOLD, F, FOLD) AND SUBROUTINE EIGEN (WI, WR, Z, RW, IW)
      REAL
     1       A( 34, 34), WR( 34), WI( 34), Z( 34, 34), RW( 34),
     2                            SV( 34), SVOLD( 34),
     3                             F( 34),  FOLD( 34)
      INTEGER                     IW( 34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  PRINT A DETAILED SOLUTION (THE INDIVIDUAL TERMS IN THE PDES AND
C...  THE DEPENDENT VARIABLES) FOR IP = 1, 51, 101 CALLS TO SUBROUTINE
C...  PRINT.  FIRST, UPDATE ALL OF THE MODEL CALCULATIONS BY A CALL
C...  TO SUBROUTINE DERV (THE INITIAL-VALUE INTEGRATION THROUGH COMMON
C...  /Y/ AND /F/ IS DONE CORRECTLY WITHOUT THIS UPDATE, BUT SOME OF THE
C...  MODEL VARIABLES MAY BE ONE INTEGRATION TIME STEP BEHIND IN TIME,
C...  T, WHEN THEY ARE PRINTED OUT IN SUBROUTINE PRINT IF THE FOLLOWING
C...  CALL TO SUBROUTINE DERV IS NOT EXECUTED)
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  ***************************************************************
C...  GAS-PHASE MATERIAL BALANCE
C...  ************************************************************(1)
C...
C...     -(V/(G*S))*Y
C...                 Z
         DO 1 I=1,N
         TEP(I)=-P1*EPZ(I)
1        CONTINUE
         N2=1
         WRITE(NO,2)T,(TEP(I),I=1,N,N2)
2        FORMAT( 1H1,5H T = ,F7.3,//,
     1          25H -(V/(G*S))*YZ           ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(2)
C...
C...     (KY*AV/G)*(YS - Y)
         DO 3 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
3        CONTINUE
         WRITE(NO,4)(TEP(I),I=1,N,N2)
4        FORMAT(25H (KA*AV/G)*(YS - Y)      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(3)
C...
C...     Y
C...      T
         WRITE(NO,5)(YT(I),I=1,N,N2)
5        FORMAT(25H YT                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(4)
C...
C...     Y
         WRITE(NO,6)(Y(I),I=1,N,N2)
6        FORMAT(25H Y                       ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  EQUILIBRIUM RELATIONSHIP
C...  ************************************************************(5)
C...
C...     YS
         WRITE(NO,7)(YS(I),I=1,N,N2)
7        FORMAT(25H YS                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ***************************************************************
C...  GAS-PHASE ENERGY BALANCE
C...  ************************************************************(6)
C...
C...     -(V/(G*S))*EP  = -(V/(G*S))*(CPA*TG + Y*(CPV*TG + DHVAP))
C...                  Z                                           Z
         DO 8 I=1,N
         TEP(I)=-P1*EPZ(I)
8        CONTINUE
         WRITE(NO,9)(TEP(I),I=1,N,N2)
9        FORMAT(25H -(V/(G*S))*EPZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(7)
C...
C...     (H*AV/G)*(TL - TG)
         DO 10 I=1,N
         TEP(I)=P3*(TL(I)-TG(I))
10       CONTINUE
         WRITE(NO,11)(TEP(I),I=1,N,N2)
11       FORMAT(25H -(H*AV/G)*(TL - TG)     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(8)
C...
C...     (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
         DO 12 I=1,N
         TEP(I)=-P2*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
12       CONTINUE
         WRITE(NO,13)(TEP(I),I=1,N,N2)
13       FORMAT(25H (KY*AV/G)*(YS - Y)*(...),5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(9)
C...
C...     EV  = (CVA*TG + Y*(CVV*TG + DHVAP))
C...       T                                T
         WRITE(NO,14)(EVT(I),I=1,N,N2)
14       FORMAT(25H EVT                     ,5E12.4,/,13X,6E12.4,//)
C...  ************************************************************(10)
C...
C...     TG
         WRITE(NO,15)(TG(I),I=1,N,N2)
15       FORMAT(25H TG                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...  LIQUID-PHASE ENERGY BALANCE
C...  ************************************************************(11)
C...
C...     -(L/(H*S))*TL
C...                  Z
         DO 16 I=1,N
         TEP(I)=P4*TLZ(I)
16       CONTINUE
         WRITE(NO,17)(TEP(I),I=1,N,N2)
17       FORMAT(25H -(L/(H*S))*TLZ          ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(12)
C...
C...     -(H*AV/(CL*H))*(TL - TG)
         DO 18 I=1,N
         TEP(I)=-P5*(TL(I)-TG(I))
18       CONTINUE
         WRITE(NO,19)(TEP(I),I=1,N,N2)
19       FORMAT(25H -(H*AV/(CL*H))*(TL-TG)  ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(13)
C...
C...     -(KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
         DO 20 I=1,N
         TEP(I)=-P6*(YS(I)-Y(I))*(CVV*TG(I)+DHVAP)
20       CONTINUE
         WRITE(NO,21)(TEP(I),I=1,N,N2)
21       FORMAT(25H -(KY*AV/(CL*H))*(YS-Y)..,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(14)
C...
C...     TL
C...       T
         WRITE(NO,22)(TLT(I),I=1,N,N2)
22       FORMAT(25H TLT                     ,5E12.4,/,13X,6E12.4,//)
C...
C...  ************************************************************(15)
C...
C...     TL
         WRITE(NO,23)(TL(I),I=1,N,N2)
23       FORMAT(25H TL                      ,5E12.4,/,13X,6E12.4,//)
C...
C...  ****************************************************************
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,WR,WI,Z,RW,IW)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
PI CONTROL OF A HUMIDIFICATION COLUMN - ENGLISH UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
PI CONTROL OF A HUMIDIFICATION COLUMN - METRIC UNITS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT02
      SUBROUTINE INITAL
C...
C...  METHOD OF LINES INTEGRATION OF BOUNDARY-VALUE ODES
C...
C...  THE FOLLOWING PROGRAMMING ILLUSTRATES HOW A SYSTEM OF FOUR
C...  BOUNDARY-VALUE ORDINARY DIFFERENTIAL EQUATIONS (BVODES) CAN
C...  BE INTEGRATED NUMERICALLY BY FIRST CONVERTING THE BVODES TO
C...  INITIAL-VALUE PDES, THEN INTEGRATING THE PDES TO STEADY STATE.
C...  THE STEADY STATE SOLUTION OF THE PDES IS THE SOLUTION TO THE
C...  BVODES.
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) MODEL A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 25, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   VT = 1, VS = 0.5, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE EXITING TEMPERATURES, T3(XL,T) AND TS(0,T), ARE OF PARTICULAR
C...  INTEREST IN THIS SIMULATION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      VS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1       CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101), TSP(101),   TP(101),
     1          T1SP(7,11),          T2SP(7,11),
     2          T3SP(7,11),          TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     1              4X,8HT3(XL,T),4X,8H TS(0,T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1)
2     FORMAT(F10.1,4F12.1)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,10)
10    FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,11)
11    FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 10,... 50)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO SUBROUTINES BVODE1 AND BVODE2 (BOUNDARY-
C...  VALUE ORDINARY DIFFERENTIAL EQUATIONS, VERSIONS 1 AND 2) SOLVE
C...  THE STEADY STATE PROBLEM (T1  = T2  = T3  = TS  = 0) DIRECTLY, FOR
C...                              T     T     T     T
C...  COMPARISON WITH THE DYNAMIC SOLUTION AT ESSENTIALLY INFINITE TIME
C...  (STEADY STATE).  SUBROUTINES BVODE1 AND BVODE2 DIFFER IN THE WAY
C...  IN WHICH THE BOUNDARY CONDITIONS OF THE STEADY STATE BVODE PROBLEM
C...  ARE IMPLEMENTED.  THE DETAILS IN BVODE1 AND BVODE2 GIVE ALL OF THE
C...  DETAILS
      CALL BVODE1
      CALL BVODE2
      RETURN
      END
      SUBROUTINE BVODE1
C...
C...  SUBROUTINE BVODE1 NUMERICALLY INTEGRATES THE BOUNDARY-VALUE
C...  ORDINARY DIFFERENTIAL EQUATIONS (BVODES) OBTAINED BY SETTING
C...  THE TIME DERIVATIVES TO ZERO IN THE THREE-PASS SHELL AND TUBE
C...  HEAT EXCHANGER PDES.  THE BVODES ARE EQUATIONS (1) TO (4)
C...  BELOW.  THE METHOD OF SOLUTION IS TO REPLACE THE SPATIAL
C...  DERIVATIVES (IN X) WITH THREE-POINT DIFFERENCE APPROXIMATIONS.
C...  THE RESULTING SET OF LINEAR ALGEBRAIC EQUATIONS IS THEN SOLVED
C...  BY CALLS TO SUBROUTINES DECOMP AND SOLVE.  THE DETAILS OF THE
C...  NUMERICAL SOLUTION ARE GIVEN IN THE FOLLOWING COMMENTS.
C...
C...  SUBROUTINE BVODE1 IS BASED ON DIRECT USE OF THE BOUNDARY CONDI-
C...  TIONS AS ALGEBRAIC EQUATIONS AT THE BOUNDARIES.  THIS CONTRASTS
C...  WITH SUBROUTINE BVODE2 IN WHICH EQUATIONS (1) TO (4) ARE APPROXI-
C...  MATED AT THE BOUNDARIES BY FINITE DIFFERENCES, THEN THE BOUNDARY
C...  CONDITIONS ARE SUBSTITUTED INTO THESE APPROXIMATIONS TO PRODUCE
C..   THE ALGEBRAIC EQUATIONS AT THE BOUNDARIES.
C...
C...     VT*DT1/DX = CT*(TS - T1)                                  (1)
C...
C...    -VT*DT2/DX = CT*(TS - T2)                                  (2)
C...
C...     VT*DT3/DX = CT*(TS - T3)                                  (3)
C...
C...    -VS*DTS/DX = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))        (4)
C...
C...  ACCESS THE INPUT/OUTPUT DEVICE NUMBERS
      COMMON/IO/NI,NO
C...
C...  DIMENSION THE ARRAYS FOR THE LINEAR ALGEBRAIC EQUATIONS
      DIMENSION A(44,44), B(44), IPVT(44), WORK(44)
C...
C...  ZERO THE COEFFICIENT MATRIX SO THAT THE SUBSEQUENT PROGRAMMING
C...  WILL DEFINE ONLY THE NONZERO ELEMENTS
      DO 13 I=1,44
      DO 13 J=1,44
      A(I,J)=0.
13    CONTINUE
C...
C...  ******************************************************************
C...
C...  EQUATION (1)
C...
C...  GRID POINT 1 (ALGEBRAIC EQUATION (AE) 1)
C...
C...     T1(1) = 25
C...
C...  GRID POINT 2 (AE 2)
C...
C...     VT*(T1(3) - T1(1))/(2*DX) = CT*(TS(2) - T1(2))
C...
C...     -VT/(2*DX)*T1(1) + CT*T1(2) + VT/(2*DX)*T1(3) - CT*TS(2) = 0
C...
C...  GRID POINT 3 (AE 3)
C...
C...     VT*(T1(4) - T1(2))/(2*DX) = CT*(TS(3) - T1(3))
C...
C...     -VT/(2*DX)*T1(2) + CT*T1(3) + VT/(2*DX)*T1(4) - CT*TS(3) = 0
C...
C...  GRID POINT 4 (AE 4)
C...
C...     VT*(T1(5) - T1(3))/(2*DX) = CT*(TS(4) - T1(4))
C...
C...     -VT/(2*DX)*T1(3) + CT*T1(4) + VT/(2*DX)*T1(5) - CT*TS(4) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 9 (AE 9)
C...
C...     VT*(T1(10) - T1(8))/(2*DX) = CT*(TS(9) - T1(9))
C...
C...     -VT/(2*DX)*T1(8) + CT*T1(9) + VT/(2*DX)*T1(10) - CT*TS(9) = 0
C...
C...  GRID POINT 10 (AE 10)
C...
C...     VT*(T1(11) - T1(9))/(2*DX) = CT*(TS(10) - T1(10))
C...
C...     -VT/(2*DX)*T1(9) + CT*T1(10) + VT/(2*DX)*T1(11) - CT*TS(10) = 0
C...
C...  GRID POINT 11 (AE 11)
C...
C...     VT*(3*T1(11) - 4*T1(10) + T1(9))/(2*DX) = CT*(TS(11) - T1(11))
C...
C...    VT/(2*DX)*T1(9) - 4*VT/(2*DX)*T1(10) + (3*VT/(2*DX) + CT)*T1(11)
C...
C...                     - CT*TS(11) = 0
C...
C...  SET THE MODEL PARAMETERS
         DX=10./FLOAT(11-1)
         VT=1.0
         VS=1.0
         C1=VT/(2.*DX)
         C2=VS/(2.*DX)
         CT=0.1
         CS=0.1
C...
C...  ******************************************************************
C...
C...  DEFINE THE COEFFICIENT MATRIX FOR THE FINITE DIFFERENCE APPROXI-
C...  MATION OF EQUATION (1)
C...
C...  AE 1
         A(1,1)=1.
C...
C...  AES 2 TO 10
         DO 1 I=2,10
         A(I,I-1)=-C1
         A(I,I  )= CT
         A(I,I+1)= C1
         IS=3*11+I
         A(I,IS )=-CT
1        CONTINUE
C...
C...  AE 11
         A(11, 9)=C1
         A(11,10)=-4.*C1
         A(11,11)=3.*C1+CT
         A(11,44)=-CT
C...
C...  ******************************************************************
C...
C...  EQUATION (2)
C...
C...  GRID POINT 11 (AE 22)
C...
C...     T2(11) = T1(11)
C...
C...  GRID POINT 10 (AE 21)
C...
C...     -VT*(T2(11) - T2(9))/(2*DX) = CT*(TS(10) - T2(10))
C...
C...     VT/(2*DX)*T2(9) + CT*T2(10) - VT/(2*DX)*T2(11) - CT*TS(10) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 2 (AE 13)
C...
C...     -VT*(T2(3) - T2(1))/(2*DX) = CT*(TS(2) - T2(2))
C...
C...     VT/(2*DX)*T2(1) + CT*T2(2) - VT/(2*DX)*T2(3) - CT*TS(2) = 0
C...
C...  GRID POINT 1 (AE 12)
C...
C...     -VT*(-T2(3) + 4*T2(2) - 3*T2(1))/(2*DX) = CT*(TS(1) - T2(1))
C...
C...     (3*VT/(2*DX)+CT)*T2(1) - 4*VT/(2*DX)*T2(2) + VT/(2*DX)*T2(3)
C...
C...                         - CT*TS(1) = 0
C...
C...  AE 12
         A(12,12)=3.*C1+CT
         A(12,13)=-4.*C1
         A(12,14)=C1
         A(12,34)=-CT
C...
C...  AES 13 TO 21
         DO 2 I=13,21
         A(I,I-1)= C1
         A(I,I  )= CT
         A(I,I+1)=-C1
         IS=2*11+I
         A(I,IS )=-CT
2        CONTINUE
C...
C...  AE 22
         A(22,11)=-1.
         A(22,22)= 1.
C...
C...  ******************************************************************
C...
C...  EQUATION (3)
C...
C...  GRID POINT 1 (AE 23)
C...
C...     T3(1) = T2(1)
C...
C...  GRID POINT 2 (AE 24)
C...
C...     VT*(T3(3) - T3(1))/(2*DX) = CT*(TS(2) - T3(2))
C...
C...     -VT/(2*DX)*T3(1) + CT*T3(2) + VT/(2*DX)*T3(3) - CT*TS(2) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 10 (AE 32)
C...
C...     VT*(T3(11) - T3(9))/(2*DX) = CT*(TS(10) - T3(10))
C...
C...    -VT/(2*DX)*(T3(9) + CT*T3(10) + VT*T3(11)/(2*DX) - CT*TS(10) = 0
C...
C...  GRID POINT 11 (AE 33)
C...
C...     VT*(3*T1(11) - 4*T3(10) + T3(9))/(2*DX) = CT*(TS(11) - T3(11))
C...
C...     VT/(2*DX)*T3(9) - 4*VT/(2*DX)*T3(10) + (3*VT/(2*DX)
C...
C...                + CT*T3(11) - CT*TS(11) = 0
C...
C...  AE 23
         A(23,12)=-1.
         A(23,23)= 1.
C...
C...  AES 24 TO 32
         DO 3 I=24,32
         A(I,I-1)=-C1
         A(I,I  )= CT
         A(I,I+1)= C1
         IS=11+I
         A(I,IS )=-CT
3        CONTINUE
C...
C...  AE 33
         A(33,31)=C1
         A(33,32)=-4.*C1
         A(33,33)=3.*C1+CT
         A(33,44)=-CT
C...
C...  ******************************************************************
C...
C...  EQUATION (4)
C...
C...  GRID POINT 11 (AE 44)
C...
C...     TS(11) = 220
C...
C...  GRID POINT 10 (AE 43)
C...
C...     -VS*(TS(11) - TS(9))/(2*DX) = CS*((T1(10) - TS(10))
C...
C...          + (T2(10) - TS(10)) + (T3(10) - TS(10)))
C...
C...     VS/(2*DX)*TS(9) + 3*CS*TS(10) - VS/(2*DX)*TS(11) - CS*T1(10)
C...
C...                     - CS*T2(10) - CS*T3(10) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 2 (AE 35)
C...
C...     -VS*(TS(3) - TS(1))/(2*DX) = CS*((T1(2) - TS(2))
C...
C...          + (T2(2) - TS(2)) + (T3(2) - TS(2)))
C...
C...     VS/(2*DX)*TS(1) + 3*CS*TS(2) - VS/(2*DX)*TS(3) - CS*T1(2)
C...
C...                   - CS*T2(2) - CS*T3(2) = 0
C...
C...  GRID POINT 1 (AE 34)
C...
C...     -VS*(-TS(3) + 4*TS(2) - 3*TS(1))/(2*DX) = CS*(T1(1) - TS(1))
C...
C...               + (T2(1) - TS(1)) + (T3(1) - TS(1)))
C...
C...    (3*VS/(2*DX) + 3*CS)*TS(1) - 4*VS/(2*DX)*TS(2) + VS/(2*DX)*TS(3)
C...
C...                 - CS*T1(1) - CS*T2(1) - CS*T3(1) = 0
C...
C...  AE 34
         A(34,34)=3.*C2+3.*CS
         A(34,35)=-4.*C2
         A(34,36)=C2
         A(34, 1)=-CS
         A(34,12)=-CS
         A(34,23)=-CS
C...
C...  AES 35 TO 43
         DO 4 I=35,43
         A(I,I-1)= C2
         A(I,I  )=3.*CS
         A(I,I+1)=-C2
         IS=I-3*11
         A(I,IS )=-CS
         IS=I-2*11
         A(I,IS )=-CS
         IS=I-1*11
         A(I,IS )=-CS
4        CONTINUE
C...
C...  AE 44
         A(44,44)=1.
C...
C...  ******************************************************************
C...
C...  RIGHT HAND SIDE (RHS) VECTOR
C...
C...  AE 1
         B(1)=25.
C...
C...  AE 2 TO 43
         DO 9 I=2,43
         B(I)=0.
9        CONTINUE
C...
C...  AE 44
         B(44)=220.
C...
C...  ******************************************************************
C...
C...  MAP THE COEFFICIENT MATRIX, A, TO DISPLAY ITS STRUCTURE
      N=44
      CALL MAP(N,A)
C...
C...  PRINT THE COEFFICIENT MATRIX TO CONFIRM THE VALUES OF THE
C...  INDIVIDUAL ELEMENTS
      CALL CHECK(N,A,IPVT)
C...
C...  SOLVE THE LINEAR ALGEBRAIC SYSTEM
      CALL DECOMP(N,N,A,COND,IPVT,WORK)
C...
C...  CHECK FOR A SINGULAR OR ILL-CONDITIONED SYSTEM
      IF(COND.LT.1.0E+20)GO TO 10
C...
C...  THE CONDITION NUMBER OF THE COEFFICIENT MATRIX, A, EXCEEDS 1.0E+20
C...  SO A WARNING MESSAGE IS PRINTED AND EXECUTION IS TERMINATED
      WRITE(NO,11)COND
11    FORMAT(26H CONDITION NUMBER OF A IS ,E12.4)
      STOP
C...
C...  COMPLETE AND PRINT THE SOLUTION
10    CALL SOLVE(N,N,A,B,IPVT)
      WRITE(NO,5)(B(I),I=1,11)
5     FORMAT(1H1,20H SOLUTION TO BVODE 1,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,6)(B(I),I=12,22)
6     FORMAT(1H ,20H SOLUTION TO BVODE 2,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,7)(B(I),I=23,33)
7     FORMAT(1H ,20H SOLUTION TO BVODE 3,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,8)(B(I),I=34,44)
8     FORMAT(1H ,20H SOLUTION TO BVODE 4,/,10X,5F10.3,/,6F10.3,///)
      RETURN
      END
      SUBROUTINE BVODE2
C...
C...  SUBROUTINE BVODE2 NUMERICALLY INTEGRATES THE BOUNDARY-VALUE
C...  ORDINARY DIFFERENTIAL EQUATIONS (BVODES) OBTAINED BY SETTING
C...  THE TIME DERIVATIVES TO ZERO IN THE THREE-PASS SHELL AND TUBE
C...  HEAT EXCHANGER PDES.  THE BVODES ARE EQUATIONS (1) TO (4)
C...  BELOW.  THE METHOD OF SOLUTION IS TO REPLACE THE SPATIAL
C...  DERIVATIVES (IN X) WITH THREE-POINT DIFFERENCE APPROXIMATIONS.
C...  THE RESULTING SET OF LINEAR ALGEBRAIC EQUATIONS IS THEN SOLVED
C...  BY CALLS TO SUBROUTINES DECOMP AND SOLVE.  THE DETAILS OF THE
C...  NUMERICAL SOLUTION ARE GIVEN IN THE FOLLOWING COMMENTS.
C...
C...  SUBROUTINE BVODE2 IS BASED ON FINITE DIFFERENCE APPROXIMATIONS
C...  OF EQUATIONS (1) TO (4) AT THE BOUNDARIES WITH THE FOUR BOUNDARY
C...  CONDITIONS SUBSTITUTED INTO THESE APPROXIMATIONS TO PRODUCE THE
C...  ALGEBRAIC EQUATIONS AT THE BOUNDARIES.  THIS CONTRASTS WITH SUB-
C...  ROUTINE BVODE1 IN WHICH THE BOUNDARY CONDITIONS ARE USED DIRECTLY
C...  AS ALGEBRAIC EQUATIONS.
C...
C...     VT*DT1/DX = CT*(TS - T1)                                  (1)
C...
C...    -VT*DT2/DX = CT*(TS - T2)                                  (2)
C...
C...     VT*DT3/DX = CT*(TS - T3)                                  (3)
C...
C...    -VS*DTS/DX = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))        (4)
C...
C...  ACCESS THE INPUT/OUTPUT DEVICE NUMBERS
      COMMON/IO/NI,NO
C...
C...  DIMENSION THE ARRAYS FOR THE LINEAR ALGEBRAIC EQUATIONS
      DIMENSION A(44,44), B(44), IPVT(44), WORK(44)
C...
C...  ZERO THE COEFFICIENT MATRIX SO THAT THE SUBSEQUENT PROGRAMMING
C...  WILL DEFINE ONLY THE NONZERO ELEMENTS
      DO 13 I=1,44
      DO 13 J=1,44
      A(I,J)=0.
13    CONTINUE
C...
C...  ******************************************************************
C...
C...  EQUATION (1)
C...
C...  GRID POINT 1 (ALGEBRAIC EQUATION (AE) 1)
C...
C...     VT*(-T1(3) + 4*T1(2) - 3*T1(1))/(2*DX) = CT*(TS(1) - T1(1))
C...
C...     4*VT/(2*DX)*T1(2) - VT/(2*DX)*T1(3) - CT*TS(1) =
C...
C...                  (3*VT/(2*DX) - CT)*25
C...
C...  GRID POINT 2 (AE 2)
C...
C...     VT*(T1(3) - T1(1))/(2*DX) = CT*(TS(2) - T1(2))
C...
C...     -VT/(2*DX)*T1(1) + CT*T1(2) + VT/(2*DX)*T1(3) - CT*TS(2) = 0
C...
C...  GRID POINT 3 (AE 3)
C...
C...     VT*(T1(4) - T1(2))/(2*DX) = CT*(TS(3) - T1(3))
C...
C...     -VT/(2*DX)*T1(2) + CT*T1(3) + VT/(2*DX)*T1(4) - CT*TS(3) = 0
C...
C...  GRID POINT 4 (AE 4)
C...
C...     VT*(T1(5) - T1(3))/(2*DX) = CT*(TS(4) - T1(4))
C...
C...     -VT/(2*DX)*T1(3) + CT*T1(4) + VT/(2*DX)*T1(5) - CT*TS(4) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 9 (AE 9)
C...
C...     VT*(T1(10) - T1(8))/(2*DX) = CT*(TS(9) - T1(9))
C...
C...     -VT/(2*DX)*T1(8) + CT*T1(9) + VT/(2*DX)*T1(10) - CT*TS(9) = 0
C...
C...  GRID POINT 10 (AE 10)
C...
C...     VT*(T1(11) - T1(9))/(2*DX) = CT*(TS(10) - T1(10))
C...
C...     -VT/(2*DX)*T1(9) + CT*T1(10) + VT/(2*DX)*T1(11) - CT*TS(10) = 0
C...
C...  GRID POINT 11 (AE 11)
C...
C...     VT*(3*T1(11) - 4*T1(10) + T1(9))/(2*DX) = CT*(TS(11) - T1(11))
C...
C...    VT/(2*DX)*T1(9) - 4*VT/(2*DX)*T1(10) + (3*VT/(2*DX) + CT)*T1(11)
C...
C...                     - CT*TS(11) = 0
C...
C...  SET THE MODEL PARAMETERS
         DX=10./FLOAT(11-1)
         VT=1.0
         VS=1.0
         C1=VT/(2.*DX)
         C2=VS/(2.*DX)
         CT=0.1
         CS=0.1
C...
C...  ******************************************************************
C...
C...  DEFINE THE COEFFICIENT MATRIX FOR THE FINITE DIFFERENCE APPROXI-
C...  MATION OF EQUATION (1)
C...
C...  AE 1
         A(1,1)=0.
         A(1,2)=4.*C1
         A(1,3)=-C1
         A(1,34)=-CT
C...
C...  AES 2 TO 10
         DO 1 I=2,10
         A(I,I-1)=-C1
         A(I,I  )= CT
         A(I,I+1)= C1
         IS=3*11+I
         A(I,IS )=-CT
1        CONTINUE
C...
C...  AE 11
         A(11, 9)=C1
         A(11,10)=-4.*C1
         A(11,11)=3.*C1+CT
         A(11,44)=-CT
C...
C...  ******************************************************************
C...
C...  EQUATION (2)
C...
C...  GRID POINT 11 (AE 22)
C...
C...     -VT*(3*T2(11) - 4*T2(10) + T2(9))/(2*DX) = CT*(TS(11) - T2(11))
C...
C...    -VT/(2*DX)*T2(9) + 4*VT/(2*DX)*T2(10) + (-3*VT/(2*DX)+CT)*T1(11)
C...
C...                            -CT*TS(11) = 0
C...
C...  GRID POINT 10 (AE 21)
C...
C...     -VT*(T2(11) - T2(9))/(2*DX) = CT*(TS(10) - T2(10))
C...
C...     VT/(2*DX)*T2(9) + CT*T2(10) - VT/(2*DX)*T2(11) - CT*TS(10) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 2 (AE 13)
C...
C...     -VT*(T2(3) - T2(1))/(2*DX) = CT*(TS(2) - T2(2))
C...
C...     VT/(2*DX)*T2(1) + CT*T2(2) - VT/(2*DX)*T2(3) - CT*TS(2) = 0
C...
C...  GRID POINT 1 (AE 12)
C...
C...     -VT*(-T2(3) + 4*T2(2) - 3*T2(1))/(2*DX) = CT*(TS(1) - T2(1))
C...
C...     (3*VT/(2*DX)+CT)*T2(1) - 4*VT/(2*DX)*T2(2) + VT/(2*DX)*T2(3)
C...
C...                         - CT*TS(1) = 0
C...
C...  AE 12
         A(12,12)=3.*C1+CT
         A(12,13)=-4.*C1
         A(12,14)=C1
         A(12,34)=-CT
C...
C...  AES 13 TO 21
         DO 2 I=13,21
         A(I,I-1)= C1
         A(I,I  )= CT
         A(I,I+1)=-C1
         IS=2*11+I
         A(I,IS )=-CT
2        CONTINUE
C...
C...  AE 22
         A(22,20)=-C1
         A(22,21)=4.*C1
         A(22,11)=-3.*C1+CT
         A(22,44)=-CT
C...
C...  ******************************************************************
C...
C...  EQUATION (3)
C...
C...  GRID POINT 1 (AE 23)
C...
C...     VT*(-T3(3) + 4*T3(2) - 3*T3(1))/(2*DX) = CT*(TS(1) - T3(1))
C...
C...     4*VT/(2*DX)*T3(2) - VT/(2*DX)*T3(3) + (-3*VT/(2*DX)+CT)*T2(1)
C...
C...                         - CT*TS(1) = 0
C...
C...  GRID POINT 2 (AE 24)
C...
C...     VT*(T3(3) - T3(1))/(2*DX) = CT*(TS(2) - T3(2))
C...
C...     -VT/(2*DX)*T3(1) + CT*T3(2) + VT/(2*DX)*T3(3) - CT*TS(2) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 10 (AE 32)
C...
C...     VT*(T3(11) - T3(9))/(2*DX) = CT*(TS(10) - T3(10))
C...
C...    -VT/(2*DX)*(T3(9) + CT*T3(10) + VT*T3(11)/(2*DX) - CT*TS(10) = 0
C...
C...  GRID POINT 11 (AE 33)
C...
C...     VT*(3*T1(11) - 4*T3(10) + T3(9))/(2*DX) = CT*(TS(11) - T3(11))
C...
C...     VT/(2*DX)*T3(9) - 4*VT/(2*DX)*T3(10) + (3*VT/(2*DX)
C...
C...                + CT*T3(11) - CT*TS(11) = 0
C...
C...  AE 23
         A(23,23)=0.
         A(23,24)=4.*C1
         A(23,25)=-C1
         A(23,12)=-3.*C1+CT
         A(23,34)=-CT
C...
C...  AES 24 TO 32
         DO 3 I=24,32
         A(I,I-1)=-C1
         A(I,I  )= CT
         A(I,I+1)= C1
         IS=11+I
         A(I,IS )=-CT
3        CONTINUE
C...
C...  AE 33
         A(33,31)=C1
         A(33,32)=-4.*C1
         A(33,33)=3.*C1+CT
         A(33,44)=-CT
C...
C...  ******************************************************************
C...
C...  EQUATION (4)
C...
C...  GRID POINT 11 (AE 44)
C...
C...     -VS*(3*TS(11) - 4*TS(10) + TS(9))/(2*DX) = CS*(T1(11) - TS(11))
C...
C...              + (T2(11) - TS(11)) + (T3(11) - TS(11)))
C...
C...     -VS/(2*DX)*TS(9) + 4*VS/(2*DX)*TS(10) - CS*(T1(11) + T2(11)
C...
C...              + T3(11)) = (3*VS/(2*DX) - 3*CS)*220
C...
C...  GRID POINT 10 (AE 43)
C...
C...     -VS*(TS(11) - TS(9))/(2*DX) = CS*((T1(10) - TS(10))
C...
C...          + (T2(10) - TS(10)) + (T3(10) - TS(10)))
C...
C...     VS/(2*DX)*TS(9) + 3*CS*TS(10) - VS/(2*DX)*TS(11) - CS*T1(10)
C...
C...                     - CS*T2(10) - CS*T3(10) = 0
C...        .                                                 .
C...        .                                                 .
C...        .                                                 .
C...
C...  GRID POINT 2 (AE 35)
C...
C...     -VS*(TS(3) - TS(1))/(2*DX) = CS*((T1(2) - TS(2))
C...
C...          + (T2(2) - TS(2)) + (T3(2) - TS(2)))
C...
C...     VS/(2*DX)*TS(1) + 3*CS*TS(2) - VS/(2*DX)*TS(3) - CS*T1(2)
C...
C...                   - CS*T2(2) - CS*T3(2) = 0
C...
C...  GRID POINT 1 (AE 34)
C...
C...     -VS*(-TS(3) + 4*TS(2) - 3*TS(1))/(2*DX) = CS*(T1(1) - TS(1))
C...
C...               + (T2(1) - TS(1)) + (T3(1) - TS(1)))
C...
C...    (3*VS/(2*DX) + 3*CS)*TS(1) - 4*VS/(2*DX)*TS(2) + VS/(2*DX)*TS(3)
C...
C...                 - CS*T1(1) - CS*T2(1) - CS*T3(1) = 0
C...
C...  AE 34
         A(34,34)=3.*C2+3.*CS
         A(34,35)=-4.*C2
         A(34,36)=C2
         A(34, 1)=-CS
         A(34,12)=-CS
         A(34,23)=-CS
C...
C...  AES 35 TO 43
         DO 4 I=35,43
         A(I,I-1)= C2
         A(I,I  )=3.*CS
         A(I,I+1)=-C2
         IS=I-3*11
         A(I,IS )=-CS
         IS=I-2*11
         A(I,IS )=-CS
         IS=I-1*11
         A(I,IS )=-CS
4        CONTINUE
C...
C...  AE 44
         A(44,44)=0.
         A(44,43)=4.*C2
         A(44,42)=-C2
         A(44,11)=-CS
         A(44,22)=-CS
         A(44,33)=-CS
C...
C...  ******************************************************************
C...
C...  RIGHT HAND SIDE (RHS) VECTOR
C...
C...  AE 1
         B(1)=(3.*C1-CT)*25.
C...
C...  AE 2 TO 43
         DO 9 I=2,43
         B(I)=0.
9        CONTINUE
C...
C...  AE 44
         B(44)=(3.*C2-3.*CS)*220.
C...
C...  ******************************************************************
C...
C...  MAP THE COEFFICIENT MATRIX, A, TO DISPLAY ITS STRUCTURE
      N=44
      CALL MAP(N,A)
C...
C...  PRINT THE COEFFICIENT MATRIX TO CONFIRM THE VALUES OF THE
C...  INDIVIDUAL ELEMENTS
      CALL CHECK(N,A,IPVT)
C...
C...  SOLVE THE LINEAR ALGEBRAIC SYSTEM
      CALL DECOMP(N,N,A,COND,IPVT,WORK)
C...
C...  CHECK FOR A SINGULAR OR ILL-CONDITIONED SYSTEM
      IF(COND.LT.1.0E+20)GO TO 10
C...
C...  THE CONDITION NUMBER OF THE COEFFICIENT MATRIX, A, EXCEEDS 1.0E+20
C...  SO A WARNING MESSAGE IS PRINTED AND EXECUTION IS TERMINATED
      WRITE(NO,11)COND
11    FORMAT(26H CONDITION NUMBER OF A IS ,E12.4)
      STOP
C...
C...  COMPLETE AND PRINT THE SOLUTION
10    CALL SOLVE(N,N,A,B,IPVT)
      WRITE(NO,5)(B(I),I=1,11)
5     FORMAT(1H1,20H SOLUTION TO BVODE 1,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,6)(B(I),I=12,22)
6     FORMAT(1H ,20H SOLUTION TO BVODE 2,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,7)(B(I),I=23,33)
7     FORMAT(1H ,20H SOLUTION TO BVODE 3,/,10X,5F10.3,/,6F10.3,///)
      WRITE(NO,8)(B(I),I=34,44)
8     FORMAT(1H ,20H SOLUTION TO BVODE 4,/,10X,5F10.3,/,6F10.3,///)
      RETURN
      END
      SUBROUTINE MAP(N,A)
C...
C...  SUBROUTINE MAP IS A BASIC MAPPING ROUTINE FOR LINEAR ALGEBRAIC
C...  EQUATIONS.  IT CAN ALSO MAP THE JACOBIAN MATRIX OF A SYSTEM OF
C...  NONLINEAR ALGEBRAIC OR ORDINARY DIFFERENTIAL EQUATIONS.  THE
C...  SIZE OF THE MATRIX TO BE MAPPED IS LIMITED TO 49 X 49 (THIS IS
C...  AN ARBITRARY CHOICE, AND THE ROUTINE CAN EASILY BE MODIFIED TO
C...  ACCOMMODATE LARGER MATRICES).  FOR A MORE SOPHISTICATED MAPPING
C...  ROUTINE, THE READER IS REFERRED TO SUBROUTINE JMAP AVAILABLE IN
C...  DSS/2.
C...
C...     N      ORDER (ROW AND COLUMN DIMENSIONS) OF THE COEFFICIENT
C...            MATRIX TO BE MAPPED (INPUT)
C...
C...     A      TWO DIMENSIONAL ARRAY TO STORE THE COEFFICIENT MATRIX
C...            TO BE MAPPED (INPUT)
C...
C...  VARIABLE DIMENSION THE ARRAY FOR THE COEFFICIENT MATRIX
      DIMENSION A(N,N)
C...
C...  ABSOLUTE DIMENSION THE ARRAYS FOR THE SYMBOLS, FIRST AND SECOND
C...  LINES OF THE MAP
      DIMENSION SYMBOL(11), HLINE1(51), HLINE2(50)
C...
C...  ACCESS THE INPUT/OUTPUT DEVICE NUMBERS
      COMMON/IO/NI,NO
C...
C...  DEFINE THE SYMBOLS PRINTED IN THE MAP
      DATA SYMBOL/2H 1,2H 2,2H 3,2H 4,2H 5,2H 6,2H 7,2H 8,2H 9,
     1            2H 0,2H  /,XCHAR/2H X/
C...
C...  DEFINE THE SYMBOLS PRINTED IN THE FIRST (TENS) ROW OF THE MAP
      DO 1 I=1,5
      DO 1 J=1,10
      JS=10*(I-1)+J
      IF(I.EQ.1)HLINE1(JS)=SYMBOL(11)
      IF(I.EQ.2)HLINE1(JS)=SYMBOL(1)
      IF(I.EQ.3)HLINE1(JS)=SYMBOL(2)
      IF(I.EQ.4)HLINE1(JS)=SYMBOL(3)
      IF(I.EQ.5)HLINE1(JS)=SYMBOL(4)
1     CONTINUE
C...
C...  DEFINE THE SYMBOLS PRINTED IN THE SECOND (UNITS) ROW OF THE MAP
      DO 2 I=1,5
      DO 2 J=1,10
      JS=10*(I-1)+J
      HLINE2(JS)=SYMBOL(J)
2     CONTINUE
C...
C...  PRINT A LABEL FOR THE HORIZONTAL AND VERTICAL LINES OF THE
C...  MAP
      WRITE(NO,8)
8     FORMAT(1H1,15X,40H COLUMN INDEX IS FOR THE UNKNOWNS -----+ ,//,
     1 1H ,4X,1H.,/,1H ,4X,1H.,/,
     2 1H ,4X,1H.,   40H ROW INDEX IS FOR THE EQUATIONS          ,/,
     3 1H ,4X,1H.,/,1H ,4X,1H.,/,
     4 1H ,4X,1H+,/)
C...
C...  PRINT THE FIRST (TENS) AND SECOND (UNITS) ROWS OF THE MAP
      NP1=N+1
      WRITE(NO,3)(HLINE1(I),I=1,NP1)
3     FORMAT(1H , 8X,50A2)
      WRITE(NO,4)(HLINE2(I),I=1,N)
4     FORMAT(1H ,10X,50A2)
C...
C...  PRINT THE ITH ROW OF THE MAP, 1 LE I LE N
      DO 6 I=1,N
C...
C...  INITIALLY, BLANK ALL J CHARACTERS OF THE ITH ROW OF THE MAP
      DO 5 J=1,N
      HLINE1(J)=SYMBOL(11)
C...
C...  IF THE JTH COLUMN ELEMENT OF THE COEFFICIENT MATRIX, A, IN THE
C...  ITH ROW EXCEEDS 1.0E-10 (ARBITRARILY SELECTED), SET THE CHARACTER
C...  TO X TO BE PRINTED IN THE I,J POSITION OF THE MAP
      IF(ABS(A(I,J)).GT.1.0E-10)HLINE1(J)=XCHAR
5     CONTINUE
C...
C...  PRINT THE ITH ROW OF THE MAP
      WRITE(NO,7)I,(HLINE1(J),J=1,N)
7     FORMAT(1H ,/,4X,I2,6X,50A2)
C...
C...  PRINT ALL N ROWS OF THE MAP BY GOING THROUGH DO LOOP 6 N TIMES
6     CONTINUE
      RETURN
      END
      SUBROUTINE CHECK(N,A,NEQ)
C...
C...  SUBROUTINE CHECK PRINTS OUT THE NUMERICAL VALUES OF THE ELEMENTS
C...  OF THE COEFFICIENT MATRIX, A.  IT IS HIGHLY SPECIFIC TO THIS
C...  PARTICULAR PROBLEM, E.G., DO LOOPS HAVE NUMERICAL UPPER LIMITS
C...  CORRESPONDING TO N = 44.
C...
C...  ARGUMENT LIST
C...
C...     N      ORDER (ROW AND COLUMN DIMENSIONS) OF THE COEFFICIENT
C...            MATRIX TO BE PRINTED (INPUT)
C...
C...     A      TWO DIMENSIONAL ARRAY CONTAINING THE COEFFICIENT MATRIX
C...            TO BE PRINTED (INPUT)
C...
C...     NEQ  CONE DIMENSIONAL, INTEGER WORK ARRAY (INPUT)
C...
C...  VARIABLE DIMENSION THE ARRAYS USED BY SUBROUTINE CHECK
      DIMENSION A(N,N), NEQ(N)
C...
C...  ACCESS THE INPUT/OUTPUT DEVICE NUMBERS
      COMMON/IO/NI,NO
C...
C...  STORE THE COLUMN SUBSCRIPTS OF THE COEFFICIENT MATRIX FOR
C...  SUBSEQUENT PRINTING
      DO 1 I=1,44
      NEQ(I)=I
1     CONTINUE
C...
C...  PRINT THE ALGEBRAIC APPROXIMATIONS OF EACH OF THE BOUNDARY-VALUE
C...  ODES (BVODES)
      DO 6 NEQN=1,4
      WRITE(NO,2)NEQN
2     FORMAT(1H1,14H ODE EQUATION ,I2,/)
C...
C...  STEP THROUGH THE 11 ALBEGRAIC APPROXIMATIONS FOR EACH BVODE
      DO 3 I=1,11
      IAE=11*(NEQN-1)+I
C...
C...  PRINT THE ITH ROW OF THE COEFFICIENT MATRIX FOR BVODE NEQN
      WRITE(NO,4)IAE,(NEQ(J),J=1,22),(A(I,J),J=1,22)
4     FORMAT(4H AE ,I2,2X,22I5,/,8X,22F5.1  )
      WRITE(NO,5)(NEQ(J),J=23,44),(A(I,J),J=23,44)
5     FORMAT(          8X,22I5,/,8X,22F5.1,/)
C...
C...  GO TO THE NEXT ROW OF THE COEFFICIENT MATRIX VIA DO LOOP 3
3     CONTINUE
C...
C...  GO TO THE NEXT BVODE VIA DO LOOP 6
6     CONTINUE
      RETURN
      END
      SUBROUTINE DECOMP(NDIM,N,A,COND,IPVT,WORK)
C
      INTEGER NDIM,N
      REAL A(NDIM,N),COND,WORK(N)
      INTEGER IPVT(N)
C
C     DECOMPOSES A REAL MATRIX BY GAUSSIAN ELIMINATION
C     AND ESTIMATES THE CONDITION OF THE MATRIX.
C
C     USE SOLVE TO COMPUTE SOLUTIONS TO LINEAR SYSTEMS.
C
C     INPUT..
C
C        NDIM = DECLARED ROW DIMENSION OF THE ARRAY CONTAINING  A.
C
C        N = ORDER OF THE MATRIX.
C
C        A = MATRIX TO BE TRIANGULARIZED.
C
C     OUTPUT..
C
C        A  CONTAINS AN UPPER TRIANGULAR MATRIX  U  AND A PERMUTED
C          VERSION OF A LOWER TRIANGULAR MATRIX  I-L  SO THAT
C          (PERMUTATION MATRIX)*A = L*U .
C
C        COND = AN ESTIMATE OF THE CONDITION OF  A .
C           FOR THE LINEAR SYSTEM  A*X = B, CHANGES IN  A  AND  B
C           MAY CAUSE CHANGES  COND  TIMES AS LARGE IN  X .
C           IF  COND+1.0 .EQ. COND , A IS SINGULAR TO WORKING
C           PRECISION.  COND  IS SET TO  1.0E+32  IF EXACT
C           SINGULARITY IS DETECTED.
C
C        IPVT = THE PIVOT VECTOR.
C           IPVT(K) = THE INDEX OF THE K-TH PIVOT ROW
C           IPVT(N) = (-1)**(NUMBER OF INTERCHANGES)
C
C     WORK SPACE..  THE VECTOR  WORK  MUST BE DECLARED AND INCLUDED
C                   IN THE CALL.  ITS INPUT CONTENTS ARE IGNORED.
C                   ITS OUTPUT CONTENTS ARE USUALLY UNIMPORTANT.
C
C     THE DETERMINANT OF A CAN BE OBTAINED ON OUTPUT BY
C        DET(A) = IPVT(N) * A(1,1) * A(2,2) * ... * A(N,N).
C
      REAL EK, T, ANORM, YNORM, ZNORM
      INTEGER NM1, I, J, K, KP1, KB, KM1, M
C
      IPVT(N) = 1
      IF (N .EQ. 1) GO TO 80
      NM1 = N - 1
C
C     COMPUTE 1-NORM OF A
C
      ANORM = 0.0
      DO 10 J = 1, N
         T = 0.0
         DO 5 I = 1, N
            T = T + ABS(A(I,J))
    5    CONTINUE
         IF (T .GT. ANORM) ANORM = T
   10 CONTINUE
C
C     GAUSSIAN ELIMINATION WITH PARTIAL PIVOTING
C
      DO 35 K = 1,NM1
         KP1= K+1
C
C        FIND PIVOT
C
         M = K
         DO 15 I = KP1,N
            IF (ABS(A(I,K)) .GT. ABS(A(M,K))) M = I
   15    CONTINUE
         IPVT(K) = M
         IF (M .NE. K) IPVT(N) = -IPVT(N)
         T = A(M,K)
         A(M,K) = A(K,K)
         A(K,K) = T
C
C        SKIP STEP IF PIVOT IS ZERO
C
         IF (T .EQ. 0.0) GO TO 35
C
C        COMPUTE MULTIPLIERS
C
         DO 20 I = KP1,N
             A(I,K) = -A(I,K)/T
   20    CONTINUE
C
C        INTERCHANGE AND ELIMINATE BY COLUMNS
C
         DO 30 J = KP1,N
             T = A(M,J)
             A(M,J) = A(K,J)
             A(K,J) = T
             IF (T .EQ. 0.0) GO TO 30
             DO 25 I = KP1,N
                A(I,J) = A(I,J) + A(I,K)*T
   25        CONTINUE
   30    CONTINUE
   35 CONTINUE
C
C     COND = (1-NORM OF A)*(AN ESTIMATE OF 1-NORM OF A-INVERSE)
C     ESTIMATE OBTAINED BY ONE STEP OF INVERSE ITERATION FOR THE
C     SMALL SINGULAR VECTOR.  THIS INVOLVES SOLVING TWO SYSTEMS
C     OF EQUATIONS, (A-TRANSPOSE)*Y = E  AND  A*Z = Y  WHERE  E
C     IS A VECTOR OF +1 OR -1 CHOSEN TO CAUSE GROWTH IN Y.
C     ESTIMATE = (1-NORM OF Z)/(1-NORM OF Y)
C
C     SOLVE (A-TRANSPOSE)*Y = E
C
      DO 50 K = 1, N
         T = 0.0
         IF (K .EQ. 1) GO TO 45
         KM1 = K-1
         DO 40 I = 1, KM1
            T = T + A(I,K)*WORK(I)
   40    CONTINUE
   45    EK = 1.0
         IF (T .LT. 0.0) EK = -1.0
         IF (A(K,K) .EQ. 0.0) GO TO 90
         WORK(K) = -(EK + T)/A(K,K)
   50 CONTINUE
      DO 60 KB = 1, NM1
         K = N - KB
         T = 0.0
         KP1 = K+1
         DO 55 I = KP1, N
            T = T + A(I,K)*WORK(K)
   55    CONTINUE
         WORK(K) = T
         M = IPVT(K)
         IF (M .EQ. K) GO TO 60
         T = WORK(M)
         WORK(M) = WORK(K)
         WORK(K) = T
   60 CONTINUE
C
      YNORM = 0.0
      DO 65 I = 1, N
         YNORM = YNORM + ABS(WORK(I))
   65 CONTINUE
C
C     SOLVE A*Z = Y
C
      CALL SOLVE(NDIM, N, A, WORK, IPVT)
C
      ZNORM = 0.0
      DO 70 I = 1, N
         ZNORM = ZNORM + ABS(WORK(I))
   70 CONTINUE
C
C     ESTIMATE CONDITION
C
      COND = ANORM*ZNORM/YNORM
      IF (COND .LT. 1.0) COND = 1.0
      RETURN
C
C     1-BY-1
C
   80 COND = 1.0
      IF (A(1,1) .NE. 0.0) RETURN
C
C     EXACT SINGULARITY
C
   90 COND = 1.0E+32
      RETURN
      END
      SUBROUTINE SOLVE(NDIM, N, A, B, IPVT)
C
      INTEGER NDIM, N, IPVT(N)
      REAL A(NDIM,N),B(N)
C
C   SOLUTION OF LINEAR SYSTEM, A*X = B .
C   DO NOT USE IF DECOMP HAS DETECTED SINGULARITY.
C
C   INPUT..
C
C     NDIM = DECLARED ROW DIMENSION OF ARRAY CONTAINING A .
C
C     N = ORDER OF MATRIX.
C
C     A = TRIANGULARIZED MATRIX OBTAINED FROM DECOMP .
C
C     B = RIGHT HAND SIDE VECTOR.
C
C     IPVT = PIVOT VECTOR OBTAINED FROM DECOMP .
C
C   OUTPUT..
C
C     B = SOLUTION VECTOR, X .
C
      INTEGER KB, KM1, NM1, KP1, I, K, M
      REAL T
C
C     FORWARD ELIMINATION
C
      IF (N .EQ. 1) GO TO 50
      NM1 = N-1
      DO 20 K = 1, NM1
         KP1 = K+1
         M = IPVT(K)
         T = B(M)
         B(M) = B(K)
         B(K) = T
         DO 10 I = KP1, N
             B(I) = B(I) + A(I,K)*T
   10    CONTINUE
   20 CONTINUE
C
C     BACK SUBSTITUTION
C
      DO 40 KB = 1,NM1
         KM1 = N-KB
         K = KM1+1
         B(K) = B(K)/A(K,K)
         T = -B(K)
         DO 30 I = 1, KM1
             B(I) = B(I) + A(I,K)*T
   30    CONTINUE
   40 CONTINUE
   50 B(1) = B(1)/A(1,1)
      RETURN
      END
METHOD OF LINES INTEGRATION OF BOUNDARY-VALUE ODES
0.        100.      1.0
   44 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT03
      SUBROUTINE INITAL
C...
C...  SOLUTION OF THE ONE-DIMENSIONAL HEAT CONDUCTION EQUATION
C...  WITH NEUMANN AND CAUCHY BOUNDARY CONDITIONS
C...
C...  OBTAIN A NUMERICAL SOLUTION TO THE FOLLOWING ONE-DIMENSIONAL
C...  PARABOLIC PDE:
C...
C...     RHO*CP*U  = K*U   + C                                 (2)
C...             T      XX
C...
C...  SUBJECT TO THE INITIAL CONDITION
C...
C...     U(X,0) = 1000 C                                       (2)
C...
C...  AND BOUNDARY CONDITIONS
C...
C...     U (0,T) = 0, K*U (L,T) = H*(UC - U(L,T))           (3)(4)
C...      X              X
C...
C...  FOR WHICH THE CONSTANTS HAVE THE VALUES
C...
C...  L = 0.1 CM, K = 0.1 CAL-CM/SEC-C-CM**2, RHO = 1 GM/CM**3,
C...
C...  CP = 1 CAL/GM-C, C = 1 CAL/SEC-CM**3, H = 0.1 CAL/SEC-C-CM**2,
C...
C..   UC = 250 C.
C...
C...  EQUATION (3) IS TERMED A NEUMANN BOUNDARY CONDITION SINCE IT
C...  INVOLVES ONLY THE SPATIAL DERIVATIVE UX(O,T), WHILE EQUATION
C...  (4) IS TERMED A CAUCHY BOUNDARY CONDITION SINCE IT INVOLVES
C...  THE DEPENDENT VARIABLE U(L,T) AND ITS SPATIAL DERIVATIVE
C...  UX(L,T) (ALSO CALLED A BOUNADRY CONDITION OF THE THIRD TYPE
C...  OR A MIXED BOUNDARY CONDITION).  THE OTHER POSSIBILITY IS A
C...  BOUNDARY CONDITION INVOLVING ONLY THE DEPENDENT VARIABLE, E.G.,
C...  U(O,T), WHICH IS TERMED A DIRICHLET BOUNDARY CONDITION.
C...
C...  USE A SPATIAL GRID WITH 11 AND 21 GRID POINTS, AND THE THREE
C...  AND FIVE-POINT APPROXIMATIONS OF DSS002 AND DSS004.  PREPARE
C...  A SUMMARY COMPARING THE SOLUTION U(0,T) FOR THESE FOUR RUNS.
C...
C...  THE ASSOCIATED STEADY STATE PROBLEM IS OBTAINED FROM EQUATION
C...  (1) WITH U  = 0.  OF COURSE, INITIAL CONDITION (1) IS NO LONGER
C...            T
C...  REQUIRED, BUT BOUNDARY CONDITIONS (3) AND (4) ARE RETAINED.  THE
C...  STEADY STATE PROBLEM IS THEREFORE
C...
C...     2    2
C...  K*D T/DX  + C = 0                                          (1S)
C...
C...  DT(0)/DX = 0, K*DT(L)/DX = H*(TC - T(L))               (2S)(3S)
C...
C...  L = 0.1 CM, K = 0.1 CAL-CM/SEC-C-CM**2, C = 1 CAL/SEC-CM**3
C...
C...  H = 0.1 CAL/SEC-C-CM**2, TC = 250K
C...
C...  THE ANALYTICAL SOLUTION TO EQUATIONS (1S) TO (3S) CAN EASILY BE
C...  DERIVED.  IF EQUATION (1S) IS INTEGRATED TWICE
C...
C...     DT/DX = -(C/K)*X + C1, T = -(C/K)*(X**2)/2 + C1*X + C2
C...
C...  FROM BOUNDARY CONDITION (2S), C1 = 0.  FROM BOUNDARY CONDITION
C...  (3S),
C...
C...     K*DT(L)/DX = -C*L = H*(TC - T(L)) = H*(TC + (C/K)*(L**2)/2 - C2)
C...
C...  WHICH CAN BE SOLVED FOR C2
C...
C...     C2 = (C/K)*(L**2)/2 + (C*L/H) + TC
C...
C...  THE FINAL SOLUTION IS
C...
C...     T(X) = (C/(2*K))*(L**2 - X**2) + (C*L/H) + TC
C...
C...  THE TEMPERATURE OF INTEREST, T(0), IS THEREFORE
C...
C...     T(0) = (C/(2*K))*(L**2) + (C*L/H) + TC
C...
C...  THIS STEADY STATE ANALYTICAL SOLUTION CAN THEN BE COMPARED WITH
C...  THE INFINITE TIME NUMERICAL SOLUTION TO EQUATIONS (1) TO (4),
C...  E.G., U(0,00).
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(21)
     2      /F/ UT(21)
     3      /S/ UX(21),UXX(21)
     4      /C/      L,      K,      C,      H,     UC,     N,     IP
      REAL           L,      K
C...
C...  COMMON AREA TO ACCESS THE INPUT/OUTPUT DEVICE NUMBERS
      COMMON/IO/    NI,     NO
C...
C...  SET THE MODEL PARAMETERS
      L=0.1
      K=0.1
      C=1.0
      H=0.1
      UC=250.
      IF((NORUN.EQ.1).OR.(NORUN.EQ.3))N=11
      IF((NORUN.EQ.2).OR.(NORUN.EQ.4))N=21
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      U(I)=1000.
1     CONTINUE
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
C...
C...  PRINT THE INITIAL TIME DERIVATIVES TO ESTIMATE THE TIME SCALE
C...  OF THE PROBLEM
      WRITE(NO,2)T,(UT(I),I=1,N)
2     FORMAT(1H ,//,33H INITIAL TIME DERIVATIVES AT T = ,F7.2,/,
     1 (5E12.3))
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(21)
     2      /F/ UT(21)
     3      /S/ UX(21),UXX(21)
     4      /C/      L,      K,      C,      H,     UC,     N,     IP
      REAL           L,      K
C...
C...  COMPUTE THE SPATIAL DERIVATIVE UX
      IF((NORUN.EQ.1).OR.(NORUN.EQ.2))CALL DSS002(0.,L,N,U,UX)
      IF((NORUN.EQ.3).OR.(NORUN.EQ.4))CALL DSS004(0.,L,N,U,UX)
C...
C...  APPLY THE BOUNDARY CONDITIONS AS CONSTRAINTS
      UX(1)=0.
      UX(N)=(H/K)*(UC-U(N))
C...
C...  COMPUTE THE SPATIAL DERIVATIVE UXX
      IF((NORUN.EQ.1).OR.(NORUN.EQ.2))CALL DSS002(0.,L,N,UX,UXX)
      IF((NORUN.EQ.3).OR.(NORUN.EQ.4))CALL DSS004(0.,L,N,UX,UXX)
C...
C...  ASSEMBLE THE PDE
      DO 1 I=1,N
      UT(I)=K*UXX(I)+C
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  U(21)
     2      /F/ UT(21)
     3      /S/ UX(21),UXX(21)
     4      /C/      L,      K,      C,      H,     UC,     N,     IP
      REAL           L,      K
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION XP(21), UP(6,21)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(1H ,//,9X,1HT,
     1 10H U(0.0L,T),10H U(0.2L,T),10H U(0.4L,T),
     2 10H U(0.6L,T),10H U(0.8L,T),10H U(1.0L,T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      IF((NORUN.EQ.1).OR.(NORUN.EQ.3))NS=2
      IF((NORUN.EQ.2).OR.(NORUN.EQ.4))NS=4
      WRITE(NO,2)T,(U(I),I=1,N,NS)
2     FORMAT(F10.2,6F10.1)
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
      IP=IP+1
      DO 3 I=1,N
      XP(I)=L/FLOAT(N-1)*FLOAT(I-1)
      UP(IP,I)=U(I)
3     CONTINUE
C...
C...  EVALUATE THE STEADY STATE ANALYTICAL SOLUTION AT THE END OF
C...  THE RUN
      IF(IP.LT.6)RETURN
      TA=(C/(2.*K))*(L**2)+(C*L/H)+UC
      WRITE(NO,5)TA
5     FORMAT(1H ,//,11H U(0,00) = ,F7.2)
C...
C...  PLOT THE NUMERICAL SOLUTION FOR THE 21 POINT RUNS
      IF((NORUN.EQ.1).OR.(NORUN.EQ.3))RETURN
      CALL TPLOTS(IP,N,XP,UP)
      WRITE(NO,4)
4     FORMAT(1H ,/,44H U(X,T) VS X, T = 0, 0.1, 0.2, 0.3, 0.4, 0.5)
      RETURN
      END
ONE-DIMENSIONAL HEAT CONDUCTION EQUATION, N = 11, DSS002
0.        5.0       1.0
   1110000    1    1  ABS 0.5
ONE-DIMENSIONAL HEAT CONDUCTION EQUATION, N = 21, DSS002
0.        5.0       1.0
   2110000    1    1  ABS 0.5
ONE-DIMENSIONAL HEAT CONDUCTION EQUATION, N = 11, DSS004
0.        5.0       1.0
   1110000    1    1  ABS 0.5
ONE-DIMENSIONAL HEAT CONDUCTION EQUATION, N = 21, DSS004
0.        5.0       1.0
   2110000    1    1  ABS 0.5
END OF RUNS
*APP HEAT04
      SUBROUTINE INITAL
C...
C...  SIZING OF A VAPOR-CONDENSING HEAT EXCHANGER
C...
C...  THE INTEGRAL TO BE EVALUATED NUMERICALLY IS
C...
C...                        T2
C...          L = M/(PI*D) INT CP/(H*(T - TS))DT
C...                        T1
C...
C...  WHERE
C...
C...     L    LENGTH OF THE EXCHANGER (FT)
C...
C...     M    FLUID MASS FLOW RATE (LB/HR)
C...
C...     PI   3.1415927
C...
C...     D    TUBE DIAMETER (FT)
C...
C...     CP   FLUID HEAT CAPACITY (BTU/LB-F)
C...
C...     H    HEAT TRANSFER COEFFICIENT (BTU/HR-FT**2-F)
C...
C...     TS   SATURATED VAPOR TEMPERATURE (F)
C...
C...     T    FLUID TEMPERATURE (F)
C...
C...     T1   ENTERING FLUID TEMPERATURE (F)
C...
C...     T2   EXITING FLUID TEMPERATURE (F)
C...
      COMMON/T/T,NFIN,NCASE/Y/L/F/DLDT/PARM/M,T1,T2,TS,D,PI,VIST(5)
      REAL M,L,K,KA,KB
C...
C...  SET THE DATA FOR SIX CASES
C...
C...     (1)  CASE A WITH T2 = 280 F
C...
C...     (2)  CASE A WITH T2 = 500 F
C...
C...     (3)  CASE B WITH T2 =  90 F
C...
C...     (4)  CASE B WITH T2 = 180 F
C...
C...     (5)  CASE A WITH PROPERTIES EVALUATED AT (60 + 280)/2
C...
C...     (6)  CASE B WITH PROPERTIES EVALUATED AT ( 0 +  90)/2
C...
      PI=4.*ATAN(1.)
      GO TO(1,2,3,4,1,3),NCASE
C...
C...  CASES 1, 5
1     M=22.5
      T1=60.
      T2=280.
      TS=550.
      D=0.495/12.
      GO TO 5
C...
C...  CASE 2
2     M=22.5
      T1=60.
      T2=500.
      TS=550.
      D=0.495/12.
      GO TO 5
C...
C...  CASES 3, 6
3     M=45000.
      T1=0.
      T2=90.
      TS=250.
      D=1.032/12.
      GO TO 5
C...
C...  CASE 4
4     M=45000.
      T1=0.
      T2=180.
      TS=250.
      D=1.032/12.
C...
C...  PRECOMPUTE THE LN OF THE VISCOSITY FOR CASE B
5     VIST(1)=ALOG(242.)
      VIST(2)=ALOG(82.1)
      VIST(3)=ALOG(30.5)
      VIST(4)=ALOG(12.6)
      VIST(5)=ALOG(5.57)
C...
C...  INITIAL CONDITION (HEAT EXCHANGER HAS ZERO LENGTH AT THE ENTRANCE)
      L=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T,NFIN,NCASE/Y/L/F/DLDT/PARM/M,T1,T2,TS,D,PI,VIST(5)
      REAL M,L,K,KA,KB
C...
C...  EVALUATE THE INTEGRAND FOR THE SIX CASES
      GO TO(1,1,1,1,2,2),NCASE
C...
C...  CASES 1, 2, 3, 4
1     DLDT=M/(PI*D)*CP(T)/(H(T)*(TS-T))
      GO TO 3
C...
C...  CASES 5, 6
2     TAVG=(T1+T2)/2.
      DLDT=M/(PI*D)*CP(TAVG)/(H(TAVG)*(TS-T))
3     RETURN
      END
      FUNCTION CP(T)
C...
C...  FUNCTION CP COMPUTES THE SPECIFIC HEAT AT THE FLUID TEMPERATURE
C...  T (F)
C...
      COMMON/T/X,NFIN,NCASE
C...
C...  EVALUATE THE SPECIFIC HEAT FOR THE SIX CASES
      GO TO(1,1,2,2,1,2),NCASE
C...
C...  CASES 1, 2, 5
1     CP=CPA(T)
      GO TO 3
C...
C...  CASES 3, 4, 6
2     CP=CPB(T)
3     RETURN
      END
      FUNCTION H(T)
C...
C...  FUNCTION H(T) EVALUATES THE HEAT TRANSFER COEFFICIENT AT THE FLUID
C...  TEMPERATURE T (F)
C...
      COMMON/T/X,NFIN,NCASE/Y/L/F/DLDT/PARM/M,T1,T2,TS,D,PI,VIST(5)
      REAL M,L,K,KA,KB
C...
C...  EVALUATE THE HEAT TRANSFER COEFFICIENT FOR THE SIX CASES
      GO TO(1,1,2,2,1,2),NCASE
C...
C...  CASES 1, 2, 5
1     K=KA(T)
      VIS=VISA(T)
      CP=CPA(T)
      GO TO 3
C...
C...  CASES 3, 4, 6
2     K=KB(T)
      VIS=VISB(T)
      CP=CPB(T)
C...
C...  EVALUATE THE HEAT TRANSFER COEFFICIENT VIA THE REYNOLDS AND
C...  PRANDTL NUMBER
3     RE=4.*M/(PI*D*VIS)
      PR=VIS*CP/K
      H=0.023*K/D*(RE**0.8)*(PR**0.4)
      RETURN
      END
      FUNCTION CPA(T)
C...
C...  FUNCTION CPA COMPUTES THE SPECIFIC HEAT FOR CASE A AT TEMPERATURE
C...  T (F)
C...
      CPA=0.251+3.46E-05*T-14400./(T+460.)**2
      RETURN
      END
      FUNCTION CPB(T)
C...
C...  FUNCTION CPB COMPUTES THE SPECIFIC HEAT FOR CASE B AT TEMPERATURE
C...  T (F)
C...
      CPB=0.53+0.00065*T
      RETURN
      END
      REAL FUNCTION KA(T)
C...
C...  FUNCTION KA COMPUTES THE THERMAL CONDUCTIVITY FOR CASE A AT
C...  TEMPERATURE T (F)
C...
C...  SET THE DATA FOR LINEAR INTERPOLATION
      DIMENSION TCT(4)
      DATA TCT/0.0085,0.0133,0.0181,0.0288/
C...
C...  COMPUTE THE THERMAL CONDUCTIVITY VIA THE LINEAR INTERPOLATION
C...  ROUTINE LINT1
      CALL LINT1(4,32.,572.,T,TCT,TCC,NERR)
      KA=TCC
      RETURN
      END
      REAL FUNCTION KB(T)
C...
C...  FUNCTION KB COMPUTES THE THERMAL CONDUCTIVITY FOR CASE B AT
C...  TEMPERATURE T (F)
C...
C...  COMPUTE THE THERMAL CONDUCTIVITY
      KB=0.153
      RETURN
      END
      FUNCTION VISA(T)
C...
C...  FUNCTION VISA COMPUTES THE VISCOSITY FOR CASE A AT TEMPERATURE
C...  T (F)
C...
C...  COMPUTE THE VISCOSITY
      VISA=0.0332*((T+460.)/460.)**0.935
      RETURN
      END
      FUNCTION VISB(T)
C...
C...  FUNCTION VISB COMPUTES THE VISCOSITY FOR CASE B AT TEMPERATURE
C...  T (F)
C...
      COMMON/T/X,NFIN,NCASE/Y/L/F/DLDT/PARM/M,T1,T2,TS,D,PI,VIST(5)
      REAL M,L,K,KA,KB
C...
C...  COMPUTE THE VISCOSITY VIA THE LINEAR INTERPOLATION ROUTINE LINT1
      CALL LINT1(5,0.,200.,T,VIST,VISC,NERR)
      VISB=EXP(VISC)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T,NFIN,NCASE/Y/L/F/DLDT/PARM/M,T1,T2,TS,D,PI,VIST(5)
      REAL M,L,K,KA,KB
C...
C...  PRINT THE VALUE OF THE INTEGRAL WHICH GIVES THE LENGTH OF THE
C...  EXCHANGER
      WRITE(NO,1)NCASE,T1,T2,L
1     FORMAT(38H THE LENGTH OF THE EXCHANGER FOR CASE ,I1,/,
     111H WITH T1 = ,F5.1,11HF AND T2 = ,F5.1,5HF IS ,E10.3,3H FT)
      RETURN
      END
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 1
60.       280.      220.
    1 4000    4    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 2
60.       500.      440.
    1 4000    4    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 3
0.        90.       90.
    1 4000    4    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 4
0.        180.      180.
    1 4000    4    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 5
60.       280.      220.
    1 4000    4    1  REL 0.001
CARNAHAN, ET AL, APPLIED NUMERICAL METHODS, PROB. 2.15, CASE 6
0.        90.       90.
    1 4000    4    1  REL 0.001
END OF RUNS
*APP HEAT05
      SUBROUTINE INITAL
C...
C...  LAMINAR-FLOW FLUID TEMPERATURE PROFILES IN A CYLINDRICAL TUBE
C...
C...  THE PARTIAL DIFFERENTIAL EQUATION
C...
C...          T   + (1/R)*T  = (1 - R**2)*T                          (1)
C...           RR          R               Z
C...
C...  IS TO BE INTEGRATED BY THE NUMERICAL METHOD OF LINES SUBJECT TO
C...  THE BOUNDARY CONDITIONS
C...
C...          T(R,0) = 0, T(1,Z) = 1, T (0,Z) = 0              (2)(3)(4)
C...                                   R
C...  WHERE
C...
C...          T    TEMPERATURE NORMALIZED WITH RESPECT TO THE WALL
C...               TEMPERATURE
C...
C...          R    RADIAL COORDINATE NORMALIZED WITH RESPECT TO THE
C...               TUBE RADIUS
C...
C...          Z    AXIAL COORDINATE
C...
C...  NOTE THAT R IS A BOUNDARY-VALUE INDEPENDENT VARIABLE WHILE Z IS
C...  AN INITIAL VALUE INDEPENDENT VARIABLE.
C...
      COMMON/T/Z/Y/T(11)/F/DTDZ(11)
      COMMON/PARM/N,DR,DRS
C...
C...  SET NUMBER OF RADIAL INCREMENTS, SPATIAL INTEGRATION INTERVAL
      N=11
      DR=1./FLOAT(N-1)
      DRS=DR*DR
C...
C...  INITIAL CONDITION (2)
      DO 1 I=1,N
1     T(I)=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/Z/Y/T(11)/F/DTDZ(11)
      COMMON/PARM/N,DR,DRS
C...
C...  STEP THROUGH N SPATIAL GRID POINTS
      DO 1 I=1,N
      IF(I.GT.1)GO TO 2
C...
C...  CENTERLINE (R = 0) INCLUDING BOUNDARY CONDITION (4)
      DTDZ(1)=4./DRS*(T(2)-T(1))
      GO TO 1
2     IF(I.LT.N)GO TO 3
C...
C...  OUTER BOUNDARY (R = 1) INCLUDING BOUNDARY CONDITION (3)
      T(N)=1.
      DTDZ(N)=0.
      GO TO 1
C...
C...  INTERMEDIATE RADIAL POINTS (R = DR, 2*DR,..., (N-1)*DR)
3     R=DR*FLOAT(I-1)
      DTDZ(I)=1./(1.-R**2)*((T(I+1)-2.*T(I)+T(I-1))/DRS
     1       +1./R*(T(I+1)-T(I-1))/(2.*DR))
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/Z/Y/T(11)/F/DTDZ(11)
      COMMON/PARM/N,DR,DRS
C...
C...  PRINT NUMERICAL SOLUTION
      WRITE(NO,1)Z
1     FORMAT(/,2X,4HZ = ,E9.2,/,
     1 11H     R=0   ,11H    R=0.2  ,11H    R=0.4  ,
     2 11H    R=0.6  ,11H    R=0.8  ,11H    R=1.0  )
      WRITE(NO,2)(T(I),I=1,N,2)
2     FORMAT(6E11.3)
      RETURN
      END
CARNAHAN, B., ET AL, APPLIED NUMERICAL METHODS, PROB. 7.22, PP. 521-522
0.        0.2       0.05
   11  100    1    1  ABS 0.001
END OF RUNS
*APP HEAT06
      SUBROUTINE INITAL
C...
C...  INTEGRATION OF THE SOLAR-RADIATION SPECTRUM
C...
C...  THE INTEGRAL I DEFINED AS
C...
C...              7.0E-07
C...          I =   INT   R(L)DL                                     (1)
C...              3.5E-07
C...
C...  IS EVALUATED NUMERICALLY FOR THE INTEGRAND R(L) DEFINING THE
C...  SOLAR-RADIATION SPECTRUM
C...
C...                      3.74E-16
C...          R(L) = ..................
C...                  5  2.52E-6/L
C...                 L (E          - 1)
C...
C...  WHERE
C...
C...     L    SOLAR-RADIATION WAVELENGTH (METERS)
C...
C...    R(L)  SOLAR-RADIATION POWER SPECTRUM (WATTS/METER)
C...
C...  THE INTEGRATION IS TO BE PERFORMED TO A MINIMUM ACCURACY OF THREE
C...  SIGNIFICANT FUGURES.  A COMPLETE STATEMENT OF THE PROBLEM IS GIVEN
C...  IN THE REFERENCE CITED ON THE FIRST DATA CARD.
C...
      COMMON/T/     L,  NFIN, NORUN
     1      /Y/     I
     2      /F/  DIDL
      REAL          L,     I
C...
C...  SET THE INITIAL CONDITION
      I=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     L,  NFIN, NORUN
     1      /Y/     I
     2      /F/  DIDL
      REAL          L,     I
C...
C...  EVALUATE THE INTEGRAND
      DIDL=R(L)
      RETURN
      END
      FUNCTION R(L)
C...
C...  THE SOLAR-RADIATION SPECTRUM (WATTS/METER) IS COMPUTED BY FUNCTION
C...  R(L)
C...
C...  ARGUMENT LIST
C...
C...     L    WAVELENGTH OF THE SOLAR RADIATION (METERS)
C...
      REAL          L
      R=3.74E-16/(L**5*(EXP(2.52E-6/L)-1.))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     L,  NFIN, NORUN
     1      /Y/     I
     2      /F/  DIDL
      REAL          L,     I
C...
C...  PRINT THE FINAL VALUE OF THE INTEGRAL
      IF(L.LT.6.0E-07)RETURN
      WRITE(NO,1)I
1     FORMAT(59H SOLAR POWER RADIATED IN THE RANGE OF VISIBLE WAVELENGTH
     1 = ,E11.4,6H WATTS)
      RETURN
      END
EISBERG, R. M., APPLIED MATHEMATICAL PHYSICS, PP. 27-33, ALGORITHM 1
   3.5E-07   7.0E-07   3.5E-07
    1 1000    1    1  REL 0.0005
EISBERG, R. M., APPLIED MATHEMATICAL PHYSICS, PP. 27-33, ALGORITHM 8
   3.5E-07   7.0E-07   3.5E-07
    1 1000    8    1  REL 0.0005
END OF RUNS
*APP HEAT07
      SUBROUTINE INITAL
C...
C...  ONE-DIMENSIONAL HEAT CONDUCTION WITH PLOTTED TEMPERATURE PROFILES
C...
C...  THE PROBLEM SYSTEM IS
C...
C...                      PU/PT = P2U/PX2                          (1)
C...
C...      PU(0,T)/PX = 0, PU(1,T)/PX = E*(TA**4 - T(1,T)**4)      (2)(3)
C...
C...                        U(X,0) = T0                            (4)
C...
C...  WHICH IS IDENTICAL TO THE PROBLEM IN THE DSS/2 MANUAL AN INTRO-
C...  DUCTION TO THE NUMERICAL METHOD OF LINES INTEGRATION OF PARTIAL
C...  DIFFERENTIAL EQUATIONS, SECTION 2.  HOWEVER, THE PROGRAMMING IN
C...  SUBROUTINE PRINT ALSO INCLUDES A CALL TO SUBROUTINE PLOTS TO PLOT
C...  THE COMPUTED TEMPERATURE PROFILES.
C...
      COMMON/T/T/Y/U(11)/F/UT(11)/PARM/E,TA,N/SD/UX(11),UXX(11)
C...
C...  SET THE PROBLEM SYSTEM PARAMETERS
      E=1.73E-09
      TA=500.
      T0=600.
      N=11
C...
C...  INITIAL CONDITION (4)
C...  U(X,0) = T0
      DO 1 I=1,N
1     U(I)=T0
C...
C...  INITIALIZE THE DERIVATIVES UX(X,T) AND UXX(X,T) FOR PLOTTING
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/T/Y/U(11)/F/UT(11)/PARM/E,TA,N/SD/UX(11),UXX(11)
C...
C...  COMPUTE THE FIRST-ORDER SPATIAL DERIVATIVE
      CALL DSS004(0.,1.,N,U,UX)
C...
C...  APPLY BOUNDARY CONDITIONS (2) AND (3) AS CONSTRAINTS
      UX(1)=0.
      UX(N)=E*(TA**4-U(N)**4)
C...
C...  COMPUTE THE SECOND-ORDER SPATIAL DERIVATIVE
      CALL DSS004(0.,1.,N,UX,UXX)
C...
C...  ASSEMBLE PDE (1)
      DO 1 I=1,N
      UT(I)=UXX(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/T/Y/U(11)/F/UT(11)/PARM/E,TA,N/SD/UX(11),UXX(11)
C...
C...  DIMENSION THE ARRAYS AND SET THE VALUES OF X, COUNTER FOR
C...  PLOTTING
      DIMENSION XPLOT(11),UPLOT(10,11),UXPLOT(10,11),UXXPLO(10,11)
      DATA XPLOT/0.,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0/,IP/0/
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T
1     FORMAT(/,2X,7HTIME = ,E9.2,/,1X,
     1 11H     X=0   ,11H    X=0.2  ,11H    X=0.4  ,
     2 11H    X=0.6  ,11H    X=0.8  ,11H    X=1.0  )
      WRITE(NO,2)(U(I),I=1,N,2)
2     FORMAT(6E11.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
C...
C...  FOR T = 0, THE NUMERICAL SOLUTION IS STORED AS THE TENTH VARIABLE
C...  WHICH IS PLOTTED BY SUBROUTINE PLOTS WITH ZEROS.  THUS THIS STEP
C...  MERELY IMPROVES THE APPEARANCE OF THE PLOT, I.E., T = 0 IS PLOTTED
C...  WITH 0 (ZERO), T = 0.25 IS PLOTTED WITH 1, T = 0.50 IS PLOTTED
C...  2, ETC. TO T = 2.25 IS PLOTTED WITH 9
      IF(T.GT.0.125)GO TO 4
C...
C...  NOTE THAT THE SPATIAL DERIVATIVES UX(X,T) AND UXX(X,T) ARE STORED
C...  FOR PLOTTING AS WELL AS THE NUMERICAL SOLUTION U(X,T).  THE PLOTS
C...  OF THESE DERIVATIVES HAVE SOME INTERESTING INTERPRETATIONS.  FOR
C...  EXAMPLE, THE PLOT OF UX(X,T) CAN BE STUDIED TO DETERMINE IF
C...  BOUNDARY CONDITION (2) IS SATISFIED, AND HOW BOUNDARY CONDITION
C...  (3) AFFECTS THE SOLUTION.
      DO 3 I=1,N
       UPLOT(10,I)=  U(I)
      UXPLOT(10,I)= UX(I)
      UXXPLO(10,I)=UXX(I)
3     CONTINUE
      GO TO 6
4     IP=IP+1
      DO 5 I=1,N
       UPLOT(IP,I)=  U(I)
      UXPLOT(IP,I)= UX(I)
      UXXPLO(IP,I)=UXX(I)
5     CONTINUE
C...
C...  PLOT THE NUMERICAL SOLUTION
6     IF(T.LT.2.125)RETURN
      CALL PLOTS(10,IP,XPLOT,UPLOT)
      WRITE(NO,8)
8     FORMAT(15X,29H TIME FOR EACH U(X,T) PROFILE,/,
     1   14X,10H  1 - 0.00,10H  1 - 0.25,10H  2 - 0.50,10H  3 - 0.75,/,
     2   14X,10H  4 - 1.00,10H  5 - 1.25,10H  6 - 1.50,10H  7 - 1.75,/,
     3   14X,10H  8 - 2.00,10H  9 - 2.25)
      CALL PLOTS(10,IP,XPLOT,UXPLOT)
      WRITE(NO,9)
9     FORMAT(15X,30H TIME FOR EACH UX(X,T) PROFILE,/,
     1   14X,10H  1 - 0.00,10H  1 - 0.25,10H  2 - 0.50,10H  3 - 0.75,/,
     2   14X,10H  4 - 1.00,10H  5 - 1.25,10H  6 - 1.50,10H  7 - 1.75,/,
     3   14X,10H  8 - 2.00,10H  9 - 2.25)
      CALL PLOTS(10,IP,XPLOT,UXXPLO)
      WRITE(NO,10)
10    FORMAT(15X,31H TIME FOR EACH UXX(X,T) PROFILE,/,
     1   14X,10H  1 - 0.00,10H  1 - 0.25,10H  2 - 0.50,10H  3 - 0.75,/,
     2   14X,10H  4 - 1.00,10H  5 - 1.25,10H  6 - 1.50,10H  7 - 1.75,/,
     3   14X,10H  8 - 2.00,10H  9 - 2.25)
      IP=0
      RETURN
      END
ONE-DIMENSIONAL HEAT CONDUCTION WITH PLOTTED TEMPERATURE PROFILES
0.        2.25      0.25
   11  100    1    1  REL 0.001
END OF RUNS
*APP HEAT08
      SUBROUTINE INITAL
C...
C...  APPROXIMATION OF THE ADVECTION EQUATION BY CENTRAL AND NONCENTRAL
C...  (UPWIND) FINITE DIFFERENCES
C...
C...  PURE CONVECTION THROUGH A TUBE WITH A UNIFORM VELOCITY PROFILE CAN
C...  BE DEPICTED AS
C...
C...
C...          .............................................
C...                         V......+.  .
C...                         V......+.  .
C...                         V......+.DX. C(X,T)
C...                         V......+.  .
C...                         V......+.  .
C...          .............................................
C...         X=0                                         X=XL
C...
C...  IF A MASS OR ENERGY BALANCE IS WRITTEN FOR A DIFFERENTIAL SECTION
C...  OF THE TUBE, THE WELL-KNOWN ADVECTION EQUATION RESULTS
C...
C...     C  + V*C  = 0                                               (1)
C...      T      X
C...
C...  SINCE EQUATION (1) IS FIRST-ORDER IN THE SPATIAL VARIABLE, X, AND
C...  THE TEMPORAL VARIABLE, T, IT REQUIRES ONE BOUNDARY CONDITION AND
C...  ONE INITIAL CONDITION
C...
C...     C(0,T) = F(T), C(X,0) = G(X)                             (2)(3)
C...
C...  IN THE FOLLOWING ANALYSIS, WE CONSIDER THE SPECIAL CASE
C...
C...     F(T) = 1, G(X) = 0                                       (4)(5)
C...
C...  FOR WHICH THE EXACT SOLUTION TO EQUATIONS (1) TO (3) IS
C...
C...     C(X,T) = 0, X GT V*T
C...                                                                 (6)
C...     C(X,T) = 1, X LT V*T
C...
C...  EQUATIONS (6) REPRESENT A TRAVELLING STEP FUNCTION WHICH INDICATES
C...  THE FUNDAMENTAL DIFFICULTY IN OBTAINING A NUMERICAL SOLUTION TO
C...  EQUATIONS (1) TO (3), I.E., AT X = V*T, THE SLOPE OF THE SOLUTION
C...  IS INFINITE.  THUS ABOUT THE BEST WE CAN EXPECT IS A NUMERICAL
C...  APPROXIMATION TO EQUATION (6) OF ACCEPTABLE ACCURACY.
C...
C...  THE SPATIAL DERIVATIVE IN EQUATION (1), C  IS REPLACED BY A FINITE
C...                                           X
C...  DIFFERENCE APPROXIMATION OVER A GRID OF N (= 21) POINTS IN X.  A
C...  SYSTEM OF N INITIAL-VALUE ORDINARY DIFFERENTIAL EQUATIONS IN T
C...  RESULTS, ONE DIFFERENTIAL EQUATION FOR EACH GRID POINT.  THIS
C...  SYSTEM OF ODES IS THEN INTEGRATED SIMULTANEOUSLY TO OBTAIN THE
C...  NUMERICAL SOLUTION TO EQUATIONS (1) TO (3).  TWO APPRROXIMATIONS
C...  TO THE SPATIAL DERIVATIVE IN EQUATION (1) ARE USED
C...
C...     (1)  TWO-POINT UPWIND DIFFERENCE
C...
C...          THIS APPROXIMATION IS EQUIVALENT TO ASSUMING THAT EACH
C...          SECTION OF THE TUBE ALONG THE GRID IN X IS PERFECTLY
C...          MIXED, I.E., THIS IS THE WELL-KNOWN METHOD OF USING A
C...          SERIES OF STIRRED TANK APPROXIMATIONS.
C...
C...     (2)  THREE-POINT CENTRAL DIFFERENCE
C...
C...          THE FINITE DIFFERENCE APPROXIMATIONS USED AT THE GRID
C...          POINTS IN X ARE IMPLEMENTED IN SUBROUTINE DSS002.
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(21)
     2      /F/ CT(21)
     3     /SD/ CX(21)
     4      /C/      V,     XL,      N,     DX,    SSE,     IP
C...
C...  SET THE VELOCITY, LENGTH OF THE SYSTEM, NUMBER OF SPATIAL GRID
C...  POINTS, LENGTH OF THE GRID INTERVAL, SUM OF SQUARES OF ERRORS OF
C...  THE NUMERICAL SOLUTION, COUNTER FOR THE PLOTTED SOLUTION USED IN
C...  SUBROUTINE PRINT
      V=1.
      XL=1.
      N=21
      DX=XL/FLOAT(N-1)
      SSE=0.
      IP=0
C...
C...  INITIAL CONDITION (5)
      DO 1 I=1,N
      C(I)=0.
1     CONTINUE
C...
C...  INITIALIZE THE TEMPORAL DERIVATIVES IN COMMON/F/
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(21)
     2      /F/ CT(21)
     3     /SD/ CX(21)
     4      /C/      V,     XL,      N,     DX,    SSE,     IP
      GO TO (1,2),NORUN
C...
C...  CASE 1 - TWO-POINT UPWIND DIFFERENCES
1     C(1)=1.
      CT(1)=0.
      DO 11 I=2,N
      CT(I)=-V*(C(I)-C(I-1))/DX
11    CONTINUE
      RETURN
C...
C...  CASE 2 - THREE-POINT CENTRAL DIFFERENCES
2     C(1)=1.
      CT(1)=0.
      CALL DSS002(0.,XL,N,C,CX)
      DO 12 I=2,N
      CT(I)=-V*CX(I)
12    CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  C(21)
     2      /F/ CT(21)
     3     /SD/ CX(21)
     4      /C/      V,     XL,      N,     DX,    SSE,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING THE SOLUTION
      DIMENSION TP(51),CP(2,51),EP(2,51)
C...
C...  PRINT A HEADING FOR NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,6X,6HC(0,T),6X,6HC(1,T))
      WRITE(NO,2)T,C(1),C(N)
2     FORMAT(F10.2,2F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      CP(NORUN,IP)=C(N)
C...
C...  COMPUTE THE ERROR IN THE NUMERICAL SOLUTION FOR PLOTTING
      X=1.
      IF(X.GE.V*T)E=C(N)
      IF(X.LT.V*T)E=C(N)-1.
      SSE=SSE+E**2
      EP(NORUN,IP)=E
C...
C...  TEST FOR THE END OF A RUN
      IF(IP.LT.51)RETURN
C...
C...  PRINT THE SUM OF SQUARES OF ERRORS OF THE NUMERICAL SOLUTION AT
C...  THE END OF THE RUN TO GIVE AN OVERALL FIGURE OF MERIT FOR THE
C...  APPROXIMATION OF THE SPATIAL DERIVATIVE IN EQUATION (1)
      WRITE(NO,5)SSE
5     FORMAT(1H ,//,48H SUM OF SQUARES OF ERROR IN NUMERICAL SOLUTION =,
     1 E10.3)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(NORUN.LT.2)RETURN
      CALL PLOTS(2,IP,TP,CP)
      WRITE(NO,3)
3     FORMAT(1H ,//,48H C(1,T) VS T, 1 - 2 PT UPWIND, 2 - 3 PT CENTRAL )
      CALL PLOTS(2,IP,TP,EP)
      WRITE(NO,4)
4     FORMAT(1H ,//,48H E(1,T) VS T, 1 - 2 PT UPWIND, 2 - 3 PT CENTRAL )
      RETURN
      END
METHOD OF LINES SOLUTION OF THE ADVECTION EQUATION, TWO-POINT UPWIND
0.        2.0       0.04
   21 1000    8    1  REL 0.001
METHOD OF LINES SOLUTION OF THE ADVECTION EQUATION, THREE-POINT CENTRAL
0.        2.0       0.04
   21 1000    8    1  REL 0.001
END OF RUNS
*APP HEAT09
      SUBROUTINE INITAL
C...
C...  SIMPLIFIED TRANSIENT ANALYSIS OF A LOCA FOR THREE MILE ISLAND
C...  REACTOR NO. 2
C...
C...  CONSIDER THE EFFECT OF A FAILURE IN PUMPING CAPACITY FOR THE
C...  SECONDARY LOOP OF TMI REACTOR NO. 2 (A DIAGRAM FOR THE REACTOR
C...  COOLING SYSTEM APPEARED IN TIME, APRIL 9, 1979, PP 10, 15, AND THE
C...  NEW YORK TIMES WITH DETAILS OF THE LOCA, APRIL 16, 1979, P B10).
C...  SPECIFICALLY, THE PRESSURE OF THE LOOP IS MAINTAINED SO THAT THE
C...  SATURATED WATER AND STEAM TEMPERATURES, T2, IN THE CONTAINMENT
C...  BUILDING REMAIN AT 450 F.  HOWEVER, DUE TO REDUCED PUMPING CAPA-
C...  CITY, THE WATER LEVEL IN THE SECONDARY LOOP DROPS AND THEREFORE
C...  THE PIPES IN THE PRIMARY LOOP HAVE GREATER EXPOSURE TO STEAM, WITH
C...  A RESULTANT DROP IN HEAT TRANSFER FROM THE PRIMARY LOOP TO THE
C...  SECONDARY LOOP.  YOU ARE ASKED TO COMPUTE THE TRANSIENT REDUCTION
C...  IN THE TOTAL HEAT TRANSFER RATE AS A RESULT OF THE REDUCED PUMPING
C...  CAPACITY IN THE SECONDARY LOOP.  SPECIFICALLY, THE MATHEMATICAL
C...  STATEMENT OF THE PROBLEM IS
C...
C...     T1  + V*T1  + (PI*D*H)/(RHO*CP*A)*(T1 - T2) = 0             (1)
C...       T       X
C...
C...     T1(0,T) = 600 F, T1(X,0) = 600 F                         (2)(3)
C...
C...  WHERE
C...
C...     T1        TEMPERATURE IN THE PRIMARY LOOP (F)
C...
C...     T2        TEMPERATURE IN THE SECONDARY LOOP (F)
C...
C...     X         POSITION ALONG THE PRIMARY LOOP IN THE CONTAINMENT
C...               BUILDING (FT)
C...
C...     T         TIME (SEC)
C...
C...     D         DIAMETER OF THE PRIMARY LOOP PIPE = 1 FT
C...
C...     RHO       DENSITY OF THE PRIMARY LOOP WATER = 62.5 LBM/FT**3
C...
C...     CP        HEAT CAPACITY OF THE PRIMARY LOOP WATER = 1 BTU/LBM-F
C...
C...     A         CROSS SECTIONAL AREA OF THE PRIMARY LOOP PIPE (AVAIL-
C...               ABLE FROM D) (FT**2)
C...
C...     V         LINEAR VELOCITY THROUGH THE PRIMARY LOOP = 2 FT/SEC
C...
C...  TWO CASES ARE TO BE ANALYZED
C...
C...     (1)  NORMAL OPERATING CONDITIONS
C...
C...            0 LE X LE  50 FT, H = HW = 500 BTU/(HR-FT**2-F)
C...
C...           50 LT X LT 100 FT, H = HS =  20 BTU/(HR-FT**2-F)
C...
C...          100 LE X LE 200 FT, H = HW = 500 BTU/(HR-FT**2-F)
C...
C...     (2)  REDUCED PUMPING CAPACITY IN THE SECONDARY LOOP WITH
C...          GREATER EXPOSURE OF THE PRIMARY LOOP PIPE TO STEAM
C...
C...            0 LE X LT 100 FT, H = HS =  20 BTU/(HR-FT**2-F)
C...
C...          100 LE X LE 200 FT, H = HW = 500 BTU/(HR-FT**2-F)
C...
C...     (NOTE THAT THE SUBSCRIPTS W AND S FOR THE HEAT TRANSFER CO-
C...     EFFICIENT H REFER TO WATER AND STEAM, RESPECTIVELY).
C...
C...  THE TOTAL LENGTH OF THE PRIMARY LOOP PIPE IN THE CONTAINMENT
C...  BUILDING IS 200 FT.  APPROXIMATE THE SPATIAL DERIVATIVE, T1 , IN
C...                                                             X
C...  EQUATION (1) WITH 20 SECTIONS OF 10 FT EACH.  NOTE THAT IN ORDER
C...  TO CALCULATE THE TOTAL HEAT TRANSFER RATE FROM THE PRIMARY LOOP TO
C...  THE SECONDARY LOOP, YOU MUST SUM (OR INTEGRATE) THE HEAT TRANSFER
C...  RATE ALONG THE PRIMARY LOOP PIPE AT 21 GRID POINTS.  ALSO, YOU
C...  MUST SELECT A TOTAL RUN TIME FOR THE SIMULATION SO THAT THE SYSTEM
C...  ESSENTIALLY COMES TO STEADY STATE.  ULTIMATELY, YOU SHOULD PRODUCE
C...  A PLOT OF TOTAL HEAT TRANSFER RATE VS TIME FOR CASES (1) AND (2)
C...  ABOVE SO THAT IT IS CLEAR HOW MUCH OF A REDUCTION IN HEAT REMOVAL
C...  OCCURS AS A RESULT OF THE PARTIAL PUMP FAILURE IN THE SECONDARY
C...  LOOP (AND THEREFORE HOW MUCH EXCESS HEAT THE REACTOR MIGHT GENER-
C...  ATE LEADING TO A POSSIBLE MELT-DOWN).
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/ T1(21)
     2      /F/T1T(21)
     3     /SD/T1X(21)
     4      /C/HTR(21),  H(21),     XL,     T2,      V,      N,     IP,
     5              C1,     C2
C...
C...  SET THE MODEL PARAMETERS
      XL=200.
      D=1.
      RHO=62.5
      CP=1.
      V=2.
      HW=500.
      HS=20.
      T2=450.
      PI=3.1415927
      A=PI*D**2/4.
      N=21
      IP=0
C...
C...  SET THE LOCAL HEAT TRANSFER COEFFICIENT
      DO 3 I=1,N
      GO TO(1,2),NORUN
1        IF(I.LE.N)H(I)=HW
         IF(I.LE.10)H(I)=HS
         IF(I.LE.6)H(I)=HW
      GO TO 3
2        IF(I.LE.N)H(I)=HW
         IF(I.LE.10)H(I)=HS
3     H(I)=H(I)/3600.
C...
C...  COMPUTE GROUPS OF CONSTANTS USED IN SUBSEQUENT CALCULATIONS
      C1=(PI*D)/(RHO*CP*A)
      C2=PI*D
C...
C...  INITIAL CONDITION (3)
      DO 4 I=1,N
4     T1(I)=600.
C...
C...  INITIALIZE THE TEMPORAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/ T1(21)
     2      /F/T1T(21)
     3     /SD/T1X(21)
     4      /C/HTR(21),  H(21),     XL,     T2,      V,      N,     IP,
     5              C1,     C2
C...
C...  APPLY BOUNDARY CONDITION (2) AS A CONSTRAINT
      T1(1)=600.
      T1T(1)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE IN EQUATION (1) BY FIVE-POINT
C...  BIASED UPWIND DIFFERENCES
      CALL DSS020(0.,XL,N,T1,T1X,V)
C...
C...  ASSEMBLE EQUATION (1)
      DO 1 I=2,N
1     T1T(I)=-V*T1X(I)+C1*H(I)*(T2-T1(I))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/ T1(21)
     2      /F/T1T(21)
     3     /SD/T1X(21)
     4      /C/HTR(21),  H(21),     XL,     T2,      V,      N,     IP,
     5              C1,     C2
C...
C...  DIMENSION THE ARRAYS FOR STORING THE PLOTTED SOLUTION
      DIMENSION TP(51),HTRP(2,51)
C...
C...  COMPUTE THE LOCAL HEAT TRANSFER RATE
      NM1=N-1
      DX=XL/FLOAT(NM1)
      DO 1 I=1,NM1
C...
C...  NOTE THAT THIS SUMMATION IS EQUIVALENT TO INTEGRATION BY THE
C...  TRAPEZOIDAL RULE
1     HTR(I)=C2*DX*(H(I)*(T1(I)-T2) + H(I+1)*(T1(I+1)-T2))/2.
C...
C...  PRINT THE TEMPERATURE PROFILE AND LOCAL HEAT TRANSFER RATE PROFILE
C...  IN THE PRIMARY LOOP AT EVERY FIFTH SOLUTION POINT
      IF((IP.NE.0).AND.(IP/5*5.NE.IP))GO TO 4
      WRITE(NO,3)T,(T1(I),I=1,N),(HTR(I),I=1,NM1)
3     FORMAT(1H ,//,8H TIME = ,F6.1,/,3(7E12.3,/),/,3(7E12.3,/))
C...
C...  SUM THE LOCAL HEAT TRANSFER RATES
4     SUM=0.
      DO 2 I=1,NM1
2     SUM=SUM+HTR(I)
C...
C...  STORE THE TOTAL HEAT TRANSFER RATE FOR PLOTTING
      IP=IP+1
      HTRP(NORUN,IP)=SUM
      TP(IP)=T
C...
C...  PLOT THE TOTAL HEAT TRANSFER RATE VS TIME FOR THE TWO CASES
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.2)RETURN
      CALL PLOTS(NORUN,IP,TP,HTRP)
      WRITE(NO,5)
5     FORMAT(1H ,//,48H TOTAL HEAT TRANSFER RATE (BTU/SEC) VS T (SEC)  ,
     1           //,48H 1 - NORMAL OPERATION   2 - LOSS OF COOLANT     )
      RETURN
      END
TRANSIENT ANALYSIS FOR A LOSS OF COOLANT ACCIDENT, NORMAL CODITIONS
0.        100.      2.
   21 1000    1    1  REL 0.001
TRANSIENT ANALYSIS FOR A LOSS OF COOLANT ACCIDENT, REDUCED COOLANT FLOW
0.        100.      2.
   21 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT10
      SUBROUTINE INITAL
C..
C...  AIR TEMPERATURE WITHIN A LARGE CITY
C..
C...  THE TEMPERATURE OF THE OUTSIDE AIR IN A LARGE CITY IS COMPUTED
C...  AS A FUNCTION OF TIME AND POSITION (ONE SPACE VARIABLE) BY SOLVING
C...  A PARTIAL DIFFERENTIAL EQUATION (PDE).  THE EQUATIONS WHICH MODEL
C...  THE CITY*S TEMPERATURE ALLOW FOR VARIATIONS IN THE AMOUNT OF SOLAR
C...  RADIATION, THE WIND VELOCITY, THE SIZE OF THE BUILDINGS AND THE
C...  THERMAL CONDUCTIVITY OF THE WALLS.
C...
C...  IT IS ASSUMED THAT UNDER CERTAIN ATMOSPHERIC CONDITIONS, THE ANA-
C...  LYSIS OF THE HEAT TRANSFER PROCESSES WITHIN A LARGE CITY CAN BE
C...  CONFINED TO A LARGE BOX WHOSE VOLUME IS L X W X H WHERE
C..
C...               L = LENGTH (PARALLEL TO THE X-AXIS)
C..
C...               W = WIDTH (PARALLEL TO THE Z-AXIS)
C..
C...               H = HEIGHT (PARALLEL TO THE Y-AXIS)
C..
C...  IT IS ASSUMED THAT THE RADIANT ENERGY MUST ENTER THROUGH THE TOP
C...  OF THE BOX, AND THAT IT CAN ONLY BE REMOVED BY BREEZES PASSING
C...  OVER AND THROUGH THE CITY.  THE BUILDINGS IN THE CITY ARE LUMPED
C...  TOGETHER TO FORM ONE LARGE BUILDING WHOSE DIMENSIONS ARE L X WB X
C...  HB.  THIS SMALLER BOX IS LOCATED WITHING THE LARGER BOX AND CEN-
C...  TERED SO THAT BOTH SIDES OF LENGTH L ARE PARALLEL.  THE FOLLOWING
C...  APPLIES TO THE SMALLER BOX
C..
C...               L = LENGTH (PARALLEL TO THE X-AXIS)
C..
C...              WB = WIDTH (PARALLEL TO THE Z-AXIS)
C..
C...              HB = HEIGHT (PARALLEL TO THE Y-AXIS)
C..
C...  A DETAILED DESCRIPTION OF THIS PROBLEM AND ITS SOLUTION IS FOUND
C...  IN THE FOLLOWING REFERENCES
C..
C...     (1)  LEE, YEE AND JAMES N. ZAISER, A CITY AIR CONDITIONING
C...          PROBLEM, PROCEEDINGS OF THE SEVENTH ANNUAL PITTSBURGH
C...          CONFERENCE ON MODELING AND SIMULATION, UNIVERSITY OF
C...          PITTSBURGH, PITTSBURGH, PA., APRIL, 1976, PP. 848-853
C...
C...     (2)  LEE, YEE, A SIMPLE MODEL FOR A CITY AIR CONDITIONING
C...          PROBLEM, MASTER*S DEGREE THESIS, BUCKNELL UNIVERSITY,
C...          LEWISBURG, PA., APRIL, 1976.
C...
C...  ADDITIONAL ASSUMPTIONS WHICH ARE MADE INCLUDE
C...
C...     (1)  THERE IS NO HEAT GENERATION IN THE AIR.
C...
C...     (2)  THE RADIANT ENERGY WHICH ENTERS INTO THE CITY FALLS ONLY
C...          ON THE BUILDINGS AND IS COMPLETELY ABSORBED BY THE BUILD-
C...          INGS.
C...
C...     (3)  THERE IS NO VERTICAL TEMPERATURE GRADIENT IN THE CITY
C...          ATMOSPHERE.  THIS MEANS NATURAL CONVECTION IS NEGLECTED.
C...
C...     (4)  THERE IS NO EVAPORATION IN THE CITY ATMOSPHERE.
C...
C...     (5)  THE ROOM TEMPERATURE IS EQUAL TO THE AIR TEMPERATURE.
C..
C...  THE NON-DIMENSIONAL EQUATION WHICH IS SOLVED TO DETERMINE THE
C...  AIR TEMPERATURE DISTRIBUTION WITHIN THE CITY IS
C..
C...               U  + (A/(1.+ ETA))U
C...                T                 X
C..
C...                        =
C..
C...               (C/(1. + ETA))*EP
C..
C...                        +
C..
C...               (E/(1. + ETA))*QP
C...       WITH
C..
C...               U(X,0) = 1.
C..
C...               U(0,T) = 1.
C..
C...       WHERE
C..
C...               U = NONDIMENSIONAL TEMPERATURE
C..
C...               T = NONDIMENSIONAL TIME
C..
C...              U  = DERIVATIVE OF TEMPERATURE WITH RESPECT TO TIME
C...               T
C..
C...              U  = DERIVATIVE OF TEMPERATURE WITH RESPECT TO X
C...               X
C..
C...              EP = NONDIMENSIONAL VALUE OF THE RADIANT ENERGY WHICH
C...                   FALLS ON THE CITY.  THIS MAY BE A FUNCTION OF
C...                   TIME.
C..
C...              QP = NONDIMENSIONAL HEAT GENERATION
C..
C...  A, C, E AND ETA ARE NONDIMENSIONAL CONSTANTS.
C..
C...  THE X-AXIS IS LOCATED AT THE BOTTOM OF THE LARGE BOX AND RUNS
C...  PARALLEL TO THE SIDE OF LENGTH L.  THE ORIGIN OF THE ZYX CO-
C...  ORDINATE SYSTEM, WHICH IS ALSO LOCATED ON THE BOTTOM OF THE BOX,
C...  HAS THE Y AND Z-AXES IN THE FRONT OF THE BOX PARALLEL TO THE SIDES
C...  WHOSE DIMENSIONS ARE H AND W.  IT IS CENTERED ON THE SIDE WHOSE
C...  LENGTH IS W.
C...
C...  IN THIS SUBROUTINE, THE INITIAL VALUE OF U, WHICH IS A FUNCTION
C...  OF X, IS SET.  THE X-AXIS FROM 0 TO 1 IS DIVIIDED INTO 20 EQUAL
C...  INCREMENTS, AND INITIALLY, THE NONDIMENSIONAL TEMPERATURE IS 1.
C..
      COMMON/T/T,NFIN,NRUN/Y/U(21)/F/UT(21)/UX/UX(21)/PARM/N,IP
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED SOLUTION, THE NUMBER OF
C...  GRID POINTS
      IP=0
      N=21
C...
C...  SET THE INITIAL CONDITION
      DO 10 I=1,N
      U(I)=1.0
10    CONTINUE
      RETURN
      END
      SUBROUTINE DERV
C...
C...  IN SUBROUTINE DERV, THE VALUES OF THE VARIOUS CONSTANTS ARE SET,
C...  U(0,T) IS SET TO 1 AND UX IS REPLACED BY A DIFFERENCE APPROXI-
C...  TION AS COMPUTED IN SUBROUTINE DSS020.  THE RESULTING 21 DIFFER-
C...  ENTIAL-DIFFERENCE EQUATIONS ARE SOLVED FOR U AT THE 21 VALUES OF
      COMMON/T/T,NFIN,NRUN/Y/U(21)/F/UT(21)/UX/UX(21)/PARM/N,IP
C...
C...  SET THE MODEL CONSTANTS
      A=4.93
      E=.066
      C=.09434
      H=2.58
      EP=SIN(H*T)
      QP=0.1
      ETA=.06383
      D=A/(1.+ETA)
      G=C/(1.+ETA)
      F=E/(1.+ETA)
C...
C...  BOUNDARY CONDITION FOR U(0,T)
      U(1)=1.
      UT(1)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE UX
      CALL DSS020(0.,1.,N,U,UX,1.)
C...
C...  ASSEMBLE THE PDE AT THE INTERIOR GRID POINTS IN X
      DO 10 I=2,N
      UT(I)=-D*UX(I)+G*EP+F*QP
10    CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
C..
C...  SUBROUTINE PRINT PRINTS AND PLOTS THE NUMERICAL SOLUTION
C...  ACCORDING TO A SPECIFIED FORMAT.  THE VALUES OF U(1), U(5),
C...  U(9), U(13), U(17) AND U(21) ARE PRINTED.  U(1), U(13) AND U(21)
C...  ARE PLOTTED.
      COMMON/T/T,NFIN,NRUN/Y/U(21)/F/UT(21)/UX/UX(21)/PARM/N,IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTING OF THE NUMERICAL SOLUTION
      DIMENSION XPLOT(51),YPLOT(3,51)
C...
C...  INCREMENT A COUNTER FOR THE PLOTTED SOLUTION
      IP=IP+1
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.1)WRITE(NO,20)
C...
C...  STORE THE NUMERICAL SOLUTION OF PLOTTING
      XPLOT(IP)=T
      YPLOT(1,IP)=U(1)
      YPLOT(2,IP)=U(13)
      YPLOT(3,IP)=U(21)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,10) T
      WRITE(NO,30) (U(I),I=1,N,4)
C..
C...  TEST TO SEE IF THE CURRENT RUN IS COMPLETED
      IF(IP.LT.51) RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL TPLOTS(3,51,XPLOT,YPLOT)
      IP=0
      RETURN
10    FORMAT(2X,5H T = ,F8.2)
30    FORMAT(2X,6F10.4,/)
20    FORMAT(8X,4HX(1),6X,4HX(5),6X,4HX(9),5X,5HX(13),
     15X,5HX(17),5X,5HX(21),/)
      END
AIR TEMPERATURE IN A LARGE CITY
0.        5.0       0.1
   21  150    3    1  REL 0.001
END OF RUNS
*APP HEAT11
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A NONISOTHERMAL HOLDING TANK
C...
C...  THE DYNAMIC MODEL FOR A NONISOTHERMAL HOLDING TANK HEATED BY A
C...  STEAM COIL IS
C...
C...    TOTAL MATERIAL BALANCE
C...
C...    DV/DT = F0 - F                                              (1)
C...
C...    ENERGY BALANCE
C...
C...    D(V*T1)/DT = F0*T0 - F*T1 + (U*AT)/(RHO*CP)*(TS - T1)       (2)
C...
C...    VALVE EQUATION
C...
C...    F = CV*X*(H**0.5)                                           (3)
C...
C...  WHERE
C...
C...     V      VOLUME OF LIQUID IN THE TANK
C...
C...     T1     TEMPERATURE OF LIQUID IN THE TANK
C...
C...     T      TIME
C...
C...     F0     ENTERING LIQUID FLOW RATE = 5000
C...
C...     F      EXITING LIQUID FLOW RATE
C...
C...     H      HEIGHT OF LIQUID IN THE TANK = V/A
C...
C...     A      TANK CROSS SECTIONAL AREA = 10000
C...
C...     X      VALVE STEM POSITION = 1
C...
C...     CV     VALVE CONSTANT = 10
C...
C...     U      STEAM COIL HEAT TRANSFER COEFFICIENT = 100
C...
C...     AT     STEAM COIL HEAT TRANSFER AREA = 2000
C...
C...     RHO    LIQUID DENSITY = 1
C...
C...     CP     LIQUID HEAT CAPACITY = 1
C...
C...     TS     STEAM TEMPERATURE = 120
C...
C...  THE INITIAL CONDITIONS FOR EQUATIONS (1) AND (2) ARE
C...
C...     V(0) = H(0)*A = 50*10000 = 500000                         (4)
C...
C...     V(0)*T1(0) = 500000*25 = 12500000                         (5)
C...
C...  A NUMERICAL SOLUTION BY AN EULER, FIXED-STEP INTEGRATION IS ALSO
C...  PROGRAMMED IN SUBROUTINE PRINT FOR COMPARISON WITH THE DSS/2
C...  SOLUTION PRINTED IN SUBROUTINE PRINT.
C...
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,     VT
     2      /F/   DVDT,  DVTDT
     3      /C/      X,     CV,     F0,     TS,    RHO,     CP,
     4              T0,      A,     AT,      U,     C1,      T,
     5               H,     IP
C...
C...  SET THE PROBLEM PARAMETERS
      X=1.
      CV=10.
      F0=5000.
      TS=120.
      RHO=1.
      CP=1.
      T0=25.
      A=10000.
      AT=2000.
      U=100.
C...
C...  PRECOMPUTE THE CONSTANTS REQUIRED IN THE CALCULATION OF THE
C...  DERIVATIVES IN SUBROUTINE DERV
      C1=U*AT/(RHO*CP)
C...
C...  INITIALIZE THE INDEX FOR THE PLOTTED SOLUTION USED IN SUBROUTINE
C...  PRINT
      IP=0
C...
C...  SET THE MODEL INITIAL CONDITIONS
      V=500000.
      VT=V*25.
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,     VT
     2      /F/   DVDT,  DVTDT
     3      /C/      X,     CV,     F0,     TS,    RHO,     CP,
     4              T0,      A,     AT,      U,     C1,      T,
     5               H,     IP
C...
C...  MODEL ALGEBRA
      H=V/A
      F=CV*X*SQRT(H)
      T=VT/V
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DVDT=F0-F
      DVTDT=F0*T0-F*T+C1*(TS-T)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,     VT
     2      /F/   DVDT,  DVTDT
     3      /C/      X,     CV,     F0,     TS,    RHO,     CP,
     4              T0,      A,     AT,      U,     C1,      T,
     5               H,     IP
C...
C...  DIMENSION THE ARRAYS REQUIRED FOR PLOTTING
      DIMENSION  TIMEP(51),    HP(51),    TP(51), DVDTP(51),DVTDTP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,9X,1HH,9X,1HT,6X,4HDVDT,5X,5HDVTDT)
      IP=IP+1
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)TIME,H,T,DVDT,DVTDT
2        FORMAT(4F10.2,E10.2)
      END IF
C...
C...  STORE THE SOLUTION FOR SUBSEQUENT PLOTTING
      TIMEP(IP)=TIME
      HP(IP)=H
      TP(IP)=T
      DVDTP(IP)=DVDT
      DVTDTP(IP)=DVTDT
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.51)RETURN
      CALL SPLOTS(1,IP,TIMEP,HP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' H VS TIME')
      CALL SPLOTS(1,IP,TIMEP,TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' T VS TIME')
      CALL SPLOTS(1,IP,TIMEP,DVDTP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' DVDT VS TIME')
      CALL SPLOTS(1,IP,TIMEP,DVTDTP)
      WRITE(NO,13)
13    FORMAT(1H ,//,' DVTDT VS TIME')
C...
C...  PERFORM AN EULER INTEGRATION AT THE END OF THE RUN
      CALL EULER(NI,NO)
      RETURN
      END
      SUBROUTINE EULER(NI,NO)
C...
C...  SUBROUTINE EULER IS REALLY A *MINI DSS/2* IN THE SENSE THAT
C...  IT PERFORMS THE BASIC OPERATIONS OF THE DSS/2 MAIN PROGRAM,
C...  IDSS2, AND THE DSS/S INTEGRATION ROUTINE FOR ODES, INTEG.
C...  OF COURSE, IT DOES NOT HAVE THE SOPHISTICATION OF INTEG, E.G.,
C...  AUTOMATIC ERROR MONITORING AND CONTROL, SINCE IT PERFORMS ONLY
C...  A FIXED-STEP EULER INTEGRATION.  THEREFORE, THE NUMERICAL SOLU-
C...  TIONS GENERATED BY SUBROUTINE EULER WILL DIFFER SIGNIFICANTLY
C...  FROM THE SOLUTIONS GENERATED BY DSS/2 VIA SUBROUTINE INTEG.
C...  HOWEVER, THE CALLS TO TWO USER-SUPPLIED SUBROUTINES, INITAL
C...  AND DERV, IN EULER PARALLEL THE CALLS TO THESE SUBROUTINES IN
C...  THE DSS/2 MAIN PROGRAM.  UNFORTUNATELY, CALLS TO SUBROUTINE
C...  PRINT FROM EULER ARE NOT POSSIBLE SINCE EULER WAS CALLED BY
C...  PRINT, I.E., RECURSIVE CALLS ARE NOT PERMITTED IN FORTRAN.
C...  THEREFORE, THE NUMERICAL SOLUTION PRODUCED BY EULER IS PRINTED
C...  BY WRITE STATEMENTS IN EULER RATHER THAN CALLS TO PRINT, AND
C...  IN THIS SENSE (DIFFERENCES IN PRINTING THE SOLUTION), THE ANALOGY
C...  BETWEEN DSS/2 AND EULER IS NOT COMPLETE.
C...
C...  ALSO, EULER DOES NOT READ DATA LINES LIKE DSS/2.  RATHER, THE
C...  BASIC PARAMETERS CONTROLLING THE ODE NUMERICAL INTEGRATION ARE
C...  SET EXPLICITLY IN EULER FOR THE PARTICULAR ODE PROBLEM.  HOWEVER,
C...  DATA PARALLELING THOSE OF DSS/2 COULD BE READ FROM EULER (VIA
C...  THE UNIT NUMBER NI).
C...
C...  AS THE NEXT STEP IN UNDERSTANDING THE OPERATION OF DSS/2, THE
C...  READER IS REFERRED TO THE DSS/2 INTRODUCTORY PROGRAMMING MANUAL,
C...  AND IN PARTICULAR, THE LISTING OF THE DSS/2 MAIN PROGRAM, IDSS2,
C...  AND THE INTEGRATION ROUTINE, INTEG, IN THE APPENDICES OF THE
C...  MANUAL.
C...
C...  ARGUMENT LIST
C...
C...     NI     INPUT DEVICE (UNIT) NUMBER (INPUT)
C...
C...     NO    OUTPUT DEVICE (UNIT) NUMBER (INPUT)
C...
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      V,     VT
     2      /F/   DVDT,  DVTDT
     3      /C/      X,     CV,     F0,     TS,    RHO,     CP,
     4              T0,      A,     AT,      U,     C1,      T,
     5               H,     IP
C...
C...  PRINT A HEADING FOR THE SOLUTION
      WRITE(NO,1)
1     FORMAT(1H1,18H EULER INTEGRATION,//,
     1        9X,1HT,9X,1HH,9X,1HT,6X,4HDVDT,5X,5HDVTDT)
C...
C...  SET THE INITIAL CONDITIONS FOR THE EULER INTEGRATION
      TIME=0.
      CALL INITAL
C...
C...  PRINT THE INITIAL CONDITIONS
      WRITE(NO,2)TIME,H,T,DVDT,DVTDT
2     FORMAT(4F10.2,E10.2)
C...
C...  PERFORM THE EULER INTEGRATION OVER THE INTERVAL 0 LE TIME LE 50
C...  USING N STEPS
      N=50
      DT=50./FLOAT(N)
      DO 3 I=1,N
C...
C...  THE FOLLOWING PROGRAMMING OF THE EULER INTEGRATION IS SPECIFIC
C...  TO THIS TWO-ODE PROBLEM.  HOWEVER, THIS PROGRAMMING COULD EASILY
C...  BE GENERALIZED BY PUTTING THE EULER STEPPING FORMULA IN A DO
C...  LOOP THAT CYCLES THROUGH THE SET OF ODES.  THIS IS THE BASIC
C...  APPROACH FOLLOWED IN THE DSS/2 INTEGRATION ROUTINE INTEG
      V=V+DVDT*DT
      VT=VT+DVTDT*DT
      TIME=TIME+DT
C...
C...  UPDATE THE DERIVATIVES
      CALL DERV
C...
C...  PRINT THE NUMERICAL SOLUTION
      IF((I/5*5).EQ.I)THEN
      WRITE(NO,2)TIME,H,T,DVDT,DVTDT
      END IF
3     CONTINUE
      RETURN
      END
NONISOTHERMAL HOLDING TANK
0.        50.       1.0
    2 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT12
      SUBROUTINE INITAL
C...
C...  INTEGRATION OF THE PLANCK DISTRIBUTION LAW OVER THE VISIBLE
C...  SPECTRUM
C...
C...  THE INTEGRAL TO BE EVALUATED CAN BE COMPUTED VIA THE EQUIVALENT
C...  DIFFERENTIAL EQUATION
C...
C...     DQB = 2*PI*(C**2)*H/(LAMBDA**5)*(1/(EXP(C*H/(LAMBDA*K*T))-1))
C...
C...                            QB(0.3E-04) = 0
C...
C...  WHERE
C...
C...     QB      INTEGRATED SPECTRUM (ERG/(SEC-CM**2))
C...
C...     LAMBDA  WAVELENGTH (CM)
C...
C...     DQB     DERIVATIVE OF QB WITH RESPECT TO LAMBDA (ERGS/
C...             (SEC-CM**3))
C...
C...     K       BOLTZMANN*S CONSTANT (1.3805E-16 ERG/(MOLECULE-K))
C...
C...     H       PLANCK*S CONSTANT (6.624E-27 ERG-SEC)
C...
C...     C       SPEED OF LIGHT (2.99793E+10 CM/SEC)
C...
C...     PI      3.1415927
C...
C...     T       TEMPERATURE OF THE RADIATING BODY (5760 K)
C...
C...  THE INTEGRATION IS TO BE CARRIED OUT OVER THE VISIBLE SPECTRUM,
C...  LAMBDA = 0.3E-04 CM TO 0.7E-04 CM.  THUS AT THE LOWER LIMIT OF
C...  INTEGRATION, THE INTEGRAL IS ZERO AS SPECIFIED BY THE INITIAL
C...  CONDITION FOR THE DIFFERENTIAL EQUATION.  IN SUBROUTINE PRINT,
C...  THE FRACTION OF THE RADIATION IN THE VISIBLE SPECTRUM IS COMPUTED
C...  BY DIVISION OF THE COMPUTED QB BY THE RADIATION OVER THE TOTAL
C...  SPECTRUM 0 LE LAMBDA LE INFINITY.  THE LATTER CAN BE COMPUTED IN
C...  CLOSED FORM (EXACTLY) FROM THE INTEGRAL AS
C...
C...         QBTOT = (2*(PI**5)*(K**4))/(15*(C**2)*(H**3))T**4
C...
C...  THE INTEGRATION IS PERFORMED WITH ALGORITHMS 1 AND 8 (TWO RUNS).
C...
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
      REAL              K,    LAMBDA
C...
C...  SET THE PROBLEM CONSTANTS
      K=1.3805E-16
      H=6.624E-27
      C=2.99793E+10
      T=5760.
      PI=4.*ATAN(1.)
C...
C...  SET THE INITIAL CONDITION
      QB=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
      REAL              K,    LAMBDA
C...
C...  THE DIFFERENTIAL EQUATION DOES NOT CONTAIN THE MULTIPLYING
C...  CONSTANT AT THIS POINT.  RATHER, IT IS INCLUDED IN SUBROUTINE
C...  PRINT
      DQB=1./((LAMBDA**5)*(EXP(C*H/(LAMBDA*K*T))-1.))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
      REAL              K,    LAMBDA
C...
C...  PRINT THE INTEGRAL AFTER INCLUDING THE MULTIPLYING CONSTANT
      QB=2.*PI*(C**2)*H*QB
      WRITE(NO,1)QB
1     FORMAT(1H ,//,
     1 40H RADIANT FLUX IN THE VISIBLE SPECTRUM = ,E10.3)
C...
C...  COMPUTE AND PRINT THE FRACTION OF THE RADIATION IN THE VISIBLE
C...  SPECTRUM
      QBTOT=2.*(PI**5)*(K**4)*(T**4)/(15.*(C**2)*(H**3))
      QFRACT=QB/QBTOT
      WRITE(NO,2)QBTOT,QFRACT
2     FORMAT(1H ,/,
     1 19H TOTAL RADIATION = ,E10.3,//,
     2 24H FRACTIONAL RADIATION = ,E10.3,////)
      RETURN
      END
BIRD, STEWART, LIGHTFOOT, TRANSPORT PHENOMENA, PP. 434-437, ALGORITHM 1
   0.3E-04   0.7E-04   0.4E-04
    1 1000    1    1  REL 0.0001
BIRD, STEWART, LIGHTFOOT, TRANSPORT PHENOMENA, PP. 434-437, ALGORITHM 8
   0.3E-04   0.7E-04   0.4E-04
    1 1000    1    8  REL 0.0001
END OF RUNS
*APP HEAT13
      SUBROUTINE INITAL
C...
C...  INTEGRATION OF THE PLANCK DISTRIBUTION LAW OVER THE VISIBLE
C...  SPECTRUM - SECOND APPROACH
C...
C...  THE FOLLOWING PROGRAMMING IS A MINOR VARIATION ON THE PROBLEM OF
C...  THE SAME TITLE IN WHICH THE TOTAL RADIATION, QBTOT, IS COMPUTED BY
C...  DSS/2 INTEGRATION RATHER THAN BY THE CLOSED-FORM (EXACT) INTEGRAL.
C...  ALSO, THE PLANCK DISTRIBUTION FUNCTION IS PLOTTED TO GIVE AN IN-
C...  DICATION OF THE NATURE OF THE NUMERICAL INTEGRATION.
C...
C...  THE INTEGRAL TO BE EVALUATED CAN BE COMPUTED VIA THE EQUIVALENT
C...  DIFFERENTIAL EQUATION
C...
C...     DQB = 2*PI*(C**2)*H/(LAMBDA**5)*(1/(EXP(C*H/(LAMBDA*K*T))-1))
C...
C...                            QB(0.3E-04) = 0
C...
C...  WHERE
C...
C...     QB      INTEGRATED SPECTRUM (ERG/(SEC-CM**2))
C...
C...     LAMBDA  WAVELENGTH (CM)
C...
C...     DQB     DERIVATIVE OF QB WITH RESPECT TO LAMBDA (ERGS/
C...             (SEC-CM**3))
C...
C...     K       BOLTZMANN*S CONSTANT (1.3805E-16 ERG/(MOLECULE-K))
C...
C...     H       PLANCK*S CONSTANT (6.624E-27 ERG-SEC)
C...
C...     C       SPEED OF LIGHT (2.99793E+10 CM/SEC)
C...
C...     PI      3.1415927
C...
C...     T       TEMPERATURE OF THE RADIATING BODY (5760 K)
C...
C...  THE INTEGRATION IS TO BE CARRIED OUT OVER THE VISIBLE SPECTRUM,
C...  LAMBDA = 0.3E-04 CM TO 0.7E-04 CM.  THUS AT THE LOWER LIMIT OF
C...  INTEGRATION, THE INTEGRAL IS ZERO AS SPECIFIED BY THE INITIAL
C...  CONDITION FOR THE DIFFERENTIAL EQUATION.  IN SUBROUTINE PRINT,
C...  THE FRACTION OF THE RADIATION IN THE VISIBLE SPECTRUM IS COMPUTED
C...  BY DIVISION OF THE COMPUTED QB BY THE RADIATION OVER THE TOTAL
C...  SPECTRUM 0 LE LAMBDA LE INFINITY.  THE LATTER CAN BE COMPUTED BY A
C...  SECOND RUN OVER ESSENTIALLY AN INFINITE WAVELENGTH SPECTRUM.  TO
C...  DETERMINE WHAT IS EFFECTIVELY INFINITE, THE WAVELENGTH CORRESPOND-
C...  ING TO THE MAXIMUM IN THE PLANCK DISTRIBUTION LAW IS COMPUTED AS
C...
C...         LAMBDA(MAX) = 0.2884/T = 0.2884/5760 = 0.00005007 CM
C...
C...  THUS INTEGRATION OVER THE INTERVAL 0 LE LAMBDA LE 10.0E-04 CM
C...  SHOULD ENCOMPASS ESSENTIALLY THE ENTIRE DISTRIBUTION FUNCTION
C...  (THIS IS CONFIRMED BY A PLOT OF THE DISTRIBUTION FUNCTION PRO-
C...  GRAMMED AT THE END OF SUBROUTINE PRINT).
C...
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
      REAL              K,    LAMBDA
C...
C...  SET THE PROBLEM CONSTANTS
      K=1.3805E-16
      H=6.624E-27
      C=2.99793E+10
      T=5760.
      PI=4.*ATAN(1.)
C...
C...  SET THE INITIAL CONDITION
      QB=0.
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
      REAL              K,    LAMBDA
C...
C...  THE DIFFERENTIAL EQUATION DOES NOT CONTAIN THE MULTIPLYING
C...  CONSTANT AT THIS POINT.  RATHER, IT IS INCLUDED IN SUBROUTINE
C...  PRINT (A TEST HAS BEEN ADDED TO PREVENT COMPUTATIONAL PROBLEMS
C...  FOR SMALL LAMBDA)
      IF(LAMBDA.LT.1.0E-06)DQB=0.
      IF(LAMBDA.GE.1.0E-06)DQB=
     1 1./((LAMBDA**5)*(EXP(C*H/(LAMBDA*K*T))-1.))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/    LAMBDA,      NFIN,     NORUN
     1      /Y/        QB
     2      /F/       DQB
     3      /C/         K,         H,         C,         T,        PI
C...
C...  DIMENSION THE ARRAYS FOR STORING THE PLOTTED SPECTRUM
      DIMENSION
     1              X(51),     Y(51)
      REAL              K,    LAMBDA
C...
C...  PRINT THE COMPUTED RADIATION FLUX AT THE END OF EACH RUN
      IF((NORUN.EQ.1).AND.(LAMBDA.LT.0.6E-04))RETURN
      IF((NORUN.EQ.2).AND.(LAMBDA.LT.9.0E-04))RETURN
      QB=2.*PI*(C**2)*H*QB
      WRITE(NO,1)QB
1     FORMAT(1H ,/,
     1 16H RADIANT FLUX = ,E10.3)
C...
C...  STORE THE FLUX AT THE END OF THE FIRST RUN FOR USE AT THE END OF
C...  THE SECOND RUN
      IF(NORUN.EQ.2)GO TO 3
      QBSTOR=QB
      RETURN
C...
C...  COMPUTE AND PRINT THE FRACTION OF THE RADIATION IN THE VISIBLE
C...  SPECTRUM
3     QFRACT=QBSTOR/QB
      WRITE(NO,2)QFRACT
2     FORMAT(1H ,/,
     1 24H FRACTIONAL RADIATION = ,E10.3,//)
C...
C...  COMPUTE AND PLOT THE PLANCK DISTRIBUTION FUNCTION
      LAMBDA=-0.1E-04
      DO 4 I=1,51
      LAMBDA=LAMBDA+0.1E-04
      X(I)=LAMBDA
      IF(LAMBDA.LT.1.0E-06)Y(I)=0.
      IF(LAMBDA.GE.1.0E-06)Y(I)=
     1 1./((LAMBDA**5)*(EXP(C*H/(LAMBDA*K*T))-1.))
      WRITE(NO,6)I,X(I),Y(I)
6     FORMAT(I5,2E15.4)
4     CONTINUE
      CALL PLOTS(1,51,X,Y)
      WRITE(NO,5)T
5     FORMAT(1H ,//,
     1 41H PLANCK DISTRIBUTION FUNCTION FOR TEMP = ,E10.3)
C...
C...  IF LAMBDA IS NOT RESET AT THIS POINT TO ITS CORRECT TERMINAL VALUE
C...  READ FROM THE SECOND DATA CARD, THE INTEGRATION WILL CONTINUE.
C...  THIS IS AN EXAMPLE OF WHAT CAN HAPPEN IF THE QUANTITIES IN COMMON
C...  /T/, /Y/ OR /F/ ARE SET IN A NONCONVENTIONAL WAY IN SUBROUTINES
C...  INITAL, DERV AND PRINT.  IN THIS CASE, LAMBDA IS REDEFINED BY DO
C...  LOOP 4 ABOVE, THEREBY OVERWRITING LAMBDA SET BY THE MAIN DSS/2
C...  PROGRAM IN COMMON/T/.  THIS IN TURN UPSETS THE CONTROL OF THE
C...  NUMERICAL INTEGRATION BY THE MAIN PROGRAM, I.E., THE NUMERICAL
C...  INTEGRATION TO THE FINAL VALUE OF LAMBDA IN THE SECOND RUN
C...  (10.0E-04) IS NOT COMPLETED.  THE PROBLEM COULD BE AVOIDED BY
C...  USING SOME OTHER VARIABLE NAME THAN LAMBDA IN DO LOOP 4
      LAMBDA=10.0E-04
      RETURN
      END
BIRD, STEWART, LIGHTFOOT, TRANSPORT PHENOMENA, PP. 434-437, VISIBLE
   0.3E-04   0.7E-04   0.4E-04
    110000    8    1  REL 0.0001
BIRD, STEWART, LIGHTFOOT, TRANSPORT PHENOMENA, PP. 434-437, TOTAL
       0.0  10.0E-04  10.0E-04
    110000    8    1  REL 0.0001
END OF RUNS
*APP HEAT14
      SUBROUTINE INITAL
C...
C...  REGENERATOR SIMULATED BY CSTR*S IN SERIES AND CENTERED DIFFERENCES
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS DESCRIBING THE DYNAMICS OF A
C...  DISTRIBUTED REGENERATOR ARE
C...
C...     TF  = -Q/(S*F)TF  - (AV*H)/(F*RHOF*CPF)(TF - TS)            (1)
C...       T             Z
C...
C...     TS  = (AV*H)/((1-F)*RHOS*CPS)(TF - TS)                      (2)
C...       T
C...
C...  WITH AUXILIARY CONDITIONS
C...
C...     TF(0,T) = F(T), TF(Z,0) = TF0, TS(Z,0) = TS0          (3)(4)(5)
C...
C...  WHERE
C...
C...     TF        FLUID TEMPERATURE
C...
C...     TS        SOLID TEMPERATURE
C...
C...     Z         AXIAL POSITION
C...
C...     T         TIME
C...
C...     Q         FLUID VOLUMETRIC FLOW RATE
C...
C...     S         REGENERATOR CROSS SECTIONAL AREA
C...
C...     F         SOLID VOID FRACTION
C...
C...     AV        HEAT TRANSFER AREA BETWEEN THE FLUID AND SOLID PER
C...               UNIT VOLUME OF REGENERATOR
C...
C...     H         HEAT TRANSFER COEFFICIENT
C...
C...     RHOF      FLUID DENSITY
C...
C...     RHOS      SOLID DENSITY
C...
C...     CPF       FLUID HEAT CAPACITY
C...
C...     CPS       SOLID HEAT CAPACITY
C...
C...     TF0       INITIAL FLUID TEMPERATURE
C...
C...     TS0       INITIAL SOLID TEMPERATURE
C...
C...     F(T)      VARIATION OF THE ENTERING FLUID TEMPERATURE WITH TIME
C...               (FOR THE FOLLOWING ANALYSIS, F(T) = TFE, A CONSTANT
C...               INLET TEMPERATURE)
C...
C...  TO SIMPLIFY THE ANALYSIS, THE FOLLOWING CONSTANTS ARE DEFINED
C...
C...     A = Q/(S*F*DZ), B = (AV*H)/(F*RHOF*CPF)
C...
C...     C = (AV*H)/((1-F)*RHOS*CPS)
C...
C...  IN THE ANALYSIS WHICH FOLLOWS, THESE CONSTANTS ARE GIVEN THE
C...  NUMERICAL VALUES A = B = C = 1
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
C...
C...  THE REGENERATOR IS SIMULATED BY THREE DIFFERENT APPROACHES
C...
C...     (1)  THE NUMERICAL METHOD OF LINES (NMOL) ODES ARE PROGRAMMED
C...          EXPLICITLY IN SUBROUTINE DERV BASED ON 20 PERECTLY MIXED
C...          SECTIONS ALONG THE REGERENATOR.  THIS IS IN EFFECT RE-
C...          PLACING THE SPATIAL DERIVATIVE TF  WITH A FIRST-ORDER TWO-
C...                                           Z
C...          POINT FINITE DIFFERENCE APPROXIMATION.
C...
C...     (2)  THE SECOND-ORDER THREE-POINT APPROXIMATIONS OF SUBROUTINE
C...          DSS002 ARE USED TO COMPUTE THE DERIVATIVE TF  OVER A 21-
C...          POINT GRID.                                 Z
C...
C...     (3)  THE FOURTH-ORDER FIVE-POINT APPROXIMATIONS OF SUBROUTINE
C...          DSS004 ARE USED TO COMPUTE THE DERIVATIVE TF  OVER A 21-
C...          POINT GRID.                                 Z
C...
C...  SET THE MODEL PARAMETERS
      N=21
      ZL=20.
      DZ=1.
      TF0=20.
      TS0=20.
      TFE=500.
      A=1.
      B=1.
      C=1.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      TF(I)=TF0
      TS(I)=TS0
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
C...
C...  IMPLEMENT THE BOUNDARY CONDITION
      TF(1)=TFE
      DTFDT(1)=0.
C...
C...  THE THREE APPROACHES DISCUSSED IN SUBROUTINE INITAL ARE PROGRAMMED
C...  HERE
      GO TO(1,2,3),NORUN
C...
C...  THE NMOL ODES ARE PROGRAMMED EXPLICITLY
1     DO 11 I=1,N
      DTSDT(I)=C*(TF(I)-TS(I))
      IF(I.EQ.1)GO TO 11
      DTFDT(I)=A*(TF(I-1)-TF(I))+B*(TS(I)-TF(I))
11    CONTINUE
      RETURN
C...
C...  SUBROUTINE DSS002 IS USED TO CALCULATE THE SPATIAL DERIVATIVE
2     CALL DSS002(0.,ZL,N,TF,DTFDZ)
      GO TO 12
C...
C...  SUBROUTINE DSS004 IS USED TO CALCULATE THE SPATIAL DERIVATIVE
3     CALL DSS004(0.,ZL,N,TF,DTFDZ)
C...
C...  ASSEMBLE THE PDES
12    DO 13 I=1,N
      DTSDT(I)=C*(TF(I)-TS(I))
      IF(I.EQ.1)GO TO 13
      DTFDT(I)=-A*DZ*DTFDZ(I)+B*(TS(I)-TF(I))
13    CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
      DIMENSION TP(4,101), TIME(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.0.5)WRITE(NO,1)
1     FORMAT(9X,1HT,5X,7HTF(0,T),5X,7HTS(0,T),4X,8HTF(ZL,T),4X,8HTS(ZL,T
     1))
C...
C...  PRINT THE NUMERICAL SOLUTION AT Z = 0, ZL
      WRITE(NO,2)T,TF(1),TS(1),TF(N),TS(N)
2     FORMAT(F10.2,4F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      TP(1,IP)=TF(1)
      TP(2,IP)=TS(1)
      TP(3,IP)=TF(N)
      TP(4,IP)=TS(N)
      TIME(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.101)RETURN
      CALL PLOTS(4,IP,TIME,TP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,//,53H 1 - TF(0,T), 2 - TS(0,T), 3 - TF(ZL,T), 4 - TS(Z
     1L,T))
      RETURN
      END
DYNAMICS OF A REGENERATOR, EXPLICIT PROGRAMMING OF THE NMOL ODES
0.        100.      1.
   42 1000    8    1  REL 0.001
DYNAMICS OF A REGENERATOR, SUBROUTINE DSS002
0.        100.      1.
   42 1000    8    1  REL 0.001
DYNAMICS OF A REGENERATOR, SUBROUTINE DSS004
0.        100.      1.
   42 1000    8    1  REL 0.001
END OF RUNS
*APP HEAT15
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS DESCRIBING THE DYNAMICS OF A
C...  DOUBLE-PIPE HEAT EXCHANGER ARE
C...
C...     TFP  = -(FFP/AP)TFP  - (U*D*PI/(RHOFP*CPFP*AP))(TFP - TFA)  (1)
C...        T               Z
C...
C...     TFA  =  (FFA/AA)TFA  + (U*D*PI/(RHOFA*CPFA*AA))(TFP - TFA)  (2)
C...        T               Z
C...
C...  WITH INITIAL CONDITIONS
C...
C...     TFP(Z,0) = G1(Z), TFA(Z,0) = G2(Z)                       (3)(4)
C...
C...  AND BOUNDARY CONDITIONS
C...
C...     TFP(0,T) = G3(T), TFA(ZL,T) = G4(T)                      (5)(6)
C...
C...  WHERE
C...
C...     TFP       PIPE FLUID TEMPERATURE
C...
C...     TFA       ANNULUS FLUID TEMPERATURE
C...
C...     Z         AXIAL POSITION ALONG THE EXCHANGER
C...
C...     T         TIME
C...
C...     ZL        LENGTH OF THE EXCHANGER
C...
C...     FFP       PIPE FLUID VOLUMETRIC FLOW RATE
C...
C...     FFA       ANNULUS FLUID VOLUMETRIC FLOW RATE
C...
C...     AP        PIPE CROSS SECTIONAL AREA
C...
C...     AA        ANNULUS CROSS SECTIONAL AREA
C...
C...     U         OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE PIPE
C...               AND ANNULUS FLUIDS
C...
C...     D         PIPE INSIDE DIAMETER
C...
C...     RHOFP     PIPE FLUID DENSITY
C...
C...     RHOFA     ANNULUS FLUID DENSITY
C...
C...     CPFP      PIPE FLUID HEAT CAPACITY
C...
C...     CPFA      ANNULUS FLUID HEAT CAPACITY
C...
C...     G1(Z)     PRESCRIBED INITIAL CONDITION FUNCTIONS
C...     G2(Z)
C...
C...     G3(T)     PRESCRIBED BOUNDARY CONDITION FUNCTIONS
C...     G4(T)
C...
C...  1.0 FT**3/MIN OF A LUBE OIL AT 250F FLOWS THROUGH THE PIPE AND IS
C...  BEING COOLED WITH 1.0 FT**3/MIN OF WATER AT 60F FLOWING COUNTER-
C...  CURRENTLY THROUGH THE ANNULUS.  FOR THE ANALYSIS OF THE EXCHANGER,
C...  THE AXIAL DERIVATIVES ARE APPROXIMATED BY 20 PERFECTLY MIXED
C...  SECTIONS IN SERIES.  THE ENTRANCE TEMPERATURES, TFP(0,T) AND
C...  TFA(L,T), AND THE EXIT TEMPERATURES, TFP(L,T) AND TFA(0,T), ARE
C...  PLOTTED VS TIME UNTIL STEADY STATE IS REACHED.
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     3      /C/         N,        ZL,        DZ,        VP,        VA,
     4                 HP,        HA,        IP
C...
C...  SET THE MODEL PARAMETERS
      FFP=1.0
      FFA=1.0
      AP=0.1
      AA=0.1
      UD=1.5
      RHOFP=50.0
      RHOFA=62.0
      CPFP=0.5
      CPFA=1.0
      ZL=20.0
      N=21
      DZ=ZL/FLOAT(N-1)
C...
C...  PRECOMPUTE SOME CONSTANTS TO SAVE TIME
      VP=FFP/AP
      VA=FFA/AA
      HP=UD*3.1415927/(RHOFP*CPFP*AP)
      HA=UD*3.1415927/(RHOFA*CPFA*AA)
C...
C...  SET THE INITIAL CONDITIONS
      DO 1 I=1,N
      Z=FLOAT(I-1)/FLOAT(N-1)*ZL
      TFP(I)=G1(Z)
      TFA(I)=G2(Z)
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      FUNCTION G1(Z)
      G1=60.0
      RETURN
      END
      FUNCTION G2(Z)
      G2=60.0
      RETURN
      END
      FUNCTION G3(T)
      G3=250.0
      RETURN
      END
      FUNCTION G4(T)
      G4=60.0
      RETURN
      END
      SUBROUTINE DERV
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     3      /C/         N,        ZL,        DZ,        VP,        VA,
     4                 HP,        HA,        IP
C...
C...  BOUNDARY CONDITIONS
      TFP(1)=G3(T)
      TFA(N)=G4(T)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      GO TO(1,2),NORUN
C...
C...  SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) ARE APPROXIMATED BY
C...  TWO-POINT BACKWARD (UPWIND) DIFFERENCES (STIRRED TANKS IN SERIES)
1     DO 11 I=1,N
      IF(I.EQ.1)GO TO 12
      TFPT(I)=-VP*(TFP(I)-TFP(I-1))/DZ-HP*(TFP(I)-TFA(I))
12    IF(I.EQ.N)GO TO 11
      TFAT(I)= VA*(TFA(I+1)-TFA(I))/DZ+HA*(TFP(I)-TFA(I))
11    CONTINUE
      TFPT(1)=0.
      TFAT(N)=0.
      RETURN
C...
C...  SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) ARE AGAIN APPROXI-
C...  MATED BY TWO-POINT BACKWARD (UPWIND) DIFFERENCES (STIRRED TANKS
C...  IN SERIES) PROGRAMMED IN SUBROUTINE DSS012.  THE SIXTH ARGUMENT OF
C...  DSS012 DEFINES THE DIRECTION OF FLOW (POSITIVE Z DIRECTION FOR
C...  EQUATION (1), NEGATIVE Z DIRECTION FOR EQUATION (2))
2     CALL DSS012(0.,ZL,N,TFP,TFPZ,+1.)
      CALL DSS012(0.,ZL,N,TFA,TFAZ,-1.)
      DO 21 I=1,N
      IF(I.EQ.1)GO TO 22
      TFPT(I)=-VP*TFPZ(I)-HP*(TFP(I)-TFA(I))
22    IF(I.EQ.N)GO TO 21
      TFAT(I)= VA*TFAZ(I)+HA*(TFP(I)-TFA(I))
21    CONTINUE
      TFPT(1)=0.
      TFAT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     3      /C/         N,        ZL,        DZ,        VP,        VA,
     4                 HP,        HA,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(4,101),TIMEP(101)
C...
C...  LABEL THE NUMERICAL OUTPUT
      IF(T.LT.0.05)WRITE(NO,2)
2     FORMAT(9X,1HT,4X,8HTFP(0,T),3X,9HTFP(ZL,T),
     1              4X,8HTFA(0,T),3X,9HTFA(ZL,T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,TFP(1),TFP(N),TFA(1),TFA(N)
1     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      TP(1,IP)=TFP(1)
      TP(2,IP)=TFA(1)
      TP(3,IP)=TFP(N)
      TP(4,IP)=TFA(N)
      TIMEP(IP)=T
      IF(IP.LT.101)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL PLOTS(4,IP,TIMEP,TP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,//,47H 1 - TFP(1), 2 - TFA(1), 3 - TFP(N), 4 - TFA(N))
      RETURN
      END
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
END OF RUNS
*APP HEAT16
      SUBROUTINE INITAL
C...
C...  THERMAL BONDING OF SOLIDS
C...
C...  TWO SHEETS OF A SOLID MATERIAL ARE TO BE BONDED TOGETHER BY
C...  USING A THIN LAYER OF THERMOPLASTIC MATERIAL WHICH FUSES AND
C...  FORMS A BOND AT TEMPERATURE UG.  THE TWO PLATES OF SOLID
C...  MATERIAL ARE INSERTED IN A PRESS, WITH BOTH PLATTENS OF THE
C...  PRESS HEATED AT A CONSTANT RATE, Q.  THE THERMOPLASTIC MATER-
C...  IAL BETWEEN THE PLATES THEREFORE IS HEATED, AND THE FOLLOWING
C...  ANALYSIS IS INTENDED TO DETERMINE THE TEMPERATURE OF THE
C...  MATERIAL, U(O,T), AS A FUNCTION OF TIME, T.  THE TIME REQUIRED
C...  TO REACH THE CRITICAL TEMPERATURE, UG, CAN THEREFORE BE DETER-
C...  MINED SO THAT THAT TIME REQUIRED IN THE PRESS TO FORM THE BOND
C...  CAN BE ESTIMATED.
C...
C...  THE FOLLOWING MATHEMATICAL MODEL IS PROGRAMMED
C...
C...     U  = A*U
C...      T      XX
C...
C...     U (0,T) = 0
C...      X
C...
C...     K*U (XL,T) = -Q
C...        X
C...
C...     U(X,0) = U0
C...
C...  WHERE
C...
C...     U       TEMPERATURE IN EITHER PLATE (C)
C...
C...     T       TIME (SEC)
C...
C...     X       DISTANCE WITHIN EITHER PLATE (X = 0 CORRESPONDS TO
C...             THE SURFACE FOR THE THERMOPLASTIC BONDING MATERIAL)
C...
C...     A       THERMAL DIFFUSIVITY OF THE PLATES (CM**2/SEC)
C...
C...     K       THERMAL CONDUCTIVITY OF THE PLATES (J/SEC-CM**2-C)
C...
C...     Q       HEAT FLUX APPLIED BY THE PRESS TO THE PLATES
C...             (J/SEC-CM**2)
C...
C...     XL      THICKNESS OF THE PLATES (CM)
C...
C...     U0      INITIAL TEMPERATURE OF THE PLATES (C)
C...
C...  THE FIRST EQUATION IS JUST FOURIER*S SECOND LAW FOR HEAT CON-
C...  DUCTION IN THE PLATES WITH THERMAL DIFFUSIVITY A.  THE SECOND
C...  EQUATION IS A BOUNDARY CONDITION REFLECTING SYMMETRY WHERE THE
C...  TWO PLATES COME TOGETHER (AND WHERE THE THERMOPLASTIC MATERIAL
C...  IS LOCATED).  THE THIRD EQUATION IS A BOUNDARY CONDITION AT
C...  X = XL SPECIFYING THE HEAT FLUX Q AT THE INTERFACE BETWEEN THE
C...  PRESS PLATTENS AND THE PLATES (THIS IS FOURIER*S FIRST LAW).
C...  THE FOURTH EQUATION IS AN INITIAL CONDITION INDICATING THAT THE
C...  PLATES START AT TEMPERATURE U0.
C...
C...  THIS MODEL IS PROGRAMMED BELOW FOR A SPATIAL GRID OF 11 AND
C...  21 POINTS, USING THREE AND FIVE-POINT APPROXIMATIONS OF THE
C...  DERIVATIVES IN X (SUBROUTINES DSS002 AND DSS004).  THUS, FOUR
C...  RUNS ARE PROGRAMMED.  ALSO, IN THE FOLLOWING PROGRAMMING, B =
C...  Q/K.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21)
     4      /C/         A,         B,        XL,         N,        IP
C...
C...  SET THE LENGTH OF THE SOLID, NUMBER OF GRID POINTS
      XL=2.
      IF((NORUN.EQ.1).OR.(NORUN.EQ.3))N=11
      IF((NORUN.EQ.2).OR.(NORUN.EQ.4))N=21
C...
C...  SET THE MODEL CONSTANTS
      A=0.009
      B=-1000.
C...
C...  SET THE MODEL INITIAL CONDITION
      DO 1 I=1,N
      U(I)=20.
1     CONTINUE
C...
C...  INITIALIZE THE CALCULATIONS IN SUBROUTINE DERV
      CALL DERV
C...
C...  INITIALIZE THE COUNTER FOR THE PLOTTED SOLUTION
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21)
     4      /C/         A,         B,        XL,         N,        IP
C...
C...  COMPUTE THE DERIVATIVE UX
      IF((NORUN.EQ.1).OR.(NORUN.EQ.2))CALL DSS002(0.,XL,N,U,UX)
      IF((NORUN.EQ.3).OR.(NORUN.EQ.4))CALL DSS004(0.,XL,N,U,UX)
C...
C...  APPLY THE BOUNDARY CONDITIONS AS CONSTRAINTS
      UX(1)=0.
      UX(N)=-B
C...
C...  COMPUTE THE DERIVATIVE UXX
      IF((NORUN.EQ.1).OR.(NORUN.EQ.2))CALL DSS002(0.,XL,N,UX,UXX)
      IF((NORUN.EQ.3).OR.(NORUN.EQ.4))CALL DSS004(0.,XL,N,UX,UXX)
C...
C...  ASSEMBLE THE PDE
      DO 1 I=1,N
      UT(I)=A*UXX(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21)
     4      /C/         A,         B,        XL,         N,        IP
C...
C...  DIMENSION THE ARRAYS TO STORE THE PLOTTED SOLUTION
      DIMENSION   TP(101),   UP(101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,2)
2     FORMAT(1H ,//,9X,1HT,4X,6HU(0,T),3X,7HU(XL,T),
     1                     3X,7HUX(0,T),2X,8HUX(XL,T))
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,1)T,U(1),U(N),UX(1),UX(N)
1     FORMAT(F10.1,4F10.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      TP(IP)=T
      UP(IP)=U(1)
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,UP)
      WRITE(NO,3)
3     FORMAT(1H ,//,22H U(0,T) (C) VS T (SEC))
      RETURN
      END
THERMAL BONDING OF SOLIDS, 11 GRID POINTS, DSS002
0.        100.      1.
   11 1000    1    1  REL 0.001
THERMAL BONDING OF SOLIDS, 21 GRID POINTS, DSS002
0.        100.      1.
   21 1000    1    1  REL 0.001
THERMAL BONDING OF SOLIDS, 11 GRID POINTS, DSS004
0.        100.      1.
   11 1000    1    1  REL 0.001
THERMAL BONDING OF SOLIDS, 21 GRID POINTS, DSS004
0.        100.      1.
   21 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT17
      SUBROUTINE INITAL
C...
C...  TEMPERATURE RISE FROM MECHANICAL AGITATION OF A FLUID
C...
C...  A STIRRER WITH A POWER CONSUMPTION OF 0.1 KW STIRS 50,000 CM**3 OF
C...  WATER IN A CYLINDRICAL VESSEL (D = 50 CM, H =,100 CM) WITH THE TOP
C...  AND BOTTOM INSULATED.  INITIALLY THE TEMPERATURE OF THE WATER AND
C...  SURROUNDING AIR IS THE SAME AND EQUAL TO 20 C.  THE FOLLOWING
C...  PROGRAMMING COMPUTES THE WATER TEMPERATURE WITH TIME.  THE RESIS-
C...  TANCE TO HEAT TRANSFER OF THE WATER AND METAL OF THE VESSEL IS
C...  ASSUMED NEGLIGIBLE.  THE HEAT TRANSFER COEFFICIENT OF THE AIR
C...  INSIDE AND OUTSIDE THE VESSEL IS 11.36 J/(SEC-M**2-C).
C...
C...  ASSUMPTIONS
C...
C...     (1)  ALL MECHANICAL ENERGY IS TRANSFERRED TO THE LIQUID
C...
C...     (2)  EVAPORATION IS NEGLIGIBLE
C...
C...     (3)  MIXING OF THE LIQUID IS ESSENTIALLY PERFECT
C...
C...     (4)  PHYSICAL PROPERTIES ARE CONSTANT
C...
C...     (5)  HEAT CAPACITY OF THE METAL IS NEGLIGIBLE
C...
C...     (6)  OUTSIDE AIR REMAINS AT 20 C
C...
C...     (7)  PRESSURE INSIDE THE VESSEL IS CONSTANT
C...
C...  THE DESCRIPTIVE EQUATIONS ARE
C...
C...     LIQUID ENERGY BALANCE
C...
C...     D(RHOW*VW*CPW*TW)/DT =
C...                                                                 (1)
C...        HAO*AWAO*(TAO - TW) + HAI*AWAI*(TAI - TW) + WSR
C...
C...     AIR (INSIDE THE VESSEL) ENERGY BALANCE
C...
C...     D(RHOAI*VAI*CVA*TAI)/DT =
C...
C...        HAI*AWAI*(TW - TAI) +                                    (2)
C...
C...        (HAO*HAI)/(HAO+HAI)*AAOAI*(TAO - TAI)
C...
C...  WHERE
C...
C...     CPA - CVA = R/MA
C...
C...     1/(U*AI) = 1/(HAO*AAO) + 1/(HAI*AI) WITH CANCELLATION OF THE
C...     AREAS AI, AAO AND AI
C...
C...     RHOW      DENSITY OF WATER (KG/M***3)
C...
C...     RHOAI     DENSITY OF THE INSIDE AIR (KG/M**3)
C...
C...     TW        WATER TEMPERATURE (C)
C...
C...     TAI       TEMPERATURE OF THE INSIDE AIR (C)
C...
C...     TAO       TEMPERATURE OF THE OUTSIDE AIR (C)
C...
C...     AWAI      HEAT TRANSFER AREA, WATER TO INSIDE AIR (M**2)
C...
C...     AWAO      HEAT TRANSFER AREA, WATER TO OUTSIDE AIR (M**2)
C...
C...     AAOAI     HEAT TRANSFER AREA, INSIDE AIR TO OUTSIDE AIR (M**2)
C...
C...     HAI       HEAT TRANSFER COEFFICIENT, INSIDE AIR (J/SEC-M**2-C)
C...
C...     HAO       HEAT TRANSFER COEFFICIENT, OUTSIDE AIR (J/SEC-M**2-C)
C...
C...     VW        VOLUME OF WATER (M**3)
C...
C...     VAI       VOLUME OF INSIDE AIR (M**3)
C...
C...     WSR       ENERGY INPUT RATE FROM THE STIRRER (J/SEC)
C...
C...     CPW       CONSTANT PRESSURE SPECIFIC HEAT OF WATER (J/KG-C)
C...
C...     CVA       CONSTANT VOLUME SPECIFIC HEAT OF AIR (J/KG-C)
C...
C...  THE UNITS IN THE INDIVIDUAL TERMS OF EQUATIONS (1) AND (2) ARE
C...
C...     D(RHOW*VW*CPW*TW)/DT = (1/SEC)*(KG/M**3)*(M**3)*(J/KG-C)
C...
C...                          = J/SEC
C...
C...     HAO*AWAO*(TAO - TW) = (J/SEC-M**2-C)*(M**2)*C = J/SEC
C...
C...     HAI*AWAI*(TAI - TW) = (J/SEC-M**2-C)*(M**2)*C = J/SEC
C...
C...     WSR = J/SEC
C...
C...  THE MODEL PARAMETERS ARE
C...
C...     TAO = 20 C
C...
C...     VW = 5.0E-2 M**3
C...
C...     RHOW = 1000 KG/M**3
C...
C...     WSR = 1OO J/SEC
C...
C...     AWAI = (PI/4)*(0.5**2) = 0.196 M**2
C...
C...     CVA = 7.5E+02 J/KG-C
C...
C...     HAI = HAO = 11.3 J/SEC-M**2-C
C...
C...     HW = 5.0E-02/((PI/4)*(0.5**2)) = 0.255 M
C...
C...     CPW = 4.18E+03 J/KG-C
C...
C...     AWAO = PI*0.5*0.255 = 0.40 M**2
C...
C...     AAOAI = PI*0.5*0.745 = 1.17 M**2
C...
C...     VAI = (PI/4)*(0.5**2)*0.745 = 0.146 M**3
C...
C...     RHOAI = 352/(TAI + 273.16) KG/M**3
C...
C...  SUBSTITUTION OF THESE PARAMETERS IN EQUATIONS (1) AND (2) GIVES
C...
C...     2.09E+05*DTW/DT = 4.52*(20 - TW) + 2.21*(TAI - TW) + 100    (3)
C...
C...     3.85E+04*D(TAI/(TAI+273.16))/DT =  2.21*(TW - TAI)
C...                                                                 (4)
C...                                     +  6.61*(20 - TAI)
C...
C...  THE GROUP TAI/(TAI+273.16) IS REPRESENTED IN THE FOLLOWING PROGRAM
C...  BY THE VARIABLE TDV WHICH IS THE DEPENDENT VARIABLE FOR EQUATION
C...  (4)
C...
C...  THE INITIAL CONDITIONS FOR EQUATIONS (3) AND (4) ARE
C...
C...     TW(0) = 20, TAI(0) = 20 (C0NVERTED TO TDV)                  (5)
C...
C...  FINALLY, THE STEADY STATE SOLUTION TO EQUATIONS (3) AND (4) CAN BE
C...  COMPUTED BY SETTING THE DERIVATIVES TO ZERO, I.E.,
C...
C...     0 = 4.52*(20 - TW) + 2.21*(TAI - TW) + 100
C...
C...     0 = 2.21*(TW - TAI) + 6.61*(20 - TAI)
C...
C...  THE SOLUTION TO THESE TWO STEADY STATE EQUATIONS IS
C...
C...     TW = 36.19, TAI = 24.06
C...
C...  THE DYNAMIC SOLUTION PRODUCED BY THE FOLLOWING PROGRAM SHOULD
C...  APPROACH THESE STEADY STATE VALUES FOR LARGE T.
C...
C...  THREE RUNS ARE PROGRAMMED AS LISTED BELOW.  THIS REPETITION OF
C...  THE CALCULATIONS WAS PROMPTED BY THE RATHER *RAGGED* APPEARANCE
C...  OF THE DERIVATIVE DTDVDT (SEE COMMON/F/) FOR A RELATIVE ERROR
C...  OF 0.001 (FROM THE FIRST RUN).  THE THREE RUNS ARE IDENTICAL
C...  EXCEPT FOR THE SPECIFICATION OF THE ERROR TOLERANCE AND INTE-
C...  GRATOR ON THE THIRD DATA CARD OF EACH RUN
C...
C...     RUN 1 - INTEGRATION ERROR - 0.001 RELATIVE
C...             INTEGRATOR - 1
C...
C...     RUN 2 - INTEGRATION ERROR - 0.000001 RELATIVE
C...             INTEGRATOR - 1
C...
C...     RUN 3 - INTEGRATION ERROR - 0.000001 RELATIVE
C...             INTEGRATOR - 14
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     TW,    TDV
     2      /F/  DTWDT, DTDVDT
     3      /C/    TAI,     IP
C...
C...  SET THE MODEL INITIAL CONDITIONS
      TW=20.
      TAI=20.
      TDV=TAI/(TAI+273.16)
C...
C...  INITIALIZE THE DERIVATIVE CALCULATIONS
      CALL DERV
C...
C...  INITIALIZE A COUNTER FOR THE PLOTTED OUTPUT
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     TW,    TDV
     2      /F/  DTWDT, DTDVDT
     3      /C/    TAI,     IP
C...
C...  MODEL ALGEBRA
      TAI=273.16*TDV/(1.-TDV)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DTWDT =(1./2.09E+05)*(2.21*(TAI-TW)+4.52*(20.0-TW)+100.0)
      DTDVDT=(1./3.85E+04)*(2.21*(TW-TAI)+6.61*(20.0-TAI))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     TW,    TDV
     2      /F/  DTWDT, DTDVDT
     3      /C/    TAI,     IP
C...
C...  DMENSION THE ARRAYS FOR STORING THE PLOTTED SOLUTION
      DIMENSION TP(51),TEMPP(2,51)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,10X,2HTW,9X,3HTAI,9X,3HTDV,7X,5HDTWDT,9X,6HDTDVDT)
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,TW,TAI,TDV,DTWDT,DTDVDT
2     FORMAT(F10.0,2F12.3,F12.5,F12.7,F15.10)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      IP=IP+1
      TP(IP)=T
      TEMPP(1,IP)=TW
      TEMPP(2,IP)=TAI
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.51)RETURN
      CALL TPLOTS(2,IP,TP,TEMPP)
      WRITE(NO,3)
3     FORMAT(1H ,//,22H 1 - TW   2 - TAI VS T)
      RETURN
      END
HEAT EFFECT FROM MECHANICAL STIRRING
0.         100000.   2000.
    2 1000    1    1  REL 0.001
HEAT EFFECT FROM MECHANICAL STIRRING, STRICT ERROR TOLERANCE
0.         100000.   2000.
    2 1000    1    1  REL 0.000001
HEAT EFFECT FROM MECHANICAL STIRRING, ACCURATE INTEGRATOR
0.         100000.   2000.
    2 1000   14    1  REL 0.000001
END OF RUNS
*APP HEAT18
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A REGENERATOR WITH PLOTTING OF THE SPATIAL PROFILES
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS DESCRIBING THE DYNAMICS OF A
C...  DISTRIBUTED REGENERATOR ARE
C...
C...     TF  = -Q/(S*F)TF  - (AV*H)/(F*RHOF*CPF)(TF - TS)            (1)
C...       T             Z
C...
C...     TS  = (AV*H)/((1-F)*RHOS*CPS)(TF - TS)                      (2)
C...       T
C...
C...  WITH AUXILIARY CONDITIONS
C...
C...     TF(0,T) = F(T), TF(Z,0) = TF0, TS(Z,0) = TS0          (3)(4)(5)
C...
C...  WHERE
C...
C...     TF        FLUID TEMPERATURE
C...
C...     TS        SOLID TEMPERATURE
C...
C...     Z         AXIAL POSITION
C...
C...     T         TIME
C...
C...     Q         FLUID VOLUMETRIC FLOW RATE
C...
C...     S         REGENERATOR CROSS SECTIONAL AREA
C...
C...     F         SOLID VOID FRACTION
C...
C...     AV        HEAT TRANSFER AREA BETWEEN THE FLUID AND SOLID PER
C...               UNIT VOLUME OF REGENERATOR
C...
C...     H         HEAT TRANSFER COEFFICIENT
C...
C...     RHOF      FLUID DENSITY
C...
C...     RHOS      SOLID DENSITY
C...
C...     CPF       FLUID HEAT CAPACITY
C...
C...     CPS       SOLID HEAT CAPACITY
C...
C...     TF0       INITIAL FLUID TEMPERATURE
C...
C...     TS0       INITIAL SOLID TEMPERATURE
C...
C...     F(T)      ENTERING FLUID TEMPERATURE AS A FUNCTION OF TIME (FOR
C...               THE FOLLOWING ANALYSIS, F(T) = TFE, A CONSTANT INLET
C...               TEMPERATURE)
C...
C...  TO SIMPLIFY THE ANALYSIS, THE FOLLOWING CONSTANTS ARE DEFINED
C...
C...     A = Q/(S*F*DZ), B = (AV*H)/(F*RHOF*CPF)
C...
C...     C = (AV*H)/((1-F)*RHOS*CPS)
C...
C...  IN THE ANALYSIS WHICH FOLLOWS, THESE CONSTANTS ARE GIVEN THE
C...  NUMERICAL VALUES A = B = C = 1.
C...
C...  THE FLUID AND SOLID TEMPERATURES, TF(0,T), TS(0,T), TF(ZL,T) AND
C...  TS(ZL,T), ARE PLOTTED AS A FUNCTION OF TIME IN SUBROUTINE PRINT.
C...  ALSO, THE SPATIAL PROFILES, TF(Z,T) AND TS(Z,T), T = 0, 25, 50
C...  AND 75 ARE PLOTTED IN SUBROUTINE PRINT.
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
C...
C...  THE REGENERATOR IS SIMULATED BY THE NUMERICAL METHOD OF LINES
C...  IN WHICH THE SPATIAL DERIVATIVE TF  IS REPLACED WITH A FIRST-
C...                                    Z
C...  ORDER, TWO-POINT DIFFERENCE.  THIS IS IN EFFECT SIMULATING
C...  THE REGENERATOR WITH 20 PERFECTLY MIXED SECTIONS.
C...
C...  SET THE MODEL PARAMETERS
      N=21
      ZL=20.
      DZ=1.
      TF0=20.
      TS0=20.
      TFE=500.
      A=1.
      B=1.
      C=1.
C...
C...  SET THE MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      TF(I)=TF0
      TS(I)=TS0
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
C...
C...  IMPLEMENT THE BOUNDARY CONDITION
      TF(1)=TFE
      DTFDT(1)=0.
C...
C...  THE NMOL ODES ARE PROGRAMMED EXPLICITLY
1     DO 11 I=1,N
      DTSDT(I)=C*(TF(I)-TS(I))
      IF(I.EQ.1)GO TO 11
      DTFDT(I)=A*(TF(I-1)-TF(I))+B*(TS(I)-TF(I))
11    CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(21),    TS(21)
     2      /F/ DTFDT(21), DTSDT(21)
     3      /S/ DTFDZ(21)
     4      /C/         A,         B,         C,       TF0,       TS0,
     5                TFE,         N,        DZ,        ZL,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE TIME PLOTS
      DIMENSION TP(4,101), TIME(101)
C...
C...  DIMENSION THE ARRAYS FOR THE SPATIAL PROFILES
      DIMENSION  TZ(8,21),    ZP(21)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IF(T.LT.0.5)WRITE(NO,1)
1     FORMAT(9X,1HT,5X,7HTF(0,T),5X,7HTS(0,T),4X,8HTF(ZL,T),4X,8HTS(ZL,T
     1))
C...
C...  PRINT THE NUMERICAL SOLUTION AT Z = 0, ZL
      WRITE(NO,2)T,TF(1),TS(1),TF(N),TS(N)
2     FORMAT(F10.2,4F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR THE TIME PLOTS
      IP=IP+1
      TP(1,IP)=TF(1)
      TP(2,IP)=TS(1)
      TP(3,IP)=TF(N)
      TP(4,IP)=TS(N)
      TIME(IP)=T
C...
C...  STORE THE NUMERICAL SOLUTION FOR THE SPATIAL PROFILES
C...  AT T = 0, 25, 50, 75
      IF((IP-1)*(IP-26)*(IP-51)*(IP-76).NE.0)GO TO 5
      IF(IP.EQ.  1)NSP=1
      IF(IP.EQ. 26)NSP=3
      IF(IP.EQ. 51)NSP=5
      IF(IP.EQ. 76)NSP=7
      DO 4 IZ=1,N
      TZ(NSP  ,IZ)=TF(IZ)
      TZ(NSP+1,IZ)=TS(IZ)
      ZP(IZ)=FLOAT(IZ-1)*DZ
4     CONTINUE
C...
C...  PLOT THE TIME RESPONSE
5     IF(IP.LT.101)RETURN
      CALL TPLOTS(4,IP,TIME,TP)
C...
C...  LABEL THE TIME PLOT
      WRITE(NO,3)
3     FORMAT(1H ,//,53H 1 - TF(0,T), 2 - TS(0,T), 3 - TF(ZL,T), 4 - TS(Z
     1L,T))
C...
C...  PLOT THE SPATIAL PROFILES
      CALL TPLOTS(8,N,ZP,TZ)
C...
C...  LABEL THE SPATIAL PROFILE PLOT
      WRITE(NO,6)
6     FORMAT(28H 1 - TF(Z, 0)   2 - TS(Z, 0),/,
     1       28H 3 - TF(Z,25)   4 - TS(Z,25),/,
     2       28H 5 - TF(Z,50)   6 - TS(Z,50),/,
     3       28H 7 - TF(Z,75)   8 - TS(Z,75))
      RETURN
      END
DYNAMICS OF A REGENERATOR, EXPLICIT PROGRAMMING OF THE NMOL ODES
0.        100.      1.
   42 1000    8    1  REL 0.001
END OF RUNS
*APP HEAT19
      SUBROUTINE INITAL
C...
C...  TEMPERATURE DISTRIBUTION IN A NUCLEAR FUEL ROD ASSEMBLY
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED FOR THE TEMPERATURE
C...  DISTRIBUTION IN A NUCLEAR FUEL ROD ASSEMBLY
C...
C...  TF  = (KF/(RHOF*CPF))*(TF   + (1/R)*TF ) - (RD*HR/(RHOF*CPF)) (1)
C...    T                      RR           R
C...
C...  TF(R,0) = TF0, TF (0,T) = 0, TF(RF,T) = TA(RF,T)        (2)(3)(4)
C...                   R
C...
C...  TA  = (KA/(RHOA*CPA))*(TA   + (1/R)*TA )                      (5)
C...    T                      RR           R
C...
C...  TA(R,0) = TA0, TA(RA,T) = TC, -KA*TA (RF,T) = -KF*TF (RF,T)
C...                                      R               R
C...                                                          (6)(7)(8)
C...  WHERE
C...
C...  TF(R,T)  FUEL TEMPERATURE, 0 LE R LE RF
C...
C...  TA(R,T)  ALUMINUM CLADDING TEMPERATURE, RF LE R LE RA
C...
C...  R        RADIAL POSITION IN THE ASSEMBLY
C...
C...  T        TIME
C...
C...  TF0      INITIAL FUEL TEMPERATURE
C...
C...  TA0      INITIAL ALUMINUM TEMPERATURE
C...
C...  TC       COOLANT TEMPERATURE
C...
C...  RHOF,    DENSITY, HEAT CAPACITY AND THERMAL CONDUCTIVITY OF
C...  CPF,KF   THE FUEL
C...
C...  RHOA,    DENSITY, HEAT CAPACITY AND THERMAL CONDUCTIVITY OF
C...  CPA,KA   THE ALUMINUM CLADDING
C...
C...  RD,HR    VOLUMETRIC DECAY RATE AND HEAT OF REACTION OF THE
C...           NUCLEAR FUEL
C...
C...  DEVELOP A COMPUTER SIMULATION OF THIS SYSTEM WHICH PRINTS AND
C...  AND PLOTS TF(0,T) AND TA(RF,T) VS T SO THAT THE HEATING OF THE
C...  FUEL AND CLADDING CAN BE DETERMINED.  THE FOLLOWING PARAMETERS
C...  APPLY
C...
C...  RHOF = 0.5, CPF = 0.8, KF = 1.0, RHOA = 1.1, CPA = 0.7, KA = 10,
C...
C...  RD = 0.1, HR = -10000, RF = 2.5, RA = 5.0, TC = 85, TF0 = 25,
C...
C...  TA0 = 25
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(11),    TA(11)
     2      /F/   TFT(11),   TAT(11)
     3      /S/   TFR(11),  TFRR(11),   TAR(11),  TARR(11)
     4      /C/      RFOF,       CPF,        KF,      RHOA,       CPA,
     5                 KA,        RD,        HR,        RF,        RA,
     6                 TC,       TF0,       TA0,    R1(11),    R2(11),
     7                CF1,       CF2,       CA1,        NF,        NA,
     8                 IP
      REAL             KF,        KA
C...
C...  SET THE MODEL PARAMETERS
      RHOF=0.5
      CPF=0.8
      KF=1.0
      RHOA=1.1
      CPA=0.7
      KA=10.
      RD=0.1
      HR=-10000.
      RF=2.5
      RA=5.0
      TC=85.
      TF0=25.
      TA0=25.
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN SUBROUTINE DERV
      CF1=KF/(RHOF*CPF)
      CF2=RD*HR/(RHOF*CPF)
      CA1=KA/(RHOA*CPA)
C...
C...  INITIAL CONDITIONS AND RADIAL GRID FOR THE FUEL
      NF=11
      DO 1 I=1,NF
      TF(I)=TF0
      R1(I)=RF*FLOAT(I-1)/FLOAT(NF-1)
1     CONTINUE
C...
C...  INITIAL CONDITIONS AND RADIAL GRID FOR THE CLADDING
      NA=11
      DO 2 I=1,NA
      TA(I)=TA0
      R2(I)=RF+(RA-RF)*FLOAT(I-1)/FLOAT(NA-1)
2     CONTINUE
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(11),    TA(11)
     2      /F/   TFT(11),   TAT(11)
     3      /S/   TFR(11),  TFRR(11),   TAR(11),  TARR(11)
     4      /C/      RFOF,       CPF,        KF,      RHOA,       CPA,
     5                 KA,        RD,        HR,        RF,        RA,
     6                 TC,       TF0,       TA0,    R1(11),    R2(11),
     7                CF1,       CF2,       CA1,        NF,        NA,
     8                 IP
      REAL             KF,        KA
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN TF
      TF(NF)=TA(1)
      CALL DSS004(0.,RF,NF,TF ,TFR )
      TFR(1)=0.
      CALL DSS004(0.,RF,NF,TFR,TFRR)
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN TA
      TA(NA)=TC
      CALL DSS004(RF,RA,NA,TA ,TAR )
      TAR(1)=(KF/KA)*TFR(NF)
      CALL DSS004(RF,RA,NA,TAR,TARR)
C...
C...  PDE FOR TF
      TFT(1)=CF1*2.*TFRR(1)-CF2
      DO 1 I=2,NF
      TFT(I)=CF1*(TFRR(I)+(1./R1(I))*TFR(I))-CF2
1     CONTINUE
C...
C...  PDE FOR TA
      DO 2 I=1,NA
      TAT(I)=CA1*(TARR(I)+(1./R2(I))*TAR(I))
2     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/    TF(11),    TA(11)
     2      /F/   TFT(11),   TAT(11)
     3      /S/   TFR(11),  TFRR(11),   TAR(11),  TARR(11)
     4      /C/      RFOF,       CPF,        KF,      RHOA,       CPA,
     5                 KA,        RD,        HR,        RF,        RA,
     6                 TC,       TF0,       TA0,    R1(11),    R2(11),
     7                CF1,       CF2,       CA1,        NF,        NA,
     8                 IP
      REAL             KF,        KA
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION     TP(31),   TFP(31),   TAP(31),
     1                     TFPR(7,31),TAPR(7,31)
C...
C...  INITIALIZE COUNTERS FOR THE PLOTTED SOLUTION
      DATA IP,IR/0,0/
C...
C...  PRINT THE NUMERICAL SOLUTION
      IF((IP/5*5).NE.IP)GO TO 10
      NS=2
      WRITE(NO,1)T,
     1 (TF(I),I=1,NF,NS),(TA(I),I=1,NA,NS)
1     FORMAT(1H ,//,5H  T  ,F9.1,/,
     1              5H TF  ,6F12.1,/,
     2              5H TA  ,6F12.1)
C...
C...  PRINT THE TIME DERIVATIVES
      IF(IP.GT.0)GO TO 10
      WRITE(NO,2)(TFT(I),I=1,NF,NS),(TAT(I),I=1,NA,NS)
2     FORMAT(1H ,/, 5H TFT ,6F12.1,/,
     1              5H TAT ,6F12.1)
C...
C...  PRINT THE SPATIAL DERIVATIVES
      WRITE(NO,3)( TFR(I),I=1,NF,NS),( TAR(I),I=1,NA,NS),
     1           (TFRR(I),I=1,NF,NS),(TARR(I),I=1,NA,NS)
3     FORMAT(1H ,/, 5H TFR ,6F12.1,/,
     1              5H TAR ,6F12.1,/,
     2              5H TFRR,6F12.1,/,
     3              5H TARR,6F12.1)
C...
C...  STORE TF(0,T) AND TA(RF,T) FOR PLOTTING
10    IP=IP+1
      TP(IP)=T
      TFP(IP)=TF(1)
      TAP(IP)=TA(1)
      IF((IP-1)/5*5.NE.(IP-1))RETURN
C...
C...  STORE TF(R,T) AND TA(R,T) FOR PLOTTING OF THE TEMPERATURE
C...  PROFILES
      IR=IR+1
      DO 4 I=1,NF
      TFPR(IR,I)=TF(I)
4     CONTINUE
      DO 5 I=1,NA
      TAPR(IR,I)=TA(I)
5     CONTINUE
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.31)RETURN
      CALL TPLOTS(1,IP,TP,TFP)
      WRITE(NO,11)
11    FORMAT(1H ,//,41H TF(0,T) VS T                            )
      CALL TPLOTS(1,IP,TP,TAP)
      WRITE(NO,12)
12    FORMAT(1H ,//,41H TA(RF,T) VS T                           )
      CALL TPLOTS(IR,NF,R1,TFPR)
      WRITE(NO,13)
13    FORMAT(1H ,//,41H TF(R,T) VS R, T = 0, 5, 10, ..., 30     )
      CALL TPLOTS(IR,NA,R2,TAPR)
      WRITE(NO,14)
14    FORMAT(1H ,//,41H TA(R,T) VS R, T = 0, 5, 10, ..., 30     )
      IP=0
      IR=0
      RETURN
      END
TEMPERATURES IN A NUCLEAR FUEL ROD ASSEMBLY
0.        3.0       0.1
   22 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT20
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) MODEL A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 25, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   VT = 1, VS = 0.5, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE EXITING TEMPERATURES, T3(XL,T) AND TS(0,T), ARE OF PARTICULAR
C...  INTEREST IN THIS SIMULATION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      VS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         VS,
     5                 CT,        CS,       TS0,          N,
     6             XP(11),        IP,       ISP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101), TSP(101),   TP(101),
     1          T1SP(7,11),          T2SP(7,11),
     2          T3SP(7,11),          TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     1              4X,8HT3(XL,T),4X,8H TS(0,T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1)
2     FORMAT(F10.1,4F12.1)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,10)
10    FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,11)
11    FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 10,... 50)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 10,... 50)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        50.       0.5
   44 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT21
      SUBROUTINE INITAL
C...
C...  EVAPORATION FROM A TANK
C...
C...  EVAPORATION FROM A TANK DEPICTED BELOW IS TO BE SIMULATED
C...
C...                                          CONVECTION
C...                         EVAPORATION         AND
C...                              +         . RADIATION
C...  AMBIENT TEMPERATURE = TA   .         .
C...  AMBIENT HUMIDITY = YA     .         .
C...                           .         .
C...              + .    TF   .         +   YI   .
C...              . ..............................
C...              . .                            .
C...              . .                            .
C...              Z .             TF             .+...........
C...              . .                            .           .
C...              . .                            .           .
C...              . .                            .           .
C...              + ..............................           .
C...                              .         RECIRCULATION .......
C...                              .              PUMP     .     .
C...                              .                       .......
C...                              .                          +
C...                              ............................
C...
C...  THE LIQUID (WATER) IN THE TANK CAN BE ASSUMED TO BE AT A UNIFORM
C...  TEMPERATURE, TF, THROUGHOUT THE TANK (PERFECTLY MIXED).
C...
C...  AN ENERGY BALANCE ON THE TANK GIVES
C...
C...     D(V*RHO*CP*TF)/DT = -KY*A*HVAP*(YI - YA) + H*A*(TA - TF)
C...                                                                (1)
C...                        + U*P*Z*(TA - TF)
C...
C...  WHERE
C...
C...     TF     TEMPERATURE OF LIQUID IN THE TANK
C...
C...     TA     AMBIENT TEMPERATURE
C...
C...     YA     AMBIENT HUMIDITY
C...
C...     YI     HUMIDITY AT THE LIQUID SURFACE (SATURATION HUMIDITY
C...            AT TEMPERATURE TF)
C...
C...     T      TIME
C...
C...     V      VOLUME OF LIQUID IN THE TANK
C...
C...     RHO    LIQUID DENSITY
C...
C...     CP     LIQUID HEAT CAPACITY
C...
C...     KY     MASS TRANSFER COEFFICIENT FOR EVAPORATION
C...
C...     A      TANK CROSS SECTIONAL AREA (AREA FOR HEAT AND MASS
C...            TRANSFER FROM THE SURFACE OF THE LIQUID TO THE
C...            SURROUNDING AIR)
C...
C...     HVAP   HEAT OF VAPORIZATION OF THE LIQUID
C...
C...     H      COEFFICIENT FOR HEAT TRANSFER FROM THE LIQUID SURFACE
C...
C...     U      COEFFICIENT FOR HEAT TRANSFER FROM THE WALL OF THE TANK
C...
C...     P      PERIMETER OF THE TANK
C...
C...     Z      HEIGHT OF THE TANK
C...
C...  THE INITIAL CONDITION FOR EQUATION (1) IS
C...
C...     TF(0) = 65 F                                               (2)
C...
C...  TWO CASES ARE PROGRAMMED
C...
C...     (1)  THE AMBIENT TEMPERATURE AND HUMIDITY, TA AND YA, ARE
C...          CONSTANT AT 80 F AND 44 PERCENT, RESPECTIVELY.
C...
C...     (2)  THE AMBIENT TEMPERATURE AND HUMIDITY, TA AND YA, VARY
C...          SINUSOIDALLY WITH TIME, WITH THE PERIOD OF OSCILLATION
C...          APPROXIMATELY 24 HOURS TO REFLECT NORMAL DAILY VARIATIONS
C...          AROUND THE CONSTANT LEVELS OF CASE (1).
C...
C...  THE VAPOR PRESSURE OF WATER IS GIVEN BY THE EQUATION
C...
C...     PV = 51.7*3206.7*EXP(6.53247 - 7173.79/(T + 389.4747))     (3)
C...
C...  WHICH IS USED IN THE CALCUATION OF THE HUMIDITIES, YA AND YI
C...  (SEE THE CODING IN SUBROUTINE DERV FOR THE DETAILS).  T IS THE
C...  TEMPERATURE IN F (T = TA OR TF WHEN THE AMBIENT HUMIDITY OR
C...  HUMIDITY AT THE LIQUID SURFACE ARE COMPUTED, RESPECTIVELY).
C...
C...  PLOTTING OF THE NUMERICAL SOLUTION IN SUBROUTINE PRINT GIVES AN
C...  INDICATION OF HOW TF AND YI VARY WITH TIME, PARTICULARLY FOR THE
C...  SECOND CASE (SINUSOIDAL VARIATION OF TA AND YA).
C...
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  SET THE MODEL PARAMETERS
      V=808.
      RHO=62.3
      CP=1.0
      KYA=7.69*200.
      H=2.0
      A=200.
      U=H
      P=60.
      Z=4.
      HVAP=970.
C...
C...  SET THE MODEL INITIAL CONDITION
      TF=65.
C...
C...  COMPUTE THE INITIAL DERIVATIVE
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  AMBIENT TEMPERATURE
      TA=TAMB(T)
C...
C...  VAPOR PRESSURE IN ATMOSPHERES AT TEMPERATURES TF AND TA
      PVTF=51.7*3206.7*EXP(6.53247-7173.79/(TF+389.4747))/760.0
      PVTA=51.7*3206.7*EXP(6.53247-7173.79/(TA+389.4747))/760.0
C...
C...  CONVERSION OF PERCENT RELATIVE HUMIDITY TO RELATIVE HUMIDITY
      RH=PRH(T)/100.
C...
C...  HUMIDITIES AS WEIGHT OF WATER/UNIT WEIGHT OF AIR
      YI=PVTF*1./(1.0-PVTF*1.)*18./29.
      YA=PVTA*RH/(1.0-PVTA*RH)*18./29.
C...
C...  MODEL DIFFERENTIAL EQUATION
      DTFDT=(1./(V*RHO*CP))*(-KYA*HVAP*(YI-YA)+H*A*(TA-TF)
     1                     +U*P*Z*(TA-TF))
      RETURN
      END
      FUNCTION TAMB(T)
C...
C...  FUNCTION TAMB COMPUTES THE AMBIENT TEMPERATURE AS A FUNCTION OF
C...  TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=0.
      IF(NORUN.EQ.2)FREQ=4.
      PI=3.1415927
      TAMB=80.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      FUNCTION PRH(T)
C...
C...  FUNCTION PRH COMPUTES THE PERCENT RELATIVE HUMIDITY AS A FUNCTION
C...  OF TIME
C...
      COMMON/T/     D,  NFIN, NORUN
      IF(NORUN.EQ.1)FREQ=0.
      IF(NORUN.EQ.2)FREQ=4.
      PI=3.1415927
      PRH=44.0+10.0*SIN(FREQ*PI*T/50.)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/     T,  NFIN, NORUN
     1      /Y/    TF
     2      /F/ DTFDT
     3      /C/     V,   RHO,    CP,   KYA,    H,     A,     U,     P,
     4              Z,  HVAP
     5      /V/    YI,    YA,    TA,    RH,   IP
      REAL KYA
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TIMEP(51), TP(2,51), YP(2,51), EP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,1HT,8X,2HTF,4X,6HDTF/DT,8X,2HTA,8X,2HRH,8X,2HYI,8X,2HYA)
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      WRITE(NO,2)T,TF,DTFDT,TA,RH,YI,YA
2     FORMAT(1H ,/,7E10.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TIMEP(IP)=T
      TP(1,IP)=TA
      TP(2,IP)=TF
      YP(1,IP)=YA
      YP(2,IP)=YI
      EP(IP)=KYA*(YI-YA)
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.51)RETURN
C...
C...  TA AND TF VS T
      CALL TPLOTS(2,IP,TIMEP,TP)
      WRITE(NO,11)
11    FORMAT(1H ,//,48H 1 - TA, 2 - TF VS T                            )
C...
C...  YA AND YI VS T
      CALL TPLOTS(2,IP,TIMEP,YP)
      WRITE(NO,12)
12    FORMAT(1H ,//,48H 1 - YA, 2 - YI VS T                            )
C...
C...  KYA*(YI - YA) VS T
      CALL TPLOTS(1,IP,TIMEP,EP)
      WRITE(NO,13)
13    FORMAT(1H ,//,48H KYA*(YI - YA) VS T                             )
      IP=0
      RETURN
      END
EVAPORATION FROM A TANK, CONSTANT TA AND YA
0.        50.       1.
    1 1000    1    1  REL 0.001
EVAPORATION FROM A TANK, SINUSOIDAL TA AND YA
0.        50.       1.
    1 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT22
      SUBROUTINE INITAL
C...
C...  IMPROVEMENT IN THE PERFORMANCE OF A MULTI-PASS HEAT EXCHANGER
C...  FROM ADDING ANOTHER PASS
C...
C...  THE FOLLOWING PARTIAL DIFFERENTIAL EQUATIONS (PDES) MODEL A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(Z,0) = T2(Z,0) = T3(Z,0) = TS(Z,0) = 25
C...
C...   T1(0,T) = 25, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   VT = 1, VS = 0.5, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE EXITING TEMPERATURES, T3(XL,T) AND TS(0,T), ARE OF PARTICULAR
C...  INTEREST IN THIS SIMULATION.  ALSO, THE POSSIBILITY OF RAISING THE
C...  EXITING TUBE TEMPERATURE BY ADDING A FOURTH TUBE PASS IS TO BE IN-
C...  VESTIGATED.  THUS, FOR THIS CASE, ANOTHER PDE WILL BE ADDED TO THE
C...  MODEL
C...
C...   T4  - VT*T4  = CT*(TS - T4)
C...     T        X
C...
C...   T4(X,0) = 25, T4(XL,T) = T3(XL,T)
C...
C...  AND THE PDE FOR THE SHELL WILL BE MODIFIED TO INCLUDE THE HEAT
C...  TRANSFER TERM FOR THE FOURTH PASS
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS) + (T4 - TS))
C...     T        X
C...
C...  THREE RUNS ARE PROGRAMMED IN THE FOLLOWING CODING
C...
C...     (1)  THREE-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 1.0
C...
C...     (2)  FOUR-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 1.0
C...
C...     (3)  FOUR-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 0.5
C...
C...  CHANGES IN THE CODING FOR THESE THREE CASES ARE PROGRAMMED WITH
C...  NORUN IN COMMON/T/.  CASES (2) AND (3) ARE INTENDED TO DETERMINE
C...  IF ADDING A FOURTH TUBE PASS WILL INCREASE THE TEMPERATURE OF THE
C...  EXITING TUBE SIDE TEMPERATURE.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),     T4(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    T4T(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11),    T4X(11)
     4      /C/        T0,        XL,        VT,         VS,         CT,
     5                 CS,       TS0,         N,         IP
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      IF(NORUN.EQ.3)VT=0.5
      VS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
      T4(I)=T0
1     CONTINUE
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),     T4(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    T4T(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11),    T4X(11)
     4      /C/        T0,        XL,        VT,         VS,         CT,
     5                 CS,       TS0,         N,         IP
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
      T4(N)=T3(N)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
      CALL DSS020(0.,XL,N,T4,T4X,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
      IF(NORUN.EQ.1)GO TO 1
      TST(I)=TST(I)+CS*(T4(I)-TS(I))
      T4T(I)= VT*T4X(I)+CT*(TS(I)-T4(I))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      T4T(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),     T4(11)
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    T4T(11)
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11),    T4X(11)
     4      /C/        T0,        XL,        VT,         VS,         CT,
     5                 CS,       TS0,         N,         IP
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))RETURN
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     1              4X,8HT3(XL,T),4X,8H TS(0,T),
     2              4X,8H T4(0,T))
C...
C...  PRINT THE SOLUTION
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),T4(1)
2     FORMAT(F10.1,5F12.1)
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 1.0
0.        100.      1.0
   44 1000    1    1  REL 0.001
FOUR-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 1.0
0.        100.      1.0
   55 1000    1    1  REL 0.001
FOUR-PASS SHELL AND TUBE HEAT EXCHANGER, VT = 0.5
0.        100.      1.0
   55 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT23
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=0.1
         TI=30.0
      ELSE
      END IF
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      QS=QSS+KC*(E+(1./TI)*EI)
      IF(QS.LT.0.)QS=0.
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  QSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      QSP(IP)=QS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QSP,IP,3H*T*,10H* QS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT24
      SUBROUTINE INITAL
C...
C...  PARAMETER ESTIMATION IN HEAT TRANSFER SYSTEMS
C...
C...  THE FOLLOWING PROGRAMMING ILLUSTRATES A METHOD BY WHICH PARAMETERS
C...  CAN BE ESTIMATED IN HEAT TRANSFER SYSTEMS.  SPECIFICALLY, THE HEAT
C...  TRANSFER COEFFICIENT OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER
C...  IS TO BE ESTIMATED FROM THE STEADY STATE INLET AND OUTLET TEMPERA-
C...  TURES.
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS WHICH MODEL THE HEAT EXCHANGER
C...  ARE
C...
C...   T1  + VT*T1  = UT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = UT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = UT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = US*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   UT,US      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  NOTE THAT THE ESTIMATION PROCEDURE IS BASED ON THE USE OF A
C...  DYNAMIC MODEL FOR THE HEAT EXCHANGER WHICH WILL CONVERGE TO THE
C...  GIVEN STEADY STATE INLET AND OUTLET TEMPERATURES.
C...
C...  UT AND US ARE A GROUP OF CONSTANTS FOR THE TUBE AND SHELL SIDES,
C...  RESPECTIVELY, WHICH CONTAIN THE OVERALL HEAT TRANSFER COEFFI-
C...  CIENT.  UT AND US ARE TO BE ESTIMATED FROM THE STEADY STATE INLET
C...  AND OUTLET TEMPERATURES OF THE HEAT EXCHANGER, INDICATED BELOW
C...  BELOW, ALONG WITH THE OTHER PARAMETERS OF THE EXCHANGER
C...
C...     INLET TEMPERATURES
C...
C...        T1(0,T) = 100, TS(XL,T) = 220
C...
C...     OUTLET TEMPERATURES
C...
C...        T3(XL,T) = 170
C...
C...        AT STEADY STATE, THE OTHER OUTLET TEMPERATURE, TS(O,T),
C...        IS SET BY THE OVERALL HEAT BALANCE FOR THE EXCHANGER
C...
C...        VT*(T3(XL,T) - T1(0,T)) = VS*(TS(XL,T) - TS(0,T))
C...
C...        TWO CASES ARE PROGRAMMED
C...
C...        (1)  VS = 1
C...
C...             FOR VT = 1, FROM THE OVERALL ENERGY BALANCE,
C...
C...             TS(0,T) = 150
C...
C...        (2)  VS = 0.5
C...
C...             FOR VT = 1, FROM THE OVERALL ENERGY BALANCE,
C...
C...             TS(0,T) = 80
C...
C...     OTHER PARAMETERS
C...
C...        XL = 10, N = 11
C...
C...  FOR CASE (1), VS = 1, THE OUTLET TEMPERATURE TS(0,T) = 150 IS
C...  PHYSICALLY REALIZABLE AND THEREFORE THE ESTIMATION OF THE HEAT
C...  TRANSFER COEFFICIENT IS POSSIBLE.  FOR CASE (2), VS = 0.5, THE
C...  OUTLET TEMPERATURE TS(0,T) = 80 IS PHYSICALLY UNREALIZABLE SINCE
C...  IT IS BELOW BOTH ENTERING TEMPERATURES.  THE PARAMETER ESTIMATION
C...  WILL STILL EXECUTE, BUT THE FINAL HEAT TRANSFER COEFFICIENT GIVES
C...  AN OUTLET TEMPERATURE, TS(0,T), WHICH DOES NOT SATISFY THE OVER-
C...  ALL ENERGY BALANCE.  CASE (2) WAS INCLUDED TO DEMONSTRATE A PIT-
C...  FALL THAT CAN OCCUR IN PARAMETER ESTIMATION, I.E., THE ESTIMATED
C...  PARAMETER MIGHT APPEAR REASONABLE, BUT ONE OR BASIC REQUIREMENTS
C...  OF THE RESULTING MODEL HAS BEEN VIOLATED, IN THIS CASE, THE OVER-
C...  ALL ENERGY BALANCE.
C...
C...  THE BOUNDARY CONDITIONS FOR THE PDES ARE (IN ADDITION TO THE INLET
C...  TEMPERATURE CONDITIONS
C...
C...        T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...  THE INITIAL CONDITIONS FOR THE DYNAMIC MODEL ARE TAKEN AS
C...
C...        T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...  THESE INITIAL CONDITIONS ARE SELECTED ARBITRARILY, AND HAVE NO
C...  EFFECT ON THE FINAL STEADY STATE OF THE MODEL.
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T), IS COMPARED WITH THE DESIR-
C...  ED VALUE, 170.  THE DIFFERENCE OR ERROR, E = 170 - T3(XL,T), IS
C...  USED TO ADJUST UT ACCORDING TO THE EQUATION
C...
C...                                   T
C...        UT = UTE + KC*(E + (1/TI)*INT E*DT)
C...                                   0
C...
C...  WHERE
C...
C...     UT       VALUE OF UT FROM THE PARAMETER ESTIMATION ALGORITHM
C...
C...     UTE      INITIAL ESTIMATE OF UT
C...
C...     E        ERROR IN THE OUTLET TUBE TEMPERATURE = 170 - T3(XL,T)
C...
C...     KC       GAIN OF THE PARAMETER ESTIMATION EQUATION
C...
C...     TI       INTEGRAL TIME OF THE PARAMETER ESTIMATION EQUATION
C...
C...  THE EQUATION FOR UT WILL ADJUST UT UNTIL THE ERROR, E, IS REDUCED
C...  TO ZERO CORRESPONDING TO THE CORRECT OUTLET TUBE TEMPERATURE.
C...  AT THIS POINT, THE OUTLET SHELL TEMPERATURE, TS(0,T), SHOULD HAVE
C...  THE CORRECT VALUE (FOR CASE (1), WHILE FOR CASE (2), THE OVERALL
C...  HEAT BALANCE WILL NOT BE SATISFIED).
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,       TS0,        VT,         VS,
     5                 UT,        US,       UTE,         KC,
     6                 TI,     T3SET,        XL,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      TS0=220.
      VT=1.0
      IF(NORUN.EQ.1)VS=1.0
      IF(NORUN.EQ.2)VS=0.5
      XL=10.
      N=11
      IP=0
C...
C...  SET THE INITIAL ESTIMATE OF UT
      UTE=0.5
C...
C...  DEFINE THE REMAINDER OF THE PARAMETER ESTIMATION ALGORITHM
      KC=0.05
      TI=100.
      T3SET=170.
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,       TS0,        VT,         VS,
     5                 UT,        US,       UTE,         KC,
     6                 TI,     T3SET,        XL,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  PARAMETER ADJUSTMENT
      E=T3SET-T3(N)
      UT=UTE+KC*(E+(1./TI)*EI)
      IF(UT.LT.0.)UT=0.
C...
C...  US AND UT ARE RELATED BY A SINGLE PROPORTIONALITY CONSTANT, A,
C...  I.E., US = A*UT, WHICH INCLUDES THE RATIO OF THE TOTAL TUBE CROSS
C...  SECTIONAL AREA TO THE TOTAL SHELL CROSS SECTIONAL AREA (FOR FLOW
C...  IN BOTH CASES).  FOR A GIVEN HEAT EXCHANGER, THIS PROPORTIONALITY
C...  CONSTANT IS DEFINED BY THE EXCHANGER DIMENSIONS AND GEOMETRY.  IN
C...  THE PRESENT CASE, FOR SIMPLICITY, WE WILL TAKE A = 1
      US=UT
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+UT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+UT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+UT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+US*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,       TS0,        VT,         VS,
     5                 UT,        US,       UTE,         KC,
     6                 TI,     T3SET,        XL,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  UTP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   UT(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),UT
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      UTP(IP)=UT
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,UTP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H UT VS T                       )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 60,.. 300)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 60,.. 300)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 60,.. 300)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 60,.. 300)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,UTP,IP,3H*T*,10H* UT(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        300.      3.0
   45 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        300.      3.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT25
      SUBROUTINE INITAL
C...
C...  ULTIMATE GAIN OF A FEEDBACK CONTROL SYSTEM
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  OF PARTICULAR INTEREST IN THIS STUDY IS THE ULTI-
C...  MATE GAIN OF THE CONTROLLER, I.E., THE VALUE OF THE GAIN FOR
C...  WHICH THE CONTROLLED SYSTEM IS ON THE THRESHOLD OF INSTABILITY
C...  AND THERFORE UNDERGOES SUSTAINED OSCILLATION.
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH MODEL THE HEAT
C...  EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      N=11
      IP=0
C...
C...  THE FOLLOWING VALUE FOR THE CONTROLLER GAIN WAS DETERMINED BY
C...  TRIAL AND ERROR TO PUT THE SYSTEM NEAR SUSTAINED OSCILLATION.
C...  IT IS THEREFORE AN APPROXIMATE VALUE FOR THE ULTIMATE GAIN,
C...  BUT IT IS NOT A HIGHLY REFINED VALUE (I.E., IT IS ACCURATE TO
C...  ONLY ABOUT ONE FIGURE).  ALSO, THE INTEGRAL ACTION HAS BEEN
C...  ESSENTIALLY REMOVED BY SETTING TI TO A LARGE VALUE.  THE SUS-
C...  TAINED OSCILLATION WHICH RESULTS IS OF SMALL AMPLITUDE (FRACTIONS
C...  OF A DEGREE), AND CAN THEREFORE BEST BE VIEWED WITH A CONTINUOUS
C...  PLOTTER, E.G., THE CALLS TO QIKPLT, RATHER THAN THE LINE PRINTER
C...  PLOTTING, I.E., THE CALLS TO TPLOTS IN SUBROUTINE PRINT.
      KC=0.6
      TI=1.0E+10
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      QS=QSS+KC*(E+(1./TI)*EI)
      IF(QS.LT.0.)QS=0.
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  QSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      QSP(IP)=QS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(XL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,QSP,IP,3H*T*,10H* QS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T1SP,N,3H*X*,10H*T1(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T2SP,N,3H*X*,10H*T2(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,T3SP,N,3H*X*,10H*T3(X,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(XP,TSSP,N,3H*X*,10H*TS(X,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
ULTIMATE GAIN OF A FEEDBACK CONTROL SYSTEM
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT26
      SUBROUTINE INITAL
C...
C...  HEAT CONDUCTION IN A SPHERE
C...
C...  THE FOLLOWING EQUATIONS MODEL HEAT CONDUCTION IN A SPHERE
C...
C...     RHO*CP*TC  = K*(TC  + (2/R)*TC )                            (1)
C...              T        RR          R
C...
C...     T (0,T) = 0, K*T (RO,T) = H*(TA - T(RO,T))               (2)(3)
C...      R              R
C...
C...     T(R,0) = T0                                                 (4)
C...
C...  WHERE
C...
C...     TC      TEMPERATURE (C)
C...
C...     T       TIME (SEC)
C...
C...     R       RADIAL POSITION (M)
C...
C...     RHO     DENSITY (KG/M**3)
C...
C...     CP      HEAT CAPACITY (J/(KG-C))
C...
C...     K       THERMAL CONDUCTIVITY (J-M/(SEC-C-M**2))
C...
C...     RO      RADIUS OF THE SPHERE (M)
C...
C...     H       HEAT TRANSFER COEFFICIENT (J/(SEC-C-M**2))
C...
C...     TA      AMBIENT TEMPERATURE (C)
C...
C...     T0      INITIAL TEMPERATURE (C)
C...
C...  THE FOLLOWING CODING COMPUTES THE SOLUTION TO EQUATIONS (1) TO
C...  (3), T(R,T), AND PLOTS THE TEMPERATURE PROFILES.  ALSO, THE TIME
C...  FOR THE TEMPERATURE T(0,T) TO REACH 60 IS DETERMINED.
C...
C...  TWO RUNS OF THE MODEL ARE PROGRAMMED FOR 11 AND 21 GRID POINTS IN
C...  THE RADIAL POSITION, R.  THUS, BY COMPARING THE TWO SOLUTIONS,
C...  AN INDICATION OF THE ACCURACY IS THE RADIAL DISCRETIZATION CAN
C...  BE GAINED (I.E., CONVERGENCE OF THE SOLUTION WITH RESPECT TO R).
C...
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  TC(21)
     2      /F/ TCT(21)
     3      /S/ TCR(21),TCRR(21)
     4      /C/   R(21),     RHO,      CP,       K,      RO,       H,
     5               TA,      T0,       A,       N,      IP
      REAL            K
C...
C...  SET THE MODEL PARAMETERS
      RHO=8000.
      CP=3000.
      K=50.
      RO=0.1
      H=500.
      TA=30.
      T0=300.
C...
C...  THERMAL DIFFUSIVITY
      A=K/(RHO*CP)
C...
C...  NUMBER OF RADIAL GRID POINTS
      IF(NORUN.EQ.1)N=11
      IF(NORUN.EQ.2)N=21
C...
C...  RADIAL GRID POINTS
      DO 2 I=1,N
      R(I)=RO*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
C...
C...  INITIAL CONDITION
      DO 1 I=1,N
      TC(I)=T0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  TC(21)
     2      /F/ TCT(21)
     3      /S/ TCR(21),TCRR(21)
     4      /C/   R(21),     RHO,      CP,       K,      RO,       H,
     5               TA,      T0,       A,       N,      IP
      REAL            K
C...
C...  COMPUTE THE DERIVATIVE TC
C...                           R
      CALL DSS004(0.,RO,N,TC,TCR)
C...
C...  BOUNDARY CONDITIONS
      TCR(1)=0.
      TCR(N)=(H/K)*(TA-TC(N))
C...
C...  COMPUTE THE DERIVATIVE TC
C...                           RR
      CALL DSS004(0.,RO,N,TCR,TCRR)
C...
C...  PARTIAL DIFFERENTIAL EQUATION
C...
C...     R = 0
         TCT(1)=A*3.*TCRR(1)
C...
C...     R GT 0
         DO 1 I=2,N
         TCT(I)=A*(TCRR(I)+(2./R(I))*TCR(I))
1        CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/       T,   NSTOP,   NORUN
     1      /Y/  TC(21)
     2      /F/ TCT(21)
     3      /S/ TCR(21),TCRR(21)
     4      /C/   R(21),     RHO,      CP,       K,      RO,       H,
     5               TA,      T0,       A,       N,      IP
      REAL            K
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION R1P(11),       TC1P(6,11), R2P(21),       TC2P(6,21)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,2X,10HTC(   0,T),2X,10HTC(0.02,T),
     1              2X,10HTC(0.04,T),2X,10HTC(0.06,T),
     2              2X,10HTC(0.08,T),2X,10HTC(0.10,T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      IF(NORUN.EQ.1)NS=2
      IF(NORUN.EQ.2)NS=4
      WRITE(NO,2)T,(TC(I),I=1,N,NS)
2     FORMAT(F10.0,6F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      DO 3 I=1,N
      IF(NORUN.EQ.1)THEN
        R1P(I)=R(I)
        TC1P(IP,I)=TC(I)
      ELSE
        R2P(I)=R(I)
        TC2P(IP,I)=TC(I)
      END IF
3     CONTINUE
C...
C...  PLOT THE SPATIAL PROFILES
      IF(IP.LT.6)THEN
         RETURN
      ELSE IF(NORUN.EQ.1)THEN
         CALL TPLOTS(IP,N,R1P,TC1P)
         WRITE(NO,5)
5        FORMAT(1H ,//,25H SPATIAL PROFILES, N = 11)
      ELSE
         CALL TPLOTS(IP,N,R2P,TC2P)
         WRITE(NO,6)
6        FORMAT(1H ,//,25H SPATIAL PROFILES, N = 21)
      END IF
      RETURN
      END
HEAT CONDUCTION IN A SPHERE, N = 11
0.         5000.    1000.
   11 1000    1    1  REL 0.001
HEAT CONDUCTION IN A SPHERE, N = 21
0.         5000.    1000.
   21 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT27
      SUBROUTINE INITAL
C...
C...  EFFECT OF SATURATION ON CONTROL SYSTEM PERFORMANCE
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + VT*T1  = CT*(TS - T1)
C...     T        X
C...
C...   T2  - VT*T2  = CT*(TS - T2)
C...     T        X
C...
C...   T3  + VT*T3  = CT*(TS - T3)
C...     T        X
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        X
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   X          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   VT,VS      AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT,CS      CONSTANTS DEFINING THE HEAT TRANSFER RATES TO THE
C...              TUBE SIDE FLUID AND SHELL SIDE FLUID, RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(X,0) = T2(X,0) = T3(X,0) = TS(X,0) = 25
C...
C...   T1(0,T) = 100, T2(XL,T) = T1(XL,T), T3(0,T) = T2(0,T)
C...
C...   TS(XL,T) = 220
C...
C...   QT = 1, AT = 1.0, AS = 1, CT = CS = 0.1, XL = 10, N = 11
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(XL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, QS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     QS = QSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     QT       TUBE SIDE VOLUMETRIC FLOW RATE
C...
C...     AT       TOTAL TUBE CROSS SECTIONAL AREA IN EACH PASS, I.E.,
C...              QT = VT*AT
C...
C...     QS       SHELL SIDE VOLUMETRIC FLOW RATE
C...
C...     AS       SHELL CROSS SECTIONAL AREA, I.E., QS = AS*VS
C...
C...     QSS      SHELL SIDE VOLUMETRIC FLOW RATE AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
C...  OF PARTICULAR INTEREST IN THIS STUDY IS THE EFFECT OF SATURATION
C...  OF THE CONTROL VALVE.  IN OTHER WORDS, THE VALVE HAS A FINITE
C...  CAPACITY WHEN IT IS FULLY OPEN, AND IF THE CONTROL SYSTEM COMMANDS
C...  A GREATER OPENING, THE CONTROL ACTION IS LIMITED BY THE VALVE.
C...
C...  THREE RUNS ARE PROGRAMNMED
C...
C...     (1)  NORUN = 1
C...
C...          THE VALVE HAS UNLIMITED CAPACITY
C...
C...     (2)  NORUN = 2
C...
C...          THE VALVE HAS FOUR TIMES THE CAPACITY OF THE NORMAL STEADY
C...          STATE FLOW
C...
C...     (3)  NORUN = 3
C...
C...          THE VALVE HAS TWO TIMES THE CAPACITY OF THE NORMAL STEADY
C...          STATE FLOW.
C...
C...  FOR EACH RUN, THE INTEGRAL OF THE ABSOLUTE ERROR IS COMPUTED TO
C...  GIVE A MEASURE OF THE OVERALL CONTROL SYSTEM PERFORMANCE.  AT THE
C...  OF THE THIRD RUN, THIS INTEGRATED ERROR IS PLOTTED VS TIME FOR ALL
C...  THREE RUNS SO THE EFFECT OF VALVE SATURATION CAN BE OBSERVED.
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=25.
      XL=10.
      VT=1.0
      QSS=0.5
      CT=0.1
      CS=0.1
      TS0=220.
      T3SET=170.
      KC=0.1
      TI=30.0
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      E1I=0.
      E2I=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=100.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      XP(I)=XL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E1=T3SET-T3(N)
      QS=QSS+KC*(E1+(1./TI)*E1I)
      IF(QS.LT.0.)QS=0.
C...
C...  VALVE SATURATION
C...
C...  NORUN = 1
      IF(NORUN.EQ.1)THEN
         GO TO 10
C...
C...  NORUN = 2
      ELSE IF(NORUN.EQ.2)THEN
         IF(QS.GT.4.0*QSS)QS=4.0*QSS
         GO TO 10
C...
C...  NORUN = 3
      ELSE
         IF(QS.GT.2.0*QSS)QS=2.0*QSS
      END IF
10    CONTINUE
C...
C...  INTEGRAL OF THE ABSOLUTE ERROR
      E2=ABS(E1)
C...
C...  SINCE AS = 1, VS = QS/AS = QS
      VS=QS
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,XL,N,T1,T1X, 1.)
      CALL DSS020(0.,XL,N,T2,T2X,-1.)
      CALL DSS020(0.,XL,N,T3,T3X, 1.)
      CALL DSS020(0.,XL,N,TS,TSX,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)=-VT*T1X(I)+CT*(TS(I)-T1(I))
      T2T(I)= VT*T2X(I)+CT*(TS(I)-T2(I))
      T3T(I)=-VT*T3X(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSX(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),   E1I, E2I
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),    E1,  E2
     3      /S/   T1X(11),   T2X(11),   T3X(11),    TSX(11)
     4      /C/        T0,        XL,        VT,         QS,
     5                 CT,        CS,       TS0,        QSS,
     6                 KC,        TI,     T3SET,     XP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11),
     1          T3P(3,101),TSP(3,101),QSP(3,101),E2P(3,101),
     2             TP(101)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(XL,T),
     14X,8HT3(XL,T),4X,8H TS(0,T),4X,8H   QS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),QS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(NORUN,IP)=T3(N)
      TSP(NORUN,IP)=TS(1)
      QSP(NORUN,IP)=QS
      E2P(NORUN,IP)=E2I
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE PROFILES AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(7,N,XP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(X,T) VS X, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,XP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(X,T) VS X, T = 0, 40,.. 200)
C...
C...  PLOT THE TIME RESPONSES FOR THE THREE CASES (NORUN = 1, 2, 3)
      IF(NORUN.LT.3)RETURN
      CALL TPLOTS(3,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(XL,T) VS T                 )
      CALL TPLOTS(3,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(3,IP,TP,QSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H QS VS T                       )
      CALL TPLOTS(3,IP,TP,E2P)
      WRITE(NO,10)
10    FORMAT(1H ,//,31H INTEGRAL OF ABS(E) VS T       )
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   46 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT28
      SUBROUTINE INITAL
C...
C...  EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
C...
C...  THE FOLLOWING EQUATIONS DESCRIBE THE DYNAMICS OF A HUMIDIFIER
C...  (A PACKED COLUMN WITH WATER AND AIR FLOWING COUNTERCURRENTLY)
C...
C...     Y   = -(V/(G*S))*Y  + (KY*AV/G)*(YS - Y)                  (1)
C...      T                Z
C...
C...     EV  = -(V/(G*S))*EP  + (H*AV/G)*(TL - TG)
C...       T                Z                                      (2)
C...
C...                          + (KY*AV/G)*(YS - Y)*(CVV*TG + DHVAP)
C...
C...     TL  =  (L/(H*S))*TL  - (H*AV/(CL*H))*(TL - TG)
C...       T                Z                                      (3)
C...
C...                          - (KY*AV/(CL*H))*(YS - Y)*(CVV*TG + DHVAP)
C...
C...  THE GAS FLOW RATE, V, IS TO BE CONTROLLED BY A PROPORTIONAL-
C...  INTEGRAL CONTROLLER ACCORDING TO THE EQUATIONS
C...
C...     V = CV*SQRT(DP)*X                                         (4)
C...
C...     X = XSS + KC*(E + (1/TI)INT(E)DT)
C...
C...     E = TL(0,T) - TSET
C...
C...  WHERE
C...
C...     TG      GAS TEMPERATURE (UNITS OF THE MODEL VARIABLES ARE
C...             DEFINED BELOW WITH THE NUMERICAL VALUES OF THE MODEL
C...             PARAMETERS AND AUXILIARY CONDITIONS)
C...
C...     EV      INTERNAL ENERGY OF THE GAS STREAM
C...             = (CVA*TG + Y*(CVV*TG + DHVAP))
C...
C...     EP      ENTHALPHY OF THE GAS STREAM
C...             = (CPA*TG + Y*(CPV*TG + DHVAP))
C...
C...     TL      LIQUID TEMPERATURE
C...
C...     Y       MOLE RATIO OF H20 IN THE GAS
C...
C...     YS      MOLE RATIO OF H20 IN THE GAS WHICH WOULD BE IN
C...             EQUILIBRIUM WITH THE LIQUID AT TEMPERATURE TL
C...
C...     T       TIME
C...
C...     Z       AXIAL POSITION ALONG THE COLUMN
C...
C...     V       DRY AIR MOLAR FLOW RATE
C...
C...     G       DRY AIR MOLAR HOLDUP
C...
C...     S       COLUMN CROSS SECTIONAL AREA
C...
C...     KY      MASS TRANSFER COEFFICIENT
C...
C...     AV      HEAT AND MASS TRANSFER AREAS PER UNIT VOLUME OF
C...             COLUMN
C...
C...     H       HEAT TRANSFER COEFFICIENT
C...
C...     CVV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT VOLUME
C...
C...     CPV     SPECIFIC HEAT OF WATER VAPOR AT CONSTANT PRESSURE
C...
C...     CVA     SPECIFIC HEAT OF DRY AIR AT CONSTANT VOLUME
C...
C...     CPA     SPECIFIC HEAT OF DRY AIR AT CONSTANT PRESSURE
C...
C...     CL      SPECIFIC HEAT OF WATER
C...
C...     L       LIQUID (H20) MOLAR FLOW RATE
C...
C...     H       LIQUID (H20) MOLAR HOLDUP
C...
C...     DHVAP   HEAT OF VAPORIZATION OF WATER
C...
C...     X       CONTROL VALVE STEM POSITION
C...
C...     XSS     X AT STEADY STATE
C...
C...     KC      CONTROLLER GAIN
C...
C...     TI      CONTROLLER INTEGRAL TIME
C...
C...     CVDP    PRODUCT OF THE CONTROL VALVE CONSTANT AND SQUARE
C...             ROOT OF THE PRESSURE DROP ACROSS THE VALVE
C...
C...     TSET    CONTROLLER SET POINT
C...
C...  THE MODEL PARAMETERS AND AUXILIARY CONDITIONS ARE
C...
C...   H*AV = 50 BTU/(HR-FT**3 OF COLUMN-F)
C...
C...   KY*AV = 4.1 LB MOLS DRY AIR/(HR-FT**3 COLUMN)
C...
C...   Z = 8 FT, CL = 18 BTU/(LB MOL-F), DHVAP = 17000 BTU/(LB MOL)
C...
C...   CPV = 7.3 BTU/(LB MOL-F), CPA = 7.3 BTU/(LB MOL-F)
C...
C...   CVV = CPV - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   CVA = CPA - R = 7.3 - 1.987 = 5.3 BTU/(LB MOLS-F)
C...
C...   L = 50 LB MOLS/HR, S = 1 FT**2 COLUMN
C...
C...   H = 0.5 LB MOLS/(FT**3 COLUMN), G = 0.01 LB MOLS/(FT**3 COLUMN)
C...
C...   P = 10**(7.96681 - 3002.4/(378.4 + TL)) MM HG (TL IS IN F)
C...
C...   YS = P/(760 - P) LB MOLS H20/LB MOL DRY AIR
C...
C...   TG(0,T) = 110 F, TL(8,T) = 110 F, Y(0,T) = 0.01 LB MOLS H20/
C...                                              LB MOL DRY AIR)
C...   TG(Z,0) = TL(Z,0) = 110 F, Y(Z,0) = 0.01
C...
C...   KC = 0.02 (1/F), TI = 0.1 HR, CV*(DP**0.5) = 50 LB MOLS/HR,
C...
C...   XSS = 0.5, TSET = 90 F
C...
C...  THE EXITING GAS COMPOSITION AND TEMPERATURE, Y(8,T) AND TG(8,T),
C...  THE EXITING LIQUID TEMPERATURE, TL(0,T), AND THE GAS FLOW RATE,
C...  G, ARE OF PARTICULAR INTEREST IN THIS SIMULATION.
C...
C...  ALSO, THREE RUNS  ARE PROGRAMMED
C...
C...     (1)  KC AND TI ARE SELECTED FOR A WELL-TUNED CONTROLLER
C...          SO THE HUMIDIFICATION COLUMN RESPONDS NEARLY OPTIMALLY
C...          (FAST RESPONSE WITH LITTLE OVERSHOOT).
C...
C...     (2)  PROPORTIONAL CONTROL ONLY WITH THE GAIN NEAR THE
C...          ULTIMATE VALUE FOR SUSTAINED OSCILLATION.
C...
C...     (3)  ONE HALF THE GAIN OF (2) WITH INTEGRAL ACTION ADDED
C...          TO AGAIN PRODUCE NEARLY SUSTAINED OSCILLATION.
C...
C...  AS THE SYSTEM MOVES CLOSER TO SUSTAINED OSCILLATION, I.E., CASES
C...  (2) AND (3), THE TEMPORAL EIGENVALUES COMPUTED BY CALLS TO SUB-
C...  ROUTINE EIGEN IN SUBROUTINE PRINT, SHOULD MOVE CLOSER TO PURE
C...  IMAGINARY VALUES.  THIS EFFECT CAN BE CHECKED BY COMPARING THE
C...  EIGENVALUES COMPUTED AND PRINTED FOR THE THREE RUNS.
C...
C...  THESE THREE RUNS CAN BE RUN CONSECUTIVELY, BUT THE TOTAL RUN
C...  TIME IS RATHER LARGE.  THEREFORE, THEY ARE PROGRAMMED TO RUN
C...  INDIVIDUALLY (SEE THE SUBSEQUENT CODING FOR SETTING KC AND TI
C...  IN SUBROUTINE INITIAL), AND ONLY ONE SET OF DATA IS USED.
C...
C...  COMMON AREA TO ESTABLISH LINKAGE WITH OTHER SUBROUTINES
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  SET THE COLUMN PARAMETERS
      L=50.
      G=0.01
      H=0.5
      HLAV=50.
      KYAV=4.1
      CL=18.
      CPV=7.3
      CPA=7.3
      CVV=5.3
      CVA=5.3
      ZL=8.
      DHVAP=17000.
      S=1.
C...
C...  SET THE CONTROLLER PARAMETERS (NOTE THAT THE CONTROLLER PARA-
C...  METERS ARE SELECTED FOR A SINGLE RUN BY REMOVING COMMENTS
C...  RATHER THAN EXECUTION OF THREE SUCCESSIVE RUNS VIA THE IF-
C...  THEN-ELSE CONSTRUCT)
C...
C...  WELL TUNED CONTROLLER
C...  IF(NORUN.EQ.1)THEN
         KC=0.02
         TI=0.1
C...
C...  ULTIMATE GAIN
C...  ELSE IF(NORUN.EQ.2)THEN
C...     KC=0.4
C...     TI=1.0E+10
C...
C...  ULTIMATE PERIOD (WITH INTEGRAL ACTION)
C...  ELSE
C...     KC=0.2
C...     TI=0.02
C...  END IF
      CVDP=50.
      XSS=0.5
      TSET=90.
      IP=0
      N=11
C...
C...  COMPUTE SOME CONSTANTS FOR USE IN OTHER SUBROUTINES
      P2=KYAV/G
      P3=HLAV/G
      P4=L/(H*S)
      P5=HLAV/(CL*H)
      P6=KYAV/(CL*H)
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      Y(I)=0.01
      TL(I)=110.
      TG(I)=110.
      EV(I)=CVA*TG(I)+Y(I)*(CVV*TG(I)+DHVAP)
1     CONTINUE
      EI=1.0E-05
C...
C...  INITIALIZE THE MODEL DERIVATIVES
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  CONTROLLER EQUATIONS
      E=TL(1)-TSET
      X=XSS+KC*(E+(1./TI)*EI)
      IF(X.LT.0.)X=0.
      IF(X.GT.1.)X=1.
      V=CVDP*X
      P1=V/(G*S)
C...
C...  MODEL ALGEBRA
      DO 1 I=1,N
      TG(I)=(EV(I)-Y(I)*DHVAP)/(CVA+Y(I)*CVV)
      EP(I)=CPA*TG(I)+Y(I)*(CPV*TG(I)+DHVAP)
      P=10.**(7.96681-3002.4/(378.4+TL(I)))
      YS(I)=P/(760.-P)
1     CONTINUE
C...
C...  BOUNDARY CONDITIONS
      Y(1)=0.01
      TL(N)=110.
      TG(1)=110.
      EP(1)=CPA*TG(1)+Y(1)*(CPV*TG(1)+DHVAP)
C...
C...  CONSTRAINTS FOR THE DEPENDENT VARIABLES AND ASSOCIATED
C...  VARIABLES
      DO 3 I=1,N
      IF( Y(I).LT. 0.) Y(I)=0.
      IF(YS(I).LT. 0.)YS(I)=0.
3     CONTINUE
C...
C...  SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N, Y, YZ, 1.)
      CALL DSS020(0.,ZL,N,EP,EPZ, 1.)
      CALL DSS020(0.,ZL,N,TL,TLZ,-1.)
C...
C...  PARTIAL DIFFERENTIAL EQUATIONS
      DO 2 I=1,N
      YT(I)=-P1*YZ(I)+P2*(YS(I)-Y(I))
      P7=CVV*TG(I)+DHVAP
      EVT(I)=-P1*EPZ(I)+P3*(TL(I)-TG(I))+P2*(YS(I)-Y(I))*P7
      TLT(I)= P4*TLZ(I)-P5*(TL(I)-TG(I))-P6*(YS(I)-Y(I))*P7
2     CONTINUE
      YT(1)=0.
      EVT(1)=0.
      TLT(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/  Y(11), EV(11), TL(11),     EI
     2      /F/ YT(11),EVT(11),TLT(11),      E
     3      /S/ YZ(11),EPZ(11),TLZ(11)
     4      /C/      V,      L,      G,      H,   HLAV,   KYAV,
     5              CL,    CPV,    CPA,    CVV,    CVA,     ZL,
     6           DHVAP,      S,     P1,     P2,     P3,     P4,
     7              P5,     P6,     P7, TG(11), EP(11), YS(11),
     8              KC,     TI,   CVDP,    XSS,   TSET,      X,
     9              IP,      N
      REAL           L,   KYAV,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION, INDIVIDUAL TERMS
C...  IN THE PDES
      DIMENSION       TLP(101),       TGP(101),        YP(101),
     1                 VP(101),        XP(101),       ERP(101),
     2                 TP(101),        TEP(11),     TGLP(2,11)
C...
C...  DIMENSION THE ARRAYS FOR SUBROUTINE JMAP AND EIGEN
      DIMENSION       A(34,34),         WF(34),
     1                  SV(34),      SVOLD(34),
     2                   F(34),       FOLD(34)
      COMPLEX       EIGENV(34)
C...
C...  EQUIVALENCE THE STATE VARIABLE VECTOR, S(34), TO THE DEPPENDENT
C...  VARIABLE VECTORS IN COMMON/Y/
      EQUIVALENCE (Y(1),SV(1)),   (YT(1),F(1))
C...
C...  MAP THE ODE JACOBIAN MATRIX AND COMPUTE THE TEMPORAL EIGENVALUES
C...  AT T = 0, 0.25, 0.5 TO OBSERVE THE CHANGE IN THE MODEL STRUCTURE
C...  AND EIGENVALUES DUE TO THE NONLINEARITIES
      IP=IP+1
      IF((IP.NE.1).AND.(IP.NE.51).AND.(IP.NE.101))GO TO 100
      CALL DERV
C...
C...  MAP THE JACOBIAN MATRIX OF THE 34 ODES DEFINED IN COMMON/Y/ AND
C...  /F/
      NODE=34
      CALL JMAP(NODE,A,SV,SVOLD,F,FOLD)
C...
C...  COMPUTE THE TEMPORAL EIGENVALUES OF THE 34 ODES DEFINED IN COMMON
C...  /Y/ AND /F/
      CALL EIGEN(NODE,A,EIGENV,WF)
C...
C...  PLOT TG AND TL VS Z
      DO 24 I=1,N
      TGLP(1,I)=TG(I)
      TGLP(2,I)=TL(I)
      TEP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
24    CONTINUE
      CALL TPLOTS(2,N,TEP,TGLP)
      WRITE(NO,25)T
25    FORMAT(1H ,/,36H 1 - TG(Z,T), 2 - TL(Z,T) VS Z, T = ,F7.3)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING (VS T)
100   TLP(IP)=TL(1)
      TGP(IP)=TG(N)
       YP(IP)= Y(N)
       VP(IP)= V
       XP(IP)= X
      ERP(IP)= E
       TP(IP)= T
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(1,IP,TP,TLP)
      WRITE(NO,101)
101   FORMAT(1H ,/,30H TL(0,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TGP)
      WRITE(NO,102)
102   FORMAT(1H ,/,30H TG(8,T) VS T                 )
      CALL TPLOTS(1,IP,TP, YP)
      WRITE(NO,103)
103   FORMAT(1H ,/,30H Y(8,T) VS T                  )
      CALL TPLOTS(1,IP,TP, VP)
      WRITE(NO,104)
104   FORMAT(1H ,/,30H V(T) VS T                    )
      CALL TPLOTS(1,IP,TP, XP)
      WRITE(NO,105)
105   FORMAT(1H ,/,30H X(T) VS T                    )
      CALL TPLOTS(1,IP,TP,ERP)
      WRITE(NO,106)
106   FORMAT(1H ,/,30H E(T) VS T                    )
C...
C... *******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE MODIFIED FOR OTHER COMPUTERS OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TLP,IP,3H*T*,9H*TL(0,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TGP,IP,3H*T*,9H*TG(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, YP,IP,3H*T*,9H* Y(8,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, VP,IP,3H*T*,9H*  V(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP, XP,IP,3H*T*,9H*  X(T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,ERP,IP,3H*T*,9H*  E(T) *,2H**,1)
C...
C... *******************************************************************
C...
      RETURN
      END
EIGENVALUE STABILITY ANALYSIS OF FEEDBACK CONTROL SYSTEMS
0.        0.5       0.005
   34 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT29
      SUBROUTINE INITAL
C...
C...  CONVECTIVE COOLING OF A MOVING POLYMER SHEET
C...
C...  CONSIDER THE CONVECTIVE COOLING OF A MOVING POLYMER SHEET ILLUS-
C...  TRATED BELOW
C                             +----- DZ -----+
C        ...........................................................
C            +                .              .
C            .                .              .
C            D    V, TP  ----+.    TP(Z,T)   . ----+ V, TP
C            .         AT Z   .              .            AT Z+DZ
C            +                .       .      .
C        ...........................................................
C      Z = 0                  Z       .     Z+DZ                 Z = ZL
C                                     .
C                                     +
C
C                                    TA
C...
C...  AN ENERGY BALANCE ON THE INCREMENTAL SECTION OF THE POLYMER SHEET
C...  GIVES
C...
C...     (DZ*W*D*RHO*CP*TP ) = DZ*W*V*RHO*CP*TP
C...                      T                    AT Z
C...
C...                         - DZ*W*V*RHO*CP*TP
C...                                           AT Z+DZ
C...
C...                         + 2*W*DZ*U*(TA - TP)
C...
C...  THE 2 IN THE HEAT TRANSFER TERM ACCOUNTS FOR COOLING ON BOTH
C...  FLAT SURFACES OF THE POLYMER.
C...
C...  DIVISION BY D*W*DZ*RHO*CP FOLLOWED BY DZ ---+ 0 GIVES
C...
C...     TP  = -V*TP  + 2*U*/(D*CP*RHO)*(TA - TP)                  (1)
C...       T        Z
C...
C...  THE BOUNDARY AND INITIAL CONDITIONS FOR EQUATION (1) ARE
C...
C...     TP(0,T) = TE, TP(Z,0) = T0                             (2)(3)
C...
C...  WHERE
C...
C...     TP        POLYMER TEMPERATURE
C...
C...     TA        AMBIENT TEMPERATURE
C...
C...     T         TIME
C...
C...     Z         POSITION ALONG THE POLYMER
C...
C...     V         VELOCITY OF THE POLYMER SHEET
C...
C...     D         THICKNESS OF THE POLYMER SHEET
C...
C...     W         WIDTH OF THE POLYMER SHEET
C...
C...     U         HEAT TRANSFER COEFFICIENT BETWEEN THE FLAT SURFACES
C...               OF THE POLYMER SHEET AND THE SURROUNDING COOLING
C...               MEDIUM
C...
C...     CP        HEAT CAPACITY OF THE POLYMER
C...
C...     RHO       DENSITY OF THE POLYMER
C...
C...  THE PROBLEM, THEN, IS TO COMPUTE TP(Z,T) TO DETERMINE IF THE
C...  POLYMER IS COOLED SUFFICIENTLY AT Z = ZL WHERE ZL IS THE LENGTH
C...  OF THE COOLING SECTION.
C...
C...  THE NUMERICAL VALUES OF THE MODEL PARAMETERS ARE
C...
C...     V = 10 CM/SEC
C...
C...     D = 0.5 CM
C...
C...     CP = 0.8 CAL/GM-C
C...
C...     RHO = 1.2 GM/CM**3
C...
C...     U = 0.1 CAL/SEC-CM**2-C
C...
C...     TE = 400 C
C...
C...     T0 = 25 C
C...
C...     TA = 25
C...
C...     ZL = 100 CM
C...
C...  THE STEADY STATE NUMERICAL AND ANALYTICAL SOLUTIONS ARE COMPARED
C...  IN SUBROUTINE PRINT.  THE STEADY STATE ANALYTICAL SOLUTION TO
C...  EQUATIONS (1) TO (3) CAN BE OBTAINED IN THE FOLLOWING WAY.
C...
C...  AT STEADY STATE, EQUATION (1) REDUCES TO
C...
C...     V*DTP/DZ = 2*U/(D*RHO*CP)*(TA - TP)
C...
C...  WHICH CAN BE REARRANGED TO
C...
C...     DTP/(TA - TP) = E*DZ, E = 2*U*/(D*RHO*CP*V)
C...
C...  INTEGRATION OF BOTH SIDES GIVES
C...
C...       TP                     Z
C...      INT DTP/(TP - TA) = -E*INT DX
C...       TE                     0
C...
C...  EVALUATION OF THE INTEGRALS AT THE LIMITS GIVES
C...
C...    LN((TP - TA)/(TE - TA)) = -E*Z
C...
C...  OR
C...
C...     (TP - TA)/(TE - TA) = EXP(-E*Z)
C...
C...  OR
C...
C...     TP = TA + (TE - TA)*EXP(-E*Z)
C...
C...  THIS STEADY STATE ANALYTICAL SOLUTION CAN BE COMPARED WITH THE
C...  STEADY STATE NUMERICAL SOLUTION.
C...
C...  FOR THE SPECIAL CASE U = 0, E = 0 IN THE PRECEDING SOLUTION WHICH
C...  REDUCES TO
C...
C...     TP = TE
C...
C...  AS EXPECTED.
C...
C...  THE NUMERICAL SOLUTION IS PROGRAMMED IN SUBROUTINE DERV FOR TWO
C...  APPROXIMATIONS OF THE SPATIAL DERIVATIVE, TP , IN EQUATION (1)
C...                                              Z
C...     (1)  A FIVE-POINT CENTERED APPROXIMATION USED IN SUBROUTINE
C...          DSS004.
C...
C...     (2)  A FIVE-POINT BIASED UPWIND APPROXIMATION USED IN SUBROU-
C...          TINE DSS020.
C...
C...  AN INTERESTING EXPERIMENT WITH THIS PROGRAM IS TO SET THE HEAT
C...  TRANSFER COEFFICIENT, U, TO ZERO.  FOR THIS CASE, EQUATION (1)
C...  REDUCES TO THE ADVECTION EQUATION, WHICH, SUPERFICIALLY, IS
C...  QUITE SIMPLE, BUT ACTUALLY IS DIFFICULT TO SOLVE NUMERICALLY
C...  BECAUSE IT PROPAGATES DISCONTINUITIES.  THESE DISCONTINUITIES
C...  PRODUCE DIFFUSION AND OSCILLATION WHICH ARE EVIDENT IN THE
C...  NUMERICAL SOLUTIONS.
C...
C...  IF FUNCTIONS OF T LESS STRINGENT THAN DISCONTINUITIES ARE APPLIED
C...  AS BOUNDARY CONDITIONS (AT Z = 0), THE FIVE-POINT BIASED UPWIND
C...  APPROXIMATION WILL GENERALLY GIVE BETTER SOLUTIONS THAN THE FIVE-
C...  POINT CENTERED APPROXIMATION.  THIS POINT HAS BEEN STUDIED EXTEN-
C...  SIVELY, AND A TUTORIAL PAPER IS AVAILABLE FROM W. E. SCHIESSER.
C...
C...  ONE EASY WAY TO REMOVE DISCONTINUITIES FROM THE PROBLEM (EQUATIONS
C...  (1) TO (3)) IS TO SET T0 = TE, FOR WHICH THE FOLLOWING PROGRAM
C...  PRODUCES A SMOOTH SOLUTION EVEN FOR U = 0.  OTHERWISE (T0 NE TE),
C...
C...  FOR U = 0, THE PROBLEM IS ESSENTIALLY IMPOSSIBLE SINCE TP  IN EQ-
C...                                                           Z
C...  UATION (1) IS INFINITE.  HOWEVER, EVEN FOR THIS CASE, A NUMERICAL
C...  SOLUTION IS COMPUTED BY THE PROGRAM WHICH CAN BE COMPARED WITH THE
C...  EXACT SOLUTION, I.E., FOR U = 0, EQUATION (1) BECOMES THE ADVEC-
C...  TION EQUATION,
C...
C...     TP  + V*TP  = 0
C...       T       Z
C...
C...  WHICH, FOR THE INITIAL AND BOUNDARY CONDITIONS
C...
C...     TP(Z,0) = T0, TP(0,T) = T0 + (TE - T0)*H(T)
C...
C...  HAS THE EXACT SOLUTION
C...
C...     TP(Z,T) = T0 + (TE - T0)*H(T - Z/V)
C...
C...  WHERE H(T) IS THE HEAVISIDE UNIT STEP FUNCTION
C...
C...            0, T LT 0
C...
C...     H(T) =
C...
C...            1, T GT 0
C...
C...  THIS EXACT SOLUTION FOR U = 0 (A STEP FUNCTION TRAVELING AT
C...  THE VELOCITY V) CAN BE COMPARED WITH THE NUMERICAL SOLUTION.
C...  IN PARTICULAR, AT Z = ZL, THE EXACT SOLUTION IS JUST A STEP AT
C...  T = ZL/V FROM T0 TO TE, AND, OF COURSE, THE NUMERICAL SOLUTION
C...  WILL ONLY APPROXIMATE THIS EXACT SOLUTION.
C...
C...  ONE OTHER IMPORTANT PARAMETER (BESIDE THE HEAT TRANSFER COEFFI-
C...  CIENT, U) CAN BE STUDIED WITH THE FOLLOWING PROGRAM, THE NUMBER
C...  OF GRID POINTS N.  IN THE PRESENT CASE, 41 WAS SELECTED RATHER
C...  ARBITRARILY.
C...
      COMMON/T/          T,     NSTOP,     NORUN
     1      /Y/     TP(41)
     2      /F/    TPT(41)
     3      /S/    TPZ(41)
     4      /C/          V,         D,        CP,       RHO,         U,
     5                  TE,        T0,        TA,        ZL,         E,
     6                   N,        IP
C...
C...  SET THE MODEL PARAMETERS
      V=10.
      D=0.5
      CP=0.8
      RHO=1.2
      U=0.10
      TE=400.
      T0=25.
      TA=25.
      ZL=100.
      N=41
C...
C...  COMPUTE THE SPATIAL EIGENVALUE E
      E=2.*U/(D*RHO*CP*V)
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      TP(I)=T0
1     CONTINUE
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/          T,     NSTOP,     NORUN
     1      /Y/     TP(41)
     2      /F/    TPT(41)
     3      /S/    TPZ(41)
     4      /C/          V,         D,        CP,       RHO,         U,
     5                  TE,        T0,        TA,        ZL,         E,
     6                   N,        IP
C...
C...  BOUNDARY CONDITION
      TP(1)=TE
      TPT(1)=0.
C...
C...  COMPUTE THE SPATIAL DERIVATIVE BY FIVE-POINT CENTERED DIFFERENCES
      IF(NORUN.EQ.1)CALL DSS004(0.,ZL,N,TP,TPZ)
C...
C...  COMPUTE THE SPATIAL DERIVATIVE BY FIVE-POINT BIASED UPWIND DIFFER-
C...  ENCES
      IF(NORUN.EQ.2)CALL DSS020(0.,ZL,N,TP,TPZ,V)
C...
C...  PDE (1)
      DO 1 I=2,N
      TPT(I)=-V*TPZ(I)+2.*U/(D*RHO*CP)*(TA-TP(I))
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/          T,     NSTOP,     NORUN
     1      /Y/     TP(41)
     2      /F/    TPT(41)
     3      /S/    TPZ(41)
     4      /C/          V,         D,        CP,       RHO,         U,
     5                  TE,        T0,        TA,        ZL,         E,
     6                   N,        IP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TIP(101), TPP(2,101)
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(1H ,//,9X,1HT,4X,8H TP(0,T),4X,8HTP(ZL,T))
C...
      IF(((IP-1)/10*10).EQ.(IP-1))WRITE(NO,2)T,TP(1),TP(N)
2     FORMAT(F10.2,2F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TIP(IP)=T
      TPP(NORUN,IP)=TP(N)
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF(IP.LT.101)RETURN
      IF(NORUN.LT.2)RETURN
      CALL TPLOTS(NORUN,IP,TIP,TPP)
C...
C...  COMPUTE AND PRINT THE ANALYTICAL STEADY STATE SOLUTION ALONG WITH
C...  THE NUMERICAL SOLUTION FOR THE SECOND RUN
      DZ=ZL/FLOAT(N-1)
      Z=-DZ
      WRITE(NO,5)
5     FORMAT(1H ,//,23H STEADY STATE SOLUTIONS,//,
     1 10H         Z,12H   TP (ANAL),12H    TP (NUM))
      DO 3 I=1,N
      Z=Z+DZ
      TPA=TA+(TE-TA)*EXP(-E*Z)
      WRITE(NO,4)Z,TPA,TP(I)
4     FORMAT(F10.1,2F12.1)
3     CONTINUE
      END
CONVECTIVE COOLING OF A MOVING POLYMER SHEET
0.        40.0      0.4
   41 1000    1    1  REL 0.001
CONVECTIVE COOLING OF A MOVING POLYMER SHEET
0.        40.0      0.4
   41 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT30
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A CROSS FLOW HEAT EXCHANGER
C...
C...  CONSIDER A CROSS FLOW HEAT EXCHANGER WITH THE TUBES RUNNING
C...  HORIZONTALLY IN 28 PASSES (IN THE Y DIRECTION) AND THE SHELL
C...  RUNNING IN ONE PASS (IN THE Z DIRECTION)
C...
C                                      + TH(4)
C                                      .
C            ......................... . ............................
C            .                         .                            .
C            .                         .                            .
C    TC(28)  .                                                      .
C       +.....................................................      .
C            .                      PASS 28                   .     .
C            .      ..........................................      .
C            .     .                PASS 27                         .
C            .      ..........................................      .
C            .                      PASS 26                   .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                      PASS I+1                  .     .
C            .      ..........................................      .
C            .     .                 PASS I                         .
C            .      ..........................................      .
C            .                      PASS I-1                  .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                                                .
C            .      ..........................................      .
C            .                                                .     .
C            .      ..........................................      .
C            .     .                PASS 3                          .
C            .      ..........................................      .
C     TC(0)  .                      PASS 2                    .     .
C       ....+.................................................      .
C            .                      PASS 1                          .
C        +   .                                                      .
C        .   .                         +                            .
C        .   .                         .                            .
C        .   ......................... . ............................
C        Z   Y ---+                    .
C                                      . TH(0)
C...
C...  HOT FLUID ENTERS THE SHELL AT Z = 0 WITH TEMPERATURE TH(0) AND
C...  LEAVES THE SHELL AT Z = ZL WITH TEMPERATURE TH(4).  COLD FLUID
C...  ENTERS THE FIRST TUBE PASS AT Y = 0 WITH TEMPERATURE TC(0) AND
C...  LEAVES THE 28TH TUBE PASS AT Y = YL (MEASURED ALONG THE TUBE
C...  PASSES) WITH TEMPERATURE TC(28).
C...
C...  IN ORDER TO ACCOUNT FOR THE DISTRIBUTED CHARACTERISTIC OF THE
C...  EXCHANGER (THE SPATIAL DISTRIBUTION OF THE FLUID TEMPERATURES),
C...  THE SHELL IS DIVIDED INTO FOUR PERFECTLY MIXED SECTIONS, AND
C...  THE TUBE PASSES ARE DIVIDED INTO 28 PERFECTLY MIXED SECTIONS.
C...  THUS THE SUBSCRIPTING OF THE EXITING TEMPERATURES, TH(4) AND
C...  TC(28).  THE NUMBERS OF SECTIONS HAVE BEEN CHOSEN ARBITRARILY.
C...  THE MODEL SHOULD THEREFORE BE RUN WITH DIFFERING NUMBERS OF
C...  SECTIONS TO DETERMINE HOW SENSITIVE THE NUMERICAL SOLUTION IS TO
C...  THE NUMBERS OF SECTIONS USED.
C...
C...  THUS, THERE ARE SEVEN TUBE SECTIONS FOR EACH SHELL SECTION.  THE
C...  TEMPERATURES WITHIN THE INDIVIDUAL SHELL AND TUBE SECTIONS CAN
C...  NOW BE COMPUTED BY APPLYING AN ENERGY CONSERVATION EQUATION TO
C...  EACH SECTION.
C...
C...  A SECTION OF TUBE OF LENGTH DY IS DEPICTED BELOW
C...
C...                         +.... DY ...+
C...             ......................................
C...                         .           .
C...                         .    Q(I)   .
C...          TC(I-1) ......+.     +     .......+ TC(I)
C...                         .     .     .
C...                         .     .     .
C...              .....................................
C...                               .
C...                             TH(J)
C...
C...  AN ENERGY BALANCE ON THE TUBE SIDE FLUID IN THE SECTION OF LENGTH
C...  DY, ASSUMING PERFECT MIXING IN THIS SECTION, GIVES
C...
C...     DY*AT*RHOM*CPM*DTC(I)/DT =
C...                                                            (1)
C...        VM*AT*RHOM*CPM*(TC(I-1) - TC(I)) + Q(I)
C...
C...  WHERE
C...
C...     Q(I) = PI*DT*DY*U*(TH(J) - TC(I))                      (2)
C...
C...  THE NOTATION FOR EQUATIONS (1) AND (2) IS DEFINED BELOW.
C...
C...  A SECTION OF SHELL OF LENGTH DZ IS DEPICTED BELOW
C...
C...                         .           .
C...                         .           .
C...                         .   TH(J)   .
C...                         .     +     .
C...                         .     .     .
C...                         .     .     .
C...                         .     .     .
C...                       + .............
C...                       . .           .
C...                       . .           .
C...                       . .           .    7
C...                      DZ .      +....... SUM Q(I)
C...                       . .           .   I=1
C...                       . .           .
C...                       . .           .
C...                       + .............
C...                         .     +     .
C...                         .     .     .
C...                         .     .     .
C...                         .     .     .
C...                         .  TH(J-1)  .
C...                         .           .
C...                         .           .
C...
C...  AN ENERGY BALANCE ON A SECTION OF THE SHELL OF LENGTH DZ, ASSUMING
C...  PERFECT MIXING IN THE SECTION GIVES
C...
C...     DZ*AS*RHOH*CPH*DTH(J)/DT =
C...                                                            (3)
C...                                              7
C...        VH*AS*RHOH*CPH*(TH(J-1) - TH(J)) + SUM Q(I)
C...                                             I=1
C...
C...  EQUATIONS (1) AND (3) HAVE THE INITIAL CONDITIONS
C...
C...     TC(I) = 125, I = 0, 1, 2, ..., 28                      (4)
C...
C...     TH(J) = 200, J = 0, 1, 2, ..., 4                       (5)
C...
C...  NOTE THAT I AND J ARE THE INDICES FOR THE TUBE AND SHELL SECTIONS,
C...  RESPECTIVELY, AND THERE ARE 28 AND 4 SECTIONS OF THE TUBE AND
C...  SHELL, RESPECTIVELY (THESE NUMBERS OF SECTIONS CAN EASILY BE
C...  CHANGED IN THE SUBSEQUENT PROGRAMMING).
C...
C...  A PI CONTROLLER FOR THE EXITING TUBE TEMPERATURE IS ALSO INCLUDED
C...  IN THE MODEL THROUGH THE EQUATION
C...
C...     VH = VHSS + AKC2*(E2 + (1/TI2)*E2I)                    (6)
C...
C...  THERE E2 IS THE ERROR IN THE EXITING TUBE TEMPERATURE
C...
C...     E2 = TCSET - TC(28)                                    (7)
C...
C...  THUS, THE MODEL CONSISTS OF 29 + 5 + 1 = 35 ORDINARY DIFFERENTIAL
C...  EQUATIONS.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1     /Y/   TC(0:28),   TH(0:4),       E2I
     2     /F/  TCT(0:28),  THT(0:4),        E2
     3     /C/         NC,        NH,        VM,        PI,        AS,
     4                 AT,      RHOH,       CPH,      RHOM,       CPM,
     5                 ZL,        DZ,        YL,        DY,      AKC2,
     6                TI2,     Q(28),         U,        DT,        VH,
     7             CON(5),     TCSET,        IP
C...
C...  MODEL PARAMETERS
C...
C...  NUMBER OF TUBE AND SHELL SECTIONS
      NC=28
      NH=4
C...
C...  TUBE FLUID VELOCITY
      VM=16000./3600.
C...
C...  THE CONSTANT PI
      PI=3.1415927
C...
C...  SHELL AND TUBE CROSS SECTIONAL AREAS
      AS=10.
      AT=0.0123
C...
C...  SHELL FLUID DENSITY AND HEAT CAPACITY
      RHOH=62.4
      CPH=1.0
C...
C...  TUBE FLUID DENSITY AND HEAT CAPACITY
      RHOM=75.0
      CPM=0.55
C...
C...  SHELL LENGTH AND SECTION LENGTH
      ZL=10.
      DZ=ZL/FLOAT(NH)
C...
C...  TUBE LENGTH AND SECTION LENGTH
      YL=1000.
      DY=YL/FLOAT(NC)
C...
C...  CONTROLLER GAIN AND INTEGRAL TIME
      AKC2=0.
      TI2=1.0E+10
C...
C...  HEAT TRANSFER COEFFICIENT AND TUBE DIAMETER
      U=35./3600.
      DT=0.125
C...
C...  CONTROLLER SET POINT
      TCSET=180.
C...
C...  SHELL FLUID VELOCITY
      VH=1131./(AS*3600.)
C...
C...  PRECOMPUTE SOME CONSTANTS
      CON(1)=PI*DT*DY*U
      CON(2)=DY*AT*RHOM*CPM
      CON(3)=VM*AT*RHOM*CPM
      CON(4)=DZ*AS*RHOH*CPH
      CON(5)=VH*AS*RHOH*CPH
C...
C...  INITIAL CONDITIONS
      DO 1 I=0,NC
      TC(I)=125.
1     CONTINUE
      DO 2 I=0,NH
      TH(I)=200.
2     CONTINUE
      E2I=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1     /Y/   TC(0:28),   TH(0:4),       E2I
     2     /F/  TCT(0:28),  THT(0:4),        E2
     3     /C/         NC,        NH,        VM,        PI,        AS,
     4                 AT,      RHOH,       CPH,      RHOM,       CPM,
     5                 ZL,        DZ,        YL,        DY,      AKC2,
     6                TI2,     Q(28),         U,        DT,        VH,
     7             CON(5),     TCSET,        IP
C...
C...  MODEL ALGEBRA
C...
C...     ERROR IN EXITING TUBE SIDE TEMPERATURE
         E2=TCSET-TC(NC)
C...
C...     SHELL SIDE VELOCITY
         VH=(1131./AS+AKC2*(E2+(1./TI2)*E2I))/3600.
         CON(5)=VH*AS*RHOH*CPH
C...
C...  BOUNDARY CONDITIONS
C...     TUBE SIDE
         TC(0)=125.
C...
C...     SHELL SIDE
         TH(0)=200.
C...
C...  TEMPERATURE CONSTRAINTS
C...
C...     TUBE SIDE
         DO 1 I=0,NC
         IF(TC(I).LT.125.)TC(I)=125.
         IF(TC(I).GT.200.)TC(I)=200.
1        CONTINUE
C...
C...     SHELL SIDE
         DO 2 I=0,NH
         IF(TH(I).LT.125.)TH(I)=125.
         IF(TH(I).GT.200.)TH(I)=200.
2        CONTINUE
C...
C...  DIFFERENTIAL EQUATIONS
C...
C...  STEP THROUGH THE PASTEURIZER
C...
C...  INITIALIZE THE SHELL SIDE SECTION NUMBER, HEAT TRANSFER RATE
         J=1
         QZ=0.
C...
C...  STEP ALONG THE NC TUBE SECTIONS
         DO 10 I=1,NC
            Q(I)=CON(1)*(TH(J)-TC(I))
            TCT(I)=(1./CON(2))*(CON(3)*(TC(I-1)-TC(I))+Q(I))
            QZ=QZ+Q(I)
C...
C...  CHECK THE SHELL SIDE SECTION NUMBER, AND USE THE CORRESPONDING
C...  ENERGY BALANCE.  FOR A NEW SHELL SIDE SECTION, INCREMENT THE
C...  SHELL SIDE NUMBER AND INITIALIZE THE HEAT TRANSFER RATE FOR THE
C...  NEW SHELL SIDE SECTION
         IF((I.EQ. 7).OR.
     1      (I.EQ.14).OR.
     2      (I.EQ.21).OR.
     3      (I.EQ.28))THEN
            THT(J)=(1./CON(4))*(CON(5)*(TH(J-1)-TH(J))-QZ)
            J=J+1
            QZ=0.
C...
C...        CHECK FOR THE CALCULATION OF THE TIME DERIVATIVES FOR THE
C...        LAST TUBE AND SHELL SECTIONS
            IF(J.GT.NH)GO TO 10
         END IF
10       CONTINUE
C...
C...  BOUNDARY TEMPERATURES ARE INVARIANT
C...
C...     TUBE SIDE
         TCT(0)=0.
C...
C...     SHELL SIDE
         THT(0)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1     /Y/   TC(0:28),   TH(0:4),       E2I
     2     /F/  TCT(0:28),  THT(0:4),        E2
     3     /C/         NC,        NH,        VM,        PI,        AS,
     4                 AT,      RHOH,       CPH,      RHOM,       CPM,
     5                 ZL,        DZ,        YL,        DY,      AKC2,
     6                TI2,     Q(28),         U,        DT,        VH,
     7             CON(5),     TCSET,        IP
      DIMENSION   TP(101),TEP(2,101),    YP(29), TCP(6,29)
C...
C...  INITIALIZE A COUNTER FOR THE TUBE FLUID TEMPERATURE PROFILES
      IF(IP.EQ.0)IP1=0
C...
C...  PRINT THE SOLUTION EVERY 20TH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/20*20).EQ.(IP-1))THEN
      WRITE(NO,1)T
1     FORMAT(1H ,//,5H T = ,E10.3)
      WRITE(NO,2)( I, TC(I), TCT(I),I=0,NC)
2     FORMAT(1H ,//,10H         I,10H     TC(I),2X,10H    TCT(I),/,
     1       (I10,F10.1,E12.3))
      WRITE(NO,3)( J, TH(J), THT(J),J=0,NH)
3     FORMAT(1H ,//,10H         J,10H     TH(J),2X,10H    THT(J),/,
     1       (I10,F10.1,E12.3))
C...
C...  STORE THE SOLUTION FOR PLOTTING THE TEMPERATURE PROFILES
      IP1=IP1+1
      DO 4 I=0,NC
      IF(IP1.EQ.1)YP(I+1)=DY*FLOAT(I)
      TCP(IP1,I+1)=TC(I)
4     CONTINUE
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING THE TIME RESPONSE
      TP(IP)=T
      TEP(1,IP)=TC(NC)
      TEP(2,IP)=TH(NH)
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.101)RETURN
      CALL TPLOTS(2,IP,TP,TEP)
      WRITE(NO,10)
10    FORMAT(1H ,//,
     1 34H 1 - TC(NC), 2 - TH(NH) VS T (SEC))
C...
C...  PLOT THE TUBE TEMPERATURE PROFILES
      CALL TPLOTS(IP1,NC+1,YP,TCP)
      WRITE(NO,11)
11    FORMAT(1H ,//,
     1 54H TUBE FLUID TEMPERATURE VS Y, T = 0, 80, 160, ..., 400)
      RETURN
      END
DYNAMICS OF A CROSS FLOW HEAT EXCHANGER
0.        400.      4.0
   35 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT31
      SUBROUTINE INITAL
C...
C...  TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD ASSEMBLY
C...
C...  A CONTROL SYSTEM HAS BEEN PROPOSED FOR CONTROLLING THE TEMPERA-
C...  TURE OF THE NUCLEAR FUEL IN A REACTOR BY SENSING THE TEMPERATURE
C...  OF THE FUEL AT THE CENTERLINE OF A ROD AND ADJUSTING THE RATE
C...  OF THE NUCLEAR REACTION BASED ON DEPARTURES FROM THE DESIRED
C...  TEMPERATURE.  THE FOLLOWING EQUATIONS MODEL THE PROPOSED SYSTEM
C...
C...  TF  = (KF/(RHOF*CPF))*(TF   + (1/R)*TF ) - (HR/(RHOF*CPF))   (1)
C...    T                      RR           R
C...
C...  TF(R,0) = TF0                                                (2)
C...
C...  TF (0,T) = 0, KF*TF (RF,T) = H*(TC - TF(RF,T))            (3)(4)
C...    R                R
C...
C...                             T
C...  HR = HRS + KC*(E + (1/TI)*INT E DT))                         (5)
C...                             0
C...
C...  E = TFSET - TF(0,T)                                          (6)
C...
C...  WHERE
C...
C...  TF(R,T)  FUEL TEMPERATURE, 0 LE R LE RF
C...
C...  R        RADIAL POSITION IN THE ROD
C...
C...  T        TIME
C...
C...  RHOF,    DENSITY, HEAT CAPACITY AND THERMAL CONDUCTIVITY OF
C...  CPF,KF   THE FUEL
C...
C...  HR       VOLUMETRIC RATE OF HEAT RELEASE OF THE NUCLEAR REACTION
C...
C...  HRS      STEADY STATE VALUE OF HR
C...
C...  RF       RADIUS OF THE FUEL ROD
C...
C...  TFSET    SET POINT TEMPERATURE FOR THE FUEL TEMPERATURE AT THE
C...           CENTERLINE OF THE ROD
C...
C...  E        ERROR IN THE FUEL CENTERLINE TEMPERATURE
C...
C...  KC,TI    GAIN AND INTEGRAL TIME OF THE CONTROLLER
C...
C...  H        HEAT TRANSFER COEFFICIENT BETWEEN THE OUTSIDE OF THE
C...           FUEL ROD AND THE SURROUNDING COOLANT
C...
C...  TC       COOLANT TEMPERATURE
C...
C...  TF0      INITIAL FUEL TEMPERATURE
C...
C...  HR COULD BE CONTROLLED ACCORDING TO EQUATIONS (5) AND (6), FOR
C...  EXAMPLE, BY POSITIONING THE CONTROL RODS FOR THE REACTOR.
C...
C...  DEVELOP A COMPUTER SIMULATION OF THIS SYSTEM WHICH PRINTS AND
C...  AND PLOTS TF(0,T) AND TF(RF,T) VS T SO THAT THE HEATING OF THE
C...  FUEL CAN BE STUDIED AND THE EFFECTIVENESS OF THE PROPOSED CON-
C...  TROLLER ASSESSED.  THE FOLLOWING PARAMETERS APPLY
C...
C...  RHOF = 0.5, CPF = 0.8, KF = 1.0, HRS = 0.1, RF = 2.5, TC = 85,
C...
C...  TF0 = 25, H = 0.1
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  SET THE MODEL PARAMETERS
      RHOF=0.5
      CPF=0.8
      KF=1.0
      RF=2.5
      TC=85.
      TFSET=900.
      TF0=25.
      H=0.1
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=5.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.3)THEN
         KC=5.0
         TI=2.0
      END IF
      HRS=200.
      NR=11
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN SUBROUTINE DERV
      CF1=1./(RHOF*CPF)
      CF2=H/KF
C...
C...  INITIAL CONDITIONS AND RADIAL GRID FOR THE FUEL
      DO 1 I=1,NR
      TF(I)=TF0
      R(I)=RF*FLOAT(I-1)/FLOAT(NR-1)
1     CONTINUE
      EINT=0.
C...
C...  COMPUTE THE INITIAL DERIVATIVES
      CALL DERV
      IP=0
      IR=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  CONTROLLER
      E=TFSET-TF(1)
      HR=HRS+KC*(E+(1./TI)*EINT)
C...
C...  SPATIAL DERIVATIVE TF
C...                       R
      CALL DSS004(0.,RF,NR,TF ,TFR )
C...
C...  BOUNDARY CONDITION AT R = 0
      TFR(1)=0.
C...
C...  BOUNDARY CONDITION AT R = RF
      TFR(NR)=CF2*(TC-TF(NR))
C...
C...  SPATIAL DERIVATIVE TR
C...                       RR
      CALL DSS004(0.,RF,NR,TFR,TFRR)
C...
C...  PDE FOR TF
C...
C...  R = 0 (NOTE - 1./R(1)*TFR(1) = TFRR(1) AT R(1) FROM L*HOSPITAL*S
C...  RULE
      TFT(1)=KF*CF1*2.*TFRR(1)+CF1*HR
C...
C...  R NE 0
      DO 1 I=2,NR
      TFT(I)=KF*CF1*(TFRR(I)+1./R(I)*TFR(I))+CF1*HR
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),      EINT
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,        KF,        RF,        TC,
     5              TFSET,       TF0,         H,        KC,        TI,
     6                HRS,       CF1,       CF2,     R(11),        HR,
     7                 NR,        IP,        IR
      REAL             KF,        KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION    TP(31), TFP(2,31),    EP(31),   HRP(31),TFPR(7,11)
C...
C...  PRINT THE NUMERICAL SOLUTION
      IP=IP+1
      IF(((IP-1)/5*5).NE.(IP-1))GO TO 3
      NS=2
      WRITE(NO,1)T,(  TF(I),I=1,NR,NS),( TFR(I),I=1,NR,NS),
     1             (TFRR(I),I=1,NR,NS),( TFT(I),I=1,NR,NS)
1     FORMAT(1H ,//,5H T = ,F9.1,//,
     1 10H   TF(R,T),6F12.0,/,10H  TFR(R,T),6E12.3,/,
     2 10H TFRR(R,T),6E12.3,/,10H  TFT(R,T),6E12.3,//)
C...
C...  STORE TF(R,T) AND TA(R,T) FOR PLOTTING OF THE TEMPERATURE
C...  PROFILES
      IR=IR+1
      DO 2 I=1,NR
      TFPR(IR,I)=TF(I)
2     CONTINUE
C...
C...  STORE TF(0,T) AND TA(RF,T) FOR PLOTTING
3     TP(IP)=T
      TFP(1,IP)=TF(1)
      TFP(2,IP)=TF(NR)
      EP(IP)=E
      HRP(IP)=HR
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.LT.31)RETURN
C...
C...  TIME PLOTS
      CALL TPLOTS(2,IP,TP,TFP)
      WRITE(NO,10)
10    FORMAT(1H ,//,
     1 56H 1 - TF(0,T), 2 - TF(RF,T) VS T                         )
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)
11    FORMAT(1H ,//,
     1 56H E = TFSET - TF(0,T) VS T                               )
      CALL TPLOTS(1,IP,TP,HRP)
      WRITE(NO,12)
12    FORMAT(1H ,//,
     1 56H HR VS T                                                )
C...
C...  SPATIAL PLOTS
      CALL TPLOTS(IR,NR,R,TFPR)
      WRITE(NO,13)
13    FORMAT(1H ,//,
     1 56H TF(R,T) VS R, T = 0, 0.5, 1.0,..., 3.0                 )
      RETURN
      END
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
CONTROL OF NUCLEAR FUEL TEMPERATURE
0.        3.        0.1
   12 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT32
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TRIPLE-EFFECT EVAPORATOR
C...
C...  CONSIDER A TRIPLE-EFFECT EVAPORATOR, DIAGRAMMED BELOW
C
C                    WS1,T1             WS2,T2         WS3,T3
C                 ............       ............       .....+
C                 .          .       .          .       .
C                 .          .       .          .       .
C               .....        .     .....        .     .....
C              .     .       .    .     .       .    .     .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .       .      .   .       .      .   .       .
C             .........      .   .........      .   .........
C             . M1,T1 .      .   . M2,T2 .      .   . M3,T3 .
C       .....+.....   .      ...+.....   .      ...+.....   .
C        WS0  .  .   .....       .  .   .....       .  .   .....
C             .   .   .  .       .   .   .  .       .   .   .  .
C       .....+.  .    .  .       .  .    .  .       .  .    .  .
C       WF,CF .   .   .  .       .   .   .  .       .   .   .  .
C             .  .    .  .       .  .    .  .       .  .    .  .
C             .   .   .  .       .   .   .  .       .   .   .  .
C          .......    .  .    .......    .  .    .......    .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          .  .       .  .    .  .       .  .    .  .       .  .
C          +  .       .  .    +  .       .  .    +  .       .  .
C         TL0 .       .  .   TL1 .       .  .   TL2 .       .  .
C              .     .   .      .+.     .   .      .+.     .   .
C               .....    .      .  .....    .      .  .....    .
C                 .      .      .    .      .      .    .      .
C                 .    .....    .    .    .....    .    .    .....
C                 .    .LLC.    .    .    .LLC.    .    .    .LLC.
C                 .    .....    .    .    .....    .    .    .....
C                 .      .      .    .      .      .    .      .
C                 .      .      .    .      .      .    .      .
C                ...    ...     .   ...    ...     .   ...    ...
C                .P....+.V.......   .P....+.V.......   .P....+.V......+
C                ...    ... W1,C1   ...    ... W2,C2   ...    ... W3,C3
C
C    .....
C    .LLC. - LIQUID LEVEL CONTROLLER
C    .....
C
C     ...
C     .P.  - PUMP
C     ...
C
C     ...
C     .V.  - CONTROL VALVE
C     ...
C...
C...  FIVE FEEDBACK CONTROL SYSTEMS ARE INCLUDED, PRIMARILY TO MAINTAIN
C...  THE CONCENTRATION OF THE LIQUID IN THE THIRD EFFECT.  THE PURPOSE
C...  OF THE SIMULATION IS TO DETERMINE HOW WELL THE CONTROLS WORK IN
C...  REGULATING THIS PRODUCT COMPOSITION.
C
C...  THE EQUATIONS WHICH MODEL THIS SYSTEM ARE
C...
C...     (1)  TOTAL MASS BALANCE FOR EACH EVAPORATOR
C...
C...          DM1/DT = WF - W1 - WS1, M1(0) = M10
C...
C...          DM2/DT = W1 - W2 - WS2, M2(0) = M20
C...
C...          DM3/DT = W2 - W3 - WS3, M3(0) = M30
C...
C...     (2)  COMPONENT (SOLUTE) BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*C1)/DT = WF*CF - W1*C1, M1(0)*C1(0) = M10*C10
C...
C...          D(M2*C2)/DT = W1*C1 - W2*C2, M2(0)*C2(0) = M20*C20
C...
C...          D(M3*C3)/DT = W2*C2 - W3*C3, M3(0)*C3(0) = M30*C30
C...
C...     (3)  CONTROLLER FOR THE LIQUID LEVEL IN EACH EVAPORATOR
C...
C...          W1 = W1SS + KC1*(M1 - M1SET)
C...
C...          W2 = W2SS + KC2*(M2 - M2SET)
C...
C...          W3 = W3SS + KC3*(M3 - M3SET)
C...
C...     (4)  ENTHALPY BALANCE FOR EACH EVAPORATOR
C...
C...          D(M1*HL1)/DT = WF*HF  + WS0*(HVS0 -HLS0)
C...
C...                       - W1*HL1 - WS1*HVS1, M1(0)*HL1(0) = M10*HL10
C...
C...          D(M2*HL2)/DT = W1*HL1 + WS1*(HVS1 - HLS1)
C...
C...                       - W2*HL2 - WS2*HVS2, M2(0)*HL2(0) = M20*HL20
C...
C...          D(M3*HL3)/DT = W2*HL2 + WS2*(HVS2 - HLS2)
C...
C...                       - W3*HL3 - WS3*HVS3, M3(0)*HL3(0) = M30*HL30
C...
C...     (5)  ENERGY BALANCE FOR THE VAPOR (NEGLECTING VAPOR DYNAMICS)
C...
C...          WS1 = U2*A2*(TL1 - T2)/(HVS1 - HLS1)
C...
C...          WS2 = U3*A3*(TL2 - T3)/(HVS2 - HLS2)
C...
C...     (6)  ENTHALPY EQUATIONS
C...
C...          HLI = HL(TI,CI), I = 1, 2, 3
C...
C...          HVSI = HVS(TI),  I = 1, 2, 3
C...
C...     (7)  CONTROLLERS FOR WS3 AND WS0 (NOT SHOWN IN THE DIAGRAM)
C...
C...          WS3 = WS3SS + KCS3*((T3 - T3SET)
C...
C...                                 T
C...                      + (1/TI3)*INT (T3 - T3SET)*DT)
C...                                 0
C...
C...          WS0 = WS0SS + KCS0*((BPRSET - BPR3)
C...
C...                                 T
C...                      + (1/TI0)*INT (BPRSET - BPR3)*DT)
C...                                 0
C...  WHERE
C...
C...     M1,M2,M3        LIQUID HOLDUPS IN EVAPORATORS 1, 2, 3
C...
C...     T               TIME
C...
C...     W1,W2,W3        LIQUID FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     WS1,WS2,WS3     VAPOR FLOW RATES FROM EVAPORATORS 1, 2, 3
C...
C...     C1,C2,C2        LIQUID CONCENTRATIONS IN EVAPORATORS 1, 2, 3
C...
C...     W1SS,W2SS,W3SS  STEADY STATE VAPOR RATES FROM EVAPORATORS 1,
C...                     2, 3
C...
C...     KC1,KC2,KC3     GAINS OF THE LIQUID LEVEL CONTROLLERS ON
C...                     EVAPORATORS 1, 2, 3
C...
C...     M1SET,M2SET,    SET POINTS FOR THE LIQUID LEVEL CONTROLLERS
C...     M3SET           ON EVAPORATORS 1, 2, 3
C...
C...     HL1,HL2,HL3     ENTHALPIES OF THE LIQUIDS IN EVAPORATORS 1, 2,
C...                     3
C...
C...     WF,TF,HF,CF     FLOW RATE, TEMPARATURE, ENTHALPY, COMPOSITION
C...                     OF THE FEED TO EVAPORATOR 1
C...
C...     WS0,HVS0,HLS0   FLOW RATE, VAPOR AND LIQUID (CONDENSATE) ENTHA-
C...                     LPIES OF THE STEAM TO EVAPORATOR 1
C...
C...     HVS1,HVS2,HVS3  ENTHALPIES OF THE VAPOR FROM EVAPORATORS 1, 2,
C...                     3
C...
C...     HLS1,HLS2       ENTHALPIES OF THE LIQUID (CONDENSATE) IN EVAP-
C...                     ORATORS 2, 3
C...
C...     T1,T2,T3        TEMPERATURES OF THE LIQUID AND VAPOR IN EVAP-
C...                     ORATORS 1, 2, 3
C...
C...     TL0,TL1,TL2     TEMPERATURES OF THE LIQUID (CONDENSATE) IN
C...                     EVAPORATORS 1, 2, 3
C...
C...     TS0             TEMPERATURE OF THE STEAM TO EVAPORATOR 1
C...
C...     U1,U2,U3        HEAT TRANSFER COEFFICIENTS FOR EVAPORATORS 1,
C...                     2, 3
C...
C...     A1,A2,A3        HEAT TRANSFER AREAS FOR EVAPORATORS 1, 2, 3
C...
C...     WS3SS, WS0SS    STEADY STATE VAPOR RATE FROM EVAPORATOR 3,
C...                     STEADY STATE STEAM RATE TO EVAPORATOR 1
C...
C...     KCS3,KCS0       CONTROLLERS GAINS FOR WS3 AND WS0
C...
C...     TI3,TI0         CONTROLLER INTEGRAL TIMES FOR WS3 AND WS0
C...
C...     T3SET, BPRSET   SET POINTS FOR T3 AND BPR (BOILING POINT RISE)
C...
C...     BPR1,BPR2,BPR3  BOILING POINT RISES FOR EVAPORATORS 1, 2, 3,
C...                     I.E., BPR1 = T1 - TL1, ETC.
C...
C...  THE NUMERICAL PARAMETERS FOR THE SYSTEM (NAOH IN WATER) ARE
C...
C...     HLI = (TI - 32)*(1 - 1.2*CI + 2.4*CI**2) BTU/LB
C...
C...         0 LE CI LE 0.3, (CI IS THE WEIGHT FRACTION OF NAOH IN THE
C...                          LIQUID IN EVAPORATOR I, I = 1, 2, 3)
C...
C...     HLI = (TI - 32)*(2.83*CI - 0.56*CI**2)
C...
C...         CI GT 0.3
C...
C...     BPRI = 36*CI + 250*CI**2 (BPRI IS THE BOILING POINT RISE IN
C...                               EVAPORATOR I, I = 1, 2, 3)
C...
C...     TLI = TI - BPRI (I = 1, 2, 3)
C...
C...     HLSI = TLI - 32 (I = 1, 2, 3)
C...
C...     HVSI = 0.45*(TI  - 32) + 1075 (I = 1, 2, 3)
C...
C...     WF = 200000 LB/HR, CF = 0.05, TF = 102 F, T3SET = 182 F
C...
C...     BPRSET = 80.5 F, A1 = A2 = A3 = 2900 FT**2, TS0 = 350 F,
C...
C...     U1 = 800 BTU/HR-FT**2-F, U2 = 500 BTU/HR-FT**2-F, U3 = 300
C...
C...     BTU/HR-FT**2-F, WS0SS = 30000 LB/HR, WS3SS = 10000 LB/HR
C...
C...     W1SS = 100000 LB/HR, W2SS = 50000 LB/HR, W3SS = 25000 LB/HR
C...
C...     KC1 = 100, KC2 = 100, KC3 = 50, M1SET = M2SET = M3SET = 2000 LB
C...
C...     KCS0 = 500, KCS3 = 500, TI0 = 0.1, TI3 = 0.1
C...
C...     INITIAL CONDITIONS
C...
C...     M1 = M2 = M3 = 2000 LB, T1 = T2 = T3 = 102 F, C1 = C2 = C3 =
C...
C...     0.05
C...
C...  DSS/2 COMMON AREA
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
C...
C...  COMMON BLOCK FOR OTHER MODEL VARIABLES, MODEL PARAMETERS
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL PARAMETERS
C...
C...     STEADY STATE VAPOR RATES
         W1SS=100000.
         W2SS= 50000.
         W3SS= 25000.
C...
C...     LIQUID LEVEL CONTROLLER GAINS
         KC1=100.
         KC2=100.
         KC3=50.
C...
C...     LIQUID LEVEL CONTROLLER SET POINTS
         M1SET=2000.
         M2SET=2000.
         M3SET=2000.
C...
C...     FEED FLOW RATE, TEMPERATURE, COMPOSITION
         WF=200000.
         TF=102.
         CF=0.05
C...
C...     HEAT TRANSFER COEFFICIENTS
         U1=800.
         U2=500.
         U3=300.
C...
C...     HEAT TRANSFER AREAS
         A1=2900.
         A2=2900.
         A3=2900.
C...
C...     STEADY STATE VAPOR RATES OF PI CONTROLLERS
         WS0SS=30000.
         WS3SS=10000.
C...
C...     GAINS OF PI CONTROLLERS
         KCS0=500.
         KCS3=500.
C...
C...     INTEGRAL TIMES OF PI CONTROLLERS
         TI0=0.1
         TI3=0.1
C...
C...     SET POINTS FOR PI CONTROLLERS
         BPRSET=80.5
         T3SET=182.0
C...
C...     STEAM TEMPERATURE
         TS0=350.
C...
C...  INITIAL CONDITIONS
C...
C...     TOTAL MASS BALANCES
         M1=2000.
         M2=2000.
         M3=2000.
C...
C...     COMPONENT BALANCES
         M1C1=2000.*0.05
         M2C2=2000.*0.05
         M3C3=2000.*0.05
C...
C...     ENTHALPY BALANCES
         M1HL1=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M2HL2=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
         M3HL3=2000.*(102.0-32.0)*(1.-1.2*0.05+2.4*0.05**2)
C...
C...     PI CONTROLLERS
         E1INT=0.
         E2INT=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  MODEL ALGEBRA
C...
C...     LIQUID COMPOSITIONS
         C1=M1C1/M1
         C2=M2C2/M2
         C3=M3C3/M3
C...
C...     LIQUID ENTHALPIES
         HL1=M1HL1/M1
         HL2=M2HL2/M2
         HL3=M3HL3/M3
C...
C...     VAPOR RATES IN THE EVAPORATORS
         W1=W1SS+KC1*(M1-M1SET)
         W2=W2SS+KC2*(M2-M2SET)
         W3=W3SS+KC3*(M3-M3SET)
C...
C...     LIQUID TEMPERATURES
C...
C...     T1
         IF(C1.LE.0.3)THEN
            T1=HL1/(1.0-1.2*C1+2.4*C1**2)+32.0
         ELSE IF(C1.GT.0.3)THEN
            T1=HL1/(2.83*C1-0.56*C1**2)+32.0
         END IF
C...
C...     T2
         IF(C2.LE.0.3)THEN
            T2=HL2/(1.0-1.2*C2+2.4*C2**2)+32.0
         ELSE IF(C2.GT.0.3)THEN
            T2=HL2/(2.83*C2-0.56*C2**2)+32.0
         END IF
C...
C...     T3
         IF(C3.LE.0.3)THEN
            T3=HL3/(1.0-1.2*C3+2.4*C3**2)+32.0
         ELSE IF(C3.GT.0.3)THEN
            T3=HL3/(2.83*C3-0.56*C3**2)+32.0
         END IF
C...
C...     BOILING POINT RISES
         BPR1=36.0*C1+250.0*C1**2
         BPR2=36.0*C2+250.0*C2**2
         BPR3=36.0*C3+250.0*C3**2
C...
C...     CONDENSATE TEMPERATURES
         TL1=T1-BPR1
         TL2=T2-BPR2
         TL3=T3-BPR3
C...
C...     CONDENSATE ENTHALPIES
         HLS0=TS0-32.0
         HLS1=TL1-32.0
         HLS2=TL2-32.0
         HLS3=TL3-32.0
C...
C...     VAPOR ENTHALPIES
         HVS0=0.45*(TS0-32.0)+1075.
         HVS1=0.45*(T1-32.0)+1075.
         HVS2=0.45*(T2-32.0)+1075.
         HVS3=0.45*(T3-32.0)+1075.
C...
C...     VAPOR RATES IN THE HEATING COILS
         WS1=U2*A2*(TL1-T2)/(HVS1-HLS1)
         WS2=U3*A3*(TL2-T3)/(HVS2-HLS2)
C...
C...     FEED ENTHALPY
         HF=(TF-32.0)*(1.0-1.2*CF+2.4*CF**2)
C...
C...     PI CONTROLLERS
         E1=BPRSET-BPR3
         WS0=WS0SS+KCS0*(E1+(1./TI0)*E1INT)
         E2=T3-T3SET
         WS3=WS3SS+KCS3*(E2+(1./TI3)*E2INT)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
C...
C...     TOTAL MASS BALANCES
         M1T=WF-W1-WS1
         M2T=W1-W2-WS2
         M3T=W2-W3-WS3
C...
C...     COMPONENT BALANCES
         M1C1T=WF*CF-W1*C1
         M2C2T=W1*C1-W2*C2
         M3C3T=W2*C2-W3*C3
C...
C...     ENTHALPY BALANCES
         M1HL1T=WF*HF +WS0*(HVS0-HLS0)
     1         -W1*HL1-WS1*HVS1
         M2HL2T=W1*HL1+WS1*(HVS1-HLS1)
     1         -W2*HL2-WS2*HVS2
         M3HL3T=W2*HL2+WS2*(HVS2-HLS2)
     1         -W3*HL3-WS3*HVS3
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/        M1,        M2,        M3,
     2               M1C1,      M2C2,      M3C3,
     3              M1HL1,     M2HL2,     M3HL3,
     4              E1INT,     E2INT
     5      /F/       M1T,       M2T,       M3T,
     6              M1C1T,     M2C2T,     M3C3T,
     7             M1HL1T,    M2HL2T,    M3HL3T,
     8                 E1,        E2
      COMMON/C1/       W1,        W2,        W3,
     1                WS1,       WS2,       WS3,
     2                 C1,        C2,        C3,
     3               W1SS,      W2SS,      W3SS,
     4                KC1,       KC2,       KC3,
     5              M1SET,     M2SET,     M3SET,
     6                HL1,       HL2,       HL3,
     7                 WF,        TF,        CF,        HF,
     8                WS0,      HVS0,      HLS0,
     9               HVS1,      HVS2,      HVS3
      COMMON/C2/     HLS1,      HLS2,
     1                 T1,        T2,        T3,
     2                TL0,       TL1,       TL2,       TS0,
     3                 U1,        U2,        U3,
     4                 A1,        A2,        A3,
     5              WS0SS,     WS3SS,
     6               KCS0,      KCS3,       TI0,       TI3,
     7             BPRSET,     T3SET,
     8               BPR1,      BPR2,      BPR3,
     9                 IP
      REAL             M1,        M2,        M3,
     1                M1T,       M2T,       M3T,
     2               M1C1,      M2C2,      M3C3,
     3              M1C1T,     M2C2T,     M3C3T,
     4              M1HL1,     M2HL2,     M3HL3,
     5             M1HL1T,    M2HL2T,    M3HL3T,
     6                KC1,       KC2,       KC3,
     7              M1SET,     M2SET,     M3SET,
     8               KCS0,      KCS3
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(101), CP(3,101)
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
         WRITE(NO,1)T,M1,M2,M3,C1,C2,C3,T1,T2,T3
1        FORMAT(' T = ',F6.3,/,
     1   10X,'M1',10X,'M2',10X,'M3',/,3F12.1,/,
     1   10X,'C1',10X,'C2',10X,'C3',/,3F12.4,/,
     1   10X,'T1',10X,'T2',10X,'T3',/,3F12.1,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      CP(1,IP)=C1
      CP(2,IP)=C2
      CP(3,IP)=C3
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.101)RETURN
      CALL TPLOTS(3,IP,TP,CP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' 1 - C1   2 - C2   3 - C3 VS T')
      RETURN
      END
CONTROL OF A TRIPLE-EFFECT EVAPORATOR
0.        1.        0.01
   11 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT33
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A TWO-STAGE HEAT EXCHANGER SYSTEM
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE TO BE COMPUTED
C...  FOR THREE VALUES OF THE PARAMETER R TO DETERMINE ITS EFFECT ON
C...  THE HEAT TRANSFER.
C...
C...  THE MODEL PARAMETERS ARE:
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = FJ = 1, U = AT = 10, T0 = 200,
C...
C...  TJ0 = 60, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1, 0.75, 0.5
C...
C...  (THREE CASES).
C...
C...  PRODUCE ABBREVIATED NUMERICAL SOLUTIONS AND GRAPHICAL SOLUTIONS
C...  AS TWO PLOTS:
C...
C...     T2(T) VS T (THREE CASES)
C...
C...     TJ2(T) VS T (THREE CASES)
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  THE INITIAL CONDITIONS (FOR ALL THREE CASES) ARE:
C...
C...     T1(0) = T2(0) = TJ1(0) = TJ2(0) = 60
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
       FJ=1.
        U=10.
       AT=10.
       T0=200.
      TJ0=60.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
C...
C...  CHANGE THE PARAMETER R FOR EACH OF THE THREE RUNS
      IF(NORUN.EQ.1)THEN
         R=1.
      ELSE IF(NORUN.EQ.2)THEN
         R=0.75
      ELSE IF(NORUN.EQ.3)THEN
         R=0.5
      END IF
C...
C...  INITIAL CONDITIONS
       T1=60.
       T2=60.
      TJ1=60.
      TJ2=60.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), T2P(3,51), TJ2P(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2
2     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
       T2P(NORUN,IP)=T2
      TJ2P(NORUN,IP)=TJ2
      TP(IP)=T
C...
C...  PLOT THE THREE NUMERICAL SOLUTIONS AT THE END OF THE THIRD RUN
      IF(IP.NE.51)RETURN
      IF(NORUN.NE.3)RETURN
C...
C...  T2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,T2P)
      WRITE(NO,11)
11    FORMAT(1H , //,' T2(T) VS T, R = 1, 0.75, 0.5')
C...
C...  TJ2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,TJ2P)
      WRITE(NO,12)
12    FORMAT(1H ,//,' TJ2(T) VS T, R = 1, 0.75, 0.5')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER, R = 1
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.75
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.5
0.        100.      2.0
    4 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT34
      SUBROUTINE INITAL
C...
C...  CONTROL OF A TWO-STAGE HEAT EXCHANGER SYSTEM
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE OF PARTICULAR
C...  INTEREST IN THE SIMULATION.
C...
C...  THE SYSTEM PARAMETERS ARE:
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = 1, U = 25, AT = 10, T0 = 60,
C...
C...  TJ0 = 200, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  A PI CONTROLLER HAS BEEN PROPOSED TO MAINTAIN THE OUTLET TEMPERA-
C...  TURE, T2, AT 180.  THE CONTROLLER EQUATIONS ARE:
C...
C...     E = T2SET - T2; (T2SET = 180)
C...
C...                                 T
C...     FJ = FJSS + AKC*(E + (1/TI)INT E*DT); (INT DENOTES AN INTEGRAL)
C...                                 0
C...
C...     FJSS = 1, T1(0) = T2(0) = 180, TJ1(0) = TJ2(0) = 200
C...
C...  WHERE
C...
C...     FJSS        STEADY STATE VALUE OF FJ
C...
C...     AKC         CONTROLLER GAIN
C...
C...     TI          CONTROLLER INTEGRAL TIME
C...
C...  NOTE THAT T1(0) = 180 WHILE T0 = 60 SO THAT THE ENTERING STREAM
C...  WITH TEMPERATURE T0 BEGINS TO COOL THE LIQUID IN THE RIGHT TANK
C...  AND THEREBY CAUSES A CHANGE IN THE TEMPERATURE TO BE CONTROLLED,
C...  T2.
C...
C...  INVESTIGATE WHETHER THIS CONTROLLER WILL WORK, AND IF IT LOOKS
C...  PROMISING, TUNE THE CONTROLLER, I.E, FIND VALUES OF AKC AND TI
C...  TO GIVE A GOOD RESPONSE OF E VS T WITH NO OFFSET.  IN ADDITION TO
C...  PLOTTING E VS T, PLOT FJ VS T TO DEMONSTRATE HOW THE CONTROLLER
C...  CHANGES THE JACKET FLOW RATE.
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
        U=25.
       AT=10.
       T0=60.
      TJ0=200.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
        R=1.
C...
C...  SET THE CONTROLLER PARAMETERS
      T2SET=180.
      FJSS=1.
      IF(NORUN.EQ.1)AKC=0.
      IF(NORUN.GE.2)AKC=5.0
      TI=10.
C...
C...  INITIAL CONDITIONS
       T1=180.
       T2=180.
      TJ1=200.
      TJ2=200.
       EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2,     EI
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  CONTROLLER EQUATIONS
      E=T2SET-T2
      FJ=FJSS+AKC*(E+(1./TI)*EI)
C...
C...  LIMIT THE JACKET FLOW TO POSITIVE VALUES IN THE THIRD RUN
      IF((NORUN.EQ.3).AND.(FJ.LT.0.))FJ=0.
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT,      E
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,  T2SET,   FJSS,    AKC,     TI,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), EP(51), FJP(51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2',11X,'E',
     1       10X,'FJ')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/1*1).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2,E,FJ
2     FORMAT(F10.1,6F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      EP(IP)=E
      FJP(IP)=FJ
      TP(IP)=T
C...
C...  PLOT THE NUMERICAL SOLUTION
      IF(IP.NE.51)RETURN
C...
C...  E(T) VS T
      CALL TPLOTS(1,IP,TP,EP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' E(T) VS T')
C...
C...  FJ(T) VS T
      CALL TPLOTS(1,IP,TP,FJP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' FJ(T) VS T')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER WITH PI CONTROLLER
0.        100.      2.0
    5 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT35
      SUBROUTINE INITAL
C...
C...  COMPARISON OF TWO-POINT UPWIND AND FIVE-POINT BIASED UPWIND
C...  APPROXIMATIONS OF A CONVECTIVE SYSTEM
C...
C...  CONSIDER THE SINGLE-PASS HEAT EXCHANGER DEPICTED BELOW
C...
C                  T2(0,T)
C                     +
C                     .
C                   . . .
C                   . . ...............................
C                   .                                 .
C                   .             T2(X,T)             .
C                   .                                 .
C                 --------------------------------------
C       T1(0,T) ---+              T1(X,T)             ---+ T2(XL,T)
C                 --------------------------------------
C                   .                                 .
C                   .                                 .
C                   ............................... + .
C                  X=0                            . . .
C                   +------------ XL ------------+. . .
C                                                   .
C                                                T2(XL,T)
C...
C...  IF AN ENERGY BALANCE IS WRITTEN ON A DIFFERENTIAL LENGTH OF
C...  THE TUBE (WITH TEMPERATURE T1(X,T)), THE FOLLOWING PARTIAL
C...  DIFFERENTIAL EQUATION (PDE) RESULTS
C...
C...     T1T = -V*T1X + (U*PI*D)/(A*RHO*CP)*(T2 - T1)           (1)
C...
C...  WHERE
C...
C...     T1T     PARTIAL DERIVATIVE OF T1 WITH RESPECT TO T
C...
C...     T1X     PARTIAL DERIVATIVE OF T1 WITH RESPECT TO X
C...
C...     V       TUBE FLUID VELOCITY
C...
C...     U       OVERALL HEAT TRANSFER COEFFICIENT
C...
C...     PI      3.1415927
C...
C...     D       TUBE DIAMETER
C...
C...     A       TUBE CROSS SECTIONAL AREA
C...
C...     RHO     TUBE FLUID DENSITY
C...
C...     CP      TUBE FLUID SPECIFIC HEAT
C...
C...  SIMILARLY, IF AN ENERGY BALANCE IS WRITTEN FOR THE SHELL SIDE
C...  FLUID (WITH TEMPERATURE T2(X,T)), THE FOLLOWING PDE RESULTS
C...
C...     T2T = VS*T2X + (U*PI*D)/(AS*RHOS*CPS)*(T1 - T2)        (2)
C...
C...  WHERE THE QUANITITIES IN EQUATION (2) ARE DEFINED ANALOGOUSLY
C...  TO THOSE IN EQUATION (1).
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATIONS (1) AND (2)
C...  ARE
C...
C...     T1(X,0) = T10, T2(X,0)  = T20
C...
C...     T1(0,T) = T1E, T2(XL,T) = T2E
C...
C...  THE POINT OF INTEREST IS THE NUMERICAL APPROXIMATION OF THE
C...  ADVECTIVE GROUPS
C...
C...     T1T +V*T1X, T2T - VS*T2X
C...
C...  IN EQUATIONS (1) AND (2).  SPECIFICALLY, THE SPATIAL DERIVATIVES,
C...  T1X AND T2X, ARE REPLACED IN EQUATIONS (1) AND (2) WITH (A)
C...  TWO-POINT UPWIND APPROXIMATIONS AND (B) FIVE-POINT BIASED UPWIND
C...  APPROXIMATIONS IN THE FOLLOWING CODING.  THE NUMERICAL SOLUTIONS
C...  PRODUCED WITH THESE TWO APPROXIMATIONS ARE THEN COMPARED VIA
C...  PLOTTING IN SUBROUTINE PRINT.
C...
C...  THE CODING IS NEARLY SELF CONTAINED FOR EACH APPROXIMATION, I.E.,
C...  APPROXIMATION (A) IS CODED IN SUBROUTINE INTAL1, DERV1 AND PRINT1
C.... APPROXIMATION (B) IS CODED IN SUBROUTINE INTAL2, DERV2 AND PRINT2.
C...
C...  A CHECK ON THE NUMERICAL SOLUTIONS TO EQUATIONS (1) AND (2) CAN
C...  BE MADE USING AN OVERALL STEADY STATE ENERGY BALANCE.  IF EQUA-
C...  TION (2) IS SUBTRACTED FROM EQUATION (1) AT STEADY STATE (T1T =
C...  T2T = 0), THE FOLLOWING ORDINARY DIFFERENTIAL EQUATION IN X
C...  RESULTS
C...
C...     V*A*RHO*CP*DT1/DX = VS*AS*RHOS*CPS*DT2/DX
C...
C...  THIS EQUATION CAN EASILY BE INTEGRATED TO GIVE
C...
C...     V*A*RHO*CP*(T1(XL,00) - T1(0,00)) =
C...
C...     VS*AS*RHOS*CPS*(T2(XL,00) - T2(0,00))
C...
C...  WHICH IS THE WELL-KNOWN OVERALL STEADY STATE ENERGY BALANCE
C...  THAT CAN BE USED TO CHECK THE EXITING TEMPERATURES, T1(XL,00)
C...  AND T2(0,00), AT STEADY STATE (00 DENOTES INFINITE TIME, T).
C...
C...  SELECT THE INITIAL CONDITION SUBROUTINE
C...
      COMMON/T/         T,     NSTOP,     NORUN
      IF(NORUN.EQ.1)CALL INTAL1
      IF(NORUN.EQ.2)CALL INTAL2
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
C...
C...  SELECT THE DERIVATIVE SUBROUTINE
      IF(NORUN.EQ.1)CALL DERV1
      IF(NORUN.EQ.2)CALL DERV2
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/I/         N,        IP
      COMMON/P/    TP(51), T1P(2,51), T2P(2,51)
C...
C...  SELECT THE PRINT SUBROUTINE
      IF(NORUN.EQ.1)CALL PRINT1(NI,NO)
      IF(NORUN.EQ.2)CALL PRINT2(NI,NO)
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.2)RETURN
C...
C...  T1(XL,T) VS T
      CALL TPLOTS(NORUN,IP,TP,T1P)
      WRITE(NO,11)
11    FORMAT(1H ,//,' T1(XL,T) VS T, 1 - TWO-POINT, 2 - FIVE POINT')
C...
C...  T2(0,T) VS T
      CALL TPLOTS(NORUN,IP,TP,T2P)
      WRITE(NO,12)
12    FORMAT(1H ,//,' T2(0,T) VS T, 1 - TWO-POINT, 2 - FIVE POINT')
      RETURN
      END
      SUBROUTINE INTAL1
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/  T1(0:10),  T2(1:11)
      COMMON/F/ T1T(0:10), T2T(1:11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
C...
C...  SET THE MODEL PARAMETERS
C...
C...  VELOCITIES
      V=5.
      VS=1.
C...
C...  HEAT TRANSFER COEFFICIENT, AREA
      U=100.
      D=0.1
C...
C...  CROSS SECTIONAL AREAS
      A=0.1
      AS=1.
C...
C...  DENSITIES
      RHO=62.5
      RHOS=62.5
C...
C...  HEAT CAPACITIES
      CP=1.
      CPS=1.
C...
C...  ENTERING TEMPERATURES
      T1E=60.
      T2E=200.
C...
C...  EXCHANGER LENGTH
      XL=10.
C...
C...  NUMBER OF SECTIONS
      N=10
C...
C...  SPATIAL INCREMENT
      DX=XL/FLOAT(N)
C...
C...  PI
      PI=3.1415927
C...
C...  INITIAL CONDITIONS
      DO 1 I=0,N
      T1(I)=60.
1     CONTINUE
      DO 2 I=1,N+1
      T2(I)=60.
2     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV1
      IP=0
      RETURN
      END
      SUBROUTINE DERV1
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/  T1(0:10),  T2(1:11)
      COMMON/F/ T1T(0:10), T2T(1:11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
C...
C...  SET THE LEFT BOUNDARY CONDITION
      T1(0)=T1E
C...
C...  SET THE RIGHT BOUNDARY CONDITION
      T2(N+1)=T2E
C...
C...  COMPUTE THE TIME DERIVATIVES FOR SECTIONS 1 TO N
      DO 1 I=1,N
      T1T(I)=-V*(T1(I)-T1(I-1))/DX+U*PI*D/(A *RHO *CP )*(T2(I)-T1(I))
      T2T(I)=VS*(T2(I+1)-T2(I))/DX+U*PI*D/(AS*RHOS*CPS)*(T1(I)-T2(I))
1     CONTINUE
C...
C...  COMPUTE THE TIME DERIVATIVES FOR THE BOUNDARY CONDITIONS
      T1T(0)=0.
      T2T(N+1)=0.
      RETURN
      END
      SUBROUTINE PRINT1(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/  T1(0:10),  T2(1:11)
      COMMON/F/ T1T(0:10), T2T(1:11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
      COMMON/P/    TP(51), T1P(2,51), T2P(2,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',5X,'T1(0,T)',4X,'T1(XL,T)',
     1              4X,'T2(XL,T)',5X,'T2(0,T)')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,T1(0),T1(N),T2(N+1),T2(1)
2        FORMAT(F10.2,4F12.2)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      T1P(NORUN,IP)=T1(N)
      T2P(NORUN,IP)=T2(1)
      RETURN
      END
      SUBROUTINE INTAL2
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/    T1(11),    T2(11)
      COMMON/F/   T1T(11),   T2T(11)
      COMMON/S/   T1X(11),   T2X(11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N+1
      T1(I)=60.
      T2(I)=60.
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV2
      IP=0
      RETURN
      END
      SUBROUTINE DERV2
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/    T1(11),    T2(11)
      COMMON/F/   T1T(11),   T2T(11)
      COMMON/S/   T1X(11),   T2X(11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
C...
C...  SET THE LEFT BOUNDARY CONDITION
      T1(1)=T1E
C...
C...  SET THE RIGHT BOUNDARY CONDITION
      T2(N+1)=T2E
C...
C...  COMPUTE THE DERIVATIVE T1X
      CALL DSS020(0.,XL,N+1,T1,T1X, 1.)
      CALL DSS020(0.,XL,N+1,T2,T2X,-1.)
C...
C...  COMPUTE THE TIME DERIVATIVES FOR SECTIONS 1 TO N
      DO 1 I=1,N+1
      T1T(I)=-V*T1X(I)+U*PI*D/(A *RHO *CP )*(T2(I)-T1(I))
      T2T(I)=VS*T2X(I)+U*PI*D/(AS*RHOS*CPS)*(T1(I)-T2(I))
1     CONTINUE
C...
C...  COMPUTE THE TIME DERIVATIVES FOR THE BOUNDARY CONDITIONS
      T1T(1)=0.
      T2T(N+1)=0.
      RETURN
      END
      SUBROUTINE PRINT2(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
      COMMON/Y/    T1(11),    T2(11)
      COMMON/F/   T1T(11),   T2T(11)
      COMMON/S/   T1X(11),   T2X(11)
      COMMON/C/         V,        VS,        DX,         U,        PI,
     1                  D,         A,        AS,       RHO,      RHOS,
     2                 CP,       CPS,        XL,       T1E,       T2E
      COMMON/I/         N,        IP
      COMMON/P/    TP(51), T1P(2,51), T2P(2,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',5X,'T1(0,T)',4X,'T1(XL,T)',
     1              4X,'T2(XL,T)',5X,'T2(0,T)')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO PRINT2
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,T1(1),T1(N+1),T2(N+1),T2(1)
2        FORMAT(F10.2,4F12.2)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      T1P(NORUN,IP)=T1(N)
      T2P(NORUN,IP)=T2(1)
      RETURN
      END
DISTRIBUTED HEAT EXCHANGER, TWO-POINT UPWIND APPROXIMATIONS
0.        25.       0.5
   22 1000    1    1  REL 0.001
DISTRIBUTED HEAT EXCHANGER, FIVE-POINT BIASED UPWIND APPROXIMATIONS
0.        25.       0.5
   22 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT36
      SUBROUTINE INITAL
C...
C...  PI CONTROL OF A THREE-PASS SHELL AND TUBE HEAT EXCHANGER (CASE 2)
C...
C...  THE FEASIBILITY OF CONTROLLING THE OUTLET TUBE TEMPERATURE OF A
C...  THREE-PASS SHELL AND TUBE HEAT EXCHANGER BY MANIUPLATING THE
C...  SHELL SIDE FLUID FLOW RATE IS TO BE INVESTIGATED WITH THE FOLLOW-
C...  ING PROGRAM.  THE PARTIAL DIFFERENTIAL EQUATIONS (PDES) WHICH
C...  MODEL THE EXCHANGER ARE
C...
C...   T1  + V*T1  = CT*(TS - T1)
C...     T       Z
C...
C...   T2  - V*T2  = CT*(TS - T2)
C...     T       Z
C...
C...   T3  + V*T3  = CT*(TS - T3)
C...     T       Z
C...
C...   TS  - VS*TS  = CS*((T1 - TS) + (T2 - TS) + (T3 - TS))
C...     T        Z
C...
C...  WHERE
C...
C...   T1,T2,T3   TEMPERATURE OF THE FLUID IN TUBE PASSES 1, 2 AND 3,
C...              RESPECTIVELY
C...
C...   TS         TEMPERATURE OF THE FLUID IN THE SHELL
C...
C...   Z          POSITION ALONG THE EXCHANGER
C...
C...   T          TIME
C...
C...   V,VS       AVERAGE VELOCITY OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CT         PI*D*U/(RHO*CP*A)
C...
C...   CS         PI*D*U/(RHOS*CPS*AS)
C...
C...   PI         3.1415927
C...
C...   D          TUBE DIAMETER
C...
C...   U          OVERALL HEAT TRANSFER COEFFICIENT
C...
C...   RHO,RHOS   DENSITIES OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   CP,CPS     HEAT CAPACITIES OF THE TUBE AND SHELL SIDE FLUIDS,
C...              RESPECTIVELY
C...
C...   A,AS       CROSS SECTIONAL AREAS OF THE TUBE AND SHELL,
C...              RESPECTIVELY
C...
C...  THE EXCHANGER IS TO BE SIMULATED SUBJECT TO THE FOLLOWING CON-
C...  DITIONS AND PARAMETERS:
C...
C...   T1(Z,0) = T2(Z,0) = T3(Z,0) = TS(Z,0) = 60
C...
C...   T1(0,T) = 60, T2(ZL,T) = T1(ZL,T), T3(0,T) = T2(0,T)
C...
C...   TS(ZL,T) = 200
C...
C...   A = 1, AS = 1, RHO = RHOS = 62.5, CP = CPS = 1, U = 100, V = 1,
C...
C...   D = 0.1, ZL = 10
C...
C...  THE OUTLET TUBE TEMPERATURE, T3(ZL,T) WILL BE SENSED AND USED
C...  TO ADJUST THE SHELL SIDE FLOW RATE, VS, ACCORDING TO THE CON-
C...  TROLLER EQUATION
C...
C...                                T
C...     VS = VSS + KC*(E + (1/TI)*INT E*DT)
C...                                0
C...
C...  WHERE
C...
C...     VSS      SHELL SIDE FLUID VELOCITY AT STEADY STATE
C...
C...     KC       CONTROLLER GAIN
C...
C...     TI       CONTROLLER INTEGRAL TIME
C...
C...     E        T3SET - T3(ZL,T)
C...
C...     T3SET    SET POINT
C...
C...  THE CONSTANTS IN THE CONTROLLER EQUATION ARE
C...
C...   VSS = 0.5, T3SET = 170
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  SET THE MODEL PARAMETERS
      T0=60.
      ZL=10.
      V=1.0
      VSS=0.5
      PI=3.1415927
      D=0.1
      U=100.
      RHO=62.5
      RHOS=62.5
      CP=1.0
      CPS=1.0
      A=1.0
      AS=1.0
      CT=PI*D*U/(RHO*CP*A)
      CS=PI*D*U/(RHOS*CPS*AS)
      TS0=200.
      T3SET=170.
      IF(NORUN.EQ.1)THEN
         KC=0.
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         KC=0.1
         TI=30.0
      ELSE
      END IF
      N=11
      IP=0
C...
C...  MODEL INITIAL CONDITIONS
      DO 1 I=1,N
      T1(I)=T0
      T2(I)=T0
      T3(I)=T0
      TS(I)=T0
1     CONTINUE
      EI=0.
C...
C...  T0 NOW BECOMES THE ENTERING TUBE TEMPERATUTE (T1(0,T) = T0) IN
C...  SUBROUTINE DERV
      T0=60.
C...
C...  INITIALIZE THE DERIVATIVES
      CALL DERV
C...
C...  INITIALIZE THE SPATIAL GRID USED IN SUBROUTINE PRINT
      ISP=0
      DO 2 I=1,N
      ZP(I)=ZL*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  CONTROLLER EQUATIONS
      E=T3SET-T3(N)
      VS=VSS+KC*(E+(1./TI)*EI)
      IF(VS.LT.0.)VS=0.
C...
C...  BOUNDARY CONDITIONS
      T1(1)=T0
      TS(N)=TS0
      T2(N)=T1(N)
      T3(1)=T2(1)
C...
C...  MODEL SPATIAL DERIVATIVES
      CALL DSS020(0.,ZL,N,T1,T1Z, 1.)
      CALL DSS020(0.,ZL,N,T2,T2Z,-1.)
      CALL DSS020(0.,ZL,N,T3,T3Z, 1.)
      CALL DSS020(0.,ZL,N,TS,TSZ,-1.)
C...
C...  MODEL PDES
      DO 1 I=1,N
      T1T(I)= -V*T1Z(I)+CT*(TS(I)-T1(I))
      T2T(I)=  V*T2Z(I)+CT*(TS(I)-T2(I))
      T3T(I)= -V*T3Z(I)+CT*(TS(I)-T3(I))
      TST(I)= VS*TSZ(I)+CS*((T1(I)-TS(I))+(T2(I)-TS(I))+(T3(I)-TS(I)))
1     CONTINUE
C...
C...  ZERO THE TEMPORAL DERIVATIVES AT THE BOUNDARIES
      T1T(1)=0.
      T2T(N)=0.
      T3T(1)=0.
      TST(N)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    T1(11),    T2(11),    T3(11),     TS(11),        EI
     2      /F/   T1T(11),   T2T(11),   T3T(11),    TST(11),         E
     3      /S/   T1Z(11),   T2Z(11),   T3Z(11),    TSZ(11)
     4      /C/        T0,        ZL,         V,         VS,
     5                 CT,        CS,       TS0,        VSS,
     6                 KC,        TI,     T3SET,     ZP(11),
     7                  N,        IP,       ISP
      REAL             KC
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION   T3P(101),  TSP(101),  VSP(101),   TP(101),
     1          T1SP(7,11),T2SP(7,11),T3SP(7,11),TSSP(7,11)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,1HT,4X,8H T1(0,T),4X,8HTS(ZL,T),
     14X,8HT3(ZL,T),4X,8H TS(0,T),4X,8H   VS(T))
C...
C...  PRINT THE SOLUTION
      IP=IP+1
      IF((IP-1)/10*10.NE.(IP-1))GO TO 3
      WRITE(NO,2)T,T1(1),TS(N),T3(N),TS(1),VS
2     FORMAT(F10.1,4F12.1,F12.3)
C...
C...  STORE THE SOLUTION FOR PLOTTING
3     TP(IP)=T
      T3P(IP)=T3(N)
      TSP(IP)=TS(1)
      VSP(IP)=VS
C...
C...  THE SPATIAL PROFILES ARE STORED EVERY 20TH CALL TO PRINT
      IF((IP-1)/20*20.NE.(IP-1))GO TO 4
      ISP=ISP+1
      DO 5 I=1,N
      T1SP(ISP,I)=T1(I)
      T2SP(ISP,I)=T2(I)
      T3SP(ISP,I)=T3(I)
      TSSP(ISP,I)=TS(I)
5     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN.  THE ENTERING SHELL
C...  FLUID TEMPERATURE IS FIRST STORED TO SCALE THE TEMPERATURE PLOTS
4     IF(IP.LT.101)RETURN
      DO 6 I=1,N
      T1SP(7,I)=TS0
      T2SP(7,I)=TS0
      T3SP(7,I)=TS0
      TSSP(7,I)=TS0
6     CONTINUE
      CALL TPLOTS(1,IP,TP,T3P)
      WRITE(NO,7)
7     FORMAT(1H ,//,31H T3(ZL,T) VS T                 )
      CALL TPLOTS(1,IP,TP,TSP)
      WRITE(NO,8)
8     FORMAT(1H ,//,31H TS(0,T) VS T                  )
      CALL TPLOTS(1,IP,TP,VSP)
      WRITE(NO,9)
9     FORMAT(1H ,//,31H VS VS T                       )
      CALL TPLOTS(7,N,ZP,T1SP)
      WRITE(NO,12)
12    FORMAT(1H ,//,31H T1(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,T2SP)
      WRITE(NO,13)
13    FORMAT(1H ,//,31H T2(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,T3SP)
      WRITE(NO,14)
14    FORMAT(1H ,//,31H T3(Z,T) VS Z, T = 0, 40,.. 200)
      CALL TPLOTS(7,N,ZP,TSSP)
      WRITE(NO,15)
15    FORMAT(1H ,//,31H TS(Z,T) VS Z, T = 0, 40,.. 200)
C...
C...  ******************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE-DEPENDENT
C...  AND WILL HAVE TO BE CHANGED FOR OTHER COMPUTERS, OR CONVERTED TO
C...  COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,T3P,IP,3H*T*,10H*T3(ZL,T)*,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,TSP,IP,3H*T*,10H*TS(0,T) *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,VSP,IP,3H*T*,10H* VS(T)  *,2H**,1)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T1SP,N,3H*Z*,10H*T1(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T2SP,N,3H*Z*,10H*T2(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,T3SP,N,3H*Z*,10H*T3(Z,T) *,2H**,7)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(ZP,TSSP,N,3H*Z*,10H*TS(Z,T) *,2H**,7)
C...
C...  ******************************************************************
C...
      RETURN
      END
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
THREE-PASS SHELL AND TUBE HEAT EXCHANGER
0.        200.      2.0
   45 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT37
      SUBROUTINE INITAL
C...
C...  TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD
C...
C...  A SYSTEM TO CONTROL THE CENTERLINE TEMPERATURE OF A NUCLEAR FUEL
C...  ROD HAS BEEN PROPOSED, AS DESCRIBED BY THE FOLLOWING EQUATIONS
C...
C...     RHOF*CPF*TF  = K*(TF   + (1/R)*TF ) + H(T)               (1)
C...                T        RR           R
C...
C...                                T
C...     H(T) = HS + KC*(E + (1/TI)INT E*DT                       (2)
C...                                0
C...
C...     E = TFSET - TF(0,T)                                      (3)
C...
C...  WHERE
C...
C...     TF(R,T)    FUEL ROD TEMPERATURE
C...
C...     R          RADIAL POSITION WITHIN THE FUEL ROD
C...
C...     T          TIME
C...
C...     RHOF       FUEL ROD DENSITY
C...
C...     CPF        FUEL ROD HEAT CAPACITY
C...
C...     K          FUEL ROD THERMAL CONDUCTIVITY
C...
C...     H(T)       VOLUMETRIC RATE OF HEAT GENERATION WITHIN THE FUEL
C...                ROD
C...
C...     KC         CONTROLLLER GAIN
C...
C...     TI         CONTROLLER INTEGRAL TIME
C...
C...     TFSET      CENTERLINE FUEL ROD TEMPERATURE SET POINT
C...
C...  THE INITIAL AND BOUNDARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     TF(R,0) = TF0                                            (4)
C...
C...     TF (0,T) = 0, K*TF (RF,T) = H*(TC - TF(RF,T))         (5)(6)
C...       R               R
C...
C...  WHERE
C...
C...     TF0        INITIAL FUEL ROD TEMPERATURE
C...
C...     RF         FUEL ROD RADIUS
C...
C...     H          HEAT TRANSFER COEFFICIENT FOR THE SURFACE OF THE
C...                FUEL ROD
C...
C...     TC         COOLANT TEMPERATURE
C...
C...  THE CENTERLINE TEMPERATURE, TF(0,T), AND ERROR, E, ARE TO BE
C...  COMPUTED VS T TO DETERMINE THE EFFECTIVENESS OF THE PROPOSED
C...  CONTROLLER.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),        EI
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,         K,         H,        RF,
     5                 TC,        HS,     TFSET,       TF0,       AKC,
     6                 TI,     R(11),        C1,        C2,        HT,
     7                 IP,         N
      REAL              K
C...
C...  MODEL PARAMETERS
      RHOF=50.
      CPF=0.9
      K=0.1
      H=100.
      RF=0.25
      TC=80.
      HS=10000.
      TFSET=1000.
      TF0=80.
C...
C...  SET THE CONTROLLER GAIN, INTEGRAL TIME
C...
C...     FOR RUN NO. 1, NO CONTROL
         IF(NORUN.EQ.1)THEN
            AKC=0.
            TI=1.0E+10
C...
C...     FOR RUN NO. 2, PROPORTIONAL CONTROL ONLY
         ELSE IF(NORUN.EQ.2)THEN
            AKC=500.
            TI=1.0E+10
C...
C...     FOR RUN NO. 3, PI CONTROL
         ELSE IF(NORUN.EQ.3)THEN
            AKC=500.
            TI=50.
         END IF
C...
C...  PRECOMPUTE SOME CONSTANTS FOR USE IN SUBROUTINE DERV
      C1= K/(RHOF*CPF)
      C2=1./(RHOF*CPF)
C...
C...  RADIAL POSITIONS WITHIN THE ROD
      N=11
      DO 2 I=1,N
      R(I)=RF*FLOAT(I-1)/FLOAT(N-1)
2     CONTINUE
C...
C...  INITIAL CONDITIONS
      DO 1 I=1,N
      TF(I)=TF0
1     CONTINUE
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),        EI
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,         K,         H,        RF,
     5                 TC,        HS,     TFSET,       TF0,       AKC,
     6                 TI,     R(11),        C1,        C2,        HT,
     7                 IP,         N
      REAL              K
C...
C...  CONTROLLER
      E=TFSET-TF(1)
      HT=HS+AKC*(E+(1./TI)*EI)
C...
C...  LIMIT THE POWER GENERATION
      IF(HT.GT.(2.0*HS))HT=2.0*HS
      IF(HT.LT.0.      )HT=0.
C...
C...  DERIVATIVE TF
C...               R
      CALL DSS004(0.,RF,N,TF,TFR)
C...
C...  BOUNDARY CONDITION (5)
      TFR(1)=0.
C...
C...  BOUNDARY CONDITION (6)
      TFR(N)=(H/K)*(TC-TF(N))
C...
C...  DERIVATIVE TF
C...               RR
      CALL DSS004(0.,RF,N,TFR,TFRR)
C...
C...  PDE
C...
C...     R = 0
         TFT(1)=2.*C1*TFRR(1)+C2*HT
C...
C...     R NE 0
         DO 1 I=2,N
         TFT(I)=C1*(TFRR(I)+(1.0/R(I))*TFR(I))+C2*HT
1        CONTINUE
         RETURN
         END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TF(11),        EI
     2      /F/   TFT(11),         E
     3      /S/   TFR(11),  TFRR(11)
     4      /C/      RHOF,       CPF,         K,         H,        RF,
     5                 TC,        HS,     TFSET,       TF0,       AKC,
     6                 TI,     R(11),        C1,        C2,        HT,
     7                 IP,         N
      REAL              K
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',5X,'TF(0,T)',4X,'TF(RF,T)',8X,'E(T)',8X,'H(T)')
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,2)T,TF(1),TF(N),E,HT
2     FORMAT(F10.2,4F12.1)
      RETURN
      END
TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD
0.        10.       0.1
   12 1000    1    1  REL 0.001
TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD
0.        10.       0.1
   12 1000    1    1  REL 0.001
TEMPERATURE CONTROL OF A NUCLEAR FUEL ROD
0.        10.       0.1
   12 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT38
      SUBROUTINE INITAL
C...
C...  VALIDATION OF DYNAMIC MODELS THROUGH CONSERVATION PRINCIPLES
C...
C...  THE GENERAL QUESTION OF WHEN A DYNAMIC MODEL IS EXECUTING
C...  CORRECTLY IS ADDRESSED IN THE FOLLOWING ANALYSIS.  SPECIFICALLY,
C...  WHEN A DYNAMIC MODEL REACHES A STEADY STATE CONDITION, A
C...  STEADY STATE CONSERVATION PRINCIPLE CAN OFTEN BE USED TO CHECK
C...  THE MODEL OUTPUT.  THIS PROCEDURE IS ILLUSTRATED WITH THE
C...  EXAMPLE IN HEAT TRANSFER.
C...
C...  CONSIDER THE FOLLOWING TWO-STAGE HEAT EXCHANGER SYSTEM
C
C           FJ, TJ0            (1 - R)*FJ                     F, T0
C          .................................               ..........
C                    .                     .               .
C                    .      .              .            .  .
C                    . .    .    .         .       .    .  + .
C               R*FJ . ...........         .       ...........
C                    + .    .    .         .       .    .    .
C                   ....    .    ....      .    ....    .    ....
C                   .  .    .    .  .      .    .  .    .    .  .
C                   .  .    .    .  . T1J  +    .  .    .    .  .  T2J
C                   .  .    . V2 .  ...........+.  .    . V1 .  .......+
C                   .  .  .....  .  .           .  .  .....  .  .
C                   .  .  .....  .  .           .  .  .....  .  .
C             T2    ....         ....     T1    ....         ....
C          +............         .+.................         .
C                      ...........                 ...........
C
C...  THE TWO TANKS, OF VOLUMES V1 AND V1, ARE JACKETED.  LIQUID OF
C...  FLOW RATE F AND TEMPERATURE T0 ENTERS THE FIRST TANK AND FLOWS
C...  RIGHT TO LEFT.  THE LIQUID TEMPERATURES FROM THE FIRST AND
C...  SECOND TANKS ARE T1 AND T2, RESPECTIVELY.
C...
C...  ANOTHER LIQUID, AT FLOW RATE FJ AND TEMPERATURE TJ0, FLOWS LEFT
C...  TO RIGHT THROUGH THE TWO JACKETS ON THE TANKS.  THE FLOW RATE
C...  THROUGH THE FIRST JACKET (ON THE LEFT) IS R*FJ, WHILE THE FLOW
C...  RATE THROUGH THE SECOND JACKET IS FJ (THROUGH THE ADDITION OF
C...  STREAMS WITH FLOW RATES R*FJ AND (1 - R)*FJ).
C...
C...  THE EXITING TEMPERATURES, T2(T) AND T2J(T), ARE TO BE COMPUTED
C...  FOR THREE VALUES OF THE PARAMETER R TO DETERMINE ITS EFFECT ON
C...  THE HEAT TRANSFER.
C...
C...  V1 = VJ1 = 10, V2 = VJ2 = 20, F = FJ = 1, U = AT = 10, T0 = 200,
C...
C...  TJ0 = 60, RHO = RHOJ = 62.5, CP = CPJ = 1, R = 1, 0.75, 0.5
C...
C...  (THREE CASES).  THE INITIAL CONDITIONS (FOR ALL THREE CASES) ARE:
C...
C...     T1(0) = T2(0) = TJ1(0) = TJ2(0) = 60
C...
C...  PRODUCE ABBREVIATED NUMERICAL SOLUTIONS AND GRAPHICAL SOLUTIONS
C...  AS TWO PLOTS:
C...
C...     T2(T) VS T (THREE CASES)
C...
C...     TJ2(T) VS T (THREE CASES)
C...
C...  THE ENERGY BALANCES WHICH MODEL THE SYSTEM ARE:
C...
C...     TANK 1:
C...
C...     D(V1*RHO*CP*T1)/DT = F*RHO*CP*T0 - F*RHO*CP*T1
C...                                                                 (1)
C...                        + U*AT*(TJ2 - T1), T1(0) = T10
C...
C...     TANK 2:
C...
C...     D(V2*RHO*CP*T2)/DT = F*RHO*CP*T1 - F*RHO*CP*T2
C...                                                                 (2)
C...                        + U*AT*(TJ1 - T2), T2(0) = T20
C...
C...     JACKET 1:
C...
C...     D(VJ1*RHOJ*CPJ*TJ1)/DT = R*FJ*RHOJ*CPJ*TJ0 - R*FJ*RHOJ*CPJ*TJ1
C...
C...                                                                (3)
C...                        + U*AT*(T2 - TJ1), TJ1(0) = TJ10
C...
C...     JACKET 2:
C...
C...     D(VJ2*RHOJ*CPJ*TJ2)/DT = R*FJ*RHOJ*CPJ*TJ1 -   FJ*RHOJ*CPJ*TJ2
C...
C...                                                                (4)
C...
C...           + (1-R)*FJ*RHOJ*CPJ*TJ0 + U*AT*(T1 - TJ2), TJ2(0) = TJ20
C...
C...  EQUATIONS (1) TO (4) ARE PROGRAMMED IN SUBROUTINE DERV, AND THEIR
C...  ASSOCIATED INITIAL CONDITIONS ARE PROGRAMMED IN SUBROUTINE INITAL.
C...
C...  IF EQUATIONS (1) TO (4) ARE SUMMED,
C...
C...     D(V1*RHO*CP*T1 + V2*RHO*CP*T2 +
C...
C...       VJ1*RHOJ*CPJ*TJ1 + VJ2*RHOJ*CPJ*TJ2)/DT =
C...                                                                (5)
C...       F*RHO*CP*T0 + FJ*RHOJ*CPJ*TJ0 -
C...
C...       F*RHO*CP*T2 - FJ*RHOJ*CPJ*TJ2
C...
C...  NOTE THE CANCELLATION OF THE TERMS FOR THE INTERMEDIATE (INTERNAL)
C...  STREAMS AND FOR THE HEAT TRANSFER.  EQUATION (5) IS AN OVERALL
C...  DYNAMIC BALANCE FOR THE TWO-STAGE HEAT TRANSFER SYSTEM.
C...
C...  AT STEADY STATE, THE TIME DERIVATIVE ON THE LHS OF EQUATION (5)
C...  WILL BE ZERO, AND EQUATION (5) REDUCES TO THE USUAL OVERALL STEADY
C...  STATE ENERGY BALANCE
C...
C...     F*RHO*CP*T0 + FJ*RHOJ*CPJ*TJ0 =
C...                                                                 (6)
C...     F*RHO*CP*T2 + FJ*RHOJ*CPJ*TJ2
C...
C...  EQUATION (6) PROVIDES AN INDEPENDENT CHECK OF THE DYNAMIC SIMULA-
C...  TION OF THE HEAT EXCHANGE SYSTEM (AFTER THE DYNAMIC SIMULATION HAS
C...  REACHED STEADY STATE).
C...
C...  THIS IDEA OF CHECKING A DYNAMIC SIMULATION VIA A CONSERVATION
C...  PRINCIPLE, IN THIS CASE THE STEADY STATE ENERGY BALANCE, CAN BE
C...  VERY USEFUL IN FINDING ERRORS IN DYNAMIC SIMULATIONS.  AS ONE
C...  RECENT EXAMPLE, AN ERROR WAS FOUND IN THE HEAT TRANSFER TERMS
C...  OF A COMPLICATED HEAT EXCHANGER MODEL BY THIS PROCEDURE (NOTE
C...  THAT IF THE HEAT TRANSFER TERMS ARE CORRECTLY FORMULATED, THEY
C...  WILL CANCEL, AS IN THE PRECEDING EQUATION (5)).
C...
C...  IN GENERAL, THE PROCEDURE IS TO ADD THE DYNAMIC EQUATIONS, THEN
C...  SET THE TIME DERIVATIVES OF THE RESULTING EQUATION TO ZERO.  THIS
C...  PROCEDURE WORKS FOR SETS OF PARTIAL DIFFERENTIAL EQUATIONS AS
C...  WELL AS ORDINARY DIFFERENTIAL EQUATIONS.
C...
C...  SOME PROGRAMMING IS ADDED AT THE END OF SUBROUTINE PRINT TO DEMON-
C...  STRATE THE APPLICATION OF EQUATION (6).
C...
C...  DSS/2 COMMON AREA
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  SET THE MODEL PARAMETERS
       V1=10.
      VJ1=10.
       V2=20.
      VJ2=20.
        F=1.
       FJ=1.
        U=10.
       AT=10.
       T0=200.
      TJ0=60.
      RHO=62.5
      RHOJ=62.5
       CP=1.
      CPJ=1.
C...
C...  CHANGE THE PARAMETER R FOR EACH OF THE THREE RUNS
      IF(NORUN.EQ.1)THEN
         R=1.
      ELSE IF(NORUN.EQ.2)THEN
         R=0.75
      ELSE IF(NORUN.EQ.3)THEN
         R=0.5
      END IF
C...
C...  INITIAL CONDITIONS
       T1=60.
       T2=60.
      TJ1=60.
      TJ2=60.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  ODES FOR THE TANKS
      DT1DT=(1./(V1*RHO*CP))*(F*RHO*CP*T0-F*RHO*CP*T1+U*AT*(TJ2-T1))
      DT2DT=(1./(V2*RHO*CP))*(F*RHO*CP*T1-F*RHO*CP*T2+U*AT*(TJ1-T2))
C...
C...  ODES FOR THE JACKETS
      DTJ1DT=(1./(VJ1*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ0-R*FJ*RHOJ*CPJ*TJ1
     1      +U*AT*(T2-TJ1))
      DTJ2DT=(1./(VJ2*RHOJ*CPJ))*(R*FJ*RHOJ*CPJ*TJ1-  FJ*RHOJ*CPJ*TJ2
     1      +(1.-R)*FJ*RHOJ*CPJ*TJ0+U*AT*(T1-TJ2))
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/     T1,     T2,    TJ1,    TJ2
     2      /F/  DT1DT,  DT2DT, DTJ1DT, DTJ2DT
     3      /C/     V1,    VJ1,     V2,    VJ2,      F,     FJ,      U,
     4              AT,     T0,    TJ0,    RHO,   RHOJ,     CP,    CPJ,
     5               R,     IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION TP(51), T2P(3,51), TJ2P(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(9X,'T',10X,'T1',10X,'T2',9X,'TJ1',9X,'TJ2')
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))WRITE(NO,2)T,T1,T2,TJ1,TJ2
2     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE SOLUTION FOR PLOTTING
       T2P(NORUN,IP)=T2
      TJ2P(NORUN,IP)=TJ2
      TP(IP)=T
C...
C...  CHECK FOR THE END OF A RUN
      IF(IP.NE.51)RETURN
C...
C...  APPLY EQUATION (6) BY FIRST COMPUTING THE STEADY STATE HEAT RATES
C...  IN AND OUT
      QIN =F*RHO*CP*T0+FJ*RHOJ*CPJ*TJ0
      QOUT=F*RHO*CP*T2+FJ*RHOJ*CPJ*TJ2
C...
C...  COMPUTE THE PERCENT DIFFERENCE BETWEEN THE HEAT RATES IN AND OUT
      PD=(QIN-QOUT)/QIN*100.
C...
C...  PRINT THE RESULTS OF THE STEADY STATE CALCULATION (NOTE - QOUT WILL
C...  NOT EQUAL QIN IF THE SYSTEM HAS NOT REACHED STEADY STATE.  IN THE
C...  PRESENT CASE, STEADY STATE HAS NOT QUITE BEEN REACHED, AND THERE-
C...  FORE THE STEADY STATE BALANCE, EQUATION (6), CLOSES TO WITHIN ONLY
C...  1.7 PERCENT.  A LONGER RUN, E.G., TO T = 200 RATHER THAN 100, WILL
C...  GIVE BETTER CLOSURE OF EQUATION (6))
      WRITE(NO,21)QIN,QOUT,PD
21    FORMAT(1H ,//,'  QIN = ',E10.3,
     1              ' QOUT = ',E10.3,
     2              '  0/0 = ',F5.2)
C...
C...  AT THE END OF THE THIRD RUN, THE NUMERICAL SOLUTIONS FOR ALL
C...  THREE RUNS ARE PLOTTED TOGETHER.
      IF(NORUN.NE.3)RETURN
C...
C...  T2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,T2P)
      WRITE(NO,11)
11    FORMAT(1H, //,' T2(T) VS T, R = 1, 0.75, 0.5')
C...
C...  TJ2(T) VS T
      CALL TPLOTS(NORUN,IP,TP,TJ2P)
      WRITE(NO,12)
12    FORMAT(1H ,//,' TJ2(T) VS T, R = 1, 0.75, 0.5')
      RETURN
      END
TWO-STAGE HEAT EXCHANGER, R = 1
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.75
0.        100.      2.0
    4 1000    1    1  REL 0.001
TWO-STAGE HEAT EXCHANGER, R = 0.5
0.        100.      2.0
    4 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT39
      SUBROUTINE INITAL
C...
C...  TESTING ENERGY CONSERVATION OF ONE-DIMENSIONAL FINITE DIFFERENCE
C...  OPERATORS
C...
C...  THE NUMERICAL INTEGRATION OF ORDINARY AND PARTIAL DIFFERENTIAL
C...  EQUATIONS (ODE/PDES) SHOULD PRODUCE SOLUTIONS WHICH OBEY CERTAIN
C...  WELL ESTABLISHED PHYSICAL PRINCIPLES IF THE ODE/PDES MODEL PHYSI-
C...  CAL SYSTEMS.  ONE SUCH PHYSICAL PRINCIPLE IS THE CONSERVATION OF
C...  ENERGY.
C...
C...  IN THE FOLLOWING PROGRAMMING, WE INVESTIGATE HOW WELL SELECTED
C...  FINITE DIFFERENCE APPROXIMATIONS CONSERVE ENERGY.  THE PROBLEM
C...  IS JUST FOURIER*S SECOND LAW WITH INSULATED BOUNDARY CONDITIONS.
C...  THUS, THE SYSTEM SHOULD NOT LOSE ENERGY AT THE BOUNDARIES, AND
C...  COMPUTED TEMPERATURES SHOULD REFLECT THIS CONSERVATION OF ENERGY.
C...
C...  THE PDE PROBLEM IS
C...
C...     U  = U                                               (1)
C...      T    XX
C...
C...     U (0,T) = U (1,T) = 0, U(X,T) = F(X)                 (2)(3)(4)
C...      X         X
C...
C...  THE FINITE DIFFERENCE APPROXIMATIONS WILL BE TESTED FOR TWO F(X)
C...
C...     (1)  CASE 1
C...
C...          F(X) = X
C...
C...     (2)  CASE 2
C...
C...          F(X) = 1, 0 LE X LT 0.5
C...
C...          F(X) = 0, 0.5 LE X LE 1
C...
C...  IN BOTH CASES, THE LONG-TIME SOLUTION IS U(X,T) = 0.5.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  SET THE NUMBER OF SPATIAL GRID POINTS
      N=21
C...
C...  SET THE INITIAL CONDITIONS
      IF((NORUN- 1)*(NORUN- 3)*(NORUN- 5)*(NORUN- 7)*(NORUN- 9)*
     +   (NORUN-11)*(NORUN-13)*(NORUN-15)
     +   .EQ.0)
     +   CALL IN1(N,X,U)
      IF((NORUN- 2)*(NORUN- 4)*(NORUN- 6)*(NORUN- 8)*(NORUN-10)*
     +   (NORUN-12)*(NORUN-14)*(NORUN-16)
     +   .EQ.0)
     +   CALL IN2(N,X,U)
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE IN1(N,X,U)
C...
C...  SUBROUTINE IN1 IMPLEMENTS THE INTIAL CONDITION
C...
C...    U(X,0) = X
C...
      DIMENSION  X(N), U(N)
      DO 1 I=1,N
      X(I)=FLOAT(I-1)/FLOAT(N-1)
      U(I)=X(I)
1     CONTINUE
      RETURN
      END
      SUBROUTINE IN2(N,X,U)
C...
C...  SUBROUTINE IN2 IMPLEMENTS THE INITIAL CONDITION
C...
C...              1.0, 0 LE X LT 0.5
C...     U(X,0) =
C...              0.0, 0.5 LT X LE 1
C...
      DIMENSION  X(N), U(N)
      N2=N/2+1
      DO 1 I=1,N
      IF(I.LT.N2)U(I)=1.0
      IF(I.GT.N2)U(I)=0.0
      IF(I.EQ.N2)U(I)=0.5
1     CONTINUE
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
C...
C...  SOLUTION BY EXPLICIT PROGRAMMING OF SECOND-ORDER DIFFERENCE
C...  APPROXIMATIONS
         IF(NORUN.EQ.1)CALL DERV1
         IF(NORUN.EQ.2)CALL DERV1
C...
C...  SOLUTION BY STAGEWISE DIFFERENTIATION, SECOND-ORDER APPROXIMATIONS
         IF(NORUN.EQ.3)CALL DERV2
         IF(NORUN.EQ.4)CALL DERV2
C...
C...  SOLUTION BY STAGEWISE DIFFERENTIATION, FOURTH-ORDER APPROXIMATIONS
         IF(NORUN.EQ.5)CALL DERV2
         IF(NORUN.EQ.6)CALL DERV2
C...
C...  SOLUTION BY STAGEWISE DIFFERENTIATION, SIXTH-ORDER APPROXIMATIONS
         IF(NORUN.EQ.7)CALL DERV2
         IF(NORUN.EQ.8)CALL DERV2
C...
C...  SOLUTION BY STAGEWISE DIFFERENTIATION, EIGHTH-ORDER APPROXIMATIONS
         IF(NORUN.EQ. 9)CALL DERV2
         IF(NORUN.EQ.10)CALL DERV2
C...
C...  SOLUTION BY STAGEWISE DIFFERENTIATION, TENTH-ORDER APPROXIMATIONS
         IF(NORUN.EQ.11)CALL DERV2
         IF(NORUN.EQ.12)CALL DERV2
C...
C...  SOLUTION BY DIRECT DIFFERENTIATION, SECOND-ORDER APPROXIMATIONS
         IF(NORUN.EQ.13)CALL DERV3
         IF(NORUN.EQ.14)CALL DERV3
C...
C...  SOLUTION BY DIRECT DIFFERENTIATION, FOURTH-ORDER APPROXIMATIONS
         IF(NORUN.EQ.15)CALL DERV3
         IF(NORUN.EQ.16)CALL DERV3
      RETURN
      END
      SUBROUTINE DERV1
C...
C...  SUBROUTINE DERV1 IMPLEMENTS THREE-POINT, SECOND-ORDER CENTERED
C...  DIFFERENCE APPROXIMATIONS OF EQUATIONS (1) TO (3)
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  SPATIAL INTERVAL
      DX=1./FLOAT(N-1)
C...
C...  UXX(0,T) INCLUDING BOUNDARY CONDITION (2)
      UXX(1)=(2.*U(2)-2.*U(1))/DX**2
C...
C...  UXX(DX,T) TO UXX(1-DX,T)
      DO 1 I=2,N-1
      UXX(I)=(U(I+1)-2.*U(I)+U(I-1))/DX**2
1     CONTINUE
C...
C...  UXX(1,T) INCLUDING BOUNDARY CONDITION (3)
      UXX(N)=(2.*U(N-1)-2.*U(N))/DX**2
C...
C...  EQUATION (1)
      DO 2 I=1,N
      UT(I)=UXX(I)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV2
C...
C...  SUBROUTINE DERV2 IMPLEMENTS A SERIES OF CENTERED AND NONCENTERED
C...  APPROXIMATIONS OF EQUATIONS (1) TO (3) AS INDICATED BELOW
C...
C...     (1)  SUBROUTINE DSS002
C...
C...          THREE-POINT, SECOND-ORDER CENTERED AND NONCENTERED
C...          APPROXIMATIONS
C...
C...     (2)  SUBROUTINE DSS004
C...
C...          FIVE-POINT, FOURTH-ORDER CENTERED AND NONCENTERED
C...          APPROXIMATIONS
C...
C...     (3)  SUBROUTINE DSS006
C...
C...          SEVEN-POINT, SIXTH-ORDER CENTERED AND NONCENTERED
C...          APPROXIMATIONS
C...
C...     (4)  SUBROUTINE DSS008
C...
C...          NINE-POINT, EIGHTH-ORDER CENTERED AND NONCENTERED
C...          APPROXIMATIONS
C...
C...     (5)  SUBROUTINE DSS010
C...
C...          ELEVEN-POINT, TENTH-ORDER CENTERED AND NONCENTERED
C...          APPROXIMATIONS
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  COMPUTE UX
      IF((NORUN.EQ. 3).OR.(NORUN.EQ. 4))CALL DSS002(0.,1.,N,U,UX)
      IF((NORUN.EQ. 5).OR.(NORUN.EQ. 6))CALL DSS004(0.,1.,N,U,UX)
      IF((NORUN.EQ. 7).OR.(NORUN.EQ. 8))CALL DSS006(0.,1.,N,U,UX)
      IF((NORUN.EQ. 9).OR.(NORUN.EQ.10))CALL DSS008(0.,1.,N,U,UX)
      IF((NORUN.EQ.11).OR.(NORUN.EQ.12))CALL DSS010(0.,1.,N,U,UX)
C...
C...  BOUNDARY CONDITIONS (2) AND (3)
      UX(1)=0.
      UX(N)=0.
C...
C...  COMPUTE UXX
      IF((NORUN.EQ. 3).OR.(NORUN.EQ. 4))CALL DSS002(0.,1.,N,UX,UXX)
      IF((NORUN.EQ. 5).OR.(NORUN.EQ. 6))CALL DSS004(0.,1.,N,UX,UXX)
      IF((NORUN.EQ. 7).OR.(NORUN.EQ. 8))CALL DSS006(0.,1.,N,UX,UXX)
      IF((NORUN.EQ. 9).OR.(NORUN.EQ.10))CALL DSS008(0.,1.,N,UX,UXX)
      IF((NORUN.EQ.11).OR.(NORUN.EQ.12))CALL DSS010(0.,1.,N,UX,UXX)
C...
C...  EQUATION (1)
      DO 2 I=1,N
      UT(I)=UXX(I)
2     CONTINUE
      RETURN
      END
      SUBROUTINE DERV3
C...
C...  SUBROUTINE DERV3 CALLS ROUTINES FOR THE DIRECT CALCULATION OF THE
C...  SECOND-ORDER DERIVATIVE IN EQUATION (1), UXX, FROM U, INCLUDING
C...  BOUNDARY CONDITIONS (2) AND (3), AS INDICATED BELOW
C...
C...     (1)  SUBROUTINE DSS042
C...
C...          SECOND-ORDER APPROXIMATIONS
C...
C...     (2)  SUBROUTINE DSS044
C...
C...          FOURTH-ORDER APPROXIMATIONS
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  BOUNDARY CONDITIONS (2) AND (3)
      UX(1)=0.
      UX(N)=0.
C...
C...  DIRECT CALCULATION OF UXX FROM U
      IF((NORUN.EQ.13).OR.(NORUN.EQ.14))
     +   CALL DSS042(0.,1.,N,U,UX,UXX,2,2)
      IF((NORUN.EQ.15).OR.(NORUN.EQ.16))
     +   CALL DSS044(0.,1.,N,U,UX,UXX,2,2)
C...
C...  EQUATION (1)
      DO 2 I=1,N
      UT(I)=UXX(I)
2     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
C...
C...  PRINT AND PLOT THE NUMERICAL SOLUTION
C...     SOLUTIONS FOR WHICH UX IS NOT AVAILABLE
         IF((NORUN- 1)*(NORUN- 2)*(NORUN-13)*(NORUN-14)*
     +      (NORUN-15)*(NORUN-16).EQ.0)CALL PRINT1(NI,NO)
C...
C...     SOLUTIONS FOR WHICH UX IS AVAILABLE
         IF((NORUN- 3)*(NORUN -4)*(NORUN- 5)*(NORUN- 6)*
     +      (NORUN- 7)*(NORUN- 8)*(NORUN- 9)*(NORUN-10)*
     +      (NORUN-11)*(NORUN-12).EQ.0)CALL PRINT2(NI,NO)
      RETURN
      END
      SUBROUTINE PRINT1(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION UP(6,21), UTP(6,21)
C...
C...  PRINT THE SOLUTION AT THE BEGINNING AND END OF THE RUN
      IP=IP+1
      IF((IP.EQ.1).OR.(IP.EQ.6))THEN
      WRITE(NO,1)T,(X(I),U(I),UXX(I),UT(I),I=1,N)
1     FORMAT(1H ,//,
     1 9X,'T',11X,'X',11X,'U',9X,'UXX',10X,'UT',/,
     1 F10.2,/,(10X,F12.3,3F12.5))
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      DO 2 I=1,N
      UP(IP,I)=U(I)
      UTP(IP,I)=UT(I)
2     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.6)RETURN
C...
C...  U(X,T) VS X WITH T AS A PARAMETER
      CALL TPLOTS(IP,N,X,UP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' U(X,T) VS X WITH T AS A PARAMETER')
C...
C...  UT(X,T) VS X WITH T AS A PARAMETER
      CALL TPLOTS(IP,N,X,UTP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' UT(X,T) VS X WITH T AS A PARAMETER')
C...
C...  COMPUTE A FIGURE OF MERIT FOR THE APPROXIMATION
      SUM=0.
      DO 20 I=1,N
      SUM=SUM+ABS(U(I)-0.5)**2
20    CONTINUE
      SUM=SQRT(SUM)/FLOAT(N)
C...
C...  COMPUTE THE FIGURE OF MERIT
      WRITE(NO,21)SUM
21    FORMAT(1H ,//,
     1 ' AVERAGE DEVIATION FROM 0.5 = ',E10.3)
      RETURN
      END
      SUBROUTINE PRINT2(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     U(21)
     2      /F/    UT(21)
     3      /S/    UX(21),   UXX(21),     X(21)
     4      /C/         N,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      DIMENSION UP(6,21), UXP(6,21), UTP(6,21)
C...
C...  PRINT THE SOLUTION AT THE BEGINNING AND END OF THE RUN
      IP=IP+1
      IF((IP.EQ.1).OR.(IP.EQ.6))THEN
      WRITE(NO,1)T,(X(I),U(I),UX(I),UT(I),I=1,N)
1     FORMAT(1H ,//,
     1 9X,'T',11X,'X',11X,'U',10X,'UX',10X,'UT',/,
     1 F10.2,/,(10X,F12.3,3F12.5))
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      DO 2 I=1,N
      UP(IP,I)=U(I)
      UXP(IP,I)=UX(I)
      UTP(IP,I)=UT(I)
2     CONTINUE
C...
C...  PLOT THE SOLUTION AT THE END OF THE RUN
      IF(IP.LT.6)RETURN
C...
C...  U(X,T) VS X WITH T AS A PARAMETER
      CALL TPLOTS(IP,N,X,UP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' U(X,T) VS X WITH T AS A PARAMETER')
C...
C...  UX(X,T) VS X WITH T AS A PARAMETER
      CALL TPLOTS(IP,N,X,UXP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' UX(X,T) VS X WITH T AS A PARAMETER')
C...
C...  UT(X,T) VS X WITH T AS A PARAMETER
      CALL TPLOTS(IP,N,X,UTP)
      WRITE(NO,12)
12    FORMAT(1H ,//,' UT(X,T) VS X WITH T AS A PARAMETER')
C...
C...  COMPUTE A FIGURE OF MERIT FOR THE APPROXIMATION
      SUM=0.
      DO 20 I=1,N
      SUM=SUM+ABS(U(I)-0.5)**2
20    CONTINUE
      SUM=SQRT(SUM)/FLOAT(N)
C...
C...  COMPUTE THE FIGURE OF MERIT
      WRITE(NO,21)SUM
21    FORMAT(1H ,//,
     1 ' AVERAGE DEVIATION FROM 0.5 = ',E10.3)
      RETURN
      END
THREE-POINT, SECOND-ORDER CENTERED DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
THREE-POINT, SECOND-ORDER CENTERED DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, SECOND-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, SECOND-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, FOURTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, FOURTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, SIXTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, SIXTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, EIGHTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, EIGHTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, TENTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
STAGEWISE DIFFERENTIATION, TENTH-ORDER DIFFERENCES
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
SECOND-ORDER DIFFERENCES, U TO UXX DIRECTLY
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
SECOND-ORDER DIFFERENCES, U TO UXX DIRECTLY
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
FOURTH-ORDER DIFFERENCES, U TO UXX DIRECTLY
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
FOURTH-ORDER DIFFERENECS, U TO UXX DIRECTLY
0.        1.0       0.2
   21 1000    1    1  ABS 0.00001
END OF RUNS
*APP HEAT40
      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 HEAT41
      SUBROUTINE INITAL
C...
C...  FEEDBACK CONTROL WITH SENSOR DYNAMICS
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED BY DAVIS (1) FOR THE
C...  HEATING OF A CONTINUOUS STIRRED TANK WITH FEEDBACK CONTROL
C...
C...  LIQUID ENERGY BALANCE
C...
C...     M*CP*DT/DTIME = F*CP*(T0 - T) + FS*HV
C...
C...  THERMOWELL ENERGY BALANCE
C...
C...     C1*DTW/DTIME = U1*A1*(T - TW)
C...
C...  THERMOCOUPLE ENERGY BALANCE
C...
C...     C2*DTT/DTIME = U2*A2*(TW - TT)
C...
C...  PROPORTIONAL CONTROL
C...
C...     FS = KP*(TS - TT)
C...
C...  WHERE
C...
C...     T          TANK LIQUID TEMPERATURE
C...
C...     TW         THERMOWELL TEMPERATURE
C...
C...     TT         THERMOCOUPLE TEMPERATURE
C...
C...     FS         STEAM FLOW RATE
C...
C...     M          MASS OF LIQUID IN THE TANK
C...
C...     CP         SPECIFIC HEAT OF THE LIQUID IN THE TANK
C...
C...     F          FLOW RATE THROUGH THE TANK
C...
C...     T0         ENTERING LIQUID TEMPERATURE
C...
C...     C1         THERMOWELL THERMAL CAPACITANCE
C...
C...     U1,A1      LIQUID TO THERMOWELL HEAT TRANSFER COEFFICIENT
C...                AND AREA
C...
C...     U2,A2      THERMOWELL TO THERMOCOUPLE HEAT TRANSFER COEFFICIENT
C...                AND AREA
C...
C...     KP         PROPORTIONAL CONTROLLER GAIN
C...
C...     TS         CONTROLLER SET POINT
C...
C...  THE PRECEDING ORDINARY DIFFERENTIAL EQUATIONS (ODES) ARE TO BE
C...  INTEGRATED SUBJECT TO THE FOLLOWING INITIAL CONDITIONS
C...
C...     T(0) = TW(0) = TT(0) = 50
C...
C...  NUMERICAL VALUES FOR THE MODEL PARAMETERS ARE GIVEN BY DAVIS.
C...
C...  (1)  DAVIS, MARK E., NUMERICAL METHODS AND MODELING FOR CHEMICAL
C...       ENGINEERING, JOHN WILEY AND SONS, INC., NY, 1984, PROB. 5,
C...       PP 47-48
C...
C...  ALSO, TO IMPROVE THE CONTROLLER PERFORMANCE (ELIMINATE OFFSET),
C...  A PROPORTIONAL-INTEGRAL (PI) CONTROLLER HAS BEEN PROGRAMMED WITH
C...  INTEGRAL TIME TI.
C...
C...  THE FOLLOWING CASES ARE PROGRAMMED
C...
C...     (1)  TS = 50, KP = 2, TI = INF (NO DYNAMIC RESPONSE SINCE ALL
C...          TIME DERIVATIVES REMAIN AT ZERO)
C...
C...     (2)  TS = 60, KP = 2, TI = INF (+10 SET POINT CHANGE, NO
C...          INTEGRAL ACTION, I.E., TI = INF WHERE INF IS INFINITY)
C...
C...     (3)  TS = 60, KP = 1, TI = 10  (+10 SET POINT CHANGE WITH
C...          A WELL TUNED CONTROLLER WHICH EFFECTIVELY ELIMINATES
C...          THE OFFSET)
C...
C...  TWO ERRORS ARE OF INTEREST
C...
C...     (1)  THE ACTUAL ERROR OF THE TANK LIQUID TEMPERATURE
C...
C...          E1 = T - TS
C...
C...     (2)  THE ERROR ON WHICH THE CONTROLLER OPERATES
C...
C...          E2 = TS - TT
C...
C...  THE FOLLOWING SIMULATION DEMONSTRATES THAT THESE TWO ERRORS ARE
C...  SUBSTANTIALLY DIFFERENT AS A RESULT OF THE SENSOR (THERMOWELL AND
C...  THERMOCOUPLE) DYNAMICS.  OF COURSE, E1 IS OF PRIMARY INTEREST.
C...
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  SET THE MODEL PARAMETERS
      T0=50.
C...
C...  SET THE CONTROLLER PARAMETERS FOR THREE RUNS
      IF(NORUN.EQ.1)THEN
         TS=50.
         KP=2.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.2)THEN
         TS=60.
         KP=2.0
         TI=1.0E+10
      ELSE IF(NORUN.EQ.3)THEN
         TS=60.
         KP=1.0
         TI=10.0
      END IF
C...
C...  INITIAL CONDITIONS
       T=50.
      TW=50.
      TT=50.
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  MODEL ALGEBRA.  NOTE THE EQUATION FOR THE CONTROLLER INCLUDES
C...  INTEGRAL ACTION.  ALSO, THERE IS NO PROVISION IN THE CONTROLLER
C...  EQUATION AS PROGRAMMED TO PREVENT THE STEAM FLOW RATE, FS, FROM
C...  GOING NEGATIVE.  THIS COULD EASILY BE PREVENTED BY SETTING FS =
C...  0 IF FS LT 0
      E2=TS-TT
      FS=KP*(E2+1./TI*EI)
C...
C...  MODEL DIFFERENTIAL EQUATIONS
      DTDT=T0-T+FS
      DTWDT=0.1*(T-TW)
      DTTDT=TW-TT
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/      T,     TW,     TT,     EI
     2      /F/   DTDT,  DTWDT,  DTTDT,     E2
     3      /C/     T0,     FS,     KP,     TS,     TI,     IP
      REAL  KP
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(51), EP1(3,51), EP2(3,51)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)WRITE(NO,1)
1     FORMAT(6X,'TIME',11X,'T',5X,'E1=T-TS',4X,'E2=TS-TT')
      IP=IP+1
      E1=T-TS
      E2=TS-TT
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO PRINT
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)TIME,T,E1,E2
2        FORMAT(F10.1,3F12.3)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=TIME
      EP1(NORUN,IP)=E1
      EP2(NORUN,IP)=E2
C...
C...  PLOT THE SOLUTION AT THE END OF THE THIRD RUN
      IF(IP.LT.51)RETURN
      IF(NORUN.LT.3)RETURN
C...
C...  PLOT LIQUID TEMPERATURE ERROR VS TIME
      CALL SPLOTS(NORUN,IP,TP,EP1)
      WRITE(NO,11)
11    FORMAT(1H ,/,
     1 ' E1 = T - TS, (TS,KP), 1 - (50,2), 2 - (60,2), 3 - (60,6)')
C...
C...  PLOT SENSOR ERROR VS TIME
      CALL SPLOTS(NORUN,IP,TP,EP2)
      WRITE(NO,12)
12    FORMAT(1H ,/,
     1 ' E2 = TS - TT, (TS,KP), 1 - (50,2), 2 - (60,2), 3 - (60,6)')
      RETURN
      END
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
FEEDBACK CONTROL WITH SENSOR DYNAMICS
0.        25.       0.5
    4 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT42
      SUBROUTINE INITAL
C...
C...  A COMPARISON OF TWO-POINT UPWIND AND FIVE-POINT BIASED UPWIND
C...  APPROXIMATIONS IN THE NUMERICAL METHOD OF LINES INTEGRATION OF
C...  FIRST-ORDER HYPERBOLIC PARTIAL DIFFERENTIAL EQUATIONS
C...
C...  THE FOLLOWING SYSTEM OF TWO FIRST-ORDER HYPERBOLIC PARTIAL DIFFER-
C...  ENTIAL EQUATIONS, WHICH MODEL A CONCENTRIC PIPE HEAT EXCHANGER,
C...  IS USED TO DEMONSTRATE THE IMPLEMENTATION OF TWO-POINT AND FIVE-
C...  POINT BIASED UPWIND APPROXIMATIONS.
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS DESCRIBING THE DYNAMICS OF A
C...  DOUBLE-PIPE HEAT EXCHANGER ARE
C...
C...     TFP  = -(FFP/AP)TFP  - (U*D*PI/(RHOFP*CPFP*AP))(TFP - TFA)  (1)
C...        T               Z
C...
C...     TFA  =  (FFA/AA)TFA  + (U*D*PI/(RHOFA*CPFA*AA))(TFP - TFA)  (2)
C...        T               Z
C...
C...  WITH INITIAL CONDITIONS
C...
C...     TFP(Z,0) = G1(Z), TFA(Z,0) = G2(Z)                       (3)(4)
C...
C...  AND BOUNDARY CONDITIONS
C...
C...     TFP(0,T) = G3(T), TFA(ZL,T) = G4(T)                      (5)(6)
C...
C...  WHERE
C...
C...     TFP       PIPE FLUID TEMPERATURE
C...
C...     TFA       ANNULUS FLUID TEMPERATURE
C...
C...     Z         AXIAL POSITION ALONG THE EXCHANGER
C...
C...     T         TIME
C...
C...     ZL        LENGTH OF THE EXCHANGER
C...
C...     FFP       PIPE FLUID VOLUMETRIC FLOW RATE
C...
C...     FFA       ANNULUS FLUID VOLUMETRIC FLOW RATE
C...
C...     AP        PIPE CROSS SECTIONAL AREA
C...
C...     AA        ANNULUS CROSS SECTIONAL AREA
C...
C...     U         OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE PIPE
C...               AND ANNULUS FLUIDS
C...
C...     D         PIPE INSIDE DIAMETER
C...
C...     RHOFP     PIPE FLUID DENSITY
C...
C...     RHOFA     ANNULUS FLUID DENSITY
C...
C...     CPFP      PIPE FLUID HEAT CAPACITY
C...
C...     CPFA      ANNULUS FLUID HEAT CAPACITY
C...
C...     G1(Z)     PRESCRIBED INITIAL CONDITION FUNCTIONS
C...     G2(Z)
C...
C...     G3(T)     PRESCRIBED BOUNDARY CONDITION FUNCTIONS
C...     G4(T)
C...
C...  1.0 FT**3/MIN OF A LUBE OIL AT 250F FLOWS THROUGH THE PIPE AND IS
C...  BEING COOLED WITH 1.0 FT**3/MIN OF WATER AT 60F FLOWING COUNTER-
C...  CURRENTLY THROUGH THE ANNULUS.  FOR THE ANALYSIS OF THE EXCHANGER,
C...  THE AXIAL DERIVATIVES ARE APPROXIMATED BY
C...
C...     (1)  TWO-POINT UPWIND APPROXIMATIONS (STIRRED TANKS IN SERIES)
C...          IMPLEMENTED IN SUBROUTINES INTAL1, DERV1 AND PRINT1
C...
C...     (2)  FIVE-POINT BIASED UPWIND APPROXIMATIONS IMPLEMENTED IN
C...          SUBROUTINES INTAL2, DERV2 AND PRINT2
C...
C...  THE PRODUCT U*D IS 3 BTU/MIN-FT-F.  THE OUTLET TEMPERATURES ARE OF
C...  PARTICULAR INTEREST, I.E., TFP(ZL,T) AND TFA(0,T).
C...
      COMMON/T/         T,      NFIN,     NORUN
      IF(NORUN.EQ.1)CALL INTAL1
      IF(NORUN.EQ.2)CALL INTAL2
      RETURN
      END
      SUBROUTINE INTAL1
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/ TFP(0:20), TFA(1:21)
     2      /F/TFPT(0:20),TFAT(1:21)
     3      /S/TFPZ(0:20),TFAZ(1:21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  SET THE MODEL PARAMETERS
      FFP=1.0
      FFA=1.0
      AP=0.1
      AA=0.1
      UD=3.0
      RHOFP=50.0
      RHOFA=62.0
      CPFP=0.5
      CPFA=1.0
      ZL=20.0
      N20=20
      N21=21
      DZ=ZL/FLOAT(N20)
C...
C...  PRECOMPUTE SOME CONSTANTS TO SAVE TIME
      VP=FFP/AP
      VA=FFA/AA
      HP=UD*3.1415927/(RHOFP*CPFP*AP)
      HA=UD*3.1415927/(RHOFA*CPFA*AA)
C...
C...  INITIAL CONDITIONS (3) AND (4)
      DO 1 I=0,N20
      Z=ZL*FLOAT(I)/FLOAT(N20)
      TFP(I)  =G1(Z)
      TFA(I+1)=G2(Z)
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE INTAL2
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  SET THE MODEL PARAMETERS
      FFP=1.0
      FFA=1.0
      AP=0.1
      AA=0.1
      UD=3.0
      RHOFP=50.0
      RHOFA=62.0
      CPFP=0.5
      CPFA=1.0
      ZL=20.0
      N20=20
      N21=21
      DZ=ZL/FLOAT(N21-1)
C...
C...  PRECOMPUTE SOME CONSTANTS TO SAVE TIME
      VP=FFP/AP
      VA=FFA/AA
      HP=UD*3.1415927/(RHOFP*CPFP*AP)
      HA=UD*3.1415927/(RHOFA*CPFA*AA)
C...
C...  INITIAL CONDITIONS (3) AND (4)
      DO 1 I=1,N21
      Z=ZL*FLOAT(I-1)/FLOAT(N21-1)
      TFP(I)=G1(Z)
      TFA(I)=G2(Z)
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      FUNCTION G1(Z)
C...
C...  FUNCTION G1(Z) IMPLEMENTS INITIAL CONDITION (3)
      G1=60.0
      RETURN
      END
      FUNCTION G2(Z)
C...
C...  FUNCTION G2(Z) IMPLEMENTS INITIAL CONDITION (4)
      G2=60.0
      RETURN
      END
      FUNCTION G3(T)
C...
C...  FUNCTION G3(T) IMPLEMENTS BOUNDARY CONDITION (5)
      G3=250.0
      RETURN
      END
      FUNCTION G4(T)
C...
C...  FUNCTION G4(T) IMPLEMENTS BOUNDARY CONDITION (6)
      G4=60.0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) BY
C...  TWO-POINT UPWIND APPROXIMATIONS (STIRRED TANKS IN SERIES)
      IF(NORUN.EQ.1)CALL DERV1
C...
C...  COMPUTE THE SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) BY
C...  FIVE-POINT BIASED UPWIND APPROXIMATIONS
      IF(NORUN.EQ.2)CALL DERV2
      RETURN
      END
      SUBROUTINE DERV1
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/ TFP(0:20), TFA(1:21)
     2      /F/TFPT(0:20),TFAT(1:21)
     3      /S/TFPZ(0:20),TFAZ(1:21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  BOUNDARY CONDITIONS (5) AND (6)
      TFP(0)  =G3(T)
      TFA(N21)=G4(T)
C...
C...  SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) ARE APPROXIMATED BY
C...  TWO-POINT UPWIND APPROXIMATIONS (STIRRED TANKS IN SERIES)
      DO 1 I=1,N20
      TFPT(I)=-VP*(TFP(I)-TFP(I-1))/DZ-HP*(TFP(I)-TFA(I))
1     CONTINUE
      DO 2 I=1,N20
      TFAT(I)= VA*(TFA(I+1)-TFA(I))/DZ+HA*(TFP(I)-TFA(I))
2     CONTINUE
      TFPT(0)=0.
      TFAT(N21)=0.
      RETURN
      END
      SUBROUTINE DERV2
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  BOUNDARY CONDITIONS (5) AND (6)
      TFP(1)  =G3(T)
      TFA(N21)=G4(T)
C...
C...  SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) ARE APPROXIMATED BY
C...  FIVE-POINT BIASED UPWIND APPROXIMATIONS
      CALL DSS020(0.,ZL,N21,TFP,TFPZ,+1.)
      CALL DSS020(0.,ZL,N21,TFA,TFAZ,-1.)
C...
C...  EQUATIONS (1) AND (2)
      DO 1 I=1,N21
      IF(I.EQ.1)GO TO 2
      TFPT(I)=-VP*TFPZ(I)-HP*(TFP(I)-TFA(I))
2     IF(I.EQ.N21)GO TO 1
      TFAT(I)= VA*TFAZ(I)+HA*(TFP(I)-TFA(I))
1     CONTINUE
      TFPT(1)=0.
      TFAT(N21)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      COMMON/PLOT/ TP(4,101), TIMEP(101)
      DIMENSION  TFOP(2,101),TAOP(2,101)
C...
C...  FOR NORUN = 1, CALL SUBROUTINE PRINT1, AND AT THE END OF THE
C...  RUN, STORE THE EXIT TEMPERATURES
      IF(NORUN.EQ.1)THEN
         CALL PRINT1(NI,NO)
            IF(IP.EQ.101)THEN
               DO 1 I=1,IP
               TFOP(NORUN,I)=TP(2,I)
               TAOP(NORUN,I)=TP(3,I)
1              CONTINUE
            END IF
C...
C...  FOR NORUN = 2, CALL SUBROUTINE PRINT2, AND AT THE END OF THE
C...  RUN, STORE THE EXIT TEMPERATURES
      ELSE IF(NORUN.EQ.2)THEN
         CALL PRINT2(NI,NO)
            IF(IP.EQ.101)THEN
               DO 2 I=1,IP
               TFOP(NORUN,I)=TP(2,I)
               TAOP(NORUN,I)=TP(3,I)
2              CONTINUE
            END IF
      END IF
C...
C...  AT THE END OF THE SECOND RUN, PLOT THE EXIT TEMPERATURES
      IF((IP.EQ.101).AND.(NORUN.EQ.2))THEN
C...
C...     EXIT PIPE TEMPERATURES VS TIME
         CALL SPLOTS(NORUN,IP,TIMEP,TFOP)
         WRITE(NO,11)
11       FORMAT(1H ,/,' TFP(ZL,T), 1 - TWO-POINT, 2 - FIVE-POINT')
C...
C...     EXIT ANNULUS TEMPERATURES VS TIME
         CALL SPLOTS(NORUN,IP,TIMEP,TAOP)
         WRITE(NO,12)
12       FORMAT(1H ,/,' TFA(0,T),  1 - TWO-POINT, 2 - FIVE-POINT')
C...
C...  COMPUTE OVERALL STEADY STATE ENERGY BALANCES TO DETERMINE IF ONE
C...  APPROXIMATION IS BETTER THAN THE OTHER
C...
C...     STEADY STATE ENERGY BALANCE FOR TWO-POINT APPROXIMATIONS
         QIN1 =1.0*50.0*0.5*250.0     +1.0*62.0*1.0*60.0
         QOUT1=1.0*50.0*0.5*TFOP(1,IP)+1.0*62.0*1.0*TAOP(1,IP)
         QNET1=QIN1-QOUT1
C...
C...     STEADY STATE ENERGY BALANCE FOR FIVE-POINT APPROXIMATIONS
         QIN2 =1.0*50.0*0.5*250.0     +1.0*62.0*1.0*60.0
         QOUT2=1.0*50.0*0.5*TFOP(2,IP)+1.0*62.0*1.0*TAOP(2,IP)
         QNET2=QIN2-QOUT2
C...
C...     PRINT THE RESULTS OF THE STEADY STATE ENERGY BALANCE
         WRITE(NO,13)QIN1,QOUT1,QNET1,QIN2,QOUT2,QNET2
13       FORMAT(1H1,/,
     1  ' QIN1 = ',E12.5,' QOUT1 = ',E12.5,' QNET1 = ',E12.5,/,
     2  ' QIN2 = ',E12.5,' QOUT2 = ',E12.5,' QNET2 = ',E12.5,/)
      END IF
      RETURN
      END
      SUBROUTINE PRINT1(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/ TFP(0:20), TFA(1:21)
     2      /F/TFPT(0:20),TFAT(1:21)
     3      /S/TFPZ(0:20),TFAZ(1:21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      COMMON/PLOT/ TP(4,101), TIMEP(101)
C...
C...  LABEL THE NUMERICAL OUTPUT
      IF(T.LT.0.05)WRITE(NO,2)
2     FORMAT(9X,1HT,4X,8HTFP(0,T),3X,9HTFP(ZL,T),
     1              4X,8HTFA(0,T),3X,9HTFA(ZL,T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,TFP(0),TFP(N20),TFA(1),TFA(N21)
1     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      TP(1,IP)=TFP(  0)
      TP(2,IP)=TFP(N20)
      TP(3,IP)=TFA(  1)
      TP(4,IP)=TFA(N21)
      TIMEP(IP)=T
C...
C...  PLOT THE INLET AND OUTLET TEMPERATURES AT THE END OF EACH RUN
      IF(IP.LT.101)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL SPLOTS(4,IP,TIMEP,TP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,/,' 1 - TFP( 0,T), 2 - TFP(ZL,T)',/,
     1             ' 3 - TFA( 0,T), 4 - TFA(ZL,T)')
      RETURN
      END
      SUBROUTINE PRINT2(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,       N20,       N21,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      COMMON/PLOT/ TP(4,101), TIMEP(101)
C...
C...  LABEL THE NUMERICAL OUTPUT
      IF(T.LT.0.05)WRITE(NO,2)
2     FORMAT(9X,1HT,4X,8HTFP(0,T),3X,9HTFP(ZL,T),
     1              4X,8HTFA(0,T),3X,9HTFA(ZL,T))
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,1)T,TFP(1),TFP(N21),TFA(1),TFA(N21)
1     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE NUMERICAL SOLUTION FOR PLOTTING
      IP=IP+1
      TP(1,IP)=TFP(  1)
      TP(2,IP)=TFP(N21)
      TP(3,IP)=TFA(  1)
      TP(4,IP)=TFA(N21)
      TIMEP(IP)=T
C...
C...  PLOT THE INLET AND OUTLET TEMPERATURES AT THE END OF EACH RUN
      IF(IP.LT.101)RETURN
C...
C...  PLOT THE NUMERICAL SOLUTION
      CALL SPLOTS(4,IP,TIMEP,TP)
C...
C...  LABEL THE PLOT
      WRITE(NO,3)
3     FORMAT(1H ,/,' 1 - TFP( 0,T), 2 - TFP(ZL,T)',/,
     1             ' 3 - TFA( 0,T), 4 - TFA(ZL,T)')
      RETURN
      END
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
END OF RUNS
*APP HEAT43
      SUBROUTINE INITAL
C...
C...  EFFECT OF HEAT LOSS FROM A HEAT EXCHANGER
C...
C...  THE PARTIAL DIFFERENTIAL EQUATIONS DESCRIBING THE DYNAMICS OF A
C...  DOUBLE-PIPE HEAT EXCHANGER WITH HEAR LOSS TO THE SURROUNDINGS ARE
C...
C...     TFP  = -(FFP/AP)TFP  - (U*D*PI/(RHOFP*CPFP*AP))(TFP - TFA)  (1)
C...        T               Z
C...
C...     TFA  =  (FFA/AA)TFA  + (U*D*PI/(RHOFA*CPFA*AA))(TFP - TFA)  (2)
C...        T               Z
C...
C...          + (UA*DA*PI)/(RHOFA*CPFA*AA))(TA - TFA)
C...
C...  WITH INITIAL CONDITIONS
C...
C...     TFP(Z,0) = G1(Z), TFA(Z,0) = G2(Z)                       (3)(4)
C...
C...  AND BOUNDARY CONDITIONS
C...
C...     TFP(0,T) = G3(T), TFA(ZL,T) = G4(T)                      (5)(6)
C...
C...  WHERE
C...
C...     TFP       PIPE FLUID TEMPERATURE
C...
C...     TFA       ANNULUS FLUID TEMPERATURE
C...
C...     TA        SURROUNDING AIR TEMPERATURE
C...
C...     Z         AXIAL POSITION ALONG THE EXCHANGER
C...
C...     T         TIME
C...
C...     ZL        LENGTH OF THE EXCHANGER
C...
C...     FFP       PIPE FLUID VOLUMETRIC FLOW RATE
C...
C...     FFA       ANNULUS FLUID VOLUMETRIC FLOW RATE
C...
C...     AP        PIPE CROSS SECTIONAL AREA
C...
C...     AA        ANNULUS CROSS SECTIONAL AREA
C...
C...     U         OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE PIPE
C...               AND ANNULUS FLUIDS
C...
C...     UA        OVERALL HEAT TRANSFER COEFFICIENT BETWEEN THE OUTER
C...               PIPE AND THE SURROUNDING AIR
C...
C...     D         PIPE INSIDE DIAMETER
C...
C...     DA        OUTER PIPE OUTSIDE DIAMETER
C...
C...     RHOFP     PIPE FLUID DENSITY
C...
C...     RHOFA     ANNULUS FLUID DENSITY
C...
C...     CPFP      PIPE FLUID HEAT CAPACITY
C...
C...     CPFA      ANNULUS FLUID HEAT CAPACITY
C...
C...     G1(Z)     PRESCRIBED INITIAL CONDITION FUNCTIONS
C...     G2(Z)
C...
C...     G3(T)     PRESCRIBED BOUNDARY CONDITION FUNCTIONS
C...     G4(T)
C...
C...  1.0 FT**3/MIN OF A LUBE OIL AT 250F FLOWS THROUGH THE PIPE AND IS
C...  BEING COOLED WITH 1.0 FT**3/MIN OF WATER AT 60F FLOWING COUNTER-
C...  CURRENTLY THROUGH THE ANNULUS.  FOR THE ANALYSIS OF THE EXCHANGER,
C...  THE AXIAL DERIVATIVES  ARE APPROXIMATED BY FIVE-POINT UPWIND
C...  APPROXIMATIONS IMPLEMENT IN SUBROUTINE DSS020 CALLED IN SUBROUTINE
C...  DERV.
C...
C...  THE PRODUCT U*D IS 3 BTU/MIN-FT-F.  THE OUTLET TEMPERATURES ARE OF
C...  PARTICULAR INTEREST, I.E., TFP(ZL,T) AND TFA(0,T).
C...
C...  TWO CASES ARE PROGRAMMED
C...
C...     (1)  UA*DA = 0 (NO HEAT LOSSES TO THE SURROUNDINGS)
C...
C...     (2)  UA*DA = 1 BTU/MIN-FT-F (HEAT LOSSES TO THE SURROUNDINGS)
C...
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,      HAIR,        TA,       N21,        IP
C...
C...  SET THE MODEL PARAMETERS
      FFP=1.0
      FFA=1.0
      AP=0.1
      AA=0.1
      UD=3.0
      IF(NORUN.EQ.1)UA=0.0
      IF(NORUN.EQ.2)UA=1.0
      TA=60.0
      RHOFP=50.0
      RHOFA=62.0
      CPFP=0.5
      CPFA=1.0
      ZL=20.0
      N21=21
      DZ=ZL/FLOAT(N21-1)
C...
C...  PRECOMPUTE SOME CONSTANTS TO SAVE TIME
      VP=FFP/AP
      VA=FFA/AA
      HP  =UD*3.1415927/(RHOFP*CPFP*AP)
      HA  =UD*3.1415927/(RHOFA*CPFA*AA)
      HAIR=UA*3.1415927/(RHOFA*CPFA*AA)
C...
C...  INITIAL CONDITIONS (3) AND (4)
      DO 1 I=1,N21
      Z=ZL*FLOAT(I-1)/FLOAT(N21-1)
      TFP(I)=G1(Z)
      TFA(I)=G2(Z)
1     CONTINUE
C...
C...  INITIALIZE THE REST OF THE MODEL
      CALL DERV
      IP=0
      RETURN
      END
      FUNCTION G1(Z)
C...
C...  FUNCTION G1(Z) IMPLEMENTS INITIAL CONDITION (3)
      G1=60.0
      RETURN
      END
      FUNCTION G2(Z)
C...
C...  FUNCTION G2(Z) IMPLEMENTS INITIAL CONDITION (4)
      G2=60.0
      RETURN
      END
      FUNCTION G3(T)
C...
C...  FUNCTION G3(T) IMPLEMENTS BOUNDARY CONDITION (5)
      G3=250.0
      RETURN
      END
      FUNCTION G4(T)
C...
C...  FUNCTION G4(T) IMPLEMENTS BOUNDARY CONDITION (6)
      G4=60.0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,      HAIR,        TA,       N21,        IP
C...
C...  BOUNDARY CONDITIONS (5) AND (6)
      TFP(1)  =G3(T)
      TFA(N21)=G4(T)
C...
C...  SPATIAL DERIVATIVES IN EQUATIONS (1) AND (2) ARE APPROXIMATED BY
C...  FIVE-POINT BIASED UPWIND APPROXIMATIONS
      CALL DSS020(0.,ZL,N21,TFP,TFPZ,+1.)
      CALL DSS020(0.,ZL,N21,TFA,TFAZ,-1.)
C...
C...  EQUATIONS (1) AND (2)
      DO 1 I=1,N21
      IF(I.EQ.1)GO TO 2
      TFPT(I)=-VP*TFPZ(I)-HP*(TFP(I)-TFA(I))
2     IF(I.EQ.N21)GO TO 1
      TFAT(I)= VA*TFAZ(I)+HA*(TFP(I)-TFA(I))
     1       +HAIR*(TA-TFA(I))
1     CONTINUE
      TFPT(1)=0.
      TFAT(N21)=0.
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,      NFIN,     NORUN
     1      /Y/   TFP(21),   TFA(21)
     2      /F/  TFPT(21),  TFAT(21)
     2      /S/  TFPZ(21),  TFAZ(21)
     4      /C/        ZL,        DZ,        VP,        VA,        HP,
     5                 HA,      HAIR,        TA,       N21,        IP
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      COMMON/PLOT/ TP(4,101), TPROF(6,21), TIMEP(101), ZP(21)
C...
C...  LABEL THE NUMERICAL OUTPUT
      IF(T.LT.0.05)WRITE(NO,2)
2     FORMAT(9X,1HT,4X,8HTFP(0,T),3X,9HTFP(ZL,T),
     1              4X,8HTFA(0,T),3X,9HTFA(ZL,T))
C...
C...  PRINT THE NUMERICAL SOLUTION EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))
     1 WRITE(NO,1)T,TFP(1),TFP(N21),TFA(1),TFA(N21)
1     FORMAT(F10.1,4F12.2)
C...
C...  STORE THE OUTLET TEMPERATURES FOR PLOTTING
      IF(NORUN.EQ.1)THEN
         TP(1,IP)=TFP(N21)
         TP(2,IP)=TFA(1)
      ELSE IF(NORUN.EQ.2)THEN
         TP(3,IP)=TFP(N21)
         TP(4,IP)=TFA(1)
      END IF
      TIMEP(IP)=T
C...
C...  STORE THE SOLUTION TO PLOT THE TEMPERATURE PROFILES
      IF(IP.EQ.1)IPROF=0
      IF((IP-1)*(IP-11)*(IP-21)*(IP-31)*(IP-41)*(IP-51).EQ.0)THEN
         IPROF=IPROF+1
      DO 10 I=1,N21
         TPROF(IPROF,I)=TFA(I)
         ZP(I)=ZL*FLOAT(I-1)/FLOAT(N21-1)
10    CONTINUE
      END IF
C...
C...  PLOT THE TEMPERATURE PROFILES
      IF(IP.LT.101)RETURN
      CALL SPLOTS(6,N21,ZP,TPROF)
      WRITE(NO,11)
11    FORMAT(1H ,//,
     1 ' TFA(Z,T) VS Z, T = 0, 1, 2, 3, 4, 5')
C...
C...  PLOT THE INLET AND OUTLET TEMPERATURES AT THE END OF THE SECOND
C...  RUN
      IF(NORUN.NE.2)RETURN
      CALL SPLOTS(4,IP,TIMEP,TP)
      WRITE(NO,12)
12    FORMAT(1H ,/,
     1 ' 1 - TFP(ZL,T), 2 - TFA(0,T), UA*DA = 0',/,
     2 ' 3 - TFP(ZL,T), 4 - TFA(0,T), UA*DA = 1')
      RETURN
      END
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
DYNAMICS OF A DOUBLE-PIPE HEAT EXCHANGER
0.        10.0      0.1
   42  100    1    1  REL 0.001
END OF RUNS
*APP HEAT44
      SUBROUTINE INITAL
C...
C...  WATER COOLING OF SULFURIC ACID
C...
C...  CONSIDER THE FOLLOWING SYSTEM OF TWO TANKS USED TO COOL SULFURIC
C...  ACID WITH A COUNTERCURRENT WATER STREAM (1)
C...
C                  TW1               TW2                TW3
C                   +......  .....................  ............ COLD
C                         .  .                   .  .           H2O IN
C                         .  .                   .  .
C                     .   .  .      .        .   .  .      .
C                     .   .  .      .        .   .  .      .
C                     ...............        ...............
C                     .   .  .      .        .   .  .      .
C HOT H2SO4 IN .......+   .  .      .........+   .  .      .......+
C 10,000 LB/HR   TA0  .   .  .      .  TA1   .   .  .      .     TA2
C                     .   .   .     .        .   .   .     .
C                     .   .COIL.    .        .   .COIL.    .
C                     .   .   .     .        .   .   .     .
C                     .   .  .      .        .   .  .      .
C                     .   ...       .        .   ...       .
C                     ...............        ...............
C...
C...  (1)  JENSON, V. G., AND G. V. JEFFREYS, MATHEMATICAL METHODS
C...       IN CHEMICAL ENGINEERING, ACADEMIC PRESS, NY, PP 68-72.
C...
C...  THE PARAMETERS AND VARIABLES FOR THE SYSTEM ARE
C...
C...     TA0         ACID FEED TEMPERATURE, C
C...
C...     TA1, TA2    ACID TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     TW3         WATER FEED TEMPERATURE, C
C...
C...     TW1, TW2    WATER TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     T           TIME, HOURS
C...
C...     W           WATER FLOW RATE, LB/HR
C...
C...     CPW         WATER SPECIFC HEAT, CHU/LB-C
C...
C...     M           ACID FLOW RATE, LB/HR
C...
C...     CPA         ACID SPECIFIC HEAT, CHU/LB-C
C...
C...     V           WEIGHT OF ACID IN EACH TANK, LB
C...
C...     A1          COIL HEAT TRANSFER AREA IN THE HOT TANK, FT**2
C...
C...     A2          COIL HEAT TRANSFER AREA IN THE COLD TANK, FT**2
C...
C...     U1          HEAT TRANSFER COEFFICIENT FOR THE HOT TANK,
C...                 CHU/HR-FT**2-C
C...
C...     U2          HEAT TRANSFER COEFFICIENT FOR THE COLD TANK,
C...                 CHU/HR-FT**2-C
C...
C...  DEVELOP A MATHEMATICAL MODEL TO COMPUTE TA1(T) AND TA2(T).
C...  ASSUME A LOG MEAN TEMPERATURE DIFFERENCE CAN BE USED FOR THE
C...  HEAT TRANSFER IN EACH COIL (CHU = CENTIGRADE HEAT UNIT IS THE
C...  HEAT REQUIRED TO RAISE ONE LB OF H2O ONE DEGREE CENTIGRADE =
C...  1.8 BTU).
C...
C...  BY A HEAT BALANCE ON THE FIRST TANK
C...
C...     V*CPA*DTA1/DT = W*CPW*TW2 + M*CPA*TA0
C...                                                            (1)
C...                   - W*CPW*TW1 - M*CPA*TA1
C...
C...  WHICH HAS THE INITIAL CONDITION
C...
C...     TA1(0) = TA10                                          (2)
C...
C...  SIMILARLY, FOR THE SECOND TANK,
C...
C...     V*CPA*DTA2/DT = W*CPW*TW3 + M*CPA*TA1
C...                                                            (3)
C...                   - W*CPW*TW2 - M*CPA*TA2
C...
C...     TA2(0) = TA20                                          (4)
C...
C...  EQUATIONS (1) TO (4) INVOLVE FOUR DEPENDENT VARIABLES, TA1,
C...  TA2, TW1 AND TW2, SO THAT TWO ADDITIONAL EQUATIONS ARE RE-
C...  QUIRED.  IF THE HEAT TRANSFER IS MODELED THROUGH A LOG-MEAN
C...  DELTA T, WE HAVE FOR THE FIRST TANK
C...
C...                                (TA1 - TW1) - (TA1 - TW2)
C...     W*CPW*(TW1 - TW2) = U1*A1-----------------------------   (5)
C...                              LN(TA1 - TW1) - LN(TA1 - TW2)
C...
C...                                (TA2 - TW2) - (TA2 - TW3)
C...     W*CPW*(TW2 - TW3) = U2*A2-----------------------------   (6)
C...                              LN(TA2 - TW2) - LN(TA2 - TW3)
C...
C...  EQUATIONS (5) AND (6) CAN BE EASILY REARRANGED (NOTE THE CANCEL-
C...  LATION IN THE NUMERATOR OF THE RHS, FOLLOWED BY THE CALCELLATION
C...  OF THE REMAINING TEMPERATURE DIFFERENCE FROM THE LHS AND RHS)
C...
C...     W*CPW = -U1*A1/LN((TA1 - TW1)/(TA1 - TW2))
C...
C...  OR
C...
C...     (TA1 - TW1)/(TA1 - TW2) = EXP(-(U1*A1)/(W*CPW)) = C1   (7)
C...
C...  SIMILARLY, FOR EQUATION (6),
C...
C...     (TA2 - TW2)/(TA2 - TW3) = EXP(-(U2*A2)/(W*CPW)) = C2   (8)
C...
C...  WHERE C1 AND C2 ARE THE INDICATED CONSTANTS.
C...
C...  EQUATIONS (7) AND (8) CAN BE REARRANGED AS
C...
C...     (TA2 - TW2) = C2*(TA2 - TW3)
C...
C...  OR
C...
C...     TW2 = TA2 - C2*(TA2 - TW3)                             (9)
C...
C...  AND
C...
C...     (TA1 - TW1) = C1*(TA1 - TW2)
C...
C...  OR
C...
C...     TW1 = TA1 - C1*(TA1 - TW2)                            (10)
C...
C...  EQUATIONS (9) AND (10) CAN BE USED TO CALCULATE TW2 AND TW1,
C...  RESPECTIVELY, WHICH ARE THEN USED IN EQUATIONS (1) AND (3).
C...
C...  THE SYSTEM NORMALLY RUNS AT A WATER RATE OF 7740 LB/HR.  THE
C...  PLANT ENGINEER HAS PROPOSED A REDUCTION IN THE WATER RATE
C...  TO 5000 LB/HR TO REDUCE COSTS.  WHAT IS THE STEADY STATE
C...  EXITING ACID TEMPERATURE, TA2, FOR THESE TWO CASES (MAKE TWO
C...  RUNS OF THE MODEL TO STEADY STATE).
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2
     2      /F/ DTA1DT, DTA2DT
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     IP
      REAL           M
C...
C...  SET THE MODEL PARAMETERS
      A1=69.3
      A2=95.8
      U1=200.
      U2=130.
      IF(NORUN.EQ.1)W=7740.
      IF(NORUN.EQ.2)W=5000.
      M=10000.
      V=10000.
      CPW=1.0
      CPA=0.36
      TA0=174.
      TW3=20.
C...
C...  CALCULATE SOME CONSTANTS
      C1=EXP(-(U1*A1)/(CPW*W))
      C2=EXP(-(U2*A2)/(CPW*W))
C...
C...  SET THE INITIAL CONDITIONS
      TA1=88.0
      TA2=45.0
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2
     2      /F/ DTA1DT, DTA2DT
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     IP
      REAL           M
C...
C...  EQUATION (9)
      TW2=TA2-C2*(TA2-TW3)
C...
C...  EQUATION (10)
      TW1=TA1-C1*(TA1-TW2)
C...
C...  EQUATION (1)
      DTA1DT=(1.0/(V*CPA))*(W*CPW*TW2+M*CPA*TA0
     1                     -W*CPW*TW1-M*CPA*TA1)
C...
C...  EQUATION (3)
      DTA2DT=(1.0/(V*CPA))*(W*CPW*TW3+M*CPA*TA1
     1                     -W*CPW*TW2-M*CPA*TA2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2
     2      /F/ DTA1DT, DTA2DT
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     IP
      REAL           M
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      DIMENSION TP(41), TA2P(2,41)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',8X,'TA1',8X,'TA2',4X,'DTA1/DT',4X,'DTA2/DT')
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,TA1,TA2,DTA1DT,DTA2DT
2        FORMAT(F10.2,2F11.2,2F11.4)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      TA2P(NORUN,IP)=TA2
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.41).OR.(NORUN.LT.2))RETURN
      CALL SPLOTS(NORUN,IP,TP,TA2P)
      WRITE(NO,10)
10    FORMAT(1H ,//,' TA2 VS T, 1 - W = 7740, 2 - W = 5000')
      END
WATER COOLING OF SULFURIC ACID, W = 7740 LB/HR
0.        2.0       0.05
    2 1000    1    1  REL 0.001
WATER COOLING OF SULFURIC ACID, W = 5000 LB/HR
0.        2.0       0.05
    2 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT45
      SUBROUTINE INITAL
C...
C...  COOLING OF SULFURIC ACID WITH LIMITED COOLING WATER
C...
C...  CONSIDER THE FOLLOWING SYSTEM OF TWO TANKS USED TO COOL SULFURIC
C...  ACID WITH A COUNTERCURRENT WATER STREAM REGULATED BY A FEEDBACK
C...  CONTROLLER (1)
C...
C                                                    CONTROL
C                                                     VALVE
C                                                      ...
C                                                   .....+... COLD H2O
C                                                   .  ...    IN, TW3
C                                                   .   .
C                  TW1              TW2             .   .
C                   +......  .....................  .   .
C                         .  .                   .  .  ...
C                         .  .                   .  .  . .+...TA2S = 45
C                         .  .                   .  .  ...   CONTROLLER
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .   .  .
C                     ...............        ...............
C                     .   .  .      .        .   .  .   .  .
C                     .   .  .      .        .   .  .  ... .
C                     .   .  .      .        .   .  .  ... .
C HOT H2SO4 IN .......+   .  .      .........+   .  .SENSOR.......+
C 10,000 LB/HR   TA0  .   .  .      .  TA1   .   .  .      .     TA2
C                     .   .   .     .        .   .   .     .
C                     .   .COIL.    .        .   .COIL.    .
C                     .   .   .     .        .   .   .     .
C                     .   .  .      .        .   .  .      .
C                     .   ...       .        .   ...       .
C                     ...............        ...............
C...
C...  (1)  JENSON, V. G., AND G. V. JEFFREYS, MATHEMATICAL METHODS
C...       IN CHEMICAL ENGINEERING, ACADEMIC PRESS, NY, PP 68-72.
C...
C...  THE PARAMETERS AND VARIABLES FOR THE SYSTEM ARE
C...
C...     TA0         ACID FEED TEMPERATURE, C
C...
C...     TA1, TA2    ACID TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     TA2S        SET POINT FOR THE CONTROLLER, C
C...
C...     TW3         WATER FEED TEMPERATURE, C
C...
C...     TW1, TW2    WATER TEMPERATURES FROM THE FIRST AND SECOND TANKS,
C...                 RESPECTIVELY, C
C...
C...     T           TIME, HOURS
C...
C...     W           WATER FLOW RATE, LB/HR
C...
C...     CPW         WATER SPECIFC HEAT, CHU/LB-C
C...
C...     M           ACID FLOW RATE, LB/HR
C...
C...     CPA         ACID SPECIFIC HEAT, CHU/LB-C
C...
C...     V           WEIGHT OF ACID IN EACH TANK, LB
C...
C...     A1          COIL HEAT TRANSFER AREA IN THE HOT TANK, FT**2
C...
C...     A2          COIL HEAT TRANSFER AREA IN THE COLD TANK, FT**2
C...
C...     U1          HEAT TRANSFER COEFFICIENT FOR THE HOT TANK,
C...                 CHU/HR-FT**2-C
C...
C...     U2          HEAT TRANSFER COEFFICIENT FOR THE COLD TANK,
C...                 CHU/HR-FT**2-C
C...
C...     KC          CONTROLLER GAIN, LB/HR-C
C...
C...     TI          CONTROLLER INTEGRAL TIME, HR
C...
C...  DEVELOP A MATHEMATICAL MODEL TO COMPUTE TA1(T) AND TA2(T).
C...  ASSUME A LOG MEAN TEMPERATURE DIFFERENCE CAN BE USED FOR THE
C...  HEAT TRANSFER IN EACH COIL (CHU = CENTIGRADE HEAT UNIT IS THE
C...  HEAT REQUIRED TO RAISE ONE LB OF H2O ONE DEGREE CENTIGRADE =
C...  1.8 BTU).  A PROPORTIONAL-INTEGRAL FEEDBACK CONTROLLER
C...  REGULATES THE COOLING WATER FLOW RATE BY SENSING THE ACID
C...  TEMPERATURE IN THE SECOND TANK, I.E., TA2.
C...
C...  BY A HEAT BALANCE ON THE FIRST TANK
C...
C...     V*CPA*DTA1/DT = W*CPW*TW2 + M*CPA*TA0
C...                                                            (1)
C...                   - W*CPW*TW1 - M*CPA*TA1
C...
C...  WHICH HAS THE INITIAL CONDITION
C...
C...     TA1(0) = TA10                                          (2)
C...
C...  SIMILARLY, FOR THE SECOND TANK,
C...
C...     V*CPA*DTA2/DT = W*CPW*TW3 + M*CPA*TA1
C...                                                            (3)
C...                   - W*CPW*TW2 - M*CPA*TA2
C...
C...     TA2(0) = TA20                                          (4)
C...
C...  EQUATIONS (1) TO (4) INVOLVE FOUR DEPENDENT VARIABLES, TA1,
C...  TA2, TW1 AND TW2, SO THAT TWO ADDITIONAL EQUATIONS ARE RE-
C...  QUIRED.  IF THE HEAT TRANSFER IS MODELED THROUGH A LOG-MEAN
C...  DELTA T, WE HAVE FOR THE FIRST TANK
C...
C...                                (TA1 - TW1) - (TA1 - TW2)
C...     W*CPW*(TW1 - TW2) = U1*A1-----------------------------   (5)
C...                              LN(TA1 - TW1) - LN(TA1 - TW2)
C...
C...                                (TA2 - TW2) - (TA2 - TW3)
C...     W*CPW*(TW2 - TW3) = U2*A2-----------------------------   (6)
C...                              LN(TA2 - TW2) - LN(TA2 - TW3)
C...
C...  EQUATIONS (5) AND (6) CAN BE EASILY REARRANGED (NOTE THE CANCEL-
C...  LATION IN THE NUMERATOR OF THE RHS, FOLLOWED BY THE CALCELLATION
C...  OF THE REMAINING TEMPERATURE DIFFERENCE FROM THE LHS AND RHS)
C...
C...     W*CPW = -U1*A1/LN((TA1 - TW1)/(TA1 - TW2))
C...
C...  OR
C...
C...     (TA1 - TW1)/(TA1 - TW2) = EXP(-(U1*A1)/(W*CPW)) = C1   (7)
C...
C...  SIMILARLY, FOR EQUATION (6),
C...
C...     (TA2 - TW2)/(TA2 - TW3) = EXP(-(U2*A2)/(W*CPW)) = C2   (8)
C...
C...  WHERE C1 AND C2 ARE THE INDICATED CONSTANTS.
C...
C...  EQUATIONS (7) AND (8) CAN BE REARRANGED AS
C...
C...     (TA2 - TW2) = C2*(TA2 - TW3)
C...
C...  OR
C...
C...     TW2 = TA2 - C2*(TA2 - TW3)                             (9)
C...
C...  AND
C...
C...     (TA1 - TW1) = C1*(TA1 - TW2)
C...
C...  OR
C...
C...     TW1 = TA1 - C1*(TA1 - TW2)                            (10)
C...
C...  EQUATIONS (9) AND (10) CAN BE USED TO CALCULATE TW2 AND TW1,
C...  RESPECTIVELY, WHICH ARE THEN USED IN EQUATIONS (1) AND (3).
C...
C...  THE SYSTEM NORMALLY RUNS AT A WATER RATE OF 7740 LB/HR.  THERE-
C...  FORE, THE CONTROLLER EQUATION WILL BE TAKEN AS
C...
C...                                T
C...     W = 7740 + KC*(E + (1/TI) INT E*DT)                    (11)
C...                                0
C...
C...  WHERE E IS THE ERROR, I.E., E = TA2 - TA2S, TA2S = 45.  SELECT
C...  KC AND TI TO ACHIEVE ACCEPTABLE CONTROL WHEN THE INLET ACID
C...  TEMPERATURE, TA0, INCREASES FROM THE USUAL STEADY STATE VALUE
C...  OF 174 TO 275 C.
C...
C...  ALSO, THE POSSIBILITY OF INSUFFICIENT COOLING WATER IS TO
C...  BE STUDIED.  SPECIFICALLY, THE WATER RATE, W, GIVEN BY
C...  EQUATION (11) MAY NOT BE AVAILABLE.  TO INVESTIGATE THIS
C...  CONDITION, FOUR RUNS ARE PROGRAMMED IN WHICH W IS LIMITED
C...  ACCORDING TO THE FOLLOWING TABLE:
C...
C...     RUN NO.           W (MAXIMUM)
C...
C...       1               UNLIMITED
C...
C...       2               W LIMITED TO 16,000 LB/HR
C...
C...       3               W LIMITED TO 13,000 LB/HR
C...
C...       4               W LIMITED TO 10,000 LB/HR
C...
C...  THE EFFECT OF THESE LIMITS ON W CAN BE OBSERVED IN THE OUTPUT,
C...  IN WHICH THE ERROR, E, AND W ARE PLOTTED TOGETHER FOR THE FOUR
C...  CASES.
C...
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...
C...  SET THE MODEL PARAMETERS
      A1=69.3
      A2=95.8
      U1=200.
      U2=130.
      M=10000.
      V=10000.
      CPW=1.0
      CPA=0.36
      TW3=20.
      TA0=275.
      TA2S=45.
      KC=300.
      TI=0.05
C...
C...  SET THE INITIAL CONDITIONS
      TA1=88.0
      TA2=45.0
      EI=0.
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  CONTROLLER EQUATION
      E=TA2-TA2S
      W=7740+KC*(E+(1.0/TI)*EI)
C...
C...  INCLUDE THE EFFECT OF LIMITED WATER SUPPLY
      IF(NORUN.EQ.1)THEN
1        CONTINUE
      ELSE IF(NORUN.EQ.2)THEN
         IF(W.GT.16000.)W=16000.
      ELSE IF(NORUN.EQ.3)THEN
         IF(W.GT.13000.)W=13000.
      ELSE IF(NORUN.EQ.4)THEN
         IF(W.GT.10000.)W=10000.
      END IF
C...
C...  CALCULATE SOME CONSTANTS
      C1=EXP(-(U1*A1)/(CPW*W))
      C2=EXP(-(U2*A2)/(CPW*W))
C...
C...  EQUATION (9)
      TW2=TA2-C2*(TA2-TW3)
C...
C...  EQUATION (10)
      TW1=TA1-C1*(TA1-TW2)
C...
C...  EQUATION (1)
      DTA1DT=(1.0/(V*CPA))*(W*CPW*TW2+M*CPA*TA0
     1                     -W*CPW*TW1-M*CPA*TA1)
C...
C...  EQUATION (3)
      DTA2DT=(1.0/(V*CPA))*(W*CPW*TW3+M*CPA*TA1
     1                     -W*CPW*TW2-M*CPA*TA2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/      T,  NSTOP,  NORUN
     1      /Y/    TA1,    TA2,     EI
     2      /F/ DTA1DT, DTA2DT,      E
     3      /C/    TA0,    TW3,      V,      W,      M,    CPA,
     4             CPW,     C1,     C2,     KC,     TI,   TA2S,
     5              U1,     U2,     A1,     A2,     IP
      REAL           M,     KC
C...
C...  DIMENSION THE ARRAYS FOR THE PLOTTED SOLUTION
      REAL TP(41), EP(4,41), WP(4,41)
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IF(IP.EQ.0)THEN
         WRITE(NO,1)
1        FORMAT(9X,'T',8X,'TA2',10X,'E',10X,'W')
      END IF
C...
C...  PRINT THE SOLUTION EVERY FIFTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/5*5).EQ.(IP-1))THEN
         WRITE(NO,2)T,TA2,E,W
2        FORMAT(F10.2,2F11.2,F11.1)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      EP(NORUN,IP)=E
      WP(NORUN,IP)=W
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN
      IF((IP.LT.41).OR.(NORUN.LT.4))RETURN
      CALL SPLOTS(NORUN,IP,TP,EP)
      WRITE(NO,10)
10    FORMAT(1H ,//,' E VS T')
      CALL SPLOTS(NORUN,IP,TP,WP)
      WRITE(NO,11)
11    FORMAT(1H ,//,' W VS T')
C...
C...  PLOT THE SOLUTIONS ON A CONTINUOUS PLOTTER
C...
C...  ****************************************************************
C...
C...  THE FOLLOWING CALLS TO A CONTINUOUS PLOTTER ARE MACHINE
C...  DEPENDENT, AND MUST BE MODIFIED FOR OTHER PLOTTERS OR
C...  CHANGED TO COMMENTS
C...
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,EP,IP,3H*T*,6H*E(T)*,12H*ERROR VS T*,4)
C...  CALL QIKSAX(3,3)
C...  CALL QIKPLT(TP,WP,IP,3H*T*,6H*W(T)*,17H*WATER RATE VS T*,4)
C...
C...  ****************************************************************
C...
      RETURN
      END
COOLING OF SULFURIC ACID, NO LIMIT ON COOLING WATER
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 16000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 13000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
COOLING OF SULFURIC ACID, COOLING WATER LIMITED TO 10000
0.        2.0       0.05
    3 1000    1    1  REL 0.001
END OF RUNS
*APP HEAT46
      SUBROUTINE INITAL
C...
C...  HEAT CONDUCTION IN A FINITE CYLINDER
C...
C...  CONSIDER THE FOLLOWING TWO-DIMENSIONAL, PARABOLIC PARTIAL
C...  DIFFERENTIAL EQUATION (PDE) FOR HEAT CONDUCTION IN A FINITE
C...  CYLINDER (1):
C...
C...     U  = D*(U   + (1/R)*U  + U  )                          (1)
C...      T       RR          R    ZZ
C...
C...  WHERE
C...
C...     U       TEMPERATURE
C...
C...     R       CYLINDER RADIAL COORDINATE
C...
C...     Z       CYLINDER AXIAL COORDINATE
C...
C...     T       TIME
C...
C...     D       THERMAL DIFFUSIVITY (= K/(RHO*CP))
C...
C...     K       THERMAL CONDUCTIVITY
C...
C...     RHO     DENSITY
C...
C...     CP      SPECIFIC HEAT
C...
C...  (1)  THIS PROBLEM WAS DEVELOPED BY DR. E. J. NOLAN, MILK COMPON-
C...       ENTS BRANCH, UNITED STATES DEPARTMENT OF AGRICULTURE, AGRI-
C...       CULTURAL RESEARCH SERVICE, NORTH ATLANTIC AREA, EASTERN
C...       REGIONAL RESEARCH CENTER, 600 MERMAID LANE, PHILADELPHIA,
C...       PA 19118
C...
C...  THE AUXILIARY CONDITIONS FOR EQUATION (1) ARE
C...
C...     U(R,Z,0) = U0                                          (2)
C...
C...     U(RA,Z,T) = U(R,0,T) = U(R,ZL,T) = US, U (0,Z,T) = 0 (3)(4)
C...                                             R            (5)(6)
C...  WHERE
C...
C...     RA      CYLINDER RADIUS
C...
C...     ZL      CYLINDER LENGTH
C...
C...     U0      INITIAL TEMPERATURE
C...
C...     US      SURFACE TEMPERATURE
C...
C...  IN ADDITION TO THE TEMPERATURE FIELD, U(R,Z,T), TWO OTHER RELATED
C...  QUANTITIES, THE TOTAL HEAT CONTENT, QTOT, AND THE TIME INTEGRATED
C...  HEAT FLUX, QI, ARE OF INTEREST, AND ARE GIVEN BY THE EQUATIONS
C...
C...     QTOT = PI*(RA**2)*ZL*RHO*CP*(UAVG - U0)                (7)
C...
C...           T
C...     QI = INT (QR**2 + QZ0**2 + QZL**2)**0.5 DT             (8)
C...           0
C...
C...  WHERE
C...
C...     UAVG   TEMPERATURE AVERAGED OVER THE CYLINDER
C...
C...     QR     RADIAL HEAT FLUX AT R = RA, Z = ZL/2 (= -K*U (RA,ZL/2,T))
C...                                                        R
C...
C...     QZ0    AXIAL HEAT FLUX AT R = RA, Z = 0 (= -K*U (RA,0,T))
C...                                                    Z
C...
C...     QZL    AXIAL HEAT FLUX AT R = RA, Z = ZL (= -K*U (RA,ZL,T))
C...                                                     Z
C...
C...  THE AVERAGE TEMPERATURE, UAVG IS COMPUTED FROM
C...
C...             ZL  RA
C...            INT INT 2*PI*R*U DR DZ
C...             0   0
C...     UAVG = ----------------------                          (9)
C...             ZL  RA
C...            INT INT 2*PI*R DR DZ
C...             0   0
C...
C...  THE INTEGRAL IN EQUATION (8) IS COMPUTED BY THE USUAL TIME
C...  INTEGRATION OF DSS/2 (THROUGH VARIABLES IN COMMON/F/ AND /Y/).
C...  THE INTEGRAL IN THE NUMERATOR OF EQUATION (9) IS COMPUTED BY
C...  A COMBINATION OF SUBROUTINES LINT2 (PART OF DSS/2) AND TWODQ
C...  (FROM THE IMSL LIBRARY).  IF THE IMSL LIBRARY IS NOT AVAILABLE,
C...  TWODQ CAN BE REPLACED BY ANOTHER ROUTINE FOR TWO DIMENSIONAL
C...  INTEGRALS, OR THE CALCULATION OF UAVG AND QTOT IN SUBROUTINE
C...  PRINT CAN BE COMMENTED OUT.  THE INTEGRAL IN THE DENOMINATOR OF
C...  EQUATION (9) IS, OF COURSE, JUST THE VOLUME OF THE CYLINDER,
C...  PI*(RA**2)*ZL.
C...
C...  THE SOLUTION TO EQUATION (1) HAS THE PROPERTY U(R,Z,INF) = US.
C...  THUS, UAVG(INF) = US AND FROM EQUATION (7)
C...
C...     QTOT(INF) = PI*(RA**2)*ZL*RHO*CP*(US - U0)       (10)
C...
C...  QTOT(INF) CAN BE CALCULATED INDEPENDENTLY FROM EQUATION (10)
C...  AND USED TO CHECK THE NUMERICAL RESULT FOR LARGE TIME.  FOR
C...  EXAMPLE, IF U0 = 25, US = 50, RA = 1, ZL = 5, RHO = 1, CP = 1,
C...
C...     QTOT(INF) = PI*(1**2)*5*(50 - 25) = PI*125 = 392.7
C...
C...  THE FOLLOWING CODING IN AN IMPLEMENTATION OF EQUATIONS (1) TO
C...  (10).
C...
C...  USUAL DSS/2 COMMON AREAS
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/   U(6,11),        QI
     2      /F/  UT(6,11),         Q
     3      /S/  UR(6,11), URR(6,11),  UZ(6,11), UZZ(6,11)
     4      /C/        RA,        ZL,        US,        U0,         K,
     5                RHO,        CP,         D,      R(6),        QR,
     6                QZ0,       QZL,      UAVG,      QTOT,        PI
     7      /I/        NR,        NZ,        IP
      REAL              K
C...
C...  COMMON AREA TO ACCESS THE INPUT/OUTPUT UNIT NUMBERS
      COMMIN/IO/ NI, NO
C...
C...  SET THE MODEL PARAMETERS
C...
C...     CYLINDER RADIUS
         RA=1.0
C...
C...     CYLINDER LENGTH
         ZL=5.0
C...
C...     PI
         PI=3.1415927
C...
C...     AMBIENT TEMPERATURE
         US=50.
C...
C...     INITIAL TEMPERATURE
         U0=25.
C...
C...     THERMAL CONDUCITIVITY
         K=1.0
C...
C...     DENSITY
         RHO=1.0
C...
C...     SPECIFIC HEAT
         CP=1.0
C...
C...     THERMAL DIFFUSIVITY
         D=K/(RHO*CP)
C...
C...     RADIAL GRID POINTS
         NR=6
C...
C...     AXIAL GRID POINTS
         NZ=11
C...
C...  INITIAL CONDITION FOR THE PDE
      DO 1 I=1,NR
      DO 1 J=1,NZ
      U(I,J)=U0
1     CONTINUE
C...
C...  INITIAL CONDITION FOR THE TIME INTEGRATED HEAT FLUX
      QI=0.
C...
C...  PRINT THE INITIAL CONDITION WITHOUT THE BOUNDARY CONDITIONS (IP
C...  IS INITIALIZED HERE AND PASSED THROUGH COMMON TO CONTROL THE
C...  OUTPUT IN SUBROUTINE PRINT)
      IP=0
      CALL PRINT(NI,NO)
C...
C...  INCLUDE THE BOUNDARY CONDITIONS INITIALLY
      CALL DERV
C...
C...  THE INITIAL CONDITION WITH THE BOUNDARY CONDITIONS WILL BE
C...  PRINTED AFTER THE FOLLOWING RETURN BY A CALL TO SUBROUTINE
C...  PRINT FROM THE DSS/2 MAIN PROGRAM
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/   U(6,11),        QI
     2      /F/  UT(6,11),         Q
     3      /S/  UR(6,11), URR(6,11),  UZ(6,11), UZZ(6,11)
     4      /C/        RA,        ZL,        US,        U0,         K,
     5                RHO,        CP,         D,      R(6),        QR,
     6                QZ0,       QZL,      UAVG,      QTOT,        PI
     7      /I/        NR,        NZ,        IP
      REAL              K
C...
C...  ELIMINATE ANY SMALL OSCILLATION DUE TO THE DISCONTINUITY AT T = 0
C...  IN THE SECOND RUN
      IF(NORUN.EQ.2)THEN
      DO 8 I=1,NR
      DO 8 J=1,NZ
      IF(U(I,J).LT.U0)U(I,J)=U0
8     CONTINUE
      END IF
C...
C...  BOUNDARY CONDITION AT R = RA
      DO 1 J=1,NZ
      U(NR,J)=US
1     CONTINUE
C...
C...  BOUNDARY CONDITION AT Z = 0
      DO 2 I=1,NR
      U(I,1)=US
2     CONTINUE
C...
C...  BOUNDARY CONDITION AT Z = ZL
      DO 3 I=1,NR
      U(I,NZ)=US
3     CONTINUE
C...
C...  DERIVATIVE UR
      CALL DSS034(0.,RA,NR,NZ,1,U,UR,0.)
C...
C...  DERIVATIVE UZ
      CALL DSS034(0.,ZL,NR,NZ,2,U,UZ,0.)
C...
C...  BOUNDARY CONDITION AT R = 0
      DO 4 J=1,NZ
      UR(1,J)=0.
4     CONTINUE
C...
C...  DERIVATIVE URR
      CALL DSS034(0.,RA,NR,NZ,1,UR,URR,0.)
C...
C...  DERIVATIVE UZZ
      CALL DSS034(0.,ZL,NR,NZ,2,UZ,UZZ,0.)
C...
C...  PDE
      DO 5 I=1,NR
      DO 5 J=1,NZ
      IF(I.EQ.1)THEN
         UT(I,J)=D*(2.0*URR(I,J)+UZZ(I,J))
      ELSE
         R(I)=(RA-0.)*FLOAT(I-1)/FLOAT(NR-1)
         UT(I,J)=D*(URR(I,J)+1.0/R(I)*UR(I,J)+UZZ(I,J))
      END IF
5     CONTINUE
C...
C...  ZERO THE TIME DERIVATIVES AT THE BOUNDARIES Z = 0, ZL
      DO 6 I=1,NR
      UT(I, 1)=0.
      UT(I,NZ)=0.
6     CONTINUE
C...
C...  ZERO THE TIME DERIVATIVE AT THE BOUNDARY R = RA
      DO 7 J=1,NZ
      UT(NR,J)=0.
7     CONTINUE
C...
C...  COMPUTE THE TIME INTEGRATED HEAT FLUX AT THE CENTER (R = 0,
C...  Z = ZL/2)
C...
C...     SURFACE FLUX AT R = RA, Z = ZL/2
         QR=-K*UR(NR,NZ/2+1)
C...
C...     SURFACE FLUX AT R = RA, Z = 0
         QZ0=-K*UZ(NR,1)
C...
C...     SURFACE FLUX AT R = RA, Z = ZL
         QZL=-K*UZ(NR,NZ)
C...
C...     MAGNITUDE OF THE THREE FLUXES
         Q=SQRT(QR**2+QZ0**2+QZL**2)
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/   U(6,11),        QI
     2      /F/  UT(6,11),         Q
     3      /S/  UR(6,11), URR(6,11),  UZ(6,11), UZZ(6,11)
     4      /C/        RA,        ZL,        US,        U0,         K,
     5                RHO,        CP,         D,      R(6),        QR,
     6                QZ0,       QZL,      UAVG,      QTOT,        PI
     7      /I/        NR,        NZ,        IP
      REAL              K
C...
C...  DIMENSION THE ARRAYS FOR PLOTTING
      REAL TP(51), UP(2,51), QIP(2,51)
C...
C...  EXTERNAL THE FUNCTIONS CALLED BY IMSL SUBROUTINE TWODQ
      EXTERNAL FCN, RLOWER, RUPPER
C...
C...  PRINT THE NUMERICAL SOLUTON EVERY TENTH CALL TO SUBROUTINE PRINT
      IP=IP+1
      IF(((IP-1)/10*10).EQ.(IP-1))THEN
C...
C...  U(X,Y,T) VS X AND Y AT THE CURRENT T
      WRITE(NO,1)T,((U(I,J),I=1,NR,1),J=1,NZ,2)
1     FORMAT(1H ,//,' T = ',F7.2,/,
     1 10X,'       R=0','  R=0.2*RA','  R=0.4*RA',
     2     '  R=0.6*RA','  R=0.8*RA','      R=RA',/,
     3 '       Z=0',6F10.3,/,'  Z=0.2*ZL',6F10.3,/,
     4 '  Z=0.4*ZL',6F10.3,/,'  Z=0.6*ZL',6F10.3,/,
     5 '  Z=0.8*ZL',6F10.3,/,'      Z=ZL',6F10.3,)
C...
C...  PRINT THE TIME INTEGRATED HEAT FLUX
      WRITE(NO,2)QI
2     FORMAT(1H ,/,' QI = ',F10.2)
C...
C...  COMPUTE THE INTEGRAL AVERAGE TEMPERATURE USING IMSL SUBROUTINE
C...  TWODQ FOR TWO-DIMENSIONAL INTEGRALS
      ERRABS=0.01
      ERRREL=0.001
      IRULE=1
      CALL TWODQ(FCN,0.,ZL,RLOWER,RUPPER,ERRABS,ERRREL,IRULE,UAVG,ERR)
C...
C...  THE INTEGRAL IS DIVIDED BY THE VOLUME OF THE CYLINDER TO OBTAIN
C...  THE INTEGRAL AVERAGE TEMPERATURE
      VOL=PI*(RA**2)*ZL
      UAVG=UAVG/VOL
C...
C...  COMPUTE THE TOTAL HEAT CONTENT
      QTOT=VOL*RHO*CP*(UAVG-U0)
C...
C...  PRINT THE AVERAGE TEMPERATURE, TOTAL HEAT CONTENT
      WRITE(NO,3)UAVG,QTOT
3     FORMAT(1H ,/,' AVERAGE TEMPERATURE = ',F10.2,//,
     1             ' TOTAL HEAT CONTENT  = ',F10.2,//)
      END IF
C...
C...  STORE THE SOLUTION FOR PLOTTING
      TP(IP)=T
      UP(NORUN,IP)=U(1,NZ/2+1)
      QIP(NORUN,IP)=QI
C...
C...  PLOT THE SOLUTION AT THE END OF THE SECOND RUN (TO DEMONSTRATE
C...  THE EFFECT OF SETTING U = U0 AT THE BEGINNING OF SUBROUTINE DERV)
      IF((IP.LT.51).OR.(NORUN.LT.2))RETURN
C...
C...  U(0,ZL/2,T) VS T
      CALL TPLOTS(NORUN,IP,TP,UP)
      WRITE(NO,11)
11    FORMAT(1H ,/,' U(0,ZL/2,T) VS T',/,
     1             ' 1 - NO LOWER CONSTRAINT',
     2          3X,' 2 - U = U0 CONSTRAINT')
C...
C...  QI(T) VS T
      CALL TPLOTS(NORUN,IP,TP,QIP)
      WRITE(NO,12)
12    FORMAT(1H ,/,' TIME INTEGRATED HEAT FLUX, QI(T), VS T',/,
     1             ' 1 - NO LOWER CONSTRAINT',
     2          3X,' 2 - U = U0 CONSTRAINT')
      RETURN
      END
      REAL FUNCTION FCN(Z,R)
C...
C...  FUNCTION FCN DEFINES THE INTEGRAND OF THE TWO-DIMENSIONAL
C...  INTEGRAL IN R AND Z FOR THE AVERAGE TEMPERATURE
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/   U(6,11),        QI
     2      /F/  UT(6,11),         Q
     3      /S/  UR(6,11), URR(6,11),  UZ(6,11), UZZ(6,11)
     4      /C/        RA,        ZL,        US,        U0,         K,
     5                RHO,        CP,         D,    DUM(6),        QR,
     6                QZ0,       QZL,      UAVG,      QTOT,        PI
     7      /I/        NR,        NZ,        IP
      REAL              K
C...
C...  PERFORM A LINEAR INTERPOLATION IN THE TEMPERATURE AT R AND Z.
C...  SUBROUTINE LINT2 IS PART OF DSS/2, AND IS DESCRIBED IN AN
C...  APPENDIX OF MANUAL NO. 1
      CALL LINT2(NR,0.,RA,R,NZ,0.,ZL,Z,U,UINT,NERR1,NERR2)
C...
C...  EVALUATE THE INTEGRAND
      FCN=2.0*PI*R*UINT
      RETURN
      END
      REAL FUNCTION RLOWER(R)
C...
C...  FUNCTION RLOWER SETS THE LOWER LIMIT ON THE INTEGRAL IN R FOR
C...  COMPUTING THE AVERAGE TEMPERATURE
C...
      RLOWER=0.
      RETURN
      END
      REAL FUNCTION RUPPER(R)
C...
C...  FUNCTION RUPPER SETS THE UPPER LIMIT ON THE INTEGRAL IN R FOR
C...  COMPUTING THE AVERAGE TEMPERATURE
C...
C...  THE UPPER LIMIT IS AVAILABLE THROUGH COMMON/C/
      COMMON/C/        RA
C...
      RUPPER=RA
      RETURN
      END
TWO-DIMENSIONAL HEAT CONDUCTION
0.        1.        0.02
   67 1000    1    1  ABS 0.01
TWO-DIMENSIONAL HEAT CONDUCTION
0.        1.        0.02
   67 1000    1    1  ABS 0.01
END OF RUNS
*APP HEAT47
      SUBROUTINE INITAL
C...
C...  HEAT CONDUCTION WITH INTERNAL HEAT GENERATION
C...
C...  CONSIDER THE FOLLOWING ONE-DIMENSIONAL FORM OF FOURIER'S SECOND
C...  LAW WITH AN INTERNAL HEAT GENERATION TERM
C...
C...     RHO*CP*TC  = K*TC   + Q                                     (1)
C...              T       XX
C...
C...  WHERE
C...
C...     TC      TEMPERATURE (C)
C...
C...     T       TIME (MIN)
C...
C...     X       SPATIAL COORDINATE (CM)
C...
C...     RHO     DENSITY = 1 GM/CM**3
C...
C...     CP      HEAT CAPACITY = 1 CAL/GM-C
C...
C...     K       THERMAL CONDUCTIVITY = 2 CAL/MIN-CM-C
C...
C...     Q       VOLUEMTRIC RATE OF HEAT GENERATION = 40 CAL/MIN-CM**3
C...
C...  THE AUXILIARY CONDITIONS FOR EQUATION (1) WILL BE TAKEN AS:
C...
C...     TC(X,0) = T0                                                (2)
C...
C...     TC (0,T) = 0, K*TC (XL,T) = U*(TA - TC(XL,T))            (3)(4)
C...       X               X
C...
C...  WHERE
C...
C...     T0       INITIAL TEMPERATURE = 25 C
C...
C...     XL       LENGTH OF THE SOLID = 1 CM
C...
C...     U        HEAT TRANSFER COEFFICIENT = 5 CAL/MIN-CM**2-C
C...
C...     TA       AMBIENT TEMPERATURE = 15 C
C...
C...  EQUATIONS (1) TO (4) ARE INTEGRATED NUMERICALLY IN THE FOLLOWING
C...  CODE.  THE NUMERICAL SOLUTION AT INFINITE T IS ALSO COMPARED WITH
C...  THE STEADY STATE ANALYTICAL SOLUTION, DERIVED IN THE FOLLOWING
C...  WAY
C...
C...  AT STEADY STATE (INFINITE TIME), EQUATIONS (1) TO (4) REDUCE TO
C...
C...    K*TC   = -Q, TC (0) = 0, K*TC (XL,T) = U*(TA - TC(0))  (5)(6)(7)
C...        XX         X
C...
C...  EQUATION (5) EASILY INTEGRATES ONCE TO
C...
C...     TC  = (-Q/K)*X + C1                                         (8)
C...       X
C...
C...  AND A SECOND TIME TO:
C...
C...     TC = (-Q/K)*X**2/2 + C1*X + C2                              (9)
C...
C...  WHERE C1 AND C2 ARE CONSTANTS.
C...
C...  APPLICATION OF EQUATION (6) TO EQUATION (8) GIVES C1 = 0.  APPLI-
C...  CATION OF EQUATION (7) TO EQUATION (9) GIVES
C...
C...     C2 = TA + (Q/K)*XL**2/2 + Q*XL/U                           (10)
C...
C...  NOW, EQUATION (9) CAN BE USED TO COMPUTE THE STEADY STATE ANAL-
C...  YTICAL SOLUTION FOR COMPARISON WITH THE NUMERICAL SOLUTION.
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(21)
     2      /F/    TT(21)
     3      /S/    TX(21),   TXX(21)
     4      /C/       RHO,        CP,         K,         Q,         U,
     5                 TA,        XL,        T0,         N,        IP
      REAL K
C...
C...  SET THE MODEL PARAMETERS
      RHO=1.0
      CP=1.0
      K=2.0
      Q=40.0
      U=5.0
      TA=15.
      XL=1.0
C...
C...  INITIAL CONDITION (2)
      N=21
      T0=25.
      DO 1 I=1,N
      TC(I)=T0
1     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(21)
     2      /F/    TT(21)
     3      /S/    TX(21),   TXX(21)
     4      /C/       RHO,        CP,         K,         Q,         U,
     5                 TA,        XL,        T0,         N,        IP
      REAL K
C...
C...  BOUNDARY CONDITION (3)
      TX(1)=0.
C...
C...  BOUNDARY CONDITION (4)
      TX(N)=(U/K)*(TA-TC(N))
C...
C...  COMPUTE TXX
      CALL DSS042(0.,XL,N,TC,TX,TXX,2,2)
C...
C...  PDE (1)
      DO 1 I=1,N
      TT(I)=K*TXX(I)+Q
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/    TC(21)
     2      /F/    TT(21)
     3      /S/    TX(21),   TXX(21)
     4      /C/       RHO,        CP,         K,         Q,         U,
     5                 TA,        XL,        T0,         N,        IP
      REAL K
C...
C...  PRINT A HEADING FOR THE SOLUTION
      IP=IP+1
      IF(IP.EQ.1)WRITE(NO,1)
1     FORMAT(9X,'T',2X,'TC(0.00*XL,T)',2X,'TC(0.25*XL,T)',
     1              2X,'TC(0.50*XL,T)',2X,'TC(0.75*XL,T)',
     2              2X,'TC(1.00*XL,T)')
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)T,(TC(I),I=1,N,5)
2     FORMAT(F10.2,5F15.2)
C...
C...  AT THE END OF THE RUN, COMPUTE AND PRINT THE STEADY STATE ANAL-
C...  YTICAL SOLUTION, EQUATIONS (9) AND (10)
      IF(IP.LT.11)RETURN
      X=-XL/4.
      C2=TA+(Q/K)*XL**2/2.+Q*XL/U
      WRITE(NO,5)
5     FORMAT(//,' STEADY STATE ANALYTICAL SOLUTION',/,9X,'X',9X,'TCA')
C...
C...  STEP THROUGH FIVE VALUES OF X IN COMPUTING THE STEADY STATE ANAL-
C...  YTICAL SOLUTION
      DO 3 I=1,5
      X=X+XL/4
      TCA=(-Q/K)*X**2/2.+C2
      WRITE(NO,4)X,TCA
4     FORMAT(F10.3,F12.4)
3     CONTINUE
      RETURN
      END
HEAT CONDUCTION WITH INTERNAL HEAT GENERATION
0.        5.0       0.5
   2110000    1    1  REL 0.001
END OF RUNS
*APP HEAT48
      SUBROUTINE INITAL
C...
C...  HEATING A LIQUID IN A TUBE WITH AXIAL CONDUCTION
C...
C...  A LIQUID FLOWS ALONG A HEATED TUBE AT F MOLES/S.  THE JACKET
C...  TEMPERATURE IS T ; THE TUBE CROSS-SECTIONAL AREA IS A AND ITS
C...                  J
C...  PERIMETER IS P.  LIQUID DENISTY IS CONSTANT AT RHO MOLES/M**3,
C...  AND HEAT TRANSFER IS CONSTANT AT UA.
C...
C...
C...  THE FOLLOWING MODEL HAS BEEN PROPOSED BY SARGENT (1):
C...
C...  RHO*A*H  = (K*T )   - F*H  + UA*P*(T  - T)                     (1)
C...         t       Z Z       Z          J
C...
C...  WHERE
C...
C...  H       LIQUID ENTHALPY
C...
C...  T       LIQUID TEMPERATURE
C...
C...  Z       DISTANCE
C...
C...  t       TIME
C...
C...  RHO     LIQUID DENSITY
C...
C...  A       TUBE CROSS SECTIONAL AREA
C...
C...  K       AXIAL THERMAL CONDUCTIVITY
C...
C...  F       LIQUID FLOW RATE
C...
C...  UA      HEAT TRANSFER COEFFICIENT
C...
C...  P       TUBE PERIMETER
C...
C...  SUBJECT TO THE INITIAL AND BOUNDARY CONDITIONS
C...
C...  H(Z,0) = H0                                                    (3)
C...
C...     I
C...  F*H  = F*H(0,t) - K*T (0,t), T (1,t) = 0                    (4)(5)
C...                       Z        Z
C...  WHERE
C...
C...  H0      INITIAL LIQUID ENTHALPY
C...
C...   I
C...  H       ENTERING LIQUID ENTHALPY
C...
C...  (1)  SARGENT, R. W. H., PERSONAL COMMUNICATION (TO WES) FROM THE
C...       DEPARTMENT OF CHEMICAL ENGINEERING AND CHEMICAL TECHNOLOGY,
C...       IMPERIAL COLLEGE OF SCIENCE AND TECHNOLOGY, LONDON, SW7 2BY,
C...       ENGLAND, 20OCT88
C...
C...  DSS/2 COMMON
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/  T(51)
     2      /F/ TT(51)
     3      /C/    RHO,      A,      F,     UA,      P,     TJ,     HI,
     4           Z(51),     CP,      N,     IP
     5      /S/ TZ(51),TZZ(51)
      REAL           K
C...
C...  MODEL PARAMETERS
      CP=1.
      RHO=1.
      A=1.
      F=1.
      UA=1.
      P=1.
      TJ=100.
      HI=25.
      H0=25.
      N=51
C...
C...  SPATIAL GRID
      DZ=1.0/FLOAT(N-1)
      DO 1 I=1,N
      Z(I)=DZ*FLOAT(I-1)
1     CONTINUE
C...
C...  MODEL INITIAL CONDITION (2)
      DO 2 I=1,N
      T(I)=CP*H0
2     CONTINUE
C...
C...  INITIAL DERIVATIVES
      CALL DERV
      IP=0
      RETURN
      END
      SUBROUTINE DERV
C...
C...  SUBROUTINE DERV IMPLEMENTS THE NUMERICAL METHOD OF LINES
C...  SOLUTION OF EQUATIONS (1) TO (4)
C...
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/  T(51)
     2      /F/ TT(51)
     3      /C/    RHO,      A,      F,     UA,      P,     TJ,     HI,
     4           Z(51),     CP,      N,     IP
     5      /S/ TZ(51),TZZ(51)
      REAL           K
C...
C...  TZ
      CALL DSS004(0.,1.,N,T,TZ)
C...
C...  BOUNDARY CONDITION (3)
      TZ(1)=(1.0/K(T(1)))*(F*CP*T(1)-F*HI)
C...
C...  BOUNDARY CONDITION (4)
      TZ(N)=0.
C...
C...  K*T
C...     Z
      DO 1 I=1,N
      TZ(I)=K(T(I))*TZ(I)
1     CONTINUE
C...
C...  (K*T )
C...      Z Z
      CALL DSS004(0.,1.,N,TZ,TZZ)
C...
C...  T  FOR CONVECTION
C...   Z
      CALL DSS020(0.,1.,N,T,TZ,1.)
C...
C...  BOUNDARY CONDITION (3)
      TZ(1)=(1.0/K(T(1)))*(F*CP*T(1)-F*HI)
C...
C...  EQUATION (1)
      DO 2 I=1,N
      TT(I)=(1.0/(CP*RHO*A))*(TZZ(I)-F*CP*TZ(I)+UA*P*(TJ-T(I)))
2     CONTINUE
      RETURN
      END
      REAL FUNCTION K(T)
      K=1.0+0.01*T
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/   TIME,  NSTOP,  NORUN
     1      /Y/  T(51)
     2      /F/ TT(51)
     3      /C/    RHO,      A,      F,     UA,      P,     TJ,     HI,
     4           Z(51),     CP,      N,     IP
     5      /S/ TZ(51),TZZ(51)
      REAL           K
C...
C...  ADDITIONAL ARRAY FOR PLOTTING
      COMMON/CAL/ TP(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,'T(0,t)',4X,'T(0.2,t)',4X,'T(0.4,t)',
     1            4X,'T(0.6,t)',4X,'T(0.8,t)',4X,'T(1.0,t)')
C...
C...  PRINT THE NUMERICAL SOLUTION
      WRITE(NO,2)TIME,T(1),T(11),T(21),T(31),T(41),T(51)
2     FORMAT(F10.2,6F12.4)
C...
C...  STORE THE SOLUTION FOR PLOTTING
      DO 3 I=1,N
      TP(IP,I)=T(I)
3     CONTINUE
C...
C...  PLOT THE SOLUTION
      IF(IP.LT.6)RETURN
      CALL TPLOTS(IP,N,Z,TP)
      WRITE(NO,4)
4     FORMAT(1H ,/,' T(Z,t) VS Z WITH t AS A PARAMETER',/,
     1             '        t = 0, 0.1,..., 0.5')
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/   TIME,  NSTOP,  NORUN
     1      /Y/  T(51)
     2      /F/ TT(51)
     3      /C/    RHO,      A,      F,     UA,      P,     TJ,     HI,
     4           Z(51),     CP,      N,     IP
     5      /S/ TZ(51),TZZ(51)
      REAL           K
C...
C...  ADDITIONAL ARRAY FOR PLOTTING
      COMMON/CAL/ TP(6,51)
C...
C...  PLOT T(Z,t) VS Z FOR T = 0, 0.1,..., 0.5
      CALL QIKSAX(3,3)
      CALL QIKSET(5.,0.,0.2,6.,6.,0.,10.)
      CALL QIKPLT(Z,TP,-N,3H*Z*,8H*T(Z,t)*,
     1 17H*SARGENT PROBLEM*,-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=-4.00
      X2=-3.85
      Y1=8.5
      Y2=8.45
      CALL SYMBOL(X1,Y1,0.125,ISYM(1),0.,-1)
      CALL SYMBOL(X2,Y2,0.125,8H - T = 0,0.,8)
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,10H - T = 0.1,0.,10)
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,10H - T = 0.2,0.,10)
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,10H - T = 0.3,0.,10)
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,10H - T = 0.4,0.,10)
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 = 0.5,0.,10)
      RETURN
      END
HEAT TRANSFER IN A TUBE
0.        0.5       0.1
   51 1000    1    1  REL 0.0001
END OF RUNS


