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

Last change on this file since 138 was 138, checked in by letzel, 16 years ago

Plant canopy model of Watanabe (2004,BLM 112,307-341) added.

  • Property svn:keywords set to Id
File size: 40.8 KB
Line 
1#if defined( __ibmy_special )
2@PROCESS NOOPTimize
3#endif
4 SUBROUTINE init_3d_model
5
6!------------------------------------------------------------------------------!
7! Actual revisions:
8! -----------------
9! New counter ngp_2dh_s_inner.
10! Allow new case bc_uv_t = 'dirichlet_0' for channel flow.
11! Corrected calculation of initial volume flow for 'set_1d-model_profiles' and
12! 'set_constant_profiles' in case of buildings in the reference cross-sections.
13!
14! Former revisions:
15! -----------------
16! $Id: init_3d_model.f90 138 2007-11-28 10:03:58Z letzel $
17!
18! 108 2007-08-24 15:10:38Z letzel
19! Flux initialization in case of coupled runs, +momentum fluxes at top boundary,
20! +arrays for phase speed c_u, c_v, c_w, indices for u|v|w_m_l|r changed
21! +qswst_remote in case of atmosphere model with humidity coupled to ocean
22! Rayleigh damping for ocean, optionally calculate km and kh from initial
23! TKE e_init
24!
25! 97 2007-06-21 08:23:15Z raasch
26! Initialization of salinity, call of init_ocean
27!
28! 87 2007-05-22 15:46:47Z raasch
29! var_hom and var_sum renamed pr_palm
30!
31! 75 2007-03-22 09:54:05Z raasch
32! Arrays for radiation boundary conditions are allocated (u_m_l, u_m_r, etc.),
33! bugfix for cases with the outflow damping layer extending over more than one
34! subdomain, moisture renamed humidity,
35! new initializing action "by_user" calls user_init_3d_model,
36! precipitation_amount/rate, ts_value are allocated, +module netcdf_control,
37! initial velocities at nzb+1 are regarded for volume
38! flow control in case they have been set zero before (to avoid small timesteps)
39! -uvmean_outflow, uxrp, vynp eliminated
40!
41! 19 2007-02-23 04:53:48Z raasch
42! +handling of top fluxes
43!
44! RCS Log replace by Id keyword, revision history cleaned up
45!
46! Revision 1.49  2006/08/22 15:59:07  raasch
47! No optimization of this file on the ibmy (Yonsei Univ.)
48!
49! Revision 1.1  1998/03/09 16:22:22  raasch
50! Initial revision
51!
52!
53! Description:
54! ------------
55! Allocation of arrays and initialization of the 3D model via
56! a) pre-run the 1D model
57! or
58! b) pre-set constant linear profiles
59! or
60! c) read values of a previous run
61!------------------------------------------------------------------------------!
62
63    USE arrays_3d
64    USE averaging
65    USE cloud_parameters
66    USE constants
67    USE control_parameters
68    USE cpulog
69    USE indices
70    USE interfaces
71    USE model_1d
72    USE netcdf_control
73    USE particle_attributes
74    USE pegrid
75    USE profil_parameter
76    USE random_function_mod
77    USE statistics
78
79    IMPLICIT NONE
80
81    INTEGER ::  i, j, k, sr
82
83    INTEGER, DIMENSION(:), ALLOCATABLE ::  ngp_2dh_l, ngp_3d_inner_l
84
85    INTEGER, DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l,  &
86         ngp_2dh_s_inner_l
87
88    REAL, DIMENSION(1:2) ::  volume_flow_area_l, volume_flow_initial_l
89
90
91!
92!-- Allocate arrays
93    ALLOCATE( ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions), &
94              ngp_3d(0:statistic_regions),                                  &
95              ngp_3d_inner(0:statistic_regions),                            &
96              ngp_3d_inner_l(0:statistic_regions),                          &
97              sums_divnew_l(0:statistic_regions),                           &
98              sums_divold_l(0:statistic_regions) )
99    ALLOCATE( rdf(nzb+1:nzt) )
100    ALLOCATE( hom_sum(nzb:nzt+1,pr_palm+max_pr_user,0:statistic_regions),   &
101              ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                 &
102              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),               &
103              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),               &
104              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),             &
105              rmask(nys-1:nyn+1,nxl-1:nxr+1,0:statistic_regions),           &
106              sums(nzb:nzt+1,pr_palm+max_pr_user),                          &
107              sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1),   &
108              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1), &
109              sums_up_fraction_l(10,3,0:statistic_regions),                 &
110              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions),                &
111              ts_value(var_ts,0:statistic_regions) )
112    ALLOCATE( km_damp_x(nxl-1:nxr+1), km_damp_y(nys-1:nyn+1) )
113
114    ALLOCATE( rif_1(nys-1:nyn+1,nxl-1:nxr+1), shf_1(nys-1:nyn+1,nxl-1:nxr+1), &
115              ts(nys-1:nyn+1,nxl-1:nxr+1), tswst_1(nys-1:nyn+1,nxl-1:nxr+1),  &
116              us(nys-1:nyn+1,nxl-1:nxr+1), usws_1(nys-1:nyn+1,nxl-1:nxr+1),   &
117              uswst_1(nys-1:nyn+1,nxl-1:nxr+1),                               &
118              vsws_1(nys-1:nyn+1,nxl-1:nxr+1),                                &
119              vswst_1(nys-1:nyn+1,nxl-1:nxr+1), z0(nys-1:nyn+1,nxl-1:nxr+1) )
120
121    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
122!
123!--    Leapfrog scheme needs two timelevels of diffusion quantities
124       ALLOCATE( rif_2(nys-1:nyn+1,nxl-1:nxr+1),   &
125                 shf_2(nys-1:nyn+1,nxl-1:nxr+1),   &
126                 tswst_2(nys-1:nyn+1,nxl-1:nxr+1), &
127                 usws_2(nys-1:nyn+1,nxl-1:nxr+1),  &
128                 uswst_2(nys-1:nyn+1,nxl-1:nxr+1), &
129                 vswst_2(nys-1:nyn+1,nxl-1:nxr+1), &
130                 vsws_2(nys-1:nyn+1,nxl-1:nxr+1) )
131    ENDIF
132
133    ALLOCATE( d(nzb+1:nzta,nys:nyna,nxl:nxra),         &
134              e_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
135              e_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
136              e_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
137              kh_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
138              km_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
139              p(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),    &
140              pt_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
141              pt_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
142              pt_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
143              tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
144              u_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
145              u_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
146              u_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
147              v_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
148              v_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
149              v_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
150              w_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
151              w_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
152              w_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
153
154    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
155       ALLOCATE( kh_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
156                 km_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
157    ENDIF
158
159    IF ( humidity  .OR.  passive_scalar ) THEN
160!
161!--    2D-humidity/scalar arrays
162       ALLOCATE ( qs(nys-1:nyn+1,nxl-1:nxr+1),     &
163                  qsws_1(nys-1:nyn+1,nxl-1:nxr+1), &
164                  qswst_1(nys-1:nyn+1,nxl-1:nxr+1) )
165
166       IF ( timestep_scheme(1:5) /= 'runge' )  THEN
167          ALLOCATE( qsws_2(nys-1:nyn+1,nxl-1:nxr+1), &
168                    qswst_2(nys-1:nyn+1,nxl-1:nxr+1) )
169       ENDIF
170!
171!--    3D-humidity/scalar arrays
172       ALLOCATE( q_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
173                 q_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
174                 q_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
175
176!
177!--    3D-arrays needed for humidity only
178       IF ( humidity )  THEN
179          ALLOCATE( vpt_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
180
181          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
182             ALLOCATE( vpt_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
183          ENDIF
184
185          IF ( cloud_physics ) THEN
186!
187!--          Liquid water content
188             ALLOCATE ( ql_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
189!
190!--          Precipitation amount and rate (only needed if output is switched)
191             ALLOCATE( precipitation_amount(nys-1:nyn+1,nxl-1:nxr+1), &
192                       precipitation_rate(nys-1:nyn+1,nxl-1:nxr+1) )
193          ENDIF
194
195          IF ( cloud_droplets )  THEN
196!
197!--          Liquid water content, change in liquid water content,
198!--          real volume of particles (with weighting), volume of particles
199             ALLOCATE ( ql_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
200                        ql_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
201                        ql_v(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
202                        ql_vp(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
203          ENDIF
204
205       ENDIF
206
207    ENDIF
208
209    IF ( ocean )  THEN
210       ALLOCATE( saswsb_1(nys-1:nyn+1,nxl-1:nxr+1), &
211                 saswst_1(nys-1:nyn+1,nxl-1:nxr+1) )
212       ALLOCATE( rho_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), &
213                 sa_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
214                 sa_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
215                 sa_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
216       rho => rho_1  ! routine calc_mean_profile requires density to be a
217                     ! pointer
218       IF ( humidity_remote )  THEN
219          ALLOCATE( qswst_remote(nys-1:nyn+1,nxl-1:nxr+1) )
220          qswst_remote = 0.0
221       ENDIF
222    ENDIF
223
224!
225!-- 3D-array for storing the dissipation, needed for calculating the sgs
226!-- particle velocities
227    IF ( use_sgs_for_particles )  THEN
228       ALLOCATE ( diss(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
229    ENDIF
230
231    IF ( dt_dosp /= 9999999.9 )  THEN
232       ALLOCATE( spectrum_x( 1:nx/2, 1:10, 1:10 ), &
233                 spectrum_y( 1:ny/2, 1:10, 1:10 ) )
234    ENDIF
235
236!
237!-- 3D-arrays for the leaf area density and the canopy drag coefficient
238    IF ( plant_canopy ) THEN
239       ALLOCATE ( lad_s(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
240                  lad_u(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
241                  lad_v(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
242                  lad_w(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1),  &
243                  cdc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
244    ENDIF
245
246!
247!-- 4D-array for storing the Rif-values at vertical walls
248    IF ( topography /= 'flat' )  THEN
249       ALLOCATE( rif_wall(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1,1:4) )
250       rif_wall = 0.0
251    ENDIF
252
253!
254!-- Velocities at nzb+1 needed for volume flow control
255    IF ( conserve_volume_flow )  THEN
256       ALLOCATE( u_nzb_p1_for_vfc(nys:nyn), v_nzb_p1_for_vfc(nxl:nxr) )
257       u_nzb_p1_for_vfc = 0.0
258       v_nzb_p1_for_vfc = 0.0
259    ENDIF
260
261!
262!-- Arrays to store velocity data from t-dt and the phase speeds which
263!-- are needed for radiation boundary conditions
264    IF ( outflow_l )  THEN
265       ALLOCATE( u_m_l(nzb:nzt+1,nys-1:nyn+1,1:2), &
266                 v_m_l(nzb:nzt+1,nys-1:nyn+1,0:1), &
267                 w_m_l(nzb:nzt+1,nys-1:nyn+1,0:1) )
268    ENDIF
269    IF ( outflow_r )  THEN
270       ALLOCATE( u_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx), &
271                 v_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx), &
272                 w_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx) )
273    ENDIF
274    IF ( outflow_l  .OR.  outflow_r )  THEN
275       ALLOCATE( c_u(nzb:nzt+1,nys-1:nyn+1), c_v(nzb:nzt+1,nys-1:nyn+1), &
276                 c_w(nzb:nzt+1,nys-1:nyn+1) )
277    ENDIF
278    IF ( outflow_s )  THEN
279       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxl-1:nxr+1), &
280                 v_m_s(nzb:nzt+1,1:2,nxl-1:nxr+1), &
281                 w_m_s(nzb:nzt+1,0:1,nxl-1:nxr+1) )
282    ENDIF
283    IF ( outflow_n )  THEN
284       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1), &
285                 v_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1), &
286                 w_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1) )
287    ENDIF
288    IF ( outflow_s  .OR.  outflow_n )  THEN
289       ALLOCATE( c_u(nzb:nzt+1,nxl-1:nxr+1), c_v(nzb:nzt+1,nxl-1:nxr+1), &
290                 c_w(nzb:nzt+1,nxl-1:nxr+1) )
291    ENDIF
292
293!
294!-- Initial assignment of the pointers
295    IF ( timestep_scheme(1:5) /= 'runge' )  THEN
296
297       rif_m   => rif_1;    rif   => rif_2
298       shf_m   => shf_1;    shf   => shf_2
299       tswst_m => tswst_1;  tswst => tswst_2
300       usws_m  => usws_1;   usws  => usws_2
301       uswst_m => uswst_1;  uswst => uswst_2
302       vsws_m  => vsws_1;   vsws  => vsws_2
303       vswst_m => vswst_1;  vswst => vswst_2
304       e_m  => e_1;   e  => e_2;   e_p  => e_3;   te_m  => e_3
305       kh_m => kh_1;  kh => kh_2
306       km_m => km_1;  km => km_2
307       pt_m => pt_1;  pt => pt_2;  pt_p => pt_3;  tpt_m => pt_3
308       u_m  => u_1;   u  => u_2;   u_p  => u_3;   tu_m  => u_3
309       v_m  => v_1;   v  => v_2;   v_p  => v_3;   tv_m  => v_3
310       w_m  => w_1;   w  => w_2;   w_p  => w_3;   tw_m  => w_3
311
312       IF ( humidity  .OR.  passive_scalar )  THEN
313          qsws_m  => qsws_1;   qsws  => qsws_2
314          qswst_m => qswst_1;  qswst => qswst_2
315          q_m    => q_1;     q    => q_2;     q_p => q_3;     tq_m => q_3
316          IF ( humidity )        vpt_m  => vpt_1;   vpt  => vpt_2
317          IF ( cloud_physics )   ql   => ql_1
318          IF ( cloud_droplets )  THEN
319             ql   => ql_1
320             ql_c => ql_2
321          ENDIF
322       ENDIF
323
324    ELSE
325
326       rif   => rif_1
327       shf   => shf_1
328       tswst => tswst_1
329       usws  => usws_1
330       uswst => uswst_1
331       vsws  => vsws_1
332       vswst => vswst_1
333       e     => e_1;   e_p  => e_2;   te_m  => e_3;   e_m  => e_3
334       kh    => kh_1
335       km    => km_1
336       pt    => pt_1;  pt_p => pt_2;  tpt_m => pt_3;  pt_m => pt_3
337       u     => u_1;   u_p  => u_2;   tu_m  => u_3;   u_m  => u_3
338       v     => v_1;   v_p  => v_2;   tv_m  => v_3;   v_m  => v_3
339       w     => w_1;   w_p  => w_2;   tw_m  => w_3;   w_m  => w_3
340
341       IF ( humidity  .OR.  passive_scalar )  THEN
342          qsws   => qsws_1
343          qswst  => qswst_1
344          q      => q_1;     q_p  => q_2;     tq_m  => q_3;    q_m => q_3
345          IF ( humidity )        vpt  => vpt_1
346          IF ( cloud_physics )   ql   => ql_1
347          IF ( cloud_droplets )  THEN
348             ql   => ql_1
349             ql_c => ql_2
350          ENDIF
351       ENDIF
352
353       IF ( ocean )  THEN
354          saswsb => saswsb_1
355          saswst => saswst_1
356          sa     => sa_1;    sa_p => sa_2;    tsa_m => sa_3
357       ENDIF
358
359    ENDIF
360
361!
362!-- Initialize model variables
363    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
364!
365!--    First model run of a possible job queue.
366!--    Initial profiles of the variables must be computes.
367       IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
368!
369!--       Use solutions of the 1D model as initial profiles,
370!--       start 1D model
371          CALL init_1d_model
372!
373!--       Transfer initial profiles to the arrays of the 3D model
374          DO  i = nxl-1, nxr+1
375             DO  j = nys-1, nyn+1
376                e(:,j,i)  = e1d
377                kh(:,j,i) = kh1d
378                km(:,j,i) = km1d
379                pt(:,j,i) = pt_init
380                u(:,j,i)  = u1d
381                v(:,j,i)  = v1d
382             ENDDO
383          ENDDO
384
385          IF ( humidity  .OR.  passive_scalar )  THEN
386             DO  i = nxl-1, nxr+1
387                DO  j = nys-1, nyn+1
388                   q(:,j,i) = q_init
389                ENDDO
390             ENDDO
391          ENDIF
392
393          IF ( .NOT. constant_diffusion )  THEN
394             DO  i = nxl-1, nxr+1
395                DO  j = nys-1, nyn+1
396                   e(:,j,i)  = e1d
397                ENDDO
398             ENDDO
399!
400!--          Store initial profiles for output purposes etc.
401             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
402
403             IF ( prandtl_layer )  THEN
404                rif  = rif1d(nzb+1)
405                ts   = 0.0  ! could actually be computed more accurately in the
406                            ! 1D model. Update when opportunity arises.
407                us   = us1d
408                usws = usws1d
409                vsws = vsws1d
410             ELSE
411                ts   = 0.0  ! must be set, because used in
412                rif  = 0.0  ! flowste
413                us   = 0.0
414                usws = 0.0
415                vsws = 0.0
416             ENDIF
417
418          ELSE
419             e    = 0.0  ! must be set, because used in
420             rif  = 0.0  ! flowste
421             ts   = 0.0
422             us   = 0.0
423             usws = 0.0
424             vsws = 0.0
425          ENDIF
426          uswst = top_momentumflux_u
427          vswst = top_momentumflux_v
428
429!
430!--       In every case qs = 0.0 (see also pt)
431!--       This could actually be computed more accurately in the 1D model.
432!--       Update when opportunity arises!
433          IF ( humidity  .OR.  passive_scalar )  qs = 0.0
434
435!
436!--       inside buildings set velocities back to zero
437          IF ( topography /= 'flat' )  THEN
438             DO  i = nxl-1, nxr+1
439                DO  j = nys-1, nyn+1
440                   u(nzb:nzb_u_inner(j,i),j,i) = 0.0
441                   v(nzb:nzb_v_inner(j,i),j,i) = 0.0
442                ENDDO
443             ENDDO
444             IF ( conserve_volume_flow )  THEN
445                IF ( nxr == nx )  THEN
446                   DO  j = nys, nyn
447                      DO  k = nzb + 1, nzb_u_inner(j,nx)
448                         u_nzb_p1_for_vfc(j) = u1d(k) * dzu(k)
449                      ENDDO
450                   ENDDO
451                ENDIF
452                IF ( nyn == ny )  THEN
453                   DO  i = nxl, nxr
454                      DO  k = nzb + 1, nzb_v_inner(ny,i)
455                         v_nzb_p1_for_vfc(i) = v1d(k) * dzu(k)
456                      ENDDO
457                   ENDDO
458                ENDIF
459             ENDIF
460!
461!--          WARNING: The extra boundary conditions set after running the
462!--          -------  1D model impose an error on the divergence one layer
463!--                   below the topography; need to correct later
464!--          ATTENTION: Provisional correction for Piacsek & Williams
465!--          ---------  advection scheme: keep u and v zero one layer below
466!--                     the topography.
467             IF ( ibc_uv_b == 0 )  THEN
468!
469!--             Satisfying the Dirichlet condition with an extra layer below
470!--             the surface where the u and v component change their sign.
471                DO  i = nxl-1, nxr+1
472                   DO  j = nys-1, nyn+1
473                      IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = -u(1,j,i)
474                      IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = -v(1,j,i)
475                   ENDDO
476                ENDDO
477
478             ELSE
479!
480!--             Neumann condition
481                DO  i = nxl-1, nxr+1
482                   DO  j = nys-1, nyn+1
483                      IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = u(1,j,i)
484                      IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = v(1,j,i)
485                   ENDDO
486                ENDDO
487
488             ENDIF
489
490          ENDIF
491
492       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 ) &
493       THEN
494!
495!--       Use constructed initial profiles (velocity constant with height,
496!--       temperature profile with constant gradient)
497          DO  i = nxl-1, nxr+1
498             DO  j = nys-1, nyn+1
499                pt(:,j,i) = pt_init
500                u(:,j,i)  = u_init
501                v(:,j,i)  = v_init
502             ENDDO
503          ENDDO
504
505!
506!--       Set initial horizontal velocities at the lowest computational grid levels
507!--       to zero in order to avoid too small time steps caused by the diffusion
508!--       limit in the initial phase of a run (at k=1, dz/2 occurs in the
509!--       limiting formula!). The original values are stored to be later used for
510!--       volume flow control.
511          DO  i = nxl-1, nxr+1
512             DO  j = nys-1, nyn+1
513                u(nzb:nzb_u_inner(j,i)+1,j,i) = 0.0
514                v(nzb:nzb_v_inner(j,i)+1,j,i) = 0.0
515             ENDDO
516          ENDDO
517          IF ( conserve_volume_flow )  THEN
518             IF ( nxr == nx )  THEN
519                DO  j = nys, nyn
520                   DO  k = nzb + 1, nzb_u_inner(j,nx) + 1
521                      u_nzb_p1_for_vfc(j) = u_init(k) * dzu(k)
522                   ENDDO
523                ENDDO
524             ENDIF
525             IF ( nyn == ny )  THEN
526                DO  i = nxl, nxr
527                   DO  k = nzb + 1, nzb_v_inner(ny,i) + 1
528                      v_nzb_p1_for_vfc(i) = v_init(k) * dzu(k)
529                   ENDDO
530                ENDDO
531             ENDIF
532          ENDIF
533
534          IF ( humidity  .OR.  passive_scalar )  THEN
535             DO  i = nxl-1, nxr+1
536                DO  j = nys-1, nyn+1
537                   q(:,j,i) = q_init
538                ENDDO
539             ENDDO
540          ENDIF
541
542          IF ( ocean )  THEN
543             DO  i = nxl-1, nxr+1
544                DO  j = nys-1, nyn+1
545                   sa(:,j,i) = sa_init
546                ENDDO
547             ENDDO
548          ENDIF
549         
550          IF ( constant_diffusion )  THEN
551             km   = km_constant
552             kh   = km / prandtl_number
553             e    = 0.0
554          ELSEIF ( e_init > 0.0 )  THEN
555             DO  k = nzb+1, nzt
556                km(k,:,:) = 0.1 * l_grid(k) * SQRT( e_init )
557             ENDDO
558             km(nzb,:,:)   = km(nzb+1,:,:)
559             km(nzt+1,:,:) = km(nzt,:,:)
560             kh   = km / prandtl_number
561             e    = e_init
562          ELSE
563             IF ( .NOT. ocean )  THEN
564                kh   = 0.01   ! there must exist an initial diffusion, because
565                km   = 0.01   ! otherwise no TKE would be produced by the
566                              ! production terms, as long as not yet
567                              ! e = (u*/cm)**2 at k=nzb+1
568             ELSE
569                kh   = 0.00001
570                km   = 0.00001
571             ENDIF
572             e    = 0.0
573          ENDIF
574          rif   = 0.0
575          ts    = 0.0
576          us    = 0.0
577          usws  = 0.0
578          uswst = top_momentumflux_u
579          vsws  = 0.0
580          vswst = top_momentumflux_v
581          IF ( humidity  .OR.  passive_scalar ) qs = 0.0
582
583!
584!--       Compute initial temperature field and other constants used in case
585!--       of a sloping surface
586          IF ( sloping_surface )  CALL init_slope
587
588       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 ) &
589       THEN
590!
591!--       Initialization will completely be done by the user
592          CALL user_init_3d_model
593
594       ENDIF
595
596!
597!--    apply channel flow boundary condition
598       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
599
600          u(nzt+1,:,:) = 0.0
601          v(nzt+1,:,:) = 0.0
602
603!--       for the Dirichlet condition to be correctly applied at the top, set
604!--       ug and vg to zero there
605          ug(nzt+1)    = 0.0
606          vg(nzt+1)    = 0.0
607
608       ENDIF
609
610!
611!--    Calculate virtual potential temperature
612       IF ( humidity ) vpt = pt * ( 1.0 + 0.61 * q )
613
614!
615!--    Store initial profiles for output purposes etc.
616       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
617       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
618       IF ( ibc_uv_b == 0 )  THEN
619          hom(nzb,1,5,:) = -hom(nzb+1,1,5,:)  ! due to satisfying the Dirichlet
620          hom(nzb,1,6,:) = -hom(nzb+1,1,6,:)  ! condition with an extra layer
621              ! below the surface where the u and v component change their sign
622       ENDIF
623       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
624       hom(:,1,23,:) = SPREAD( km(:,nys,nxl), 2, statistic_regions+1 )
625       hom(:,1,24,:) = SPREAD( kh(:,nys,nxl), 2, statistic_regions+1 )
626
627       IF ( ocean )  THEN
628!
629!--       Store initial salinity profile
630          hom(:,1,26,:)  = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 )
631       ENDIF
632
633       IF ( humidity )  THEN
634!
635!--       Store initial profile of total water content, virtual potential
636!--       temperature
637          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
638          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
639          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
640!
641!--          Store initial profile of specific humidity and potential
642!--          temperature
643             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
644             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
645          ENDIF
646       ENDIF
647
648       IF ( passive_scalar )  THEN
649!
650!--       Store initial scalar profile
651          hom(:,1,26,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
652       ENDIF
653
654!
655!--    Initialize fluxes at bottom surface
656       IF ( use_surface_fluxes )  THEN
657
658          IF ( constant_heatflux )  THEN
659!
660!--          Heat flux is prescribed
661             IF ( random_heatflux )  THEN
662                CALL disturb_heatflux
663             ELSE
664                shf = surface_heatflux
665!
666!--             Over topography surface_heatflux is replaced by wall_heatflux(0)
667                IF ( TRIM( topography ) /= 'flat' )  THEN
668                   DO  i = nxl-1, nxr+1
669                      DO  j = nys-1, nyn+1
670                         IF ( nzb_s_inner(j,i) /= 0 )  THEN
671                            shf(j,i) = wall_heatflux(0)
672                         ENDIF
673                      ENDDO
674                   ENDDO
675                ENDIF
676             ENDIF
677             IF ( ASSOCIATED( shf_m ) )  shf_m = shf
678          ENDIF
679
680!
681!--       Determine the near-surface water flux
682          IF ( humidity  .OR.  passive_scalar )  THEN
683             IF ( constant_waterflux )  THEN
684                qsws   = surface_waterflux
685                IF ( ASSOCIATED( qsws_m ) )  qsws_m = qsws
686             ENDIF
687          ENDIF
688
689       ENDIF
690
691!
692!--    Initialize fluxes at top surface
693!--    Currently, only the heatflux and salinity flux can be prescribed.
694!--    The latent flux is zero in this case!
695       IF ( use_top_fluxes )  THEN
696
697          IF ( constant_top_heatflux )  THEN
698!
699!--          Heat flux is prescribed
700             tswst = top_heatflux
701             IF ( ASSOCIATED( tswst_m ) )  tswst_m = tswst
702
703             IF ( humidity  .OR.  passive_scalar )  THEN
704                qswst = 0.0
705                IF ( ASSOCIATED( qswst_m ) )  qswst_m = qswst
706             ENDIF
707
708             IF ( ocean )  THEN
709                saswsb = bottom_salinityflux
710                saswst = top_salinityflux
711             ENDIF
712          ENDIF
713
714!
715!--       Initialization in case of a coupled model run
716          IF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
717             tswst = 0.0
718             IF ( ASSOCIATED( tswst_m ) )  tswst_m = tswst
719          ENDIF
720
721       ENDIF
722
723!
724!--    Initialize Prandtl layer quantities
725       IF ( prandtl_layer )  THEN
726
727          z0 = roughness_length
728
729          IF ( .NOT. constant_heatflux )  THEN 
730!
731!--          Surface temperature is prescribed. Here the heat flux cannot be
732!--          simply estimated, because therefore rif, u* and theta* would have
733!--          to be computed by iteration. This is why the heat flux is assumed
734!--          to be zero before the first time step. It approaches its correct
735!--          value in the course of the first few time steps.
736             shf   = 0.0
737             IF ( ASSOCIATED( shf_m ) )  shf_m = 0.0
738          ENDIF
739
740          IF ( humidity  .OR.  passive_scalar )  THEN
741             IF ( .NOT. constant_waterflux )  THEN
742                qsws   = 0.0
743                IF ( ASSOCIATED( qsws_m ) )   qsws_m = 0.0
744             ENDIF
745          ENDIF
746
747       ENDIF
748
749!
750!--    Calculate the initial volume flow at the right and north boundary
751       IF ( conserve_volume_flow )  THEN
752
753          volume_flow_initial_l = 0.0
754          volume_flow_area_l    = 0.0
755 
756          IF ( nxr == nx )  THEN
757             DO  j = nys, nyn
758                DO  k = nzb_2d(j,nx) + 1, nzt
759                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
760                                              u(k,j,nx) * dzu(k)
761                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzu(k)
762                ENDDO
763!
764!--             Correction if velocity at nzb+1 has been set zero further above
765                volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
766                                           u_nzb_p1_for_vfc(j)
767             ENDDO
768          ENDIF
769
770          IF ( nyn == ny )  THEN
771             DO  i = nxl, nxr
772                DO  k = nzb_2d(ny,i) + 1, nzt 
773                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
774                                              v(k,ny,i) * dzu(k)
775                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzu(k)
776                ENDDO
777!
778!--             Correction if velocity at nzb+1 has been set zero further above
779                volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
780                                           v_nzb_p1_for_vfc(i)
781             ENDDO
782          ENDIF
783
784#if defined( __parallel )
785          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
786                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
787          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
788                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
789#else
790          volume_flow_initial = volume_flow_initial_l
791          volume_flow_area    = volume_flow_area_l
792#endif 
793       ENDIF
794
795!
796!--    For the moment, perturbation pressure and vertical velocity are zero
797       p = 0.0; w = 0.0
798
799!
800!--    Initialize array sums (must be defined in first call of pres)
801       sums = 0.0
802
803!
804!--    Treating cloud physics, liquid water content and precipitation amount
805!--    are zero at beginning of the simulation
806       IF ( cloud_physics )  THEN
807          ql = 0.0
808          IF ( precipitation )  precipitation_amount = 0.0
809       ENDIF
810
811!
812!--    Initialize spectra
813       IF ( dt_dosp /= 9999999.9 )  THEN
814          spectrum_x = 0.0
815          spectrum_y = 0.0
816       ENDIF
817
818!
819!--    Impose vortex with vertical axis on the initial velocity profile
820       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
821          CALL init_rankine
822       ENDIF
823
824!
825!--    Impose temperature anomaly (advection test only)
826       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 )  THEN
827          CALL init_pt_anomaly
828       ENDIF
829
830!
831!--    If required, change the surface temperature at the start of the 3D run
832       IF ( pt_surface_initial_change /= 0.0 )  THEN
833          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
834       ENDIF
835
836!
837!--    If required, change the surface humidity/scalar at the start of the 3D
838!--    run
839       IF ( ( humidity .OR. passive_scalar ) .AND. &
840            q_surface_initial_change /= 0.0 )  THEN
841          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
842       ENDIF
843
844!
845!--    Initialize the random number generator (from numerical recipes)
846       CALL random_function_ini
847
848!
849!--    Impose random perturbation on the horizontal velocity field and then
850!--    remove the divergences from the velocity field
851       IF ( create_disturbances )  THEN
852          CALL disturb_field( nzb_u_inner, tend, u )
853          CALL disturb_field( nzb_v_inner, tend, v )
854          n_sor = nsor_ini
855          CALL pres
856          n_sor = nsor
857       ENDIF
858
859!
860!--    Once again set the perturbation pressure explicitly to zero in order to
861!--    assure that it does not generate any divergences in the first time step.
862!--    At t=0 the velocity field is free of divergence (as constructed above).
863!--    Divergences being created during a time step are not yet known and thus
864!--    cannot be corrected during the time step yet.
865       p = 0.0
866
867!
868!--    Initialize old and new time levels.
869       IF ( timestep_scheme(1:5) /= 'runge' )  THEN
870          e_m = e; pt_m = pt; u_m = u; v_m = v; w_m = w; kh_m = kh; km_m = km
871       ELSE
872          te_m = 0.0; tpt_m = 0.0; tu_m = 0.0; tv_m = 0.0; tw_m = 0.0
873       ENDIF
874       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
875
876       IF ( humidity  .OR.  passive_scalar )  THEN
877          IF ( ASSOCIATED( q_m ) )  q_m = q
878          IF ( timestep_scheme(1:5) == 'runge' )  tq_m = 0.0
879          q_p = q
880          IF ( humidity  .AND.  ASSOCIATED( vpt_m ) )  vpt_m = vpt
881       ENDIF
882
883       IF ( ocean )  THEN
884          tsa_m = 0.0
885          sa_p  = sa
886       ENDIF
887
888!
889!--    Initialize old timelevels needed for radiation boundary conditions
890       IF ( outflow_l )  THEN
891          u_m_l(:,:,:) = u(:,:,1:2)
892          v_m_l(:,:,:) = v(:,:,0:1)
893          w_m_l(:,:,:) = w(:,:,0:1)
894       ENDIF
895       IF ( outflow_r )  THEN
896          u_m_r(:,:,:) = u(:,:,nx-1:nx)
897          v_m_r(:,:,:) = v(:,:,nx-1:nx)
898          w_m_r(:,:,:) = w(:,:,nx-1:nx)
899       ENDIF
900       IF ( outflow_s )  THEN
901          u_m_s(:,:,:) = u(:,0:1,:)
902          v_m_s(:,:,:) = v(:,1:2,:)
903          w_m_s(:,:,:) = w(:,0:1,:)
904       ENDIF
905       IF ( outflow_n )  THEN
906          u_m_n(:,:,:) = u(:,ny-1:ny,:)
907          v_m_n(:,:,:) = v(:,ny-1:ny,:)
908          w_m_n(:,:,:) = w(:,ny-1:ny,:)
909       ENDIF
910
911    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data' ) &
912    THEN
913!
914!--    Read binary data from restart file
915       CALL read_3d_binary
916
917!
918!--    Calculate initial temperature field and other constants used in case
919!--    of a sloping surface
920       IF ( sloping_surface )  CALL init_slope
921
922!
923!--    Initialize new time levels (only done in order to set boundary values
924!--    including ghost points)
925       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
926       IF ( humidity  .OR.  passive_scalar )  q_p = q
927       IF ( ocean )  sa_p = sa
928
929    ELSE
930!
931!--    Actually this part of the programm should not be reached
932       IF ( myid == 0 )  PRINT*,'+++ init_3d_model: unknown initializing ', &
933                                                    'problem'
934       CALL local_stop
935    ENDIF
936
937!
938!-- Initialization of the leaf area density
939    IF ( plant_canopy ) THEN
940 
941       SELECT CASE ( TRIM( canopy_mode ) )
942
943          CASE( 'block' )
944
945             DO  i = nxl-1, nxr+1
946                DO  j = nys-1, nyn+1
947                   lad_s(:,j,i) = lad(:)
948                   cdc(:,j,i)   = drag_coefficient
949                ENDDO
950             ENDDO
951
952          CASE DEFAULT
953
954!
955!--          The DEFAULT case is reached either if the parameter
956!--          canopy mode contains a wrong character string or if the
957!--          user has coded a special case in the user interface.
958!--          There, the subroutine user_init_plant_canopy checks
959!--          which of these two conditions applies.
960             CALL user_init_plant_canopy
961 
962          END SELECT
963
964       CALL exchange_horiz( lad_s )
965       CALL exchange_horiz( cdc )
966
967       DO  i = nxl, nxr
968          DO  j = nys, nyn
969             DO  k = nzb, nzt+1 
970                lad_u(k,j,i) = 0.5 * ( lad_s(k,j,i-1) + lad_s(k,j,i) )
971                lad_v(k,j,i) = 0.5 * ( lad_s(k,j-1,i) + lad_s(k,j,i) )
972             ENDDO
973             DO  k = nzb, nzt
974                lad_w(k,j,i) = 0.5 * ( lad_s(k+1,j,i) + lad_s(k,j,i) )
975             ENDDO
976          ENDDO
977       ENDDO
978
979       lad_w(nzt+1,:,:) = lad_w(nzt,:,:)
980
981       CALL exchange_horiz( lad_u )
982       CALL exchange_horiz( lad_v )
983       CALL exchange_horiz( lad_w )
984 
985    ENDIF
986
987!
988!-- If required, initialize dvrp-software
989    IF ( dt_dvrp /= 9999999.9 )  CALL init_dvrp
990
991    IF ( ocean )  THEN
992!
993!--    Initialize quantities needed for the ocean model
994       CALL init_ocean
995    ELSE
996!
997!--    Initialize quantities for handling cloud physics
998!--    This routine must be called before init_particles, because
999!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
1000!--    init_particles) is not defined.
1001       CALL init_cloud_physics
1002    ENDIF
1003
1004!
1005!-- If required, initialize particles
1006    IF ( particle_advection )  CALL init_particles
1007
1008!
1009!-- Initialize quantities for special advections schemes
1010    CALL init_advec
1011
1012!
1013!-- Initialize Rayleigh damping factors
1014    rdf = 0.0
1015    IF ( rayleigh_damping_factor /= 0.0 )  THEN
1016       IF ( .NOT. ocean )  THEN
1017          DO  k = nzb+1, nzt
1018             IF ( zu(k) >= rayleigh_damping_height )  THEN
1019                rdf(k) = rayleigh_damping_factor * &
1020                      ( SIN( pi * 0.5 * ( zu(k) - rayleigh_damping_height )    &
1021                                      / ( zu(nzt) - rayleigh_damping_height ) )&
1022                      )**2
1023             ENDIF
1024          ENDDO
1025       ELSE
1026          DO  k = nzt, nzb+1, -1
1027             IF ( zu(k) <= rayleigh_damping_height )  THEN
1028                rdf(k) = rayleigh_damping_factor * &
1029                      ( SIN( pi * 0.5 * ( rayleigh_damping_height - zu(k) )    &
1030                                      / ( rayleigh_damping_height - zu(nzb+1)))&
1031                      )**2
1032             ENDIF
1033          ENDDO
1034       ENDIF
1035    ENDIF
1036
1037!
1038!-- Initialize diffusivities used within the outflow damping layer in case of
1039!-- non-cyclic lateral boundaries. A linear increase is assumed over the first
1040!-- half of the width of the damping layer
1041    IF ( bc_lr == 'dirichlet/radiation' )  THEN
1042
1043       DO  i = nxl-1, nxr+1
1044          IF ( i >= nx - outflow_damping_width )  THEN
1045             km_damp_x(i) = km_damp_max * MIN( 1.0,                    &
1046                            ( i - ( nx - outflow_damping_width ) ) /   &
1047                            REAL( outflow_damping_width/2 )            &
1048                                             )
1049          ELSE
1050             km_damp_x(i) = 0.0
1051          ENDIF
1052       ENDDO
1053
1054    ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
1055
1056       DO  i = nxl-1, nxr+1
1057          IF ( i <= outflow_damping_width )  THEN
1058             km_damp_x(i) = km_damp_max * MIN( 1.0,                    &
1059                            ( outflow_damping_width - i ) /            &
1060                            REAL( outflow_damping_width/2 )            &
1061                                             )
1062          ELSE
1063             km_damp_x(i) = 0.0
1064          ENDIF
1065       ENDDO
1066
1067    ENDIF
1068
1069    IF ( bc_ns == 'dirichlet/radiation' )  THEN
1070
1071       DO  j = nys-1, nyn+1
1072          IF ( j >= ny - outflow_damping_width )  THEN
1073             km_damp_y(j) = km_damp_max * MIN( 1.0,                    &
1074                            ( j - ( ny - outflow_damping_width ) ) /   &
1075                            REAL( outflow_damping_width/2 )            &
1076                                             )
1077          ELSE
1078             km_damp_y(j) = 0.0
1079          ENDIF
1080       ENDDO
1081
1082    ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
1083
1084       DO  j = nys-1, nyn+1
1085          IF ( j <= outflow_damping_width )  THEN
1086             km_damp_y(j) = km_damp_max * MIN( 1.0,                    &
1087                            ( outflow_damping_width - j ) /            &
1088                            REAL( outflow_damping_width/2 )            &
1089                                             )
1090          ELSE
1091             km_damp_y(j) = 0.0
1092          ENDIF
1093       ENDDO
1094
1095    ENDIF
1096
1097!
1098!-- Initialize local summation arrays for UP flow_statistics. This is necessary
1099!-- because they may not yet have been initialized when they are called from
1100!-- flow_statistics (or - depending on the chosen model run - are never
1101!-- initialized)
1102    sums_divnew_l      = 0.0
1103    sums_divold_l      = 0.0
1104    sums_l_l           = 0.0
1105    sums_up_fraction_l = 0.0
1106    sums_wsts_bc_l     = 0.0
1107
1108!
1109!-- Pre-set masks for regional statistics. Default is the total model domain.
1110    rmask = 1.0
1111
1112!
1113!-- User-defined initializing actions. Check afterwards, if maximum number
1114!-- of allowed timeseries is not exceeded
1115    CALL user_init
1116
1117    IF ( dots_num > dots_max )  THEN
1118       IF ( myid == 0 )  THEN
1119          PRINT*, '+++ user_init: number of time series quantities exceeds', &
1120                  ' its maximum of dots_max = ', dots_max
1121          PRINT*, '    Please increase dots_max in modules.f90.'
1122       ENDIF
1123       CALL local_stop
1124    ENDIF
1125
1126!
1127!-- Input binary data file is not needed anymore. This line must be placed
1128!-- after call of user_init!
1129    CALL close_file( 13 )
1130
1131!
1132!-- Compute total sum of active mask grid points
1133!-- ngp_2dh: number of grid points of a horizontal cross section through the
1134!--          total domain
1135!-- ngp_3d:  number of grid points of the total domain
1136    ngp_2dh_outer_l   = 0
1137    ngp_2dh_outer     = 0
1138    ngp_2dh_s_inner_l = 0
1139    ngp_2dh_s_inner   = 0
1140    ngp_2dh_l         = 0
1141    ngp_2dh           = 0
1142    ngp_3d_inner_l    = 0
1143    ngp_3d_inner      = 0
1144    ngp_3d            = 0
1145    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
1146
1147    DO  sr = 0, statistic_regions
1148       DO  i = nxl, nxr
1149          DO  j = nys, nyn
1150             IF ( rmask(j,i,sr) == 1.0 )  THEN
1151!
1152!--             All xy-grid points
1153                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
1154!
1155!--             xy-grid points above topography
1156                DO  k = nzb_s_outer(j,i), nz + 1
1157                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr) + 1
1158                ENDDO
1159                DO  k = nzb_s_inner(j,i), nz + 1
1160                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) + 1
1161                ENDDO
1162!
1163!--             All grid points of the total domain above topography
1164                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + &
1165                                     ( nz - nzb_s_inner(j,i) + 2 )
1166             ENDIF
1167          ENDDO
1168       ENDDO
1169    ENDDO
1170
1171    sr = statistic_regions + 1
1172#if defined( __parallel )
1173    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,  &
1174                        comm2d, ierr )
1175    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr, &
1176                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
1177    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),        &
1178                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
1179    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner(0), sr, MPI_INTEGER, &
1180                        MPI_SUM, comm2d, ierr )
1181#else
1182    ngp_2dh         = ngp_2dh_l
1183    ngp_2dh_outer   = ngp_2dh_outer_l
1184    ngp_2dh_s_inner = ngp_2dh_s_inner_l
1185    ngp_3d_inner    = ngp_3d_inner_l
1186#endif
1187
1188    ngp_3d = ngp_2dh * ( nz + 2 )
1189
1190!
1191!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
1192!-- buoyancy, etc. A zero value will occur for cases where all grid points of
1193!-- the respective subdomain lie below the surface topography
1194    ngp_2dh_outer = MAX( 1, ngp_2dh_outer(:,:) ) 
1195    ngp_3d_inner  = MAX( 1, ngp_3d_inner(:)    )
1196
1197    DEALLOCATE( ngp_2dh_l, ngp_2dh_outer_l, ngp_3d_inner_l )
1198
1199
1200 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.