source: palm/trunk/SOURCE/init_3d_model.f90 @ 4877

Last change on this file since 4877 was 4877, checked in by suehring, 3 years ago

Bugfix in initialization of vertical surfaces with roughness and surface heat fluxes

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to (toggle deleted branches)
    /palm/branches/chemistry/SOURCE/init_3d_model.f902047-3190,​3218-3297
    /palm/branches/rans/SOURCE/init_3d_model.f902078-3128
    /palm/branches/resler/SOURCE/init_3d_model.f902023-4492
    /palm/branches/salsa/SOURCE/init_3d_model.f902503-3581
    /palm/branches/forwind/SOURCE/init_3d_model.f901564-1913
    /palm/branches/mosaik_M2/init_3d_model.f902360-3471
    /palm/branches/palm4u/SOURCE/init_3d_model.f902540-2692
File size: 85.2 KB
Line 
1!> @file init_3d_model.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 terms of the GNU General
6! Public License as published by the Free Software Foundation, either version 3 of the License, or
7! (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11! Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with PALM. If not, see
14! <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2021 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: init_3d_model.f90 4877 2021-02-17 16:17:35Z suehring $
26! Bugfix in initialization of vertical surfaces with roughness and surface heat fluxes
27!
28! 4848 2021-01-21 15:51:51Z gronemeier
29! replaced use_syn_turb_gen by syn_turb_gen
30!
31! 4845 2021-01-18 11:15:37Z raasch
32! removed allocation and initialization of arrays required for radiation boundary conditions
33!
34! 4828 2021-01-05 11:21:41Z Giersch
35! Add possibility to initialize surface flux of passive scalar via static driver
36!
37! 4783 2020-11-13 13:58:45Z raasch
38! bugfix for reading restart data with MPI-I/O (does not work with blockwise I/O)
39!
40! 4680 2020-09-16 10:20:34Z gronemeier
41! Add option to fix date or time of the simulation
42!
43! 4671 2020-09-09 20:27:58Z pavelkrc
44! Implementation of downward facing USM and LSM surfaces
45!
46! 4648 2020-08-25 07:52:08Z raasch
47! file re-formatted to follow the PALM coding standard
48!
49! 4548 2020-05-28 19:36:45Z suehring
50! Bugfix, move call for lsf_forcing_surf after lsf_init is called
51!
52! 4514 2020-04-30 16:29:59Z suehring
53! Add possibility to initialize surface sensible and latent heat fluxes via a static driver.
54!
55! 4493 2020-04-10 09:49:43Z pavelkrc
56! Overwrite u_init, v_init, pt_init, q_init and s_init with hom for all cyclic_fill-cases, not only
57! for turbulent_inflow = .TRUE.
58!
59! 4360 2020-01-07 11:25:50Z suehring
60! Introduction of wall_flags_total_0, which currently sets bits based on static topography
61! information used in wall_flags_static_0
62!
63! 4329 2019-12-10 15:46:36Z motisi
64! Renamed wall_flags_0 to wall_flags_static_0
65!
66! 4286 2019-10-30 16:01:14Z resler
67! implement new palm_date_time_mod
68!
69! 4223 2019-09-10 09:20:47Z gronemeier
70! Deallocate temporary string array since it may be re-used to read different input data in other
71! modules
72!
73! 4186 2019-08-23 16:06:14Z suehring
74! Design change, use variables defined in netcdf_data_input_mod to read netcd variables rather than
75! define local ones.
76!
77! 4185 2019-08-23 13:49:38Z oliver.maas
78! For initializing_actions = ' cyclic_fill':
79! Overwrite u_init, v_init, pt_init, q_init and s_init with the (temporally) and horizontally
80! averaged vertical profiles from the end of the prerun, because these profiles shall be used as the
81! basic state for the rayleigh damping and the pt_damping.
82!
83! 4182 2019-08-22 15:20:23Z scharf
84! Corrected "Former revisions" section
85!
86! 4168 2019-08-16 13:50:17Z suehring
87! Replace function get_topography_top_index by topo_top_ind
88!
89! 4151 2019-08-09 08:24:30Z suehring
90! Add netcdf directive around input calls (fix for last commit)
91!
92! 4150 2019-08-08 20:00:47Z suehring
93! Input of additional surface variables independent on land- or urban-surface model
94!
95! 4131 2019-08-02 11:06:18Z monakurppa
96! Allocate sums and sums_l to allow profile output for salsa variables.
97!
98! 4130 2019-08-01 13:04:13Z suehring
99! Effectively reduce 3D initialization to 1D initial profiles. This is because 3D initialization
100! produces structures in the w-component that are correlated with the processor grid for some
101! unknown reason
102!
103! 4090 2019-07-11 15:06:47Z Giersch
104! Unused variables removed
105!
106! 4088 2019-07-11 13:57:56Z Giersch
107! Pressure and density profile calculations revised using basic functions
108!
109! 4048 2019-06-21 21:00:21Z knoop
110! Further modularization of particle code components
111!
112! 4017 2019-06-06 12:16:46Z schwenkel
113! Convert most location messages to debug messages to reduce output in job logfile to a minimum
114!
115! unused variable removed
116!
117! 3937 2019-04-29 15:09:07Z suehring
118! Move initialization of synthetic turbulence generator behind initialization of offline nesting.
119! Remove call for stg_adjust, as this is now already done in stg_init.
120!
121! 3900 2019-04-16 15:17:43Z suehring
122! Fix problem with LOD = 2 initialization
123!
124! 3885 2019-04-11 11:29:34Z kanani
125! Changes related to global restructuring of location messages and introduction of additional debug
126! messages
127!
128! 3849 2019-04-01 16:35:16Z knoop
129! Move initialization of rmask before initializing user_init_arrays
130!
131! 3711 2019-01-31 13:44:26Z knoop
132! Introduced module_interface_init_checks for post-init checks in modules
133!
134! 3700 2019-01-26 17:03:42Z knoop
135! Some interface calls moved to module_interface + cleanup
136!
137! 3648 2019-01-02 16:35:46Z suehring
138! Rename subroutines for surface-data output
139!
140! Revision 1.1  1998/03/09 16:22:22  raasch
141! Initial revision
142!
143!
144! Description:
145! ------------
146!> Allocation of arrays and initialization of the 3D model via
147!> a) pre-run the 1D model
148!> or
149!> b) pre-set constant linear profiles
150!> or
151!> c) read values of a previous run
152!--------------------------------------------------------------------------------------------------!
153 SUBROUTINE init_3d_model
154
155
156    USE advec_ws
157
158    USE arrays_3d
159
160    USE basic_constants_and_equations_mod,                                                         &
161        ONLY:  barometric_formula, c_p, exner_function, exner_function_invers, g,                  &
162               ideal_gas_law_rho, ideal_gas_law_rho_pt, l_v, pi
163
164    USE bulk_cloud_model_mod,                                                                      &
165        ONLY:  bulk_cloud_model
166
167    USE chem_modules,                                                                              &
168        ONLY:  max_pr_cs ! ToDo: this dependency needs to be removed cause it is ugly #new_dom
169
170    USE control_parameters
171
172    USE exchange_horiz_mod,                                                                        &
173        ONLY:  exchange_horiz_2d
174
175    USE grid_variables,                                                                            &
176        ONLY:  dx, dy, ddx2_mg, ddy2_mg
177
178    USE indices
179
180    USE kinds
181
182    USE lsf_nudging_mod,                                                                           &
183        ONLY:  ls_forcing_surf
184
185    USE model_1d_mod,                                                                              &
186        ONLY:  init_1d_model, l1d, u1d, v1d
187
188    USE module_interface,                                                                          &
189        ONLY:  module_interface_init_arrays,                                                       &
190               module_interface_init,                                                              &
191               module_interface_init_checks
192
193    USE multi_agent_system_mod,                                                                    &
194        ONLY:  agents_active, mas_init
195
196    USE netcdf_interface,                                                                          &
197        ONLY:  dots_max
198
199    USE netcdf_data_input_mod,                                                                     &
200        ONLY:  char_fill,                                                                          &
201               check_existence,                                                                    &
202               close_input_file,                                                                   &
203               get_attribute,                                                                      &
204               get_variable,                                                                       &
205               init_3d,                                                                            &
206               input_pids_static,                                                                  &
207               inquire_num_variables,                                                              &
208               inquire_variable_names,                                                             &
209               input_file_static,                                                                  &
210               netcdf_data_input_init_3d,                                                          &
211               num_var_pids,                                                                       &
212               open_read_file,                                                                     &
213               pids_id,                                                                            &
214               real_2d,                                                                            &
215               resize_array,                                                                       &
216               vars_pids
217
218    USE nesting_offl_mod,                                                                          &
219        ONLY:  nesting_offl_init
220
221    USE palm_date_time_mod,                                                                        &
222        ONLY:  init_date_time
223
224    USE pegrid
225
226#if defined( __parallel )
227    USE pmc_interface,                                                                             &
228        ONLY:  nested_run
229#endif
230
231    USE random_function_mod
232
233    USE random_generator_parallel,                                                                 &
234        ONLY:  init_parallel_random_generator
235
236    USE read_restart_data_mod,                                                                     &
237        ONLY:  rrd_local, rrd_read_parts_of_global
238
239    USE statistics,                                                                                &
240        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask, statistic_regions, sums,   &
241               sums_divnew_l, sums_divold_l, sums_l, sums_l_l, sums_wsts_bc_l, ts_value,           &
242               weight_pres, weight_substep
243
244    USE synthetic_turbulence_generator_mod,                                                        &
245        ONLY:  stg_init
246
247    USE surface_layer_fluxes_mod,                                                                  &
248        ONLY:  init_surface_layer_fluxes
249
250    USE surface_mod,                                                                               &
251        ONLY :  init_single_surface_properties,                                                    &
252                init_surface_arrays,                                                               &
253                init_surfaces,                                                                     &
254                surf_def_h,                                                                        &
255                surf_def_v,                                                                        &
256                surf_lsm_h,                                                                        &
257                surf_usm_h
258
259#if defined( _OPENACC )
260    USE surface_mod,                                                                               &
261        ONLY :  bc_h
262#endif
263
264    USE surface_data_output_mod,                                                                   &
265        ONLY:  surface_data_output_init
266
267    USE transpose_indices
268
269
270    IMPLICIT NONE
271
272    INTEGER(iwp) ::  i                    !< grid index in x direction
273    INTEGER(iwp) ::  ind_array(1)         !< dummy used to determine start index for external pressure forcing
274    INTEGER(iwp) ::  j                    !< grid index in y direction
275    INTEGER(iwp) ::  k                    !< grid index in z direction
276    INTEGER(iwp) ::  k_surf               !< surface level index
277    INTEGER(iwp) ::  l                    !< running index over surface orientation
278    INTEGER(iwp) ::  m                    !< index of surface element in surface data type
279    INTEGER(iwp) ::  nz_u_shift           !< topography-top index on u-grid, used to vertically shift initial profiles
280    INTEGER(iwp) ::  nz_v_shift           !< topography-top index on v-grid, used to vertically shift initial profiles
281    INTEGER(iwp) ::  nz_w_shift           !< topography-top index on w-grid, used to vertically shift initial profiles
282    INTEGER(iwp) ::  nz_s_shift           !< topography-top index on scalar-grid, used to vertically shift initial profiles
283    INTEGER(iwp) ::  nz_u_shift_l         !< topography-top index on u-grid, used to vertically shift initial profiles
284    INTEGER(iwp) ::  nz_v_shift_l         !< topography-top index on v-grid, used to vertically shift initial profiles
285    INTEGER(iwp) ::  nz_w_shift_l         !< topography-top index on w-grid, used to vertically shift initial profiles
286    INTEGER(iwp) ::  nz_s_shift_l         !< topography-top index on scalar-grid, used to vertically shift initial profiles
287    INTEGER(iwp) ::  nzt_l                !< index of top PE boundary for multigrid level
288    INTEGER(iwp) ::  sr                   !< index of statistic region
289
290    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !< toal number of horizontal grid points in statistical region on
291                                                             !< subdomain
292
293    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !< number of horizontal non-wall bounded grid points on
294                                                                     !< subdomain
295    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !< number of horizontal non-topography grid points on
296                                                                     !< subdomain
297
298    REAL(wp) ::  dx_l !< grid spacing along x on different multigrid level
299    REAL(wp) ::  dy_l !< grid spacing along y on different multigrid level
300
301    REAL(wp), DIMENSION(:), ALLOCATABLE ::  init_l                       !< dummy array used for averaging 3D data to obtain
302                                                                         !< inital profiles
303    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l  !< mean surface level height on subdomain
304    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l               !< total number of non-topography grid points on subdomain
305    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp             !< total number of non-topography grid points
306    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic                !< hydrostatic pressure
307
308    REAL(wp), DIMENSION(1:3) ::  volume_flow_area_l     !< area of lateral and top model domain surface on local subdomain
309    REAL(wp), DIMENSION(1:3) ::  volume_flow_initial_l  !< initial volume flow into model domain
310
311    TYPE(real_2d) ::  tmp_2d !< temporary variable to input additional surface-data from static file
312
313    CALL location_message( 'model initialization', 'start' )
314!
315!-- Set reference date-time
316    CALL init_date_time( date_time_str=origin_date_time,                                           &
317                         use_fixed_date=use_fixed_date,                                            &
318                         use_fixed_time=use_fixed_time )
319
320    IF ( debug_output )  CALL debug_message( 'allocating arrays', 'start' )
321!
322!-- Allocate arrays
323    ALLOCATE( mean_surface_level_height(0:statistic_regions),                                      &
324              mean_surface_level_height_l(0:statistic_regions),                                    &
325              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),                        &
326              ngp_3d(0:statistic_regions),                                                         &
327              ngp_3d_inner(0:statistic_regions),                                                   &
328              ngp_3d_inner_l(0:statistic_regions),                                                 &
329              ngp_3d_inner_tmp(0:statistic_regions),                                               &
330              sums_divnew_l(0:statistic_regions),                                                  &
331              sums_divold_l(0:statistic_regions) )
332    ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
333    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                                        &
334              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                                      &
335              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                                      &
336              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                                    &
337              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                                      &
338              sums(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa),                          &
339              sums_l(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa,0:threads_per_task-1),   &
340              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),                        &
341              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions) )
342    ALLOCATE( ts_value(dots_max,0:statistic_regions) )
343    ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) )
344
345    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                                        &
346              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                    &
347              tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
348
349    ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                 &
350              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                 &
351              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
352              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
353              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
354              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
355              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
356              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
357              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
358              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                                  &
359              w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
360    IF (  .NOT.  neutral )  THEN
361       ALLOCATE( pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
362    ENDIF
363!
364!-- Pre-set masks for regional statistics. Default is the total model domain.
365!-- Ghost points are excluded because counting values at the ghost boundaries would bias the
366!-- statistics.
367    rmask = 1.0_wp
368    rmask(:,nxlg:nxl-1,:) = 0.0_wp;  rmask(:,nxr+1:nxrg,:) = 0.0_wp
369    rmask(nysg:nys-1,:,:) = 0.0_wp;  rmask(nyn+1:nyng,:,:) = 0.0_wp
370!
371!-- Following array is required for perturbation pressure within the iterative pressure solvers. For
372!-- the multistep schemes (Runge-Kutta), array p holds the weighted average of the substeps and
373!-- cannot be used in the Poisson solver.
374    IF ( psolver == 'sor' )  THEN
375       ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
376    ELSEIF ( psolver(1:9) == 'multigrid' )  THEN
377!
378!--    For performance reasons, multigrid is using one ghost layer only
379       ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
380    ENDIF
381
382!
383!-- Array for storing constant coeffficients of the tridiagonal solver
384    IF ( psolver == 'poisfft' )  THEN
385       ALLOCATE( tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,2) )
386       ALLOCATE( tric(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) )
387    ENDIF
388
389    IF ( humidity )  THEN
390!
391!--    3D-humidity
392       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
393                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
394                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
395                 vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
396    ENDIF
397
398    IF ( passive_scalar )  THEN
399
400!
401!--    3D scalar arrays
402       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
403                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                               &
404                 s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
405
406    ENDIF
407
408!
409!-- Allocate and set 1d-profiles for Stokes drift velocity. It may be set to non-zero values later
410!-- in ocean_init.
411    ALLOCATE( u_stokes_zu(nzb:nzt+1), u_stokes_zw(nzb:nzt+1),                                      &
412              v_stokes_zu(nzb:nzt+1), v_stokes_zw(nzb:nzt+1) )
413    u_stokes_zu(:) = 0.0_wp
414    u_stokes_zw(:) = 0.0_wp
415    v_stokes_zu(:) = 0.0_wp
416    v_stokes_zw(:) = 0.0_wp
417
418!
419!-- Allocation of anelastic and Boussinesq approximation specific arrays
420    ALLOCATE( p_hydrostatic(nzb:nzt+1) )
421    ALLOCATE( rho_air(nzb:nzt+1) )
422    ALLOCATE( rho_air_zw(nzb:nzt+1) )
423    ALLOCATE( drho_air(nzb:nzt+1) )
424    ALLOCATE( drho_air_zw(nzb:nzt+1) )
425!
426!-- Density profile calculation for anelastic and Boussinesq approximation.
427!-- In case of a Boussinesq approximation, a constant density is calculated mainly for output
428!-- purposes. This density does not need to be considered in the model's system of equations.
429    IF ( TRIM( approximation ) == 'anelastic' )  THEN
430       DO  k = nzb, nzt+1
431          p_hydrostatic(k) = barometric_formula(zu(k), pt_surface *                                &
432                                                exner_function(surface_pressure * 100.0_wp),       &
433                                                surface_pressure * 100.0_wp)
434
435          rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(k))
436       ENDDO
437
438       DO  k = nzb, nzt
439          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
440       ENDDO
441
442       rho_air_zw(nzt+1)  = rho_air_zw(nzt) + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
443
444    ELSE
445       DO  k = nzb, nzt+1
446          p_hydrostatic(k) = barometric_formula(zu(nzb), pt_surface *                              &
447                                                exner_function(surface_pressure * 100.0_wp),       &
448                                                surface_pressure * 100.0_wp)
449
450          rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(nzb))
451       ENDDO
452
453       DO  k = nzb, nzt
454          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
455       ENDDO
456
457       rho_air_zw(nzt+1)  = rho_air_zw(nzt) + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
458
459    ENDIF
460!
461!-- Compute the inverse density array in order to avoid expencive divisions
462    drho_air    = 1.0_wp / rho_air
463    drho_air_zw = 1.0_wp / rho_air_zw
464
465!
466!-- Allocation of flux conversion arrays
467    ALLOCATE( heatflux_input_conversion(nzb:nzt+1) )
468    ALLOCATE( waterflux_input_conversion(nzb:nzt+1) )
469    ALLOCATE( momentumflux_input_conversion(nzb:nzt+1) )
470    ALLOCATE( heatflux_output_conversion(nzb:nzt+1) )
471    ALLOCATE( waterflux_output_conversion(nzb:nzt+1) )
472    ALLOCATE( momentumflux_output_conversion(nzb:nzt+1) )
473
474!
475!-- Calculate flux conversion factors according to approximation and in-/output mode
476    DO  k = nzb, nzt+1
477
478        IF ( TRIM( flux_input_mode ) == 'kinematic' )  THEN
479            heatflux_input_conversion(k)      = rho_air_zw(k)
480            waterflux_input_conversion(k)     = rho_air_zw(k)
481            momentumflux_input_conversion(k)  = rho_air_zw(k)
482        ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN
483            heatflux_input_conversion(k)      = 1.0_wp / c_p
484            waterflux_input_conversion(k)     = 1.0_wp / l_v
485            momentumflux_input_conversion(k)  = 1.0_wp
486        ENDIF
487
488        IF ( TRIM( flux_output_mode ) == 'kinematic' )  THEN
489            heatflux_output_conversion(k)     = drho_air_zw(k)
490            waterflux_output_conversion(k)    = drho_air_zw(k)
491            momentumflux_output_conversion(k) = drho_air_zw(k)
492        ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN
493            heatflux_output_conversion(k)     = c_p
494            waterflux_output_conversion(k)    = l_v
495            momentumflux_output_conversion(k) = 1.0_wp
496        ENDIF
497
498        IF ( .NOT. humidity ) THEN
499            waterflux_input_conversion(k)  = 1.0_wp
500            waterflux_output_conversion(k) = 1.0_wp
501        ENDIF
502
503    ENDDO
504
505!
506!-- In case of multigrid method, compute grid lengths and grid factors for the grid levels with
507!-- respective density on each grid.
508    IF ( psolver(1:9) == 'multigrid' )  THEN
509
510       ALLOCATE( ddx2_mg(maximum_grid_level) )
511       ALLOCATE( ddy2_mg(maximum_grid_level) )
512       ALLOCATE( dzu_mg(nzb+1:nzt+1,maximum_grid_level) )
513       ALLOCATE( dzw_mg(nzb+1:nzt+1,maximum_grid_level) )
514       ALLOCATE( f1_mg(nzb+1:nzt,maximum_grid_level) )
515       ALLOCATE( f2_mg(nzb+1:nzt,maximum_grid_level) )
516       ALLOCATE( f3_mg(nzb+1:nzt,maximum_grid_level) )
517       ALLOCATE( rho_air_mg(nzb:nzt+1,maximum_grid_level) )
518       ALLOCATE( rho_air_zw_mg(nzb:nzt+1,maximum_grid_level) )
519
520       dzu_mg(:,maximum_grid_level) = dzu
521       rho_air_mg(:,maximum_grid_level) = rho_air
522!
523!--    Next line to ensure an equally spaced grid.
524       dzu_mg(1,maximum_grid_level) = dzu(2)
525       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) + (rho_air(nzb) - rho_air(nzb+1))
526
527       dzw_mg(:,maximum_grid_level) = dzw
528       rho_air_zw_mg(:,maximum_grid_level) = rho_air_zw
529       nzt_l = nzt
530       DO  l = maximum_grid_level-1, 1, -1
531           dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1)
532           dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1)
533           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1)    + ( rho_air_mg(nzb,l+1)    -              &
534                                                             rho_air_mg(nzb+1,l+1)    )
535           rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + ( rho_air_zw_mg(nzb,l+1) -              &
536                                                             rho_air_zw_mg(nzb+1,l+1) )
537           rho_air_mg(nzb+1,l)    = rho_air_mg(nzb+1,l+1)
538           rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1)
539           nzt_l = nzt_l / 2
540           DO  k = 2, nzt_l+1
541              dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1)
542              dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1)
543              rho_air_mg(k,l)    = rho_air_mg(2*k-1,l+1)
544              rho_air_zw_mg(k,l) = rho_air_zw_mg(2*k-1,l+1)
545           ENDDO
546       ENDDO
547
548       nzt_l = nzt
549       dx_l  = dx
550       dy_l  = dy
551       DO  l = maximum_grid_level, 1, -1
552          ddx2_mg(l) = 1.0_wp / dx_l**2
553          ddy2_mg(l) = 1.0_wp / dy_l**2
554          DO  k = nzb+1, nzt_l
555             f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) )
556             f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l)   * dzw_mg(k,l) )
557             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) )                                     &
558                          * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l)
559          ENDDO
560          nzt_l = nzt_l / 2
561          dx_l  = dx_l * 2.0_wp
562          dy_l  = dy_l * 2.0_wp
563       ENDDO
564
565    ENDIF
566
567!
568!-- 1D-array for large scale subsidence velocity
569    IF ( .NOT. ALLOCATED( w_subs ) )  THEN
570       ALLOCATE ( w_subs(nzb:nzt+1) )
571       w_subs = 0.0_wp
572    ENDIF
573
574!
575!-- Initial assignment of the pointers
576    IF ( .NOT. neutral )  THEN
577       pt => pt_1;  pt_p => pt_2;  tpt_m => pt_3
578    ELSE
579       pt => pt_1;  pt_p => pt_1;  tpt_m => pt_3
580    ENDIF
581    u  => u_1;   u_p  => u_2;   tu_m  => u_3
582    v  => v_1;   v_p  => v_2;   tv_m  => v_3
583    w  => w_1;   w_p  => w_2;   tw_m  => w_3
584
585    IF ( humidity )  THEN
586       q => q_1;  q_p => q_2;  tq_m => q_3
587       vpt  => vpt_1
588    ENDIF
589
590    IF ( passive_scalar )  THEN
591       s => s_1;  s_p => s_2;  ts_m => s_3
592    ENDIF
593
594!
595!-- Initialize surface arrays
596    CALL init_surface_arrays
597!
598!-- Allocate arrays for other modules
599    CALL module_interface_init_arrays
600
601
602!
603!-- Allocate arrays containing the RK coefficient for calculation of perturbation pressure and
604!-- turbulent fluxes. At this point values are set for pressure calculation during initialization
605!-- (where no timestep is done). Further below the values needed within the timestep scheme will be
606!-- set.
607    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),                                   &
608              weight_pres(1:intermediate_timestep_count_max) )
609    weight_substep = 1.0_wp
610    weight_pres    = 1.0_wp
611    intermediate_timestep_count = 0  ! needed when simulated_time = 0.0
612
613    IF ( debug_output )  CALL debug_message( 'allocating arrays', 'end' )
614
615!
616!-- Initialize time series
617    ts_value = 0.0_wp
618
619!
620!-- Initialize local summation arrays for routine flow_statistics.
621!-- This is necessary because they may not yet have been initialized when they are called from
622!-- flow_statistics (or - depending on the chosen model run - are never initialized)
623    sums_divnew_l  = 0.0_wp
624    sums_divold_l  = 0.0_wp
625    sums_l_l       = 0.0_wp
626    sums_wsts_bc_l = 0.0_wp
627
628!
629!-- Initialize model variables
630    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
631         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
632!
633!--    Initialization with provided input data derived from larger-scale model
634       IF ( INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
635          IF ( debug_output )  CALL debug_message( 'initializing with INIFOR', 'start' )
636!
637!--       Read initial 1D profiles or 3D data from NetCDF file, depending on the provided
638!--       level-of-detail.
639!--       At the moment, only u, v, w, pt and q are provided.
640          CALL netcdf_data_input_init_3d
641!
642!--       Please note, Inifor provides data from nzb+1 to nzt.
643!--       Bottom and top boundary conditions for Inifor profiles are already set (just after
644!--       reading), so that this is not necessary here.
645!--       Depending on the provided level-of-detail, initial Inifor data is either stored on data
646!--       type (lod=1), or directly on 3D arrays (lod=2).
647!--       In order to obtain also initial profiles in case of lod=2 (which is required for e.g.
648!--       damping), average over 3D data.
649          IF( init_3d%lod_u == 1 )  THEN
650             u_init = init_3d%u_init
651          ELSEIF( init_3d%lod_u == 2 )  THEN
652             ALLOCATE( init_l(nzb:nzt+1) )
653             DO  k = nzb, nzt+1
654                init_l(k) = SUM( u(k,nys:nyn,nxl:nxr) )
655             ENDDO
656             init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp )
657
658#if defined( __parallel )
659             CALL MPI_ALLREDUCE( init_l, u_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
660#else
661             u_init = init_l
662#endif
663             DEALLOCATE( init_l )
664
665          ENDIF
666
667          IF( init_3d%lod_v == 1 )  THEN
668             v_init = init_3d%v_init
669          ELSEIF( init_3d%lod_v == 2 )  THEN
670             ALLOCATE( init_l(nzb:nzt+1) )
671             DO  k = nzb, nzt+1
672                init_l(k) = SUM( v(k,nys:nyn,nxl:nxr) )
673             ENDDO
674             init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp )
675
676#if defined( __parallel )
677             CALL MPI_ALLREDUCE( init_l, v_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
678#else
679             v_init = init_l
680#endif
681             DEALLOCATE( init_l )
682          ENDIF
683          IF( .NOT. neutral )  THEN
684             IF( init_3d%lod_pt == 1 )  THEN
685                pt_init = init_3d%pt_init
686             ELSEIF( init_3d%lod_pt == 2 )  THEN
687                ALLOCATE( init_l(nzb:nzt+1) )
688                DO  k = nzb, nzt+1
689                   init_l(k) = SUM( pt(k,nys:nyn,nxl:nxr) )
690                ENDDO
691                init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp )
692
693#if defined( __parallel )
694                CALL MPI_ALLREDUCE( init_l, pt_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
695#else
696                pt_init = init_l
697#endif
698                DEALLOCATE( init_l )
699             ENDIF
700          ENDIF
701
702
703          IF( humidity )  THEN
704             IF( init_3d%lod_q == 1 )  THEN
705                q_init = init_3d%q_init
706             ELSEIF( init_3d%lod_q == 2 )  THEN
707                ALLOCATE( init_l(nzb:nzt+1) )
708                DO  k = nzb, nzt+1
709                   init_l(k) = SUM( q(k,nys:nyn,nxl:nxr) )
710                ENDDO
711                init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp )
712
713#if defined( __parallel )
714                CALL MPI_ALLREDUCE( init_l, q_init, nzt+1-nzb+1, MPI_REAL, MPI_SUM, comm2d, ierr )
715#else
716                q_init = init_l
717#endif
718                DEALLOCATE( init_l )
719             ENDIF
720          ENDIF
721
722!
723!--       Write initial profiles onto 3D arrays.
724!--       Work-around, 3D initialization of u,v,w creates artificial structures which correlate with
725!--       the processor grid. The reason for this is still unknown. To work-around this, 3D
726!--       initialization will be effectively reduce to a 1D initialization where no such artificial
727!--       structures appear.
728          DO  i = nxlg, nxrg
729             DO  j = nysg, nyng
730                IF( init_3d%lod_u == 1  .OR.  init_3d%lod_u == 2 )  u(:,j,i) = u_init(:)
731                IF( init_3d%lod_v == 1  .OR.  init_3d%lod_u == 2 )  v(:,j,i) = v_init(:)
732                IF( .NOT. neutral  .AND.  ( init_3d%lod_pt == 1  .OR.  init_3d%lod_pt == 2 ) )     &
733                   pt(:,j,i) = pt_init(:)
734                IF( humidity  .AND.  ( init_3d%lod_q == 1  .OR.  init_3d%lod_q == 2 ) )            &
735                   q(:,j,i) = q_init(:)
736             ENDDO
737          ENDDO
738!
739!--       Set geostrophic wind components.
740          IF ( init_3d%from_file_ug )  THEN
741             ug(:) = init_3d%ug_init(:)
742          ENDIF
743          IF ( init_3d%from_file_vg )  THEN
744             vg(:) = init_3d%vg_init(:)
745          ENDIF
746!
747!--       Set bottom and top boundary condition for geostrophic wind
748          ug(nzt+1) = ug(nzt)
749          vg(nzt+1) = vg(nzt)
750          ug(nzb)   = ug(nzb+1)
751          vg(nzb)   = vg(nzb+1)
752!
753!--       Set inital w to 0
754          w = 0.0_wp
755
756          IF ( passive_scalar )  THEN
757             DO  i = nxlg, nxrg
758                DO  j = nysg, nyng
759                   s(:,j,i) = s_init
760                ENDDO
761             ENDDO
762          ENDIF
763
764!
765!--       Set velocity components at non-atmospheric / oceanic grid points to zero.
766          u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) )
767          v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
768          w = MERGE( w, 0.0_wp, BTEST( wall_flags_total_0, 3 ) )
769!
770!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
771          CALL  init_surfaces
772
773          IF ( debug_output )  CALL  debug_message( 'initializing with INIFOR', 'end' )
774!
775!--    Initialization via computed 1D-model profiles
776       ELSEIF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
777
778          IF ( debug_output )  CALL  debug_message( 'initializing with 1D model profiles', 'start' )
779!
780!--       Use solutions of the 1D model as initial profiles,
781!--       start 1D model
782          CALL init_1d_model
783!
784!--       Transfer initial profiles to the arrays of the 3D model
785          DO  i = nxlg, nxrg
786             DO  j = nysg, nyng
787                pt(:,j,i) = pt_init
788                u(:,j,i)  = u1d
789                v(:,j,i)  = v1d
790             ENDDO
791          ENDDO
792
793          IF ( humidity )  THEN
794             DO  i = nxlg, nxrg
795                DO  j = nysg, nyng
796                   q(:,j,i) = q_init
797                ENDDO
798             ENDDO
799          ENDIF
800
801          IF ( passive_scalar )  THEN
802             DO  i = nxlg, nxrg
803                DO  j = nysg, nyng
804                   s(:,j,i) = s_init
805                ENDDO
806             ENDDO
807          ENDIF
808!
809!--          Store initial profiles for output purposes etc.
810          IF ( .NOT. constant_diffusion )  THEN
811             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
812          ENDIF
813!
814!--       Set velocities back to zero
815          u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) )
816          v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
817!
818!--       WARNING: The extra boundary conditions set after running the 1D model impose an error on
819!--       -------- the divergence one layer below the topography; need to correct later
820!--       ATTENTION: Provisional correction for Piacsek & Williams advection scheme: keep u and v
821!--       ---------- zero one layer below the topography.
822          IF ( ibc_uv_b == 1 )  THEN
823!
824!--          Neumann condition
825             DO  i = nxl-1, nxr+1
826                DO  j = nys-1, nyn+1
827                   u(nzb,j,i) = u(nzb+1,j,i)
828                   v(nzb,j,i) = v(nzb+1,j,i)
829                ENDDO
830             ENDDO
831
832          ENDIF
833!
834!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
835          CALL init_surfaces
836
837          IF ( debug_output )  CALL  debug_message( 'initializing with 1D model profiles', 'end' )
838
839       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )  THEN
840
841          IF ( debug_output )  CALL  debug_message( 'initializing with constant profiles', 'start' )
842
843!
844!--       Use constructed initial profiles (velocity constant with height, temperature profile with
845!--       constant gradient)
846          DO  i = nxlg, nxrg
847             DO  j = nysg, nyng
848                pt(:,j,i) = pt_init
849                u(:,j,i)  = u_init
850                v(:,j,i)  = v_init
851             ENDDO
852          ENDDO
853!
854!--       Mask topography
855          u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) )
856          v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) )
857!
858!--       Set initial horizontal velocities at the lowest computational grid levels to zero in order
859!--       to avoid too small time steps caused by the diffusion limit in the initial phase of a run
860!--       (at k=1, dz/2 occurs in the limiting formula!).
861!--       Please note, in case land- or urban-surface model is used and a spinup is applied, masking
862!--       the lowest computational level is not possible as MOST as well as energy-balance
863!--       parametrizations will not work with zero wind velocity.
864          IF ( ibc_uv_b /= 1  .AND.  .NOT. spinup )  THEN
865             DO  i = nxlg, nxrg
866                DO  j = nysg, nyng
867                   DO  k = nzb, nzt
868                      u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 20 ) )
869                      v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 21 ) )
870                   ENDDO
871                ENDDO
872             ENDDO
873          ENDIF
874
875          IF ( humidity )  THEN
876             DO  i = nxlg, nxrg
877                DO  j = nysg, nyng
878                   q(:,j,i) = q_init
879                ENDDO
880             ENDDO
881          ENDIF
882
883          IF ( passive_scalar )  THEN
884             DO  i = nxlg, nxrg
885                DO  j = nysg, nyng
886                   s(:,j,i) = s_init
887                ENDDO
888             ENDDO
889          ENDIF
890
891!
892!--       Compute initial temperature field and other constants used in case of a sloping surface.
893          IF ( sloping_surface )  CALL init_slope
894!
895!--       Initialize surface variables, e.g. friction velocity, momentum fluxes, etc.
896          CALL init_surfaces
897
898          IF ( debug_output )  CALL debug_message( 'initializing with constant profiles', 'end' )
899
900       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )  THEN
901
902          IF ( debug_output )  CALL debug_message( 'initializing by user', 'start' )
903!
904!--       Pre-initialize surface variables, i.e. setting start- and end-indices at each
905!--       (j,i)-location. Please note, this does not supersede user-defined initialization of
906!--       surface quantities.
907          CALL init_surfaces
908!
909!--       Initialization will completely be done by the user
910          CALL user_init_3d_model
911
912          IF ( debug_output )  CALL debug_message( 'initializing by user', 'end' )
913
914       ENDIF
915
916       IF ( debug_output )  THEN
917          CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'start' )
918       ENDIF
919
920!
921!--    Bottom boundary
922       IF ( ibc_uv_b == 0  .OR.  ibc_uv_b == 2  )  THEN
923          u(nzb,:,:) = 0.0_wp
924          v(nzb,:,:) = 0.0_wp
925       ENDIF
926
927!
928!--    Apply channel flow boundary condition
929       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
930          u(nzt+1,:,:) = 0.0_wp
931          v(nzt+1,:,:) = 0.0_wp
932       ENDIF
933
934!
935!--    Calculate virtual potential temperature
936       IF ( humidity )  vpt = pt * ( 1.0_wp + 0.61_wp * q )
937
938!
939!--    Store initial profiles for output purposes etc.. Please note, in case of initialization of u,
940!--    v, w, pt, and q via output data derived from larger scale models, data will not be
941!--    horizontally homogeneous. Actually, a mean profile should be calculated before.
942       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
943       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
944       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2)  THEN
945          hom(nzb,1,5,:) = 0.0_wp
946          hom(nzb,1,6,:) = 0.0_wp
947       ENDIF
948       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
949
950       IF ( humidity )  THEN
951!
952!--       Store initial profile of total water content, virtual potential temperature
953          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
954          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
955!
956!--       Store initial profile of mixing ratio and potential temperature
957          IF ( bulk_cloud_model  .OR.  cloud_droplets ) THEN
958             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
959             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
960          ENDIF
961       ENDIF
962
963!
964!--    Store initial scalar profile
965       IF ( passive_scalar )  THEN
966          hom(:,1,121,:) = SPREAD(  s(:,nys,nxl), 2, statistic_regions+1 )
967       ENDIF
968
969!
970!--    Initialize the random number generators (from numerical recipes)
971       CALL random_function_ini
972
973       IF ( random_generator == 'random-parallel' )  THEN
974          CALL init_parallel_random_generator( nx, nys, nyn, nxl, nxr )
975       ENDIF
976!
977!--    Set the reference state to be used in the buoyancy terms (for ocean runs the reference state
978!--    will be set (overwritten) in init_ocean).
979       IF ( use_single_reference_value )  THEN
980          IF ( .NOT. humidity )  THEN
981             ref_state(:) = pt_reference
982          ELSE
983             ref_state(:) = vpt_reference
984          ENDIF
985       ELSE
986          IF ( .NOT. humidity )  THEN
987             ref_state(:) = pt_init(:)
988          ELSE
989             ref_state(:) = vpt(:,nys,nxl)
990          ENDIF
991       ENDIF
992
993!
994!--    For the moment, vertical velocity is zero
995       w = 0.0_wp
996
997!
998!--    Initialize array sums (must be defined in first call of pres)
999       sums = 0.0_wp
1000
1001!
1002!--    In case of iterative solvers, p must get an initial value
1003       IF ( psolver(1:9) == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0_wp
1004!
1005!--    Impose vortex with vertical axis on the initial velocity profile
1006       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
1007          CALL init_rankine
1008       ENDIF
1009
1010!
1011!--    Impose temperature anomaly (advection test only) or warm air bubble close to surface.
1012       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0  .OR.                          &
1013            INDEX( initializing_actions, 'initialize_bubble' ) /= 0  )  THEN
1014          CALL init_pt_anomaly
1015       ENDIF
1016
1017!
1018!--    If required, change the surface temperature at the start of the 3D run
1019       IF ( pt_surface_initial_change /= 0.0_wp )  THEN
1020          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
1021       ENDIF
1022
1023!
1024!--    If required, change the surface humidity/scalar at the start of the 3D
1025!--    run
1026       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )                                  &
1027          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
1028
1029       IF ( passive_scalar  .AND.  s_surface_initial_change /= 0.0_wp )                            &
1030          s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change
1031
1032
1033!
1034!--    Initialize old and new time levels.
1035       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
1036       pt_p = pt; u_p = u; v_p = v; w_p = w
1037
1038       IF ( humidity  )  THEN
1039          tq_m = 0.0_wp
1040          q_p = q
1041       ENDIF
1042
1043       IF ( passive_scalar )  THEN
1044          ts_m = 0.0_wp
1045          s_p  = s
1046       ENDIF
1047
1048       IF ( debug_output )  THEN
1049          CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'end' )
1050       ENDIF
1051
1052    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
1053             TRIM( initializing_actions ) == 'cyclic_fill' )                   &
1054    THEN
1055
1056       IF ( debug_output )  THEN
1057          CALL debug_message( 'initializing in case of restart / cyclic_fill', 'start' )
1058       ENDIF
1059!
1060!--    Initialize surface elements and its attributes, e.g. heat- and momentumfluxes, roughness,
1061!--    scaling parameters. As number of surface elements might be different between runs, e.g. in
1062!--    case of cyclic fill, and not all surface elements are read, surface elements need to be
1063!--    initialized before.
1064!--    Please note, in case of cyclic fill, surfaces should be initialized after restart data is
1065!--    read, else, individual settings of surface parameters will be overwritten from data of
1066!--    precursor run, hence, init_surfaces is called a second time after reading the restart data.
1067       CALL init_surfaces
1068!
1069!--    When reading data for cyclic fill of 3D prerun data files, read some of the global variables
1070!--    from the restart file which are required for initializing the inflow
1071       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1072
1073!
1074!--       Blockwise I/O does not work together with MPI-I/O
1075          IF ( restart_data_format_input(1:3) == 'mpi' )  THEN
1076             CALL rrd_read_parts_of_global
1077          ELSE
1078             DO  i = 0, io_blocks-1
1079                IF ( i == io_group )  THEN
1080                   CALL rrd_read_parts_of_global
1081                ENDIF
1082#if defined( __parallel )
1083                CALL MPI_BARRIER( comm2d, ierr )
1084#endif
1085             ENDDO
1086          ENDIF
1087
1088       ENDIF
1089
1090!
1091!--    Read processor specific binary data from restart file.
1092!--    Blockwise I/O does not work together with MPI-I/O
1093       IF ( restart_data_format_input(1:3) == 'mpi' )  THEN
1094          CALL rrd_local
1095       ELSE
1096          DO  i = 0, io_blocks-1
1097             IF ( i == io_group )  THEN
1098                CALL rrd_local
1099             ENDIF
1100#if defined( __parallel )
1101             CALL MPI_BARRIER( comm2d, ierr )
1102#endif
1103          ENDDO
1104       ENDIF
1105
1106
1107       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1108
1109!
1110!--       In case of cyclic fill, call init_surfaces a second time, so that surface properties such
1111!--       as heat fluxes are initialized as prescribed.
1112          CALL init_surfaces
1113
1114!
1115!--       Overwrite u_init, v_init, pt_init, q_init and s_init with the horizontally mean (hom)
1116!--       vertical profiles from the end of the prerun, because these profiles shall be used as the
1117!--       reference state for the rayleigh damping and the pt_damping. This is especially important
1118!--       for the use of large_scale_subsidence, because the reference temperature in the free
1119!--       atmosphere changes in time.
1120          u_init(:) = hom_sum(:,1,0)
1121          v_init(:) = hom_sum(:,2,0)
1122          pt_init(:) = hom_sum(:,4,0)
1123          IF ( humidity )  q_init(:) = hom_sum(:,41,0)
1124          IF ( passive_scalar )  s_init(:) = hom_sum(:,115,0)
1125       ENDIF
1126!
1127!--    In case of complex terrain and cyclic fill method as initialization, shift initial data in
1128!--    the vertical direction for each point in the x-y-plane depending on local surface height.
1129       IF ( complex_terrain  .AND.  TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1130          DO  i = nxlg, nxrg
1131             DO  j = nysg, nyng
1132                nz_u_shift = topo_top_ind(j,i,1)
1133                nz_v_shift = topo_top_ind(j,i,2)
1134                nz_w_shift = topo_top_ind(j,i,3)
1135                nz_s_shift = topo_top_ind(j,i,0)
1136
1137                u(nz_u_shift:nzt+1,j,i)  = u(0:nzt+1-nz_u_shift,j,i)
1138
1139                v(nz_v_shift:nzt+1,j,i)  = v(0:nzt+1-nz_v_shift,j,i)
1140
1141                w(nz_w_shift:nzt+1,j,i)  = w(0:nzt+1-nz_w_shift,j,i)
1142
1143                p(nz_s_shift:nzt+1,j,i)  =  p(0:nzt+1-nz_s_shift,j,i)
1144                pt(nz_s_shift:nzt+1,j,i) = pt(0:nzt+1-nz_s_shift,j,i)
1145             ENDDO
1146          ENDDO
1147       ENDIF
1148!
1149!--    Initialization of the turbulence recycling method
1150       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  turbulent_inflow )  THEN
1151!
1152!--       First store the profiles to be used at the inflow.
1153!--       These profiles are the (temporally) and horizontally averaged vertical profiles from the
1154!--       prerun. Alternatively, prescribed profiles for u,v-components can be used.
1155          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,1:num_mean_inflow_profiles) )
1156
1157          IF ( use_prescribed_profile_data )  THEN
1158             mean_inflow_profiles(:,1) = u_init            ! u
1159             mean_inflow_profiles(:,2) = v_init            ! v
1160          ELSE
1161             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
1162             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
1163          ENDIF
1164          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
1165          IF ( humidity )  mean_inflow_profiles(:,6) = hom_sum(:,41,0)          ! q
1166          IF ( passive_scalar )  mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
1167
1168!
1169!--       In case of complex terrain, determine vertical displacement at inflow boundary and adjust
1170!--       mean inflow profiles
1171          IF ( complex_terrain )  THEN
1172             IF ( nxlg <= 0  .AND.  nxrg >= 0  .AND.  nysg <= 0  .AND.  nyng >= 0 )  THEN
1173                nz_u_shift_l = topo_top_ind(j,i,1)
1174                nz_v_shift_l = topo_top_ind(j,i,2)
1175                nz_w_shift_l = topo_top_ind(j,i,3)
1176                nz_s_shift_l = topo_top_ind(j,i,0)
1177             ELSE
1178                nz_u_shift_l = 0
1179                nz_v_shift_l = 0
1180                nz_w_shift_l = 0
1181                nz_s_shift_l = 0
1182             ENDIF
1183
1184#if defined( __parallel )
1185             CALL MPI_ALLREDUCE( nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
1186             CALL MPI_ALLREDUCE( nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
1187             CALL MPI_ALLREDUCE( nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
1188             CALL MPI_ALLREDUCE( nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr )
1189#else
1190             nz_u_shift = nz_u_shift_l
1191             nz_v_shift = nz_v_shift_l
1192             nz_w_shift = nz_w_shift_l
1193             nz_s_shift = nz_s_shift_l
1194#endif
1195
1196             mean_inflow_profiles(:,1) = 0.0_wp
1197             mean_inflow_profiles(nz_u_shift:nzt+1,1) = hom_sum(0:nzt+1-nz_u_shift,1,0)  ! u
1198
1199             mean_inflow_profiles(:,2) = 0.0_wp
1200             mean_inflow_profiles(nz_v_shift:nzt+1,2) = hom_sum(0:nzt+1-nz_v_shift,2,0)  ! v
1201
1202             mean_inflow_profiles(nz_s_shift:nzt+1,4) = hom_sum(0:nzt+1-nz_s_shift,4,0)  ! pt
1203
1204          ENDIF
1205
1206!
1207!--       If necessary, adjust the horizontal flow field to the prescribed profiles
1208          IF ( use_prescribed_profile_data )  THEN
1209             DO  i = nxlg, nxrg
1210                DO  j = nysg, nyng
1211                   DO  k = nzb, nzt+1
1212                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
1213                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
1214                   ENDDO
1215                ENDDO
1216             ENDDO
1217          ENDIF
1218
1219!
1220!--       Use these mean profiles at the inflow (provided that Dirichlet conditions are used)
1221          IF ( bc_dirichlet_l )  THEN
1222             DO  j = nysg, nyng
1223                DO  k = nzb, nzt+1
1224                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
1225                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
1226                   w(k,j,nxlg:-1)  = 0.0_wp
1227                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
1228                   IF ( humidity )  q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
1229                   IF ( passive_scalar )  s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)
1230                ENDDO
1231             ENDDO
1232          ENDIF
1233
1234!
1235!--       Calculate the damping factors to be used at the inflow. For a turbulent inflow the
1236!--       turbulent fluctuations have to be limited vertically because otherwise the turbulent
1237!--       inflow layer will grow in time.
1238          IF ( inflow_damping_height == 9999999.9_wp )  THEN
1239!
1240!--          Default: use the inversion height calculated by the prerun; if this is zero,
1241!--          inflow_damping_height must be explicitly specified.
1242             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp )  THEN
1243                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
1244             ELSE
1245                WRITE( message_string, * ) 'inflow_damping_height must be ',                       &
1246                                           'explicitly specified because&the inversion height ',   &
1247                                           'calculated by the prerun is zero.'
1248                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
1249             ENDIF
1250
1251          ENDIF
1252
1253          IF ( inflow_damping_width == 9999999.9_wp )  THEN
1254!
1255!--          Default for the transition range: one tenth of the undamped layer
1256             inflow_damping_width = 0.1_wp * inflow_damping_height
1257
1258          ENDIF
1259
1260          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
1261
1262          DO  k = nzb, nzt+1
1263
1264             IF ( zu(k) <= inflow_damping_height )  THEN
1265                inflow_damping_factor(k) = 1.0_wp
1266             ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) )  THEN
1267                inflow_damping_factor(k) = 1.0_wp -                                                &
1268                                           ( zu(k) - inflow_damping_height ) / inflow_damping_width
1269             ELSE
1270                inflow_damping_factor(k) = 0.0_wp
1271             ENDIF
1272
1273          ENDDO
1274
1275       ENDIF
1276
1277!
1278!--    Inside buildings set velocities back to zero
1279       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  topography /= 'flat' )  THEN
1280!
1281!--       Inside buildings set velocities back to zero.
1282!--       Other scalars (pt, q, s, p, sa, ...) are ignored at present,
1283!--       maybe revise later.
1284          DO  i = nxlg, nxrg
1285             DO  j = nysg, nyng
1286                DO  k = nzb, nzt
1287                   u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 1 ) )
1288                   v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 2 ) )
1289                   w(k,j,i) = MERGE( w(k,j,i), 0.0_wp, BTEST( wall_flags_total_0(k,j,i), 3 ) )
1290                ENDDO
1291             ENDDO
1292          ENDDO
1293
1294       ENDIF
1295
1296!
1297!--    Calculate initial temperature field and other constants used in case of a sloping surface
1298       IF ( sloping_surface )  CALL init_slope
1299
1300!
1301!--    Initialize new time levels (only done in order to set boundary values including ghost points)
1302       pt_p = pt; u_p = u; v_p = v; w_p = w
1303       IF ( humidity )  THEN
1304          q_p = q
1305       ENDIF
1306       IF ( passive_scalar )  s_p  = s
1307!
1308!--    Allthough tendency arrays are set in prognostic_equations, they have have to be predefined
1309!--    here because they are used (but multiplied with 0) there before they are set.
1310       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
1311       IF ( humidity )  THEN
1312          tq_m = 0.0_wp
1313       ENDIF
1314       IF ( passive_scalar )  ts_m  = 0.0_wp
1315
1316       IF ( debug_output )  THEN
1317          CALL debug_message( 'initializing in case of restart / cyclic_fill', 'end' )
1318       ENDIF
1319
1320    ELSE
1321!
1322!--    Actually this part of the programm should not be reached
1323       message_string = 'unknown initializing problem'
1324       CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 )
1325    ENDIF
1326
1327!
1328!-- Calculate the initial volume flow at the right and north boundary
1329    IF ( conserve_volume_flow )  THEN
1330
1331       IF ( use_prescribed_profile_data )  THEN
1332
1333          volume_flow_initial_l = 0.0_wp
1334          volume_flow_area_l    = 0.0_wp
1335
1336          IF ( nxr == nx )  THEN
1337             DO  j = nys, nyn
1338                DO  k = nzb+1, nzt
1339                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
1340                                              u_init(k) * dzw(k)                                   &
1341                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1342                                                       BTEST( wall_flags_total_0(k,j,nxr), 1 )     &
1343                                                     )
1344
1345                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
1346                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1347                                                       BTEST( wall_flags_total_0(k,j,nxr), 1 )     &
1348                                                     )
1349                ENDDO
1350             ENDDO
1351          ENDIF
1352
1353          IF ( nyn == ny )  THEN
1354             DO  i = nxl, nxr
1355                DO  k = nzb+1, nzt
1356                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
1357                                              v_init(k) * dzw(k)                                   &
1358                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1359                                                       BTEST( wall_flags_total_0(k,nyn,i), 2 )     &
1360                                                     )
1361                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
1362                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1363                                                       BTEST( wall_flags_total_0(k,nyn,i), 2 )     &
1364                                                     )
1365                ENDDO
1366             ENDDO
1367          ENDIF
1368
1369#if defined( __parallel )
1370          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
1371                              MPI_SUM, comm2d, ierr )
1372          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
1373                              comm2d, ierr )
1374
1375#else
1376          volume_flow_initial = volume_flow_initial_l
1377          volume_flow_area    = volume_flow_area_l
1378#endif
1379
1380       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1381
1382          volume_flow_initial_l = 0.0_wp
1383          volume_flow_area_l    = 0.0_wp
1384
1385          IF ( nxr == nx )  THEN
1386             DO  j = nys, nyn
1387                DO  k = nzb+1, nzt
1388                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
1389                                              hom_sum(k,1,0) * dzw(k)                              &
1390                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1391                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
1392                                                     )
1393                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
1394                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1395                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
1396                                                     )
1397                ENDDO
1398             ENDDO
1399          ENDIF
1400
1401          IF ( nyn == ny )  THEN
1402             DO  i = nxl, nxr
1403                DO  k = nzb+1, nzt
1404                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
1405                                              hom_sum(k,2,0) * dzw(k)                              &
1406                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1407                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
1408                                                     )
1409                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
1410                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1411                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
1412                                                     )
1413                ENDDO
1414             ENDDO
1415          ENDIF
1416
1417#if defined( __parallel )
1418          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
1419                              MPI_SUM, comm2d, ierr )
1420          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
1421                              comm2d, ierr )
1422
1423#else
1424          volume_flow_initial = volume_flow_initial_l
1425          volume_flow_area    = volume_flow_area_l
1426#endif
1427
1428       ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
1429
1430          volume_flow_initial_l = 0.0_wp
1431          volume_flow_area_l    = 0.0_wp
1432
1433          IF ( nxr == nx )  THEN
1434             DO  j = nys, nyn
1435                DO  k = nzb+1, nzt
1436                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +                           &
1437                                              u(k,j,nx) * dzw(k)                                   &
1438                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1439                                                       BTEST( wall_flags_total_0(k,j,nx), 1 )      &
1440                                                     )
1441                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)                       &
1442                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1443                                                   BTEST( wall_flags_total_0(k,j,nx), 1 )          &
1444                                                     )
1445                ENDDO
1446             ENDDO
1447          ENDIF
1448
1449          IF ( nyn == ny )  THEN
1450             DO  i = nxl, nxr
1451                DO  k = nzb+1, nzt
1452                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +                           &
1453                                              v(k,ny,i) * dzw(k)                                   &
1454                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1455                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
1456                                                     )
1457                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)                       &
1458                                              * MERGE( 1.0_wp, 0.0_wp,                             &
1459                                                       BTEST( wall_flags_total_0(k,ny,i), 2 )      &
1460                                                     )
1461                ENDDO
1462             ENDDO
1463          ENDIF
1464
1465#if defined( __parallel )
1466          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1), 2, MPI_REAL,       &
1467                              MPI_SUM, comm2d, ierr )
1468          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), 2, MPI_REAL, MPI_SUM,    &
1469                              comm2d, ierr )
1470
1471#else
1472          volume_flow_initial = volume_flow_initial_l
1473          volume_flow_area    = volume_flow_area_l
1474#endif
1475
1476       ENDIF
1477
1478!
1479!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated from u|v_bulk instead
1480       IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
1481          volume_flow_initial(1) = u_bulk * volume_flow_area(1)
1482          volume_flow_initial(2) = v_bulk * volume_flow_area(2)
1483       ENDIF
1484
1485    ENDIF
1486!
1487!-- In the following, surface properties can be further initialized with input from static driver
1488!-- file.
1489!-- At the moment this affects only default surfaces. For example, roughness length or sensible /
1490!-- latent heat fluxes can be initialized heterogeneously for default surfaces. Therefore, a generic
1491!-- routine from netcdf_data_input_mod is called to read a 2D array.
1492    IF ( input_pids_static )  THEN
1493!
1494!--    Allocate memory for possible static input
1495       ALLOCATE( tmp_2d%var(nys:nyn,nxl:nxr) )
1496       tmp_2d%var = 0.0_wp
1497!
1498!--    Open the static input file
1499#if defined( __netcdf )
1500       CALL open_read_file( TRIM( input_file_static ) //                                           &
1501                            TRIM( coupling_char ), pids_id )
1502
1503       CALL inquire_num_variables( pids_id, num_var_pids )
1504!
1505!--    Allocate memory to store variable names and read them
1506       ALLOCATE( vars_pids(1:num_var_pids) )
1507       CALL inquire_variable_names( pids_id, vars_pids )
1508!
1509!--    Input roughness length.
1510       IF ( check_existence( vars_pids, 'z0' ) )  THEN
1511!
1512!--       Read _FillValue attribute
1513          CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'z0' )
1514!
1515!--       Read variable
1516          CALL get_variable( pids_id, 'z0', tmp_2d%var, nxl, nxr, nys, nyn )
1517          CALL resize_array( tmp_2d%var, nys, nyn, nxl, nxr )
1518          CALL exchange_horiz_2d( tmp_2d%var )
1519!
1520!--       Initialize roughness length. Note, z0 will be only initialized at default-type surfaces.
1521!--       At natural or urban z0 is implicitly initialized by the respective parameter lists.
1522!--       Initialize horizontal surface elements.
1523          CALL init_single_surface_properties( surf_def_h(0)%z0, tmp_2d%var, surf_def_h(0)%ns,     &
1524                                               tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
1525!
1526!--       Initialize roughness also at vertical surface elements.
1527!--       Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
1528!--       index arrays with their respective offset values.
1529          DO  l = 0, 3
1530             CALL init_single_surface_properties( surf_def_v(l)%z0, tmp_2d%var, surf_def_v(l)%ns,  &
1531                                                  tmp_2d%fill, surf_def_v(l)%i+surf_def_v(l)%ioff, &
1532                                                  surf_def_v(l)%j+surf_def_v(l)%joff )
1533          ENDDO
1534
1535       ENDIF
1536!
1537!--    Input surface sensible heat flux.
1538       IF ( check_existence( vars_pids, 'shf' ) )  THEN
1539!
1540!--       Read _FillValue attribute
1541          CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'shf' )
1542!
1543!--       Read variable
1544          CALL get_variable( pids_id, 'shf', tmp_2d%var, nxl, nxr, nys, nyn )
1545          CALL resize_array( tmp_2d%var, nys, nyn, nxl, nxr )
1546          CALL exchange_horiz_2d( tmp_2d%var )
1547!
1548!--       Initialize heat flux. Note, shf will be only initialized at default-type surfaces. At
1549!--       natural or urban shf is implicitly initialized by the respective parameter lists.
1550!--       Initialize horizontal surface elements.
1551          CALL init_single_surface_properties( surf_def_h(0)%shf, tmp_2d%var, surf_def_h(0)%ns,    &
1552                                               tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
1553!
1554!--       Initialize heat flux also at vertical surface elements.
1555!--       Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
1556!--       index arrays with their respective offset values.
1557          DO  l = 0, 3
1558             CALL init_single_surface_properties( surf_def_v(l)%shf, tmp_2d%var, surf_def_v(l)%ns, &
1559                                                  tmp_2d%fill, surf_def_v(l)%i+surf_def_v(l)%ioff, &
1560                                                  surf_def_v(l)%j+surf_def_v(l)%joff )
1561          ENDDO
1562
1563       ENDIF
1564!
1565!--    Input surface latent heat flux.
1566       IF ( humidity )  THEN
1567          IF ( check_existence( vars_pids, 'qsws' ) )  THEN
1568!
1569!--          Read _FillValue attribute
1570             CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'qsws' )
1571!
1572!--          Read variable
1573             CALL get_variable( pids_id, 'qsws', tmp_2d%var, nxl, nxr, nys, nyn )
1574             CALL resize_array( tmp_2d%var, nys, nyn, nxl, nxr )
1575             CALL exchange_horiz_2d( tmp_2d%var )
1576!
1577!--          Initialize latent heat flux. Note, qsws will be only initialized at default-type surfaces.
1578!--          At natural or urban qsws is implicitly initialized by the respective parameter lists.
1579!--          Initialize horizontal surface elements.
1580             CALL init_single_surface_properties( surf_def_h(0)%qsws, tmp_2d%var, surf_def_h(0)%ns,&
1581                                                  tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
1582!
1583!--          Initialize latent heat flux also at vertical surface elements.
1584!--          Note, the actual 2D input arrays are only defined on the subdomain. Therefore, pass the
1585!--          index arrays with their respective offset values.
1586             DO  l = 0, 3
1587                CALL init_single_surface_properties( surf_def_v(l)%qsws, tmp_2d%var,               &
1588                                                     surf_def_v(l)%ns, tmp_2d%fill,                &
1589                                                     surf_def_v(l)%i+surf_def_v(l)%ioff,           &
1590                                                     surf_def_v(l)%j+surf_def_v(l)%joff )
1591             ENDDO
1592
1593          ENDIF
1594       ENDIF
1595!
1596!--    Input passive scalar flux.
1597       IF ( passive_scalar )  THEN
1598          IF ( check_existence( vars_pids, 'ssws' ) )  THEN
1599!
1600!--          Read _FillValue attribute
1601             CALL get_attribute( pids_id, char_fill, tmp_2d%fill, .FALSE., 'ssws' )
1602!
1603!--          Read variable
1604             CALL get_variable( pids_id, 'ssws', tmp_2d%var, nxl, nxr, nys, nyn )
1605             CALL resize_array( tmp_2d%var, nys, nyn, nxl, nxr )
1606             CALL exchange_horiz_2d( tmp_2d%var )
1607!
1608!--          Initialize passive scalar flux. Initialize horizontal surface elements.
1609             CALL init_single_surface_properties( surf_def_h(0)%ssws, tmp_2d%var, surf_def_h(0)%ns,&
1610                                                  tmp_2d%fill, surf_def_h(0)%i, surf_def_h(0)%j )
1611
1612             DO  l = 0, 3
1613                CALL init_single_surface_properties( surf_def_v(l)%ssws, tmp_2d%var,               &
1614                                                     surf_def_v(l)%ns, tmp_2d%fill,                &
1615                                                     surf_def_v(l)%i+surf_def_v(l)%ioff,           &
1616                                                     surf_def_v(l)%j+surf_def_v(l)%joff )
1617             ENDDO
1618
1619          ENDIF
1620       ENDIF
1621!
1622!--    Additional variables, can be initialized the
1623!--    same way.
1624
1625!
1626!--    Finally, close the input file and deallocate temporary arrays
1627       DEALLOCATE( vars_pids )
1628
1629       CALL close_input_file( pids_id )
1630#endif
1631       DEALLOCATE( tmp_2d%var )
1632    ENDIF
1633!
1634!-- Finally, if random_heatflux is set, disturb shf at horizontal surfaces. Actually, this should be
1635!-- done in surface_mod, where all other initializations of surface quantities are done. However,
1636!-- this would create a ring dependency, hence, it is done here. Maybe delete disturb_heatflux and
1637!-- tranfer the respective code directly into the initialization in surface_mod.
1638    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
1639         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
1640
1641       IF ( use_surface_fluxes  .AND.  constant_heatflux  .AND.  random_heatflux )  THEN
1642          IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
1643          IF ( surf_lsm_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_lsm_h(0) )
1644          IF ( surf_usm_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_usm_h(0) )
1645       ENDIF
1646    ENDIF
1647
1648!
1649!-- Compute total sum of grid points and the mean surface level height for each statistic region.
1650!-- These are mainly used for horizontal averaging of turbulence statistics.
1651!-- ngp_2dh: number of grid points of a horizontal cross section through the respective statistic
1652!--          region
1653!-- ngp_3d:  number of grid points of the respective statistic region
1654    ngp_2dh_outer_l   = 0
1655    ngp_2dh_outer     = 0
1656    ngp_2dh_s_inner_l = 0
1657    ngp_2dh_s_inner   = 0
1658    ngp_2dh_l         = 0
1659    ngp_2dh           = 0
1660    ngp_3d_inner_l    = 0.0_wp
1661    ngp_3d_inner      = 0
1662    ngp_3d            = 0
1663    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
1664
1665    mean_surface_level_height   = 0.0_wp
1666    mean_surface_level_height_l = 0.0_wp
1667!
1668!-- To do: New concept for these non-topography grid points!
1669    DO  sr = 0, statistic_regions
1670       DO  i = nxl, nxr
1671          DO  j = nys, nyn
1672             IF ( rmask(j,i,sr) == 1.0_wp )  THEN
1673!
1674!--             All xy-grid points
1675                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
1676!
1677!--             Determine mean surface-level height. In case of downward-facing walls are present,
1678!--             more than one surface level exist.
1679!--             In this case, use the lowest surface-level height.
1680                IF ( surf_def_h(0)%start_index(j,i) <= surf_def_h(0)%end_index(j,i) )  THEN
1681                   m = surf_def_h(0)%start_index(j,i)
1682                   k = surf_def_h(0)%k(m)
1683                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
1684                ENDIF
1685                IF ( surf_lsm_h(0)%start_index(j,i) <= surf_lsm_h(0)%end_index(j,i) )  THEN
1686                   m = surf_lsm_h(0)%start_index(j,i)
1687                   k = surf_lsm_h(0)%k(m)
1688                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
1689                ENDIF
1690                IF ( surf_usm_h(0)%start_index(j,i) <= surf_usm_h(0)%end_index(j,i) )  THEN
1691                   m = surf_usm_h(0)%start_index(j,i)
1692                   k = surf_usm_h(0)%k(m)
1693                   mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) + zw(k-1)
1694                ENDIF
1695
1696                k_surf = k - 1
1697
1698                DO  k = nzb, nzt+1
1699!
1700!--                xy-grid points above topography
1701                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr)     +                             &
1702                                           MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 24 ) )
1703
1704                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) +                             &
1705                                             MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 22 ) )
1706
1707                ENDDO
1708!
1709!--             All grid points of the total domain above topography
1710                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + ( nz - k_surf + 2 )
1711
1712
1713
1714             ENDIF
1715          ENDDO
1716       ENDDO
1717    ENDDO
1718
1719    sr = statistic_regions + 1
1720#if defined( __parallel )
1721    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1722    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
1723    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1724    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr, MPI_INTEGER, MPI_SUM, &
1725                        comm2d, ierr )
1726    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1727    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0), (nz+2)*sr, MPI_INTEGER,      &
1728                        MPI_SUM, comm2d, ierr )
1729    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1730    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL, MPI_SUM, comm2d,     &
1731                        ierr )
1732    ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
1733    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1734    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0), mean_surface_level_height(0), sr, MPI_REAL,&
1735                        MPI_SUM, comm2d, ierr )
1736    mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh )
1737#else
1738    ngp_2dh         = ngp_2dh_l
1739    ngp_2dh_outer   = ngp_2dh_outer_l
1740    ngp_2dh_s_inner = ngp_2dh_s_inner_l
1741    ngp_3d_inner    = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) )
1742    mean_surface_level_height = mean_surface_level_height_l / REAL( ngp_2dh_l )
1743#endif
1744
1745    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) *                                     &
1746             INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
1747
1748!
1749!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics, buoyancy, etc. A
1750!-- zero value will occur for cases where all grid points of the respective subdomain lie below the
1751!-- surface topography
1752    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   )
1753    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )), ngp_3d_inner(:) )
1754    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) )
1755
1756    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l, ngp_3d_inner_l,           &
1757                ngp_3d_inner_tmp )
1758
1759!
1760!-- Initializae 3D offline nesting in COSMO model and read data from
1761!-- external NetCDF file.
1762    IF ( nesting_offline )  CALL nesting_offl_init
1763!
1764!-- Initialize quantities for special advections schemes
1765    CALL init_advec
1766
1767!
1768!-- Impose random perturbation on the horizontal velocity field and then
1769!-- remove the divergences from the velocity field at the initial stage
1770    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND.                     &
1771         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.                                &
1772         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
1773
1774       IF ( debug_output )  THEN
1775          CALL debug_message( 'creating disturbances + applying pressure solver', 'start' )
1776       ENDIF
1777!
1778!--    Needed for both disturb_field and pres
1779!$ACC DATA &
1780!$ACC CREATE(tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
1781!$ACC COPY(u(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
1782!$ACC COPY(v(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
1783
1784       CALL disturb_field( 'u', tend, u )
1785       CALL disturb_field( 'v', tend, v )
1786
1787!$ACC DATA &
1788!$ACC CREATE(d(nzb+1:nzt,nys:nyn,nxl:nxr)) &
1789!$ACC COPY(w(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
1790!$ACC COPY(p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
1791!$ACC COPYIN(rho_air(nzb:nzt+1), rho_air_zw(nzb:nzt+1)) &
1792!$ACC COPYIN(ddzu(1:nzt+1), ddzw(1:nzt+1)) &
1793!$ACC COPYIN(wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
1794!$ACC COPYIN(bc_h(0:1)) &
1795!$ACC COPYIN(bc_h(0)%i(1:bc_h(0)%ns)) &
1796!$ACC COPYIN(bc_h(0)%j(1:bc_h(0)%ns)) &
1797!$ACC COPYIN(bc_h(0)%k(1:bc_h(0)%ns)) &
1798!$ACC COPYIN(bc_h(1)%i(1:bc_h(1)%ns)) &
1799!$ACC COPYIN(bc_h(1)%j(1:bc_h(1)%ns)) &
1800!$ACC COPYIN(bc_h(1)%k(1:bc_h(1)%ns))
1801
1802       n_sor = nsor_ini
1803       CALL pres
1804       n_sor = nsor
1805
1806!$ACC END DATA
1807!$ACC END DATA
1808
1809       IF ( debug_output )  THEN
1810          CALL debug_message( 'creating disturbances + applying pressure solver', 'end' )
1811       ENDIF
1812
1813    ENDIF
1814
1815    IF ( .NOT. ocean_mode )  THEN
1816
1817       ALLOCATE( hyp(nzb:nzt+1) )
1818       ALLOCATE( d_exner(nzb:nzt+1) )
1819       ALLOCATE( exner(nzb:nzt+1) )
1820       ALLOCATE( hyrho(nzb:nzt+1) )
1821!
1822!--    Check temperature in case of too large domain height
1823       DO  k = nzb, nzt+1
1824          IF ( ( pt_surface * exner_function( surface_pressure * 100.0_wp ) - g/c_p * zu(k) )      &
1825                 < 0.0_wp )  THEN
1826             WRITE( message_string, * )  'absolute temperature < 0.0 at zu(', k, ') = ', zu(k)
1827             CALL message( 'init_3d_model', 'PA0142', 1, 2, 0, 6, 0 )
1828          ENDIF
1829       ENDDO
1830
1831!
1832!--    Calculate vertical profile of the hydrostatic pressure (hyp)
1833       hyp    = barometric_formula( zu, pt_surface * exner_function( surface_pressure * 100.0_wp ),&
1834                                    surface_pressure * 100.0_wp )
1835       d_exner = exner_function_invers( hyp )
1836       exner = 1.0_wp / exner_function_invers( hyp )
1837       hyrho  = ideal_gas_law_rho_pt( hyp, pt_init )
1838!
1839!--    Compute reference density
1840       rho_surface = ideal_gas_law_rho( surface_pressure * 100.0_wp,                               &
1841                                        pt_surface * exner_function( surface_pressure * 100.0_wp ) )
1842
1843    ENDIF
1844
1845!
1846!-- If required, initialize particles
1847    IF ( agents_active )  CALL mas_init
1848!
1849!-- Initialization of synthetic turbulence generator
1850    IF ( syn_turb_gen )  CALL stg_init
1851!
1852!-- Initializing actions for all other modules
1853    CALL module_interface_init
1854!
1855!-- Initialize surface layer (done after LSM as roughness length are required for initialization
1856    IF ( constant_flux_layer )  CALL init_surface_layer_fluxes
1857!
1858!-- Initialize surface data output
1859    IF ( surface_output )  CALL surface_data_output_init
1860!
1861!-- Initialize the ws-scheme.
1862    IF ( ws_scheme_sca  .OR.  ws_scheme_mom )  CALL ws_init
1863!
1864!-- Perform post-initializing checks for all other modules
1865    CALL module_interface_init_checks
1866
1867!
1868!-- Initialize surface forcing corresponding to large-scale forcing. Therein,
1869!-- initialize heat-fluxes, etc. via datatype. Revise it later!
1870    IF ( large_scale_forcing  .AND.  lsf_surf )  THEN
1871       IF ( use_surface_fluxes  .AND.  constant_heatflux )  THEN
1872          CALL ls_forcing_surf( simulated_time )
1873       ENDIF
1874    ENDIF
1875!
1876!-- Setting weighting factors for calculation of perturbation pressure and turbulent quantities from
1877!-- the RK substeps.
1878    IF ( TRIM( timestep_scheme ) == 'runge-kutta-3' )  THEN      ! for RK3-method
1879
1880       weight_substep(1) = 1._wp/6._wp
1881       weight_substep(2) = 3._wp/10._wp
1882       weight_substep(3) = 8._wp/15._wp
1883
1884       weight_pres(1)    = 1._wp/3._wp
1885       weight_pres(2)    = 5._wp/12._wp
1886       weight_pres(3)    = 1._wp/4._wp
1887
1888    ELSEIF ( TRIM( timestep_scheme ) == 'runge-kutta-2' )  THEN  ! for RK2-method
1889
1890       weight_substep(1) = 1._wp/2._wp
1891       weight_substep(2) = 1._wp/2._wp
1892
1893       weight_pres(1)    = 1._wp/2._wp
1894       weight_pres(2)    = 1._wp/2._wp
1895
1896    ELSE                                     ! for Euler-method
1897
1898       weight_substep(1) = 1.0_wp
1899       weight_pres(1)    = 1.0_wp
1900
1901    ENDIF
1902
1903!
1904!-- Initialize Rayleigh damping factors
1905    rdf    = 0.0_wp
1906    rdf_sc = 0.0_wp
1907    IF ( rayleigh_damping_factor /= 0.0_wp )  THEN
1908
1909       IF (  .NOT.  ocean_mode )  THEN
1910          DO  k = nzb+1, nzt
1911             IF ( zu(k) >= rayleigh_damping_height )  THEN
1912                rdf(k) = rayleigh_damping_factor *                                                 &
1913                         ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height )                  &
1914                                / ( zu(nzt) - rayleigh_damping_height ) )                          &
1915                         )**2
1916             ENDIF
1917          ENDDO
1918       ELSE
1919!
1920!--       In ocean mode, rayleigh damping is applied in the lower part of the model domain
1921          DO  k = nzt, nzb+1, -1
1922             IF ( zu(k) <= rayleigh_damping_height )  THEN
1923                rdf(k) = rayleigh_damping_factor *                                                 &
1924                         ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) )                  &
1925                                / ( rayleigh_damping_height - zu(nzb+1) ) )                        &
1926                         )**2
1927             ENDIF
1928          ENDDO
1929       ENDIF
1930
1931    ENDIF
1932    IF ( scalar_rayleigh_damping )  rdf_sc = rdf
1933
1934!
1935!-- Initialize the starting level and the vertical smoothing factor used for the external pressure
1936!-- gradient
1937    dp_smooth_factor = 1.0_wp
1938    IF ( dp_external )  THEN
1939!
1940!--    Set the starting level dp_level_ind_b only if it has not been set before (e.g. in init_grid).
1941       IF ( dp_level_ind_b == 0 )  THEN
1942          ind_array = MINLOC( ABS( dp_level_b - zu ) )
1943          dp_level_ind_b = ind_array(1) - 1 + nzb
1944                                        ! MINLOC uses lower array bound 1
1945       ENDIF
1946       IF ( dp_smooth )  THEN
1947          dp_smooth_factor(:dp_level_ind_b) = 0.0_wp
1948          DO  k = dp_level_ind_b+1, nzt
1949             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *                                   &
1950                                             ( REAL( k - dp_level_ind_b, KIND=wp ) /               &
1951                                               REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
1952          ENDDO
1953       ENDIF
1954    ENDIF
1955
1956!
1957!-- Initialize damping zone for the potential temperature in case of non-cyclic lateral boundaries.
1958!-- The damping zone has the maximum value at the inflow boundary and decreases to zero at
1959!-- pt_damping_width.
1960    ptdf_x = 0.0_wp
1961    ptdf_y = 0.0_wp
1962    IF ( bc_lr_dirrad )  THEN
1963       DO  i = nxl, nxr
1964          IF ( ( i * dx ) < pt_damping_width )  THEN
1965             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *                                  &
1966                                                    REAL( pt_damping_width - i * dx, KIND=wp ) /   &
1967                                                    REAL( pt_damping_width, KIND=wp ) ) )**2
1968                                  ENDIF
1969       ENDDO
1970    ELSEIF ( bc_lr_raddir )  THEN
1971       DO  i = nxl, nxr
1972          IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) )  THEN
1973             ptdf_x(i) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
1974                                                  ( ( i - nx ) * dx + pt_damping_width ) /         &
1975                                                  REAL( pt_damping_width, KIND=wp ) )**2
1976          ENDIF
1977       ENDDO
1978    ELSEIF ( bc_ns_dirrad )  THEN
1979       DO  j = nys, nyn
1980          IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) )  THEN
1981             ptdf_y(j) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
1982                                                  ( ( j - ny ) * dy + pt_damping_width ) /         &
1983                                                  REAL( pt_damping_width, KIND=wp ) )**2
1984          ENDIF
1985       ENDDO
1986    ELSEIF ( bc_ns_raddir )  THEN
1987       DO  j = nys, nyn
1988          IF ( ( j * dy ) < pt_damping_width )  THEN
1989             ptdf_y(j) = pt_damping_factor * SIN( pi * 0.5_wp *                                    &
1990                                                  ( pt_damping_width - j * dy ) /                  &
1991                                                  REAL( pt_damping_width, KIND=wp ) )**2
1992          ENDIF
1993       ENDDO
1994    ENDIF
1995
1996!
1997!-- Input binary data file is not needed anymore. This line must be placed after call of user_init!
1998    CALL close_file( 13 )
1999!
2000!-- In case of nesting, put an barrier to assure that all parent and child domains finished
2001!-- initialization.
2002#if defined( __parallel )
2003    IF ( nested_run )  CALL MPI_BARRIER( MPI_COMM_WORLD, ierr )
2004#endif
2005
2006
2007    CALL location_message( 'model initialization', 'finished' )
2008
2009 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.