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

Last change on this file since 1757 was 1744, checked in by raasch, 9 years ago

two last commits documented

  • Property svn:keywords set to Id
File size: 31.5 KB
RevLine 
[1682]1!> @file boundary_conds.f90
[1036]2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
[1310]16! Copyright 1997-2014 Leibniz Universitaet Hannover
[1036]17!--------------------------------------------------------------------------------!
18!
[484]19! Current revisions:
[1]20! -----------------
[1718]21!
[1744]22!
[1321]23! Former revisions:
24! -----------------
25! $Id: boundary_conds.f90 1744 2016-01-13 10:29:35Z maronga $
26!
[1744]27! 1742 2016-01-13 09:50:06Z raasch
28! bugfix for outflow Neumann boundary conditions at bottom and top
29!
[1718]30! 1717 2015-11-11 15:09:47Z raasch
31! Bugfix: index error in outflow conditions for left boundary
32!
[1683]33! 1682 2015-10-07 23:56:08Z knoop
34! Code annotations made doxygen readable
35!
[1717]36! 1410 2014-05-23 12:16:18Z suehring
[1463]37! Bugfix: set dirichlet boundary condition for passive_scalar at model domain
38! top
39!
[1410]40! 1399 2014-05-07 11:16:25Z heinze
41! Bugfix: set inflow boundary conditions also if no humidity or passive_scalar
42! is used.
43!
[1399]44! 1398 2014-05-07 11:15:00Z heinze
45! Dirichlet-condition at the top for u and v changed to u_init and v_init also
46! for large_scale_forcing
47!
[1381]48! 1380 2014-04-28 12:40:45Z heinze
49! Adjust Dirichlet-condition at the top for pt in case of nudging
50!
[1362]51! 1361 2014-04-16 15:17:48Z hoffmann
52! Bottom and top boundary conditions of rain water content (qr) and
53! rain drop concentration (nr) changed to Dirichlet
54!
[1354]55! 1353 2014-04-08 15:21:23Z heinze
56! REAL constants provided with KIND-attribute
57
[1321]58! 1320 2014-03-20 08:40:49Z raasch
[1320]59! ONLY-attribute added to USE-statements,
60! kind-parameters added to all INTEGER and REAL declaration statements,
61! kinds are defined in new module kinds,
62! revision history before 2012 removed,
63! comment fields (!:) to be used for variable explanations added to
64! all variable declaration statements
[1160]65!
[1258]66! 1257 2013-11-08 15:18:40Z raasch
67! loop independent clauses added
68!
[1242]69! 1241 2013-10-30 11:36:58Z heinze
70! Adjust ug and vg at each timestep in case of large_scale_forcing
71!
[1160]72! 1159 2013-05-21 11:58:22Z fricke
[1159]73! Bugfix: Neumann boundary conditions for the velocity components at the
74! outflow are in fact radiation boundary conditions using the maximum phase
75! velocity that ensures numerical stability (CFL-condition).
76! Hence, logical operator use_cmax is now used instead of bc_lr_dirneu/_neudir.
77! Bugfix: In case of use_cmax at the outflow, u, v, w are replaced by
78! u_p, v_p, w_p 
[1116]79!
80! 1115 2013-03-26 18:16:16Z hoffmann
81! boundary conditions of two-moment cloud scheme are restricted to Neumann-
82! boundary-conditions
83!
[1114]84! 1113 2013-03-10 02:48:14Z raasch
85! GPU-porting
86! dummy argument "range" removed
87! Bugfix: wrong index in loops of radiation boundary condition
[1113]88!
[1054]89! 1053 2012-11-13 17:11:03Z hoffmann
90! boundary conditions for the two new prognostic equations (nr, qr) of the
91! two-moment cloud scheme
92!
[1037]93! 1036 2012-10-22 13:43:42Z raasch
94! code put under GPL (PALM 3.9)
95!
[997]96! 996 2012-09-07 10:41:47Z raasch
97! little reformatting
98!
[979]99! 978 2012-08-09 08:28:32Z fricke
100! Neumann boudnary conditions are added at the inflow boundary for the SGS-TKE.
101! Outflow boundary conditions for the velocity components can be set to Neumann
102! conditions or to radiation conditions with a horizontal averaged phase
103! velocity.
104!
[876]105! 875 2012-04-02 15:35:15Z gryschka
106! Bugfix in case of dirichlet inflow bc at the right or north boundary
107!
[1]108! Revision 1.1  1997/09/12 06:21:34  raasch
109! Initial revision
110!
111!
112! Description:
113! ------------
[1682]114!> Boundary conditions for the prognostic quantities.
115!> One additional bottom boundary condition is applied for the TKE (=(u*)**2)
116!> in prandtl_fluxes. The cyclic lateral boundary conditions are implicitly
117!> handled in routine exchange_horiz. Pressure boundary conditions are
118!> explicitly set in routines pres, poisfft, poismg and sor.
[1]119!------------------------------------------------------------------------------!
[1682]120 SUBROUTINE boundary_conds
121 
[1]122
[1320]123    USE arrays_3d,                                                             &
124        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,  &
125               dzu, e_p, nr_p, pt, pt_p, q, q_p, qr_p, sa, sa_p,               &
126               u, ug, u_init, u_m_l, u_m_n, u_m_r, u_m_s, u_p,                 &
127               v, vg, v_init, v_m_l, v_m_n, v_m_r, v_m_s, v_p,                 &
[1380]128               w, w_p, w_m_l, w_m_n, w_m_r, w_m_s,&
129               pt_init
[1320]130
131    USE control_parameters,                                                    &
132        ONLY:  bc_pt_t_val, bc_q_t_val, constant_diffusion,                    &
133               cloud_physics, dt_3d, humidity,                                 &
[1462]134               ibc_pt_b, ibc_pt_t, ibc_q_b, ibc_q_t, ibc_sa_t, ibc_uv_b,       &
135               ibc_uv_t, icloud_scheme, inflow_l, inflow_n, inflow_r, inflow_s,&
[1320]136               intermediate_timestep_count, large_scale_forcing, ocean,        &
137               outflow_l, outflow_n, outflow_r, outflow_s, passive_scalar,     &
[1380]138               precipitation, tsc, use_cmax, &
139               nudging
[1320]140
141    USE grid_variables,                                                        &
142        ONLY:  ddx, ddy, dx, dy
143
144    USE indices,                                                               &
145        ONLY:  nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg,             &
146               nzb, nzb_s_inner, nzb_w_inner, nzt
147
148    USE kinds
149
[1]150    USE pegrid
151
[1320]152
[1]153    IMPLICIT NONE
154
[1682]155    INTEGER(iwp) ::  i !<
156    INTEGER(iwp) ::  j !<
157    INTEGER(iwp) ::  k !<
[1]158
[1682]159    REAL(wp)    ::  c_max !<
160    REAL(wp)    ::  denom !<
[1]161
[73]162
[1]163!
[1113]164!-- Bottom boundary
165    IF ( ibc_uv_b == 1 )  THEN
166       !$acc kernels present( u_p, v_p )
167       u_p(nzb,:,:) = u_p(nzb+1,:,:)
168       v_p(nzb,:,:) = v_p(nzb+1,:,:)
169       !$acc end kernels
170    ENDIF
171
172    !$acc kernels present( nzb_w_inner, w_p )
173    DO  i = nxlg, nxrg
174       DO  j = nysg, nyng
[1353]175          w_p(nzb_w_inner(j,i),j,i) = 0.0_wp
[1113]176       ENDDO
177    ENDDO
178    !$acc end kernels
179
180!
181!-- Top boundary
182    IF ( ibc_uv_t == 0 )  THEN
183       !$acc kernels present( u_init, u_p, v_init, v_p )
184        u_p(nzt+1,:,:) = u_init(nzt+1)
185        v_p(nzt+1,:,:) = v_init(nzt+1)
186       !$acc end kernels
187    ELSE
188       !$acc kernels present( u_p, v_p )
189        u_p(nzt+1,:,:) = u_p(nzt,:,:)
190        v_p(nzt+1,:,:) = v_p(nzt,:,:)
191       !$acc end kernels
192    ENDIF
193    !$acc kernels present( w_p )
[1353]194    w_p(nzt:nzt+1,:,:) = 0.0_wp  ! nzt is not a prognostic level (but cf. pres)
[1113]195    !$acc end kernels
196
197!
198!-- Temperature at bottom boundary.
199!-- In case of coupled runs (ibc_pt_b = 2) the temperature is given by
200!-- the sea surface temperature of the coupled ocean model.
201    IF ( ibc_pt_b == 0 )  THEN
202       !$acc kernels present( nzb_s_inner, pt, pt_p )
[1257]203       !$acc loop independent
[667]204       DO  i = nxlg, nxrg
[1257]205          !$acc loop independent
[667]206          DO  j = nysg, nyng
[1113]207             pt_p(nzb_s_inner(j,i),j,i) = pt(nzb_s_inner(j,i),j,i)
[1]208          ENDDO
209       ENDDO
[1113]210       !$acc end kernels
211    ELSEIF ( ibc_pt_b == 1 )  THEN
212       !$acc kernels present( nzb_s_inner, pt_p )
[1257]213       !$acc loop independent
[1113]214       DO  i = nxlg, nxrg
[1257]215          !$acc loop independent
[1113]216          DO  j = nysg, nyng
217             pt_p(nzb_s_inner(j,i),j,i) = pt_p(nzb_s_inner(j,i)+1,j,i)
218          ENDDO
219       ENDDO
220      !$acc end kernels
221    ENDIF
[1]222
223!
[1113]224!-- Temperature at top boundary
225    IF ( ibc_pt_t == 0 )  THEN
226       !$acc kernels present( pt, pt_p )
227        pt_p(nzt+1,:,:) = pt(nzt+1,:,:)
[1380]228!
229!--     In case of nudging adjust top boundary to pt which is
230!--     read in from NUDGING-DATA
231        IF ( nudging )  THEN
232           pt_p(nzt+1,:,:) = pt_init(nzt+1)
233        ENDIF
[1113]234       !$acc end kernels
235    ELSEIF ( ibc_pt_t == 1 )  THEN
236       !$acc kernels present( pt_p )
237        pt_p(nzt+1,:,:) = pt_p(nzt,:,:)
238       !$acc end kernels
239    ELSEIF ( ibc_pt_t == 2 )  THEN
240       !$acc kernels present( dzu, pt_p )
241        pt_p(nzt+1,:,:) = pt_p(nzt,:,:)   + bc_pt_t_val * dzu(nzt+1)
242       !$acc end kernels
243    ENDIF
[1]244
245!
[1113]246!-- Boundary conditions for TKE
247!-- Generally Neumann conditions with de/dz=0 are assumed
248    IF ( .NOT. constant_diffusion )  THEN
249       !$acc kernels present( e_p, nzb_s_inner )
[1257]250       !$acc loop independent
[1113]251       DO  i = nxlg, nxrg
[1257]252          !$acc loop independent
[1113]253          DO  j = nysg, nyng
254             e_p(nzb_s_inner(j,i),j,i) = e_p(nzb_s_inner(j,i)+1,j,i)
[73]255          ENDDO
[1113]256       ENDDO
257       e_p(nzt+1,:,:) = e_p(nzt,:,:)
258       !$acc end kernels
259    ENDIF
260
261!
262!-- Boundary conditions for salinity
263    IF ( ocean )  THEN
264!
265!--    Bottom boundary: Neumann condition because salinity flux is always
266!--    given
267       DO  i = nxlg, nxrg
268          DO  j = nysg, nyng
269             sa_p(nzb_s_inner(j,i),j,i) = sa_p(nzb_s_inner(j,i)+1,j,i)
[1]270          ENDDO
[1113]271       ENDDO
[1]272
273!
[1113]274!--    Top boundary: Dirichlet or Neumann
275       IF ( ibc_sa_t == 0 )  THEN
276           sa_p(nzt+1,:,:) = sa(nzt+1,:,:)
277       ELSEIF ( ibc_sa_t == 1 )  THEN
278           sa_p(nzt+1,:,:) = sa_p(nzt,:,:)
[1]279       ENDIF
280
[1113]281    ENDIF
282
[1]283!
[1113]284!-- Boundary conditions for total water content or scalar,
285!-- bottom and top boundary (see also temperature)
286    IF ( humidity  .OR.  passive_scalar )  THEN
287!
288!--    Surface conditions for constant_humidity_flux
289       IF ( ibc_q_b == 0 ) THEN
[667]290          DO  i = nxlg, nxrg
291             DO  j = nysg, nyng
[1113]292                q_p(nzb_s_inner(j,i),j,i) = q(nzb_s_inner(j,i),j,i)
[1]293             ENDDO
294          ENDDO
[1113]295       ELSE
[667]296          DO  i = nxlg, nxrg
297             DO  j = nysg, nyng
[1113]298                q_p(nzb_s_inner(j,i),j,i) = q_p(nzb_s_inner(j,i)+1,j,i)
[95]299             ENDDO
300          ENDDO
[1113]301       ENDIF
[95]302!
[1113]303!--    Top boundary
[1462]304       IF ( ibc_q_t == 0 ) THEN
305          q_p(nzt+1,:,:) = q(nzt+1,:,:)
306       ELSEIF ( ibc_q_t == 1 ) THEN
307          q_p(nzt+1,:,:) = q_p(nzt,:,:)   + bc_q_t_val * dzu(nzt+1)
308       ENDIF
[95]309
[1361]310       IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.  precipitation )  THEN
[1113]311!             
[1361]312!--       Surface conditions rain water (Dirichlet)
[1115]313          DO  i = nxlg, nxrg
314             DO  j = nysg, nyng
[1361]315                qr_p(nzb_s_inner(j,i),j,i) = 0.0_wp
316                nr_p(nzb_s_inner(j,i),j,i) = 0.0_wp
[73]317             ENDDO
[1115]318          ENDDO
[1]319!
[1361]320!--       Top boundary condition for rain water (Dirichlet)
321          qr_p(nzt+1,:,:) = 0.0_wp
322          nr_p(nzt+1,:,:) = 0.0_wp
[1115]323           
[1]324       ENDIF
[1409]325    ENDIF
[1]326!
[1409]327!-- In case of inflow at the south boundary the boundary for v is at nys
328!-- and in case of inflow at the left boundary the boundary for u is at nxl.
329!-- Since in prognostic_equations (cache optimized version) these levels are
330!-- handled as a prognostic level, boundary values have to be restored here.
331!-- For the SGS-TKE, Neumann boundary conditions are used at the inflow.
332    IF ( inflow_s )  THEN
333       v_p(:,nys,:) = v_p(:,nys-1,:)
334       IF ( .NOT. constant_diffusion ) e_p(:,nys-1,:) = e_p(:,nys,:)
335    ELSEIF ( inflow_n )  THEN
336       IF ( .NOT. constant_diffusion ) e_p(:,nyn+1,:) = e_p(:,nyn,:)
337    ELSEIF ( inflow_l ) THEN
338       u_p(:,:,nxl) = u_p(:,:,nxl-1)
339       IF ( .NOT. constant_diffusion ) e_p(:,:,nxl-1) = e_p(:,:,nxl)
340    ELSEIF ( inflow_r )  THEN
341       IF ( .NOT. constant_diffusion ) e_p(:,:,nxr+1) = e_p(:,:,nxr)
342    ENDIF
[1]343
344!
[1409]345!-- Lateral boundary conditions for scalar quantities at the outflow
346    IF ( outflow_s )  THEN
347       pt_p(:,nys-1,:)     = pt_p(:,nys,:)
348       IF ( .NOT. constant_diffusion     )  e_p(:,nys-1,:) = e_p(:,nys,:)
349       IF ( humidity  .OR.  passive_scalar )  THEN
350          q_p(:,nys-1,:) = q_p(:,nys,:)
351          IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.              &
352               precipitation)  THEN
353             qr_p(:,nys-1,:) = qr_p(:,nys,:)
354             nr_p(:,nys-1,:) = nr_p(:,nys,:)
[1053]355          ENDIF
[1409]356       ENDIF
357    ELSEIF ( outflow_n )  THEN
358       pt_p(:,nyn+1,:)     = pt_p(:,nyn,:)
359       IF ( .NOT. constant_diffusion     )  e_p(:,nyn+1,:) = e_p(:,nyn,:)
360       IF ( humidity  .OR.  passive_scalar )  THEN
361          q_p(:,nyn+1,:) = q_p(:,nyn,:)
362          IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.              &
363               precipitation )  THEN
364             qr_p(:,nyn+1,:) = qr_p(:,nyn,:)
365             nr_p(:,nyn+1,:) = nr_p(:,nyn,:)
[1053]366          ENDIF
[1409]367       ENDIF
368    ELSEIF ( outflow_l )  THEN
369       pt_p(:,:,nxl-1)     = pt_p(:,:,nxl)
370       IF ( .NOT. constant_diffusion     )  e_p(:,:,nxl-1) = e_p(:,:,nxl)
371       IF ( humidity  .OR.  passive_scalar )  THEN
372          q_p(:,:,nxl-1) = q_p(:,:,nxl)
373          IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.              &
374               precipitation )  THEN
375             qr_p(:,:,nxl-1) = qr_p(:,:,nxl)
376             nr_p(:,:,nxl-1) = nr_p(:,:,nxl)
[1053]377          ENDIF
[1409]378       ENDIF
379    ELSEIF ( outflow_r )  THEN
380       pt_p(:,:,nxr+1)     = pt_p(:,:,nxr)
381       IF ( .NOT. constant_diffusion     )  e_p(:,:,nxr+1) = e_p(:,:,nxr)
382       IF ( humidity .OR. passive_scalar )  THEN
383          q_p(:,:,nxr+1) = q_p(:,:,nxr)
384          IF ( cloud_physics  .AND.  icloud_scheme == 0  .AND.  precipitation )  THEN
385             qr_p(:,:,nxr+1) = qr_p(:,:,nxr)
386             nr_p(:,:,nxr+1) = nr_p(:,:,nxr)
[1053]387          ENDIF
[1]388       ENDIF
389    ENDIF
390
391!
[1159]392!-- Radiation boundary conditions for the velocities at the respective outflow.
393!-- The phase velocity is either assumed to the maximum phase velocity that
394!-- ensures numerical stability (CFL-condition) or calculated after
395!-- Orlanski(1976) and averaged along the outflow boundary.
[106]396    IF ( outflow_s )  THEN
[75]397
[1159]398       IF ( use_cmax )  THEN
399          u_p(:,-1,:) = u(:,0,:)
400          v_p(:,0,:)  = v(:,1,:)
401          w_p(:,-1,:) = w(:,0,:)         
402       ELSEIF ( .NOT. use_cmax )  THEN
[75]403
[978]404          c_max = dy / dt_3d
[75]405
[1353]406          c_u_m_l = 0.0_wp 
407          c_v_m_l = 0.0_wp
408          c_w_m_l = 0.0_wp
[978]409
[1353]410          c_u_m = 0.0_wp 
411          c_v_m = 0.0_wp
412          c_w_m = 0.0_wp
[978]413
[75]414!
[996]415!--       Calculate the phase speeds for u, v, and w, first local and then
416!--       average along the outflow boundary.
417          DO  k = nzb+1, nzt+1
418             DO  i = nxl, nxr
[75]419
[106]420                denom = u_m_s(k,0,i) - u_m_s(k,1,i)
421
[1353]422                IF ( denom /= 0.0_wp )  THEN
[996]423                   c_u(k,i) = -c_max * ( u(k,0,i) - u_m_s(k,0,i) ) / ( denom * tsc(2) )
[1353]424                   IF ( c_u(k,i) < 0.0_wp )  THEN
425                      c_u(k,i) = 0.0_wp
[106]426                   ELSEIF ( c_u(k,i) > c_max )  THEN
427                      c_u(k,i) = c_max
428                   ENDIF
429                ELSE
430                   c_u(k,i) = c_max
[75]431                ENDIF
432
[106]433                denom = v_m_s(k,1,i) - v_m_s(k,2,i)
434
[1353]435                IF ( denom /= 0.0_wp )  THEN
[996]436                   c_v(k,i) = -c_max * ( v(k,1,i) - v_m_s(k,1,i) ) / ( denom * tsc(2) )
[1353]437                   IF ( c_v(k,i) < 0.0_wp )  THEN
438                      c_v(k,i) = 0.0_wp
[106]439                   ELSEIF ( c_v(k,i) > c_max )  THEN
440                      c_v(k,i) = c_max
441                   ENDIF
442                ELSE
443                   c_v(k,i) = c_max
[75]444                ENDIF
445
[106]446                denom = w_m_s(k,0,i) - w_m_s(k,1,i)
[75]447
[1353]448                IF ( denom /= 0.0_wp )  THEN
[996]449                   c_w(k,i) = -c_max * ( w(k,0,i) - w_m_s(k,0,i) ) / ( denom * tsc(2) )
[1353]450                   IF ( c_w(k,i) < 0.0_wp )  THEN
451                      c_w(k,i) = 0.0_wp
[106]452                   ELSEIF ( c_w(k,i) > c_max )  THEN
453                      c_w(k,i) = c_max
454                   ENDIF
455                ELSE
456                   c_w(k,i) = c_max
[75]457                ENDIF
[106]458
[978]459                c_u_m_l(k) = c_u_m_l(k) + c_u(k,i)
460                c_v_m_l(k) = c_v_m_l(k) + c_v(k,i)
461                c_w_m_l(k) = c_w_m_l(k) + c_w(k,i)
[106]462
[978]463             ENDDO
464          ENDDO
[75]465
[978]466#if defined( __parallel )   
467          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
468          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
469                              MPI_SUM, comm1dx, ierr )   
470          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
471          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
472                              MPI_SUM, comm1dx, ierr ) 
473          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
474          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
475                              MPI_SUM, comm1dx, ierr ) 
476#else
477          c_u_m = c_u_m_l
478          c_v_m = c_v_m_l
479          c_w_m = c_w_m_l
480#endif
481
482          c_u_m = c_u_m / (nx+1)
483          c_v_m = c_v_m / (nx+1)
484          c_w_m = c_w_m / (nx+1)
485
[75]486!
[978]487!--       Save old timelevels for the next timestep
488          IF ( intermediate_timestep_count == 1 )  THEN
489             u_m_s(:,:,:) = u(:,0:1,:)
490             v_m_s(:,:,:) = v(:,1:2,:)
491             w_m_s(:,:,:) = w(:,0:1,:)
492          ENDIF
493
494!
495!--       Calculate the new velocities
[996]496          DO  k = nzb+1, nzt+1
497             DO  i = nxlg, nxrg
[978]498                u_p(k,-1,i) = u(k,-1,i) - dt_3d * tsc(2) * c_u_m(k) *          &
[75]499                                       ( u(k,-1,i) - u(k,0,i) ) * ddy
500
[978]501                v_p(k,0,i)  = v(k,0,i)  - dt_3d * tsc(2) * c_v_m(k) *          &
[106]502                                       ( v(k,0,i) - v(k,1,i) ) * ddy
[75]503
[978]504                w_p(k,-1,i) = w(k,-1,i) - dt_3d * tsc(2) * c_w_m(k) *          &
[75]505                                       ( w(k,-1,i) - w(k,0,i) ) * ddy
[978]506             ENDDO
[75]507          ENDDO
508
509!
[978]510!--       Bottom boundary at the outflow
511          IF ( ibc_uv_b == 0 )  THEN
[1353]512             u_p(nzb,-1,:) = 0.0_wp 
513             v_p(nzb,0,:)  = 0.0_wp 
[978]514          ELSE                   
515             u_p(nzb,-1,:) =  u_p(nzb+1,-1,:)
516             v_p(nzb,0,:)  =  v_p(nzb+1,0,:)
517          ENDIF
[1353]518          w_p(nzb,-1,:) = 0.0_wp
[73]519
[75]520!
[978]521!--       Top boundary at the outflow
522          IF ( ibc_uv_t == 0 )  THEN
523             u_p(nzt+1,-1,:) = u_init(nzt+1)
524             v_p(nzt+1,0,:)  = v_init(nzt+1)
525          ELSE
[1742]526             u_p(nzt+1,-1,:) = u_p(nzt,-1,:)
527             v_p(nzt+1,0,:)  = v_p(nzt,0,:)
[978]528          ENDIF
[1353]529          w_p(nzt:nzt+1,-1,:) = 0.0_wp
[978]530
[75]531       ENDIF
[73]532
[75]533    ENDIF
[73]534
[106]535    IF ( outflow_n )  THEN
[73]536
[1159]537       IF ( use_cmax )  THEN
538          u_p(:,ny+1,:) = u(:,ny,:)
539          v_p(:,ny+1,:) = v(:,ny,:)
540          w_p(:,ny+1,:) = w(:,ny,:)         
541       ELSEIF ( .NOT. use_cmax )  THEN
[75]542
[978]543          c_max = dy / dt_3d
[75]544
[1353]545          c_u_m_l = 0.0_wp 
546          c_v_m_l = 0.0_wp
547          c_w_m_l = 0.0_wp
[978]548
[1353]549          c_u_m = 0.0_wp 
550          c_v_m = 0.0_wp
551          c_w_m = 0.0_wp
[978]552
[1]553!
[996]554!--       Calculate the phase speeds for u, v, and w, first local and then
555!--       average along the outflow boundary.
556          DO  k = nzb+1, nzt+1
557             DO  i = nxl, nxr
[73]558
[106]559                denom = u_m_n(k,ny,i) - u_m_n(k,ny-1,i)
560
[1353]561                IF ( denom /= 0.0_wp )  THEN
[996]562                   c_u(k,i) = -c_max * ( u(k,ny,i) - u_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]563                   IF ( c_u(k,i) < 0.0_wp )  THEN
564                      c_u(k,i) = 0.0_wp
[106]565                   ELSEIF ( c_u(k,i) > c_max )  THEN
566                      c_u(k,i) = c_max
567                   ENDIF
568                ELSE
569                   c_u(k,i) = c_max
[73]570                ENDIF
571
[106]572                denom = v_m_n(k,ny,i) - v_m_n(k,ny-1,i)
[73]573
[1353]574                IF ( denom /= 0.0_wp )  THEN
[996]575                   c_v(k,i) = -c_max * ( v(k,ny,i) - v_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]576                   IF ( c_v(k,i) < 0.0_wp )  THEN
577                      c_v(k,i) = 0.0_wp
[106]578                   ELSEIF ( c_v(k,i) > c_max )  THEN
579                      c_v(k,i) = c_max
580                   ENDIF
581                ELSE
582                   c_v(k,i) = c_max
[73]583                ENDIF
584
[106]585                denom = w_m_n(k,ny,i) - w_m_n(k,ny-1,i)
[73]586
[1353]587                IF ( denom /= 0.0_wp )  THEN
[996]588                   c_w(k,i) = -c_max * ( w(k,ny,i) - w_m_n(k,ny,i) ) / ( denom * tsc(2) )
[1353]589                   IF ( c_w(k,i) < 0.0_wp )  THEN
590                      c_w(k,i) = 0.0_wp
[106]591                   ELSEIF ( c_w(k,i) > c_max )  THEN
592                      c_w(k,i) = c_max
593                   ENDIF
594                ELSE
595                   c_w(k,i) = c_max
[73]596                ENDIF
[106]597
[978]598                c_u_m_l(k) = c_u_m_l(k) + c_u(k,i)
599                c_v_m_l(k) = c_v_m_l(k) + c_v(k,i)
600                c_w_m_l(k) = c_w_m_l(k) + c_w(k,i)
[106]601
[978]602             ENDDO
603          ENDDO
[73]604
[978]605#if defined( __parallel )   
606          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
607          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
608                              MPI_SUM, comm1dx, ierr )   
609          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
610          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
611                              MPI_SUM, comm1dx, ierr ) 
612          IF ( collective_wait )  CALL MPI_BARRIER( comm1dx, ierr )
613          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
614                              MPI_SUM, comm1dx, ierr ) 
615#else
616          c_u_m = c_u_m_l
617          c_v_m = c_v_m_l
618          c_w_m = c_w_m_l
619#endif
620
621          c_u_m = c_u_m / (nx+1)
622          c_v_m = c_v_m / (nx+1)
623          c_w_m = c_w_m / (nx+1)
624
[73]625!
[978]626!--       Save old timelevels for the next timestep
627          IF ( intermediate_timestep_count == 1 )  THEN
628                u_m_n(:,:,:) = u(:,ny-1:ny,:)
629                v_m_n(:,:,:) = v(:,ny-1:ny,:)
630                w_m_n(:,:,:) = w(:,ny-1:ny,:)
631          ENDIF
[73]632
[978]633!
634!--       Calculate the new velocities
[996]635          DO  k = nzb+1, nzt+1
636             DO  i = nxlg, nxrg
[978]637                u_p(k,ny+1,i) = u(k,ny+1,i) - dt_3d * tsc(2) * c_u_m(k) *      &
638                                       ( u(k,ny+1,i) - u(k,ny,i) ) * ddy
[73]639
[978]640                v_p(k,ny+1,i) = v(k,ny+1,i)  - dt_3d * tsc(2) * c_v_m(k) *     &
641                                       ( v(k,ny+1,i) - v(k,ny,i) ) * ddy
[73]642
[978]643                w_p(k,ny+1,i) = w(k,ny+1,i) - dt_3d * tsc(2) * c_w_m(k) *      &
644                                       ( w(k,ny+1,i) - w(k,ny,i) ) * ddy
645             ENDDO
[1]646          ENDDO
647
648!
[978]649!--       Bottom boundary at the outflow
650          IF ( ibc_uv_b == 0 )  THEN
[1353]651             u_p(nzb,ny+1,:) = 0.0_wp
652             v_p(nzb,ny+1,:) = 0.0_wp   
[978]653          ELSE                   
654             u_p(nzb,ny+1,:) =  u_p(nzb+1,ny+1,:)
655             v_p(nzb,ny+1,:) =  v_p(nzb+1,ny+1,:)
656          ENDIF
[1353]657          w_p(nzb,ny+1,:) = 0.0_wp
[73]658
659!
[978]660!--       Top boundary at the outflow
661          IF ( ibc_uv_t == 0 )  THEN
662             u_p(nzt+1,ny+1,:) = u_init(nzt+1)
663             v_p(nzt+1,ny+1,:) = v_init(nzt+1)
664          ELSE
665             u_p(nzt+1,ny+1,:) = u_p(nzt,nyn+1,:)
666             v_p(nzt+1,ny+1,:) = v_p(nzt,nyn+1,:)
667          ENDIF
[1353]668          w_p(nzt:nzt+1,ny+1,:) = 0.0_wp
[978]669
[1]670       ENDIF
671
[75]672    ENDIF
673
[106]674    IF ( outflow_l )  THEN
[75]675
[1159]676       IF ( use_cmax )  THEN
[1717]677          u_p(:,:,0)  = u(:,:,1)
678          v_p(:,:,-1) = v(:,:,0)
[1159]679          w_p(:,:,-1) = w(:,:,0)         
680       ELSEIF ( .NOT. use_cmax )  THEN
[75]681
[978]682          c_max = dx / dt_3d
[75]683
[1353]684          c_u_m_l = 0.0_wp 
685          c_v_m_l = 0.0_wp
686          c_w_m_l = 0.0_wp
[978]687
[1353]688          c_u_m = 0.0_wp 
689          c_v_m = 0.0_wp
690          c_w_m = 0.0_wp
[978]691
[1]692!
[996]693!--       Calculate the phase speeds for u, v, and w, first local and then
694!--       average along the outflow boundary.
695          DO  k = nzb+1, nzt+1
696             DO  j = nys, nyn
[75]697
[106]698                denom = u_m_l(k,j,1) - u_m_l(k,j,2)
699
[1353]700                IF ( denom /= 0.0_wp )  THEN
[996]701                   c_u(k,j) = -c_max * ( u(k,j,1) - u_m_l(k,j,1) ) / ( denom * tsc(2) )
[1353]702                   IF ( c_u(k,j) < 0.0_wp )  THEN
703                      c_u(k,j) = 0.0_wp
[107]704                   ELSEIF ( c_u(k,j) > c_max )  THEN
705                      c_u(k,j) = c_max
[106]706                   ENDIF
707                ELSE
[107]708                   c_u(k,j) = c_max
[75]709                ENDIF
710
[106]711                denom = v_m_l(k,j,0) - v_m_l(k,j,1)
[75]712
[1353]713                IF ( denom /= 0.0_wp )  THEN
[996]714                   c_v(k,j) = -c_max * ( v(k,j,0) - v_m_l(k,j,0) ) / ( denom * tsc(2) )
[1353]715                   IF ( c_v(k,j) < 0.0_wp )  THEN
716                      c_v(k,j) = 0.0_wp
[106]717                   ELSEIF ( c_v(k,j) > c_max )  THEN
718                      c_v(k,j) = c_max
719                   ENDIF
720                ELSE
721                   c_v(k,j) = c_max
[75]722                ENDIF
723
[106]724                denom = w_m_l(k,j,0) - w_m_l(k,j,1)
[75]725
[1353]726                IF ( denom /= 0.0_wp )  THEN
[996]727                   c_w(k,j) = -c_max * ( w(k,j,0) - w_m_l(k,j,0) ) / ( denom * tsc(2) )
[1353]728                   IF ( c_w(k,j) < 0.0_wp )  THEN
729                      c_w(k,j) = 0.0_wp
[106]730                   ELSEIF ( c_w(k,j) > c_max )  THEN
731                      c_w(k,j) = c_max
732                   ENDIF
733                ELSE
734                   c_w(k,j) = c_max
[75]735                ENDIF
[106]736
[978]737                c_u_m_l(k) = c_u_m_l(k) + c_u(k,j)
738                c_v_m_l(k) = c_v_m_l(k) + c_v(k,j)
739                c_w_m_l(k) = c_w_m_l(k) + c_w(k,j)
[106]740
[978]741             ENDDO
742          ENDDO
[75]743
[978]744#if defined( __parallel )   
745          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
746          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
747                              MPI_SUM, comm1dy, ierr )   
748          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
749          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
750                              MPI_SUM, comm1dy, ierr ) 
751          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
752          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
753                              MPI_SUM, comm1dy, ierr ) 
754#else
755          c_u_m = c_u_m_l
756          c_v_m = c_v_m_l
757          c_w_m = c_w_m_l
758#endif
759
760          c_u_m = c_u_m / (ny+1)
761          c_v_m = c_v_m / (ny+1)
762          c_w_m = c_w_m / (ny+1)
763
[73]764!
[978]765!--       Save old timelevels for the next timestep
766          IF ( intermediate_timestep_count == 1 )  THEN
767                u_m_l(:,:,:) = u(:,:,1:2)
768                v_m_l(:,:,:) = v(:,:,0:1)
769                w_m_l(:,:,:) = w(:,:,0:1)
770          ENDIF
771
772!
773!--       Calculate the new velocities
[996]774          DO  k = nzb+1, nzt+1
[1113]775             DO  j = nysg, nyng
[978]776                u_p(k,j,0) = u(k,j,0) - dt_3d * tsc(2) * c_u_m(k) *            &
[106]777                                       ( u(k,j,0) - u(k,j,1) ) * ddx
[75]778
[978]779                v_p(k,j,-1) = v(k,j,-1) - dt_3d * tsc(2) * c_v_m(k) *          &
[75]780                                       ( v(k,j,-1) - v(k,j,0) ) * ddx
781
[978]782                w_p(k,j,-1) = w(k,j,-1) - dt_3d * tsc(2) * c_w_m(k) *          &
[75]783                                       ( w(k,j,-1) - w(k,j,0) ) * ddx
[978]784             ENDDO
[75]785          ENDDO
786
787!
[978]788!--       Bottom boundary at the outflow
789          IF ( ibc_uv_b == 0 )  THEN
[1353]790             u_p(nzb,:,0)  = 0.0_wp 
791             v_p(nzb,:,-1) = 0.0_wp
[978]792          ELSE                   
793             u_p(nzb,:,0)  =  u_p(nzb+1,:,0)
794             v_p(nzb,:,-1) =  v_p(nzb+1,:,-1)
795          ENDIF
[1353]796          w_p(nzb,:,-1) = 0.0_wp
[1]797
[75]798!
[978]799!--       Top boundary at the outflow
800          IF ( ibc_uv_t == 0 )  THEN
801             u_p(nzt+1,:,-1) = u_init(nzt+1)
802             v_p(nzt+1,:,-1) = v_init(nzt+1)
803          ELSE
804             u_p(nzt+1,:,-1) = u_p(nzt,:,-1)
805             v_p(nzt+1,:,-1) = v_p(nzt,:,-1)
806          ENDIF
[1353]807          w_p(nzt:nzt+1,:,-1) = 0.0_wp
[978]808
[75]809       ENDIF
[73]810
[75]811    ENDIF
[73]812
[106]813    IF ( outflow_r )  THEN
[73]814
[1159]815       IF ( use_cmax )  THEN
816          u_p(:,:,nx+1) = u(:,:,nx)
817          v_p(:,:,nx+1) = v(:,:,nx)
818          w_p(:,:,nx+1) = w(:,:,nx)         
819       ELSEIF ( .NOT. use_cmax )  THEN
[75]820
[978]821          c_max = dx / dt_3d
[75]822
[1353]823          c_u_m_l = 0.0_wp 
824          c_v_m_l = 0.0_wp
825          c_w_m_l = 0.0_wp
[978]826
[1353]827          c_u_m = 0.0_wp 
828          c_v_m = 0.0_wp
829          c_w_m = 0.0_wp
[978]830
[1]831!
[996]832!--       Calculate the phase speeds for u, v, and w, first local and then
833!--       average along the outflow boundary.
834          DO  k = nzb+1, nzt+1
835             DO  j = nys, nyn
[73]836
[106]837                denom = u_m_r(k,j,nx) - u_m_r(k,j,nx-1)
838
[1353]839                IF ( denom /= 0.0_wp )  THEN
[996]840                   c_u(k,j) = -c_max * ( u(k,j,nx) - u_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]841                   IF ( c_u(k,j) < 0.0_wp )  THEN
842                      c_u(k,j) = 0.0_wp
[106]843                   ELSEIF ( c_u(k,j) > c_max )  THEN
844                      c_u(k,j) = c_max
845                   ENDIF
846                ELSE
847                   c_u(k,j) = c_max
[73]848                ENDIF
849
[106]850                denom = v_m_r(k,j,nx) - v_m_r(k,j,nx-1)
[73]851
[1353]852                IF ( denom /= 0.0_wp )  THEN
[996]853                   c_v(k,j) = -c_max * ( v(k,j,nx) - v_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]854                   IF ( c_v(k,j) < 0.0_wp )  THEN
855                      c_v(k,j) = 0.0_wp
[106]856                   ELSEIF ( c_v(k,j) > c_max )  THEN
857                      c_v(k,j) = c_max
858                   ENDIF
859                ELSE
860                   c_v(k,j) = c_max
[73]861                ENDIF
862
[106]863                denom = w_m_r(k,j,nx) - w_m_r(k,j,nx-1)
[73]864
[1353]865                IF ( denom /= 0.0_wp )  THEN
[996]866                   c_w(k,j) = -c_max * ( w(k,j,nx) - w_m_r(k,j,nx) ) / ( denom * tsc(2) )
[1353]867                   IF ( c_w(k,j) < 0.0_wp )  THEN
868                      c_w(k,j) = 0.0_wp
[106]869                   ELSEIF ( c_w(k,j) > c_max )  THEN
870                      c_w(k,j) = c_max
871                   ENDIF
872                ELSE
873                   c_w(k,j) = c_max
[73]874                ENDIF
[106]875
[978]876                c_u_m_l(k) = c_u_m_l(k) + c_u(k,j)
877                c_v_m_l(k) = c_v_m_l(k) + c_v(k,j)
878                c_w_m_l(k) = c_w_m_l(k) + c_w(k,j)
[106]879
[978]880             ENDDO
881          ENDDO
[73]882
[978]883#if defined( __parallel )   
884          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
885          CALL MPI_ALLREDUCE( c_u_m_l(nzb+1), c_u_m(nzb+1), nzt-nzb, MPI_REAL, &
886                              MPI_SUM, comm1dy, ierr )   
887          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
888          CALL MPI_ALLREDUCE( c_v_m_l(nzb+1), c_v_m(nzb+1), nzt-nzb, MPI_REAL, &
889                              MPI_SUM, comm1dy, ierr ) 
890          IF ( collective_wait )  CALL MPI_BARRIER( comm1dy, ierr )
891          CALL MPI_ALLREDUCE( c_w_m_l(nzb+1), c_w_m(nzb+1), nzt-nzb, MPI_REAL, &
892                              MPI_SUM, comm1dy, ierr ) 
893#else
894          c_u_m = c_u_m_l
895          c_v_m = c_v_m_l
896          c_w_m = c_w_m_l
897#endif
898
899          c_u_m = c_u_m / (ny+1)
900          c_v_m = c_v_m / (ny+1)
901          c_w_m = c_w_m / (ny+1)
902
[73]903!
[978]904!--       Save old timelevels for the next timestep
905          IF ( intermediate_timestep_count == 1 )  THEN
906                u_m_r(:,:,:) = u(:,:,nx-1:nx)
907                v_m_r(:,:,:) = v(:,:,nx-1:nx)
908                w_m_r(:,:,:) = w(:,:,nx-1:nx)
909          ENDIF
[73]910
[978]911!
912!--       Calculate the new velocities
[996]913          DO  k = nzb+1, nzt+1
[1113]914             DO  j = nysg, nyng
[978]915                u_p(k,j,nx+1) = u(k,j,nx+1) - dt_3d * tsc(2) * c_u_m(k) *      &
916                                       ( u(k,j,nx+1) - u(k,j,nx) ) * ddx
[73]917
[978]918                v_p(k,j,nx+1) = v(k,j,nx+1) - dt_3d * tsc(2) * c_v_m(k) *      &
919                                       ( v(k,j,nx+1) - v(k,j,nx) ) * ddx
[73]920
[978]921                w_p(k,j,nx+1) = w(k,j,nx+1) - dt_3d * tsc(2) * c_w_m(k) *      &
922                                       ( w(k,j,nx+1) - w(k,j,nx) ) * ddx
923             ENDDO
[73]924          ENDDO
925
926!
[978]927!--       Bottom boundary at the outflow
928          IF ( ibc_uv_b == 0 )  THEN
[1353]929             u_p(nzb,:,nx+1) = 0.0_wp
930             v_p(nzb,:,nx+1) = 0.0_wp 
[978]931          ELSE                   
932             u_p(nzb,:,nx+1) =  u_p(nzb+1,:,nx+1)
933             v_p(nzb,:,nx+1) =  v_p(nzb+1,:,nx+1)
934          ENDIF
[1353]935          w_p(nzb,:,nx+1) = 0.0_wp
[73]936
937!
[978]938!--       Top boundary at the outflow
939          IF ( ibc_uv_t == 0 )  THEN
940             u_p(nzt+1,:,nx+1) = u_init(nzt+1)
941             v_p(nzt+1,:,nx+1) = v_init(nzt+1)
942          ELSE
943             u_p(nzt+1,:,nx+1) = u_p(nzt,:,nx+1)
944             v_p(nzt+1,:,nx+1) = v_p(nzt,:,nx+1)
945          ENDIF
[1742]946          w_p(nzt:nzt+1,:,nx+1) = 0.0_wp
[978]947
[1]948       ENDIF
949
950    ENDIF
951
952 END SUBROUTINE boundary_conds
Note: See TracBrowser for help on using the repository browser.