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

Last change on this file since 2331 was 2299, checked in by maronga, 7 years ago

improvements for spinup mechanism

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