PROGRAM SET4NSLUBNEW
C---- VERTICAL NUMBERING
C----MOVING LEFT TO RIGHT
C=======================================================================
C      DATA GENERATING PROGRAM FOR NSEQ8STD.FOR
C   PROJECT: DRIVEN CAVITY FLOW   PROJECT NAME: LUB0000
C     UNITS:  SECOND, 1/000 METER
C    DOMAIN: LEFT=B1, RIGHT=B2, LENGTH=RLENGTH
C    ELEMENT: FOUR-NODED ISOPARAMETRIC ELEMENT
C    DOMAIN DISCRETIZATION: UNEVEN ELEMENTS WITH VERTICAL SCAN
C     VISCOSITY RATIO [VRATIO]: 2ND VISCOSITY / 1ST VISCOSITY
C     EIJI FUKUMORI DECEMBER 29, 1990
C                       FEB. 02, 2013
C=======================================================================
      IMPLICIT REAL*8 ( A-H , O-Z )
      PARAMETER ( ND=4, MXE=12000, MXN=13000, MXB=4000, NF=3 )
      PARAMETER (  VRATIO=1.D9, RLENGTH=8000.D-3, UAVE=100.D0,
     * VISCO=10.D0, FLMDA=VISCO*VRATIO,
     * ITEFIX=7, MAXITE=15,ERMAX=1.D-6, RELAXMAX=1.D0,RELAXMIN=1.D-4,
     * TLX=RLENGTH, B1=8.D-3, B2=2.D-3, NEY = 10, NEX = 200,
     * NDX=NEX+1, NDY=NEY+1 )
      PARAMETER ( INTEPT=2 )
C=======================================================================
      DIMENSION NODEX(MXE,ND),XCOORD(MXN),YCOORD(MXN), 
     * IBNDFX(MXB),IBNDFY(MXB),BVX(MXB),BVY(MXB),IBNDS(MXB),BVS(MXB)
      DIMENSION U(MXN), V(MXN)
      CHARACTER FNAME(NF)*19,EXTEN(NF)*4,PROJECT*15,EXFILE*3
      LOGICAL YES
C=======================================================================
      DATA PROJECT / 'LUBRICATION0000' /
      DATA EXTEN / '.DAT', '.BIN', '.STM' /
C=======================================================================
C      F(X) = X * X * ( 3.D0- 2.D0* X )
      G(X) = X * ( (0.1-1.)* X + (2.- 0.1) )
C=======================================================================
      FNAME(1)=PROJECT//EXTEN(1)
      FNAME(2)=PROJECT//EXTEN(2)
      FNAME(3)=PROJECT//EXTEN(3)
      OPEN ( UNIT=2, FILE='NSDATA4.FLN', STATUS='UNKNOWN')
      WRITE (2,'(A15)') PROJECT
      WRITE (2,'(A19)') FNAME(1)
      WRITE (2,'(A19)') FNAME(2)
      WRITE (2,'(A19)') FNAME(3)
      CLOSE (2)
      WRITE (*,*) PROJECT
      WRITE (*,*) FNAME(1)
      WRITE (*,*) FNAME(2)
      WRITE (*,*) FNAME(3)
C=======================================================================
C    C1: ADDED VISCOSITY COMPUTATION PARAMETER
C    C1=0. FOR NO ADDED VISCOSITY, C1=1. FOR UPWIND (OPTIMUM) ADDED 
C    C1 OPTION IS AVALABLE IN NSEQ8DD.FOR SOLVER
C         NEY: NEMBER OF VERTICAL ELEMENTS (NUMBER OF NODES: NEY+1)
C         NEX: NEMBER OF HORIZONTAL ELEMENTS (NUMBER OF NODES: NEX+1)
C  MAXITE: MAXIMUM NUMBER OF ITERATIONS AT EACH TIME INCREMENT
C ITERATION PROCEDURE IS REQUIRED BECAUSE OF NON-LINEAR CONVECTIVE TERM.
C  ERMAX: MAXIMUM DIFFERENCE BETWEEN GUESSED {U&V} AND COMPUTED {U&V}
C  HEIGHT: HEIGHT OF DRIVEN CAVITY FLOW DOMAIN
C=======================================================================
      WRITE (*,*)' LUBRICATION PROBLEM '
      WRITE (*,*)' VISCOSITY RATIO OF ',VRATIO
C=======================================================================
C                    ELEMENT CREATION
      NE = 0
      DO J = 1 , NEX
      DO I = 1 , NEY
      NE = NE + 1
      IF ( NE .GT. MXE ) STOP 'NE > MXE'
      NODEX(NE,1) = NDY*(J-1) + I
      NODEX(NE,2) = NODEX(NE,1) + NDY
      NODEX(NE,3) = NODEX(NE,2) + 1
      NODEX(NE,4) = NODEX(NE,1) + 1
      END DO
      END DO
C=======================================================================
C                 NODAL COORDINATE CREATION
      NNODE = 0
      DX = TLX / NEX
      SLOPE = (B2-B1)/TLX
      DO I = 1 , NDX
         XCURRENT = DX * (I-1)
         B = B1 + SLOPE * XCURRENT
         DY = B / NEY
       DO J = 1 , NDY
          NNODE = NNODE + 1
          IF ( NNODE .GT. MXN ) STOP 'NNODE > MXN'
          XCOORD(NNODE) = XCURRENT
          YCOORD(NNODE) = B*G(DY*(J-1)/B)
       END DO
      END DO
