1 | !> @file init_grid.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of PALM. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
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-2017 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: init_grid.f90 2129 2017-01-23 15:00:36Z scharf $ |
---|
27 | ! |
---|
28 | ! 2128 2017-01-23 15:00:03Z suehring |
---|
29 | ! Bugfix in setting topography from file in case of ocean simulations |
---|
30 | ! |
---|
31 | ! 2088 2016-12-19 16:30:25Z suehring |
---|
32 | ! Bugfix in generic topography in case of ocean simulations |
---|
33 | ! |
---|
34 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
35 | ! Anelastic approximation implemented |
---|
36 | ! |
---|
37 | ! 2021 2016-10-07 14:08:57Z suehring |
---|
38 | ! Bugfix: setting Neumann boundary conditions for topography required for |
---|
39 | ! topography flags in multigrid_noopt solver |
---|
40 | ! |
---|
41 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
42 | ! Forced header and separation lines into 80 columns |
---|
43 | ! |
---|
44 | ! 1994 2016-08-15 09:52:21Z suehring |
---|
45 | ! Bugfix in definition of generic topography |
---|
46 | ! |
---|
47 | ! 1982 2016-08-01 11:04:48Z suehring |
---|
48 | ! Bugfix concering consistency check for topography |
---|
49 | ! |
---|
50 | ! 1968 2016-07-18 12:01:49Z suehring |
---|
51 | ! Changed: PE-wise reading of topography file in order to avoid global definition |
---|
52 | ! of arrays nzb_local and nzb_tmp. Thereby, topography definition for single |
---|
53 | ! buildings and street canyons has changed, as well as flag setting for |
---|
54 | ! multigrid scheme. |
---|
55 | ! |
---|
56 | ! Bugfix in checking l_grid anisotropy. |
---|
57 | ! Simplify initial computation of lwall and vertical_influence, i.e. remove |
---|
58 | ! nzb_s_inner as it is still zero at this point. |
---|
59 | ! |
---|
60 | ! 1942 2016-06-14 12:18:18Z suehring |
---|
61 | ! Topography filter implemented to fill holes resolved by only one grid point. |
---|
62 | ! Initialization of flags for ws-scheme moved to advec_ws. |
---|
63 | ! |
---|
64 | ! 1931 2016-06-10 12:06:59Z suehring |
---|
65 | ! Rename multigrid into multigrid_noopt and multigrid_fast into multigrid |
---|
66 | ! |
---|
67 | ! 1910 2016-05-26 06:49:46Z raasch |
---|
68 | ! Bugfix: if topography is read from file, Neumann conditions are used for the |
---|
69 | ! nzb_local array (instead of cyclic conditions) in case that non-cyclic |
---|
70 | ! boundary conditions are switched on for the run |
---|
71 | ! |
---|
72 | ! 1902 2016-05-09 11:18:56Z suehring |
---|
73 | ! Set topography flags for multigrid solver only (not for multigrid_fast) |
---|
74 | ! |
---|
75 | ! 1886 2016-04-21 11:20:47Z suehring |
---|
76 | ! Bugfix: setting advection flags near walls |
---|
77 | ! reformulated index values for nzb_v_inner |
---|
78 | ! variable discriptions added in declaration block |
---|
79 | ! |
---|
80 | ! 1845 2016-04-08 08:29:13Z raasch |
---|
81 | ! nzb_2d removed |
---|
82 | ! |
---|
83 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
84 | ! Removed code for parameter file check (__check) |
---|
85 | ! |
---|
86 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
87 | ! coupling_char is trimmed at every place it occurs, because it can have |
---|
88 | ! different length now |
---|
89 | ! |
---|
90 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
91 | ! Introduction of nested domain feature |
---|
92 | ! |
---|
93 | ! 1743 2016-01-13 10:23:51Z raasch |
---|
94 | ! Bugfix for calculation of nzb_s_outer and nzb_u_outer at north boundary of |
---|
95 | ! total domain |
---|
96 | ! |
---|
97 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
98 | ! Renamed prandtl_layer to constant_flux_layer. |
---|
99 | ! |
---|
100 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
101 | ! Code annotations made doxygen readable |
---|
102 | ! |
---|
103 | ! 1677 2015-10-02 13:25:23Z boeske |
---|
104 | ! Bugfix: Ghost points are included in wall_flags_0 and wall_flags_00 |
---|
105 | ! |
---|
106 | ! 1675 2015-10-02 08:28:59Z gronemeier |
---|
107 | ! Bugfix: Definition of topography grid levels |
---|
108 | ! |
---|
109 | ! 1660 2015-09-21 08:15:16Z gronemeier |
---|
110 | ! Bugfix: Definition of topography grid levels if vertical grid stretching |
---|
111 | ! starts below the maximum topography height. |
---|
112 | ! |
---|
113 | ! 1580 2015-04-10 13:43:49Z suehring |
---|
114 | ! Bugfix: setting flags for 5th order scheme near buildings |
---|
115 | ! |
---|
116 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
117 | ! adjustments for psolver-queries |
---|
118 | ! |
---|
119 | ! 1557 2015-03-05 16:43:04Z suehring |
---|
120 | ! Adjustment for monotoinic limiter |
---|
121 | ! |
---|
122 | ! 1418 2014-06-06 13:05:08Z fricke |
---|
123 | ! Bugfix: Change if-condition for stretched grid in the ocean, with the old |
---|
124 | ! condition and a negative value for dz_stretch_level the condition |
---|
125 | ! was always true for the whole model domain |
---|
126 | ! |
---|
127 | ! 1409 2014-05-23 12:11:32Z suehring |
---|
128 | ! Bugfix: set wall_flags_0 at inflow and outflow boundary also for i <= nxlu |
---|
129 | ! j <= nysv |
---|
130 | ! |
---|
131 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
132 | ! REAL constants provided with KIND-attribute |
---|
133 | ! |
---|
134 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
135 | ! REAL constants defined as wp-kind |
---|
136 | ! |
---|
137 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
138 | ! ONLY-attribute added to USE-statements, |
---|
139 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
140 | ! kinds are defined in new module kinds, |
---|
141 | ! revision history before 2012 removed, |
---|
142 | ! comment fields (!:) to be used for variable explanations added to |
---|
143 | ! all variable declaration statements |
---|
144 | ! |
---|
145 | ! 1221 2013-09-10 08:59:13Z raasch |
---|
146 | ! wall_flags_00 introduced to hold bits 32-63, |
---|
147 | ! additional 3D-flag arrays for replacing the 2D-index array nzb_s_inner in |
---|
148 | ! loops optimized for openACC (pres + flow_statistics) |
---|
149 | ! |
---|
150 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
151 | ! unused variables removed |
---|
152 | ! |
---|
153 | ! 1069 2012-11-28 16:18:43Z maronga |
---|
154 | ! bugfix: added coupling_char to TOPOGRAPHY_DATA to allow topography in the |
---|
155 | ! ocean model in case of coupled runs |
---|
156 | ! |
---|
157 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
158 | ! code put under GPL (PALM 3.9) |
---|
159 | ! |
---|
160 | ! 1015 2012-09-27 09:23:24Z raasch |
---|
161 | ! lower index for calculating wall_flags_0 set to nzb_w_inner instead of |
---|
162 | ! nzb_w_inner+1 |
---|
163 | ! |
---|
164 | ! 996 2012-09-07 10:41:47Z raasch |
---|
165 | ! little reformatting |
---|
166 | ! |
---|
167 | ! 978 2012-08-09 08:28:32Z fricke |
---|
168 | ! Bugfix: nzb_max is set to nzt at non-cyclic lateral boundaries |
---|
169 | ! Bugfix: Set wall_flags_0 for inflow boundary |
---|
170 | ! |
---|
171 | ! 927 2012-06-06 19:15:04Z raasch |
---|
172 | ! Wall flags are not set for multigrid method in case of masking method |
---|
173 | ! |
---|
174 | ! 864 2012-03-27 15:10:33Z gryschka |
---|
175 | ! In case of ocean and Dirichlet bottom bc for u and v dzu_mg and ddzu_pres |
---|
176 | ! were not correctly defined for k=1. |
---|
177 | ! |
---|
178 | ! 861 2012-03-26 14:18:34Z suehring |
---|
179 | ! Set wall_flags_0. The array is needed for degradation in ws-scheme near walls, |
---|
180 | ! inflow and outflow boundaries as well as near the bottom and the top of the |
---|
181 | ! model domain.! |
---|
182 | ! Initialization of nzb_s_inner and nzb_w_inner. |
---|
183 | ! gls has to be at least nbgp to do not exceed the array bounds of nzb_local |
---|
184 | ! while setting wall_flags_0 |
---|
185 | ! |
---|
186 | ! 843 2012-02-29 15:16:21Z gryschka |
---|
187 | ! In case of ocean and dirichlet bc for u and v at the bottom |
---|
188 | ! the first u-level ist defined at same height as the first w-level |
---|
189 | ! |
---|
190 | ! 818 2012-02-08 16:11:23Z maronga |
---|
191 | ! Bugfix: topo_height is only required if topography is used. It is thus now |
---|
192 | ! allocated in the topography branch |
---|
193 | ! |
---|
194 | ! 809 2012-01-30 13:32:58Z maronga |
---|
195 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
196 | ! |
---|
197 | ! 807 2012-01-25 11:53:51Z maronga |
---|
198 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
199 | ! |
---|
200 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
201 | ! Initial revision (Testversion) |
---|
202 | ! |
---|
203 | ! |
---|
204 | ! Description: |
---|
205 | ! ------------ |
---|
206 | !> Creating grid depending constants |
---|
207 | !------------------------------------------------------------------------------! |
---|
208 | SUBROUTINE init_grid |
---|
209 | |
---|
210 | USE advec_ws, & |
---|
211 | ONLY: ws_init_flags |
---|
212 | |
---|
213 | USE arrays_3d, & |
---|
214 | ONLY: dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzu_mg, dzw, dzw_mg, f1_mg, & |
---|
215 | f2_mg, f3_mg, l_grid, l_wall, zu, zw |
---|
216 | |
---|
217 | USE control_parameters, & |
---|
218 | ONLY: bc_lr_cyc, bc_ns_cyc, building_height, building_length_x, & |
---|
219 | building_length_y, building_wall_left, building_wall_south, & |
---|
220 | canyon_height, canyon_wall_left, canyon_wall_south, & |
---|
221 | canyon_width_x, canyon_width_y, constant_flux_layer, & |
---|
222 | coupling_char, dp_level_ind_b, dz, dz_max, dz_stretch_factor, & |
---|
223 | dz_stretch_level, dz_stretch_level_index, grid_level, ibc_uv_b, & |
---|
224 | io_blocks, io_group, inflow_l, inflow_n, inflow_r, inflow_s, & |
---|
225 | masking_method, maximum_grid_level, message_string, & |
---|
226 | momentum_advec, nest_domain, nest_bound_l, nest_bound_n, & |
---|
227 | nest_bound_r, nest_bound_s, ocean, outflow_l, outflow_n, & |
---|
228 | outflow_r, outflow_s, psolver, scalar_advec, topography, & |
---|
229 | topography_grid_convention, use_surface_fluxes, use_top_fluxes, & |
---|
230 | wall_adjustment_factor |
---|
231 | |
---|
232 | USE grid_variables, & |
---|
233 | ONLY: ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, fwxm, & |
---|
234 | fwxp, fwym, fwyp, fxm, fxp, fym, fyp, wall_e_x, wall_e_y, & |
---|
235 | wall_u, wall_v, wall_w_x, wall_w_y, zu_s_inner, zw_w_inner |
---|
236 | |
---|
237 | USE indices, & |
---|
238 | ONLY: flags, nbgp, nx, nxl, nxlg, nxl_mg, nxr, nxrg, nxr_mg, & |
---|
239 | ny, nyn, nyng, nyn_mg, nys, nys_mg, nysg, nz, nzb, & |
---|
240 | nzb_diff, nzb_diff_s_inner, nzb_diff_s_outer, nzb_diff_u, & |
---|
241 | nzb_diff_v, nzb_max, nzb_s_inner, nzb_s_outer, nzb_u_inner, & |
---|
242 | nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner, & |
---|
243 | nzb_w_outer, nzt, nzt_diff, nzt_mg, rflags_invers, & |
---|
244 | rflags_s_inner, wall_flags_0, wall_flags_00, wall_flags_1, & |
---|
245 | wall_flags_10, wall_flags_2, wall_flags_3, wall_flags_4, & |
---|
246 | wall_flags_5, wall_flags_6, wall_flags_7, wall_flags_8, & |
---|
247 | wall_flags_9 |
---|
248 | |
---|
249 | USE kinds |
---|
250 | |
---|
251 | USE pegrid |
---|
252 | |
---|
253 | IMPLICIT NONE |
---|
254 | |
---|
255 | INTEGER(iwp) :: bh !< temporary vertical index of building height |
---|
256 | INTEGER(iwp) :: blx !< grid point number of building size along x |
---|
257 | INTEGER(iwp) :: bly !< grid point number of building size along y |
---|
258 | INTEGER(iwp) :: bxl !< index for left building wall |
---|
259 | INTEGER(iwp) :: bxr !< index for right building wall |
---|
260 | INTEGER(iwp) :: byn !< index for north building wall |
---|
261 | INTEGER(iwp) :: bys !< index for south building wall |
---|
262 | INTEGER(iwp) :: ch !< temporary vertical index for canyon height |
---|
263 | INTEGER(iwp) :: cwx !< grid point number of canyon size along x |
---|
264 | INTEGER(iwp) :: cwy !< grid point number of canyon size along y |
---|
265 | INTEGER(iwp) :: cxl !< index for left canyon wall |
---|
266 | INTEGER(iwp) :: cxr !< index for right canyon wall |
---|
267 | INTEGER(iwp) :: cyn !< index for north canyon wall |
---|
268 | INTEGER(iwp) :: cys !< index for south canyon wall |
---|
269 | INTEGER(iwp) :: i !< index variable along x |
---|
270 | INTEGER(iwp) :: ii !< loop variable for reading topography file |
---|
271 | INTEGER(iwp) :: inc !< incremental parameter for coarsening grid level |
---|
272 | INTEGER(iwp) :: j !< index variable along y |
---|
273 | INTEGER(iwp) :: k !< index variable along z |
---|
274 | INTEGER(iwp) :: l !< loop variable |
---|
275 | INTEGER(iwp) :: nxl_l !< index of left PE boundary for multigrid level |
---|
276 | INTEGER(iwp) :: nxr_l !< index of right PE boundary for multigrid level |
---|
277 | INTEGER(iwp) :: nyn_l !< index of north PE boundary for multigrid level |
---|
278 | INTEGER(iwp) :: nys_l !< index of south PE boundary for multigrid level |
---|
279 | INTEGER(iwp) :: nzb_local_max !< vertical grid index of maximum topography height |
---|
280 | INTEGER(iwp) :: nzb_local_min !< vertical grid index of minimum topography height |
---|
281 | INTEGER(iwp) :: nzb_si !< dummy index for local nzb_s_inner |
---|
282 | INTEGER(iwp) :: nzt_l !< index of top PE boundary for multigrid level |
---|
283 | INTEGER(iwp) :: num_hole !< number of holes (in topography) resolved by only one grid point |
---|
284 | INTEGER(iwp) :: num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE |
---|
285 | INTEGER(iwp) :: num_wall !< number of surrounding vertical walls for a single grid point |
---|
286 | INTEGER(iwp) :: skip_n_rows !< counting variable to skip rows while reading topography file |
---|
287 | INTEGER(iwp) :: vi !< dummy for vertical influence |
---|
288 | |
---|
289 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: & |
---|
290 | vertical_influence !< number of vertical grid points above obstacle where adjustment of near-wall mixing length is required |
---|
291 | |
---|
292 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_nl !< index of north-left corner location to limit near-wall mixing length |
---|
293 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_nr !< north-right |
---|
294 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_sl !< south-left |
---|
295 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_sr !< south-right |
---|
296 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !< index for topography top at cell-center |
---|
297 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_tmp !< dummy to calculate topography indices on u- and v-grid |
---|
298 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_l !< distance to adjacent left-facing wall |
---|
299 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_n !< north-facing |
---|
300 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_r !< right-facing |
---|
301 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_s !< right-facing |
---|
302 | |
---|
303 | REAL(wp) :: dum !< dummy variable to skip columns while reading topography file |
---|
304 | REAL(wp) :: dz_stretched !< stretched vertical grid spacing |
---|
305 | |
---|
306 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: topo_height !< input variable for topography height |
---|
307 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zu_s_inner_l !< dummy array on global scale to write topography output array |
---|
308 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: zw_w_inner_l !< dummy array on global scale to write topography output array |
---|
309 | |
---|
310 | |
---|
311 | ! |
---|
312 | !-- Calculation of horizontal array bounds including ghost layers |
---|
313 | nxlg = nxl - nbgp |
---|
314 | nxrg = nxr + nbgp |
---|
315 | nysg = nys - nbgp |
---|
316 | nyng = nyn + nbgp |
---|
317 | |
---|
318 | ! |
---|
319 | !-- Allocate grid arrays |
---|
320 | ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & |
---|
321 | dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) ) |
---|
322 | |
---|
323 | ! |
---|
324 | !-- Compute height of u-levels from constant grid length and dz stretch factors |
---|
325 | IF ( dz == -1.0_wp ) THEN |
---|
326 | message_string = 'missing dz' |
---|
327 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
328 | ELSEIF ( dz <= 0.0_wp ) THEN |
---|
329 | WRITE( message_string, * ) 'dz=',dz,' <= 0.0' |
---|
330 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
331 | ENDIF |
---|
332 | |
---|
333 | ! |
---|
334 | !-- Define the vertical grid levels |
---|
335 | IF ( .NOT. ocean ) THEN |
---|
336 | ! |
---|
337 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
338 | !-- The second u-level (k=1) corresponds to the top of the |
---|
339 | !-- Prandtl-layer. |
---|
340 | |
---|
341 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN |
---|
342 | zu(0) = 0.0_wp |
---|
343 | ! zu(0) = - dz * 0.5_wp |
---|
344 | ELSE |
---|
345 | zu(0) = - dz * 0.5_wp |
---|
346 | ENDIF |
---|
347 | zu(1) = dz * 0.5_wp |
---|
348 | |
---|
349 | dz_stretch_level_index = nzt+1 |
---|
350 | dz_stretched = dz |
---|
351 | DO k = 2, nzt+1 |
---|
352 | IF ( dz_stretch_level <= zu(k-1) .AND. dz_stretched < dz_max ) THEN |
---|
353 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
354 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
355 | IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1 |
---|
356 | ENDIF |
---|
357 | zu(k) = zu(k-1) + dz_stretched |
---|
358 | ENDDO |
---|
359 | |
---|
360 | ! |
---|
361 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
362 | !-- corresponding u-levels. In case of dirichlet bc for u and v at the |
---|
363 | !-- ground the first u- and w-level (k=0) are defined at same height (z=0). |
---|
364 | !-- The top w-level is extrapolated linearly. |
---|
365 | zw(0) = 0.0_wp |
---|
366 | DO k = 1, nzt |
---|
367 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
368 | ENDDO |
---|
369 | zw(nzt+1) = zw(nzt) + 2.0_wp * ( zu(nzt+1) - zw(nzt) ) |
---|
370 | |
---|
371 | ELSE |
---|
372 | ! |
---|
373 | !-- Grid for ocean with free water surface is at k=nzt (w-grid). |
---|
374 | !-- In case of neumann bc at the ground the first first u-level (k=0) lies |
---|
375 | !-- below the first w-level (k=0). In case of dirichlet bc the first u- and |
---|
376 | !-- w-level are defined at same height, but staggered from the second level. |
---|
377 | !-- The second u-level (k=1) corresponds to the top of the Prandtl-layer. |
---|
378 | zu(nzt+1) = dz * 0.5_wp |
---|
379 | zu(nzt) = - dz * 0.5_wp |
---|
380 | |
---|
381 | dz_stretch_level_index = 0 |
---|
382 | dz_stretched = dz |
---|
383 | DO k = nzt-1, 0, -1 |
---|
384 | ! |
---|
385 | !-- The default value of dz_stretch_level is positive, thus the first |
---|
386 | !-- condition is always true. Hence, the second condition is necessary. |
---|
387 | IF ( dz_stretch_level >= zu(k+1) .AND. dz_stretch_level <= 0.0 & |
---|
388 | .AND. dz_stretched < dz_max ) THEN |
---|
389 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
390 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
391 | IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1 |
---|
392 | ENDIF |
---|
393 | zu(k) = zu(k+1) - dz_stretched |
---|
394 | ENDDO |
---|
395 | |
---|
396 | ! |
---|
397 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
398 | !-- corresponding u-levels, except in case of dirichlet bc for u and v |
---|
399 | !-- at the ground. In this case the first u- and w-level are defined at |
---|
400 | !-- same height. The top w-level (nzt+1) is not used but set for |
---|
401 | !-- consistency, since w and all scalar variables are defined up tp nzt+1. |
---|
402 | zw(nzt+1) = dz |
---|
403 | zw(nzt) = 0.0_wp |
---|
404 | DO k = 0, nzt |
---|
405 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
406 | ENDDO |
---|
407 | |
---|
408 | ! |
---|
409 | !-- In case of dirichlet bc for u and v the first u- and w-level are defined |
---|
410 | !-- at same height. |
---|
411 | IF ( ibc_uv_b == 0 ) THEN |
---|
412 | zu(0) = zw(0) |
---|
413 | ENDIF |
---|
414 | |
---|
415 | ENDIF |
---|
416 | |
---|
417 | ! |
---|
418 | !-- Compute grid lengths. |
---|
419 | DO k = 1, nzt+1 |
---|
420 | dzu(k) = zu(k) - zu(k-1) |
---|
421 | ddzu(k) = 1.0_wp / dzu(k) |
---|
422 | dzw(k) = zw(k) - zw(k-1) |
---|
423 | ddzw(k) = 1.0_wp / dzw(k) |
---|
424 | ENDDO |
---|
425 | |
---|
426 | DO k = 1, nzt |
---|
427 | dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) ) |
---|
428 | ENDDO |
---|
429 | |
---|
430 | ! |
---|
431 | !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid |
---|
432 | !-- everywhere. For the actual grid, the grid spacing at the lowest level |
---|
433 | !-- is only dz/2, but should be dz. Therefore, an additional array |
---|
434 | !-- containing with appropriate grid information is created for these |
---|
435 | !-- solvers. |
---|
436 | IF ( psolver(1:9) /= 'multigrid' ) THEN |
---|
437 | ALLOCATE( ddzu_pres(1:nzt+1) ) |
---|
438 | ddzu_pres = ddzu |
---|
439 | ddzu_pres(1) = ddzu_pres(2) ! change for lowest level |
---|
440 | ENDIF |
---|
441 | |
---|
442 | ! |
---|
443 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
444 | ddx = 1.0_wp / dx |
---|
445 | ddy = 1.0_wp / dy |
---|
446 | dx2 = dx * dx |
---|
447 | dy2 = dy * dy |
---|
448 | ddx2 = 1.0_wp / dx2 |
---|
449 | ddy2 = 1.0_wp / dy2 |
---|
450 | |
---|
451 | ! |
---|
452 | !-- Compute the grid-dependent mixing length. |
---|
453 | DO k = 1, nzt |
---|
454 | l_grid(k) = ( dx * dy * dzw(k) )**0.33333333333333_wp |
---|
455 | ENDDO |
---|
456 | |
---|
457 | ! |
---|
458 | !-- Allocate outer and inner index arrays for topography and set |
---|
459 | !-- defaults. |
---|
460 | |
---|
461 | ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr), & |
---|
462 | corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr), & |
---|
463 | wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr), & |
---|
464 | wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) ) |
---|
465 | |
---|
466 | ALLOCATE( fwxm(nysg:nyng,nxlg:nxrg), fwxp(nysg:nyng,nxlg:nxrg), & |
---|
467 | fwym(nysg:nyng,nxlg:nxrg), fwyp(nysg:nyng,nxlg:nxrg), & |
---|
468 | fxm(nysg:nyng,nxlg:nxrg), fxp(nysg:nyng,nxlg:nxrg), & |
---|
469 | fym(nysg:nyng,nxlg:nxrg), fyp(nysg:nyng,nxlg:nxrg), & |
---|
470 | nzb_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
471 | nzb_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
472 | nzb_u_inner(nysg:nyng,nxlg:nxrg), & |
---|
473 | nzb_u_outer(nysg:nyng,nxlg:nxrg), & |
---|
474 | nzb_v_inner(nysg:nyng,nxlg:nxrg), & |
---|
475 | nzb_v_outer(nysg:nyng,nxlg:nxrg), & |
---|
476 | nzb_w_inner(nysg:nyng,nxlg:nxrg), & |
---|
477 | nzb_w_outer(nysg:nyng,nxlg:nxrg), & |
---|
478 | nzb_diff_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
479 | nzb_diff_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
480 | nzb_diff_u(nysg:nyng,nxlg:nxrg), & |
---|
481 | nzb_diff_v(nysg:nyng,nxlg:nxrg), & |
---|
482 | nzb_local(nysg:nyng,nxlg:nxrg), & |
---|
483 | nzb_tmp(nysg:nyng,nxlg:nxrg), & |
---|
484 | rflags_s_inner(nzb:nzt+2,nysg:nyng,nxlg:nxrg), & |
---|
485 | rflags_invers(nysg:nyng,nxlg:nxrg,nzb:nzt+2), & |
---|
486 | wall_e_x(nysg:nyng,nxlg:nxrg), & |
---|
487 | wall_e_y(nysg:nyng,nxlg:nxrg), & |
---|
488 | wall_u(nysg:nyng,nxlg:nxrg), & |
---|
489 | wall_v(nysg:nyng,nxlg:nxrg), & |
---|
490 | wall_w_x(nysg:nyng,nxlg:nxrg), & |
---|
491 | wall_w_y(nysg:nyng,nxlg:nxrg) ) |
---|
492 | |
---|
493 | |
---|
494 | |
---|
495 | ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
496 | |
---|
497 | |
---|
498 | nzb_s_inner = nzb; nzb_s_outer = nzb |
---|
499 | nzb_u_inner = nzb; nzb_u_outer = nzb |
---|
500 | nzb_v_inner = nzb; nzb_v_outer = nzb |
---|
501 | nzb_w_inner = nzb; nzb_w_outer = nzb |
---|
502 | |
---|
503 | rflags_s_inner = 1.0_wp |
---|
504 | rflags_invers = 1.0_wp |
---|
505 | |
---|
506 | ! |
---|
507 | !-- Define vertical gridpoint from (or to) which on the usual finite difference |
---|
508 | !-- form (which does not use surface fluxes) is applied |
---|
509 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
510 | nzb_diff = nzb + 2 |
---|
511 | ELSE |
---|
512 | nzb_diff = nzb + 1 |
---|
513 | ENDIF |
---|
514 | IF ( use_top_fluxes ) THEN |
---|
515 | nzt_diff = nzt - 1 |
---|
516 | ELSE |
---|
517 | nzt_diff = nzt |
---|
518 | ENDIF |
---|
519 | |
---|
520 | nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff |
---|
521 | nzb_diff_u = nzb_diff; nzb_diff_v = nzb_diff |
---|
522 | |
---|
523 | wall_e_x = 0.0_wp; wall_e_y = 0.0_wp; wall_u = 0.0_wp; wall_v = 0.0_wp |
---|
524 | wall_w_x = 0.0_wp; wall_w_y = 0.0_wp |
---|
525 | fwxp = 1.0_wp; fwxm = 1.0_wp; fwyp = 1.0_wp; fwym = 1.0_wp |
---|
526 | fxp = 1.0_wp; fxm = 1.0_wp; fyp = 1.0_wp; fym = 1.0_wp |
---|
527 | |
---|
528 | ! |
---|
529 | !-- Initialize near-wall mixing length l_wall only in the vertical direction |
---|
530 | !-- for the moment, |
---|
531 | !-- multiplication with wall_adjustment_factor near the end of this routine |
---|
532 | l_wall(nzb,:,:) = l_grid(1) |
---|
533 | DO k = nzb+1, nzt |
---|
534 | l_wall(k,:,:) = l_grid(k) |
---|
535 | ENDDO |
---|
536 | l_wall(nzt+1,:,:) = l_grid(nzt) |
---|
537 | |
---|
538 | ALLOCATE ( vertical_influence(nzb:nzt) ) |
---|
539 | DO k = 1, nzt |
---|
540 | vertical_influence(k) = MIN ( INT( l_grid(k) / & |
---|
541 | ( wall_adjustment_factor * dzw(k) ) + 0.5_wp ), nzt - k ) |
---|
542 | ENDDO |
---|
543 | |
---|
544 | DO k = 1, nzt |
---|
545 | IF ( l_grid(k) > 1.5_wp * dx * wall_adjustment_factor .OR. & |
---|
546 | l_grid(k) > 1.5_wp * dy * wall_adjustment_factor ) THEN |
---|
547 | WRITE( message_string, * ) 'grid anisotropy exceeds ', & |
---|
548 | 'threshold given by only local', & |
---|
549 | ' &horizontal reduction of near_wall ', & |
---|
550 | 'mixing length l_wall', & |
---|
551 | ' &starting from height level k = ', k, '.' |
---|
552 | CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 ) |
---|
553 | EXIT |
---|
554 | ENDIF |
---|
555 | ENDDO |
---|
556 | vertical_influence(0) = vertical_influence(1) |
---|
557 | |
---|
558 | DO k = nzb + 1, nzb + vertical_influence(nzb) |
---|
559 | l_wall(k,:,:) = zu(k) - zw(nzb) |
---|
560 | ENDDO |
---|
561 | |
---|
562 | ! |
---|
563 | !-- Set outer and inner index arrays for non-flat topography. |
---|
564 | !-- Here consistency checks concerning domain size and periodicity are |
---|
565 | !-- necessary. |
---|
566 | !-- Within this SELECT CASE structure only nzb_local is initialized |
---|
567 | !-- individually depending on the chosen topography type, all other index |
---|
568 | !-- arrays are initialized further below. |
---|
569 | SELECT CASE ( TRIM( topography ) ) |
---|
570 | |
---|
571 | CASE ( 'flat' ) |
---|
572 | ! |
---|
573 | !-- nzb_local is required for the multigrid solver |
---|
574 | nzb_local = 0 |
---|
575 | |
---|
576 | CASE ( 'single_building' ) |
---|
577 | ! |
---|
578 | !-- Single rectangular building, by default centered in the middle of the |
---|
579 | !-- total domain |
---|
580 | blx = NINT( building_length_x / dx ) |
---|
581 | bly = NINT( building_length_y / dy ) |
---|
582 | IF ( .NOT. ocean ) THEN |
---|
583 | bh = MINLOC( ABS( zw - building_height ), 1 ) - 1 |
---|
584 | ELSE |
---|
585 | bh = MINLOC( ABS( zw - zw(0) - building_height ), 1 ) - 1 |
---|
586 | ENDIF |
---|
587 | |
---|
588 | IF ( ABS( zw(bh ) - building_height ) == & |
---|
589 | ABS( zw(bh+1) - building_height ) ) bh = bh + 1 |
---|
590 | |
---|
591 | IF ( building_wall_left == 9999999.9_wp ) THEN |
---|
592 | building_wall_left = ( nx + 1 - blx ) / 2 * dx |
---|
593 | ENDIF |
---|
594 | bxl = NINT( building_wall_left / dx ) |
---|
595 | bxr = bxl + blx |
---|
596 | |
---|
597 | IF ( building_wall_south == 9999999.9_wp ) THEN |
---|
598 | building_wall_south = ( ny + 1 - bly ) / 2 * dy |
---|
599 | ENDIF |
---|
600 | bys = NINT( building_wall_south / dy ) |
---|
601 | byn = bys + bly |
---|
602 | |
---|
603 | ! |
---|
604 | !-- Building size has to meet some requirements |
---|
605 | IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & |
---|
606 | ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN |
---|
607 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
608 | '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & |
---|
609 | 'byn=', byn, 'nx=', nx, 'ny=', ny |
---|
610 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
611 | ENDIF |
---|
612 | |
---|
613 | ! |
---|
614 | !-- Define the building. |
---|
615 | nzb_local = 0 |
---|
616 | IF ( bxl <= nxr .AND. bxr >= nxl .AND. & |
---|
617 | bys <= nyn .AND. byn >= nys ) & |
---|
618 | nzb_local(MAX(nys,bys):MIN(nyn,byn),MAX(nxl,bxl):MIN(nxr,bxr)) = bh |
---|
619 | |
---|
620 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
621 | |
---|
622 | CASE ( 'single_street_canyon' ) |
---|
623 | ! |
---|
624 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
625 | !-- The canyon is centered in the other direction by default. |
---|
626 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
627 | ! |
---|
628 | !-- Street canyon in y direction |
---|
629 | cwx = NINT( canyon_width_x / dx ) |
---|
630 | IF ( canyon_wall_left == 9999999.9_wp ) THEN |
---|
631 | canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx |
---|
632 | ENDIF |
---|
633 | cxl = NINT( canyon_wall_left / dx ) |
---|
634 | cxr = cxl + cwx |
---|
635 | |
---|
636 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
637 | ! |
---|
638 | !-- Street canyon in x direction |
---|
639 | cwy = NINT( canyon_width_y / dy ) |
---|
640 | IF ( canyon_wall_south == 9999999.9_wp ) THEN |
---|
641 | canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy |
---|
642 | ENDIF |
---|
643 | cys = NINT( canyon_wall_south / dy ) |
---|
644 | cyn = cys + cwy |
---|
645 | |
---|
646 | ELSE |
---|
647 | |
---|
648 | message_string = 'no street canyon width given' |
---|
649 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
650 | |
---|
651 | ENDIF |
---|
652 | |
---|
653 | IF ( .NOT. ocean ) THEN |
---|
654 | ch = MINLOC( ABS( zw - canyon_height ), 1 ) - 1 |
---|
655 | ELSE |
---|
656 | ch = MINLOC( ABS( zw - zw(0) - canyon_height ), 1 ) - 1 |
---|
657 | ENDIF |
---|
658 | |
---|
659 | IF ( ABS( zw(ch ) - canyon_height ) == & |
---|
660 | ABS( zw(ch+1) - canyon_height ) ) ch = ch + 1 |
---|
661 | |
---|
662 | dp_level_ind_b = ch |
---|
663 | ! |
---|
664 | !-- Street canyon size has to meet some requirements |
---|
665 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
666 | IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & |
---|
667 | ( ch < 3 ) ) THEN |
---|
668 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
669 | '&cxl=', cxl, 'cxr=', cxr, & |
---|
670 | 'cwx=', cwx, & |
---|
671 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
672 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
673 | ENDIF |
---|
674 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
675 | IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & |
---|
676 | ( ch < 3 ) ) THEN |
---|
677 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
678 | '&cys=', cys, 'cyn=', cyn, & |
---|
679 | 'cwy=', cwy, & |
---|
680 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
681 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
682 | ENDIF |
---|
683 | ENDIF |
---|
684 | IF ( canyon_width_x /= 9999999.9_wp .AND. & |
---|
685 | canyon_width_y /= 9999999.9_wp ) THEN |
---|
686 | message_string = 'inconsistent canyon parameters:' // & |
---|
687 | '&street canyon can only be oriented' // & |
---|
688 | '&either in x- or in y-direction' |
---|
689 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
690 | ENDIF |
---|
691 | |
---|
692 | nzb_local = ch |
---|
693 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
694 | IF ( cxl <= nxr .AND. cxr >= nxl ) & |
---|
695 | nzb_local(:,MAX(nxl,cxl+1):MIN(nxr,cxr-1)) = 0 |
---|
696 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
697 | IF ( cys <= nyn .AND. cyn >= nys ) & |
---|
698 | nzb_local(MAX(nys,cys+1):MIN(nyn,cyn-1),:) = 0 |
---|
699 | ENDIF |
---|
700 | |
---|
701 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
702 | |
---|
703 | CASE ( 'read_from_file' ) |
---|
704 | |
---|
705 | ALLOCATE ( topo_height(nys:nyn,nxl:nxr) ) |
---|
706 | |
---|
707 | DO ii = 0, io_blocks-1 |
---|
708 | IF ( ii == io_group ) THEN |
---|
709 | |
---|
710 | ! |
---|
711 | !-- Arbitrary irregular topography data in PALM format (exactly |
---|
712 | !-- matching the grid size and total domain size) |
---|
713 | OPEN( 90, FILE='TOPOGRAPHY_DATA'//TRIM( coupling_char ), & |
---|
714 | STATUS='OLD', FORM='FORMATTED', ERR=10 ) |
---|
715 | ! |
---|
716 | !-- Read topography PE-wise. Rows are read from nyn to nys, columns |
---|
717 | !-- are read from nxl to nxr. At first, ny-nyn rows need to be skipped. |
---|
718 | skip_n_rows = 0 |
---|
719 | DO WHILE ( skip_n_rows < ny - nyn ) |
---|
720 | READ( 90, * ) |
---|
721 | skip_n_rows = skip_n_rows + 1 |
---|
722 | ENDDO |
---|
723 | ! |
---|
724 | !-- Read data from nyn to nys and nxl to nxr. Therefore, skip |
---|
725 | !-- column until nxl-1 is reached |
---|
726 | DO j = nyn, nys, -1 |
---|
727 | READ( 90, *, ERR=11, END=11 ) & |
---|
728 | ( dum, i = 0, nxl-1 ), & |
---|
729 | ( topo_height(j,i), i = nxl, nxr ) |
---|
730 | ENDDO |
---|
731 | |
---|
732 | GOTO 12 |
---|
733 | |
---|
734 | 10 message_string = 'file TOPOGRAPHY'//TRIM( coupling_char )// & |
---|
735 | ' does not exist' |
---|
736 | CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 ) |
---|
737 | |
---|
738 | 11 message_string = 'errors in file TOPOGRAPHY_DATA'// & |
---|
739 | TRIM( coupling_char ) |
---|
740 | CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 ) |
---|
741 | |
---|
742 | 12 CLOSE( 90 ) |
---|
743 | |
---|
744 | ENDIF |
---|
745 | #if defined( __parallel ) |
---|
746 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
747 | #endif |
---|
748 | ENDDO |
---|
749 | |
---|
750 | ! |
---|
751 | !-- Calculate the index height of the topography |
---|
752 | nzb_local = 0 |
---|
753 | DO i = nxl, nxr |
---|
754 | DO j = nys, nyn |
---|
755 | IF ( .NOT. ocean ) THEN |
---|
756 | nzb_local(j,i) = MINLOC( ABS( zw - topo_height(j,i) ), 1 ) - 1 |
---|
757 | IF ( ABS( zw(nzb_local(j,i) ) - topo_height(j,i) ) == & |
---|
758 | ABS( zw(nzb_local(j,i)+1) - topo_height(j,i) ) ) & |
---|
759 | nzb_local(j,i) = nzb_local(j,i) + 1 |
---|
760 | ELSE |
---|
761 | nzb_local(j,i) = MINLOC( ABS( zw - zw(0) & |
---|
762 | - topo_height(j,i) ), 1 ) - 1 |
---|
763 | IF ( ABS( zw(nzb_local(j,i) ) - zw(0) & |
---|
764 | - topo_height(j,i) ) == & |
---|
765 | ABS( zw(nzb_local(j,i)+1) - zw(0) & |
---|
766 | - topo_height(j,i) ) ) & |
---|
767 | nzb_local(j,i) = nzb_local(j,i) + 1 |
---|
768 | ENDIF |
---|
769 | |
---|
770 | ENDDO |
---|
771 | ENDDO |
---|
772 | |
---|
773 | DEALLOCATE ( topo_height ) |
---|
774 | ! |
---|
775 | !-- Filter topography, i.e. fill holes resolved by only one grid point. |
---|
776 | !-- Such holes are suspected to lead to velocity blow-ups as continuity |
---|
777 | !-- equation on discrete grid cannot be fulfilled in such case. |
---|
778 | !-- For now, check only for holes and fill them to the lowest height level |
---|
779 | !-- of the directly adjoining grid points along x- and y- direction. |
---|
780 | !-- Before checking for holes, set lateral boundary conditions for |
---|
781 | !-- topography. After hole-filling, boundary conditions must be set again! |
---|
782 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
783 | |
---|
784 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
785 | IF ( nys == 0 ) nzb_local(-1,:) = nzb_local(0,:) |
---|
786 | IF ( nyn == ny ) nzb_local(ny+1,:) = nzb_local(ny,:) |
---|
787 | ENDIF |
---|
788 | |
---|
789 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
790 | IF ( nxl == 0 ) nzb_local(:,-1) = nzb_local(:,0) |
---|
791 | IF ( nxr == nx ) nzb_local(:,nx+1) = nzb_local(:,nx) |
---|
792 | ENDIF |
---|
793 | |
---|
794 | num_hole_l = 0 |
---|
795 | DO i = nxl, nxr |
---|
796 | DO j = nys, nyn |
---|
797 | |
---|
798 | num_wall = 0 |
---|
799 | |
---|
800 | IF ( nzb_local(j-1,i) > nzb_local(j,i) ) & |
---|
801 | num_wall = num_wall + 1 |
---|
802 | IF ( nzb_local(j+1,i) > nzb_local(j,i) ) & |
---|
803 | num_wall = num_wall + 1 |
---|
804 | IF ( nzb_local(j,i-1) > nzb_local(j,i) ) & |
---|
805 | num_wall = num_wall + 1 |
---|
806 | IF ( nzb_local(j,i+1) > nzb_local(j,i) ) & |
---|
807 | num_wall = num_wall + 1 |
---|
808 | |
---|
809 | IF ( num_wall == 4 ) THEN |
---|
810 | nzb_local(j,i) = MIN( nzb_local(j-1,i), nzb_local(j+1,i), & |
---|
811 | nzb_local(j,i-1), nzb_local(j,i+1) ) |
---|
812 | num_hole_l = num_hole_l + 1 |
---|
813 | ENDIF |
---|
814 | ENDDO |
---|
815 | ENDDO |
---|
816 | ! |
---|
817 | !-- Count the total number of holes, required for informative message. |
---|
818 | #if defined( __parallel ) |
---|
819 | CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM, & |
---|
820 | comm2d, ierr ) |
---|
821 | #else |
---|
822 | num_hole = num_hole_l |
---|
823 | #endif |
---|
824 | ! |
---|
825 | !-- Create an informative message if any hole was removed. |
---|
826 | IF ( num_hole > 0 ) THEN |
---|
827 | WRITE( message_string, * ) num_hole, 'hole(s) resolved by only '//& |
---|
828 | 'one grid point were filled' |
---|
829 | CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 ) |
---|
830 | ENDIF |
---|
831 | ! |
---|
832 | !-- Exchange ghost-points, as well as add cyclic or Neumann boundary |
---|
833 | !-- conditions. |
---|
834 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
835 | |
---|
836 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
837 | IF ( nys == 0 ) nzb_local(-1,:) = nzb_local(0,:) |
---|
838 | IF ( nyn == ny ) nzb_local(ny+1,:) = nzb_local(ny,:) |
---|
839 | ENDIF |
---|
840 | |
---|
841 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
842 | IF ( nxl == 0 ) nzb_local(:,-1) = nzb_local(:,0) |
---|
843 | IF ( nxr == nx ) nzb_local(:,nx+1) = nzb_local(:,nx) |
---|
844 | ENDIF |
---|
845 | |
---|
846 | CASE DEFAULT |
---|
847 | ! |
---|
848 | !-- The DEFAULT case is reached either if the parameter topography |
---|
849 | !-- contains a wrong character string or if the user has defined a special |
---|
850 | !-- case in the user interface. There, the subroutine user_init_grid |
---|
851 | !-- checks which of these two conditions applies. |
---|
852 | CALL user_init_grid( nzb_local ) |
---|
853 | |
---|
854 | END SELECT |
---|
855 | ! |
---|
856 | !-- Determine the maximum level of topography. Furthermore it is used for |
---|
857 | !-- steering the degradation of order of the applied advection scheme. |
---|
858 | !-- In case of non-cyclic lateral boundaries, the order of the advection |
---|
859 | !-- scheme has to be reduced up to nzt (required at the lateral boundaries). |
---|
860 | #if defined( __parallel ) |
---|
861 | CALL MPI_ALLREDUCE( MAXVAL( nzb_local ) + 1, nzb_max, 1, MPI_INTEGER, & |
---|
862 | MPI_MAX, comm2d, ierr ) |
---|
863 | #else |
---|
864 | nzb_max = MAXVAL( nzb_local ) + 1 |
---|
865 | #endif |
---|
866 | IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR. & |
---|
867 | inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s .OR. & |
---|
868 | nest_domain ) & |
---|
869 | THEN |
---|
870 | nzb_max = nzt |
---|
871 | ENDIF |
---|
872 | |
---|
873 | ! |
---|
874 | !-- Consistency checks and index array initialization are only required for |
---|
875 | !-- non-flat topography, also the initialization of topography height arrays |
---|
876 | !-- zu_s_inner and zw_w_inner |
---|
877 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
878 | #if defined( __parallel ) |
---|
879 | CALL MPI_ALLREDUCE( MAXVAL( nzb_local ), nzb_local_max, 1, MPI_INTEGER, & |
---|
880 | MPI_MAX, comm2d, ierr ) |
---|
881 | CALL MPI_ALLREDUCE( MINVAL( nzb_local ), nzb_local_min, 1, MPI_INTEGER, & |
---|
882 | MPI_MIN, comm2d, ierr ) |
---|
883 | #else |
---|
884 | nzb_local_max = MAXVAL( nzb_local ) |
---|
885 | nzb_local_min = MINVAL( nzb_local ) |
---|
886 | #endif |
---|
887 | |
---|
888 | ! |
---|
889 | !-- Consistency checks |
---|
890 | IF ( nzb_local_min < 0 .OR. nzb_local_max > nz + 1 ) THEN |
---|
891 | WRITE( message_string, * ) 'nzb_local values are outside the', & |
---|
892 | 'model domain', & |
---|
893 | '&MINVAL( nzb_local ) = ', nzb_local_min, & |
---|
894 | '&MAXVAL( nzb_local ) = ', nzb_local_max |
---|
895 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
896 | ENDIF |
---|
897 | |
---|
898 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
899 | ! |
---|
900 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
901 | !-- describes the actual total size of topography which is defined at the |
---|
902 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
903 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
904 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
905 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
906 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
907 | !-- to form the basis for nzb_s_inner. |
---|
908 | !-- Note, the reverse memory access (i-j instead of j-i) is absolutely |
---|
909 | !-- required at this point. |
---|
910 | DO j = nys+1, nyn+1 |
---|
911 | DO i = nxl-1, nxr |
---|
912 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) ) |
---|
913 | ENDDO |
---|
914 | ENDDO |
---|
915 | ! |
---|
916 | !-- Exchange ghost points |
---|
917 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
918 | |
---|
919 | DO i = nxl, nxr+1 |
---|
920 | DO j = nys-1, nyn |
---|
921 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) ) |
---|
922 | ENDDO |
---|
923 | ENDDO |
---|
924 | ! |
---|
925 | !-- Exchange ghost points |
---|
926 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
927 | ENDIF |
---|
928 | ! |
---|
929 | !-- Initialize index arrays nzb_s_inner and nzb_w_inner |
---|
930 | nzb_s_inner = nzb_local |
---|
931 | nzb_w_inner = nzb_local |
---|
932 | |
---|
933 | ! |
---|
934 | !-- Initialize remaining index arrays: |
---|
935 | !-- first pre-initialize them with nzb_s_inner... |
---|
936 | nzb_u_inner = nzb_s_inner |
---|
937 | nzb_u_outer = nzb_s_inner |
---|
938 | nzb_v_inner = nzb_s_inner |
---|
939 | nzb_v_outer = nzb_s_inner |
---|
940 | nzb_w_outer = nzb_s_inner |
---|
941 | nzb_s_outer = nzb_s_inner |
---|
942 | |
---|
943 | ! |
---|
944 | !-- ...then extend pre-initialized arrays in their according directions |
---|
945 | !-- based on nzb_local using nzb_tmp as a temporary global index array |
---|
946 | |
---|
947 | ! |
---|
948 | !-- nzb_s_outer: |
---|
949 | !-- extend nzb_local east-/westwards first, then north-/southwards |
---|
950 | nzb_tmp = nzb_local |
---|
951 | DO j = nys, nyn |
---|
952 | DO i = nxl, nxr |
---|
953 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & |
---|
954 | nzb_local(j,i+1) ) |
---|
955 | ENDDO |
---|
956 | ENDDO |
---|
957 | |
---|
958 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
959 | |
---|
960 | DO i = nxl, nxr |
---|
961 | DO j = nys, nyn |
---|
962 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
963 | nzb_tmp(j+1,i) ) |
---|
964 | ENDDO |
---|
965 | ! |
---|
966 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
967 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
968 | IF ( nys == 0 ) THEN |
---|
969 | j = -1 |
---|
970 | nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
971 | ENDIF |
---|
972 | IF ( nyn == ny ) THEN |
---|
973 | j = ny + 1 |
---|
974 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
975 | ENDIF |
---|
976 | ENDDO |
---|
977 | ! |
---|
978 | !-- nzb_w_outer: |
---|
979 | !-- identical to nzb_s_outer |
---|
980 | nzb_w_outer = nzb_s_outer |
---|
981 | |
---|
982 | ! |
---|
983 | !-- nzb_u_inner: |
---|
984 | !-- extend nzb_local rightwards only |
---|
985 | nzb_tmp = nzb_local |
---|
986 | DO j = nys, nyn |
---|
987 | DO i = nxl, nxr |
---|
988 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) |
---|
989 | ENDDO |
---|
990 | ENDDO |
---|
991 | |
---|
992 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
993 | |
---|
994 | nzb_u_inner = nzb_tmp |
---|
995 | ! |
---|
996 | !-- nzb_u_outer: |
---|
997 | !-- extend current nzb_tmp (nzb_u_inner) north-/southwards |
---|
998 | DO i = nxl, nxr |
---|
999 | DO j = nys, nyn |
---|
1000 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
1001 | nzb_tmp(j+1,i) ) |
---|
1002 | ENDDO |
---|
1003 | ! |
---|
1004 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
1005 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
1006 | IF ( nys == 0 ) THEN |
---|
1007 | j = -1 |
---|
1008 | nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
1009 | ENDIF |
---|
1010 | IF ( nyn == ny ) THEN |
---|
1011 | j = ny + 1 |
---|
1012 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
1013 | ENDIF |
---|
1014 | ENDDO |
---|
1015 | |
---|
1016 | ! |
---|
1017 | !-- nzb_v_inner: |
---|
1018 | !-- extend nzb_local northwards only |
---|
1019 | nzb_tmp = nzb_local |
---|
1020 | DO i = nxl, nxr |
---|
1021 | DO j = nys, nyn |
---|
1022 | nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) |
---|
1023 | ENDDO |
---|
1024 | ENDDO |
---|
1025 | |
---|
1026 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
1027 | nzb_v_inner = nzb_tmp |
---|
1028 | |
---|
1029 | ! |
---|
1030 | !-- nzb_v_outer: |
---|
1031 | !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards |
---|
1032 | DO j = nys, nyn |
---|
1033 | DO i = nxl, nxr |
---|
1034 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & |
---|
1035 | nzb_tmp(j,i+1) ) |
---|
1036 | ENDDO |
---|
1037 | ! |
---|
1038 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
1039 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
1040 | IF ( nxl == 0 ) THEN |
---|
1041 | i = -1 |
---|
1042 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) |
---|
1043 | ENDIF |
---|
1044 | IF ( nxr == nx ) THEN |
---|
1045 | i = nx + 1 |
---|
1046 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) |
---|
1047 | ENDIF |
---|
1048 | ENDDO |
---|
1049 | |
---|
1050 | ! |
---|
1051 | !-- Exchange of lateral boundary values (parallel computers) and cyclic |
---|
1052 | !-- boundary conditions, if applicable. |
---|
1053 | !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local |
---|
1054 | !-- they do not require exchange and are not included here. |
---|
1055 | CALL exchange_horiz_2d_int( nzb_u_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
1056 | CALL exchange_horiz_2d_int( nzb_u_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
1057 | CALL exchange_horiz_2d_int( nzb_v_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
1058 | CALL exchange_horiz_2d_int( nzb_v_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
1059 | CALL exchange_horiz_2d_int( nzb_w_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
1060 | CALL exchange_horiz_2d_int( nzb_s_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
1061 | |
---|
1062 | ! |
---|
1063 | !-- Allocate and set the arrays containing the topography height |
---|
1064 | ALLOCATE( zu_s_inner(0:nx+1,0:ny+1), zw_w_inner(0:nx+1,0:ny+1), & |
---|
1065 | zu_s_inner_l(0:nx+1,0:ny+1), zw_w_inner_l(0:nx+1,0:ny+1) ) |
---|
1066 | |
---|
1067 | zu_s_inner = 0.0_wp |
---|
1068 | zw_w_inner = 0.0_wp |
---|
1069 | zu_s_inner_l = 0.0_wp |
---|
1070 | zw_w_inner_l = 0.0_wp |
---|
1071 | |
---|
1072 | DO i = nxl, nxr |
---|
1073 | DO j = nys, nyn |
---|
1074 | zu_s_inner_l(i,j) = zu(nzb_local(j,i)) |
---|
1075 | zw_w_inner_l(i,j) = zw(nzb_local(j,i)) |
---|
1076 | ENDDO |
---|
1077 | ENDDO |
---|
1078 | |
---|
1079 | #if defined( __parallel ) |
---|
1080 | CALL MPI_REDUCE( zu_s_inner_l, zu_s_inner, (nx+2)*(ny+2), & |
---|
1081 | MPI_REAL, MPI_SUM, 0, comm2d, ierr ) |
---|
1082 | CALL MPI_REDUCE( zw_w_inner_l, zw_w_inner, (nx+2)*(ny+2), & |
---|
1083 | MPI_REAL, MPI_SUM, 0, comm2d, ierr ) |
---|
1084 | #else |
---|
1085 | zu_s_inner = zu_s_inner_l |
---|
1086 | zw_w_inner = zw_w_inner_l |
---|
1087 | #endif |
---|
1088 | |
---|
1089 | DEALLOCATE( zu_s_inner_l, zw_w_inner_l ) |
---|
1090 | IF ( myid /= 0 ) DEALLOCATE( zu_s_inner, zw_w_inner ) |
---|
1091 | ! |
---|
1092 | !-- Set south and left ghost points, required for netcdf output |
---|
1093 | IF ( myid == 0 ) THEN |
---|
1094 | IF( bc_lr_cyc ) THEN |
---|
1095 | zu_s_inner(nx+1,:) = zu_s_inner(0,:) |
---|
1096 | zw_w_inner(nx+1,:) = zw_w_inner(0,:) |
---|
1097 | ELSE |
---|
1098 | zu_s_inner(nx+1,:) = zu_s_inner(nx,:) |
---|
1099 | zw_w_inner(nx+1,:) = zw_w_inner(nx,:) |
---|
1100 | ENDIF |
---|
1101 | IF( bc_ns_cyc ) THEN |
---|
1102 | zu_s_inner(:,ny+1) = zu_s_inner(:,0) |
---|
1103 | zw_w_inner(:,ny+1) = zw_w_inner(:,0) |
---|
1104 | ELSE |
---|
1105 | zu_s_inner(:,ny+1) = zu_s_inner(:,ny) |
---|
1106 | zw_w_inner(:,ny+1) = zw_w_inner(:,ny) |
---|
1107 | ENDIF |
---|
1108 | ENDIF |
---|
1109 | ! |
---|
1110 | !-- Set flag arrays to be used for masking of grid points |
---|
1111 | DO i = nxlg, nxrg |
---|
1112 | DO j = nysg, nyng |
---|
1113 | DO k = nzb, nzt+1 |
---|
1114 | IF ( k <= nzb_s_inner(j,i) ) rflags_s_inner(k,j,i) = 0.0_wp |
---|
1115 | IF ( k <= nzb_s_inner(j,i) ) rflags_invers(j,i,k) = 0.0_wp |
---|
1116 | ENDDO |
---|
1117 | ENDDO |
---|
1118 | ENDDO |
---|
1119 | |
---|
1120 | ENDIF |
---|
1121 | ! |
---|
1122 | !-- Deallocate temporary array, as it might be reused for different |
---|
1123 | !-- grid-levels further below. |
---|
1124 | DEALLOCATE( nzb_tmp ) |
---|
1125 | |
---|
1126 | ! |
---|
1127 | !-- Set the individual index arrays which define the k index from which on |
---|
1128 | !-- the usual finite difference form (which does not use surface fluxes) is |
---|
1129 | !-- applied |
---|
1130 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
1131 | nzb_diff_u = nzb_u_inner + 2 |
---|
1132 | nzb_diff_v = nzb_v_inner + 2 |
---|
1133 | nzb_diff_s_inner = nzb_s_inner + 2 |
---|
1134 | nzb_diff_s_outer = nzb_s_outer + 2 |
---|
1135 | ELSE |
---|
1136 | nzb_diff_u = nzb_u_inner + 1 |
---|
1137 | nzb_diff_v = nzb_v_inner + 1 |
---|
1138 | nzb_diff_s_inner = nzb_s_inner + 1 |
---|
1139 | nzb_diff_s_outer = nzb_s_outer + 1 |
---|
1140 | ENDIF |
---|
1141 | |
---|
1142 | ! |
---|
1143 | !-- Calculation of wall switches and factors required by diffusion_u/v.f90 and |
---|
1144 | !-- for limitation of near-wall mixing length l_wall further below |
---|
1145 | corner_nl = 0 |
---|
1146 | corner_nr = 0 |
---|
1147 | corner_sl = 0 |
---|
1148 | corner_sr = 0 |
---|
1149 | wall_l = 0 |
---|
1150 | wall_n = 0 |
---|
1151 | wall_r = 0 |
---|
1152 | wall_s = 0 |
---|
1153 | |
---|
1154 | DO i = nxl, nxr |
---|
1155 | DO j = nys, nyn |
---|
1156 | ! |
---|
1157 | !-- u-component |
---|
1158 | IF ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) THEN |
---|
1159 | wall_u(j,i) = 1.0_wp ! north wall (location of adjacent fluid) |
---|
1160 | fym(j,i) = 0.0_wp |
---|
1161 | fyp(j,i) = 1.0_wp |
---|
1162 | ELSEIF ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) THEN |
---|
1163 | wall_u(j,i) = 1.0_wp ! south wall (location of adjacent fluid) |
---|
1164 | fym(j,i) = 1.0_wp |
---|
1165 | fyp(j,i) = 0.0_wp |
---|
1166 | ENDIF |
---|
1167 | ! |
---|
1168 | !-- v-component |
---|
1169 | IF ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) ) THEN |
---|
1170 | wall_v(j,i) = 1.0_wp ! rigth wall (location of adjacent fluid) |
---|
1171 | fxm(j,i) = 0.0_wp |
---|
1172 | fxp(j,i) = 1.0_wp |
---|
1173 | ELSEIF ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) ) THEN |
---|
1174 | wall_v(j,i) = 1.0_wp ! left wall (location of adjacent fluid) |
---|
1175 | fxm(j,i) = 1.0_wp |
---|
1176 | fxp(j,i) = 0.0_wp |
---|
1177 | ENDIF |
---|
1178 | ! |
---|
1179 | !-- w-component, also used for scalars, separate arrays for shear |
---|
1180 | !-- production of tke |
---|
1181 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) ) THEN |
---|
1182 | wall_e_y(j,i) = 1.0_wp ! north wall (location of adjacent fluid) |
---|
1183 | wall_w_y(j,i) = 1.0_wp |
---|
1184 | fwym(j,i) = 0.0_wp |
---|
1185 | fwyp(j,i) = 1.0_wp |
---|
1186 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) ) THEN |
---|
1187 | wall_e_y(j,i) = -1.0_wp ! south wall (location of adjacent fluid) |
---|
1188 | wall_w_y(j,i) = 1.0_wp |
---|
1189 | fwym(j,i) = 1.0_wp |
---|
1190 | fwyp(j,i) = 0.0_wp |
---|
1191 | ENDIF |
---|
1192 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) ) THEN |
---|
1193 | wall_e_x(j,i) = 1.0_wp ! right wall (location of adjacent fluid) |
---|
1194 | wall_w_x(j,i) = 1.0_wp |
---|
1195 | fwxm(j,i) = 0.0_wp |
---|
1196 | fwxp(j,i) = 1.0_wp |
---|
1197 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) ) THEN |
---|
1198 | wall_e_x(j,i) = -1.0_wp ! left wall (location of adjacent fluid) |
---|
1199 | wall_w_x(j,i) = 1.0_wp |
---|
1200 | fwxm(j,i) = 1.0_wp |
---|
1201 | fwxp(j,i) = 0.0_wp |
---|
1202 | ENDIF |
---|
1203 | ! |
---|
1204 | !-- Wall and corner locations inside buildings for limitation of |
---|
1205 | !-- near-wall mixing length l_wall |
---|
1206 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j+1,i) ) THEN |
---|
1207 | |
---|
1208 | wall_n(j,i) = nzb_s_inner(j+1,i) + 1 ! North wall |
---|
1209 | |
---|
1210 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
1211 | corner_nl(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northleft corner |
---|
1212 | nzb_s_inner(j,i-1) ) + 1 |
---|
1213 | ENDIF |
---|
1214 | |
---|
1215 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
1216 | corner_nr(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northright corner |
---|
1217 | nzb_s_inner(j,i+1) ) + 1 |
---|
1218 | ENDIF |
---|
1219 | |
---|
1220 | ENDIF |
---|
1221 | |
---|
1222 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j-1,i) ) THEN |
---|
1223 | |
---|
1224 | wall_s(j,i) = nzb_s_inner(j-1,i) + 1 ! South wall |
---|
1225 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
1226 | corner_sl(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southleft corner |
---|
1227 | nzb_s_inner(j,i-1) ) + 1 |
---|
1228 | ENDIF |
---|
1229 | |
---|
1230 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
1231 | corner_sr(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southright corner |
---|
1232 | nzb_s_inner(j,i+1) ) + 1 |
---|
1233 | ENDIF |
---|
1234 | |
---|
1235 | ENDIF |
---|
1236 | |
---|
1237 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
1238 | wall_l(j,i) = nzb_s_inner(j,i-1) + 1 ! Left wall |
---|
1239 | ENDIF |
---|
1240 | |
---|
1241 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
1242 | wall_r(j,i) = nzb_s_inner(j,i+1) + 1 ! Right wall |
---|
1243 | ENDIF |
---|
1244 | |
---|
1245 | ENDDO |
---|
1246 | ENDDO |
---|
1247 | ! |
---|
1248 | !-- Calculate wall flag arrays for the multigrid method. |
---|
1249 | !-- Please note, wall flags are only applied in the not cache-optimized |
---|
1250 | !-- version. |
---|
1251 | IF ( psolver == 'multigrid_noopt' ) THEN |
---|
1252 | |
---|
1253 | ! |
---|
1254 | !-- Gridpoint increment of the current level. |
---|
1255 | inc = 1 |
---|
1256 | DO l = maximum_grid_level, 1 , -1 |
---|
1257 | ! |
---|
1258 | !-- Set grid_level as it is required for exchange_horiz_2d_int |
---|
1259 | grid_level = l |
---|
1260 | |
---|
1261 | nxl_l = nxl_mg(l) |
---|
1262 | nxr_l = nxr_mg(l) |
---|
1263 | nys_l = nys_mg(l) |
---|
1264 | nyn_l = nyn_mg(l) |
---|
1265 | nzt_l = nzt_mg(l) |
---|
1266 | ! |
---|
1267 | !-- Assign the flag level to be calculated |
---|
1268 | SELECT CASE ( l ) |
---|
1269 | CASE ( 1 ) |
---|
1270 | flags => wall_flags_1 |
---|
1271 | CASE ( 2 ) |
---|
1272 | flags => wall_flags_2 |
---|
1273 | CASE ( 3 ) |
---|
1274 | flags => wall_flags_3 |
---|
1275 | CASE ( 4 ) |
---|
1276 | flags => wall_flags_4 |
---|
1277 | CASE ( 5 ) |
---|
1278 | flags => wall_flags_5 |
---|
1279 | CASE ( 6 ) |
---|
1280 | flags => wall_flags_6 |
---|
1281 | CASE ( 7 ) |
---|
1282 | flags => wall_flags_7 |
---|
1283 | CASE ( 8 ) |
---|
1284 | flags => wall_flags_8 |
---|
1285 | CASE ( 9 ) |
---|
1286 | flags => wall_flags_9 |
---|
1287 | CASE ( 10 ) |
---|
1288 | flags => wall_flags_10 |
---|
1289 | END SELECT |
---|
1290 | |
---|
1291 | ! |
---|
1292 | !-- Depending on the grid level, set the respective bits in case of |
---|
1293 | !-- neighbouring walls |
---|
1294 | !-- Bit 0: wall to the bottom |
---|
1295 | !-- Bit 1: wall to the top (not realized in remaining PALM code so far) |
---|
1296 | !-- Bit 2: wall to the south |
---|
1297 | !-- Bit 3: wall to the north |
---|
1298 | !-- Bit 4: wall to the left |
---|
1299 | !-- Bit 5: wall to the right |
---|
1300 | !-- Bit 6: inside building |
---|
1301 | |
---|
1302 | flags = 0 |
---|
1303 | |
---|
1304 | ! |
---|
1305 | !-- In case of masking method, flags are not set and multigrid method |
---|
1306 | !-- works like FFT-solver |
---|
1307 | IF ( .NOT. masking_method ) THEN |
---|
1308 | |
---|
1309 | ! |
---|
1310 | !-- Allocate temporary array for topography heights on coarser grid |
---|
1311 | !-- level. Please note, 2 ghoist points are required, in order to |
---|
1312 | !-- calculate flags() on the interior ghost point. |
---|
1313 | ALLOCATE( nzb_tmp(nys_l-2:nyn_l+2,nxl_l-2:nxr_l+2) ) |
---|
1314 | nzb_tmp = 0 |
---|
1315 | |
---|
1316 | DO i = nxl_l, nxr_l |
---|
1317 | DO j = nys_l, nyn_l |
---|
1318 | nzb_tmp(j,i) = nzb_local(j*inc,i*inc) |
---|
1319 | ENDDO |
---|
1320 | ENDDO |
---|
1321 | ! |
---|
1322 | !-- Exchange ghost points on respective multigrid level. 2 ghost points |
---|
1323 | !-- are required, in order to calculate flags on |
---|
1324 | !-- nys_l-1 / nyn_l+1 / nxl_l-1 / nxr_l+1. The alternative would be to |
---|
1325 | !-- exchange 3D-INTEGER array flags on the respective multigrid level. |
---|
1326 | CALL exchange_horiz_2d_int( nzb_tmp, nys_l, nyn_l, nxl_l, nxr_l, 2 ) |
---|
1327 | ! |
---|
1328 | !-- Set non-cyclic boundary conditions on respective multigrid level |
---|
1329 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
1330 | IF ( inflow_s .OR. outflow_s .OR. nest_bound_s ) THEN |
---|
1331 | nzb_tmp(-2,:) = nzb_tmp(0,:) |
---|
1332 | nzb_tmp(-1,:) = nzb_tmp(0,:) |
---|
1333 | ENDIF |
---|
1334 | IF ( inflow_n .OR. outflow_n .OR. nest_bound_n ) THEN |
---|
1335 | nzb_tmp(nyn_l+2,:) = nzb_tmp(nyn_l,:) |
---|
1336 | nzb_tmp(nyn_l+1,:) = nzb_tmp(nyn_l,:) |
---|
1337 | ENDIF |
---|
1338 | ENDIF |
---|
1339 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
1340 | IF ( inflow_l .OR. outflow_l .OR. nest_bound_l ) THEN |
---|
1341 | nzb_tmp(:,-2) = nzb_tmp(:,0) |
---|
1342 | nzb_tmp(:,-1) = nzb_tmp(:,0) |
---|
1343 | ENDIF |
---|
1344 | IF ( inflow_r .OR. outflow_r .OR. nest_bound_r ) THEN |
---|
1345 | nzb_tmp(:,nxr_l+1) = nzb_tmp(:,nxr_l) |
---|
1346 | nzb_tmp(:,nxr_l+2) = nzb_tmp(:,nxr_l) |
---|
1347 | ENDIF |
---|
1348 | ENDIF |
---|
1349 | |
---|
1350 | DO i = nxl_l-1, nxr_l+1 |
---|
1351 | DO j = nys_l-1, nyn_l+1 |
---|
1352 | DO k = nzb, nzt_l+1 |
---|
1353 | ! |
---|
1354 | !-- Inside/outside building (inside building does not need |
---|
1355 | !-- further tests for walls) |
---|
1356 | IF ( k*inc <= nzb_tmp(j,i) ) THEN |
---|
1357 | |
---|
1358 | flags(k,j,i) = IBSET( flags(k,j,i), 6 ) |
---|
1359 | |
---|
1360 | ELSE |
---|
1361 | ! |
---|
1362 | !-- Bottom wall |
---|
1363 | IF ( (k-1)*inc <= nzb_tmp(j,i) ) THEN |
---|
1364 | flags(k,j,i) = IBSET( flags(k,j,i), 0 ) |
---|
1365 | ENDIF |
---|
1366 | ! |
---|
1367 | !-- South wall |
---|
1368 | IF ( k*inc <= nzb_tmp(j-1,i) ) THEN |
---|
1369 | flags(k,j,i) = IBSET( flags(k,j,i), 2 ) |
---|
1370 | ENDIF |
---|
1371 | ! |
---|
1372 | !-- North wall |
---|
1373 | IF ( k*inc <= nzb_tmp(j+1,i) ) THEN |
---|
1374 | flags(k,j,i) = IBSET( flags(k,j,i), 3 ) |
---|
1375 | ENDIF |
---|
1376 | ! |
---|
1377 | !-- Left wall |
---|
1378 | IF ( k*inc <= nzb_tmp(j,i-1) ) THEN |
---|
1379 | flags(k,j,i) = IBSET( flags(k,j,i), 4 ) |
---|
1380 | ENDIF |
---|
1381 | ! |
---|
1382 | !-- Right wall |
---|
1383 | IF ( k*inc <= nzb_tmp(j,i+1) ) THEN |
---|
1384 | flags(k,j,i) = IBSET( flags(k,j,i), 5 ) |
---|
1385 | ENDIF |
---|
1386 | |
---|
1387 | ENDIF |
---|
1388 | |
---|
1389 | ENDDO |
---|
1390 | ENDDO |
---|
1391 | ENDDO |
---|
1392 | |
---|
1393 | DEALLOCATE( nzb_tmp ) |
---|
1394 | |
---|
1395 | ENDIF |
---|
1396 | |
---|
1397 | inc = inc * 2 |
---|
1398 | |
---|
1399 | ENDDO |
---|
1400 | ! |
---|
1401 | !-- Reset grid_level to "normal" grid |
---|
1402 | grid_level = 0 |
---|
1403 | |
---|
1404 | ENDIF |
---|
1405 | ! |
---|
1406 | !-- Allocate flags needed for masking walls. Even though these flags are only |
---|
1407 | !-- required in the ws-scheme, the arrays need to be allocated here as they are |
---|
1408 | !-- used in OpenACC directives. |
---|
1409 | ALLOCATE( wall_flags_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
1410 | wall_flags_00(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
1411 | wall_flags_0 = 0 |
---|
1412 | wall_flags_00 = 0 |
---|
1413 | ! |
---|
1414 | !-- Init flags for ws-scheme to degrade order of the numerics near walls, i.e. |
---|
1415 | !-- to decrease the numerical stencil appropriately. |
---|
1416 | IF ( momentum_advec == 'ws-scheme' .OR. scalar_advec == 'ws-scheme' .OR.& |
---|
1417 | scalar_advec == 'ws-scheme-mono' ) THEN |
---|
1418 | CALL ws_init_flags |
---|
1419 | ENDIF |
---|
1420 | |
---|
1421 | ! |
---|
1422 | !-- In case of topography: limit near-wall mixing length l_wall further: |
---|
1423 | !-- Go through all points of the subdomain one by one and look for the closest |
---|
1424 | !-- surface |
---|
1425 | IF ( TRIM(topography) /= 'flat' ) THEN |
---|
1426 | DO i = nxl, nxr |
---|
1427 | DO j = nys, nyn |
---|
1428 | |
---|
1429 | nzb_si = nzb_s_inner(j,i) |
---|
1430 | vi = vertical_influence(nzb_si) |
---|
1431 | |
---|
1432 | IF ( wall_n(j,i) > 0 ) THEN |
---|
1433 | ! |
---|
1434 | !-- North wall (y distance) |
---|
1435 | DO k = wall_n(j,i), nzb_si |
---|
1436 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), 0.5_wp * dy ) |
---|
1437 | ENDDO |
---|
1438 | ! |
---|
1439 | !-- Above North wall (yz distance) |
---|
1440 | DO k = nzb_si + 1, nzb_si + vi |
---|
1441 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), & |
---|
1442 | SQRT( 0.25_wp * dy**2 + & |
---|
1443 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1444 | ENDDO |
---|
1445 | ! |
---|
1446 | !-- Northleft corner (xy distance) |
---|
1447 | IF ( corner_nl(j,i) > 0 ) THEN |
---|
1448 | DO k = corner_nl(j,i), nzb_si |
---|
1449 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
1450 | 0.5_wp * SQRT( dx**2 + dy**2 ) ) |
---|
1451 | ENDDO |
---|
1452 | ! |
---|
1453 | !-- Above Northleft corner (xyz distance) |
---|
1454 | DO k = nzb_si + 1, nzb_si + vi |
---|
1455 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
1456 | SQRT( 0.25_wp * (dx**2 + dy**2) + & |
---|
1457 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1458 | ENDDO |
---|
1459 | ENDIF |
---|
1460 | ! |
---|
1461 | !-- Northright corner (xy distance) |
---|
1462 | IF ( corner_nr(j,i) > 0 ) THEN |
---|
1463 | DO k = corner_nr(j,i), nzb_si |
---|
1464 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
1465 | 0.5_wp * SQRT( dx**2 + dy**2 ) ) |
---|
1466 | ENDDO |
---|
1467 | ! |
---|
1468 | !-- Above northright corner (xyz distance) |
---|
1469 | DO k = nzb_si + 1, nzb_si + vi |
---|
1470 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
1471 | SQRT( 0.25_wp * (dx**2 + dy**2) + & |
---|
1472 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1473 | ENDDO |
---|
1474 | ENDIF |
---|
1475 | ENDIF |
---|
1476 | |
---|
1477 | IF ( wall_s(j,i) > 0 ) THEN |
---|
1478 | ! |
---|
1479 | !-- South wall (y distance) |
---|
1480 | DO k = wall_s(j,i), nzb_si |
---|
1481 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), 0.5_wp * dy ) |
---|
1482 | ENDDO |
---|
1483 | ! |
---|
1484 | !-- Above south wall (yz distance) |
---|
1485 | DO k = nzb_si + 1, nzb_si + vi |
---|
1486 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), & |
---|
1487 | SQRT( 0.25_wp * dy**2 + & |
---|
1488 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1489 | ENDDO |
---|
1490 | ! |
---|
1491 | !-- Southleft corner (xy distance) |
---|
1492 | IF ( corner_sl(j,i) > 0 ) THEN |
---|
1493 | DO k = corner_sl(j,i), nzb_si |
---|
1494 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1495 | 0.5_wp * SQRT( dx**2 + dy**2 ) ) |
---|
1496 | ENDDO |
---|
1497 | ! |
---|
1498 | !-- Above southleft corner (xyz distance) |
---|
1499 | DO k = nzb_si + 1, nzb_si + vi |
---|
1500 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1501 | SQRT( 0.25_wp * (dx**2 + dy**2) + & |
---|
1502 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1503 | ENDDO |
---|
1504 | ENDIF |
---|
1505 | ! |
---|
1506 | !-- Southright corner (xy distance) |
---|
1507 | IF ( corner_sr(j,i) > 0 ) THEN |
---|
1508 | DO k = corner_sr(j,i), nzb_si |
---|
1509 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1510 | 0.5_wp * SQRT( dx**2 + dy**2 ) ) |
---|
1511 | ENDDO |
---|
1512 | ! |
---|
1513 | !-- Above southright corner (xyz distance) |
---|
1514 | DO k = nzb_si + 1, nzb_si + vi |
---|
1515 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1516 | SQRT( 0.25_wp * (dx**2 + dy**2) + & |
---|
1517 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1518 | ENDDO |
---|
1519 | ENDIF |
---|
1520 | |
---|
1521 | ENDIF |
---|
1522 | |
---|
1523 | IF ( wall_l(j,i) > 0 ) THEN |
---|
1524 | ! |
---|
1525 | !-- Left wall (x distance) |
---|
1526 | DO k = wall_l(j,i), nzb_si |
---|
1527 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), 0.5_wp * dx ) |
---|
1528 | ENDDO |
---|
1529 | ! |
---|
1530 | !-- Above left wall (xz distance) |
---|
1531 | DO k = nzb_si + 1, nzb_si + vi |
---|
1532 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), & |
---|
1533 | SQRT( 0.25_wp * dx**2 + & |
---|
1534 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1535 | ENDDO |
---|
1536 | ENDIF |
---|
1537 | |
---|
1538 | IF ( wall_r(j,i) > 0 ) THEN |
---|
1539 | ! |
---|
1540 | !-- Right wall (x distance) |
---|
1541 | DO k = wall_r(j,i), nzb_si |
---|
1542 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), 0.5_wp * dx ) |
---|
1543 | ENDDO |
---|
1544 | ! |
---|
1545 | !-- Above right wall (xz distance) |
---|
1546 | DO k = nzb_si + 1, nzb_si + vi |
---|
1547 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), & |
---|
1548 | SQRT( 0.25_wp * dx**2 + & |
---|
1549 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1550 | ENDDO |
---|
1551 | |
---|
1552 | ENDIF |
---|
1553 | |
---|
1554 | ENDDO |
---|
1555 | ENDDO |
---|
1556 | |
---|
1557 | ENDIF |
---|
1558 | |
---|
1559 | ! |
---|
1560 | !-- Multiplication with wall_adjustment_factor |
---|
1561 | l_wall = wall_adjustment_factor * l_wall |
---|
1562 | |
---|
1563 | ! |
---|
1564 | !-- Set lateral boundary conditions for l_wall |
---|
1565 | CALL exchange_horiz( l_wall, nbgp ) |
---|
1566 | |
---|
1567 | DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, & |
---|
1568 | vertical_influence, wall_l, wall_n, wall_r, wall_s ) |
---|
1569 | |
---|
1570 | |
---|
1571 | END SUBROUTINE init_grid |
---|