source: palm/tags/release-3.1c/SOURCE/init_3d_model.f90 @ 102

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

documentation update for the new svn-based version and for 3.1c, update of .mrun.config.default, -u in mbuild only compiles scripts

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