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

Last change on this file since 144 was 143, checked in by raasch, 16 years ago

first preliminary update for turbulent inflow

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