C=======================================================================
C                    BOUNDARY CONDITIONS
C--------- MOMENTUM EQUATIONS
      NBFX = 0
      NBFY = 0
C--------- FACE OF -X
C--------- FACE OF -Y
      U0 = UAVE
      V0 = 0.D0
      DO I = 1 , NDX
      NBFX = NBFX + 1
      NBFY = NBFY + 1
      IBNDFX(NBFX) = 1 + NDY*(I-1)
      IBNDFY(NBFY) = 1 + NDY*(I-1)
      BVX(NBFX) = U0
      BVY(NBFY) = V0
      END DO
C--------- FACE OF +Y
      U0 = 0.D0
      V0 = 0.D0
      DO I = 1 , NDX
      NBFX = NBFX + 1
      NBFY = NBFY + 1
      IBNDFX(NBFX) = I*NDY
      IBNDFY(NBFY) = I*NDY
      BVX(NBFX) = U0
      BVY(NBFY) = V0
      END DO
C--------- FACE OF +X
C=======================================================================
C                     B. C. FOR STREAM FUNCTION
C--------- FACE OD -Y
      NBS = 0
      DO I = 1 , NDX
      NBS = NBS + 1
      IBNDS(NBS) = 1 + NDY*(I-1)
      BVS(NBS) = 0.D0
      END DO
C--------- FACE OD +Y
      Q = B1 * UAVE / 2.
      DO I = 1 , NDX
      NBS = NBS + 1
      IBNDS(NBS) = I*NDY
      BVS(NBS) = Q
      END DO
C=======================================================================
C                      DATA FILE INQUIRY
      EXFILE = 'NEW'
      INQUIRE ( FILE = FNAME(1), EXIST = YES )
      IF ( YES ) EXFILE='OLD'
C=======================================================================
C                     MAKING DATA FILES
C---------- HEADER
      OPEN ( 1, FILE=FNAME(1), STATUS = 'UNKNOWN' )
      WRITE(1,*) VISCO   , FLMDA
      WRITE(1,*) RELAXMAX, RELAXMIN
      WRITE(1,*) MAXITE  , ERMAX   ,   ITEFIX
C---------- ELEMENT
      WRITE(1,*) NE
      DO I = 1 , NE
      WRITE (1,*) I, (NODEX(I,J), J = 1 , ND )
      END DO
C---------- NODE
      WRITE(1,*) NNODE
      DO I = 1 , NNODE
      WRITE(1,*) I, XCOORD(I), YCOORD(I)
      END DO
C---------- BOUNDARY
      WRITE(1,*) NBFX
      DO I = 1 , NBFX
      WRITE (1,*) IBNDFX(I), BVX(I)
      END DO
      WRITE(1,*) NBFY
      DO I = 1 , NBFY
      WRITE (1,*) IBNDFY(I), BVY(I)
      END DO
      CLOSE (1)
C=======================================================================
C                       INITIAL CONDITIONS
      U0 = 0.D0
      V0 = 0.D0
      DO I = 1 , NNODE
      U(I) = U0
      V(I) = V0
      END DO
C=======================================================================
C---------- 'PROJECT'.BIN
      OPEN ( 1, FILE=FNAME(2),STATUS ='UNKNOWN',FORM='UNFORMATTED' )
      WRITE(1) TIME, DT
      WRITE(1) ( U(I)    , I = 1 , NNODE )
      WRITE(1) ( V(I)    , I = 1 , NNODE )
      CLOSE (1)
C=======================================================================
C---------- 'PROJECT'.STM
      OPEN ( 1, FILE=FNAME(3), STATUS = 'UNKNOWN' )
      WRITE(1,*) NBS
      WRITE (1,*) ( IBNDS(I) , BVS(I) , I = 1 , NBS )
      CLOSE (1)
C=======================================================================
      CALL BANDWID ( ND, MXE, NE, NODEX , NBW  )
C------ CREATION OF PARAMETER FILE TO BE USED IN INCLUDE STATEMENT
      OPEN ( 1, FILE='PARAM.DAT', STATUS='UNKNOWN' )
      WRITE (1,*) '      PARAMETER ( NF=',NF,'    )'
      WRITE (1,*) '      PARAMETER ( ND=',ND,'    )'
      WRITE (1,*) '      PARAMETER ( INTEPT=',INTEPT,')'
      WRITE (1,*) '      PARAMETER ( MXE=',NE,')'
      WRITE (1,*) '      PARAMETER ( MXN=',NNODE,')'
      WRITE (1,*) '      PARAMETER ( MXW=',NBW,')'
      NB = MAX0 (NBFX, NBFY, NBS )
      WRITE (1,*) '      PARAMETER ( MXB=',NB,'   )'
      CLOSE (1)
C=======================================================================
      STOP "NORMAL TERMINATION"
      END
C
C
      SUBROUTINE BANDWID ( ND, MXE, NE, NODEX , NBW  )
      IMPLICIT REAL*8 ( A-H , O-Z )
      DIMENSION NODEX(MXE,ND)
      NBW = 0
      DO  I = 1 , NE
      DO  J = 1 , ND-1
      DO  K = J+1 , ND
      NBW = MAX0(NBW,IABS(NODEX(I,J)-NODEX(I,K)))
      END DO
      END DO
      END DO
      NBW = NBW + 1
      WRITE(*,*) 'HALF BANDWIDTH + 1 =', NBW
      RETURN
      END