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

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

bugfixes for spinup mechanism to work with lsm+usm+radiation

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