[17] | 1 | MODULE advect_tracer_mod |
---|
[19] | 2 | USE icosa |
---|
[138] | 3 | IMPLICIT NONE |
---|
[17] | 4 | PRIVATE |
---|
[22] | 5 | |
---|
[186] | 6 | TYPE(t_field),SAVE,POINTER :: f_normal(:) |
---|
| 7 | TYPE(t_field),SAVE,POINTER :: f_tangent(:) |
---|
| 8 | TYPE(t_field),SAVE,POINTER :: f_gradq3d(:) |
---|
| 9 | TYPE(t_field),SAVE,POINTER :: f_cc(:) ! starting point of backward-trajectory (Miura approach) |
---|
[252] | 10 | TYPE(t_field),SAVE,POINTER :: f_sqrt_leng(:) |
---|
[151] | 11 | |
---|
[186] | 12 | TYPE(t_message),SAVE :: req_u, req_cc, req_wfluxt, req_q, req_rhodz, req_gradq3d |
---|
[151] | 13 | |
---|
[136] | 14 | REAL(rstd), PARAMETER :: pente_max=2.0 ! for vlz |
---|
| 15 | |
---|
[151] | 16 | ! temporary shared variable for vlz |
---|
[186] | 17 | TYPE(t_field),SAVE,POINTER :: f_dzqw(:) ! vertical finite difference of q |
---|
| 18 | TYPE(t_field),SAVE,POINTER :: f_adzqw(:) ! abs(dzqw) |
---|
| 19 | TYPE(t_field),SAVE,POINTER :: f_dzq(:) ! limited slope of q |
---|
| 20 | TYPE(t_field),SAVE,POINTER :: f_wq(:) ! time-integrated flux of q |
---|
[151] | 21 | |
---|
[136] | 22 | PUBLIC init_advect_tracer, advect_tracer |
---|
| 23 | |
---|
[17] | 24 | CONTAINS |
---|
[22] | 25 | |
---|
[98] | 26 | SUBROUTINE init_advect_tracer |
---|
[22] | 27 | USE advect_mod |
---|
[295] | 28 | USE omp_para |
---|
[22] | 29 | REAL(rstd),POINTER :: tangent(:,:) |
---|
| 30 | REAL(rstd),POINTER :: normal(:,:) |
---|
[252] | 31 | REAL(rstd),POINTER :: sqrt_leng(:) |
---|
[23] | 32 | INTEGER :: ind |
---|
[22] | 33 | |
---|
[138] | 34 | CALL allocate_field(f_normal,field_u,type_real,3, name='normal') |
---|
| 35 | CALL allocate_field(f_tangent,field_u,type_real,3, name='tangent') |
---|
| 36 | CALL allocate_field(f_gradq3d,field_t,type_real,llm,3, name='gradq3d') |
---|
| 37 | CALL allocate_field(f_cc,field_u,type_real,llm,3, name='cc') |
---|
[252] | 38 | CALL allocate_field(f_sqrt_leng,field_t,type_real, name='sqrt_leng') |
---|
[151] | 39 | CALL allocate_field(f_dzqw, field_t, type_real, llm, name='dzqw') |
---|
| 40 | CALL allocate_field(f_adzqw, field_t, type_real, llm, name='adzqw') |
---|
| 41 | CALL allocate_field(f_dzq, field_t, type_real, llm, name='dzq') |
---|
| 42 | CALL allocate_field(f_wq, field_t, type_real, llm+1, name='wq') |
---|
| 43 | |
---|
[22] | 44 | DO ind=1,ndomain |
---|
[186] | 45 | IF (.NOT. assigned_domain(ind)) CYCLE |
---|
[22] | 46 | CALL swap_dimensions(ind) |
---|
| 47 | CALL swap_geometry(ind) |
---|
| 48 | normal=f_normal(ind) |
---|
| 49 | tangent=f_tangent(ind) |
---|
[252] | 50 | sqrt_leng=f_sqrt_leng(ind) |
---|
[295] | 51 | IF (is_omp_level_master) CALL init_advect(normal,tangent,sqrt_leng) |
---|
[22] | 52 | END DO |
---|
| 53 | |
---|
[17] | 54 | END SUBROUTINE init_advect_tracer |
---|
[22] | 55 | |
---|
[136] | 56 | SUBROUTINE advect_tracer(f_hfluxt, f_wfluxt,f_u, f_q,f_rhodz) |
---|
[22] | 57 | USE advect_mod |
---|
[136] | 58 | USE mpipara |
---|
[145] | 59 | USE trace |
---|
[347] | 60 | USE write_field_mod |
---|
[380] | 61 | USE tracer_mod |
---|
[22] | 62 | IMPLICIT NONE |
---|
[145] | 63 | |
---|
[136] | 64 | TYPE(t_field),POINTER :: f_hfluxt(:) ! time-integrated horizontal mass flux |
---|
| 65 | TYPE(t_field),POINTER :: f_wfluxt(:) ! time-integrated vertical mass flux |
---|
| 66 | TYPE(t_field),POINTER :: f_u(:) ! velocity (for back-trajectories) |
---|
| 67 | TYPE(t_field),POINTER :: f_q(:) ! tracer |
---|
| 68 | TYPE(t_field),POINTER :: f_rhodz(:) ! mass field at beginning of macro time step |
---|
[17] | 69 | |
---|
[252] | 70 | REAL(rstd),POINTER :: q(:,:,:), normal(:,:), tangent(:,:), sqrt_leng(:), gradq3d(:,:,:), cc(:,:,:) |
---|
[136] | 71 | REAL(rstd),POINTER :: hfluxt(:,:), wfluxt(:,:) |
---|
| 72 | REAL(rstd),POINTER :: rhodz(:,:), u(:,:) |
---|
[151] | 73 | ! temporary shared variable for vlz |
---|
| 74 | REAL(rstd),POINTER :: dzqw(:,:) ! vertical finite difference of q |
---|
| 75 | REAL(rstd),POINTER :: adzqw(:,:) ! abs(dzqw) |
---|
| 76 | REAL(rstd),POINTER :: dzq(:,:) ! limited slope of q |
---|
| 77 | REAL(rstd),POINTER :: wq(:,:) ! time-integrated flux of q |
---|
| 78 | |
---|
[380] | 79 | INTEGER :: ind,k, nq_last |
---|
[151] | 80 | LOGICAL,SAVE :: first=.TRUE. |
---|
| 81 | !$OMP THREADPRIVATE(first) |
---|
[17] | 82 | |
---|
[151] | 83 | IF (first) THEN |
---|
| 84 | first=.FALSE. |
---|
[364] | 85 | CALL init_message(f_u,req_e1_vect,req_u, 'req_u') |
---|
| 86 | CALL init_message(f_cc,req_e1_scal,req_cc, 'req_cc') |
---|
| 87 | CALL init_message(f_wfluxt,req_i1,req_wfluxt, 'req_wfluxt') |
---|
| 88 | CALL init_message(f_q,req_i1,req_q, 'req_q') |
---|
| 89 | CALL init_message(f_rhodz,req_i1,req_rhodz, 'req_rhodz') |
---|
| 90 | CALL init_message(f_gradq3d,req_i1,req_gradq3d, 'req_gradq3d') |
---|
[151] | 91 | ENDIF |
---|
| 92 | |
---|
[186] | 93 | !!$OMP BARRIER |
---|
[151] | 94 | |
---|
[364] | 95 | IF(nqtot<1) RETURN |
---|
[380] | 96 | nq_last=-1 |
---|
| 97 | |
---|
| 98 | DO k = 1, nqtot |
---|
| 99 | IF (advection_scheme(k)==advect_vanleer) nq_last=k |
---|
| 100 | ENDDO |
---|
| 101 | |
---|
| 102 | IF(nq_last<0) RETURN |
---|
| 103 | |
---|
[145] | 104 | CALL trace_start("advect_tracer") |
---|
| 105 | |
---|
[151] | 106 | CALL send_message(f_u,req_u) |
---|
[327] | 107 | CALL send_message(f_wfluxt,req_wfluxt) |
---|
| 108 | CALL send_message(f_q,req_q) |
---|
| 109 | CALL send_message(f_rhodz,req_rhodz) |
---|
| 110 | |
---|
[186] | 111 | CALL wait_message(req_u) |
---|
| 112 | CALL wait_message(req_wfluxt) |
---|
| 113 | CALL wait_message(req_q) |
---|
[151] | 114 | CALL wait_message(req_rhodz) |
---|
| 115 | |
---|
[138] | 116 | ! 1/2 vertical transport + back-trajectories |
---|
[22] | 117 | DO ind=1,ndomain |
---|
[186] | 118 | IF (.NOT. assigned_domain(ind)) CYCLE |
---|
[17] | 119 | CALL swap_dimensions(ind) |
---|
| 120 | CALL swap_geometry(ind) |
---|
[138] | 121 | normal = f_normal(ind) |
---|
| 122 | tangent = f_tangent(ind) |
---|
| 123 | cc = f_cc(ind) |
---|
| 124 | u = f_u(ind) |
---|
[136] | 125 | q = f_q(ind) |
---|
| 126 | rhodz = f_rhodz(ind) |
---|
| 127 | wfluxt = f_wfluxt(ind) |
---|
[151] | 128 | dzqw = f_dzqw(ind) |
---|
| 129 | adzqw = f_adzqw(ind) |
---|
| 130 | dzq = f_dzq(ind) |
---|
| 131 | wq = f_wq(ind) |
---|
[148] | 132 | |
---|
[138] | 133 | DO k = 1, nqtot |
---|
[380] | 134 | IF (advection_scheme(k)==advect_vanleer) CALL vlz(k==nq_last,0.5, wfluxt,rhodz,q(:,:,k),1,dzqw, adzqw, dzq, wq) |
---|
[138] | 135 | END DO |
---|
[148] | 136 | |
---|
[138] | 137 | CALL compute_backward_traj(tangent,normal,u,0.5*dt*itau_adv, cc) |
---|
[151] | 138 | |
---|
[22] | 139 | END DO |
---|
[17] | 140 | |
---|
[174] | 141 | CALL send_message(f_cc,req_cc) |
---|
[17] | 142 | |
---|
[174] | 143 | |
---|
[138] | 144 | ! horizontal transport - split in two to place transfer of gradq3d |
---|
[136] | 145 | DO k = 1, nqtot |
---|
[380] | 146 | IF (advection_scheme(k)==advect_vanleer) THEN |
---|
| 147 | |
---|
| 148 | DO ind=1,ndomain |
---|
[186] | 149 | IF (.NOT. assigned_domain(ind)) CYCLE |
---|
[138] | 150 | CALL swap_dimensions(ind) |
---|
| 151 | CALL swap_geometry(ind) |
---|
| 152 | q = f_q(ind) |
---|
| 153 | gradq3d = f_gradq3d(ind) |
---|
[252] | 154 | sqrt_leng=f_sqrt_leng(ind) |
---|
| 155 | CALL compute_gradq3d(q(:,:,k),sqrt_leng,gradq3d,xyz_i,xyz_v) |
---|
[327] | 156 | |
---|
[380] | 157 | END DO |
---|
[17] | 158 | |
---|
[380] | 159 | CALL send_message(f_gradq3d,req_gradq3d) |
---|
| 160 | CALL wait_message(req_cc) |
---|
| 161 | CALL wait_message(req_gradq3d) |
---|
[17] | 162 | |
---|
[148] | 163 | |
---|
[380] | 164 | DO ind=1,ndomain |
---|
[186] | 165 | IF (.NOT. assigned_domain(ind)) CYCLE |
---|
[138] | 166 | CALL swap_dimensions(ind) |
---|
| 167 | CALL swap_geometry(ind) |
---|
| 168 | cc = f_cc(ind) |
---|
| 169 | q = f_q(ind) |
---|
| 170 | rhodz = f_rhodz(ind) |
---|
| 171 | hfluxt = f_hfluxt(ind) |
---|
| 172 | gradq3d = f_gradq3d(ind) |
---|
[380] | 173 | CALL compute_advect_horiz(k==nq_last,hfluxt,cc,gradq3d, rhodz,q(:,:,k)) |
---|
| 174 | END DO |
---|
| 175 | ENDIF |
---|
[138] | 176 | END DO |
---|
[146] | 177 | |
---|
[136] | 178 | ! 1/2 vertical transport |
---|
[186] | 179 | !!$OMP BARRIER |
---|
[151] | 180 | |
---|
[138] | 181 | DO ind=1,ndomain |
---|
[186] | 182 | IF (.NOT. assigned_domain(ind)) CYCLE |
---|
[138] | 183 | CALL swap_dimensions(ind) |
---|
| 184 | CALL swap_geometry(ind) |
---|
| 185 | q = f_q(ind) |
---|
| 186 | rhodz = f_rhodz(ind) |
---|
| 187 | wfluxt = f_wfluxt(ind) |
---|
[151] | 188 | dzqw = f_dzqw(ind) |
---|
| 189 | adzqw = f_adzqw(ind) |
---|
| 190 | dzq = f_dzq(ind) |
---|
| 191 | wq = f_wq(ind) |
---|
| 192 | |
---|
[138] | 193 | DO k = 1,nqtot |
---|
[380] | 194 | IF (advection_scheme(k)==advect_vanleer) CALL vlz(k==nq_last, 0.5,wfluxt,rhodz, q(:,:,k),0, dzqw, adzqw, dzq, wq) |
---|
[138] | 195 | END DO |
---|
[151] | 196 | |
---|
[136] | 197 | END DO |
---|
[138] | 198 | |
---|
[146] | 199 | CALL trace_end("advect_tracer") |
---|
| 200 | |
---|
[186] | 201 | !!$OMP BARRIER |
---|
[151] | 202 | |
---|
[138] | 203 | END SUBROUTINE advect_tracer |
---|
| 204 | |
---|
[151] | 205 | SUBROUTINE vlz(update_mass, fac,wfluxt,mass, q, halo, dzqw, adzqw, dzq, wq) |
---|
[136] | 206 | ! |
---|
| 207 | ! Auteurs: P.Le Van, F.Hourdin, F.Forget, T. Dubos |
---|
| 208 | ! |
---|
| 209 | ! ******************************************************************** |
---|
| 210 | ! Update tracers using vertical mass flux only |
---|
| 211 | ! Van Leer scheme with minmod limiter |
---|
| 212 | ! wfluxt >0 for upward transport |
---|
| 213 | ! ******************************************************************** |
---|
[148] | 214 | USE trace |
---|
[151] | 215 | USE omp_para |
---|
[22] | 216 | IMPLICIT NONE |
---|
[136] | 217 | LOGICAL, INTENT(IN) :: update_mass |
---|
| 218 | REAL(rstd), INTENT(IN) :: fac, wfluxt(iim*jjm,llm+1) ! vertical mass flux |
---|
| 219 | REAL(rstd), INTENT(INOUT) :: mass(iim*jjm,llm) |
---|
| 220 | REAL(rstd), INTENT(INOUT) :: q(iim*jjm,llm) |
---|
[148] | 221 | INTEGER, INTENT(IN) :: halo |
---|
[22] | 222 | |
---|
[151] | 223 | ! temporary shared variable |
---|
| 224 | REAL(rstd),INTENT(INOUT) :: dzqw(iim*jjm,llm), & ! vertical finite difference of q |
---|
| 225 | adzqw(iim*jjm,llm), & ! abs(dzqw) |
---|
| 226 | dzq(iim*jjm,llm), & ! limited slope of q |
---|
| 227 | wq(iim*jjm,llm+1) ! time-integrated flux of q |
---|
| 228 | |
---|
| 229 | |
---|
[136] | 230 | REAL(rstd) :: dzqmax, newmass, sigw, qq, w |
---|
[174] | 231 | INTEGER :: i,ij,l,j,ijb,ije |
---|
[22] | 232 | |
---|
[148] | 233 | CALL trace_start("vlz") |
---|
[174] | 234 | |
---|
| 235 | ijb=((jj_begin-halo)-1)*iim+ii_begin-halo |
---|
| 236 | ije = ((jj_end+halo)-1)*iim+ii_end+halo |
---|
[148] | 237 | |
---|
[136] | 238 | ! finite difference of q |
---|
[151] | 239 | |
---|
| 240 | DO l=ll_beginp1,ll_end |
---|
[174] | 241 | !$SIMD |
---|
| 242 | DO ij=ijb,ije |
---|
| 243 | dzqw(ij,l)=q(ij,l)-q(ij,l-1) |
---|
| 244 | adzqw(ij,l)=abs(dzqw(ij,l)) |
---|
[22] | 245 | ENDDO |
---|
| 246 | ENDDO |
---|
| 247 | |
---|
[151] | 248 | !--> flush dzqw, adzqw |
---|
[295] | 249 | !$OMP BARRIER |
---|
[151] | 250 | |
---|
[136] | 251 | ! minmod-limited slope of q |
---|
| 252 | ! dzq = slope*dz, i.e. the reconstructed q varies by dzq inside level l |
---|
[151] | 253 | |
---|
| 254 | DO l=ll_beginp1,ll_endm1 |
---|
[174] | 255 | !$SIMD |
---|
| 256 | DO ij=ijb,ije |
---|
| 257 | IF(dzqw(ij,l)*dzqw(ij,l+1).gt.0.) THEN |
---|
| 258 | dzq(ij,l) = 0.5*( dzqw(ij,l)+dzqw(ij,l+1) ) |
---|
| 259 | dzqmax = pente_max * min( adzqw(ij,l),adzqw(ij,l+1) ) |
---|
| 260 | dzq(ij,l) = sign( min(abs(dzq(ij,l)),dzqmax) , dzq(ij,l) ) ! NB : sign(a,b)=a*sign(b) |
---|
| 261 | ELSE |
---|
| 262 | dzq(ij,l)=0. |
---|
| 263 | ENDIF |
---|
[22] | 264 | ENDDO |
---|
| 265 | ENDDO |
---|
[17] | 266 | |
---|
[151] | 267 | |
---|
[136] | 268 | ! 0 slope in top and bottom layers |
---|
[295] | 269 | IF (is_omp_first_level) THEN |
---|
[174] | 270 | DO ij=ijb,ije |
---|
[151] | 271 | dzq(ij,1)=0. |
---|
| 272 | ENDDO |
---|
| 273 | ENDIF |
---|
| 274 | |
---|
[295] | 275 | IF (is_omp_last_level) THEN |
---|
[174] | 276 | DO ij=ijb,ije |
---|
[136] | 277 | dzq(ij,llm)=0. |
---|
[151] | 278 | ENDDO |
---|
| 279 | ENDIF |
---|
[17] | 280 | |
---|
[151] | 281 | !---> flush dzq |
---|
[295] | 282 | !$OMP BARRIER |
---|
[151] | 283 | |
---|
[136] | 284 | ! sigw = fraction of mass that leaves level l/l+1 |
---|
| 285 | ! then amount of q leaving level l/l+1 = wq = w * qq |
---|
[151] | 286 | DO l=ll_beginp1,ll_end |
---|
[174] | 287 | !$SIMD |
---|
| 288 | DO ij=ijb,ije |
---|
[151] | 289 | w = fac*wfluxt(ij,l) |
---|
[138] | 290 | IF(w>0.) THEN ! upward transport, upwind side is at level l |
---|
[151] | 291 | sigw = w/mass(ij,l-1) |
---|
| 292 | qq = q(ij,l-1)+0.5*(1.-sigw)*dzq(ij,l-1) ! qq = q if sigw=1 , qq = q+dzq/2 if sigw=0 |
---|
| 293 | ELSE ! downward transport, upwind side is at level l+1 |
---|
[138] | 294 | sigw = w/mass(ij,l) |
---|
[151] | 295 | qq = q(ij,l)-0.5*(1.+sigw)*dzq(ij,l) ! qq = q if sigw=-1 , qq = q-dzq/2 if sigw=0 |
---|
[22] | 296 | ENDIF |
---|
[151] | 297 | wq(ij,l) = w*qq |
---|
[22] | 298 | ENDDO |
---|
| 299 | END DO |
---|
[136] | 300 | ! wq = 0 at top and bottom |
---|
[295] | 301 | IF (is_omp_first_level) THEN |
---|
[174] | 302 | DO ij=ijb,ije |
---|
[151] | 303 | wq(ij,1)=0. |
---|
| 304 | END DO |
---|
| 305 | ENDIF |
---|
| 306 | |
---|
[295] | 307 | IF (is_omp_last_level) THEN |
---|
[174] | 308 | DO ij=ijb,ije |
---|
[151] | 309 | wq(ij,llm+1)=0. |
---|
| 310 | END DO |
---|
| 311 | ENDIF |
---|
[17] | 312 | |
---|
[151] | 313 | ! --> flush wq |
---|
[295] | 314 | !$OMP BARRIER |
---|
[151] | 315 | |
---|
| 316 | |
---|
[136] | 317 | ! update q, mass is updated only after all q's have been updated |
---|
[151] | 318 | DO l=ll_begin,ll_end |
---|
[174] | 319 | !$SIMD |
---|
| 320 | DO ij=ijb,ije |
---|
[136] | 321 | newmass = mass(ij,l) + fac*(wfluxt(ij,l)-wfluxt(ij,l+1)) |
---|
| 322 | q(ij,l) = ( q(ij,l)*mass(ij,l) + wq(ij,l)-wq(ij,l+1) ) / newmass |
---|
| 323 | IF(update_mass) mass(ij,l)=newmass |
---|
[22] | 324 | ENDDO |
---|
| 325 | END DO |
---|
[136] | 326 | |
---|
[148] | 327 | CALL trace_end("vlz") |
---|
| 328 | |
---|
[22] | 329 | END SUBROUTINE vlz |
---|
[17] | 330 | |
---|
| 331 | END MODULE advect_tracer_mod |
---|