Changeset 8a65cb0 in flexpart.git for src/advance.f90


Ignore:
Timestamp:
Mar 2, 2015, 3:11:55 PM (9 years ago)
Author:
Espen Sollum ATMOS <espen@…>
Branches:
master, 10.4.1_pesei, GFS_025, bugfixes+enhancements, dev, release-10, release-10.4.1, scaling-bug, univie
Children:
1d207bb
Parents:
60403cd
Message:

Added code, makefile for dev branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/advance.f90

    re200b7a r8a65cb0  
    103103  use hanna_mod
    104104  use cmapf_mod
     105  use random_mod, only: ran3
    105106
    106107  implicit none
     
    108109  real(kind=dp) :: xt,yt
    109110  real :: zt,xts,yts,weight
    110   integer :: itime,itimec,nstop,ldt,i,j,k,nrand,loop,memindnext
     111  integer :: itime,itimec,nstop,ldt,i,j,k,nrand,loop,memindnext,mind
    111112  integer :: ngr,nix,njy,ks,nsp,nrelpoint
    112113  real :: dz,dz1,dz2,xlon,ylat,xpol,ypol,gridsize
     
    119120  !real usigprof(nzmax),vsigprof(nzmax),wsigprof(nzmax)
    120121  !real rhoprof(nzmax),rhogradprof(nzmax)
    121   real :: rhoa,rhograd,ran3,delz,dtf,rhoaux,dtftlw,uxscale,wpscale
     122  real :: rhoa,rhograd,delz,dtf,rhoaux,dtftlw,uxscale,wpscale
    122123  integer(kind=2) :: icbt
    123124  real,parameter :: eps=nxmax/3.e5,eps2=1.e-9
     125  real :: ptot_lhh,Q_lhh,phi_lhh,ath,bth !modified by mc
     126  real :: old_wp_buf,dcas,dcas1,del_test !added by mc
     127  integer :: i_well,jj,flagrein !test well mixed: modified by mc
    124128
    125129
     
    225229  if (ngrid.le.0) then
    226230    do k=1,2
     231! eso: compatibility with 3-field version
     232      mind=memind(k)
    227233      do j=jy,jyp
    228234        do i=ix,ixp
    229           if (hmix(i,j,1,k).gt.h) h=hmix(i,j,1,k)
     235          if (hmix(i,j,1,mind).gt.h) h=hmix(i,j,1,mind)
    230236        end do
    231237      end do
     
    234240  else
    235241    do k=1,2
     242      mind=memind(k)
    236243      do j=jy,jyp
    237244        do i=ix,ixp
    238           if (hmixn(i,j,1,k,ngrid).gt.h) h=hmixn(i,j,1,k,ngrid)
     245          if (hmixn(i,j,1,mind,ngrid).gt.h) h=hmixn(i,j,1,mind,ngrid)
    239246        end do
    240247      end do
     
    379386        if (turbswitch) then
    380387          if (dtftlw.lt..5) then
    381             wp=((1.-dtftlw)*wp+rannumb(nrand+i)*sqrt(2.*dtftlw) &
    382                  +dtf*(dsigwdz+rhoaux*sigw))*real(icbt)
     388  !*************************************************************
     389  !************** CBL options added by mc see routine cblf90 ***
     390            if (cblflag.eq.1) then  !modified by mc
     391              if (-h/ol.gt.5) then  !modified by mc
     392              !if (ol.lt.0.) then   !modified by mc 
     393              !if (ol.gt.0.) then   !modified by mc : for test
     394                  !print  *,zt,wp,ath,bth,tlw,dtf,'prima'
     395                  flagrein=0
     396                  nrand=nrand+1
     397                  old_wp_buf=wp
     398                  call cbl(wp,zt,ust,wst,h,rhoa,rhograd,sigw,dsigwdz,tlw,ptot_lhh,Q_lhh,phi_lhh,ath,bth,ol,flagrein) !inside the routine for inverse time
     399                  wp=(wp+ath*dtf+bth*rannumb(nrand)*sqrt(dtf))*real(icbt)
     400                  ! wp=(wp+ath*dtf+bth*gasdev2(mydum)*sqrt(dtf))*real(icbt)
     401                  delz=wp*dtf
     402                  if (flagrein.eq.1) then
     403                      call re_initialize_particle(zt,ust,wst,h,sigw,old_wp_buf,nrand,ol)
     404                      wp=old_wp_buf
     405                      delz=wp*dtf
     406                      nan_count=nan_count+1
     407                  end if
     408                  !print  *,zt,wp,ath,bth,tlw,dtf,rannumb(nrand+i),icbt
     409                  !pause                 
     410              else
     411                  nrand=nrand+1
     412                  old_wp_buf=wp
     413                  ath=-wp/tlw+sigw*dsigwdz+wp*wp/sigw*dsigwdz+sigw*sigw/rhoa*rhograd  !1-note for inverse time should be -wp/tlw*ldirect+... calculated for wp=-wp
     414                                                                                      !2-but since ldirect =-1 for inverse time and this must be calculated for (-wp) and
     415                                                                                      !3-the gaussian pdf is symmetric (i.e. pdf(w)=pdf(-w) ldirect can be discarded
     416                  bth=sigw*rannumb(nrand)*sqrt(2.*dtftlw)
     417                  wp=(wp+ath*dtf+bth)*real(icbt) 
     418                  delz=wp*dtf
     419                  del_test=(1.-wp)/wp !catch infinity value
     420                  if (isnan(wp).or.isnan(del_test)) then
     421                      nrand=nrand+1                     
     422                      wp=sigw*rannumb(nrand)
     423                      delz=wp*dtf
     424                      nan_count2=nan_count2+1
     425                      !print *,'NaN coutner equal to:', nan_count,'reduce ifine if this number became a non-negligible fraction of the particle number'
     426                  end if 
     427              end if
     428  !******************** END CBL option *******************************           
     429  !*******************************************************************           
     430            else
     431                 wp=((1.-dtftlw)*wp+rannumb(nrand+i)*sqrt(2.*dtftlw) &
     432                 +dtf*(dsigwdz+rhoaux*sigw))*real(icbt)
     433                 delz=wp*sigw*dtf
     434            end if
    383435          else
    384436            rw=exp(-dtftlw)
    385437            wp=(rw*wp+rannumb(nrand+i)*sqrt(1.-rw**2) &
    386438                 +tlw*(1.-rw)*(dsigwdz+rhoaux*sigw))*real(icbt)
     439            delz=wp*sigw*dtf
    387440          endif
    388           delz=wp*sigw*dtf
     441         
    389442        else
    390443          rw=exp(-dtftlw)
     
    421474
    422475      end do
    423       nrand=nrand+i
     476      if (cblflag.ne.1) nrand=nrand+i
    424477
    425478  ! Determine time step for next integration
     
    463516      dcwsave=dcwsave+vp*dt
    464517      zt=zt+w*dt*real(ldirect)
     518
     519      ! HSO/AL: Particle managed to go over highest level -> interpolation error in goto 700
     520      !          alias interpol_wind (division by zero)
     521      if (zt.ge.height(nz)) zt=height(nz)-100.*eps
    465522
    466523      if (zt.gt.h) then
     
    493550  !if (mod(itime,10800).ne.0) dump=.true.
    494551  !!! CHANGE
    495 
    496 
     552     
     553  !!!----- TEST OF THE WELL-MIXED CRITERION: modified by mc,  not to be included in final version mc
     554      ! if (zt.lt.h) then
     555      !     i_well=int(zt/h*25.)+1
     556      !     well_mixed_vector(i_well)=well_mixed_vector(i_well)+dt
     557      !     well_mixed_norm=well_mixed_norm+dt
     558      !     avg_air_dens(i_well)=avg_air_dens(i_well)+rhoa*dt
     559      !     avg_wst=avg_wst+wst*dt
     560      !     avg_ol=avg_ol+ol*dt
     561      !     avg_h=avg_h+h*dt
     562      ! end if
     563      ! h_well=h
     564  !------- END TEST
     565     
    497566  ! Determine probability of deposition
    498567  !************************************
     
    656725
    657726  call windalign(dxsave,dysave,dawsave,dcwsave,ux,vy)
    658   dxsave=dxsave+ux
     727  dxsave=dxsave+ux   ! comment by mc: comment this line to stop the particles horizontally for test reasons
    659728  dysave=dysave+vy
    660729  if (ngrid.ge.0) then
     
    663732    yt=yt+real(dysave*dyconst*real(ldirect),kind=dp)
    664733  else if (ngrid.eq.-1) then      ! around north pole
    665     xlon=xlon0+xt*dx
     734    xlon=xlon0+xt*dx                                !comment by mc: compute old particle position
    666735    ylat=ylat0+yt*dy
    667     call cll2xy(northpolemap,ylat,xlon,xpol,ypol)
    668     gridsize=1000.*cgszll(northpolemap,ylat,xlon)
    669     dxsave=dxsave/gridsize
     736    call cll2xy(northpolemap,ylat,xlon,xpol,ypol)   !convert old particle position in polar stereographic
     737    gridsize=1000.*cgszll(northpolemap,ylat,xlon)   !calculate size in m of grid element in polar stereographic coordinate
     738    dxsave=dxsave/gridsize                          !increment from meter to grdi unit
    670739    dysave=dysave/gridsize
    671     xpol=xpol+dxsave*real(ldirect)
     740    xpol=xpol+dxsave*real(ldirect)                  !position in grid unit polar stereographic
    672741    ypol=ypol+dysave*real(ldirect)
    673     call cxy2ll(northpolemap,xpol,ypol,ylat,xlon)
    674     xt=(xlon-xlon0)/dx
     742    call cxy2ll(northpolemap,xpol,ypol,ylat,xlon)  !convert to lat long coordinate
     743    xt=(xlon-xlon0)/dx                             !convert to grid units in lat long coordinate, comment by mc
    675744    yt=(ylat-ylat0)/dy
    676745  else if (ngrid.eq.-2) then    ! around south pole
     
    699768  endif
    700769
     770  ! HSO/AL: Prevent particles from disappearing at the pole
     771  !******************************************************************
     772
     773  if ( yt.lt.0. ) then
     774    xt=mod(xt+180.,360.)
     775    yt=-yt
     776  else if ( yt.gt.real(nymin1) ) then
     777    xt=mod(xt+180.,360.)
     778    yt=2*real(nymin1)-yt
     779  endif
    701780
    702781  ! Check position: If trajectory outside model domain, terminate it
     
    704783
    705784  if ((xt.lt.0.).or.(xt.ge.real(nxmin1)).or.(yt.lt.0.).or. &
    706        (yt.ge.real(nymin1))) then
     785       (yt.gt.real(nymin1))) then
    707786    nstop=3
    708787    return
     
    859938  endif
    860939
     940  ! HSO/AL: Prevent particles from disappearing at the pole
     941  !******************************************************************
     942
     943  if ( yt.lt.0. ) then
     944    xt=mod(xt+180.,360.)
     945    yt=-yt
     946  else if ( yt.gt.real(nymin1) ) then
     947    xt=mod(xt+180.,360.)
     948    yt=2*real(nymin1)-yt
     949  endif
     950
    861951  ! Check position: If trajectory outside model domain, terminate it
    862952  !*****************************************************************
    863953
    864954  if ((xt.lt.0.).or.(xt.ge.real(nxmin1)).or.(yt.lt.0.).or. &
    865        (yt.ge.real(nymin1))) then
     955       (yt.gt.real(nymin1))) then
    866956    nstop=3
    867957    return
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG