MODULE diffusion_w_mod !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! ! Former revisions: ! ----------------- ! $Id: diffusion_w.f90 668 2010-12-23 13:22:58Z helmke $ ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! ! 366 2009-08-25 08:06:27Z raasch ! bc_lr/bc_ns replaced by bc_lr_cyc/bc_ns_cyc ! ! 75 2007-03-22 09:54:05Z raasch ! Wall functions now include diabatic conditions, call of routine wall_fluxes, ! z0 removed from argument list ! ! 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.12 2006/02/23 10:38:03 raasch ! nzb_2d replaced by nzb_w_outer, wall functions added for all vertical walls, ! +z0 in argument list ! WARNING: loops containing the MAX function are still not properly vectorized! ! ! Revision 1.1 1997/09/12 06:24:11 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion term of the w-component !------------------------------------------------------------------------------! USE wall_fluxes_mod PRIVATE PUBLIC diffusion_w INTERFACE diffusion_w MODULE PROCEDURE diffusion_w MODULE PROCEDURE diffusion_w_ij END INTERFACE diffusion_w CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE diffusion_w( ddzu, ddzw, km, km_damp_x, km_damp_y, tend, u, v, & w ) USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmxm_x, kmxm_z, kmxp_x, kmxp_z, kmym_y, kmym_z, kmyp_y, & kmyp_z REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1), km_damp_x(nxlg:nxrg), & km_damp_y(nysg:nyng) REAL :: tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) REAL, DIMENSION(:,:,:), POINTER :: km, u, v, w REAL, DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: wsus, wsvs ! !-- First calculate horizontal momentum flux w'u' and/or w'v' at vertical !-- walls, if neccessary IF ( topography /= 'flat' ) THEN CALL wall_fluxes( wsus, 0.0, 0.0, 0.0, 1.0, nzb_w_inner, & nzb_w_outer, wall_w_x ) CALL wall_fluxes( wsvs, 0.0, 0.0, 1.0, 0.0, nzb_w_inner, & nzb_w_outer, wall_w_y ) ENDIF DO i = nxl, nxr DO j = nys, nyn DO k = nzb_w_outer(j,i)+1, nzt-1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp_x = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm_x = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmxp_z = kmxp_x kmxm_z = kmxm_x kmyp_y = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym_y = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) kmyp_z = kmyp_y kmym_z = kmym_y ! !-- 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 ( .NOT. bc_lr_cyc ) THEN kmxp_x = MAX( kmxp_x, km_damp_x(i) ) kmxm_x = MAX( kmxm_x, km_damp_x(i) ) ENDIF IF ( .NOT. bc_ns_cyc ) 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) & & + ( kmxp_x * ( w(k,j,i+1) - w(k,j,i) ) * ddx & & + kmxp_z * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & & - kmxm_x * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & - kmxm_z * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & ) * ddx & & + ( kmyp_y * ( w(k,j+1,i) - w(k,j,i) ) * ddy & & + kmyp_z * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & & - kmym_y * ( w(k,j,i) - w(k,j-1,i) ) * ddy & & - kmym_z * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & & ) * ddy & & + 2.0 * ( & & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & & ) * ddzu(k+1) ENDDO ! !-- Wall functions at all vertical walls, where necessary IF ( wall_w_x(j,i) /= 0.0 .OR. wall_w_y(j,i) /= 0.0 ) THEN DO k = nzb_w_inner(j,i)+1, nzb_w_outer(j,i) ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp_x = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm_x = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmxp_z = kmxp_x kmxm_z = kmxm_x kmyp_y = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym_y = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) kmyp_z = kmyp_y kmym_z = kmym_y ! !-- 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 ( .NOT. bc_lr_cyc ) THEN kmxp_x = MAX( kmxp_x, km_damp_x(i) ) kmxm_x = MAX( kmxm_x, km_damp_x(i) ) ENDIF IF ( .NOT. bc_ns_cyc ) 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) & + ( fwxp(j,i) * ( & kmxp_x * ( w(k,j,i+1) - w(k,j,i) ) * ddx & + kmxp_z * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & ) & - fwxm(j,i) * ( & kmxm_x * ( w(k,j,i) - w(k,j,i-1) ) * ddx & + kmxm_z * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & ) & + wall_w_x(j,i) * wsus(k,j,i) & ) * ddx & + ( fwyp(j,i) * ( & kmyp_y * ( w(k,j+1,i) - w(k,j,i) ) * ddy & + kmyp_z * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & ) & - fwym(j,i) * ( & kmym_y * ( w(k,j,i) - w(k,j-1,i) ) * ddy & + kmym_z * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & ) & + wall_w_y(j,i) * wsvs(k,j,i) & ) * ddy & + 2.0 * ( & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & ) * ddzu(k+1) ENDDO ENDIF ENDDO ENDDO END SUBROUTINE diffusion_w !------------------------------------------------------------------------------! ! Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE diffusion_w_ij( i, j, ddzu, ddzw, km, km_damp_x, km_damp_y, & tend, u, v, w ) USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmxm_x, kmxm_z, kmxp_x, kmxp_z, kmym_y, kmym_z, kmyp_y, & kmyp_z REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1), km_damp_x(nxlg:nxrg), & km_damp_y(nysg:nyng) REAL :: tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) REAL, DIMENSION(nzb:nzt+1) :: wsus, wsvs REAL, DIMENSION(:,:,:), POINTER :: km, u, v, w DO k = nzb_w_outer(j,i)+1, nzt-1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp_x = 0.25 * ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm_x = 0.25 * ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmxp_z = kmxp_x kmxm_z = kmxm_x kmyp_y = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym_y = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) kmyp_z = kmyp_y kmym_z = kmym_y ! !-- 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 ( .NOT. bc_lr_cyc ) THEN kmxp_x = MAX( kmxp_x, km_damp_x(i) ) kmxm_x = MAX( kmxm_x, km_damp_x(i) ) ENDIF IF ( .NOT. bc_ns_cyc ) 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) & & + ( kmxp_x * ( w(k,j,i+1) - w(k,j,i) ) * ddx & & + kmxp_z * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & & - kmxm_x * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & - kmxm_z * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & ) * ddx & & + ( kmyp_y * ( w(k,j+1,i) - w(k,j,i) ) * ddy & & + kmyp_z * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & & - kmym_y * ( w(k,j,i) - w(k,j-1,i) ) * ddy & & - kmym_z * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & & ) * ddy & & + 2.0 * ( & & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & & ) * ddzu(k+1) ENDDO ! !-- Wall functions at all vertical walls, where necessary IF ( wall_w_x(j,i) /= 0.0 .OR. wall_w_y(j,i) /= 0.0 ) THEN ! !-- Calculate the horizontal momentum fluxes w'u' and/or w'v' IF ( wall_w_x(j,i) /= 0.0 ) THEN CALL wall_fluxes( i, j, nzb_w_inner(j,i)+1, nzb_w_outer(j,i), & wsus, 0.0, 0.0, 0.0, 1.0 ) ELSE wsus = 0.0 ENDIF IF ( wall_w_y(j,i) /= 0.0 ) THEN CALL wall_fluxes( i, j, nzb_w_inner(j,i)+1, nzb_w_outer(j,i), & wsvs, 0.0, 0.0, 1.0, 0.0 ) ELSE wsvs = 0.0 ENDIF DO k = nzb_w_inner(j,i)+1, nzb_w_outer(j,i) ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp_x = 0.25 * ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm_x = 0.25 * ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmxp_z = kmxp_x kmxm_z = kmxm_x kmyp_y = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym_y = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) kmyp_z = kmyp_y kmym_z = kmym_y ! !-- 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 ( .NOT. bc_lr_cyc ) THEN kmxp_x = MAX( kmxp_x, km_damp_x(i) ) kmxm_x = MAX( kmxm_x, km_damp_x(i) ) ENDIF IF ( .NOT. bc_ns_cyc ) 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) & + ( fwxp(j,i) * ( & kmxp_x * ( w(k,j,i+1) - w(k,j,i) ) * ddx & + kmxp_z * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & ) & - fwxm(j,i) * ( & kmxm_x * ( w(k,j,i) - w(k,j,i-1) ) * ddx & + kmxm_z * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & ) & + wall_w_x(j,i) * wsus(k) & ) * ddx & + ( fwyp(j,i) * ( & kmyp_y * ( w(k,j+1,i) - w(k,j,i) ) * ddy & + kmyp_z * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & ) & - fwym(j,i) * ( & kmym_y * ( w(k,j,i) - w(k,j-1,i) ) * ddy & + kmym_z * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & ) & + wall_w_y(j,i) * wsvs(k) & ) * ddy & + 2.0 * ( & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & ) * ddzu(k+1) ENDDO ENDIF END SUBROUTINE diffusion_w_ij END MODULE diffusion_w_mod