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

Last change on this file since 1317 was 1310, checked in by raasch, 11 years ago

update of GPL copyright

  • 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!
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 1310 2014-03-14 08:01:56Z heinze $
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 interfaces
182    USE ls_forcing_mod
183    USE particle_attributes
184    USE pegrid
185    USE production_e_mod
186    USE prognostic_equations_mod
187    USE statistics
188    USE user_actions_mod
189
190    IMPLICIT NONE
191
192    CHARACTER (LEN=9) ::  time_to_string
193    INTEGER           ::  netcdf_data_format_save
194
195!
196!-- At the beginning of a simulation determine the time step as well as
197!-- determine and print out the run control parameters
198    IF ( simulated_time == 0.0 )  CALL timestep
199
200    CALL run_control
201
202
203!
204!-- Data exchange between coupled models in case that a call has been omitted
205!-- at the end of the previous run of a job chain.
206    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
207!
208!--    In case of model termination initiated by the local model the coupler
209!--    must not be called because this would again cause an MPI hang.
210       DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
211          CALL surface_coupler
212          time_coupling = time_coupling - dt_coupling
213       ENDDO
214       IF (time_coupling == 0.0 .AND. time_since_reference_point < dt_coupling)&
215       THEN
216          time_coupling = time_since_reference_point
217       ENDIF
218    ENDIF
219
220
221#if defined( __dvrp_graphics )
222!
223!-- Time measurement with dvrp software 
224    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
225#endif
226
227!
228!-- Start of the time loop
229    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
230                .NOT. terminate_run )
231
232       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
233
234!
235!--    Determine size of next time step
236       IF ( simulated_time /= 0.0 )  THEN
237          CALL timestep
238       ENDIF
239
240!
241!--    Determine ug, vg and w_subs in dependence on data from external file
242!--    LSF_DATA
243       IF ( large_scale_forcing .AND. lsf_vert ) THEN
244           CALL ls_forcing_vert ( simulated_time )
245       ENDIF
246
247!
248!--    Execute the user-defined actions
249       CALL user_actions( 'before_timestep' )
250
251!
252!--    Start of intermediate step loop
253       intermediate_timestep_count = 0
254       DO  WHILE ( intermediate_timestep_count < &
255                   intermediate_timestep_count_max )
256
257          intermediate_timestep_count = intermediate_timestep_count + 1
258
259!
260!--       Set the steering factors for the prognostic equations which depend
261!--       on the timestep scheme
262          CALL timestep_scheme_steering
263
264!
265!--       Calculate those variables needed in the tendency terms which need
266!--       global communication
267          IF ( .NOT. use_single_reference_value  .AND. &
268               .NOT. use_initial_profile_as_reference )  THEN
269!
270!--          Horizontally averaged profiles to be used as reference state in
271!--          buoyancy terms (WARNING: only the respective last call of
272!--          calc_mean_profile defines the reference state!)
273             IF ( .NOT. neutral )  CALL calc_mean_profile( pt, 4, 'time_int' )
274             IF ( ocean         )  CALL calc_mean_profile( rho, 64, 'time_int' )
275             IF ( humidity      )  CALL calc_mean_profile( vpt, 44, 'time_int' )
276          ENDIF
277
278          IF ( .NOT. constant_diffusion )  CALL production_e_init
279          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  &
280               intermediate_timestep_count == 1 )  CALL ws_statistics
281
282!
283!--       Solve the prognostic equations. A fast cache optimized version with
284!--       only one single loop is used in case of Piascek-Williams advection
285!--       scheme. NEC vector machines use a different version, because
286!--       in the other versions a good vectorization is prohibited due to
287!--       inlining problems.
288          IF ( loop_optimization == 'cache' )  THEN
289             CALL prognostic_equations_cache
290          ELSEIF ( loop_optimization == 'vector' )  THEN
291             CALL prognostic_equations_vector
292          ELSEIF ( loop_optimization == 'acc' )  THEN
293             i_left  = nxl;         i_right = nxr
294             j_south = nys;         j_north = nyn
295             CALL prognostic_equations_acc
296
297!             i_left  = nxl;         i_right = nxl+nbgp-1
298!             j_south = nys;         j_north = nyn
299!             CALL prognostic_equations_acc
300!             i_left  = nxr-nbgp+1;  i_right = nxr
301!             j_south = nys;         j_north = nyn
302!             CALL prognostic_equations_acc
303
304!
305!--          Exchange of ghost points (lateral boundary conditions)
306             IF ( background_communication )  THEN
307
308                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
309               
310                send_receive = 'lr'
311                sendrecv_in_background = .TRUE.
312                req          = 0
313                req_count    = 0
314
315                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
316                   on_device = .TRUE.         ! to be removed after complete porting
317                ELSE                          ! of ghost point exchange
318                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
319                ENDIF
320
321                CALL exchange_horiz( u_p, nbgp )
322                CALL exchange_horiz( v_p, nbgp )
323                CALL exchange_horiz( w_p, nbgp )
324                CALL exchange_horiz( pt_p, nbgp )
325                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
326                IF ( ocean )  THEN
327                   CALL exchange_horiz( sa_p, nbgp )
328                   CALL exchange_horiz( rho, nbgp )
329                  CALL exchange_horiz( prho, nbgp )
330                ENDIF
331                IF (humidity  .OR.  passive_scalar)  THEN
332                   CALL exchange_horiz( q_p, nbgp )
333                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
334                      CALL exchange_horiz( qr_p, nbgp )
335                      CALL exchange_horiz( nr_p, nbgp )
336                   ENDIF
337                ENDIF
338                IF ( cloud_droplets )  THEN
339                   CALL exchange_horiz( ql, nbgp )
340                   CALL exchange_horiz( ql_c, nbgp )
341                   CALL exchange_horiz( ql_v, nbgp )
342                   CALL exchange_horiz( ql_vp, nbgp )
343                ENDIF
344                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
345
346                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
347                   on_device = .FALSE.        ! to be removed after complete porting
348                ELSE                          ! of ghost point exchange
349                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
350                ENDIF
351
352                sendrecv_in_background = .FALSE.
353
354                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'pause' )
355
356             ENDIF
357
358!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
359!             j_south = nys;         j_north = nys+nbgp-1
360!             CALL prognostic_equations_acc
361!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
362!             j_south = nyn-nbgp+1;  j_north = nyn
363!             CALL prognostic_equations_acc
364
365             IF ( background_communication )  THEN
366                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'start' )
367#if defined( __parallel )
368                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
369#endif
370                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'pause' )
371
372                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'continue' )
373
374                send_receive = 'ns'
375                sendrecv_in_background = .TRUE.
376                req          = 0
377                req_count    = 0
378
379                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
380                   on_device = .TRUE.         ! to be removed after complete porting
381                ELSE                          ! of ghost point exchange
382                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
383                ENDIF
384
385                CALL exchange_horiz( u_p, nbgp )
386                CALL exchange_horiz( v_p, nbgp )
387                CALL exchange_horiz( w_p, nbgp )
388                CALL exchange_horiz( pt_p, nbgp )
389                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
390                IF ( ocean )  THEN
391                   CALL exchange_horiz( sa_p, nbgp )
392                   CALL exchange_horiz( rho, nbgp )
393                  CALL exchange_horiz( prho, nbgp )
394                ENDIF
395                IF (humidity  .OR.  passive_scalar)  THEN
396                   CALL exchange_horiz( q_p, nbgp )
397                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
398                      CALL exchange_horiz( qr_p, nbgp )
399                      CALL exchange_horiz( nr_p, nbgp )
400                   ENDIF
401                ENDIF
402                IF ( cloud_droplets )  THEN
403                   CALL exchange_horiz( ql, nbgp )
404                   CALL exchange_horiz( ql_c, nbgp )
405                   CALL exchange_horiz( ql_v, nbgp )
406                   CALL exchange_horiz( ql_vp, nbgp )
407                ENDIF
408                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
409
410                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
411                   on_device = .FALSE.        ! to be removed after complete porting
412                ELSE                          ! of ghost point exchange
413                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
414                ENDIF
415
416                sendrecv_in_background = .FALSE.
417
418                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
419
420             ENDIF
421
422!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
423!             j_south = nys+nbgp;    j_north = nyn-nbgp
424!             CALL prognostic_equations_acc
425
426             IF ( background_communication )  THEN
427                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'continue' )
428#if defined( __parallel )
429                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
430#endif
431                send_receive = 'al'
432                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'stop' )
433             ENDIF
434
435          ENDIF
436
437!
438!--       Particle transport/physics with the Lagrangian particle model
439!--       (only once during intermediate steps, because it uses an Euler-step)
440!--       ### particle model should be moved before prognostic_equations, in order
441!--       to regard droplet interactions directly
442          IF ( particle_advection  .AND.                         &
443               simulated_time >= particle_advection_start  .AND. &
444               intermediate_timestep_count == 1 )  THEN
445             CALL lpm
446             first_call_lpm = .FALSE.
447          ENDIF
448
449!
450!--       Interaction of droplets with temperature and specific humidity.
451!--       Droplet condensation and evaporation is calculated within
452!--       advec_particles.
453          IF ( cloud_droplets  .AND.  &
454               intermediate_timestep_count == intermediate_timestep_count_max )&
455          THEN
456             CALL interaction_droplets_ptq
457          ENDIF
458
459!
460!--       Exchange of ghost points (lateral boundary conditions)
461          IF ( .NOT. background_communication )  THEN
462
463             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
464
465             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
466                on_device = .TRUE.         ! to be removed after complete porting
467             ELSE                          ! of ghost point exchange
468                !$acc update host( e_p, pt_p, u_p, v_p, w_p )
469             ENDIF
470
471             CALL exchange_horiz( u_p, nbgp )
472             CALL exchange_horiz( v_p, nbgp )
473             CALL exchange_horiz( w_p, nbgp )
474             CALL exchange_horiz( pt_p, nbgp )
475             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
476             IF ( ocean )  THEN
477                CALL exchange_horiz( sa_p, nbgp )
478                CALL exchange_horiz( rho, nbgp )
479                CALL exchange_horiz( prho, nbgp )
480             ENDIF
481             IF (humidity  .OR.  passive_scalar)  THEN
482                CALL exchange_horiz( q_p, nbgp )
483                IF ( cloud_physics .AND. icloud_scheme == 0  .AND.  &
484                     precipitation )  THEN
485                   CALL exchange_horiz( qr_p, nbgp )
486                   CALL exchange_horiz( nr_p, nbgp )
487                ENDIF
488             ENDIF
489             IF ( cloud_droplets )  THEN
490                CALL exchange_horiz( ql, nbgp )
491                CALL exchange_horiz( ql_c, nbgp )
492                CALL exchange_horiz( ql_v, nbgp )
493                CALL exchange_horiz( ql_vp, nbgp )
494             ENDIF
495             IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
496
497             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
498                on_device = .FALSE.        ! to be removed after complete porting
499             ELSE                          ! of ghost point exchange
500                !$acc update device( e_p, pt_p, u_p, v_p, w_p )
501             ENDIF
502
503             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
504
505          ENDIF
506
507!
508!--       Boundary conditions for the prognostic quantities (except of the
509!--       velocities at the outflow in case of a non-cyclic lateral wall)
510          CALL boundary_conds
511
512!
513!--       Swap the time levels in preparation for the next time step.
514          CALL swap_timelevel
515
516!
517!--       Temperature offset must be imposed at cyclic boundaries in x-direction
518!--       when a sloping surface is used
519          IF ( sloping_surface )  THEN
520             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - &
521                                                    pt_slope_offset
522             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + &
523                                                    pt_slope_offset
524          ENDIF
525
526!
527!--       Impose a turbulent inflow using the recycling method
528          IF ( turbulent_inflow )  CALL  inflow_turbulence
529
530!
531!--       Impose a random perturbation on the horizontal velocity field
532          IF ( create_disturbances  .AND.                                      &
533               ( call_psolver_at_all_substeps  .AND.                           &
534               intermediate_timestep_count == intermediate_timestep_count_max )&
535          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
536               intermediate_timestep_count == 1 ) )                            &
537          THEN
538             time_disturb = time_disturb + dt_3d
539             IF ( time_disturb >= dt_disturb )  THEN
540                !$acc update host( u, v )
541                IF ( numprocs == 1 )  on_device = .FALSE.  ! workaround, remove later
542                IF ( hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
543                   CALL disturb_field( nzb_u_inner, tend, u )
544                   CALL disturb_field( nzb_v_inner, tend, v )
545                ELSEIF ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )  THEN
546!
547!--                Runs with a non-cyclic lateral wall need perturbations
548!--                near the inflow throughout the whole simulation
549                   dist_range = 1
550                   CALL disturb_field( nzb_u_inner, tend, u )
551                   CALL disturb_field( nzb_v_inner, tend, v )
552                   dist_range = 0
553                ENDIF
554                IF ( numprocs == 1 )  on_device = .TRUE.  ! workaround, remove later
555                !$acc update device( u, v )
556                time_disturb = time_disturb - dt_disturb
557             ENDIF
558          ENDIF
559
560!
561!--       Reduce the velocity divergence via the equation for perturbation
562!--       pressure.
563          IF ( intermediate_timestep_count == 1  .OR. &
564                call_psolver_at_all_substeps )  THEN
565             CALL pres
566          ENDIF
567
568!
569!--       If required, compute liquid water content
570          IF ( cloud_physics )  THEN
571             CALL calc_liquid_water_content
572             !$acc update device( ql )
573          ENDIF
574!
575!--       If required, compute virtual potential temperature
576          IF ( humidity )  THEN
577             CALL compute_vpt 
578             !$acc update device( vpt )
579          ENDIF 
580!
581!--       Compute the diffusion quantities
582          IF ( .NOT. constant_diffusion )  THEN
583
584!
585!--          Determine surface fluxes shf and qsws and surface values
586!--          pt_surface and q_surface in dependence on data from external
587!--          file LSF_DATA respectively
588             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
589                 intermediate_timestep_count == intermediate_timestep_count_max )&
590             THEN
591                CALL ls_forcing_surf ( simulated_time )
592             ENDIF
593
594!
595!--          First the vertical fluxes in the Prandtl layer are being computed
596             IF ( prandtl_layer )  THEN
597                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'start' )
598                CALL prandtl_fluxes
599                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'stop' )
600             ENDIF
601
602!
603!--          Compute the diffusion coefficients
604             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
605             IF ( .NOT. humidity ) THEN
606                IF ( ocean )  THEN
607                   CALL diffusivities( prho, prho_reference )
608                ELSE
609                   CALL diffusivities( pt, pt_reference )
610                ENDIF
611             ELSE
612                CALL diffusivities( vpt, pt_reference )
613             ENDIF
614             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
615
616          ENDIF
617
618       ENDDO   ! Intermediate step loop
619
620!
621!--    Increase simulation time and output times
622       nr_timesteps_this_run      = nr_timesteps_this_run + 1
623       current_timestep_number    = current_timestep_number + 1
624       simulated_time             = simulated_time   + dt_3d
625       simulated_time_chr         = time_to_string( simulated_time )
626       time_since_reference_point = simulated_time - coupling_start_time
627
628       IF ( simulated_time >= skip_time_data_output_av )  THEN
629          time_do_av         = time_do_av       + dt_3d
630       ENDIF
631       IF ( simulated_time >= skip_time_do2d_xy )  THEN
632          time_do2d_xy       = time_do2d_xy     + dt_3d
633       ENDIF
634       IF ( simulated_time >= skip_time_do2d_xz )  THEN
635          time_do2d_xz       = time_do2d_xz     + dt_3d
636       ENDIF
637       IF ( simulated_time >= skip_time_do2d_yz )  THEN
638          time_do2d_yz       = time_do2d_yz     + dt_3d
639       ENDIF
640       IF ( simulated_time >= skip_time_do3d    )  THEN
641          time_do3d          = time_do3d        + dt_3d
642       ENDIF
643       DO  mid = 1, masks
644          IF ( simulated_time >= skip_time_domask(mid) )  THEN
645             time_domask(mid)= time_domask(mid) + dt_3d
646          ENDIF
647       ENDDO
648       time_dvrp          = time_dvrp        + dt_3d
649       IF ( simulated_time >= skip_time_dosp )  THEN
650          time_dosp       = time_dosp        + dt_3d
651       ENDIF
652       time_dots          = time_dots        + dt_3d
653       IF ( .NOT. first_call_lpm )  THEN
654          time_dopts      = time_dopts       + dt_3d
655       ENDIF
656       IF ( simulated_time >= skip_time_dopr )  THEN
657          time_dopr       = time_dopr        + dt_3d
658       ENDIF
659       time_dopr_listing          = time_dopr_listing        + dt_3d
660       time_run_control   = time_run_control + dt_3d
661
662!
663!--    Data exchange between coupled models
664       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
665          time_coupling = time_coupling + dt_3d
666
667!
668!--       In case of model termination initiated by the local model
669!--       (terminate_coupled > 0), the coupler must be skipped because it would
670!--       cause an MPI intercomminucation hang.
671!--       If necessary, the coupler will be called at the beginning of the
672!--       next restart run.
673          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
674             CALL surface_coupler
675             time_coupling = time_coupling - dt_coupling
676          ENDDO
677       ENDIF
678
679!
680!--    Execute user-defined actions
681       CALL user_actions( 'after_integration' )
682
683!
684!--    If Galilei transformation is used, determine the distance that the
685!--    model has moved so far
686       IF ( galilei_transformation )  THEN
687          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
688          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
689       ENDIF
690
691!
692!--    Check, if restart is necessary (because cpu-time is expiring or
693!--    because it is forced by user) and set stop flag
694!--    This call is skipped if the remote model has already initiated a restart.
695       IF ( .NOT. terminate_run )  CALL check_for_restart
696
697!
698!--    Carry out statistical analysis and output at the requested output times.
699!--    The MOD function is used for calculating the output time counters (like
700!--    time_dopr) in order to regard a possible decrease of the output time
701!--    interval in case of restart runs
702
703!
704!--    Set a flag indicating that so far no statistics have been created
705!--    for this time step
706       flow_statistics_called = .FALSE.
707
708!
709!--    If required, call flow_statistics for averaging in time
710       IF ( averaging_interval_pr /= 0.0  .AND.  &
711            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
712            simulated_time >= skip_time_dopr )  THEN
713          time_dopr_av = time_dopr_av + dt_3d
714          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
715             do_sum = .TRUE.
716             time_dopr_av = MOD( time_dopr_av, &
717                                    MAX( dt_averaging_input_pr, dt_3d ) )
718          ENDIF
719       ENDIF
720       IF ( do_sum )  CALL flow_statistics
721
722!
723!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
724       IF ( averaging_interval /= 0.0  .AND.                                &
725            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
726            simulated_time >= skip_time_data_output_av )                    &
727       THEN
728          time_do_sla = time_do_sla + dt_3d
729          IF ( time_do_sla >= dt_averaging_input )  THEN
730             CALL sum_up_3d_data
731             average_count_3d = average_count_3d + 1
732             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
733          ENDIF
734       ENDIF
735
736!
737!--    Calculate spectra for time averaging
738       IF ( averaging_interval_sp /= 0.0  .AND.  &
739            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
740            simulated_time >= skip_time_dosp )  THEN
741          time_dosp_av = time_dosp_av + dt_3d
742          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
743             CALL calc_spectra
744             time_dosp_av = MOD( time_dosp_av, &
745                                 MAX( dt_averaging_input_pr, dt_3d ) )
746          ENDIF
747       ENDIF
748
749!
750!--    Computation and output of run control parameters.
751!--    This is also done whenever perturbations have been imposed
752       IF ( time_run_control >= dt_run_control  .OR.                     &
753            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created ) &
754       THEN
755          CALL run_control
756          IF ( time_run_control >= dt_run_control )  THEN
757             time_run_control = MOD( time_run_control, &
758                                     MAX( dt_run_control, dt_3d ) )
759          ENDIF
760       ENDIF
761
762!
763!--    Profile output (ASCII) on file
764       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
765          CALL print_1d
766          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
767                                                           dt_3d ) )
768       ENDIF
769
770!
771!--    Graphic output for PROFIL
772       IF ( time_dopr >= dt_dopr )  THEN
773          IF ( dopr_n /= 0 )  CALL data_output_profiles
774          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
775          time_dopr_av = 0.0    ! due to averaging (see above)
776       ENDIF
777
778!
779!--    Graphic output for time series
780       IF ( time_dots >= dt_dots )  THEN
781          CALL data_output_tseries
782          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
783       ENDIF
784
785!
786!--    Output of spectra (formatted for use with PROFIL), in case of no
787!--    time averaging, spectra has to be calculated before
788       IF ( time_dosp >= dt_dosp )  THEN
789          IF ( average_count_sp == 0 )  CALL calc_spectra
790          CALL data_output_spectra
791          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
792       ENDIF
793
794!
795!--    2d-data output (cross-sections)
796       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
797          CALL data_output_2d( 'xy', 0 )
798          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
799       ENDIF
800       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
801          CALL data_output_2d( 'xz', 0 )
802          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
803       ENDIF
804       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
805          CALL data_output_2d( 'yz', 0 )
806          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
807       ENDIF
808
809!
810!--    3d-data output (volume data)
811       IF ( time_do3d >= dt_do3d )  THEN
812          CALL data_output_3d( 0 )
813          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
814       ENDIF
815
816!
817!--    masked data output
818!--    Parallel netcdf output is not tested so far for masked data, hence
819!--    netcdf_data_format is switched back to non-paralell output.
820       netcdf_data_format_save = netcdf_data_format
821       IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
822       IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
823       DO  mid = 1, masks
824          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
825             CALL data_output_mask( 0 )
826             time_domask(mid) = MOD( time_domask(mid),  &
827                                     MAX( dt_domask(mid), dt_3d ) )
828          ENDIF
829       ENDDO
830       netcdf_data_format = netcdf_data_format_save
831
832!
833!--    Output of time-averaged 2d/3d/masked data
834       IF ( time_do_av >= dt_data_output_av )  THEN
835          CALL average_3d_data
836          CALL data_output_2d( 'xy', 1 )
837          CALL data_output_2d( 'xz', 1 )
838          CALL data_output_2d( 'yz', 1 )
839          CALL data_output_3d( 1 )
840!--       Parallel netcdf output is not tested so far for masked data, hence
841!--       netcdf_data_format is switched back to non-paralell output.
842          netcdf_data_format_save = netcdf_data_format
843          IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
844          IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
845          DO  mid = 1, masks
846             CALL data_output_mask( 1 )
847          ENDDO
848          netcdf_data_format = netcdf_data_format_save
849          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
850       ENDIF
851
852!
853!--    Output of particle time series
854       IF ( particle_advection )  THEN
855          IF ( time_dopts >= dt_dopts  .OR. &
856               ( simulated_time >= particle_advection_start  .AND. &
857                 first_call_lpm ) )  THEN
858             CALL data_output_ptseries
859             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
860          ENDIF
861       ENDIF
862
863!
864!--    Output of dvrp-graphics (isosurface, particles, slicer)
865#if defined( __dvrp_graphics )
866       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
867#endif
868       IF ( time_dvrp >= dt_dvrp )  THEN
869          CALL data_output_dvrp
870          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
871       ENDIF
872#if defined( __dvrp_graphics )
873       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
874#endif
875
876!
877!--    If required, set the heat flux for the next time step at a random value
878       IF ( constant_heatflux  .AND.  random_heatflux )  CALL disturb_heatflux
879
880!
881!--    Execute user-defined actions
882       CALL user_actions( 'after_timestep' )
883
884       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
885
886
887    ENDDO   ! time loop
888
889#if defined( __dvrp_graphics )
890    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
891#endif
892
893 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.