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

Last change on this file since 786 was 786, checked in by raasch, 12 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 58.8 KB
RevLine 
[1]1#if defined( __ibmy_special )
2@PROCESS NOOPTimize
3#endif
4 SUBROUTINE init_3d_model
5
6!------------------------------------------------------------------------------!
[254]7! Current revisions:
[732]8! ------------------
[786]9!
[708]10!
11! Former revisions:
12! -----------------
13! $Id: init_3d_model.f90 786 2011-11-28 10:06:08Z raasch $
14!
[786]15! 785 2011-11-28 09:47:19Z raasch
16! initialization of rdf_sc
17!
[768]18! 767 2011-10-14 06:39:12Z raasch
19! adjustments concerning implementation of prescribed u,v-profiles
20! bugfix: dirichlet_0 conditions for ug/vg moved to check_parameters
21!
[760]22! 759 2011-09-15 13:58:31Z raasch
23! Splitting of parallel I/O in blocks of PEs
24! Bugfix: No zero assignments to volume_flow_initial and volume_flow_area in
25! case of normal restart runs.
26!
[714]27! 713 2011-03-30 14:21:21Z suehring
[732]28! weight_substep and weight_pres are given as fractions.
[714]29!
[710]30! 709 2011-03-30 09:31:40Z raasch
31! formatting adjustments
32!
[708]33! 707 2011-03-29 11:39:40Z raasch
[707]34! p_sub renamed p_loc and allocated depending on the chosen pressure solver,
35! initial assignments of zero to array p for iterative solvers only,
36! bc_lr/ns replaced by bc_lr/ns_dirrad/raddir
[674]37!
[708]38! 680 2011-02-04 23:16:06Z gryschka
[681]39! bugfix: volume_flow_control
[668]40!
[674]41! 673 2011-01-18 16:19:48Z suehring
42! weight_substep (moved from advec_ws) and weight_pres added.
43! Allocate p_sub when using Multigrid or SOR solver.
44! Call of ws_init moved behind the if requests.
45!
[668]46! 667 2010-12-23 12:06:00Z suehring/gryschka
[667]47! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng in loops and
48! allocation of arrays. Calls of exchange_horiz are modified.
[709]49! Call ws_init to initialize arrays needed for calculating statisticas and for
[667]50! optimization when ws-scheme is used.
51! Initial volume flow is now calculated by using the variable hom_sum.
52! Therefore the correction of initial volume flow for non-flat topography
53! removed (removed u_nzb_p1_for_vfc and v_nzb_p1_for_vfc)
54! Changed surface boundary conditions for u and v in case of ibc_uv_b == 0 from
[709]55! mirror to Dirichlet boundary conditions (u=v=0), so that k=nzb is
56! representative for the height z0.
[667]57! Bugfix: type conversion of '1' to 64bit for the MAX function (ngp_3d_inner)
58!
[623]59! 622 2010-12-10 08:08:13Z raasch
60! optional barriers included in order to speed up collective operations
61!
[561]62! 560 2010-09-09 10:06:09Z weinreis
63! bugfix: correction of calculating ngp_3d for 64 bit
64!
[486]65! 485 2010-02-05 10:57:51Z raasch
66! calculation of ngp_3d + ngp_3d_inner changed because they have now 64 bit
67!
[482]68! 407 2009-12-01 15:01:15Z maronga
69! var_ts is replaced by dots_max
70! Enabled passive scalar/humidity wall fluxes for non-flat topography
71!
[392]72! 388 2009-09-23 09:40:33Z raasch
[388]73! Initialization of prho added.
[359]74! bugfix: correction of initial volume flow for non-flat topography
75! bugfix: zero initialization of arrays within buildings for 'cyclic_fill'
[333]76! bugfix: avoid that ngp_2dh_s_inner becomes zero
[328]77! initializing_actions='read_data_for_recycling' renamed to 'cyclic_fill', now
78! independent of turbulent_inflow
[254]79! Output of messages replaced by message handling routine.
[240]80! Set the starting level and the vertical smoothing factor used for
81! the external pressure gradient
[254]82! +conserve_volume_flow_mode: 'default', 'initial_profiles', 'inflow_profile'
[241]83! and 'bulk_velocity'
[292]84! If the inversion height calculated by the prerun is zero,
85! inflow_damping_height must be explicitly specified.
[139]86!
[198]87! 181 2008-07-30 07:07:47Z raasch
88! bugfix: zero assignments to tendency arrays in case of restarts,
89! further extensions and modifications in the initialisation of the plant
90! canopy model,
91! allocation of hom_sum moved to parin, initialization of spectrum_x|y directly
92! after allocating theses arrays,
93! read data for recycling added as new initialization option,
94! dummy allocation for diss
95!
[139]96! 138 2007-11-28 10:03:58Z letzel
[132]97! New counter ngp_2dh_s_inner.
98! Allow new case bc_uv_t = 'dirichlet_0' for channel flow.
99! Corrected calculation of initial volume flow for 'set_1d-model_profiles' and
100! 'set_constant_profiles' in case of buildings in the reference cross-sections.
[77]101!
[110]102! 108 2007-08-24 15:10:38Z letzel
103! Flux initialization in case of coupled runs, +momentum fluxes at top boundary,
104! +arrays for phase speed c_u, c_v, c_w, indices for u|v|w_m_l|r changed
105! +qswst_remote in case of atmosphere model with humidity coupled to ocean
106! Rayleigh damping for ocean, optionally calculate km and kh from initial
107! TKE e_init
108!
[98]109! 97 2007-06-21 08:23:15Z raasch
110! Initialization of salinity, call of init_ocean
111!
[90]112! 87 2007-05-22 15:46:47Z raasch
113! var_hom and var_sum renamed pr_palm
114!
[77]115! 75 2007-03-22 09:54:05Z raasch
[73]116! Arrays for radiation boundary conditions are allocated (u_m_l, u_m_r, etc.),
117! bugfix for cases with the outflow damping layer extending over more than one
[75]118! subdomain, moisture renamed humidity,
119! new initializing action "by_user" calls user_init_3d_model,
[72]120! precipitation_amount/rate, ts_value are allocated, +module netcdf_control,
[51]121! initial velocities at nzb+1 are regarded for volume
122! flow control in case they have been set zero before (to avoid small timesteps)
[75]123! -uvmean_outflow, uxrp, vynp eliminated
[1]124!
[39]125! 19 2007-02-23 04:53:48Z raasch
126! +handling of top fluxes
127!
[3]128! RCS Log replace by Id keyword, revision history cleaned up
129!
[1]130! Revision 1.49  2006/08/22 15:59:07  raasch
131! No optimization of this file on the ibmy (Yonsei Univ.)
132!
133! Revision 1.1  1998/03/09 16:22:22  raasch
134! Initial revision
135!
136!
137! Description:
138! ------------
139! Allocation of arrays and initialization of the 3D model via
140! a) pre-run the 1D model
141! or
142! b) pre-set constant linear profiles
143! or
144! c) read values of a previous run
145!------------------------------------------------------------------------------!
146
[667]147    USE advec_ws
[1]148    USE arrays_3d
149    USE averaging
[72]150    USE cloud_parameters
[1]151    USE constants
152    USE control_parameters
153    USE cpulog
154    USE indices
155    USE interfaces
156    USE model_1d
[51]157    USE netcdf_control
[1]158    USE particle_attributes
159    USE pegrid
160    USE profil_parameter
161    USE random_function_mod
162    USE statistics
163
164    IMPLICIT NONE
165
[559]166    INTEGER ::  i, ind_array(1), j, k, sr
[1]167
[485]168    INTEGER, DIMENSION(:), ALLOCATABLE ::  ngp_2dh_l
[1]169
[132]170    INTEGER, DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l,  &
171         ngp_2dh_s_inner_l
[1]172
[153]173    REAL ::  a, b
174
[1]175    REAL, DIMENSION(1:2) ::  volume_flow_area_l, volume_flow_initial_l
176
[485]177    REAL, DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l, ngp_3d_inner_tmp
[1]178
[485]179
[1]180!
181!-- Allocate arrays
182    ALLOCATE( ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions), &
183              ngp_3d(0:statistic_regions),                                  &
184              ngp_3d_inner(0:statistic_regions),                            &
185              ngp_3d_inner_l(0:statistic_regions),                          &
[485]186              ngp_3d_inner_tmp(0:statistic_regions),                        &
[1]187              sums_divnew_l(0:statistic_regions),                           &
188              sums_divold_l(0:statistic_regions) )
[785]189    ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
[143]190    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                 &
[1]191              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),               &
[132]192              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),               &
193              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),             &
[667]194              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),           &
[87]195              sums(nzb:nzt+1,pr_palm+max_pr_user),                          &
196              sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1),   &
[1]197              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1), &
198              sums_up_fraction_l(10,3,0:statistic_regions),                 &
[48]199              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions),                &
[394]200              ts_value(dots_max,0:statistic_regions) )
[667]201    ALLOCATE( km_damp_x(nxlg:nxrg), km_damp_y(nysg:nyng) )
[1]202
[667]203    ALLOCATE( rif_1(nysg:nyng,nxlg:nxrg), shf_1(nysg:nyng,nxlg:nxrg), &
204              ts(nysg:nyng,nxlg:nxrg), tswst_1(nysg:nyng,nxlg:nxrg),  &
205              us(nysg:nyng,nxlg:nxrg), usws_1(nysg:nyng,nxlg:nxrg),   &
206              uswst_1(nysg:nyng,nxlg:nxrg),                               &
207              vsws_1(nysg:nyng,nxlg:nxrg),                                &
208              vswst_1(nysg:nyng,nxlg:nxrg), z0(nysg:nyng,nxlg:nxrg) )
[1]209
210    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
211!
212!--    Leapfrog scheme needs two timelevels of diffusion quantities
[667]213       ALLOCATE( rif_2(nysg:nyng,nxlg:nxrg),   &
214                 shf_2(nysg:nyng,nxlg:nxrg),   &
215                 tswst_2(nysg:nyng,nxlg:nxrg), &
216                 usws_2(nysg:nyng,nxlg:nxrg),  &
217                 uswst_2(nysg:nyng,nxlg:nxrg), &
218                 vswst_2(nysg:nyng,nxlg:nxrg), &
219                 vsws_2(nysg:nyng,nxlg:nxrg) )
[1]220    ENDIF
221
[75]222    ALLOCATE( d(nzb+1:nzta,nys:nyna,nxl:nxra),         &
[667]223              e_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
224              e_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
225              e_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
226              kh_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
227              km_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
228              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),    &
229              pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
230              pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
231              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
232              tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
233              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
234              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
235              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
236              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
237              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
238              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
239              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
240              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
241              w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[673]242!
[707]243!-- Following array is required for perturbation pressure within the iterative
244!-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds
245!-- the weighted average of the substeps and cannot be used in the Poisson
246!-- solver.
247    IF ( psolver == 'sor' )  THEN
248       ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
249    ELSEIF ( psolver == 'multigrid' )  THEN
250!
251!--    For performance reasons, multigrid is using one ghost layer only
252       ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
[673]253    ENDIF
[1]254
255    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
[667]256       ALLOCATE( kh_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
257                 km_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]258    ENDIF
259
[75]260    IF ( humidity  .OR.  passive_scalar ) THEN
[1]261!
[75]262!--    2D-humidity/scalar arrays
[667]263       ALLOCATE ( qs(nysg:nyng,nxlg:nxrg),     &
264                  qsws_1(nysg:nyng,nxlg:nxrg), &
265                  qswst_1(nysg:nyng,nxlg:nxrg) )
[1]266
267       IF ( timestep_scheme(1:5) /= 'runge' )  THEN
[667]268          ALLOCATE( qsws_2(nysg:nyng,nxlg:nxrg), &
269                    qswst_2(nysg:nyng,nxlg:nxrg) )
[1]270       ENDIF
271!
[75]272!--    3D-humidity/scalar arrays
[667]273       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
274                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
275                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]276
277!
[75]278!--    3D-arrays needed for humidity only
279       IF ( humidity )  THEN
[667]280          ALLOCATE( vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]281
282          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
[667]283             ALLOCATE( vpt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]284          ENDIF
285
286          IF ( cloud_physics ) THEN
287!
288!--          Liquid water content
[667]289             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[72]290!
291!--          Precipitation amount and rate (only needed if output is switched)
[667]292             ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg), &
293                       precipitation_rate(nysg:nyng,nxlg:nxrg) )
[1]294          ENDIF
295
296          IF ( cloud_droplets )  THEN
297!
298!--          Liquid water content, change in liquid water content,
299!--          real volume of particles (with weighting), volume of particles
[667]300             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
301                        ql_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
302                        ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
303                        ql_vp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]304          ENDIF
305
306       ENDIF
307
308    ENDIF
309
[94]310    IF ( ocean )  THEN
[667]311       ALLOCATE( saswsb_1(nysg:nyng,nxlg:nxrg), &
312                 saswst_1(nysg:nyng,nxlg:nxrg) )
313       ALLOCATE( prho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
314                 rho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
315                 sa_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),   &
316                 sa_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),   &
317                 sa_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[388]318       prho => prho_1
319       rho  => rho_1  ! routines calc_mean_profile and diffusion_e require
320                      ! density to be apointer
[108]321       IF ( humidity_remote )  THEN
[667]322          ALLOCATE( qswst_remote(nysg:nyng,nxlg:nxrg))
[108]323          qswst_remote = 0.0
324       ENDIF
[94]325    ENDIF
326
[1]327!
328!-- 3D-array for storing the dissipation, needed for calculating the sgs
329!-- particle velocities
330    IF ( use_sgs_for_particles )  THEN
[667]331       ALLOCATE ( diss(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[181]332    ELSE
333       ALLOCATE ( diss(2,2,2) )  ! required because diss is used as a
334                                 ! formal parameter
[1]335    ENDIF
336
337    IF ( dt_dosp /= 9999999.9 )  THEN
338       ALLOCATE( spectrum_x( 1:nx/2, 1:10, 1:10 ), &
339                 spectrum_y( 1:ny/2, 1:10, 1:10 ) )
[146]340       spectrum_x = 0.0
341       spectrum_y = 0.0
[1]342    ENDIF
343
344!
[138]345!-- 3D-arrays for the leaf area density and the canopy drag coefficient
346    IF ( plant_canopy ) THEN
[667]347       ALLOCATE ( lad_s(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
348                  lad_u(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
349                  lad_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
350                  lad_w(nzb:nzt+1,nysg:nyng,nxlg:nxrg),  &
351                  cdc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[153]352
353       IF ( passive_scalar ) THEN
[667]354          ALLOCATE ( sls(nzb:nzt+1,nysg:nyng,nxlg:nxrg),   &
355                     sec(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) 
[153]356       ENDIF
357
358       IF ( cthf /= 0.0 ) THEN
[667]359          ALLOCATE ( lai(nzb:nzt+1,nysg:nyng,nxlg:nxrg),   &
360                     canopy_heat_flux(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[153]361       ENDIF
362
[138]363    ENDIF
364
365!
[51]366!-- 4D-array for storing the Rif-values at vertical walls
367    IF ( topography /= 'flat' )  THEN
[667]368       ALLOCATE( rif_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg,1:4) )
[51]369       rif_wall = 0.0
370    ENDIF
371
372!
[106]373!-- Arrays to store velocity data from t-dt and the phase speeds which
374!-- are needed for radiation boundary conditions
[73]375    IF ( outflow_l )  THEN
[667]376       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2), &
377                 v_m_l(nzb:nzt+1,nysg:nyng,0:1), &
378                 w_m_l(nzb:nzt+1,nysg:nyng,0:1) )
[73]379    ENDIF
380    IF ( outflow_r )  THEN
[667]381       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx), &
382                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx), &
383                 w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) )
[73]384    ENDIF
[106]385    IF ( outflow_l  .OR.  outflow_r )  THEN
[667]386       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng), &
387                 c_w(nzb:nzt+1,nysg:nyng) )
[106]388    ENDIF
[73]389    IF ( outflow_s )  THEN
[667]390       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg), &
391                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg), &
392                 w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) )
[73]393    ENDIF
394    IF ( outflow_n )  THEN
[667]395       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg), &
396                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg), &
397                 w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) )
[73]398    ENDIF
[106]399    IF ( outflow_s  .OR.  outflow_n )  THEN
[667]400       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg), &
401                 c_w(nzb:nzt+1,nxlg:nxrg) )
[106]402    ENDIF
[73]403
404!
[1]405!-- Initial assignment of the pointers
406    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
407
[19]408       rif_m   => rif_1;    rif   => rif_2
409       shf_m   => shf_1;    shf   => shf_2
410       tswst_m => tswst_1;  tswst => tswst_2
411       usws_m  => usws_1;   usws  => usws_2
[102]412       uswst_m => uswst_1;  uswst => uswst_2
[19]413       vsws_m  => vsws_1;   vsws  => vsws_2
[102]414       vswst_m => vswst_1;  vswst => vswst_2
[1]415       e_m  => e_1;   e  => e_2;   e_p  => e_3;   te_m  => e_3
416       kh_m => kh_1;  kh => kh_2
417       km_m => km_1;  km => km_2
418       pt_m => pt_1;  pt => pt_2;  pt_p => pt_3;  tpt_m => pt_3
419       u_m  => u_1;   u  => u_2;   u_p  => u_3;   tu_m  => u_3
420       v_m  => v_1;   v  => v_2;   v_p  => v_3;   tv_m  => v_3
421       w_m  => w_1;   w  => w_2;   w_p  => w_3;   tw_m  => w_3
422
[75]423       IF ( humidity  .OR.  passive_scalar )  THEN
[19]424          qsws_m  => qsws_1;   qsws  => qsws_2
425          qswst_m => qswst_1;  qswst => qswst_2
[1]426          q_m    => q_1;     q    => q_2;     q_p => q_3;     tq_m => q_3
[75]427          IF ( humidity )        vpt_m  => vpt_1;   vpt  => vpt_2
[1]428          IF ( cloud_physics )   ql   => ql_1
429          IF ( cloud_droplets )  THEN
430             ql   => ql_1
431             ql_c => ql_2
432          ENDIF
433       ENDIF
434
435    ELSE
436
[19]437       rif   => rif_1
438       shf   => shf_1
439       tswst => tswst_1
440       usws  => usws_1
[102]441       uswst => uswst_1
[19]442       vsws  => vsws_1
[102]443       vswst => vswst_1
[19]444       e     => e_1;   e_p  => e_2;   te_m  => e_3;   e_m  => e_3
445       kh    => kh_1
446       km    => km_1
447       pt    => pt_1;  pt_p => pt_2;  tpt_m => pt_3;  pt_m => pt_3
448       u     => u_1;   u_p  => u_2;   tu_m  => u_3;   u_m  => u_3
449       v     => v_1;   v_p  => v_2;   tv_m  => v_3;   v_m  => v_3
450       w     => w_1;   w_p  => w_2;   tw_m  => w_3;   w_m  => w_3
[1]451
[75]452       IF ( humidity  .OR.  passive_scalar )  THEN
[1]453          qsws   => qsws_1
[19]454          qswst  => qswst_1
[94]455          q      => q_1;     q_p  => q_2;     tq_m  => q_3;    q_m => q_3
[75]456          IF ( humidity )        vpt  => vpt_1
[1]457          IF ( cloud_physics )   ql   => ql_1
458          IF ( cloud_droplets )  THEN
459             ql   => ql_1
460             ql_c => ql_2
461          ENDIF
462       ENDIF
463
[94]464       IF ( ocean )  THEN
[95]465          saswsb => saswsb_1
[94]466          saswst => saswst_1
467          sa     => sa_1;    sa_p => sa_2;    tsa_m => sa_3
468       ENDIF
469
[1]470    ENDIF
[673]471   
[1]472!
[709]473!-- Allocate arrays containing the RK coefficient for calculation of
474!-- perturbation pressure and turbulent fluxes. At this point values are
475!-- set for pressure calculation during initialization (where no timestep
476!-- is done). Further below the values needed within the timestep scheme
477!-- will be set.
478    ALLOCATE( weight_substep(1:intermediate_timestep_count_max), &
[673]479              weight_pres(1:intermediate_timestep_count_max) )
[709]480    weight_substep = 1.0
481    weight_pres    = 1.0
482    intermediate_timestep_count = 1  ! needed when simulated_time = 0.0
[673]483       
484!
[1]485!-- Initialize model variables
[147]486    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.  &
[328]487         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[1]488!
489!--    First model run of a possible job queue.
490!--    Initial profiles of the variables must be computes.
491       IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
492!
493!--       Use solutions of the 1D model as initial profiles,
494!--       start 1D model
495          CALL init_1d_model
496!
497!--       Transfer initial profiles to the arrays of the 3D model
[667]498          DO  i = nxlg, nxrg
499             DO  j = nysg, nyng
[1]500                e(:,j,i)  = e1d
501                kh(:,j,i) = kh1d
502                km(:,j,i) = km1d
503                pt(:,j,i) = pt_init
504                u(:,j,i)  = u1d
505                v(:,j,i)  = v1d
506             ENDDO
507          ENDDO
508
[75]509          IF ( humidity  .OR.  passive_scalar )  THEN
[667]510             DO  i = nxlg, nxrg
511                DO  j = nysg, nyng
[1]512                   q(:,j,i) = q_init
513                ENDDO
514             ENDDO
515          ENDIF
516
517          IF ( .NOT. constant_diffusion )  THEN
[667]518             DO  i = nxlg, nxrg
519                DO  j = nysg, nyng
[1]520                   e(:,j,i)  = e1d
521                ENDDO
522             ENDDO
523!
524!--          Store initial profiles for output purposes etc.
525             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
526
527             IF ( prandtl_layer )  THEN
528                rif  = rif1d(nzb+1)
529                ts   = 0.0  ! could actually be computed more accurately in the
530                            ! 1D model. Update when opportunity arises.
531                us   = us1d
532                usws = usws1d
533                vsws = vsws1d
534             ELSE
535                ts   = 0.0  ! must be set, because used in
536                rif  = 0.0  ! flowste
537                us   = 0.0
538                usws = 0.0
539                vsws = 0.0
540             ENDIF
541
542          ELSE
543             e    = 0.0  ! must be set, because used in
544             rif  = 0.0  ! flowste
545             ts   = 0.0
546             us   = 0.0
547             usws = 0.0
548             vsws = 0.0
549          ENDIF
[102]550          uswst = top_momentumflux_u
551          vswst = top_momentumflux_v
[1]552
553!
554!--       In every case qs = 0.0 (see also pt)
555!--       This could actually be computed more accurately in the 1D model.
556!--       Update when opportunity arises!
[75]557          IF ( humidity  .OR.  passive_scalar )  qs = 0.0
[1]558
559!
560!--       inside buildings set velocities back to zero
561          IF ( topography /= 'flat' )  THEN
562             DO  i = nxl-1, nxr+1
563                DO  j = nys-1, nyn+1
564                   u(nzb:nzb_u_inner(j,i),j,i) = 0.0
565                   v(nzb:nzb_v_inner(j,i),j,i) = 0.0
566                ENDDO
567             ENDDO
[667]568             
[1]569!
570!--          WARNING: The extra boundary conditions set after running the
571!--          -------  1D model impose an error on the divergence one layer
572!--                   below the topography; need to correct later
573!--          ATTENTION: Provisional correction for Piacsek & Williams
574!--          ---------  advection scheme: keep u and v zero one layer below
575!--                     the topography.
576!
[667]577!--           Following was removed, because mirror boundary condition are
578!--           replaced by dirichlet boundary conditions
[1]579!
[667]580!             IF ( ibc_uv_b == 0 )  THEN
581!!
582!!--             Satisfying the Dirichlet condition with an extra layer below
583!!--             the surface where the u and v component change their sign.
584!                DO  i = nxl-1, nxr+1
585!                   DO  j = nys-1, nyn+1
586!                      IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = -u(1,j,i)
587!                      IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = -v(1,j,i)
588!                   ENDDO
589!                ENDDO
590!
591!             ELSE
592             IF ( ibc_uv_b == 1 )  THEN
593!
[1]594!--             Neumann condition
595                DO  i = nxl-1, nxr+1
596                   DO  j = nys-1, nyn+1
597                      IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = u(1,j,i)
598                      IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = v(1,j,i)
599                   ENDDO
600                ENDDO
601
602             ENDIF
603
604          ENDIF
605
606       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 ) &
607       THEN
608!
609!--       Use constructed initial profiles (velocity constant with height,
610!--       temperature profile with constant gradient)
[667]611          DO  i = nxlg, nxrg
612             DO  j = nysg, nyng
[1]613                pt(:,j,i) = pt_init
614                u(:,j,i)  = u_init
615                v(:,j,i)  = v_init
616             ENDDO
617          ENDDO
[75]618
[1]619!
[292]620!--       Set initial horizontal velocities at the lowest computational grid
621!--       levels to zero in order to avoid too small time steps caused by the
622!--       diffusion limit in the initial phase of a run (at k=1, dz/2 occurs
623!--       in the limiting formula!). The original values are stored to be later
624!--       used for volume flow control.
[667]625          DO  i = nxlg, nxrg
626             DO  j = nysg, nyng
[1]627                u(nzb:nzb_u_inner(j,i)+1,j,i) = 0.0
628                v(nzb:nzb_v_inner(j,i)+1,j,i) = 0.0
629             ENDDO
630          ENDDO
631
[75]632          IF ( humidity  .OR.  passive_scalar )  THEN
[667]633             DO  i = nxlg, nxrg
634                DO  j = nysg, nyng
[1]635                   q(:,j,i) = q_init
636                ENDDO
637             ENDDO
638          ENDIF
639
[94]640          IF ( ocean )  THEN
[667]641             DO  i = nxlg, nxrg
642                DO  j = nysg, nyng
[94]643                   sa(:,j,i) = sa_init
644                ENDDO
645             ENDDO
646          ENDIF
[1]647         
648          IF ( constant_diffusion )  THEN
649             km   = km_constant
650             kh   = km / prandtl_number
[108]651             e    = 0.0
652          ELSEIF ( e_init > 0.0 )  THEN
653             DO  k = nzb+1, nzt
654                km(k,:,:) = 0.1 * l_grid(k) * SQRT( e_init )
655             ENDDO
656             km(nzb,:,:)   = km(nzb+1,:,:)
657             km(nzt+1,:,:) = km(nzt,:,:)
658             kh   = km / prandtl_number
659             e    = e_init
[1]660          ELSE
[108]661             IF ( .NOT. ocean )  THEN
662                kh   = 0.01   ! there must exist an initial diffusion, because
663                km   = 0.01   ! otherwise no TKE would be produced by the
664                              ! production terms, as long as not yet
665                              ! e = (u*/cm)**2 at k=nzb+1
666             ELSE
667                kh   = 0.00001
668                km   = 0.00001
669             ENDIF
670             e    = 0.0
[1]671          ENDIF
[102]672          rif   = 0.0
673          ts    = 0.0
674          us    = 0.0
675          usws  = 0.0
676          uswst = top_momentumflux_u
677          vsws  = 0.0
678          vswst = top_momentumflux_v
[75]679          IF ( humidity  .OR.  passive_scalar ) qs = 0.0
[1]680
681!
682!--       Compute initial temperature field and other constants used in case
683!--       of a sloping surface
684          IF ( sloping_surface )  CALL init_slope
685
[46]686       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 ) &
687       THEN
688!
689!--       Initialization will completely be done by the user
690          CALL user_init_3d_model
691
[1]692       ENDIF
[667]693!
694!--    Bottom boundary
695       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2  )  THEN
696          u(nzb,:,:) = 0.0
697          v(nzb,:,:) = 0.0
698       ENDIF
[1]699
700!
[151]701!--    Apply channel flow boundary condition
[132]702       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
703          u(nzt+1,:,:) = 0.0
704          v(nzt+1,:,:) = 0.0
705       ENDIF
706
707!
[1]708!--    Calculate virtual potential temperature
[75]709       IF ( humidity ) vpt = pt * ( 1.0 + 0.61 * q )
[1]710
711!
712!--    Store initial profiles for output purposes etc.
713       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
714       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
[667]715       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2)  THEN
716          hom(nzb,1,5,:) = 0.0   
717          hom(nzb,1,6,:) = 0.0 
[1]718       ENDIF
719       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
720       hom(:,1,23,:) = SPREAD( km(:,nys,nxl), 2, statistic_regions+1 )
721       hom(:,1,24,:) = SPREAD( kh(:,nys,nxl), 2, statistic_regions+1 )
722
[97]723       IF ( ocean )  THEN
724!
725!--       Store initial salinity profile
726          hom(:,1,26,:)  = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 )
727       ENDIF
[1]728
[75]729       IF ( humidity )  THEN
[1]730!
731!--       Store initial profile of total water content, virtual potential
732!--       temperature
733          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
734          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
735          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
736!
737!--          Store initial profile of specific humidity and potential
738!--          temperature
739             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
740             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
741          ENDIF
742       ENDIF
743
744       IF ( passive_scalar )  THEN
745!
746!--       Store initial scalar profile
747          hom(:,1,26,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
748       ENDIF
749
750!
[19]751!--    Initialize fluxes at bottom surface
[1]752       IF ( use_surface_fluxes )  THEN
753
754          IF ( constant_heatflux )  THEN
755!
756!--          Heat flux is prescribed
757             IF ( random_heatflux )  THEN
758                CALL disturb_heatflux
759             ELSE
760                shf = surface_heatflux
761!
762!--             Over topography surface_heatflux is replaced by wall_heatflux(0)
763                IF ( TRIM( topography ) /= 'flat' )  THEN
[667]764                   DO  i = nxlg, nxrg
765                      DO  j = nysg, nyng
[1]766                         IF ( nzb_s_inner(j,i) /= 0 )  THEN
767                            shf(j,i) = wall_heatflux(0)
768                         ENDIF
769                      ENDDO
770                   ENDDO
771                ENDIF
772             ENDIF
773             IF ( ASSOCIATED( shf_m ) )  shf_m = shf
774          ENDIF
775
776!
777!--       Determine the near-surface water flux
[75]778          IF ( humidity  .OR.  passive_scalar )  THEN
[1]779             IF ( constant_waterflux )  THEN
780                qsws   = surface_waterflux
[407]781!
782!--             Over topography surface_waterflux is replaced by
783!--             wall_humidityflux(0)
784                IF ( TRIM( topography ) /= 'flat' )  THEN
785                   wall_qflux = wall_humidityflux
[667]786                   DO  i = nxlg, nxrg
787                      DO  j = nysg, nyng
[407]788                         IF ( nzb_s_inner(j,i) /= 0 )  THEN
789                            qsws(j,i) = wall_qflux(0)
790                         ENDIF
791                      ENDDO
792                   ENDDO
793                ENDIF
[1]794                IF ( ASSOCIATED( qsws_m ) )  qsws_m = qsws
795             ENDIF
796          ENDIF
797
798       ENDIF
799
800!
[19]801!--    Initialize fluxes at top surface
[94]802!--    Currently, only the heatflux and salinity flux can be prescribed.
803!--    The latent flux is zero in this case!
[19]804       IF ( use_top_fluxes )  THEN
805
806          IF ( constant_top_heatflux )  THEN
807!
808!--          Heat flux is prescribed
809             tswst = top_heatflux
810             IF ( ASSOCIATED( tswst_m ) )  tswst_m = tswst
811
[75]812             IF ( humidity  .OR.  passive_scalar )  THEN
[19]813                qswst = 0.0
814                IF ( ASSOCIATED( qswst_m ) )  qswst_m = qswst
815             ENDIF
[94]816
817             IF ( ocean )  THEN
[95]818                saswsb = bottom_salinityflux
[94]819                saswst = top_salinityflux
820             ENDIF
[102]821          ENDIF
[19]822
[102]823!
824!--       Initialization in case of a coupled model run
825          IF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
826             tswst = 0.0
827             IF ( ASSOCIATED( tswst_m ) )  tswst_m = tswst
828          ENDIF
829
[19]830       ENDIF
831
832!
[1]833!--    Initialize Prandtl layer quantities
834       IF ( prandtl_layer )  THEN
835
836          z0 = roughness_length
837
838          IF ( .NOT. constant_heatflux )  THEN 
839!
840!--          Surface temperature is prescribed. Here the heat flux cannot be
841!--          simply estimated, because therefore rif, u* and theta* would have
842!--          to be computed by iteration. This is why the heat flux is assumed
843!--          to be zero before the first time step. It approaches its correct
844!--          value in the course of the first few time steps.
845             shf   = 0.0
846             IF ( ASSOCIATED( shf_m ) )  shf_m = 0.0
847          ENDIF
848
[75]849          IF ( humidity  .OR.  passive_scalar )  THEN
[1]850             IF ( .NOT. constant_waterflux )  THEN
851                qsws   = 0.0
852                IF ( ASSOCIATED( qsws_m ) )   qsws_m = 0.0
853             ENDIF
854          ENDIF
855
856       ENDIF
857
[152]858
859!
[707]860!--    For the moment, vertical velocity is zero
861       w = 0.0
[1]862
863!
864!--    Initialize array sums (must be defined in first call of pres)
865       sums = 0.0
866
867!
[707]868!--    In case of iterative solvers, p must get an initial value
869       IF ( psolver == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0
870
871!
[72]872!--    Treating cloud physics, liquid water content and precipitation amount
873!--    are zero at beginning of the simulation
874       IF ( cloud_physics )  THEN
875          ql = 0.0
876          IF ( precipitation )  precipitation_amount = 0.0
877       ENDIF
[673]878       
879!
880!--    Initialize quantities for special advections schemes
881       CALL init_advec
[1]882
883!
884!--    Impose vortex with vertical axis on the initial velocity profile
885       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
886          CALL init_rankine
887       ENDIF
888
889!
890!--    Impose temperature anomaly (advection test only)
891       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 )  THEN
892          CALL init_pt_anomaly
893       ENDIF
894
895!
896!--    If required, change the surface temperature at the start of the 3D run
897       IF ( pt_surface_initial_change /= 0.0 )  THEN
898          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
899       ENDIF
900
901!
902!--    If required, change the surface humidity/scalar at the start of the 3D
903!--    run
[75]904       IF ( ( humidity .OR. passive_scalar ) .AND. &
[1]905            q_surface_initial_change /= 0.0 )  THEN
906          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
907       ENDIF
908
909!
910!--    Initialize the random number generator (from numerical recipes)
911       CALL random_function_ini
912
913!
914!--    Initialize old and new time levels.
915       IF ( timestep_scheme(1:5) /= 'runge' )  THEN
916          e_m = e; pt_m = pt; u_m = u; v_m = v; w_m = w; kh_m = kh; km_m = km
917       ELSE
918          te_m = 0.0; tpt_m = 0.0; tu_m = 0.0; tv_m = 0.0; tw_m = 0.0
919       ENDIF
920       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
921
[75]922       IF ( humidity  .OR.  passive_scalar )  THEN
[1]923          IF ( ASSOCIATED( q_m ) )  q_m = q
924          IF ( timestep_scheme(1:5) == 'runge' )  tq_m = 0.0
925          q_p = q
[75]926          IF ( humidity  .AND.  ASSOCIATED( vpt_m ) )  vpt_m = vpt
[1]927       ENDIF
928
[94]929       IF ( ocean )  THEN
930          tsa_m = 0.0
931          sa_p  = sa
932       ENDIF
[667]933       
[94]934
[147]935    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.    &
[667]936         TRIM( initializing_actions ) == 'cyclic_fill' )  &
[1]937    THEN
938!
[767]939!--    When reading data for cyclic fill of 3D prerun data files, read
940!--    some of the global variables from the restart file which are required
941!--    for initializing the inflow
[328]942       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
[559]943
[759]944          DO  i = 0, io_blocks-1
945             IF ( i == io_group )  THEN
946                CALL read_parts_of_var_list
947                CALL close_file( 13 )
948             ENDIF
949#if defined( __parallel )
950             CALL MPI_BARRIER( comm2d, ierr )
951#endif
952          ENDDO
[328]953
[767]954       ENDIF
955
[151]956!
[767]957!--    Read binary data from restart file
958       DO  i = 0, io_blocks-1
959          IF ( i == io_group )  THEN
960             CALL read_3d_binary
961          ENDIF
962#if defined( __parallel )
963          CALL MPI_BARRIER( comm2d, ierr )
964#endif
965       ENDDO
966
[328]967!
[767]968!--    Initialization of the turbulence recycling method
969       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.  &
970            turbulent_inflow )  THEN
971!
972!--       First store the profiles to be used at the inflow.
973!--       These profiles are the (temporally) and horizontally averaged vertical
974!--       profiles from the prerun. Alternatively, prescribed profiles
975!--       for u,v-components can be used.
976          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,5) )
[151]977
[767]978          IF ( use_prescribed_profile_data )  THEN
979             mean_inflow_profiles(:,1) = u_init            ! u
980             mean_inflow_profiles(:,2) = v_init            ! v
981          ELSE
[328]982             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
983             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
[767]984          ENDIF
985          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
986          mean_inflow_profiles(:,5) = hom_sum(:,8,0)       ! e
[151]987
988!
[767]989!--       If necessary, adjust the horizontal flow field to the prescribed
990!--       profiles
991          IF ( use_prescribed_profile_data )  THEN
992             DO  i = nxlg, nxrg
[667]993                DO  j = nysg, nyng
[328]994                   DO  k = nzb, nzt+1
[767]995                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
996                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
[328]997                   ENDDO
[151]998                ENDDO
[767]999             ENDDO
1000          ENDIF
[151]1001
1002!
[767]1003!--       Use these mean profiles at the inflow (provided that Dirichlet
1004!--       conditions are used)
1005          IF ( inflow_l )  THEN
1006             DO  j = nysg, nyng
1007                DO  k = nzb, nzt+1
1008                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
1009                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
1010                   w(k,j,nxlg:-1)  = 0.0
1011                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
1012                   e(k,j,nxlg:-1)  = mean_inflow_profiles(k,5)
1013                ENDDO
1014             ENDDO
1015          ENDIF
1016
[151]1017!
[767]1018!--       Calculate the damping factors to be used at the inflow. For a
1019!--       turbulent inflow the turbulent fluctuations have to be limited
1020!--       vertically because otherwise the turbulent inflow layer will grow
1021!--       in time.
1022          IF ( inflow_damping_height == 9999999.9 )  THEN
1023!
1024!--          Default: use the inversion height calculated by the prerun; if
1025!--          this is zero, inflow_damping_height must be explicitly
1026!--          specified.
1027             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0 )  THEN
1028                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
1029             ELSE
1030                WRITE( message_string, * ) 'inflow_damping_height must be ',&
1031                     'explicitly specified because&the inversion height ', &
1032                     'calculated by the prerun is zero.'
1033                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
[292]1034             ENDIF
[151]1035
[767]1036          ENDIF
1037
1038          IF ( inflow_damping_width == 9999999.9 )  THEN
[151]1039!
[767]1040!--          Default for the transition range: one tenth of the undamped
1041!--          layer
1042             inflow_damping_width = 0.1 * inflow_damping_height
[151]1043
[767]1044          ENDIF
[151]1045
[767]1046          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
[151]1047
[767]1048          DO  k = nzb, nzt+1
[151]1049
[767]1050             IF ( zu(k) <= inflow_damping_height )  THEN
1051                inflow_damping_factor(k) = 1.0
1052             ELSEIF ( zu(k) <= inflow_damping_height +  &
1053                               inflow_damping_width )  THEN
1054                inflow_damping_factor(k) = 1.0 -                            &
1055                                        ( zu(k) - inflow_damping_height ) / &
1056                                        inflow_damping_width
1057             ELSE
1058                inflow_damping_factor(k) = 0.0
1059             ENDIF
[151]1060
[767]1061          ENDDO
[151]1062
[147]1063       ENDIF
1064
[152]1065!
[359]1066!--    Inside buildings set velocities and TKE back to zero
1067       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.  &
1068            topography /= 'flat' )  THEN
1069!
1070!--       Inside buildings set velocities and TKE back to zero.
1071!--       Other scalars (pt, q, s, km, kh, p, sa, ...) are ignored at present,
1072!--       maybe revise later.
1073          IF ( timestep_scheme(1:5) == 'runge' )  THEN
[667]1074             DO  i = nxlg, nxrg
1075                DO  j = nysg, nyng
[359]1076                   u  (nzb:nzb_u_inner(j,i),j,i) = 0.0
1077                   v  (nzb:nzb_v_inner(j,i),j,i) = 0.0
1078                   w  (nzb:nzb_w_inner(j,i),j,i) = 0.0
1079                   e  (nzb:nzb_w_inner(j,i),j,i) = 0.0
1080                   u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
1081                   v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
1082                   w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1083                   e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1084                   tu_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
1085                   tv_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
1086                   tw_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1087                   te_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1088                   tpt_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1089                ENDDO
1090             ENDDO
1091          ELSE
[667]1092             DO  i = nxlg, nxrg
1093                DO  j = nysg, nyng
[359]1094                   u  (nzb:nzb_u_inner(j,i),j,i) = 0.0
1095                   v  (nzb:nzb_v_inner(j,i),j,i) = 0.0
1096                   w  (nzb:nzb_w_inner(j,i),j,i) = 0.0
1097                   e  (nzb:nzb_w_inner(j,i),j,i) = 0.0
1098                   u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0
1099                   v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0
1100                   w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1101                   e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0
1102                   u_p(nzb:nzb_u_inner(j,i),j,i) = 0.0
1103                   v_p(nzb:nzb_v_inner(j,i),j,i) = 0.0
1104                   w_p(nzb:nzb_w_inner(j,i),j,i) = 0.0
1105                   e_p(nzb:nzb_w_inner(j,i),j,i) = 0.0
1106                ENDDO
1107             ENDDO
1108          ENDIF
1109
1110       ENDIF
1111
1112!
[1]1113!--    Calculate initial temperature field and other constants used in case
1114!--    of a sloping surface
1115       IF ( sloping_surface )  CALL init_slope
1116
1117!
1118!--    Initialize new time levels (only done in order to set boundary values
1119!--    including ghost points)
1120       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
[75]1121       IF ( humidity  .OR.  passive_scalar )  q_p = q
[94]1122       IF ( ocean )  sa_p = sa
[1]1123
[181]1124!
1125!--    Allthough tendency arrays are set in prognostic_equations, they have
1126!--    have to be predefined here because they are used (but multiplied with 0)
1127!--    there before they are set.
1128       IF ( timestep_scheme(1:5) == 'runge' )  THEN
1129          te_m = 0.0; tpt_m = 0.0; tu_m = 0.0; tv_m = 0.0; tw_m = 0.0
1130          IF ( humidity  .OR.  passive_scalar )  tq_m = 0.0
1131          IF ( ocean )  tsa_m = 0.0
1132       ENDIF
1133
[1]1134    ELSE
1135!
1136!--    Actually this part of the programm should not be reached
[254]1137       message_string = 'unknown initializing problem'
1138       CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 )
[1]1139    ENDIF
1140
[151]1141
1142    IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
[1]1143!
[151]1144!--    Initialize old timelevels needed for radiation boundary conditions
1145       IF ( outflow_l )  THEN
1146          u_m_l(:,:,:) = u(:,:,1:2)
1147          v_m_l(:,:,:) = v(:,:,0:1)
1148          w_m_l(:,:,:) = w(:,:,0:1)
1149       ENDIF
1150       IF ( outflow_r )  THEN
1151          u_m_r(:,:,:) = u(:,:,nx-1:nx)
1152          v_m_r(:,:,:) = v(:,:,nx-1:nx)
1153          w_m_r(:,:,:) = w(:,:,nx-1:nx)
1154       ENDIF
1155       IF ( outflow_s )  THEN
1156          u_m_s(:,:,:) = u(:,0:1,:)
1157          v_m_s(:,:,:) = v(:,1:2,:)
1158          w_m_s(:,:,:) = w(:,0:1,:)
1159       ENDIF
1160       IF ( outflow_n )  THEN
1161          u_m_n(:,:,:) = u(:,ny-1:ny,:)
1162          v_m_n(:,:,:) = v(:,ny-1:ny,:)
1163          w_m_n(:,:,:) = w(:,ny-1:ny,:)
1164       ENDIF
[667]1165       
[151]1166    ENDIF
[680]1167
[667]1168!
1169!-- Calculate the initial volume flow at the right and north boundary
[709]1170    IF ( conserve_volume_flow )  THEN
[151]1171
[767]1172       IF ( use_prescribed_profile_data )  THEN
[667]1173
[732]1174          volume_flow_initial_l = 0.0
1175          volume_flow_area_l    = 0.0
1176
[667]1177          IF ( nxr == nx )  THEN
1178             DO  j = nys, nyn
[709]1179                DO  k = nzb_2d(j,nx)+1, nzt
[667]1180                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
[767]1181                                              u_init(k) * dzw(k)
1182                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1183                ENDDO
1184             ENDDO
1185          ENDIF
1186         
1187          IF ( nyn == ny )  THEN
1188             DO  i = nxl, nxr
1189                DO  k = nzb_2d(ny,i)+1, nzt 
1190                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
1191                                              v_init(k) * dzw(k)
1192                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1193                ENDDO
1194             ENDDO
1195          ENDIF
1196
1197#if defined( __parallel )
1198          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1199                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1200          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1201                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1202
1203#else
1204          volume_flow_initial = volume_flow_initial_l
1205          volume_flow_area    = volume_flow_area_l
1206#endif 
1207
1208       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1209
1210          volume_flow_initial_l = 0.0
1211          volume_flow_area_l    = 0.0
1212
1213          IF ( nxr == nx )  THEN
1214             DO  j = nys, nyn
1215                DO  k = nzb_2d(j,nx)+1, nzt
1216                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
[667]1217                                              hom_sum(k,1,0) * dzw(k)
1218                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1219                ENDDO
1220             ENDDO
1221          ENDIF
1222         
1223          IF ( nyn == ny )  THEN
1224             DO  i = nxl, nxr
[709]1225                DO  k = nzb_2d(ny,i)+1, nzt 
[667]1226                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
[709]1227                                              hom_sum(k,2,0) * dzw(k)
[667]1228                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1229                ENDDO
1230             ENDDO
1231          ENDIF
1232
[732]1233#if defined( __parallel )
1234          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1235                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1236          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1237                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1238
1239#else
1240          volume_flow_initial = volume_flow_initial_l
1241          volume_flow_area    = volume_flow_area_l
1242#endif 
1243
[667]1244       ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
1245
[732]1246          volume_flow_initial_l = 0.0
1247          volume_flow_area_l    = 0.0
1248
[667]1249          IF ( nxr == nx )  THEN
1250             DO  j = nys, nyn
[709]1251                DO  k = nzb_2d(j,nx)+1, nzt
[667]1252                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
[709]1253                                              u(k,j,nx) * dzw(k)
[667]1254                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1255                ENDDO
1256             ENDDO
1257          ENDIF
1258         
1259          IF ( nyn == ny )  THEN
1260             DO  i = nxl, nxr
[709]1261                DO  k = nzb_2d(ny,i)+1, nzt 
[667]1262                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
1263                                              v(k,ny,i) * dzw(k)
1264                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1265                ENDDO
1266             ENDDO
1267          ENDIF
1268
1269#if defined( __parallel )
[732]1270          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1271                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1272          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1273                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
[667]1274
1275#else
[732]1276          volume_flow_initial = volume_flow_initial_l
1277          volume_flow_area    = volume_flow_area_l
[667]1278#endif 
1279
[732]1280       ENDIF
1281
[151]1282!
[709]1283!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated
1284!--    from u|v_bulk instead
[680]1285       IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
1286          volume_flow_initial(1) = u_bulk * volume_flow_area(1)
1287          volume_flow_initial(2) = v_bulk * volume_flow_area(2)
1288       ENDIF
[667]1289
[680]1290    ENDIF
1291
1292
[667]1293!
[680]1294!-- Impose random perturbation on the horizontal velocity field and then
1295!-- remove the divergences from the velocity field at the initial stage
1296    IF ( create_disturbances .AND. &
1297         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.  &
1298         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
1299
1300       CALL disturb_field( nzb_u_inner, tend, u )
1301       CALL disturb_field( nzb_v_inner, tend, v )
1302       n_sor = nsor_ini
1303       CALL pres
1304       n_sor = nsor
1305    ENDIF
1306
1307!
[138]1308!-- Initialization of the leaf area density
[709]1309    IF ( plant_canopy )  THEN
[138]1310 
1311       SELECT CASE ( TRIM( canopy_mode ) )
1312
1313          CASE( 'block' )
1314
[667]1315             DO  i = nxlg, nxrg
1316                DO  j = nysg, nyng
[138]1317                   lad_s(:,j,i) = lad(:)
1318                   cdc(:,j,i)   = drag_coefficient
[709]1319                   IF ( passive_scalar )  THEN
[153]1320                      sls(:,j,i) = leaf_surface_concentration
1321                      sec(:,j,i) = scalar_exchange_coefficient
1322                   ENDIF
[138]1323                ENDDO
1324             ENDDO
1325
1326          CASE DEFAULT
1327
1328!
1329!--          The DEFAULT case is reached either if the parameter
1330!--          canopy mode contains a wrong character string or if the
1331!--          user has coded a special case in the user interface.
1332!--          There, the subroutine user_init_plant_canopy checks
1333!--          which of these two conditions applies.
1334             CALL user_init_plant_canopy
1335 
1336          END SELECT
1337
[667]1338       CALL exchange_horiz( lad_s, nbgp )
1339       CALL exchange_horiz( cdc, nbgp )
[138]1340
[709]1341       IF ( passive_scalar )  THEN
[667]1342          CALL exchange_horiz( sls, nbgp )
1343          CALL exchange_horiz( sec, nbgp )
[153]1344       ENDIF
1345
1346!
1347!--    Sharp boundaries of the plant canopy in horizontal directions
1348!--    In vertical direction the interpolation is retained, as the leaf
1349!--    area density is initialised by prescribing a vertical profile
1350!--    consisting of piecewise linear segments. The upper boundary
1351!--    of the plant canopy is now defined by lad_w(pch_index,:,:) = 0.0.
1352
[138]1353       DO  i = nxl, nxr
1354          DO  j = nys, nyn
1355             DO  k = nzb, nzt+1 
[709]1356                IF ( lad_s(k,j,i) > 0.0 )  THEN
[153]1357                   lad_u(k,j,i)   = lad_s(k,j,i) 
1358                   lad_u(k,j,i+1) = lad_s(k,j,i)
1359                   lad_v(k,j,i)   = lad_s(k,j,i)
1360                   lad_v(k,j+1,i) = lad_s(k,j,i)
1361                ENDIF
[138]1362             ENDDO
1363             DO  k = nzb, nzt
1364                lad_w(k,j,i) = 0.5 * ( lad_s(k+1,j,i) + lad_s(k,j,i) )
1365             ENDDO
1366          ENDDO
1367       ENDDO
1368
[153]1369       lad_w(pch_index,:,:) = 0.0
1370       lad_w(nzt+1,:,:)     = lad_w(nzt,:,:)
[138]1371
[667]1372       CALL exchange_horiz( lad_u, nbgp )
1373       CALL exchange_horiz( lad_v, nbgp )
1374       CALL exchange_horiz( lad_w, nbgp )
[153]1375
1376!
1377!--    Initialisation of the canopy heat source distribution
[709]1378       IF ( cthf /= 0.0 )  THEN
[153]1379!
1380!--       Piecewise evaluation of the leaf area index by
1381!--       integration of the leaf area density
1382          lai(:,:,:) = 0.0
[667]1383          DO  i = nxlg, nxrg
1384             DO  j = nysg, nyng
[153]1385                DO  k = pch_index-1, 0, -1
1386                   lai(k,j,i) = lai(k+1,j,i) +                   &
1387                                ( 0.5 * ( lad_w(k+1,j,i) +       &
1388                                          lad_s(k+1,j,i) ) *     &
1389                                  ( zw(k+1) - zu(k+1) ) )  +     &
1390                                ( 0.5 * ( lad_w(k,j,i)   +       &
1391                                          lad_s(k+1,j,i) ) *     &
1392                                  ( zu(k+1) - zw(k) ) )
1393                ENDDO
1394             ENDDO
1395          ENDDO
1396
1397!
1398!--       Evaluation of the upward kinematic vertical heat flux within the
1399!--       canopy
[667]1400          DO  i = nxlg, nxrg
1401             DO  j = nysg, nyng
[153]1402                DO  k = 0, pch_index
1403                   canopy_heat_flux(k,j,i) = cthf *                    &
1404                                             exp( -0.6 * lai(k,j,i) )
1405                ENDDO
1406             ENDDO
1407          ENDDO
1408
1409!
1410!--       The near surface heat flux is derived from the heat flux
1411!--       distribution within the canopy
1412          shf(:,:) = canopy_heat_flux(0,:,:)
1413
[709]1414          IF ( ASSOCIATED( shf_m ) )  shf_m = shf
[153]1415
1416       ENDIF
1417
[138]1418    ENDIF
1419
1420!
[1]1421!-- If required, initialize dvrp-software
1422    IF ( dt_dvrp /= 9999999.9 )  CALL init_dvrp
1423
[96]1424    IF ( ocean )  THEN
[1]1425!
[96]1426!--    Initialize quantities needed for the ocean model
1427       CALL init_ocean
[388]1428
[96]1429    ELSE
1430!
1431!--    Initialize quantities for handling cloud physics
1432!--    This routine must be called before init_particles, because
1433!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
1434!--    init_particles) is not defined.
1435       CALL init_cloud_physics
1436    ENDIF
[1]1437
1438!
1439!-- If required, initialize particles
[63]1440    IF ( particle_advection )  CALL init_particles
[1]1441
1442!
[673]1443!-- Initialize the ws-scheme.   
1444    IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init       
[1]1445
1446!
[709]1447!-- Setting weighting factors for calculation of perturbation pressure
1448!-- and turbulent quantities from the RK substeps               
1449    IF ( TRIM(timestep_scheme) == 'runge-kutta-3' )  THEN      ! for RK3-method
1450
[713]1451       weight_substep(1) = 1./6.
1452       weight_substep(2) = 3./10.
1453       weight_substep(3) = 8./15.
[709]1454
[713]1455       weight_pres(1)    = 1./3.
1456       weight_pres(2)    = 5./12.
1457       weight_pres(3)    = 1./4.
[709]1458
1459    ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' )  THEN  ! for RK2-method
1460
[713]1461       weight_substep(1) = 1./2.
1462       weight_substep(2) = 1./2.
[673]1463         
[713]1464       weight_pres(1)    = 1./2.
1465       weight_pres(2)    = 1./2.       
[709]1466
1467    ELSE                                     ! for Euler- and leapfrog-method
1468
[673]1469       weight_substep(1) = 1.0     
[709]1470       weight_pres(1)    = 1.0                   
1471
[673]1472    ENDIF
1473
1474!
[1]1475!-- Initialize Rayleigh damping factors
[785]1476    rdf    = 0.0
1477    rdf_sc = 0.0
[1]1478    IF ( rayleigh_damping_factor /= 0.0 )  THEN
[108]1479       IF ( .NOT. ocean )  THEN
1480          DO  k = nzb+1, nzt
1481             IF ( zu(k) >= rayleigh_damping_height )  THEN
1482                rdf(k) = rayleigh_damping_factor * &
[1]1483                      ( SIN( pi * 0.5 * ( zu(k) - rayleigh_damping_height )    &
1484                                      / ( zu(nzt) - rayleigh_damping_height ) )&
1485                      )**2
[108]1486             ENDIF
1487          ENDDO
1488       ELSE
1489          DO  k = nzt, nzb+1, -1
1490             IF ( zu(k) <= rayleigh_damping_height )  THEN
1491                rdf(k) = rayleigh_damping_factor * &
1492                      ( SIN( pi * 0.5 * ( rayleigh_damping_height - zu(k) )    &
1493                                      / ( rayleigh_damping_height - zu(nzb+1)))&
1494                      )**2
1495             ENDIF
1496          ENDDO
1497       ENDIF
[1]1498    ENDIF
[785]1499    IF ( scalar_rayleigh_damping )  rdf_sc = rdf
[1]1500
1501!
[240]1502!-- Initialize the starting level and the vertical smoothing factor used for
1503!-- the external pressure gradient
1504    dp_smooth_factor = 1.0
1505    IF ( dp_external )  THEN
1506!
1507!--    Set the starting level dp_level_ind_b only if it has not been set before
1508!--    (e.g. in init_grid).
1509       IF ( dp_level_ind_b == 0 )  THEN
1510          ind_array = MINLOC( ABS( dp_level_b - zu ) )
1511          dp_level_ind_b = ind_array(1) - 1 + nzb 
1512                                        ! MINLOC uses lower array bound 1
1513       ENDIF
1514       IF ( dp_smooth )  THEN
1515          dp_smooth_factor(:dp_level_ind_b) = 0.0
1516          DO  k = dp_level_ind_b+1, nzt
1517             dp_smooth_factor(k) = 0.5 * ( 1.0 + SIN( pi * &
1518                  ( REAL( k - dp_level_ind_b ) /  &
1519                    REAL( nzt - dp_level_ind_b ) - 0.5 ) ) )
1520          ENDDO
1521       ENDIF
1522    ENDIF
1523
1524!
[1]1525!-- Initialize diffusivities used within the outflow damping layer in case of
1526!-- non-cyclic lateral boundaries. A linear increase is assumed over the first
1527!-- half of the width of the damping layer
[707]1528    IF ( bc_lr_dirrad )  THEN
[1]1529
[667]1530       DO  i = nxlg, nxrg
[73]1531          IF ( i >= nx - outflow_damping_width )  THEN
1532             km_damp_x(i) = km_damp_max * MIN( 1.0,                    &
1533                            ( i - ( nx - outflow_damping_width ) ) /   &
1534                            REAL( outflow_damping_width/2 )            &
1535                                             )
1536          ELSE
1537             km_damp_x(i) = 0.0
1538          ENDIF
1539       ENDDO
[1]1540
[707]1541    ELSEIF ( bc_lr_raddir )  THEN
[1]1542
[667]1543       DO  i = nxlg, nxrg
[73]1544          IF ( i <= outflow_damping_width )  THEN
1545             km_damp_x(i) = km_damp_max * MIN( 1.0,                    &
1546                            ( outflow_damping_width - i ) /            &
1547                            REAL( outflow_damping_width/2 )            &
1548                                             )
1549          ELSE
1550             km_damp_x(i) = 0.0
1551          ENDIF
1552       ENDDO
[1]1553
[73]1554    ENDIF
[1]1555
[707]1556    IF ( bc_ns_dirrad )  THEN
[1]1557
[667]1558       DO  j = nysg, nyng
[73]1559          IF ( j >= ny - outflow_damping_width )  THEN
1560             km_damp_y(j) = km_damp_max * MIN( 1.0,                    &
1561                            ( j - ( ny - outflow_damping_width ) ) /   &
1562                            REAL( outflow_damping_width/2 )            &
1563                                             )
1564          ELSE
1565             km_damp_y(j) = 0.0
[1]1566          ENDIF
1567       ENDDO
1568
[707]1569    ELSEIF ( bc_ns_raddir )  THEN
[1]1570
[667]1571       DO  j = nysg, nyng
[73]1572          IF ( j <= outflow_damping_width )  THEN
1573             km_damp_y(j) = km_damp_max * MIN( 1.0,                    &
1574                            ( outflow_damping_width - j ) /            &
1575                            REAL( outflow_damping_width/2 )            &
1576                                             )
1577          ELSE
1578             km_damp_y(j) = 0.0
[1]1579          ENDIF
[73]1580       ENDDO
[1]1581
1582    ENDIF
1583
1584!
[709]1585!-- Initialize local summation arrays for routine flow_statistics.
1586!-- This is necessary because they may not yet have been initialized when they
1587!-- are called from flow_statistics (or - depending on the chosen model run -
1588!-- are never initialized)
[1]1589    sums_divnew_l      = 0.0
1590    sums_divold_l      = 0.0
1591    sums_l_l           = 0.0
1592    sums_up_fraction_l = 0.0
1593    sums_wsts_bc_l     = 0.0
1594
1595!
1596!-- Pre-set masks for regional statistics. Default is the total model domain.
1597    rmask = 1.0
1598
1599!
[51]1600!-- User-defined initializing actions. Check afterwards, if maximum number
[709]1601!-- of allowed timeseries is exceeded
[1]1602    CALL user_init
1603
[51]1604    IF ( dots_num > dots_max )  THEN
[254]1605       WRITE( message_string, * ) 'number of time series quantities exceeds', &
[274]1606                                  ' its maximum of dots_max = ', dots_max,    &
[254]1607                                  ' &Please increase dots_max in modules.f90.'
1608       CALL message( 'init_3d_model', 'PA0194', 1, 2, 0, 6, 0 )   
[51]1609    ENDIF
1610
[1]1611!
1612!-- Input binary data file is not needed anymore. This line must be placed
1613!-- after call of user_init!
1614    CALL close_file( 13 )
1615
1616!
1617!-- Compute total sum of active mask grid points
1618!-- ngp_2dh: number of grid points of a horizontal cross section through the
1619!--          total domain
1620!-- ngp_3d:  number of grid points of the total domain
[132]1621    ngp_2dh_outer_l   = 0
1622    ngp_2dh_outer     = 0
1623    ngp_2dh_s_inner_l = 0
1624    ngp_2dh_s_inner   = 0
1625    ngp_2dh_l         = 0
1626    ngp_2dh           = 0
[485]1627    ngp_3d_inner_l    = 0.0
[132]1628    ngp_3d_inner      = 0
1629    ngp_3d            = 0
1630    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
[1]1631
1632    DO  sr = 0, statistic_regions
1633       DO  i = nxl, nxr
1634          DO  j = nys, nyn
1635             IF ( rmask(j,i,sr) == 1.0 )  THEN
1636!
1637!--             All xy-grid points
1638                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
1639!
1640!--             xy-grid points above topography
1641                DO  k = nzb_s_outer(j,i), nz + 1
1642                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr) + 1
1643                ENDDO
[132]1644                DO  k = nzb_s_inner(j,i), nz + 1
1645                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) + 1
1646                ENDDO
[1]1647!
1648!--             All grid points of the total domain above topography
1649                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + &
1650                                     ( nz - nzb_s_inner(j,i) + 2 )
1651             ENDIF
1652          ENDDO
1653       ENDDO
1654    ENDDO
1655
1656    sr = statistic_regions + 1
1657#if defined( __parallel )
[622]1658    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[485]1659    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,   &
[1]1660                        comm2d, ierr )
[622]1661    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[485]1662    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr,  &
[1]1663                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
[622]1664    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[485]1665    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),         &
[132]1666                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
[622]1667    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[485]1668    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL, &
[1]1669                        MPI_SUM, comm2d, ierr )
[485]1670    ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
[1]1671#else
[132]1672    ngp_2dh         = ngp_2dh_l
1673    ngp_2dh_outer   = ngp_2dh_outer_l
1674    ngp_2dh_s_inner = ngp_2dh_s_inner_l
[485]1675    ngp_3d_inner    = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) )
[1]1676#endif
1677
[560]1678    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * &
1679             INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
[1]1680
1681!
1682!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
1683!-- buoyancy, etc. A zero value will occur for cases where all grid points of
1684!-- the respective subdomain lie below the surface topography
[667]1685    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   ) 
[631]1686    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )),            &
1687                           ngp_3d_inner(:) )
[667]1688    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) 
[1]1689
[485]1690    DEALLOCATE( ngp_2dh_l, ngp_2dh_outer_l, ngp_3d_inner_l, ngp_3d_inner_tmp )
[1]1691
1692
1693 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.