*DECK SEP04
      SUBROUTINE INITAL
C...
C...  DYNAMICS OF A COUNTERCURRENT MIXER-SETTLER SYSTEM
C...
C...  DIETHYLAMINE (DEA) IS TO BE EXTRACTED FROM AN AQUEOUS SOLUTION BY
C...  COUNTERCURRENT EXTRACTION WITH TOLUENE IN A THREE-STATE EXTRACTION
C...  UNIT.  THE AQUEOUS SOLUTION IS FED TO THE FIRST STAGE AT A FLOW
C...  RATE OF 3000 CM**3/SEC (FW(0)) AND ANALYZES 0.0005 GM MOLE DEA/CM**3.
C...  THE TOLUENE ENTERS THE LAST STAGE AT ZERO CONCENTRATION OF DEA AND
C...  A FLOW RATE OF 3000 CM**3/SEC (FT(4)).  
C...
C...  THE HOLDUP VOLUMES IN EACH STAGE ARE MAINTAINED CONSTANT WITH
C...  VT = 850,000 CM**3 (TOLUENE PHASE) AND VW = 850,000 CM**3
C...  (AQUEOUS PHASE).  INITIALLY THE CONCENTRATION OF DEA IN EACH STAGE
C...  AND EACH PHASE IS ZERO.  ASSUME THAT WATER AND TOLUENE ARE COM-
C...  PLETELY IMMISCIBLE AND THAT EQUILIBRIUM IS ATTAINED IN EACH STAGE
C...  WITH THE FOLLOWING EQUILIBRIUM RELATIONSHIP
C...
C...                  CAW(N) = 1.2*CAT(N), N = 1, 2, 3
C...
C...  WHERE
C...
C...     CAT(N) = GM MOLE DEA IN TOLUENE PHASE/CM**3 IN STAGE N
C...
C...     CAW(N) = GM MOLE DEA IN WATER PHASE/CM**3 IN STAGE N
C...
C...  THE CONSTANT HOLDUP ASSUMPTION REQUIRES THAT THE TOLUENE AND WATER
C...  FLOWRATES BE UNIFORM THROUGHOUT THE SYSTEM AND EQUAL TO THE ENTER-
C...  FLOWRATES, FWO AND FT4
C...
C...                      FT(N) = FT(4), N = 1, 2, 3
C...
C...                      FW(N) = FW(0), N = 1, 2, 3
C...
C...  A DEA MATERIAL BALANCE ON STAGE N GIVES
C...
C...          D(VT(N)*CAT(N)+VW(N)*CAW(N))/DT =
C...
C...                FW(N-1)*CAW(N-1) + FT(N+1)*CAW(N+1)
C...
C...              - FW(N)*CAW(N) - FT(N)*CAT(N), N = 1, 2, 3
C...
C...  NOTE THAT THE CODING OF THE MODEL DIFFERENTIAL EQUATIONS IN SUB-
C...  ROUTINE DERV IS GENERAL IN THE SENSE THAT ANY NUMBER OF MIXER-
C...  SETTLER STAGES CAN BE SIMULATED BY SETTING NT (AND INCREASING THE
C...  ARRAYS IN COMMON/Y/, /F/ AND /C/).  ALSO, BECAUSE OF THE SUB-
C...  SCRIPTING LIMITATIONS OF FORTRAN, THE FIRST STAGE (N = 1) AND
C...  THE LAST STAGE (N = NT) ARE PROGRAMMED SPECIFICALLY.  THE INTER-
C...  MEDIATE STAGES CAN ALL BE PROGRAMMED WITH A SINGLE GENERAL STATE-
C...  MENT.  THE DEPENDENT VARIABLES IN COMMON/Y/ ARE CONTAINED IN A
C...  SINGLE ARRAY DV, I.E., DV(N) = VT(N)*CAT(N) + VW(N)*CAW(N).  THE
C...  CORRESPONDING DERIVATIVES IN COMMON/F/ ARE CONTAINED IN THE ARRAY
C...  DVDT
C...
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),       FT4,       FW0,      CAT4,      CAW0,
     5                 NT,        IP
C...
C...  SET THE MODEL PARAMETERS
      FT4=3000.
      FW0=3000.
      CAT4=0.
      CAW0=0.0005
C...
C...  THE MODEL PARAMETERS AND INITIAL CONDITIONS ARE SET FOR NT STAGES
      NT=3
      DO 1 N=1,NT
      VT(N)=850000.
      VW(N)=850000.
      FT(N)=3000.
      FW(N)=3000.
      CAT(N)=0.
      CAW(N)=0.
