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

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

formatting adjustments

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