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

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

New:
---
ocean version including prognostic equation for salinity and equation of state for seawater. Routine buoyancy can be used with both temperature and density.
+ inipar-parameters bc_sa_t, bottom_salinityflux, ocean, sa_surface, sa_vertical_gradient, sa_vertical_gradient_level, top_salinityflux

advec_s_bc, average_3d_data, boundary_conds, buoyancy, check_parameters, data_output_2d, data_output_3d, diffusion_e, flow_statistics, header, init_grid, init_3d_model, modules, netcdf, parin, production_e, prognostic_equations, read_var_list, sum_up_3d_data, swap_timelevel, time_integration, user_interface, write_var_list, write_3d_binary

New:
eqn_state_seawater, init_ocean

Changed:


inipar-parameter use_pt_reference renamed use_reference

hydro_press renamed hyp, routine calc_mean_pt_profile renamed calc_mean_profile

format adjustments for the ocean version (run_control)

advec_particles, buoyancy, calc_liquid_water_content, check_parameters, diffusion_e, diffusivities, header, init_cloud_physics, modules, production_e, prognostic_equations, run_control

Errors:


Bugfix: height above topography instead of height above level k=0 is used for calculating the mixing length (diffusion_e and diffusivities).

Bugfix: error in boundary condition for TKE removed (advec_s_bc)

advec_s_bc, diffusion_e, prognostic_equations

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