MODULE diffusion_u_mod !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! Wall functions now include diabatic conditions, call of routine wall_fluxes ! ! Former revisions: ! ----------------- ! $Id: diffusion_u.f90 53 2007-03-07 12:33:47Z raasch $ ! ! 20 2007-02-26 00:12:32Z raasch ! Bugfix: ddzw dimensioned 1:nzt"+1" ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.15 2006/02/23 10:35:35 raasch ! nzb_2d replaced by nzb_u_outer in horizontal diffusion and by nzb_u_inner ! or nzb_diff_u, respectively, in vertical diffusion, ! wall functions added for north and south walls, +z0 in argument list, ! terms containing w(k-1,..) are removed from the Prandtl-layer equation ! because they cause errors at the edges of topography ! WARNING: loops containing the MAX function are still not properly vectorized! ! ! Revision 1.1 1997/09/12 06:23:51 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion term of the u-component ! To do: additional damping (needed for non-cyclic bc) causes bad vectorization ! and slows down the speed on NEC about 5-10% !------------------------------------------------------------------------------! PRIVATE PUBLIC diffusion_u INTERFACE diffusion_u MODULE PROCEDURE diffusion_u MODULE PROCEDURE diffusion_u_ij END INTERFACE diffusion_u CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE diffusion_u( ddzu, ddzw, km, km_damp_y, tend, u, usws, v, w, z0 ) USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmym_x, kmym_y, kmyp_x, kmyp_y, kmzm, kmzp REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1), km_damp_y(nys-1:nyn+1) REAL :: z0(nys-1:nyn+1,nxl-1:nxr+1) REAL :: tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) REAL, DIMENSION(nzb:nzt+1) :: usvs REAL, DIMENSION(:,:), POINTER :: usws REAL, DIMENSION(:,:,:), POINTER :: km, u, v, w DO i = nxl, nxr+uxrp DO j = nys,nyn ! !-- Compute horizontal diffusion DO k = nzb_u_outer(j,i)+1, nzt ! !-- Interpolate eddy diffusivities on staggered gridpoints kmyp_x = 0.25 * & ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) ) kmym_x = 0.25 * & ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) ) kmyp_y = kmyp_x kmym_y = kmym_x ! !-- Increase diffusion at the outflow boundary in case of !-- non-cyclic lateral boundaries. Damping is only needed for !-- velocity components parallel to the outflow boundary in !-- the direction normal to the outflow boundary. IF ( bc_ns /= 'cyclic' ) THEN kmyp_y = MAX( kmyp_y, km_damp_y(j) ) kmym_y = MAX( kmym_y, km_damp_y(j) ) ENDIF tend(k,j,i) = tend(k,j,i) & & + 2.0 * ( & & km(k,j,i) * ( u(k,j,i+1) - u(k,j,i) ) & & - km(k,j,i-1) * ( u(k,j,i) - u(k,j,i-1) ) & & ) * ddx2 & & + ( kmyp_y * ( u(k,j+1,i) - u(k,j,i) ) * ddy & & + kmyp_x * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx & & - kmym_y * ( u(k,j,i) - u(k,j-1,i) ) * ddy & & - kmym_x * ( v(k,j,i) - v(k,j,i-1) ) * ddx & & ) * ddy ENDDO ! !-- Wall functions at the north and south walls, respectively IF ( wall_u(j,i) /= 0.0 ) THEN ! !-- Calculate the horizontal momentum flux u'v' CALL wall_fluxes( i, j, nzb_u_inner(j,i)+1, nzb_u_outer(j,i), & usvs, 1.0, 0.0, 0.0, 0.0 ) DO k = nzb_u_inner(j,i)+1, nzb_u_outer(j,i) kmyp_x = 0.25 * & ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) ) kmym_x = 0.25 * & ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) ) kmyp_y = kmyp_x kmym_y = kmym_x ! !-- Increase diffusion at the outflow boundary in case of !-- non-cyclic lateral boundaries. Damping is only needed for !-- velocity components parallel to the outflow boundary in !-- the direction normal to the outflow boundary. IF ( bc_ns /= 'cyclic' ) THEN kmyp_y = MAX( kmyp_y, km_damp_y(j) ) kmym_y = MAX( kmym_y, km_damp_y(j) ) ENDIF tend(k,j,i) = tend(k,j,i) & + 2.0 * ( & km(k,j,i) * ( u(k,j,i+1) - u(k,j,i) ) & - km(k,j,i-1) * ( u(k,j,i) - u(k,j,i-1) ) & ) * ddx2 & + ( fyp(j,i) * ( & kmyp_y * ( u(k,j+1,i) - u(k,j,i) ) * ddy & + kmyp_x * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx & ) & - fym(j,i) * ( & kmym_y * ( u(k,j,i) - u(k,j-1,i) ) * ddy & + kmym_x * ( v(k,j,i) - v(k,j,i-1) ) * ddx & ) & + wall_u(j,i) * usvs(k) & ) * ddy ENDDO ENDIF ! !-- Compute vertical diffusion. In case of simulating a Prandtl layer, !-- index k starts at nzb_u_inner+2. DO k = nzb_diff_u(j,i), nzt ! !-- Interpolate eddy diffusivities on staggered gridpoints kmzp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) ) kmzm = 0.25 * & ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) ) tend(k,j,i) = tend(k,j,i) & & + ( kmzp * ( ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & + ( w(k,j,i) - w(k,j,i-1) ) * ddx & & ) & & - kmzm * ( ( u(k,j,i) - u(k-1,j,i) ) * ddzu(k) & & + ( w(k-1,j,i) - w(k-1,j,i-1) ) * ddx & & ) & & ) * ddzw(k) ENDDO ! !-- Vertical diffusion at the first grid point above the surface, !-- if the momentum flux at the bottom is given by the Prandtl law or !-- if it is prescribed by the user. !-- Difference quotient of the momentum flux is not formed over half !-- of the grid spacing (2.0*ddzw(k)) any more, since the comparison !-- with other (LES) modell showed that the values of the momentum !-- flux becomes too large in this case. !-- The term containing w(k-1,..) (see above equation) is removed here !-- because the vertical velocity is assumed to be zero at the surface. IF ( use_surface_fluxes ) THEN k = nzb_u_inner(j,i)+1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmzp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) ) kmzm = 0.25 * & ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) ) tend(k,j,i) = tend(k,j,i) & & + ( kmzp * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & ) * ddzw(k) & & + ( kmzp * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & + usws(j,i) & & ) * ddzw(k) ENDIF ENDDO ENDDO END SUBROUTINE diffusion_u !------------------------------------------------------------------------------! ! Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE diffusion_u_ij( i, j, ddzu, ddzw, km, km_damp_y, tend, u, usws, & v, w, z0 ) USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmym_x, kmym_y, kmyp_x, kmyp_y, kmzm, kmzp REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1), km_damp_y(nys-1:nyn+1) REAL :: z0(nys-1:nyn+1,nxl-1:nxr+1) REAL :: tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) REAL, DIMENSION(nzb:nzt+1) :: usvs REAL, DIMENSION(:,:), POINTER :: usws REAL, DIMENSION(:,:,:), POINTER :: km, u, v, w ! !-- Compute horizontal diffusion DO k = nzb_u_outer(j,i)+1, nzt ! !-- Interpolate eddy diffusivities on staggered gridpoints kmyp_x = 0.25 * ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) ) kmym_x = 0.25 * ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) ) kmyp_y = kmyp_x kmym_y = kmym_x ! !-- Increase diffusion at the outflow boundary in case of non-cyclic !-- lateral boundaries. Damping is only needed for velocity components !-- parallel to the outflow boundary in the direction normal to the !-- outflow boundary. IF ( bc_ns /= 'cyclic' ) THEN kmyp_y = MAX( kmyp_y, km_damp_y(j) ) kmym_y = MAX( kmym_y, km_damp_y(j) ) ENDIF tend(k,j,i) = tend(k,j,i) & & + 2.0 * ( & & km(k,j,i) * ( u(k,j,i+1) - u(k,j,i) ) & & - km(k,j,i-1) * ( u(k,j,i) - u(k,j,i-1) ) & & ) * ddx2 & & + ( kmyp_y * ( u(k,j+1,i) - u(k,j,i) ) * ddy & & + kmyp_x * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx & & - kmym_y * ( u(k,j,i) - u(k,j-1,i) ) * ddy & & - kmym_x * ( v(k,j,i) - v(k,j,i-1) ) * ddx & & ) * ddy ENDDO ! !-- Wall functions at the north and south walls, respectively IF ( wall_u(j,i) .NE. 0.0 ) THEN ! !-- Calculate the horizontal momentum flux u'v' CALL wall_fluxes( i, j, nzb_u_inner(j,i)+1, nzb_u_outer(j,i), & usvs, 1.0, 0.0, 0.0, 0.0 ) DO k = nzb_u_inner(j,i)+1, nzb_u_outer(j,i) kmyp_x = 0.25 * ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) ) kmym_x = 0.25 * ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) ) kmyp_y = kmyp_x kmym_y = kmym_x ! !-- Increase diffusion at the outflow boundary in case of !-- non-cyclic lateral boundaries. Damping is only needed for !-- velocity components parallel to the outflow boundary in !-- the direction normal to the outflow boundary. IF ( bc_ns /= 'cyclic' ) THEN kmyp_y = MAX( kmyp_y, km_damp_y(j) ) kmym_y = MAX( kmym_y, km_damp_y(j) ) ENDIF tend(k,j,i) = tend(k,j,i) & + 2.0 * ( & km(k,j,i) * ( u(k,j,i+1) - u(k,j,i) ) & - km(k,j,i-1) * ( u(k,j,i) - u(k,j,i-1) ) & ) * ddx2 & + ( fyp(j,i) * ( & kmyp_y * ( u(k,j+1,i) - u(k,j,i) ) * ddy & + kmyp_x * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx & ) & - fym(j,i) * ( & kmym_y * ( u(k,j,i) - u(k,j-1,i) ) * ddy & + kmym_x * ( v(k,j,i) - v(k,j,i-1) ) * ddx & ) & + wall_u(j,i) * usvs(k) & ) * ddy ENDDO ENDIF ! !-- Compute vertical diffusion. In case of simulating a Prandtl layer, !-- index k starts at nzb_u_inner+2. DO k = nzb_diff_u(j,i), nzt ! !-- Interpolate eddy diffusivities on staggered gridpoints kmzp = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) ) kmzm = 0.25 * ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) ) tend(k,j,i) = tend(k,j,i) & & + ( kmzp * ( ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & + ( w(k,j,i) - w(k,j,i-1) ) * ddx & & ) & & - kmzm * ( ( u(k,j,i) - u(k-1,j,i) ) * ddzu(k) & & + ( w(k-1,j,i) - w(k-1,j,i-1) ) * ddx & & ) & & ) * ddzw(k) ENDDO ! !-- Vertical diffusion at the first grid point above the surface, if the !-- momentum flux at the bottom is given by the Prandtl law or if it is !-- prescribed by the user. !-- Difference quotient of the momentum flux is not formed over half of !-- the grid spacing (2.0*ddzw(k)) any more, since the comparison with !-- other (LES) modell showed that the values of the momentum flux becomes !-- too large in this case. !-- The term containing w(k-1,..) (see above equation) is removed here !-- because the vertical velocity is assumed to be zero at the surface. IF ( use_surface_fluxes ) THEN k = nzb_u_inner(j,i)+1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmzp = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) ) kmzm = 0.25 * ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) ) tend(k,j,i) = tend(k,j,i) & & + ( kmzp * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & ) * ddzw(k) & & + ( kmzp * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & + usws(j,i) & & ) * ddzw(k) ENDIF END SUBROUTINE diffusion_u_ij END MODULE diffusion_u_mod