!> @file plant_canopy_model.f90 !--------------------------------------------------------------------------------! ! 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: plant_canopy_model.f90 1722 2015-11-16 13:06:09Z knoop $ ! ! 1721 2015-11-16 12:56:48Z raasch ! bugfixes: shf is reduced in areas covered with canopy only, ! canopy is set on top of topography ! ! 1682 2015-10-07 23:56:08Z knoop ! Code annotations made doxygen readable ! ! 1484 2014-10-21 10:53:05Z kanani ! Changes due to new module structure of the plant canopy model: ! module plant_canopy_model_mod now contains a subroutine for the ! initialization of the canopy model (init_plant_canopy), ! limitation of the canopy drag (previously accounted for by calculation of ! a limiting canopy timestep for the determination of the maximum LES timestep ! in subroutine timestep) is now realized by the calculation of pre-tendencies ! and preliminary velocities in subroutine plant_canopy_model, ! some redundant MPI communication removed in subroutine init_plant_canopy ! (was previously in init_3d_model), ! unnecessary 3d-arrays lad_u, lad_v, lad_w removed - lad information on the ! respective grid is now provided only by lad_s (e.g. in the calculation of ! the tendency terms or of cum_lai_hf), ! drag_coefficient, lai, leaf_surface_concentration, ! scalar_exchange_coefficient, sec and sls renamed to canopy_drag_coeff, ! cum_lai_hf, leaf_surface_conc, leaf_scalar_exch_coeff, lsec and lsc, ! respectively, ! unnecessary 3d-arrays cdc, lsc and lsec now defined as single-value constants, ! USE-statements and ONLY-lists modified accordingly ! ! 1340 2014-03-25 19:45:13Z kanani ! REAL constants defined as wp-kind ! ! 1320 2014-03-20 08:40:49Z raasch ! ONLY-attribute added to USE-statements, ! kind-parameters added to all INTEGER and REAL declaration statements, ! kinds are defined in new module kinds, ! old module precision_kind is removed, ! revision history before 2012 removed, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 138 2007-11-28 10:03:58Z letzel ! Initial revision ! ! Description: ! ------------ !> 1) Initialization of the canopy model, e.g. construction of leaf area density !> profile (subroutine init_plant_canopy). !> 2) Calculation of sinks and sources of momentum, heat and scalar concentration !> due to canopy elements (subroutine plant_canopy_model). !------------------------------------------------------------------------------! MODULE plant_canopy_model_mod USE arrays_3d, & ONLY: dzu, dzw, e, q, shf, tend, u, v, w, zu, zw USE indices, & ONLY: nbgp, nxl, nxlg, nxlu, nxr, nxrg, nyn, nyng, nys, nysg, nysv, & nz, nzb, nzb_s_inner, nzb_u_inner, nzb_v_inner, nzb_w_inner, nzt USE kinds IMPLICIT NONE CHARACTER (LEN=20) :: canopy_mode = 'block' !< canopy coverage INTEGER(iwp) :: pch_index = 0 !< plant canopy height/top index INTEGER(iwp) :: & lad_vertical_gradient_level_ind(10) = -9999 !< lad-profile levels (index) LOGICAL :: calc_beta_lad_profile = .FALSE. !< switch for calc. of lad from beta func. LOGICAL :: plant_canopy = .FALSE. !< switch for use of canopy model REAL(wp) :: alpha_lad = 9999999.9_wp !< coefficient for lad calculation REAL(wp) :: beta_lad = 9999999.9_wp !< coefficient for lad calculation REAL(wp) :: canopy_drag_coeff = 0.0_wp !< canopy drag coefficient (parameter) REAL(wp) :: cdc = 0.0_wp !< canopy drag coeff. (abbreviation used in equations) REAL(wp) :: cthf = 0.0_wp !< canopy top heat flux REAL(wp) :: dt_plant_canopy = 0.0_wp !< timestep account. for canopy drag REAL(wp) :: lad_surface = 0.0_wp !< lad surface value REAL(wp) :: lai_beta = 0.0_wp !< leaf area index (lai) for lad calc. REAL(wp) :: & leaf_scalar_exch_coeff = 0.0_wp !< canopy scalar exchange coeff. REAL(wp) :: & leaf_surface_conc = 0.0_wp !< leaf surface concentration REAL(wp) :: lsec = 0.0_wp !< leaf scalar exchange coeff. REAL(wp) :: lsc = 0.0_wp !< leaf surface concentration REAL(wp) :: & lad_vertical_gradient(10) = 0.0_wp !< lad gradient REAL(wp) :: & lad_vertical_gradient_level(10) = -9999999.9_wp !< lad-prof. levels (in m) REAL(wp), DIMENSION(:), ALLOCATABLE :: lad !< leaf area density REAL(wp), DIMENSION(:), ALLOCATABLE :: pre_lad !< preliminary lad REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: & canopy_heat_flux !< canopy heat flux REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: cum_lai_hf !< cumulative lai for heatflux calc. REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: lad_s !< lad on scalar-grid SAVE PRIVATE PUBLIC alpha_lad, beta_lad, calc_beta_lad_profile, canopy_drag_coeff, & canopy_mode, cdc, cthf, dt_plant_canopy, init_plant_canopy, lad, & lad_s, lad_surface, lad_vertical_gradient, & lad_vertical_gradient_level, lad_vertical_gradient_level_ind, & lai_beta, leaf_scalar_exch_coeff, leaf_surface_conc, lsc, lsec, & pch_index, plant_canopy, plant_canopy_model INTERFACE init_plant_canopy MODULE PROCEDURE init_plant_canopy END INTERFACE init_plant_canopy INTERFACE plant_canopy_model MODULE PROCEDURE plant_canopy_model MODULE PROCEDURE plant_canopy_model_ij END INTERFACE plant_canopy_model CONTAINS !------------------------------------------------------------------------------! ! Description: ! ------------ !> Initialization of the plant canopy model !------------------------------------------------------------------------------! SUBROUTINE init_plant_canopy USE control_parameters, & ONLY: dz, ocean, passive_scalar IMPLICIT NONE INTEGER(iwp) :: i !< running index INTEGER(iwp) :: j !< running index INTEGER(iwp) :: k !< running index REAL(wp) :: int_bpdf !< vertical integral for lad-profile construction REAL(wp) :: dzh !< vertical grid spacing in units of canopy height REAL(wp) :: gradient !< gradient for lad-profile construction REAL(wp) :: canopy_height !< canopy height for lad-profile construction ! !-- Allocate one-dimensional arrays for the computation of the !-- leaf area density (lad) profile ALLOCATE( lad(0:nz+1), pre_lad(0:nz+1) ) lad = 0.0_wp pre_lad = 0.0_wp ! !-- Compute the profile of leaf area density used in the plant !-- canopy model. The profile can either be constructed from !-- prescribed vertical gradients of the leaf area density or by !-- using a beta probability density function (see e.g. Markkanen et al., !-- 2003: Boundary-Layer Meteorology, 106, 437-459) IF ( .NOT. calc_beta_lad_profile ) THEN ! !-- Use vertical gradients for lad-profile construction i = 1 gradient = 0.0_wp IF ( .NOT. ocean ) THEN lad(0) = lad_surface lad_vertical_gradient_level_ind(1) = 0 DO k = 1, pch_index IF ( i < 11 ) THEN IF ( lad_vertical_gradient_level(i) < zu(k) .AND. & lad_vertical_gradient_level(i) >= 0.0_wp ) THEN gradient = lad_vertical_gradient(i) lad_vertical_gradient_level_ind(i) = k - 1 i = i + 1 ENDIF ENDIF IF ( gradient /= 0.0_wp ) THEN IF ( k /= 1 ) THEN lad(k) = lad(k-1) + dzu(k) * gradient ELSE lad(k) = lad_surface + dzu(k) * gradient ENDIF ELSE lad(k) = lad(k-1) ENDIF ENDDO ENDIF ! !-- In case of no given leaf area density gradients, choose a vanishing !-- gradient. This information is used for the HEADER and the RUN_CONTROL !-- file. IF ( lad_vertical_gradient_level(1) == -9999999.9_wp ) THEN lad_vertical_gradient_level(1) = 0.0_wp ENDIF ELSE ! !-- Use beta function for lad-profile construction int_bpdf = 0.0_wp canopy_height = pch_index * dz DO k = nzb, pch_index int_bpdf = int_bpdf + & ( ( ( zw(k) / canopy_height )**( alpha_lad-1.0_wp ) ) * & ( ( 1.0_wp - ( zw(k) / canopy_height ) )**( beta_lad-1.0_wp ) ) * & ( ( zw(k+1)-zw(k) ) / canopy_height ) ) ENDDO ! !-- Preliminary lad profile (defined on w-grid) DO k = nzb, pch_index pre_lad(k) = lai_beta * & ( ( ( zw(k) / canopy_height )**( alpha_lad-1.0_wp ) ) * & ( ( 1.0_wp - ( zw(k) / canopy_height ) )**( beta_lad-1.0_wp ) ) / & int_bpdf & ) / canopy_height ENDDO ! !-- Final lad profile (defined on scalar-grid level, since most prognostic !-- quantities are defined there, hence, less interpolation is required !-- when calculating the canopy tendencies) lad(0) = pre_lad(0) DO k = nzb+1, pch_index lad(k) = 0.5 * ( pre_lad(k-1) + pre_lad(k) ) ENDDO ENDIF ! !-- Allocate 3D-array for the leaf area density (lad_s). In case of a !-- prescribed canopy-top heat flux (cthf), allocate 3D-arrays for !-- the cumulative leaf area index (cum_lai_hf) and the canopy heat flux. ALLOCATE( lad_s(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) IF ( cthf /= 0.0_wp ) THEN ALLOCATE( cum_lai_hf(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & canopy_heat_flux(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) ENDIF ! !-- Initialize canopy parameters cdc (canopy drag coefficient), !-- lsec (leaf scalar exchange coefficient), lsc (leaf surface concentration) !-- with the prescribed values cdc = canopy_drag_coeff lsec = leaf_scalar_exch_coeff lsc = leaf_surface_conc ! !-- Initialization of the canopy coverage in the model domain: !-- Setting the parameter canopy_mode = 'block' initializes a canopy, which !-- fully covers the domain surface SELECT CASE ( TRIM( canopy_mode ) ) CASE( 'block' ) DO i = nxlg, nxrg DO j = nysg, nyng lad_s(:,j,i) = lad(:) ENDDO ENDDO CASE DEFAULT ! !-- The DEFAULT case is reached either if the parameter !-- canopy mode contains a wrong character string or if the !-- user has coded a special case in the user interface. !-- There, the subroutine user_init_plant_canopy checks !-- which of these two conditions applies. CALL user_init_plant_canopy END SELECT ! !-- Initialization of the canopy heat source distribution IF ( cthf /= 0.0_wp ) THEN ! !-- Piecewise calculation of the leaf area index by vertical !-- integration of the leaf area density cum_lai_hf(:,:,:) = 0.0_wp DO i = nxlg, nxrg DO j = nysg, nyng DO k = pch_index-1, 0, -1 IF ( k == pch_index-1 ) THEN cum_lai_hf(k,j,i) = cum_lai_hf(k+1,j,i) + & ( 0.5_wp * lad_s(k+1,j,i) * & ( zw(k+1) - zu(k+1) ) ) + & ( 0.5_wp * ( 0.5_wp * ( lad_s(k+1,j,i) + & lad_s(k,j,i) ) + & lad_s(k+1,j,i) ) * & ( zu(k+1) - zw(k) ) ) ELSE cum_lai_hf(k,j,i) = cum_lai_hf(k+1,j,i) + & ( 0.5_wp * ( 0.5_wp * ( lad_s(k+2,j,i) + & lad_s(k+1,j,i) ) + & lad_s(k+1,j,i) ) * & ( zw(k+1) - zu(k+1) ) ) + & ( 0.5_wp * ( 0.5_wp * ( lad_s(k+1,j,i) + & lad_s(k,j,i) ) + & lad_s(k+1,j,i) ) * & ( zu(k+1) - zw(k) ) ) ENDIF ENDDO ENDDO ENDDO ! !-- Calculation of the upward kinematic vertical heat flux within the !-- canopy DO i = nxlg, nxrg DO j = nysg, nyng DO k = 0, pch_index canopy_heat_flux(k,j,i) = cthf * & exp( -0.6_wp * cum_lai_hf(k,j,i) ) ENDDO ENDDO ENDDO ! !-- In areas covered with canopy, the surface heat flux is set to !-- the surface value of the above calculated in-canopy heat flux !-- distribution DO i = nxlg,nxrg DO j = nysg, nyng IF ( canopy_heat_flux(0,j,i) /= cthf ) THEN shf(j,i) = canopy_heat_flux(0,j,i) ENDIF ENDDO ENDDO ENDIF END SUBROUTINE init_plant_canopy !------------------------------------------------------------------------------! ! Description: ! ------------ !> Calculation of the tendency terms, accounting for the effect of the plant !> canopy on momentum and scalar quantities. !> !> The canopy is located where the leaf area density lad_s(k,j,i) > 0.0 !> (defined on scalar grid), as initialized in subroutine init_plant_canopy. !> The lad on the w-grid is vertically interpolated from the surrounding !> lad_s. The upper boundary of the canopy is defined on the w-grid at !> k = pch_index. Here, the lad is zero. !> !> The canopy drag must be limited (previously accounted for by calculation of !> a limiting canopy timestep for the determination of the maximum LES timestep !> in subroutine timestep), since it is physically impossible that the canopy !> drag alone can locally change the sign of a velocity component. This !> limitation is realized by calculating preliminary tendencies and velocities. !> It is subsequently checked if the preliminary new velocity has a different !> sign than the current velocity. If so, the tendency is limited in a way that !> the velocity can at maximum be reduced to zero by the canopy drag. !> !> !> Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE plant_canopy_model( component ) USE control_parameters, & ONLY: dt_3d, message_string USE kinds IMPLICIT NONE INTEGER(iwp) :: component !< prognostic variable (u,v,w,pt,q,e) INTEGER(iwp) :: i !< running index INTEGER(iwp) :: j !< running index INTEGER(iwp) :: k !< running index INTEGER(iwp) :: kk !< running index for flat lad arrays REAL(wp) :: ddt_3d !< inverse of the LES timestep (dt_3d) REAL(wp) :: lad_local !< local lad value REAL(wp) :: pre_tend !< preliminary tendency REAL(wp) :: pre_u !< preliminary u-value REAL(wp) :: pre_v !< preliminary v-value REAL(wp) :: pre_w !< preliminary w-value ddt_3d = 1.0_wp / dt_3d ! !-- Compute drag for the three velocity components and the SGS-TKE: SELECT CASE ( component ) ! !-- u-component CASE ( 1 ) DO i = nxlu, nxr DO j = nys, nyn DO k = nzb_u_inner(j,i)+1, nzb_u_inner(j,i)+pch_index kk = k - nzb_u_inner(j,i) !- lad arrays are defined flat ! !-- In order to create sharp boundaries of the plant canopy, !-- the lad on the u-grid at index (k,j,i) is equal to !-- lad_s(k,j,i), rather than being interpolated from the !-- surrounding lad_s, because this would yield smaller lad !-- at the canopy boundaries than inside of the canopy. !-- For the same reason, the lad at the rightmost(i+1)canopy !-- boundary on the u-grid equals lad_s(k,j,i). lad_local = lad_s(kk,j,i) IF ( lad_local == 0.0_wp .AND. lad_s(kk,j,i-1) > 0.0_wp )& THEN lad_local = lad_s(kk,j,i-1) ENDIF pre_tend = 0.0_wp pre_u = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & lad_local * & SQRT( u(k,j,i)**2 + & ( 0.25_wp * ( v(k,j,i-1) + & v(k,j,i) + & v(k,j+1,i) + & v(k,j+1,i-1) ) & )**2 + & ( 0.25_wp * ( w(k-1,j,i-1) + & w(k-1,j,i) + & w(k,j,i-1) + & w(k,j,i) ) & )**2 & ) * & u(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_u = u(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_u,u(k,j,i)) /= pre_u ) THEN pre_tend = - u(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ENDDO ENDDO ! !-- v-component CASE ( 2 ) DO i = nxl, nxr DO j = nysv, nyn DO k = nzb_v_inner(j,i)+1, nzb_v_inner(j,i)+pch_index kk = k - nzb_v_inner(j,i) !- lad arrays are defined flat ! !-- In order to create sharp boundaries of the plant canopy, !-- the lad on the v-grid at index (k,j,i) is equal to !-- lad_s(k,j,i), rather than being interpolated from the !-- surrounding lad_s, because this would yield smaller lad !-- at the canopy boundaries than inside of the canopy. !-- For the same reason, the lad at the northmost(j+1) canopy !-- boundary on the v-grid equals lad_s(k,j,i). lad_local = lad_s(kk,j,i) IF ( lad_local == 0.0_wp .AND. lad_s(kk,j-1,i) > 0.0_wp )& THEN lad_local = lad_s(kk,j-1,i) ENDIF pre_tend = 0.0_wp pre_v = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & lad_local * & SQRT( ( 0.25_wp * ( u(k,j-1,i) + & u(k,j-1,i+1) + & u(k,j,i) + & u(k,j,i+1) ) & )**2 + & v(k,j,i)**2 + & ( 0.25_wp * ( w(k-1,j-1,i) + & w(k-1,j,i) + & w(k,j-1,i) + & w(k,j,i) ) & )**2 & ) * & v(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_v = v(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_v,v(k,j,i)) /= pre_v ) THEN pre_tend = - v(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ENDDO ENDDO ! !-- w-component CASE ( 3 ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb_w_inner(j,i)+1, nzb_w_inner(j,i)+pch_index-1 kk = k - nzb_w_inner(j,i) !- lad arrays are defined flat pre_tend = 0.0_wp pre_w = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & (0.5_wp * & ( lad_s(kk+1,j,i) + lad_s(kk,j,i) )) * & SQRT( ( 0.25_wp * ( u(k,j,i) + & u(k,j,i+1) + & u(k+1,j,i) + & u(k+1,j,i+1) ) & )**2 + & ( 0.25_wp * ( v(k,j,i) + & v(k,j+1,i) + & v(k+1,j,i) + & v(k+1,j+1,i) ) & )**2 + & w(k,j,i)**2 & ) * & w(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_w = w(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_w,w(k,j,i)) /= pre_w ) THEN pre_tend = - w(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ENDDO ENDDO ! !-- potential temperature CASE ( 4 ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) + & ( canopy_heat_flux(kk,j,i) - & canopy_heat_flux(kk-1,j,i) ) / dzw(k) ENDDO ENDDO ENDDO ! !-- scalar concentration CASE ( 5 ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) - & lsec * & lad_s(kk,j,i) * & SQRT( ( 0.5_wp * ( u(k,j,i) + & u(k,j,i+1) ) & )**2 + & ( 0.5_wp * ( v(k,j,i) + & v(k,j+1,i) ) & )**2 + & ( 0.5_wp * ( w(k-1,j,i) + & w(k,j,i) ) & )**2 & ) * & ( q(k,j,i) - lsc ) ENDDO ENDDO ENDDO ! !-- sgs-tke CASE ( 6 ) DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) - & 2.0_wp * cdc * & lad_s(kk,j,i) * & SQRT( ( 0.5_wp * ( u(k,j,i) + & u(k,j,i+1) ) & )**2 + & ( 0.5_wp * ( v(k,j,i) + & v(k,j+1,i) ) & )**2 + & ( 0.5_wp * ( w(k,j,i) + & w(k+1,j,i) ) & )**2 & ) * & e(k,j,i) ENDDO ENDDO ENDDO CASE DEFAULT WRITE( message_string, * ) 'wrong component: ', component CALL message( 'plant_canopy_model', 'PA0279', 1, 2, 0, 6, 0 ) END SELECT END SUBROUTINE plant_canopy_model !------------------------------------------------------------------------------! ! Description: ! ------------ !> Calculation of the tendency terms, accounting for the effect of the plant !> canopy on momentum and scalar quantities. !> !> The canopy is located where the leaf area density lad_s(k,j,i) > 0.0 !> (defined on scalar grid), as initialized in subroutine init_plant_canopy. !> The lad on the w-grid is vertically interpolated from the surrounding !> lad_s. The upper boundary of the canopy is defined on the w-grid at !> k = pch_index. Here, the lad is zero. !> !> The canopy drag must be limited (previously accounted for by calculation of !> a limiting canopy timestep for the determination of the maximum LES timestep !> in subroutine timestep), since it is physically impossible that the canopy !> drag alone can locally change the sign of a velocity component. This !> limitation is realized by calculating preliminary tendencies and velocities. !> It is subsequently checked if the preliminary new velocity has a different !> sign than the current velocity. If so, the tendency is limited in a way that !> the velocity can at maximum be reduced to zero by the canopy drag. !> !> !> Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE plant_canopy_model_ij( i, j, component ) USE control_parameters, & ONLY: dt_3d, message_string USE kinds IMPLICIT NONE INTEGER(iwp) :: component !< prognostic variable (u,v,w,pt,q,e) INTEGER(iwp) :: i !< running index INTEGER(iwp) :: j !< running index INTEGER(iwp) :: k !< running index INTEGER(iwp) :: kk !< running index for flat lad arrays REAL(wp) :: ddt_3d !< inverse of the LES timestep (dt_3d) REAL(wp) :: lad_local !< local lad value REAL(wp) :: pre_tend !< preliminary tendency REAL(wp) :: pre_u !< preliminary u-value REAL(wp) :: pre_v !< preliminary v-value REAL(wp) :: pre_w !< preliminary w-value ddt_3d = 1.0_wp / dt_3d ! !-- Compute drag for the three velocity components and the SGS-TKE SELECT CASE ( component ) ! !-- u-component CASE ( 1 ) DO k = nzb_u_inner(j,i)+1, nzb_u_inner(j,i)+pch_index kk = k - nzb_u_inner(j,i) !- lad arrays are defined flat ! !-- In order to create sharp boundaries of the plant canopy, !-- the lad on the u-grid at index (k,j,i) is equal to lad_s(k,j,i), !-- rather than being interpolated from the surrounding lad_s, !-- because this would yield smaller lad at the canopy boundaries !-- than inside of the canopy. !-- For the same reason, the lad at the rightmost(i+1)canopy !-- boundary on the u-grid equals lad_s(k,j,i). lad_local = lad_s(kk,j,i) IF ( lad_local == 0.0_wp .AND. lad_s(kk,j,i-1) > 0.0_wp ) THEN lad_local = lad_s(kk,j,i-1) ENDIF pre_tend = 0.0_wp pre_u = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & lad_local * & SQRT( u(k,j,i)**2 + & ( 0.25_wp * ( v(k,j,i-1) + & v(k,j,i) + & v(k,j+1,i) + & v(k,j+1,i-1) ) & )**2 + & ( 0.25_wp * ( w(k-1,j,i-1) + & w(k-1,j,i) + & w(k,j,i-1) + & w(k,j,i) ) & )**2 & ) * & u(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_u = u(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_u,u(k,j,i)) /= pre_u ) THEN pre_tend = - u(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ! !-- v-component CASE ( 2 ) DO k = nzb_v_inner(j,i)+1, nzb_v_inner(j,i)+pch_index kk = k - nzb_v_inner(j,i) !- lad arrays are defined flat ! !-- In order to create sharp boundaries of the plant canopy, !-- the lad on the v-grid at index (k,j,i) is equal to lad_s(k,j,i), !-- rather than being interpolated from the surrounding lad_s, !-- because this would yield smaller lad at the canopy boundaries !-- than inside of the canopy. !-- For the same reason, the lad at the northmost(j+1)canopy !-- boundary on the v-grid equals lad_s(k,j,i). lad_local = lad_s(kk,j,i) IF ( lad_local == 0.0_wp .AND. lad_s(kk,j-1,i) > 0.0_wp ) THEN lad_local = lad_s(kk,j-1,i) ENDIF pre_tend = 0.0_wp pre_v = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & lad_local * & SQRT( ( 0.25_wp * ( u(k,j-1,i) + & u(k,j-1,i+1) + & u(k,j,i) + & u(k,j,i+1) ) & )**2 + & v(k,j,i)**2 + & ( 0.25_wp * ( w(k-1,j-1,i) + & w(k-1,j,i) + & w(k,j-1,i) + & w(k,j,i) ) & )**2 & ) * & v(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_v = v(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_v,v(k,j,i)) /= pre_v ) THEN pre_tend = - v(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ! !-- w-component CASE ( 3 ) DO k = nzb_w_inner(j,i)+1, nzb_w_inner(j,i)+pch_index-1 kk = k - nzb_w_inner(j,i) !- lad arrays are defined flat pre_tend = 0.0_wp pre_w = 0.0_wp ! !-- Calculate preliminary value (pre_tend) of the tendency pre_tend = - cdc * & (0.5_wp * & ( lad_s(kk+1,j,i) + lad_s(kk,j,i) )) * & SQRT( ( 0.25_wp * ( u(k,j,i) + & u(k,j,i+1) + & u(k+1,j,i) + & u(k+1,j,i+1) ) & )**2 + & ( 0.25_wp * ( v(k,j,i) + & v(k,j+1,i) + & v(k+1,j,i) + & v(k+1,j+1,i) ) & )**2 + & w(k,j,i)**2 & ) * & w(k,j,i) ! !-- Calculate preliminary new velocity, based on pre_tend pre_w = w(k,j,i) + dt_3d * pre_tend ! !-- Compare sign of old velocity and new preliminary velocity, !-- and in case the signs are different, limit the tendency IF ( SIGN(pre_w,w(k,j,i)) /= pre_w ) THEN pre_tend = - w(k,j,i) * ddt_3d ELSE pre_tend = pre_tend ENDIF ! !-- Calculate final tendency tend(k,j,i) = tend(k,j,i) + pre_tend ENDDO ! !-- potential temperature CASE ( 4 ) DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) + & ( canopy_heat_flux(kk,j,i) - & canopy_heat_flux(kk-1,j,i) ) / dzw(k) ENDDO ! !-- scalar concentration CASE ( 5 ) DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) - & lsec * & lad_s(kk,j,i) * & SQRT( ( 0.5_wp * ( u(k,j,i) + & u(k,j,i+1) ) & )**2 + & ( 0.5_wp * ( v(k,j,i) + & v(k,j+1,i) ) & )**2 + & ( 0.5_wp * ( w(k-1,j,i) + & w(k,j,i) ) & )**2 & ) * & ( q(k,j,i) - lsc ) ENDDO ! !-- sgs-tke CASE ( 6 ) DO k = nzb_s_inner(j,i)+1, nzb_s_inner(j,i)+pch_index kk = k - nzb_s_inner(j,i) !- lad arrays are defined flat tend(k,j,i) = tend(k,j,i) - & 2.0_wp * cdc * & lad_s(kk,j,i) * & SQRT( ( 0.5_wp * ( u(k,j,i) + & u(k,j,i+1) ) & )**2 + & ( 0.5_wp * ( v(k,j,i) + & v(k,j+1,i) ) & )**2 + & ( 0.5_wp * ( w(k,j,i) + & w(k+1,j,i) ) & )**2 & ) * & e(k,j,i) ENDDO CASE DEFAULT WRITE( message_string, * ) 'wrong component: ', component CALL message( 'plant_canopy_model', 'PA0279', 1, 2, 0, 6, 0 ) END SELECT END SUBROUTINE plant_canopy_model_ij END MODULE plant_canopy_model_mod