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

Last change on this file since 557 was 557, checked in by weinreis, 14 years ago

bugfix message string in set_mask_locations

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