Advertisement
PashaYa

Untitled

Jan 14th, 2019
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Program Main
  2.  
  3.   character(*), parameter:: InputFile='input.txt',OutputFile='data.plt' ! names of input and output files
  4.   character MeshFile*30        ! name of file with computational mesh
  5.   integer, parameter:: IO = 12 ! input-output unit
  6.   real,allocatable,dimension(:,:):: X,Y,P,CellVolume ! scalar arrays
  7.   real,allocatable,dimension(:,:,:):: CellCenter,IFaceCenter,IFaceVector,JFaceCenter,JFaceVector ! vector arrays
  8.   real,allocatable,dimension(:,:,:):: GradP, GradPExact, GradPError, V
  9.   real,allocatable,dimension(:,:):: DivV, DivVExact, DivVError
  10.   real,allocatable,dimension(:,:):: LapP, LapPExact, LapPError
  11.  
  12.   INTEGER Niter, it, mode
  13.  
  14. !===  READ INPUT FILE ===
  15.   WRITE(*,*) 'Read input file: ', InputFile
  16.   OPEN(IO,FILE=InputFile)
  17.   READ(IO,*) MeshFile  ! read name of file with computational mesh
  18.   READ(IO,*) Niter
  19.   READ(IO,*) mode
  20.   CLOSE(IO)
  21.  
  22. !===   READ NODES NUMBER (NI,NJ) FROM FILE WITH MESH ===
  23.   WRITE(*,*) 'Read nodes number from file: ', MeshFile
  24.   OPEN(IO,FILE = MeshFile)
  25.   READ(IO,*) NI,NJ
  26.   WRITE(*,*) 'NI, NJ = ',NI,NJ
  27.  
  28. !=== ALLOCATE ALL ARRAYS ===
  29.   WRITE(*,*) 'Allocate arrays'      
  30.   allocate(X(NI,NJ)) ! mesh nodes X-coordinates
  31.   allocate(Y(NI,NJ)) ! mesh nodes Y-coordinates
  32.   allocate(P(0:NI,0:NJ))   ! Pressure
  33.   allocate(CellVolume(NI-1,NJ-1))   ! Cell Volumes    
  34.   allocate(CellCenter(0:NI,0:NJ,2)) ! Cell Centers
  35.   allocate(IFaceCenter( NI,NJ-1,2)) ! Face Centers for I-faces
  36.   allocate(IFaceVector( NI,NJ-1,2)) ! Face Vectors for I-faces
  37.   allocate(JFaceCenter( NI-1,NJ,2)) ! Face Centers for J-faces
  38.   allocate(JFaceVector( NI-1,NJ,2)) ! Face Vectors for I-faces
  39.   allocate(GradP(0:NI,0:NJ,2))  !Gradient
  40.   allocate(GradPExact(0:NI,0:NJ,2))  !GradientP Exact
  41.   allocate(GradPError(0:NI,0:NJ,2))  !GradientP Error
  42.  
  43.   allocate(V(0:NI,0:NJ,2))  !V
  44.   allocate(DivV(0:NI,0:NJ))  !DivV
  45.   allocate(DivVExact(0:NI,0:NJ))  !DivVExact
  46.   allocate(DivVError(0:NI,0:NJ))  !DivVError
  47.  
  48.   allocate(LapP(0:NI,0:NJ))  !LapP
  49.   allocate(LapPExact(0:NI,0:NJ))  !LapPExact
  50.   allocate(LapPError(0:NI,0:NJ))  !LapPError
  51.      
  52.  
  53. !===  READ GRID ===
  54.   WRITE(*,*) 'Read mesh from file: ', MeshFile
  55.   READ(IO,*) ((X(I,J),Y(I,J),I=1,NI),J=1,NJ)
  56.   CLOSE(IO)
  57.  
  58. !=== CALCULATE METRIC ===
  59.   WRITE(*,*) 'Calculate metric'      
  60.   Call B_CalcMetric(NI,NJ,X,Y,CellCenter,CellVolume,IFaceCenter,IFaceVector,JFaceCenter,JFaceVector)
  61.  
  62. !=== INITIATE FIELDS ===
  63.   WRITE(*,*) 'Initiate fields'      
  64.   DO  J = 0,NJ
  65.     DO  I = 0,NI
  66.       P(I,J) = Pressure(CellCenter(I,J,1),CellCenter(i,j,2))
  67.       call CalcGradPExact(CellCenter(I,J,1),CellCenter(i,j,2),GradPExact(I,J,:))
  68.       call Velocity(CellCenter(I,J,1),CellCenter(I,J,2),V(I,J,:))
  69.       IF (mode.eq.0) THEN
  70.         DivVExact(I,J)=DivVelocityExact(CellCenter(I,J,1),CellCenter(I,J,2))
  71.         ELSE IF (mode.ge.1) THEN
  72.         DivVExact(I,J)=DivVelocityPExact(CellCenter(I,J,1),CellCenter(I,J,2))
  73.     END IF
  74.     LapPExact(I,J)=RLaplacianP(CellCenter(I,J,1),CellCenter(I,J,2))
  75.     ENDDO
  76.   ENDDO
  77.  
  78. !=== CALCULATE GRADIENT ===
  79.   WRITE(*,*) 'Calculate derivatives'    
  80.  
  81.   GradP=0.0
  82.   Do it =1, Niter
  83.  
  84.   Call B_CalcGradient(NI,NJ,P,GradP,CellCenter,CellVolume,IFaceCenter,IFaceVector,JFaceCenter,JFaceVector)
  85.   GradPError=ABS(GradPExact - GradP)/GradPExact
  86.   write(*,*) 'Iteration ', it, 'maximum error', maxval(GradPError(1:NI-1,1:NJ-1,:))
  87.  
  88.   end do
  89.  
  90.   GradPError=ABS(GradPExact - GradP)/GradPExact
  91.  
  92.   write(*,*) 'maximum x-error', maxval(GradPError(1:NI-1,1:NJ-1,1))
  93.   write(*,*) 'maximum y-error', maxval(GradPError(1:NI-1,1:NJ-1,2))
  94.  
  95. !=== CALCULATE DIVERGENCE ===
  96.   WRITE(*,*) 'Calculate Divergence'  
  97.   DivV=0.0
  98.   Call B_CalcDivergence(NI,NJ,V,P,GradP,DivV,CellCenter,CellVolume,IFaceCenter,IFaceVector,JFaceCenter,JFaceVector,mode)
  99.   DivVError=ABS(DivVExact-DivV)/DivVExact
  100.   write(*,*) 'maximum error', maxval(DivVError(1:NI-1,1:NJ-1))
  101.  
  102. !=== CALCULATE LAPLACIAN ===
  103.   WRITE(*,*) 'Calculate Laplacian'  
  104.   LapP=0.0
  105.   Call B_CalcLaplacian(NI,NJ,P,GradP,LapP,CellCenter,CellVolume,IFaceCenter,IFaceVector,JFaceCenter,JFaceVector)
  106.   LapPError=ABS(LapPExact-LapP)/LapPExact
  107.   write(*,*) 'maximum error', maxval(LapPError(1:NI-1,1:NJ-1))  
  108.  
  109. !=== OUTPUT FIELDS ===
  110.   WRITE(*,*) 'Output fields to file: ', OutputFile      
  111.   Open(IO,FILE=OutputFile)
  112.   Call B_OutputFields(IO,NI,NJ,X,Y,P,GradP,GradPError,V,DivV,DivVError,LapP,LapPError)
  113.   Close(IO)
  114.  
  115. END PROGRAM Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement