source: palm/trunk/SOURCE/init_1d_model.f90 @ 990

Last change on this file since 990 was 979, checked in by fricke, 12 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 34.4 KB
Line 
1 SUBROUTINE init_1d_model
2
3!------------------------------------------------------------------------------!
4! Current revisions:
5! -----------------
6!
7!
8! Former revisions:
9! -----------------
10! $Id: init_1d_model.f90 979 2012-08-09 08:50:11Z maronga $
11!
12! 978 2012-08-09 08:28:32Z fricke
13! roughness length for scalar quantities z0h1d added
14!
15! 667 2010-12-23 12:06:00Z suehring/gryschka
16! replaced mirror boundary conditions for u and v  at the ground
17! by dirichlet boundary conditions
18!
19! 254 2009-03-05 15:33:42Z heinze
20! Output of messages replaced by message handling routine.
21!
22! 184 2008-08-04 15:53:39Z letzel
23! provisional solution for run_control_1d output: add 'CALL check_open( 15 )'
24!
25! 135 2007-11-22 12:24:23Z raasch
26! Bugfix: absolute value of f must be used when calculating the Blackadar
27! mixing length
28!
29! 82 2007-04-16 15:40:52Z raasch
30! Preprocessor strings for different linux clusters changed to "lc",
31! routine local_flush is used for buffer flushing
32!
33! 75 2007-03-22 09:54:05Z raasch
34! Bugfix: preset of tendencies te_em, te_um, te_vm,
35! moisture renamed humidity
36!
37! RCS Log replace by Id keyword, revision history cleaned up
38!
39! Revision 1.21  2006/06/02 15:19:57  raasch
40! cpp-directives extended for lctit
41!
42! Revision 1.1  1998/03/09 16:22:10  raasch
43! Initial revision
44!
45!
46! Description:
47! ------------
48! 1D-model to initialize the 3D-arrays.
49! The temperature profile is set as steady and a corresponding steady solution
50! of the wind profile is being computed.
51! All subroutines required can be found within this file.
52!------------------------------------------------------------------------------!
53
54    USE arrays_3d
55    USE indices
56    USE model_1d
57    USE control_parameters
58
59    IMPLICIT NONE
60
61    CHARACTER (LEN=9) ::  time_to_string
62    INTEGER ::  k
63    REAL    ::  lambda
64
65!
66!-- Allocate required 1D-arrays
67    ALLOCATE( e1d(nzb:nzt+1),    e1d_m(nzb:nzt+1),   e1d_p(nzb:nzt+1), &
68              kh1d(nzb:nzt+1),   kh1d_m(nzb:nzt+1),  km1d(nzb:nzt+1),  &
69              km1d_m(nzb:nzt+1), l_black(nzb:nzt+1), l1d(nzb:nzt+1),   &
70              l1d_m(nzb:nzt+1),  rif1d(nzb:nzt+1),   te_e(nzb:nzt+1),  &
71              te_em(nzb:nzt+1),  te_u(nzb:nzt+1),    te_um(nzb:nzt+1), &
72              te_v(nzb:nzt+1),   te_vm(nzb:nzt+1),    u1d(nzb:nzt+1),   &
73              u1d_m(nzb:nzt+1),  u1d_p(nzb:nzt+1),   v1d(nzb:nzt+1),   &
74              v1d_m(nzb:nzt+1),  v1d_p(nzb:nzt+1) )
75
76!
77!-- Initialize arrays
78    IF ( constant_diffusion )  THEN
79       km1d   = km_constant
80       km1d_m = km_constant
81       kh1d   = km_constant / prandtl_number
82       kh1d_m = km_constant / prandtl_number
83    ELSE
84       e1d = 0.0; e1d_m = 0.0; e1d_p = 0.0
85       kh1d = 0.0; kh1d_m = 0.0; km1d = 0.0; km1d_m = 0.0
86       rif1d = 0.0
87!
88!--    Compute the mixing length
89       l_black(nzb) = 0.0
90
91       IF ( TRIM( mixing_length_1d ) == 'blackadar' )  THEN
92!
93!--       Blackadar mixing length
94          IF ( f /= 0.0 )  THEN
95             lambda = 2.7E-4 * SQRT( ug(nzt+1)**2 + vg(nzt+1)**2 ) / &
96                               ABS( f ) + 1E-10
97          ELSE
98             lambda = 30.0
99          ENDIF
100
101          DO  k = nzb+1, nzt+1
102             l_black(k) = kappa * zu(k) / ( 1.0 + kappa * zu(k) / lambda )
103          ENDDO
104
105       ELSEIF ( TRIM( mixing_length_1d ) == 'as_in_3d_model' )  THEN
106!
107!--       Use the same mixing length as in 3D model
108          l_black(1:nzt) = l_grid
109          l_black(nzt+1) = l_black(nzt)
110
111       ENDIF
112
113!
114!--    Adjust mixing length to the prandtl mixing length (within the prandtl
115!--    layer)
116       IF ( adjust_mixing_length  .AND.  prandtl_layer )  THEN
117          k = nzb+1
118          l_black(k) = MIN( l_black(k), kappa * zu(k) )
119       ENDIF
120    ENDIF
121    l1d   = l_black
122    l1d_m = l_black
123    u1d   = u_init
124    u1d_m = u_init
125    u1d_p = u_init
126    v1d   = v_init
127    v1d_m = v_init
128    v1d_p = v_init
129
130!
131!-- Set initial horizontal velocities at the lowest grid levels to a very small
132!-- value in order to avoid too small time steps caused by the diffusion limit
133!-- in the initial phase of a run (at k=1, dz/2 occurs in the limiting formula!)
134    u1d(0:1)   = 0.1
135    u1d_m(0:1) = 0.1
136    u1d_p(0:1) = 0.1
137    v1d(0:1)   = 0.1
138    v1d_m(0:1) = 0.1
139    v1d_p(0:1) = 0.1
140
141!
142!-- For u*, theta* and the momentum fluxes plausible values are set
143    IF ( prandtl_layer )  THEN
144       us1d = 0.1   ! without initial friction the flow would not change
145    ELSE
146       e1d(nzb+1)  = 1.0
147       km1d(nzb+1) = 1.0
148       us1d = 0.0
149    ENDIF
150    ts1d = 0.0
151    usws1d = 0.0; usws1d_m = 0.0
152    vsws1d = 0.0; vsws1d_m = 0.0
153    z01d = roughness_length
154    z0h1d = z0h_factor * z01d 
155    IF ( humidity .OR. passive_scalar )  qs1d = 0.0
156
157!
158!-- Tendencies must be preset in order to avoid runtime errors within the
159!-- first Runge-Kutta step
160    te_em = 0.0
161    te_um = 0.0
162    te_vm = 0.0
163
164!
165!-- Set start time in hh:mm:ss - format
166    simulated_time_chr = time_to_string( simulated_time_1d )
167
168!
169!-- Integrate the 1D-model equations using the leap-frog scheme
170    CALL time_integration_1d
171
172
173 END SUBROUTINE init_1d_model
174
175
176
177 SUBROUTINE time_integration_1d
178
179!------------------------------------------------------------------------------!
180! Description:
181! ------------
182! Leap-frog time differencing scheme for the 1D-model.
183!------------------------------------------------------------------------------!
184
185    USE arrays_3d
186    USE control_parameters
187    USE indices
188    USE model_1d
189    USE pegrid
190
191    IMPLICIT NONE
192
193    CHARACTER (LEN=9) ::  time_to_string
194    INTEGER ::  k
195    REAL    ::  a, b, dissipation, dpt_dz, flux, kmzm, kmzp, l_stable, pt_0, &
196                uv_total
197
198!
199!-- Determine the time step at the start of a 1D-simulation and
200!-- determine and printout quantities used for run control
201    CALL timestep_1d
202    CALL run_control_1d
203
204!
205!-- Start of time loop
206    DO  WHILE ( simulated_time_1d < end_time_1d  .AND.  .NOT. stop_dt_1d )
207
208!
209!--    Depending on the timestep scheme, carry out one or more intermediate
210!--    timesteps
211
212       intermediate_timestep_count = 0
213       DO  WHILE ( intermediate_timestep_count < &
214                   intermediate_timestep_count_max )
215
216          intermediate_timestep_count = intermediate_timestep_count + 1
217
218          CALL timestep_scheme_steering
219
220!
221!--       Compute all tendency terms. If a Prandtl-layer is simulated, k starts
222!--       at nzb+2.
223          DO  k = nzb_diff, nzt
224
225             kmzm = 0.5 * ( km1d_m(k-1) + km1d_m(k) )
226             kmzp = 0.5 * ( km1d_m(k) + km1d_m(k+1) )
227!
228!--          u-component
229             te_u(k) =  f * ( v1d(k) - vg(k) ) + ( &
230                              kmzp * ( u1d_m(k+1) - u1d_m(k) ) * ddzu(k+1) &
231                            - kmzm * ( u1d_m(k) - u1d_m(k-1) ) * ddzu(k)   &
232                                              ) * ddzw(k)
233!
234!--          v-component
235             te_v(k) = -f * ( u1d(k) - ug(k) ) + ( &
236                              kmzp * ( v1d_m(k+1) - v1d_m(k) ) * ddzu(k+1) &
237                            - kmzm * ( v1d_m(k) - v1d_m(k-1) ) * ddzu(k)   &
238                                              ) * ddzw(k)
239          ENDDO
240          IF ( .NOT. constant_diffusion )  THEN
241             DO  k = nzb_diff, nzt
242!
243!--             TKE
244                kmzm = 0.5 * ( km1d_m(k-1) + km1d_m(k) )
245                kmzp = 0.5 * ( km1d_m(k) + km1d_m(k+1) )
246                IF ( .NOT. humidity )  THEN
247                   pt_0 = pt_init(k)
248                   flux =  ( pt_init(k+1)-pt_init(k-1) ) * dd2zu(k)
249                ELSE
250                   pt_0 = pt_init(k) * ( 1.0 + 0.61 * q_init(k) )
251                   flux = ( ( pt_init(k+1) - pt_init(k-1) ) +                 &
252                            0.61 * pt_init(k) * ( q_init(k+1) - q_init(k-1) ) &
253                          ) * dd2zu(k)
254                ENDIF
255
256                IF ( dissipation_1d == 'detering' )  THEN
257!
258!--                According to Detering, c_e=0.064
259                   dissipation = 0.064 * e1d_m(k) * SQRT( e1d_m(k) ) / l1d_m(k)
260                ELSEIF ( dissipation_1d == 'as_in_3d_model' )  THEN
261                   dissipation = ( 0.19 + 0.74 * l1d_m(k) / l_grid(k) ) &
262                                 * e1d_m(k) * SQRT( e1d_m(k) ) / l1d_m(k)
263                ENDIF
264
265                te_e(k) = km1d(k) * ( ( ( u1d(k+1) - u1d(k-1) ) * dd2zu(k) )**2&
266                                    + ( ( v1d(k+1) - v1d(k-1) ) * dd2zu(k) )**2&
267                                    )                                          &
268                                    - g / pt_0 * kh1d(k) * flux                &
269                                    +            (                             &
270                                 kmzp * ( e1d_m(k+1) - e1d_m(k) ) * ddzu(k+1)  &
271                               - kmzm * ( e1d_m(k) - e1d_m(k-1) ) * ddzu(k)    &
272                                                 ) * ddzw(k)                   &
273                               - dissipation
274             ENDDO
275          ENDIF
276
277!
278!--       Tendency terms at the top of the Prandtl-layer.
279!--       Finite differences of the momentum fluxes are computed using half the
280!--       normal grid length (2.0*ddzw(k)) for the sake of enhanced accuracy
281          IF ( prandtl_layer )  THEN
282
283             k = nzb+1
284             kmzm = 0.5 * ( km1d_m(k-1) + km1d_m(k) )
285             kmzp = 0.5 * ( km1d_m(k) + km1d_m(k+1) )
286             IF ( .NOT. humidity )  THEN
287                pt_0 = pt_init(k)
288                flux =  ( pt_init(k+1)-pt_init(k-1) ) * dd2zu(k)
289             ELSE
290                pt_0 = pt_init(k) * ( 1.0 + 0.61 * q_init(k) )
291                flux = ( ( pt_init(k+1) - pt_init(k-1) ) +                 &
292                         0.61 * pt_init(k) * ( q_init(k+1) - q_init(k-1) ) &
293                       ) * dd2zu(k)
294             ENDIF
295
296             IF ( dissipation_1d == 'detering' )  THEN
297!
298!--             According to Detering, c_e=0.064
299                dissipation = 0.064 * e1d_m(k) * SQRT( e1d_m(k) ) / l1d_m(k)
300             ELSEIF ( dissipation_1d == 'as_in_3d_model' )  THEN
301                dissipation = ( 0.19 + 0.74 * l1d_m(k) / l_grid(k) ) &
302                              * e1d_m(k) * SQRT( e1d_m(k) ) / l1d_m(k)
303             ENDIF
304
305!
306!--          u-component
307             te_u(k) = f * ( v1d(k) - vg(k) ) + ( &
308                       kmzp * ( u1d_m(k+1) - u1d_m(k) ) * ddzu(k+1) + usws1d_m &
309                                               ) * 2.0 * ddzw(k)
310!
311!--          v-component
312             te_v(k) = -f * ( u1d(k) - ug(k) ) + ( &
313                       kmzp * ( v1d_m(k+1) - v1d_m(k) ) * ddzu(k+1) + vsws1d_m &
314                                           ) * 2.0 * ddzw(k)
315!
316!--          TKE
317             te_e(k) = km1d(k) * ( ( ( u1d(k+1) - u1d(k-1) ) * dd2zu(k) )**2   &
318                                 + ( ( v1d(k+1) - v1d(k-1) ) * dd2zu(k) )**2   &
319                                 )                                             &
320                                 - g / pt_0 * kh1d(k) * flux                   &
321                                 +           (                                 &
322                              kmzp * ( e1d_m(k+1) - e1d_m(k) ) * ddzu(k+1)     &
323                            - kmzm * ( e1d_m(k) - e1d_m(k-1) ) * ddzu(k)       &
324                                              ) * ddzw(k)                      &
325                            - dissipation
326          ENDIF
327
328!
329!--       Prognostic equations for all 1D variables
330          DO  k = nzb+1, nzt
331
332             u1d_p(k) = ( 1. - tsc(1) ) * u1d_m(k) + &
333                        tsc(1) * u1d(k) + dt_1d * ( tsc(2) * te_u(k) + &
334                                                    tsc(3) * te_um(k) ) 
335             v1d_p(k) = ( 1. - tsc(1) ) * v1d_m(k) + &
336                        tsc(1) * v1d(k) + dt_1d * ( tsc(2) * te_v(k) + &
337                                                    tsc(3) * te_vm(k) ) 
338
339          ENDDO
340          IF ( .NOT. constant_diffusion )  THEN
341             DO  k = nzb+1, nzt
342
343                e1d_p(k) = ( 1. - tsc(1) ) * e1d_m(k) + &
344                           tsc(1) * e1d(k) + dt_1d * ( tsc(2) * te_e(k) + &
345                                                       tsc(3) * te_em(k) ) 
346
347             ENDDO
348!
349!--          Eliminate negative TKE values, which can result from the
350!--          integration due to numerical inaccuracies. In such cases the TKE
351!--          value is reduced to 10 percent of its old value.
352             WHERE ( e1d_p < 0.0 )  e1d_p = 0.1 * e1d
353          ENDIF
354
355!
356!--       Calculate tendencies for the next Runge-Kutta step
357          IF ( timestep_scheme(1:5) == 'runge' ) THEN
358             IF ( intermediate_timestep_count == 1 )  THEN
359
360                DO  k = nzb+1, nzt
361                   te_um(k) = te_u(k)
362                   te_vm(k) = te_v(k)
363                ENDDO
364
365                IF ( .NOT. constant_diffusion )  THEN
366                   DO k = nzb+1, nzt
367                      te_em(k) = te_e(k)
368                   ENDDO
369                ENDIF
370
371             ELSEIF ( intermediate_timestep_count < &
372                         intermediate_timestep_count_max )  THEN
373
374                DO  k = nzb+1, nzt
375                   te_um(k) = -9.5625 * te_u(k) + 5.3125 * te_um(k)
376                   te_vm(k) = -9.5625 * te_v(k) + 5.3125 * te_vm(k)
377                ENDDO
378
379                IF ( .NOT. constant_diffusion )  THEN
380                   DO k = nzb+1, nzt
381                      te_em(k) = -9.5625 * te_e(k) + 5.3125 * te_em(k)
382                   ENDDO
383                ENDIF
384
385             ENDIF
386          ENDIF
387
388
389!
390!--       Boundary conditions for the prognostic variables.
391!--       At the top boundary (nzt+1) u,v and e keep their initial values
392!--       (ug(nzt+1), vg(nzt+1), 0), at the bottom boundary the mirror
393!--       boundary condition applies to u and v.
394!--       The boundary condition for e is set further below ( (u*/cm)**2 ).
395         ! u1d_p(nzb) = -u1d_p(nzb+1)
396         ! v1d_p(nzb) = -v1d_p(nzb+1)
397
398          u1d_p(nzb) = 0.0
399          v1d_p(nzb) = 0.0
400
401!
402!--       If necessary, apply the time filter
403          IF ( asselin_filter_factor /= 0.0  .AND. &
404               timestep_scheme(1:5) /= 'runge' )  THEN
405
406             u1d = u1d + asselin_filter_factor * ( u1d_p - 2.0 * u1d + u1d_m )
407             v1d = v1d + asselin_filter_factor * ( v1d_p - 2.0 * v1d + v1d_m )
408
409             IF ( .NOT. constant_diffusion )  THEN
410                e1d = e1d + asselin_filter_factor * &
411                            ( e1d_p - 2.0 * e1d + e1d_m )
412             ENDIF
413
414          ENDIF
415
416!
417!--       Swap the time levels in preparation for the next time step.
418          IF ( timestep_scheme(1:4) == 'leap' )  THEN
419             u1d_m  = u1d
420             v1d_m  = v1d
421             IF ( .NOT. constant_diffusion )  THEN
422                e1d_m  = e1d
423                kh1d_m = kh1d  ! The old diffusion quantities are required for
424                km1d_m = km1d  ! explicit diffusion in the leap-frog scheme.
425                l1d_m  = l1d
426                IF ( prandtl_layer )  THEN
427                   usws1d_m = usws1d
428                   vsws1d_m = vsws1d
429                ENDIF
430             ENDIF
431          ENDIF
432          u1d  = u1d_p
433          v1d  = v1d_p
434          IF ( .NOT. constant_diffusion )  THEN
435             e1d  = e1d_p
436          ENDIF
437
438!
439!--       Compute diffusion quantities
440          IF ( .NOT. constant_diffusion )  THEN
441
442!
443!--          First compute the vertical fluxes in the Prandtl-layer
444             IF ( prandtl_layer )  THEN
445!
446!--             Compute theta* using Rif numbers of the previous time step
447                IF ( rif1d(1) >= 0.0 )  THEN
448!
449!--                Stable stratification
450                   ts1d = kappa * ( pt_init(nzb+1) - pt_init(nzb) ) /      &
451                          ( LOG( zu(nzb+1) / z0h1d ) + 5.0 * rif1d(nzb+1) * &
452                                          ( zu(nzb+1) - z0h1d ) / zu(nzb+1) &
453                          )
454                ELSE
455!
456!--                Unstable stratification
457                   a = SQRT( 1.0 - 16.0 * rif1d(nzb+1) )
458                   b = SQRT( 1.0 - 16.0 * rif1d(nzb+1) / zu(nzb+1) * z0h1d )
459!
460!--                In the borderline case the formula for stable stratification
461!--                must be applied, because otherwise a zero division would
462!--                occur in the argument of the logarithm.
463                   IF ( a == 0.0  .OR.  b == 0.0 )  THEN
464                      ts1d = kappa * ( pt_init(nzb+1) - pt_init(nzb) ) /      &
465                             ( LOG( zu(nzb+1) / z0h1d ) + 5.0 * rif1d(nzb+1) * &
466                                             ( zu(nzb+1) - z0h1d ) / zu(nzb+1) &
467                             )
468                   ELSE
469                      ts1d = kappa * ( pt_init(nzb+1) - pt_init(nzb) ) / &
470                             LOG( (a-1.0) / (a+1.0) * (b+1.0) / (b-1.0) )
471                   ENDIF
472                ENDIF
473
474             ENDIF    ! prandtl_layer
475
476!
477!--          Compute the Richardson-flux numbers,
478!--          first at the top of the Prandtl-layer using u* of the previous
479!--          time step (+1E-30, if u* = 0), then in the remaining area. There
480!--          the rif-numbers of the previous time step are used.
481
482             IF ( prandtl_layer )  THEN
483                IF ( .NOT. humidity )  THEN
484                   pt_0 = pt_init(nzb+1)
485                   flux = ts1d
486                ELSE
487                   pt_0 = pt_init(nzb+1) * ( 1.0 + 0.61 * q_init(nzb+1) )
488                   flux = ts1d + 0.61 * pt_init(k) * qs1d
489                ENDIF
490                rif1d(nzb+1) = zu(nzb+1) * kappa * g * flux / &
491                               ( pt_0 * ( us1d**2 + 1E-30 ) )
492             ENDIF
493
494             DO  k = nzb_diff, nzt
495                IF ( .NOT. humidity )  THEN
496                   pt_0 = pt_init(k)
497                   flux = ( pt_init(k+1) - pt_init(k-1) ) * dd2zu(k)
498                ELSE
499                   pt_0 = pt_init(k) * ( 1.0 + 0.61 * q_init(k) )
500                   flux = ( ( pt_init(k+1) - pt_init(k-1) )                    &
501                            + 0.61 * pt_init(k) * ( q_init(k+1) - q_init(k-1) )&
502                          ) * dd2zu(k)
503                ENDIF
504                IF ( rif1d(k) >= 0.0 )  THEN
505                   rif1d(k) = g / pt_0 * flux /                              &
506                              (  ( ( u1d(k+1) - u1d(k-1) ) * dd2zu(k) )**2   &
507                               + ( ( v1d(k+1) - v1d(k-1) ) * dd2zu(k) )**2   &
508                               + 1E-30                                       &
509                              )
510                ELSE
511                   rif1d(k) = g / pt_0 * flux /                              &
512                              (  ( ( u1d(k+1) - u1d(k-1) ) * dd2zu(k) )**2   &
513                               + ( ( v1d(k+1) - v1d(k-1) ) * dd2zu(k) )**2   &
514                               + 1E-30                                       &
515                              ) * ( 1.0 - 16.0 * rif1d(k) )**0.25
516                ENDIF
517             ENDDO
518!
519!--          Richardson-numbers must remain restricted to a realistic value
520!--          range. It is exceeded excessively for very small velocities
521!--          (u,v --> 0).
522             WHERE ( rif1d < rif_min )  rif1d = rif_min
523             WHERE ( rif1d > rif_max )  rif1d = rif_max
524
525!
526!--          Compute u* from the absolute velocity value
527             IF ( prandtl_layer )  THEN
528                uv_total = SQRT( u1d(nzb+1)**2 + v1d(nzb+1)**2 )
529
530                IF ( rif1d(nzb+1) >= 0.0 )  THEN
531!
532!--                Stable stratification
533                   us1d = kappa * uv_total / (                                 &
534                             LOG( zu(nzb+1) / z01d ) + 5.0 * rif1d(nzb+1) *    &
535                                              ( zu(nzb+1) - z01d ) / zu(nzb+1) &
536                                             )
537                ELSE
538!
539!--                Unstable stratification
540                   a = 1.0 / SQRT( SQRT( 1.0 - 16.0 * rif1d(nzb+1) ) )
541                   b = 1.0 / SQRT( SQRT( 1.0 - 16.0 * rif1d(nzb+1) / zu(nzb+1) &
542                                                    * z01d ) )
543!
544!--                In the borderline case the formula for stable stratification
545!--                must be applied, because otherwise a zero division would
546!--                occur in the argument of the logarithm.
547                   IF ( a == 1.0  .OR.  b == 1.0 )  THEN
548                      us1d = kappa * uv_total / (                            &
549                             LOG( zu(nzb+1) / z01d ) +                       &
550                             5.0 * rif1d(nzb+1) * ( zu(nzb+1) - z01d ) /     &
551                                                  zu(nzb+1) )
552                   ELSE
553                      us1d = kappa * uv_total / (                              &
554                                 LOG( (1.0+b) / (1.0-b) * (1.0-a) / (1.0+a) ) +&
555                                 2.0 * ( ATAN( b ) - ATAN( a ) )               &
556                                                )
557                   ENDIF
558                ENDIF
559
560!
561!--             Compute the momentum fluxes for the diffusion terms
562                usws1d  = - u1d(nzb+1) / uv_total * us1d**2
563                vsws1d  = - v1d(nzb+1) / uv_total * us1d**2
564
565!
566!--             Boundary condition for the turbulent kinetic energy at the top
567!--             of the Prandtl-layer. c_m = 0.4 according to Detering.
568!--             Additional Neumann condition de/dz = 0 at nzb is set to ensure
569!--             compatibility with the 3D model.
570                IF ( ibc_e_b == 2 )  THEN
571                   e1d(nzb+1) = ( us1d / 0.1 )**2
572!                  e1d(nzb+1) = ( us1d / 0.4 )**2  !not used so far, see also
573                                                   !prandtl_fluxes
574                ENDIF
575                e1d(nzb) = e1d(nzb+1)
576
577                IF ( humidity .OR. passive_scalar ) THEN
578!
579!--                Compute q*
580                   IF ( rif1d(1) >= 0.0 )  THEN
581!
582!--                Stable stratification
583                   qs1d = kappa * ( q_init(nzb+1) - q_init(nzb) ) /        &
584                          ( LOG( zu(nzb+1) / z0h1d ) + 5.0 * rif1d(nzb+1) * &
585                                          ( zu(nzb+1) - z0h1d ) / zu(nzb+1) &
586                          )
587                ELSE
588!
589!--                Unstable stratification
590                   a = SQRT( 1.0 - 16.0 * rif1d(nzb+1) )
591                   b = SQRT( 1.0 - 16.0 * rif1d(nzb+1) / zu(nzb+1) * z0h1d )
592!
593!--                In the borderline case the formula for stable stratification
594!--                must be applied, because otherwise a zero division would
595!--                occur in the argument of the logarithm.
596                   IF ( a == 1.0  .OR.  b == 1.0 )  THEN
597                      qs1d = kappa * ( q_init(nzb+1) - q_init(nzb) ) /        &
598                             ( LOG( zu(nzb+1) / z0h1d ) + 5.0 * rif1d(nzb+1) * &
599                                             ( zu(nzb+1) - z0h1d ) / zu(nzb+1) &
600                             )
601                   ELSE
602                      qs1d = kappa * ( q_init(nzb+1) - q_init(nzb) ) / &
603                             LOG( (a-1.0) / (a+1.0) * (b+1.0) / (b-1.0) )
604                   ENDIF
605                ENDIF               
606                ELSE
607                   qs1d = 0.0
608                ENDIF             
609
610             ENDIF   !  prandtl_layer
611
612!
613!--          Compute the diabatic mixing length
614             IF ( mixing_length_1d == 'blackadar' )  THEN
615                DO  k = nzb+1, nzt
616                   IF ( rif1d(k) >= 0.0 )  THEN
617                      l1d(k) = l_black(k) / ( 1.0 + 5.0 * rif1d(k) )
618                   ELSE
619                      l1d(k) = l_black(k) * ( 1.0 - 16.0 * rif1d(k) )**0.25
620                   ENDIF
621                   l1d(k) = l_black(k)
622                ENDDO
623
624             ELSEIF ( mixing_length_1d == 'as_in_3d_model' )  THEN
625                DO  k = nzb+1, nzt
626                   dpt_dz = ( pt_init(k+1) - pt_init(k-1) ) * dd2zu(k)
627                   IF ( dpt_dz > 0.0 )  THEN
628                      l_stable = 0.76 * SQRT( e1d(k) ) / &
629                                     SQRT( g / pt_init(k) * dpt_dz ) + 1E-5
630                   ELSE
631                      l_stable = l_grid(k)
632                   ENDIF
633                   l1d(k) = MIN( l_grid(k), l_stable )
634                ENDDO
635             ENDIF
636
637!
638!--          Adjust mixing length to the prandtl mixing length
639             IF ( adjust_mixing_length  .AND.  prandtl_layer )  THEN
640                k = nzb+1
641                IF ( rif1d(k) >= 0.0 )  THEN
642                   l1d(k) = MIN( l1d(k), kappa * zu(k) / ( 1.0 + 5.0 * &
643                                                           rif1d(k) ) )
644                ELSE
645                   l1d(k) = MIN( l1d(k), kappa * zu(k) *          &
646                                  SQRT( SQRT( 1.0 - 16.0 * rif1d(k) ) ) )
647                ENDIF
648             ENDIF
649
650!
651!--          Compute the diffusion coefficients for momentum via the
652!--          corresponding Prandtl-layer relationship and according to
653!--          Prandtl-Kolmogorov, respectively. The unstable stratification is
654!--          computed via the adiabatic mixing length, for the unstability has
655!--          already been taken account of via the TKE (cf. also Diss.).
656             IF ( prandtl_layer )  THEN
657                IF ( rif1d(nzb+1) >= 0.0 )  THEN
658                   km1d(nzb+1) = us1d * kappa * zu(nzb+1) / &
659                                 ( 1.0 + 5.0 * rif1d(nzb+1) )
660                ELSE
661                   km1d(nzb+1) = us1d * kappa * zu(nzb+1) * &
662                                 ( 1.0 - 16.0 * rif1d(nzb+1) )**0.25
663                ENDIF
664             ENDIF
665             DO  k = nzb_diff, nzt
666!                km1d(k) = 0.4 * SQRT( e1d(k) ) !changed: adjustment to 3D-model
667                km1d(k) = 0.1 * SQRT( e1d(k) )
668                IF ( rif1d(k) >= 0.0 )  THEN
669                   km1d(k) = km1d(k) * l1d(k)
670                ELSE
671                   km1d(k) = km1d(k) * l_black(k)
672                ENDIF
673             ENDDO
674
675!
676!--          Add damping layer
677             DO  k = damp_level_ind_1d+1, nzt+1
678                km1d(k) = 1.1 * km1d(k-1)
679                km1d(k) = MIN( km1d(k), 10.0 )
680             ENDDO
681
682!
683!--          Compute the diffusion coefficient for heat via the relationship
684!--          kh = phim / phih * km
685             DO  k = nzb+1, nzt
686                IF ( rif1d(k) >= 0.0 )  THEN
687                   kh1d(k) = km1d(k)
688                ELSE
689                   kh1d(k) = km1d(k) * ( 1.0 - 16.0 * rif1d(k) )**0.25
690                ENDIF
691             ENDDO
692
693          ENDIF   ! .NOT. constant_diffusion
694
695!
696!--       The Runge-Kutta scheme needs the recent diffusion quantities
697          IF ( timestep_scheme(1:5) == 'runge' )  THEN
698             u1d_m  = u1d
699             v1d_m  = v1d
700             IF ( .NOT. constant_diffusion )  THEN
701                e1d_m  = e1d
702                kh1d_m = kh1d
703                km1d_m = km1d
704                l1d_m  = l1d
705                IF ( prandtl_layer )  THEN
706                   usws1d_m = usws1d
707                   vsws1d_m = vsws1d
708                ENDIF
709             ENDIF
710          ENDIF
711
712
713       ENDDO   ! intermediate step loop
714
715!
716!--    Increment simulated time and output times
717       current_timestep_number_1d = current_timestep_number_1d + 1
718       simulated_time_1d          = simulated_time_1d + dt_1d
719       simulated_time_chr         = time_to_string( simulated_time_1d )
720       time_pr_1d                 = time_pr_1d          + dt_1d
721       time_run_control_1d        = time_run_control_1d + dt_1d
722
723!
724!--    Determine and print out quantities for run control
725       IF ( time_run_control_1d >= dt_run_control_1d )  THEN
726          CALL run_control_1d
727          time_run_control_1d = time_run_control_1d - dt_run_control_1d
728       ENDIF
729
730!
731!--    Profile output on file
732       IF ( time_pr_1d >= dt_pr_1d )  THEN
733          CALL print_1d_model
734          time_pr_1d = time_pr_1d - dt_pr_1d
735       ENDIF
736
737!
738!--    Determine size of next time step
739       CALL timestep_1d
740
741    ENDDO   ! time loop
742
743
744 END SUBROUTINE time_integration_1d
745
746
747 SUBROUTINE run_control_1d
748
749!------------------------------------------------------------------------------!
750! Description:
751! ------------
752! Compute and print out quantities for run control of the 1D model.
753!------------------------------------------------------------------------------!
754
755    USE constants
756    USE indices
757    USE model_1d
758    USE pegrid
759    USE control_parameters
760
761    IMPLICIT NONE
762
763    INTEGER ::  k
764    REAL    ::  alpha, energy, umax, uv_total, vmax
765
766!
767!-- Output
768    IF ( myid == 0 )  THEN
769!
770!--    If necessary, write header
771       IF ( .NOT. run_control_header_1d )  THEN
772          CALL check_open( 15 )
773          WRITE ( 15, 100 )
774          run_control_header_1d = .TRUE.
775       ENDIF
776
777!
778!--    Compute control quantities
779!--    grid level nzp is excluded due to mirror boundary condition
780       umax = 0.0; vmax = 0.0; energy = 0.0
781       DO  k = nzb+1, nzt+1
782          umax = MAX( ABS( umax ), ABS( u1d(k) ) )
783          vmax = MAX( ABS( vmax ), ABS( v1d(k) ) )
784          energy = energy + 0.5 * ( u1d(k)**2 + v1d(k)**2 )
785       ENDDO
786       energy = energy / REAL( nzt - nzb + 1 )
787
788       uv_total = SQRT( u1d(nzb+1)**2 + v1d(nzb+1)**2 )
789       IF ( ABS( v1d(nzb+1) ) .LT. 1.0E-5 )  THEN
790          alpha = ACOS( SIGN( 1.0 , u1d(nzb+1) ) )
791       ELSE
792          alpha = ACOS( u1d(nzb+1) / uv_total )
793          IF ( v1d(nzb+1) <= 0.0 )  alpha = 2.0 * pi - alpha
794       ENDIF
795       alpha = alpha / ( 2.0 * pi ) * 360.0
796
797       WRITE ( 15, 101 )  current_timestep_number_1d, simulated_time_chr, &
798                          dt_1d, umax, vmax, us1d, alpha, energy
799!
800!--    Write buffer contents to disc immediately
801       CALL local_flush( 15 )
802
803    ENDIF
804
805!
806!-- formats
807100 FORMAT (///'1D-Zeitschrittkontrollausgaben:'/ &
808              &'------------------------------'// &
809           &'ITER.  HH:MM:SS    DT      UMAX   VMAX    U*   ALPHA   ENERG.'/ &
810           &'-------------------------------------------------------------')
811101 FORMAT (I5,2X,A9,1X,F6.2,2X,F6.2,1X,F6.2,2X,F5.3,2X,F5.1,2X,F7.2)
812
813
814 END SUBROUTINE run_control_1d
815
816
817
818 SUBROUTINE timestep_1d
819
820!------------------------------------------------------------------------------!
821! Description:
822! ------------
823! Compute the time step w.r.t. the diffusion criterion
824!------------------------------------------------------------------------------!
825
826    USE arrays_3d
827    USE indices
828    USE model_1d
829    USE pegrid
830    USE control_parameters
831
832    IMPLICIT NONE
833
834    INTEGER ::  k
835    REAL    ::  div, dt_diff, fac, percent_change, value
836
837
838!
839!-- Compute the currently feasible time step according to the diffusion
840!-- criterion. At nzb+1 the half grid length is used.
841    IF ( timestep_scheme(1:4) == 'leap' )  THEN
842       fac = 0.25
843    ELSE
844       fac = 0.35
845    ENDIF
846    dt_diff = dt_max_1d
847    DO  k = nzb+2, nzt
848       value   = fac * dzu(k) * dzu(k) / ( km1d(k) + 1E-20 )
849       dt_diff = MIN( value, dt_diff )
850    ENDDO
851    value   = fac * zu(nzb+1) * zu(nzb+1) / ( km1d(nzb+1) + 1E-20 )
852    dt_1d = MIN( value, dt_diff )
853
854!
855!-- Set flag when the time step becomes too small
856    IF ( dt_1d < ( 0.00001 * dt_max_1d ) )  THEN
857       stop_dt_1d = .TRUE.
858
859       WRITE( message_string, * ) 'timestep has exceeded the lower limit &', &
860                                  'dt_1d = ',dt_1d,' s   simulation stopped!'
861       CALL message( 'timestep_1d', 'PA0192', 1, 2, 0, 6, 0 )
862       
863    ENDIF
864
865    IF ( timestep_scheme(1:4) == 'leap' )  THEN
866
867!
868!--    The current time step will only be changed if the new time step exceeds
869!--    its previous value by 5 % or falls 2 % below. After a time step
870!--    reduction at least 30 iterations must be done with this value before a
871!--    new reduction will be allowed again.
872!--    The control parameters for application of Euler- or leap-frog schemes are
873!--    set accordingly.
874       percent_change = dt_1d / old_dt_1d - 1.0
875       IF ( percent_change > 0.05  .OR.  percent_change < -0.02 )  THEN
876
877!
878!--       Each time step increase is by at most 2 %
879          IF ( percent_change > 0.0  .AND.  simulated_time_1d /= 0.0 )  THEN
880             dt_1d = 1.02 * old_dt_1d
881          ENDIF
882
883!
884!--       A more or less simple new time step value is obtained taking only the
885!--       first two significant digits
886          div = 1000.0
887          DO  WHILE ( dt_1d < div )
888             div = div / 10.0
889          ENDDO
890          dt_1d = NINT( dt_1d * 100.0 / div ) * div / 100.0
891
892!
893!--       Now the time step can be changed.
894          IF ( percent_change < 0.0 )  THEN
895!
896!--          Time step reduction
897             old_dt_1d = dt_1d
898             last_dt_change_1d = current_timestep_number_1d
899          ELSE
900!
901!--          Time step will only be increased if at least 30 iterations have
902!--          been done since the previous time step change, and of course at
903!--          simulation start, respectively.
904             IF ( current_timestep_number_1d >= last_dt_change_1d + 30  .OR. &
905                     simulated_time_1d == 0.0 )  THEN
906                old_dt_1d = dt_1d
907                last_dt_change_1d = current_timestep_number_1d
908             ELSE
909                dt_1d = old_dt_1d
910             ENDIF
911          ENDIF
912       ELSE
913!
914!--       No time step change since the difference is too small
915          dt_1d = old_dt_1d
916       ENDIF
917
918    ELSE    ! Runge-Kutta
919
920!--    A more or less simple new time step value is obtained taking only the
921!--    first two significant digits
922       div = 1000.0
923       DO  WHILE ( dt_1d < div )
924          div = div / 10.0
925       ENDDO
926       dt_1d = NINT( dt_1d * 100.0 / div ) * div / 100.0
927
928       old_dt_1d = dt_1d
929       last_dt_change_1d = current_timestep_number_1d
930
931    ENDIF
932
933 END SUBROUTINE timestep_1d
934
935
936
937 SUBROUTINE print_1d_model
938
939!------------------------------------------------------------------------------!
940! Description:
941! ------------
942! List output of profiles from the 1D-model
943!------------------------------------------------------------------------------!
944
945    USE arrays_3d
946    USE indices
947    USE model_1d
948    USE pegrid
949    USE control_parameters
950
951    IMPLICIT NONE
952
953
954    INTEGER ::  k
955
956
957    IF ( myid == 0 )  THEN
958!
959!--    Open list output file for profiles from the 1D-model
960       CALL check_open( 17 )
961
962!
963!--    Write Header
964       WRITE ( 17, 100 )  TRIM( run_description_header ), &
965                          TRIM( simulated_time_chr )
966       WRITE ( 17, 101 )
967
968!
969!--    Write the values
970       WRITE ( 17, 102 )
971       WRITE ( 17, 101 )
972       DO  k = nzt+1, nzb, -1
973          WRITE ( 17, 103)  k, zu(k), u1d(k), v1d(k), pt_init(k), e1d(k), &
974                            rif1d(k), km1d(k), kh1d(k), l1d(k), zu(k), k
975       ENDDO
976       WRITE ( 17, 101 )
977       WRITE ( 17, 102 )
978       WRITE ( 17, 101 )
979
980!
981!--    Write buffer contents to disc immediately
982       CALL local_flush( 17 )
983
984    ENDIF
985
986!
987!-- Formats
988100 FORMAT (//1X,A/1X,10('-')/' 1d-model profiles'/ &
989            ' Time: ',A)
990101 FORMAT (1X,79('-'))
991102 FORMAT ('   k     zu      u      v     pt      e    rif    Km    Kh     ', &
992            'l      zu      k')
993103 FORMAT (1X,I4,1X,F7.1,1X,F6.2,1X,F6.2,1X,F6.2,1X,F6.2,1X,F5.2,1X,F5.2, &
994            1X,F5.2,1X,F6.2,1X,F7.1,2X,I4)
995
996
997 END SUBROUTINE print_1d_model
Note: See TracBrowser for help on using the repository browser.