source: palm/trunk/SOURCE/lpm_advec.f90 @ 1691

Last change on this file since 1691 was 1691, checked in by maronga, 9 years ago

various bugfixes and modifications of the atmosphere-land-surface-radiation interaction. Completely re-written routine to calculate surface fluxes (surface_layer_fluxes.f90) that replaces prandtl_fluxes. Minor formatting corrections and renamings

  • Property svn:keywords set to Id
File size: 61.5 KB
Line 
1!> @file lpm_advec.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2015 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21! Renamed prandtl_layer to constant_flux_layer.
22!
23! Former revisions:
24! -----------------
25! $Id: lpm_advec.f90 1691 2015-10-26 16:17:44Z maronga $
26!
27! 1685 2015-10-08 07:32:13Z raasch
28! TKE check for negative values (so far, only zero value was checked)
29! offset_ocean_nzt_m1 removed
30!
31! 1682 2015-10-07 23:56:08Z knoop
32! Code annotations made doxygen readable
33!
34! 1583 2015-04-15 12:16:27Z suehring
35! Bugfix: particle advection within Prandtl-layer in case of Galilei
36! transformation.
37!
38! 1369 2014-04-24 05:57:38Z raasch
39! usage of module interfaces removed
40!
41! 1359 2014-04-11 17:15:14Z hoffmann
42! New particle structure integrated.
43! Kind definition added to all floating point numbers.
44!
45! 1322 2014-03-20 16:38:49Z raasch
46! REAL constants defined as wp_kind
47!
48! 1320 2014-03-20 08:40:49Z raasch
49! ONLY-attribute added to USE-statements,
50! kind-parameters added to all INTEGER and REAL declaration statements,
51! kinds are defined in new module kinds,
52! revision history before 2012 removed,
53! comment fields (!:) to be used for variable explanations added to
54! all variable declaration statements
55!
56! 1314 2014-03-14 18:25:17Z suehring
57! Vertical logarithmic interpolation of horizontal particle speed for particles
58! between roughness height and first vertical grid level.
59!
60! 1036 2012-10-22 13:43:42Z raasch
61! code put under GPL (PALM 3.9)
62!
63! 849 2012-03-15 10:35:09Z raasch
64! initial revision (former part of advec_particles)
65!
66!
67! Description:
68! ------------
69!> Calculation of new particle positions due to advection using a simple Euler
70!> scheme. Particles may feel inertia effects. SGS transport can be included
71!> using the stochastic model of Weil et al. (2004, JAS, 61, 2877-2887).
72!------------------------------------------------------------------------------!
73 SUBROUTINE lpm_advec (ip,jp,kp)
74 
75
76    USE arrays_3d,                                                             &
77        ONLY:  de_dx, de_dy, de_dz, diss, e, u, us, usws, v, vsws, w, z0, zu,  &
78               zw
79
80    USE cpulog
81
82    USE pegrid
83
84    USE control_parameters,                                                    &
85        ONLY:  atmos_ocean_sign, cloud_droplets, constant_flux_layer, dt_3d,   &
86               dt_3d_reached_l, dz, g, kappa, molecular_viscosity, topography, &
87               u_gtrans, v_gtrans, simulated_time
88
89    USE grid_variables,                                                        &
90        ONLY:  ddx, dx, ddy, dy
91       
92    USE indices,                                                               &
93        ONLY:  nzb, nzb_s_inner, nzt
94       
95    USE kinds
96   
97    USE particle_attributes,                                                   &
98        ONLY:  block_offset, c_0, density_ratio, dt_min_part, grid_particles,  &
99               iran_part, log_z_z0, number_of_particles, number_of_sublayers,  &
100               particles, particle_groups, offset_ocean_nzt, sgs_wfu_part,     &
101               sgs_wfv_part, sgs_wfw_part, use_sgs_for_particles,              &
102               vertical_particle_advection, z0_av_global
103       
104    USE statistics,                                                            &
105        ONLY:  hom
106
107    IMPLICIT NONE
108
109    INTEGER(iwp) ::  agp                         !<
110    INTEGER(iwp) ::  gp_outside_of_building(1:8) !<
111    INTEGER(iwp) ::  i                           !<
112    INTEGER(iwp) ::  ip                          !<
113    INTEGER(iwp) ::  j                           !<
114    INTEGER(iwp) ::  jp                          !<
115    INTEGER(iwp) ::  k                           !<
116    INTEGER(iwp) ::  kp                          !<
117    INTEGER(iwp) ::  kw                          !<
118    INTEGER(iwp) ::  n                           !<
119    INTEGER(iwp) ::  nb                          !<
120    INTEGER(iwp) ::  num_gp                      !<
121
122    INTEGER(iwp), DIMENSION(0:7) ::  start_index !<
123    INTEGER(iwp), DIMENSION(0:7) ::  end_index   !<
124
125    REAL(wp) ::  aa                 !<
126    REAL(wp) ::  bb                 !<
127    REAL(wp) ::  cc                 !<
128    REAL(wp) ::  d_sum              !<
129    REAL(wp) ::  d_z_p_z0           !<
130    REAL(wp) ::  dd                 !<
131    REAL(wp) ::  de_dx_int_l        !<
132    REAL(wp) ::  de_dx_int_u        !<
133    REAL(wp) ::  de_dy_int_l        !<
134    REAL(wp) ::  de_dy_int_u        !<
135    REAL(wp) ::  de_dt              !<
136    REAL(wp) ::  de_dt_min          !<
137    REAL(wp) ::  de_dz_int_l        !<
138    REAL(wp) ::  de_dz_int_u        !<
139    REAL(wp) ::  diss_int_l         !<
140    REAL(wp) ::  diss_int_u         !<
141    REAL(wp) ::  dt_gap             !<
142    REAL(wp) ::  dt_particle_m      !<
143    REAL(wp) ::  e_int_l            !<
144    REAL(wp) ::  e_int_u            !<
145    REAL(wp) ::  e_mean_int         !<
146    REAL(wp) ::  exp_arg            !<
147    REAL(wp) ::  exp_term           !<
148    REAL(wp) ::  gg                 !<
149    REAL(wp) ::  height_int         !<
150    REAL(wp) ::  height_p           !<
151    REAL(wp) ::  lagr_timescale     !<
152    REAL(wp) ::  location(1:30,1:3) !<
153    REAL(wp) ::  random_gauss       !<
154    REAL(wp) ::  u_int_l            !<
155    REAL(wp) ::  u_int_u            !<
156    REAL(wp) ::  us_int             !<
157    REAL(wp) ::  v_int_l            !<
158    REAL(wp) ::  v_int_u            !<
159    REAL(wp) ::  vv_int             !<
160    REAL(wp) ::  w_int_l            !<
161    REAL(wp) ::  w_int_u            !<
162    REAL(wp) ::  x                  !<
163    REAL(wp) ::  y                  !<
164    REAL(wp) ::  z_p                !<   
165
166    REAL(wp), DIMENSION(1:30) ::  d_gp_pl !<
167    REAL(wp), DIMENSION(1:30) ::  de_dxi  !<
168    REAL(wp), DIMENSION(1:30) ::  de_dyi  !<
169    REAL(wp), DIMENSION(1:30) ::  de_dzi  !<
170    REAL(wp), DIMENSION(1:30) ::  dissi   !<
171    REAL(wp), DIMENSION(1:30) ::  ei      !<
172
173    REAL(wp), DIMENSION(number_of_particles) ::  dens_ratio   !<
174    REAL(wp), DIMENSION(number_of_particles) ::  de_dx_int    !<
175    REAL(wp), DIMENSION(number_of_particles) ::  de_dy_int    !<
176    REAL(wp), DIMENSION(number_of_particles) ::  de_dz_int    !<
177    REAL(wp), DIMENSION(number_of_particles) ::  diss_int     !<
178    REAL(wp), DIMENSION(number_of_particles) ::  dt_particle  !<
179    REAL(wp), DIMENSION(number_of_particles) ::  e_int        !<
180    REAL(wp), DIMENSION(number_of_particles) ::  fs_int       !<
181    REAL(wp), DIMENSION(number_of_particles) ::  log_z_z0_int !<
182    REAL(wp), DIMENSION(number_of_particles) ::  u_int        !<
183    REAL(wp), DIMENSION(number_of_particles) ::  v_int        !<
184    REAL(wp), DIMENSION(number_of_particles) ::  w_int        !<
185    REAL(wp), DIMENSION(number_of_particles) ::  xv           !<
186    REAL(wp), DIMENSION(number_of_particles) ::  yv           !<
187    REAL(wp), DIMENSION(number_of_particles) ::  zv           !<
188
189    REAL(wp), DIMENSION(number_of_particles, 3) ::  rg !<
190
191    CALL cpu_log( log_point_s(44), 'lpm_advec', 'continue' )
192
193!
194!-- Determine height of Prandtl layer and distance between Prandtl-layer
195!-- height and horizontal mean roughness height, which are required for
196!-- vertical logarithmic interpolation of horizontal particle speeds
197!-- (for particles below first vertical grid level).
198    z_p      = zu(nzb+1) - zw(nzb)
199    d_z_p_z0 = 1.0_wp / ( z_p - z0_av_global )
200
201    start_index = grid_particles(kp,jp,ip)%start_index
202    end_index   = grid_particles(kp,jp,ip)%end_index
203
204    xv = particles(1:number_of_particles)%x
205    yv = particles(1:number_of_particles)%y
206    zv = particles(1:number_of_particles)%z
207
208    DO  nb = 0, 7
209
210       i = ip
211       j = jp + block_offset(nb)%j_off
212       k = kp + block_offset(nb)%k_off
213
214!
215!--    Interpolate u velocity-component
216       DO  n = start_index(nb), end_index(nb)
217!
218!--       Interpolation of the u velocity component onto particle position. 
219!--       Particles are interpolation bi-linearly in the horizontal and a
220!--       linearly in the vertical. An exception is made for particles below
221!--       the first vertical grid level in case of a prandtl layer. In this
222!--       case the horizontal particle velocity components are determined using
223!--       Monin-Obukhov relations (if branch).
224!--       First, check if particle is located below first vertical grid level
225!--       (Prandtl-layer height)
226          IF ( constant_flux_layer  .AND.  particles(n)%z < z_p )  THEN
227!
228!--          Resolved-scale horizontal particle velocity is zero below z0.
229             IF ( particles(n)%z < z0_av_global )  THEN
230                u_int(n) = 0.0_wp
231             ELSE
232!
233!--             Determine the sublayer. Further used as index.
234                height_p     = ( particles(n)%z - z0_av_global )            &
235                                     * REAL( number_of_sublayers, KIND=wp ) &
236                                     * d_z_p_z0 
237!
238!--             Calculate LOG(z/z0) for exact particle height. Therefore,   
239!--             interpolate linearly between precalculated logarithm.
240                log_z_z0_int(n) = log_z_z0(INT(height_p))                      &
241                                 + ( height_p - INT(height_p) )                &
242                                 * ( log_z_z0(INT(height_p)+1)                 &
243                                      - log_z_z0(INT(height_p))                &
244                                   ) 
245!
246!--             Neutral solution is applied for all situations, e.g. also for
247!--             unstable and stable situations. Even though this is not exact
248!--             this saves a lot of CPU time since several calls of intrinsic
249!--             FORTRAN procedures (LOG, ATAN) are avoided, This is justified
250!--             as sensitivity studies revealed no significant effect of
251!--             using the neutral solution also for un/stable situations.
252!--             Calculated left and bottom index on u grid.
253                us_int = 0.5_wp * ( us(j,i) + us(j,i-1) ) 
254
255                u_int  = -usws(j,i) / ( us_int * kappa + 1E-10_wp )           & 
256                         * log_z_z0_int(n) - u_gtrans
257
258             ENDIF
259!
260!--       Particle above the first grid level. Bi-linear interpolation in the
261!--       horizontal and linear interpolation in the vertical direction.
262          ELSE
263
264             x  = xv(n) + ( 0.5_wp - i ) * dx
265             y  = yv(n) - j * dy
266             aa = x**2          + y**2
267             bb = ( dx - x )**2 + y**2
268             cc = x**2          + ( dy - y )**2
269             dd = ( dx - x )**2 + ( dy - y )**2
270             gg = aa + bb + cc + dd
271
272             u_int_l = ( ( gg - aa ) * u(k,j,i)   + ( gg - bb ) * u(k,j,i+1)   &
273                         + ( gg - cc ) * u(k,j+1,i) + ( gg - dd ) *            &
274                         u(k,j+1,i+1) ) / ( 3.0_wp * gg ) - u_gtrans
275
276             IF ( k == nzt )  THEN
277                u_int(n) = u_int_l
278             ELSE
279                u_int_u = ( ( gg-aa ) * u(k+1,j,i) + ( gg-bb ) * u(k+1,j,i+1)  &
280                            + ( gg-cc ) * u(k+1,j+1,i) + ( gg-dd ) *           &
281                            u(k+1,j+1,i+1) ) / ( 3.0_wp * gg ) - u_gtrans
282                u_int(n) = u_int_l + ( zv(n) - zu(k) ) / dz *                  &
283                           ( u_int_u - u_int_l )
284             ENDIF
285          ENDIF
286
287       ENDDO
288
289       i = ip + block_offset(nb)%i_off
290       j = jp
291       k = kp + block_offset(nb)%k_off
292!
293!--    Same procedure for interpolation of the v velocity-component
294       DO  n = start_index(nb), end_index(nb)
295
296          IF ( constant_flux_layer  .AND.  particles(n)%z < z_p )  THEN
297
298             IF ( particles(n)%z < z0_av_global )  THEN
299!
300!--             Resolved-scale horizontal particle velocity is zero below z0.
301                v_int(n) = 0.0_wp
302             ELSE       
303!
304!--             Neutral solution is applied for all situations, e.g. also for
305!--             unstable and stable situations. Even though this is not exact
306!--             this saves a lot of CPU time since several calls of intrinsic
307!--             FORTRAN procedures (LOG, ATAN) are avoided, This is justified
308!--             as sensitivity studies revealed no significant effect of
309!--             using the neutral solution also for un/stable situations.
310!--             Calculated left and bottom index on v grid.
311                us_int = 0.5_wp * ( us(j,i) + us(j-1,i) )   
312
313                v_int  = -vsws(j,i) / ( us_int * kappa + 1E-10_wp )             &
314                         * log_z_z0_int(n) - v_gtrans
315             ENDIF
316          ELSE
317             x  = xv(n) - i * dx
318             y  = yv(n) + ( 0.5_wp - j ) * dy
319             aa = x**2          + y**2
320             bb = ( dx - x )**2 + y**2
321             cc = x**2          + ( dy - y )**2
322             dd = ( dx - x )**2 + ( dy - y )**2
323             gg = aa + bb + cc + dd
324
325             v_int_l = ( ( gg - aa ) * v(k,j,i)   + ( gg - bb ) * v(k,j,i+1)   &
326                       + ( gg - cc ) * v(k,j+1,i) + ( gg - dd ) * v(k,j+1,i+1) &
327                       ) / ( 3.0_wp * gg ) - v_gtrans
328
329             IF ( k == nzt )  THEN
330                v_int(n) = v_int_l
331             ELSE
332                v_int_u = ( ( gg-aa ) * v(k+1,j,i)   + ( gg-bb ) * v(k+1,j,i+1)   &
333                          + ( gg-cc ) * v(k+1,j+1,i) + ( gg-dd ) * v(k+1,j+1,i+1) &
334                          ) / ( 3.0_wp * gg ) - v_gtrans
335                v_int(n) = v_int_l + ( zv(n) - zu(k) ) / dz * &
336                                  ( v_int_u - v_int_l )
337             ENDIF
338          ENDIF
339
340       ENDDO
341
342       i = ip + block_offset(nb)%i_off
343       j = jp + block_offset(nb)%j_off
344       k = kp-1
345!
346!--    Same procedure for interpolation of the w velocity-component
347       DO  n = start_index(nb), end_index(nb)
348
349          IF ( vertical_particle_advection(particles(n)%group) )  THEN
350
351             x  = xv(n) - i * dx
352             y  = yv(n) - j * dy
353             aa = x**2          + y**2
354             bb = ( dx - x )**2 + y**2
355             cc = x**2          + ( dy - y )**2
356             dd = ( dx - x )**2 + ( dy - y )**2
357             gg = aa + bb + cc + dd
358
359             w_int_l = ( ( gg - aa ) * w(k,j,i)   + ( gg - bb ) * w(k,j,i+1)   &
360                       + ( gg - cc ) * w(k,j+1,i) + ( gg - dd ) * w(k,j+1,i+1) &
361                       ) / ( 3.0_wp * gg )
362
363             IF ( k == nzt )  THEN
364                w_int(n) = w_int_l
365             ELSE
366                w_int_u = ( ( gg-aa ) * w(k+1,j,i)   + &
367                            ( gg-bb ) * w(k+1,j,i+1) + &
368                            ( gg-cc ) * w(k+1,j+1,i) + &
369                            ( gg-dd ) * w(k+1,j+1,i+1) &
370                          ) / ( 3.0_wp * gg )
371                w_int(n) = w_int_l + ( zv(n) - zw(k) ) / dz * &
372                           ( w_int_u - w_int_l )
373             ENDIF
374
375          ELSE
376
377             w_int(n) = 0.0_wp
378
379          ENDIF
380
381       ENDDO
382
383    ENDDO
384
385!-- Interpolate and calculate quantities needed for calculating the SGS
386!-- velocities
387    IF ( use_sgs_for_particles )  THEN
388
389       IF ( topography == 'flat' )  THEN
390
391          DO  nb = 0,7
392
393             i = ip + block_offset(nb)%i_off
394             j = jp + block_offset(nb)%j_off
395             k = kp + block_offset(nb)%k_off
396
397             DO  n = start_index(nb), end_index(nb)
398!
399!--             Interpolate TKE
400                x  = xv(n) - i * dx
401                y  = yv(n) - j * dy
402                aa = x**2          + y**2
403                bb = ( dx - x )**2 + y**2
404                cc = x**2          + ( dy - y )**2
405                dd = ( dx - x )**2 + ( dy - y )**2
406                gg = aa + bb + cc + dd
407
408                e_int_l = ( ( gg-aa ) * e(k,j,i)   + ( gg-bb ) * e(k,j,i+1)   &
409                          + ( gg-cc ) * e(k,j+1,i) + ( gg-dd ) * e(k,j+1,i+1) &
410                          ) / ( 3.0_wp * gg )
411
412                IF ( k+1 == nzt+1 )  THEN
413                   e_int(n) = e_int_l
414                ELSE
415                   e_int_u = ( ( gg - aa ) * e(k+1,j,i)   + &
416                               ( gg - bb ) * e(k+1,j,i+1) + &
417                               ( gg - cc ) * e(k+1,j+1,i) + &
418                               ( gg - dd ) * e(k+1,j+1,i+1) &
419                            ) / ( 3.0_wp * gg )
420                   e_int(n) = e_int_l + ( zv(n) - zu(k) ) / dz * &
421                                     ( e_int_u - e_int_l )
422                ENDIF
423!
424!--             Needed to avoid NaN particle velocities (this might not be
425!--             required any more)
426                IF ( e_int(n) <= 0.0_wp )  THEN
427                   e_int(n) = 1.0E-20_wp
428                ENDIF
429!
430!--             Interpolate the TKE gradient along x (adopt incides i,j,k and
431!--             all position variables from above (TKE))
432                de_dx_int_l = ( ( gg - aa ) * de_dx(k,j,i)   + &
433                                ( gg - bb ) * de_dx(k,j,i+1) + &
434                                ( gg - cc ) * de_dx(k,j+1,i) + &
435                                ( gg - dd ) * de_dx(k,j+1,i+1) &
436                               ) / ( 3.0_wp * gg )
437
438                IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
439                   de_dx_int(n) = de_dx_int_l
440                ELSE
441                   de_dx_int_u = ( ( gg - aa ) * de_dx(k+1,j,i)   + &
442                                   ( gg - bb ) * de_dx(k+1,j,i+1) + &
443                                   ( gg - cc ) * de_dx(k+1,j+1,i) + &
444                                   ( gg - dd ) * de_dx(k+1,j+1,i+1) &
445                                  ) / ( 3.0_wp * gg )
446                   de_dx_int(n) = de_dx_int_l + ( zv(n) - zu(k) ) / dz * &
447                                              ( de_dx_int_u - de_dx_int_l )
448                ENDIF
449!
450!--             Interpolate the TKE gradient along y
451                de_dy_int_l = ( ( gg - aa ) * de_dy(k,j,i)   + &
452                                ( gg - bb ) * de_dy(k,j,i+1) + &
453                                ( gg - cc ) * de_dy(k,j+1,i) + &
454                                ( gg - dd ) * de_dy(k,j+1,i+1) &
455                               ) / ( 3.0_wp * gg )
456                IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
457                   de_dy_int(n) = de_dy_int_l
458                ELSE
459                   de_dy_int_u = ( ( gg - aa ) * de_dy(k+1,j,i)   + &
460                                  ( gg - bb ) * de_dy(k+1,j,i+1) + &
461                                  ( gg - cc ) * de_dy(k+1,j+1,i) + &
462                                  ( gg - dd ) * de_dy(k+1,j+1,i+1) &
463                                  ) / ( 3.0_wp * gg )
464                   de_dy_int(n) = de_dy_int_l + ( zv(n) - zu(k) ) / dz * &
465                                              ( de_dy_int_u - de_dy_int_l )
466                ENDIF
467
468!
469!--             Interpolate the TKE gradient along z
470                IF ( zv(n) < 0.5_wp * dz )  THEN
471                   de_dz_int(n) = 0.0_wp
472                ELSE
473                   de_dz_int_l = ( ( gg - aa ) * de_dz(k,j,i)   + &
474                                   ( gg - bb ) * de_dz(k,j,i+1) + &
475                                   ( gg - cc ) * de_dz(k,j+1,i) + &
476                                   ( gg - dd ) * de_dz(k,j+1,i+1) &
477                                  ) / ( 3.0_wp * gg )
478
479                   IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
480                      de_dz_int(n) = de_dz_int_l
481                   ELSE
482                      de_dz_int_u = ( ( gg - aa ) * de_dz(k+1,j,i)   + &
483                                      ( gg - bb ) * de_dz(k+1,j,i+1) + &
484                                      ( gg - cc ) * de_dz(k+1,j+1,i) + &
485                                      ( gg - dd ) * de_dz(k+1,j+1,i+1) &
486                                     ) / ( 3.0_wp * gg )
487                      de_dz_int(n) = de_dz_int_l + ( zv(n) - zu(k) ) / dz * &
488                                                 ( de_dz_int_u - de_dz_int_l )
489                   ENDIF
490                ENDIF
491
492!
493!--             Interpolate the dissipation of TKE
494                diss_int_l = ( ( gg - aa ) * diss(k,j,i)   + &
495                               ( gg - bb ) * diss(k,j,i+1) + &
496                               ( gg - cc ) * diss(k,j+1,i) + &
497                               ( gg - dd ) * diss(k,j+1,i+1) &
498                              ) / ( 3.0_wp * gg )
499
500                IF ( k == nzt )  THEN
501                   diss_int(n) = diss_int_l
502                ELSE
503                   diss_int_u = ( ( gg - aa ) * diss(k+1,j,i)   + &
504                                  ( gg - bb ) * diss(k+1,j,i+1) + &
505                                  ( gg - cc ) * diss(k+1,j+1,i) + &
506                                  ( gg - dd ) * diss(k+1,j+1,i+1) &
507                                 ) / ( 3.0_wp * gg )
508                   diss_int(n) = diss_int_l + ( zv(n) - zu(k) ) / dz * &
509                                           ( diss_int_u - diss_int_l )
510                ENDIF
511
512             ENDDO
513          ENDDO
514
515       ELSE ! non-flat topography, e.g., buildings
516
517          DO  n = 1, number_of_particles
518
519             i = particles(n)%x * ddx
520             j = particles(n)%y * ddy
521             k = ( zv(n) + 0.5_wp * dz * atmos_ocean_sign ) / dz  &
522                 + offset_ocean_nzt                      ! only exact if eq.dist
523!
524!--          In case that there are buildings it has to be determined
525!--          how many of the gridpoints defining the particle box are
526!--          situated within a building
527!--          gp_outside_of_building(1): i,j,k
528!--          gp_outside_of_building(2): i,j+1,k
529!--          gp_outside_of_building(3): i,j,k+1
530!--          gp_outside_of_building(4): i,j+1,k+1
531!--          gp_outside_of_building(5): i+1,j,k
532!--          gp_outside_of_building(6): i+1,j+1,k
533!--          gp_outside_of_building(7): i+1,j,k+1
534!--          gp_outside_of_building(8): i+1,j+1,k+1
535
536             gp_outside_of_building = 0
537             location = 0.0_wp
538             num_gp = 0
539
540             IF ( k > nzb_s_inner(j,i)  .OR.  nzb_s_inner(j,i) == 0 )  THEN
541                num_gp = num_gp + 1
542                gp_outside_of_building(1) = 1
543                location(num_gp,1) = i * dx
544                location(num_gp,2) = j * dy
545                location(num_gp,3) = k * dz - 0.5_wp * dz
546                ei(num_gp)     = e(k,j,i)
547                dissi(num_gp)  = diss(k,j,i)
548                de_dxi(num_gp) = de_dx(k,j,i)
549                de_dyi(num_gp) = de_dy(k,j,i)
550                de_dzi(num_gp) = de_dz(k,j,i)
551             ENDIF
552
553             IF ( k > nzb_s_inner(j+1,i)  .OR.  nzb_s_inner(j+1,i) == 0 ) &
554             THEN
555                num_gp = num_gp + 1
556                gp_outside_of_building(2) = 1
557                location(num_gp,1) = i * dx
558                location(num_gp,2) = (j+1) * dy
559                location(num_gp,3) = k * dz - 0.5_wp * dz
560                ei(num_gp)     = e(k,j+1,i)
561                dissi(num_gp)  = diss(k,j+1,i)
562                de_dxi(num_gp) = de_dx(k,j+1,i)
563                de_dyi(num_gp) = de_dy(k,j+1,i)
564                de_dzi(num_gp) = de_dz(k,j+1,i)
565             ENDIF
566
567             IF ( k+1 > nzb_s_inner(j,i)  .OR.  nzb_s_inner(j,i) == 0 )  THEN
568                num_gp = num_gp + 1
569                gp_outside_of_building(3) = 1
570                location(num_gp,1) = i * dx
571                location(num_gp,2) = j * dy
572                location(num_gp,3) = (k+1) * dz - 0.5_wp * dz
573                ei(num_gp)     = e(k+1,j,i)
574                dissi(num_gp)  = diss(k+1,j,i)
575                de_dxi(num_gp) = de_dx(k+1,j,i)
576                de_dyi(num_gp) = de_dy(k+1,j,i)
577                de_dzi(num_gp) = de_dz(k+1,j,i)
578             ENDIF
579
580             IF ( k+1 > nzb_s_inner(j+1,i)  .OR.  nzb_s_inner(j+1,i) == 0 ) &
581             THEN
582                num_gp = num_gp + 1
583                gp_outside_of_building(4) = 1
584                location(num_gp,1) = i * dx
585                location(num_gp,2) = (j+1) * dy
586                location(num_gp,3) = (k+1) * dz - 0.5_wp * dz
587                ei(num_gp)     = e(k+1,j+1,i)
588                dissi(num_gp)  = diss(k+1,j+1,i)
589                de_dxi(num_gp) = de_dx(k+1,j+1,i)
590                de_dyi(num_gp) = de_dy(k+1,j+1,i)
591                de_dzi(num_gp) = de_dz(k+1,j+1,i)
592             ENDIF
593
594             IF ( k > nzb_s_inner(j,i+1)  .OR.  nzb_s_inner(j,i+1) == 0 ) &
595             THEN
596                num_gp = num_gp + 1
597                gp_outside_of_building(5) = 1
598                location(num_gp,1) = (i+1) * dx
599                location(num_gp,2) = j * dy
600                location(num_gp,3) = k * dz - 0.5_wp * dz
601                ei(num_gp)     = e(k,j,i+1)
602                dissi(num_gp)  = diss(k,j,i+1)
603                de_dxi(num_gp) = de_dx(k,j,i+1)
604                de_dyi(num_gp) = de_dy(k,j,i+1)
605                de_dzi(num_gp) = de_dz(k,j,i+1)
606             ENDIF
607
608             IF ( k > nzb_s_inner(j+1,i+1)  .OR.  nzb_s_inner(j+1,i+1) == 0 ) &
609             THEN
610                num_gp = num_gp + 1
611                gp_outside_of_building(6) = 1
612                location(num_gp,1) = (i+1) * dx
613                location(num_gp,2) = (j+1) * dy
614                location(num_gp,3) = k * dz - 0.5_wp * dz
615                ei(num_gp)     = e(k,j+1,i+1)
616                dissi(num_gp)  = diss(k,j+1,i+1)
617                de_dxi(num_gp) = de_dx(k,j+1,i+1)
618                de_dyi(num_gp) = de_dy(k,j+1,i+1)
619                de_dzi(num_gp) = de_dz(k,j+1,i+1)
620             ENDIF
621
622             IF ( k+1 > nzb_s_inner(j,i+1)  .OR.  nzb_s_inner(j,i+1) == 0 ) &
623             THEN
624                num_gp = num_gp + 1
625                gp_outside_of_building(7) = 1
626                location(num_gp,1) = (i+1) * dx
627                location(num_gp,2) = j * dy
628                location(num_gp,3) = (k+1) * dz - 0.5_wp * dz
629                ei(num_gp)     = e(k+1,j,i+1)
630                dissi(num_gp)  = diss(k+1,j,i+1)
631                de_dxi(num_gp) = de_dx(k+1,j,i+1)
632                de_dyi(num_gp) = de_dy(k+1,j,i+1)
633                de_dzi(num_gp) = de_dz(k+1,j,i+1)
634             ENDIF
635
636             IF ( k+1 > nzb_s_inner(j+1,i+1)  .OR.  nzb_s_inner(j+1,i+1) == 0)&
637             THEN
638                num_gp = num_gp + 1
639                gp_outside_of_building(8) = 1
640                location(num_gp,1) = (i+1) * dx
641                location(num_gp,2) = (j+1) * dy
642                location(num_gp,3) = (k+1) * dz - 0.5_wp * dz
643                ei(num_gp)     = e(k+1,j+1,i+1)
644                dissi(num_gp)  = diss(k+1,j+1,i+1)
645                de_dxi(num_gp) = de_dx(k+1,j+1,i+1)
646                de_dyi(num_gp) = de_dy(k+1,j+1,i+1)
647                de_dzi(num_gp) = de_dz(k+1,j+1,i+1)
648             ENDIF
649
650!
651!--          If all gridpoints are situated outside of a building, then the
652!--          ordinary interpolation scheme can be used.
653             IF ( num_gp == 8 )  THEN
654
655                x  = particles(n)%x - i * dx
656                y  = particles(n)%y - j * dy
657                aa = x**2          + y**2
658                bb = ( dx - x )**2 + y**2
659                cc = x**2          + ( dy - y )**2
660                dd = ( dx - x )**2 + ( dy - y )**2
661                gg = aa + bb + cc + dd
662
663                e_int_l = ( ( gg - aa ) * e(k,j,i)   + ( gg - bb ) * e(k,j,i+1)   &
664                          + ( gg - cc ) * e(k,j+1,i) + ( gg - dd ) * e(k,j+1,i+1) &
665                          ) / ( 3.0_wp * gg )
666
667                IF ( k == nzt )  THEN
668                   e_int(n) = e_int_l
669                ELSE
670                   e_int_u = ( ( gg - aa ) * e(k+1,j,i)   + &
671                               ( gg - bb ) * e(k+1,j,i+1) + &
672                               ( gg - cc ) * e(k+1,j+1,i) + &
673                               ( gg - dd ) * e(k+1,j+1,i+1) &
674                             ) / ( 3.0_wp * gg )
675                   e_int(n) = e_int_l + ( zv(n) - zu(k) ) / dz * &
676                                     ( e_int_u - e_int_l )
677                ENDIF
678!
679!--             Needed to avoid NaN particle velocities (this might not be
680!--             required any more)
681                IF ( e_int(n) <= 0.0_wp )  THEN
682                   e_int(n) = 1.0E-20_wp
683                ENDIF
684!
685!--             Interpolate the TKE gradient along x (adopt incides i,j,k
686!--             and all position variables from above (TKE))
687                de_dx_int_l = ( ( gg - aa ) * de_dx(k,j,i)   + &
688                                ( gg - bb ) * de_dx(k,j,i+1) + &
689                                ( gg - cc ) * de_dx(k,j+1,i) + &
690                                ( gg - dd ) * de_dx(k,j+1,i+1) &
691                              ) / ( 3.0_wp * gg )
692
693                IF ( ( k == nzt )  .OR.  ( k == nzb ) )  THEN
694                   de_dx_int(n) = de_dx_int_l
695                ELSE
696                   de_dx_int_u = ( ( gg - aa ) * de_dx(k+1,j,i)   + &
697                                   ( gg - bb ) * de_dx(k+1,j,i+1) + &
698                                   ( gg - cc ) * de_dx(k+1,j+1,i) + &
699                                   ( gg - dd ) * de_dx(k+1,j+1,i+1) &
700                                 ) / ( 3.0_wp * gg )
701                   de_dx_int(n) = de_dx_int_l + ( zv(n) - zu(k) ) / &
702                                           dz * ( de_dx_int_u - de_dx_int_l )
703                ENDIF
704
705!
706!--             Interpolate the TKE gradient along y
707                de_dy_int_l = ( ( gg - aa ) * de_dy(k,j,i)   + &
708                                ( gg - bb ) * de_dy(k,j,i+1) + &
709                                ( gg - cc ) * de_dy(k,j+1,i) + &
710                                ( gg - dd ) * de_dy(k,j+1,i+1) &
711                              ) / ( 3.0_wp * gg )
712                IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
713                   de_dy_int(n) = de_dy_int_l
714                ELSE
715                   de_dy_int_u = ( ( gg - aa ) * de_dy(k+1,j,i)   + &
716                                   ( gg - bb ) * de_dy(k+1,j,i+1) + &
717                                   ( gg - cc ) * de_dy(k+1,j+1,i) + &
718                                   ( gg - dd ) * de_dy(k+1,j+1,i+1) &
719                                 ) / ( 3.0_wp * gg )
720                   de_dy_int(n) = de_dy_int_l + ( zv(n) - zu(k) ) / &
721                                           dz * ( de_dy_int_u - de_dy_int_l )
722                ENDIF
723
724!
725!--             Interpolate the TKE gradient along z
726                IF ( zv(n) < 0.5_wp * dz )  THEN
727                   de_dz_int(n) = 0.0_wp
728                ELSE
729                   de_dz_int_l = ( ( gg - aa ) * de_dz(k,j,i)   + &
730                                   ( gg - bb ) * de_dz(k,j,i+1) + &
731                                   ( gg - cc ) * de_dz(k,j+1,i) + &
732                                   ( gg - dd ) * de_dz(k,j+1,i+1) &
733                                 ) / ( 3.0_wp * gg )
734
735                   IF ( ( k+1 == nzt+1 )  .OR.  ( k == nzb ) )  THEN
736                      de_dz_int(n) = de_dz_int_l
737                   ELSE
738                      de_dz_int_u = ( ( gg - aa ) * de_dz(k+1,j,i)   + &
739                                      ( gg - bb ) * de_dz(k+1,j,i+1) + &
740                                      ( gg - cc ) * de_dz(k+1,j+1,i) + &
741                                      ( gg - dd ) * de_dz(k+1,j+1,i+1) &
742                                    ) / ( 3.0_wp * gg )
743                      de_dz_int(n) = de_dz_int_l + ( zv(n) - zu(k) ) /&
744                                           dz * ( de_dz_int_u - de_dz_int_l )
745                   ENDIF
746                ENDIF
747
748!
749!--             Interpolate the dissipation of TKE
750                diss_int_l = ( ( gg - aa ) * diss(k,j,i)   + &
751                               ( gg - bb ) * diss(k,j,i+1) + &
752                               ( gg - cc ) * diss(k,j+1,i) + &
753                               ( gg - dd ) * diss(k,j+1,i+1) &
754                             ) / ( 3.0_wp * gg )
755
756                IF ( k == nzt )  THEN
757                   diss_int(n) = diss_int_l
758                ELSE
759                   diss_int_u = ( ( gg - aa ) * diss(k+1,j,i)   + &
760                                  ( gg - bb ) * diss(k+1,j,i+1) + &
761                                  ( gg - cc ) * diss(k+1,j+1,i) + &
762                                  ( gg - dd ) * diss(k+1,j+1,i+1) &
763                                ) / ( 3.0_wp * gg )
764                   diss_int(n) = diss_int_l + ( zv(n) - zu(k) ) / dz *&
765                                           ( diss_int_u - diss_int_l )
766                ENDIF
767
768             ELSE
769
770!
771!--             If wall between gridpoint 1 and gridpoint 5, then
772!--             Neumann boundary condition has to be applied
773                IF ( gp_outside_of_building(1) == 1  .AND. &
774                     gp_outside_of_building(5) == 0 )  THEN
775                   num_gp = num_gp + 1
776                   location(num_gp,1) = i * dx + 0.5_wp * dx
777                   location(num_gp,2) = j * dy
778                   location(num_gp,3) = k * dz - 0.5_wp * dz
779                   ei(num_gp)     = e(k,j,i)
780                   dissi(num_gp)  = diss(k,j,i)
781                   de_dxi(num_gp) = 0.0_wp
782                   de_dyi(num_gp) = de_dy(k,j,i)
783                   de_dzi(num_gp) = de_dz(k,j,i)
784                ENDIF
785
786                IF ( gp_outside_of_building(5) == 1  .AND. &
787                   gp_outside_of_building(1) == 0 )  THEN
788                   num_gp = num_gp + 1
789                   location(num_gp,1) = i * dx + 0.5_wp * dx
790                   location(num_gp,2) = j * dy
791                   location(num_gp,3) = k * dz - 0.5_wp * dz
792                   ei(num_gp)     = e(k,j,i+1)
793                   dissi(num_gp)  = diss(k,j,i+1)
794                   de_dxi(num_gp) = 0.0_wp
795                   de_dyi(num_gp) = de_dy(k,j,i+1)
796                   de_dzi(num_gp) = de_dz(k,j,i+1)
797                ENDIF
798
799!
800!--             If wall between gridpoint 5 and gridpoint 6, then
801!--             then Neumann boundary condition has to be applied
802                IF ( gp_outside_of_building(5) == 1  .AND. &
803                     gp_outside_of_building(6) == 0 )  THEN
804                   num_gp = num_gp + 1
805                   location(num_gp,1) = (i+1) * dx
806                   location(num_gp,2) = j * dy + 0.5_wp * dy
807                   location(num_gp,3) = k * dz - 0.5_wp * dz
808                   ei(num_gp)     = e(k,j,i+1)
809                   dissi(num_gp)  = diss(k,j,i+1)
810                   de_dxi(num_gp) = de_dx(k,j,i+1)
811                   de_dyi(num_gp) = 0.0_wp
812                   de_dzi(num_gp) = de_dz(k,j,i+1)
813                ENDIF
814
815                IF ( gp_outside_of_building(6) == 1  .AND. &
816                     gp_outside_of_building(5) == 0 )  THEN
817                   num_gp = num_gp + 1
818                   location(num_gp,1) = (i+1) * dx
819                   location(num_gp,2) = j * dy + 0.5_wp * dy
820                   location(num_gp,3) = k * dz - 0.5_wp * dz
821                   ei(num_gp)     = e(k,j+1,i+1)
822                   dissi(num_gp)  = diss(k,j+1,i+1)
823                   de_dxi(num_gp) = de_dx(k,j+1,i+1)
824                   de_dyi(num_gp) = 0.0_wp
825                   de_dzi(num_gp) = de_dz(k,j+1,i+1)
826                ENDIF
827
828!
829!--             If wall between gridpoint 2 and gridpoint 6, then
830!--             Neumann boundary condition has to be applied
831                IF ( gp_outside_of_building(2) == 1  .AND. &
832                     gp_outside_of_building(6) == 0 )  THEN
833                   num_gp = num_gp + 1
834                   location(num_gp,1) = i * dx + 0.5_wp * dx
835                   location(num_gp,2) = (j+1) * dy
836                   location(num_gp,3) = k * dz - 0.5_wp * dz
837                   ei(num_gp)     = e(k,j+1,i)
838                   dissi(num_gp)  = diss(k,j+1,i)
839                   de_dxi(num_gp) = 0.0_wp
840                   de_dyi(num_gp) = de_dy(k,j+1,i)
841                   de_dzi(num_gp) = de_dz(k,j+1,i)
842                ENDIF
843
844                IF ( gp_outside_of_building(6) == 1  .AND. &
845                     gp_outside_of_building(2) == 0 )  THEN
846                   num_gp = num_gp + 1
847                   location(num_gp,1) = i * dx + 0.5_wp * dx
848                   location(num_gp,2) = (j+1) * dy
849                   location(num_gp,3) = k * dz - 0.5_wp * dz
850                   ei(num_gp)     = e(k,j+1,i+1)
851                   dissi(num_gp)  = diss(k,j+1,i+1)
852                   de_dxi(num_gp) = 0.0_wp
853                   de_dyi(num_gp) = de_dy(k,j+1,i+1)
854                   de_dzi(num_gp) = de_dz(k,j+1,i+1)
855                ENDIF
856
857!
858!--             If wall between gridpoint 1 and gridpoint 2, then
859!--             Neumann boundary condition has to be applied
860                IF ( gp_outside_of_building(1) == 1  .AND. &
861                     gp_outside_of_building(2) == 0 )  THEN
862                   num_gp = num_gp + 1
863                   location(num_gp,1) = i * dx
864                   location(num_gp,2) = j * dy + 0.5_wp * dy
865                   location(num_gp,3) = k * dz - 0.5_wp * dz
866                   ei(num_gp)     = e(k,j,i)
867                   dissi(num_gp)  = diss(k,j,i)
868                   de_dxi(num_gp) = de_dx(k,j,i)
869                   de_dyi(num_gp) = 0.0_wp
870                   de_dzi(num_gp) = de_dz(k,j,i)
871                ENDIF
872
873                IF ( gp_outside_of_building(2) == 1  .AND. &
874                     gp_outside_of_building(1) == 0 )  THEN
875                   num_gp = num_gp + 1
876                   location(num_gp,1) = i * dx
877                   location(num_gp,2) = j * dy + 0.5_wp * dy
878                   location(num_gp,3) = k * dz - 0.5_wp * dz
879                   ei(num_gp)     = e(k,j+1,i)
880                   dissi(num_gp)  = diss(k,j+1,i)
881                   de_dxi(num_gp) = de_dx(k,j+1,i)
882                   de_dyi(num_gp) = 0.0_wp
883                   de_dzi(num_gp) = de_dz(k,j+1,i)
884                ENDIF
885
886!
887!--             If wall between gridpoint 3 and gridpoint 7, then
888!--             Neumann boundary condition has to be applied
889                IF ( gp_outside_of_building(3) == 1  .AND. &
890                     gp_outside_of_building(7) == 0 )  THEN
891                   num_gp = num_gp + 1
892                   location(num_gp,1) = i * dx + 0.5_wp * dx
893                   location(num_gp,2) = j * dy
894                   location(num_gp,3) = k * dz + 0.5_wp * dz
895                   ei(num_gp)     = e(k+1,j,i)
896                   dissi(num_gp)  = diss(k+1,j,i)
897                   de_dxi(num_gp) = 0.0_wp
898                   de_dyi(num_gp) = de_dy(k+1,j,i)
899                   de_dzi(num_gp) = de_dz(k+1,j,i) 
900                ENDIF
901
902                IF ( gp_outside_of_building(7) == 1  .AND. &
903                     gp_outside_of_building(3) == 0 )  THEN
904                   num_gp = num_gp + 1
905                   location(num_gp,1) = i * dx + 0.5_wp * dx
906                   location(num_gp,2) = j * dy
907                   location(num_gp,3) = k * dz + 0.5_wp * dz
908                   ei(num_gp)     = e(k+1,j,i+1)
909                   dissi(num_gp)  = diss(k+1,j,i+1)
910                   de_dxi(num_gp) = 0.0_wp
911                   de_dyi(num_gp) = de_dy(k+1,j,i+1)
912                   de_dzi(num_gp) = de_dz(k+1,j,i+1)
913                ENDIF
914
915!
916!--             If wall between gridpoint 7 and gridpoint 8, then
917!--             Neumann boundary condition has to be applied
918                IF ( gp_outside_of_building(7) == 1  .AND. &
919                     gp_outside_of_building(8) == 0 )  THEN
920                   num_gp = num_gp + 1
921                   location(num_gp,1) = (i+1) * dx
922                   location(num_gp,2) = j * dy + 0.5_wp * dy
923                   location(num_gp,3) = k * dz + 0.5_wp * dz
924                   ei(num_gp)     = e(k+1,j,i+1)
925                   dissi(num_gp)  = diss(k+1,j,i+1)
926                   de_dxi(num_gp) = de_dx(k+1,j,i+1)
927                   de_dyi(num_gp) = 0.0_wp
928                   de_dzi(num_gp) = de_dz(k+1,j,i+1)
929                ENDIF
930
931                IF ( gp_outside_of_building(8) == 1  .AND. &
932                     gp_outside_of_building(7) == 0 )  THEN
933                   num_gp = num_gp + 1
934                   location(num_gp,1) = (i+1) * dx
935                   location(num_gp,2) = j * dy + 0.5_wp * dy
936                   location(num_gp,3) = k * dz + 0.5_wp * dz
937                   ei(num_gp)     = e(k+1,j+1,i+1)
938                   dissi(num_gp)  = diss(k+1,j+1,i+1)
939                   de_dxi(num_gp) = de_dx(k+1,j+1,i+1)
940                   de_dyi(num_gp) = 0.0_wp
941                   de_dzi(num_gp) = de_dz(k+1,j+1,i+1)
942                ENDIF
943
944!
945!--             If wall between gridpoint 4 and gridpoint 8, then
946!--             Neumann boundary condition has to be applied
947                IF ( gp_outside_of_building(4) == 1  .AND. &
948                     gp_outside_of_building(8) == 0 )  THEN
949                   num_gp = num_gp + 1
950                   location(num_gp,1) = i * dx + 0.5_wp * dx
951                   location(num_gp,2) = (j+1) * dy
952                   location(num_gp,3) = k * dz + 0.5_wp * dz
953                   ei(num_gp)     = e(k+1,j+1,i)
954                   dissi(num_gp)  = diss(k+1,j+1,i)
955                   de_dxi(num_gp) = 0.0_wp
956                   de_dyi(num_gp) = de_dy(k+1,j+1,i)
957                   de_dzi(num_gp) = de_dz(k+1,j+1,i)
958                ENDIF
959
960                IF ( gp_outside_of_building(8) == 1  .AND. &
961                     gp_outside_of_building(4) == 0 )  THEN
962                   num_gp = num_gp + 1
963                   location(num_gp,1) = i * dx + 0.5_wp * dx
964                   location(num_gp,2) = (j+1) * dy
965                   location(num_gp,3) = k * dz + 0.5_wp * dz
966                   ei(num_gp)     = e(k+1,j+1,i+1)
967                   dissi(num_gp)  = diss(k+1,j+1,i+1)
968                   de_dxi(num_gp) = 0.0_wp
969                   de_dyi(num_gp) = de_dy(k+1,j+1,i+1)
970                   de_dzi(num_gp) = de_dz(k+1,j+1,i+1)
971                ENDIF
972
973!
974!--             If wall between gridpoint 3 and gridpoint 4, then
975!--             Neumann boundary condition has to be applied
976                IF ( gp_outside_of_building(3) == 1  .AND. &
977                     gp_outside_of_building(4) == 0 )  THEN
978                   num_gp = num_gp + 1
979                   location(num_gp,1) = i * dx
980                   location(num_gp,2) = j * dy + 0.5_wp * dy
981                   location(num_gp,3) = k * dz + 0.5_wp * dz
982                   ei(num_gp)     = e(k+1,j,i)
983                   dissi(num_gp)  = diss(k+1,j,i)
984                   de_dxi(num_gp) = de_dx(k+1,j,i)
985                   de_dyi(num_gp) = 0.0_wp
986                   de_dzi(num_gp) = de_dz(k+1,j,i)
987                ENDIF
988
989                IF ( gp_outside_of_building(4) == 1  .AND. &
990                     gp_outside_of_building(3) == 0 )  THEN
991                   num_gp = num_gp + 1
992                   location(num_gp,1) = i * dx
993                   location(num_gp,2) = j * dy + 0.5_wp * dy
994                   location(num_gp,3) = k * dz + 0.5_wp * dz
995                   ei(num_gp)     = e(k+1,j+1,i)
996                   dissi(num_gp)  = diss(k+1,j+1,i)
997                   de_dxi(num_gp) = de_dx(k+1,j+1,i)
998                   de_dyi(num_gp) = 0.0_wp
999                   de_dzi(num_gp) = de_dz(k+1,j+1,i)
1000                ENDIF
1001
1002!
1003!--             If wall between gridpoint 1 and gridpoint 3, then
1004!--             Neumann boundary condition has to be applied
1005!--             (only one case as only building beneath is possible)
1006                IF ( gp_outside_of_building(1) == 0  .AND. &
1007                     gp_outside_of_building(3) == 1 )  THEN
1008                   num_gp = num_gp + 1
1009                   location(num_gp,1) = i * dx
1010                   location(num_gp,2) = j * dy
1011                   location(num_gp,3) = k * dz
1012                   ei(num_gp)     = e(k+1,j,i)
1013                   dissi(num_gp)  = diss(k+1,j,i)
1014                   de_dxi(num_gp) = de_dx(k+1,j,i)
1015                   de_dyi(num_gp) = de_dy(k+1,j,i)
1016                   de_dzi(num_gp) = 0.0_wp
1017                ENDIF
1018
1019!
1020!--             If wall between gridpoint 5 and gridpoint 7, then
1021!--             Neumann boundary condition has to be applied
1022!--             (only one case as only building beneath is possible)
1023                IF ( gp_outside_of_building(5) == 0  .AND. &
1024                     gp_outside_of_building(7) == 1 )  THEN
1025                   num_gp = num_gp + 1
1026                   location(num_gp,1) = (i+1) * dx
1027                   location(num_gp,2) = j * dy
1028                   location(num_gp,3) = k * dz
1029                   ei(num_gp)     = e(k+1,j,i+1)
1030                   dissi(num_gp)  = diss(k+1,j,i+1)
1031                   de_dxi(num_gp) = de_dx(k+1,j,i+1)
1032                   de_dyi(num_gp) = de_dy(k+1,j,i+1)
1033                   de_dzi(num_gp) = 0.0_wp
1034                ENDIF
1035
1036!
1037!--             If wall between gridpoint 2 and gridpoint 4, then
1038!--             Neumann boundary condition has to be applied
1039!--             (only one case as only building beneath is possible)
1040                IF ( gp_outside_of_building(2) == 0  .AND. &
1041                     gp_outside_of_building(4) == 1 )  THEN
1042                   num_gp = num_gp + 1
1043                   location(num_gp,1) = i * dx
1044                   location(num_gp,2) = (j+1) * dy
1045                   location(num_gp,3) = k * dz
1046                   ei(num_gp)     = e(k+1,j+1,i)
1047                   dissi(num_gp)  = diss(k+1,j+1,i)
1048                   de_dxi(num_gp) = de_dx(k+1,j+1,i)
1049                   de_dyi(num_gp) = de_dy(k+1,j+1,i)
1050                   de_dzi(num_gp) = 0.0_wp
1051                ENDIF
1052
1053!
1054!--             If wall between gridpoint 6 and gridpoint 8, then
1055!--             Neumann boundary condition has to be applied
1056!--             (only one case as only building beneath is possible)
1057                IF ( gp_outside_of_building(6) == 0  .AND. &
1058                     gp_outside_of_building(8) == 1 )  THEN
1059                   num_gp = num_gp + 1
1060                   location(num_gp,1) = (i+1) * dx
1061                   location(num_gp,2) = (j+1) * dy
1062                   location(num_gp,3) = k * dz
1063                   ei(num_gp)     = e(k+1,j+1,i+1)
1064                   dissi(num_gp)  = diss(k+1,j+1,i+1)
1065                   de_dxi(num_gp) = de_dx(k+1,j+1,i+1)
1066                   de_dyi(num_gp) = de_dy(k+1,j+1,i+1)
1067                   de_dzi(num_gp) = 0.0_wp
1068                ENDIF
1069
1070!
1071!--             Carry out the interpolation
1072                IF ( num_gp == 1 )  THEN
1073!
1074!--                If only one of the gridpoints is situated outside of the
1075!--                building, it follows that the values at the particle
1076!--                location are the same as the gridpoint values
1077                   e_int(n)     = ei(num_gp)
1078                   diss_int(n)  = dissi(num_gp)
1079                   de_dx_int(n) = de_dxi(num_gp)
1080                   de_dy_int(n) = de_dyi(num_gp)
1081                   de_dz_int(n) = de_dzi(num_gp)
1082                ELSE IF ( num_gp > 1 )  THEN
1083
1084                   d_sum = 0.0_wp
1085!
1086!--                Evaluation of the distances between the gridpoints
1087!--                contributing to the interpolated values, and the particle
1088!--                location
1089                   DO  agp = 1, num_gp
1090                      d_gp_pl(agp) = ( particles(n)%x-location(agp,1) )**2  &
1091                                   + ( particles(n)%y-location(agp,2) )**2  &
1092                                   + ( zv(n)-location(agp,3) )**2
1093                      d_sum        = d_sum + d_gp_pl(agp)
1094                   ENDDO
1095
1096!
1097!--                Finally the interpolation can be carried out
1098                   e_int(n)     = 0.0_wp 
1099                   diss_int(n)  = 0.0_wp 
1100                   de_dx_int(n) = 0.0_wp 
1101                   de_dy_int(n) = 0.0_wp 
1102                   de_dz_int(n) = 0.0_wp 
1103                   DO  agp = 1, num_gp
1104                      e_int(n)     = e_int(n)     + ( d_sum - d_gp_pl(agp) ) * &
1105                                             ei(agp) / ( (num_gp-1) * d_sum )
1106                      diss_int(n)  = diss_int(n)  + ( d_sum - d_gp_pl(agp) ) * &
1107                                          dissi(agp) / ( (num_gp-1) * d_sum )
1108                      de_dx_int(n) = de_dx_int(n) + ( d_sum - d_gp_pl(agp) ) * &
1109                                         de_dxi(agp) / ( (num_gp-1) * d_sum )
1110                      de_dy_int(n) = de_dy_int(n) + ( d_sum - d_gp_pl(agp) ) * &
1111                                         de_dyi(agp) / ( (num_gp-1) * d_sum )
1112                      de_dz_int(n) = de_dz_int(n) + ( d_sum - d_gp_pl(agp) ) * &
1113                                         de_dzi(agp) / ( (num_gp-1) * d_sum )
1114                   ENDDO
1115
1116                ENDIF
1117
1118             ENDIF
1119          ENDDO
1120       ENDIF
1121
1122       DO nb = 0,7
1123          i = ip + block_offset(nb)%i_off
1124          j = jp + block_offset(nb)%j_off
1125          k = kp + block_offset(nb)%k_off
1126
1127          DO  n = start_index(nb), end_index(nb)
1128!
1129!--          Vertical interpolation of the horizontally averaged SGS TKE and
1130!--          resolved-scale velocity variances and use the interpolated values
1131!--          to calculate the coefficient fs, which is a measure of the ratio
1132!--          of the subgrid-scale turbulent kinetic energy to the total amount
1133!--          of turbulent kinetic energy.
1134             IF ( k == 0 )  THEN
1135                e_mean_int = hom(0,1,8,0)
1136             ELSE
1137                e_mean_int = hom(k,1,8,0) +                                    &
1138                                           ( hom(k+1,1,8,0) - hom(k,1,8,0) ) / &
1139                                           ( zu(k+1) - zu(k) ) *               &
1140                                           ( zv(n) - zu(k) )
1141             ENDIF
1142
1143             kw = kp - 1
1144
1145             IF ( k == 0 )  THEN
1146                aa  = hom(k+1,1,30,0)  * ( zv(n) / &
1147                                         ( 0.5_wp * ( zu(k+1) - zu(k) ) ) )
1148                bb  = hom(k+1,1,31,0)  * ( zv(n) / &
1149                                         ( 0.5_wp * ( zu(k+1) - zu(k) ) ) )
1150                cc  = hom(kw+1,1,32,0) * ( zv(n) / &
1151                                         ( 1.0_wp * ( zw(kw+1) - zw(kw) ) ) )
1152             ELSE
1153                aa  = hom(k,1,30,0) + ( hom(k+1,1,30,0) - hom(k,1,30,0) ) *    &
1154                           ( ( zv(n) - zu(k) ) / ( zu(k+1) - zu(k) ) )
1155                bb  = hom(k,1,31,0) + ( hom(k+1,1,31,0) - hom(k,1,31,0) ) *    &
1156                           ( ( zv(n) - zu(k) ) / ( zu(k+1) - zu(k) ) )
1157                cc  = hom(kw,1,32,0) + ( hom(kw+1,1,32,0)-hom(kw,1,32,0) ) *   &
1158                           ( ( zv(n) - zw(kw) ) / ( zw(kw+1)-zw(kw) ) )
1159             ENDIF
1160
1161             vv_int = ( 1.0_wp / 3.0_wp ) * ( aa + bb + cc )
1162!
1163!--          Needed to avoid NaN particle velocities. The value of 1.0 is just
1164!--          an educated guess for the given case.
1165             IF ( vv_int + ( 2.0_wp / 3.0_wp ) * e_mean_int == 0.0_wp )  THEN
1166                fs_int(n) = 1.0_wp
1167             ELSE
1168                fs_int(n) = ( 2.0_wp / 3.0_wp ) * e_mean_int /                 &
1169                            ( vv_int + ( 2.0_wp / 3.0_wp ) * e_mean_int )
1170             ENDIF
1171
1172          ENDDO
1173       ENDDO
1174
1175       DO  n = 1, number_of_particles
1176
1177         rg(n,1) = random_gauss( iran_part, 5.0_wp )
1178         rg(n,2) = random_gauss( iran_part, 5.0_wp )
1179         rg(n,3) = random_gauss( iran_part, 5.0_wp )
1180
1181       ENDDO
1182
1183       DO  n = 1, number_of_particles
1184!
1185!--       Calculate the Lagrangian timescale according to Weil et al. (2004).
1186          lagr_timescale = ( 4.0_wp * e_int(n) ) / &
1187                           ( 3.0_wp * fs_int(n) * c_0 * diss_int(n) )
1188
1189!
1190!--       Calculate the next particle timestep. dt_gap is the time needed to
1191!--       complete the current LES timestep.
1192          dt_gap = dt_3d - particles(n)%dt_sum
1193          dt_particle(n) = MIN( dt_3d, 0.025_wp * lagr_timescale, dt_gap )
1194
1195!
1196!--       The particle timestep should not be too small in order to prevent
1197!--       the number of particle timesteps of getting too large
1198          IF ( dt_particle(n) < dt_min_part  .AND.  dt_min_part < dt_gap )  THEN
1199             dt_particle(n) = dt_min_part
1200          ENDIF
1201
1202!
1203!--       Calculate the SGS velocity components
1204          IF ( particles(n)%age == 0.0_wp )  THEN
1205!
1206!--          For new particles the SGS components are derived from the SGS
1207!--          TKE. Limit the Gaussian random number to the interval
1208!--          [-5.0*sigma, 5.0*sigma] in order to prevent the SGS velocities
1209!--          from becoming unrealistically large.
1210             particles(n)%rvar1 = SQRT( 2.0_wp * sgs_wfu_part * e_int(n) ) *   &
1211                                  ( rg(n,1) - 1.0_wp )
1212             particles(n)%rvar2 = SQRT( 2.0_wp * sgs_wfv_part * e_int(n) ) *   &
1213                                  ( rg(n,2) - 1.0_wp )
1214             particles(n)%rvar3 = SQRT( 2.0_wp * sgs_wfw_part * e_int(n) ) *   &
1215                                  ( rg(n,3) - 1.0_wp )
1216
1217          ELSE
1218!
1219!--          Restriction of the size of the new timestep: compared to the
1220!--          previous timestep the increase must not exceed 200%
1221
1222             dt_particle_m = particles(n)%age - particles(n)%age_m
1223             IF ( dt_particle(n) > 2.0_wp * dt_particle_m )  THEN
1224                dt_particle(n) = 2.0_wp * dt_particle_m
1225             ENDIF
1226
1227!
1228!--          For old particles the SGS components are correlated with the
1229!--          values from the previous timestep. Random numbers have also to
1230!--          be limited (see above).
1231!--          As negative values for the subgrid TKE are not allowed, the
1232!--          change of the subgrid TKE with time cannot be smaller than
1233!--          -e_int(n)/dt_particle. This value is used as a lower boundary
1234!--          value for the change of TKE
1235
1236             de_dt_min = - e_int(n) / dt_particle(n)
1237
1238             de_dt = ( e_int(n) - particles(n)%e_m ) / dt_particle_m
1239
1240             IF ( de_dt < de_dt_min )  THEN
1241                de_dt = de_dt_min
1242             ENDIF
1243
1244             particles(n)%rvar1 = particles(n)%rvar1 - fs_int(n) * c_0 *       &
1245                           diss_int(n) * particles(n)%rvar1 * dt_particle(n) / &
1246                           ( 4.0_wp * sgs_wfu_part * e_int(n) ) +              &
1247                           ( 2.0_wp * sgs_wfu_part * de_dt *                   &
1248                             particles(n)%rvar1 /                              &
1249                             ( 2.0_wp * sgs_wfu_part * e_int(n) ) +            &
1250                             de_dx_int(n)                                      &
1251                           ) * dt_particle(n) / 2.0_wp          +              &
1252                           SQRT( fs_int(n) * c_0 * diss_int(n) ) *             &
1253                           ( rg(n,1) - 1.0_wp ) *                              &
1254                           SQRT( dt_particle(n) )
1255
1256             particles(n)%rvar2 = particles(n)%rvar2 - fs_int(n) * c_0 *       &
1257                           diss_int(n) * particles(n)%rvar2 * dt_particle(n) / &
1258                           ( 4.0_wp * sgs_wfv_part * e_int(n) ) +              &
1259                           ( 2.0_wp * sgs_wfv_part * de_dt *                   &
1260                             particles(n)%rvar2 /                              &
1261                             ( 2.0_wp * sgs_wfv_part * e_int(n) ) +            &
1262                             de_dy_int(n)                                      &
1263                           ) * dt_particle(n) / 2.0_wp          +              &
1264                           SQRT( fs_int(n) * c_0 * diss_int(n) ) *             &
1265                           ( rg(n,2) - 1.0_wp ) *                              &
1266                           SQRT( dt_particle(n) )
1267
1268             particles(n)%rvar3 = particles(n)%rvar3 - fs_int(n) * c_0 *       &
1269                           diss_int(n) * particles(n)%rvar3 * dt_particle(n) / &
1270                           ( 4.0_wp * sgs_wfw_part * e_int(n) ) +              &
1271                           ( 2.0_wp * sgs_wfw_part * de_dt *                   &
1272                             particles(n)%rvar3 /                              &
1273                             ( 2.0_wp * sgs_wfw_part * e_int(n) ) +            &
1274                             de_dz_int(n)                                      &
1275                           ) * dt_particle(n) / 2.0_wp          +              &
1276                           SQRT( fs_int(n) * c_0 * diss_int(n) ) *             &
1277                           ( rg(n,3) - 1.0_wp ) *                              &
1278                           SQRT( dt_particle(n) )
1279
1280          ENDIF
1281          u_int(n) = u_int(n) + particles(n)%rvar1
1282          v_int(n) = v_int(n) + particles(n)%rvar2
1283          w_int(n) = w_int(n) + particles(n)%rvar3
1284
1285!
1286!--       Store the SGS TKE of the current timelevel which is needed for
1287!--       for calculating the SGS particle velocities at the next timestep
1288          particles(n)%e_m = e_int(n)
1289       ENDDO
1290
1291    ELSE
1292!
1293!--    If no SGS velocities are used, only the particle timestep has to
1294!--    be set
1295       dt_particle = dt_3d
1296
1297    ENDIF
1298!
1299!-- Store the old age of the particle ( needed to prevent that a
1300!-- particle crosses several PEs during one timestep, and for the
1301!-- evaluation of the subgrid particle velocity fluctuations )
1302    particles(1:number_of_particles)%age_m = particles(1:number_of_particles)%age
1303
1304    dens_ratio = particle_groups(particles(1:number_of_particles)%group)%density_ratio
1305
1306    IF ( ANY( dens_ratio == 0.0_wp ) )  THEN
1307       DO  n = 1, number_of_particles
1308
1309!
1310!--       Particle advection
1311          IF ( dens_ratio(n) == 0.0_wp )  THEN
1312!
1313!--          Pure passive transport (without particle inertia)
1314             particles(n)%x = xv(n) + u_int(n) * dt_particle(n)
1315             particles(n)%y = yv(n) + v_int(n) * dt_particle(n)
1316             particles(n)%z = zv(n) + w_int(n) * dt_particle(n)
1317
1318             particles(n)%speed_x = u_int(n)
1319             particles(n)%speed_y = v_int(n)
1320             particles(n)%speed_z = w_int(n)
1321
1322          ELSE
1323!
1324!--          Transport of particles with inertia
1325             particles(n)%x = particles(n)%x + particles(n)%speed_x * &
1326                                               dt_particle(n)
1327             particles(n)%y = particles(n)%y + particles(n)%speed_y * &
1328                                               dt_particle(n)
1329             particles(n)%z = particles(n)%z + particles(n)%speed_z * &
1330                                               dt_particle(n)
1331
1332!
1333!--          Update of the particle velocity
1334             IF ( cloud_droplets )  THEN
1335                exp_arg  = 4.5_wp * dens_ratio(n) * molecular_viscosity /      &
1336                           ( particles(n)%radius )**2 *                        &
1337                           ( 1.0_wp + 0.15_wp * ( 2.0_wp * particles(n)%radius &
1338                             * SQRT( ( u_int(n) - particles(n)%speed_x )**2 +  &
1339                                     ( v_int(n) - particles(n)%speed_y )**2 +  &
1340                                     ( w_int(n) - particles(n)%speed_z )**2 )  &
1341                                          / molecular_viscosity )**0.687_wp    &
1342                           )
1343
1344                exp_term = EXP( -exp_arg * dt_particle(n) )
1345             ELSEIF ( use_sgs_for_particles )  THEN
1346                exp_arg  = particle_groups(particles(n)%group)%exp_arg
1347                exp_term = EXP( -exp_arg * dt_particle(n) )
1348             ELSE
1349                exp_arg  = particle_groups(particles(n)%group)%exp_arg
1350                exp_term = particle_groups(particles(n)%group)%exp_term
1351             ENDIF
1352             particles(n)%speed_x = particles(n)%speed_x * exp_term +          &
1353                                    u_int(n) * ( 1.0_wp - exp_term )
1354             particles(n)%speed_y = particles(n)%speed_y * exp_term +          &
1355                                    v_int(n) * ( 1.0_wp - exp_term )
1356             particles(n)%speed_z = particles(n)%speed_z * exp_term +          &
1357                                    ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) *  &
1358                                    g / exp_arg ) * ( 1.0_wp - exp_term )
1359          ENDIF
1360
1361       ENDDO
1362   
1363    ELSE
1364
1365       DO  n = 1, number_of_particles
1366
1367!--       Transport of particles with inertia
1368          particles(n)%x = xv(n) + particles(n)%speed_x * dt_particle(n)
1369          particles(n)%y = yv(n) + particles(n)%speed_y * dt_particle(n)
1370          particles(n)%z = zv(n) + particles(n)%speed_z * dt_particle(n)
1371!
1372!--       Update of the particle velocity
1373          IF ( cloud_droplets )  THEN
1374
1375             exp_arg  = 4.5_wp * dens_ratio(n) * molecular_viscosity /         &
1376                        ( particles(n)%radius )**2 *                           &
1377                        ( 1.0_wp + 0.15_wp * ( 2.0_wp * particles(n)%radius *  &
1378                          SQRT( ( u_int(n) - particles(n)%speed_x )**2 +       &
1379                                ( v_int(n) - particles(n)%speed_y )**2 +       &
1380                                ( w_int(n) - particles(n)%speed_z )**2 ) /     &
1381                                         molecular_viscosity )**0.687_wp       &
1382                        )
1383
1384             exp_term = EXP( -exp_arg * dt_particle(n) )
1385          ELSEIF ( use_sgs_for_particles )  THEN
1386             exp_arg  = particle_groups(particles(n)%group)%exp_arg
1387             exp_term = EXP( -exp_arg * dt_particle(n) )
1388          ELSE
1389             exp_arg  = particle_groups(particles(n)%group)%exp_arg
1390             exp_term = particle_groups(particles(n)%group)%exp_term
1391          ENDIF
1392          particles(n)%speed_x = particles(n)%speed_x * exp_term +             &
1393                                 u_int(n) * ( 1.0_wp - exp_term )
1394          particles(n)%speed_y = particles(n)%speed_y * exp_term +             &
1395                                 v_int(n) * ( 1.0_wp - exp_term )
1396          particles(n)%speed_z = particles(n)%speed_z * exp_term +             &
1397                                 ( w_int(n) - ( 1.0_wp - dens_ratio(n) ) * g / &
1398                                 exp_arg ) * ( 1.0_wp - exp_term )
1399       ENDDO
1400
1401    ENDIF
1402
1403    DO  n = 1, number_of_particles
1404!
1405!--    Increment the particle age and the total time that the particle
1406!--    has advanced within the particle timestep procedure
1407       particles(n)%age    = particles(n)%age    + dt_particle(n)
1408       particles(n)%dt_sum = particles(n)%dt_sum + dt_particle(n)
1409
1410!
1411!--    Check whether there is still a particle that has not yet completed
1412!--    the total LES timestep
1413       IF ( ( dt_3d - particles(n)%dt_sum ) > 1E-8_wp )  THEN
1414          dt_3d_reached_l = .FALSE.
1415       ENDIF
1416
1417    ENDDO
1418
1419    CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
1420
1421 END SUBROUTINE lpm_advec
Note: See TracBrowser for help on using the repository browser.