source: palm/trunk/SOURCE/boundary_conds.f90 @ 3255

Last change on this file since 3255 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

  • Property svn:keywords set to Id
File size: 46.2 KB
RevLine 
[1682]1!> @file boundary_conds.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]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!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1]21! -----------------
[1933]22!
[3183]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: boundary_conds.f90 3241 2018-09-12 15:02:00Z suehring $
[3241]27! unused variables removed
28!
29! 3183 2018-07-27 14:25:55Z suehring
[3183]30! Rename some variables concerning LES-LES as well as offline nesting
31!
32! 3182 2018-07-27 13:36:03Z suehring
[3129]33! - Use wall function for e_p and diss_p in case of rans_tke_e
34! - move limitation of diss_p from tcm_prognostic
35!
36! 2938 2018-03-27 15:52:42Z suehring
[2938]37! Set boundary condition for TKE and TKE dissipation rate in case of nesting
38! and if parent model operates in RANS mode but child model in LES mode.
39! mode
40!
41! 2793 2018-02-07 10:54:33Z suehring
[2766]42! Removed preprocessor directive __chem
43!
44! 2718 2018-01-02 08:49:38Z maronga
[2716]45! Corrected "Former revisions" section
46!
47! 2696 2017-12-14 17:12:51Z kanani
48! Change in file header (GPL part)
[2696]49! Adjust boundary conditions for e and diss in case of TKE-e closure (TG)
50! Implementation of chemistry module (FK)
51!
52! 2569 2017-10-20 11:54:42Z kanani
[2569]53! Removed redundant code for ibc_s_b=1 and ibc_q_b=1
54!
55! 2365 2017-08-21 14:59:59Z kanani
[2365]56! Vertical grid nesting implemented: exclude setting vertical velocity to zero
57! on fine grid (SadiqHuq)
58!
59! 2320 2017-07-21 12:47:43Z suehring
[2320]60! Remove unused control parameter large_scale_forcing from only-list
61!
62! 2292 2017-06-20 09:51:42Z schwenkel
[2292]63! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
64! includes two more prognostic equations for cloud drop concentration (nc) 
65! and cloud water content (qc).
66!
67! 2233 2017-05-30 18:08:54Z suehring
[1321]68!
[2233]69! 2232 2017-05-30 17:47:52Z suehring
70! Set boundary conditions on topography top using flag method.
71!
[2119]72! 2118 2017-01-17 16:38:49Z raasch
73! OpenACC directives removed
74!
[2001]75! 2000 2016-08-20 18:09:15Z knoop
76! Forced header and separation lines into 80 columns
77!
[1993]78! 1992 2016-08-12 15:14:59Z suehring
79! Adjustments for top boundary condition for passive scalar
80!
[1961]81! 1960 2016-07-12 16:34:24Z suehring
82! Treat humidity and passive scalar separately
83!
[1933]84! 1823 2016-04-07 08:57:52Z hoffmann
85! Initial version of purely vertical nesting introduced.
86!
[1823]87! 1822 2016-04-07 07:49:42Z hoffmann
88! icloud_scheme removed. microphyisics_seifert added.
89!
[1765]90! 1764 2016-02-28 12:45:19Z raasch
91! index bug for u_p at left outflow removed
92!
[1763]93! 1762 2016-02-25 12:31:13Z hellstea
94! Introduction of nested domain feature
95!
[1744]96! 1742 2016-01-13 09:50:06Z raasch
97! bugfix for outflow Neumann boundary conditions at bottom and top
98!
[1718]99! 1717 2015-11-11 15:09:47Z raasch
100! Bugfix: index error in outflow conditions for left boundary
101!
[1683]102! 1682 2015-10-07 23:56:08Z knoop
103! Code annotations made doxygen readable
104!
[1717]105! 1410 2014-05-23 12:16:18Z suehring
[1463]106! Bugfix: set dirichlet boundary condition for passive_scalar at model domain
107! top
108!
[1410]109! 1399 2014-05-07 11:16:25Z heinze
110! Bugfix: set inflow boundary conditions also if no humidity or passive_scalar
111! is used.
112!
[1399]113! 1398 2014-05-07 11:15:00Z heinze
114! Dirichlet-condition at the top for u and v changed to u_init and v_init also
115! for large_scale_forcing
116!
[1381]117! 1380 2014-04-28 12:40:45Z heinze
118! Adjust Dirichlet-condition at the top for pt in case of nudging
119!
[1362]120! 1361 2014-04-16 15:17:48Z hoffmann
121! Bottom and top boundary conditions of rain water content (qr) and
122! rain drop concentration (nr) changed to Dirichlet
123!
[1354]124! 1353 2014-04-08 15:21:23Z heinze
125! REAL constants provided with KIND-attribute
126
[1321]127! 1320 2014-03-20 08:40:49Z raasch
[1320]128! ONLY-attribute added to USE-statements,
129! kind-parameters added to all INTEGER and REAL declaration statements,
130! kinds are defined in new module kinds,
131! revision history before 2012 removed,
132! comment fields (!:) to be used for variable explanations added to
133! all variable declaration statements
[1160]134!
[1258]135! 1257 2013-11-08 15:18:40Z raasch
136! loop independent clauses added
137!
[1242]138! 1241 2013-10-30 11:36:58Z heinze
139! Adjust ug and vg at each timestep in case of large_scale_forcing
140!
[1160]141! 1159 2013-05-21 11:58:22Z fricke
[1159]142! Bugfix: Neumann boundary conditions for the velocity components at the
143! outflow are in fact radiation boundary conditions using the maximum phase
144! velocity that ensures numerical stability (CFL-condition).
145! Hence, logical operator use_cmax is now used instead of bc_lr_dirneu/_neudir.
146! Bugfix: In case of use_cmax at the outflow, u, v, w are replaced by
147! u_p, v_p, w_p 
[1116]148!
149! 1115 2013-03-26 18:16:16Z hoffmann
150! boundary conditions of two-moment cloud scheme are restricted to Neumann-
151! boundary-conditions
152!
[1114]153! 1113 2013-03-10 02:48:14Z raasch
154! GPU-porting
155! dummy argument "range" removed
156! Bugfix: wrong index in loops of radiation boundary condition
[1113]157!
[1054]158! 1053 2012-11-13 17:11:03Z hoffmann
159! boundary conditions for the two new prognostic equations (nr, qr) of the
160! two-moment cloud scheme
161!
[1037]162! 1036 2012-10-22 13:43:42Z raasch
163! code put under GPL (PALM 3.9)
164!
[997]165! 996 2012-09-07 10:41:47Z raasch
166! little reformatting
167!
[979]168! 978 2012-08-09 08:28:32Z fricke
169! Neumann boudnary conditions are added at the inflow boundary for the SGS-TKE.
170! Outflow boundary conditions for the velocity components can be set to Neumann
171! conditions or to radiation conditions with a horizontal averaged phase
172! velocity.
173!
[876]174! 875 2012-04-02 15:35:15Z gryschka
175! Bugfix in case of dirichlet inflow bc at the right or north boundary
176!
[1]177! Revision 1.1  1997/09/12 06:21:34  raasch
178! Initial revision
179!
180!
181! Description:
182! ------------
[1682]183!> Boundary conditions for the prognostic quantities.
184!> One additional bottom boundary condition is applied for the TKE (=(u*)**2)
185!> in prandtl_fluxes. The cyclic lateral boundary conditions are implicitly
186!> handled in routine exchange_horiz. Pressure boundary conditions are
187!> explicitly set in routines pres, poisfft, poismg and sor.
[1]188!------------------------------------------------------------------------------!
[1682]189 SUBROUTINE boundary_conds
190 
[1]191
[1320]192    USE arrays_3d,                                                             &
193        ONLY:  c_u, c_u_m, c_u_m_l, c_v, c_v_m, c_v_m_l, c_w, c_w_m, c_w_m_l,  &
[3241]194               diss, diss_p, dzu, e_p, nc_p, nr_p, pt, pt_init, pt_p, q,       &
195               q_p, qc_p, qr_p, s, s_p, sa, sa_p, u, u_init, u_m_l, u_m_n,     &
196               u_m_r, u_m_s, u_p, v, v_init, v_m_l, v_m_n, v_m_r, v_m_s, v_p,  &
197               w, w_p, w_m_l, w_m_n, w_m_r, w_m_s
[2696]198
199    USE chemistry_model_mod,                                                   &
200        ONLY:  chem_boundary_conds 
201             
[1320]202    USE control_parameters,                                                    &
[3182]203        ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,  &
204               bc_dirichlet_s, bc_radiation_l, bc_radiation_n, bc_radiation_r, &
205               bc_radiation_s, bc_pt_t_val, bc_q_t_val, bc_s_t_val,            &
206               child_domain, constant_diffusion, cloud_physics, coupling_mode, &
207               dt_3d, humidity, ibc_pt_b, ibc_pt_t, ibc_q_b, ibc_q_t, ibc_s_b, &
208               ibc_s_t,ibc_sa_t, ibc_uv_b, ibc_uv_t,                           &
209               intermediate_timestep_count, kappa,                             &
210               microphysics_morrison, microphysics_seifert,                    &
211               nesting_offline, nudging,                                       &
212               ocean, passive_scalar, rans_mode, rans_tke_e, tsc, use_cmax
[1320]213
214    USE grid_variables,                                                        &
215        ONLY:  ddx, ddy, dx, dy
216
217    USE indices,                                                               &
218        ONLY:  nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg,             &
[3241]219               nzb, nzt
[1320]220
221    USE kinds
222
[1]223    USE pegrid
224
[1933]225    USE pmc_interface,                                                         &
[2938]226        ONLY : nesting_mode, rans_mode_parent
[1320]227
[2232]228    USE surface_mod,                                                           &
[3129]229        ONLY :  bc_h, surf_def_h, surf_def_v, surf_lsm_h, surf_lsm_v,          &
230                surf_usm_h, surf_usm_v
[1933]231
[3129]232    USE turbulence_closure_mod,                                                &
233        ONLY:  c_0
234
[1]235    IMPLICIT NONE
236
[2232]237    INTEGER(iwp) ::  i  !< grid index x direction
238    INTEGER(iwp) ::  j  !< grid index y direction
239    INTEGER(iwp) ::  k  !< grid index z direction
240    INTEGER(iwp) ::  kb !< variable to set respective boundary value, depends on facing.
241    INTEGER(iwp) ::  l  !< running index boundary type, for up- and downward-facing walls
242    INTEGER(iwp) ::  m  !< running index surface elements
[1]243
[1682]244    REAL(wp)    ::  c_max !<
245    REAL(wp)    ::  denom !<
[1]246
[73]247
[1]248!
[1113]249!-- Bottom boundary
250    IF ( ibc_uv_b == 1 )  THEN
251       u_p(nzb,:,:) = u_p(nzb+1,:,:)
252       v_p(nzb,:,:) = v_p(nzb+1,:,:)
253    ENDIF
[2232]254!
255!-- Set zero vertical velocity at topography top (l=0), or bottom (l=1) in case
256!-- of downward-facing surfaces.
257    DO  l = 0, 1
258!
259!--    Set kb, for upward-facing surfaces value at topography top (k-1) is set,
260!--    for downward-facing surfaces at topography bottom (k+1).
261       kb = MERGE( -1, 1, l == 0 )
262       !$OMP PARALLEL DO PRIVATE( i, j, k )
263       DO  m = 1, bc_h(l)%ns
264          i = bc_h(l)%i(m)           
265          j = bc_h(l)%j(m)
266          k = bc_h(l)%k(m)
267          w_p(k+kb,j,i) = 0.0_wp
[1113]268       ENDDO
269    ENDDO
270
271!
[1762]272!-- Top boundary. A nested domain ( ibc_uv_t = 3 ) does not require settings.
[1113]273    IF ( ibc_uv_t == 0 )  THEN
274        u_p(nzt+1,:,:) = u_init(nzt+1)
275        v_p(nzt+1,:,:) = v_init(nzt+1)
[1762]276    ELSEIF ( ibc_uv_t == 1 )  THEN
[1113]277        u_p(nzt+1,:,:) = u_p(nzt,:,:)
278        v_p(nzt+1,:,:) = v_p(nzt,:,:)
279    ENDIF
280
[2365]281!
282!-- Vertical nesting: Vertical velocity not zero at the top of the fine grid
[3182]283    IF (  .NOT.  child_domain  .AND.                                           &
[2365]284                 TRIM(coupling_mode) /= 'vnested_fine' )  THEN
285       w_p(nzt:nzt+1,:,:) = 0.0_wp  !< nzt is not a prognostic level (but cf. pres)
[1762]286    ENDIF
287
[1113]288!
[2232]289!-- Temperature at bottom and top boundary.
[1113]290!-- In case of coupled runs (ibc_pt_b = 2) the temperature is given by
291!-- the sea surface temperature of the coupled ocean model.
[2232]292!-- Dirichlet
[1113]293    IF ( ibc_pt_b == 0 )  THEN
[2232]294       DO  l = 0, 1
295!
296!--       Set kb, for upward-facing surfaces value at topography top (k-1) is set,
297!--       for downward-facing surfaces at topography bottom (k+1).
298          kb = MERGE( -1, 1, l == 0 )
299          !$OMP PARALLEL DO PRIVATE( i, j, k )
300          DO  m = 1, bc_h(l)%ns
301             i = bc_h(l)%i(m)           
302             j = bc_h(l)%j(m)
303             k = bc_h(l)%k(m)
304             pt_p(k+kb,j,i) = pt(k+kb,j,i)
[1]305          ENDDO
306       ENDDO
[2232]307!
308!-- Neumann, zero-gradient
[1113]309    ELSEIF ( ibc_pt_b == 1 )  THEN
[2232]310       DO  l = 0, 1
311!
312!--       Set kb, for upward-facing surfaces value at topography top (k-1) is set,
313!--       for downward-facing surfaces at topography bottom (k+1).
314          kb = MERGE( -1, 1, l == 0 )
315          !$OMP PARALLEL DO PRIVATE( i, j, k )
316          DO  m = 1, bc_h(l)%ns
317             i = bc_h(l)%i(m)           
318             j = bc_h(l)%j(m)
319             k = bc_h(l)%k(m)
320             pt_p(k+kb,j,i) = pt_p(k,j,i)
[1113]321          ENDDO
322       ENDDO
323    ENDIF
[1]324
325!
[1113]326!-- Temperature at top boundary
327    IF ( ibc_pt_t == 0 )  THEN
328        pt_p(nzt+1,:,:) = pt(nzt+1,:,:)
[1380]329!
330!--     In case of nudging adjust top boundary to pt which is
331!--     read in from NUDGING-DATA
332        IF ( nudging )  THEN
333           pt_p(nzt+1,:,:) = pt_init(nzt+1)
334        ENDIF
[1113]335    ELSEIF ( ibc_pt_t == 1 )  THEN
336        pt_p(nzt+1,:,:) = pt_p(nzt,:,:)
337    ELSEIF ( ibc_pt_t == 2 )  THEN
[1992]338        pt_p(nzt+1,:,:) = pt_p(nzt,:,:) + bc_pt_t_val * dzu(nzt+1)
[1113]339    ENDIF
[1]340
341!
[2938]342!-- Boundary conditions for TKE.
343!-- Generally Neumann conditions with de/dz=0 are assumed.
[1113]344    IF ( .NOT. constant_diffusion )  THEN
[2232]345
[2696]346       IF ( .NOT. rans_tke_e )  THEN
347          DO  l = 0, 1
[2232]348!
[2696]349!--         Set kb, for upward-facing surfaces value at topography top (k-1) is set,
350!--         for downward-facing surfaces at topography bottom (k+1).
351             kb = MERGE( -1, 1, l == 0 )
352             !$OMP PARALLEL DO PRIVATE( i, j, k )
353             DO  m = 1, bc_h(l)%ns
354                i = bc_h(l)%i(m)           
355                j = bc_h(l)%j(m)
356                k = bc_h(l)%k(m)
357                e_p(k+kb,j,i) = e_p(k,j,i)
358             ENDDO
[73]359          ENDDO
[3129]360       ELSE
361!
362!--       Use wall function within constant-flux layer
363!--       Upward-facing surfaces
364!--       Default surfaces
365          DO  m = 1, surf_def_h(0)%ns
366             i = surf_def_h(0)%i(m)
367             j = surf_def_h(0)%j(m)
368             k = surf_def_h(0)%k(m)
369             e_p(k,j,i) = ( surf_def_h(0)%us(m) / c_0 )**2
370          ENDDO
371!
372!--       Natural surfaces
373          DO  m = 1, surf_lsm_h%ns
374             i = surf_lsm_h%i(m)
375             j = surf_lsm_h%j(m)
376             k = surf_lsm_h%k(m)
377             e_p(k,j,i) = ( surf_lsm_h%us(m) / c_0 )**2
378          ENDDO
379!
380!--       Urban surfaces
381          DO  m = 1, surf_usm_h%ns
382             i = surf_usm_h%i(m)
383             j = surf_usm_h%j(m)
384             k = surf_usm_h%k(m)
385             e_p(k,j,i) = ( surf_usm_h%us(m) / c_0 )**2
386          ENDDO
387!
388!--       Vertical surfaces
389          DO  l = 0, 3
390!
391!--          Default surfaces
392             DO  m = 1, surf_def_v(l)%ns
393                i = surf_def_v(l)%i(m)
394                j = surf_def_v(l)%j(m)
395                k = surf_def_v(l)%k(m)
396                e_p(k,j,i) = ( surf_def_v(l)%us(m) / c_0 )**2
397             ENDDO
398!
399!--          Natural surfaces
400             DO  m = 1, surf_lsm_v(l)%ns
401                i = surf_lsm_v(l)%i(m)
402                j = surf_lsm_v(l)%j(m)
403                k = surf_lsm_v(l)%k(m)
404                e_p(k,j,i) = ( surf_lsm_v(l)%us(m) / c_0 )**2
405             ENDDO
406!
407!--          Urban surfaces
408             DO  m = 1, surf_usm_v(l)%ns
409                i = surf_usm_v(l)%i(m)
410                j = surf_usm_v(l)%j(m)
411                k = surf_usm_v(l)%k(m)
412                e_p(k,j,i) = ( surf_usm_v(l)%us(m) / c_0 )**2
413             ENDDO
414          ENDDO
[2696]415       ENDIF
[2232]416
[3182]417       IF ( .NOT. child_domain )  THEN
[1762]418          e_p(nzt+1,:,:) = e_p(nzt,:,:)
[2938]419!
420!--    Nesting case: if parent operates in RANS mode and child in LES mode,
421!--    no TKE is transfered. This case, set Neumann conditions at lateral and
422!--    top child boundaries.
423!--    If not ( both either in RANS or in LES mode ), TKE boundary condition
424!--    is treated in the nesting.
425       ELSE
426
427          IF ( rans_mode_parent  .AND.  .NOT. rans_mode )  THEN
428
429             e_p(nzt+1,:,:) = e_p(nzt,:,:)
[3182]430             IF ( bc_dirichlet_l )  e_p(:,:,nxl-1) = e_p(:,:,nxl)
431             IF ( bc_dirichlet_r )  e_p(:,:,nxr+1) = e_p(:,:,nxr)
432             IF ( bc_dirichlet_s )  e_p(:,nys-1,:) = e_p(:,nys,:)
433             IF ( bc_dirichlet_n )  e_p(:,nyn+1,:) = e_p(:,nyn,:)
[2938]434
435          ENDIF
[1762]436       ENDIF
[1113]437    ENDIF
438
439!
[2938]440!-- Boundary conditions for TKE dissipation rate.
[3129]441    IF ( rans_tke_e )  THEN
442!
443!--    Use wall function within constant-flux layer
444!--    Upward-facing surfaces
445!--    Default surfaces
446       DO  m = 1, surf_def_h(0)%ns
447          i = surf_def_h(0)%i(m)
448          j = surf_def_h(0)%j(m)
449          k = surf_def_h(0)%k(m)
450          diss_p(k,j,i) = surf_def_h(0)%us(m)**3          &
451                        / ( kappa * surf_def_h(0)%z_mo(m) )
452       ENDDO
453!
454!--    Natural surfaces
455       DO  m = 1, surf_lsm_h%ns
456          i = surf_lsm_h%i(m)
457          j = surf_lsm_h%j(m)
458          k = surf_lsm_h%k(m)
459          diss_p(k,j,i) = surf_lsm_h%us(m)**3          &
460                        / ( kappa * surf_lsm_h%z_mo(m) )
461       ENDDO
462!
463!--    Urban surfaces
464       DO  m = 1, surf_usm_h%ns
465          i = surf_usm_h%i(m)
466          j = surf_usm_h%j(m)
467          k = surf_usm_h%k(m)
468          diss_p(k,j,i) = surf_usm_h%us(m)**3          &
469                        / ( kappa * surf_usm_h%z_mo(m) )
470       ENDDO
471!
472!--    Vertical surfaces
473       DO  l = 0, 3
474!
475!--       Default surfaces
476          DO  m = 1, surf_def_v(l)%ns
477             i = surf_def_v(l)%i(m)
478             j = surf_def_v(l)%j(m)
479             k = surf_def_v(l)%k(m)
480             diss_p(k,j,i) = surf_def_v(l)%us(m)**3          &
481                           / ( kappa * surf_def_v(l)%z_mo(m) )
482          ENDDO
483!
484!--       Natural surfaces
485          DO  m = 1, surf_lsm_v(l)%ns
486             i = surf_lsm_v(l)%i(m)
487             j = surf_lsm_v(l)%j(m)
488             k = surf_lsm_v(l)%k(m)
489             diss_p(k,j,i) = surf_lsm_v(l)%us(m)**3          &
490                           / ( kappa * surf_lsm_v(l)%z_mo(m) )
491          ENDDO
492!
493!--       Urban surfaces
494          DO  m = 1, surf_usm_v(l)%ns
495             i = surf_usm_v(l)%i(m)
496             j = surf_usm_v(l)%j(m)
497             k = surf_usm_v(l)%k(m)
498             diss_p(k,j,i) = surf_usm_v(l)%us(m)**3          &
499                           / ( kappa * surf_usm_v(l)%z_mo(m) )
500          ENDDO
501       ENDDO
502!
503!--    Limit change of diss to be between -90% and +100%. Also, set an absolute
504!--    minimum value
505       DO  i = nxl, nxr
506          DO  j = nys, nyn
507             DO  k = nzb, nzt+1
508                diss_p(k,j,i) = MAX( MIN( diss_p(k,j,i),          &
509                                          2.0_wp * diss(k,j,i) ), &
510                                     0.1_wp * diss(k,j,i),        &
511                                     0.0001_wp )
512             ENDDO
513          ENDDO
514       ENDDO
515
[3182]516       IF ( .NOT. child_domain )  THEN
[3129]517          diss_p(nzt+1,:,:) = diss_p(nzt,:,:)
518       ENDIF
[2696]519    ENDIF
520
521!
[1113]522!-- Boundary conditions for salinity
523    IF ( ocean )  THEN
524!
525!--    Bottom boundary: Neumann condition because salinity flux is always
[2232]526!--    given.
527       DO  l = 0, 1
528!
529!--       Set kb, for upward-facing surfaces value at topography top (k-1) is set,
530!--       for downward-facing surfaces at topography bottom (k+1).
531          kb = MERGE( -1, 1, l == 0 )
532          !$OMP PARALLEL DO PRIVATE( i, j, k )
533          DO  m = 1, bc_h(l)%ns
534             i = bc_h(l)%i(m)           
535             j = bc_h(l)%j(m)
536             k = bc_h(l)%k(m)
537             sa_p(k+kb,j,i) = sa_p(k,j,i)
[1]538          ENDDO
[1113]539       ENDDO
[1]540!
[1113]541!--    Top boundary: Dirichlet or Neumann
542       IF ( ibc_sa_t == 0 )  THEN
543           sa_p(nzt+1,:,:) = sa(nzt+1,:,:)
544       ELSEIF ( ibc_sa_t == 1 )  THEN
545           sa_p(nzt+1,:,:) = sa_p(nzt,:,:)
[1]546       ENDIF
547
[1113]548    ENDIF
549
[1]550!
[1960]551!-- Boundary conditions for total water content,
[1113]552!-- bottom and top boundary (see also temperature)
[1960]553    IF ( humidity )  THEN
[1113]554!
555!--    Surface conditions for constant_humidity_flux
[2232]556!--    Run loop over all non-natural and natural walls. Note, in wall-datatype
557!--    the k coordinate belongs to the atmospheric grid point, therefore, set
558!--    q_p at k-1
[1113]559       IF ( ibc_q_b == 0 ) THEN
[2232]560
561          DO  l = 0, 1
562!
563!--          Set kb, for upward-facing surfaces value at topography top (k-1) is set,
564!--          for downward-facing surfaces at topography bottom (k+1).
565             kb = MERGE( -1, 1, l == 0 )
566             !$OMP PARALLEL DO PRIVATE( i, j, k )
567             DO  m = 1, bc_h(l)%ns
568                i = bc_h(l)%i(m)           
569                j = bc_h(l)%j(m)
570                k = bc_h(l)%k(m)
571                q_p(k+kb,j,i) = q(k+kb,j,i)
[1]572             ENDDO
573          ENDDO
[2232]574         
[1113]575       ELSE
[2232]576         
577          DO  l = 0, 1
578!
579!--          Set kb, for upward-facing surfaces value at topography top (k-1) is set,
580!--          for downward-facing surfaces at topography bottom (k+1).
581             kb = MERGE( -1, 1, l == 0 )
582             !$OMP PARALLEL DO PRIVATE( i, j, k )
583             DO  m = 1, bc_h(l)%ns
584                i = bc_h(l)%i(m)           
585                j = bc_h(l)%j(m)
586                k = bc_h(l)%k(m)
587                q_p(k+kb,j,i) = q_p(k,j,i)
[95]588             ENDDO
589          ENDDO
[1113]590       ENDIF
[95]591!
[1113]592!--    Top boundary
[1462]593       IF ( ibc_q_t == 0 ) THEN
594          q_p(nzt+1,:,:) = q(nzt+1,:,:)
595       ELSEIF ( ibc_q_t == 1 ) THEN
[1992]596          q_p(nzt+1,:,:) = q_p(nzt,:,:) + bc_q_t_val * dzu(nzt+1)
[1462]597       ENDIF
[95]598
[2292]599       IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
600!             
601!--       Surface conditions cloud water (Dirichlet)
602!--       Run loop over all non-natural and natural walls. Note, in wall-datatype
603!--       the k coordinate belongs to the atmospheric grid point, therefore, set
604!--       qr_p and nr_p at k-1
605          !$OMP PARALLEL DO PRIVATE( i, j, k )
606          DO  m = 1, bc_h(0)%ns
607             i = bc_h(0)%i(m)           
608             j = bc_h(0)%j(m)
609             k = bc_h(0)%k(m)
610             qc_p(k-1,j,i) = 0.0_wp
611             nc_p(k-1,j,i) = 0.0_wp
612          ENDDO
613!
614!--       Top boundary condition for cloud water (Dirichlet)
615          qc_p(nzt+1,:,:) = 0.0_wp
616          nc_p(nzt+1,:,:) = 0.0_wp
617           
618       ENDIF
619
[1822]620       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1113]621!             
[1361]622!--       Surface conditions rain water (Dirichlet)
[2232]623!--       Run loop over all non-natural and natural walls. Note, in wall-datatype
624!--       the k coordinate belongs to the atmospheric grid point, therefore, set
625!--       qr_p and nr_p at k-1
626          !$OMP PARALLEL DO PRIVATE( i, j, k )
627          DO  m = 1, bc_h(0)%ns
628             i = bc_h(0)%i(m)           
629             j = bc_h(0)%j(m)
630             k = bc_h(0)%k(m)
631             qr_p(k-1,j,i) = 0.0_wp
632             nr_p(k-1,j,i) = 0.0_wp
[1115]633          ENDDO
[1]634!
[1361]635!--       Top boundary condition for rain water (Dirichlet)
636          qr_p(nzt+1,:,:) = 0.0_wp
637          nr_p(nzt+1,:,:) = 0.0_wp
[1115]638           
[1]639       ENDIF
[1409]640    ENDIF
[1]641!
[1960]642!-- Boundary conditions for scalar,
643!-- bottom and top boundary (see also temperature)
644    IF ( passive_scalar )  THEN
645!
646!--    Surface conditions for constant_humidity_flux
[2232]647!--    Run loop over all non-natural and natural walls. Note, in wall-datatype
648!--    the k coordinate belongs to the atmospheric grid point, therefore, set
649!--    s_p at k-1
[1960]650       IF ( ibc_s_b == 0 ) THEN
[2232]651         
652          DO  l = 0, 1
653!
654!--          Set kb, for upward-facing surfaces value at topography top (k-1) is set,
655!--          for downward-facing surfaces at topography bottom (k+1).
656             kb = MERGE( -1, 1, l == 0 )
657             !$OMP PARALLEL DO PRIVATE( i, j, k )
658             DO  m = 1, bc_h(l)%ns
659                i = bc_h(l)%i(m)           
660                j = bc_h(l)%j(m)
661                k = bc_h(l)%k(m)
662                s_p(k+kb,j,i) = s(k+kb,j,i)
[1960]663             ENDDO
664          ENDDO
[2232]665         
[1960]666       ELSE
[2232]667         
668          DO  l = 0, 1
669!
670!--          Set kb, for upward-facing surfaces value at topography top (k-1) is set,
671!--          for downward-facing surfaces at topography bottom (k+1).
672             kb = MERGE( -1, 1, l == 0 )
673             !$OMP PARALLEL DO PRIVATE( i, j, k )
674             DO  m = 1, bc_h(l)%ns
675                i = bc_h(l)%i(m)           
676                j = bc_h(l)%j(m)
677                k = bc_h(l)%k(m)
678                s_p(k+kb,j,i) = s_p(k,j,i)
[1960]679             ENDDO
680          ENDDO
681       ENDIF
682!
[1992]683!--    Top boundary condition
684       IF ( ibc_s_t == 0 )  THEN
[1960]685          s_p(nzt+1,:,:) = s(nzt+1,:,:)
[1992]686       ELSEIF ( ibc_s_t == 1 )  THEN
687          s_p(nzt+1,:,:) = s_p(nzt,:,:)
688       ELSEIF ( ibc_s_t == 2 )  THEN
689          s_p(nzt+1,:,:) = s_p(nzt,:,:) + bc_s_t_val * dzu(nzt+1)
[1960]690       ENDIF
691
692    ENDIF   
693!
[2696]694!-- Top/bottom boundary conditions for chemical species
695    IF ( air_chemistry )  CALL chem_boundary_conds( 'set_bc_bottomtop' )
696!
[1762]697!-- In case of inflow or nest boundary at the south boundary the boundary for v
698!-- is at nys and in case of inflow or nest boundary at the left boundary the
699!-- boundary for u is at nxl. Since in prognostic_equations (cache optimized
700!-- version) these levels are handled as a prognostic level, boundary values
701!-- have to be restored here.
[1409]702!-- For the SGS-TKE, Neumann boundary conditions are used at the inflow.
[3182]703    IF ( bc_dirichlet_s )  THEN
[1409]704       v_p(:,nys,:) = v_p(:,nys-1,:)
705       IF ( .NOT. constant_diffusion ) e_p(:,nys-1,:) = e_p(:,nys,:)
[3182]706    ELSEIF ( bc_dirichlet_n )  THEN
[1409]707       IF ( .NOT. constant_diffusion ) e_p(:,nyn+1,:) = e_p(:,nyn,:)
[3182]708    ELSEIF ( bc_dirichlet_l ) THEN
[1409]709       u_p(:,:,nxl) = u_p(:,:,nxl-1)
710       IF ( .NOT. constant_diffusion ) e_p(:,:,nxl-1) = e_p(:,:,nxl)
[3182]711    ELSEIF ( bc_dirichlet_r )  THEN
[1409]712       IF ( .NOT. constant_diffusion ) e_p(:,:,nxr+1) = e_p(:,:,nxr)
713    ENDIF
[1]714
715!
[1762]716!-- The same restoration for u at i=nxl and v at j=nys as above must be made
[1933]717!-- in case of nest boundaries. This must not be done in case of vertical nesting
[3182]718!-- mode as in that case the lateral boundaries are actually cyclic.
719!-- @todo: Is this really needed? Boundary values will be overwritten in
720!--        coupler or by Inifor data.
721    IF ( nesting_mode /= 'vertical'  .OR.  nesting_offline )  THEN
722       IF ( bc_dirichlet_s )  THEN
[1933]723          v_p(:,nys,:) = v_p(:,nys-1,:)
724       ENDIF
[3182]725       IF ( bc_dirichlet_l )  THEN
[1933]726          u_p(:,:,nxl) = u_p(:,:,nxl-1)
727       ENDIF
[1762]728    ENDIF
729
730!
[1409]731!-- Lateral boundary conditions for scalar quantities at the outflow
[3182]732    IF ( bc_radiation_s )  THEN
[1409]733       pt_p(:,nys-1,:)     = pt_p(:,nys,:)
[2232]734       IF ( .NOT. constant_diffusion )  e_p(:,nys-1,:) = e_p(:,nys,:)
[2696]735       IF ( rans_tke_e )  diss_p(:,nys-1,:) = diss_p(:,nys,:)
[1960]736       IF ( humidity )  THEN
[1409]737          q_p(:,nys-1,:) = q_p(:,nys,:)
[2292]738          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
739             qc_p(:,nys-1,:) = qc_p(:,nys,:)
740             nc_p(:,nys-1,:) = nc_p(:,nys,:)
741          ENDIF
[1822]742          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1409]743             qr_p(:,nys-1,:) = qr_p(:,nys,:)
744             nr_p(:,nys-1,:) = nr_p(:,nys,:)
[1053]745          ENDIF
[1409]746       ENDIF
[1960]747       IF ( passive_scalar )  s_p(:,nys-1,:) = s_p(:,nys,:)
[3182]748    ELSEIF ( bc_radiation_n )  THEN
[1409]749       pt_p(:,nyn+1,:)     = pt_p(:,nyn,:)
[2696]750       IF ( .NOT. constant_diffusion )  e_p(:,nyn+1,:) = e_p(:,nyn,:)
751       IF ( rans_tke_e )  diss_p(:,nyn+1,:) = diss_p(:,nyn,:)
[1960]752       IF ( humidity )  THEN
[1409]753          q_p(:,nyn+1,:) = q_p(:,nyn,:)
[2292]754          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
755             qc_p(:,nyn+1,:) = qc_p(:,nyn,:)
756             nc_p(:,nyn+1,:) = nc_p(:,nyn,:)
757          ENDIF
[1822]758          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1409]759             qr_p(:,nyn+1,:) = qr_p(:,nyn,:)
760             nr_p(:,nyn+1,:) = nr_p(:,nyn,:)
[1053]761          ENDIF
[1409]762       ENDIF
[1960]763       IF ( passive_scalar )  s_p(:,nyn+1,:) = s_p(:,nyn,:)
[3182]764    ELSEIF ( bc_radiation_l )  THEN
[1409]765       pt_p(:,:,nxl-1)     = pt_p(:,:,nxl)
[2696]766       IF ( .NOT. constant_diffusion )  e_p(:,:,nxl-1) = e_p(:,:,nxl)
767       IF ( rans_tke_e )  diss_p(:,:,nxl-1) = diss_p(:,:,nxl)
[1960]768       IF ( humidity )  THEN
[1409]769          q_p(:,:,nxl-1) = q_p(:,:,nxl)
[2292]770          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
771             qc_p(:,:,nxl-1) = qc_p(:,:,nxl)
772             nc_p(:,:,nxl-1) = nc_p(:,:,nxl)
773          ENDIF
[1822]774          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1409]775             qr_p(:,:,nxl-1) = qr_p(:,:,nxl)
776             nr_p(:,:,nxl-1) = nr_p(:,:,nxl)
[1053]777          ENDIF
[1409]778       ENDIF
[1960]779       IF ( passive_scalar )  s_p(:,:,nxl-1) = s_p(:,:,nxl)
[3182]780    ELSEIF ( bc_radiation_r )  THEN
[1409]781       pt_p(:,:,nxr+1)     = pt_p(:,:,nxr)
[2696]782       IF ( .NOT. constant_diffusion )  e_p(:,:,nxr+1) = e_p(:,:,nxr)
783       IF ( rans_tke_e )  diss_p(:,:,nxr+1) = diss_p(:,:,nxr)
[1960]784       IF ( humidity )  THEN
[1409]785          q_p(:,:,nxr+1) = q_p(:,:,nxr)
[2292]786          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
787             qc_p(:,:,nxr+1) = qc_p(:,:,nxr)
788             nc_p(:,:,nxr+1) = nc_p(:,:,nxr)
789          ENDIF
[1822]790          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1409]791             qr_p(:,:,nxr+1) = qr_p(:,:,nxr)
792             nr_p(:,:,nxr+1) = nr_p(:,:,nxr)
[1053]793          ENDIF
[1]794       ENDIF
[1960]795       IF ( passive_scalar )  s_p(:,:,nxr+1) = s_p(:,:,nxr)
[1]796    ENDIF
797
798!
[2696]799!-- Lateral boundary conditions for chemical species
800    IF ( air_chemistry )  CALL chem_boundary_conds( 'set_bc_lateral' )   
801
802!
[1159]803!-- Radiation boundary conditions for the velocities at the respective outflow.
804!-- The phase velocity is either assumed to the maximum phase velocity that
805!-- ensures numerical stability (CFL-condition) or calculated after
806!-- Orlanski(1976) and averaged along the outflow boundary.
[3182]807    IF ( bc_radiation_s )  THEN
[75]808
[1159]809       IF ( use_cmax )  THEN
810          u_p(:,-1,:) = u(:,0,:)
811          v_p(:,0,:)  = v(:,1,:)
812          w_p(:,-1,:) = w(:,0,:)         
813       ELSEIF ( .NOT. use_cmax )  THEN
[75]814
[978]815          c_max = dy / dt_3d
[75]816
[1353]817          c_u_m_l = 0.0_wp 
818          c_v_m_l = 0.0_wp
819          c_w_m_l = 0.0_wp
[978]820
[1353]821          c_u_m = 0.0_wp 
822          c_v_m = 0.0_wp
823          c_w_m = 0.0_wp
[978]824
[75]825!
[996]826!--       Calculate the phase speeds for u, v, and w, first local and then
827!--       average along the outflow boundary.
828          DO  k = nzb+1, nzt+1
829             DO  i = nxl, nxr
[75]830
[106]831                denom = u_m_s(k,0,i) - u_m_s(k,1,i)
832
[1353]833                IF ( denom /= 0.0_wp )  THEN
[996]834                   c_u(k,i) = -c_max * ( u(k,0,i) - u_m_s(k,0,i) ) / ( denom * tsc(2) )
[1353]835                   IF ( c_u(k,i) < 0.0_wp )  THEN
836                      c_u(k,i) = 0.0_wp
[106]837                   ELSEIF ( c_u(k,i) > c_max )  THEN
838                      c_u(k,i) = c_max
839                   ENDIF
840                ELSE
841                   c_u(k,i) = c_max
[75]842                ENDIF
843
[106]844                denom = v_m_s(k,1,i) - v_m_s(k,2,i)
845
[1353]846                IF ( denom /= 0.0_wp )  THEN
[996]847                   c_v(k,i) = -c_max * ( v(k,1,i) - v_m_s(k,1,i) ) / ( denom * tsc(2) )
[1353]848                   IF ( c_v(k,i) < 0.0_wp )  THEN
849                      c_v(k,i) = 0.0_wp
[106]850                   ELSEIF ( c_v(k,i) > c_max )  THEN
851                      c_v(k,i) = c_max
852                   ENDIF
853                ELSE
854                   c_v(k,i) = c_max
[75]855                ENDIF
856
[106]857                denom = w_m_s(k,0,i) - w_m_s(k,1,i)
[75]858
[1353]859                IF ( denom /= 0.0_wp )  THEN
[996]860                   c_w(k,i) = -c_max * ( w(k,0,i) - w_m_s(k,0,i) ) / ( denom * tsc(2) )
[1353]861                   IF ( c_w(k,i) < 0.0_wp )  THEN
862                      c_w(k,i) = 0.0_wp
[106]863                   ELSEIF ( c_w(k,i) > c_max )  THEN
864                      c_w(k,i) = c_max
865                   ENDIF
866                ELSE
867                   c_w(k,i) = c_max
[75]868                ENDIF
[106]869
[978]870                c_u_m_l(k) = c_u_m_l(k) + c_u(k,i)
871                c_v_m_l(k) = c_v_m_l(k) + c_v(k,i)
872                c_w_m_l(k) = c_w_m_l(k) + c_w(k,i)
[106]873
[978]874             ENDDO
875          ENDDO
[75]876
[978]877#if defined( __parallel )   
878          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
879          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
880                              MPI_SUM, comm1dx, ierr )   
881          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
882          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
883                              MPI_SUM, comm1dx, ierr ) 
884          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
885          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
886                              MPI_SUM, comm1dx, ierr ) 
887#else
888          c_u_m = c_u_m_l
889          c_v_m = c_v_m_l
890          c_w_m = c_w_m_l
891#endif
892
893          c_u_m = c_u_m / (nx+1)
894          c_v_m = c_v_m / (nx+1)
895          c_w_m = c_w_m / (nx+1)
896
[75]897!
[978]898!--       Save old timelevels for the next timestep
899          IF ( intermediate_timestep_count == 1 )  THEN
900             u_m_s(:,:,:) = u(:,0:1,:)
901             v_m_s(:,:,:) = v(:,1:2,:)
902             w_m_s(:,:,:) = w(:,0:1,:)
903          ENDIF
904
905!
906!--       Calculate the new velocities
[996]907          DO  k = nzb+1, nzt+1
908             DO  i = nxlg, nxrg
[978]909                u_p(k,-1,i) = u(k,-1,i) - dt_3d * tsc(2) * c_u_m(k) *          &
[75]910                                       ( u(k,-1,i) - u(k,0,i) ) * ddy
911
[978]912                v_p(k,0,i)  = v(k,0,i)  - dt_3d * tsc(2) * c_v_m(k) *          &
[106]913                                       ( v(k,0,i) - v(k,1,i) ) * ddy
[75]914
[978]915                w_p(k,-1,i) = w(k,-1,i) - dt_3d * tsc(2) * c_w_m(k) *          &
[75]916                                       ( w(k,-1,i) - w(k,0,i) ) * ddy
[978]917             ENDDO
[75]918          ENDDO
919
920!
[978]921!--       Bottom boundary at the outflow
922          IF ( ibc_uv_b == 0 )  THEN
[1353]923             u_p(nzb,-1,:) = 0.0_wp 
924             v_p(nzb,0,:)  = 0.0_wp 
[978]925          ELSE                   
926             u_p(nzb,-1,:) =  u_p(nzb+1,-1,:)
927             v_p(nzb,0,:)  =  v_p(nzb+1,0,:)
928          ENDIF
[1353]929          w_p(nzb,-1,:) = 0.0_wp
[73]930
[75]931!
[978]932!--       Top boundary at the outflow
933          IF ( ibc_uv_t == 0 )  THEN
934             u_p(nzt+1,-1,:) = u_init(nzt+1)
935             v_p(nzt+1,0,:)  = v_init(nzt+1)
936          ELSE
[1742]937             u_p(nzt+1,-1,:) = u_p(nzt,-1,:)
938             v_p(nzt+1,0,:)  = v_p(nzt,0,:)
[978]939          ENDIF
[1353]940          w_p(nzt:nzt+1,-1,:) = 0.0_wp
[978]941
[75]942       ENDIF
[73]943
[75]944    ENDIF
[73]945
[3182]946    IF ( bc_radiation_n )  THEN
[73]947
[1159]948       IF ( use_cmax )  THEN
949          u_p(:,ny+1,:) = u(:,ny,:)
950          v_p(:,ny+1,:) = v(:,ny,:)
951          w_p(:,ny+1,:) = w(:,ny,:)         
952       ELSEIF ( .NOT. use_cmax )  THEN
[75]953
[978]954          c_max = dy / dt_3d
[75]955
[1353]956          c_u_m_l = 0.0_wp 
957          c_v_m_l = 0.0_wp
958          c_w_m_l = 0.0_wp
[978]959
[1353]960          c_u_m = 0.0_wp 
961          c_v_m = 0.0_wp
962          c_w_m = 0.0_wp
[978]963
[1]964!
[996]965!--       Calculate the phase speeds for u, v, and w, first local and then
966!--       average along the outflow boundary.
967          DO  k = nzb+1, nzt+1
968             DO  i = nxl, nxr
[73]969
[106]970                denom = u_m_n(k,ny,i) - u_m_n(k,ny-1,i)
971
[1353]972                IF ( denom /= 0.0_wp )  THEN
[996]973                   c_u(k,i) = -c_max * ( u(k,ny,i) - u_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]974                   IF ( c_u(k,i) < 0.0_wp )  THEN
975                      c_u(k,i) = 0.0_wp
[106]976                   ELSEIF ( c_u(k,i) > c_max )  THEN
977                      c_u(k,i) = c_max
978                   ENDIF
979                ELSE
980                   c_u(k,i) = c_max
[73]981                ENDIF
982
[106]983                denom = v_m_n(k,ny,i) - v_m_n(k,ny-1,i)
[73]984
[1353]985                IF ( denom /= 0.0_wp )  THEN
[996]986                   c_v(k,i) = -c_max * ( v(k,ny,i) - v_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]987                   IF ( c_v(k,i) < 0.0_wp )  THEN
988                      c_v(k,i) = 0.0_wp
[106]989                   ELSEIF ( c_v(k,i) > c_max )  THEN
990                      c_v(k,i) = c_max
991                   ENDIF
992                ELSE
993                   c_v(k,i) = c_max
[73]994                ENDIF
995
[106]996                denom = w_m_n(k,ny,i) - w_m_n(k,ny-1,i)
[73]997
[1353]998                IF ( denom /= 0.0_wp )  THEN
[996]999                   c_w(k,i) = -c_max * ( w(k,ny,i) - w_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]1000                   IF ( c_w(k,i) < 0.0_wp )  THEN
1001                      c_w(k,i) = 0.0_wp
[106]1002                   ELSEIF ( c_w(k,i) > c_max )  THEN
1003                      c_w(k,i) = c_max
1004                   ENDIF
1005                ELSE
1006                   c_w(k,i) = c_max
[73]1007                ENDIF
[106]1008
[978]1009                c_u_m_l(k) = c_u_m_l(k) + c_u(k,i)
1010                c_v_m_l(k) = c_v_m_l(k) + c_v(k,i)
1011                c_w_m_l(k) = c_w_m_l(k) + c_w(k,i)
[106]1012
[978]1013             ENDDO
1014          ENDDO
[73]1015
[978]1016#if defined( __parallel )   
1017          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
1018          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
1019                              MPI_SUM, comm1dx, ierr )   
1020          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
1021          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
1022                              MPI_SUM, comm1dx, ierr ) 
1023          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
1024          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
1025                              MPI_SUM, comm1dx, ierr ) 
1026#else
1027          c_u_m = c_u_m_l
1028          c_v_m = c_v_m_l
1029          c_w_m = c_w_m_l
1030#endif
1031
1032          c_u_m = c_u_m / (nx+1)
1033          c_v_m = c_v_m / (nx+1)
1034          c_w_m = c_w_m / (nx+1)
1035
[73]1036!
[978]1037!--       Save old timelevels for the next timestep
1038          IF ( intermediate_timestep_count == 1 )  THEN
1039                u_m_n(:,:,:) = u(:,ny-1:ny,:)
1040                v_m_n(:,:,:) = v(:,ny-1:ny,:)
1041                w_m_n(:,:,:) = w(:,ny-1:ny,:)
1042          ENDIF
[73]1043
[978]1044!
1045!--       Calculate the new velocities
[996]1046          DO  k = nzb+1, nzt+1
1047             DO  i = nxlg, nxrg
[978]1048                u_p(k,ny+1,i) = u(k,ny+1,i) - dt_3d * tsc(2) * c_u_m(k) *      &
1049                                       ( u(k,ny+1,i) - u(k,ny,i) ) * ddy
[73]1050
[978]1051                v_p(k,ny+1,i) = v(k,ny+1,i)  - dt_3d * tsc(2) * c_v_m(k) *     &
1052                                       ( v(k,ny+1,i) - v(k,ny,i) ) * ddy
[73]1053
[978]1054                w_p(k,ny+1,i) = w(k,ny+1,i) - dt_3d * tsc(2) * c_w_m(k) *      &
1055                                       ( w(k,ny+1,i) - w(k,ny,i) ) * ddy
1056             ENDDO
[1]1057          ENDDO
1058
1059!
[978]1060!--       Bottom boundary at the outflow
1061          IF ( ibc_uv_b == 0 )  THEN
[1353]1062             u_p(nzb,ny+1,:) = 0.0_wp
1063             v_p(nzb,ny+1,:) = 0.0_wp   
[978]1064          ELSE                   
1065             u_p(nzb,ny+1,:) =  u_p(nzb+1,ny+1,:)
1066             v_p(nzb,ny+1,:) =  v_p(nzb+1,ny+1,:)
1067          ENDIF
[1353]1068          w_p(nzb,ny+1,:) = 0.0_wp
[73]1069
1070!
[978]1071!--       Top boundary at the outflow
1072          IF ( ibc_uv_t == 0 )  THEN
1073             u_p(nzt+1,ny+1,:) = u_init(nzt+1)
1074             v_p(nzt+1,ny+1,:) = v_init(nzt+1)
1075          ELSE
1076             u_p(nzt+1,ny+1,:) = u_p(nzt,nyn+1,:)
1077             v_p(nzt+1,ny+1,:) = v_p(nzt,nyn+1,:)
1078          ENDIF
[1353]1079          w_p(nzt:nzt+1,ny+1,:) = 0.0_wp
[978]1080
[1]1081       ENDIF
1082
[75]1083    ENDIF
1084
[3182]1085    IF ( bc_radiation_l )  THEN
[75]1086
[1159]1087       IF ( use_cmax )  THEN
[1717]1088          u_p(:,:,0)  = u(:,:,1)
1089          v_p(:,:,-1) = v(:,:,0)
[1159]1090          w_p(:,:,-1) = w(:,:,0)         
1091       ELSEIF ( .NOT. use_cmax )  THEN
[75]1092
[978]1093          c_max = dx / dt_3d
[75]1094
[1353]1095          c_u_m_l = 0.0_wp 
1096          c_v_m_l = 0.0_wp
1097          c_w_m_l = 0.0_wp
[978]1098
[1353]1099          c_u_m = 0.0_wp 
1100          c_v_m = 0.0_wp
1101          c_w_m = 0.0_wp
[978]1102
[1]1103!
[996]1104!--       Calculate the phase speeds for u, v, and w, first local and then
1105!--       average along the outflow boundary.
1106          DO  k = nzb+1, nzt+1
1107             DO  j = nys, nyn
[75]1108
[106]1109                denom = u_m_l(k,j,1) - u_m_l(k,j,2)
1110
[1353]1111                IF ( denom /= 0.0_wp )  THEN
[996]1112                   c_u(k,j) = -c_max * ( u(k,j,1) - u_m_l(k,j,1) ) / ( denom * tsc(2) )
[1353]1113                   IF ( c_u(k,j) < 0.0_wp )  THEN
1114                      c_u(k,j) = 0.0_wp
[107]1115                   ELSEIF ( c_u(k,j) > c_max )  THEN
1116                      c_u(k,j) = c_max
[106]1117                   ENDIF
1118                ELSE
[107]1119                   c_u(k,j) = c_max
[75]1120                ENDIF
1121
[106]1122                denom = v_m_l(k,j,0) - v_m_l(k,j,1)
[75]1123
[1353]1124                IF ( denom /= 0.0_wp )  THEN
[996]1125                   c_v(k,j) = -c_max * ( v(k,j,0) - v_m_l(k,j,0) ) / ( denom * tsc(2) )
[1353]1126                   IF ( c_v(k,j) < 0.0_wp )  THEN
1127                      c_v(k,j) = 0.0_wp
[106]1128                   ELSEIF ( c_v(k,j) > c_max )  THEN
1129                      c_v(k,j) = c_max
1130                   ENDIF
1131                ELSE
1132                   c_v(k,j) = c_max
[75]1133                ENDIF
1134
[106]1135                denom = w_m_l(k,j,0) - w_m_l(k,j,1)
[75]1136
[1353]1137                IF ( denom /= 0.0_wp )  THEN
[996]1138                   c_w(k,j) = -c_max * ( w(k,j,0) - w_m_l(k,j,0) ) / ( denom * tsc(2) )
[1353]1139                   IF ( c_w(k,j) < 0.0_wp )  THEN
1140                      c_w(k,j) = 0.0_wp
[106]1141                   ELSEIF ( c_w(k,j) > c_max )  THEN
1142                      c_w(k,j) = c_max
1143                   ENDIF
1144                ELSE
1145                   c_w(k,j) = c_max
[75]1146                ENDIF
[106]1147
[978]1148                c_u_m_l(k) = c_u_m_l(k) + c_u(k,j)
1149                c_v_m_l(k) = c_v_m_l(k) + c_v(k,j)
1150                c_w_m_l(k) = c_w_m_l(k) + c_w(k,j)
[106]1151
[978]1152             ENDDO
1153          ENDDO
[75]1154
[978]1155#if defined( __parallel )   
1156          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1157          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
1158                              MPI_SUM, comm1dy, ierr )   
1159          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1160          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
1161                              MPI_SUM, comm1dy, ierr ) 
1162          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1163          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
1164                              MPI_SUM, comm1dy, ierr ) 
1165#else
1166          c_u_m = c_u_m_l
1167          c_v_m = c_v_m_l
1168          c_w_m = c_w_m_l
1169#endif
1170
1171          c_u_m = c_u_m / (ny+1)
1172          c_v_m = c_v_m / (ny+1)
1173          c_w_m = c_w_m / (ny+1)
1174
[73]1175!
[978]1176!--       Save old timelevels for the next timestep
1177          IF ( intermediate_timestep_count == 1 )  THEN
1178                u_m_l(:,:,:) = u(:,:,1:2)
1179                v_m_l(:,:,:) = v(:,:,0:1)
1180                w_m_l(:,:,:) = w(:,:,0:1)
1181          ENDIF
1182
1183!
1184!--       Calculate the new velocities
[996]1185          DO  k = nzb+1, nzt+1
[1113]1186             DO  j = nysg, nyng
[978]1187                u_p(k,j,0) = u(k,j,0) - dt_3d * tsc(2) * c_u_m(k) *            &
[106]1188                                       ( u(k,j,0) - u(k,j,1) ) * ddx
[75]1189
[978]1190                v_p(k,j,-1) = v(k,j,-1) - dt_3d * tsc(2) * c_v_m(k) *          &
[75]1191                                       ( v(k,j,-1) - v(k,j,0) ) * ddx
1192
[978]1193                w_p(k,j,-1) = w(k,j,-1) - dt_3d * tsc(2) * c_w_m(k) *          &
[75]1194                                       ( w(k,j,-1) - w(k,j,0) ) * ddx
[978]1195             ENDDO
[75]1196          ENDDO
1197
1198!
[978]1199!--       Bottom boundary at the outflow
1200          IF ( ibc_uv_b == 0 )  THEN
[1353]1201             u_p(nzb,:,0)  = 0.0_wp 
1202             v_p(nzb,:,-1) = 0.0_wp
[978]1203          ELSE                   
1204             u_p(nzb,:,0)  =  u_p(nzb+1,:,0)
1205             v_p(nzb,:,-1) =  v_p(nzb+1,:,-1)
1206          ENDIF
[1353]1207          w_p(nzb,:,-1) = 0.0_wp
[1]1208
[75]1209!
[978]1210!--       Top boundary at the outflow
1211          IF ( ibc_uv_t == 0 )  THEN
[1764]1212             u_p(nzt+1,:,0)  = u_init(nzt+1)
[978]1213             v_p(nzt+1,:,-1) = v_init(nzt+1)
1214          ELSE
[1764]1215             u_p(nzt+1,:,0)  = u_p(nzt,:,0)
[978]1216             v_p(nzt+1,:,-1) = v_p(nzt,:,-1)
1217          ENDIF
[1353]1218          w_p(nzt:nzt+1,:,-1) = 0.0_wp
[978]1219
[75]1220       ENDIF
[73]1221
[75]1222    ENDIF
[73]1223
[3182]1224    IF ( bc_radiation_r )  THEN
[73]1225
[1159]1226       IF ( use_cmax )  THEN
1227          u_p(:,:,nx+1) = u(:,:,nx)
1228          v_p(:,:,nx+1) = v(:,:,nx)
1229          w_p(:,:,nx+1) = w(:,:,nx)         
1230       ELSEIF ( .NOT. use_cmax )  THEN
[75]1231
[978]1232          c_max = dx / dt_3d
[75]1233
[1353]1234          c_u_m_l = 0.0_wp 
1235          c_v_m_l = 0.0_wp
1236          c_w_m_l = 0.0_wp
[978]1237
[1353]1238          c_u_m = 0.0_wp 
1239          c_v_m = 0.0_wp
1240          c_w_m = 0.0_wp
[978]1241
[1]1242!
[996]1243!--       Calculate the phase speeds for u, v, and w, first local and then
1244!--       average along the outflow boundary.
1245          DO  k = nzb+1, nzt+1
1246             DO  j = nys, nyn
[73]1247
[106]1248                denom = u_m_r(k,j,nx) - u_m_r(k,j,nx-1)
1249
[1353]1250                IF ( denom /= 0.0_wp )  THEN
[996]1251                   c_u(k,j) = -c_max * ( u(k,j,nx) - u_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]1252                   IF ( c_u(k,j) < 0.0_wp )  THEN
1253                      c_u(k,j) = 0.0_wp
[106]1254                   ELSEIF ( c_u(k,j) > c_max )  THEN
1255                      c_u(k,j) = c_max
1256                   ENDIF
1257                ELSE
1258                   c_u(k,j) = c_max
[73]1259                ENDIF
1260
[106]1261                denom = v_m_r(k,j,nx) - v_m_r(k,j,nx-1)
[73]1262
[1353]1263                IF ( denom /= 0.0_wp )  THEN
[996]1264                   c_v(k,j) = -c_max * ( v(k,j,nx) - v_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]1265                   IF ( c_v(k,j) < 0.0_wp )  THEN
1266                      c_v(k,j) = 0.0_wp
[106]1267                   ELSEIF ( c_v(k,j) > c_max )  THEN
1268                      c_v(k,j) = c_max
1269                   ENDIF
1270                ELSE
1271                   c_v(k,j) = c_max
[73]1272                ENDIF
1273
[106]1274                denom = w_m_r(k,j,nx) - w_m_r(k,j,nx-1)
[73]1275
[1353]1276                IF ( denom /= 0.0_wp )  THEN
[996]1277                   c_w(k,j) = -c_max * ( w(k,j,nx) - w_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]1278                   IF ( c_w(k,j) < 0.0_wp )  THEN
1279                      c_w(k,j) = 0.0_wp
[106]1280                   ELSEIF ( c_w(k,j) > c_max )  THEN
1281                      c_w(k,j) = c_max
1282                   ENDIF
1283                ELSE
1284                   c_w(k,j) = c_max
[73]1285                ENDIF
[106]1286
[978]1287                c_u_m_l(k) = c_u_m_l(k) + c_u(k,j)
1288                c_v_m_l(k) = c_v_m_l(k) + c_v(k,j)
1289                c_w_m_l(k) = c_w_m_l(k) + c_w(k,j)
[106]1290
[978]1291             ENDDO
1292          ENDDO
[73]1293
[978]1294#if defined( __parallel )   
1295          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1296          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
1297                              MPI_SUM, comm1dy, ierr )   
1298          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1299          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
1300                              MPI_SUM, comm1dy, ierr ) 
1301          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
1302          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
1303                              MPI_SUM, comm1dy, ierr ) 
1304#else
1305          c_u_m = c_u_m_l
1306          c_v_m = c_v_m_l
1307          c_w_m = c_w_m_l
1308#endif
1309
1310          c_u_m = c_u_m / (ny+1)
1311          c_v_m = c_v_m / (ny+1)
1312          c_w_m = c_w_m / (ny+1)
1313
[73]1314!
[978]1315!--       Save old timelevels for the next timestep
1316          IF ( intermediate_timestep_count == 1 )  THEN
1317                u_m_r(:,:,:) = u(:,:,nx-1:nx)
1318                v_m_r(:,:,:) = v(:,:,nx-1:nx)
1319                w_m_r(:,:,:) = w(:,:,nx-1:nx)
1320          ENDIF
[73]1321
[978]1322!
1323!--       Calculate the new velocities
[996]1324          DO  k = nzb+1, nzt+1
[1113]1325             DO  j = nysg, nyng
[978]1326                u_p(k,j,nx+1) = u(k,j,nx+1) - dt_3d * tsc(2) * c_u_m(k) *      &
1327                                       ( u(k,j,nx+1) - u(k,j,nx) ) * ddx
[73]1328
[978]1329                v_p(k,j,nx+1) = v(k,j,nx+1) - dt_3d * tsc(2) * c_v_m(k) *      &
1330                                       ( v(k,j,nx+1) - v(k,j,nx) ) * ddx
[73]1331
[978]1332                w_p(k,j,nx+1) = w(k,j,nx+1) - dt_3d * tsc(2) * c_w_m(k) *      &
1333                                       ( w(k,j,nx+1) - w(k,j,nx) ) * ddx
1334             ENDDO
[73]1335          ENDDO
1336
1337!
[978]1338!--       Bottom boundary at the outflow
1339          IF ( ibc_uv_b == 0 )  THEN
[1353]1340             u_p(nzb,:,nx+1) = 0.0_wp
1341             v_p(nzb,:,nx+1) = 0.0_wp 
[978]1342          ELSE                   
1343             u_p(nzb,:,nx+1) =  u_p(nzb+1,:,nx+1)
1344             v_p(nzb,:,nx+1) =  v_p(nzb+1,:,nx+1)
1345          ENDIF
[1353]1346          w_p(nzb,:,nx+1) = 0.0_wp
[73]1347
1348!
[978]1349!--       Top boundary at the outflow
1350          IF ( ibc_uv_t == 0 )  THEN
1351             u_p(nzt+1,:,nx+1) = u_init(nzt+1)
1352             v_p(nzt+1,:,nx+1) = v_init(nzt+1)
1353          ELSE
1354             u_p(nzt+1,:,nx+1) = u_p(nzt,:,nx+1)
1355             v_p(nzt+1,:,nx+1) = v_p(nzt,:,nx+1)
1356          ENDIF
[1742]1357          w_p(nzt:nzt+1,:,nx+1) = 0.0_wp
[978]1358
[1]1359       ENDIF
1360
1361    ENDIF
1362
1363 END SUBROUTINE boundary_conds
Note: See TracBrowser for help on using the repository browser.