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

Last change on this file since 3467 was 3467, checked in by suehring, 5 years ago

Branch salsa @3446 re-integrated into trunk

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