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

Last change on this file since 2334 was 2334, checked in by gronemeier, 7 years ago

set c_m to 0.4 within 1D model

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