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

Last change on this file since 4669 was 4669, checked in by pavelkrc, 4 years ago

Fix multiple issues with radiation call times

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