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

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

preliminary changes for radiation conditions

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