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

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

Add possibility to output surface data during spinup

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