1 | !> @file init_grid.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 1997-2019 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: init_grid.f90 4265 2019-10-15 16:16:24Z resler $ |
---|
27 | ! Bugfix for last commit, exchange oro_max variable only when it is allocated |
---|
28 | ! (not necessarily the case when topography is input from ASCII file). |
---|
29 | ! |
---|
30 | ! 4245 2019-09-30 08:40:37Z pavelkrc |
---|
31 | ! Store oro_max (building z-offset) in 2D for building surfaces |
---|
32 | ! |
---|
33 | ! 4189 2019-08-26 16:19:38Z suehring |
---|
34 | ! - Add check for proper setting of namelist parameter topography |
---|
35 | ! - Set flag to indicate land surfaces in case no topography is provided |
---|
36 | ! |
---|
37 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
38 | ! Corrected "Former revisions" section |
---|
39 | ! |
---|
40 | ! 4168 2019-08-16 13:50:17Z suehring |
---|
41 | ! Pre-calculate topography top index and store it on an array (replaces former |
---|
42 | ! functions get_topography_top_index) |
---|
43 | ! |
---|
44 | ! 4159 2019-08-15 13:31:35Z suehring |
---|
45 | ! Revision of topography processing. This was not consistent between 2D and 3D |
---|
46 | ! buildings. |
---|
47 | ! |
---|
48 | ! 4144 2019-08-06 09:11:47Z raasch |
---|
49 | ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc. |
---|
50 | ! |
---|
51 | ! 4115 2019-07-24 12:50:49Z suehring |
---|
52 | ! Bugfix in setting near-surface flag 24, inidicating wall-bounded grid points |
---|
53 | ! |
---|
54 | ! 4110 2019-07-22 17:05:21Z suehring |
---|
55 | ! - Separate initialization of advection flags for momentum and scalars. |
---|
56 | ! - Change subroutine interface for ws_init_flags_scalar to pass boundary flags |
---|
57 | ! |
---|
58 | ! 4109 2019-07-22 17:00:34Z suehring |
---|
59 | ! Fix bad commit |
---|
60 | ! |
---|
61 | ! 3926 2019-04-23 12:56:42Z suehring |
---|
62 | ! Minor bugfix in building mapping when all building IDs in the model domain |
---|
63 | ! are missing |
---|
64 | ! |
---|
65 | ! 3857 2019-04-03 13:00:16Z knoop |
---|
66 | ! In projection of non-building 3D objects onto numerical grid remove |
---|
67 | ! dependency on building_type |
---|
68 | ! |
---|
69 | ! 3763 2019-02-25 17:33:49Z suehring |
---|
70 | ! Replace work-around for ghost point exchange of 1-byte arrays with specific |
---|
71 | ! routine as already done in other routines |
---|
72 | ! |
---|
73 | ! 3761 2019-02-25 15:31:42Z raasch |
---|
74 | ! unused variables removed |
---|
75 | ! |
---|
76 | ! 3661 2019-01-08 18:22:50Z suehring |
---|
77 | ! Remove setting of nzb_max to nzt at non-cyclic boundary PEs, instead, |
---|
78 | ! order degradation of advection scheme is handeled directly in advec_ws |
---|
79 | ! |
---|
80 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
81 | ! Comment added |
---|
82 | ! |
---|
83 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
84 | ! Initial revision (Testversion) |
---|
85 | ! |
---|
86 | ! |
---|
87 | ! Description: |
---|
88 | ! -----------------------------------------------------------------------------! |
---|
89 | !> Creating grid depending constants |
---|
90 | !> @todo: Rearrange topo flag list |
---|
91 | !> @todo: reference 3D buildings on top of orography is not tested and may need |
---|
92 | !> further improvement for steep slopes |
---|
93 | !> @todo: Use more advanced setting of building type at filled holes |
---|
94 | !------------------------------------------------------------------------------! |
---|
95 | SUBROUTINE init_grid |
---|
96 | |
---|
97 | USE advec_ws, & |
---|
98 | ONLY: ws_init_flags_momentum, ws_init_flags_scalar |
---|
99 | |
---|
100 | USE arrays_3d, & |
---|
101 | ONLY: dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzw, x, xu, y, yv, zu, zw |
---|
102 | |
---|
103 | USE control_parameters, & |
---|
104 | ONLY: bc_lr_cyc, bc_ns_cyc, & |
---|
105 | bc_dirichlet_l, & |
---|
106 | bc_dirichlet_n, & |
---|
107 | bc_dirichlet_r, & |
---|
108 | bc_dirichlet_s, & |
---|
109 | bc_radiation_l, & |
---|
110 | bc_radiation_n, & |
---|
111 | bc_radiation_r, & |
---|
112 | bc_radiation_s, & |
---|
113 | constant_flux_layer, dz, dz_max, dz_stretch_factor, & |
---|
114 | dz_stretch_factor_array, dz_stretch_level, dz_stretch_level_end,& |
---|
115 | dz_stretch_level_end_index, dz_stretch_level_start_index, & |
---|
116 | dz_stretch_level_start, ibc_uv_b, message_string, & |
---|
117 | momentum_advec, number_stretch_level_end, & |
---|
118 | number_stretch_level_start, ocean_mode, psolver, scalar_advec, & |
---|
119 | topography, use_surface_fluxes |
---|
120 | |
---|
121 | USE grid_variables, & |
---|
122 | ONLY: ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, zu_s_inner, zw_w_inner |
---|
123 | |
---|
124 | USE indices, & |
---|
125 | ONLY: advc_flags_m, & |
---|
126 | advc_flags_s, & |
---|
127 | nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz, & |
---|
128 | nzb, nzb_diff, nzb_diff_s_inner, nzb_diff_s_outer, & |
---|
129 | nzb_max, nzb_s_inner, nzb_s_outer, nzb_u_inner, & |
---|
130 | nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner, & |
---|
131 | nzb_w_outer, nzt, topo_top_ind, topo_min_level |
---|
132 | |
---|
133 | USE kinds |
---|
134 | |
---|
135 | USE pegrid |
---|
136 | |
---|
137 | USE poismg_noopt_mod |
---|
138 | |
---|
139 | USE surface_mod, & |
---|
140 | ONLY: init_bc |
---|
141 | |
---|
142 | USE vertical_nesting_mod, & |
---|
143 | ONLY: vnested, vnest_init_grid |
---|
144 | |
---|
145 | IMPLICIT NONE |
---|
146 | |
---|
147 | INTEGER(iwp) :: i !< index variable along x |
---|
148 | INTEGER(iwp) :: j !< index variable along y |
---|
149 | INTEGER(iwp) :: k !< index variable along z |
---|
150 | INTEGER(iwp) :: k_top !< topography top index on local PE |
---|
151 | INTEGER(iwp) :: n !< loop variable for stretching |
---|
152 | INTEGER(iwp) :: number_dz !< number of user-specified dz values |
---|
153 | INTEGER(iwp) :: nzb_local_max !< vertical grid index of maximum topography height |
---|
154 | INTEGER(iwp) :: nzb_local_min !< vertical grid index of minimum topography height |
---|
155 | |
---|
156 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !< index for topography top at cell-center |
---|
157 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_tmp !< dummy to calculate topography indices on u- and v-grid |
---|
158 | |
---|
159 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: topo !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
160 | |
---|
161 | REAL(wp) :: dz_level_end !< distance between calculated height level for u/v-grid and user-specified end level for stretching |
---|
162 | REAL(wp) :: dz_stretched !< stretched vertical grid spacing |
---|
163 | |
---|
164 | REAL(wp), DIMENSION(:), ALLOCATABLE :: min_dz_stretch_level_end !< Array that contains all minimum heights where the stretching can end |
---|
165 | |
---|
166 | |
---|
167 | ! |
---|
168 | !-- Calculation of horizontal array bounds including ghost layers |
---|
169 | nxlg = nxl - nbgp |
---|
170 | nxrg = nxr + nbgp |
---|
171 | nysg = nys - nbgp |
---|
172 | nyng = nyn + nbgp |
---|
173 | |
---|
174 | ! |
---|
175 | !-- Allocate grid arrays |
---|
176 | ALLOCATE( x(0:nx), xu(0:nx) ) |
---|
177 | DO i = 0, nx |
---|
178 | xu(i) = i * dx |
---|
179 | x(i) = i * dx + 0.5_wp * dx |
---|
180 | ENDDO |
---|
181 | |
---|
182 | ALLOCATE( y(0:ny), yv(0:ny) ) |
---|
183 | DO j = 0, ny |
---|
184 | yv(j) = j * dy |
---|
185 | y(j) = j * dy + 0.5_wp * dy |
---|
186 | ENDDO |
---|
187 | |
---|
188 | ! |
---|
189 | !-- Allocate grid arrays |
---|
190 | ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & |
---|
191 | dzw(1:nzt+1), zu(nzb:nzt+1), zw(nzb:nzt+1) ) |
---|
192 | |
---|
193 | ! |
---|
194 | !-- Compute height of u-levels from constant grid length and dz stretch factors |
---|
195 | IF ( dz(1) == -1.0_wp ) THEN |
---|
196 | message_string = 'missing dz' |
---|
197 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
198 | ELSEIF ( dz(1) <= 0.0_wp ) THEN |
---|
199 | WRITE( message_string, * ) 'dz=',dz(1),' <= 0.0' |
---|
200 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
201 | ENDIF |
---|
202 | |
---|
203 | ! |
---|
204 | !-- Initialize dz_stretch_level_start with the value of dz_stretch_level |
---|
205 | !-- if it was set by the user |
---|
206 | IF ( dz_stretch_level /= -9999999.9_wp ) THEN |
---|
207 | dz_stretch_level_start(1) = dz_stretch_level |
---|
208 | ENDIF |
---|
209 | |
---|
210 | ! |
---|
211 | !-- Determine number of dz values and stretching levels specified by the |
---|
212 | !-- user to allow right controlling of the stretching mechanism and to |
---|
213 | !-- perform error checks. The additional requirement that dz /= dz_max |
---|
214 | !-- for counting number of user-specified dz values is necessary. Otherwise |
---|
215 | !-- restarts would abort if the old stretching mechanism with dz_stretch_level |
---|
216 | !-- is used (Attention: The user is not allowed to specify a dz value equal |
---|
217 | !-- to the default of dz_max = 999.0). |
---|
218 | number_dz = COUNT( dz /= -1.0_wp .AND. dz /= dz_max) |
---|
219 | number_stretch_level_start = COUNT( dz_stretch_level_start /= & |
---|
220 | -9999999.9_wp ) |
---|
221 | number_stretch_level_end = COUNT( dz_stretch_level_end /= & |
---|
222 | 9999999.9_wp ) |
---|
223 | |
---|
224 | ! |
---|
225 | !-- The number of specified end levels +1 has to be the same than the number |
---|
226 | !-- of specified dz values |
---|
227 | IF ( number_dz /= number_stretch_level_end + 1 ) THEN |
---|
228 | WRITE( message_string, * ) 'The number of values for dz = ', & |
---|
229 | number_dz, 'has to be the same than& ', & |
---|
230 | 'the number of values for ', & |
---|
231 | 'dz_stretch_level_end + 1 = ', & |
---|
232 | number_stretch_level_end+1 |
---|
233 | CALL message( 'init_grid', 'PA0156', 1, 2, 0, 6, 0 ) |
---|
234 | ENDIF |
---|
235 | |
---|
236 | ! |
---|
237 | !-- The number of specified start levels has to be the same or one less than |
---|
238 | !-- the number of specified dz values |
---|
239 | IF ( number_dz /= number_stretch_level_start + 1 .AND. & |
---|
240 | number_dz /= number_stretch_level_start ) THEN |
---|
241 | WRITE( message_string, * ) 'The number of values for dz = ', & |
---|
242 | number_dz, 'has to be the same or one ', & |
---|
243 | 'more than& the number of values for ', & |
---|
244 | 'dz_stretch_level_start = ', & |
---|
245 | number_stretch_level_start |
---|
246 | CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 ) |
---|
247 | ENDIF |
---|
248 | |
---|
249 | !-- The number of specified start levels has to be the same or one more than |
---|
250 | !-- the number of specified end levels |
---|
251 | IF ( number_stretch_level_start /= number_stretch_level_end + 1 .AND. & |
---|
252 | number_stretch_level_start /= number_stretch_level_end ) THEN |
---|
253 | WRITE( message_string, * ) 'The number of values for ', & |
---|
254 | 'dz_stretch_level_start = ', & |
---|
255 | dz_stretch_level_start, 'has to be the ',& |
---|
256 | 'same or one more than& the number of ', & |
---|
257 | 'values for dz_stretch_level_end = ', & |
---|
258 | number_stretch_level_end |
---|
259 | CALL message( 'init_grid', 'PA0216', 1, 2, 0, 6, 0 ) |
---|
260 | ENDIF |
---|
261 | |
---|
262 | ! |
---|
263 | !-- Initialize dz for the free atmosphere with the value of dz_max |
---|
264 | IF ( dz(number_stretch_level_start+1) == -1.0_wp .AND. & |
---|
265 | number_stretch_level_start /= 0 ) THEN |
---|
266 | dz(number_stretch_level_start+1) = dz_max |
---|
267 | ENDIF |
---|
268 | |
---|
269 | ! |
---|
270 | !-- Initialize the stretching factor if (infinitely) stretching in the free |
---|
271 | !-- atmosphere is desired (dz_stretch_level_end was not specified for the |
---|
272 | !-- free atmosphere) |
---|
273 | IF ( number_stretch_level_start == number_stretch_level_end + 1 ) THEN |
---|
274 | dz_stretch_factor_array(number_stretch_level_start) = & |
---|
275 | dz_stretch_factor |
---|
276 | ENDIF |
---|
277 | |
---|
278 | ! |
---|
279 | !-- Allocation of arrays for stretching |
---|
280 | ALLOCATE( min_dz_stretch_level_end(number_stretch_level_start) ) |
---|
281 | |
---|
282 | ! |
---|
283 | !-- Define the vertical grid levels |
---|
284 | IF ( .NOT. ocean_mode ) THEN |
---|
285 | |
---|
286 | ! |
---|
287 | !-- The stretching region has to be large enough to allow for a smooth |
---|
288 | !-- transition between two different grid spacings |
---|
289 | DO n = 1, number_stretch_level_start |
---|
290 | min_dz_stretch_level_end(n) = dz_stretch_level_start(n) + & |
---|
291 | 4 * MAX( dz(n),dz(n+1) ) |
---|
292 | ENDDO |
---|
293 | |
---|
294 | IF ( ANY( min_dz_stretch_level_end(1:number_stretch_level_start) > & |
---|
295 | dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN |
---|
296 | message_string= 'Eeach dz_stretch_level_end has to be larger ' // & |
---|
297 | 'than its corresponding value for &' // & |
---|
298 | 'dz_stretch_level_start + 4*MAX(dz(n),dz(n+1)) '//& |
---|
299 | 'to allow for smooth grid stretching' |
---|
300 | CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 ) |
---|
301 | ENDIF |
---|
302 | |
---|
303 | ! |
---|
304 | !-- Stretching must not be applied within the prandtl_layer |
---|
305 | !-- (first two grid points). For the default case dz_stretch_level_start |
---|
306 | !-- is negative. Therefore the absolut value is checked here. |
---|
307 | IF ( ANY( ABS( dz_stretch_level_start ) < dz(1) * 1.5_wp ) ) THEN |
---|
308 | WRITE( message_string, * ) 'Eeach dz_stretch_level_start has to be ',& |
---|
309 | 'larger than ', dz(1) * 1.5 |
---|
310 | CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 ) |
---|
311 | ENDIF |
---|
312 | |
---|
313 | ! |
---|
314 | !-- The stretching has to start and end on a grid level. Therefore |
---|
315 | !-- user-specified values have to ''interpolate'' to the next lowest level |
---|
316 | IF ( number_stretch_level_start /= 0 ) THEN |
---|
317 | dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) - & |
---|
318 | dz(1)/2.0) / dz(1) ) & |
---|
319 | * dz(1) + dz(1)/2.0 |
---|
320 | ENDIF |
---|
321 | |
---|
322 | IF ( number_stretch_level_start > 1 ) THEN |
---|
323 | DO n = 2, number_stretch_level_start |
---|
324 | dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / & |
---|
325 | dz(n) ) * dz(n) |
---|
326 | ENDDO |
---|
327 | ENDIF |
---|
328 | |
---|
329 | IF ( number_stretch_level_end /= 0 ) THEN |
---|
330 | DO n = 1, number_stretch_level_end |
---|
331 | dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / & |
---|
332 | dz(n+1) ) * dz(n+1) |
---|
333 | ENDDO |
---|
334 | ENDIF |
---|
335 | |
---|
336 | ! |
---|
337 | !-- Determine stretching factor if necessary |
---|
338 | IF ( number_stretch_level_end >= 1 ) THEN |
---|
339 | CALL calculate_stretching_factor( number_stretch_level_end ) |
---|
340 | ENDIF |
---|
341 | |
---|
342 | ! |
---|
343 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
344 | !-- First compute the u- and v-levels. In case of dirichlet bc for u and v |
---|
345 | !-- the first u/v- and w-level (k=0) are defined at same height (z=0). |
---|
346 | !-- The second u-level (k=1) corresponds to the top of the |
---|
347 | !-- Prandtl-layer. |
---|
348 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN |
---|
349 | zu(0) = 0.0_wp |
---|
350 | ELSE |
---|
351 | zu(0) = - dz(1) * 0.5_wp |
---|
352 | ENDIF |
---|
353 | |
---|
354 | zu(1) = dz(1) * 0.5_wp |
---|
355 | |
---|
356 | ! |
---|
357 | !-- Determine u and v height levels considering the possibility of grid |
---|
358 | !-- stretching in several heights. |
---|
359 | n = 1 |
---|
360 | dz_stretch_level_start_index = nzt+1 |
---|
361 | dz_stretch_level_end_index = nzt+1 |
---|
362 | dz_stretched = dz(1) |
---|
363 | |
---|
364 | !-- The default value of dz_stretch_level_start is negative, thus the first |
---|
365 | !-- condition is always true. Hence, the second condition is necessary. |
---|
366 | DO k = 2, nzt+1 |
---|
367 | IF ( dz_stretch_level_start(n) <= zu(k-1) .AND. & |
---|
368 | dz_stretch_level_start(n) /= -9999999.9_wp ) THEN |
---|
369 | dz_stretched = dz_stretched * dz_stretch_factor_array(n) |
---|
370 | |
---|
371 | IF ( dz(n) > dz(n+1) ) THEN |
---|
372 | dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz |
---|
373 | ELSE |
---|
374 | dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz |
---|
375 | ENDIF |
---|
376 | |
---|
377 | IF ( dz_stretch_level_start_index(n) == nzt+1 ) & |
---|
378 | dz_stretch_level_start_index(n) = k-1 |
---|
379 | |
---|
380 | ENDIF |
---|
381 | |
---|
382 | zu(k) = zu(k-1) + dz_stretched |
---|
383 | |
---|
384 | ! |
---|
385 | !-- Make sure that the stretching ends exactly at dz_stretch_level_end |
---|
386 | dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) |
---|
387 | |
---|
388 | IF ( dz_level_end < dz(n+1)/3.0 ) THEN |
---|
389 | zu(k) = dz_stretch_level_end(n) |
---|
390 | dz_stretched = dz(n+1) |
---|
391 | dz_stretch_level_end_index(n) = k |
---|
392 | n = n + 1 |
---|
393 | ENDIF |
---|
394 | ENDDO |
---|
395 | |
---|
396 | ! |
---|
397 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
398 | !-- corresponding u-levels. In case of dirichlet bc for u and v at the |
---|
399 | !-- ground the first u- and w-level (k=0) are defined at same height (z=0). |
---|
400 | !-- The top w-level is extrapolated linearly. |
---|
401 | zw(0) = 0.0_wp |
---|
402 | DO k = 1, nzt |
---|
403 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
404 | ENDDO |
---|
405 | zw(nzt+1) = zw(nzt) + 2.0_wp * ( zu(nzt+1) - zw(nzt) ) |
---|
406 | |
---|
407 | ELSE |
---|
408 | |
---|
409 | ! |
---|
410 | !-- The stretching region has to be large enough to allow for a smooth |
---|
411 | !-- transition between two different grid spacings |
---|
412 | DO n = 1, number_stretch_level_start |
---|
413 | min_dz_stretch_level_end(n) = dz_stretch_level_start(n) - & |
---|
414 | 4 * MAX( dz(n),dz(n+1) ) |
---|
415 | ENDDO |
---|
416 | |
---|
417 | IF ( ANY( min_dz_stretch_level_end (1:number_stretch_level_start) < & |
---|
418 | dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN |
---|
419 | message_string= 'Eeach dz_stretch_level_end has to be less ' // & |
---|
420 | 'than its corresponding value for &' // & |
---|
421 | 'dz_stretch_level_start - 4*MAX(dz(n),dz(n+1)) '//& |
---|
422 | 'to allow for smooth grid stretching' |
---|
423 | CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 ) |
---|
424 | ENDIF |
---|
425 | |
---|
426 | ! |
---|
427 | !-- Stretching must not be applied close to the surface (last two grid |
---|
428 | !-- points). For the default case dz_stretch_level_start is negative. |
---|
429 | IF ( ANY( dz_stretch_level_start > - dz(1) * 1.5_wp ) ) THEN |
---|
430 | WRITE( message_string, * ) 'Eeach dz_stretch_level_start has to be ',& |
---|
431 | 'less than ', dz(1) * 1.5 |
---|
432 | CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 ) |
---|
433 | ENDIF |
---|
434 | |
---|
435 | ! |
---|
436 | !-- The stretching has to start and end on a grid level. Therefore |
---|
437 | !-- user-specified values have to ''interpolate'' to the next highest level |
---|
438 | IF ( number_stretch_level_start /= 0 ) THEN |
---|
439 | dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) + & |
---|
440 | dz(1)/2.0) / dz(1) ) & |
---|
441 | * dz(1) - dz(1)/2.0 |
---|
442 | ENDIF |
---|
443 | |
---|
444 | IF ( number_stretch_level_start > 1 ) THEN |
---|
445 | DO n = 2, number_stretch_level_start |
---|
446 | dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / & |
---|
447 | dz(n) ) * dz(n) |
---|
448 | ENDDO |
---|
449 | ENDIF |
---|
450 | |
---|
451 | IF ( number_stretch_level_end /= 0 ) THEN |
---|
452 | DO n = 1, number_stretch_level_end |
---|
453 | dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / & |
---|
454 | dz(n+1) ) * dz(n+1) |
---|
455 | ENDDO |
---|
456 | ENDIF |
---|
457 | |
---|
458 | ! |
---|
459 | !-- Determine stretching factor if necessary |
---|
460 | IF ( number_stretch_level_end >= 1 ) THEN |
---|
461 | CALL calculate_stretching_factor( number_stretch_level_end ) |
---|
462 | ENDIF |
---|
463 | |
---|
464 | ! |
---|
465 | !-- Grid for ocean with free water surface is at k=nzt (w-grid). |
---|
466 | !-- In case of neumann bc at the ground the first first u-level (k=0) lies |
---|
467 | !-- below the first w-level (k=0). In case of dirichlet bc the first u- and |
---|
468 | !-- w-level are defined at same height, but staggered from the second level. |
---|
469 | !-- The second u-level (k=1) corresponds to the top of the Prandtl-layer. |
---|
470 | !-- z values are negative starting from z=0 (surface) |
---|
471 | zu(nzt+1) = dz(1) * 0.5_wp |
---|
472 | zu(nzt) = - dz(1) * 0.5_wp |
---|
473 | |
---|
474 | ! |
---|
475 | !-- Determine u and v height levels considering the possibility of grid |
---|
476 | !-- stretching in several heights. |
---|
477 | n = 1 |
---|
478 | dz_stretch_level_start_index = 0 |
---|
479 | dz_stretch_level_end_index = 0 |
---|
480 | dz_stretched = dz(1) |
---|
481 | |
---|
482 | DO k = nzt-1, 0, -1 |
---|
483 | |
---|
484 | IF ( dz_stretch_level_start(n) >= zu(k+1) ) THEN |
---|
485 | dz_stretched = dz_stretched * dz_stretch_factor_array(n) |
---|
486 | |
---|
487 | IF ( dz(n) > dz(n+1) ) THEN |
---|
488 | dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz |
---|
489 | ELSE |
---|
490 | dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz |
---|
491 | ENDIF |
---|
492 | |
---|
493 | IF ( dz_stretch_level_start_index(n) == 0 ) & |
---|
494 | dz_stretch_level_start_index(n) = k+1 |
---|
495 | |
---|
496 | ENDIF |
---|
497 | |
---|
498 | zu(k) = zu(k+1) - dz_stretched |
---|
499 | |
---|
500 | ! |
---|
501 | !-- Make sure that the stretching ends exactly at dz_stretch_level_end |
---|
502 | dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) |
---|
503 | |
---|
504 | IF ( dz_level_end < dz(n+1)/3.0 ) THEN |
---|
505 | zu(k) = dz_stretch_level_end(n) |
---|
506 | dz_stretched = dz(n+1) |
---|
507 | dz_stretch_level_end_index(n) = k |
---|
508 | n = n + 1 |
---|
509 | ENDIF |
---|
510 | ENDDO |
---|
511 | |
---|
512 | ! |
---|
513 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
514 | !-- corresponding u-levels, except in case of dirichlet bc for u and v |
---|
515 | !-- at the ground. In this case the first u- and w-level are defined at |
---|
516 | !-- same height. The top w-level (nzt+1) is not used but set for |
---|
517 | !-- consistency, since w and all scalar variables are defined up tp nzt+1. |
---|
518 | zw(nzt+1) = dz(1) |
---|
519 | zw(nzt) = 0.0_wp |
---|
520 | DO k = 0, nzt |
---|
521 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
522 | ENDDO |
---|
523 | |
---|
524 | ! |
---|
525 | !-- In case of dirichlet bc for u and v the first u- and w-level are defined |
---|
526 | !-- at same height. |
---|
527 | IF ( ibc_uv_b == 0 ) THEN |
---|
528 | zu(0) = zw(0) |
---|
529 | ENDIF |
---|
530 | |
---|
531 | ENDIF |
---|
532 | |
---|
533 | ! |
---|
534 | !-- Compute grid lengths. |
---|
535 | DO k = 1, nzt+1 |
---|
536 | dzu(k) = zu(k) - zu(k-1) |
---|
537 | ddzu(k) = 1.0_wp / dzu(k) |
---|
538 | dzw(k) = zw(k) - zw(k-1) |
---|
539 | ddzw(k) = 1.0_wp / dzw(k) |
---|
540 | ENDDO |
---|
541 | |
---|
542 | DO k = 1, nzt |
---|
543 | dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) ) |
---|
544 | ENDDO |
---|
545 | |
---|
546 | ! |
---|
547 | !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid |
---|
548 | !-- everywhere. For the actual grid, the grid spacing at the lowest level |
---|
549 | !-- is only dz/2, but should be dz. Therefore, an additional array |
---|
550 | !-- containing with appropriate grid information is created for these |
---|
551 | !-- solvers. |
---|
552 | IF ( psolver(1:9) /= 'multigrid' ) THEN |
---|
553 | ALLOCATE( ddzu_pres(1:nzt+1) ) |
---|
554 | ddzu_pres = ddzu |
---|
555 | ddzu_pres(1) = ddzu_pres(2) ! change for lowest level |
---|
556 | ENDIF |
---|
557 | |
---|
558 | ! |
---|
559 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
560 | ddx = 1.0_wp / dx |
---|
561 | ddy = 1.0_wp / dy |
---|
562 | dx2 = dx * dx |
---|
563 | dy2 = dy * dy |
---|
564 | ddx2 = 1.0_wp / dx2 |
---|
565 | ddy2 = 1.0_wp / dy2 |
---|
566 | |
---|
567 | ! |
---|
568 | !-- Allocate 3D array to set topography |
---|
569 | ALLOCATE( topo(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
570 | topo = 0 |
---|
571 | ! |
---|
572 | !-- Initialize topography by generic topography or read from topography from file. |
---|
573 | CALL init_topo( topo ) |
---|
574 | ! |
---|
575 | !-- Set flags to mask topography on the grid. |
---|
576 | CALL set_topo_flags( topo ) |
---|
577 | ! |
---|
578 | !-- Calculate wall flag arrays for the multigrid method. |
---|
579 | !-- Please note, wall flags are only applied in the non-optimized version. |
---|
580 | IF ( psolver == 'multigrid_noopt' ) CALL poismg_noopt_init |
---|
581 | |
---|
582 | ! |
---|
583 | !-- Init flags for ws-scheme to degrade order of the numerics near walls, i.e. |
---|
584 | !-- to decrease the numerical stencil appropriately. The order of the scheme |
---|
585 | !-- is degraded near solid walls as well as near non-cyclic inflow and outflow |
---|
586 | !-- boundaries. Do this separately for momentum and scalars. |
---|
587 | IF ( momentum_advec == 'ws-scheme' ) THEN |
---|
588 | ALLOCATE( advc_flags_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
589 | CALL ws_init_flags_momentum |
---|
590 | ENDIF |
---|
591 | IF ( scalar_advec == 'ws-scheme' ) THEN |
---|
592 | ALLOCATE( advc_flags_s(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
593 | advc_flags_s = 0 |
---|
594 | |
---|
595 | CALL ws_init_flags_scalar( bc_dirichlet_l .OR. bc_radiation_l, & |
---|
596 | bc_dirichlet_n .OR. bc_radiation_n, & |
---|
597 | bc_dirichlet_r .OR. bc_radiation_r, & |
---|
598 | bc_dirichlet_s .OR. bc_radiation_s, & |
---|
599 | advc_flags_s ) |
---|
600 | ENDIF |
---|
601 | |
---|
602 | ! |
---|
603 | !-- Determine the maximum level of topography. It is used for |
---|
604 | !-- steering the degradation of order of the applied advection scheme, |
---|
605 | !-- as well in the lpm. |
---|
606 | k_top = 0 |
---|
607 | DO i = nxl, nxr |
---|
608 | DO j = nys, nyn |
---|
609 | DO k = nzb, nzt + 1 |
---|
610 | k_top = MAX( k_top, MERGE( k, 0, .NOT. BTEST( topo(k,j,i), 0 ) ) ) |
---|
611 | ENDDO |
---|
612 | ENDDO |
---|
613 | ENDDO |
---|
614 | #if defined( __parallel ) |
---|
615 | CALL MPI_ALLREDUCE( k_top + 1, nzb_max, 1, MPI_INTEGER, & !is +1 really necessary here? |
---|
616 | MPI_MAX, comm2d, ierr ) |
---|
617 | #else |
---|
618 | nzb_max = k_top + 1 |
---|
619 | #endif |
---|
620 | ! |
---|
621 | !-- If topography extents up to the model top, limit nzb_max to nzt. |
---|
622 | nzb_max = MIN( nzb_max, nzt ) |
---|
623 | ! |
---|
624 | !-- Determine minimum index of topography. Usually, this will be nzb. In case |
---|
625 | !-- there is elevated topography, however, the lowest topography will be higher. |
---|
626 | !-- This index is e.g. used to calculate mean first-grid point atmosphere |
---|
627 | !-- temperature, surface pressure and density, etc. . |
---|
628 | topo_min_level = 0 |
---|
629 | #if defined( __parallel ) |
---|
630 | CALL MPI_ALLREDUCE( MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), & |
---|
631 | topo_min_level, 1, MPI_INTEGER, MPI_MIN, comm2d, ierr ) |
---|
632 | #else |
---|
633 | topo_min_level = MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ) |
---|
634 | #endif |
---|
635 | ! |
---|
636 | !-- Initialize boundary conditions via surface type |
---|
637 | CALL init_bc |
---|
638 | |
---|
639 | ! |
---|
640 | !-- Allocate and set topography height arrays required for data output |
---|
641 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
642 | ! |
---|
643 | !-- Allocate and set the arrays containing the topography height |
---|
644 | IF ( nxr == nx .AND. nyn /= ny ) THEN |
---|
645 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn), & |
---|
646 | zw_w_inner(nxl:nxr+1,nys:nyn) ) |
---|
647 | ELSEIF ( nxr /= nx .AND. nyn == ny ) THEN |
---|
648 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn+1), & |
---|
649 | zw_w_inner(nxl:nxr,nys:nyn+1) ) |
---|
650 | ELSEIF ( nxr == nx .AND. nyn == ny ) THEN |
---|
651 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn+1), & |
---|
652 | zw_w_inner(nxl:nxr+1,nys:nyn+1) ) |
---|
653 | ELSE |
---|
654 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn), & |
---|
655 | zw_w_inner(nxl:nxr,nys:nyn) ) |
---|
656 | ENDIF |
---|
657 | |
---|
658 | zu_s_inner = 0.0_wp |
---|
659 | zw_w_inner = 0.0_wp |
---|
660 | ! |
---|
661 | !-- Determine local topography height on scalar and w-grid. Note, setting |
---|
662 | !-- lateral boundary values is not necessary, realized via wall_flags_0 |
---|
663 | !-- array. Further, please note that loop bounds are different from |
---|
664 | !-- nxl to nxr and nys to nyn on south and right model boundary, hence, |
---|
665 | !-- use intrinsic lbound and ubound functions to infer array bounds. |
---|
666 | DO i = LBOUND(zu_s_inner, 1), UBOUND(zu_s_inner, 1) |
---|
667 | DO j = LBOUND(zu_s_inner, 2), UBOUND(zu_s_inner, 2) |
---|
668 | ! |
---|
669 | !-- Topography height on scalar grid. Therefore, determine index of |
---|
670 | !-- upward-facing surface element on scalar grid. |
---|
671 | zu_s_inner(i,j) = zu(topo_top_ind(j,i,0)) |
---|
672 | ! |
---|
673 | !-- Topography height on w grid. Therefore, determine index of |
---|
674 | !-- upward-facing surface element on w grid. |
---|
675 | zw_w_inner(i,j) = zw(topo_top_ind(j,i,3)) |
---|
676 | ENDDO |
---|
677 | ENDDO |
---|
678 | ENDIF |
---|
679 | |
---|
680 | ! |
---|
681 | !-- In the following, calculate 2D index arrays. Note, these will be removed |
---|
682 | !-- soon. |
---|
683 | !-- Allocate outer and inner index arrays for topography and set |
---|
684 | !-- defaults. |
---|
685 | ALLOCATE( nzb_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
686 | nzb_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
687 | nzb_u_inner(nysg:nyng,nxlg:nxrg), & |
---|
688 | nzb_u_outer(nysg:nyng,nxlg:nxrg), & |
---|
689 | nzb_v_inner(nysg:nyng,nxlg:nxrg), & |
---|
690 | nzb_v_outer(nysg:nyng,nxlg:nxrg), & |
---|
691 | nzb_w_inner(nysg:nyng,nxlg:nxrg), & |
---|
692 | nzb_w_outer(nysg:nyng,nxlg:nxrg), & |
---|
693 | nzb_diff_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
694 | nzb_diff_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
695 | nzb_local(nysg:nyng,nxlg:nxrg), & |
---|
696 | nzb_tmp(nysg:nyng,nxlg:nxrg) ) |
---|
697 | ! |
---|
698 | !-- Initialize 2D-index arrays. Note, these will be removed soon! |
---|
699 | nzb_local(nys:nyn,nxl:nxr) = topo_top_ind(nys:nyn,nxl:nxr,0) |
---|
700 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
701 | ! |
---|
702 | !-- Check topography for consistency with model domain. Therefore, use |
---|
703 | !-- maximum and minium topography-top indices. Note, minimum topography top |
---|
704 | !-- index is already calculated. |
---|
705 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
706 | #if defined( __parallel ) |
---|
707 | CALL MPI_ALLREDUCE( MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), & |
---|
708 | nzb_local_max, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr ) |
---|
709 | #else |
---|
710 | nzb_local_max = MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ) |
---|
711 | #endif |
---|
712 | nzb_local_min = topo_min_level |
---|
713 | ! |
---|
714 | !-- Consistency checks |
---|
715 | IF ( nzb_local_min < 0 .OR. nzb_local_max > nz + 1 ) THEN |
---|
716 | WRITE( message_string, * ) 'nzb_local values are outside the', & |
---|
717 | ' model domain', & |
---|
718 | '&MINVAL( nzb_local ) = ', nzb_local_min, & |
---|
719 | '&MAXVAL( nzb_local ) = ', nzb_local_max |
---|
720 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
721 | ENDIF |
---|
722 | ENDIF |
---|
723 | |
---|
724 | nzb_s_inner = nzb; nzb_s_outer = nzb |
---|
725 | nzb_u_inner = nzb; nzb_u_outer = nzb |
---|
726 | nzb_v_inner = nzb; nzb_v_outer = nzb |
---|
727 | nzb_w_inner = nzb; nzb_w_outer = nzb |
---|
728 | |
---|
729 | ! |
---|
730 | !-- Define vertical gridpoint from (or to) which on the usual finite difference |
---|
731 | !-- form (which does not use surface fluxes) is applied |
---|
732 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
733 | nzb_diff = nzb + 2 |
---|
734 | ELSE |
---|
735 | nzb_diff = nzb + 1 |
---|
736 | ENDIF |
---|
737 | |
---|
738 | nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff |
---|
739 | ! |
---|
740 | !-- Set Neumann conditions for topography. Will be removed soon. |
---|
741 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
742 | IF ( nys == 0 ) THEN |
---|
743 | DO i = 1, nbgp |
---|
744 | nzb_local(nys-i,:) = nzb_local(nys,:) |
---|
745 | ENDDO |
---|
746 | ELSEIF ( nyn == ny ) THEN |
---|
747 | DO i = 1, nbgp |
---|
748 | nzb_local(ny+i,:) = nzb_local(ny,:) |
---|
749 | ENDDO |
---|
750 | ENDIF |
---|
751 | ENDIF |
---|
752 | |
---|
753 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
754 | IF ( nxl == 0 ) THEN |
---|
755 | DO i = 1, nbgp |
---|
756 | nzb_local(:,nxl-i) = nzb_local(:,nxl) |
---|
757 | ENDDO |
---|
758 | ELSEIF ( nxr == nx ) THEN |
---|
759 | DO i = 1, nbgp |
---|
760 | nzb_local(:,nx+i) = nzb_local(:,nx) |
---|
761 | ENDDO |
---|
762 | ENDIF |
---|
763 | ENDIF |
---|
764 | ! |
---|
765 | !-- Initialization of 2D index arrays, will be removed soon! |
---|
766 | !-- Initialize nzb_s_inner and nzb_w_inner |
---|
767 | nzb_s_inner = nzb_local |
---|
768 | nzb_w_inner = nzb_local |
---|
769 | |
---|
770 | ! |
---|
771 | !-- Initialize remaining index arrays: |
---|
772 | !-- first pre-initialize them with nzb_s_inner... |
---|
773 | nzb_u_inner = nzb_s_inner |
---|
774 | nzb_u_outer = nzb_s_inner |
---|
775 | nzb_v_inner = nzb_s_inner |
---|
776 | nzb_v_outer = nzb_s_inner |
---|
777 | nzb_w_outer = nzb_s_inner |
---|
778 | nzb_s_outer = nzb_s_inner |
---|
779 | |
---|
780 | ! |
---|
781 | !-- nzb_s_outer: |
---|
782 | !-- extend nzb_local east-/westwards first, then north-/southwards |
---|
783 | nzb_tmp = nzb_local |
---|
784 | DO j = nys, nyn |
---|
785 | DO i = nxl, nxr |
---|
786 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & |
---|
787 | nzb_local(j,i+1) ) |
---|
788 | ENDDO |
---|
789 | ENDDO |
---|
790 | |
---|
791 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
792 | |
---|
793 | DO i = nxl, nxr |
---|
794 | DO j = nys, nyn |
---|
795 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
796 | nzb_tmp(j+1,i) ) |
---|
797 | ENDDO |
---|
798 | ! |
---|
799 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
800 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
801 | IF ( nys == 0 ) THEN |
---|
802 | j = -1 |
---|
803 | nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
804 | ENDIF |
---|
805 | IF ( nyn == ny ) THEN |
---|
806 | j = ny + 1 |
---|
807 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
808 | ENDIF |
---|
809 | ENDDO |
---|
810 | ! |
---|
811 | !-- nzb_w_outer: |
---|
812 | !-- identical to nzb_s_outer |
---|
813 | nzb_w_outer = nzb_s_outer |
---|
814 | ! |
---|
815 | !-- nzb_u_inner: |
---|
816 | !-- extend nzb_local rightwards only |
---|
817 | nzb_tmp = nzb_local |
---|
818 | DO j = nys, nyn |
---|
819 | DO i = nxl, nxr |
---|
820 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) |
---|
821 | ENDDO |
---|
822 | ENDDO |
---|
823 | |
---|
824 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
825 | |
---|
826 | nzb_u_inner = nzb_tmp |
---|
827 | ! |
---|
828 | !-- nzb_u_outer: |
---|
829 | !-- extend current nzb_tmp (nzb_u_inner) north-/southwards |
---|
830 | DO i = nxl, nxr |
---|
831 | DO j = nys, nyn |
---|
832 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
833 | nzb_tmp(j+1,i) ) |
---|
834 | ENDDO |
---|
835 | ! |
---|
836 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
837 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
838 | IF ( nys == 0 ) THEN |
---|
839 | j = -1 |
---|
840 | nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
841 | ENDIF |
---|
842 | IF ( nyn == ny ) THEN |
---|
843 | j = ny + 1 |
---|
844 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
845 | ENDIF |
---|
846 | ENDDO |
---|
847 | |
---|
848 | ! |
---|
849 | !-- nzb_v_inner: |
---|
850 | !-- extend nzb_local northwards only |
---|
851 | nzb_tmp = nzb_local |
---|
852 | DO i = nxl, nxr |
---|
853 | DO j = nys, nyn |
---|
854 | nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) |
---|
855 | ENDDO |
---|
856 | ENDDO |
---|
857 | |
---|
858 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
859 | nzb_v_inner = nzb_tmp |
---|
860 | |
---|
861 | ! |
---|
862 | !-- nzb_v_outer: |
---|
863 | !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards |
---|
864 | DO j = nys, nyn |
---|
865 | DO i = nxl, nxr |
---|
866 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & |
---|
867 | nzb_tmp(j,i+1) ) |
---|
868 | ENDDO |
---|
869 | ! |
---|
870 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
871 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
872 | IF ( nxl == 0 ) THEN |
---|
873 | i = -1 |
---|
874 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) |
---|
875 | ENDIF |
---|
876 | IF ( nxr == nx ) THEN |
---|
877 | i = nx + 1 |
---|
878 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) |
---|
879 | ENDIF |
---|
880 | ENDDO |
---|
881 | |
---|
882 | ! |
---|
883 | !-- Exchange of lateral boundary values (parallel computers) and cyclic |
---|
884 | !-- boundary conditions, if applicable. |
---|
885 | !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local |
---|
886 | !-- they do not require exchange and are not included here. |
---|
887 | CALL exchange_horiz_2d_int( nzb_u_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
888 | CALL exchange_horiz_2d_int( nzb_u_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
889 | CALL exchange_horiz_2d_int( nzb_v_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
890 | CALL exchange_horiz_2d_int( nzb_v_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
891 | CALL exchange_horiz_2d_int( nzb_w_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
892 | CALL exchange_horiz_2d_int( nzb_s_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
893 | |
---|
894 | ! |
---|
895 | !-- Set the individual index arrays which define the k index from which on |
---|
896 | !-- the usual finite difference form (which does not use surface fluxes) is |
---|
897 | !-- applied |
---|
898 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
899 | nzb_diff_s_inner = nzb_s_inner + 2 |
---|
900 | nzb_diff_s_outer = nzb_s_outer + 2 |
---|
901 | ELSE |
---|
902 | nzb_diff_s_inner = nzb_s_inner + 1 |
---|
903 | nzb_diff_s_outer = nzb_s_outer + 1 |
---|
904 | ENDIF |
---|
905 | ! |
---|
906 | !-- Vertical nesting: communicate vertical grid level arrays between fine and |
---|
907 | !-- coarse grid |
---|
908 | IF ( vnested ) CALL vnest_init_grid |
---|
909 | |
---|
910 | END SUBROUTINE init_grid |
---|
911 | |
---|
912 | |
---|
913 | ! Description: |
---|
914 | ! -----------------------------------------------------------------------------! |
---|
915 | !> Calculation of the stretching factor through an iterative method. Ideas were |
---|
916 | !> taken from the paper "Regional stretched grid generation and its application |
---|
917 | !> to the NCAR RegCM (1999)". Normally, no analytic solution exists because the |
---|
918 | !> system of equations has two variables (r,l) but four requirements |
---|
919 | !> (l=integer, r=[0,88;1,2], Eq(6), Eq(5) starting from index j=1) which |
---|
920 | !> results into an overdetermined system. |
---|
921 | !------------------------------------------------------------------------------! |
---|
922 | SUBROUTINE calculate_stretching_factor( number_end ) |
---|
923 | |
---|
924 | USE control_parameters, & |
---|
925 | ONLY: dz, dz_stretch_factor_array, & |
---|
926 | dz_stretch_level_end, dz_stretch_level_start, message_string |
---|
927 | |
---|
928 | USE kinds |
---|
929 | |
---|
930 | IMPLICIT NONE |
---|
931 | |
---|
932 | INTEGER(iwp) :: iterations !< number of iterations until stretch_factor_lower/upper_limit is reached |
---|
933 | INTEGER(iwp) :: l_rounded !< after l_rounded grid levels dz(n) is strechted to dz(n+1) with stretch_factor_2 |
---|
934 | INTEGER(iwp) :: n !< loop variable for stretching |
---|
935 | |
---|
936 | INTEGER(iwp), INTENT(IN) :: number_end !< number of user-specified end levels for stretching |
---|
937 | |
---|
938 | REAL(wp) :: delta_l !< absolute difference between l and l_rounded |
---|
939 | REAL(wp) :: delta_stretch_factor !< absolute difference between stretch_factor_1 and stretch_factor_2 |
---|
940 | REAL(wp) :: delta_total_new !< sum of delta_l and delta_stretch_factor for the next iteration (should be as small as possible) |
---|
941 | REAL(wp) :: delta_total_old !< sum of delta_l and delta_stretch_factor for the last iteration |
---|
942 | REAL(wp) :: distance !< distance between dz_stretch_level_start and dz_stretch_level_end (stretching region) |
---|
943 | REAL(wp) :: l !< value that fulfil Eq. (5) in the paper mentioned above together with stretch_factor_1 exactly |
---|
944 | REAL(wp) :: numerator !< numerator of the quotient |
---|
945 | REAL(wp) :: stretch_factor_1 !< stretching factor that fulfil Eq. (5) togehter with l exactly |
---|
946 | REAL(wp) :: stretch_factor_2 !< stretching factor that fulfil Eq. (6) togehter with l_rounded exactly |
---|
947 | |
---|
948 | REAL(wp) :: dz_stretch_factor_array_2(9) = 1.08_wp !< Array that contains all stretch_factor_2 that belongs to stretch_factor_1 |
---|
949 | |
---|
950 | REAL(wp), PARAMETER :: stretch_factor_interval = 1.0E-06 !< interval for sampling possible stretching factors |
---|
951 | REAL(wp), PARAMETER :: stretch_factor_lower_limit = 0.88 !< lowest possible stretching factor |
---|
952 | REAL(wp), PARAMETER :: stretch_factor_upper_limit = 1.12 !< highest possible stretching factor |
---|
953 | |
---|
954 | |
---|
955 | l = 0 |
---|
956 | DO n = 1, number_end |
---|
957 | |
---|
958 | iterations = 1 |
---|
959 | stretch_factor_1 = 1.0 |
---|
960 | stretch_factor_2 = 1.0 |
---|
961 | delta_total_old = 1.0 |
---|
962 | |
---|
963 | IF ( dz(n) > dz(n+1) ) THEN |
---|
964 | DO WHILE ( stretch_factor_1 >= stretch_factor_lower_limit ) |
---|
965 | |
---|
966 | stretch_factor_1 = 1.0 - iterations * stretch_factor_interval |
---|
967 | distance = ABS( dz_stretch_level_end(n) - & |
---|
968 | dz_stretch_level_start(n) ) |
---|
969 | numerator = distance*stretch_factor_1/dz(n) + & |
---|
970 | stretch_factor_1 - distance/dz(n) |
---|
971 | |
---|
972 | IF ( numerator > 0.0 ) THEN |
---|
973 | l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0 |
---|
974 | l_rounded = NINT( l ) |
---|
975 | delta_l = ABS( l_rounded - l ) / l |
---|
976 | ENDIF |
---|
977 | |
---|
978 | stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) ) |
---|
979 | |
---|
980 | delta_stretch_factor = ABS( stretch_factor_1 - & |
---|
981 | stretch_factor_2 ) / & |
---|
982 | stretch_factor_2 |
---|
983 | |
---|
984 | delta_total_new = delta_l + delta_stretch_factor |
---|
985 | |
---|
986 | ! |
---|
987 | !-- stretch_factor_1 is taken to guarantee that the stretching |
---|
988 | !-- procedure ends as close as possible to dz_stretch_level_end. |
---|
989 | !-- stretch_factor_2 would guarantee that the stretched dz(n) is |
---|
990 | !-- equal to dz(n+1) after l_rounded grid levels. |
---|
991 | IF (delta_total_new < delta_total_old) THEN |
---|
992 | dz_stretch_factor_array(n) = stretch_factor_1 |
---|
993 | dz_stretch_factor_array_2(n) = stretch_factor_2 |
---|
994 | delta_total_old = delta_total_new |
---|
995 | ENDIF |
---|
996 | |
---|
997 | iterations = iterations + 1 |
---|
998 | |
---|
999 | ENDDO |
---|
1000 | |
---|
1001 | ELSEIF ( dz(n) < dz(n+1) ) THEN |
---|
1002 | DO WHILE ( stretch_factor_1 <= stretch_factor_upper_limit ) |
---|
1003 | |
---|
1004 | stretch_factor_1 = 1.0 + iterations * stretch_factor_interval |
---|
1005 | distance = ABS( dz_stretch_level_end(n) - & |
---|
1006 | dz_stretch_level_start(n) ) |
---|
1007 | numerator = distance*stretch_factor_1/dz(n) + & |
---|
1008 | stretch_factor_1 - distance/dz(n) |
---|
1009 | |
---|
1010 | l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0 |
---|
1011 | l_rounded = NINT( l ) |
---|
1012 | delta_l = ABS( l_rounded - l ) / l |
---|
1013 | |
---|
1014 | stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) ) |
---|
1015 | |
---|
1016 | delta_stretch_factor = ABS( stretch_factor_1 - & |
---|
1017 | stretch_factor_2 ) / & |
---|
1018 | stretch_factor_2 |
---|
1019 | |
---|
1020 | delta_total_new = delta_l + delta_stretch_factor |
---|
1021 | |
---|
1022 | ! |
---|
1023 | !-- stretch_factor_1 is taken to guarantee that the stretching |
---|
1024 | !-- procedure ends as close as possible to dz_stretch_level_end. |
---|
1025 | !-- stretch_factor_2 would guarantee that the stretched dz(n) is |
---|
1026 | !-- equal to dz(n+1) after l_rounded grid levels. |
---|
1027 | IF (delta_total_new < delta_total_old) THEN |
---|
1028 | dz_stretch_factor_array(n) = stretch_factor_1 |
---|
1029 | dz_stretch_factor_array_2(n) = stretch_factor_2 |
---|
1030 | delta_total_old = delta_total_new |
---|
1031 | ENDIF |
---|
1032 | |
---|
1033 | iterations = iterations + 1 |
---|
1034 | ENDDO |
---|
1035 | |
---|
1036 | ELSE |
---|
1037 | message_string= 'Two adjacent values of dz must be different' |
---|
1038 | CALL message( 'init_grid', 'PA0228', 1, 2, 0, 6, 0 ) |
---|
1039 | |
---|
1040 | ENDIF |
---|
1041 | |
---|
1042 | ! |
---|
1043 | !-- Check if also the second stretching factor fits into the allowed |
---|
1044 | !-- interval. If not, print a warning for the user. |
---|
1045 | IF ( dz_stretch_factor_array_2(n) < stretch_factor_lower_limit .OR. & |
---|
1046 | dz_stretch_factor_array_2(n) > stretch_factor_upper_limit ) THEN |
---|
1047 | WRITE( message_string, * ) 'stretch_factor_2 = ', & |
---|
1048 | dz_stretch_factor_array_2(n), ' which is',& |
---|
1049 | ' responsible for exactly reaching& dz =',& |
---|
1050 | dz(n+1), 'after a specific amount of', & |
---|
1051 | ' grid levels& exceeds the upper', & |
---|
1052 | ' limit =', stretch_factor_upper_limit, & |
---|
1053 | ' &or lower limit = ', & |
---|
1054 | stretch_factor_lower_limit |
---|
1055 | CALL message( 'init_grid', 'PA0499', 0, 1, 0, 6, 0 ) |
---|
1056 | |
---|
1057 | ENDIF |
---|
1058 | ENDDO |
---|
1059 | |
---|
1060 | END SUBROUTINE calculate_stretching_factor |
---|
1061 | |
---|
1062 | |
---|
1063 | ! Description: |
---|
1064 | ! -----------------------------------------------------------------------------! |
---|
1065 | !> Set temporary topography flags and reference buildings on top of underlying |
---|
1066 | !> orography. |
---|
1067 | !------------------------------------------------------------------------------! |
---|
1068 | SUBROUTINE process_topography( topo_3d ) |
---|
1069 | |
---|
1070 | USE arrays_3d, & |
---|
1071 | ONLY: zu, zw |
---|
1072 | |
---|
1073 | USE control_parameters, & |
---|
1074 | ONLY: bc_lr_cyc, bc_ns_cyc, message_string, ocean_mode |
---|
1075 | |
---|
1076 | USE indices, & |
---|
1077 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, & |
---|
1078 | nzt |
---|
1079 | |
---|
1080 | USE netcdf_data_input_mod, & |
---|
1081 | ONLY: buildings_f, building_id_f, building_type_f, input_pids_static, & |
---|
1082 | terrain_height_f |
---|
1083 | |
---|
1084 | USE kinds |
---|
1085 | |
---|
1086 | USE pegrid |
---|
1087 | |
---|
1088 | IMPLICIT NONE |
---|
1089 | |
---|
1090 | INTEGER(iwp) :: i !< running index along x-direction |
---|
1091 | INTEGER(iwp) :: j !< running index along y-direction |
---|
1092 | INTEGER(iwp) :: k !< running index along z-direction with respect to numeric grid |
---|
1093 | INTEGER(iwp) :: k2 !< running index along z-direction with respect to netcdf grid |
---|
1094 | INTEGER(iwp) :: nr !< index variable indication maximum terrain height for respective building ID |
---|
1095 | INTEGER(iwp) :: num_build !< counter for number of buildings |
---|
1096 | INTEGER(iwp) :: topo_top_index !< orography top index, used to map 3D buildings onto terrain |
---|
1097 | |
---|
1098 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: displace_dum !< displacements of start addresses, used for MPI_ALLGATHERV |
---|
1099 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids !< building IDs on entire model domain |
---|
1100 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_final !< building IDs on entire model domain, multiple occurences are sorted out |
---|
1101 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_final_tmp !< temporary array used for resizing |
---|
1102 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_l !< building IDs on local subdomain |
---|
1103 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_l_tmp !< temporary array used to resize array of building IDs |
---|
1104 | |
---|
1105 | INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_buildings !< number of buildings with different ID on entire model domain |
---|
1106 | INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_buildings_l !< number of buildings with different ID on local subdomain |
---|
1107 | |
---|
1108 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo_3d !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
1109 | |
---|
1110 | REAL(wp) :: ocean_offset !< offset to consider inverse vertical coordinate at topography definition |
---|
1111 | REAL(wp) :: oro_min = 0.0_wp !< minimum terrain height in entire model domain, used to reference terrain to zero |
---|
1112 | REAL(wp), DIMENSION(:), ALLOCATABLE :: oro_max !< maximum terrain height occupied by an building with certain id |
---|
1113 | REAL(wp), DIMENSION(:), ALLOCATABLE :: oro_max_l !< maximum terrain height occupied by an building with certain id, on local subdomain |
---|
1114 | |
---|
1115 | ! |
---|
1116 | !-- Reference lowest terrain height to zero. In case the minimum terrain height |
---|
1117 | !-- is non-zero, all grid points of the lower vertical grid levels might be |
---|
1118 | !-- entirely below the surface, meaning a waste of computational resources. |
---|
1119 | !-- In order to avoid this, remove the lowest terrain height. Please note, |
---|
1120 | !-- in case of a nested run, the global minimum from all parent and childs |
---|
1121 | !-- need to be remove to avoid steep edges at the child-domain boundaries. |
---|
1122 | IF ( input_pids_static ) THEN |
---|
1123 | |
---|
1124 | #if defined( __parallel ) |
---|
1125 | CALL MPI_ALLREDUCE( MINVAL( terrain_height_f%var ), oro_min, 1, & |
---|
1126 | MPI_REAL, MPI_MIN, MPI_COMM_WORLD, ierr ) |
---|
1127 | #else |
---|
1128 | oro_min = MINVAL( terrain_height_f%var ) |
---|
1129 | #endif |
---|
1130 | terrain_height_f%var = terrain_height_f%var - oro_min |
---|
1131 | ! |
---|
1132 | !-- Give an informative message that terrain height is referenced to zero |
---|
1133 | IF ( oro_min > 0.0_wp ) THEN |
---|
1134 | WRITE( message_string, * ) 'Terrain height was internally shifted '//& |
---|
1135 | 'downwards by ', oro_min, 'meter(s) to save ' // & |
---|
1136 | 'computational resources.' |
---|
1137 | CALL message( 'init_grid', 'PA0505', 0, 0, 0, 6, 0 ) |
---|
1138 | ENDIF |
---|
1139 | ENDIF |
---|
1140 | |
---|
1141 | ! |
---|
1142 | !-- In the following, buildings and orography are further preprocessed |
---|
1143 | !-- before they are mapped on the LES grid. |
---|
1144 | !-- Buildings are mapped on top of the orography by maintaining the roof |
---|
1145 | !-- shape of the building. This can be achieved by referencing building on |
---|
1146 | !-- top of the maximum terrain height within the area occupied by the |
---|
1147 | !-- respective building. As buildings and terrain height are defined PE-wise, |
---|
1148 | !-- parallelization of this referencing is required (a building can be |
---|
1149 | !-- distributed between different PEs). |
---|
1150 | !-- In a first step, determine the number of buildings with different |
---|
1151 | !-- building id on each PE. In a next step, all building ids are gathered |
---|
1152 | !-- into one array which is present to all PEs. For each building ID, |
---|
1153 | !-- the maximum terrain height occupied by the respective building is |
---|
1154 | !-- computed and distributed to each PE. |
---|
1155 | !-- Finally, for each building id and its respective reference orography, |
---|
1156 | !-- builidings are mapped on top. |
---|
1157 | !-- |
---|
1158 | !-- First, pre-set topography flags, bit 1 indicates orography, bit 2 |
---|
1159 | !-- buildings |
---|
1160 | !-- classify the respective surfaces. |
---|
1161 | topo_3d = IBSET( topo_3d, 0 ) |
---|
1162 | topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 ) |
---|
1163 | ! |
---|
1164 | !-- In order to map topography on PALM grid also in case of ocean simulations, |
---|
1165 | !-- pre-calculate an offset value. |
---|
1166 | ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode ) |
---|
1167 | ! |
---|
1168 | !-- Reference buildings on top of orography. This is not necessary |
---|
1169 | !-- if topography is read from ASCII file as no distinction between buildings |
---|
1170 | !-- and terrain height can be made. Moreover, this is also not necessary if |
---|
1171 | !-- urban-surface and land-surface model are used at the same time. |
---|
1172 | IF ( input_pids_static ) THEN |
---|
1173 | |
---|
1174 | IF ( buildings_f%from_file ) THEN |
---|
1175 | num_buildings_l = 0 |
---|
1176 | num_buildings = 0 |
---|
1177 | ! |
---|
1178 | !-- Allocate at least one element for building ids and give it an inital |
---|
1179 | !-- negative value that will be overwritten later. This, however, is |
---|
1180 | !-- necessary in case there all IDs in the model domain are fill values. |
---|
1181 | ALLOCATE( build_ids_l(1) ) |
---|
1182 | build_ids_l = -1 |
---|
1183 | DO i = nxl, nxr |
---|
1184 | DO j = nys, nyn |
---|
1185 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
1186 | IF ( num_buildings_l(myid) > 0 ) THEN |
---|
1187 | IF ( ANY( building_id_f%var(j,i) == build_ids_l ) ) & |
---|
1188 | THEN |
---|
1189 | CYCLE |
---|
1190 | ELSE |
---|
1191 | num_buildings_l(myid) = num_buildings_l(myid) + 1 |
---|
1192 | ! |
---|
1193 | !-- Resize array with different local building ids |
---|
1194 | ALLOCATE( build_ids_l_tmp(1:SIZE(build_ids_l)) ) |
---|
1195 | build_ids_l_tmp = build_ids_l |
---|
1196 | DEALLOCATE( build_ids_l ) |
---|
1197 | ALLOCATE( build_ids_l(1:num_buildings_l(myid)) ) |
---|
1198 | build_ids_l(1:num_buildings_l(myid)-1) = & |
---|
1199 | build_ids_l_tmp(1:num_buildings_l(myid)-1) |
---|
1200 | build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i) |
---|
1201 | DEALLOCATE( build_ids_l_tmp ) |
---|
1202 | ENDIF |
---|
1203 | ! |
---|
1204 | !-- First occuring building id on PE |
---|
1205 | ELSE |
---|
1206 | num_buildings_l(myid) = num_buildings_l(myid) + 1 |
---|
1207 | build_ids_l(1) = building_id_f%var(j,i) |
---|
1208 | ENDIF |
---|
1209 | ENDIF |
---|
1210 | ENDDO |
---|
1211 | ENDDO |
---|
1212 | ! |
---|
1213 | !-- Determine number of different building ids for the entire domain |
---|
1214 | #if defined( __parallel ) |
---|
1215 | CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs, & |
---|
1216 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
1217 | #else |
---|
1218 | num_buildings = num_buildings_l |
---|
1219 | #endif |
---|
1220 | ! |
---|
1221 | !-- Gather all buildings ids on each PEs. |
---|
1222 | !-- First, allocate array encompassing all building ids in model domain. |
---|
1223 | ALLOCATE( build_ids(1:SUM(num_buildings)) ) |
---|
1224 | #if defined( __parallel ) |
---|
1225 | ! |
---|
1226 | !-- Allocate array for displacements. |
---|
1227 | !-- As each PE may has a different number of buildings, so that |
---|
1228 | !-- the block sizes send by each PE may not be equal. Hence, |
---|
1229 | !-- information about the respective displacement is required, indicating |
---|
1230 | !-- the respective adress where each MPI-task writes into the receive |
---|
1231 | !-- buffer array |
---|
1232 | ALLOCATE( displace_dum(0:numprocs-1) ) |
---|
1233 | displace_dum(0) = 0 |
---|
1234 | DO i = 1, numprocs-1 |
---|
1235 | displace_dum(i) = displace_dum(i-1) + num_buildings(i-1) |
---|
1236 | ENDDO |
---|
1237 | |
---|
1238 | CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)), & |
---|
1239 | num_buildings(myid), & |
---|
1240 | MPI_INTEGER, & |
---|
1241 | build_ids, & |
---|
1242 | num_buildings, & |
---|
1243 | displace_dum, & |
---|
1244 | MPI_INTEGER, & |
---|
1245 | comm2d, ierr ) |
---|
1246 | |
---|
1247 | DEALLOCATE( displace_dum ) |
---|
1248 | |
---|
1249 | #else |
---|
1250 | build_ids = build_ids_l |
---|
1251 | #endif |
---|
1252 | |
---|
1253 | ! |
---|
1254 | !-- Note, in parallel mode building ids can occure mutliple times, as |
---|
1255 | !-- each PE has send its own ids. Therefore, sort out building ids which |
---|
1256 | !-- appear more than one time. |
---|
1257 | num_build = 0 |
---|
1258 | DO nr = 1, SIZE(build_ids) |
---|
1259 | |
---|
1260 | IF ( ALLOCATED(build_ids_final) ) THEN |
---|
1261 | IF ( ANY( build_ids(nr) == build_ids_final ) ) THEN |
---|
1262 | CYCLE |
---|
1263 | ELSE |
---|
1264 | num_build = num_build + 1 |
---|
1265 | ! |
---|
1266 | !-- Resize |
---|
1267 | ALLOCATE( build_ids_final_tmp(1:num_build) ) |
---|
1268 | build_ids_final_tmp(1:num_build-1) = build_ids_final(1:num_build-1) |
---|
1269 | DEALLOCATE( build_ids_final ) |
---|
1270 | ALLOCATE( build_ids_final(1:num_build) ) |
---|
1271 | build_ids_final(1:num_build-1) = build_ids_final_tmp(1:num_build-1) |
---|
1272 | build_ids_final(num_build) = build_ids(nr) |
---|
1273 | DEALLOCATE( build_ids_final_tmp ) |
---|
1274 | ENDIF |
---|
1275 | ELSE |
---|
1276 | num_build = num_build + 1 |
---|
1277 | ALLOCATE( build_ids_final(1:num_build) ) |
---|
1278 | build_ids_final(num_build) = build_ids(nr) |
---|
1279 | ENDIF |
---|
1280 | ENDDO |
---|
1281 | |
---|
1282 | ! |
---|
1283 | !-- Determine maximumum terrain height occupied by the respective |
---|
1284 | !-- building and temporalily store on oro_max |
---|
1285 | ALLOCATE( oro_max_l(1:SIZE(build_ids_final)) ) |
---|
1286 | ALLOCATE( oro_max(1:SIZE(build_ids_final)) ) |
---|
1287 | oro_max_l = 0.0_wp |
---|
1288 | |
---|
1289 | DO nr = 1, SIZE(build_ids_final) |
---|
1290 | oro_max_l(nr) = MAXVAL( & |
---|
1291 | MERGE( terrain_height_f%var(nys:nyn,nxl:nxr), & |
---|
1292 | 0.0_wp, & |
---|
1293 | building_id_f%var(nys:nyn,nxl:nxr) == & |
---|
1294 | build_ids_final(nr) ) ) |
---|
1295 | ENDDO |
---|
1296 | |
---|
1297 | #if defined( __parallel ) |
---|
1298 | IF ( SIZE(build_ids_final) >= 1 ) THEN |
---|
1299 | CALL MPI_ALLREDUCE( oro_max_l, oro_max, SIZE( oro_max ), MPI_REAL,& |
---|
1300 | MPI_MAX, comm2d, ierr ) |
---|
1301 | ENDIF |
---|
1302 | #else |
---|
1303 | oro_max = oro_max_l |
---|
1304 | #endif |
---|
1305 | ! |
---|
1306 | !-- Finally, determine discrete grid height of maximum orography occupied |
---|
1307 | !-- by a building. Use all-or-nothing approach, i.e. if terrain |
---|
1308 | !-- exceeds the scalar level the grid box is fully terrain and the |
---|
1309 | !-- maximum terrain is set to the zw level. |
---|
1310 | !-- terrain or |
---|
1311 | oro_max_l = 0.0 |
---|
1312 | DO nr = 1, SIZE(build_ids_final) |
---|
1313 | DO k = nzb, nzt |
---|
1314 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) & |
---|
1315 | oro_max_l(nr) = zw(k) - ocean_offset |
---|
1316 | ENDDO |
---|
1317 | oro_max(nr) = oro_max_l(nr) |
---|
1318 | ENDDO |
---|
1319 | ENDIF |
---|
1320 | ! |
---|
1321 | !-- Allocate array for storing terrain height under buildings |
---|
1322 | IF ( buildings_f%from_file ) THEN |
---|
1323 | ALLOCATE( buildings_f%oro_max(nysg:nyng,nxlg:nxrg) ) |
---|
1324 | buildings_f%oro_max = buildings_f%fill1 |
---|
1325 | END IF |
---|
1326 | ! |
---|
1327 | !-- Map orography as well as buildings onto grid. |
---|
1328 | DO i = nxl, nxr |
---|
1329 | DO j = nys, nyn |
---|
1330 | topo_top_index = 0 |
---|
1331 | ! |
---|
1332 | !-- Obtain index in global building_id array |
---|
1333 | IF ( buildings_f%from_file ) THEN |
---|
1334 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
1335 | ! |
---|
1336 | !-- Determine index where maximum terrain height occupied by |
---|
1337 | !-- the respective building height is stored. |
---|
1338 | nr = MINLOC( ABS( build_ids_final - & |
---|
1339 | building_id_f%var(j,i) ), DIM = 1 ) |
---|
1340 | ! |
---|
1341 | !-- Save grid-indexed oro_max |
---|
1342 | buildings_f%oro_max(j,i) = oro_max(nr) |
---|
1343 | ENDIF |
---|
1344 | ENDIF |
---|
1345 | DO k = nzb, nzt |
---|
1346 | ! |
---|
1347 | !-- In a first step, if grid point is below or equal the given |
---|
1348 | !-- terrain height, grid point is flagged to be of type natural. |
---|
1349 | !-- Please note, in case there is also a building which is lower |
---|
1350 | !-- than the vertical grid spacing, initialization of surface |
---|
1351 | !-- attributes will not be correct as given surface information |
---|
1352 | !-- will not be in accordance to the classified grid points. |
---|
1353 | !-- Hence, in this case, also a building flag. |
---|
1354 | IF ( zu(k) - ocean_offset <= terrain_height_f%var(j,i) ) THEN |
---|
1355 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1356 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
1357 | topo_top_index = k ! topo_top_index + 1 |
---|
1358 | ENDIF |
---|
1359 | ! |
---|
1360 | !-- Set building grid points. Here, only consider 2D buildings. |
---|
1361 | !-- 3D buildings require separate treatment. |
---|
1362 | IF ( buildings_f%from_file .AND. buildings_f%lod == 1 ) THEN |
---|
1363 | ! |
---|
1364 | !-- Fill-up the terrain to the level of maximum orography |
---|
1365 | !-- within the building-covered area. |
---|
1366 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
1367 | ! |
---|
1368 | !-- Note, oro_max is always on zw level |
---|
1369 | IF ( zu(k) - ocean_offset < oro_max(nr) ) THEN |
---|
1370 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1371 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
1372 | ELSEIF ( zu(k) - ocean_offset <= & |
---|
1373 | oro_max(nr) + buildings_f%var_2d(j,i) ) THEN |
---|
1374 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1375 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
1376 | ENDIF |
---|
1377 | ENDIF |
---|
1378 | ENDIF |
---|
1379 | ENDDO |
---|
1380 | ! |
---|
1381 | !-- Special treatment for non grid-resolved buildings. This case, |
---|
1382 | !-- the uppermost terrain grid point is flagged as building as well |
---|
1383 | !-- well, even though no building exists at all. However, the |
---|
1384 | !-- surface element will be identified as urban-surface and the |
---|
1385 | !-- input data provided by the drivers is consistent to the surface |
---|
1386 | !-- classification. Else, all non grid-resolved buildings would vanish |
---|
1387 | !-- and identified as terrain grid points, which, however, won't be |
---|
1388 | !-- consistent with the input data. |
---|
1389 | IF ( buildings_f%from_file .AND. buildings_f%lod == 1 ) THEN |
---|
1390 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
1391 | DO k = nzb, nzt |
---|
1392 | IF( zw(k) - ocean_offset == oro_max(nr) ) THEN |
---|
1393 | IF ( buildings_f%var_2d(j,i) <= zu(k+1) - zw(k) ) THEN |
---|
1394 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
1395 | ENDIF |
---|
1396 | ENDIF |
---|
1397 | ENDDO |
---|
1398 | ENDIF |
---|
1399 | ENDIF |
---|
1400 | ! |
---|
1401 | !-- Map 3D buildings onto terrain height. |
---|
1402 | !-- In case of any slopes, map building on top of maximum terrain |
---|
1403 | !-- height covered by the building. In other words, extend |
---|
1404 | !-- building down to the respective local terrain-surface height. |
---|
1405 | IF ( buildings_f%from_file .AND. buildings_f%lod == 2 ) THEN |
---|
1406 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
1407 | ! |
---|
1408 | !-- Extend building down to the terrain surface, i.e. fill-up |
---|
1409 | !-- surface irregularities below a building. Note, oro_max |
---|
1410 | !-- is already a discrete height according to the all-or-nothing |
---|
1411 | !-- approach, i.e. grid box is either topography or atmosphere, |
---|
1412 | !-- terrain top is defined at upper bound of the grid box. |
---|
1413 | !-- Hence, check for zw in this case. |
---|
1414 | !-- Note, do this only for buildings which are surface mounted, |
---|
1415 | !-- i.e. building types 1-6. Below bridges, which are represented |
---|
1416 | !-- exclusively by building type 7, terrain shape should be |
---|
1417 | !-- maintained. |
---|
1418 | IF ( building_type_f%from_file ) THEN |
---|
1419 | IF ( building_type_f%var(j,i) /= 7 ) THEN |
---|
1420 | DO k = topo_top_index + 1, nzt + 1 |
---|
1421 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) THEN |
---|
1422 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1423 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
1424 | ENDIF |
---|
1425 | ENDDO |
---|
1426 | ! |
---|
1427 | !-- After surface irregularities are smoothen, determine |
---|
1428 | !-- lower start index where building starts. |
---|
1429 | DO k = nzb, nzt |
---|
1430 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) & |
---|
1431 | topo_top_index = k |
---|
1432 | ENDDO |
---|
1433 | ENDIF |
---|
1434 | ENDIF |
---|
1435 | ! |
---|
1436 | !-- Finally, map building on top. |
---|
1437 | k2 = 0 |
---|
1438 | DO k = topo_top_index, nzt + 1 |
---|
1439 | IF ( k2 <= buildings_f%nz-1 ) THEN |
---|
1440 | IF ( buildings_f%var_3d(k2,j,i) == 1 ) THEN |
---|
1441 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1442 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
1443 | ENDIF |
---|
1444 | ENDIF |
---|
1445 | k2 = k2 + 1 |
---|
1446 | ENDDO |
---|
1447 | ENDIF |
---|
1448 | ENDIF |
---|
1449 | ENDDO |
---|
1450 | ENDDO |
---|
1451 | ! |
---|
1452 | !-- Horizontal exchange the oro_max array, which is required to for |
---|
1453 | !-- initialization of building-surface properties. |
---|
1454 | IF ( ALLOCATED( buildings_f%oro_max ) ) THEN |
---|
1455 | CALL exchange_horiz_2d( buildings_f%oro_max(:,:), nbgp ) |
---|
1456 | ENDIF |
---|
1457 | ! |
---|
1458 | !-- Deallocate temporary arrays required for processing and reading data |
---|
1459 | IF ( ALLOCATED( oro_max ) ) DEALLOCATE( oro_max ) |
---|
1460 | IF ( ALLOCATED( oro_max_l ) ) DEALLOCATE( oro_max_l ) |
---|
1461 | IF ( ALLOCATED( build_ids_final ) ) DEALLOCATE( build_ids_final ) |
---|
1462 | ! |
---|
1463 | !-- Topography input via ASCII format. |
---|
1464 | ELSE |
---|
1465 | ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode ) |
---|
1466 | ! |
---|
1467 | !-- Initialize topography bit 0 (indicates obstacle) everywhere to zero |
---|
1468 | !-- and clear all grid points at nzb, where alway a surface is defined. |
---|
1469 | !-- Further, set also bit 1 (indicates terrain) at nzb, which is further |
---|
1470 | !-- used for masked data output and further processing. Note, in the |
---|
1471 | !-- ASCII case no distinction is made between buildings and terrain, |
---|
1472 | !-- so that setting of bit 1 and 2 at the same time has no effect. |
---|
1473 | topo_3d = IBSET( topo_3d, 0 ) |
---|
1474 | topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 ) |
---|
1475 | topo_3d(nzb,:,:) = IBSET( topo_3d(nzb,:,:), 1 ) |
---|
1476 | DO i = nxl, nxr |
---|
1477 | DO j = nys, nyn |
---|
1478 | DO k = nzb, nzt |
---|
1479 | ! |
---|
1480 | !-- Flag topography for all grid points which are below |
---|
1481 | !-- the local topography height. |
---|
1482 | !-- Note, each topography is flagged as building. |
---|
1483 | IF ( zu(k) - ocean_offset <= buildings_f%var_2d(j,i) ) THEN |
---|
1484 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1485 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) !indicates building |
---|
1486 | ENDIF |
---|
1487 | ENDDO |
---|
1488 | ENDDO |
---|
1489 | ENDDO |
---|
1490 | ENDIF |
---|
1491 | |
---|
1492 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
1493 | |
---|
1494 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1495 | IF ( nys == 0 ) topo_3d(:,-1,:) = topo_3d(:,0,:) |
---|
1496 | IF ( nyn == ny ) topo_3d(:,ny+1,:) = topo_3d(:,ny,:) |
---|
1497 | ENDIF |
---|
1498 | |
---|
1499 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1500 | IF ( nxl == 0 ) topo_3d(:,:,-1) = topo_3d(:,:,0) |
---|
1501 | IF ( nxr == nx ) topo_3d(:,:,nx+1) = topo_3d(:,:,nx) |
---|
1502 | ENDIF |
---|
1503 | |
---|
1504 | END SUBROUTINE process_topography |
---|
1505 | |
---|
1506 | |
---|
1507 | ! Description: |
---|
1508 | ! -----------------------------------------------------------------------------! |
---|
1509 | !> Filter topography, i.e. fill holes resolved by only one grid point. |
---|
1510 | !> Such holes are suspected to lead to velocity blow-ups as continuity |
---|
1511 | !> equation on discrete grid cannot be fulfilled in such case. |
---|
1512 | !------------------------------------------------------------------------------! |
---|
1513 | SUBROUTINE filter_topography( topo_3d ) |
---|
1514 | |
---|
1515 | USE control_parameters, & |
---|
1516 | ONLY: bc_lr_cyc, bc_ns_cyc, message_string |
---|
1517 | |
---|
1518 | USE indices, & |
---|
1519 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt |
---|
1520 | |
---|
1521 | USE netcdf_data_input_mod, & |
---|
1522 | ONLY: building_id_f, building_type_f |
---|
1523 | |
---|
1524 | USE pegrid |
---|
1525 | |
---|
1526 | IMPLICIT NONE |
---|
1527 | |
---|
1528 | LOGICAL :: filled = .FALSE. !< flag indicating if holes were filled |
---|
1529 | |
---|
1530 | INTEGER(iwp) :: i !< running index along x-direction |
---|
1531 | INTEGER(iwp) :: j !< running index along y-direction |
---|
1532 | INTEGER(iwp) :: k !< running index along z-direction |
---|
1533 | INTEGER(iwp) :: num_hole !< number of holes (in topography) resolved by only one grid point |
---|
1534 | INTEGER(iwp) :: num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE |
---|
1535 | INTEGER(iwp) :: num_wall !< number of surrounding vertical walls for a single grid point |
---|
1536 | |
---|
1537 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: topo_tmp !< temporary 3D-topography used to fill holes |
---|
1538 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo_3d !< 3D-topography array merging buildings and orography |
---|
1539 | ! |
---|
1540 | !-- Before checking for holes, set lateral boundary conditions for |
---|
1541 | !-- topography. After hole-filling, boundary conditions must be set again. |
---|
1542 | !-- Several iterations are performed, in order to fill holes which might |
---|
1543 | !-- emerge by the filling-algorithm itself. |
---|
1544 | ALLOCATE( topo_tmp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
1545 | topo_tmp = 0 |
---|
1546 | |
---|
1547 | num_hole = 99999 |
---|
1548 | DO WHILE ( num_hole > 0 ) |
---|
1549 | |
---|
1550 | num_hole = 0 |
---|
1551 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
1552 | ! |
---|
1553 | !-- Exchange also building ID and type. Note, building_type is an one-byte |
---|
1554 | !-- variable. |
---|
1555 | IF ( building_id_f%from_file ) & |
---|
1556 | CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
1557 | IF ( building_type_f%from_file ) & |
---|
1558 | CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
1559 | |
---|
1560 | topo_tmp = topo_3d |
---|
1561 | ! |
---|
1562 | !-- In case of non-cyclic lateral boundaries, assume lateral boundary to be |
---|
1563 | !-- a solid wall. Thus, intermediate spaces of one grid point between |
---|
1564 | !-- boundary and some topographic structure will be filled. |
---|
1565 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1566 | IF ( nys == 0 ) topo_tmp(:,-1,:) = IBCLR( topo_tmp(:,0,:), 0 ) |
---|
1567 | IF ( nyn == ny ) topo_tmp(:,ny+1,:) = IBCLR( topo_tmp(:,ny,:), 0 ) |
---|
1568 | ENDIF |
---|
1569 | |
---|
1570 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1571 | IF ( nxl == 0 ) topo_tmp(:,:,-1) = IBCLR( topo_tmp(:,:,0), 0 ) |
---|
1572 | IF ( nxr == nx ) topo_tmp(:,:,nx+1) = IBCLR( topo_tmp(:,:,nx), 0 ) |
---|
1573 | ENDIF |
---|
1574 | |
---|
1575 | num_hole_l = 0 |
---|
1576 | DO i = nxl, nxr |
---|
1577 | DO j = nys, nyn |
---|
1578 | DO k = nzb+1, nzt |
---|
1579 | IF ( BTEST( topo_tmp(k,j,i), 0 ) ) THEN |
---|
1580 | num_wall = 0 |
---|
1581 | IF ( .NOT. BTEST( topo_tmp(k,j-1,i), 0 ) ) & |
---|
1582 | num_wall = num_wall + 1 |
---|
1583 | IF ( .NOT. BTEST( topo_tmp(k,j+1,i), 0 ) ) & |
---|
1584 | num_wall = num_wall + 1 |
---|
1585 | IF ( .NOT. BTEST( topo_tmp(k,j,i-1), 0 ) ) & |
---|
1586 | num_wall = num_wall + 1 |
---|
1587 | IF ( .NOT. BTEST( topo_tmp(k,j,i+1), 0 ) ) & |
---|
1588 | num_wall = num_wall + 1 |
---|
1589 | IF ( .NOT. BTEST( topo_tmp(k-1,j,i), 0 ) ) & |
---|
1590 | num_wall = num_wall + 1 |
---|
1591 | IF ( .NOT. BTEST( topo_tmp(k+1,j,i), 0 ) ) & |
---|
1592 | num_wall = num_wall + 1 |
---|
1593 | |
---|
1594 | IF ( num_wall >= 4 ) THEN |
---|
1595 | num_hole_l = num_hole_l + 1 |
---|
1596 | ! |
---|
1597 | !-- Clear flag 0 and set special flag ( bit 3) to indicate |
---|
1598 | !-- that new topography point is a result of filtering process. |
---|
1599 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
1600 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 3 ) |
---|
1601 | ! |
---|
1602 | !-- If filled grid point is occupied by a building, classify |
---|
1603 | !-- it as building grid point. |
---|
1604 | IF ( building_type_f%from_file ) THEN |
---|
1605 | IF ( building_type_f%var(j,i) /= & |
---|
1606 | building_type_f%fill .OR. & |
---|
1607 | building_type_f%var(j+1,i) /= & |
---|
1608 | building_type_f%fill .OR. & |
---|
1609 | building_type_f%var(j-1,i) /= & |
---|
1610 | building_type_f%fill .OR. & |
---|
1611 | building_type_f%var(j,i+1) /= & |
---|
1612 | building_type_f%fill .OR. & |
---|
1613 | building_type_f%var(j,i-1) /= & |
---|
1614 | building_type_f%fill ) THEN |
---|
1615 | ! |
---|
1616 | !-- Set flag indicating building surfaces |
---|
1617 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
1618 | ! |
---|
1619 | !-- Set building_type and ID at this position if not |
---|
1620 | !-- already set. This is required for proper |
---|
1621 | !-- initialization of urban-surface energy balance |
---|
1622 | !-- solver. |
---|
1623 | IF ( building_type_f%var(j,i) == & |
---|
1624 | building_type_f%fill ) THEN |
---|
1625 | |
---|
1626 | IF ( building_type_f%var(j+1,i) /= & |
---|
1627 | building_type_f%fill ) THEN |
---|
1628 | building_type_f%var(j,i) = & |
---|
1629 | building_type_f%var(j+1,i) |
---|
1630 | building_id_f%var(j,i) = & |
---|
1631 | building_id_f%var(j+1,i) |
---|
1632 | ELSEIF ( building_type_f%var(j-1,i) /= & |
---|
1633 | building_type_f%fill ) THEN |
---|
1634 | building_type_f%var(j,i) = & |
---|
1635 | building_type_f%var(j-1,i) |
---|
1636 | building_id_f%var(j,i) = & |
---|
1637 | building_id_f%var(j-1,i) |
---|
1638 | ELSEIF ( building_type_f%var(j,i+1) /= & |
---|
1639 | building_type_f%fill ) THEN |
---|
1640 | building_type_f%var(j,i) = & |
---|
1641 | building_type_f%var(j,i+1) |
---|
1642 | building_id_f%var(j,i) = & |
---|
1643 | building_id_f%var(j,i+1) |
---|
1644 | ELSEIF ( building_type_f%var(j,i-1) /= & |
---|
1645 | building_type_f%fill ) THEN |
---|
1646 | building_type_f%var(j,i) = & |
---|
1647 | building_type_f%var(j,i-1) |
---|
1648 | building_id_f%var(j,i) = & |
---|
1649 | building_id_f%var(j,i-1) |
---|
1650 | ENDIF |
---|
1651 | ENDIF |
---|
1652 | ENDIF |
---|
1653 | ENDIF |
---|
1654 | ! |
---|
1655 | !-- If filled grid point is already classified as building |
---|
1656 | !-- everything is fine, else classify this grid point as |
---|
1657 | !-- natural type grid point. This case, values for the |
---|
1658 | !-- surface type are already set. |
---|
1659 | IF ( .NOT. BTEST( topo_3d(k,j,i), 2 ) ) THEN |
---|
1660 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
1661 | ENDIF |
---|
1662 | ENDIF |
---|
1663 | ENDIF |
---|
1664 | ENDDO |
---|
1665 | ENDDO |
---|
1666 | ENDDO |
---|
1667 | ! |
---|
1668 | !-- Count the total number of holes, required for informative message. |
---|
1669 | #if defined( __parallel ) |
---|
1670 | CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM, & |
---|
1671 | comm2d, ierr ) |
---|
1672 | #else |
---|
1673 | num_hole = num_hole_l |
---|
1674 | #endif |
---|
1675 | IF ( num_hole > 0 .AND. .NOT. filled ) filled = .TRUE. |
---|
1676 | |
---|
1677 | ENDDO |
---|
1678 | ! |
---|
1679 | !-- Create an informative message if any holes were filled. |
---|
1680 | IF ( filled ) THEN |
---|
1681 | WRITE( message_string, * ) 'Topography was filtered, i.e. holes ' // & |
---|
1682 | 'resolved by only one grid point ' // & |
---|
1683 | 'were filled during initialization.' |
---|
1684 | CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 ) |
---|
1685 | ENDIF |
---|
1686 | |
---|
1687 | DEALLOCATE( topo_tmp ) |
---|
1688 | ! |
---|
1689 | !-- Finally, exchange topo_3d array again and if necessary set Neumann boundary |
---|
1690 | !-- condition in case of non-cyclic lateral boundaries. |
---|
1691 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
1692 | |
---|
1693 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1694 | IF ( nys == 0 ) topo_3d(:,-1,:) = topo_3d(:,0,:) |
---|
1695 | IF ( nyn == ny ) topo_3d(:,ny+1,:) = topo_3d(:,ny,:) |
---|
1696 | ENDIF |
---|
1697 | |
---|
1698 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1699 | IF ( nxl == 0 ) topo_3d(:,:,-1) = topo_3d(:,:,0) |
---|
1700 | IF ( nxr == nx ) topo_3d(:,:,nx+1) = topo_3d(:,:,nx) |
---|
1701 | ENDIF |
---|
1702 | ! |
---|
1703 | !-- Exchange building ID and type. Note, building_type is an one-byte variable. |
---|
1704 | IF ( building_id_f%from_file ) & |
---|
1705 | CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
1706 | IF ( building_type_f%from_file ) & |
---|
1707 | CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
1708 | |
---|
1709 | END SUBROUTINE filter_topography |
---|
1710 | |
---|
1711 | |
---|
1712 | ! Description: |
---|
1713 | ! -----------------------------------------------------------------------------! |
---|
1714 | !> Reads topography information from file or sets generic topography. Moreover, |
---|
1715 | !> all topography-relevant topography arrays are initialized, and grid flags |
---|
1716 | !> are set. |
---|
1717 | !------------------------------------------------------------------------------! |
---|
1718 | SUBROUTINE init_topo( topo ) |
---|
1719 | |
---|
1720 | USE arrays_3d, & |
---|
1721 | ONLY: zw |
---|
1722 | |
---|
1723 | USE control_parameters, & |
---|
1724 | ONLY: bc_lr_cyc, bc_ns_cyc, building_height, building_length_x, & |
---|
1725 | building_length_y, building_wall_left, building_wall_south, & |
---|
1726 | canyon_height, canyon_wall_left, canyon_wall_south, & |
---|
1727 | canyon_width_x, canyon_width_y, dp_level_ind_b, dz, & |
---|
1728 | message_string, topography, topography_grid_convention, & |
---|
1729 | tunnel_height, tunnel_length, tunnel_width_x, tunnel_width_y, & |
---|
1730 | tunnel_wall_depth |
---|
1731 | |
---|
1732 | USE grid_variables, & |
---|
1733 | ONLY: dx, dy |
---|
1734 | |
---|
1735 | USE indices, & |
---|
1736 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz, & |
---|
1737 | nzb, nzt |
---|
1738 | |
---|
1739 | USE kinds |
---|
1740 | |
---|
1741 | USE netcdf_data_input_mod, & |
---|
1742 | ONLY: buildings_f, terrain_height_f |
---|
1743 | |
---|
1744 | USE pegrid |
---|
1745 | |
---|
1746 | IMPLICIT NONE |
---|
1747 | |
---|
1748 | INTEGER(iwp) :: bh !< temporary vertical index of building height |
---|
1749 | INTEGER(iwp) :: blx !< grid point number of building size along x |
---|
1750 | INTEGER(iwp) :: bly !< grid point number of building size along y |
---|
1751 | INTEGER(iwp) :: bxl !< index for left building wall |
---|
1752 | INTEGER(iwp) :: bxr !< index for right building wall |
---|
1753 | INTEGER(iwp) :: byn !< index for north building wall |
---|
1754 | INTEGER(iwp) :: bys !< index for south building wall |
---|
1755 | INTEGER(iwp) :: ch !< temporary vertical index for canyon height |
---|
1756 | INTEGER(iwp) :: cwx !< grid point number of canyon size along x |
---|
1757 | INTEGER(iwp) :: cwy !< grid point number of canyon size along y |
---|
1758 | INTEGER(iwp) :: cxl !< index for left canyon wall |
---|
1759 | INTEGER(iwp) :: cxr !< index for right canyon wall |
---|
1760 | INTEGER(iwp) :: cyn !< index for north canyon wall |
---|
1761 | INTEGER(iwp) :: cys !< index for south canyon wall |
---|
1762 | INTEGER(iwp) :: i !< index variable along x |
---|
1763 | INTEGER(iwp) :: j !< index variable along y |
---|
1764 | INTEGER(iwp) :: k !< index variable along z |
---|
1765 | INTEGER(iwp) :: hv_in !< heavyside function to model inner tunnel surface |
---|
1766 | INTEGER(iwp) :: hv_out !< heavyside function to model outer tunnel surface |
---|
1767 | INTEGER(iwp) :: txe_out !< end position of outer tunnel wall in x |
---|
1768 | INTEGER(iwp) :: txs_out !< start position of outer tunnel wall in x |
---|
1769 | INTEGER(iwp) :: tye_out !< end position of outer tunnel wall in y |
---|
1770 | INTEGER(iwp) :: tys_out !< start position of outer tunnel wall in y |
---|
1771 | INTEGER(iwp) :: txe_in !< end position of inner tunnel wall in x |
---|
1772 | INTEGER(iwp) :: txs_in !< start position of inner tunnel wall in x |
---|
1773 | INTEGER(iwp) :: tye_in !< end position of inner tunnel wall in y |
---|
1774 | INTEGER(iwp) :: tys_in !< start position of inner tunnel wall in y |
---|
1775 | INTEGER(iwp) :: td !< tunnel wall depth |
---|
1776 | INTEGER(iwp) :: th !< height of outer tunnel wall |
---|
1777 | |
---|
1778 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !< index for topography top at cell-center |
---|
1779 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
1780 | ! |
---|
1781 | !-- Check for correct setting of the namelist parameter topography. If |
---|
1782 | !-- topography information is read from file but topography = 'flat', |
---|
1783 | !-- initialization does not properly. |
---|
1784 | IF ( ( buildings_f%from_file .OR. terrain_height_f%from_file ) .AND. & |
---|
1785 | TRIM( topography ) /= 'read_from_file' ) THEN |
---|
1786 | message_string = 'If topography information is provided (via ' // & |
---|
1787 | 'Netcdf or ASCII input) topography = ' // & |
---|
1788 | '"read_from_file" is required.' |
---|
1789 | CALL message( 'init_grid', 'PA0437', 1, 2, 0, 6, 0 ) |
---|
1790 | ENDIF |
---|
1791 | ! |
---|
1792 | !-- Set outer and inner index arrays for non-flat topography. |
---|
1793 | !-- Here consistency checks concerning domain size and periodicity are |
---|
1794 | !-- necessary. |
---|
1795 | !-- Within this SELECT CASE structure only nzb_local is initialized |
---|
1796 | !-- individually depending on the chosen topography type, all other index |
---|
1797 | !-- arrays are initialized further below. |
---|
1798 | SELECT CASE ( TRIM( topography ) ) |
---|
1799 | |
---|
1800 | CASE ( 'flat' ) |
---|
1801 | ! |
---|
1802 | !-- Initialilize 3D topography array, used later for initializing flags |
---|
1803 | topo(nzb+1:nzt+1,:,:) = IBSET( topo(nzb+1:nzt+1,:,:), 0 ) |
---|
1804 | |
---|
1805 | CASE ( 'single_building' ) |
---|
1806 | ! |
---|
1807 | !-- Single rectangular building, by default centered in the middle of the |
---|
1808 | !-- total domain |
---|
1809 | blx = NINT( building_length_x / dx ) |
---|
1810 | bly = NINT( building_length_y / dy ) |
---|
1811 | bh = MINLOC( ABS( zw - building_height ), 1 ) - 1 |
---|
1812 | IF ( ABS( zw(bh) - building_height ) == & |
---|
1813 | ABS( zw(bh+1) - building_height ) ) bh = bh + 1 |
---|
1814 | IF ( building_wall_left == 9999999.9_wp ) THEN |
---|
1815 | building_wall_left = ( nx + 1 - blx ) / 2 * dx |
---|
1816 | ENDIF |
---|
1817 | bxl = NINT( building_wall_left / dx ) |
---|
1818 | bxr = bxl + blx |
---|
1819 | |
---|
1820 | IF ( building_wall_south == 9999999.9_wp ) THEN |
---|
1821 | building_wall_south = ( ny + 1 - bly ) / 2 * dy |
---|
1822 | ENDIF |
---|
1823 | bys = NINT( building_wall_south / dy ) |
---|
1824 | byn = bys + bly |
---|
1825 | |
---|
1826 | ! |
---|
1827 | !-- Building size has to meet some requirements |
---|
1828 | IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & |
---|
1829 | ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN |
---|
1830 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
1831 | '&bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & |
---|
1832 | 'byn=', byn, 'nx=', nx, 'ny=', ny |
---|
1833 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
1834 | ENDIF |
---|
1835 | |
---|
1836 | ALLOCATE( nzb_local(nysg:nyng,nxlg:nxrg) ) |
---|
1837 | nzb_local = 0 |
---|
1838 | ! |
---|
1839 | !-- Define the building. |
---|
1840 | IF ( bxl <= nxr .AND. bxr >= nxl .AND. & |
---|
1841 | bys <= nyn .AND. byn >= nys ) & |
---|
1842 | nzb_local(MAX(nys,bys):MIN(nyn,byn),MAX(nxl,bxl):MIN(nxr,bxr)) = bh |
---|
1843 | ! |
---|
1844 | !-- Set bit array on basis of nzb_local |
---|
1845 | DO i = nxl, nxr |
---|
1846 | DO j = nys, nyn |
---|
1847 | topo(nzb_local(j,i)+1:nzt+1,j,i) = & |
---|
1848 | IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
1849 | ENDDO |
---|
1850 | ENDDO |
---|
1851 | |
---|
1852 | DEALLOCATE( nzb_local ) |
---|
1853 | |
---|
1854 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
1855 | ! |
---|
1856 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann |
---|
1857 | !-- boundary conditions for topography. |
---|
1858 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1859 | IF ( nys == 0 ) THEN |
---|
1860 | DO i = 1, nbgp |
---|
1861 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
1862 | ENDDO |
---|
1863 | ENDIF |
---|
1864 | IF ( nyn == ny ) THEN |
---|
1865 | DO i = 1, nbgp |
---|
1866 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
1867 | ENDDO |
---|
1868 | ENDIF |
---|
1869 | ENDIF |
---|
1870 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1871 | IF ( nxl == 0 ) THEN |
---|
1872 | DO i = 1, nbgp |
---|
1873 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
1874 | ENDDO |
---|
1875 | ENDIF |
---|
1876 | IF ( nxr == nx ) THEN |
---|
1877 | DO i = 1, nbgp |
---|
1878 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
1879 | ENDDO |
---|
1880 | ENDIF |
---|
1881 | ENDIF |
---|
1882 | |
---|
1883 | CASE ( 'single_street_canyon' ) |
---|
1884 | ! |
---|
1885 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
1886 | !-- The canyon is centered in the other direction by default. |
---|
1887 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
1888 | ! |
---|
1889 | !-- Street canyon in y direction |
---|
1890 | cwx = NINT( canyon_width_x / dx ) |
---|
1891 | IF ( canyon_wall_left == 9999999.9_wp ) THEN |
---|
1892 | canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx |
---|
1893 | ENDIF |
---|
1894 | cxl = NINT( canyon_wall_left / dx ) |
---|
1895 | cxr = cxl + cwx |
---|
1896 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
1897 | ! |
---|
1898 | !-- Street canyon in x direction |
---|
1899 | cwy = NINT( canyon_width_y / dy ) |
---|
1900 | IF ( canyon_wall_south == 9999999.9_wp ) THEN |
---|
1901 | canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy |
---|
1902 | ENDIF |
---|
1903 | cys = NINT( canyon_wall_south / dy ) |
---|
1904 | cyn = cys + cwy |
---|
1905 | |
---|
1906 | ELSE |
---|
1907 | |
---|
1908 | message_string = 'no street canyon width given' |
---|
1909 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
1910 | |
---|
1911 | ENDIF |
---|
1912 | |
---|
1913 | ch = MINLOC( ABS( zw - canyon_height ), 1 ) - 1 |
---|
1914 | IF ( ABS( zw(ch) - canyon_height ) == & |
---|
1915 | ABS( zw(ch+1) - canyon_height ) ) ch = ch + 1 |
---|
1916 | dp_level_ind_b = ch |
---|
1917 | ! |
---|
1918 | !-- Street canyon size has to meet some requirements |
---|
1919 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
1920 | IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & |
---|
1921 | ( ch < 3 ) ) THEN |
---|
1922 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
1923 | '&cxl=', cxl, ' cxr=', cxr, & |
---|
1924 | ' cwx=', cwx, & |
---|
1925 | ' ch=', ch, ' nx=', nx, ' ny=', ny |
---|
1926 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
1927 | ENDIF |
---|
1928 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
1929 | IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & |
---|
1930 | ( ch < 3 ) ) THEN |
---|
1931 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
1932 | '&cys=', cys, ' cyn=', cyn, & |
---|
1933 | ' cwy=', cwy, & |
---|
1934 | ' ch=', ch, ' nx=', nx, ' ny=', ny |
---|
1935 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
1936 | ENDIF |
---|
1937 | ENDIF |
---|
1938 | IF ( canyon_width_x /= 9999999.9_wp .AND. & |
---|
1939 | canyon_width_y /= 9999999.9_wp ) THEN |
---|
1940 | message_string = 'inconsistent canyon parameters:' // & |
---|
1941 | '&street canyon can only be oriented' // & |
---|
1942 | ' either in x- or in y-direction' |
---|
1943 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
1944 | ENDIF |
---|
1945 | |
---|
1946 | ALLOCATE( nzb_local(nysg:nyng,nxlg:nxrg) ) |
---|
1947 | nzb_local = ch |
---|
1948 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
1949 | IF ( cxl <= nxr .AND. cxr >= nxl ) & |
---|
1950 | nzb_local(:,MAX(nxl,cxl+1):MIN(nxr,cxr-1)) = 0 |
---|
1951 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
1952 | IF ( cys <= nyn .AND. cyn >= nys ) & |
---|
1953 | nzb_local(MAX(nys,cys+1):MIN(nyn,cyn-1),:) = 0 |
---|
1954 | ENDIF |
---|
1955 | ! |
---|
1956 | !-- Set bit array on basis of nzb_local |
---|
1957 | DO i = nxl, nxr |
---|
1958 | DO j = nys, nyn |
---|
1959 | topo(nzb_local(j,i)+1:nzt+1,j,i) = & |
---|
1960 | IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
1961 | ENDDO |
---|
1962 | ENDDO |
---|
1963 | DEALLOCATE( nzb_local ) |
---|
1964 | |
---|
1965 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
1966 | ! |
---|
1967 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann |
---|
1968 | !-- boundary conditions for topography. |
---|
1969 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1970 | IF ( nys == 0 ) THEN |
---|
1971 | DO i = 1, nbgp |
---|
1972 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
1973 | ENDDO |
---|
1974 | ENDIF |
---|
1975 | IF ( nyn == ny ) THEN |
---|
1976 | DO i = 1, nbgp |
---|
1977 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
1978 | ENDDO |
---|
1979 | ENDIF |
---|
1980 | ENDIF |
---|
1981 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1982 | IF ( nxl == 0 ) THEN |
---|
1983 | DO i = 1, nbgp |
---|
1984 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
1985 | ENDDO |
---|
1986 | ENDIF |
---|
1987 | IF ( nxr == nx ) THEN |
---|
1988 | DO i = 1, nbgp |
---|
1989 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
1990 | ENDDO |
---|
1991 | ENDIF |
---|
1992 | ENDIF |
---|
1993 | |
---|
1994 | CASE ( 'tunnel' ) |
---|
1995 | |
---|
1996 | ! |
---|
1997 | !-- Tunnel height |
---|
1998 | IF ( tunnel_height == 9999999.9_wp ) THEN |
---|
1999 | th = zw( INT( 0.2 * nz) ) |
---|
2000 | ELSE |
---|
2001 | th = tunnel_height |
---|
2002 | ENDIF |
---|
2003 | ! |
---|
2004 | !-- Tunnel-wall depth |
---|
2005 | IF ( tunnel_wall_depth == 9999999.9_wp ) THEN |
---|
2006 | td = MAX ( dx, dy, dz(1) ) |
---|
2007 | ELSE |
---|
2008 | td = tunnel_wall_depth |
---|
2009 | ENDIF |
---|
2010 | ! |
---|
2011 | !-- Check for tunnel width |
---|
2012 | IF ( tunnel_width_x == 9999999.9_wp .AND. & |
---|
2013 | tunnel_width_y == 9999999.9_wp ) THEN |
---|
2014 | message_string = 'No tunnel width is given. ' |
---|
2015 | CALL message( 'init_grid', 'PA0280', 1, 2, 0, 6, 0 ) |
---|
2016 | ENDIF |
---|
2017 | IF ( tunnel_width_x /= 9999999.9_wp .AND. & |
---|
2018 | tunnel_width_y /= 9999999.9_wp ) THEN |
---|
2019 | message_string = 'Inconsistent tunnel parameters:' // & |
---|
2020 | 'tunnel can only be oriented' // & |
---|
2021 | 'either in x- or in y-direction.' |
---|
2022 | CALL message( 'init_grid', 'PA0281', 1, 2, 0, 6, 0 ) |
---|
2023 | ENDIF |
---|
2024 | ! |
---|
2025 | !-- Tunnel axis along y |
---|
2026 | IF ( tunnel_width_x /= 9999999.9_wp ) THEN |
---|
2027 | IF ( tunnel_width_x > ( nx + 1 ) * dx ) THEN |
---|
2028 | message_string = 'Tunnel width too large' |
---|
2029 | CALL message( 'init_grid', 'PA0282', 1, 2, 0, 6, 0 ) |
---|
2030 | ENDIF |
---|
2031 | |
---|
2032 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_width_x * 0.5_wp ) |
---|
2033 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_width_x * 0.5_wp ) |
---|
2034 | txs_in = INT( ( nx + 1 ) * 0.5_wp * dx - & |
---|
2035 | ( tunnel_width_x * 0.5_wp - td ) ) |
---|
2036 | txe_in = INT( ( nx + 1 ) * 0.5_wp * dx + & |
---|
2037 | ( tunnel_width_x * 0.5_wp - td ) ) |
---|
2038 | |
---|
2039 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_length * 0.5_wp ) |
---|
2040 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_length * 0.5_wp ) |
---|
2041 | tys_in = tys_out |
---|
2042 | tye_in = tye_out |
---|
2043 | ENDIF |
---|
2044 | IF ( tunnel_width_x /= 9999999.9_wp .AND. & |
---|
2045 | tunnel_width_x - 2.0_wp * td <= 2.0_wp * dx ) & |
---|
2046 | THEN |
---|
2047 | message_string = 'Tunnel width too small' |
---|
2048 | CALL message( 'init_grid', 'PA0175', 1, 2, 0, 6, 0 ) |
---|
2049 | ENDIF |
---|
2050 | IF ( tunnel_width_y /= 9999999.9_wp .AND. & |
---|
2051 | tunnel_width_y - 2.0_wp * td <= 2.0_wp * dy ) & |
---|
2052 | THEN |
---|
2053 | message_string = 'Tunnel width too small' |
---|
2054 | CALL message( 'init_grid', 'PA0455', 1, 2, 0, 6, 0 ) |
---|
2055 | ENDIF |
---|
2056 | ! |
---|
2057 | !-- Tunnel axis along x |
---|
2058 | IF ( tunnel_width_y /= 9999999.9_wp ) THEN |
---|
2059 | IF ( tunnel_width_y > ( ny + 1 ) * dy ) THEN |
---|
2060 | message_string = 'Tunnel width too large' |
---|
2061 | CALL message( 'init_grid', 'PA0456', 1, 2, 0, 6, 0 ) |
---|
2062 | ENDIF |
---|
2063 | |
---|
2064 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_length * 0.5_wp ) |
---|
2065 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_length * 0.5_wp ) |
---|
2066 | txs_in = txs_out |
---|
2067 | txe_in = txe_out |
---|
2068 | |
---|
2069 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_width_y * 0.5_wp ) |
---|
2070 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_width_y * 0.5_wp ) |
---|
2071 | tys_in = INT( ( ny + 1 ) * 0.5_wp * dy - & |
---|
2072 | ( tunnel_width_y * 0.5_wp - td ) ) |
---|
2073 | tye_in = INT( ( ny + 1 ) * 0.5_wp * dy + & |
---|
2074 | ( tunnel_width_y * 0.5_wp - td ) ) |
---|
2075 | ENDIF |
---|
2076 | |
---|
2077 | topo = 0 |
---|
2078 | DO i = nxl, nxr |
---|
2079 | DO j = nys, nyn |
---|
2080 | ! |
---|
2081 | !-- Use heaviside function to model outer tunnel surface |
---|
2082 | hv_out = th * 0.5_wp * & |
---|
2083 | ( ( SIGN( 1.0_wp, i * dx - txs_out ) + 1.0_wp ) & |
---|
2084 | - ( SIGN( 1.0_wp, i * dx - txe_out ) + 1.0_wp ) ) |
---|
2085 | |
---|
2086 | hv_out = hv_out * 0.5_wp * & |
---|
2087 | ( ( SIGN( 1.0_wp, j * dy - tys_out ) + 1.0_wp ) & |
---|
2088 | - ( SIGN( 1.0_wp, j * dy - tye_out ) + 1.0_wp ) ) |
---|
2089 | ! |
---|
2090 | !-- Use heaviside function to model inner tunnel surface |
---|
2091 | hv_in = ( th - td ) * 0.5_wp * & |
---|
2092 | ( ( SIGN( 1.0_wp, i * dx - txs_in ) + 1.0_wp ) & |
---|
2093 | - ( SIGN( 1.0_wp, i * dx - txe_in ) + 1.0_wp ) ) |
---|
2094 | |
---|
2095 | hv_in = hv_in * 0.5_wp * & |
---|
2096 | ( ( SIGN( 1.0_wp, j * dy - tys_in ) + 1.0_wp ) & |
---|
2097 | - ( SIGN( 1.0_wp, j * dy - tye_in ) + 1.0_wp ) ) |
---|
2098 | ! |
---|
2099 | !-- Set flags at x-y-positions without any tunnel surface |
---|
2100 | IF ( hv_out - hv_in == 0.0_wp ) THEN |
---|
2101 | topo(nzb+1:nzt+1,j,i) = IBSET( topo(nzb+1:nzt+1,j,i), 0 ) |
---|
2102 | ! |
---|
2103 | !-- Set flags at x-y-positions with tunnel surfaces |
---|
2104 | ELSE |
---|
2105 | DO k = nzb + 1, nzt + 1 |
---|
2106 | ! |
---|
2107 | !-- Inner tunnel |
---|
2108 | IF ( hv_out - hv_in == th ) THEN |
---|
2109 | IF ( zw(k) <= hv_out ) THEN |
---|
2110 | topo(k,j,i) = IBCLR( topo(k,j,i), 0 ) |
---|
2111 | ELSE |
---|
2112 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
2113 | ENDIF |
---|
2114 | ENDIF |
---|
2115 | ! |
---|
2116 | !-- Lateral tunnel walls |
---|
2117 | IF ( hv_out - hv_in == td ) THEN |
---|
2118 | IF ( zw(k) <= hv_in ) THEN |
---|
2119 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
2120 | ELSEIF ( zw(k) > hv_in .AND. zw(k) <= hv_out ) THEN |
---|
2121 | topo(k,j,i) = IBCLR( topo(k,j,i), 0 ) |
---|
2122 | ELSEIF ( zw(k) > hv_out ) THEN |
---|
2123 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
2124 | ENDIF |
---|
2125 | ENDIF |
---|
2126 | ENDDO |
---|
2127 | ENDIF |
---|
2128 | ENDDO |
---|
2129 | ENDDO |
---|
2130 | |
---|
2131 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2132 | ! |
---|
2133 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann |
---|
2134 | !-- boundary conditions for topography. |
---|
2135 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
2136 | IF ( nys == 0 ) THEN |
---|
2137 | DO i = 1, nbgp |
---|
2138 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
2139 | ENDDO |
---|
2140 | ENDIF |
---|
2141 | IF ( nyn == ny ) THEN |
---|
2142 | DO i = 1, nbgp |
---|
2143 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
2144 | ENDDO |
---|
2145 | ENDIF |
---|
2146 | ENDIF |
---|
2147 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
2148 | IF ( nxl == 0 ) THEN |
---|
2149 | DO i = 1, nbgp |
---|
2150 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
2151 | ENDDO |
---|
2152 | ENDIF |
---|
2153 | IF ( nxr == nx ) THEN |
---|
2154 | DO i = 1, nbgp |
---|
2155 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
2156 | ENDDO |
---|
2157 | ENDIF |
---|
2158 | ENDIF |
---|
2159 | |
---|
2160 | CASE ( 'read_from_file' ) |
---|
2161 | ! |
---|
2162 | !-- Note, topography information have been already read. |
---|
2163 | !-- If required, further process topography, i.e. reference buildings on |
---|
2164 | !-- top of orography and set temporary 3D topography array, which is |
---|
2165 | !-- used later to set grid flags. Calling of this rouinte is also |
---|
2166 | !-- required in case of ASCII input, even though no distinction between |
---|
2167 | !-- terrain- and building height is made in this case. |
---|
2168 | CALL process_topography( topo ) |
---|
2169 | ! |
---|
2170 | !-- Filter holes resolved by only one grid-point |
---|
2171 | CALL filter_topography( topo ) |
---|
2172 | ! |
---|
2173 | !-- Exchange ghost-points, as well as add cyclic or Neumann boundary |
---|
2174 | !-- conditions. |
---|
2175 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2176 | ! |
---|
2177 | !-- Set lateral boundary conditions for topography on all ghost layers |
---|
2178 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
2179 | IF ( nys == 0 ) THEN |
---|
2180 | DO i = 1, nbgp |
---|
2181 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
2182 | ENDDO |
---|
2183 | ENDIF |
---|
2184 | IF ( nyn == ny ) THEN |
---|
2185 | DO i = 1, nbgp |
---|
2186 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
2187 | ENDDO |
---|
2188 | ENDIF |
---|
2189 | ENDIF |
---|
2190 | |
---|
2191 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
2192 | IF ( nxl == 0 ) THEN |
---|
2193 | DO i = 1, nbgp |
---|
2194 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
2195 | ENDDO |
---|
2196 | ENDIF |
---|
2197 | IF ( nxr == nx ) THEN |
---|
2198 | DO i = 1, nbgp |
---|
2199 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
2200 | ENDDO |
---|
2201 | ENDIF |
---|
2202 | ENDIF |
---|
2203 | |
---|
2204 | |
---|
2205 | CASE DEFAULT |
---|
2206 | ! |
---|
2207 | !-- The DEFAULT case is reached either if the parameter topography |
---|
2208 | !-- contains a wrong character string or if the user has defined a special |
---|
2209 | !-- case in the user interface. There, the subroutine user_init_grid |
---|
2210 | !-- checks which of these two conditions applies. |
---|
2211 | CALL user_init_grid( topo ) |
---|
2212 | CALL filter_topography( topo ) |
---|
2213 | |
---|
2214 | END SELECT |
---|
2215 | ! |
---|
2216 | !-- Consistency checks and index array initialization are only required for |
---|
2217 | !-- non-flat topography. |
---|
2218 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
2219 | ! |
---|
2220 | !-- In case of non-flat topography, check whether the convention how to |
---|
2221 | !-- define the topography grid has been set correctly, or whether the default |
---|
2222 | !-- is applicable. If this is not possible, abort. |
---|
2223 | IF ( TRIM( topography_grid_convention ) == ' ' ) THEN |
---|
2224 | IF ( TRIM( topography ) /= 'single_building' .AND. & |
---|
2225 | TRIM( topography ) /= 'single_street_canyon' .AND. & |
---|
2226 | TRIM( topography ) /= 'tunnel' .AND. & |
---|
2227 | TRIM( topography ) /= 'read_from_file') THEN |
---|
2228 | !-- The default value is not applicable here, because it is only valid |
---|
2229 | !-- for the four standard cases 'single_building', |
---|
2230 | !-- 'single_street_canyon', 'tunnel' and 'read_from_file' |
---|
2231 | !-- defined in init_grid. |
---|
2232 | WRITE( message_string, * ) & |
---|
2233 | 'The value for "topography_grid_convention" ', & |
---|
2234 | 'is not set. Its default value is & only valid for ', & |
---|
2235 | '"topography" = ''single_building'', ''tunnel'' ', & |
---|
2236 | '''single_street_canyon'' & or ''read_from_file''.', & |
---|
2237 | '& Choose ''cell_edge'' or ''cell_center''.' |
---|
2238 | CALL message( 'init_grid', 'PA0239', 1, 2, 0, 6, 0 ) |
---|
2239 | ELSE |
---|
2240 | !-- The default value is applicable here. |
---|
2241 | !-- Set convention according to topography. |
---|
2242 | IF ( TRIM( topography ) == 'single_building' .OR. & |
---|
2243 | TRIM( topography ) == 'single_street_canyon' ) THEN |
---|
2244 | topography_grid_convention = 'cell_edge' |
---|
2245 | ELSEIF ( TRIM( topography ) == 'read_from_file' .OR. & |
---|
2246 | TRIM( topography ) == 'tunnel') THEN |
---|
2247 | topography_grid_convention = 'cell_center' |
---|
2248 | ENDIF |
---|
2249 | ENDIF |
---|
2250 | ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND. & |
---|
2251 | TRIM( topography_grid_convention ) /= 'cell_center' ) THEN |
---|
2252 | WRITE( message_string, * ) & |
---|
2253 | 'The value for "topography_grid_convention" is ', & |
---|
2254 | 'not recognized.& Choose ''cell_edge'' or ''cell_center''.' |
---|
2255 | CALL message( 'init_grid', 'PA0240', 1, 2, 0, 6, 0 ) |
---|
2256 | ENDIF |
---|
2257 | |
---|
2258 | |
---|
2259 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
2260 | ! |
---|
2261 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
2262 | !-- describes the actual total size of topography which is defined at the |
---|
2263 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
2264 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
2265 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
2266 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
2267 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
2268 | !-- to form the basis for nzb_s_inner. |
---|
2269 | !-- Note, the reverse memory access (i-j instead of j-i) is absolutely |
---|
2270 | !-- required at this point. |
---|
2271 | DO j = nys+1, nyn+1 |
---|
2272 | DO i = nxl-1, nxr |
---|
2273 | DO k = nzb, nzt+1 |
---|
2274 | IF ( BTEST( topo(k,j,i), 0 ) .OR. & |
---|
2275 | BTEST( topo(k,j,i+1), 0 ) ) & |
---|
2276 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
2277 | ENDDO |
---|
2278 | ENDDO |
---|
2279 | ENDDO |
---|
2280 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2281 | |
---|
2282 | DO i = nxl, nxr+1 |
---|
2283 | DO j = nys-1, nyn |
---|
2284 | DO k = nzb, nzt+1 |
---|
2285 | IF ( BTEST( topo(k,j,i), 0 ) .OR. & |
---|
2286 | BTEST( topo(k,j+1,i), 0 ) ) & |
---|
2287 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
2288 | ENDDO |
---|
2289 | ENDDO |
---|
2290 | ENDDO |
---|
2291 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2292 | |
---|
2293 | ENDIF |
---|
2294 | ENDIF |
---|
2295 | |
---|
2296 | |
---|
2297 | END SUBROUTINE init_topo |
---|
2298 | |
---|
2299 | SUBROUTINE set_topo_flags(topo) |
---|
2300 | |
---|
2301 | USE control_parameters, & |
---|
2302 | ONLY: bc_lr_cyc, bc_ns_cyc, constant_flux_layer, land_surface, & |
---|
2303 | scalar_advec, topography, use_surface_fluxes, use_top_fluxes, & |
---|
2304 | urban_surface |
---|
2305 | |
---|
2306 | USE indices, & |
---|
2307 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, & |
---|
2308 | nzt, topo_top_ind, wall_flags_0 |
---|
2309 | |
---|
2310 | USE kinds |
---|
2311 | |
---|
2312 | IMPLICIT NONE |
---|
2313 | |
---|
2314 | INTEGER(iwp) :: i !< index variable along x |
---|
2315 | INTEGER(iwp) :: ibit !< integer bit position of topgraphy masking array |
---|
2316 | INTEGER(iwp) :: j !< index variable along y |
---|
2317 | INTEGER(iwp) :: k !< index variable along z |
---|
2318 | |
---|
2319 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
2320 | |
---|
2321 | ALLOCATE( wall_flags_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
2322 | wall_flags_0 = 0 |
---|
2323 | ! |
---|
2324 | !-- Set-up topography flags. First, set flags only for s, u, v and w-grid. |
---|
2325 | !-- Further special flags will be set in following loops. |
---|
2326 | DO i = nxl, nxr |
---|
2327 | DO j = nys, nyn |
---|
2328 | DO k = nzb, nzt+1 |
---|
2329 | ! |
---|
2330 | !-- scalar grid |
---|
2331 | IF ( BTEST( topo(k,j,i), 0 ) ) & |
---|
2332 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 ) |
---|
2333 | ! |
---|
2334 | !-- u grid |
---|
2335 | IF ( BTEST( topo(k,j,i), 0 ) .AND. & |
---|
2336 | BTEST( topo(k,j,i-1), 0 ) ) & |
---|
2337 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 ) |
---|
2338 | ! |
---|
2339 | !-- v grid |
---|
2340 | IF ( BTEST( topo(k,j,i), 0 ) .AND. & |
---|
2341 | BTEST( topo(k,j-1,i), 0 ) ) & |
---|
2342 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 2 ) |
---|
2343 | |
---|
2344 | ENDDO |
---|
2345 | |
---|
2346 | DO k = nzb, nzt |
---|
2347 | ! |
---|
2348 | !-- w grid |
---|
2349 | IF ( BTEST( topo(k,j,i), 0 ) .AND. & |
---|
2350 | BTEST( topo(k+1,j,i), 0 ) ) & |
---|
2351 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 3 ) |
---|
2352 | ENDDO |
---|
2353 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 3 ) |
---|
2354 | |
---|
2355 | ENDDO |
---|
2356 | ENDDO |
---|
2357 | |
---|
2358 | CALL exchange_horiz_int( wall_flags_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2359 | ! |
---|
2360 | !-- Set outer array for scalars to mask near-surface grid points. Note, on |
---|
2361 | !-- basis of flag 24 futher flags will be derived which are used to control |
---|
2362 | !-- production of subgrid TKE production near walls. |
---|
2363 | DO i = nxl, nxr |
---|
2364 | DO j = nys, nyn |
---|
2365 | DO k = nzb, nzt+1 |
---|
2366 | IF ( BTEST( wall_flags_0(k,j-1,i), 0 ) .AND. & |
---|
2367 | BTEST( wall_flags_0(k,j+1,i), 0 ) .AND. & |
---|
2368 | BTEST( wall_flags_0(k,j,i-1), 0 ) .AND. & |
---|
2369 | BTEST( wall_flags_0(k,j,i+1), 0 ) .AND. & |
---|
2370 | BTEST( wall_flags_0(k,j-1,i-1), 0 ) .AND. & |
---|
2371 | BTEST( wall_flags_0(k,j+1,i-1), 0 ) .AND. & |
---|
2372 | BTEST( wall_flags_0(k,j-1,i+1), 0 ) .AND. & |
---|
2373 | BTEST( wall_flags_0(k,j+1,i+1), 0 ) ) & |
---|
2374 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 24 ) |
---|
2375 | ENDDO |
---|
2376 | ENDDO |
---|
2377 | ENDDO |
---|
2378 | ! |
---|
2379 | !-- Set further special flags |
---|
2380 | DO i = nxl, nxr |
---|
2381 | DO j = nys, nyn |
---|
2382 | DO k = nzb, nzt+1 |
---|
2383 | ! |
---|
2384 | !-- scalar grid, former nzb_diff_s_inner. |
---|
2385 | !-- Note, use this flag also to mask topography in diffusion_u and |
---|
2386 | !-- diffusion_v along the vertical direction. In case of |
---|
2387 | !-- use_surface_fluxes, fluxes are calculated via MOST, else, simple |
---|
2388 | !-- gradient approach is applied. Please note, in case of u- and v- |
---|
2389 | !-- diffuison, a small error is made at edges (on the east side for u, |
---|
2390 | !-- at the north side for v), since topography on scalar grid point |
---|
2391 | !-- is used instead of topography on u/v-grid. As number of topography grid |
---|
2392 | !-- points on uv-grid is different than s-grid, different number of |
---|
2393 | !-- surface elements would be required. In order to avoid this, |
---|
2394 | !-- treat edges (u(k,j,i+1)) simply by a gradient approach, i.e. these |
---|
2395 | !-- points are not masked within diffusion_u. Tests had shown that the |
---|
2396 | !-- effect on the flow is negligible. |
---|
2397 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
2398 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
2399 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) |
---|
2400 | ELSE |
---|
2401 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) |
---|
2402 | ENDIF |
---|
2403 | |
---|
2404 | ENDDO |
---|
2405 | ! |
---|
2406 | !-- Special flag to control vertical diffusion at model top - former |
---|
2407 | !-- nzt_diff |
---|
2408 | wall_flags_0(:,j,i) = IBSET( wall_flags_0(:,j,i), 9 ) |
---|
2409 | IF ( use_top_fluxes ) & |
---|
2410 | wall_flags_0(nzt+1,j,i) = IBCLR( wall_flags_0(nzt+1,j,i), 9 ) |
---|
2411 | |
---|
2412 | |
---|
2413 | DO k = nzb+1, nzt |
---|
2414 | ! |
---|
2415 | !-- Special flag on u grid, former nzb_u_inner + 1, required |
---|
2416 | !-- for disturb_field and initialization. Do not disturb directly at |
---|
2417 | !-- topography, as well as initialize u with zero one grid point outside |
---|
2418 | !-- of topography. |
---|
2419 | IF ( BTEST( wall_flags_0(k-1,j,i), 1 ) .AND. & |
---|
2420 | BTEST( wall_flags_0(k,j,i), 1 ) .AND. & |
---|
2421 | BTEST( wall_flags_0(k+1,j,i), 1 ) ) & |
---|
2422 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 20 ) |
---|
2423 | ! |
---|
2424 | !-- Special flag on v grid, former nzb_v_inner + 1, required |
---|
2425 | !-- for disturb_field and initialization. Do not disturb directly at |
---|
2426 | !-- topography, as well as initialize v with zero one grid point outside |
---|
2427 | !-- of topography. |
---|
2428 | IF ( BTEST( wall_flags_0(k-1,j,i), 2 ) .AND. & |
---|
2429 | BTEST( wall_flags_0(k,j,i), 2 ) .AND. & |
---|
2430 | BTEST( wall_flags_0(k+1,j,i), 2 ) ) & |
---|
2431 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 ) |
---|
2432 | ! |
---|
2433 | !-- Special flag on scalar grid, former nzb_s_inner+1. Used for |
---|
2434 | !-- lpm_sgs_tke |
---|
2435 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
2436 | BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
2437 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
2438 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 25 ) |
---|
2439 | ! |
---|
2440 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in |
---|
2441 | !-- in production_e |
---|
2442 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
2443 | IF ( BTEST( wall_flags_0(k,j,i), 24 ) .AND. & |
---|
2444 | BTEST( wall_flags_0(k-1,j,i), 24 ) .AND. & |
---|
2445 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
2446 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 29 ) |
---|
2447 | ELSE |
---|
2448 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
2449 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 29 ) |
---|
2450 | ENDIF |
---|
2451 | ! |
---|
2452 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in |
---|
2453 | !-- in production_e |
---|
2454 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
2455 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
2456 | BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
2457 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
2458 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) |
---|
2459 | ELSE |
---|
2460 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
2461 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) |
---|
2462 | ENDIF |
---|
2463 | ENDDO |
---|
2464 | ! |
---|
2465 | !-- Flags indicating downward facing walls |
---|
2466 | DO k = nzb+1, nzt |
---|
2467 | ! |
---|
2468 | !-- Scalar grid |
---|
2469 | IF ( BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
2470 | .NOT. BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
2471 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 13 ) |
---|
2472 | ! |
---|
2473 | !-- Downward facing wall on u grid |
---|
2474 | IF ( BTEST( wall_flags_0(k-1,j,i), 1 ) .AND. & |
---|
2475 | .NOT. BTEST( wall_flags_0(k,j,i), 1 ) ) & |
---|
2476 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 15 ) |
---|
2477 | ! |
---|
2478 | !-- Downward facing wall on v grid |
---|
2479 | IF ( BTEST( wall_flags_0(k-1,j,i), 2 ) .AND. & |
---|
2480 | .NOT. BTEST( wall_flags_0(k,j,i), 2 ) ) & |
---|
2481 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 17 ) |
---|
2482 | ! |
---|
2483 | !-- Downward facing wall on w grid |
---|
2484 | IF ( BTEST( wall_flags_0(k-1,j,i), 3 ) .AND. & |
---|
2485 | .NOT. BTEST( wall_flags_0(k,j,i), 3 ) ) & |
---|
2486 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 19 ) |
---|
2487 | ENDDO |
---|
2488 | ! |
---|
2489 | !-- Flags indicating upward facing walls |
---|
2490 | DO k = nzb, nzt |
---|
2491 | ! |
---|
2492 | !-- Upward facing wall on scalar grid |
---|
2493 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
2494 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
2495 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 ) |
---|
2496 | ! |
---|
2497 | !-- Upward facing wall on u grid |
---|
2498 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 1 ) .AND. & |
---|
2499 | BTEST( wall_flags_0(k+1,j,i), 1 ) ) & |
---|
2500 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 14 ) |
---|
2501 | |
---|
2502 | ! |
---|
2503 | !-- Upward facing wall on v grid |
---|
2504 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 2 ) .AND. & |
---|
2505 | BTEST( wall_flags_0(k+1,j,i), 2 ) ) & |
---|
2506 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 16 ) |
---|
2507 | |
---|
2508 | ! |
---|
2509 | !-- Upward facing wall on w grid |
---|
2510 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 3 ) .AND. & |
---|
2511 | BTEST( wall_flags_0(k+1,j,i), 3 ) ) & |
---|
2512 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 ) |
---|
2513 | ! |
---|
2514 | !-- Special flag on scalar grid, former nzb_s_inner |
---|
2515 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .OR. & |
---|
2516 | BTEST( wall_flags_0(k,j,i), 12 ) .OR. & |
---|
2517 | BTEST( wall_flags_0(k,j,i), 13 ) ) & |
---|
2518 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 22 ) |
---|
2519 | ! |
---|
2520 | !-- Special flag on scalar grid, nzb_diff_s_inner - 1, required for |
---|
2521 | !-- flow_statistics |
---|
2522 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
2523 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
2524 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
2525 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) |
---|
2526 | ELSE |
---|
2527 | IF ( BTEST( wall_flags_0(k,j,i), 22 ) ) & |
---|
2528 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) |
---|
2529 | ENDIF |
---|
2530 | |
---|
2531 | |
---|
2532 | ENDDO |
---|
2533 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 22 ) |
---|
2534 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 23 ) |
---|
2535 | ! |
---|
2536 | !-- Set flags indicating that topography is close by in horizontal |
---|
2537 | !-- direction, i.e. flags that infold the topography. These will be used |
---|
2538 | !-- to set advection flags for passive scalars, where due to large |
---|
2539 | !-- gradients near buildings stationary numerical oscillations can produce |
---|
2540 | !-- unrealistically high concentrations. This is only necessary if |
---|
2541 | !-- WS-scheme is applied for scalar advection. Note, these flags will be |
---|
2542 | !-- only used for passive scalars such as chemical species or aerosols. |
---|
2543 | IF ( scalar_advec == 'ws-scheme' ) THEN |
---|
2544 | DO k = nzb, nzt |
---|
2545 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. ( & |
---|
2546 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i-1), 0 ) ) .OR.& |
---|
2547 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i-2), 0 ) ) .OR.& |
---|
2548 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i-3), 0 ) ) .OR.& |
---|
2549 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i+1), 0 ) ) .OR.& |
---|
2550 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i+2), 0 ) ) .OR.& |
---|
2551 | ANY( .NOT. BTEST( wall_flags_0(k,j-3:j+3,i+3), 0 ) ) .OR.& |
---|
2552 | ANY( .NOT. BTEST( wall_flags_0(k,j-1,i-3:i+3), 0 ) ) .OR.& |
---|
2553 | ANY( .NOT. BTEST( wall_flags_0(k,j-2,i-3:i+3), 0 ) ) .OR.& |
---|
2554 | ANY( .NOT. BTEST( wall_flags_0(k,j-3,i-3:i+3), 0 ) ) .OR.& |
---|
2555 | ANY( .NOT. BTEST( wall_flags_0(k,j+1,i-3:i+3), 0 ) ) .OR.& |
---|
2556 | ANY( .NOT. BTEST( wall_flags_0(k,j+2,i-3:i+3), 0 ) ) .OR.& |
---|
2557 | ANY( .NOT. BTEST( wall_flags_0(k,j+3,i-3:i+3), 0 ) ) & |
---|
2558 | ) ) & |
---|
2559 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 31 ) |
---|
2560 | |
---|
2561 | ENDDO |
---|
2562 | ENDIF |
---|
2563 | ENDDO |
---|
2564 | ENDDO |
---|
2565 | ! |
---|
2566 | !-- Finally, set identification flags indicating natural terrain or buildings. |
---|
2567 | !-- Natural terrain grid points. Information on the type of the surface is |
---|
2568 | !-- stored in bit 1 of 3D Integer array topo. However, this bit is only set |
---|
2569 | !-- when topography is read from file. In order to run the land-surface model |
---|
2570 | !-- also without topography information, set bit 1 explicitely in this case. |
---|
2571 | IF ( land_surface ) THEN |
---|
2572 | ! |
---|
2573 | !-- If no topography is initialized, the land-surface is at k = nzb. |
---|
2574 | IF ( TRIM( topography ) /= 'read_from_file' ) THEN |
---|
2575 | wall_flags_0(nzb,:,:) = IBSET( wall_flags_0(nzb,:,:), 5 ) |
---|
2576 | ELSE |
---|
2577 | DO i = nxl, nxr |
---|
2578 | DO j = nys, nyn |
---|
2579 | DO k = nzb, nzt+1 |
---|
2580 | ! |
---|
2581 | !-- Natural terrain grid point |
---|
2582 | IF ( BTEST( topo(k,j,i), 1 ) ) & |
---|
2583 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 5 ) |
---|
2584 | ENDDO |
---|
2585 | ENDDO |
---|
2586 | ENDDO |
---|
2587 | ENDIF |
---|
2588 | ENDIF |
---|
2589 | ! |
---|
2590 | !-- Building grid points. |
---|
2591 | IF ( urban_surface ) THEN |
---|
2592 | DO i = nxl, nxr |
---|
2593 | DO j = nys, nyn |
---|
2594 | DO k = nzb, nzt+1 |
---|
2595 | IF ( BTEST( topo(k,j,i), 2 ) ) & |
---|
2596 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 6 ) |
---|
2597 | ENDDO |
---|
2598 | ENDDO |
---|
2599 | ENDDO |
---|
2600 | ENDIF |
---|
2601 | ! |
---|
2602 | !-- Exchange ghost points for wall flags |
---|
2603 | CALL exchange_horiz_int( wall_flags_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
2604 | ! |
---|
2605 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann |
---|
2606 | !-- boundary conditions for topography. |
---|
2607 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
2608 | IF ( nys == 0 ) THEN |
---|
2609 | DO i = 1, nbgp |
---|
2610 | wall_flags_0(:,nys-i,:) = wall_flags_0(:,nys,:) |
---|
2611 | ENDDO |
---|
2612 | ENDIF |
---|
2613 | IF ( nyn == ny ) THEN |
---|
2614 | DO i = 1, nbgp |
---|
2615 | wall_flags_0(:,nyn+i,:) = wall_flags_0(:,nyn,:) |
---|
2616 | ENDDO |
---|
2617 | ENDIF |
---|
2618 | ENDIF |
---|
2619 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
2620 | IF ( nxl == 0 ) THEN |
---|
2621 | DO i = 1, nbgp |
---|
2622 | wall_flags_0(:,:,nxl-i) = wall_flags_0(:,:,nxl) |
---|
2623 | ENDDO |
---|
2624 | ENDIF |
---|
2625 | IF ( nxr == nx ) THEN |
---|
2626 | DO i = 1, nbgp |
---|
2627 | wall_flags_0(:,:,nxr+i) = wall_flags_0(:,:,nxr) |
---|
2628 | ENDDO |
---|
2629 | ENDIF |
---|
2630 | ENDIF |
---|
2631 | ! |
---|
2632 | !-- Pre-calculate topography top indices (former get_topography_top_index |
---|
2633 | !-- function) |
---|
2634 | ALLOCATE( topo_top_ind(nysg:nyng,nxlg:nxrg,0:4) ) |
---|
2635 | ! |
---|
2636 | !-- Uppermost topography index on scalar grid |
---|
2637 | ibit = 12 |
---|
2638 | topo_top_ind(:,:,0) = MAXLOC( & |
---|
2639 | MERGE( 1, 0, & |
---|
2640 | BTEST( wall_flags_0(:,:,:), ibit ) & |
---|
2641 | ), DIM = 1 & |
---|
2642 | ) - 1 |
---|
2643 | ! |
---|
2644 | !-- Uppermost topography index on u grid |
---|
2645 | ibit = 14 |
---|
2646 | topo_top_ind(:,:,1) = MAXLOC( & |
---|
2647 | MERGE( 1, 0, & |
---|
2648 | BTEST( wall_flags_0(:,:,:), ibit ) & |
---|
2649 | ), DIM = 1 & |
---|
2650 | ) - 1 |
---|
2651 | ! |
---|
2652 | !-- Uppermost topography index on v grid |
---|
2653 | ibit = 16 |
---|
2654 | topo_top_ind(:,:,2) = MAXLOC( & |
---|
2655 | MERGE( 1, 0, & |
---|
2656 | BTEST( wall_flags_0(:,:,:), ibit ) & |
---|
2657 | ), DIM = 1 & |
---|
2658 | ) - 1 |
---|
2659 | ! |
---|
2660 | !-- Uppermost topography index on w grid |
---|
2661 | ibit = 18 |
---|
2662 | topo_top_ind(:,:,3) = MAXLOC( & |
---|
2663 | MERGE( 1, 0, & |
---|
2664 | BTEST( wall_flags_0(:,:,:), ibit ) & |
---|
2665 | ), DIM = 1 & |
---|
2666 | ) - 1 |
---|
2667 | ! |
---|
2668 | !-- Uppermost topography index on scalar outer grid |
---|
2669 | ibit = 24 |
---|
2670 | topo_top_ind(:,:,4) = MAXLOC( & |
---|
2671 | MERGE( 1, 0, & |
---|
2672 | BTEST( wall_flags_0(:,:,:), ibit ) & |
---|
2673 | ), DIM = 1 & |
---|
2674 | ) - 1 |
---|
2675 | |
---|
2676 | END SUBROUTINE set_topo_flags |
---|
2677 | |
---|
2678 | |
---|
2679 | |
---|