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

Last change on this file since 622 was 622, checked in by raasch, 13 years ago

New:
---

Optional barriers included in order to speed up collective operations
MPI_ALLTOALL and MPI_ALLREDUCE. This feature is controlled with new initial
parameter collective_wait. Default is .FALSE, but .TRUE. on SGI-type
systems. (advec_particles, advec_s_bc, buoyancy, check_for_restart,
cpu_statistics, data_output_2d, data_output_ptseries, flow_statistics,
global_min_max, inflow_turbulence, init_3d_model, init_particles, init_pegrid,
init_slope, parin, pres, poismg, set_particle_attributes, timestep,
read_var_list, user_statistics, write_compressed, write_var_list)

Adjustments for Kyushu Univ. (lcrte, ibmku). Concerning hybrid
(MPI/openMP) runs, the number of openMP threads per MPI tasks can now
be given as an argument to mrun-option -O. (mbuild, mrun, subjob)

Changed:


Initialization of the module command changed for SGI-ICE/lcsgi (mbuild, subjob)

Errors:


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