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

Last change on this file since 2726 was 2724, checked in by maronga, 6 years ago

some changes in spinup mechanism and additional check in land surface model

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