source: palm/trunk/SOURCE/time_integration_spinup.f90 @ 3019

Last change on this file since 3019 was 2983, checked in by suehring, 6 years ago

Revise limitation of wall-adjacent velocity in spinup

  • Property svn:keywords set to Id
File size: 22.0 KB
Line 
1!> @file time_integration_spinup.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
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-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration_spinup.f90 2983 2018-04-18 10:43:40Z maronga $
27! Revise limitation of wall-adjacent velocity.
28!
29! 2934 2018-03-26 19:13:22Z suehring
30! Synchronize parent and child models after spinup.
31!
32! 2881 2018-03-13 16:24:40Z maronga
33! Added flag for switching on/off calculation of soil moisture
34!
35! 2818 2018-02-19 16:42:36Z maronga
36! Velocity components near walls/ground are now set to the profiles stored in
37! u_init and v_init. Activated soil moisture calculation during spinup.
38!
39! 2782 2018-02-02 11:51:10Z maronga
40! Bugfix and re-activation of homogeneous setting of velocity components
41! during spinup
42!
43! 2758 2018-01-17 12:55:21Z suehring
44! Comment out homogeneous setting of wind velocity as this will lead to zero
45! friction velocity and cause problems in MOST relationships.
46!
47! 2728 2018-01-09 07:03:53Z maronga
48! Set velocity componenets to homogeneous values during spinup
49!
50! 2724 2018-01-05 12:12:38Z maronga
51! Use dt_spinup for all active components during spinup
52!
53! 2723 2018-01-05 09:27:03Z maronga
54! Bugfix: array rad_sw_in no longer exists and is thus removed from RUN_CONTROL
55! output.
56! Added output of XY and 3D data during spinup.
57! Bugfix: time step in LSM and USM was set to dt_3d instead of dt_spinup
58!
59! 2718 2018-01-02 08:49:38Z maronga
60! Corrected "Former revisions" section
61!
62! 2696 2017-12-14 17:12:51Z kanani
63! Change in file header (GPL part)
64! Added radiation interactions (moved from USM) (MS)
65!
66! 2544 2017-10-13 18:09:32Z maronga
67! Date and time quantities are now read from date_and_time_mod
68!
69! 2299 2017-06-29 10:14:38Z maronga
70! Call of soil model adjusted to avoid prognostic equation for soil moisture
71! during spinup.
72! Better representation of diurnal cycle of near-surface temperature.
73! Excluded prognostic equation for soil moisture during spinup.
74! Added output of run control data for spinup.
75!
76! 2297 2017-06-28 14:35:57Z scharf
77! bugfixes
78!
79! 2296 2017-06-28 07:53:56Z maronga
80! Initial revision
81!
82!
83! Description:
84! ------------
85!> Integration in time of the non-atmospheric model components such as land
86!> surface model and urban surface model
87!------------------------------------------------------------------------------!
88 SUBROUTINE time_integration_spinup
89 
90    USE arrays_3d,                                                             &
91        ONLY:  pt, pt_p, u, u_init, v, v_init
92
93    USE control_parameters,                                                    &
94        ONLY:  averaging_interval_pr, calc_soil_moisture_during_spinup,        &
95               constant_diffusion, constant_flux_layer,                        &
96               coupling_start_time, current_timestep_number,                   &
97               data_output_during_spinup, disturbance_created, dopr_n, do_sum, &
98               dt_averaging_input_pr, dt_dopr, dt_dots, dt_do2d_xy, dt_do3d,   &
99               dt_run_control, dt_spinup, dt_3d, humidity,                     &
100               intermediate_timestep_count,                                    &
101               intermediate_timestep_count_max, land_surface,                  &
102               simulated_time, simulated_time_chr,                             &
103               skip_time_dopr, skip_time_do2d_xy, skip_time_do3d, spinup,      &
104               spinup_pt_amplitude, spinup_pt_mean, spinup_time,               &
105               timestep_count, timestep_scheme, time_dopr, time_dopr_av,       &
106               time_dots, time_do2d_xy, time_do3d, time_run_control,           &
107               time_since_reference_point, ug_surface, vg_surface, urban_surface
108
109    USE constants,                                                             &
110        ONLY:  pi
111
112    USE cpulog,                                                                &
113        ONLY:  cpu_log, log_point, log_point_s
114
115    USE date_and_time_mod,                                                     &
116        ONLY: day_of_year_init, time_utc_init
117
118    USE indices,                                                               &
119        ONLY:  nbgp, nzb, nzt, nysg, nyng, nxlg, nxrg
120
121
122    USE land_surface_model_mod,                                                &
123        ONLY:  lsm_energy_balance, lsm_soil_model, lsm_swap_timelevel
124
125    USE pegrid
126
127    USE pmc_interface,                                                         &
128        ONLY:  nested_run
129
130    USE kinds
131
132    USE radiation_model_mod,                                                   &
133        ONLY:  force_radiation_call, radiation,                                &
134               radiation_control, rad_sw_in, time_radiation,                   &
135               radiation_interaction, radiation_interactions
136
137    USE statistics,                                                            &
138        ONLY:  flow_statistics_called
139
140    USE surface_layer_fluxes_mod,                                              &
141        ONLY:  surface_layer_fluxes
142
143    USE surface_mod,                                                           &
144        ONLY :  surf_def_h, surf_def_v, surf_lsm_h, surf_lsm_v, surf_usm_h,    &
145                surf_usm_v
146
147    USE urban_surface_mod,                                                     &
148        ONLY:  usm_material_heat_model, usm_material_model,                    &
149               usm_surface_energy_balance, usm_swap_timelevel,                 &
150               usm_green_heat_model, usm_temperature_near_surface
151
152
153
154
155    IMPLICIT NONE
156
157    CHARACTER (LEN=9) ::  time_to_string          !<
158 
159    INTEGER(iwp) ::  i !< running index
160    INTEGER(iwp) ::  j !< running index
161    INTEGER(iwp) ::  k !< running index
162    INTEGER(iwp) ::  l !< running index
163    INTEGER(iwp) ::  m !< running index
164
165    INTEGER(iwp) :: current_timestep_number_spinup = 0  !< number if timestep during spinup
166 
167    LOGICAL :: run_control_header_spinup = .FALSE.  !< flag parameter for steering whether the header information must be output
168
169    REAL(wp) ::  pt_spinup   !< temporary storage of temperature
170    REAL(wp) ::  dt_save     !< temporary storage for time step
171                 
172    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_save  !< temporary storage of temperature
173    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_save   !< temporary storage of u wind component
174    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_save   !< temporary storage of v wind component
175
176
177!
178!-- Save 3D arrays because they are to be changed for spinup purpose
179    ALLOCATE( pt_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
180    ALLOCATE( u_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
181    ALLOCATE( v_save(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
182
183    CALL exchange_horiz( pt, nbgp )   
184    CALL exchange_horiz( u,  nbgp ) 
185    CALL exchange_horiz( v,  nbgp ) 
186 
187    pt_save = pt
188    u_save  = u
189    v_save  = v
190
191!
192!-- Set the same wall-adjacent velocity to all grid points. The sign of the
193!-- original velocity field must be preserved because the surface schemes crash
194!-- otherwise. The precise reason is still unknown. A minimum velocity of 0.1
195!-- m/s is used to maintain turbulent transfer at the surface.
196    IF ( land_surface )  THEN
197       DO  m = 1, surf_lsm_h%ns
198          i   = surf_lsm_h%i(m)           
199          j   = surf_lsm_h%j(m)
200          k   = surf_lsm_h%k(m)
201          u(k,j,i) = SIGN(1.0_wp,u_init(k)) * MAX( ABS( u_init(k) ),0.1_wp)
202          v(k,j,i) = SIGN(1.0_wp,v_init(k)) * MAX( ABS( v_init(k) ),0.1_wp)
203       ENDDO
204
205       DO  l = 0, 3
206          DO  m = 1, surf_lsm_v(l)%ns
207             i   = surf_lsm_v(l)%i(m)           
208             j   = surf_lsm_v(l)%j(m)
209             k   = surf_lsm_v(l)%k(m)
210             u(k,j,i) = SIGN(1.0_wp,u_init(k)) * MAX( ABS( u_init(k) ),0.1_wp)
211             v(k,j,i) = SIGN(1.0_wp,v_init(k)) * MAX( ABS( v_init(k) ),0.1_wp)
212          ENDDO
213       ENDDO
214    ENDIF
215
216    IF ( urban_surface )  THEN
217       DO  m = 1, surf_usm_h%ns
218          i   = surf_usm_h%i(m)           
219          j   = surf_usm_h%j(m)
220          k   = surf_usm_h%k(m)
221          u(k,j,i) = SIGN(1.0_wp,u_init(k)) * MAX( ABS( u_init(k) ),0.1_wp)
222          v(k,j,i) = SIGN(1.0_wp,v_init(k)) * MAX( ABS( v_init(k) ),0.1_wp)
223       ENDDO
224
225       DO  l = 0, 3
226          DO  m = 1, surf_usm_v(l)%ns
227             i   = surf_usm_v(l)%i(m)           
228             j   = surf_usm_v(l)%j(m)
229             k   = surf_usm_v(l)%k(m)
230             u(k,j,i) = SIGN(1.0_wp,u_init(k)) * MAX( ABS( u_init(k) ),0.1_wp)
231             v(k,j,i) = SIGN(1.0_wp,v_init(k)) * MAX( ABS( v_init(k) ),0.1_wp)
232          ENDDO
233       ENDDO
234    ENDIF
235
236    CALL exchange_horiz( u,  nbgp )
237    CALL exchange_horiz( v,  nbgp )
238
239    dt_save = dt_3d
240    dt_3d   = dt_spinup
241
242    CALL location_message( 'starting spinup-sequence', .TRUE. )
243!
244!-- Start of the time loop
245    DO  WHILE ( simulated_time < spinup_time )
246
247       CALL cpu_log( log_point_s(15), 'timesteps spinup', 'start' )
248   
249!
250!--    Start of intermediate step loop
251       intermediate_timestep_count = 0
252       DO  WHILE ( intermediate_timestep_count < &
253                   intermediate_timestep_count_max )
254
255          intermediate_timestep_count = intermediate_timestep_count + 1
256
257!
258!--       Set the steering factors for the prognostic equations which depend
259!--       on the timestep scheme
260          CALL timestep_scheme_steering
261
262
263!
264!--       Estimate a near-surface air temperature based on the position of the
265!--       sun and user input about mean temperature and amplitude. The time is
266!--       shifted by one hour to simulate a lag between air temperature and
267!--       incoming radiation
268          pt_spinup = spinup_pt_mean + spinup_pt_amplitude                     &
269             * solar_angle (time_utc_init + time_since_reference_point - 3600.0)
270
271!
272!--       Map air temperature to all grid points in the vicinity of a surface
273!--       element
274          IF ( land_surface )  THEN
275             DO  m = 1, surf_lsm_h%ns
276                i   = surf_lsm_h%i(m)           
277                j   = surf_lsm_h%j(m)
278                k   = surf_lsm_h%k(m)
279                pt(k,j,i) = pt_spinup
280             ENDDO
281
282             DO  l = 0, 3
283                DO  m = 1, surf_lsm_v(l)%ns
284                   i   = surf_lsm_v(l)%i(m)           
285                   j   = surf_lsm_v(l)%j(m)
286                   k   = surf_lsm_v(l)%k(m)
287                   pt(k,j,i) = pt_spinup
288                ENDDO
289             ENDDO
290          ENDIF
291
292          IF ( urban_surface )  THEN
293             DO  m = 1, surf_usm_h%ns
294                i   = surf_usm_h%i(m)           
295                j   = surf_usm_h%j(m)
296                k   = surf_usm_h%k(m)
297                pt(k,j,i) = pt_spinup
298             ENDDO
299
300             DO  l = 0, 3
301                DO  m = 1, surf_usm_v(l)%ns
302                   i   = surf_usm_v(l)%i(m)           
303                   j   = surf_usm_v(l)%j(m)
304                   k   = surf_usm_v(l)%k(m)
305                   pt(k,j,i) = pt_spinup
306                ENDDO
307             ENDDO
308          ENDIF
309
310          CALL exchange_horiz( pt,  nbgp )   
311
312
313!
314!--       Swap the time levels in preparation for the next time step.
315          timestep_count = timestep_count + 1
316     
317          IF ( land_surface )  THEN
318              CALL lsm_swap_timelevel ( 0 )
319          ENDIF
320
321          IF ( urban_surface )  THEN
322             CALL usm_swap_timelevel ( 0 )
323          ENDIF
324
325          IF ( land_surface )  THEN
326             CALL lsm_swap_timelevel ( MOD( timestep_count, 2) )
327          ENDIF
328
329          IF ( urban_surface )  THEN
330             CALL usm_swap_timelevel ( MOD( timestep_count, 2) )
331          ENDIF
332         
333!
334!--       If required, compute virtual potential temperature
335          IF ( humidity )  THEN
336             CALL compute_vpt 
337          ENDIF 
338
339!
340!--       Compute the diffusion quantities
341          IF ( .NOT. constant_diffusion )  THEN
342
343!
344!--          First the vertical (and horizontal) fluxes in the surface
345!--          (constant flux) layer are computed
346             IF ( constant_flux_layer )  THEN
347                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'start' )
348                CALL surface_layer_fluxes
349                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'stop' )
350             ENDIF
351
352!
353!--          If required, solve the energy balance for the surface and run soil
354!--          model. Call for horizontal as well as vertical surfaces.
355!--          The prognostic equation for soil moisure is switched off
356             IF ( land_surface )  THEN
357
358                CALL cpu_log( log_point(54), 'land_surface', 'start' )
359!
360!--             Call for horizontal upward-facing surfaces
361                CALL lsm_energy_balance( .TRUE., -1 )
362                CALL lsm_soil_model( .TRUE., -1, calc_soil_moisture_during_spinup )
363!
364!--             Call for northward-facing surfaces
365                CALL lsm_energy_balance( .FALSE., 0 )
366                CALL lsm_soil_model( .FALSE., 0, calc_soil_moisture_during_spinup )
367!
368!--             Call for southward-facing surfaces
369                CALL lsm_energy_balance( .FALSE., 1 )
370                CALL lsm_soil_model( .FALSE., 1, calc_soil_moisture_during_spinup )
371!
372!--             Call for eastward-facing surfaces
373                CALL lsm_energy_balance( .FALSE., 2 )
374                CALL lsm_soil_model( .FALSE., 2, calc_soil_moisture_during_spinup )
375!
376!--             Call for westward-facing surfaces
377                CALL lsm_energy_balance( .FALSE., 3 )
378                CALL lsm_soil_model( .FALSE., 3, calc_soil_moisture_during_spinup )
379
380                CALL cpu_log( log_point(54), 'land_surface', 'stop' )
381             ENDIF
382
383!
384!--          If required, solve the energy balance for urban surfaces and run
385!--          the material heat model
386             IF (urban_surface) THEN
387                CALL cpu_log( log_point(74), 'urban_surface', 'start' )
388                CALL usm_surface_energy_balance
389                IF ( usm_material_model )  THEN
390                   CALL usm_green_heat_model
391                   CALL usm_material_heat_model
392                ENDIF
393                IF ( urban_surface ) THEN
394                   CALL usm_temperature_near_surface
395                ENDIF
396                CALL cpu_log( log_point(74), 'urban_surface', 'stop' )
397             ENDIF
398
399          ENDIF
400
401!
402!--       If required, calculate radiative fluxes and heating rates
403          IF ( radiation .AND. intermediate_timestep_count                     &
404               == intermediate_timestep_count_max )  THEN
405
406               time_radiation = time_radiation + dt_3d
407
408             IF ( time_radiation >= dt_3d .OR. force_radiation_call )          &
409             THEN
410
411                CALL cpu_log( log_point(50), 'radiation', 'start' )
412
413                IF ( .NOT. force_radiation_call )  THEN
414                   time_radiation = time_radiation - dt_3d
415                ENDIF
416
417                CALL radiation_control
418
419                CALL cpu_log( log_point(50), 'radiation', 'stop' )
420
421                IF ( radiation_interactions )  THEN
422                   CALL cpu_log( log_point(75), 'radiation_interaction', 'start' )
423                   CALL radiation_interaction
424                   CALL cpu_log( log_point(75), 'radiation_interaction', 'stop' )
425                ENDIF
426             ENDIF
427          ENDIF
428
429       ENDDO   ! Intermediate step loop
430
431!
432!--    Increase simulation time and output times
433       current_timestep_number_spinup = current_timestep_number_spinup + 1
434       simulated_time             = simulated_time   + dt_3d
435       simulated_time_chr         = time_to_string( simulated_time )
436       time_since_reference_point = simulated_time - coupling_start_time
437
438       IF ( data_output_during_spinup )  THEN
439          IF ( simulated_time >= skip_time_do2d_xy )  THEN
440             time_do2d_xy       = time_do2d_xy     + dt_3d
441          ENDIF
442          IF ( simulated_time >= skip_time_do3d    )  THEN
443             time_do3d          = time_do3d        + dt_3d
444          ENDIF
445          time_dots          = time_dots        + dt_3d
446          IF ( simulated_time >= skip_time_dopr )  THEN
447             time_dopr       = time_dopr        + dt_3d
448          ENDIF
449          time_run_control   = time_run_control + dt_3d
450
451!
452!--       Carry out statistical analysis and output at the requested output times.
453!--       The MOD function is used for calculating the output time counters (like
454!--       time_dopr) in order to regard a possible decrease of the output time
455!--       interval in case of restart runs
456
457!
458!--       Set a flag indicating that so far no statistics have been created
459!--       for this time step
460          flow_statistics_called = .FALSE.
461
462!
463!--       If required, call flow_statistics for averaging in time
464          IF ( averaging_interval_pr /= 0.0_wp  .AND.                          &
465             ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.           &
466             simulated_time >= skip_time_dopr )  THEN
467             time_dopr_av = time_dopr_av + dt_3d
468             IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
469                do_sum = .TRUE.
470                time_dopr_av = MOD( time_dopr_av,                              &
471                               MAX( dt_averaging_input_pr, dt_3d ) )
472             ENDIF
473          ENDIF
474          IF ( do_sum )  CALL flow_statistics
475
476!
477!--       Output of profiles
478          IF ( time_dopr >= dt_dopr )  THEN
479             IF ( dopr_n /= 0 )  CALL data_output_profiles
480             time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
481             time_dopr_av = 0.0_wp    ! due to averaging (see above)
482          ENDIF
483
484!
485!--       Output of time series
486          IF ( time_dots >= dt_dots )  THEN
487             CALL data_output_tseries
488             time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
489          ENDIF
490
491!
492!--       2d-data output (cross-sections)
493          IF ( time_do2d_xy >= dt_do2d_xy )  THEN
494             CALL data_output_2d( 'xy', 0 )
495             time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
496          ENDIF
497
498!
499!--       3d-data output (volume data)
500          IF ( time_do3d >= dt_do3d )  THEN
501             CALL data_output_3d( 0 )
502             time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
503          ENDIF
504
505
506       ENDIF
507
508!
509!--    Computation and output of run control parameters.
510!--    This is also done whenever perturbations have been imposed
511!        IF ( time_run_control >= dt_run_control  .OR.                           &
512!             timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created )       &
513!        THEN
514!           CALL run_control
515!           IF ( time_run_control >= dt_run_control )  THEN
516!              time_run_control = MOD( time_run_control,                         &
517!                                      MAX( dt_run_control, dt_3d ) )
518!           ENDIF
519!        ENDIF
520
521       CALL cpu_log( log_point_s(15), 'timesteps spinup', 'stop' )
522
523
524!
525!--    Run control output
526       IF ( myid == 0 )  THEN
527!
528!--       If necessary, write header
529          IF ( .NOT. run_control_header_spinup )  THEN
530             CALL check_open( 15 )
531             WRITE ( 15, 100 )
532             run_control_header_spinup = .TRUE.
533          ENDIF
534!
535!--       Write some general information about the spinup in run control file
536          WRITE ( 15, 101 )  current_timestep_number_spinup, simulated_time_chr, dt_3d, pt_spinup
537!
538!--       Write buffer contents to disc immediately
539          FLUSH( 15 )
540       ENDIF
541
542
543
544    ENDDO   ! time loop
545
546!
547!-- Write back saved arrays to the 3D arrays
548    pt   = pt_save
549    pt_p = pt_save
550    u    = u_save
551    v    = v_save
552
553!
554!-- Reset time step
555    dt_3d = dt_save
556
557    DEALLOCATE(pt_save)
558    DEALLOCATE(u_save)
559    DEALLOCATE(v_save)
560
561#if defined( __parallel )
562    IF ( nested_run )  CALL MPI_BARRIER( MPI_COMM_WORLD, ierr )
563#endif
564
565    CALL location_message( 'finished spinup-sequence', .TRUE. )
566
567
568!
569!-- Formats
570100 FORMAT (///'Spinup control output:'/  &
571            '--------------------------------'// &
572            'ITER.  HH:MM:SS    DT   PT(z_MO)'/   &
573            '--------------------------------')
574101 FORMAT (I5,2X,A9,1X,F6.2,3X,F6.2,2X,F6.2)
575
576 CONTAINS
577
578!
579!-- Returns the cosine of the solar zenith angle at a given time. This routine
580!-- is similar to that for calculation zenith (see radiation_model_mod.f90)
581    FUNCTION solar_angle( local_time ) 
582
583       USE constants,                                                          &
584       ONLY:  pi
585     
586       USE kinds
587
588       USE radiation_model_mod,                                                &
589           ONLY:  decl_1, decl_2, decl_3, lat, lon
590
591       IMPLICIT NONE
592
593
594       REAL(wp) ::  solar_angle     !< cosine of the solar zenith angle
595
596       REAL(wp) ::  day             !< day of the year
597       REAL(wp) ::  declination     !< solar declination angle
598       REAL(wp) ::  hour_angle      !< solar hour angle
599       REAL(wp) ::  time_utc        !< current time in UTC
600       REAL(wp), INTENT(IN) :: local_time
601!
602!--    Calculate current day and time based on the initial values and simulation
603!--    time
604
605       day = day_of_year_init + INT(FLOOR( local_time / 86400.0_wp ), KIND=iwp)
606       time_utc = MOD(local_time, 86400.0_wp)
607
608
609!
610!--    Calculate solar declination and hour angle   
611       declination = ASIN( decl_1 * SIN(decl_2 * REAL(day, KIND=wp) - decl_3) )
612       hour_angle  = 2.0_wp * pi * (time_utc / 86400.0_wp) + lon - pi
613
614!
615!--    Calculate cosine of solar zenith angle
616       solar_angle = SIN(lat) * SIN(declination) + COS(lat) * COS(declination) &
617                     * COS(hour_angle)
618
619
620    END FUNCTION solar_angle
621
622
623 END SUBROUTINE time_integration_spinup
Note: See TracBrowser for help on using the repository browser.