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

Last change on this file since 4676 was 4671, checked in by pavelkrc, 4 years ago

Radiative transfer model RTM version 4.1

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