source: palm/trunk/SOURCE/time_integration.f90 @ 1318

Last change on this file since 1318 was 1318, checked in by raasch, 8 years ago

former files/routines cpu_log and cpu_statistics combined to one module,
which also includes the former data module cpulog from the modules-file,
module interfaces removed

  • Property svn:keywords set to Id
File size: 33.3 KB
Line 
1 SUBROUTINE time_integration
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! module interfaces removed
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 1318 2014-03-17 13:35:16Z raasch $
27!
28! 1308 2014-03-13 14:58:42Z fricke
29! +netcdf_data_format_save
30! For masked data, parallel netcdf output is not tested so far, hence
31! netcdf_data_format is switched back to non-paralell output.
32!
33! 1276 2014-01-15 13:40:41Z heinze
34! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
35!
36! 1257 2013-11-08 15:18:40Z raasch
37! acc-update-host directive for timestep removed
38!
39! 1241 2013-10-30 11:36:58Z heinze
40! Generalize calc_mean_profile for wider use
41! Determine shf and qsws in dependence on data from LSF_DATA
42! Determine ug and vg in dependence on data from LSF_DATA
43! 1221 2013-09-10 08:59:13Z raasch
44! host update of arrays before timestep is called
45!
46! 1179 2013-06-14 05:57:58Z raasch
47! mean profiles for reference state are only calculated if required,
48! small bugfix for background communication
49!
50! 1171 2013-05-30 11:27:45Z raasch
51! split of prognostic_equations deactivated (comment lines), for the time being
52!
53! 1128 2013-04-12 06:19:32Z raasch
54! asynchronous transfer of ghost point data realized for acc-optimized version:
55! prognostic_equations are first called two times for those points required for
56! the left-right and north-south exchange, respectively, and then for the
57! remaining points,
58! those parts requiring global communication moved from prognostic_equations to
59! here
60!
61! 1115 2013-03-26 18:16:16Z hoffmann
62! calculation of qr and nr is restricted to precipitation
63!
64! 1113 2013-03-10 02:48:14Z raasch
65! GPU-porting of boundary conditions,
66! openACC directives updated
67! formal parameter removed from routine boundary_conds
68!
69! 1111 2013-03-08 23:54:10Z raasch
70! +internal timestep counter for cpu statistics added,
71! openACC directives updated
72!
73! 1092 2013-02-02 11:24:22Z raasch
74! unused variables removed
75!
76! 1065 2012-11-22 17:42:36Z hoffmann
77! exchange of diss (dissipation rate) in case of turbulence = .TRUE. added
78!
79! 1053 2012-11-13 17:11:03Z hoffmann
80! exchange of ghost points for nr, qr added
81!
82! 1036 2012-10-22 13:43:42Z raasch
83! code put under GPL (PALM 3.9)
84!
85! 1019 2012-09-28 06:46:45Z raasch
86! non-optimized version of prognostic_equations removed
87!
88! 1015 2012-09-27 09:23:24Z raasch
89! +call of prognostic_equations_acc
90!
91! 1001 2012-09-13 14:08:46Z raasch
92! all actions concerning leapfrog- and upstream-spline-scheme removed
93!
94! 849 2012-03-15 10:35:09Z raasch
95! advec_particles renamed lpm, first_call_advec_particles renamed first_call_lpm
96!
97! 825 2012-02-19 03:03:44Z raasch
98! wang_collision_kernel renamed wang_kernel
99!
100! 790 2011-11-29 03:11:20Z raasch
101! exchange of ghostpoints for array diss
102!
103! 707 2011-03-29 11:39:40Z raasch
104! bc_lr/ns replaced by bc_lr/ns_cyc, calls of exchange_horiz are modified,
105! adaption to sloping surface
106!
107! 667  2010-12-23 12:06:00Z suehring/gryschka
108! Calls of exchange_horiz are modified.
109! Adaption to slooping surface.
110!
111! 449 2010-02-02 11:23:59Z raasch
112! Bugfix: exchange of ghost points for prho included
113!
114! 410 2009-12-04 17:05:40Z letzel
115! masked data output
116!
117! 388 2009-09-23 09:40:33Z raasch
118! Using prho instead of rho in diffusvities.
119! Coupling with independent precursor runs.
120! Bugfix: output of particle time series only if particle advection is switched
121!         on
122!
123! 151 2008-03-07 13:42:18Z raasch
124! inflow turbulence is imposed by calling new routine inflow_turbulence
125!
126! 108 2007-08-24 15:10:38Z letzel
127! Call of new routine surface_coupler,
128! presure solver is called after the first Runge-Kutta substep instead of the
129! last in case that call_psolver_at_all_substeps = .F.; for this case, the
130! random perturbation has to be added to the velocity fields also after the
131! first substep
132!
133! 97 2007-06-21 08:23:15Z raasch
134! diffusivities is called with argument rho in case of ocean runs,
135! new argument pt_/prho_reference in calls of diffusivities,
136! ghostpoint exchange for salinity and density
137!
138! 87 2007-05-22 15:46:47Z raasch
139! var_hom renamed pr_palm
140!
141! 75 2007-03-22 09:54:05Z raasch
142! Move call of user_actions( 'after_integration' ) below increment of times
143! and counters,
144! calls of prognostic_equations_.. changed to .._noopt, .._cache, and
145! .._vector, these calls are now controlled by switch loop_optimization,
146! uxrp, vynp eliminated, 2nd+3rd argument removed from exchange horiz,
147! moisture renamed humidity
148!
149! RCS Log replace by Id keyword, revision history cleaned up
150!
151! Revision 1.8  2006/08/22 14:16:05  raasch
152! Disturbances are imposed only for the last Runge-Kutta-substep
153!
154! Revision 1.2  2004/04/30 13:03:40  raasch
155! decalpha-specific warning removed, routine name changed to time_integration,
156! particle advection is carried out only once during the intermediate steps,
157! impulse_advec renamed momentum_advec
158!
159! Revision 1.1  1997/08/11 06:19:04  raasch
160! Initial revision
161!
162!
163! Description:
164! ------------
165! Integration in time of the model equations, statistical analysis and graphic
166! output
167!------------------------------------------------------------------------------!
168
169    USE advec_ws
170    USE arrays_3d
171    USE averaging
172    USE buoyancy_mod
173    USE control_parameters
174    USE cpulog
175#if defined( __dvrp_graphics )
176    USE DVRP
177#endif
178    USE grid_variables
179    USE indices
180    USE interaction_droplets_ptq_mod
181    USE ls_forcing_mod
182    USE particle_attributes
183    USE pegrid
184    USE production_e_mod
185    USE prognostic_equations_mod
186    USE statistics
187    USE user_actions_mod
188
189    IMPLICIT NONE
190
191    CHARACTER (LEN=9) ::  time_to_string
192    INTEGER           ::  netcdf_data_format_save
193
194!
195!-- At the beginning of a simulation determine the time step as well as
196!-- determine and print out the run control parameters
197    IF ( simulated_time == 0.0 )  CALL timestep
198
199    CALL run_control
200
201
202!
203!-- Data exchange between coupled models in case that a call has been omitted
204!-- at the end of the previous run of a job chain.
205    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
206!
207!--    In case of model termination initiated by the local model the coupler
208!--    must not be called because this would again cause an MPI hang.
209       DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
210          CALL surface_coupler
211          time_coupling = time_coupling - dt_coupling
212       ENDDO
213       IF (time_coupling == 0.0 .AND. time_since_reference_point < dt_coupling)&
214       THEN
215          time_coupling = time_since_reference_point
216       ENDIF
217    ENDIF
218
219
220#if defined( __dvrp_graphics )
221!
222!-- Time measurement with dvrp software 
223    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
224#endif
225
226!
227!-- Start of the time loop
228    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
229                .NOT. terminate_run )
230
231       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
232
233!
234!--    Determine size of next time step
235       IF ( simulated_time /= 0.0 )  THEN
236          CALL timestep
237       ENDIF
238
239!
240!--    Determine ug, vg and w_subs in dependence on data from external file
241!--    LSF_DATA
242       IF ( large_scale_forcing .AND. lsf_vert ) THEN
243           CALL ls_forcing_vert ( simulated_time )
244       ENDIF
245
246!
247!--    Execute the user-defined actions
248       CALL user_actions( 'before_timestep' )
249
250!
251!--    Start of intermediate step loop
252       intermediate_timestep_count = 0
253       DO  WHILE ( intermediate_timestep_count < &
254                   intermediate_timestep_count_max )
255
256          intermediate_timestep_count = intermediate_timestep_count + 1
257
258!
259!--       Set the steering factors for the prognostic equations which depend
260!--       on the timestep scheme
261          CALL timestep_scheme_steering
262
263!
264!--       Calculate those variables needed in the tendency terms which need
265!--       global communication
266          IF ( .NOT. use_single_reference_value  .AND. &
267               .NOT. use_initial_profile_as_reference )  THEN
268!
269!--          Horizontally averaged profiles to be used as reference state in
270!--          buoyancy terms (WARNING: only the respective last call of
271!--          calc_mean_profile defines the reference state!)
272             IF ( .NOT. neutral )  CALL calc_mean_profile( pt, 4, 'time_int' )
273             IF ( ocean         )  CALL calc_mean_profile( rho, 64, 'time_int' )
274             IF ( humidity      )  CALL calc_mean_profile( vpt, 44, 'time_int' )
275          ENDIF
276
277          IF ( .NOT. constant_diffusion )  CALL production_e_init
278          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  &
279               intermediate_timestep_count == 1 )  CALL ws_statistics
280
281!
282!--       Solve the prognostic equations. A fast cache optimized version with
283!--       only one single loop is used in case of Piascek-Williams advection
284!--       scheme. NEC vector machines use a different version, because
285!--       in the other versions a good vectorization is prohibited due to
286!--       inlining problems.
287          IF ( loop_optimization == 'cache' )  THEN
288             CALL prognostic_equations_cache
289          ELSEIF ( loop_optimization == 'vector' )  THEN
290             CALL prognostic_equations_vector
291          ELSEIF ( loop_optimization == 'acc' )  THEN
292             i_left  = nxl;         i_right = nxr
293             j_south = nys;         j_north = nyn
294             CALL prognostic_equations_acc
295
296!             i_left  = nxl;         i_right = nxl+nbgp-1
297!             j_south = nys;         j_north = nyn
298!             CALL prognostic_equations_acc
299!             i_left  = nxr-nbgp+1;  i_right = nxr
300!             j_south = nys;         j_north = nyn
301!             CALL prognostic_equations_acc
302
303!
304!--          Exchange of ghost points (lateral boundary conditions)
305             IF ( background_communication )  THEN
306
307                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
308               
309                send_receive = 'lr'
310                sendrecv_in_background = .TRUE.
311                req          = 0
312                req_count    = 0
313
314                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
315                   on_device = .TRUE.         ! to be removed after complete porting
316                ELSE                          ! of ghost point exchange
317                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
318                ENDIF
319
320                CALL exchange_horiz( u_p, nbgp )
321                CALL exchange_horiz( v_p, nbgp )
322                CALL exchange_horiz( w_p, nbgp )
323                CALL exchange_horiz( pt_p, nbgp )
324                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
325                IF ( ocean )  THEN
326                   CALL exchange_horiz( sa_p, nbgp )
327                   CALL exchange_horiz( rho, nbgp )
328                  CALL exchange_horiz( prho, nbgp )
329                ENDIF
330                IF (humidity  .OR.  passive_scalar)  THEN
331                   CALL exchange_horiz( q_p, nbgp )
332                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
333                      CALL exchange_horiz( qr_p, nbgp )
334                      CALL exchange_horiz( nr_p, nbgp )
335                   ENDIF
336                ENDIF
337                IF ( cloud_droplets )  THEN
338                   CALL exchange_horiz( ql, nbgp )
339                   CALL exchange_horiz( ql_c, nbgp )
340                   CALL exchange_horiz( ql_v, nbgp )
341                   CALL exchange_horiz( ql_vp, nbgp )
342                ENDIF
343                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
344
345                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
346                   on_device = .FALSE.        ! to be removed after complete porting
347                ELSE                          ! of ghost point exchange
348                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
349                ENDIF
350
351                sendrecv_in_background = .FALSE.
352
353                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'pause' )
354
355             ENDIF
356
357!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
358!             j_south = nys;         j_north = nys+nbgp-1
359!             CALL prognostic_equations_acc
360!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
361!             j_south = nyn-nbgp+1;  j_north = nyn
362!             CALL prognostic_equations_acc
363
364             IF ( background_communication )  THEN
365                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'start' )
366#if defined( __parallel )
367                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
368#endif
369                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'pause' )
370
371                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'continue' )
372
373                send_receive = 'ns'
374                sendrecv_in_background = .TRUE.
375                req          = 0
376                req_count    = 0
377
378                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
379                   on_device = .TRUE.         ! to be removed after complete porting
380                ELSE                          ! of ghost point exchange
381                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
382                ENDIF
383
384                CALL exchange_horiz( u_p, nbgp )
385                CALL exchange_horiz( v_p, nbgp )
386                CALL exchange_horiz( w_p, nbgp )
387                CALL exchange_horiz( pt_p, nbgp )
388                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
389                IF ( ocean )  THEN
390                   CALL exchange_horiz( sa_p, nbgp )
391                   CALL exchange_horiz( rho, nbgp )
392                  CALL exchange_horiz( prho, nbgp )
393                ENDIF
394                IF (humidity  .OR.  passive_scalar)  THEN
395                   CALL exchange_horiz( q_p, nbgp )
396                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
397                      CALL exchange_horiz( qr_p, nbgp )
398                      CALL exchange_horiz( nr_p, nbgp )
399                   ENDIF
400                ENDIF
401                IF ( cloud_droplets )  THEN
402                   CALL exchange_horiz( ql, nbgp )
403                   CALL exchange_horiz( ql_c, nbgp )
404                   CALL exchange_horiz( ql_v, nbgp )
405                   CALL exchange_horiz( ql_vp, nbgp )
406                ENDIF
407                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
408
409                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
410                   on_device = .FALSE.        ! to be removed after complete porting
411                ELSE                          ! of ghost point exchange
412                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
413                ENDIF
414
415                sendrecv_in_background = .FALSE.
416
417                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
418
419             ENDIF
420
421!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
422!             j_south = nys+nbgp;    j_north = nyn-nbgp
423!             CALL prognostic_equations_acc
424
425             IF ( background_communication )  THEN
426                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'continue' )
427#if defined( __parallel )
428                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
429#endif
430                send_receive = 'al'
431                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'stop' )
432             ENDIF
433
434          ENDIF
435
436!
437!--       Particle transport/physics with the Lagrangian particle model
438!--       (only once during intermediate steps, because it uses an Euler-step)
439!--       ### particle model should be moved before prognostic_equations, in order
440!--       to regard droplet interactions directly
441          IF ( particle_advection  .AND.                         &
442               simulated_time >= particle_advection_start  .AND. &
443               intermediate_timestep_count == 1 )  THEN
444             CALL lpm
445             first_call_lpm = .FALSE.
446          ENDIF
447
448!
449!--       Interaction of droplets with temperature and specific humidity.
450!--       Droplet condensation and evaporation is calculated within
451!--       advec_particles.
452          IF ( cloud_droplets  .AND.  &
453               intermediate_timestep_count == intermediate_timestep_count_max )&
454          THEN
455             CALL interaction_droplets_ptq
456          ENDIF
457
458!
459!--       Exchange of ghost points (lateral boundary conditions)
460          IF ( .NOT. background_communication )  THEN
461
462             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
463
464             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
465                on_device = .TRUE.         ! to be removed after complete porting
466             ELSE                          ! of ghost point exchange
467                !$acc update host( e_p, pt_p, u_p, v_p, w_p )
468             ENDIF
469
470             CALL exchange_horiz( u_p, nbgp )
471             CALL exchange_horiz( v_p, nbgp )
472             CALL exchange_horiz( w_p, nbgp )
473             CALL exchange_horiz( pt_p, nbgp )
474             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
475             IF ( ocean )  THEN
476                CALL exchange_horiz( sa_p, nbgp )
477                CALL exchange_horiz( rho, nbgp )
478                CALL exchange_horiz( prho, nbgp )
479             ENDIF
480             IF (humidity  .OR.  passive_scalar)  THEN
481                CALL exchange_horiz( q_p, nbgp )
482                IF ( cloud_physics .AND. icloud_scheme == 0  .AND.  &
483                     precipitation )  THEN
484                   CALL exchange_horiz( qr_p, nbgp )
485                   CALL exchange_horiz( nr_p, nbgp )
486                ENDIF
487             ENDIF
488             IF ( cloud_droplets )  THEN
489                CALL exchange_horiz( ql, nbgp )
490                CALL exchange_horiz( ql_c, nbgp )
491                CALL exchange_horiz( ql_v, nbgp )
492                CALL exchange_horiz( ql_vp, nbgp )
493             ENDIF
494             IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
495
496             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
497                on_device = .FALSE.        ! to be removed after complete porting
498             ELSE                          ! of ghost point exchange
499                !$acc update device( e_p, pt_p, u_p, v_p, w_p )
500             ENDIF
501
502             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
503
504          ENDIF
505
506!
507!--       Boundary conditions for the prognostic quantities (except of the
508!--       velocities at the outflow in case of a non-cyclic lateral wall)
509          CALL boundary_conds
510
511!
512!--       Swap the time levels in preparation for the next time step.
513          CALL swap_timelevel
514
515!
516!--       Temperature offset must be imposed at cyclic boundaries in x-direction
517!--       when a sloping surface is used
518          IF ( sloping_surface )  THEN
519             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - &
520                                                    pt_slope_offset
521             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + &
522                                                    pt_slope_offset
523          ENDIF
524
525!
526!--       Impose a turbulent inflow using the recycling method
527          IF ( turbulent_inflow )  CALL  inflow_turbulence
528
529!
530!--       Impose a random perturbation on the horizontal velocity field
531          IF ( create_disturbances  .AND.                                      &
532               ( call_psolver_at_all_substeps  .AND.                           &
533               intermediate_timestep_count == intermediate_timestep_count_max )&
534          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
535               intermediate_timestep_count == 1 ) )                            &
536          THEN
537             time_disturb = time_disturb + dt_3d
538             IF ( time_disturb >= dt_disturb )  THEN
539                !$acc update host( u, v )
540                IF ( numprocs == 1 )  on_device = .FALSE.  ! workaround, remove later
541                IF ( hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
542                   CALL disturb_field( nzb_u_inner, tend, u )
543                   CALL disturb_field( nzb_v_inner, tend, v )
544                ELSEIF ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )  THEN
545!
546!--                Runs with a non-cyclic lateral wall need perturbations
547!--                near the inflow throughout the whole simulation
548                   dist_range = 1
549                   CALL disturb_field( nzb_u_inner, tend, u )
550                   CALL disturb_field( nzb_v_inner, tend, v )
551                   dist_range = 0
552                ENDIF
553                IF ( numprocs == 1 )  on_device = .TRUE.  ! workaround, remove later
554                !$acc update device( u, v )
555                time_disturb = time_disturb - dt_disturb
556             ENDIF
557          ENDIF
558
559!
560!--       Reduce the velocity divergence via the equation for perturbation
561!--       pressure.
562          IF ( intermediate_timestep_count == 1  .OR. &
563                call_psolver_at_all_substeps )  THEN
564             CALL pres
565          ENDIF
566
567!
568!--       If required, compute liquid water content
569          IF ( cloud_physics )  THEN
570             CALL calc_liquid_water_content
571             !$acc update device( ql )
572          ENDIF
573!
574!--       If required, compute virtual potential temperature
575          IF ( humidity )  THEN
576             CALL compute_vpt
577             !$acc update device( vpt )
578          ENDIF
579!
580!--       Compute the diffusion quantities
581          IF ( .NOT. constant_diffusion )  THEN
582
583!
584!--          Determine surface fluxes shf and qsws and surface values
585!--          pt_surface and q_surface in dependence on data from external
586!--          file LSF_DATA respectively
587             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
588                 intermediate_timestep_count == intermediate_timestep_count_max )&
589             THEN
590                CALL ls_forcing_surf ( simulated_time )
591             ENDIF
592
593!
594!--          First the vertical fluxes in the Prandtl layer are being computed
595             IF ( prandtl_layer )  THEN
596                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'start' )
597                CALL prandtl_fluxes
598                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'stop' )
599             ENDIF
600
601!
602!--          Compute the diffusion coefficients
603             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
604             IF ( .NOT. humidity ) THEN
605                IF ( ocean )  THEN
606                   CALL diffusivities( prho, prho_reference )
607                ELSE
608                   CALL diffusivities( pt, pt_reference )
609                ENDIF
610             ELSE
611                CALL diffusivities( vpt, pt_reference )
612             ENDIF
613             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
614
615          ENDIF
616
617       ENDDO   ! Intermediate step loop
618
619!
620!--    Increase simulation time and output times
621       nr_timesteps_this_run      = nr_timesteps_this_run + 1
622       current_timestep_number    = current_timestep_number + 1
623       simulated_time             = simulated_time   + dt_3d
624       simulated_time_chr         = time_to_string( simulated_time )
625       time_since_reference_point = simulated_time - coupling_start_time
626
627       IF ( simulated_time >= skip_time_data_output_av )  THEN
628          time_do_av         = time_do_av       + dt_3d
629       ENDIF
630       IF ( simulated_time >= skip_time_do2d_xy )  THEN
631          time_do2d_xy       = time_do2d_xy     + dt_3d
632       ENDIF
633       IF ( simulated_time >= skip_time_do2d_xz )  THEN
634          time_do2d_xz       = time_do2d_xz     + dt_3d
635       ENDIF
636       IF ( simulated_time >= skip_time_do2d_yz )  THEN
637          time_do2d_yz       = time_do2d_yz     + dt_3d
638       ENDIF
639       IF ( simulated_time >= skip_time_do3d    )  THEN
640          time_do3d          = time_do3d        + dt_3d
641       ENDIF
642       DO  mid = 1, masks
643          IF ( simulated_time >= skip_time_domask(mid) )  THEN
644             time_domask(mid)= time_domask(mid) + dt_3d
645          ENDIF
646       ENDDO
647       time_dvrp          = time_dvrp        + dt_3d
648       IF ( simulated_time >= skip_time_dosp )  THEN
649          time_dosp       = time_dosp        + dt_3d
650       ENDIF
651       time_dots          = time_dots        + dt_3d
652       IF ( .NOT. first_call_lpm )  THEN
653          time_dopts      = time_dopts       + dt_3d
654       ENDIF
655       IF ( simulated_time >= skip_time_dopr )  THEN
656          time_dopr       = time_dopr        + dt_3d
657       ENDIF
658       time_dopr_listing          = time_dopr_listing        + dt_3d
659       time_run_control   = time_run_control + dt_3d
660
661!
662!--    Data exchange between coupled models
663       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
664          time_coupling = time_coupling + dt_3d
665
666!
667!--       In case of model termination initiated by the local model
668!--       (terminate_coupled > 0), the coupler must be skipped because it would
669!--       cause an MPI intercomminucation hang.
670!--       If necessary, the coupler will be called at the beginning of the
671!--       next restart run.
672          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
673             CALL surface_coupler
674             time_coupling = time_coupling - dt_coupling
675          ENDDO
676       ENDIF
677
678!
679!--    Execute user-defined actions
680       CALL user_actions( 'after_integration' )
681
682!
683!--    If Galilei transformation is used, determine the distance that the
684!--    model has moved so far
685       IF ( galilei_transformation )  THEN
686          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
687          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
688       ENDIF
689
690!
691!--    Check, if restart is necessary (because cpu-time is expiring or
692!--    because it is forced by user) and set stop flag
693!--    This call is skipped if the remote model has already initiated a restart.
694       IF ( .NOT. terminate_run )  CALL check_for_restart
695
696!
697!--    Carry out statistical analysis and output at the requested output times.
698!--    The MOD function is used for calculating the output time counters (like
699!--    time_dopr) in order to regard a possible decrease of the output time
700!--    interval in case of restart runs
701
702!
703!--    Set a flag indicating that so far no statistics have been created
704!--    for this time step
705       flow_statistics_called = .FALSE.
706
707!
708!--    If required, call flow_statistics for averaging in time
709       IF ( averaging_interval_pr /= 0.0  .AND.  &
710            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
711            simulated_time >= skip_time_dopr )  THEN
712          time_dopr_av = time_dopr_av + dt_3d
713          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
714             do_sum = .TRUE.
715             time_dopr_av = MOD( time_dopr_av, &
716                                    MAX( dt_averaging_input_pr, dt_3d ) )
717          ENDIF
718       ENDIF
719       IF ( do_sum )  CALL flow_statistics
720
721!
722!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
723       IF ( averaging_interval /= 0.0  .AND.                                &
724            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
725            simulated_time >= skip_time_data_output_av )                    &
726       THEN
727          time_do_sla = time_do_sla + dt_3d
728          IF ( time_do_sla >= dt_averaging_input )  THEN
729             CALL sum_up_3d_data
730             average_count_3d = average_count_3d + 1
731             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
732          ENDIF
733       ENDIF
734
735!
736!--    Calculate spectra for time averaging
737       IF ( averaging_interval_sp /= 0.0  .AND.  &
738            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
739            simulated_time >= skip_time_dosp )  THEN
740          time_dosp_av = time_dosp_av + dt_3d
741          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
742             CALL calc_spectra
743             time_dosp_av = MOD( time_dosp_av, &
744                                 MAX( dt_averaging_input_pr, dt_3d ) )
745          ENDIF
746       ENDIF
747
748!
749!--    Computation and output of run control parameters.
750!--    This is also done whenever perturbations have been imposed
751       IF ( time_run_control >= dt_run_control  .OR.                     &
752            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created ) &
753       THEN
754          CALL run_control
755          IF ( time_run_control >= dt_run_control )  THEN
756             time_run_control = MOD( time_run_control, &
757                                     MAX( dt_run_control, dt_3d ) )
758          ENDIF
759       ENDIF
760
761!
762!--    Profile output (ASCII) on file
763       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
764          CALL print_1d
765          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
766                                                           dt_3d ) )
767       ENDIF
768
769!
770!--    Graphic output for PROFIL
771       IF ( time_dopr >= dt_dopr )  THEN
772          IF ( dopr_n /= 0 )  CALL data_output_profiles
773          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
774          time_dopr_av = 0.0    ! due to averaging (see above)
775       ENDIF
776
777!
778!--    Graphic output for time series
779       IF ( time_dots >= dt_dots )  THEN
780          CALL data_output_tseries
781          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
782       ENDIF
783
784!
785!--    Output of spectra (formatted for use with PROFIL), in case of no
786!--    time averaging, spectra has to be calculated before
787       IF ( time_dosp >= dt_dosp )  THEN
788          IF ( average_count_sp == 0 )  CALL calc_spectra
789          CALL data_output_spectra
790          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
791       ENDIF
792
793!
794!--    2d-data output (cross-sections)
795       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
796          CALL data_output_2d( 'xy', 0 )
797          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
798       ENDIF
799       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
800          CALL data_output_2d( 'xz', 0 )
801          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
802       ENDIF
803       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
804          CALL data_output_2d( 'yz', 0 )
805          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
806       ENDIF
807
808!
809!--    3d-data output (volume data)
810       IF ( time_do3d >= dt_do3d )  THEN
811          CALL data_output_3d( 0 )
812          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
813       ENDIF
814
815!
816!--    masked data output
817!--    Parallel netcdf output is not tested so far for masked data, hence
818!--    netcdf_data_format is switched back to non-paralell output.
819       netcdf_data_format_save = netcdf_data_format
820       IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
821       IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
822       DO  mid = 1, masks
823          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
824             CALL data_output_mask( 0 )
825             time_domask(mid) = MOD( time_domask(mid),  &
826                                     MAX( dt_domask(mid), dt_3d ) )
827          ENDIF
828       ENDDO
829       netcdf_data_format = netcdf_data_format_save
830
831!
832!--    Output of time-averaged 2d/3d/masked data
833       IF ( time_do_av >= dt_data_output_av )  THEN
834          CALL average_3d_data
835          CALL data_output_2d( 'xy', 1 )
836          CALL data_output_2d( 'xz', 1 )
837          CALL data_output_2d( 'yz', 1 )
838          CALL data_output_3d( 1 )
839!--       Parallel netcdf output is not tested so far for masked data, hence
840!--       netcdf_data_format is switched back to non-paralell output.
841          netcdf_data_format_save = netcdf_data_format
842          IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
843          IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
844          DO  mid = 1, masks
845             CALL data_output_mask( 1 )
846          ENDDO
847          netcdf_data_format = netcdf_data_format_save
848          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
849       ENDIF
850
851!
852!--    Output of particle time series
853       IF ( particle_advection )  THEN
854          IF ( time_dopts >= dt_dopts  .OR. &
855               ( simulated_time >= particle_advection_start  .AND. &
856                 first_call_lpm ) )  THEN
857             CALL data_output_ptseries
858             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
859          ENDIF
860       ENDIF
861
862!
863!--    Output of dvrp-graphics (isosurface, particles, slicer)
864#if defined( __dvrp_graphics )
865       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
866#endif
867       IF ( time_dvrp >= dt_dvrp )  THEN
868          CALL data_output_dvrp
869          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
870       ENDIF
871#if defined( __dvrp_graphics )
872       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
873#endif
874
875!
876!--    If required, set the heat flux for the next time step at a random value
877       IF ( constant_heatflux  .AND.  random_heatflux )  CALL disturb_heatflux
878
879!
880!--    Execute user-defined actions
881       CALL user_actions( 'after_timestep' )
882
883       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
884
885
886    ENDDO   ! time loop
887
888#if defined( __dvrp_graphics )
889    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
890#endif
891
892 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.