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

Last change on this file since 4456 was 4444, checked in by raasch, 4 years ago

bugfix: cpp-directives for serial mode added

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