Guest User

Untitled

a guest
Sep 6th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PROGRAM uebung
  2. !*********************************************************************
  3. !
  4. ! Description:
  5. !  Sheet 5, Exercise 1
  6. !    
  7. !**********************************************************************
  8.  
  9. ! mo_output provides a simplified interface for writing netCDF data
  10. !     see supplement.pdf for details          
  11.   USE mo_output,   ONLY:  open_out_file,   &
  12.                           init_out,        &
  13.                           write_out,       &
  14.                           close_out_file  
  15.  
  16.   IMPLICIT NONE
  17.  
  18. ! 1. variable declaration-----------------------------------
  19.  
  20.    ! number of grid-points in x-direction
  21.   INTEGER, PARAMETER :: jmax = 201
  22.    ! number of time steps
  23.   INTEGER, PARAMETER ::  nmax = 120
  24.    ! grid spacing in x-direction
  25.   DOUBLE PRECISION, PARAMETER :: dx   = 5.D3
  26.    ! length of time step
  27.   DOUBLE PRECISION, PARAMETER :: dt   = 10.0D0
  28.    ! velocity
  29.  ! DOUBLE PRECISION, PARAMETER :: c    = 0.5D0
  30.    ! mean depth of fluid
  31.   DOUBLE PRECISION, PARAMETER :: H    = 1.D3
  32.    ! gravitaional acceleration
  33.   DOUBLE PRECISION, PARAMETER :: g    = 9.81D0
  34.  
  35.    ! netcdf output unit                          
  36.   INTEGER :: ncid  
  37.     ! "time step" index
  38.   INTEGER :: nstep
  39.     ! the function (3 time level scheme)
  40.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: ufct
  41.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: ufct_old
  42.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: ufct_new
  43.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: hfct
  44.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: hfct_old
  45.   DOUBLE PRECISION, POINTER, DIMENSION(:) :: hfct_new
  46.  
  47.   INTEGER :: j
  48.   DOUBLE PRECISION :: fact
  49.  
  50. !-end variable declaration --------------------------------
  51.  
  52.     ! write to screen:
  53.   WRITE(6,*) 'This is uebung.exe'
  54.  
  55.   ! 1. allocate (add ghost points at the boundaries)
  56.    ALLOCATE( ufct(0:jmax+3))
  57.    ALLOCATE( ufct_old(0:jmax+1))
  58.    ALLOCATE( ufct_new(0:jmax+1))
  59.    ALLOCATE( hfct(0:jmax+3))
  60.    ALLOCATE( hfct_old(0:jmax+1))
  61.    ALLOCATE( hfct_new(0:jmax+1))
  62.    
  63.  
  64.   ! 2. initialize the function
  65.     DO j=0, jmax+1
  66.      IF ( DBLE(j-1)*dx .GE. 450.D3 .AND. DBLE(j-1)*dx .LE. 550.D3 ) THEN
  67.        hfct(j) = 1.D0
  68.      ELSE
  69.        hfct(j) = 0.D0
  70.      END IF
  71.     END DO
  72.  
  73. print*, hfct(91)
  74.  
  75.    ! 4. open a netCDF output file
  76.   CALL open_out_file(ncid, "out.nc")
  77.  
  78.    ! 5. add the variable "ufct" to a list of output variables
  79.   CALL init_out(ncid, ufct, "ufct", "none","x", timedep=.TRUE.)
  80.   CALL init_out(ncid, hfct, "hfct", "none","x", timedep=.TRUE.)
  81.  
  82.    ! 6. write all the variables in the list of output variables to the output file
  83.    !   here: initial values
  84.   CALL write_out(ncid)
  85.  
  86.    ! 7. start time loop
  87.   DO nstep=1,nmax
  88.  
  89.     ! periodic boundary cond.
  90.  
  91.      ufct(0)=ufct(jmax)
  92.      ufct(jmax+1)=ufct(1)
  93.      hfct(0)=hfct(jmax)
  94.      hfct(jmax+1)=hfct(1)
  95.  
  96.    ! first step should be Euler forward
  97.        fact=1.D0
  98.      IF ( nstep .EQ. 1 ) THEN
  99.        ufct_old = ufct(1:jmax)
  100.        hfct_old = hfct(1:jmax)
  101.        fact=0.5D0
  102.      END IF
  103.    
  104.    ! calculate values at  step n+1 ACHTUNG: Halb-Schritte j beginnt also bei 1/2
  105.     DO j = 1, jmax
  106.      ufct_new(j) = ufct_old(j) - fact * dt * g * ( hfct(j+3) - hfct(j-1) ) / dx
  107.      hfct_new(j) = hfct_old(j) - fact * dt * H * ( ufct(j+1) - ufct(j-1) ) / dx
  108.     END DO
  109.  
  110.     ! apply the Robert Asselin filter
  111.     DO j = 1, jmax
  112.      ufct_old(j) = ufct(j) + 0.1d0 * (ufct_old(j) - 2.d0* ufct(j) + ufct_new(j))
  113.      hfct_old(j) = hfct(j) + 0.1d0 * (hfct_old(j) - 2.d0* hfct(j) + hfct_new(j))
  114.     END DO
  115.      
  116.     ! update ufct
  117.       ufct(1:jmax-100)=ufct_new(2:jmax+1:2)
  118.       hfct(1:jmax-100)=hfct_new(2:jmax+1:2)
  119.  print*, nstep, hfct(45)
  120.     ! write output
  121.     CALL write_out(ncid)
  122.  
  123.        ! update ufct
  124.       ufct(1:jmax)=ufct_new
  125.       hfct(1:jmax)=hfct_new
  126.  
  127.  END DO
  128.  
  129.  
  130.    ! 8 close the output file
  131.   CALL close_out_file(ncid)
  132.  
  133.    ! 9. free memory
  134.   DEALLOCATE(ufct)
  135.   DEALLOCATE(ufct_new)
  136.   DEALLOCATE(ufct_old)
  137.   DEALLOCATE(hfct)
  138.   DEALLOCATE(hfct_new)
  139.   DEALLOCATE(hfct_old)
  140.  
  141.   WRITE(6,*) 'uebung.exe: DONE.'
  142.  
  143. END PROGRAM uebung
Add Comment
Please, Sign In to add comment