C...
C...  NOTE THAT THE DEPENDENT VARIABLES IN COMMON/Y ARE THE TOTAL MOLAR
C...  HOLDUPS, DV(N), IN THE NT STAGES WHICH ARE INITIALIZED AT THIS
C...  POINT.  THESE TOTAL MOLAR HOLDUPS CONTAIN THE TOLUENE-PHASE AND
C...  WATER-PHASE COMPOSITIONS, CAT(N) AND CAW(N), WHICH ARE THE PRINCI-
C...  PAL MODEL OUTPUTS.  THESE CONCENTRATIONS ARE COMPUTED FROM THE
C...  TOTAL MOLAR HOLDUPS IN SUBROUTINE DERV BY USING THE NUMERICAL
C...  VALUES OF DV(N)
      DV(N)=VT(N)*CAT(N)+VW(N)*CAW(N)
1     CONTINUE
C...
C...  INITIALIZE THE REMAINING MODEL VARIABLES BY A CALL TO SUBROUTINE
C...  DERV
      CALL DERV
      RETURN
      END
      SUBROUTINE DERV
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),       FT4,       FW0,      CAT4,      CAW0,
     5                 NT,        IP
C...
C...  THE DEPENDENT VARIABLE FOR EACH STAGE IS THE TOTAL MOLAR HOLDUP OF
C...  DEA.  THE CONCENTRATIONS IN THE TOLUENE AND WATER PHASES, CAT(N)
C...  AND CAW(N), CAN BE COMPUTED FROM THE TOTAL MOLAR HOLDUP AND
C...  TOLUENE AND WATER HOLDUPS, VT AND VW, BY STRAIGHTFORWARD ALGEBRA
C...  AND THE EQUILIBRIUM RELATIONSHIP
      DO 2 N=1,NT
      CAT(N)=DV(N)/(1.2*VW(N)+VT(N))
      CAW(N)=1.2*CAT(N)
2     CONTINUE
C...
C...  COMPUTE THE TEMPORAL DERIVATIVES FOR THE NT MIXER-SETTLER STAGES
      DO 1 N=1,NT
C...
C...  FIRST STAGE WITH INLET FLOWRATE AND COMPOSITION FW0 AND CAW0
      IF(N.EQ.1)
     1   DVDT(N)=FW0*CAW0+FT(2)*CAT(2)
     2          -FW(1)*CAW(1)-FT(1)*CAT(1)
C...
C...  NT-TH STAGE WITH INLET FLOWRATE AND COMPOSITION FT4 AND CAT4
      IF(N.EQ.NT)
     1   DVDT(NT)=FW(NT-1)*CAW(NT-1)+FT4*CAT4
     2           -FW(NT)*CAW(NT)-FT(NT)*CAT(NT)
C...
C...  STAGES 2 TO NT-1
      IF((N.NE.1).AND.(N.NE.NT))
     1   DVDT(N)=FW(N-1)*CAW(N-1)+FT(N+1)*CAT(N+1)
     2          -FW(N)*CAW(N)-FT(N)*CAT(N)
1     CONTINUE
      RETURN
      END
      SUBROUTINE PRINT(NI,NO)
      COMMON/T/         T,     NSTOP,     NORUN
     1      /Y/     DV(3)
     2      /F/   DVDT(3)
     3      /C/     VT(3),     VW(3),     FT(3),     FW(3),    CAT(3),
     4             CAW(3),       FT4,       FW0,      CAT4,      CAW0,
     5                 NT,        IP
C...
C...  PRINT A HEADING FOR THE NUMERICAL SOLUTION
      WRITE(NO,1)T
1     FORMAT(1H ,//,5H T = ,F7.1,/,9X,1HN,4X,6HCAT(N),4X,6HCAW(N),5X,
     1 5HDV(N),3X,7HDVDT(N))
C...
C...  PRINT THE NUMERICAL SOLUTION.  THE MODEL DERIVATIVES, DVDT(N),
C...  IN COMMON/F/ ARE ALSO PRINTED TO GIVE SOME INDICATION OF THE
C...  RESPONSE DEFINED BY THE MODEL DIFFERENTIAL EQUATIONS
      WRITE(NO,2)(N,CAT(N),CAW(N),DV(N),DVDT(N),N=1,NT)
2     FORMAT(I10,4E10.3,/,I10,4E10.3,/,I10,4E10.3)
      RETURN
      END

