source: palm/trunk/SOURCE/plant_canopy_model_mod.f90 @ 3248

Last change on this file since 3248 was 3248, checked in by sward, 6 years ago

Minor format changes

  • Property svn:keywords set to Id
File size: 75.6 KB
RevLine 
[1826]1!> @file plant_canopy_model_mod.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[257]20! Current revisions:
[2977]21! ------------------
[2214]22!
[3049]23!
[2214]24! Former revisions:
25! -----------------
26! $Id: plant_canopy_model_mod.f90 3248 2018-09-14 09:42:06Z sward $
[3248]27! Minor formating changes
28!
29! 3246 2018-09-13 15:14:50Z sward
[3246]30! Added error handling for input namelist via parin_fail_message
31!
32! 3241 2018-09-12 15:02:00Z raasch
[3241]33! unused variables removed
34!
35! 3065 2018-06-12 07:03:02Z Giersch
[3065]36! dz was replaced by the help of zw to allow for vertical stretching
37!
38! 3049 2018-05-29 13:52:36Z Giersch
[3049]39! Error messages revised
40!
41! 3045 2018-05-28 07:55:41Z Giersch
[3045]42! Error message revised
43!
44! 3022 2018-05-18 11:12:35Z suehring
[3022]45! Bugfix in allocation of transpiration rate
46!
47! 3014 2018-05-09 08:42:38Z maronga
[3014]48! Bugfix: nzb_do and nzt_do were not used for 3d data output
49! Added pc_transpiration_rate
50!
51! 2977 2018-04-17 10:27:57Z kanani
[2977]52! Implement changes from branch radiation (r2948-2971) with minor modifications,
53! plus some formatting.
54! (moh.hefny):
55! Add plant canopy type to account for changes in LAD (based on the changes
56! done by Resler & Pavel) and correct the error message to PALM Standard.
57!
58! 2932 2018-03-26 09:39:22Z maronga
[2932]59! renamed canopy_par to plant_canopy_parameters
60!
61! 2920 2018-03-22 11:22:01Z kanani
[2920]62! Move usm_lad_rma and prototype_lad to radiation_model (moh.hefny)
63!
64! 2892 2018-03-14 15:06:29Z suehring
[2892]65! Bugfix, read separate ASCII LAD files for parent and child model.
66!
67! 2770 2018-01-25 15:10:09Z kanani
[2770]68! Correction of parameter check
69!
70! 2768 2018-01-24 15:38:29Z kanani
[2768]71! Added check for output quantity pcm_heatrate, some formatting
72!
73! 2766 2018-01-22 17:17:47Z kanani
[2766]74! Increased LEN of canopy mode to 30
75!
76! 2746 2018-01-15 12:06:04Z suehring
[2746]77! Move flag plant canopy to modules
78!
79! 2718 2018-01-02 08:49:38Z maronga
[2716]80! Corrected "Former revisions" section
81!
82! 2701 2017-12-15 15:40:50Z suehring
83! Changes from last commit documented
84!
85! 2698 2017-12-14 18:46:24Z suehring
[2701]86! Bugfix in get_topography_top_index
87!
[2716]88! 2696 2017-12-14 17:12:51Z kanani
89! Change in file header (GPL part)
[2696]90! Bugfix for vertical loop index pch_index in case of Netcdf input
91! Introduce 2D index array incorporate canopy top index
92! Check if canopy on top of topography do not exceed vertical dimension
93! Add check for canopy_mode in case of Netcdf input.
94! Enable _FillValue output for 3d quantities
95! Bugfix in reading of PIDS leaf area density (MS)
96!
97! 2669 2017-12-06 16:03:27Z raasch
[2669]98! coupling_char removed
99!
100! 2512 2017-10-04 08:26:59Z raasch
[2512]101! upper bounds of 3d output changed from nx+1,ny+1 to nx,ny
102! no output of ghost layer data
103!
104! 2318 2017-07-20 17:27:44Z suehring
[2318]105! Get topography top index via Function call
106!
107! 2317 2017-07-20 17:27:19Z suehring
[2274]108! Changed error messages
109!
110! 2233 2017-05-30 18:08:54Z suehring
[2214]111!
[2233]112! 2232 2017-05-30 17:47:52Z suehring
113! Adjustments to new topography concept
114!
[2214]115! 2213 2017-04-24 15:10:35Z kanani
[2213]116! Bugfix: exchange of ghost points in array pc_heating_rate needed for output
117! of pcm_heatrate, onetime ghost point exchange of lad_s after initialization.
118! Formatting and clean-up of subroutine pcm_read_plant_canopy_3d,
119! minor re-organization of canopy-heating initialization.
[2008]120!
[2210]121! 2209 2017-04-19 09:34:46Z kanani
122! Added 3d output of leaf area density (pcm_lad) and canopy
123! heat rate (pcm_heatrate)
124!
[2025]125! 2024 2016-10-12 16:42:37Z kanani
126! Added missing lad_s initialization
127!
[2012]128! 2011 2016-09-19 17:29:57Z kanani
129! Renamed canopy_heat_flux to pc_heating_rate, since the original meaning/
130! calculation of the quantity has changed, related to the urban surface model
131! and similar future applications.
132!
[2008]133! 2007 2016-08-24 15:47:17Z kanani
[2007]134! Added SUBROUTINE pcm_read_plant_canopy_3d for reading 3d plant canopy data
135! from file (new case canopy_mode=read_from_file_3d) in the course of
136! introduction of urban surface model,
137! introduced variable ext_coef,
138! resorted SUBROUTINEs to alphabetical order
[1827]139!
[2001]140! 2000 2016-08-20 18:09:15Z knoop
141! Forced header and separation lines into 80 columns
142!
[1961]143! 1960 2016-07-12 16:34:24Z suehring
144! Separate humidity and passive scalar
145!
[1954]146! 1953 2016-06-21 09:28:42Z suehring
147! Bugfix, lad_s and lad must be public
148!
[1827]149! 1826 2016-04-07 12:01:39Z maronga
150! Further modularization
151!
[1722]152! 1721 2015-11-16 12:56:48Z raasch
153! bugfixes: shf is reduced in areas covered with canopy only,
154!           canopy is set on top of topography
155!
[1683]156! 1682 2015-10-07 23:56:08Z knoop
157! Code annotations made doxygen readable
158!
[1485]159! 1484 2014-10-21 10:53:05Z kanani
[1484]160! Changes due to new module structure of the plant canopy model:
161!   module plant_canopy_model_mod now contains a subroutine for the
[1826]162!   initialization of the canopy model (pcm_init),
[1484]163!   limitation of the canopy drag (previously accounted for by calculation of
164!   a limiting canopy timestep for the determination of the maximum LES timestep
165!   in subroutine timestep) is now realized by the calculation of pre-tendencies
[1826]166!   and preliminary velocities in subroutine pcm_tendency,
167!   some redundant MPI communication removed in subroutine pcm_init
[1484]168!   (was previously in init_3d_model),
169!   unnecessary 3d-arrays lad_u, lad_v, lad_w removed - lad information on the
170!   respective grid is now provided only by lad_s (e.g. in the calculation of
171!   the tendency terms or of cum_lai_hf),
172!   drag_coefficient, lai, leaf_surface_concentration,
173!   scalar_exchange_coefficient, sec and sls renamed to canopy_drag_coeff,
174!   cum_lai_hf, leaf_surface_conc, leaf_scalar_exch_coeff, lsec and lsc,
175!   respectively,
176!   unnecessary 3d-arrays cdc, lsc and lsec now defined as single-value constants,
177!   USE-statements and ONLY-lists modified accordingly
[1341]178!
179! 1340 2014-03-25 19:45:13Z kanani
180! REAL constants defined as wp-kind
181!
[1321]182! 1320 2014-03-20 08:40:49Z raasch
[1320]183! ONLY-attribute added to USE-statements,
184! kind-parameters added to all INTEGER and REAL declaration statements,
185! kinds are defined in new module kinds,
186! old module precision_kind is removed,
187! revision history before 2012 removed,
188! comment fields (!:) to be used for variable explanations added to
189! all variable declaration statements
[153]190!
[1037]191! 1036 2012-10-22 13:43:42Z raasch
192! code put under GPL (PALM 3.9)
193!
[139]194! 138 2007-11-28 10:03:58Z letzel
195! Initial revision
196!
[138]197! Description:
198! ------------
[1682]199!> 1) Initialization of the canopy model, e.g. construction of leaf area density
[1826]200!> profile (subroutine pcm_init).
[1682]201!> 2) Calculation of sinks and sources of momentum, heat and scalar concentration
[1826]202!> due to canopy elements (subroutine pcm_tendency).
[138]203!------------------------------------------------------------------------------!
[1682]204 MODULE plant_canopy_model_mod
205 
[1484]206    USE arrays_3d,                                                             &
[2232]207        ONLY:  dzu, dzw, e, q, s, tend, u, v, w, zu, zw 
[138]208
[1484]209    USE indices,                                                               &
210        ONLY:  nbgp, nxl, nxlg, nxlu, nxr, nxrg, nyn, nyng, nys, nysg, nysv,   &
[2317]211               nz, nzb, nzt
[1484]212
213    USE kinds
214
[2317]215    USE surface_mod,                                                           &
[2698]216        ONLY:  get_topography_top_index_ji
[1484]217
[2317]218
[1484]219    IMPLICIT NONE
220
221
[2766]222    CHARACTER (LEN=30)   ::  canopy_mode = 'block' !< canopy coverage
[1484]223
[2696]224    INTEGER(iwp) ::  pch_index = 0                               !< plant canopy height/top index
225    INTEGER(iwp) ::  lad_vertical_gradient_level_ind(10) = -9999 !< lad-profile levels (index)
[1484]226
[2696]227    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  pch_index_ji   !< local plant canopy top
228
[1682]229    LOGICAL ::  calc_beta_lad_profile = .FALSE. !< switch for calc. of lad from beta func.
[1484]230
[2696]231    REAL(wp) ::  alpha_lad = 9999999.9_wp         !< coefficient for lad calculation
232    REAL(wp) ::  beta_lad = 9999999.9_wp          !< coefficient for lad calculation
233    REAL(wp) ::  canopy_drag_coeff = 0.0_wp       !< canopy drag coefficient (parameter)
234    REAL(wp) ::  cdc = 0.0_wp                     !< canopy drag coeff. (abbreviation used in equations)
235    REAL(wp) ::  cthf = 0.0_wp                    !< canopy top heat flux
236    REAL(wp) ::  dt_plant_canopy = 0.0_wp         !< timestep account. for canopy drag
237    REAL(wp) ::  ext_coef = 0.6_wp                !< extinction coefficient
238    REAL(wp) ::  lad_surface = 0.0_wp             !< lad surface value
239    REAL(wp) ::  lai_beta = 0.0_wp                !< leaf area index (lai) for lad calc.
240    REAL(wp) ::  leaf_scalar_exch_coeff = 0.0_wp  !< canopy scalar exchange coeff.
241    REAL(wp) ::  leaf_surface_conc = 0.0_wp       !< leaf surface concentration
[2768]242    REAL(wp) ::  lsc = 0.0_wp                     !< leaf surface concentration
[2696]243    REAL(wp) ::  lsec = 0.0_wp                    !< leaf scalar exchange coeff.
[1484]244
[2696]245    REAL(wp) ::  lad_vertical_gradient(10) = 0.0_wp              !< lad gradient
246    REAL(wp) ::  lad_vertical_gradient_level(10) = -9999999.9_wp !< lad-prof. levels (in m)
[1484]247
[2977]248    REAL(wp) ::  lad_type_coef(0:10) = 1.0_wp   !< multiplicative coeficients for particular types
249                                                !< of plant canopy (e.g. deciduous tree during winter)
250
[1682]251    REAL(wp), DIMENSION(:), ALLOCATABLE ::  lad            !< leaf area density
252    REAL(wp), DIMENSION(:), ALLOCATABLE ::  pre_lad        !< preliminary lad
[1484]253   
[2768]254    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  cum_lai_hf       !< cumulative lai for heatflux calc.
255    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  lad_s            !< lad on scalar-grid
256    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_heating_rate  !< plant canopy heating rate
[3014]257    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pc_transpiration_rate  !< plant canopy transpiration rate
[1484]258
259    SAVE
260
261
[138]262    PRIVATE
[1826]263 
264!
265!-- Public functions
[2209]266    PUBLIC pcm_check_data_output, pcm_check_parameters, pcm_data_output_3d,    &
267           pcm_define_netcdf_grid, pcm_header, pcm_init, pcm_parin, pcm_tendency
[138]268
[1826]269!
270!-- Public variables and constants
[3014]271    PUBLIC pc_heating_rate, pc_transpiration_rate, canopy_mode, cthf, dt_plant_canopy, lad, lad_s,   &
[2920]272           pch_index
[2007]273           
[1484]274
[2209]275    INTERFACE pcm_check_data_output
276       MODULE PROCEDURE pcm_check_data_output
277    END INTERFACE pcm_check_data_output
278   
[1826]279    INTERFACE pcm_check_parameters
280       MODULE PROCEDURE pcm_check_parameters
[2209]281    END INTERFACE pcm_check_parameters
282
283    INTERFACE pcm_data_output_3d
284       MODULE PROCEDURE pcm_data_output_3d
285    END INTERFACE pcm_data_output_3d
286
287    INTERFACE pcm_define_netcdf_grid
288       MODULE PROCEDURE pcm_define_netcdf_grid
289    END INTERFACE pcm_define_netcdf_grid
[1826]290   
291     INTERFACE pcm_header
292       MODULE PROCEDURE pcm_header
293    END INTERFACE pcm_header       
294   
295    INTERFACE pcm_init
296       MODULE PROCEDURE pcm_init
297    END INTERFACE pcm_init
[138]298
[1826]299    INTERFACE pcm_parin
300       MODULE PROCEDURE pcm_parin
[2007]301    END INTERFACE pcm_parin
302
303    INTERFACE pcm_read_plant_canopy_3d
304       MODULE PROCEDURE pcm_read_plant_canopy_3d
305    END INTERFACE pcm_read_plant_canopy_3d
[1826]306   
307    INTERFACE pcm_tendency
308       MODULE PROCEDURE pcm_tendency
309       MODULE PROCEDURE pcm_tendency_ij
310    END INTERFACE pcm_tendency
[1484]311
312
[138]313 CONTAINS
314
[2209]315
316!------------------------------------------------------------------------------!
317! Description:
318! ------------
319!> Check data output for plant canopy model
320!------------------------------------------------------------------------------!
321 SUBROUTINE pcm_check_data_output( var, unit )
[1826]322 
[2209]323 
324    USE control_parameters,                                                 &
[3241]325        ONLY:  message_string, urban_surface
[2209]326
327    IMPLICIT NONE
328
329    CHARACTER (LEN=*) ::  unit  !<
330    CHARACTER (LEN=*) ::  var   !<
331
332
333    SELECT CASE ( TRIM( var ) )
334
335       CASE ( 'pcm_heatrate' )
[2770]336          IF ( cthf == 0.0_wp  .AND. .NOT.  urban_surface )  THEN
[2768]337             message_string = 'output of "' // TRIM( var ) // '" requi' //  &
338                              'res setting of parameter cthf /= 0.0'
339             CALL message( 'pcm_check_data_output', 'PA1000', 1, 2, 0, 6, 0 )
340          ENDIF
[2209]341          unit = 'K s-1'
342   
[3014]343       CASE ( 'pcm_transpirationrate' )
344          unit = 'kg kg-1 s-1'
345
[2209]346       CASE ( 'pcm_lad' )
347          unit = 'm2 m-3'
348
349
350       CASE DEFAULT
351          unit = 'illegal'
352
353    END SELECT
354
355
356 END SUBROUTINE pcm_check_data_output
357 
358 
[1826]359!------------------------------------------------------------------------------!
360! Description:
361! ------------
362!> Check parameters routine for plant canopy model
363!------------------------------------------------------------------------------!
364    SUBROUTINE pcm_check_parameters
[138]365
[1826]366       USE control_parameters,                                                 &
[2696]367           ONLY: cloud_physics, coupling_char, message_string,                 &
368                 microphysics_seifert
369
370       USE netcdf_data_input_mod,                                              &
371           ONLY:  input_file_static, input_pids_static
[1826]372                 
373   
374       IMPLICIT NONE
375
376   
377       IF ( canopy_drag_coeff == 0.0_wp )  THEN
378          message_string = 'plant_canopy = .TRUE. requires a non-zero drag '// &
[3046]379                           'coefficient & given value is canopy_drag_coeff = 0.0'
[2768]380          CALL message( 'pcm_check_parameters', 'PA0041', 1, 2, 0, 6, 0 )
[1826]381       ENDIF
382   
[3045]383       IF ( ( alpha_lad /= 9999999.9_wp  .AND.  beta_lad == 9999999.9_wp ) .OR.&
[1826]384              beta_lad /= 9999999.9_wp   .AND.  alpha_lad == 9999999.9_wp )  THEN
385          message_string = 'using the beta function for the construction ' //  &
386                           'of the leaf area density profile requires '    //  &
387                           'both alpha_lad and beta_lad to be /= 9999999.9'
[2768]388          CALL message( 'pcm_check_parameters', 'PA0118', 1, 2, 0, 6, 0 )
[1826]389       ENDIF
390   
391       IF ( calc_beta_lad_profile  .AND.  lai_beta == 0.0_wp )  THEN
392          message_string = 'using the beta function for the construction ' //  &
393                           'of the leaf area density profile requires '    //  &
394                           'a non-zero lai_beta, but given value is '      //  &
395                           'lai_beta = 0.0'
[2768]396          CALL message( 'pcm_check_parameters', 'PA0119', 1, 2, 0, 6, 0 )
[1826]397       ENDIF
398
399       IF ( calc_beta_lad_profile  .AND.  lad_surface /= 0.0_wp )  THEN
[2274]400          message_string = 'simultaneous setting of alpha_lad /= 9999999.9 '// &
401                           'combined with beta_lad /= 9999999.9 '           // &
[1826]402                           'and lad_surface /= 0.0 is not possible, '       // &
403                           'use either vertical gradients or the beta '     // &
404                           'function for the construction of the leaf area '// &
405                           'density profile'
[2768]406          CALL message( 'pcm_check_parameters', 'PA0120', 1, 2, 0, 6, 0 )
[1826]407       ENDIF
408
409       IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
410          message_string = 'plant_canopy = .TRUE. requires cloud_scheme /=' // &
411                          ' seifert_beheng'
[2768]412          CALL message( 'pcm_check_parameters', 'PA0360', 1, 2, 0, 6, 0 )
[1826]413       ENDIF
[2696]414!
415!--    If dynamic input file is used, canopy need to be read from file
416       IF ( input_pids_static  .AND.                                           &
417            TRIM( canopy_mode ) /= 'read_from_file_3d' )  THEN
418          message_string = 'Usage of dynamic input file ' //                   &
419                           TRIM( input_file_static ) //                        &
420                           TRIM( coupling_char ) // ' requires ' //            &
421                           'canopy_mode = read_from_file_3d'
[2768]422          CALL message( 'pcm_check_parameters', 'PA0999', 1, 2, 0, 6, 0 )
[2696]423       ENDIF
[1826]424
425 
426    END SUBROUTINE pcm_check_parameters 
427 
428
[138]429!------------------------------------------------------------------------------!
[2209]430!
[1484]431! Description:
432! ------------
[2209]433!> Subroutine defining 3D output variables
434!------------------------------------------------------------------------------!
[3014]435 SUBROUTINE pcm_data_output_3d( av, variable, found, local_pf, fill_value,     &
436                                nzb_do, nzt_do )
437 
[2209]438    USE indices
439
440    USE kinds
441
442
443    IMPLICIT NONE
444
445    CHARACTER (LEN=*) ::  variable !<
446
[2696]447    INTEGER(iwp) ::  av     !<
448    INTEGER(iwp) ::  i      !<
449    INTEGER(iwp) ::  j      !<
450    INTEGER(iwp) ::  k      !<
451    INTEGER(iwp) ::  k_topo !< topography top index
[3014]452    INTEGER(iwp) ::  nzb_do !< lower limit of the data output (usually 0)
453    INTEGER(iwp) ::  nzt_do !< vertical upper limit of the data output (usually nz_do3d)
[2209]454
455    LOGICAL      ::  found !<
456
[2696]457    REAL(wp)     ::  fill_value
[3014]458    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf !<
[2209]459
460
461    found = .TRUE.
462
[2696]463    local_pf = REAL( fill_value, KIND = 4 )
[2209]464
465    SELECT CASE ( TRIM( variable ) )
466
467      CASE ( 'pcm_heatrate' )
468         IF ( av == 0 )  THEN
[2512]469            DO  i = nxl, nxr
470               DO  j = nys, nyn
[2696]471                  IF ( pch_index_ji(j,i) /= 0 )  THEN
[2698]472                     k_topo = get_topography_top_index_ji( j, i, 's' )
[2696]473                     DO  k = k_topo, k_topo + pch_index_ji(j,i)
474                        local_pf(i,j,k) = pc_heating_rate(k-k_topo,j,i)
475                     ENDDO
476                  ENDIF
[2209]477               ENDDO
478            ENDDO
479         ENDIF
[3014]480   
481       CASE ( 'pcm_transpirationrate' )
482         IF ( av == 0 )  THEN
483            DO  i = nxl, nxr
484               DO  j = nys, nyn
485                  IF ( pch_index_ji(j,i) /= 0 )  THEN
486                     k_topo = get_topography_top_index_ji( j, i, 's' )
487                     DO  k = k_topo, k_topo + pch_index_ji(j,i)
488                        local_pf(i,j,k) = pc_transpiration_rate(k-k_topo,j,i)
489                     ENDDO
490                  ENDIF
491               ENDDO
492            ENDDO
493         ENDIF
[2209]494   
495      CASE ( 'pcm_lad' )
496         IF ( av == 0 )  THEN
[2512]497            DO  i = nxl, nxr
498               DO  j = nys, nyn
[2696]499                  IF ( pch_index_ji(j,i) /= 0 )  THEN
[2698]500                     k_topo = get_topography_top_index_ji( j, i, 's' )
[2696]501                     DO  k = k_topo, k_topo + pch_index_ji(j,i)
502                        local_pf(i,j,k) = lad_s(k-k_topo,j,i)
503                     ENDDO
504                  ENDIF
[2209]505               ENDDO
506            ENDDO
507         ENDIF
508                 
509         
510       CASE DEFAULT
511          found = .FALSE.
512
513    END SELECT
514
515
516 END SUBROUTINE pcm_data_output_3d 
517         
518!------------------------------------------------------------------------------!
519!
520! Description:
521! ------------
522!> Subroutine defining appropriate grid for netcdf variables.
523!> It is called from subroutine netcdf.
524!------------------------------------------------------------------------------!
525 SUBROUTINE pcm_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
526   
527     IMPLICIT NONE
528
529     CHARACTER (LEN=*), INTENT(IN)  ::  var         !<
530     LOGICAL, INTENT(OUT)           ::  found       !<
531     CHARACTER (LEN=*), INTENT(OUT) ::  grid_x      !<
532     CHARACTER (LEN=*), INTENT(OUT) ::  grid_y      !<
533     CHARACTER (LEN=*), INTENT(OUT) ::  grid_z      !<
534
535     found  = .TRUE.
536
537!
538!--  Check for the grid
539     SELECT CASE ( TRIM( var ) )
540
[3014]541        CASE ( 'pcm_heatrate', 'pcm_lad', 'pcm_transpirationrate')
[2209]542           grid_x = 'x'
543           grid_y = 'y'
544           grid_z = 'zu'
545
546        CASE DEFAULT
547           found  = .FALSE.
548           grid_x = 'none'
549           grid_y = 'none'
550           grid_z = 'none'
551     END SELECT
552
553 END SUBROUTINE pcm_define_netcdf_grid
554 
555 
556!------------------------------------------------------------------------------!
557! Description:
558! ------------
[1826]559!> Header output for plant canopy model
560!------------------------------------------------------------------------------!
561    SUBROUTINE pcm_header ( io )
562
563       USE control_parameters,                                                 &
[3065]564           ONLY: passive_scalar
[1826]565
566
567       IMPLICIT NONE
568 
569       CHARACTER (LEN=10) ::  coor_chr            !<
570
571       CHARACTER (LEN=86) ::  coordinates         !<
572       CHARACTER (LEN=86) ::  gradients           !<
573       CHARACTER (LEN=86) ::  leaf_area_density   !<
574       CHARACTER (LEN=86) ::  slices              !<
575 
576       INTEGER(iwp) :: i                !<
577       INTEGER(iwp),  INTENT(IN) ::  io !< Unit of the output file
578       INTEGER(iwp) :: k                !<       
579   
580       REAL(wp) ::  canopy_height       !< canopy height (in m)
581       
[3065]582       canopy_height = zw(pch_index)
[1826]583
584       WRITE ( io, 1 )  canopy_mode, canopy_height, pch_index,                 &
585                          canopy_drag_coeff
586       IF ( passive_scalar )  THEN
587          WRITE ( io, 2 )  leaf_scalar_exch_coeff,                             &
588                             leaf_surface_conc
589       ENDIF
590
591!
592!--    Heat flux at the top of vegetation
593       WRITE ( io, 3 )  cthf
594
595!
596!--    Leaf area density profile, calculated either from given vertical
597!--    gradients or from beta probability density function.
598       IF (  .NOT.  calc_beta_lad_profile )  THEN
599
600!--       Building output strings, starting with surface value
601          WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
602          gradients = '------'
603          slices = '     0'
604          coordinates = '   0.0'
605          i = 1
606          DO  WHILE ( i < 11  .AND.  lad_vertical_gradient_level_ind(i)        &
607                      /= -9999 )
608
609             WRITE (coor_chr,'(F7.2)')  lad(lad_vertical_gradient_level_ind(i))
610             leaf_area_density = TRIM( leaf_area_density ) // ' ' //           &
611                                 TRIM( coor_chr )
612 
613             WRITE (coor_chr,'(F7.2)')  lad_vertical_gradient(i)
614             gradients = TRIM( gradients ) // ' ' // TRIM( coor_chr )
615
616             WRITE (coor_chr,'(I7)')  lad_vertical_gradient_level_ind(i)
617             slices = TRIM( slices ) // ' ' // TRIM( coor_chr )
618
619             WRITE (coor_chr,'(F7.1)')  lad_vertical_gradient_level(i)
620             coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
621
622             i = i + 1
623          ENDDO
624
625          WRITE ( io, 4 )  TRIM( coordinates ), TRIM( leaf_area_density ),     &
626                             TRIM( gradients ), TRIM( slices )
627
628       ELSE
629       
630          WRITE ( leaf_area_density, '(F7.4)' )  lad_surface
631          coordinates = '   0.0'
632         
633          DO  k = 1, pch_index
634
635             WRITE (coor_chr,'(F7.2)')  lad(k)
636             leaf_area_density = TRIM( leaf_area_density ) // ' ' //           &
637                                 TRIM( coor_chr )
638 
639             WRITE (coor_chr,'(F7.1)')  zu(k)
640             coordinates = TRIM( coordinates ) // ' '  // TRIM( coor_chr )
641
642          ENDDO       
643
644          WRITE ( io, 5 ) TRIM( coordinates ), TRIM( leaf_area_density ),      &
645                          alpha_lad, beta_lad, lai_beta
646
647       ENDIF 
648
6491 FORMAT (//' Vegetation canopy (drag) model:'/                                &
650              ' ------------------------------'//                              &
651              ' Canopy mode: ', A /                                            &
652              ' Canopy height: ',F6.2,'m (',I4,' grid points)' /               &
653              ' Leaf drag coefficient: ',F6.2 /)
6542 FORMAT (/ ' Scalar exchange coefficient: ',F6.2 /                            &
655              ' Scalar concentration at leaf surfaces in kg/m**3: ',F6.2 /)
6563 FORMAT (' Predefined constant heatflux at the top of the vegetation: ',F6.2, &
657          ' K m/s')
6584 FORMAT (/ ' Characteristic levels of the leaf area density:'//               &
659              ' Height:              ',A,'  m'/                                &
660              ' Leaf area density:   ',A,'  m**2/m**3'/                        &
661              ' Gradient:            ',A,'  m**2/m**4'/                        &
662              ' Gridpoint:           ',A)
6635 FORMAT (//' Characteristic levels of the leaf area density and coefficients:'&
664          //  ' Height:              ',A,'  m'/                                &
665              ' Leaf area density:   ',A,'  m**2/m**3'/                        &
666              ' Coefficient alpha: ',F6.2 /                                    &
667              ' Coefficient beta: ',F6.2 /                                     &
668              ' Leaf area index: ',F6.2,'  m**2/m**2' /)   
669       
670    END SUBROUTINE pcm_header
671 
672 
673!------------------------------------------------------------------------------!
674! Description:
675! ------------
[1682]676!> Initialization of the plant canopy model
[138]677!------------------------------------------------------------------------------!
[1826]678    SUBROUTINE pcm_init
[1484]679   
680
681       USE control_parameters,                                                 &
[3241]682           ONLY: humidity, message_string, ocean, urban_surface
[1484]683
[2696]684       USE netcdf_data_input_mod,                                              &
685           ONLY:  leaf_area_density_f
686
[2232]687       USE surface_mod,                                                        &
688           ONLY: surf_def_h, surf_lsm_h, surf_usm_h
[1484]689
690       IMPLICIT NONE
691
[2007]692       INTEGER(iwp) ::  i   !< running index
693       INTEGER(iwp) ::  j   !< running index
694       INTEGER(iwp) ::  k   !< running index
[2232]695       INTEGER(iwp) ::  m   !< running index
[1484]696
[2007]697       REAL(wp) ::  int_bpdf        !< vertical integral for lad-profile construction
698       REAL(wp) ::  gradient        !< gradient for lad-profile construction
699       REAL(wp) ::  canopy_height   !< canopy height for lad-profile construction
[3241]700
[1484]701!
702!--    Allocate one-dimensional arrays for the computation of the
703!--    leaf area density (lad) profile
704       ALLOCATE( lad(0:nz+1), pre_lad(0:nz+1) )
705       lad = 0.0_wp
706       pre_lad = 0.0_wp
707
708!
[1826]709!--    Set flag that indicates that the lad-profile shall be calculated by using
710!--    a beta probability density function
711       IF ( alpha_lad /= 9999999.9_wp  .AND.  beta_lad /= 9999999.9_wp )  THEN
712          calc_beta_lad_profile = .TRUE.
713       ENDIF
714       
715       
716!
[1484]717!--    Compute the profile of leaf area density used in the plant
718!--    canopy model. The profile can either be constructed from
719!--    prescribed vertical gradients of the leaf area density or by
720!--    using a beta probability density function (see e.g. Markkanen et al.,
721!--    2003: Boundary-Layer Meteorology, 106, 437-459)
722       IF (  .NOT.  calc_beta_lad_profile )  THEN   
723
724!
725!--       Use vertical gradients for lad-profile construction   
726          i = 1
727          gradient = 0.0_wp
728
729          IF (  .NOT.  ocean )  THEN
730
731             lad(0) = lad_surface
732             lad_vertical_gradient_level_ind(1) = 0
733 
734             DO k = 1, pch_index
735                IF ( i < 11 )  THEN
736                   IF ( lad_vertical_gradient_level(i) < zu(k)  .AND.          &
737                        lad_vertical_gradient_level(i) >= 0.0_wp )  THEN
738                      gradient = lad_vertical_gradient(i)
739                      lad_vertical_gradient_level_ind(i) = k - 1
740                      i = i + 1
741                   ENDIF
742                ENDIF
743                IF ( gradient /= 0.0_wp )  THEN
744                   IF ( k /= 1 )  THEN
745                      lad(k) = lad(k-1) + dzu(k) * gradient
746                   ELSE
747                      lad(k) = lad_surface + dzu(k) * gradient
748                   ENDIF
749                ELSE
750                   lad(k) = lad(k-1)
751                ENDIF
752             ENDDO
753
754          ENDIF
755
756!
757!--       In case of no given leaf area density gradients, choose a vanishing
758!--       gradient. This information is used for the HEADER and the RUN_CONTROL
759!--       file.
760          IF ( lad_vertical_gradient_level(1) == -9999999.9_wp )  THEN
761             lad_vertical_gradient_level(1) = 0.0_wp
762          ENDIF
763
764       ELSE
765
766!
767!--       Use beta function for lad-profile construction
768          int_bpdf = 0.0_wp
[3065]769          canopy_height = zw(pch_index)
[1484]770
[2232]771          DO k = 0, pch_index
[1484]772             int_bpdf = int_bpdf +                                             &
[1826]773                      ( ( ( zw(k) / canopy_height )**( alpha_lad-1.0_wp ) ) *  &
774                      ( ( 1.0_wp - ( zw(k) / canopy_height ) )**(              &
775                          beta_lad-1.0_wp ) )                                  &
776                      * ( ( zw(k+1)-zw(k) ) / canopy_height ) )
[1484]777          ENDDO
778
779!
780!--       Preliminary lad profile (defined on w-grid)
[2232]781          DO k = 0, pch_index
[1826]782             pre_lad(k) =  lai_beta *                                          &
783                        ( ( ( zw(k) / canopy_height )**( alpha_lad-1.0_wp ) )  &
784                        * ( ( 1.0_wp - ( zw(k) / canopy_height ) )**(          &
785                              beta_lad-1.0_wp ) ) / int_bpdf                   &
786                        ) / canopy_height
[1484]787          ENDDO
788
789!
790!--       Final lad profile (defined on scalar-grid level, since most prognostic
791!--       quantities are defined there, hence, less interpolation is required
792!--       when calculating the canopy tendencies)
793          lad(0) = pre_lad(0)
[2232]794          DO k = 1, pch_index
[1484]795             lad(k) = 0.5 * ( pre_lad(k-1) + pre_lad(k) )
796          ENDDO         
797
798       ENDIF
799
800!
[2213]801!--    Allocate 3D-array for the leaf area density (lad_s).
[1484]802       ALLOCATE( lad_s(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
803
804!
805!--    Initialize canopy parameters cdc (canopy drag coefficient),
806!--    lsec (leaf scalar exchange coefficient), lsc (leaf surface concentration)
807!--    with the prescribed values
808       cdc = canopy_drag_coeff
809       lsec = leaf_scalar_exch_coeff
810       lsc = leaf_surface_conc
811
812!
813!--    Initialization of the canopy coverage in the model domain:
814!--    Setting the parameter canopy_mode = 'block' initializes a canopy, which
815!--    fully covers the domain surface
816       SELECT CASE ( TRIM( canopy_mode ) )
817
818          CASE( 'block' )
819
820             DO  i = nxlg, nxrg
821                DO  j = nysg, nyng
822                   lad_s(:,j,i) = lad(:)
823                ENDDO
824             ENDDO
825
[2007]826          CASE ( 'read_from_file_3d' )
827!
[2696]828!--          Initialize LAD with data from file. If LAD is given in NetCDF file,
829!--          use these values, else take LAD profiles from ASCII file.
830!--          Please note, in NetCDF file LAD is only given up to the maximum
831!--          canopy top, indicated by leaf_area_density_f%nz. 
832             lad_s = 0.0_wp
833             IF ( leaf_area_density_f%from_file )  THEN
834!
835!--             Set also pch_index, used to be the upper bound of the vertical
836!--             loops. Therefore, use the global top of the canopy layer.
837                pch_index = leaf_area_density_f%nz - 1
838
839                DO  i = nxl, nxr
840                   DO  j = nys, nyn
841                      DO  k = 0, leaf_area_density_f%nz - 1
842                      IF ( leaf_area_density_f%var(k,j,i) /=                   &
843                           leaf_area_density_f%fill )                          &
844                         lad_s(k,j,i) = leaf_area_density_f%var(k,j,i)
845                      ENDDO
846                   ENDDO
847                ENDDO
848                CALL exchange_horiz( lad_s, nbgp )
849!
850!            ASCII file
[2007]851!--          Initialize canopy parameters cdc (canopy drag coefficient),
852!--          lsec (leaf scalar exchange coefficient), lsc (leaf surface concentration)
853!--          from file which contains complete 3D data (separate vertical profiles for
854!--          each location).
[2696]855             ELSE
856                CALL pcm_read_plant_canopy_3d
857             ENDIF
[2007]858
[1484]859          CASE DEFAULT
860!
[2007]861!--          The DEFAULT case is reached either if the parameter
862!--          canopy mode contains a wrong character string or if the
863!--          user has coded a special case in the user interface.
864!--          There, the subroutine user_init_plant_canopy checks
865!--          which of these two conditions applies.
866             CALL user_init_plant_canopy
[1484]867 
868       END SELECT
[2696]869!
870!--    Initialize 2D index array indicating canopy top index.
871       ALLOCATE( pch_index_ji(nysg:nyng,nxlg:nxrg) )
872       pch_index_ji = 0
[1484]873
[2696]874       DO  i = nxl, nxr
875          DO  j = nys, nyn
876             DO  k = 0, pch_index
877                IF ( lad_s(k,j,i) /= 0 )  pch_index_ji(j,i) = k
878             ENDDO
[1484]879!
[2696]880!--          Check whether topography and local vegetation on top exceed
881!--          height of the model domain.
[2698]882             k = get_topography_top_index_ji( j, i, 's' )
[2696]883             IF ( k + pch_index_ji(j,i) >= nzt + 1 )  THEN
884                message_string =  'Local vegetation height on top of ' //      &
885                                  'topography exceeds height of model domain.'
886                CALL message( 'pcm_init', 'PA0999', 2, 2, 0, 6, 0 )
887             ENDIF
888
889          ENDDO
890       ENDDO
891
892       CALL exchange_horiz_2d_int( pch_index_ji, nys, nyn, nxl, nxr, nbgp )
893
894!
[2011]895!--    Initialization of the canopy heat source distribution due to heating
896!--    of the canopy layers by incoming solar radiation, in case that a non-zero
897!--    value is set for the canopy top heat flux (cthf), which equals the
898!--    available net radiation at canopy top.
899!--    The heat source distribution is calculated by a decaying exponential
900!--    function of the downward cumulative leaf area index (cum_lai_hf),
901!--    assuming that the foliage inside the plant canopy is heated by solar
902!--    radiation penetrating the canopy layers according to the distribution
903!--    of net radiation as suggested by Brown & Covey (1966; Agric. Meteorol. 3,
904!--    73–96). This approach has been applied e.g. by Shaw & Schumann (1992;
[2213]905!--    Bound.-Layer Meteorol. 61, 47–64).
906!--    When using the urban surface model (USM), canopy heating (pc_heating_rate)
907!--    by radiation is calculated in the USM.
[2768]908       IF ( cthf /= 0.0_wp  .AND. .NOT.  urban_surface )  THEN
[2213]909
910          ALLOCATE( cum_lai_hf(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                 &
[3022]911                    pc_heating_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1484]912!
[2011]913!--       Piecewise calculation of the cumulative leaf area index by vertical
[1484]914!--       integration of the leaf area density
915          cum_lai_hf(:,:,:) = 0.0_wp
916          DO  i = nxlg, nxrg
917             DO  j = nysg, nyng
[2696]918                DO  k = pch_index_ji(j,i)-1, 0, -1
919                   IF ( k == pch_index_ji(j,i)-1 )  THEN
[1484]920                      cum_lai_hf(k,j,i) = cum_lai_hf(k+1,j,i) +                &
921                         ( 0.5_wp * lad_s(k+1,j,i) *                           &
922                           ( zw(k+1) - zu(k+1) ) )  +                          &
923                         ( 0.5_wp * ( 0.5_wp * ( lad_s(k+1,j,i) +              &
924                                                 lad_s(k,j,i) ) +              &
925                                      lad_s(k+1,j,i) ) *                       &
926                           ( zu(k+1) - zw(k) ) ) 
927                   ELSE
928                      cum_lai_hf(k,j,i) = cum_lai_hf(k+1,j,i) +                &
929                         ( 0.5_wp * ( 0.5_wp * ( lad_s(k+2,j,i) +              &
930                                                 lad_s(k+1,j,i) ) +            &
931                                      lad_s(k+1,j,i) ) *                       &
932                           ( zw(k+1) - zu(k+1) ) )  +                          &
933                         ( 0.5_wp * ( 0.5_wp * ( lad_s(k+1,j,i) +              &
934                                                 lad_s(k,j,i) ) +              &
935                                      lad_s(k+1,j,i) ) *                       &
936                           ( zu(k+1) - zw(k) ) )
937                   ENDIF
938                ENDDO
939             ENDDO
940          ENDDO
941
[2232]942!           
943!--       In areas with canopy the surface value of the canopy heat
944!--       flux distribution overrides the surface heat flux (shf)
945!--       Start with default surface type
946          DO  m = 1, surf_def_h(0)%ns
947             k = surf_def_h(0)%k(m)
948             IF ( cum_lai_hf(0,j,i) /= 0.0_wp )                                &
949                surf_def_h(0)%shf(m) = cthf * exp( -ext_coef * cum_lai_hf(0,j,i) )
950          ENDDO
[1484]951!
[2232]952!--       Natural surfaces
953          DO  m = 1, surf_lsm_h%ns
954             k = surf_lsm_h%k(m)
955             IF ( cum_lai_hf(0,j,i) /= 0.0_wp )                                &
956                surf_lsm_h%shf(m) = cthf * exp( -ext_coef * cum_lai_hf(0,j,i) )
957          ENDDO
958!
959!--       Urban surfaces
960          DO  m = 1, surf_usm_h%ns
961             k = surf_usm_h%k(m)
962             IF ( cum_lai_hf(0,j,i) /= 0.0_wp )                                &
963                surf_usm_h%shf(m) = cthf * exp( -ext_coef * cum_lai_hf(0,j,i) )
964          ENDDO
965!
966!
[2011]967!--       Calculation of the heating rate (K/s) within the different layers of
[2232]968!--       the plant canopy. Calculation is only necessary in areas covered with
969!--       canopy.
970!--       Within the different canopy layers the plant-canopy heating
971!--       rate (pc_heating_rate) is calculated as the vertical
972!--       divergence of the canopy heat fluxes at the top and bottom
973!--       of the respective layer
[1484]974          DO  i = nxlg, nxrg
975             DO  j = nysg, nyng
[2696]976                DO  k = 1, pch_index_ji(j,i)
[2232]977                   IF ( cum_lai_hf(0,j,i) /= 0.0_wp )  THEN
[3022]978                      pc_heating_rate(k,j,i) = cthf *                          &
979                                ( exp(-ext_coef*cum_lai_hf(k,j,i)) -           &
[2232]980                                  exp(-ext_coef*cum_lai_hf(k-1,j,i) ) ) / dzw(k)
981                   ENDIF
982                ENDDO
[1721]983             ENDDO
984          ENDDO
[1484]985
986       ENDIF
[3022]987!
988!--    Allocate transpiration rate
989       IF ( humidity )                                                         &
990          ALLOCATE( pc_transpiration_rate(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1484]991
992
993
[1826]994    END SUBROUTINE pcm_init
[1484]995
996
[2007]997!------------------------------------------------------------------------------!
998! Description:
999! ------------
[2932]1000!> Parin for &plant_canopy_parameters for plant canopy model
[2007]1001!------------------------------------------------------------------------------!
1002    SUBROUTINE pcm_parin
[1484]1003
[2746]1004       USE control_parameters,                                                 &
[2932]1005           ONLY:  message_string, plant_canopy
[2007]1006
1007       IMPLICIT NONE
1008
1009       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current line of the parameter file
1010       
[2932]1011       NAMELIST /plant_canopy_parameters/                                      &
1012                                  alpha_lad, beta_lad, canopy_drag_coeff,      &
1013                                  canopy_mode, cthf,                           &
[2977]1014                                  lad_surface, lad_type_coef,                  & 
[2932]1015                                  lad_vertical_gradient,                       &
1016                                  lad_vertical_gradient_level,                 &
1017                                  lai_beta,                                    &
1018                                  leaf_scalar_exch_coeff,                      &
1019                                  leaf_surface_conc, pch_index
1020
[2007]1021       NAMELIST /canopy_par/      alpha_lad, beta_lad, canopy_drag_coeff,      &
1022                                  canopy_mode, cthf,                           &
[2977]1023                                  lad_surface, lad_type_coef,                  & 
[2007]1024                                  lad_vertical_gradient,                       &
1025                                  lad_vertical_gradient_level,                 &
1026                                  lai_beta,                                    &
1027                                  leaf_scalar_exch_coeff,                      &
1028                                  leaf_surface_conc, pch_index
[3246]1029
[2007]1030       line = ' '
[3246]1031
[2007]1032!
1033!--    Try to find radiation model package
1034       REWIND ( 11 )
1035       line = ' '
[3248]1036       DO WHILE ( INDEX( line, '&plant_canopy_parameters' ) == 0 )
[3246]1037          READ ( 11, '(A)', END=12 )  line
[2007]1038       ENDDO
1039       BACKSPACE ( 11 )
1040
1041!
1042!--    Read user-defined namelist
[3246]1043       READ ( 11, plant_canopy_parameters, ERR = 10 )
[2932]1044
1045!
1046!--    Set flag that indicates that the radiation model is switched on
1047       plant_canopy = .TRUE.
[3246]1048
1049       GOTO 14
1050
1051 10    BACKSPACE( 11 )
[3248]1052       READ( 11 , '(A)') line
1053       CALL parin_fail_message( 'plant_canopy_parameters', line )
[2932]1054!
1055!--    Try to find old namelist
[3246]1056 12    REWIND ( 11 )
[2932]1057       line = ' '
[3248]1058       DO WHILE ( INDEX( line, '&canopy_par' ) == 0 )
[3246]1059          READ ( 11, '(A)', END=14 )  line
[2932]1060       ENDDO
1061       BACKSPACE ( 11 )
1062
1063!
1064!--    Read user-defined namelist
[3246]1065       READ ( 11, canopy_par, ERR = 13, END = 14 )
[2007]1066
[2932]1067       message_string = 'namelist canopy_par is deprecated and will be ' // &
[3046]1068                     'removed in near future. Please use namelist ' //      &
[2932]1069                     'plant_canopy_parameters instead'
1070       CALL message( 'pcm_parin', 'PA0487', 0, 1, 0, 6, 0 )
[3246]1071
[2007]1072!
1073!--    Set flag that indicates that the radiation model is switched on
1074       plant_canopy = .TRUE.
1075
[3246]1076       GOTO 14
[2007]1077
[3246]1078 13    BACKSPACE( 11 )
[3248]1079       READ( 11 , '(A)') line
1080       CALL parin_fail_message( 'canopy_par', line )
[3246]1081
1082 14    CONTINUE
1083
1084
[2007]1085    END SUBROUTINE pcm_parin
1086
1087
1088
[1484]1089!------------------------------------------------------------------------------!
1090! Description:
1091! ------------
[2007]1092!
1093!> Loads 3D plant canopy data from file. File format is as follows:
1094!>
1095!> num_levels
[2977]1096!> dtype,x,y,pctype,value(nzb),value(nzb+1), ... ,value(nzb+num_levels-1)
1097!> dtype,x,y,pctype,value(nzb),value(nzb+1), ... ,value(nzb+num_levels-1)
1098!> dtype,x,y,pctype,value(nzb),value(nzb+1), ... ,value(nzb+num_levels-1)
[2007]1099!> ...
1100!>
1101!> i.e. first line determines number of levels and further lines represent plant
1102!> canopy data, one line per column and variable. In each data line,
1103!> dtype represents variable to be set:
1104!>
1105!> dtype=1: leaf area density (lad_s)
[2213]1106!> dtype=2....n: some additional plant canopy input data quantity
[2007]1107!>
1108!> Zeros are added automatically above num_levels until top of domain.  Any
1109!> non-specified (x,y) columns have zero values as default.
1110!------------------------------------------------------------------------------!
1111    SUBROUTINE pcm_read_plant_canopy_3d
[2213]1112   
1113       USE control_parameters,                                                 &
[3241]1114           ONLY:  coupling_char, message_string
[2007]1115
[2213]1116       USE indices,                                                            &
1117           ONLY:  nbgp
1118           
1119       IMPLICIT NONE
[2007]1120
[2213]1121       INTEGER(iwp)                        ::  dtype     !< type of input data (1=lad)
[2977]1122       INTEGER(iwp)                        ::  pctype    !< type of plant canopy (deciduous,non-deciduous,...)
[2213]1123       INTEGER(iwp)                        ::  i, j      !< running index
1124       INTEGER(iwp)                        ::  nzp       !< number of vertical layers of plant canopy
1125       
1126       REAL(wp), DIMENSION(:), ALLOCATABLE ::  col   !< vertical column of input data
[2007]1127
[2213]1128!
1129!--    Initialize lad_s array
1130       lad_s = 0.0_wp
1131       
1132!
1133!--    Open and read plant canopy input data
[2977]1134       OPEN(152, FILE='PLANT_CANOPY_DATA_3D' // TRIM( coupling_char ),         &
1135                 ACCESS='SEQUENTIAL', ACTION='READ', STATUS='OLD',             &
1136                 FORM='FORMATTED', ERR=515)
1137       READ(152, *, ERR=516, END=517)  nzp   !< read first line = number of vertical layers
[2213]1138       
[2977]1139       ALLOCATE( col(0:nzp-1) )
[2007]1140
[2213]1141       DO
[2977]1142          READ(152, *, ERR=516, END=517) dtype, i, j, pctype, col(:)
1143          IF ( i < nxlg  .OR.  i > nxrg  .OR.  j < nysg  .OR.  j > nyng )  CYCLE
1144         
1145          SELECT CASE (dtype)
1146             CASE( 1 )   !< leaf area density
[2213]1147!
[2977]1148!--             This is just the pure canopy layer assumed to be grounded to
1149!--             a flat domain surface. At locations where plant canopy sits
1150!--             on top of any kind of topography, the vertical plant column
1151!--             must be "lifted", which is done in SUBROUTINE pcm_tendency.           
1152                IF ( pctype < 0  .OR.  pctype > 10 )  THEN   !< incorrect plant canopy type
1153                   WRITE( message_string, * ) 'Incorrect type of plant canopy. '   //  &
1154                                              'Allowed values 0 <= pctype <= 10, ' //  &
1155                                              'but pctype is ', pctype
1156                   CALL message( 'pcm_read_plant_canopy_3d', 'PA0349', 1, 2, 0, 6, 0 )
1157                ENDIF
1158                lad_s(0:nzp-1,j,i) = col(0:nzp-1) * lad_type_coef(pctype)
1159               
1160             CASE DEFAULT
1161                WRITE(message_string, '(a,i2,a)')   &
1162                     'Unknown record type in file PLANT_CANOPY_DATA_3D: "', dtype, '"'
1163                CALL message( 'pcm_read_plant_canopy_3d', 'PA0530', 1, 2, 0, 6, 0 )
1164          END SELECT
[2213]1165       ENDDO
[2007]1166
[2213]1167515    message_string = 'error opening file PLANT_CANOPY_DATA_3D'
1168       CALL message( 'pcm_read_plant_canopy_3d', 'PA0531', 1, 2, 0, 6, 0 )
[2007]1169
[2213]1170516    message_string = 'error reading file PLANT_CANOPY_DATA_3D'
1171       CALL message( 'pcm_read_plant_canopy_3d', 'PA0532', 1, 2, 0, 6, 0 )
1172
1173517    CLOSE(152)
[2977]1174       DEALLOCATE( col )
[2213]1175       
1176       CALL exchange_horiz( lad_s, nbgp )
[2007]1177       
1178    END SUBROUTINE pcm_read_plant_canopy_3d
1179   
1180   
1181
1182!------------------------------------------------------------------------------!
1183! Description:
1184! ------------
[1682]1185!> Calculation of the tendency terms, accounting for the effect of the plant
1186!> canopy on momentum and scalar quantities.
1187!>
1188!> The canopy is located where the leaf area density lad_s(k,j,i) > 0.0
[1826]1189!> (defined on scalar grid), as initialized in subroutine pcm_init.
[1682]1190!> The lad on the w-grid is vertically interpolated from the surrounding
1191!> lad_s. The upper boundary of the canopy is defined on the w-grid at
1192!> k = pch_index. Here, the lad is zero.
1193!>
1194!> The canopy drag must be limited (previously accounted for by calculation of
1195!> a limiting canopy timestep for the determination of the maximum LES timestep
1196!> in subroutine timestep), since it is physically impossible that the canopy
1197!> drag alone can locally change the sign of a velocity component. This
1198!> limitation is realized by calculating preliminary tendencies and velocities.
1199!> It is subsequently checked if the preliminary new velocity has a different
1200!> sign than the current velocity. If so, the tendency is limited in a way that
1201!> the velocity can at maximum be reduced to zero by the canopy drag.
1202!>
1203!>
1204!> Call for all grid points
[1484]1205!------------------------------------------------------------------------------!
[1826]1206    SUBROUTINE pcm_tendency( component )
[138]1207
1208
[1320]1209       USE control_parameters,                                                 &
[1484]1210           ONLY:  dt_3d, message_string
[1320]1211
1212       USE kinds
1213
[138]1214       IMPLICIT NONE
1215
[1682]1216       INTEGER(iwp) ::  component !< prognostic variable (u,v,w,pt,q,e)
1217       INTEGER(iwp) ::  i         !< running index
1218       INTEGER(iwp) ::  j         !< running index
1219       INTEGER(iwp) ::  k         !< running index
[2232]1220       INTEGER(iwp) ::  k_wall    !< vertical index of topography top
[1721]1221       INTEGER(iwp) ::  kk        !< running index for flat lad arrays
[1484]1222
[1682]1223       REAL(wp) ::  ddt_3d    !< inverse of the LES timestep (dt_3d)
1224       REAL(wp) ::  lad_local !< local lad value
1225       REAL(wp) ::  pre_tend  !< preliminary tendency
1226       REAL(wp) ::  pre_u     !< preliminary u-value
1227       REAL(wp) ::  pre_v     !< preliminary v-value
1228       REAL(wp) ::  pre_w     !< preliminary w-value
[1484]1229
1230
1231       ddt_3d = 1.0_wp / dt_3d
[138]1232 
1233!
[1484]1234!--    Compute drag for the three velocity components and the SGS-TKE:
[138]1235       SELECT CASE ( component )
1236
1237!
1238!--       u-component
1239          CASE ( 1 )
1240             DO  i = nxlu, nxr
1241                DO  j = nys, nyn
[2232]1242!
1243!--                Determine topography-top index on u-grid
[2698]1244                   k_wall = get_topography_top_index_ji( j, i, 'u' )
[2696]1245                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[1484]1246
[2232]1247                      kk = k - k_wall   !- lad arrays are defined flat
[1484]1248!
1249!--                   In order to create sharp boundaries of the plant canopy,
1250!--                   the lad on the u-grid at index (k,j,i) is equal to
1251!--                   lad_s(k,j,i), rather than being interpolated from the
1252!--                   surrounding lad_s, because this would yield smaller lad
1253!--                   at the canopy boundaries than inside of the canopy.
1254!--                   For the same reason, the lad at the rightmost(i+1)canopy
1255!--                   boundary on the u-grid equals lad_s(k,j,i).
[1721]1256                      lad_local = lad_s(kk,j,i)
1257                      IF ( lad_local == 0.0_wp .AND. lad_s(kk,j,i-1) > 0.0_wp )&
1258                      THEN
1259                         lad_local = lad_s(kk,j,i-1)
[1484]1260                      ENDIF
1261
1262                      pre_tend = 0.0_wp
1263                      pre_u = 0.0_wp
1264!
1265!--                   Calculate preliminary value (pre_tend) of the tendency
1266                      pre_tend = - cdc *                                       &
1267                                   lad_local *                                 &
1268                                   SQRT( u(k,j,i)**2 +                         &
1269                                         ( 0.25_wp * ( v(k,j,i-1) +            &
1270                                                       v(k,j,i)   +            &
1271                                                       v(k,j+1,i) +            &
1272                                                       v(k,j+1,i-1) )          &
1273                                         )**2 +                                &
1274                                         ( 0.25_wp * ( w(k-1,j,i-1) +          &
1275                                                       w(k-1,j,i)   +          &
1276                                                       w(k,j,i-1)   +          &
1277                                                       w(k,j,i) )              &
1278                                         )**2                                  &
1279                                       ) *                                     &
1280                                   u(k,j,i)
1281
1282!
1283!--                   Calculate preliminary new velocity, based on pre_tend
1284                      pre_u = u(k,j,i) + dt_3d * pre_tend
1285!
1286!--                   Compare sign of old velocity and new preliminary velocity,
1287!--                   and in case the signs are different, limit the tendency
1288                      IF ( SIGN(pre_u,u(k,j,i)) /= pre_u )  THEN
1289                         pre_tend = - u(k,j,i) * ddt_3d
1290                      ELSE
1291                         pre_tend = pre_tend
1292                      ENDIF
1293!
1294!--                   Calculate final tendency
1295                      tend(k,j,i) = tend(k,j,i) + pre_tend
1296
[138]1297                   ENDDO
1298                ENDDO
1299             ENDDO
1300
1301!
1302!--       v-component
1303          CASE ( 2 )
1304             DO  i = nxl, nxr
1305                DO  j = nysv, nyn
[2232]1306!
1307!--                Determine topography-top index on v-grid
[2698]1308                   k_wall = get_topography_top_index_ji( j, i, 'v' )
[2317]1309
[2696]1310                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[1484]1311
[2232]1312                      kk = k - k_wall   !- lad arrays are defined flat
[1484]1313!
1314!--                   In order to create sharp boundaries of the plant canopy,
1315!--                   the lad on the v-grid at index (k,j,i) is equal to
1316!--                   lad_s(k,j,i), rather than being interpolated from the
1317!--                   surrounding lad_s, because this would yield smaller lad
1318!--                   at the canopy boundaries than inside of the canopy.
1319!--                   For the same reason, the lad at the northmost(j+1) canopy
1320!--                   boundary on the v-grid equals lad_s(k,j,i).
[1721]1321                      lad_local = lad_s(kk,j,i)
1322                      IF ( lad_local == 0.0_wp .AND. lad_s(kk,j-1,i) > 0.0_wp )&
1323                      THEN
1324                         lad_local = lad_s(kk,j-1,i)
[1484]1325                      ENDIF
1326
1327                      pre_tend = 0.0_wp
1328                      pre_v = 0.0_wp
1329!
1330!--                   Calculate preliminary value (pre_tend) of the tendency
1331                      pre_tend = - cdc *                                       &
1332                                   lad_local *                                 &
1333                                   SQRT( ( 0.25_wp * ( u(k,j-1,i)   +          &
1334                                                       u(k,j-1,i+1) +          &
1335                                                       u(k,j,i)     +          &
1336                                                       u(k,j,i+1) )            &
1337                                         )**2 +                                &
1338                                         v(k,j,i)**2 +                         &
1339                                         ( 0.25_wp * ( w(k-1,j-1,i) +          &
1340                                                       w(k-1,j,i)   +          &
1341                                                       w(k,j-1,i)   +          &
1342                                                       w(k,j,i) )              &
1343                                         )**2                                  &
1344                                       ) *                                     &
1345                                   v(k,j,i)
1346
1347!
1348!--                   Calculate preliminary new velocity, based on pre_tend
1349                      pre_v = v(k,j,i) + dt_3d * pre_tend
1350!
1351!--                   Compare sign of old velocity and new preliminary velocity,
1352!--                   and in case the signs are different, limit the tendency
1353                      IF ( SIGN(pre_v,v(k,j,i)) /= pre_v )  THEN
1354                         pre_tend = - v(k,j,i) * ddt_3d
1355                      ELSE
1356                         pre_tend = pre_tend
1357                      ENDIF
1358!
1359!--                   Calculate final tendency
1360                      tend(k,j,i) = tend(k,j,i) + pre_tend
1361
[138]1362                   ENDDO
1363                ENDDO
1364             ENDDO
1365
1366!
1367!--       w-component
1368          CASE ( 3 )
1369             DO  i = nxl, nxr
1370                DO  j = nys, nyn
[2232]1371!
1372!--                Determine topography-top index on w-grid
[2698]1373                   k_wall = get_topography_top_index_ji( j, i, 'w' )
[2317]1374
[2696]1375                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i) - 1
[1484]1376
[2232]1377                      kk = k - k_wall   !- lad arrays are defined flat
[1721]1378
[1484]1379                      pre_tend = 0.0_wp
1380                      pre_w = 0.0_wp
1381!
1382!--                   Calculate preliminary value (pre_tend) of the tendency
1383                      pre_tend = - cdc *                                       &
1384                                   (0.5_wp *                                   &
[1721]1385                                      ( lad_s(kk+1,j,i) + lad_s(kk,j,i) )) *   &
[1484]1386                                   SQRT( ( 0.25_wp * ( u(k,j,i)   +            &
1387                                                       u(k,j,i+1) +            &
1388                                                       u(k+1,j,i) +            &
1389                                                       u(k+1,j,i+1) )          &
1390                                         )**2 +                                &
1391                                         ( 0.25_wp * ( v(k,j,i)   +            &
1392                                                       v(k,j+1,i) +            &
1393                                                       v(k+1,j,i) +            &
1394                                                       v(k+1,j+1,i) )          &
1395                                         )**2 +                                &
1396                                         w(k,j,i)**2                           &
1397                                       ) *                                     &
1398                                   w(k,j,i)
1399!
1400!--                   Calculate preliminary new velocity, based on pre_tend
1401                      pre_w = w(k,j,i) + dt_3d * pre_tend
1402!
1403!--                   Compare sign of old velocity and new preliminary velocity,
1404!--                   and in case the signs are different, limit the tendency
1405                      IF ( SIGN(pre_w,w(k,j,i)) /= pre_w )  THEN
1406                         pre_tend = - w(k,j,i) * ddt_3d
1407                      ELSE
1408                         pre_tend = pre_tend
1409                      ENDIF
1410!
1411!--                   Calculate final tendency
1412                      tend(k,j,i) = tend(k,j,i) + pre_tend
1413
[138]1414                   ENDDO
1415                ENDDO
1416             ENDDO
1417
1418!
[153]1419!--       potential temperature
[138]1420          CASE ( 4 )
1421             DO  i = nxl, nxr
1422                DO  j = nys, nyn
[2232]1423!
1424!--                Determine topography-top index on scalar-grid
[2698]1425                   k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1426
[2696]1427                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[2232]1428
1429                      kk = k - k_wall   !- lad arrays are defined flat
[2011]1430                      tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
[153]1431                   ENDDO
1432                ENDDO
1433             ENDDO
1434
1435!
[1960]1436!--       humidity
[153]1437          CASE ( 5 )
1438             DO  i = nxl, nxr
1439                DO  j = nys, nyn
[2232]1440!
1441!--                Determine topography-top index on scalar-grid
[2698]1442                   k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1443
[2696]1444                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[2232]1445
1446                      kk = k - k_wall   !- lad arrays are defined flat
[3014]1447                      pc_transpiration_rate(kk,j,i) =  - lsec                  &
1448                                       * lad_s(kk,j,i) *                       &
[1484]1449                                       SQRT( ( 0.5_wp * ( u(k,j,i) +           &
1450                                                          u(k,j,i+1) )         &
1451                                             )**2 +                            &
1452                                             ( 0.5_wp * ( v(k,j,i) +           &
1453                                                          v(k,j+1,i) )         &
1454                                             )**2 +                            &
1455                                             ( 0.5_wp * ( w(k-1,j,i) +         & 
1456                                                          w(k,j,i) )           &
1457                                             )**2                              &
1458                                           ) *                                 &
1459                                       ( q(k,j,i) - lsc )
[3014]1460
1461                      tend(k,j,i) = tend(k,j,i) + pc_transpiration_rate(kk,j,i)
[153]1462                   ENDDO
1463                ENDDO
1464             ENDDO
1465
1466!
1467!--       sgs-tke
1468          CASE ( 6 )
1469             DO  i = nxl, nxr
1470                DO  j = nys, nyn
[2232]1471!
1472!--                Determine topography-top index on scalar-grid
[2698]1473                   k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1474
[2696]1475                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[2232]1476
1477                      kk = k - k_wall   !- lad arrays are defined flat
[1484]1478                      tend(k,j,i) = tend(k,j,i) -                              &
1479                                       2.0_wp * cdc *                          &
[1721]1480                                       lad_s(kk,j,i) *                         &
[1484]1481                                       SQRT( ( 0.5_wp * ( u(k,j,i) +           &
1482                                                          u(k,j,i+1) )         &
1483                                             )**2 +                            &
1484                                             ( 0.5_wp * ( v(k,j,i) +           &
1485                                                          v(k,j+1,i) )         &
1486                                             )**2 +                            &
1487                                             ( 0.5_wp * ( w(k,j,i) +           &
1488                                                          w(k+1,j,i) )         &
1489                                             )**2                              &
1490                                           ) *                                 &
1491                                       e(k,j,i)
[138]1492                   ENDDO
1493                ENDDO
1494             ENDDO 
[1960]1495!
1496!--       scalar concentration
1497          CASE ( 7 )
1498             DO  i = nxl, nxr
1499                DO  j = nys, nyn
[2232]1500!
1501!--                Determine topography-top index on scalar-grid
[2698]1502                   k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1503
[2696]1504                   DO  k = k_wall+1, k_wall + pch_index_ji(j,i)
[2232]1505
1506                      kk = k - k_wall   !- lad arrays are defined flat
[1960]1507                      tend(k,j,i) = tend(k,j,i) -                              &
1508                                       lsec *                                  &
1509                                       lad_s(kk,j,i) *                         &
1510                                       SQRT( ( 0.5_wp * ( u(k,j,i) +           &
1511                                                          u(k,j,i+1) )         &
1512                                             )**2 +                            &
1513                                             ( 0.5_wp * ( v(k,j,i) +           &
1514                                                          v(k,j+1,i) )         &
1515                                             )**2 +                            &
1516                                             ( 0.5_wp * ( w(k-1,j,i) +         & 
1517                                                          w(k,j,i) )           &
1518                                             )**2                              &
1519                                           ) *                                 &
1520                                       ( s(k,j,i) - lsc )
1521                   ENDDO
1522                ENDDO
1523             ENDDO   
[1484]1524
1525
[1960]1526
[138]1527          CASE DEFAULT
1528
[257]1529             WRITE( message_string, * ) 'wrong component: ', component
[1826]1530             CALL message( 'pcm_tendency', 'PA0279', 1, 2, 0, 6, 0 ) 
[138]1531
1532       END SELECT
1533
[1826]1534    END SUBROUTINE pcm_tendency
[138]1535
1536
1537!------------------------------------------------------------------------------!
[1484]1538! Description:
1539! ------------
[1682]1540!> Calculation of the tendency terms, accounting for the effect of the plant
1541!> canopy on momentum and scalar quantities.
1542!>
1543!> The canopy is located where the leaf area density lad_s(k,j,i) > 0.0
[1826]1544!> (defined on scalar grid), as initialized in subroutine pcm_init.
[1682]1545!> The lad on the w-grid is vertically interpolated from the surrounding
1546!> lad_s. The upper boundary of the canopy is defined on the w-grid at
1547!> k = pch_index. Here, the lad is zero.
1548!>
1549!> The canopy drag must be limited (previously accounted for by calculation of
1550!> a limiting canopy timestep for the determination of the maximum LES timestep
1551!> in subroutine timestep), since it is physically impossible that the canopy
1552!> drag alone can locally change the sign of a velocity component. This
1553!> limitation is realized by calculating preliminary tendencies and velocities.
1554!> It is subsequently checked if the preliminary new velocity has a different
1555!> sign than the current velocity. If so, the tendency is limited in a way that
1556!> the velocity can at maximum be reduced to zero by the canopy drag.
1557!>
1558!>
1559!> Call for grid point i,j
[138]1560!------------------------------------------------------------------------------!
[1826]1561    SUBROUTINE pcm_tendency_ij( i, j, component )
[138]1562
1563
[1320]1564       USE control_parameters,                                                 &
[1484]1565           ONLY:  dt_3d, message_string
[1320]1566
1567       USE kinds
1568
[138]1569       IMPLICIT NONE
1570
[1682]1571       INTEGER(iwp) ::  component !< prognostic variable (u,v,w,pt,q,e)
1572       INTEGER(iwp) ::  i         !< running index
1573       INTEGER(iwp) ::  j         !< running index
1574       INTEGER(iwp) ::  k         !< running index
[2232]1575       INTEGER(iwp) ::  k_wall    !< vertical index of topography top
[1721]1576       INTEGER(iwp) ::  kk        !< running index for flat lad arrays
[138]1577
[1682]1578       REAL(wp) ::  ddt_3d    !< inverse of the LES timestep (dt_3d)
1579       REAL(wp) ::  lad_local !< local lad value
1580       REAL(wp) ::  pre_tend  !< preliminary tendency
1581       REAL(wp) ::  pre_u     !< preliminary u-value
1582       REAL(wp) ::  pre_v     !< preliminary v-value
1583       REAL(wp) ::  pre_w     !< preliminary w-value
[1484]1584
1585
1586       ddt_3d = 1.0_wp / dt_3d
[138]1587!
[1484]1588!--    Compute drag for the three velocity components and the SGS-TKE
[142]1589       SELECT CASE ( component )
[138]1590
1591!
[142]1592!--       u-component
[1484]1593          CASE ( 1 )
[2232]1594!
1595!--          Determine topography-top index on u-grid
[2698]1596             k_wall = get_topography_top_index_ji( j, i, 'u' )
[2696]1597             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[2317]1598
[2696]1599                kk = k - k_wall  !- lad arrays are defined flat
[138]1600
1601!
[1484]1602!--             In order to create sharp boundaries of the plant canopy,
1603!--             the lad on the u-grid at index (k,j,i) is equal to lad_s(k,j,i),
1604!--             rather than being interpolated from the surrounding lad_s,
1605!--             because this would yield smaller lad at the canopy boundaries
1606!--             than inside of the canopy.
1607!--             For the same reason, the lad at the rightmost(i+1)canopy
1608!--             boundary on the u-grid equals lad_s(k,j,i).
[1721]1609                lad_local = lad_s(kk,j,i)
1610                IF ( lad_local == 0.0_wp .AND. lad_s(kk,j,i-1) > 0.0_wp )  THEN
1611                   lad_local = lad_s(kk,j,i-1)
[1484]1612                ENDIF
1613
1614                pre_tend = 0.0_wp
1615                pre_u = 0.0_wp
1616!
1617!--             Calculate preliminary value (pre_tend) of the tendency
1618                pre_tend = - cdc *                                             &
1619                             lad_local *                                       &   
1620                             SQRT( u(k,j,i)**2 +                               &
1621                                   ( 0.25_wp * ( v(k,j,i-1)  +                 &
1622                                                 v(k,j,i)    +                 &
1623                                                 v(k,j+1,i)  +                 &
1624                                                 v(k,j+1,i-1) )                &
1625                                   )**2 +                                      &
1626                                   ( 0.25_wp * ( w(k-1,j,i-1) +                &
1627                                                 w(k-1,j,i)   +                &
1628                                                 w(k,j,i-1)   +                &
1629                                                 w(k,j,i) )                    &
1630                                   )**2                                        &
1631                                 ) *                                           &
1632                             u(k,j,i)
1633
1634!
1635!--             Calculate preliminary new velocity, based on pre_tend
1636                pre_u = u(k,j,i) + dt_3d * pre_tend
1637!
1638!--             Compare sign of old velocity and new preliminary velocity,
1639!--             and in case the signs are different, limit the tendency
1640                IF ( SIGN(pre_u,u(k,j,i)) /= pre_u )  THEN
1641                   pre_tend = - u(k,j,i) * ddt_3d
1642                ELSE
1643                   pre_tend = pre_tend
1644                ENDIF
1645!
1646!--             Calculate final tendency
1647                tend(k,j,i) = tend(k,j,i) + pre_tend
1648             ENDDO
1649
1650
1651!
[142]1652!--       v-component
[1484]1653          CASE ( 2 )
[2232]1654!
1655!--          Determine topography-top index on v-grid
[2698]1656             k_wall = get_topography_top_index_ji( j, i, 'v' )
[2317]1657
[2696]1658             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[138]1659
[2232]1660                kk = k - k_wall  !- lad arrays are defined flat
[138]1661!
[1484]1662!--             In order to create sharp boundaries of the plant canopy,
1663!--             the lad on the v-grid at index (k,j,i) is equal to lad_s(k,j,i),
1664!--             rather than being interpolated from the surrounding lad_s,
1665!--             because this would yield smaller lad at the canopy boundaries
1666!--             than inside of the canopy.
1667!--             For the same reason, the lad at the northmost(j+1)canopy
1668!--             boundary on the v-grid equals lad_s(k,j,i).
[1721]1669                lad_local = lad_s(kk,j,i)
1670                IF ( lad_local == 0.0_wp .AND. lad_s(kk,j-1,i) > 0.0_wp )  THEN
1671                   lad_local = lad_s(kk,j-1,i)
[1484]1672                ENDIF
1673
1674                pre_tend = 0.0_wp
1675                pre_v = 0.0_wp
1676!
1677!--             Calculate preliminary value (pre_tend) of the tendency
1678                pre_tend = - cdc *                                             &
1679                             lad_local *                                       &
1680                             SQRT( ( 0.25_wp * ( u(k,j-1,i)   +                &
1681                                                 u(k,j-1,i+1) +                &
1682                                                 u(k,j,i)     +                &
1683                                                 u(k,j,i+1) )                  &
1684                                   )**2 +                                      &
1685                                   v(k,j,i)**2 +                               &
1686                                   ( 0.25_wp * ( w(k-1,j-1,i) +                &
1687                                                 w(k-1,j,i)   +                &
1688                                                 w(k,j-1,i)   +                &
1689                                                 w(k,j,i) )                    &
1690                                   )**2                                        &
1691                                 ) *                                           &
1692                             v(k,j,i)
1693
1694!
1695!--             Calculate preliminary new velocity, based on pre_tend
1696                pre_v = v(k,j,i) + dt_3d * pre_tend
1697!
1698!--             Compare sign of old velocity and new preliminary velocity,
1699!--             and in case the signs are different, limit the tendency
1700                IF ( SIGN(pre_v,v(k,j,i)) /= pre_v )  THEN
1701                   pre_tend = - v(k,j,i) * ddt_3d
1702                ELSE
1703                   pre_tend = pre_tend
1704                ENDIF
1705!
1706!--             Calculate final tendency
1707                tend(k,j,i) = tend(k,j,i) + pre_tend
1708             ENDDO
1709
1710
1711!
[142]1712!--       w-component
[1484]1713          CASE ( 3 )
[2232]1714!
1715!--          Determine topography-top index on w-grid
[2698]1716             k_wall = get_topography_top_index_ji( j, i, 'w' )
[2317]1717
[2696]1718             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i) - 1
[138]1719
[2232]1720                kk = k - k_wall  !- lad arrays are defined flat
[1721]1721
[1484]1722                pre_tend = 0.0_wp
1723                pre_w = 0.0_wp
[138]1724!
[1484]1725!--             Calculate preliminary value (pre_tend) of the tendency
1726                pre_tend = - cdc *                                             &
1727                             (0.5_wp *                                         &
[1721]1728                                ( lad_s(kk+1,j,i) + lad_s(kk,j,i) )) *         &
[1484]1729                             SQRT( ( 0.25_wp * ( u(k,j,i)    +                 & 
1730                                                 u(k,j,i+1)  +                 &
1731                                                 u(k+1,j,i)  +                 &
1732                                                 u(k+1,j,i+1) )                &
1733                                   )**2 +                                      &
1734                                   ( 0.25_wp * ( v(k,j,i)    +                 &
1735                                                 v(k,j+1,i)  +                 &
1736                                                 v(k+1,j,i)  +                 &
1737                                                 v(k+1,j+1,i) )                &
1738                                   )**2 +                                      &
1739                                   w(k,j,i)**2                                 &
1740                                 ) *                                           &
1741                             w(k,j,i)
1742!
1743!--             Calculate preliminary new velocity, based on pre_tend
1744                pre_w = w(k,j,i) + dt_3d * pre_tend
1745!
1746!--             Compare sign of old velocity and new preliminary velocity,
1747!--             and in case the signs are different, limit the tendency
1748                IF ( SIGN(pre_w,w(k,j,i)) /= pre_w )  THEN
1749                   pre_tend = - w(k,j,i) * ddt_3d
1750                ELSE
1751                   pre_tend = pre_tend
1752                ENDIF
1753!
1754!--             Calculate final tendency
1755                tend(k,j,i) = tend(k,j,i) + pre_tend
1756             ENDDO
1757
1758!
[153]1759!--       potential temperature
1760          CASE ( 4 )
[2232]1761!
1762!--          Determine topography-top index on scalar grid
[2698]1763             k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1764
[2696]1765             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[2232]1766                kk = k - k_wall  !- lad arrays are defined flat
[2011]1767                tend(k,j,i) = tend(k,j,i) + pc_heating_rate(kk,j,i)
[153]1768             ENDDO
1769
1770
1771!
[1960]1772!--       humidity
[153]1773          CASE ( 5 )
[2232]1774!
1775!--          Determine topography-top index on scalar grid
[2698]1776             k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1777
[2696]1778             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[3014]1779                kk = k - k_wall  !- lad arrays are defined flat
[2232]1780
[3014]1781                pc_transpiration_rate(kk,j,i) = - lsec                         &
1782                                 * lad_s(kk,j,i) *                             &
[1484]1783                                 SQRT( ( 0.5_wp * ( u(k,j,i) +                 &
1784                                                    u(k,j,i+1) )               &
1785                                       )**2  +                                 &
1786                                       ( 0.5_wp * ( v(k,j,i) +                 &
1787                                                    v(k,j+1,i) )               &
1788                                       )**2 +                                  &
1789                                       ( 0.5_wp * ( w(k-1,j,i) +               &
1790                                                    w(k,j,i) )                 &
1791                                       )**2                                    &
1792                                     ) *                                       &
1793                                 ( q(k,j,i) - lsc )
[3014]1794
1795                tend(k,j,i) = tend(k,j,i) + pc_transpiration_rate(kk,j,i)
1796
[153]1797             ENDDO   
1798
1799!
[142]1800!--       sgs-tke
[1484]1801          CASE ( 6 )
[2232]1802!
1803!--          Determine topography-top index on scalar grid
[2698]1804             k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1805
[2696]1806             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[2232]1807
1808                kk = k - k_wall
[1484]1809                tend(k,j,i) = tend(k,j,i) -                                    &
1810                                 2.0_wp * cdc *                                &
[1721]1811                                 lad_s(kk,j,i) *                               &
[1484]1812                                 SQRT( ( 0.5_wp * ( u(k,j,i) +                 &
1813                                                    u(k,j,i+1) )               &
1814                                       )**2 +                                  & 
1815                                       ( 0.5_wp * ( v(k,j,i) +                 &
1816                                                    v(k,j+1,i) )               &
1817                                       )**2 +                                  &
1818                                       ( 0.5_wp * ( w(k,j,i) +                 &
1819                                                    w(k+1,j,i) )               &
1820                                       )**2                                    &
1821                                     ) *                                       &
1822                                 e(k,j,i)
1823             ENDDO
[1960]1824             
1825!
1826!--       scalar concentration
1827          CASE ( 7 )
[2232]1828!
1829!--          Determine topography-top index on scalar grid
[2698]1830             k_wall = get_topography_top_index_ji( j, i, 's' )
[2317]1831
[2696]1832             DO  k = k_wall + 1, k_wall + pch_index_ji(j,i)
[2232]1833
1834                kk = k - k_wall
[1960]1835                tend(k,j,i) = tend(k,j,i) -                                    &
1836                                 lsec *                                        &
1837                                 lad_s(kk,j,i) *                               &
1838                                 SQRT( ( 0.5_wp * ( u(k,j,i) +                 &
1839                                                    u(k,j,i+1) )               &
1840                                       )**2  +                                 &
1841                                       ( 0.5_wp * ( v(k,j,i) +                 &
1842                                                    v(k,j+1,i) )               &
1843                                       )**2 +                                  &
1844                                       ( 0.5_wp * ( w(k-1,j,i) +               &
1845                                                    w(k,j,i) )                 &
1846                                       )**2                                    &
1847                                     ) *                                       &
1848                                 ( s(k,j,i) - lsc )
1849             ENDDO               
[138]1850
[142]1851       CASE DEFAULT
[138]1852
[257]1853          WRITE( message_string, * ) 'wrong component: ', component
[1826]1854          CALL message( 'pcm_tendency', 'PA0279', 1, 2, 0, 6, 0 ) 
[138]1855
[142]1856       END SELECT
[138]1857
[1826]1858    END SUBROUTINE pcm_tendency_ij
[138]1859
[2007]1860
1861
[138]1862 END MODULE plant_canopy_model_mod
Note: See TracBrowser for help on using the repository browser.