Changeset 3449 for palm/trunk/SOURCE


Ignore:
Timestamp:
Oct 29, 2018 7:36:56 PM (5 years ago)
Author:
suehring
Message:

Branch resler -r 3439 re-integrated into current trunk: RTM 3.0, transpiration of plant canopy, output fixes in USM

Location:
palm/trunk/SOURCE
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/basic_constants_and_equations_mod.f90

    r3361 r3449  
    2525! -----------------
    2626! $Id$
     27! +degc_to_k
     28!
     29! 3361 2018-10-16 20:39:37Z knoop
    2730! New module (introduced with modularization of bulk cloud physics model)
    2831!
     
    4346    IMPLICIT NONE
    4447
    45     REAL(wp), PARAMETER ::  pi = 3.141592654_wp  !< PI
    46 
    4748    REAL(wp), PARAMETER ::  c_p = 1005.0_wp                           !< heat capacity of dry air (J kg-1 K-1)
     49    REAL(wp), PARAMETER ::  degc_to_k = 273.15_wp                     !< temperature (in K) of 0 deg C (K)
    4850    REAL(wp), PARAMETER ::  g = 9.81_wp                               !< gravitational acceleration (m s-2)
    4951    REAL(wp), PARAMETER ::  kappa = 0.4_wp                            !< von Karman constant
     
    5557    REAL(wp), PARAMETER ::  molecular_weight_of_nh4no3 = 0.08004_wp   !< mol. m. ammonium sulfate (kg mol-1)
    5658    REAL(wp), PARAMETER ::  molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1)
     59    REAL(wp), PARAMETER ::  pi = 3.141592654_wp                       !< PI
    5760    REAL(wp), PARAMETER ::  rho_l = 1.0E3_wp                          !< density of water (kg m-3)
    5861    REAL(wp), PARAMETER ::  rho_nacl = 2165.0_wp                      !< density of NaCl (kg m-3)
     
    6164    REAL(wp), PARAMETER ::  r_d = 287.0_wp                            !< sp. gas const. dry air (J kg-1 K-1)
    6265    REAL(wp), PARAMETER ::  r_v = 461.51_wp                           !< sp. gas const. water vapor (J kg-1 K-1)
    63     REAL(wp), PARAMETER ::  sigma_sb = 5.67E-08_wp                    !< Stefan-Boltzmann constant
     66    REAL(wp), PARAMETER ::  sigma_sb = 5.67037E-08_wp                 !< Stefan-Boltzmann constant
    6467    REAL(wp), PARAMETER ::  solar_constant = 1368.0_wp                !< solar constant at top of atmosphere
    6568    REAL(wp), PARAMETER ::  vanthoff_nacl = 2.0_wp                    !< van't Hoff factor for NaCl
     
    143146!
    144147!--    Saturation vapor pressure for a specific temperature:
    145        magnus_0d =  611.2_wp * EXP( 17.62_wp * ( t - 273.15_wp ) /             &
     148       magnus_0d =  611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) /             &
    146149                                                   ( t - 29.65_wp  ) )
    147150
     
    163166!
    164167!--    Saturation vapor pressure for a specific temperature:
    165        magnus_1d =  611.2_wp * EXP( 17.62_wp * ( t - 273.15_wp ) /             &
     168       magnus_1d =  611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) /             &
    166169                                               ( t - 29.65_wp  ) )
    167170
  • palm/trunk/SOURCE/chemistry_model_mod.f90

    r3435 r3449  
    2727! -----------------
    2828! $Id$
     29! additional output - merged from branch resler
     30!
     31! 3438 2018-10-28 19:31:42Z pavelkrc
    2932! Add terrain-following masked output
    3033!
     
    262265                                 !< neumann = zero gradient
    263266
    264     REAL(kind=wp), PUBLIC :: cs_time_step
     267    REAL(kind=wp), PUBLIC :: cs_time_step = 0._wp
    265268    CHARACTER(10), PUBLIC :: photolysis_scheme
    266269                                         ! 'constant',
     
    410413       IF ( mode == 'allocate' )  THEN
    411414          DO lsp = 1, nspec
    412              IF (TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
     415             IF ( TRIM(variable(1:3)) == 'kc_' .AND. &
     416                  TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
    413417                chem_species(lsp)%conc_av = 0.0_wp
    414                
    415418             ENDIF
    416419          ENDDO
     
    418421       ELSEIF ( mode == 'sum' )  THEN
    419422
    420 
    421423          DO lsp = 1, nspec
    422              IF (TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
     424             IF ( TRIM(variable(1:3)) == 'kc_' .AND. &
     425                  TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
    423426                DO  i = nxlg, nxrg
    424427                   DO  j = nysg, nyng
     
    462465       ELSEIF ( mode == 'average' )  THEN
    463466          DO lsp = 1, nspec
    464              IF (TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
     467             IF ( TRIM(variable(1:3)) == 'kc_' .AND. &
     468                  TRIM(variable(4:)) == TRIM(chem_species(lsp)%name)) THEN
    465469                DO  i = nxlg, nxrg
    466470                   DO  j = nysg, nyng
     
    811815       unit = 'illegal'
    812816
    813        spec_name = TRIM(var(4:))             !< var 1:3 is 'kc_'.
     817       spec_name = TRIM(var(4:))             !< var 1:3 is 'kc_' or 'em_'.
     818
     819       IF ( TRIM(var(1:3)) == 'em_' )  THEN
     820          DO lsp=1,nspec
     821             IF (TRIM(spec_name) == TRIM(chem_species(lsp)%name))   THEN
     822                unit = 'mol m-2 s-1'
     823             ENDIF
     824             !-- It is possible to plant PM10 and PM25 into the gasphase chemistry code
     825             !-- as passive species (e.g. 'passive' in GASPHASE_PREPROC/mechanisms):
     826             !-- set unit to micrograms per m**3 for PM10 and PM25 (PM2.5)
     827             IF (spec_name(1:2) == 'PM')   THEN
     828                unit = 'kg m-2 s-1'
     829             ENDIF
     830          ENDDO
     831
     832       ELSE
    814833
    815834          DO lsp=1,nspec
     
    821840!            set unit to micrograms per m**3 for PM10 and PM25 (PM2.5)
    822841             IF (spec_name(1:2) == 'PM')   THEN 
    823             unit = 'kg m-3'
     842               unit = 'kg m-3'
    824843             ENDIF
    825844          ENDDO
    826845
    827           DO lsp=1,nphot                                                     
     846          DO lsp=1,nphot
    828847             IF (TRIM(spec_name) == TRIM(phot_frequen(lsp)%name))   THEN
    829848                unit = 'sec-1'
    830849             ENDIF
    831850          ENDDO
    832 
    833 
    834        RETURN
     851       ENDIF
     852
     853
     854      RETURN
    835855    END SUBROUTINE chem_check_data_output
    836856!
     
    933953          CALL message( 'chem_check_parameters', 'CM0426', 1, 2, 0, 6, 0 )
    934954       ENDIF
     955
     956!---------------------
     957!--    chem_check_parameters is called before the array chem_species is allocated!
     958!--    temporary switch of this part of the check
     959       RETURN
     960!---------------------
    935961
    936962!--    check for initial chem species input
     
    10761102       USE kinds
    10771103
     1104       USE surface_mod
     1105
     1106       !USE chem_modules, ONLY: nvar
    10781107
    10791108       IMPLICIT NONE
     
    10911120
    10921121       !-- local variables
    1093 
    1094        INTEGER              ::  i, j, k, lsp
    10951122       CHARACTER(len=16)    ::  spec_name
     1123       INTEGER(iwp)         ::  i, j, k
     1124       INTEGER(iwp)         ::  m, l    !< running indices for surfaces
     1125       INTEGER(iwp)         ::  lsp  !< running index for chem spcs
    10961126
    10971127
    10981128       found = .FALSE.
     1129       IF ( .NOT. (variable(1:3) == 'kc_' .OR. variable(1:3) == 'em_' ) ) THEN
     1130          RETURN
     1131       ENDIF
    10991132
    11001133       spec_name = TRIM(variable(4:))
    11011134
    1102        DO lsp=1,nspec
    1103           IF (TRIM(spec_name) == TRIM(chem_species(lsp)%name))   THEN
     1135       IF ( variable(1:3) == 'em_' ) THEN
     1136
     1137         local_pf = 0.0_wp
     1138
     1139         DO lsp = 1, nvar  !!! cssws - nvar species, chem_species - nspec species !!!
     1140            IF ( TRIM(spec_name) == TRIM(chem_species(lsp)%name) )   THEN
     1141               ! no average for now
     1142               DO m = 1, surf_usm_h%ns
     1143                  local_pf(surf_usm_h%i(m),surf_usm_h%j(m),surf_usm_h%k(m)) = &
     1144                     local_pf(surf_usm_h%i(m),surf_usm_h%j(m),surf_usm_h%k(m)) + surf_usm_h%cssws(lsp,m)
     1145               ENDDO
     1146               DO m = 1, surf_lsm_h%ns
     1147                  local_pf(surf_lsm_h%i(m),surf_lsm_h%j(m),surf_lsm_h%k(m)) = &
     1148                     local_pf(surf_lsm_h%i(m),surf_lsm_h%j(m),surf_lsm_h%k(m)) + surf_lsm_h%cssws(lsp,m)
     1149               ENDDO
     1150               DO l = 0, 3
     1151                  DO m = 1, surf_usm_v(l)%ns
     1152                     local_pf(surf_usm_v(l)%i(m),surf_usm_v(l)%j(m),surf_usm_v(l)%k(m)) = &
     1153                        local_pf(surf_usm_v(l)%i(m),surf_usm_v(l)%j(m),surf_usm_v(l)%k(m)) + surf_usm_v(l)%cssws(lsp,m)
     1154                  ENDDO
     1155                  DO m = 1, surf_lsm_v(l)%ns
     1156                     local_pf(surf_lsm_v(l)%i(m),surf_lsm_v(l)%j(m),surf_lsm_v(l)%k(m)) = &
     1157                        local_pf(surf_lsm_v(l)%i(m),surf_lsm_v(l)%j(m),surf_lsm_v(l)%k(m)) + surf_lsm_v(l)%cssws(lsp,m)
     1158                  ENDDO
     1159               ENDDO
     1160               found = .TRUE.
     1161            ENDIF
     1162         ENDDO
     1163       ELSE
     1164         DO lsp=1,nspec
     1165            IF (TRIM(spec_name) == TRIM(chem_species(lsp)%name))   THEN
    11041166!
    11051167!--   todo: remove or replace by "CALL message" mechanism (kanani)
    11061168!              IF(myid == 0 .AND. chem_debug0 )  WRITE(6,*) 'Output of species ' // TRIM(variable)  //  &
    11071169!                                                           TRIM(chem_species(lsp)%name)       
    1108              
    1109              IF (av == 0) THEN
    1110                 DO  i = nxl, nxr
    1111                    DO  j = nys, nyn
    1112                       DO  k = nzb_do, nzt_do
    1113                           local_pf(i,j,k) = MERGE(                             &
    1114                                               chem_species(lsp)%conc(k,j,i),   &
    1115                                               REAL( fill_value, KIND = wp ),   &
    1116                                               BTEST( wall_flags_0(k,j,i), 0 ) )
    1117                       ENDDO
    1118                    ENDDO
    1119                 ENDDO
    1120            
    1121              ELSE
    1122                 DO  i = nxl, nxr
    1123                    DO  j = nys, nyn
    1124                       DO  k = nzb_do, nzt_do
    1125                           local_pf(i,j,k) = MERGE(                             &
    1126                                               chem_species(lsp)%conc_av(k,j,i),&
    1127                                               REAL( fill_value, KIND = wp ),   &
    1128                                               BTEST( wall_flags_0(k,j,i), 0 ) )
    1129                       ENDDO
    1130                    ENDDO
    1131                 ENDDO
    1132              ENDIF
    1133 
    1134              found = .TRUE.
    1135           ENDIF
    1136        ENDDO
     1170               IF (av == 0) THEN
     1171                  DO  i = nxl, nxr
     1172                     DO  j = nys, nyn
     1173                        DO  k = nzb_do, nzt_do
     1174                            local_pf(i,j,k) = MERGE(                             &
     1175                                                chem_species(lsp)%conc(k,j,i),   &
     1176                                                REAL( fill_value, KIND = wp ),   &
     1177                                                BTEST( wall_flags_0(k,j,i), 0 ) )
     1178                        ENDDO
     1179                     ENDDO
     1180                  ENDDO
     1181
     1182               ELSE
     1183                  DO  i = nxl, nxr
     1184                     DO  j = nys, nyn
     1185                        DO  k = nzb_do, nzt_do
     1186                            local_pf(i,j,k) = MERGE(                             &
     1187                                                chem_species(lsp)%conc_av(k,j,i),&
     1188                                                REAL( fill_value, KIND = wp ),   &
     1189                                                BTEST( wall_flags_0(k,j,i), 0 ) )
     1190                        ENDDO
     1191                     ENDDO
     1192                  ENDDO
     1193               ENDIF
     1194               found = .TRUE.
     1195            ENDIF
     1196         ENDDO
     1197       ENDIF
    11371198
    11381199       RETURN
     1200
    11391201    END SUBROUTINE chem_data_output_3d
    11401202!
     
    11771239
    11781240       spec_name = TRIM( variable(4:) )
    1179    !av == 0
     1241       !av == 0
    11801242
    11811243       DO lsp=1,nspec
     
    12921354       found  = .TRUE.
    12931355
    1294        IF (var(1:3) == 'kc_')   THEN                   !< always the same grid for chemistry variables
     1356       IF ( var(1:3) == 'kc_' .OR. var(1:3) == 'em_' )   THEN                   !< always the same grid for chemistry variables
    12951357          grid_x = 'x'
    12961358          grid_y = 'y'
     
    18731935 !--   Enable chemistry model
    18741936       air_chemistry = .TRUE.                   
    1875       GOTO 20
    1876 
    1877  10   BACKSPACE( 11 )
    1878       READ( 11 , '(A)') line
    1879       CALL parin_fail_message( 'chemistry_parameters', line )
    1880 
    1881  20   CONTINUE
     1937       GOTO 20
     1938
     1939 10    BACKSPACE( 11 )
     1940       READ( 11 , '(A)') line
     1941       CALL parin_fail_message( 'chemistry_parameters', line )
     1942
     1943 20    CONTINUE
    18821944
    18831945!
  • palm/trunk/SOURCE/plant_canopy_model_mod.f90

    r3337 r3449  
    1616!
    1717! Copyright 1997-2018 Leibniz Universitaet Hannover
     18! Copyright 2018 Institute of Computer Science of the
     19!                Czech Academy of Sciences, Prague
    1820!------------------------------------------------------------------------------!
    1921!
     
    2527! -----------------
    2628! $Id$
     29! Add calculation of transpiration for resolved plant canopy (trees, shrubs)
     30! (V. Fuka, MFF UK Prague, J.Resler, ICS AS, Prague)
     31!
     32! Fix reading plant canopy over buildings
     33!
     34! 3337 2018-10-12 15:17:09Z kanani
    2735! Fix reading plant canopy over buildings
    2836!
     
    214222 
    215223    USE arrays_3d,                                                             &
    216         ONLY:  dzu, dzw, e, q, s, tend, u, v, w, zu, zw
     224        ONLY:  dzu, dzw, e, exner, hyp, pt, q, s, tend, u, v, w, zu, zw
     225
     226    USE basic_constants_and_equations_mod,                                     &
     227        ONLY:  c_p, degc_to_k, l_v, lv_d_cp, r_d, rd_d_rv
     228
     229    USE control_parameters,                                                   &
     230        ONLY: humidity
    217231
    218232    USE indices,                                                               &
     
    222236    USE kinds
    223237
     238    USE pegrid
     239
    224240    USE surface_mod,                                                           &
    225241        ONLY:  get_topography_top_index_ji
     
    229245
    230246
    231     CHARACTER (LEN=30)   ::  canopy_mode = 'block' !< canopy coverage
    232 
    233     INTEGER(iwp) ::  pch_index = 0                               !< plant canopy height/top index
    234     INTEGER(iwp) ::  lad_vertical_gradient_level_ind(10) = -9999 !< lad-profile levels (index)
    235 
    236     INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  pch_index_ji   !< local plant canopy top
    237 
    238     LOGICAL ::  calc_beta_lad_profile = .FALSE. !< switch for calc. of lad from beta func.
     247    CHARACTER (LEN=30)   ::  canopy_mode = 'block'                 !< canopy coverage
     248    LOGICAL              ::  plant_canopy_transpiration = .FALSE.  !< flag to switch calculation of transpiration and corresponding latent heat
     249                                                                   !< for resolved plant canopy inside radiation model
     250                                                                   !< (calls subroutine pcm_calc_transpiration_rate from module plant_canopy_mod)
     251
     252    INTEGER(iwp) ::  pch_index = 0                                 !< plant canopy height/top index
     253    INTEGER(iwp) ::  lad_vertical_gradient_level_ind(10) = -9999   !< lad-profile levels (index)
     254
     255    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  pch_index_ji     !< local plant canopy top
     256
     257    LOGICAL ::  calc_beta_lad_profile = .FALSE.   !< switch for calc. of lad from beta func.
    239258
    240259    REAL(wp) ::  alpha_lad = 9999999.9_wp         !< coefficient for lad calculation
     
    261280    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pre_lad        !< preliminary lad
    262281   
    263     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  cum_lai_hf       !< cumulative lai for heatflux calc.
    264     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  lad_s            !< lad on scalar-grid
    265     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_heating_rate  !< plant canopy heating rate
     282    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  cum_lai_hf             !< cumulative lai for heatflux calc.
     283    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  lad_s                  !< lad on scalar-grid
     284    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_heating_rate        !< plant canopy heating rate
    266285    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_transpiration_rate  !< plant canopy transpiration rate
     286    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_latent_rate         !< plant canopy latent heating rate
    267287
    268288    SAVE
     
    273293!
    274294!-- Public functions
    275     PUBLIC pcm_check_data_output, pcm_check_parameters, pcm_data_output_3d,    &
    276            pcm_define_netcdf_grid, pcm_header, pcm_init, pcm_parin, pcm_tendency
     295    PUBLIC pcm_calc_transpiration_rate, pcm_check_data_output,                &
     296           pcm_check_parameters, pcm_data_output_3d, pcm_define_netcdf_grid,  &
     297           pcm_header, pcm_init, pcm_parin, pcm_tendency
    277298
    278299!
    279300!-- Public variables and constants
    280     PUBLIC pc_heating_rate, pc_transpiration_rate, canopy_mode, cthf, dt_plant_canopy, lad, lad_s,   &
    281            pch_index
    282            
     301    PUBLIC pc_heating_rate, pc_transpiration_rate, pc_latent_rate,             &
     302            canopy_mode, cthf, dt_plant_canopy, lad, lad_s, pch_index,         &
     303            plant_canopy_transpiration
     304
     305    INTERFACE pcm_calc_transpiration_rate
     306       MODULE PROCEDURE pcm_calc_transpiration_rate
     307    END INTERFACE pcm_calc_transpiration_rate
    283308
    284309    INTERFACE pcm_check_data_output
     
    323348
    324349
     350
     351!------------------------------------------------------------------------------!
     352! Description:
     353! ------------
     354!> Calculation of the plant canopy transpiration rate based on the Jarvis-Stewart
     355!> with parametrizations described in Daudet et al. (1999; Agricult. and Forest
     356!> Meteorol. 97) and Ngao, Adam and Saudreau (2017;  Agricult. and Forest Meteorol
     357!> 237-238). Model functions f1-f4 were adapted from Stewart (1998; Agric.
     358!> and Forest. Meteorol. 43) instead, because they are valid for broader intervals
     359!> of values. Funcion f4 used in form present in van Wijk et al. (1998;
     360!> Tree Physiology 20).
     361!>
     362!> This subroutine is called from subroutine radiation_interaction
     363!> after the calculation of radiation in plant canopy boxes.
     364!> (arrays pcbinsw and pcbinlw).
     365!>
     366!------------------------------------------------------------------------------!
     367 SUBROUTINE pcm_calc_transpiration_rate(i, j, k, kk, pcbsw, pcblw, pcbtr, pcblh)
     368
     369     USE control_parameters,                                                   &
     370        ONLY: dz
     371
     372     USE grid_variables,                                                       &
     373        ONLY:  dx, dy
     374
     375     IMPLICIT NONE
     376!--  input parameters
     377     INTEGER(iwp), INTENT(IN)          :: i, j, k, kk        !< indices of the pc gridbox
     378     REAL(wp), INTENT(IN)              :: pcbsw              !< sw radiation in gridbox (W)
     379     REAL(wp), INTENT(IN)              :: pcblw              !< lw radiation in gridbox (W)
     380     REAL(wp), INTENT(OUT)             :: pcbtr              !< transpiration rate dq/dt (kg/kg/s)
     381     REAL(wp), INTENT(OUT)             :: pcblh              !< latent heat from transpiration dT/dt (K/s)
     382
     383!--  variables and parameters for calculation of transpiration rate
     384     REAL(wp)                          :: sat_press, sat_press_d, temp, v_lad
     385     REAL(wp)                          :: d_fact, g_b, g_s, wind_speed, evapor_rate
     386     REAL(wp)                          :: f1, f2, f3, f4, vpd, rswc, e_eq, e_imp, rad
     387     REAL(wp), PARAMETER               :: gama_psychr = 66   !< psychrometric constant (Pa/K)
     388     REAL(wp), PARAMETER               :: g_s_max = 0.01     !< maximum stomatal conductivity (m/s)
     389     REAL(wp), PARAMETER               :: m_soil = 0.4_wp    !< soil water content (needs to adjust or take from LSM)
     390     REAL(wp), PARAMETER               :: m_wilt = 0.01_wp   !< wilting point soil water content (needs to adjust or take from LSM)
     391     REAL(wp), PARAMETER               :: m_sat = 0.51_wp    !< saturation soil water content (needs to adjust or take from LSM)
     392     REAL(wp), PARAMETER               :: t2_min = 0.0_wp    !< minimal temperature for calculation of f2
     393     REAL(wp), PARAMETER               :: t2_max = 40.0_wp   !< maximal temperature for calculation of f2
     394
     395
     396!--  Temperature (deg C)
     397     temp = pt(k,j,i) * exner(k) - degc_to_k
     398!--  Coefficient for conversion of radiation to grid to radiation to unit leaves surface
     399     v_lad = 1.0_wp / ( MAX(lad_s(kk,j,i), 1.0e-10) * dx * dy * dz(1) )
     400!--  Magnus formula for the saturation pressure (see Ngao, Adam and Saudreau (2017) eq. 1)
     401!--  There are updated formulas available, kept consistent with the rest of the parametrization
     402     sat_press = 610.8_wp * exp(17.27_wp * temp/(temp + 237.3_wp))
     403!--  Saturation pressure derivative (derivative of the above)
     404     sat_press_d = sat_press * 17.27_wp * 237.3_wp / (temp + 237.3_wp)**2
     405!--  Wind speed
     406     wind_speed = SQRT( ((u(k,j,i) + u(k,j,i+1))/2.0_wp )**2 +           &
     407                        ((v(k,j,i) + v(k,j,i+1))/2.0_wp )**2 +           &
     408                        ((w(k,j,i) + w(k,j,i+1))/2.0_wp )**2 )
     409!--  Aerodynamic conductivity (Daudet et al. (1999) eq. 14
     410     g_b = 0.01_wp * wind_speed + 0.0071_wp
     411!--  Radiation flux per leaf surface unit
     412     rad = pcbsw * v_lad
     413!--  First function for calculation of stomatal conductivity (radiation dependency)
     414!--  Stewart (1988; Agric. and Forest. Meteorol. 43) eq. 17
     415     f1 = rad * (1000._wp+42.1_wp) / 1000._wp / (rad+42.1_wp)
     416!--  Second function for calculation of stomatal conductivity (temperature dependency)
     417!--  Stewart (1988; Agric. and Forest. Meteorol. 43) eq. 21
     418     f2 = MAX(t2_min, (temp-t2_min) * (t2_max-temp)**((t2_max-16.9_wp)/(16.9_wp-t2_min)) / &
     419              ((16.9_wp-t2_min) * (t2_max-16.9_wp)**((t2_max-16.9_wp)/(16.9_wp-t2_min))) )
     420!--  Water pressure deficit
     421!--  Ngao, Adam and Saudreau (2017) eq. 6 but with water vapour partial pressure
     422     vpd = max( sat_press - q(k,j,i) * hyp(k) / rd_d_rv, 0._wp )
     423!--  Third function for calculation of stomatal conductivity (water pressure deficit dependency)
     424!--  Ngao, Adam and Saudreau (2017) Table 1, limited from below according to Stewart (1988)
     425!--  The coefficients of the linear dependence should better correspond to broad-leaved trees
     426!--  than the coefficients from Stewart (1988) which correspond to conifer trees.
     427     vpd = MIN(MAX(vpd,770.0_wp),3820.0_wp)
     428     f3 = -2e-4_wp * vpd + 1.154_wp
     429!--  Fourth function for calculation of stomatal conductivity (soil moisture dependency)
     430!--  Residual soil water content
     431!--  van Wijk et al. (1998; Tree Physiology 20) eq. 7
     432!--  TODO - over LSM surface might be calculated from LSM parameters
     433     rswc = ( m_sat - m_soil ) / ( m_sat - m_wilt )
     434!--  van Wijk et al. (1998; Tree Physiology 20) eq. 5-6 (it is a reformulation of eq. 22-23 of Stewart(1988))
     435     f4 = MAX(0._wp, MIN(1.0_wp - 0.041_wp * EXP(3.2_wp * rswc), 1.0_wp - 0.041_wp))
     436!--  Stomatal conductivity
     437!--  Stewart (1988; Agric. and Forest. Meteorol. 43) eq. 12
     438!--  (notation according to Ngao, Adam and Saudreau (2017) and others)
     439     g_s = g_s_max * f1 * f2 * f3 * f4 + 1.0e-10_wp
     440!--  Decoupling factor
     441!--  Daudet et al. (1999) eq. 6
     442     d_fact = (sat_press_d / gama_psychr + 2._wp ) /                        &
     443              (sat_press_d / gama_psychr + 2._wp + 2 * g_b / g_s )
     444!--  Equilibrium evaporation rate
     445!--  Daudet et al. (1999) eq. 4
     446     e_eq = (pcbsw + pcblw) * v_lad * sat_press_d /                         &
     447                 gama_psychr /( sat_press_d / gama_psychr + 2.0_wp ) / l_v
     448!--  Imposed evaporation rate
     449!--  Daudet et al. (1999) eq. 5
     450     e_imp = r_d * pt(k,j,i) * exner(k) / hyp(k) * c_p * g_s * vpd / gama_psychr / l_v
     451!--  Evaporation rate
     452!--  Daudet et al. (1999) eq. 3
     453!--  (evaporation rate is limited to non-negative values)
     454     evapor_rate = MAX(d_fact * e_eq + ( 1.0_wp - d_fact ) * e_imp, 0.0_wp)
     455!--  Conversion of evaporation rate to q tendency in gridbox
     456!--  dq/dt = E * LAD * V_g / (rho_air * V_g)
     457     pcbtr = evapor_rate * r_d * pt(k,j,i) * exner(k) * lad_s(kk,j,i) / hyp(k)  !-- = dq/dt
     458!--  latent heat from evaporation
     459     pcblh = pcbtr * lv_d_cp  !-- = - dT/dt
     460
     461 END SUBROUTINE pcm_calc_transpiration_rate
     462
     463
    325464!------------------------------------------------------------------------------!
    326465! Description:
     
    352491       CASE ( 'pcm_transpirationrate' )
    353492          unit = 'kg kg-1 s-1'
     493
     494       CASE ( 'pcm_latentrate' )
     495          unit = 'K s-1'
     496
     497       CASE ( 'pcm_bowenratio' )
     498          unit = 'K s-1'
    354499
    355500       CASE ( 'pcm_lad' )
     
    503648            ENDDO
    504649         ENDIF
    505    
     650
     651       CASE ( 'pcm_latentrate' )
     652         IF ( av == 0 )  THEN
     653            DO  i = nxl, nxr
     654               DO  j = nys, nyn
     655                  IF ( pch_index_ji(j,i) /= 0 )  THEN
     656                     k_topo = get_topography_top_index_ji( j, i, 's' )
     657                     DO  k = k_topo, k_topo + pch_index_ji(j,i)
     658                        local_pf(i,j,k) = pc_latent_rate(k-k_topo,j,i)
     659                     ENDDO
     660                  ENDIF
     661               ENDDO
     662            ENDDO
     663         ENDIF
     664
     665       CASE ( 'pcm_bowenratio' )
     666         IF ( av == 0 )  THEN
     667            DO  i = nxl, nxr
     668               DO  j = nys, nyn
     669                  IF ( pch_index_ji(j,i) /= 0 )  THEN
     670                     k_topo = get_topography_top_index_ji( j, i, 's' )
     671                     DO  k = k_topo, k_topo + pch_index_ji(j,i)
     672                        IF ( pc_latent_rate(k-k_topo,j,i) /= 0._wp ) THEN
     673                           local_pf(i,j,k) = pc_heating_rate(k-k_topo,j,i) / &
     674                                             pc_latent_rate(k-k_topo,j,i)
     675                        ENDIF
     676                     ENDDO
     677                  ENDIF
     678               ENDDO
     679            ENDDO
     680         ENDIF
     681
    506682      CASE ( 'pcm_lad' )
    507683         IF ( av == 0 )  THEN
     
    550726     SELECT CASE ( TRIM( var ) )
    551727
    552         CASE ( 'pcm_heatrate', 'pcm_lad', 'pcm_transpirationrate')
     728        CASE ( 'pcm_heatrate', 'pcm_lad', 'pcm_transpirationrate', 'pcm_latentrate', 'pcm_bowenratio')
    553729           grid_x = 'x'
    554730           grid_y = 'y'
     
    691867
    692868       USE control_parameters,                                                 &
    693            ONLY: humidity, message_string, ocean_mode, urban_surface
     869           ONLY: message_string, ocean_mode, urban_surface
    694870
    695871       USE netcdf_data_input_mod,                                              &
     
    705881       INTEGER(iwp) ::  k   !< running index
    706882       INTEGER(iwp) ::  m   !< running index
     883       INTEGER(iwp) ::  pch_index_l
    707884
    708885       REAL(wp) ::  int_bpdf        !< vertical integral for lad-profile construction
     
    9031080       CALL exchange_horiz_2d_int( pch_index_ji, nys, nyn, nxl, nxr, nbgp )
    9041081
     1082!--    Calculate global pch_index value (index of top of plant canopy from ground)
     1083       pch_index = MAXVAL(pch_index_ji)
     1084!--    Exchange pch_index from all processors
     1085#if defined( __parallel )
     1086       CALL MPI_Allreduce(MPI_IN_PLACE, pch_index, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr)
     1087       IF ( ierr /= 0 )  THEN
     1088          WRITE (9,*) 'Error MPI_Allreduce pch_index:', ierr
     1089          FLUSH(9)
     1090       ENDIF
     1091#endif
     1092
     1093!--    Allocation of arrays pc_heating_rate, pc_transpiration_rate and pc_latent_rate
     1094       ALLOCATE( pc_heating_rate(0:pch_index,nysg:nyng,nxlg:nxrg) )
     1095       IF ( humidity )  THEN
     1096          ALLOCATE( pc_transpiration_rate(0:pch_index,nysg:nyng,nxlg:nxrg) )
     1097          pc_transpiration_rate = 0.0_wp
     1098          ALLOCATE( pc_latent_rate(0:pch_index,nysg:nyng,nxlg:nxrg) )
     1099          pc_latent_rate = 0.0_wp
     1100       ENDIF
     1101
    9051102!
    9061103!--    Initialization of the canopy heat source distribution due to heating
     
    9151112!--    73–96). This approach has been applied e.g. by Shaw & Schumann (1992;
    9161113!--    Bound.-Layer Meteorol. 61, 47–64).
    917 !--    When using the urban surface model (USM), canopy heating (pc_heating_rate)
    918 !--    by radiation is calculated in the USM.
    919        IF ( cthf /= 0.0_wp  .AND. .NOT.  urban_surface )  THEN
    920 
    921           ALLOCATE( cum_lai_hf(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                 &
    922                     pc_heating_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
     1114!--    When using the radiation_interactions, canopy heating (pc_heating_rate)
     1115!--    and plant canopy transpiration (pc_transpiration_rate, pc_latent_rate)
     1116!--    are calculated in the RTM after the calculation of radiation.
     1117!--    We cannot use variable radiation_interactions here to determine the situation
     1118!--    as it is assigned in init_3d_model after the call of pcm_init.
     1119       IF ( cthf /= 0.0_wp )  THEN
     1120
     1121          ALLOCATE( cum_lai_hf(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
    9231122!
    9241123!--       Piecewise calculation of the cumulative leaf area index by vertical
     
    9961195
    9971196       ENDIF
    998 !
    999 !--    Allocate transpiration rate
    1000        IF ( humidity )                                                         &
    1001           ALLOCATE( pc_transpiration_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
    1002 
    10031197
    10041198
     
    10281222                                  lai_beta,                                    &
    10291223                                  leaf_scalar_exch_coeff,                      &
    1030                                   leaf_surface_conc, pch_index
     1224                                  leaf_surface_conc, pch_index,                &
     1225                                  plant_canopy_transpiration
    10311226
    10321227       NAMELIST /canopy_par/      alpha_lad, beta_lad, canopy_drag_coeff,      &
     
    10371232                                  lai_beta,                                    &
    10381233                                  leaf_scalar_exch_coeff,                      &
    1039                                   leaf_surface_conc, pch_index
     1234                                  leaf_surface_conc, pch_index,                &
     1235                                  plant_canopy_transpiration
    10401236
    10411237       line = ' '
     
    14341630!--       potential temperature
    14351631          CASE ( 4 )
    1436              DO  i = nxl, nxr
    1437                 DO  j = nys, nyn
    1438 !
    1439 !--                Determine topography-top index on scalar-grid
    1440                    k_wall = get_topography_top_index_ji( j, i, 's' )
    1441 
    1442                    DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
    1443 
    1444                       kk = k - k_wall   !- lad arrays are defined flat
    1445                       tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
     1632             IF ( humidity ) THEN
     1633                DO  i = nxl, nxr
     1634                   DO  j = nys, nyn
     1635!--                   Determine topography-top index on scalar-grid
     1636                      k_wall = get_topography_top_index_ji( j, i, 's' )
     1637                      DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
     1638                         kk = k - k_wall   !- lad arrays are defined flat
     1639                         tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i) - pc_latent_rate(kk,j,i)
     1640                      ENDDO
    14461641                   ENDDO
    14471642                ENDDO
    1448              ENDDO
     1643             ELSE
     1644                DO  i = nxl, nxr
     1645                   DO  j = nys, nyn
     1646!--                   Determine topography-top index on scalar-grid
     1647                      k_wall = get_topography_top_index_ji( j, i, 's' )
     1648                      DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
     1649                         kk = k - k_wall   !- lad arrays are defined flat
     1650                         tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
     1651                      ENDDO
     1652                   ENDDO
     1653                ENDDO
     1654             ENDIF
    14491655
    14501656!
     
    14601666
    14611667                      kk = k - k_wall   !- lad arrays are defined flat
    1462                       pc_transpiration_rate(kk,j,i) =  - lsec                  &
    1463                                        * lad_s(kk,j,i) *                       &
    1464                                        SQRT( ( 0.5_wp * ( u(k,j,i) +           &
    1465                                                           u(k,j,i+1) )         &
    1466                                              )**2 +                            &
    1467                                              ( 0.5_wp * ( v(k,j,i) +           &
    1468                                                           v(k,j+1,i) )         &
    1469                                              )**2 +                            &
    1470                                              ( 0.5_wp * ( w(k-1,j,i) +         &
    1471                                                           w(k,j,i) )           &
    1472                                              )**2                              &
    1473                                            ) *                                 &
    1474                                        ( q(k,j,i) - lsc )
     1668
     1669                      IF ( .NOT. plant_canopy_transpiration ) THEN
     1670                         ! pc_transpiration_rate is calculated in radiation model
     1671                         ! in case of plant_canopy_transpiration = .T.
     1672                         ! to include also the dependecy to the radiation
     1673                         ! in the plant canopy box
     1674                         pc_transpiration_rate(kk,j,i) =  - lsec                  &
     1675                                          * lad_s(kk,j,i) *                       &
     1676                                          SQRT( ( 0.5_wp * ( u(k,j,i) +           &
     1677                                                             u(k,j,i+1) )         &
     1678                                                )**2 +                            &
     1679                                                ( 0.5_wp * ( v(k,j,i) +           &
     1680                                                             v(k,j+1,i) )         &
     1681                                                )**2 +                            &
     1682                                                ( 0.5_wp * ( w(k-1,j,i) +         &
     1683                                                             w(k,j,i) )           &
     1684                                                )**2                              &
     1685                                              ) *                                 &
     1686                                          ( q(k,j,i) - lsc )
     1687                      ENDIF
    14751688
    14761689                      tend(k,j,i) = tend(k,j,i) + pc_transpiration_rate(kk,j,i)
     
    17781991             k_wall = get_topography_top_index_ji( j, i, 's' )
    17791992
     1993             IF ( humidity ) THEN
     1994                DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
     1995                   kk = k - k_wall  !- lad arrays are defined flat
     1996                   tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i) - pc_latent_rate(kk,j,i)
     1997                ENDDO
     1998             ELSE
     1999                DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
     2000                   kk = k - k_wall  !- lad arrays are defined flat
     2001                   tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
     2002                ENDDO
     2003             ENDIF
     2004
     2005!
     2006!--       humidity
     2007          CASE ( 5 )
     2008!
     2009!--          Determine topography-top index on scalar grid
     2010             k_wall = get_topography_top_index_ji( j, i, 's' )
     2011
    17802012             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
    17812013                kk = k - k_wall  !- lad arrays are defined flat
    1782                 tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
    1783              ENDDO
    1784 
    1785 
    1786 !
    1787 !--       humidity
    1788           CASE ( 5 )
    1789 !
    1790 !--          Determine topography-top index on scalar grid
    1791              k_wall = get_topography_top_index_ji( j, i, 's' )
    1792 
    1793              DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
    1794                 kk = k - k_wall  !- lad arrays are defined flat
    1795 
    1796                 pc_transpiration_rate(kk,j,i) = - lsec                         &
    1797                                  * lad_s(kk,j,i) *                             &
    1798                                  SQRT( ( 0.5_wp * ( u(k,j,i) +                 &
    1799                                                     u(k,j,i+1) )               &
    1800                                        )**2  +                                 &
    1801                                        ( 0.5_wp * ( v(k,j,i) +                 &
    1802                                                     v(k,j+1,i) )               &
    1803                                        )**2 +                                  &
    1804                                        ( 0.5_wp * ( w(k-1,j,i) +               &
    1805                                                     w(k,j,i) )                 &
    1806                                        )**2                                    &
    1807                                      ) *                                       &
    1808                                  ( q(k,j,i) - lsc )
     2014                IF ( .NOT. plant_canopy_transpiration ) THEN
     2015                   ! pc_transpiration_rate is calculated in radiation model
     2016                   ! in case of plant_canopy_transpiration = .T.
     2017                   ! to include also the dependecy to the radiation
     2018                   ! in the plant canopy box
     2019                   pc_transpiration_rate(kk,j,i) = - lsec                         &
     2020                                    * lad_s(kk,j,i) *                             &
     2021                                    SQRT( ( 0.5_wp * ( u(k,j,i) +                 &
     2022                                                       u(k,j,i+1) )               &
     2023                                          )**2  +                                 &
     2024                                          ( 0.5_wp * ( v(k,j,i) +                 &
     2025                                                       v(k,j+1,i) )               &
     2026                                          )**2 +                                  &
     2027                                          ( 0.5_wp * ( w(k-1,j,i) +               &
     2028                                                       w(k,j,i) )                 &
     2029                                          )**2                                    &
     2030                                        ) *                                       &
     2031                                    ( q(k,j,i) - lsc )
     2032                ENDIF
    18092033
    18102034                tend(k,j,i) = tend(k,j,i) + pc_transpiration_rate(kk,j,i)
  • palm/trunk/SOURCE/radiation_model_mod.f90

    r3435 r3449  
    2828! -----------------
    2929! $Id$
     30! New RTM version 3.0: (Pavel Krc, Jaroslav Resler, ICS, Prague)
     31!   - Interaction of plant canopy with LW radiation
     32!   - Transpiration from resolved plant canopy dependent on radiation
     33!     called from RTM
     34!
     35!
     36! 3435 2018-10-26 18:25:44Z gronemeier
    3037! - workaround: return unit=illegal in check_data_output for certain variables
    3138!   when check called from init_masks
     
    499506
    500507    USE basic_constants_and_equations_mod,                                     &
    501         ONLY:  c_p, g, lv_d_cp, l_v, pi, r_d, rho_l, solar_constant,           &
     508        ONLY:  c_p, g, lv_d_cp, l_v, pi, r_d, rho_l, solar_constant,      &
    502509               barometric_formula
    503510
     
    544551
    545552    USE plant_canopy_model_mod,                                                &
    546         ONLY:  lad_s, pc_heating_rate, pc_transpiration_rate
     553        ONLY:  lad_s, pc_heating_rate, pc_transpiration_rate, pc_latent_rate,  &
     554               plant_canopy_transpiration, pcm_calc_transpiration_rate
    547555
    548556    USE pegrid
     
    853861    INTEGER(iwp), DIMENSION(0:nsurf_type), PARAMETER ::  jdir = (/0, 0,1,-1,0, 0,0,1,-1,0, 0/)   !< surface normal direction y indices
    854862    INTEGER(iwp), DIMENSION(0:nsurf_type), PARAMETER ::  kdir = (/1,-1,0, 0,0, 0,1,0, 0,0, 0/)   !< surface normal direction z indices
    855                                                                                           !< parameter but set in the code
     863    REAL(wp),     DIMENSION(0:nsurf_type)          :: facearea                            !< area of single face in respective
     864                                                                                          !< direction (will be calc'd)
    856865
    857866
     
    887896!-- configuration parameters (they can be setup in PALM config)
    888897    LOGICAL                                        ::  raytrace_mpi_rma = .TRUE.          !< use MPI RMA to access LAD and gridsurf from remote processes during raytracing
    889     LOGICAL                                        ::  read_svf_on_init = .FALSE.         !< flag parameter indicating wheather SVFs will be read from a file at initialization
    890     LOGICAL                                        ::  write_svf_on_init = .FALSE.        !< flag parameter indicating wheather SVFs will be written out to a file
    891     LOGICAL                                        ::  rad_angular_discretization = .TRUE.!< whether to use fixed resolution discretization of view factors for
     898    LOGICAL                                        ::  rad_angular_discretization = .TRUE.!< whether to use fixed resolution discretization of view factors for
    892899                                                                                          !< reflected radiation (as opposed to all mutually visible pairs)
     900    LOGICAL                                        ::  plant_lw_interact = .TRUE.         !< whether plant canopy interacts with LW radiation (in addition to SW)
    893901    INTEGER(iwp)                                   ::  mrt_nlevels = 0                    !< number of vertical boxes above surface for which to calculate MRT
    894902    LOGICAL                                        ::  mrt_skip_roof = .TRUE.             !< do not calculate MRT above roof surfaces
    895903    LOGICAL                                        ::  mrt_include_sw = .TRUE.            !< should MRT calculation include SW radiation as well?
    896     INTEGER(iwp)                                   ::  nrefsteps = 0                      !< number of reflection steps to perform
     904    INTEGER(iwp)                                   ::  nrefsteps = 3                      !< number of reflection steps to perform
    897905    REAL(wp), PARAMETER                            ::  ext_coef = 0.6_wp                  !< extinction coefficient (a.k.a. alpha)
    898906    INTEGER(iwp), PARAMETER                        ::  rad_version_len = 10               !< length of identification string of rad version
    899     CHARACTER(rad_version_len), PARAMETER          ::  rad_version = 'RAD v. 1.1'         !< identification of version of binary svf and restart files
     907    CHARACTER(rad_version_len), PARAMETER          ::  rad_version = 'RAD v. 3.0'         !< identification of version of binary svf and restart files
    900908    INTEGER(iwp)                                   ::  raytrace_discrete_elevs = 40       !< number of discretization steps for elevation (nadir to zenith)
    901909    INTEGER(iwp)                                   ::  raytrace_discrete_azims = 80       !< number of discretization steps for azimuth (out of 360 degrees)
     
    929937        INTEGER(iwp)                               :: ity               !<
    930938        INTEGER(iwp)                               :: itz               !<
    931         INTEGER(iwp)                               :: isurfs            !<
    932         REAL(wp)                                   :: rsvf              !<
     939        INTEGER(iwp)                               :: isurfs            !< Idx of source face / -1 for sky
     940        REAL(wp)                                   :: rcvf              !< Canopy view factor for faces /
     941                                                                        !< canopy sink factor for sky (-1)
    933942    END TYPE
    934943
     
    976985    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfouts         !< array of reflected sw radiation for all surfaces in i-th reflection
    977986    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutl         !< array of reflected + emitted lw radiation for all surfaces in i-th reflection
     987    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfinlg         !< global array of incoming lw radiation from plant canopy
    978988    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutsw        !< array of total sw radiation outgoing from nonvirtual surfaces surfaces after all reflection
    979989    REAL(wp), DIMENSION(:), ALLOCATABLE            ::  surfoutlw        !< array of total lw radiation outgoing from nonvirtual surfaces surfaces after all reflection
     
    29282938       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
    29292939       
    2930        NAMELIST /radiation_par/   albedo, albedo_type, albedo_lw_dir,          &
    2931                                   albedo_lw_dif, albedo_sw_dir, albedo_sw_dif, &
    2932                                   constant_albedo, dt_radiation, emissivity,   &
    2933                                   lw_radiation, mrt_nlevels, mrt_skip_roof,    &
    2934                                   mrt_include_sw,  net_radiation,              &
    2935                                   radiation_scheme, skip_time_do_radiation,    &
    2936                                   sw_radiation, unscheduled_radiation_calls,   &
    2937                                   max_raytracing_dist, min_irrf_value,         &
    2938                                   nrefsteps, raytrace_mpi_rma,                 &
    2939                                   surface_reflections, svfnorm_report_thresh,  &
    2940                                   radiation_interactions_on,                   &
    2941                                   rad_angular_discretization,                  &
    2942                                   raytrace_discrete_azims,                     &
    2943                                   raytrace_discrete_elevs
     2940       NAMELIST /radiation_par/   albedo, albedo_lw_dif, albedo_lw_dir,         &
     2941                                  albedo_sw_dif, albedo_sw_dir, albedo_type,    &
     2942                                  constant_albedo, dt_radiation, emissivity,    &
     2943                                  lw_radiation, max_raytracing_dist,            &
     2944                                  min_irrf_value, mrt_include_sw, mrt_nlevels,  &
     2945                                  mrt_skip_roof, net_radiation, nrefsteps,      &
     2946                                  plant_lw_interact, rad_angular_discretization,&
     2947                                  radiation_interactions_on, radiation_scheme,  &
     2948                                  raytrace_discrete_azims,                      &
     2949                                  raytrace_discrete_elevs, raytrace_mpi_rma,    &
     2950                                  skip_time_do_radiation, surface_reflections,  &
     2951                                  svfnorm_report_thresh, sw_radiation,          &
     2952                                  unscheduled_radiation_calls
     2953
    29442954   
    2945        NAMELIST /radiation_parameters/   albedo, albedo_type, albedo_lw_dir,   &
    2946                                   albedo_lw_dif, albedo_sw_dir, albedo_sw_dif, &
    2947                                   constant_albedo, dt_radiation, emissivity,   &
    2948                                   lw_radiation, mrt_nlevels, mrt_skip_roof,    &
    2949                                   mrt_include_sw,  net_radiation,              &
    2950                                   radiation_scheme, skip_time_do_radiation,    &
    2951                                   sw_radiation, unscheduled_radiation_calls,   &
    2952                                   max_raytracing_dist, min_irrf_value,         &
    2953                                   nrefsteps, raytrace_mpi_rma,                 &
    2954                                   surface_reflections, svfnorm_report_thresh,  &
    2955                                   radiation_interactions_on,                   &
    2956                                   rad_angular_discretization,                  &
    2957                                   raytrace_discrete_azims,                     &
    2958                                   raytrace_discrete_elevs
     2955       NAMELIST /radiation_parameters/ albedo, albedo_lw_dif, albedo_lw_dir,    &
     2956                                  albedo_sw_dif, albedo_sw_dir, albedo_type,    &
     2957                                  constant_albedo, dt_radiation, emissivity,    &
     2958                                  lw_radiation, max_raytracing_dist,            &
     2959                                  min_irrf_value, mrt_include_sw, mrt_nlevels,  &
     2960                                  mrt_skip_roof, net_radiation, nrefsteps,      &
     2961                                  plant_lw_interact, rad_angular_discretization,&
     2962                                  radiation_interactions_on, radiation_scheme,  &
     2963                                  raytrace_discrete_azims,                      &
     2964                                  raytrace_discrete_elevs, raytrace_mpi_rma,    &
     2965                                  skip_time_do_radiation, surface_reflections,  &
     2966                                  svfnorm_report_thresh, sw_radiation,          &
     2967                                  unscheduled_radiation_calls
    29592968   
    29602969       line = ' '
     
    46484657     REAL(wp), DIMENSION(0:nsurf_type) :: costheta           !< direct irradiance factor of solar angle
    46494658     REAL(wp), DIMENSION(nzub:nzut)    :: pchf_prep          !< precalculated factor for canopy temperature tendency
    4650      REAL(wp), DIMENSION(nzub:nzut)    :: pctf_prep          !< precalculated factor for canopy transpiration tendency
    46514659     REAL(wp), PARAMETER               :: alpha = 0._wp      !< grid rotation (TODO: add to namelist or remove)
    46524660     REAL(wp)                          :: pc_box_area, pc_abs_frac, pc_abs_eff
    4653      REAL(wp), DIMENSION(0:nsurf_type) :: facearea
     4661     REAL(wp)                          :: asrc               !< area of source face
     4662     REAL(wp)                          :: pcrad              !< irradiance from plant canopy
    46544663     REAL(wp)                          :: pabsswl  = 0.0_wp  !< total absorbed SW radiation energy in local processor (W)
    46554664     REAL(wp)                          :: pabssw   = 0.0_wp  !< total absorbed SW radiation energy in all processors (W)
     
    46724681         pchf_prep(:) = r_d * exner(nzub:nzut)                                 &
    46734682                     / (c_p * hyp(nzub:nzut) * dx*dy*dz(1)) !< equals to 1 / (rho * c_p * Vbox * T)
    4674          pctf_prep(:) = r_d * exner(nzub:nzut)                                 &
    4675                      / (l_v * hyp(nzub:nzut) * dx*dy*dz(1))
    46764683     ENDIF
    46774684#endif
     
    47294736        mrtinlw(:) = 0._wp
    47304737     ENDIF
     4738     surfinlg(:)  = 0._wp !global
    47314739
    47324740
     
    48244832!
    48254833!--        For surface-to-surface factors we calculate thermal radiation in 1st pass
    4826            surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * surfoutl(isurfsrc)
     4834           IF ( plant_lw_interact )  THEN
     4835              surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * svf(2,isvf) * surfoutl(isurfsrc)
     4836           ELSE
     4837              surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * surfoutl(isurfsrc)
     4838           ENDIF
    48274839        ENDDO
    48284840     ENDIF
     
    48334845        i = surfl(ix, isurf)
    48344846        surfinswdif(isurf) = rad_sw_in_diff(j,i) * skyvft(isurf)
    4835         surfinlwdif(isurf) = rad_lw_in_diff(j,i) * skyvf(isurf)
     4847        IF ( plant_lw_interact )  THEN
     4848           surfinlwdif(isurf) = rad_lw_in_diff(j,i) * skyvft(isurf)
     4849        ELSE
     4850           surfinlwdif(isurf) = rad_lw_in_diff(j,i) * skyvf(isurf)
     4851        ENDIF
    48364852     ENDDO
    48374853!
     
    48804896         pcbinswdir(:) = 0._wp
    48814897         pcbinswdif(:) = 0._wp
    4882          pcbinlw(:) = 0._wp  !< will stay always 0 since we don't absorb lw anymore
    4883 !
    4884 !--         pcsf first pass
     4898         pcbinlw(:) = 0._wp
     4899!
     4900!--      pcsf first pass
    48854901         DO icsf = 1, ncsfl
    48864902             ipcgb = csfsurf(1, icsf)
     
    48914907
    48924908             IF ( isurfsrc == -1 )  THEN
    4893 !--                 Diffuse rad from sky.
    4894                  pcbinswdif(ipcgb) = csf(1,icsf) * rad_sw_in_diff(j,i)
    4895 
    4896                  !--Direct rad
    4897                  IF ( zenith(0) > 0 )  THEN
    4898                     !--Estimate directed box absorption
    4899                     pc_abs_frac = 1._wp - exp(pc_abs_eff * lad_s(k,j,i))
    4900 
    4901                     !--isd has already been established, see 1)
    4902                     pcbinswdir(ipcgb) = rad_sw_in_dir(j, i) * pc_box_area &
    4903                                         * pc_abs_frac * dsitransc(ipcgb, isd)
    4904                  ENDIF
     4909!
     4910!--             Diffuse rad from sky.
     4911                pcbinswdif(ipcgb) = csf(1,icsf) * rad_sw_in_diff(j,i)
     4912!
     4913!--             Absorbed diffuse LW from sky minus emitted to sky
     4914                IF ( plant_lw_interact )  THEN
     4915                   pcbinlw(ipcgb) = csf(1,icsf)                                  &
     4916                                       * (rad_lw_in_diff(j, i)                   &
     4917                                          - sigma_sb * (pt(k,j,i)*exner(k))**4)
     4918                ENDIF
     4919!
     4920!--             Direct rad
     4921                IF ( zenith(0) > 0 )  THEN
     4922!--                Estimate directed box absorption
     4923                   pc_abs_frac = 1._wp - exp(pc_abs_eff * lad_s(k,j,i))
     4924!
     4925!--                isd has already been established, see 1)
     4926                   pcbinswdir(ipcgb) = rad_sw_in_dir(j, i) * pc_box_area &
     4927                                       * pc_abs_frac * dsitransc(ipcgb, isd)
     4928                ENDIF
     4929             ELSE
     4930                IF ( plant_lw_interact )  THEN
     4931!
     4932!--                Thermal emission from plan canopy towards respective face
     4933                   pcrad = sigma_sb * (pt(k,j,i) * exner(k))**4 * csf(1,icsf)
     4934                   surfinlg(isurfsrc) = surfinlg(isurfsrc) + pcrad
     4935!
     4936!--                Remove the flux above + absorb LW from first pass from surfaces
     4937                   asrc = facearea(surf(id, isurfsrc))
     4938                   pcbinlw(ipcgb) = pcbinlw(ipcgb)                      &
     4939                                    + (csf(1,icsf) * surfoutl(isurfsrc) & ! Absorb from first pass surf emit
     4940                                       - pcrad)                         & ! Remove emitted heatflux
     4941                                    * asrc
     4942                ENDIF
    49054943             ENDIF
    49064944         ENDDO
     
    49084946         pcbinsw(:) = pcbinswdir(:) + pcbinswdif(:)
    49094947     ENDIF
     4948
     4949     IF ( plant_lw_interact )  THEN
     4950!
     4951!--     Exchange incoming lw radiation from plant canopy
     4952#if defined( __parallel )
     4953        CALL MPI_Allreduce(MPI_IN_PLACE, surfinlg, nsurf, MPI_REAL, MPI_SUM, comm2d, ierr)
     4954        IF ( ierr /= 0 )  THEN
     4955           WRITE (9,*) 'Error MPI_Allreduce:', ierr
     4956           FLUSH(9)
     4957        ENDIF
     4958        surfinl(:) = surfinl(:) + surfinlg(surfstart(myid)+1:surfstart(myid+1))
     4959#else
     4960        surfinl(:) = surfinl(:) + surfinlg(:)
     4961#endif
     4962     ENDIF
     4963
    49104964     surfins = surfinswdir + surfinswdif
    49114965     surfinl = surfinl + surfinlwdif
     
    49665020             isurfsrc = svfsurf(2, isvf)
    49675021             surfins(isurf) = surfins(isurf) + svf(1,isvf) * svf(2,isvf) * surfouts(isurfsrc)
    4968              surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * surfoutl(isurfsrc)
     5022             IF ( plant_lw_interact )  THEN
     5023                surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * svf(2,isvf) * surfoutl(isurfsrc)
     5024             ELSE
     5025                surfinl(isurf) = surfinl(isurf) + svf(1,isvf) * surfoutl(isurfsrc)
     5026             ENDIF
    49695027         ENDDO
    4970 
    4971 !--         radiation absorbed by plant canopy
    4972          DO icsf = 1, ncsfl
     5028!
     5029!--      NOTE: PC absorbtion and MRT from reflected can both be done at once
     5030!--      after all reflections if we do one more MPI_ALLGATHERV on surfout.
     5031!--      Advantage: less local computation. Disadvantage: one more collective
     5032!--      MPI call.
     5033!
     5034!--      Radiation absorbed by plant canopy
     5035         DO  icsf = 1, ncsfl
    49735036             ipcgb = csfsurf(1, icsf)
    49745037             isurfsrc = csfsurf(2, icsf)
    49755038             IF ( isurfsrc == -1 )  CYCLE ! sky->face only in 1st pass, not here
    4976 
    4977              pcbinsw(ipcgb) = pcbinsw(ipcgb) + csf(1,icsf) * surfouts(isurfsrc)
     5039!
     5040!--          Calculate source surface area. If the `surf' array is removed
     5041!--          before timestepping starts (future version), then asrc must be
     5042!--          stored within `csf'
     5043             asrc = facearea(surf(id, isurfsrc))
     5044             pcbinsw(ipcgb) = pcbinsw(ipcgb) + csf(1,icsf) * surfouts(isurfsrc) * asrc
     5045             IF ( plant_lw_interact )  THEN
     5046                pcbinlw(ipcgb) = pcbinlw(ipcgb) + csf(1,icsf) * surfoutl(isurfsrc) * asrc
     5047             ENDIF
    49785048         ENDDO
    49795049!
     
    49965066     IF ( npcbl > 0 )  THEN
    49975067         pc_heating_rate(:,:,:) = 0.0_wp
    4998          pc_transpiration_rate(:,:,:) = 0.0_wp
    49995068         DO ipcgb = 1, npcbl
    5000                  
    50015069             j = pcbl(iy, ipcgb)
    50025070             i = pcbl(ix, ipcgb)
    50035071             k = pcbl(iz, ipcgb)
    50045072!
    5005 !--             Following expression equals former kk = k - nzb_s_inner(j,i)
     5073!--          Following expression equals former kk = k - nzb_s_inner(j,i)
    50065074             kk = k - get_topography_top_index_ji( j, i, 's' )  !- lad arrays are defined flat
    50075075             pc_heating_rate(kk, j, i) = (pcbinsw(ipcgb) + pcbinlw(ipcgb)) &
    50085076                 * pchf_prep(k) * pt(k, j, i) !-- = dT/dt
    5009 
    5010 !             pc_transpiration_rate(kk,j,i) = 0.75_wp* (pcbinsw(ipcgb) + pcbinlw(ipcgb)) &
    5011 !                 * pctf_prep(k) * pt(k, j, i) !-- = dq/dt
    5012 
    50135077         ENDDO
     5078
     5079         IF ( humidity .AND. plant_canopy_transpiration ) THEN
     5080!--          Calculation of plant canopy transpiration rate and correspondidng latent heat rate
     5081             pc_transpiration_rate(:,:,:) = 0.0_wp
     5082             pc_latent_rate(:,:,:) = 0.0_wp
     5083             DO ipcgb = 1, npcbl
     5084                 i = pcbl(ix, ipcgb)
     5085                 j = pcbl(iy, ipcgb)
     5086                 k = pcbl(iz, ipcgb)
     5087                 kk = k - get_topography_top_index_ji( j, i, 's' )  !- lad arrays are defined flat
     5088                 CALL pcm_calc_transpiration_rate( i, j, k, kk, pcbinsw(ipcgb), pcbinlw(ipcgb), &
     5089                                                   pc_transpiration_rate(kk,j,i), pc_latent_rate(kk,j,i) )
     5090              ENDDO
     5091         ENDIF
    50145092     ENDIF
    50155093!
     
    51615239!--  domain when using average_radiation in the respective radiation model
    51625240
    5163 !--  Precalculate face areas for all face directions using normal vector
    5164      DO d = 0, nsurf_type
    5165         facearea(d) = 1._wp
    5166         IF ( idir(d) == 0 ) facearea(d) = facearea(d) * dx
    5167         IF ( jdir(d) == 0 ) facearea(d) = facearea(d) * dy
    5168         IF ( kdir(d) == 0 ) facearea(d) = facearea(d) * dz(1)
    5169      ENDDO
    51705241!--  calculate horizontal area
    51715242! !!! ATTENTION!!! uniform grid is assumed here
     
    54295500       IMPLICIT NONE
    54305501
    5431        INTEGER(iwp) :: i, j, k, l, m
     5502       INTEGER(iwp) :: i, j, k, l, m, d
    54325503       INTEGER(iwp) :: k_topo     !< vertical index indicating topography top for given (j,i)
    54335504       INTEGER(iwp) :: nzptl, nzubl, nzutl, isurf, ipcgb, imrt
     
    54395510#endif
    54405511
     5512!
     5513!--     precalculate face areas for different face directions using normal vector
     5514        DO d = 0, nsurf_type
     5515            facearea(d) = 1._wp
     5516            IF ( idir(d) == 0 ) facearea(d) = facearea(d) * dx
     5517            IF ( jdir(d) == 0 ) facearea(d) = facearea(d) * dy
     5518            IF ( kdir(d) == 0 ) facearea(d) = facearea(d) * dz(1)
     5519        ENDDO
    54415520!
    54425521!--    Find nzub, nzut, nzu via wall_flag_0 array (nzb_s_inner will be
     
    59045983       ALLOCATE( surfouts(nsurf) )
    59055984       ALLOCATE( surfoutl(nsurf) )
     5985       ALLOCATE( surfinlg(nsurf) )
    59065986       ALLOCATE( skyvf(nsurfl) )
    59075987       ALLOCATE( skyvft(nsurfl) )
     
    59406020        REAL(wp)                                      :: az1, az2      !< relative azimuth of section borders
    59416021        REAL(wp)                                      :: azmid         !< ray (center) azimuth
     6022        REAL(wp)                                      :: yxlen         !< |yxdir|
    59426023        REAL(wp), DIMENSION(2)                        :: yxdir         !< y,x *unit* vector of ray direction (in grid units)
    59436024        REAL(wp), DIMENSION(:), ALLOCATABLE           :: zdirs         !< directions in z (tangent of elevation)
     6025        REAL(wp), DIMENSION(:), ALLOCATABLE           :: zcent         !< zenith angle centers
    59446026        REAL(wp), DIMENSION(:), ALLOCATABLE           :: zbdry         !< zenith angle boundaries
    59456027        REAL(wp), DIMENSION(:), ALLOCATABLE           :: vffrac        !< view factor fractions for individual rays
     
    59496031        INTEGER(iwp), DIMENSION(:), ALLOCATABLE       :: itarget       !< face indices of detected obstacles
    59506032        INTEGER(iwp)                                  :: itarg0, itarg1
    5951 #if defined( __parallel )
    5952 #endif
    5953 
    5954 
    5955 
    5956         REAL(wp),     DIMENSION(0:nsurf_type)         :: facearea
     6033
    59576034        INTEGER(iwp)                                  :: udim
    59586035        INTEGER(iwp), DIMENSION(:), ALLOCATABLE,TARGET:: nzterrl_l
     
    59666043        LOGICAL                                       :: visible
    59676044        REAL(wp), DIMENSION(3)                        :: sa, ta          !< real coordinates z,y,x of source and target
     6045        REAL(wp)                                      :: difvf           !< differential view factor
    59686046        REAL(wp)                                      :: transparency, rirrf, sqdist, svfsum
    59696047        INTEGER(iwp)                                  :: isurflt, isurfs, isurflt_prev
     
    59836061        CALL location_message( '    calculation of SVF and CSF', .TRUE. )
    59846062        CALL radiation_write_debug_log('Start calculation of SVF and CSF')
    5985 
    5986 !--     precalculate face areas for different face directions using normal vector
    5987         DO d = 0, nsurf_type
    5988             facearea(d) = 1._wp
    5989             IF ( idir(d) == 0 ) facearea(d) = facearea(d) * dx
    5990             IF ( jdir(d) == 0 ) facearea(d) = facearea(d) * dy
    5991             IF ( kdir(d) == 0 ) facearea(d) = facearea(d) * dz(1)
    5992         ENDDO
    59936063
    59946064!--     initialize variables and temporary arrays for calculation of svf and csf
     
    62196289            END SELECT
    62206290
    6221             ALLOCATE ( zdirs(1:nzn), zbdry(0:nzn), vffrac(1:nzn*naz), &
     6291            ALLOCATE ( zdirs(1:nzn), zcent(1:nzn), zbdry(0:nzn), vffrac(1:nzn*naz), &
    62226292                       ztransp(1:nzn*naz), itarget(1:nzn*naz) )   !FIXME allocate itarget only
    62236293                                                                  !in case of rad_angular_discretization
     
    62256295            itarg0 = 1
    62266296            itarg1 = nzn
    6227             zdirs(:) = (/( TAN(pi/2 - (zn0+(REAL(izn,wp)-.5_wp)*zns)), izn=1, nzn )/)
     6297            zcent(:) = (/( zn0+(REAL(izn,wp)-.5_wp)*zns, izn=1, nzn )/)
    62286298            zbdry(:) = (/( zn0+REAL(izn,wp)*zns, izn=0, nzn )/)
    62296299            IF ( td == iup_u  .OR.  td == iup_l )  THEN
     
    62516321!--               sum of whole vffrac equals 1, verified
    62526322               ENDIF
    6253                yxdir = (/ COS(azmid), SIN(azmid) /)
     6323               yxdir(:) = (/ COS(azmid) / dy, SIN(azmid) / dx /)
     6324               yxlen = SQRT(SUM(yxdir(:)**2))
     6325               zdirs(:) = COS(zcent(:)) / (dz(1) * yxlen * SIN(zcent(:)))
     6326               yxdir(:) = yxdir(:) / yxlen
     6327
    62546328               CALL raytrace_2d(ta, yxdir, nzn, zdirs,                        &
    62556329                                    surfstart(myid) + isurflt, facearea(td),  &
     
    62576331                                    .FALSE., lowest_free_ray,                 &
    62586332                                    ztransp(itarg0:itarg1),                   &
    6259                                     itarget(itarg0:itarg1))   !FIXME unit vect in grid units + zdirs
    6260                                                               !FIXME itarget available only in
    6261                                                               !case of rad_angular_discretization
     6333                                    itarget(itarg0:itarg1))
     6334
    62626335               skyvf(isurflt) = skyvf(isurflt) + &
    62636336                                SUM(vffrac(itarg0:itarg0+lowest_free_ray-1))
     
    63376410            ENDIF ! rad_angular_discretization
    63386411
    6339             DEALLOCATE ( zdirs, zbdry, vffrac, ztransp, itarget ) !FIXME itarget shall be allocated only
     6412            DEALLOCATE ( zdirs, zcent, zbdry, vffrac, ztransp, itarget ) !FIXME itarget shall be allocated only
    63406413                                                                  !in case of rad_angular_discretization
    63416414!
     
    63676440                  ENDIF
    63686441                 
     6442                  difvf = dot_product((/ kdir(sd), jdir(sd), idir(sd) /), uv) & ! cosine of source normal and direction
     6443                      * dot_product((/ kdir(td), jdir(td), idir(td) /), -uv) &  ! cosine of target normal and reverse direction
     6444                      / (pi * sqdist) ! square of distance between centers
     6445!
    63696446!--               irradiance factor (our unshaded shape view factor) = view factor per differential target area * source area
    6370                   rirrf = dot_product((/ kdir(sd), jdir(sd), idir(sd) /), uv) & ! cosine of source normal and direction
    6371                       * dot_product((/ kdir(td), jdir(td), idir(td) /), -uv) &  ! cosine of target normal and reverse direction
    6372                       / (pi * sqdist) & ! square of distance between centers
    6373                       * facearea(sd)
     6447                  rirrf = difvf * facearea(sd)
    63746448
    63756449!--               reject raytracing for potentially too small view factor values
     
    63806454
    63816455!--               raytrace + process plant canopy sinks within
    6382                   CALL raytrace(sa, ta, isurfs, rirrf, facearea(td), .TRUE., &
     6456                  CALL raytrace(sa, ta, isurfs, difvf, facearea(td), .TRUE., &
    63836457                                visible, transparency)
    63846458
     
    64286502        nzn = raytrace_discrete_elevs / 2
    64296503        zns = pi / 2._wp / REAL(nzn, wp)
    6430         ALLOCATE ( zdirs(1:nzn), vffrac(1:nzn), ztransp(1:nzn), &
     6504        ALLOCATE ( zdirs(1:nzn), zcent(1:nzn), vffrac(1:nzn), ztransp(1:nzn), &
    64316505               itarget(1:nzn) )
    6432         zdirs(:) = (/( TAN(pi/2 - (zn0+(REAL(izn,wp)-.5_wp)*zns)), izn=1, nzn )/)
     6506        zcent(:) = (/( zn0+(REAL(izn,wp)-.5_wp)*zns, izn=1, nzn )/)
    64336507        vffrac(:) = 0._wp
    64346508
     
    64406514           DO  iaz = 1, naz
    64416515              azmid = az0 + (REAL(iaz, wp) - .5_wp) * azs
    6442               yxdir = (/ COS(azmid), SIN(azmid) /)
     6516              yxdir(:) = (/ COS(azmid) / dy, SIN(azmid) / dx /)
     6517              yxlen = SQRT(SUM(yxdir(:)**2))
     6518              zdirs(:) = COS(zcent(:)) / (dz(1) * yxlen * SIN(zcent(:)))
     6519              yxdir(:) = yxdir(:) / yxlen
    64436520              CALL raytrace_2d(ta, yxdir, nzn, zdirs,                                &
    64446521                                   -999, -999._wp, vffrac, .FALSE., .FALSE., .TRUE., &
    6445                                    lowest_free_ray, ztransp, itarget) !FIXME unit vect in grid units + zdirs
     6522                                   lowest_free_ray, ztransp, itarget)
    64466523
    64476524!--           Save direct solar transparency
     
    64566533           ENDDO
    64576534        ENDDO
    6458         DEALLOCATE ( zdirs, vffrac, ztransp, itarget )
     6535        DEALLOCATE ( zdirs, zcent, vffrac, ztransp, itarget )
    64596536!--
    64606537!--     Raytrace to MRT boxes
     
    64696546           nzn = raytrace_discrete_elevs
    64706547           zns = pi / REAL(nzn, wp)
    6471            ALLOCATE ( zdirs(1:nzn), zbdry(0:nzn), vffrac(1:nzn*naz), vffrac0(1:nzn), &
     6548           ALLOCATE ( zdirs(1:nzn), zcent(1:nzn), zbdry(0:nzn), vffrac(1:nzn*naz), vffrac0(1:nzn), &
    64726549                      ztransp(1:nzn*naz), itarget(1:nzn*naz) )   !FIXME allocate itarget only
    64736550                                                                 !in case of rad_angular_discretization
    64746551
    6475            zdirs(:) = (/( TAN(pi/2 - (zn0+(REAL(izn,wp)-.5_wp)*zns)), izn=1, nzn )/)
     6552           zcent(:) = (/( zn0+(REAL(izn,wp)-.5_wp)*zns, izn=1, nzn )/)
    64766553           zbdry(:) = (/( zn0+REAL(izn,wp)*zns, izn=0, nzn )/)
    64776554           vffrac0(:) = (COS(zbdry(0:nzn-1)) - COS(zbdry(1:nzn))) / 2._wp / REAL(naz, wp)
     
    64936570              DO  iaz = 1, naz
    64946571                 azmid = az0 + (REAL(iaz, wp) - .5_wp) * azs
    6495                  CALL raytrace_2d(ta, (/ COS(azmid), SIN(azmid) /), nzn, zdirs,  &
     6572                 yxdir(:) = (/ COS(azmid) / dy, SIN(azmid) / dx /)
     6573                 yxlen = SQRT(SUM(yxdir(:)**2))
     6574                 zdirs(:) = COS(zcent(:)) / (dz(1) * yxlen * SIN(zcent(:)))
     6575                 yxdir(:) = yxdir(:) / yxlen
     6576
     6577                 CALL raytrace_2d(ta, yxdir, nzn, zdirs,                         &
    64966578                                  -999, -999._wp, vffrac(itarg0:itarg1), .TRUE., &
    64976579                                  .FALSE., .TRUE., lowest_free_ray,              &
    64986580                                  ztransp(itarg0:itarg1),                        &
    6499                                   itarget(itarg0:itarg1))   !FIXME unit vect in grid units + zdirs
    6500                                                             !FIXME itarget available only in
    6501                                                             !case of rad_angular_discretization
     6581                                  itarget(itarg0:itarg1))
    65026582
    65036583!--              Sky view factors for MRT
     
    65746654
    65756655           ENDDO ! imrt
    6576            DEALLOCATE ( zdirs, zbdry, vffrac, vffrac0, ztransp, itarget )
     6656           DEALLOCATE ( zdirs, zcent, zbdry, vffrac, vffrac0, ztransp, itarget )
    65776657!
    65786658!--        Move MRT factors to final arrays
     
    67786858                    j = 0
    67796859                ENDIF
    6780 !--             fill out real values of rsvf, rtransp
    6781                 csflt(1,kcsf) = acsf(kcsf)%rsvf
     6860                csflt(1,kcsf) = acsf(kcsf)%rcvf
    67826861!--             fill out integer values of itz,ity,itx,isurfs
    67836862                kcsflt(1,kcsf) = acsf(kcsf)%itz
     
    69467025!>    doesn't need to be the same in all three dimensions).
    69477026!------------------------------------------------------------------------------!
    6948     SUBROUTINE raytrace(src, targ, isrc, rirrf, atarg, create_csf, visible, transparency)
     7027    SUBROUTINE raytrace(src, targ, isrc, difvf, atarg, create_csf, visible, transparency)
    69497028        IMPLICIT NONE
    69507029
    69517030        REAL(wp), DIMENSION(3), INTENT(in)     :: src, targ    !< real coordinates z,y,x
    69527031        INTEGER(iwp), INTENT(in)               :: isrc         !< index of source face for csf
    6953         REAL(wp), INTENT(in)                   :: rirrf        !< irradiance factor for csf
     7032        REAL(wp), INTENT(in)                   :: difvf        !< differential view factor for csf
    69547033        REAL(wp), INTENT(in)                   :: atarg        !< target surface area for csf
    69557034        LOGICAL, INTENT(in)                    :: create_csf   !< whether to generate new CSFs during raytracing
     
    71137192                    acsf(ncsfl)%itz = boxes(1,i)
    71147193                    acsf(ncsfl)%isurfs = isrc
    7115                     acsf(ncsfl)%rsvf = cursink*transparency*rirrf*atarg
     7194                    acsf(ncsfl)%rcvf = cursink*transparency*difvf*atarg
    71167195                ENDIF  !< create_csf
    71177196
     
    75147593                           acsf(ncsfl)%itz = iz
    75157594                           acsf(ncsfl)%isurfs = iorig
    7516                            acsf(ncsfl)%rsvf = (1._wp - curtrans)*transparency(k)*aorig*vffrac(k)
     7595                           acsf(ncsfl)%rcvf = (1._wp - curtrans)*transparency(k)*vffrac(k)
    75177596                        ENDIF
    75187597
     
    75717650                        acsf(ncsfl)%ity = rt2_track(1,i)
    75727651                        acsf(ncsfl)%itz = iz
    7573                         acsf(ncsfl)%isurfs = itarget(k) !if above horizon, then itarget(k)==-1, which
    7574                                                         !is also a special ID indicating sky
    7575                         acsf(ncsfl)%rsvf = (1._wp - curtrans)*transparency(k)*aorig*vffrac(k)
     7652                        IF ( itarget(k) /= -1 )  ERROR STOP !FIXME remove after test
     7653                        acsf(ncsfl)%isurfs = -1
     7654                        acsf(ncsfl)%rcvf = (1._wp - curtrans)*transparency(k)*aorig*vffrac(k)
    75767655                     ENDIF  ! create_csf
    75777656
     
    76007679         INTEGER(iwp), TARGET, INTENT(out)   ::  isurfl
    76017680         INTEGER(iwp), INTENT(out)           ::  iproc
     7681#if defined( __parallel )
     7682#else
     7683         INTEGER(iwp)                        ::  target_displ  !< index of the grid in the local gridsurf array
     7684#endif
    76027685         INTEGER(iwp)                        ::  px, py        !< number of processors in x and y direction
    76037686                                                               !< before the processor in the question
     
    81388221                         .AND.  acsfnew(iwrite)%isurfs == acsf(iread)%isurfs )  THEN
    81398222
    8140                     acsfnew(iwrite)%rsvf = acsfnew(iwrite)%rsvf + acsf(iread)%rsvf
     8223                    acsfnew(iwrite)%rcvf = acsfnew(iwrite)%rcvf + acsf(iread)%rcvf
    81418224!--                 advance reading index, keep writing index
    81428225                ELSE
  • palm/trunk/SOURCE/urban_surface_mod.f90

    r3435 r3449  
    2828! -----------------
    2929! $Id$
     30! Bugfix: Fix average arrays allocations in usm_average_3d_data (J.Resler)
     31! Bugfix: Fix reading wall temperatures (J.Resler)
     32! Bugfix: Fix treating of outputs for wall temperature and sky view factors (J.Resler)
     33!
     34!
     35! 3435 2018-10-26 18:25:44Z gronemeier
    3036! Bugfix: allocate gamma_w_green_sat until nzt_wall+1
    3137!
     
    411417   
    412418    USE plant_canopy_model_mod,                                                &
    413         ONLY:  pc_heating_rate, pc_transpiration_rate
     419        ONLY:  pc_heating_rate, pc_transpiration_rate, pc_latent_rate
    414420   
    415421    USE radiation_model_mod,                                                   &
     
    18451851                CASE ( 'usm_rad_net' )
    18461852!--                 array of complete radiation balance
    1847                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%rad_net_av) )  THEN
    1848                         ALLOCATE( surf_usm_h%rad_net_av(1:surf_usm_h%ns) )
    1849                         surf_usm_h%rad_net_av = 0.0_wp
     1853                    IF ( l == -1 ) THEN
     1854                        IF ( .NOT.  ALLOCATED(surf_usm_h%rad_net_av) )  THEN
     1855                            ALLOCATE( surf_usm_h%rad_net_av(1:surf_usm_h%ns) )
     1856                            surf_usm_h%rad_net_av = 0.0_wp
     1857                        ENDIF
    18501858                    ELSE
    18511859                        IF ( .NOT.  ALLOCATED(surf_usm_v(l)%rad_net_av) )  THEN
     
    19681976                CASE ( 'usm_rad_hf' )
    19691977!--                 array of heat flux from radiation for surfaces after i-th reflection
    1970                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%surfhf_av) )  THEN
    1971                         ALLOCATE( surf_usm_h%surfhf_av(1:surf_usm_h%ns) )
    1972                         surf_usm_h%surfhf_av = 0.0_wp
     1978                    IF ( l == -1 ) THEN
     1979                        IF ( .NOT.  ALLOCATED(surf_usm_h%surfhf_av) )  THEN
     1980                           ALLOCATE( surf_usm_h%surfhf_av(1:surf_usm_h%ns) )
     1981                           surf_usm_h%surfhf_av = 0.0_wp
     1982                        ENDIF
    19731983                    ELSE
    19741984                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%surfhf_av) )  THEN
     
    19811991!--                 array of sensible heat flux from surfaces
    19821992!--                 land surfaces
    1983                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wshf_eb_av) )  THEN
    1984                         ALLOCATE( surf_usm_h%wshf_eb_av(1:surf_usm_h%ns) )
    1985                         surf_usm_h%wshf_eb_av = 0.0_wp
     1993                    IF ( l == -1 ) THEN
     1994                       IF ( .NOT.  ALLOCATED(surf_usm_h%wshf_eb_av) )  THEN
     1995                          ALLOCATE( surf_usm_h%wshf_eb_av(1:surf_usm_h%ns) )
     1996                          surf_usm_h%wshf_eb_av = 0.0_wp
     1997                       ENDIF
    19861998                    ELSE
    19871999                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wshf_eb_av) )  THEN
     
    20362048                CASE ( 'usm_wghf' )
    20372049!--                 array of heat flux from ground (wall, roof, land)
    2038                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_av) )  THEN
    2039                         ALLOCATE( surf_usm_h%wghf_eb_av(1:surf_usm_h%ns) )
    2040                         surf_usm_h%wghf_eb_av = 0.0_wp
     2050                    IF ( l == -1 ) THEN
     2051                       IF ( .NOT.  ALLOCATED(surf_usm_h%wghf_eb_av) )  THEN
     2052                           ALLOCATE( surf_usm_h%wghf_eb_av(1:surf_usm_h%ns) )
     2053                           surf_usm_h%wghf_eb_av = 0.0_wp
     2054                       ENDIF
    20412055                    ELSE
    20422056                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_av) )  THEN
     
    20482062                CASE ( 'usm_wghf_window' )
    20492063!--                 array of heat flux from window ground (wall, roof, land)
    2050                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_window_av) )  THEN
    2051                         ALLOCATE( surf_usm_h%wghf_eb_window_av(1:surf_usm_h%ns) )
    2052                         surf_usm_h%wghf_eb_window_av = 0.0_wp
     2064                    IF ( l == -1 ) THEN
     2065                       IF ( .NOT.  ALLOCATED(surf_usm_h%wghf_eb_window_av) )  THEN
     2066                           ALLOCATE( surf_usm_h%wghf_eb_window_av(1:surf_usm_h%ns) )
     2067                           surf_usm_h%wghf_eb_window_av = 0.0_wp
     2068                       ENDIF
    20532069                    ELSE
    20542070                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_window_av) )  THEN
     
    20602076                CASE ( 'usm_wghf_green' )
    20612077!--                 array of heat flux from green ground (wall, roof, land)
    2062                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%wghf_eb_green_av) )  THEN
    2063                         ALLOCATE( surf_usm_h%wghf_eb_green_av(1:surf_usm_h%ns) )
    2064                         surf_usm_h%wghf_eb_green_av = 0.0_wp
     2078                    IF ( l == -1 ) THEN
     2079                       IF ( .NOT.  ALLOCATED(surf_usm_h%wghf_eb_green_av) )  THEN
     2080                           ALLOCATE( surf_usm_h%wghf_eb_green_av(1:surf_usm_h%ns) )
     2081                           surf_usm_h%wghf_eb_green_av = 0.0_wp
     2082                       ENDIF
    20652083                    ELSE
    20662084                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%wghf_eb_green_av) )  THEN
     
    20722090                CASE ( 'usm_iwghf' )
    20732091!--                 array of heat flux from indoor ground (wall, roof, land)
    2074                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_av) )  THEN
    2075                         ALLOCATE( surf_usm_h%iwghf_eb_av(1:surf_usm_h%ns) )
    2076                         surf_usm_h%iwghf_eb_av = 0.0_wp
     2092                    IF ( l == -1 ) THEN
     2093                       IF ( .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_av) )  THEN
     2094                           ALLOCATE( surf_usm_h%iwghf_eb_av(1:surf_usm_h%ns) )
     2095                           surf_usm_h%iwghf_eb_av = 0.0_wp
     2096                       ENDIF
    20772097                    ELSE
    20782098                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%iwghf_eb_av) )  THEN
     
    20842104                CASE ( 'usm_iwghf_window' )
    20852105!--                 array of heat flux from indoor window ground (wall, roof, land)
    2086                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_window_av) )  THEN
    2087                         ALLOCATE( surf_usm_h%iwghf_eb_window_av(1:surf_usm_h%ns) )
    2088                         surf_usm_h%iwghf_eb_window_av = 0.0_wp
     2106                    IF ( l == -1 ) THEN
     2107                       IF ( .NOT.  ALLOCATED(surf_usm_h%iwghf_eb_window_av) )  THEN
     2108                           ALLOCATE( surf_usm_h%iwghf_eb_window_av(1:surf_usm_h%ns) )
     2109                           surf_usm_h%iwghf_eb_window_av = 0.0_wp
     2110                       ENDIF
    20892111                    ELSE
    20902112                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%iwghf_eb_window_av) )  THEN
     
    20932115                       ENDIF
    20942116                    ENDIF
    2095                    
     2117
    20962118                CASE ( 'usm_t_surf_wall' )
    20972119!--                 surface temperature for surfaces
    2098                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_wall_av) )  THEN
    2099                         ALLOCATE( surf_usm_h%t_surf_wall_av(1:surf_usm_h%ns) )
    2100                         surf_usm_h%t_surf_wall_av = 0.0_wp
     2120                    IF ( l == -1 ) THEN
     2121                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_surf_wall_av) )  THEN
     2122                           ALLOCATE( surf_usm_h%t_surf_wall_av(1:surf_usm_h%ns) )
     2123                           surf_usm_h%t_surf_wall_av = 0.0_wp
     2124                       ENDIF
    21012125                    ELSE
    21022126                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_wall_av) )  THEN
     
    21082132                CASE ( 'usm_t_surf_window' )
    21092133!--                 surface temperature for window surfaces
    2110                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_window_av) )  THEN
    2111                         ALLOCATE( surf_usm_h%t_surf_window_av(1:surf_usm_h%ns) )
    2112                         surf_usm_h%t_surf_window_av = 0.0_wp
     2134                    IF ( l == -1 ) THEN
     2135                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_surf_window_av) )  THEN
     2136                           ALLOCATE( surf_usm_h%t_surf_window_av(1:surf_usm_h%ns) )
     2137                           surf_usm_h%t_surf_window_av = 0.0_wp
     2138                       ENDIF
    21132139                    ELSE
    21142140                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_window_av) )  THEN
     
    21202146                CASE ( 'usm_t_surf_green' )
    21212147!--                 surface temperature for green surfaces
    2122                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_green_av) )  THEN
    2123                         ALLOCATE( surf_usm_h%t_surf_green_av(1:surf_usm_h%ns) )
    2124                         surf_usm_h%t_surf_green_av = 0.0_wp
     2148                    IF ( l == -1 ) THEN
     2149                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_surf_green_av) )  THEN
     2150                           ALLOCATE( surf_usm_h%t_surf_green_av(1:surf_usm_h%ns) )
     2151                           surf_usm_h%t_surf_green_av = 0.0_wp
     2152                       ENDIF
    21252153                    ELSE
    21262154                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_green_av) )  THEN
     
    21322160                CASE ( 'usm_t_surf_10cm' )
    21332161!--                 near surface temperature for whole surfaces
    2134                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_surf_10cm_av) )  THEN
    2135                         ALLOCATE( surf_usm_h%t_surf_10cm_av(1:surf_usm_h%ns) )
    2136                         surf_usm_h%t_surf_10cm_av = 0.0_wp
     2162                    IF ( l == -1 ) THEN
     2163                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_surf_10cm_av) )  THEN
     2164                           ALLOCATE( surf_usm_h%t_surf_10cm_av(1:surf_usm_h%ns) )
     2165                           surf_usm_h%t_surf_10cm_av = 0.0_wp
     2166                       ENDIF
    21372167                    ELSE
    21382168                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_surf_10cm_av) )  THEN
     
    21442174                CASE ( 'usm_t_wall' )
    21452175!--                 wall temperature for iwl layer of walls and land
    2146                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_wall_av) )  THEN
    2147                         ALLOCATE( surf_usm_h%t_wall_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
    2148                         surf_usm_h%t_wall_av = 0.0_wp
     2176                    IF ( l == -1 ) THEN
     2177                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_wall_av) )  THEN
     2178                           ALLOCATE( surf_usm_h%t_wall_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
     2179                           surf_usm_h%t_wall_av = 0.0_wp
     2180                       ENDIF
    21492181                    ELSE
    21502182                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_wall_av) )  THEN
     
    21562188                CASE ( 'usm_t_window' )
    21572189!--                 window temperature for iwl layer of walls and land
    2158                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_window_av) )  THEN
    2159                         ALLOCATE( surf_usm_h%t_window_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
    2160                         surf_usm_h%t_window_av = 0.0_wp
     2190                    IF ( l == -1 ) THEN
     2191                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_window_av) )  THEN
     2192                           ALLOCATE( surf_usm_h%t_window_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
     2193                           surf_usm_h%t_window_av = 0.0_wp
     2194                       ENDIF
    21612195                    ELSE
    21622196                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_window_av) )  THEN
     
    21682202                CASE ( 'usm_t_green' )
    21692203!--                 green temperature for iwl layer of walls and land
    2170                     IF ( l == -1 .AND. .NOT.  ALLOCATED(surf_usm_h%t_green_av) )  THEN
    2171                         ALLOCATE( surf_usm_h%t_green_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
    2172                         surf_usm_h%t_green_av = 0.0_wp
     2204                    IF ( l == -1 ) THEN
     2205                       IF ( .NOT.  ALLOCATED(surf_usm_h%t_green_av) )  THEN
     2206                           ALLOCATE( surf_usm_h%t_green_av(nzb_wall:nzt_wall,1:surf_usm_h%ns) )
     2207                           surf_usm_h%t_green_av = 0.0_wp
     2208                       ENDIF
    21732209                    ELSE
    21742210                       IF ( .NOT.  ALLOCATED(surf_usm_v(l)%t_green_av) )  THEN
     
    30913127        CHARACTER(LEN=*),INTENT(OUT)   ::  unit       !<
    30923128
    3093         INTEGER(iwp)                                  :: i,j          !< index
     3129        INTEGER(iwp)                                  :: i,j,l        !< index
     3130        CHARACTER(LEN=2)                              :: ls
    30943131        CHARACTER(LEN=varnamelength)                  :: var          !< TRIM(variable)
    3095         INTEGER(iwp), PARAMETER                       :: nl1 = 32     !< number of directional usm variables
     3132        INTEGER(iwp), PARAMETER                       :: nl1 = 31     !< number of directional usm variables
    30963133        CHARACTER(LEN=varnamelength), DIMENSION(nl1)  :: varlist1 = & !< list of directional usm variables
    30973134                  (/'usm_rad_net                   ', &
     
    31193156                    'usm_surfalb                   ', &
    31203157                    'usm_surfemis                  ', &
    3121                     'usm_t_surf                    ', &
     3158                    'usm_t_surf_wall               ', &
    31223159                    'usm_t_surf_window             ', &
    31233160                    'usm_t_surf_green              ', &
    31243161                    'usm_t_green                   ', &
    31253162                    'usm_t_surf_10cm               ', &
    3126                     'usm_t_wall                    ', &
    3127                     'usm_t_window                  ', &
    3128                     'usm_t_green                   '/)
    3129 
    3130         INTEGER(iwp), PARAMETER                       :: nl2 = 9      !< number of other variables
     3163                    'usm_skyvf                     ', &
     3164                    'usm_skyvft                    '/)
     3165
     3166        INTEGER(iwp), PARAMETER                       :: nl2 = 7      !< number of other variables
    31313167        CHARACTER(LEN=varnamelength), DIMENSION(nl2)  :: varlist2 = & !< list of other usm variables
    3132                   (/'usm_skyvf                     ', &
    3133                     'usm_skyvft                    ', &
    3134                     'usm_svf                       ', &
     3168                  (/'usm_svf                       ', &
    31353169                    'usm_dif                       ', &
    31363170                    'usm_rad_pc_inlw               ', &
     
    31393173                    'usm_rad_pc_inswdif            ', &
    31403174                    'usm_rad_pc_inswref            '/)
     3175
     3176        INTEGER(iwp), PARAMETER                       :: nl3 = 3      !< number of directional layer usm variables
     3177        CHARACTER(LEN=varnamelength), DIMENSION(nl3)  :: varlist3 = & !< list of directional layer usm variables
     3178                  (/'usm_t_wall                    ', &
     3179                    'usm_t_window                  ', &
     3180                    'usm_t_green                   '/)
    31413181
    31423182        INTEGER(iwp), PARAMETER                       :: nd = 5     !< number of directions
     
    31583198                 EXIT
    31593199              ENDIF
     3200              IF ( lfound ) EXIT
     3201           ENDDO
     3202        ENDDO
     3203        IF ( lfound ) GOTO 10
     3204!       directional layer variables
     3205        DO i = 1, nl3
     3206           DO j = 1, nd
     3207              DO l = nzb_wall, nzt_wall
     3208                 WRITE(ls,'(A1,I1)') '_',l
     3209                 IF ( TRIM(var) == TRIM(varlist3(i))//TRIM(ls)//TRIM(dirname(j)) ) THEN
     3210                    lfound = .TRUE.
     3211                    EXIT
     3212                 ENDIF
     3213              ENDDO
    31603214              IF ( lfound ) EXIT
    31613215           ENDDO
     
    45034557             var(1:9) == 'usm_qsws_'  .OR.  var(1:13) == 'usm_qsws_veg_'  .OR.              &
    45044558             var(1:13) == 'usm_qsws_liq_' .OR.                                              &
    4505              var(1:10) == 'usm_t_surf_wall'  .OR.  var(1:10) == 'usm_t_wall'  .OR.          &
     4559             var(1:15) == 'usm_t_surf_wall'  .OR.  var(1:10) == 'usm_t_wall'  .OR.          &
    45064560             var(1:17) == 'usm_t_surf_window'  .OR.  var(1:12) == 'usm_t_window'  .OR.      &
    45074561             var(1:16) == 'usm_t_surf_green'  .OR. var(1:11) == 'usm_t_green' .OR.          &
     
    59105964        ENDIF
    59115965
    5912         IF ( plant_canopy )  THEN
    5913            
    5914             IF ( .NOT.  ALLOCATED( pc_heating_rate) )  THEN
    5915 !--             then pc_heating_rate is allocated in init_plant_canopy
    5916 !--             in case of cthf /= 0 => we need to allocate it for our use here
    5917                 ALLOCATE( pc_heating_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
    5918 
    5919                 pc_heating_rate = 0.0_wp
    5920 
    5921             ENDIF
    5922 
    5923             IF ( .NOT.  ALLOCATED( pc_transpiration_rate) )  THEN
    5924 !--             then pc_heating_rate is allocated in init_plant_canopy
    5925 !--             in case of cthf /= 0 => we need to allocate it for our use here
    5926                 ALLOCATE( pc_transpiration_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
    5927 
    5928                 pc_transpiration_rate = 0.0_wp
    5929 
    5930 
    5931             ENDIF
    5932         ENDIF
    59335966!
    59345967!--    Check for consistent initialization.
     
    60926125               ENDDO
    60936126            ENDDO
    6094         ELSE
    6095 !--         If specified, replace constant wall temperatures with fully 3D values from file
    6096             IF ( read_wall_temp_3d )  CALL usm_read_wall_temperature()
    6097 !
    60986127        ENDIF
    6099        
    6100 !--   
     6128
     6129!--     If specified, replace constant wall temperatures with fully 3D values from file
     6130        IF ( read_wall_temp_3d )  CALL usm_read_wall_temperature()
     6131
     6132!--
    61016133!--     Possibly DO user-defined actions (e.g. define heterogeneous wall surface)
    61026134        CALL user_init_urban_surface
     
    88708902!> x, y, d, z coordinates
    88718903!------------------------------------------------------------------------------!
    8872     PURE FUNCTION advance_surface(isurfl_start, isurfl_stop, x, y, z, d) &
    8873             result(isurfl)
    8874 
    8875         INTEGER(iwp), INTENT(in)                :: isurfl_start, isurfl_stop
     8904    PURE FUNCTION find_surface( x, y, z, d ) result(isurfl)
     8905
    88768906        INTEGER(iwp), INTENT(in)                :: x, y, z, d
    8877         INTEGER(iwp)                            :: isx, isy, isz, isd
    88788907        INTEGER(iwp)                            :: isurfl
    8879 
    8880         DO isurfl = isurfl_start, isurfl_stop
    8881             isx = surfl(ix, isurfl)
    8882             isy = surfl(iy, isurfl)
    8883             isz = surfl(iz, isurfl)
    8884             isd = surfl(id, isurfl)
    8885             IF ( isx==x .and. isy==y .and. isz==z .and. isd==d )  RETURN
    8886         ENDDO
     8908        INTEGER(iwp)                            :: isx, isy, isz
     8909
     8910        IF ( d == 0 ) THEN
     8911           DO  isurfl = 1, surf_usm_h%ns
     8912              isx = surf_usm_h%i(isurfl)
     8913              isy = surf_usm_h%j(isurfl)
     8914              isz = surf_usm_h%k(isurfl)
     8915              IF ( isx==x .and. isy==y .and. isz==z )  RETURN
     8916           ENDDO
     8917        ELSE
     8918           DO  isurfl = 1, surf_usm_v(d-1)%ns
     8919              isx = surf_usm_v(d-1)%i(isurfl)
     8920              isy = surf_usm_v(d-1)%j(isurfl)
     8921              isz = surf_usm_v(d-1)%k(isurfl)
     8922              IF ( isx==x .and. isy==y .and. isz==z )  RETURN
     8923           ENDDO
     8924        ENDIF
    88878925
    88888926!--     coordinate not found
     
    89278965                        nys <= j .and. j <= nyn)  THEN  !< local processor
    89288966!--                     identify surface id
    8929                         isurfl = advance_surface(isurfl+1, nsurfl, i, j, k, d)
     8967                        isurfl = find_surface( i, j, k, d )
    89308968                        IF ( isurfl == -1 )  THEN
    89318969                            WRITE(message_string, '(a,4i5,a,i5,a)') 'Coordinates (xyzd) ', i, j, k, d, &
     
    89398977                           t_surf_wall_h(isurfl) = rtsurf
    89408978                           t_wall_h(:,isurfl) = rtwall(:)
     8979                           t_window_h(:,isurfl) = rtwall(:)
     8980                           t_green_h(:,isurfl) = rtwall(:)
    89418981                        ELSE
    89428982                           t_surf_wall_v(d-1)%t(isurfl) = rtsurf
    89438983                           t_wall_v(d-1)%t(:,isurfl) = rtwall(:)
     8984                           t_window_v(d-1)%t(:,isurfl) = rtwall(:)
     8985                           t_green_v(d-1)%t(:,isurfl) = rtwall(:)
    89448986                        ENDIF
    89458987                    ENDIF
     
    96639705                                          surf_usm_v(l)%rad_lw_out(m)
    96649706
    9665 if ((abs(t_surf_wall_v(l)%t(m)-276.).gt.100.).or.(abs(t_surf_window_v(l)%t(m)-276.).gt.300.) &
    9666 .or.(abs(t_surf_green_v(l)%t(m)-276.).gt.100)) then
    9667 print*, "tsurfvvvv",m,t_surf_wall_v(l)%t(m),t_surf_window_v(l)%t(m),t_surf_green_v(l)%t(m)
    9668 print*, "params", surf_usm_v(l)%emissivity(ind_veg_wall,m),lambda_surface, t_wall_v(l)%t(nzb_wall:nzt_wall,m), &
    9669                   surf_usm_v(l)%emissivity(ind_wat_win,m),lambda_surface_window,t_window_v(l)%t(nzb_wall:nzt_wall,m),t_green_v(l)%t(nzb_wall:nzt_wall,m)
    9670 print*, "dicken",surf_usm_v(l)%zw(nzb_wall:nzt_wall,m),surf_usm_v(l)%zw_window(nzb_wall:nzt_wall,m),surf_usm_v(l)%zw_green(nzb_wall:nzt_wall,m)
    9671 print*, "c",surf_usm_v(l)%c_surface_window(m),surf_usm_v(l)%c_surface(m)
    9672 !if ((abs(t_surf_v(l)%t(m)-276.).gt.10.).or.(abs(t_surf_window_v(l)%t(m)-276.).gt.10.)) then
    9673 stop
    9674 endif
    96759707!--           numerator of the prognostic equation
    96769708              coef_1 = surf_usm_v(l)%rad_net_l(m) +                            & ! coef +1 corresponds to -lwout included in calculation of radnet_l
Note: See TracChangeset for help on using the changeset viewer.