MODULE diffusion_e_mod !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: diffusion_e.f90 791 2011-11-29 03:33:42Z suehring $ ! ! 790 2011-11-29 03:11:20Z raasch ! diss is also calculated in case that the Wang kernel is used ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! ! 97 2007-06-21 08:23:15Z raasch ! Adjustment of mixing length calculation for the ocean version. zw added to ! argument list. ! This is also a bugfix, because the height above the topography is now ! used instead of the height above level k=0. ! theta renamed var, dpt_dz renamed dvar_dz, +new argument var_reference ! use_pt_reference renamed use_reference ! ! 65 2007-03-13 12:11:43Z raasch ! Reference temperature pt_reference can be used in buoyancy term ! ! 20 2007-02-26 00:12:32Z raasch ! Bugfix: ddzw dimensioned 1:nzt"+1" ! Calculation extended for gridpoint nzt ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.18 2006/08/04 14:29:43 raasch ! dissipation is stored in extra array diss if needed later on for calculating ! the sgs particle velocities ! ! Revision 1.1 1997/09/19 07:40:24 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion- and dissipation terms for the TKE !------------------------------------------------------------------------------! PRIVATE PUBLIC diffusion_e INTERFACE diffusion_e MODULE PROCEDURE diffusion_e MODULE PROCEDURE diffusion_e_ij END INTERFACE diffusion_e CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE diffusion_e( ddzu, dd2zu, ddzw, diss, e, km, l_grid, var, & var_reference, rif, tend, zu, zw ) USE control_parameters USE grid_variables USE indices USE particle_attributes IMPLICIT NONE INTEGER :: i, j, k REAL :: dvar_dz, l_stable, phi_m, var_reference REAL :: ddzu(1:nzt+1), dd2zu(1:nzt), ddzw(1:nzt+1), & l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) REAL, DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: diss, tend REAL, DIMENSION(:,:), POINTER :: rif REAL, DIMENSION(:,:,:), POINTER :: e, km, var REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: dissipation, l, ll ! !-- This if clause must be outside the k-loop because otherwise !-- runtime errors occur with -C hopt on NEC IF ( use_reference ) THEN DO i = nxl, nxr DO j = nys, nyn ! !-- First, calculate phi-function for eventually adjusting the & !-- mixing length to the prandtl mixing length IF ( adjust_mixing_length .AND. prandtl_layer ) THEN IF ( rif(j,i) >= 0.0 ) THEN phi_m = 1.0 + 5.0 * rif(j,i) ELSE phi_m = 1.0 / SQRT( SQRT( 1.0 - 16.0 * rif(j,i) ) ) ENDIF ENDIF DO k = nzb_s_inner(j,i)+1, nzt ! !-- Calculate the mixing length (for dissipation) dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var_reference * dvar_dz ) + 1E-5 ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k), l_stable ) ll(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k) ) ELSE l(k,j) = MIN( l_grid(k), l_stable ) ll(k,j) = l_grid(k) ENDIF IF ( adjust_mixing_length .AND. prandtl_layer ) THEN l(k,j) = MIN( l(k,j), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) & / phi_m ) ll(k,j) = MIN( ll(k,j), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) & / phi_m ) ENDIF ENDDO ENDDO ! !-- Calculate the tendency terms DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt dissipation(k,j) = ( 0.19 + 0.74 * l(k,j) / ll(k,j) ) * & e(k,j,i) * SQRT( e(k,j,i) ) / l(k,j) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k,j) ENDDO ENDDO ! !-- Store dissipation if needed for calculating the sgs particle !-- velocities IF ( use_sgs_for_particles .OR. wang_collision_kernel ) THEN DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k,j) ENDDO ENDDO ENDIF ENDDO ELSE DO i = nxl, nxr DO j = nys, nyn ! !-- First, calculate phi-function for eventually adjusting the & !-- mixing length to the prandtl mixing length IF ( adjust_mixing_length .AND. prandtl_layer ) THEN IF ( rif(j,i) >= 0.0 ) THEN phi_m = 1.0 + 5.0 * rif(j,i) ELSE phi_m = 1.0 / SQRT( SQRT( 1.0 - 16.0 * rif(j,i) ) ) ENDIF ENDIF DO k = nzb_s_inner(j,i)+1, nzt ! !-- Calculate the mixing length (for dissipation) dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5 ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k), l_stable ) ll(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k) ) ELSE l(k,j) = MIN( l_grid(k), l_stable ) ll(k,j) = l_grid(k) ENDIF IF ( adjust_mixing_length .AND. prandtl_layer ) THEN l(k,j) = MIN( l(k,j), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) & / phi_m ) ll(k,j) = MIN( ll(k,j), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) & / phi_m ) ENDIF ENDDO ENDDO ! !-- Calculate the tendency terms DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt dissipation(k,j) = ( 0.19 + 0.74 * l(k,j) / ll(k,j) ) * & e(k,j,i) * SQRT( e(k,j,i) ) / l(k,j) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k,j) ENDDO ENDDO ! !-- Store dissipation if needed for calculating the sgs particle !-- velocities IF ( use_sgs_for_particles .OR. wang_collision_kernel ) THEN DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k,j) ENDDO ENDDO ENDIF ENDDO ENDIF ! !-- Boundary condition for dissipation IF ( use_sgs_for_particles .OR. wang_collision_kernel ) THEN DO i = nxl, nxr DO j = nys, nyn diss(nzb_s_inner(j,i),j,i) = diss(nzb_s_inner(j,i)+1,j,i) ENDDO ENDDO ENDIF END SUBROUTINE diffusion_e !------------------------------------------------------------------------------! ! Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE diffusion_e_ij( i, j, ddzu, dd2zu, ddzw, diss, e, km, l_grid, & var, var_reference, rif, tend, zu, zw ) USE control_parameters USE grid_variables USE indices USE particle_attributes IMPLICIT NONE INTEGER :: i, j, k REAL :: dvar_dz, l_stable, phi_m, var_reference REAL :: ddzu(1:nzt+1), dd2zu(1:nzt), ddzw(1:nzt+1), & l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) REAL, DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: diss, tend REAL, DIMENSION(:,:), POINTER :: rif REAL, DIMENSION(:,:,:), POINTER :: e, km, var REAL, DIMENSION(nzb+1:nzt) :: dissipation, l, ll ! !-- First, calculate phi-function for eventually adjusting the mixing length !-- to the prandtl mixing length IF ( adjust_mixing_length .AND. prandtl_layer ) THEN IF ( rif(j,i) >= 0.0 ) THEN phi_m = 1.0 + 5.0 * rif(j,i) ELSE phi_m = 1.0 / SQRT( SQRT( 1.0 - 16.0 * rif(j,i) ) ) ENDIF ENDIF ! !-- Calculate the mixing length (for dissipation) DO k = nzb_s_inner(j,i)+1, nzt dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN IF ( use_reference ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var_reference * dvar_dz ) + 1E-5 ELSE l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5 ENDIF ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), l_grid(k), & l_stable ) ll(k) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), l_grid(k) ) ELSE l(k) = MIN( l_grid(k), l_stable ) ll(k) = l_grid(k) ENDIF IF ( adjust_mixing_length .AND. prandtl_layer ) THEN l(k) = MIN( l(k), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) / phi_m ) ll(k) = MIN( ll(k), kappa * & ( zu(k) - zw(nzb_s_inner(j,i)) ) / phi_m ) ENDIF ! !-- Calculate the tendency term dissipation(k) = ( 0.19 + 0.74 * l(k) / ll(k) ) * e(k,j,i) * & SQRT( e(k,j,i) ) / l(k) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k) ENDDO ! !-- Store dissipation if needed for calculating the sgs particle velocities IF ( use_sgs_for_particles .OR. wang_collision_kernel ) THEN DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k) ENDDO ! !-- Boundary condition for dissipation diss(nzb_s_inner(j,i),j,i) = diss(nzb_s_inner(j,i)+1,j,i) ENDIF END SUBROUTINE diffusion_e_ij END MODULE diffusion_e_mod