PHOTON USE
  p;;;;;
 
  up 1 0 0;vi 0.5 1 0.75
  gr ou x 1;gr ou y 1;gr ou z 1
  gr ou x m;gr ou y m;gr ou z m
  gr ou x 1 y 1 2 z 2 2 col 2
  gr ou x 6 y 1 2 z 7 7 col 2
  gr ou z 4 x 1 4 y 1 3 col 6
  gr ou z 6 x 2 5 y 1 3 col 6
  ve y 2 sh
 
  msg                3D SHELL-AND-TUBE HEAT EXCHANGER
  msg                --------------------------------
  msg                    Velocity 1 phase:
  msg  Press Enter to continue
  pause;vi 0 1 0
  msg                3D SHELL-AND-TUBE HEAT EXCHANGER
  msg                --------------------------------
  msg              Temperature distribution 1 phase:
  con 1sth y 2 sh;in 50
  msg  Press Enter to continue
  pause
  con off;red
  msg                3D SHELL-AND-TUBE HEAT EXCHANGER
  msg                --------------------------------
  msg              Temperature distribution 2 phase:
  con 2ndh y 2 sh;in 50
  msg Press e to END
  ENDUSE
 
    GROUP 1. Run title
TEXT(3D SHELL-AND-TUBE HEAT EXCHANGER:110

  DISPLAY
     The heat exchanger considered has two baffles within
     the shell and the tubes arranged in five passes.
     The overall heat transfer coefficient depends on the
     local velocity and is introduced by PLANT.
              =====================
  ENDDIS

REAL(T1IN,T2IN,FLO1,FLO2,COEF1,COEF2,COEF12)
  Here 1 refers to the shell-side fluid and 2 to the tube-side fluid
  The units are arbitrary
T1IN=1.0; T2IN=0.0    ! temperatures
FLO1=0.1; FLO2=0.1    ! flow rates
COEF1=0.1; COEF2=0.4  ! heat-transfer coefficients
COEF12=1.0/(1.0/COEF1+1.0/COEF2)
RG(1)=COEF12         ! overall coefficient, transmitted via RG(1)
REAL(RESCO);RESCO=1.E2 ! tube-bank flow-resistance coefficient

    GROUP 3. X-direction grid specification
    The heat exchanger is a rectangular box, 1m high,
    1m wide and 4m long. A uniform 5*3*8 grid is used,
    as was done by Patankar and Spalding in the first-ever
    heat-exchanger simulation [ Afghan & Schluender (Eds),
    'Heat Exchangers', Scripta Book Company, 1974].
 
    The example is chosen only because of its historical interest;
    for the 5-pass flow pattern does not make it a good heat
    exchanger.
    
    Only one half of the exchanger is included in the
    calculation domain, because of symmetry.
    
    The shell-side flow pattern, and the temperature fields of both
    fluids, are 3D because the shell-fluid inlet and outlet do not
    cover the whole dise area.
    
    
GRDPWR(X,5,1.0,1.0)
    GROUP 4. Y-direction grid specification
GRDPWR(Y,3,0.5,1.0)                   ! half-width is 0.5 m
    GROUP 5. Z-direction grid specification
GRDPWR(Z,8,4.0,1.0)
    GROUP 7. Variables stored, solved & named
    The shell-side fluid is a single-phase one, for which the
    folowing five variables must be solved; only the enthalpy 
    needs to be computed for the tube-side fluid, because its
    flow pattern is prescribed.
SOLVE(P1,U1,V1,W1,H1,H2)
NAME(H1)=1STH;NAME(H2)=2NDH  ! names signify first- and second-
                             ! fluid enthalpy
STORE(EPOR,NPOR,HPOR)
    GROUP 8. Terms (in differential equations) & devices
    The "diffusion" terms are cut out for all vaiables, and
    the built-in sources for the enthalpies.
TERMS(U1,Y,Y,N,Y,Y,Y);TERMS(V1,Y,Y,N,Y,Y,Y)
TERMS(W1,Y,Y,N,Y,Y,Y);TERMS(1STH,N,Y,N,Y,Y,Y)
TERMS(2NDH,N,N,N,Y,N,N)
    GROUP 11. Initialization of variable or porosity fields
FIINIT(W1)=FLO1;FIINIT(U1)=0.0;FIINIT(V1)=0.0
FIINIT(1STH)=T1IN;FIINIT(2NDH)=T2IN
FIINIT(EPOR)=0.5;FIINIT(NPOR)=0.5;FIINIT(HPOR)=0.5
    
    GROUP 13. Boundary conditions and special sources
    West boundary; shell fluid inlet ; 2 cells in west wall
PATCH(SHELLIN,CELL,1,1,2,3,2,2,1,1000)   ! small patch in west wall
COVAL(SHELLIN,P1,FIXFLU,FLO1/2.0); COVAL(SHELLIN,1STH,ONLYMS,T1IN)

    East boundary; shell fluid outlet; 2 cells in east wall
PATCH(SHELLOUT,EAST,NX,NX,2,3,NZ-1,NZ-1,1,1000) ! patch in east wall
COVAL(SHELLOUT,P1,FIXP,0.0)

    High boundary, tube fluid inlet; 5 cells in high wall
PATCH(TUBEIN,CELL,1,1,1,NY,NZ,NZ,1,1000)  ! IX=1; all IY; IZ=NZ
COVAL(TUBEIN,2NDH,FLO2/3.0,T2IN)

    Note how the giving of special names to patches,
    beginning NE (for neighbour), coupled with LOCNE (GRND8) in
    the "value" location, produces sources which simulate along-
    the-tube convection fluid-to-metal heat transfer etc,
    by activating special calls to the built-in coding:
   gxnepat.htm
    
    The flow pattern is:
    
     ---<--------------------------------------------
                                                    ^
        --------------------------------------------!
        ^
        !--------------------------------------------
                                                    ^
        --------------------------------------------!
        ^
        !--------------------------------------------<---
    
    In the following COVALs, the /3.0 appears because there are
    3 cells in the y-direction (NY=3)
    Flow of tube fluid in first pass   <---
PATCH(NEH1,CELL,1,1,1,NY,1,NZ-1,1,1000)   ! IX=1; all IY; IZ=1,NZ
COVAL(NEH1,2NDH,FLO2/3.0,LOCNE)           ! from higher-z neighbour
                                         
    Flow of tube fluid in first bend   ^  
PATCH(NEW1,CELL,2,2,1,NY,1,1,1,1000)      ! IX=2; all IY; IZ=1
COVAL(NEW1,2NDH,FLO2/3.0,LOCNE)           ! from lower-x neighbour
                                         
    Flow of tube fluid in second pass  --->  
PATCH(NEL1,CELL,2,2,1,NY,2,NZ,1,1000)     ! IX=2; all IY; IZ=2,NZ
COVAL(NEL1,2NDH,FLO2/3.0,LOCNE)           ! from lower-z neighbour
                                         
    Flow of tube fluid in second bend  ^  
PATCH(NEW2,CELL,3,3,1,NY,NZ,NZ,1,1000)    ! IX=3; all IY; IZ=NZ
COVAL(NEW2,2NDH,FLO2/3.0,LOCNE)           ! from lower-x neighbour
                                         
    Flow of tube fluid in third pass   <---  
PATCH(NEH2,CELL,3,3,1,NY,1,NZ-1,1,1000)   ! IX=3; all IY; IZ=1,NZ-1
COVAL(NEH2,2NDH,FLO2/3.0,LOCNE)           ! from higher-z neighbour
                                         
    Flow of tube fluid in third bend   ^  
PATCH(NEW3,CELL,4,4,1,NY,1,1,1,1000)      ! IX=4; all IY; IZ=1
COVAL(NEW3,2NDH,FLO2/3.0,LOCNE)           ! from lower-x neighbour
                                         
    Flow of tube fluid in fourth pass  --->  
PATCH(NEL2,CELL,4,4,1,NY,2,NZ,1,1000)     ! IX=4; all IY; IZ=2,NZ
COVAL(NEL2,2NDH,FLO2/3.0,LOCNE)           ! from lower-z neighbour
                                         
    Flow of tube fluid in fourth bend  ^  
PATCH(NEW4,CELL,NX,NX,1,NY,NZ,NZ,1,1000)  ! IX=5; all IY; IZ=NZ
COVAL(NEW4,2NDH,FLO2/3.0,LOCNE)           ! from lower-x neighbour
 
    Flow of tube fluid in fifth pass   <---
PATCH(NEH3,CELL,NX,NX,1,NY,1,NZ-1,1,1000) ! IX=5; all IY; IZ=1,NZ-1
COVAL(NEH3,2NDH,FLO2/3.0,LOCNE)           ! from higher-z neighbour

  PLANTBEGIN 
    Heat-exchange with tube fluid, throughout the exchanger.
PATCH(HEX,VOLUME,1,NX,1,NY,1,NZ,1,1000)
    CO=2.*(U1**2+V1**2+W1**2)**0.25
    VAL=2NDH
COVAL(HEX,1STH,GRND,GRND)
    Heat-exchange with shell fluid, throughout the exchanger.
    CO=2.*(U1**2+W1**2+V1**2)**0.25
    VAL=1STH
COVAL(HEX,2NDH,GRND,GRND)
  PLANTEND
 
    Baffle 1 at NZ=3
PATCH(BAFFLE1,HIGH,1,NX-1,1,NY,3,3,1,1000)
COVAL(BAFFLE1,W1,FIXVAL,0.0)
 
    Baffle 2 at NZ=5
PATCH(BAFFLE2,HIGH,2,NX,1,NY,5,5,1,1000)
COVAL(BAFFLE2,W1,FIXVAL,0.0)
 
    Resistance to flow exerted by tubes, throughout the shell.
PATCH(RESIST,PHASEM,1,NX,1,NY,1,NZ,1,1000)
COVAL(RESIST,U1,RESCO,0.0);COVAL(RESIST,V1,RESCO,0.0)
COVAL(RESIST,W1,0.5*RESCO,0.0)
    GROUP 15. Termination of sweeps
LSWEEP=100
    GROUP 16. Termination of iterations
LITER(P1)=100
    GROUP 17. Under-relaxation devices
RELAX(U1,FALSDT,1.0);RELAX(V1,FALSDT,1.0)
RELAX(W1,FALSDT,1.0)
RELAX(1STH,FALSDT,100.0);RELAX(2NDH,FALSDT,100.0)
    GROUP 19. Data communicated by satellite to GROUND
NAMSAT=MOSG
    GROUP 20. Preliminary print-out
    GROUP 21. Print-out of variables
    Print-out of porosities is suppressed.
OUTPUT(EPOR,N,N,N,N,N,N);OUTPUT(NPOR,N,N,N,N,N,N)
OUTPUT(HPOR,N,N,N,N,N,N)
OUTPUT(1STH,Y,N,Y,Y,Y,Y);OUTPUT(2NDH,Y,N,Y,Y,Y,Y)
 
    GROUP 22. Spot-value print-out
IXMON=6;IYMON=6;TSTSWP=5
    GROUP 23. Field print-out and plot control
IPLTL=LSWEEP;IPROF=1;ORSIZ=0.4;XZPR=T;NPLT=1
 
PATCH(PASS1,PROFIL,1,1,2,2,1,NZ,1,1000)
PLOT(PASS1,1STH,T2IN,T1IN);PLOT(PASS1,2NDH,T2IN,T1IN)
 
PATCH(PASS2,PROFIL,2,2,2,2,1,NZ,1,1000)
PLOT(PASS2,1STH,T2IN,T1IN);PLOT(PASS2,2NDH,T2IN,T1IN)
 
PATCH(PASS3,PROFIL,3,3,2,2,1,NZ,1,1000)
PLOT(PASS3,1STH,T2IN,T1IN);PLOT(PASS3,2NDH,T2IN,T1IN)
 
PATCH(PASS4,PROFIL,4,4,2,2,1,NZ,1,1000)
PLOT(PASS4,1STH,T2IN,T1IN);PLOT(PASS4,2NDH,T2IN,T1IN)
tstswp=-1
dmpstk=t
DISTIL=T
EX(P1)=1.191E+02; EX(U1)=3.000E-01
EX(V1)=2.262E-02; EX(W1)=3.339E-01
EX(1STH)=4.835E-01; EX(2NDH)=4.681E-01
 LIBREF=110
STOP