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

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

further updates for turbulent inflow: PE-grid change for restart is working

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