XBeach
C:/repositories/XBeach/trunk/src/xbeachlibrary/wave_bc_nextgen.f90
Go to the documentation of this file.
00001 module wave_bc_nextgen
00002    ! New setup to handle wave boundary conditions in XBeach, that can also be ported to
00003    ! Delft3D / FlowFM
00004    ! The following modules from XBeach need to be included in other models to allow this
00005    ! module to work
00006    use paramsconst
00007    implicit none
00008    save
00009    private
00010    !public wave_bc_generate
00011 
00012    logical      :: initialized = .false.
00013 
00014 contains
00015    !
00016    !   subroutine wave_bc_generate(t,wbctype,xref, yref, ntheta,dtheta,thetamin, theta, seed,  &
00017    !                                nbc, xbc, ybc, hbc, isBoundary,                     &
00018    !                                eebc, uibc, vibc, zsbc, isRecomputed )
00019    !      ! This subroutine is the main (only) call from the external program (XBeach/Delft3D)
00020    !      ! The subroutine generates one value of wave energy and/or wave flux per offshore boundary
00021    !      ! point, depending on the wbctype specified in the input of this call, for time = t. If
00022    !      ! necessary, this subroutine will initialise variables and/or generate new time series
00023    !      ! files.
00024    !      !
00025    !      !
00026    !      ! Input variables into subroutine are:
00027    !      !
00028    !      ! t             = current time (s)
00029    !      ! wbctype       = switch for type of wave boundary condition (==par%instat in XBeach)
00030    !      ! xref          = world x-coordinate of reference point from which waves are unrolled
00031    !      !                 (in case of XBeach, this is xw(1,1))
00032    !      ! yref          = world y-coordinate of reference point from which waves are unrolled
00033    !      !                 (in case of XBeach, this is yw(1,1))
00034    !      !
00035    !      !
00036    !      !
00037    !      ! Output variables of the subroutine are:
00038    !      !
00039    !      !
00040    !      ! Input variables
00041    !      real*8, intent(in)                        :: t,xref,yref,dtheta,thetamin
00042    !      integer, intent(in)                       :: wbctype,ntheta,nbc
00043    !      real*8,dimension(nbc), intent(in)         :: xbc,ybc,hbc
00044    !      integer,dimension(40),intent(in)          :: seed
00045    !      logical,intent(in)                        :: isBoundary
00046    !      ! Output variables
00047    !      real*8,dimension(nbc,ntheta),intent(out)  :: eebc
00048    !      real*8,dimension(nbc),intent(out)         :: uibc,vibc,zsbc
00049    !      logical,intent(out)                       :: isRecomputed
00050    !      ! Internal variables
00051    !      integer                                   :: i,j,itheta
00052    !
00053    !
00054    !      ! First check if this is a subdomain with a wave boundary
00055    !      if (isBoundary .eqv. false) then
00056    !         ! This domain does not have to do any work
00057    !         eebc = 0.d0
00058    !         uibc = 0.d0
00059    !         vibc = 0.d0
00060    !         zsbc = 0.d0
00061    !         isRecomputed = .false.
00062    !      else
00063    !
00064    !      endif
00065    !
00066    !
00067    !
00068    !
00069    !
00070    !
00071    !!!!   New setup for wave_bc, spectral wave conditions (surfbeat mode only)
00072    !!!!
00073    !!!!   Independent of XBeach where possible
00074    !!!!   Parallel implementation: each process has to be independent
00075    !!!!   Information common to all domains needed:
00076    !!!!      x,y reference point
00077    !!!!      mean depth along boundary
00078    !!!!      ntheta,dtheta,thetamin, theta
00079    !!!!      seed for random phases (is this enough?)
00080    !!!!   Local information needed:
00081    !!!!      nbc              - number of boundary points
00082    !!!!      xbc, ybc         - locations of boundary points (preferably ordered)
00083    !!!!      distbc           - cum. distance along boundary points (or computed within?)
00084    !!!!      hbc              - depth at boundary points
00085    !!!
00086    !!!
00087    !!!    integer, intent(in)             :: instat
00088    !!!    real*8,  intent(in)             :: xref
00089    !!!    real*8,  intent(in)             :: yref
00090    !!!
00091    !!!
00092    !!!    startbcf=.false.
00093    !!!
00094    !!!    if(.not. bccreated ) then
00095    !!!       bccreated=.true.
00096    !!!       startbcf=.true.                     ! trigger read from bcf for instat 3,4,5,7
00097    !!!       bcendtime=huge(0.0d0)               ! initial assumption for instat 3,4,5,7
00098    !!!       s%newstatbc=1
00099    !!!
00100    !!!
00101    !!!       if ((instat==INSTAT_JONS.or.instat==INSTAT_JONS_TABLE &
00102    !!!         & .or. instat==INSTAT_SWAN.or.instat==INSTAT_VARDENS).and.xmaster) then
00103    !!!          call spectral_wave_bc(sg,par,curline)
00104    !!!       elseif (instat==INSTAT_REUSE.and.xmaster) then
00105    !!!          curline = 1
00106    !!!       endif
00107    !!!
00108    !!!    end if
00109    !!!
00110    !!!    if (t .ge. bcendtime) then  ! Recalculate bcf-file
00111    !!!       close(71)
00112    !!!       close(72)
00113    !!!       if ((instat==INSTAT_JONS.or.instat==INSTAT_JONS_TABLE &
00114    !!!         & .or. instat==INSTAT_SWAN.or.instat==INSTAT_VARDENS).and.xmaster) then
00115    !!!          call spectral_wave_bc(sg,par,curline)
00116    !!!       elseif (instat==INSTAT_REUSE.and.xmaster) then
00117    !!!          startbcf=.true.
00118    !!!          curline = curline + 1
00119    !!!       endif
00120    !!!    end if
00121    !!!    !
00122    !!!    ! COMPUTE WAVE BOUNDARY CONDITIONS CURRENT TIMESTEP
00123    !!!    if (  (instat==INSTAT_JONS).or. &
00124    !!!          (instat==INSTAT_JONS_TABLE).or. &
00125    !!!          (instat==INSTAT_SWAN) .or. &
00126    !!!          (instat==INSTAT_VARDENS) .or. &
00127    !!!          (instat==INSTAT_REUSE) ) then
00128    !!!       ! open file if first time
00129    !!!       if (startbcf) then
00130    !!!
00131    !!!          bcendtime=wbcseries(curline)%bcendtime
00132    !!!          rt       =wbcseries(curline)%rt
00133    !!!          dtbcfile =wbcseries(curline)%dtbcfile
00134    !!!          Trep     =wbcseries(curline)%Trep
00135    !!!          theta0   =wbcseries(curline)%theta0
00136    !!!          ebcfname =wbcseries(curline)%ebcfname
00137    !!!          qbcfname =wbcseries(curline)%qbcfname
00138    !!!
00139    !!!
00140    !!!       endif
00141    !!!
00142    !!!!Dano DOES THIS  BELONG HERE?
00143    !!!       do itheta=1,ntheta
00144    !!!          sigt(:,:,itheta) = 2*par%px/par%Trep
00145    !!!       end do
00146    !!!       sigm = sum(sigt,3)/ntheta
00147    !!!       call dispersion(par,s)
00148    !!!       ! End initialize
00149    !!!!Dano END QUESTION
00150    !!!
00151    !!!       inquire(iolength=wordsize) 1.d0
00152    !!!       reclen=wordsize*(sg%ny+1)*(sg%ntheta)
00153    !!!       open(71,file=ebcfname,status='old',form='unformatted',access='direct',recl=reclen)
00154    !!!       reclen=wordsize*((sg%ny+1)*4)
00155    !!!       open(72,file=qbcfname,status='old',form='unformatted',access='direct',recl=reclen)
00156    !!!       if (.not. allocated(q1) ) then
00157    !!!          allocate(q1(ny+1,4),q2(ny+1,4),q(ny+1,4))
00158    !!!          allocate(ee1(ny+1,ntheta),ee2(ny+1,ntheta))
00159    !!!       end if
00160    !!!       read(71,rec=1,iostat=ier )ee1      ! Earlier in time
00161    !!!       read(71,rec=2,iostat=ier2)ee2      ! Later in time
00162    !!!       read(72,rec=1,iostat=ier )q1       ! Earlier in time
00163    !!!       read(72,rec=2,iostat=ier2)q2       ! Later in time
00164    !!!       old=floor((par%t/dtbcfile)+1)
00165    !!!       recpos=1
00166    !!!    end if
00167    !!!
00168    !!!    new=floor((par%t/dtbcfile)+1)
00169    !!!
00170    !!!    ! Check for next level in boundary condition file
00171    !!!    if (new/=old) then
00172    !!!       recpos=recpos+(new-old)
00173    !!!       ! Check for how many bcfile steps are jumped
00174    !!!       if (new-old>1) then  ! Many steps further in the bc file
00175    !!!          read(72,rec=recpos+1,iostat=ier)q2
00176    !!!          read(71,rec=recpos+1,iostat=ier)ee2
00177    !!!          read(72,rec=recpos  ,iostat=ier)q1
00178    !!!          read(71,rec=recpos  ,iostat=ier)ee1
00179    !!!       else  ! Only one step further in the bc file
00180    !!!          ee1=ee2
00181    !!!          q1=q2
00182    !!!          read(72,rec=recpos+1,iostat=ier)q2
00183    !!!          read(71,rec=recpos+1,iostat=ier)ee2
00184    !!!          endif
00185    !!!          old=new
00186    !!!       end if
00187    !!!    endif
00188    !!!
00189    !!!    tnew = dble(new)*dtbcfile
00190    !!!    facinterp=(tnew-par%t)/dtbcfile
00191    !!!    eebc = (1.d0-facinterp)*ee2 + facinterp*ee1
00192    !!!    qbc  = (1.d0-facinterp)*q2  + facinterp*q1
00193    !!!    uibc = qbc/hbc*min(par%t/par%taper,1.0d0)
00194    !!!    vibc = qbc/hbc*min(par%t/par%taper,1.0d0)
00195    !!!    eebc = eebc*min(par%t/par%taper,1.0d0)
00196    !!!
00197    !!!
00198    !      end subroutine wave_bc_generate
00199 
00200 end module wave_bc_nextgen
00201 
 All Classes Files Functions Variables Defines