source: flexpart.git/src/calcfluxes.f90 @ 4138764

dev
Last change on this file since 4138764 was 4138764, checked in by Sabine <sabine.eckhardt@…>, 3 years ago

Merge remote-tracking branch 'refs/remotes/origin/dev' into dev

  • Property mode set to 100644
File size: 6.4 KB
Line 
1! SPDX-FileCopyrightText: FLEXPART 1998-2019, see flexpart_license.txt
2! SPDX-License-Identifier: GPL-3.0-or-later
3
4subroutine calcfluxes(nage,jpart,xold,yold,zold)
5  !                       i     i    i    i    i
6  !*****************************************************************************
7  !                                                                            *
8  !     Calculation of the gross fluxes across horizontal, eastward and        *
9  !     northward facing surfaces. The routine calculates the mass flux        *
10  !     due to the motion of only one particle. The fluxes of subsequent calls *
11  !     to this subroutine are accumulated until the next output is due.       *
12  !     Upon output, flux fields are re-set to zero in subroutine fluxoutput.f.*
13  !                                                                            *
14  !     Author: A. Stohl                                                       *
15  !                                                                            *
16  !     04 April 2000                                                          *
17  !                                                                            *
18  !*****************************************************************************
19  !                                                                            *
20  ! Variables:                                                                 *
21  !                                                                            *
22  ! nage                  Age class of the particle considered                 *
23  ! jpart                 Index of the particle considered                     *
24  ! xold,yold,zold        "Memorized" old positions of the particle            *
25  !                                                                            *
26  !*****************************************************************************
27
28  use flux_mod
29  use outg_mod
30  use par_mod
31  use com_mod
32
33  implicit none
34
35  integer :: jpart,nage,ixave,jyave,kz,kzave,kp
36  integer :: k,k1,k2,ix,ix1,ix2,ixs,jy,jy1,jy2
37  real :: xold,yold,zold,xmean,ymean
38
39
40  ! Determine average positions
41  !****************************
42
43  if ((ioutputforeachrelease.eq.1).and.(mdomainfill.eq.0)) then
44     kp=npoint(jpart)
45  else
46     kp=1
47  endif
48
49  xmean=(xold+xtra1(jpart))/2.
50  ymean=(yold+ytra1(jpart))/2.
51
52  ixave=int((xmean*dx+xoutshift)/dxout)
53  jyave=int((ymean*dy+youtshift)/dyout)
54  do kz=1,numzgrid                ! determine height of cell
55    if (outheight(kz).gt.ztra1(jpart)) goto 16
56  end do
5716   kzave=kz
58
59
60  ! Determine vertical fluxes
61  !**************************
62
63  if ((ixave.ge.0).and.(jyave.ge.0).and.(ixave.le.numxgrid-1).and. &
64       (jyave.le.numygrid-1)) then
65    do kz=1,numzgrid                ! determine height of cell
66!      if (outheighthalf(kz).gt.zold) goto 11
67      if (outheight(kz).gt.zold) goto 11 !sec, use upper layer instead of mid layer
68    end do
6911   k1=min(numzgrid,kz)
70    do kz=1,numzgrid                ! determine height of cell
71!      if (outheighthalf(kz).gt.ztra1(jpart)) goto 21
72      if (outheight(kz).gt.ztra1(jpart)) goto 21
73    end do
7421   k2=min(numzgrid,kz)
75
76    do k=1,nspec
77      do kz=k1,k2-1
78        flux(5,ixave,jyave,kz,k,kp,nage)= &
79             flux(5,ixave,jyave,kz,k,kp,nage)+ &
80             xmass1(jpart,k)
81      end do
82      do kz=k2,k1-1
83        flux(6,ixave,jyave,kz,k,kp,nage)= &
84             flux(6,ixave,jyave,kz,k,kp,nage)+ &
85             xmass1(jpart,k)
86      end do
87    end do
88  endif
89
90
91  ! Determine west-east fluxes (fluxw) and east-west fluxes (fluxe)
92  !****************************************************************
93
94  if ((kzave.le.numzgrid).and.(jyave.ge.0).and. &
95       (jyave.le.numygrid-1)) then
96
97  ! 1) Particle does not cross domain boundary
98
99    if (abs(xold-xtra1(jpart)).lt.real(nx)/2.) then
100      ix1=int((xold*dx+xoutshift)/dxout)              ! flux throught the western boundary (sec)
101      ix2=int((xtra1(jpart)*dx+xoutshift)/dxout)      ! flux throught the western boundary (sec)
102!      ix1=int((xold*dx+xoutshift)/dxout+0.5)
103!      ix2=int((xtra1(jpart)*dx+xoutshift)/dxout+0.5)
104      do k=1,nspec
105        do ix=ix1,ix2-1
106          if ((ix.ge.0).and.(ix.le.numxgrid-1)) then
107            flux(1,ix,jyave,kzave,k,kp,nage)= &
108                 flux(1,ix,jyave,kzave,k,kp,nage) &
109                 +xmass1(jpart,k)
110          endif
111        end do
112        do ix=ix2,ix1-1
113          if ((ix.ge.0).and.(ix.le.numxgrid-1)) then
114            flux(2,ix,jyave,kzave,k,kp,nage)= &
115                 flux(2,ix,jyave,kzave,k,kp,nage) &
116                 +xmass1(jpart,k)
117          endif
118        end do
119      end do
120
121  ! 2) Particle crosses domain boundary: use cyclic boundary condition
122  !    and attribute flux to easternmost grid row only (approximation valid
123  !    for relatively slow motions compared to output grid cell size)
124
125    else
126      ixs=int(((real(nxmin1)-1.e5)*dx+xoutshift)/dxout)
127      if ((ixs.ge.0).and.(ixs.le.numxgrid-1)) then
128        if (xold.gt.xtra1(jpart)) then       ! west-east flux
129          do k=1,nspec
130            flux(1,ixs,jyave,kzave,k,kp,nage)= &
131                 flux(1,ixs,jyave,kzave,k,kp,nage) &
132                 +xmass1(jpart,k)
133          end do
134        else                                 ! east-west flux
135          do k=1,nspec
136            flux(2,ixs,jyave,kzave,k,kp,nage)= &
137                 flux(2,ixs,jyave,kzave,k,kp,nage) &
138                 +xmass1(jpart,k)
139          end do
140        endif
141      endif
142    endif
143  endif
144
145
146  ! Determine south-north fluxes (fluxs) and north-south fluxes (fluxn)
147  !********************************************************************
148
149  if ((kzave.le.numzgrid).and.(ixave.ge.0).and. &
150       (ixave.le.numxgrid-1)) then
151    jy1=int((yold*dy+youtshift)/dyout)         ! flux throught the southern boundary (sec)
152    jy2=int((ytra1(jpart)*dy+youtshift)/dyout) ! flux throught the southern boundary (sec)
153!    jy1=int((yold*dy+youtshift)/dyout+0.5)
154!    jy2=int((ytra1(jpart)*dy+youtshift)/dyout+0.5)
155
156    do k=1,nspec
157      do jy=jy1,jy2-1
158        if ((jy.ge.0).and.(jy.le.numygrid-1)) then
159          flux(3,ixave,jy,kzave,k,kp,nage)= &
160               flux(3,ixave,jy,kzave,k,kp,nage) &
161               +xmass1(jpart,k)
162        endif
163      end do
164      do jy=jy2,jy1-1
165        if ((jy.ge.0).and.(jy.le.numygrid-1)) then
166          flux(4,ixave,jy,kzave,k,kp,nage)= &
167               flux(4,ixave,jy,kzave,k,kp,nage) &
168               +xmass1(jpart,k)
169        endif
170      end do
171    end do
172  endif
173
174end subroutine calcfluxes
175
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG