source: palm/trunk/SOURCE/prognostic_equations.f90 @ 1257

Last change on this file since 1257 was 1257, checked in by raasch, 10 years ago

New:
---

openACC porting of timestep calculation
(modules, timestep, time_integration)

Changed:


openACC loop directives and vector clauses removed (because they do not give any performance improvement with PGI
compiler versions > 13.6)
(advec_ws, buoyancy, coriolis, diffusion_e, diffusion_s, diffusion_u, diffusion_v, diffusion_w, diffusivities, exchange_horiz, fft_xy, pres, production_e, transpose, tridia_solver, wall_fluxes)

openACC loop independent clauses added
(boundary_conds, prandtl_fluxes, pres)

openACC declare create statements moved after FORTRAN declaration statement
(diffusion_u, diffusion_v, diffusion_w, fft_xy, poisfft, production_e, tridia_solver)

openACC end parallel replaced by end parallel loop
(flow_statistics, pres)

openACC "kernels do" replaced by "kernels loop"
(prandtl_fluxes)

output format for theta* changed to avoid output of *
(run_control)

Errors:


bugfix for calculation of advective timestep (old version may cause wrong timesteps in case of
vertixcally stretched grids)
Attention: standard run-control output has changed!
(timestep)

  • Property svn:keywords set to Id
File size: 66.5 KB
Line 
1 MODULE prognostic_equations_mod
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-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! openacc loop vector clauses removed, independent clauses added
23!
24! Former revisions:
25! -----------------
26! $Id: prognostic_equations.f90 1257 2013-11-08 15:18:40Z raasch $
27!
28! 1246 2013-11-01 08:59:45Z heinze
29! enable nudging also for accelerator version
30!
31! 1241 2013-10-30 11:36:58Z heinze
32! usage of nudging enabled (so far not implemented for accelerator version)
33!
34! 1179 2013-06-14 05:57:58Z raasch
35! two arguments removed from routine buoyancy, ref_state updated on device
36!
37! 1128 2013-04-12 06:19:32Z raasch
38! those parts requiring global communication moved to time_integration,
39! loop index bounds in accelerator version replaced by i_left, i_right, j_south,
40! j_north
41!
42! 1115 2013-03-26 18:16:16Z hoffmann
43! optimized cloud physics: calculation of microphysical tendencies transfered
44! to microphysics.f90; qr and nr are only calculated if precipitation is required
45!
46! 1111 2013-03-08 23:54:10Z raasch
47! update directives for prognostic quantities removed
48!
49! 1106 2013-03-04 05:31:38Z raasch
50! small changes in code formatting
51!
52! 1092 2013-02-02 11:24:22Z raasch
53! unused variables removed
54!
55! 1053 2012-11-13 17:11:03Z hoffmann
56! implementation of two new prognostic equations for rain drop concentration (nr)
57! and rain water content (qr)
58!
59! currently, only available for cache loop optimization
60!
61! 1036 2012-10-22 13:43:42Z raasch
62! code put under GPL (PALM 3.9)
63!
64! 1019 2012-09-28 06:46:45Z raasch
65! non-optimized version of prognostic_equations removed
66!
67! 1015 2012-09-27 09:23:24Z raasch
68! new branch prognostic_equations_acc
69! OpenACC statements added + code changes required for GPU optimization
70!
71! 1001 2012-09-13 14:08:46Z raasch
72! all actions concerning leapfrog- and upstream-spline-scheme removed
73!
74! 978 2012-08-09 08:28:32Z fricke
75! km_damp_x and km_damp_y removed in calls of diffusion_u and diffusion_v
76! add ptdf_x, ptdf_y for damping the potential temperature at the inflow
77! boundary in case of non-cyclic lateral boundaries
78! Bugfix: first thread index changes for WS-scheme at the inflow
79!
80! 940 2012-07-09 14:31:00Z raasch
81! temperature equation can be switched off
82!
83! 785 2011-11-28 09:47:19Z raasch
84! new factor rdf_sc allows separate Rayleigh damping of scalars
85!
86! 736 2011-08-17 14:13:26Z suehring
87! Bugfix: determination of first thread index i for WS-scheme
88!
89! 709 2011-03-30 09:31:40Z raasch
90! formatting adjustments
91!
92! 673 2011-01-18 16:19:48Z suehring
93! Consideration of the pressure gradient (steered by tsc(4)) during the time
94! integration removed.
95!
96! 667 2010-12-23 12:06:00Z suehring/gryschka
97! Calls of the advection routines with WS5 added.
98! Calls of ws_statistics added to set the statistical arrays to zero after each
99! time step.
100!
101! 531 2010-04-21 06:47:21Z heinze
102! add call of subsidence in the equation for humidity / passive scalar
103!
104! 411 2009-12-11 14:15:58Z heinze
105! add call of subsidence in the equation for potential temperature
106!
107! 388 2009-09-23 09:40:33Z raasch
108! prho is used instead of rho in diffusion_e,
109! external pressure gradient
110!
111! 153 2008-03-19 09:41:30Z steinfeld
112! add call of plant_canopy_model in the prognostic equation for
113! the potential temperature and for the passive scalar
114!
115! 138 2007-11-28 10:03:58Z letzel
116! add call of subroutines that evaluate the canopy drag terms,
117! add wall_*flux to parameter list of calls of diffusion_s
118!
119! 106 2007-08-16 14:30:26Z raasch
120! +uswst, vswst as arguments in calls of diffusion_u|v,
121! loops for u and v are starting from index nxlu, nysv, respectively (needed
122! for non-cyclic boundary conditions)
123!
124! 97 2007-06-21 08:23:15Z raasch
125! prognostic equation for salinity, density is calculated from equation of
126! state for seawater and is used for calculation of buoyancy,
127! +eqn_state_seawater_mod
128! diffusion_e is called with argument rho in case of ocean runs,
129! new argument zw in calls of diffusion_e, new argument pt_/prho_reference
130! in calls of buoyancy and diffusion_e, calc_mean_pt_profile renamed
131! calc_mean_profile
132!
133! 75 2007-03-22 09:54:05Z raasch
134! checking for negative q and limiting for positive values,
135! z0 removed from arguments in calls of diffusion_u/v/w, uxrp, vynp eliminated,
136! subroutine names changed to .._noopt, .._cache, and .._vector,
137! moisture renamed humidity, Bott-Chlond-scheme can be used in the
138! _vector-version
139!
140! 19 2007-02-23 04:53:48Z raasch
141! Calculation of e, q, and pt extended for gridpoint nzt,
142! handling of given temperature/humidity/scalar fluxes at top surface
143!
144! RCS Log replace by Id keyword, revision history cleaned up
145!
146! Revision 1.21  2006/08/04 15:01:07  raasch
147! upstream scheme can be forced to be used for tke (use_upstream_for_tke)
148! regardless of the timestep scheme used for the other quantities,
149! new argument diss in call of diffusion_e
150!
151! Revision 1.1  2000/04/13 14:56:27  schroeter
152! Initial revision
153!
154!
155! Description:
156! ------------
157! Solving the prognostic equations.
158!------------------------------------------------------------------------------!
159
160    USE arrays_3d
161    USE control_parameters
162    USE cpulog
163    USE eqn_state_seawater_mod
164    USE grid_variables
165    USE indices
166    USE interfaces
167    USE pegrid
168    USE pointer_interfaces
169    USE statistics
170    USE advec_ws
171    USE advec_s_pw_mod
172    USE advec_s_up_mod
173    USE advec_u_pw_mod
174    USE advec_u_up_mod
175    USE advec_v_pw_mod
176    USE advec_v_up_mod
177    USE advec_w_pw_mod
178    USE advec_w_up_mod
179    USE buoyancy_mod
180    USE calc_precipitation_mod
181    USE calc_radiation_mod
182    USE coriolis_mod
183    USE diffusion_e_mod
184    USE diffusion_s_mod
185    USE diffusion_u_mod
186    USE diffusion_v_mod
187    USE diffusion_w_mod
188    USE impact_of_latent_heat_mod
189    USE microphysics_mod
190    USE nudge_mod
191    USE plant_canopy_model_mod
192    USE production_e_mod
193    USE subsidence_mod
194    USE user_actions_mod
195
196
197    PRIVATE
198    PUBLIC prognostic_equations_cache, prognostic_equations_vector, &
199           prognostic_equations_acc
200
201    INTERFACE prognostic_equations_cache
202       MODULE PROCEDURE prognostic_equations_cache
203    END INTERFACE prognostic_equations_cache
204
205    INTERFACE prognostic_equations_vector
206       MODULE PROCEDURE prognostic_equations_vector
207    END INTERFACE prognostic_equations_vector
208
209    INTERFACE prognostic_equations_acc
210       MODULE PROCEDURE prognostic_equations_acc
211    END INTERFACE prognostic_equations_acc
212
213
214 CONTAINS
215
216
217 SUBROUTINE prognostic_equations_cache
218
219!------------------------------------------------------------------------------!
220! Version with one optimized loop over all equations. It is only allowed to
221! be called for the Wicker and Skamarock or Piascek-Williams advection scheme.
222!
223! Here the calls of most subroutines are embedded in two DO loops over i and j,
224! so communication between CPUs is not allowed (does not make sense) within
225! these loops.
226!
227! (Optimized to avoid cache missings, i.e. for Power4/5-architectures.)
228!------------------------------------------------------------------------------!
229
230    IMPLICIT NONE
231
232    INTEGER ::  i, i_omp_start, j, k, omp_get_thread_num, tn = 0
233    LOGICAL ::  loop_start
234
235
236!
237!-- Time measurement can only be performed for the whole set of equations
238    CALL cpu_log( log_point(32), 'all progn.equations', 'start' )
239
240!
241!-- Loop over all prognostic equations
242!$OMP PARALLEL private (i,i_omp_start,j,k,loop_start,tn)
243
244!$  tn = omp_get_thread_num()
245    loop_start = .TRUE.
246!$OMP DO
247    DO  i = nxl, nxr
248
249!
250!--    Store the first loop index. It differs for each thread and is required
251!--    later in advec_ws
252       IF ( loop_start )  THEN
253          loop_start  = .FALSE.
254          i_omp_start = i 
255       ENDIF
256 
257       DO  j = nys, nyn
258!
259!--       Tendency terms for u-velocity component
260          IF ( .NOT. outflow_l  .OR.  i > nxl )  THEN
261
262             tend(:,j,i) = 0.0
263             IF ( timestep_scheme(1:5) == 'runge' )  THEN
264                IF ( ws_scheme_mom )  THEN
265                   IF ( ( inflow_l .OR. outflow_l ) .AND. i_omp_start == nxl )  THEN
266                      CALL advec_u_ws( i, j, i_omp_start + 1, tn )
267                   ELSE
268                      CALL advec_u_ws( i, j, i_omp_start, tn )
269                   ENDIF
270                ELSE
271                   CALL advec_u_pw( i, j )
272                ENDIF
273             ELSE
274                CALL advec_u_up( i, j )
275             ENDIF
276             CALL diffusion_u( i, j )
277             CALL coriolis( i, j, 1 )
278             IF ( sloping_surface  .AND.  .NOT. neutral )  THEN
279                CALL buoyancy( i, j, pt, 1 )
280             ENDIF
281
282!
283!--          Drag by plant canopy
284             IF ( plant_canopy )  CALL plant_canopy_model( i, j, 1 )
285
286!
287!--          External pressure gradient
288             IF ( dp_external )  THEN
289                DO  k = dp_level_ind_b+1, nzt
290                   tend(k,j,i) = tend(k,j,i) - dpdxy(1) * dp_smooth_factor(k)
291                ENDDO
292             ENDIF
293
294!
295!--          Nudging
296             IF ( nudging )  CALL nudge( i, j, simulated_time, 'u' ) 
297
298             CALL user_actions( i, j, 'u-tendency' )
299!
300!--          Prognostic equation for u-velocity component
301             DO  k = nzb_u_inner(j,i)+1, nzt
302                u_p(k,j,i) = u(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
303                                                  tsc(3) * tu_m(k,j,i) )       &
304                                      - tsc(5) * rdf(k) * ( u(k,j,i) - ug(k) )
305             ENDDO
306
307!
308!--          Calculate tendencies for the next Runge-Kutta step
309             IF ( timestep_scheme(1:5) == 'runge' )  THEN
310                IF ( intermediate_timestep_count == 1 )  THEN
311                   DO  k = nzb_u_inner(j,i)+1, nzt
312                      tu_m(k,j,i) = tend(k,j,i)
313                   ENDDO
314                ELSEIF ( intermediate_timestep_count < &
315                         intermediate_timestep_count_max )  THEN
316                   DO  k = nzb_u_inner(j,i)+1, nzt
317                      tu_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tu_m(k,j,i)
318                   ENDDO
319                ENDIF
320             ENDIF
321
322          ENDIF
323
324!
325!--       Tendency terms for v-velocity component
326          IF ( .NOT. outflow_s  .OR.  j > nys )  THEN
327
328             tend(:,j,i) = 0.0
329             IF ( timestep_scheme(1:5) == 'runge' )  THEN
330                IF ( ws_scheme_mom )  THEN
331                    CALL advec_v_ws( i, j, i_omp_start, tn )
332                ELSE
333                    CALL advec_v_pw( i, j )
334                ENDIF
335             ELSE
336                CALL advec_v_up( i, j )
337             ENDIF
338             CALL diffusion_v( i, j )
339             CALL coriolis( i, j, 2 )
340
341!
342!--          Drag by plant canopy
343             IF ( plant_canopy )  CALL plant_canopy_model( i, j, 2 )       
344
345!
346!--          External pressure gradient
347             IF ( dp_external )  THEN
348                DO  k = dp_level_ind_b+1, nzt
349                   tend(k,j,i) = tend(k,j,i) - dpdxy(2) * dp_smooth_factor(k)
350                ENDDO
351             ENDIF
352
353!
354!--          Nudging
355             IF ( nudging )  CALL nudge( i, j, simulated_time, 'v' ) 
356
357             CALL user_actions( i, j, 'v-tendency' )
358!
359!--          Prognostic equation for v-velocity component
360             DO  k = nzb_v_inner(j,i)+1, nzt
361                v_p(k,j,i) = v(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
362                                                  tsc(3) * tv_m(k,j,i) )       &
363                                      - tsc(5) * rdf(k) * ( v(k,j,i) - vg(k) )
364             ENDDO
365
366!
367!--          Calculate tendencies for the next Runge-Kutta step
368             IF ( timestep_scheme(1:5) == 'runge' )  THEN
369                IF ( intermediate_timestep_count == 1 )  THEN
370                   DO  k = nzb_v_inner(j,i)+1, nzt
371                      tv_m(k,j,i) = tend(k,j,i)
372                   ENDDO
373                ELSEIF ( intermediate_timestep_count < &
374                         intermediate_timestep_count_max )  THEN
375                   DO  k = nzb_v_inner(j,i)+1, nzt
376                      tv_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tv_m(k,j,i)
377                   ENDDO
378                ENDIF
379             ENDIF
380
381          ENDIF
382
383!
384!--       Tendency terms for w-velocity component
385          tend(:,j,i) = 0.0
386          IF ( timestep_scheme(1:5) == 'runge' )  THEN
387             IF ( ws_scheme_mom )  THEN
388                CALL advec_w_ws( i, j, i_omp_start, tn )
389             ELSE
390                CALL advec_w_pw( i, j )
391             END IF
392          ELSE
393             CALL advec_w_up( i, j )
394          ENDIF
395          CALL diffusion_w( i, j )
396          CALL coriolis( i, j, 3 )
397
398          IF ( .NOT. neutral )  THEN
399             IF ( ocean )  THEN
400                CALL buoyancy( i, j, rho, 3 )
401             ELSE
402                IF ( .NOT. humidity )  THEN
403                   CALL buoyancy( i, j, pt, 3 )
404                ELSE
405                   CALL buoyancy( i, j, vpt, 3 )
406                ENDIF
407             ENDIF
408          ENDIF
409
410!
411!--       Drag by plant canopy
412          IF ( plant_canopy )  CALL plant_canopy_model( i, j, 3 )
413
414          CALL user_actions( i, j, 'w-tendency' )
415
416!
417!--       Prognostic equation for w-velocity component
418          DO  k = nzb_w_inner(j,i)+1, nzt-1
419             w_p(k,j,i) = w(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +          &
420                                               tsc(3) * tw_m(k,j,i) )          &
421                                   - tsc(5) * rdf(k) * w(k,j,i)
422          ENDDO
423
424!
425!--       Calculate tendencies for the next Runge-Kutta step
426          IF ( timestep_scheme(1:5) == 'runge' )  THEN
427             IF ( intermediate_timestep_count == 1 )  THEN
428                DO  k = nzb_w_inner(j,i)+1, nzt-1
429                   tw_m(k,j,i) = tend(k,j,i)
430                ENDDO
431             ELSEIF ( intermediate_timestep_count < &
432                      intermediate_timestep_count_max )  THEN
433                DO  k = nzb_w_inner(j,i)+1, nzt-1
434                   tw_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tw_m(k,j,i)
435                ENDDO
436             ENDIF
437          ENDIF
438!
439!--       If required, calculate tendencies for total water content, liquid water
440!--       potential temperature, rain water content and rain drop concentration
441          IF ( cloud_physics  .AND.  icloud_scheme == 0 )  CALL microphysics_control( i, j )
442!
443!--       If required, compute prognostic equation for potential temperature
444          IF ( .NOT. neutral )  THEN
445!
446!--          Tendency terms for potential temperature
447             tend(:,j,i) = 0.0
448             IF ( timestep_scheme(1:5) == 'runge' )  THEN
449                   IF ( ws_scheme_sca )  THEN
450                      CALL advec_s_ws( i, j, pt, 'pt', flux_s_pt, diss_s_pt, &
451                                       flux_l_pt, diss_l_pt, i_omp_start, tn )
452                   ELSE
453                      CALL advec_s_pw( i, j, pt )
454                   ENDIF
455             ELSE
456                CALL advec_s_up( i, j, pt )
457             ENDIF
458             CALL diffusion_s( i, j, pt, shf, tswst, wall_heatflux )
459
460!
461!--          If required compute heating/cooling due to long wave radiation
462!--          processes
463             IF ( radiation )  THEN
464                CALL calc_radiation( i, j )
465             ENDIF
466
467!
468!--          Using microphysical tendencies (latent heat)
469             IF ( cloud_physics )  THEN
470                IF ( icloud_scheme == 0 )  THEN
471                   tend(:,j,i) = tend(:,j,i) + tend_pt(:,j,i)
472                ELSEIF ( icloud_scheme == 1  .AND.  precipitation )  THEN
473                   CALL impact_of_latent_heat( i, j ) 
474                ENDIF
475             ENDIF
476
477!
478!--          Consideration of heat sources within the plant canopy
479             IF ( plant_canopy  .AND.  cthf /= 0.0 )  THEN
480                CALL plant_canopy_model( i, j, 4 )
481             ENDIF
482
483!
484!--          If required, compute effect of large-scale subsidence/ascent
485             IF ( large_scale_subsidence )  THEN
486                CALL subsidence( i, j, tend, pt, pt_init )
487             ENDIF
488
489!
490!--          Nudging
491             IF ( nudging )  CALL nudge( i, j, simulated_time, 'pt' ) 
492
493             CALL user_actions( i, j, 'pt-tendency' )
494
495!
496!--          Prognostic equation for potential temperature
497             DO  k = nzb_s_inner(j,i)+1, nzt
498                pt_p(k,j,i) = pt(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +     &
499                                                    tsc(3) * tpt_m(k,j,i) )    &
500                                        - tsc(5) * ( pt(k,j,i) - pt_init(k) ) *&
501                                          ( rdf_sc(k) + ptdf_x(i) + ptdf_y(j) )
502             ENDDO
503
504!
505!--          Calculate tendencies for the next Runge-Kutta step
506             IF ( timestep_scheme(1:5) == 'runge' )  THEN
507                IF ( intermediate_timestep_count == 1 )  THEN
508                   DO  k = nzb_s_inner(j,i)+1, nzt
509                      tpt_m(k,j,i) = tend(k,j,i)
510                   ENDDO
511                ELSEIF ( intermediate_timestep_count < &
512                         intermediate_timestep_count_max )  THEN
513                   DO  k = nzb_s_inner(j,i)+1, nzt
514                      tpt_m(k,j,i) = -9.5625 * tend(k,j,i) + &
515                                      5.3125 * tpt_m(k,j,i)
516                   ENDDO
517                ENDIF
518             ENDIF
519
520          ENDIF
521
522!
523!--       If required, compute prognostic equation for salinity
524          IF ( ocean )  THEN
525
526!
527!--          Tendency-terms for salinity
528             tend(:,j,i) = 0.0
529             IF ( timestep_scheme(1:5) == 'runge' ) &
530             THEN
531                IF ( ws_scheme_sca )  THEN
532                    CALL advec_s_ws( i, j, sa, 'sa', flux_s_sa,  &
533                                diss_s_sa, flux_l_sa, diss_l_sa, i_omp_start, tn  )
534                ELSE
535                    CALL advec_s_pw( i, j, sa )
536                ENDIF
537             ELSE
538                CALL advec_s_up( i, j, sa )
539             ENDIF
540             CALL diffusion_s( i, j, sa, saswsb, saswst, wall_salinityflux )
541
542             CALL user_actions( i, j, 'sa-tendency' )
543
544!
545!--          Prognostic equation for salinity
546             DO  k = nzb_s_inner(j,i)+1, nzt
547                sa_p(k,j,i) = sa(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +     &
548                                                    tsc(3) * tsa_m(k,j,i) )    &
549                                        - tsc(5) * rdf_sc(k) *                 &
550                                          ( sa(k,j,i) - sa_init(k) )
551                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
552             ENDDO
553
554!
555!--          Calculate tendencies for the next Runge-Kutta step
556             IF ( timestep_scheme(1:5) == 'runge' )  THEN
557                IF ( intermediate_timestep_count == 1 )  THEN
558                   DO  k = nzb_s_inner(j,i)+1, nzt
559                      tsa_m(k,j,i) = tend(k,j,i)
560                   ENDDO
561                ELSEIF ( intermediate_timestep_count < &
562                         intermediate_timestep_count_max )  THEN
563                   DO  k = nzb_s_inner(j,i)+1, nzt
564                      tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
565                                      5.3125 * tsa_m(k,j,i)
566                   ENDDO
567                ENDIF
568             ENDIF
569
570!
571!--          Calculate density by the equation of state for seawater
572             CALL eqn_state_seawater( i, j )
573
574          ENDIF
575
576!
577!--       If required, compute prognostic equation for total water content /
578!--       scalar
579          IF ( humidity  .OR.  passive_scalar )  THEN
580
581!
582!--          Tendency-terms for total water content / scalar
583             tend(:,j,i) = 0.0
584             IF ( timestep_scheme(1:5) == 'runge' ) &
585             THEN
586                IF ( ws_scheme_sca )  THEN
587                   CALL advec_s_ws( i, j, q, 'q', flux_s_q, & 
588                                diss_s_q, flux_l_q, diss_l_q, i_omp_start, tn )
589                ELSE
590                   CALL advec_s_pw( i, j, q )
591                ENDIF
592             ELSE
593                CALL advec_s_up( i, j, q )
594             ENDIF
595             CALL diffusion_s( i, j, q, qsws, qswst, wall_qflux )
596     
597!
598!--          Using microphysical tendencies
599             IF ( cloud_physics )  THEN
600                IF ( icloud_scheme == 0 )  THEN
601                   tend(:,j,i) = tend(:,j,i) + tend_q(:,j,i)
602                ELSEIF ( icloud_scheme == 1  .AND.  precipitation )  THEN
603                   CALL calc_precipitation( i, j )
604                ENDIF
605             ENDIF
606!
607!--          Sink or source of scalar concentration due to canopy elements
608             IF ( plant_canopy )  CALL plant_canopy_model( i, j, 5 )
609
610!
611!--          If required compute influence of large-scale subsidence/ascent
612             IF ( large_scale_subsidence )  THEN
613                CALL subsidence( i, j, tend, q, q_init )
614             ENDIF
615
616!
617!--          Nudging
618             IF ( nudging )  CALL nudge( i, j, simulated_time, 'q' ) 
619
620             CALL user_actions( i, j, 'q-tendency' )
621
622!
623!--          Prognostic equation for total water content / scalar
624             DO  k = nzb_s_inner(j,i)+1, nzt
625                q_p(k,j,i) = q(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
626                                                  tsc(3) * tq_m(k,j,i) )       &
627                                      - tsc(5) * rdf_sc(k) *                   &
628                                        ( q(k,j,i) - q_init(k) )
629                IF ( q_p(k,j,i) < 0.0 )  q_p(k,j,i) = 0.1 * q(k,j,i)
630             ENDDO
631
632!
633!--          Calculate tendencies for the next Runge-Kutta step
634             IF ( timestep_scheme(1:5) == 'runge' )  THEN
635                IF ( intermediate_timestep_count == 1 )  THEN
636                   DO  k = nzb_s_inner(j,i)+1, nzt
637                      tq_m(k,j,i) = tend(k,j,i)
638                   ENDDO
639                ELSEIF ( intermediate_timestep_count < &
640                         intermediate_timestep_count_max )  THEN
641                   DO  k = nzb_s_inner(j,i)+1, nzt
642                      tq_m(k,j,i) = -9.5625 * tend(k,j,i) + &
643                                     5.3125 * tq_m(k,j,i)
644                   ENDDO
645                ENDIF
646             ENDIF
647
648!
649!--          If required, calculate prognostic equations for rain water content
650!--          and rain drop concentration
651             IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.              &
652                  precipitation )  THEN
653!
654!--             Calculate prognostic equation for rain water content
655                tend(:,j,i) = 0.0
656                IF ( timestep_scheme(1:5) == 'runge' ) &
657                THEN
658                   IF ( ws_scheme_sca )  THEN
659                      CALL advec_s_ws( i, j, qr, 'qr', flux_s_qr,       & 
660                                       diss_s_qr, flux_l_qr, diss_l_qr, &
661                                       i_omp_start, tn )
662                   ELSE
663                      CALL advec_s_pw( i, j, qr )
664                   ENDIF
665                ELSE
666                   CALL advec_s_up( i, j, qr )
667                ENDIF
668                CALL diffusion_s( i, j, qr, qrsws, qrswst, wall_qrflux )
669!
670!--             Using microphysical tendencies (autoconversion, accretion,
671!--             evaporation; if required: sedimentation)
672                tend(:,j,i) = tend(:,j,i) + tend_qr(:,j,i)
673
674                CALL user_actions( i, j, 'qr-tendency' )
675!
676!--             Prognostic equation for rain water content
677                DO  k = nzb_s_inner(j,i)+1, nzt
678                   qr_p(k,j,i) = qr(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +  &
679                                                       tsc(3) * tqr_m(k,j,i) ) &
680                                           - tsc(5) * rdf_sc(k) * qr(k,j,i)
681                   IF ( qr_p(k,j,i) < 0.0 )  qr_p(k,j,i) = 0.0
682                ENDDO
683!
684!--             Calculate tendencies for the next Runge-Kutta step
685                IF ( timestep_scheme(1:5) == 'runge' )  THEN
686                   IF ( intermediate_timestep_count == 1 )  THEN
687                      DO  k = nzb_s_inner(j,i)+1, nzt
688                         tqr_m(k,j,i) = tend(k,j,i)
689                      ENDDO
690                   ELSEIF ( intermediate_timestep_count < &
691                            intermediate_timestep_count_max )  THEN
692                      DO  k = nzb_s_inner(j,i)+1, nzt
693                         tqr_m(k,j,i) = -9.5625 * tend(k,j,i) + &
694                                        5.3125 * tqr_m(k,j,i)
695                      ENDDO
696                   ENDIF
697                ENDIF
698
699!
700!--             Calculate prognostic equation for rain drop concentration.
701                tend(:,j,i) = 0.0
702                IF ( timestep_scheme(1:5) == 'runge' )  THEN
703                   IF ( ws_scheme_sca )  THEN
704                      CALL advec_s_ws( i, j, nr, 'nr', flux_s_nr,    & 
705                                    diss_s_nr, flux_l_nr, diss_l_nr, &
706                                    i_omp_start, tn )
707                   ELSE
708                      CALL advec_s_pw( i, j, nr )
709                   ENDIF
710                ELSE
711                   CALL advec_s_up( i, j, nr )
712                ENDIF
713                CALL diffusion_s( i, j, nr, nrsws, nrswst, wall_nrflux )
714!
715!--             Using microphysical tendencies (autoconversion, accretion,
716!--             selfcollection, breakup, evaporation;
717!--             if required: sedimentation)
718                tend(:,j,i) = tend(:,j,i) + tend_nr(:,j,i)
719
720                CALL user_actions( i, j, 'nr-tendency' )
721!
722!--             Prognostic equation for rain drop concentration
723                DO  k = nzb_s_inner(j,i)+1, nzt
724                   nr_p(k,j,i) = nr(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +  &
725                                                       tsc(3) * tnr_m(k,j,i) ) &
726                                           - tsc(5) * rdf_sc(k) * nr(k,j,i)
727                   IF ( nr_p(k,j,i) < 0.0 )  nr_p(k,j,i) = 0.0
728                ENDDO
729!
730!--             Calculate tendencies for the next Runge-Kutta step
731                IF ( timestep_scheme(1:5) == 'runge' )  THEN
732                   IF ( intermediate_timestep_count == 1 )  THEN
733                      DO  k = nzb_s_inner(j,i)+1, nzt
734                         tnr_m(k,j,i) = tend(k,j,i)
735                      ENDDO
736                   ELSEIF ( intermediate_timestep_count < &
737                            intermediate_timestep_count_max )  THEN
738                      DO  k = nzb_s_inner(j,i)+1, nzt
739                         tnr_m(k,j,i) = -9.5625 * tend(k,j,i) + &
740                                        5.3125 * tnr_m(k,j,i)
741                      ENDDO
742                   ENDIF
743                ENDIF
744
745             ENDIF
746
747          ENDIF
748
749!
750!--       If required, compute prognostic equation for turbulent kinetic
751!--       energy (TKE)
752          IF ( .NOT. constant_diffusion )  THEN
753
754!
755!--          Tendency-terms for TKE
756             tend(:,j,i) = 0.0
757             IF ( timestep_scheme(1:5) == 'runge'  &
758                 .AND.  .NOT. use_upstream_for_tke )  THEN
759                 IF ( ws_scheme_sca )  THEN
760                     CALL advec_s_ws( i, j, e, 'e', flux_s_e, diss_s_e, &
761                                      flux_l_e, diss_l_e , i_omp_start, tn )
762                 ELSE
763                     CALL advec_s_pw( i, j, e )
764                 ENDIF
765             ELSE
766                CALL advec_s_up( i, j, e )
767             ENDIF
768             IF ( .NOT. humidity )  THEN
769                IF ( ocean )  THEN
770                   CALL diffusion_e( i, j, prho, prho_reference )
771                ELSE
772                   CALL diffusion_e( i, j, pt, pt_reference )
773                ENDIF
774             ELSE
775                CALL diffusion_e( i, j, vpt, pt_reference )
776             ENDIF
777             CALL production_e( i, j )
778
779!
780!--          Additional sink term for flows through plant canopies
781             IF ( plant_canopy )  CALL plant_canopy_model( i, j, 6 ) 
782
783             CALL user_actions( i, j, 'e-tendency' )
784
785!
786!--          Prognostic equation for TKE.
787!--          Eliminate negative TKE values, which can occur due to numerical
788!--          reasons in the course of the integration. In such cases the old
789!--          TKE value is reduced by 90%.
790             DO  k = nzb_s_inner(j,i)+1, nzt
791                e_p(k,j,i) = e(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
792                                                  tsc(3) * te_m(k,j,i) )
793                IF ( e_p(k,j,i) < 0.0 )  e_p(k,j,i) = 0.1 * e(k,j,i)
794             ENDDO
795
796!
797!--          Calculate tendencies for the next Runge-Kutta step
798             IF ( timestep_scheme(1:5) == 'runge' )  THEN
799                IF ( intermediate_timestep_count == 1 )  THEN
800                   DO  k = nzb_s_inner(j,i)+1, nzt
801                      te_m(k,j,i) = tend(k,j,i)
802                   ENDDO
803                ELSEIF ( intermediate_timestep_count < &
804                         intermediate_timestep_count_max )  THEN
805                   DO  k = nzb_s_inner(j,i)+1, nzt
806                      te_m(k,j,i) = -9.5625 * tend(k,j,i) + &
807                                     5.3125 * te_m(k,j,i)
808                   ENDDO
809                ENDIF
810             ENDIF
811
812          ENDIF   ! TKE equation
813
814       ENDDO
815    ENDDO
816!$OMP END PARALLEL
817
818    CALL cpu_log( log_point(32), 'all progn.equations', 'stop' )
819
820
821 END SUBROUTINE prognostic_equations_cache
822
823
824 SUBROUTINE prognostic_equations_vector
825
826!------------------------------------------------------------------------------!
827! Version for vector machines
828!------------------------------------------------------------------------------!
829
830    IMPLICIT NONE
831
832    INTEGER ::  i, j, k
833    REAL    ::  sbt
834
835
836!
837!-- u-velocity component
838    CALL cpu_log( log_point(5), 'u-equation', 'start' )
839
840    tend = 0.0
841    IF ( timestep_scheme(1:5) == 'runge' )  THEN
842       IF ( ws_scheme_mom )  THEN
843          CALL advec_u_ws
844       ELSE
845          CALL advec_u_pw
846       ENDIF
847    ELSE
848       CALL advec_u_up
849    ENDIF
850    CALL diffusion_u
851    CALL coriolis( 1 )
852    IF ( sloping_surface  .AND.  .NOT. neutral )  THEN
853       CALL buoyancy( pt, 1 )
854    ENDIF
855
856!
857!-- Drag by plant canopy
858    IF ( plant_canopy )  CALL plant_canopy_model( 1 )
859
860!
861!-- External pressure gradient
862    IF ( dp_external )  THEN
863       DO  i = nxlu, nxr
864          DO  j = nys, nyn
865             DO  k = dp_level_ind_b+1, nzt
866                tend(k,j,i) = tend(k,j,i) - dpdxy(1) * dp_smooth_factor(k)
867             ENDDO
868          ENDDO
869       ENDDO
870    ENDIF
871
872!
873!-- Nudging
874    IF ( nudging )  CALL nudge( simulated_time, 'u' ) 
875
876    CALL user_actions( 'u-tendency' )
877
878!
879!-- Prognostic equation for u-velocity component
880    DO  i = nxlu, nxr
881       DO  j = nys, nyn
882          DO  k = nzb_u_inner(j,i)+1, nzt
883             u_p(k,j,i) = u(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +          &
884                                               tsc(3) * tu_m(k,j,i) )          &
885                                   - tsc(5) * rdf(k) * ( u(k,j,i) - ug(k) )
886          ENDDO
887       ENDDO
888    ENDDO
889
890!
891!-- Calculate tendencies for the next Runge-Kutta step
892    IF ( timestep_scheme(1:5) == 'runge' )  THEN
893       IF ( intermediate_timestep_count == 1 )  THEN
894          DO  i = nxlu, nxr
895             DO  j = nys, nyn
896                DO  k = nzb_u_inner(j,i)+1, nzt
897                   tu_m(k,j,i) = tend(k,j,i)
898                ENDDO
899             ENDDO
900          ENDDO
901       ELSEIF ( intermediate_timestep_count < &
902                intermediate_timestep_count_max )  THEN
903          DO  i = nxlu, nxr
904             DO  j = nys, nyn
905                DO  k = nzb_u_inner(j,i)+1, nzt
906                   tu_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tu_m(k,j,i)
907                ENDDO
908             ENDDO
909          ENDDO
910       ENDIF
911    ENDIF
912
913    CALL cpu_log( log_point(5), 'u-equation', 'stop' )
914
915!
916!-- v-velocity component
917    CALL cpu_log( log_point(6), 'v-equation', 'start' )
918
919    tend = 0.0
920    IF ( timestep_scheme(1:5) == 'runge' )  THEN
921       IF ( ws_scheme_mom )  THEN
922          CALL advec_v_ws
923       ELSE
924          CALL advec_v_pw
925       END IF
926    ELSE
927       CALL advec_v_up
928    ENDIF
929    CALL diffusion_v
930    CALL coriolis( 2 )
931
932!
933!-- Drag by plant canopy
934    IF ( plant_canopy )  CALL plant_canopy_model( 2 )
935
936!
937!-- External pressure gradient
938    IF ( dp_external )  THEN
939       DO  i = nxl, nxr
940          DO  j = nysv, nyn
941             DO  k = dp_level_ind_b+1, nzt
942                tend(k,j,i) = tend(k,j,i) - dpdxy(2) * dp_smooth_factor(k)
943             ENDDO
944          ENDDO
945       ENDDO
946    ENDIF
947
948!
949!-- Nudging
950    IF ( nudging )  CALL nudge( simulated_time, 'v' ) 
951
952    CALL user_actions( 'v-tendency' )
953
954!
955!-- Prognostic equation for v-velocity component
956    DO  i = nxl, nxr
957       DO  j = nysv, nyn
958          DO  k = nzb_v_inner(j,i)+1, nzt
959             v_p(k,j,i) = v(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +          &
960                                               tsc(3) * tv_m(k,j,i) )          &
961                                   - tsc(5) * rdf(k) * ( v(k,j,i) - vg(k) )
962          ENDDO
963       ENDDO
964    ENDDO
965
966!
967!-- Calculate tendencies for the next Runge-Kutta step
968    IF ( timestep_scheme(1:5) == 'runge' )  THEN
969       IF ( intermediate_timestep_count == 1 )  THEN
970          DO  i = nxl, nxr
971             DO  j = nysv, nyn
972                DO  k = nzb_v_inner(j,i)+1, nzt
973                   tv_m(k,j,i) = tend(k,j,i)
974                ENDDO
975             ENDDO
976          ENDDO
977       ELSEIF ( intermediate_timestep_count < &
978                intermediate_timestep_count_max )  THEN
979          DO  i = nxl, nxr
980             DO  j = nysv, nyn
981                DO  k = nzb_v_inner(j,i)+1, nzt
982                   tv_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tv_m(k,j,i)
983                ENDDO
984             ENDDO
985          ENDDO
986       ENDIF
987    ENDIF
988
989    CALL cpu_log( log_point(6), 'v-equation', 'stop' )
990
991!
992!-- w-velocity component
993    CALL cpu_log( log_point(7), 'w-equation', 'start' )
994
995    tend = 0.0
996    IF ( timestep_scheme(1:5) == 'runge' )  THEN
997       IF ( ws_scheme_mom )  THEN
998          CALL advec_w_ws
999       ELSE
1000          CALL advec_w_pw
1001       ENDIF
1002    ELSE
1003       CALL advec_w_up
1004    ENDIF
1005    CALL diffusion_w
1006    CALL coriolis( 3 )
1007
1008    IF ( .NOT. neutral )  THEN
1009       IF ( ocean )  THEN
1010          CALL buoyancy( rho, 3 )
1011       ELSE
1012          IF ( .NOT. humidity )  THEN
1013             CALL buoyancy( pt, 3 )
1014          ELSE
1015             CALL buoyancy( vpt, 3 )
1016          ENDIF
1017       ENDIF
1018    ENDIF
1019
1020!
1021!-- Drag by plant canopy
1022    IF ( plant_canopy )  CALL plant_canopy_model( 3 )
1023
1024    CALL user_actions( 'w-tendency' )
1025
1026!
1027!-- Prognostic equation for w-velocity component
1028    DO  i = nxl, nxr
1029       DO  j = nys, nyn
1030          DO  k = nzb_w_inner(j,i)+1, nzt-1
1031             w_p(k,j,i) = w(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +          &
1032                                               tsc(3) * tw_m(k,j,i) )          &
1033                                   - tsc(5) * rdf(k) * w(k,j,i)
1034          ENDDO
1035       ENDDO
1036    ENDDO
1037
1038!
1039!-- Calculate tendencies for the next Runge-Kutta step
1040    IF ( timestep_scheme(1:5) == 'runge' )  THEN
1041       IF ( intermediate_timestep_count == 1 )  THEN
1042          DO  i = nxl, nxr
1043             DO  j = nys, nyn
1044                DO  k = nzb_w_inner(j,i)+1, nzt-1
1045                   tw_m(k,j,i) = tend(k,j,i)
1046                ENDDO
1047             ENDDO
1048          ENDDO
1049       ELSEIF ( intermediate_timestep_count < &
1050                intermediate_timestep_count_max )  THEN
1051          DO  i = nxl, nxr
1052             DO  j = nys, nyn
1053                DO  k = nzb_w_inner(j,i)+1, nzt-1
1054                   tw_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tw_m(k,j,i)
1055                ENDDO
1056             ENDDO
1057          ENDDO
1058       ENDIF
1059    ENDIF
1060
1061    CALL cpu_log( log_point(7), 'w-equation', 'stop' )
1062
1063
1064!
1065!-- If required, compute prognostic equation for potential temperature
1066    IF ( .NOT. neutral )  THEN
1067
1068       CALL cpu_log( log_point(13), 'pt-equation', 'start' )
1069
1070!
1071!--    pt-tendency terms with communication
1072       sbt = tsc(2)
1073       IF ( scalar_advec == 'bc-scheme' )  THEN
1074
1075          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1076!
1077!--          Bott-Chlond scheme always uses Euler time step. Thus:
1078             sbt = 1.0
1079          ENDIF
1080          tend = 0.0
1081          CALL advec_s_bc( pt, 'pt' )
1082
1083       ENDIF
1084
1085!
1086!--    pt-tendency terms with no communication
1087       IF ( scalar_advec /= 'bc-scheme' )  THEN
1088          tend = 0.0
1089          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1090             IF ( ws_scheme_sca )  THEN
1091                CALL advec_s_ws( pt, 'pt' )
1092             ELSE
1093                CALL advec_s_pw( pt )
1094             ENDIF
1095          ELSE
1096             CALL advec_s_up( pt )
1097          ENDIF
1098       ENDIF
1099
1100       CALL diffusion_s( pt, shf, tswst, wall_heatflux )
1101
1102!
1103!--    If required compute heating/cooling due to long wave radiation processes
1104       IF ( radiation )  THEN
1105          CALL calc_radiation
1106       ENDIF
1107
1108!
1109!--    If required compute impact of latent heat due to precipitation
1110       IF ( precipitation )  THEN
1111          CALL impact_of_latent_heat
1112       ENDIF
1113
1114!
1115!--    Consideration of heat sources within the plant canopy
1116       IF ( plant_canopy .AND. ( cthf /= 0.0 ) ) THEN
1117          CALL plant_canopy_model( 4 )
1118       ENDIF
1119
1120!
1121!--    If required compute influence of large-scale subsidence/ascent
1122       IF ( large_scale_subsidence )  THEN
1123          CALL subsidence( tend, pt, pt_init )
1124       ENDIF
1125
1126!
1127!--    Nudging
1128       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
1129
1130       CALL user_actions( 'pt-tendency' )
1131
1132!
1133!--    Prognostic equation for potential temperature
1134       DO  i = nxl, nxr
1135          DO  j = nys, nyn
1136             DO  k = nzb_s_inner(j,i)+1, nzt
1137                pt_p(k,j,i) = pt(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +        &
1138                                                    tsc(3) * tpt_m(k,j,i) )    &
1139                                        - tsc(5) * ( pt(k,j,i) - pt_init(k) ) *&
1140                                          ( rdf_sc(k) + ptdf_x(i) + ptdf_y(j) )
1141             ENDDO
1142          ENDDO
1143       ENDDO
1144
1145!
1146!--    Calculate tendencies for the next Runge-Kutta step
1147       IF ( timestep_scheme(1:5) == 'runge' )  THEN
1148          IF ( intermediate_timestep_count == 1 )  THEN
1149             DO  i = nxl, nxr
1150                DO  j = nys, nyn
1151                   DO  k = nzb_s_inner(j,i)+1, nzt
1152                      tpt_m(k,j,i) = tend(k,j,i)
1153                   ENDDO
1154                ENDDO
1155             ENDDO
1156          ELSEIF ( intermediate_timestep_count < &
1157                   intermediate_timestep_count_max )  THEN
1158             DO  i = nxl, nxr
1159                DO  j = nys, nyn
1160                   DO  k = nzb_s_inner(j,i)+1, nzt
1161                      tpt_m(k,j,i) = -9.5625 * tend(k,j,i) + &
1162                                      5.3125 * tpt_m(k,j,i)
1163                   ENDDO
1164                ENDDO
1165             ENDDO
1166          ENDIF
1167       ENDIF
1168
1169       CALL cpu_log( log_point(13), 'pt-equation', 'stop' )
1170
1171    ENDIF
1172
1173!
1174!-- If required, compute prognostic equation for salinity
1175    IF ( ocean )  THEN
1176
1177       CALL cpu_log( log_point(37), 'sa-equation', 'start' )
1178
1179!
1180!--    sa-tendency terms with communication
1181       sbt = tsc(2)
1182       IF ( scalar_advec == 'bc-scheme' )  THEN
1183
1184          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1185!
1186!--          Bott-Chlond scheme always uses Euler time step. Thus:
1187             sbt = 1.0
1188          ENDIF
1189          tend = 0.0
1190          CALL advec_s_bc( sa, 'sa' )
1191
1192       ENDIF
1193
1194!
1195!--    sa-tendency terms with no communication
1196       IF ( scalar_advec /= 'bc-scheme' )  THEN
1197          tend = 0.0
1198          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1199             IF ( ws_scheme_sca )  THEN
1200                 CALL advec_s_ws( sa, 'sa' )
1201             ELSE
1202                 CALL advec_s_pw( sa )
1203             ENDIF
1204          ELSE
1205             CALL advec_s_up( sa )
1206          ENDIF
1207       ENDIF
1208
1209       CALL diffusion_s( sa, saswsb, saswst, wall_salinityflux )
1210       
1211       CALL user_actions( 'sa-tendency' )
1212
1213!
1214!--    Prognostic equation for salinity
1215       DO  i = nxl, nxr
1216          DO  j = nys, nyn
1217             DO  k = nzb_s_inner(j,i)+1, nzt
1218                sa_p(k,j,i) = sa(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +        &
1219                                                    tsc(3) * tsa_m(k,j,i) )    &
1220                                        - tsc(5) * rdf_sc(k) *                 &
1221                                          ( sa(k,j,i) - sa_init(k) )
1222                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
1223             ENDDO
1224          ENDDO
1225       ENDDO
1226
1227!
1228!--    Calculate tendencies for the next Runge-Kutta step
1229       IF ( timestep_scheme(1:5) == 'runge' )  THEN
1230          IF ( intermediate_timestep_count == 1 )  THEN
1231             DO  i = nxl, nxr
1232                DO  j = nys, nyn
1233                   DO  k = nzb_s_inner(j,i)+1, nzt
1234                      tsa_m(k,j,i) = tend(k,j,i)
1235                   ENDDO
1236                ENDDO
1237             ENDDO
1238          ELSEIF ( intermediate_timestep_count < &
1239                   intermediate_timestep_count_max )  THEN
1240             DO  i = nxl, nxr
1241                DO  j = nys, nyn
1242                   DO  k = nzb_s_inner(j,i)+1, nzt
1243                      tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + &
1244                                      5.3125 * tsa_m(k,j,i)
1245                   ENDDO
1246                ENDDO
1247             ENDDO
1248          ENDIF
1249       ENDIF
1250
1251       CALL cpu_log( log_point(37), 'sa-equation', 'stop' )
1252
1253!
1254!--    Calculate density by the equation of state for seawater
1255       CALL cpu_log( log_point(38), 'eqns-seawater', 'start' )
1256       CALL eqn_state_seawater
1257       CALL cpu_log( log_point(38), 'eqns-seawater', 'stop' )
1258
1259    ENDIF
1260
1261!
1262!-- If required, compute prognostic equation for total water content / scalar
1263    IF ( humidity  .OR.  passive_scalar )  THEN
1264
1265       CALL cpu_log( log_point(29), 'q/s-equation', 'start' )
1266
1267!
1268!--    Scalar/q-tendency terms with communication
1269       sbt = tsc(2)
1270       IF ( scalar_advec == 'bc-scheme' )  THEN
1271
1272          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1273!
1274!--          Bott-Chlond scheme always uses Euler time step. Thus:
1275             sbt = 1.0
1276          ENDIF
1277          tend = 0.0
1278          CALL advec_s_bc( q, 'q' )
1279
1280       ENDIF
1281
1282!
1283!--    Scalar/q-tendency terms with no communication
1284       IF ( scalar_advec /= 'bc-scheme' )  THEN
1285          tend = 0.0
1286          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1287             IF ( ws_scheme_sca )  THEN
1288                CALL advec_s_ws( q, 'q' )
1289             ELSE
1290                CALL advec_s_pw( q )
1291             ENDIF
1292          ELSE
1293             CALL advec_s_up( q )
1294          ENDIF
1295       ENDIF
1296
1297       CALL diffusion_s( q, qsws, qswst, wall_qflux )
1298       
1299!
1300!--    If required compute decrease of total water content due to
1301!--    precipitation
1302       IF ( precipitation )  THEN
1303          CALL calc_precipitation
1304       ENDIF
1305
1306!
1307!--    Sink or source of scalar concentration due to canopy elements
1308       IF ( plant_canopy ) CALL plant_canopy_model( 5 )
1309       
1310!
1311!--    If required compute influence of large-scale subsidence/ascent
1312       IF ( large_scale_subsidence )  THEN
1313         CALL subsidence( tend, q, q_init )
1314       ENDIF
1315
1316!
1317!--    Nudging
1318       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
1319
1320       CALL user_actions( 'q-tendency' )
1321
1322!
1323!--    Prognostic equation for total water content / scalar
1324       DO  i = nxl, nxr
1325          DO  j = nys, nyn
1326             DO  k = nzb_s_inner(j,i)+1, nzt
1327                q_p(k,j,i) = q(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +          &
1328                                                  tsc(3) * tq_m(k,j,i) )       &
1329                                      - tsc(5) * rdf_sc(k) *                   &
1330                                        ( q(k,j,i) - q_init(k) )
1331                IF ( q_p(k,j,i) < 0.0 )  q_p(k,j,i) = 0.1 * q(k,j,i)
1332             ENDDO
1333          ENDDO
1334       ENDDO
1335
1336!
1337!--    Calculate tendencies for the next Runge-Kutta step
1338       IF ( timestep_scheme(1:5) == 'runge' )  THEN
1339          IF ( intermediate_timestep_count == 1 )  THEN
1340             DO  i = nxl, nxr
1341                DO  j = nys, nyn
1342                   DO  k = nzb_s_inner(j,i)+1, nzt
1343                      tq_m(k,j,i) = tend(k,j,i)
1344                   ENDDO
1345                ENDDO
1346             ENDDO
1347          ELSEIF ( intermediate_timestep_count < &
1348                   intermediate_timestep_count_max )  THEN
1349             DO  i = nxl, nxr
1350                DO  j = nys, nyn
1351                   DO  k = nzb_s_inner(j,i)+1, nzt
1352                      tq_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tq_m(k,j,i)
1353                   ENDDO
1354                ENDDO
1355             ENDDO
1356          ENDIF
1357       ENDIF
1358
1359       CALL cpu_log( log_point(29), 'q/s-equation', 'stop' )
1360
1361    ENDIF
1362
1363!
1364!-- If required, compute prognostic equation for turbulent kinetic
1365!-- energy (TKE)
1366    IF ( .NOT. constant_diffusion )  THEN
1367
1368       CALL cpu_log( log_point(16), 'tke-equation', 'start' )
1369
1370       sbt = tsc(2)
1371       IF ( .NOT. use_upstream_for_tke )  THEN
1372          IF ( scalar_advec == 'bc-scheme' )  THEN
1373
1374             IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1375!
1376!--             Bott-Chlond scheme always uses Euler time step. Thus:
1377                sbt = 1.0
1378             ENDIF
1379             tend = 0.0
1380             CALL advec_s_bc( e, 'e' )
1381
1382          ENDIF
1383       ENDIF
1384
1385!
1386!--    TKE-tendency terms with no communication
1387       IF ( scalar_advec /= 'bc-scheme'  .OR.  use_upstream_for_tke )  THEN
1388          IF ( use_upstream_for_tke )  THEN
1389             tend = 0.0
1390             CALL advec_s_up( e )
1391          ELSE
1392             tend = 0.0
1393             IF ( timestep_scheme(1:5) == 'runge' )  THEN
1394                IF ( ws_scheme_sca )  THEN
1395                   CALL advec_s_ws( e, 'e' )
1396                ELSE
1397                   CALL advec_s_pw( e )
1398                ENDIF
1399             ELSE
1400                CALL advec_s_up( e )
1401             ENDIF
1402          ENDIF
1403       ENDIF
1404
1405       IF ( .NOT. humidity )  THEN
1406          IF ( ocean )  THEN
1407             CALL diffusion_e( prho, prho_reference )
1408          ELSE
1409             CALL diffusion_e( pt, pt_reference )
1410          ENDIF
1411       ELSE
1412          CALL diffusion_e( vpt, pt_reference )
1413       ENDIF
1414
1415       CALL production_e
1416
1417!
1418!--    Additional sink term for flows through plant canopies
1419       IF ( plant_canopy )  CALL plant_canopy_model( 6 )
1420       CALL user_actions( 'e-tendency' )
1421
1422!
1423!--    Prognostic equation for TKE.
1424!--    Eliminate negative TKE values, which can occur due to numerical
1425!--    reasons in the course of the integration. In such cases the old TKE
1426!--    value is reduced by 90%.
1427       DO  i = nxl, nxr
1428          DO  j = nys, nyn
1429             DO  k = nzb_s_inner(j,i)+1, nzt
1430                e_p(k,j,i) = e(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +          &
1431                                                  tsc(3) * te_m(k,j,i) )
1432                IF ( e_p(k,j,i) < 0.0 )  e_p(k,j,i) = 0.1 * e(k,j,i)
1433             ENDDO
1434          ENDDO
1435       ENDDO
1436
1437!
1438!--    Calculate tendencies for the next Runge-Kutta step
1439       IF ( timestep_scheme(1:5) == 'runge' )  THEN
1440          IF ( intermediate_timestep_count == 1 )  THEN
1441             DO  i = nxl, nxr
1442                DO  j = nys, nyn
1443                   DO  k = nzb_s_inner(j,i)+1, nzt
1444                      te_m(k,j,i) = tend(k,j,i)
1445                   ENDDO
1446                ENDDO
1447             ENDDO
1448          ELSEIF ( intermediate_timestep_count < &
1449                   intermediate_timestep_count_max )  THEN
1450             DO  i = nxl, nxr
1451                DO  j = nys, nyn
1452                   DO  k = nzb_s_inner(j,i)+1, nzt
1453                      te_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * te_m(k,j,i)
1454                   ENDDO
1455                ENDDO
1456             ENDDO
1457          ENDIF
1458       ENDIF
1459
1460       CALL cpu_log( log_point(16), 'tke-equation', 'stop' )
1461
1462    ENDIF
1463
1464
1465 END SUBROUTINE prognostic_equations_vector
1466
1467
1468 SUBROUTINE prognostic_equations_acc
1469
1470!------------------------------------------------------------------------------!
1471! Version for accelerator boards
1472!------------------------------------------------------------------------------!
1473
1474    IMPLICIT NONE
1475
1476    INTEGER ::  i, j, k, runge_step
1477    REAL    ::  sbt
1478
1479!
1480!-- Set switch for intermediate Runge-Kutta step
1481    runge_step = 0
1482    IF ( timestep_scheme(1:5) == 'runge' )  THEN
1483       IF ( intermediate_timestep_count == 1 )  THEN
1484          runge_step = 1
1485       ELSEIF ( intermediate_timestep_count < &
1486                intermediate_timestep_count_max )  THEN
1487          runge_step = 2
1488       ENDIF
1489    ENDIF
1490
1491!
1492!-- u-velocity component
1493!++ Statistics still not ported to accelerators
1494    !$acc update device( hom, ref_state )
1495    CALL cpu_log( log_point(5), 'u-equation', 'start' )
1496
1497    IF ( timestep_scheme(1:5) == 'runge' )  THEN
1498       IF ( ws_scheme_mom )  THEN
1499          CALL advec_u_ws_acc
1500       ELSE
1501          tend = 0.0    ! to be removed later??
1502          CALL advec_u_pw
1503       ENDIF
1504    ELSE
1505       CALL advec_u_up
1506    ENDIF
1507    CALL diffusion_u_acc
1508    CALL coriolis_acc( 1 )
1509    IF ( sloping_surface  .AND.  .NOT. neutral )  THEN
1510       CALL buoyancy( pt, 1 )
1511    ENDIF
1512
1513!
1514!-- Drag by plant canopy
1515    IF ( plant_canopy )  CALL plant_canopy_model( 1 )
1516
1517!
1518!-- External pressure gradient
1519    IF ( dp_external )  THEN
1520       DO  i = i_left, i_right
1521          DO  j = j_south, j_north
1522             DO  k = dp_level_ind_b+1, nzt
1523                tend(k,j,i) = tend(k,j,i) - dpdxy(1) * dp_smooth_factor(k)
1524             ENDDO
1525          ENDDO
1526       ENDDO
1527    ENDIF
1528
1529!
1530!-- Nudging
1531    IF ( nudging )  CALL nudge( simulated_time, 'u' ) 
1532
1533    CALL user_actions( 'u-tendency' )
1534
1535!
1536!-- Prognostic equation for u-velocity component
1537    !$acc kernels present( nzb_u_inner, rdf, tend, tu_m, u, ug, u_p )
1538    !$acc loop independent
1539    DO  i = i_left, i_right
1540       !$acc loop independent
1541       DO  j = j_south, j_north
1542          !$acc loop independent
1543          DO  k = 1, nzt
1544             IF ( k > nzb_u_inner(j,i) )  THEN
1545                u_p(k,j,i) = u(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
1546                                                  tsc(3) * tu_m(k,j,i) )       &
1547                                      - tsc(5) * rdf(k) * ( u(k,j,i) - ug(k) )
1548!
1549!--             Tendencies for the next Runge-Kutta step
1550                IF ( runge_step == 1 )  THEN
1551                   tu_m(k,j,i) = tend(k,j,i)
1552                ELSEIF ( runge_step == 2 )  THEN
1553                   tu_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tu_m(k,j,i)
1554                ENDIF
1555             ENDIF
1556          ENDDO
1557       ENDDO
1558    ENDDO
1559    !$acc end kernels
1560
1561    CALL cpu_log( log_point(5), 'u-equation', 'stop' )
1562
1563!
1564!-- v-velocity component
1565    CALL cpu_log( log_point(6), 'v-equation', 'start' )
1566
1567    IF ( timestep_scheme(1:5) == 'runge' )  THEN
1568       IF ( ws_scheme_mom )  THEN
1569          CALL advec_v_ws_acc
1570       ELSE
1571          tend = 0.0    ! to be removed later??
1572          CALL advec_v_pw
1573       END IF
1574    ELSE
1575       CALL advec_v_up
1576    ENDIF
1577    CALL diffusion_v_acc
1578    CALL coriolis_acc( 2 )
1579
1580!
1581!-- Drag by plant canopy
1582    IF ( plant_canopy )  CALL plant_canopy_model( 2 )
1583
1584!
1585!-- External pressure gradient
1586    IF ( dp_external )  THEN
1587       DO  i = i_left, i_right
1588          DO  j = j_south, j_north
1589             DO  k = dp_level_ind_b+1, nzt
1590                tend(k,j,i) = tend(k,j,i) - dpdxy(2) * dp_smooth_factor(k)
1591             ENDDO
1592          ENDDO
1593       ENDDO
1594    ENDIF
1595
1596!
1597!-- Nudging
1598    IF ( nudging )  CALL nudge( simulated_time, 'v' ) 
1599
1600    CALL user_actions( 'v-tendency' )
1601
1602!
1603!-- Prognostic equation for v-velocity component
1604    !$acc kernels present( nzb_v_inner, rdf, tend, tv_m, v, vg, v_p )
1605    !$acc loop independent
1606    DO  i = i_left, i_right
1607       !$acc loop independent
1608       DO  j = j_south, j_north
1609          !$acc loop independent
1610          DO  k = 1, nzt
1611             IF ( k > nzb_v_inner(j,i) )  THEN
1612                v_p(k,j,i) = v(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
1613                                                  tsc(3) * tv_m(k,j,i) )       &
1614                                      - tsc(5) * rdf(k) * ( v(k,j,i) - vg(k) )
1615!
1616!--             Tendencies for the next Runge-Kutta step
1617                IF ( runge_step == 1 )  THEN
1618                   tv_m(k,j,i) = tend(k,j,i)
1619                ELSEIF ( runge_step == 2 )  THEN
1620                   tv_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tv_m(k,j,i)
1621                ENDIF
1622             ENDIF
1623          ENDDO
1624       ENDDO
1625    ENDDO
1626    !$acc end kernels
1627
1628    CALL cpu_log( log_point(6), 'v-equation', 'stop' )
1629
1630!
1631!-- w-velocity component
1632    CALL cpu_log( log_point(7), 'w-equation', 'start' )
1633
1634    IF ( timestep_scheme(1:5) == 'runge' )  THEN
1635       IF ( ws_scheme_mom )  THEN
1636          CALL advec_w_ws_acc
1637       ELSE
1638          tend = 0.0    ! to be removed later??
1639          CALL advec_w_pw
1640       ENDIF
1641    ELSE
1642       CALL advec_w_up
1643    ENDIF
1644    CALL diffusion_w_acc
1645    CALL coriolis_acc( 3 )
1646
1647    IF ( .NOT. neutral )  THEN
1648       IF ( ocean )  THEN
1649          CALL buoyancy( rho, 3 )
1650       ELSE
1651          IF ( .NOT. humidity )  THEN
1652             CALL buoyancy_acc( pt, 3 )
1653          ELSE
1654             CALL buoyancy( vpt, 3 )
1655          ENDIF
1656       ENDIF
1657    ENDIF
1658
1659!
1660!-- Drag by plant canopy
1661    IF ( plant_canopy )  CALL plant_canopy_model( 3 )
1662
1663    CALL user_actions( 'w-tendency' )
1664
1665!
1666!-- Prognostic equation for w-velocity component
1667    !$acc kernels present( nzb_w_inner, rdf, tend, tw_m, w, w_p )
1668    !$acc loop independent
1669    DO  i = i_left, i_right
1670       !$acc loop independent
1671       DO  j = j_south, j_north
1672          !$acc loop independent
1673          DO  k = 1, nzt-1
1674             IF ( k > nzb_w_inner(j,i) )  THEN
1675                w_p(k,j,i) = w(k,j,i) + dt_3d * ( tsc(2) * tend(k,j,i) +       &
1676                                                  tsc(3) * tw_m(k,j,i) )       &
1677                                      - tsc(5) * rdf(k) * w(k,j,i)
1678   !
1679   !--          Tendencies for the next Runge-Kutta step
1680                IF ( runge_step == 1 )  THEN
1681                   tw_m(k,j,i) = tend(k,j,i)
1682                ELSEIF ( runge_step == 2 )  THEN
1683                   tw_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tw_m(k,j,i)
1684                ENDIF
1685             ENDIF
1686          ENDDO
1687       ENDDO
1688    ENDDO
1689    !$acc end kernels
1690
1691    CALL cpu_log( log_point(7), 'w-equation', 'stop' )
1692
1693
1694!
1695!-- If required, compute prognostic equation for potential temperature
1696    IF ( .NOT. neutral )  THEN
1697
1698       CALL cpu_log( log_point(13), 'pt-equation', 'start' )
1699
1700!
1701!--    pt-tendency terms with communication
1702       sbt = tsc(2)
1703       IF ( scalar_advec == 'bc-scheme' )  THEN
1704
1705          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1706!
1707!--          Bott-Chlond scheme always uses Euler time step. Thus:
1708             sbt = 1.0
1709          ENDIF
1710          tend = 0.0
1711          CALL advec_s_bc( pt, 'pt' )
1712
1713       ENDIF
1714
1715!
1716!--    pt-tendency terms with no communication
1717       IF ( scalar_advec /= 'bc-scheme' )  THEN
1718          tend = 0.0
1719          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1720             IF ( ws_scheme_sca )  THEN
1721                CALL advec_s_ws_acc( pt, 'pt' )
1722             ELSE
1723                tend = 0.0    ! to be removed later??
1724                CALL advec_s_pw( pt )
1725             ENDIF
1726          ELSE
1727             CALL advec_s_up( pt )
1728          ENDIF
1729       ENDIF
1730
1731       CALL diffusion_s_acc( pt, shf, tswst, wall_heatflux )
1732
1733!
1734!--    If required compute heating/cooling due to long wave radiation processes
1735       IF ( radiation )  THEN
1736          CALL calc_radiation
1737       ENDIF
1738
1739!
1740!--    If required compute impact of latent heat due to precipitation
1741       IF ( precipitation )  THEN
1742          CALL impact_of_latent_heat
1743       ENDIF
1744
1745!
1746!--    Consideration of heat sources within the plant canopy
1747       IF ( plant_canopy .AND. ( cthf /= 0.0 ) ) THEN
1748          CALL plant_canopy_model( 4 )
1749       ENDIF
1750
1751!
1752!--    If required compute influence of large-scale subsidence/ascent
1753       IF ( large_scale_subsidence )  THEN
1754          CALL subsidence( tend, pt, pt_init )
1755       ENDIF
1756
1757!
1758!--    Nudging
1759       IF ( nudging )  CALL nudge( simulated_time, 'pt' ) 
1760
1761       CALL user_actions( 'pt-tendency' )
1762
1763!
1764!--    Prognostic equation for potential temperature
1765       !$acc kernels present( nzb_s_inner, rdf_sc, ptdf_x, ptdf_y, pt_init ) &
1766       !$acc         present( tend, tpt_m, pt, pt_p )
1767       !$acc loop independent
1768       DO  i = i_left, i_right
1769          !$acc loop independent
1770          DO  j = j_south, j_north
1771             !$acc loop independent
1772             DO  k = 1, nzt
1773                IF ( k > nzb_s_inner(j,i) )  THEN
1774                   pt_p(k,j,i) = pt(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +        &
1775                                                       tsc(3) * tpt_m(k,j,i) )    &
1776                                           - tsc(5) * ( pt(k,j,i) - pt_init(k) ) *&
1777                                             ( rdf_sc(k) + ptdf_x(i) + ptdf_y(j) )
1778!
1779!--                Tendencies for the next Runge-Kutta step
1780                   IF ( runge_step == 1 )  THEN
1781                      tpt_m(k,j,i) = tend(k,j,i)
1782                   ELSEIF ( runge_step == 2 )  THEN
1783                      tpt_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tpt_m(k,j,i)
1784                   ENDIF
1785                ENDIF
1786             ENDDO
1787          ENDDO
1788       ENDDO
1789       !$acc end kernels
1790
1791       CALL cpu_log( log_point(13), 'pt-equation', 'stop' )
1792
1793    ENDIF
1794
1795!
1796!-- If required, compute prognostic equation for salinity
1797    IF ( ocean )  THEN
1798
1799       CALL cpu_log( log_point(37), 'sa-equation', 'start' )
1800
1801!
1802!--    sa-tendency terms with communication
1803       sbt = tsc(2)
1804       IF ( scalar_advec == 'bc-scheme' )  THEN
1805
1806          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1807!
1808!--          Bott-Chlond scheme always uses Euler time step. Thus:
1809             sbt = 1.0
1810          ENDIF
1811          tend = 0.0
1812          CALL advec_s_bc( sa, 'sa' )
1813
1814       ENDIF
1815
1816!
1817!--    sa-tendency terms with no communication
1818       IF ( scalar_advec /= 'bc-scheme' )  THEN
1819          tend = 0.0
1820          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1821             IF ( ws_scheme_sca )  THEN
1822                 CALL advec_s_ws( sa, 'sa' )
1823             ELSE
1824                 CALL advec_s_pw( sa )
1825             ENDIF
1826          ELSE
1827             CALL advec_s_up( sa )
1828          ENDIF
1829       ENDIF
1830
1831       CALL diffusion_s( sa, saswsb, saswst, wall_salinityflux )
1832
1833       CALL user_actions( 'sa-tendency' )
1834
1835!
1836!--    Prognostic equation for salinity
1837       DO  i = i_left, i_right
1838          DO  j = j_south, j_north
1839             DO  k = nzb_s_inner(j,i)+1, nzt
1840                sa_p(k,j,i) = sa(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +        &
1841                                                    tsc(3) * tsa_m(k,j,i) )    &
1842                                        - tsc(5) * rdf_sc(k) *                 &
1843                                          ( sa(k,j,i) - sa_init(k) )
1844                IF ( sa_p(k,j,i) < 0.0 )  sa_p(k,j,i) = 0.1 * sa(k,j,i)
1845!
1846!--             Tendencies for the next Runge-Kutta step
1847                IF ( runge_step == 1 )  THEN
1848                   tsa_m(k,j,i) = tend(k,j,i)
1849                ELSEIF ( runge_step == 2 )  THEN
1850                   tsa_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tsa_m(k,j,i)
1851                ENDIF
1852             ENDDO
1853          ENDDO
1854       ENDDO
1855
1856       CALL cpu_log( log_point(37), 'sa-equation', 'stop' )
1857
1858!
1859!--    Calculate density by the equation of state for seawater
1860       CALL cpu_log( log_point(38), 'eqns-seawater', 'start' )
1861       CALL eqn_state_seawater
1862       CALL cpu_log( log_point(38), 'eqns-seawater', 'stop' )
1863
1864    ENDIF
1865
1866!
1867!-- If required, compute prognostic equation for total water content / scalar
1868    IF ( humidity  .OR.  passive_scalar )  THEN
1869
1870       CALL cpu_log( log_point(29), 'q/s-equation', 'start' )
1871
1872!
1873!--    Scalar/q-tendency terms with communication
1874       sbt = tsc(2)
1875       IF ( scalar_advec == 'bc-scheme' )  THEN
1876
1877          IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1878!
1879!--          Bott-Chlond scheme always uses Euler time step. Thus:
1880             sbt = 1.0
1881          ENDIF
1882          tend = 0.0
1883          CALL advec_s_bc( q, 'q' )
1884
1885       ENDIF
1886
1887!
1888!--    Scalar/q-tendency terms with no communication
1889       IF ( scalar_advec /= 'bc-scheme' )  THEN
1890          tend = 0.0
1891          IF ( timestep_scheme(1:5) == 'runge' )  THEN
1892             IF ( ws_scheme_sca )  THEN
1893                CALL advec_s_ws( q, 'q' )
1894             ELSE
1895                CALL advec_s_pw( q )
1896             ENDIF
1897          ELSE
1898             CALL advec_s_up( q )
1899          ENDIF
1900       ENDIF
1901
1902       CALL diffusion_s( q, qsws, qswst, wall_qflux )
1903
1904!
1905!--    If required compute decrease of total water content due to
1906!--    precipitation
1907       IF ( precipitation )  THEN
1908          CALL calc_precipitation
1909       ENDIF
1910
1911!
1912!--    Sink or source of scalar concentration due to canopy elements
1913       IF ( plant_canopy ) CALL plant_canopy_model( 5 )
1914
1915!
1916!--    If required compute influence of large-scale subsidence/ascent
1917       IF ( large_scale_subsidence )  THEN
1918         CALL subsidence( tend, q, q_init )
1919       ENDIF
1920
1921!
1922!--    Nudging
1923       IF ( nudging )  CALL nudge( simulated_time, 'q' ) 
1924
1925       CALL user_actions( 'q-tendency' )
1926
1927!
1928!--    Prognostic equation for total water content / scalar
1929       DO  i = i_left, i_right
1930          DO  j = j_south, j_north
1931             DO  k = nzb_s_inner(j,i)+1, nzt
1932                q_p(k,j,i) = q(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +          &
1933                                                  tsc(3) * tq_m(k,j,i) )       &
1934                                      - tsc(5) * rdf_sc(k) *                   &
1935                                        ( q(k,j,i) - q_init(k) )
1936                IF ( q_p(k,j,i) < 0.0 )  q_p(k,j,i) = 0.1 * q(k,j,i)
1937!
1938!--             Tendencies for the next Runge-Kutta step
1939                IF ( runge_step == 1 )  THEN
1940                   tq_m(k,j,i) = tend(k,j,i)
1941                ELSEIF ( runge_step == 2 )  THEN
1942                   tq_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * tq_m(k,j,i)
1943                ENDIF
1944             ENDDO
1945          ENDDO
1946       ENDDO
1947
1948       CALL cpu_log( log_point(29), 'q/s-equation', 'stop' )
1949
1950    ENDIF
1951
1952!
1953!-- If required, compute prognostic equation for turbulent kinetic
1954!-- energy (TKE)
1955    IF ( .NOT. constant_diffusion )  THEN
1956
1957       CALL cpu_log( log_point(16), 'tke-equation', 'start' )
1958
1959       sbt = tsc(2)
1960       IF ( .NOT. use_upstream_for_tke )  THEN
1961          IF ( scalar_advec == 'bc-scheme' )  THEN
1962
1963             IF ( timestep_scheme(1:5) /= 'runge' )  THEN
1964!
1965!--             Bott-Chlond scheme always uses Euler time step. Thus:
1966                sbt = 1.0
1967             ENDIF
1968             tend = 0.0
1969             CALL advec_s_bc( e, 'e' )
1970
1971          ENDIF
1972       ENDIF
1973
1974!
1975!--    TKE-tendency terms with no communication
1976       IF ( scalar_advec /= 'bc-scheme'  .OR.  use_upstream_for_tke )  THEN
1977          IF ( use_upstream_for_tke )  THEN
1978             tend = 0.0
1979             CALL advec_s_up( e )
1980          ELSE
1981             IF ( timestep_scheme(1:5) == 'runge' )  THEN
1982                IF ( ws_scheme_sca )  THEN
1983                   CALL advec_s_ws_acc( e, 'e' )
1984                ELSE
1985                   tend = 0.0    ! to be removed later??
1986                   CALL advec_s_pw( e )
1987                ENDIF
1988             ELSE
1989                tend = 0.0    ! to be removed later??
1990                CALL advec_s_up( e )
1991             ENDIF
1992          ENDIF
1993       ENDIF
1994
1995       IF ( .NOT. humidity )  THEN
1996          IF ( ocean )  THEN
1997             CALL diffusion_e( prho, prho_reference )
1998          ELSE
1999             CALL diffusion_e_acc( pt, pt_reference )
2000          ENDIF
2001       ELSE
2002          CALL diffusion_e( vpt, pt_reference )
2003       ENDIF
2004
2005       CALL production_e_acc
2006
2007!
2008!--    Additional sink term for flows through plant canopies
2009       IF ( plant_canopy )  CALL plant_canopy_model( 6 )
2010       CALL user_actions( 'e-tendency' )
2011
2012!
2013!--    Prognostic equation for TKE.
2014!--    Eliminate negative TKE values, which can occur due to numerical
2015!--    reasons in the course of the integration. In such cases the old TKE
2016!--    value is reduced by 90%.
2017       !$acc kernels present( e, e_p, nzb_s_inner, tend, te_m )
2018       !$acc loop independent
2019       DO  i = i_left, i_right
2020          !$acc loop independent
2021          DO  j = j_south, j_north
2022             !$acc loop independent
2023             DO  k = 1, nzt
2024                IF ( k > nzb_s_inner(j,i) )  THEN
2025                   e_p(k,j,i) = e(k,j,i) + dt_3d * ( sbt * tend(k,j,i) +          &
2026                                                     tsc(3) * te_m(k,j,i) )
2027                   IF ( e_p(k,j,i) < 0.0 )  e_p(k,j,i) = 0.1 * e(k,j,i)
2028!
2029!--                Tendencies for the next Runge-Kutta step
2030                   IF ( runge_step == 1 )  THEN
2031                      te_m(k,j,i) = tend(k,j,i)
2032                   ELSEIF ( runge_step == 2 )  THEN
2033                      te_m(k,j,i) = -9.5625 * tend(k,j,i) + 5.3125 * te_m(k,j,i)
2034                   ENDIF
2035                ENDIF
2036             ENDDO
2037          ENDDO
2038       ENDDO
2039       !$acc end kernels
2040
2041       CALL cpu_log( log_point(16), 'tke-equation', 'stop' )
2042
2043    ENDIF
2044
2045
2046 END SUBROUTINE prognostic_equations_acc
2047
2048
2049 END MODULE prognostic_equations_mod
Note: See TracBrowser for help on using the repository browser.