SUBROUTINE prandtl_fluxes !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2014 Leibniz Universitaet Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: prandtl_fluxes.f90 1310 2014-03-14 08:01:56Z fricke $ ! ! 1276 2014-01-15 13:40:41Z heinze ! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars ! ! 1257 2013-11-08 15:18:40Z raasch ! openACC "kernels do" replaced by "kernels loop", "loop independent" added ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! OpenACC statements added ! ! 978 2012-08-09 08:28:32Z fricke ! roughness length for scalar quantities z0h added ! ! 759 2011-09-15 13:58:31Z raasch ! Bugfix for ts limitation ! ! 709 2011-03-30 09:31:40Z raasch ! formatting adjustments ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! Changed surface boundary conditions for u and v from mirror to Dirichlet. ! Therefore u(uzb,:,:) and v(nzb,:,:) are now representative for height z0. ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! ! 315 2009-05-13 10:57:59Z raasch ! Saturation condition at (sea) surface is not used in precursor runs (only ! in the following coupled runs) ! Bugfix: qsws was calculated in case of constant heatflux = .FALSE. ! ! 187 2008-08-06 16:25:09Z letzel ! Bugfix: modification of the calculation of the vertical turbulent momentum ! fluxes u'w' and v'w' ! Bugfix: change definition of us_wall from 1D to 2D ! Change: modification of the integrated version of the profile function for ! momentum for unstable stratification (does not effect results) ! ! 108 2007-08-24 15:10:38Z letzel ! assume saturation at k=nzb_s_inner(j,i) for atmosphere coupled to ocean ! ! 75 2007-03-22 09:54:05Z raasch ! moisture renamed humidity ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.19 2006/04/26 12:24:35 raasch ! +OpenMP directives and optimization (array assignments replaced by DO loops) ! ! Revision 1.1 1998/01/23 10:06:06 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diagnostic computation of vertical fluxes in the Prandtl layer from the ! values of the variables at grid point k=1 !------------------------------------------------------------------------------! USE arrays_3d USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k LOGICAL :: coupled_run REAL :: a, b, e_q, rifm, uv_total, z_p ! !-- Data information for accelerators !$acc data present( e, nzb_u_inner, nzb_v_inner, nzb_s_inner, pt, q, qs ) & !$acc present( qsws, rif, shf, ts, u, us, usws, v, vpt, vsws, zu, zw, z0, z0h ) ! !-- Compute theta* IF ( constant_heatflux ) THEN ! !-- For a given heat flux in the Prandtl layer: !-- for u* use the value from the previous time step !$OMP PARALLEL DO !$acc kernels loop DO i = nxlg, nxrg DO j = nysg, nyng ts(j,i) = -shf(j,i) / ( us(j,i) + 1E-30 ) ! !-- ts must be limited, because otherwise overflow may occur in case of !-- us=0 when computing rif further below IF ( ts(j,i) < -1.05E5 ) ts(j,i) = -1.0E5 IF ( ts(j,i) > 1.0E5 ) ts(j,i) = 1.0E5 ENDDO ENDDO ELSE ! !-- For a given surface temperature: !-- (the Richardson number is still the one from the previous time step) IF ( large_scale_forcing .AND. lsf_surf ) THEN pt(0,:,:) = pt_surface ENDIF !$OMP PARALLEL DO PRIVATE( a, b, k, z_p ) !$acc kernels loop DO i = nxlg, nxrg DO j = nysg, nyng k = nzb_s_inner(j,i) z_p = zu(k+1) - zw(k) IF ( rif(j,i) >= 0.0 ) THEN ! !-- Stable stratification ts(j,i) = kappa * ( pt(k+1,j,i) - pt(k,j,i) ) / ( & LOG( z_p / z0h(j,i) ) + & 5.0 * rif(j,i) * ( z_p - z0h(j,i) ) / z_p & ) ELSE ! !-- Unstable stratification a = SQRT( 1.0 - 16.0 * rif(j,i) ) b = SQRT( 1.0 - 16.0 * rif(j,i) * z0h(j,i) / z_p ) ts(j,i) = kappa * ( pt(k+1,j,i) - pt(k,j,i) ) / ( & LOG( z_p / z0h(j,i) ) - & 2.0 * LOG( ( 1.0 + a ) / ( 1.0 + b ) ) ) ENDIF ENDDO ENDDO ENDIF ! !-- Compute z_p/L (corresponds to the Richardson-flux number) IF ( .NOT. humidity ) THEN !$OMP PARALLEL DO PRIVATE( k, z_p ) !$acc kernels loop DO i = nxlg, nxrg DO j = nysg, nyng k = nzb_s_inner(j,i) z_p = zu(k+1) - zw(k) rif(j,i) = z_p * kappa * g * ts(j,i) / & ( pt(k+1,j,i) * ( us(j,i)**2 + 1E-30 ) ) ! !-- Limit the value range of the Richardson numbers. !-- This is necessary for very small velocities (u,v --> 0), because !-- the absolute value of rif can then become very large, which in !-- consequence would result in very large shear stresses and very !-- small momentum fluxes (both are generally unrealistic). IF ( rif(j,i) < rif_min ) rif(j,i) = rif_min IF ( rif(j,i) > rif_max ) rif(j,i) = rif_max ENDDO ENDDO ELSE !$OMP PARALLEL DO PRIVATE( k, z_p ) !$acc kernels loop DO i = nxlg, nxrg DO j = nysg, nyng k = nzb_s_inner(j,i) z_p = zu(k+1) - zw(k) rif(j,i) = z_p * kappa * g * & ( ts(j,i) + 0.61 * pt(k+1,j,i) * qs(j,i) ) / & ( vpt(k+1,j,i) * ( us(j,i)**2 + 1E-30 ) ) ! !-- Limit the value range of the Richardson numbers. !-- This is necessary for very small velocities (u,v --> 0), because !-- the absolute value of rif can then become very large, which in !-- consequence would result in very large shear stresses and very !-- small momentum fluxes (both are generally unrealistic). IF ( rif(j,i) < rif_min ) rif(j,i) = rif_min IF ( rif(j,i) > rif_max ) rif(j,i) = rif_max ENDDO ENDDO ENDIF ! !-- Compute u* at the scalars' grid points !$OMP PARALLEL DO PRIVATE( a, b, k, uv_total, z_p ) !$acc kernels loop DO i = nxl, nxr DO j = nys, nyn k = nzb_s_inner(j,i) z_p = zu(k+1) - zw(k) ! !-- Compute the absolute value of the horizontal velocity !-- (relative to the surface) uv_total = SQRT( ( 0.5 * ( u(k+1,j,i) + u(k+1,j,i+1) & - u(k,j,i) - u(k,j,i+1) ) )**2 + & ( 0.5 * ( v(k+1,j,i) + v(k+1,j+1,i) & - v(k,j,i) - v(k,j+1,i) ) )**2 ) IF ( rif(j,i) >= 0.0 ) THEN ! !-- Stable stratification us(j,i) = kappa * uv_total / ( & LOG( z_p / z0(j,i) ) + & 5.0 * rif(j,i) * ( z_p - z0(j,i) ) / z_p & ) ELSE ! !-- Unstable stratification a = SQRT( SQRT( 1.0 - 16.0 * rif(j,i) ) ) b = SQRT( SQRT( 1.0 - 16.0 * rif(j,i) / z_p * z0(j,i) ) ) us(j,i) = kappa * uv_total / ( & LOG( z_p / z0(j,i) ) - & LOG( ( 1.0 + a )**2 * ( 1.0 + a**2 ) / ( & ( 1.0 + b )**2 * ( 1.0 + b**2 ) ) ) + & 2.0 * ( ATAN( a ) - ATAN( b ) ) & ) ENDIF ENDDO ENDDO ! !-- Values of us at ghost point locations are needed for the evaluation of usws !-- and vsws. !$acc update host( us ) CALL exchange_horiz_2d( us ) !$acc update device( us ) ! !-- Compute u'w' for the total model domain. !-- First compute the corresponding component of u* and square it. !$OMP PARALLEL DO PRIVATE( a, b, k, rifm, z_p ) !$acc kernels loop DO i = nxl, nxr DO j = nys, nyn k = nzb_u_inner(j,i) z_p = zu(k+1) - zw(k) ! !-- Compute Richardson-flux number for this point rifm = 0.5 * ( rif(j,i-1) + rif(j,i) ) IF ( rifm >= 0.0 ) THEN ! !-- Stable stratification usws(j,i) = kappa * ( u(k+1,j,i) - u(k,j,i) )/ ( & LOG( z_p / z0(j,i) ) + & 5.0 * rifm * ( z_p - z0(j,i) ) / z_p & ) ELSE ! !-- Unstable stratification a = SQRT( SQRT( 1.0 - 16.0 * rifm ) ) b = SQRT( SQRT( 1.0 - 16.0 * rifm / z_p * z0(j,i) ) ) usws(j,i) = kappa * ( u(k+1,j,i) - u(k,j,i) ) / ( & LOG( z_p / z0(j,i) ) - & LOG( (1.0 + a )**2 * ( 1.0 + a**2 ) / ( & (1.0 + b )**2 * ( 1.0 + b**2 ) ) ) + & 2.0 * ( ATAN( a ) - ATAN( b ) ) & ) ENDIF usws(j,i) = -usws(j,i) * 0.5 * ( us(j,i-1) + us(j,i) ) ENDDO ENDDO ! !-- Compute v'w' for the total model domain. !-- First compute the corresponding component of u* and square it. !$OMP PARALLEL DO PRIVATE( a, b, k, rifm, z_p ) !$acc kernels loop DO i = nxl, nxr DO j = nys, nyn k = nzb_v_inner(j,i) z_p = zu(k+1) - zw(k) ! !-- Compute Richardson-flux number for this point rifm = 0.5 * ( rif(j-1,i) + rif(j,i) ) IF ( rifm >= 0.0 ) THEN ! !-- Stable stratification vsws(j,i) = kappa * ( v(k+1,j,i) - v(k,j,i) ) / ( & LOG( z_p / z0(j,i) ) + & 5.0 * rifm * ( z_p - z0(j,i) ) / z_p & ) ELSE ! !-- Unstable stratification a = SQRT( SQRT( 1.0 - 16.0 * rifm ) ) b = SQRT( SQRT( 1.0 - 16.0 * rifm / z_p * z0(j,i) ) ) vsws(j,i) = kappa * ( v(k+1,j,i) - v(k,j,i) ) / ( & LOG( z_p / z0(j,i) ) - & LOG( (1.0 + a )**2 * ( 1.0 + a**2 ) / ( & (1.0 + b )**2 * ( 1.0 + b**2 ) ) ) + & 2.0 * ( ATAN( a ) - ATAN( b ) ) & ) ENDIF vsws(j,i) = -vsws(j,i) * 0.5 * ( us(j-1,i) + us(j,i) ) ENDDO ENDDO ! !-- If required compute q* IF ( humidity .OR. passive_scalar ) THEN IF ( constant_waterflux ) THEN ! !-- For a given water flux in the Prandtl layer: !$OMP PARALLEL DO !$acc kernels loop DO i = nxlg, nxrg DO j = nysg, nyng qs(j,i) = -qsws(j,i) / ( us(j,i) + 1E-30 ) ENDDO ENDDO ELSE coupled_run = ( coupling_mode == 'atmosphere_to_ocean' .AND. run_coupled ) IF ( large_scale_forcing .AND. lsf_surf ) THEN q(0,:,:) = q_surface ENDIF !$OMP PARALLEL DO PRIVATE( a, b, k, z_p ) !$acc kernels loop independent DO i = nxlg, nxrg !$acc loop independent DO j = nysg, nyng k = nzb_s_inner(j,i) z_p = zu(k+1) - zw(k) ! !-- Assume saturation for atmosphere coupled to ocean (but not !-- in case of precursor runs) IF ( coupled_run ) THEN e_q = 6.1 * & EXP( 0.07 * ( MIN(pt(0,j,i),pt(1,j,i)) - 273.15 ) ) q(k,j,i) = 0.622 * e_q / ( surface_pressure - e_q ) ENDIF IF ( rif(j,i) >= 0.0 ) THEN ! !-- Stable stratification qs(j,i) = kappa * ( q(k+1,j,i) - q(k,j,i) ) / ( & LOG( z_p / z0h(j,i) ) + & 5.0 * rif(j,i) * ( z_p - z0h(j,i) ) / z_p & ) ELSE ! !-- Unstable stratification a = SQRT( 1.0 - 16.0 * rif(j,i) ) b = SQRT( 1.0 - 16.0 * rif(j,i) * z0h(j,i) / z_p ) qs(j,i) = kappa * ( q(k+1,j,i) - q(k,j,i) ) / ( & LOG( z_p / z0h(j,i) ) - & 2.0 * LOG( (1.0 + a ) / ( 1.0 + b ) ) ) ENDIF ENDDO ENDDO ENDIF ENDIF ! !-- Exchange the boundaries for the momentum fluxes (only for sake of !-- completeness) !$acc update host( usws, vsws ) CALL exchange_horiz_2d( usws ) CALL exchange_horiz_2d( vsws ) !$acc update device( usws, vsws ) IF ( humidity .OR. passive_scalar ) THEN !$acc update host( qsws ) CALL exchange_horiz_2d( qsws ) !$acc update device( qsws ) ENDIF ! !-- Compute the vertical kinematic heat flux IF ( .NOT. constant_heatflux ) THEN !$OMP PARALLEL DO !$acc kernels loop independent DO i = nxlg, nxrg !$acc loop independent DO j = nysg, nyng shf(j,i) = -ts(j,i) * us(j,i) ENDDO ENDDO ENDIF ! !-- Compute the vertical water/scalar flux IF ( .NOT. constant_waterflux .AND. ( humidity .OR. passive_scalar ) ) THEN !$OMP PARALLEL DO !$acc kernels loop independent DO i = nxlg, nxrg !$acc loop independent DO j = nysg, nyng qsws(j,i) = -qs(j,i) * us(j,i) ENDDO ENDDO ENDIF ! !-- Bottom boundary condition for the TKE IF ( ibc_e_b == 2 ) THEN !$OMP PARALLEL DO !$acc kernels loop independent DO i = nxlg, nxrg !$acc loop independent DO j = nysg, nyng e(nzb_s_inner(j,i)+1,j,i) = ( us(j,i) / 0.1 )**2 ! !-- As a test: cm = 0.4 ! e(nzb_s_inner(j,i)+1,j,i) = ( us(j,i) / 0.4 )**2 e(nzb_s_inner(j,i),j,i) = e(nzb_s_inner(j,i)+1,j,i) ENDDO ENDDO ENDIF !$acc end data END SUBROUTINE prandtl_fluxes