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

Last change on this file since 75 was 75, checked in by raasch, 17 years ago

preliminary update for changes concerning non-cyclic boundary conditions

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