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

Last change on this file since 668 was 668, checked in by suehring, 13 years ago

last commit documented

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