!> @file surface_layer_fluxes_mod.f90 !------------------------------------------------------------------------------! ! This file is part of the PALM model system. ! ! PALM is free software: you can redistribute it and/or modify it under the ! terms of the GNU General Public License as published by the Free Software ! Foundation, either version 3 of the License, or (at your option) any later ! version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2018 Leibniz Universitaet Hannover ! !------------------------------------------------------------------------------! ! ! Current revisions: ! ------------------ ! ! ! Former revisions: ! ----------------- ! $Id: surface_layer_fluxes_mod.f90 3597 2018-12-04 08:40:18Z eckhard $ ! Added routine for calculating near surface air potential temperature (moved ! from urban_surface_mod) ! ! 3547 2018-11-21 13:21:24Z suehring ! variables documented ! ! 3361 2018-10-16 20:39:37Z knoop ! Modularization of all bulk cloud physics code components ! ! 3271 2018-09-24 08:20:34Z suehring ! Comment revised ! ! 3157 2018-07-19 21:08:49Z maronga ! Added local free convection velocity scale w_lfc in calculation of uvw_abs. ! This can be switche on/off by the user via the flag namelist parameter ! use_free_convection_scaling ! ! 3152 2018-07-19 13:26:52Z suehring ! q_surface is now part of surface structure ! ! 3149 2018-07-19 05:48:09Z maronga ! Correct accidental last commit ! ! 3148 2018-07-19 05:45:25Z maronga ! Major bugfix in calculation of Obukhov length ! ! 3146 2018-07-18 22:36:19Z maronga ! move phi_m from turbulence_closure_mod ! ! 3045 2018-05-28 07:55:41Z Giersch ! Error message revised ! ! 2766 2018-01-22 17:17:47Z kanani ! Removed preprocessor directive __chem ! ! 2718 2018-01-02 08:49:38Z maronga ! Corrected "Former revisions" section ! ! 2696 2017-12-14 17:12:51Z kanani ! - Change in file header (GPL part) ! - Implementation of chemistry module (FK) ! - Added calculation of pt1 and qv1 for all surface types. Added calculation of ! pt_surface for default-type surfaces (BM) ! - Add flag to disable computation of qsws in case of urban surface (MS) ! ! 2547 2017-10-16 12:41:56Z schwenkel ! extended by cloud_droplets option ! ! 2321 2017-07-24 15:57:07Z schwenkel ! Bugfix: Correct index in lookup table for Obukhov length ! ! 2299 2017-06-29 10:14:38Z suehring ! Adjusted for allow separate spinups of LSM and atmosphere code ! ! 2292 2017-06-20 09:51:42Z schwenkel ! Implementation of new microphysic scheme: cloud_scheme = 'morrison' ! includes two more prognostic equations for cloud drop concentration (nc) ! and cloud water content (qc). ! ! 2281 2017-06-13 11:34:50Z suehring ! Clean-up unnecessary index access to surface type ! ! 2233 2017-05-30 18:08:54Z suehring ! ! 2232 2017-05-30 17:47:52Z suehring ! Adjustments to new surface concept ! OpenMP bugfix ! ! 2118 2017-01-17 16:38:49Z raasch ! OpenACC directives and related code removed ! ! 2091 2016-12-21 16:38:18Z suehring ! Bugfix in calculation of vsws ( incorrect linear interpolation of us ) ! ! 2076 2016-12-02 13:54:20Z raasch ! further openmp bugfix for lookup method ! ! 2073 2016-11-30 14:34:05Z raasch ! openmp bugfix for lookup method ! ! 2037 2016-10-26 11:15:40Z knoop ! Anelastic approximation implemented ! ! 2011 2016-09-19 17:29:57Z kanani ! Flag urban_surface is now defined in module control_parameters. ! ! 2007 2016-08-24 15:47:17Z kanani ! Account for urban surface model in computation of vertical kinematic heatflux ! ! 2000 2016-08-20 18:09:15Z knoop ! Forced header and separation lines into 80 columns ! ! 1992 2016-08-12 15:14:59Z suehring ! Minor bug, declaration of look-up index as INTEGER ! ! 1960 2016-07-12 16:34:24Z suehring ! Treat humidity and passive scalar separately ! ! 1929 2016-06-09 16:25:25Z suehring ! Bugfix: avoid segmentation fault in case one grid point is horizontally ! completely surrounded by topography ! ! 1920 2016-05-30 10:50:15Z suehring ! Avoid segmentation fault (see change in 1915) by different initialization of ! us instead of adding a very small number in the denominator ! ! 1915 2016-05-27 11:05:02Z suehring ! Bugfix: avoid segmentation fault in case of most_method = 'circular' at first ! timestep ! ! 1850 2016-04-08 13:29:27Z maronga ! Module renamed ! ! ! 1822 2016-04-07 07:49:42Z hoffmann ! icloud_scheme replaced by microphysics_* ! ! 1788 2016-03-10 11:01:04Z maronga ! Added parameter z0q which replaces z0h in the similarity functions for ! humidity. ! Syntax layout improved. ! ! 1757 2016-02-22 15:49:32Z maronga ! Minor fixes. ! ! 1749 2016-02-09 12:19:56Z raasch ! further OpenACC adjustments ! ! 1747 2016-02-08 12:25:53Z raasch ! adjustments for OpenACC usage ! ! 1709 2015-11-04 14:47:01Z maronga ! Bugfix: division by zero could occur when calculating rib at low wind speeds ! Bugfix: calculation of uv_total for neutral = .T., initial value for ol for ! neutral = .T. ! ! 1705 2015-11-02 14:28:56Z maronga ! Typo removed ! ! 1697 2015-10-28 17:14:10Z raasch ! FORTRAN and OpenMP errors removed ! ! 1696 2015-10-27 10:03:34Z maronga ! Modularized and completely re-written version of prandtl_fluxes.f90. In the ! course of the re-writing two additional methods have been implemented. See ! updated description. ! ! 1551 2015-03-03 14:18:16Z maronga ! Removed land surface model part. The surface fluxes are now always calculated ! within prandtl_fluxes, based on the given surface temperature/humidity (which ! is either provided by the land surface model, by large scale forcing data, or ! directly prescribed by the user. ! ! 1496 2014-12-02 17:25:50Z maronga ! Adapted for land surface model ! ! 1494 2014-11-21 17:14:03Z maronga ! Bugfixes: qs is now calculated before calculation of Rif. calculation of ! buoyancy flux in Rif corrected (added missing humidity term), allow use of ! topography for coupled runs (not tested) ! ! 1361 2014-04-16 15:17:48Z hoffmann ! Bugfix: calculation of turbulent fluxes of rain water content (qrsws) and rain ! drop concentration (nrsws) added ! ! 1340 2014-03-25 19:45:13Z kanani ! REAL constants defined as wp-kind ! ! 1320 2014-03-20 08:40:49Z raasch ! ONLY-attribute added to USE-statements, ! kind-parameters added to all INTEGER and REAL declaration statements, ! kinds are defined in new module kinds, ! old module precision_kind is removed, ! revision history before 2012 removed, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1276 2014-01-15 13:40:41Z heinze ! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars ! ! 1257 2013-11-08 15:18:40Z raasch ! openACC "kernels do" replaced by "kernels loop", "loop independent" added ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! OpenACC statements added ! ! 978 2012-08-09 08:28:32Z fricke ! roughness length for scalar quantities z0h added ! ! Revision 1.1 1998/01/23 10:06:06 raasch ! Initial revision ! ! ! Description: ! ------------ !> Diagnostic computation of vertical fluxes in the constant flux layer from the !> values of the variables at grid point k=1. Three different methods are !> available: !> 1) the "old" version (most_method = 'circular') which is fast, but inaccurate !> 2) a Newton iteration method (most_method = 'newton'), which is accurate, but !> slower !> 3) a method using a lookup table which is fast and accurate. Note, however, !> that this method cannot be used in case of roughness heterogeneity !> !> @todo (re)move large_scale_forcing actions !> @todo check/optimize OpenMP directives !> @todo simplify if conditions (which flux need to be computed in which case) !------------------------------------------------------------------------------! MODULE surface_layer_fluxes_mod USE arrays_3d, & ONLY: e, kh, nc, nr, pt, q, ql, qc, qr, s, u, v, vpt, w, zu, zw, & drho_air_zw, rho_air_zw, d_exner USE basic_constants_and_equations_mod, & ONLY: g, kappa, lv_d_cp, pi, rd_d_rv USE chem_modules, & ONLY: constant_csflux, nvar USE cpulog USE control_parameters, & ONLY: air_chemistry, cloud_droplets, & constant_heatflux, constant_scalarflux, & constant_waterflux, coupling_mode, do_output_at_2m, humidity, & ibc_e_b, ibc_pt_b, indoor_model, initializing_actions, & intermediate_timestep_count, intermediate_timestep_count_max, & land_surface, large_scale_forcing, lsf_surf, message_string, & most_method, neutral, passive_scalar, pt_surface, q_surface, & run_coupled, surface_pressure, simulated_time, terminate_run, & time_since_reference_point, urban_surface, & use_free_convection_scaling, zeta_max, zeta_min USE grid_variables, & ONLY: dx, dy USE indices, & ONLY: nxl, nxr, nys, nyn, nzb USE kinds USE bulk_cloud_model_mod, & ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert USE pegrid USE land_surface_model_mod, & ONLY: aero_resist_kray, skip_time_do_lsm USE surface_mod, & ONLY : surf_def_h, surf_def_v, surf_lsm_h, surf_lsm_v, surf_type, & surf_usm_h, surf_usm_v IMPLICIT NONE INTEGER(iwp) :: i !< loop index x direction INTEGER(iwp) :: j !< loop index y direction INTEGER(iwp) :: k !< loop index z direction INTEGER(iwp) :: l !< loop index for surf type INTEGER(iwp) :: li_bnd = 7500 !< Lookup table index of the last time step INTEGER(iwp), PARAMETER :: num_steps = 15000 !< number of steps in the lookup table LOGICAL :: coupled_run !< Flag for coupled atmosphere-ocean runs LOGICAL :: downward = .FALSE.!< Flag indicating downward-facing horizontal surface LOGICAL :: mom_uv = .FALSE. !< Flag indicating calculation of usvs and vsus at vertical surfaces LOGICAL :: mom_w = .FALSE. !< Flag indicating calculation of wsus and wsvs at vertical surfaces LOGICAL :: mom_tke = .FALSE. !< Flag indicating calculation of momentum fluxes at vertical surfaces used for TKE production LOGICAL :: surf_vertical !< Flag indicating vertical surfaces REAL(wp), DIMENSION(0:num_steps-1) :: rib_tab, & !< Lookup table bulk Richardson number ol_tab !< Lookup table values of L REAL(wp) :: e_s, & !< Saturation water vapor pressure ol_max = 1.0E6_wp, & !< Maximum Obukhov length rib_max, & !< Maximum Richardson number in lookup table rib_min, & !< Minimum Richardson number in lookup table z_mo !< Height of the constant flux layer where MOST is assumed TYPE(surf_type), POINTER :: surf !< surf-type array, used to generalize subroutines SAVE PRIVATE PUBLIC init_surface_layer_fluxes, phi_m, surface_layer_fluxes INTERFACE init_surface_layer_fluxes MODULE PROCEDURE init_surface_layer_fluxes END INTERFACE init_surface_layer_fluxes INTERFACE phi_m MODULE PROCEDURE phi_m END INTERFACE phi_m INTERFACE surface_layer_fluxes MODULE PROCEDURE surface_layer_fluxes END INTERFACE surface_layer_fluxes CONTAINS !------------------------------------------------------------------------------! ! Description: ! ------------ !> Main routine to compute the surface fluxes !------------------------------------------------------------------------------! SUBROUTINE surface_layer_fluxes IMPLICIT NONE surf_vertical = .FALSE. !< flag indicating vertically orientated surface elements downward = .FALSE. !< flag indicating downward-facing surface elements ! !-- Derive potential temperature and specific humidity at first grid level !-- from the fields pt and q ! !-- First call for horizontal default-type surfaces (l=0 - upward facing, !-- l=1 - downward facing) DO l = 0, 1 IF ( surf_def_h(l)%ns >= 1 ) THEN surf => surf_def_h(l) CALL calc_pt_q IF ( .NOT. neutral ) THEN CALL calc_pt_surface IF ( humidity ) THEN CALL calc_q_surface CALL calc_vpt_surface ENDIF ENDIF ENDIF ENDDO ! !-- Call for natural-type horizontal surfaces IF ( surf_lsm_h%ns >= 1 ) THEN surf => surf_lsm_h CALL calc_pt_q ENDIF ! !-- Call for urban-type horizontal surfaces IF ( surf_usm_h%ns >= 1 ) THEN surf => surf_usm_h CALL calc_pt_q ENDIF ! !-- Call for natural-type vertical surfaces DO l = 0, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) CALL calc_pt_q ENDIF !-- Call for urban-type vertical surfaces IF ( surf_usm_v(l)%ns >= 1 ) THEN surf => surf_usm_v(l) CALL calc_pt_q ENDIF ENDDO ! !-- First, calculate the new Obukhov length, then new friction velocity, !-- followed by the new scaling parameters (th*, q*, etc.), and the new !-- surface fluxes if required. The old routine ("circular") requires a !-- different order of calls as the scaling parameters from the previous time !-- steps are used to calculate the Obukhov length ! !-- Depending on setting of most_method use the "old" routine !-- Note, each routine is called for different surface types. !-- First call for default-type horizontal surfaces, for natural- and !-- urban-type surfaces. Note, at this place only upward-facing horizontal !-- surfaces are treted. IF ( most_method == 'circular' ) THEN ! !-- Default-type upward-facing horizontal surfaces IF ( surf_def_h(0)%ns >= 1 ) THEN surf => surf_def_h(0) CALL calc_scaling_parameters CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF ENDIF ! !-- Natural-type horizontal surfaces IF ( surf_lsm_h%ns >= 1 ) THEN surf => surf_lsm_h CALL calc_scaling_parameters CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF ENDIF ! !-- Urban-type horizontal surfaces IF ( surf_usm_h%ns >= 1 ) THEN surf => surf_usm_h CALL calc_scaling_parameters CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF IF ( indoor_model ) THEN CALL calc_pt_near_surface ( '10cm' ) ENDIF ENDIF ! !-- Use either Newton iteration or a lookup table for the bulk Richardson !-- number to calculate the Obukhov length ELSEIF ( most_method == 'newton' .OR. most_method == 'lookup' ) THEN ! !-- Default-type upward-facing horizontal surfaces IF ( surf_def_h(0)%ns >= 1 ) THEN surf => surf_def_h(0) CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_scaling_parameters CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF ENDIF ! !-- Natural-type horizontal surfaces IF ( surf_lsm_h%ns >= 1 ) THEN surf => surf_lsm_h CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_scaling_parameters CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF ENDIF ! !-- Urban-type horizontal surfaces IF ( surf_usm_h%ns >= 1 ) THEN surf => surf_usm_h CALL calc_uvw_abs IF ( .NOT. neutral ) CALL calc_ol CALL calc_us CALL calc_scaling_parameters CALL calc_surface_fluxes IF ( do_output_at_2m ) THEN CALL calc_pt_near_surface ( '2m' ) ENDIF IF ( indoor_model ) THEN CALL calc_pt_near_surface ( '10cm' ) ENDIF ENDIF ENDIF ! !-- Treat downward-facing horizontal surfaces. Note, so far, these are !-- always default type. Stratification is not considered !-- in this case, hence, no further distinction between different !-- most_method is required. IF ( surf_def_h(1)%ns >= 1 ) THEN downward = .TRUE. surf => surf_def_h(1) CALL calc_uvw_abs CALL calc_us CALL calc_surface_fluxes downward = .FALSE. ENDIF ! !-- Calculate surfaces fluxes at vertical surfaces for momentum !-- and subgrid-scale TKE. !-- No stability is considered. Therefore, scaling parameters and Obukhov- !-- length do not need to be calculated and no distinction in 'circular', !-- 'Newton' or 'lookup' is necessary so far. !-- Note, this will change if stability is once considered. surf_vertical = .TRUE. ! !-- Calculate horizontal momentum fluxes at north- and south-facing !-- surfaces(usvs). !-- For default-type surfaces mom_uv = .TRUE. DO l = 0, 1 IF ( surf_def_v(l)%ns >= 1 ) THEN surf => surf_def_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_ugrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ! !-- For natural-type surfaces. Please note, even though stability is not !-- considered for the calculation of momentum fluxes at vertical surfaces, !-- scaling parameters and Obukov length are calculated nevertheless in this !-- case. This is due to the requirement of ts in parameterization of heat !-- flux in land-surface model in case of aero_resist_kray is not true. IF ( .NOT. aero_resist_kray ) THEN IF ( most_method == 'circular' ) THEN DO l = 0, 1 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute scaling parameters CALL calc_scaling_parameters ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_ugrid ! !-- Compute Obukhov length IF ( .NOT. neutral ) CALL calc_ol ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ELSE DO l = 0, 1 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_ugrid ! !-- Compute Obukhov length IF ( .NOT. neutral ) CALL calc_ol ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute scaling parameters CALL calc_scaling_parameters ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ENDIF ! !-- No ts is required, so scaling parameters and Obukhov length do not need !-- to be computed. ELSE DO l = 0, 1 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_ugrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ENDIF ! !-- For urban-type surfaces DO l = 0, 1 IF ( surf_usm_v(l)%ns >= 1 ) THEN surf => surf_usm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_ugrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ! !-- Calculate horizontal momentum fluxes at east- and west-facing !-- surfaces (vsus). !-- For default-type surfaces DO l = 2, 3 IF ( surf_def_v(l)%ns >= 1 ) THEN surf => surf_def_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_vgrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ! !-- For natural-type surfaces. Please note, even though stability is not !-- considered for the calculation of momentum fluxes at vertical surfaces, !-- scaling parameters and Obukov length are calculated nevertheless in this !-- case. This is due to the requirement of ts in parameterization of heat !-- flux in land-surface model in case of aero_resist_kray is not true. IF ( .NOT. aero_resist_kray ) THEN IF ( most_method == 'circular' ) THEN DO l = 2, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute scaling parameters CALL calc_scaling_parameters ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_vgrid ! !-- Compute Obukhov length IF ( .NOT. neutral ) CALL calc_ol ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ELSE DO l = 2, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_vgrid ! !-- Compute Obukhov length IF ( .NOT. neutral ) CALL calc_ol ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute scaling parameters CALL calc_scaling_parameters ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ENDIF ELSE DO l = 2, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_vgrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO ENDIF ! !-- For urban-type surfaces DO l = 2, 3 IF ( surf_usm_v(l)%ns >= 1 ) THEN surf => surf_usm_v(l) ! !-- Compute surface-parallel velocity CALL calc_uvw_abs_v_vgrid ! !-- Compute respective friction velocity on staggered grid CALL calc_us ! !-- Compute respective surface fluxes for momentum and TKE CALL calc_surface_fluxes ENDIF ENDDO mom_uv = .FALSE. ! !-- Calculate horizontal momentum fluxes of w (wsus and wsvs) at vertial !-- surfaces. mom_w = .TRUE. ! !-- Default-type surfaces DO l = 0, 3 IF ( surf_def_v(l)%ns >= 1 ) THEN surf => surf_def_v(l) CALL calc_uvw_abs_v_wgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO ! !-- Natural-type surfaces DO l = 0, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) CALL calc_uvw_abs_v_wgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO ! !-- Urban-type surfaces DO l = 0, 3 IF ( surf_usm_v(l)%ns >= 1 ) THEN surf => surf_usm_v(l) CALL calc_uvw_abs_v_wgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO mom_w = .FALSE. ! !-- Calculate momentum fluxes usvs, vsus, wsus and wsvs at vertical !-- surfaces for TKE production. Note, here, momentum fluxes are defined !-- at grid center and are not staggered as before. mom_tke = .TRUE. ! !-- Default-type surfaces DO l = 0, 3 IF ( surf_def_v(l)%ns >= 1 ) THEN surf => surf_def_v(l) CALL calc_uvw_abs_v_sgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO ! !-- Natural-type surfaces DO l = 0, 3 IF ( surf_lsm_v(l)%ns >= 1 ) THEN surf => surf_lsm_v(l) CALL calc_uvw_abs_v_sgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO ! !-- Urban-type surfaces DO l = 0, 3 IF ( surf_usm_v(l)%ns >= 1 ) THEN surf => surf_usm_v(l) CALL calc_uvw_abs_v_sgrid CALL calc_us CALL calc_surface_fluxes ENDIF ENDDO mom_tke = .FALSE. END SUBROUTINE surface_layer_fluxes !------------------------------------------------------------------------------! ! Description: ! ------------ !> Initializing actions for the surface layer routine. Basically, this involves !> the preparation of a lookup table for the the bulk Richardson number vs !> Obukhov length L when using the lookup table method. !------------------------------------------------------------------------------! SUBROUTINE init_surface_layer_fluxes IMPLICIT NONE INTEGER(iwp) :: li, & !< Index for loop to create lookup table num_steps_n !< Number of non-stretched zeta steps LOGICAL :: terminate_run_l = .FALSE. !< Flag to terminate run (global) REAL(wp), PARAMETER :: zeta_stretch = -10.0_wp !< Start of stretching in the free convection limit REAL(wp), DIMENSION(:), ALLOCATABLE :: zeta_tmp REAL(wp) :: zeta_step, & !< Increment of zeta regr = 1.01_wp, & !< Stretching factor of zeta_step in the free convection limit regr_old = 1.0E9_wp, & !< Stretching factor of last iteration step z0h_min = 0.0_wp, & !< Minimum value of z0h to create table z0_min = 0.0_wp !< Minimum value of z0 to create table ! !-- In case of runs with neutral statification, set Obukhov length to a !-- large value IF ( neutral ) THEN IF ( surf_def_h(0)%ns >= 1 ) surf_def_h(0)%ol = 1.0E10_wp IF ( surf_lsm_h%ns >= 1 ) surf_lsm_h%ol = 1.0E10_wp IF ( surf_usm_h%ns >= 1 ) surf_usm_h%ol = 1.0E10_wp ENDIF IF ( most_method == 'lookup' ) THEN ! !-- Check for roughness heterogeneity. In that case terminate run and !-- inform user. Check for both, natural and non-natural walls. IF ( surf_def_h(0)%ns >= 1 ) THEN IF ( MINVAL( surf_def_h(0)%z0h ) /= MAXVAL( surf_def_h(0)%z0h ) .OR. & MINVAL( surf_def_h(0)%z0 ) /= MAXVAL( surf_def_h(0)%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF IF ( surf_lsm_h%ns >= 1 ) THEN IF ( MINVAL( surf_lsm_h%z0h ) /= MAXVAL( surf_lsm_h%z0h ) .OR. & MINVAL( surf_lsm_h%z0 ) /= MAXVAL( surf_lsm_h%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF IF ( surf_usm_h%ns >= 1 ) THEN IF ( MINVAL( surf_usm_h%z0h ) /= MAXVAL( surf_usm_h%z0h ) .OR. & MINVAL( surf_usm_h%z0 ) /= MAXVAL( surf_usm_h%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF ! !-- Check roughness homogeneity between differt surface types. IF ( surf_lsm_h%ns >= 1 .AND. surf_def_h(0)%ns >= 1 ) THEN IF ( MINVAL( surf_lsm_h%z0h ) /= MAXVAL( surf_def_h(0)%z0h ) .OR. & MINVAL( surf_lsm_h%z0 ) /= MAXVAL( surf_def_h(0)%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF IF ( surf_usm_h%ns >= 1 .AND. surf_def_h(0)%ns >= 1 ) THEN IF ( MINVAL( surf_usm_h%z0h ) /= MAXVAL( surf_def_h(0)%z0h ) .OR. & MINVAL( surf_usm_h%z0 ) /= MAXVAL( surf_def_h(0)%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF IF ( surf_usm_h%ns >= 1 .AND. surf_lsm_h%ns >= 1 ) THEN IF ( MINVAL( surf_usm_h%z0h ) /= MAXVAL( surf_lsm_h%z0h ) .OR. & MINVAL( surf_usm_h%z0 ) /= MAXVAL( surf_lsm_h%z0 ) ) THEN terminate_run_l = .TRUE. ENDIF ENDIF #if defined( __parallel ) ! !-- Make a logical OR for all processes. Force termiation of model if result !-- is TRUE IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( terminate_run_l, terminate_run, 1, MPI_LOGICAL, & MPI_LOR, comm2d, ierr ) #else terminate_run = terminate_run_l #endif IF ( terminate_run ) THEN message_string = 'most_method = "lookup" cannot be used in ' // & 'combination with a prescribed roughness ' // & 'heterogeneity' CALL message( 'surface_layer_fluxes', 'PA0116', 1, 2, 0, 6, 0 ) ENDIF ALLOCATE( zeta_tmp(0:num_steps-1) ) ! !-- Use the lowest possible value for z_mo k = nzb z_mo = zu(k+1) - zw(k) ! !-- Calculate z/L range from zeta_stretch to zeta_max using 90% of the !-- available steps (num_steps). The calculation is done with negative !-- values of zeta in order to simplify the stretching in the free !-- convection limit for the remaining 10% of steps. zeta_tmp(0) = - zeta_max num_steps_n = ( num_steps * 9 / 10 ) - 1 zeta_step = (zeta_max - zeta_stretch) / REAL(num_steps_n) DO li = 1, num_steps_n zeta_tmp(li) = zeta_tmp(li-1) + zeta_step ENDDO ! !-- Calculate stretching factor for the free convection range DO WHILE ( ABS( (regr-regr_old) / regr_old ) > 1.0E-10_wp ) regr_old = regr regr = ( 1.0_wp - ( -zeta_min / zeta_step ) * ( 1.0_wp - regr ) & )**( 10.0_wp / REAL(num_steps) ) ENDDO ! !-- Calculate z/L range from zeta_min to zeta_stretch DO li = num_steps_n+1, num_steps-1 zeta_tmp(li) = zeta_tmp(li-1) + zeta_step zeta_step = zeta_step * regr ENDDO ! !-- Save roughness lengths to temporary variables IF ( surf_def_h(0)%ns >= 1 ) THEN z0h_min = surf_def_h(0)%z0h(1) z0_min = surf_def_h(0)%z0(1) ELSEIF ( surf_lsm_h%ns >= 1 ) THEN z0h_min = surf_lsm_h%z0h(1) z0_min = surf_lsm_h%z0(1) ELSEIF ( surf_usm_h%ns >= 1 ) THEN z0h_min = surf_usm_h%z0h(1) z0_min = surf_usm_h%z0(1) ENDIF ! !-- Calculate lookup table for the Richardson number versus Obukhov length !-- The Richardson number (rib) is defined depending on the choice of !-- boundary conditions for temperature IF ( ibc_pt_b == 1 ) THEN DO li = 0, num_steps-1 ol_tab(li) = - z_mo / zeta_tmp(num_steps-1-li) rib_tab(li) = z_mo / ol_tab(li) / ( LOG( z_mo / z0_min ) & - psi_m( z_mo / ol_tab(li) ) & + psi_m( z0_min / ol_tab(li) ) & )**3 ENDDO ELSE DO li = 0, num_steps-1 ol_tab(li) = - z_mo / zeta_tmp(num_steps-1-li) rib_tab(li) = z_mo / ol_tab(li) * ( LOG( z_mo / z0h_min ) & - psi_h( z_mo / ol_tab(li) ) & + psi_h( z0h_min / ol_tab(li) ) & ) & / ( LOG( z_mo / z0_min ) & - psi_m( z_mo / ol_tab(li) ) & + psi_m( z0_min / ol_tab(li) ) & )**2 ENDDO ENDIF ! !-- Determine minimum values of rib in the lookup table. Set upper limit !-- to critical Richardson number (0.25) rib_min = MINVAL(rib_tab) rib_max = 0.25 !MAXVAL(rib_tab) DEALLOCATE( zeta_tmp ) ENDIF END SUBROUTINE init_surface_layer_fluxes !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the absolute value of the horizontal velocity (relative to the !> surface) for horizontal surface elements. This is required by all methods. !------------------------------------------------------------------------------! SUBROUTINE calc_uvw_abs IMPLICIT NONE INTEGER(iwp) :: i !< running index x direction INTEGER(iwp) :: ibit !< flag to mask computation of relative velocity in case of downward-facing surfaces INTEGER(iwp) :: j !< running index y direction INTEGER(iwp) :: k !< running index z direction INTEGER(iwp) :: m !< running index surface elements REAL(wp) :: w_lfc !< local free convection velocity scale ! !-- ibit is 1 for upward-facing surfaces, zero for downward-facing surfaces. ibit = MERGE( 1, 0, .NOT. downward ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) ! !-- Calculate free convection velocity scale w_lfc is !-- use_free_convection_scaling = .T.. This will maintain a horizontal !-- velocity even for very weak wind convective conditions. SIGN is used !-- to set w_lfc to zero under stable conditions. IF ( use_free_convection_scaling ) THEN w_lfc = ABS(g / surf%pt1(m) * surf%z_mo(m) * surf%shf(m)) w_lfc = ( 0.5_wp * ( w_lfc + SIGN(w_lfc,surf%shf(m)) ) )**(0.33333_wp) ELSE w_lfc = 0.0_wp ENDIF ! !-- Compute the absolute value of the horizontal velocity. !-- (relative to the surface in case the lower surface is the ocean). !-- Please note, in new surface modelling concept the index values changed, !-- i.e. the reference grid point is not the surface-grid point itself but !-- the first grid point outside of the topography. !-- Note, in case of coupled ocean-atmosphere simulations relative velocity !-- with respect to the ocean surface is used, hence, (k-1,j,i) values !-- are used to calculate the absolute velocity. !-- However, this do not apply for downward-facing walls. To mask this, !-- use ibit, which checks for upward/downward-facing surfaces. surf%uvw_abs(m) = SQRT( & ( 0.5_wp * ( u(k,j,i) + u(k,j,i+1) & - ( u(k-1,j,i) + u(k-1,j,i+1) & ) * ibit & ) & )**2 + & ( 0.5_wp * ( v(k,j,i) + v(k,j+1,i) & - ( v(k-1,j,i) + v(k-1,j+1,i) & ) * ibit & ) & )**2 + w_lfc**2 & ) ENDDO END SUBROUTINE calc_uvw_abs !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the absolute value of the horizontal velocity (relative to the !> surface) for horizontal surface elements. This is required by all methods. !------------------------------------------------------------------------------! SUBROUTINE calc_uvw_abs_v_ugrid IMPLICIT NONE INTEGER(iwp) :: i !< running index x direction INTEGER(iwp) :: j !< running index y direction INTEGER(iwp) :: k !< running index z direction INTEGER(iwp) :: m !< running index surface elements REAL(wp) :: u_i !< u-component on xu-grid REAL(wp) :: w_i !< w-component on xu-grid DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) ! !-- Compute the absolute value of the surface parallel velocity on u-grid. u_i = u(k,j,i) w_i = 0.25_wp * ( w(k-1,j,i-1) + w(k-1,j,i) + & w(k,j,i-1) + w(k,j,i) ) surf%uvw_abs(m) = SQRT( u_i**2 + w_i**2 ) ENDDO END SUBROUTINE calc_uvw_abs_v_ugrid !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the absolute value of the horizontal velocity (relative to the !> surface) for horizontal surface elements. This is required by all methods. !------------------------------------------------------------------------------! SUBROUTINE calc_uvw_abs_v_vgrid IMPLICIT NONE INTEGER(iwp) :: i !< running index x direction INTEGER(iwp) :: j !< running index y direction INTEGER(iwp) :: k !< running index z direction INTEGER(iwp) :: m !< running index surface elements REAL(wp) :: v_i !< v-component on yv-grid REAL(wp) :: w_i !< w-component on yv-grid DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) v_i = u(k,j,i) w_i = 0.25_wp * ( w(k-1,j-1,i) + w(k-1,j,i) + & w(k,j-1,i) + w(k,j,i) ) surf%uvw_abs(m) = SQRT( v_i**2 + w_i**2 ) ENDDO END SUBROUTINE calc_uvw_abs_v_vgrid !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the absolute value of the horizontal velocity (relative to the !> surface) for horizontal surface elements. This is required by all methods. !------------------------------------------------------------------------------! SUBROUTINE calc_uvw_abs_v_wgrid IMPLICIT NONE INTEGER(iwp) :: i !< running index x direction INTEGER(iwp) :: j !< running index y direction INTEGER(iwp) :: k !< running index z direction INTEGER(iwp) :: m !< running index surface elements REAL(wp) :: u_i !< u-component on x-zw-grid REAL(wp) :: v_i !< v-component on y-zw-grid REAL(wp) :: w_i !< w-component on zw-grid ! !-- North- (l=0) and south-facing (l=1) surfaces IF ( l == 0 .OR. l == 1 ) THEN DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i = 0.25_wp * ( u(k+1,j,i+1) + u(k+1,j,i) + & u(k,j,i+1) + u(k,j,i) ) v_i = 0.0_wp w_i = w(k,j,i) surf%uvw_abs(m) = SQRT( u_i**2 + v_i**2 + w_i**2 ) ENDDO ! !-- East- (l=2) and west-facing (l=3) surfaces ELSE DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i = 0.0_wp v_i = 0.25_wp * ( v(k+1,j+1,i) + v(k+1,j,i) + & v(k,j+1,i) + v(k,j,i) ) w_i = w(k,j,i) surf%uvw_abs(m) = SQRT( u_i**2 + v_i**2 + w_i**2 ) ENDDO ENDIF END SUBROUTINE calc_uvw_abs_v_wgrid !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the absolute value of the horizontal velocity (relative to the !> surface) for horizontal surface elements. This is required by all methods. !------------------------------------------------------------------------------! SUBROUTINE calc_uvw_abs_v_sgrid IMPLICIT NONE INTEGER(iwp) :: i !< running index x direction INTEGER(iwp) :: j !< running index y direction INTEGER(iwp) :: k !< running index z direction INTEGER(iwp) :: m !< running index surface elements REAL(wp) :: u_i !< u-component on scalar grid REAL(wp) :: v_i !< v-component on scalar grid REAL(wp) :: w_i !< w-component on scalar grid ! !-- North- (l=0) and south-facing (l=1) walls IF ( l == 0 .OR. l == 1 ) THEN DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i = 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) v_i = 0.0_wp w_i = 0.5_wp * ( w(k,j,i) + w(k-1,j,i) ) surf%uvw_abs(m) = SQRT( u_i**2 + v_i**2 + w_i**2 ) ENDDO ! !-- East- (l=2) and west-facing (l=3) walls ELSE DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i = 0.0_wp v_i = 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) w_i = 0.5_wp * ( w(k,j,i) + w(k-1,j,i) ) surf%uvw_abs(m) = SQRT( u_i**2 + v_i**2 + w_i**2 ) ENDDO ENDIF END SUBROUTINE calc_uvw_abs_v_sgrid !------------------------------------------------------------------------------! ! Description: ! ------------ !> Calculate the Obukhov length (L) and Richardson flux number (z/L) !------------------------------------------------------------------------------! SUBROUTINE calc_ol IMPLICIT NONE INTEGER(iwp) :: iter !< Newton iteration step INTEGER(iwp) :: li !< look index INTEGER(iwp) :: m !< loop variable over all horizontal wall elements REAL(wp) :: f, & !< Function for Newton iteration: f = Ri - [...]/[...]^2 = 0 f_d_ol, & !< Derivative of f ol_l, & !< Lower bound of L for Newton iteration ol_m, & !< Previous value of L for Newton iteration ol_old, & !< Previous time step value of L ol_u !< Upper bound of L for Newton iteration IF ( TRIM( most_method ) /= 'circular' ) THEN ! !-- Evaluate bulk Richardson number (calculation depends on !-- definition based on setting of boundary conditions IF ( ibc_pt_b /= 1 ) THEN IF ( humidity ) THEN !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%rib(m) = g * z_mo & * ( surf%vpt1(m) - surf%vpt_surface(m) ) & / ( surf%uvw_abs(m)**2 * surf%vpt1(m) & + 1.0E-20_wp ) ENDDO ELSE !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%rib(m) = g * z_mo & * ( surf%pt1(m) - surf%pt_surface(m) ) & / ( surf%uvw_abs(m)**2 * surf%pt1(m) & + 1.0E-20_wp ) ENDDO ENDIF ELSE IF ( humidity ) THEN !$OMP PARALLEL DO PRIVATE( k, z_mo ) DO m = 1, surf%ns k = surf%k(m) z_mo = surf%z_mo(m) surf%rib(m) = - g * z_mo * ( ( 1.0_wp + 0.61_wp & * surf%qv1(m) ) * surf%shf(m) + 0.61_wp & * surf%pt1(m) * surf%qsws(m) ) * & drho_air_zw(k-1) / & ( surf%uvw_abs(m)**3 * surf%vpt1(m) * kappa**2 & + 1.0E-20_wp ) ENDDO ELSE !$OMP PARALLEL DO PRIVATE( k, z_mo ) DO m = 1, surf%ns k = surf%k(m) z_mo = surf%z_mo(m) surf%rib(m) = - g * z_mo * surf%shf(m) * & drho_air_zw(k-1) / & ( surf%uvw_abs(m)**3 * surf%pt1(m) * kappa**2 & + 1.0E-20_wp ) ENDDO ENDIF ENDIF ENDIF ! !-- Calculate the Obukhov length either using a Newton iteration !-- method, via a lookup table, or using the old circular way IF ( TRIM( most_method ) == 'newton' ) THEN DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) z_mo = surf%z_mo(m) ! !-- Store current value in case the Newton iteration fails ol_old = surf%ol(m) ! !-- Ensure that the bulk Richardson number and the Obukhov !-- length have the same sign IF ( surf%rib(m) * surf%ol(m) < 0.0_wp .OR. & ABS( surf%ol(m) ) == ol_max ) THEN IF ( surf%rib(m) > 1.0_wp ) surf%ol(m) = 0.01_wp IF ( surf%rib(m) < 0.0_wp ) surf%ol(m) = -0.01_wp ENDIF ! !-- Iteration to find Obukhov length iter = 0 DO iter = iter + 1 ! !-- In case of divergence, use the value of the previous time step IF ( iter > 1000 ) THEN surf%ol(m) = ol_old EXIT ENDIF ol_m = surf%ol(m) ol_l = ol_m - 0.001_wp * ol_m ol_u = ol_m + 0.001_wp * ol_m IF ( ibc_pt_b /= 1 ) THEN ! !-- Calculate f = Ri - [...]/[...]^2 = 0 f = surf%rib(m) - ( z_mo / ol_m ) * ( & LOG( z_mo / surf%z0h(m) ) & - psi_h( z_mo / ol_m ) & + psi_h( surf%z0h(m) / & ol_m ) & ) & / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / ol_m ) & + psi_m( surf%z0(m) / & ol_m ) & )**2 ! !-- Calculate df/dL f_d_ol = ( - ( z_mo / ol_u ) * ( LOG( z_mo / & surf%z0h(m) ) & - psi_h( z_mo / ol_u ) & + psi_h( surf%z0h(m) / ol_u ) & ) & / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / ol_u ) & + psi_m( surf%z0(m) / ol_u ) & )**2 & + ( z_mo / ol_l ) * ( LOG( z_mo / surf%z0h(m) ) & - psi_h( z_mo / ol_l ) & + psi_h( surf%z0h(m) / ol_l ) & ) & / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / ol_l ) & + psi_m( surf%z0(m) / ol_l ) & )**2 & ) / ( ol_u - ol_l ) ELSE ! !-- Calculate f = Ri - 1 /[...]^3 = 0 f = surf%rib(m) - ( z_mo / ol_m ) / & ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / ol_m ) & + psi_m( surf%z0(m) / ol_m ) & )**3 ! !-- Calculate df/dL f_d_ol = ( - ( z_mo / ol_u ) / ( LOG( z_mo / & surf%z0(m) ) & - psi_m( z_mo / ol_u ) & + psi_m( surf%z0(m) / ol_u ) & )**3 & + ( z_mo / ol_l ) / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / ol_l ) & + psi_m( surf%z0(m) / ol_l ) & )**3 & ) / ( ol_u - ol_l ) ENDIF ! !-- Calculate new L surf%ol(m) = ol_m - f / f_d_ol ! !-- Ensure that the bulk Richardson number and the Obukhov !-- length have the same sign and ensure convergence. IF ( surf%ol(m) * ol_m < 0.0_wp ) surf%ol(m) = ol_m * 0.5_wp ! !-- If unrealistic value occurs, set L to the maximum !-- value that is allowed IF ( ABS( surf%ol(m) ) > ol_max ) THEN surf%ol(m) = ol_max EXIT ENDIF ! !-- Check for convergence IF ( ABS( ( surf%ol(m) - ol_m ) / & surf%ol(m) ) < 1.0E-4_wp ) THEN EXIT ELSE CYCLE ENDIF ENDDO ENDDO ELSEIF ( TRIM( most_method ) == 'lookup' ) THEN !$OMP PARALLEL DO PRIVATE( i, j, z_mo, li ) FIRSTPRIVATE( li_bnd ) LASTPRIVATE( li_bnd ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) ! !-- If the bulk Richardson number is outside the range of the lookup !-- table, set it to the exceeding threshold value IF ( surf%rib(m) < rib_min ) surf%rib(m) = rib_min IF ( surf%rib(m) > rib_max ) surf%rib(m) = rib_max ! !-- Find the correct index bounds for linear interpolation. As the !-- Richardson number will not differ very much from time step to !-- time step , use the index from the last step and search in the !-- correct direction li = li_bnd IF ( rib_tab(li) - surf%rib(m) > 0.0_wp ) THEN DO WHILE ( rib_tab(li-1) - surf%rib(m) > 0.0_wp .AND. li > 0 ) li = li-1 ENDDO ELSE DO WHILE ( rib_tab(li) - surf%rib(m) < 0.0_wp & .AND. li < num_steps-1 ) li = li+1 ENDDO ENDIF li_bnd = li ! !-- Linear interpolation to find the correct value of z/L surf%ol(m) = ( ol_tab(li-1) + ( ol_tab(li) - ol_tab(li-1) ) & / ( rib_tab(li) - rib_tab(li-1) ) & * ( surf%rib(m) - rib_tab(li-1) ) ) ENDDO ELSEIF ( TRIM( most_method ) == 'circular' ) THEN IF ( .NOT. humidity ) THEN !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%ol(m) = ( surf%pt1(m) * surf%us(m)**2 ) / & ( kappa * g * & surf%ts(m) + 1E-30_wp ) ! !-- Limit the value range of the Obukhov length. !-- This is necessary for very small velocities (u,v --> 1), because !-- the absolute value of ol can then become very small, which in !-- consequence would result in very large shear stresses and very !-- small momentum fluxes (both are generally unrealistic). IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) < zeta_min ) & surf%ol(m) = z_mo / zeta_min IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) > zeta_max ) & surf%ol(m) = z_mo / zeta_max ENDDO ELSEIF ( bulk_cloud_model .OR. cloud_droplets ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%ol(m) = ( surf%vpt1(m) * surf%us(m)**2 ) / & ( kappa * g * ( surf%ts(m) + & 0.61_wp * surf%pt1(m) * surf%us(m) & + 0.61_wp * surf%qv1(m) * surf%ts(m) - & surf%ts(m) * ql(k,j,i) ) + 1E-30_wp ) ! !-- Limit the value range of the Obukhov length. !-- This is necessary for very small velocities (u,v --> 1), because !-- the absolute value of ol can then become very small, which in !-- consequence would result in very large shear stresses and very !-- small momentum fluxes (both are generally unrealistic). IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) < zeta_min ) & surf%ol(m) = z_mo / zeta_min IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) > zeta_max ) & surf%ol(m) = z_mo / zeta_max ENDDO ELSE !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%ol(m) = ( surf%vpt1(m) * surf%us(m)**2 ) / & ( kappa * g * ( surf%ts(m) + 0.61_wp * surf%pt1(m) * & surf%qs(m) + 0.61_wp * surf%qv1(m) * & surf%ts(m) ) + 1E-30_wp ) ! !-- Limit the value range of the Obukhov length. !-- This is necessary for very small velocities (u,v --> 1), because !-- the absolute value of ol can then become very small, which in !-- consequence would result in very large shear stresses and very !-- small momentum fluxes (both are generally unrealistic). IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) < zeta_min ) & surf%ol(m) = z_mo / zeta_min IF ( ( z_mo / ( surf%ol(m) + 1E-30_wp ) ) > zeta_max ) & surf%ol(m) = z_mo / zeta_max ENDDO ENDIF ENDIF END SUBROUTINE calc_ol ! !-- Calculate friction velocity u* SUBROUTINE calc_us IMPLICIT NONE INTEGER(iwp) :: m !< loop variable over all horizontal surf elements ! !-- Compute u* at horizontal surfaces at the scalars' grid points IF ( .NOT. surf_vertical ) THEN ! !-- Compute u* at upward-facing surfaces IF ( .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) ! !-- Compute u* at the scalars' grid points surf%us(m) = kappa * surf%uvw_abs(m) / & ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / surf%ol(m) ) & + psi_m( surf%z0(m) / surf%ol(m) ) ) ENDDO ! !-- Compute u* at downward-facing surfaces. This case, do not consider !-- any stability. ELSE !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) ! !-- Compute u* at the scalars' grid points surf%us(m) = kappa * surf%uvw_abs(m) / LOG( z_mo / surf%z0(m) ) ENDDO ENDIF ! !-- Compute u* at vertical surfaces at the u/v/v grid, respectively. !-- No stability is considered in this case. ELSE !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%us(m) = kappa * surf%uvw_abs(m) / LOG( z_mo / surf%z0(m) ) ENDDO ENDIF END SUBROUTINE calc_us ! !-- Calculate potential temperature, specific humidity, and virtual potential !-- temperature at first grid level SUBROUTINE calc_pt_q IMPLICIT NONE INTEGER(iwp) :: m !< loop variable over all horizontal surf elements !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) IF ( bulk_cloud_model ) THEN surf%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i) surf%qv1(m) = q(k,j,i) - ql(k,j,i) ELSEIF( cloud_droplets ) THEN surf%pt1(m) = pt(k,j,i) + lv_d_cp * d_exner(k) * ql(k,j,i) surf%qv1(m) = q(k,j,i) ELSE surf%pt1(m) = pt(k,j,i) IF ( humidity ) THEN surf%qv1(m) = q(k,j,i) ELSE surf%qv1(m) = 0.0_wp ENDIF ENDIF IF ( humidity ) THEN surf%vpt1(m) = pt(k,j,i) * ( 1.0_wp + 0.61_wp * q(k,j,i) ) ENDIF ENDDO END SUBROUTINE calc_pt_q ! !-- Set potential temperature at surface grid level. !-- ( only for upward-facing surfs ) SUBROUTINE calc_pt_surface IMPLICIT NONE INTEGER(iwp) :: k_off !< index offset between surface and atmosphere grid point (-1 for upward-, +1 for downward-facing walls) INTEGER(iwp) :: m !< loop variable over all horizontal surf elements k_off = surf%koff !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%pt_surface(m) = pt(k+k_off,j,i) ENDDO END SUBROUTINE calc_pt_surface ! !-- Set mixing ratio at surface grid level. ( Only for upward-facing surfs. ) SUBROUTINE calc_q_surface IMPLICIT NONE INTEGER(iwp) :: k_off !< index offset between surface and atmosphere grid point (-1 for upward-, +1 for downward-facing walls) INTEGER(iwp) :: m !< loop variable over all horizontal surf elements k_off = surf%koff !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%q_surface(m) = q(k+k_off,j,i) ENDDO END SUBROUTINE calc_q_surface ! !-- Set virtual potential temperature at surface grid level. !-- ( only for upward-facing surfs ) SUBROUTINE calc_vpt_surface IMPLICIT NONE INTEGER(iwp) :: k_off !< index offset between surface and atmosphere grid point (-1 for upward-, +1 for downward-facing walls) INTEGER(iwp) :: m !< loop variable over all horizontal surf elements k_off = surf%koff !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%vpt_surface(m) = vpt(k+k_off,j,i) ENDDO END SUBROUTINE calc_vpt_surface ! !-- Calculate the other MOST scaling parameters theta*, q*, (qc*, qr*, nc*, nr*) SUBROUTINE calc_scaling_parameters IMPLICIT NONE INTEGER(iwp) :: m !< loop variable over all horizontal surf elements INTEGER(iwp) :: lsp !< running index for chemical species ! !-- Compute theta* at horizontal surfaces IF ( constant_heatflux .AND. .NOT. surf_vertical ) THEN ! !-- For a given heat flux in the surface layer: !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%ts(m) = -surf%shf(m) * drho_air_zw(k-1) / & ( surf%us(m) + 1E-30_wp ) ! !-- ts must be limited, because otherwise overflow may occur in case !-- of us=0 when computing ol further below IF ( surf%ts(m) < -1.05E5_wp ) surf%ts(m) = -1.0E5_wp IF ( surf%ts(m) > 1.0E5_wp ) surf%ts(m) = 1.0E5_wp ENDDO ELSEIF ( .NOT. surf_vertical ) THEN ! !-- For a given surface temperature: IF ( large_scale_forcing .AND. lsf_surf ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) pt(k-1,j,i) = pt_surface ENDDO ENDIF !$OMP PARALLEL DO PRIVATE( z_mo ) DO m = 1, surf%ns z_mo = surf%z_mo(m) surf%ts(m) = kappa * ( surf%pt1(m) - surf%pt_surface(m) ) & / ( LOG( z_mo / surf%z0h(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0h(m) / surf%ol(m) ) ) ENDDO ENDIF ! !-- Compute theta* at vertical surfaces. This is only required in case of !-- land-surface model, in order to compute aerodynamical resistance. IF ( surf_vertical ) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%ts(m) = -surf%shf(m) / ( surf%us(m) + 1E-30_wp ) ! !-- ts must be limited, because otherwise overflow may occur in case !-- of us=0 when computing ol further below IF ( surf%ts(m) < -1.05E5_wp ) surf%ts(m) = -1.0E5_wp IF ( surf%ts(m) > 1.0E5_wp ) surf%ts(m) = 1.0E5_wp ENDDO ENDIF ! !-- If required compute q* at horizontal surfaces IF ( humidity ) THEN IF ( constant_waterflux .AND. .NOT. surf_vertical ) THEN ! !-- For a given water flux in the surface layer !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%qs(m) = -surf%qsws(m) * drho_air_zw(k-1) / & ( surf%us(m) + 1E-30_wp ) ENDDO ELSEIF ( .NOT. surf_vertical ) THEN coupled_run = ( coupling_mode == 'atmosphere_to_ocean' .AND. & run_coupled ) IF ( large_scale_forcing .AND. lsf_surf ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) q(k-1,j,i) = q_surface ENDDO ENDIF ! !-- Assume saturation for atmosphere coupled to ocean (but not !-- in case of precursor runs) IF ( coupled_run ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, e_s ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) e_s = 6.1_wp * & EXP( 0.07_wp * ( MIN(pt(k-1,j,i),pt(k,j,i)) & - 273.15_wp ) ) q(k-1,j,i) = rd_d_rv * e_s / ( surface_pressure - e_s ) ENDDO ENDIF IF ( bulk_cloud_model .OR. cloud_droplets ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%qs(m) = kappa * ( surf%qv1(m) - surf%q_surface(m) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / & surf%ol(m) ) ) ENDDO ELSE !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%qs(m) = kappa * ( q(k,j,i) - q(k-1,j,i) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / & surf%ol(m) ) ) ENDDO ENDIF ENDIF ! !-- Compute q* at vertical surfaces IF ( surf_vertical ) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%qs(m) = -surf%qsws(m) / ( surf%us(m) + 1E-30_wp ) ENDDO ENDIF ENDIF ! !-- If required compute s* IF ( passive_scalar ) THEN ! !-- At horizontal surfaces IF ( constant_scalarflux .AND. .NOT. surf_vertical ) THEN ! !-- For a given scalar flux in the surface layer !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%ss(m) = -surf%ssws(m) / ( surf%us(m) + 1E-30_wp ) ENDDO ENDIF ! !-- At vertical surfaces IF ( surf_vertical ) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%ss(m) = -surf%ssws(m) / ( surf%us(m) + 1E-30_wp ) ENDDO ENDIF ENDIF ! !-- If required compute cs* (chemical species) IF ( air_chemistry ) THEN ! !-- At horizontal surfaces DO lsp = 1, nvar IF ( constant_csflux(lsp) .AND. .NOT. surf_vertical ) THEN !-- For a given chemical species' flux in the surface layer !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%css(lsp,m) = -surf%cssws(lsp,m) / ( surf%us(m) + 1E-30_wp ) ENDDO ENDIF ENDDO ! !-- At vertical surfaces IF ( surf_vertical ) THEN DO lsp = 1, nvar !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%css(lsp,m) = -surf%cssws(lsp,m) / ( surf%us(m) + 1E-30_wp ) ENDDO ENDDO ENDIF ENDIF ! !-- If required compute qc* and nc* IF ( bulk_cloud_model .AND. microphysics_morrison .AND. & .NOT. surf_vertical ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%qcs(m) = kappa * ( qc(k,j,i) - qc(k-1,j,i) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / surf%ol(m) ) ) surf%ncs(m) = kappa * ( nc(k,j,i) - nc(k-1,j,i) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / surf%ol(m) ) ) ENDDO ENDIF ! !-- If required compute qr* and nr* IF ( bulk_cloud_model .AND. microphysics_seifert .AND. & .NOT. surf_vertical ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%qrs(m) = kappa * ( qr(k,j,i) - qr(k-1,j,i) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / surf%ol(m) ) ) surf%nrs(m) = kappa * ( nr(k,j,i) - nr(k-1,j,i) ) & / ( LOG( z_mo / surf%z0q(m) ) & - psi_h( z_mo / surf%ol(m) ) & + psi_h( surf%z0q(m) / surf%ol(m) ) ) ENDDO ENDIF END SUBROUTINE calc_scaling_parameters ! !-- Calculate surface fluxes usws, vsws, shf, qsws, (qcsws, qrsws, ncsws, nrsws) SUBROUTINE calc_surface_fluxes IMPLICIT NONE INTEGER(iwp) :: m !< loop variable over all horizontal surf elements INTEGER(iwp) :: lsp !< running index for chemical species REAL(wp) :: dum !< dummy to precalculate logarithm REAL(wp) :: flag_u !< flag indicating u-grid, used for calculation of horizontal momentum fluxes at vertical surfaces REAL(wp) :: flag_v !< flag indicating v-grid, used for calculation of horizontal momentum fluxes at vertical surfaces REAL(wp), DIMENSION(:), ALLOCATABLE :: u_i !< u-component interpolated onto scalar grid point, required for momentum fluxes at vertical surfaces REAL(wp), DIMENSION(:), ALLOCATABLE :: v_i !< v-component interpolated onto scalar grid point, required for momentum fluxes at vertical surfaces REAL(wp), DIMENSION(:), ALLOCATABLE :: w_i !< w-component interpolated onto scalar grid point, required for momentum fluxes at vertical surfaces ! !-- Calcuate surface fluxes at horizontal walls IF ( .NOT. surf_vertical ) THEN ! !-- Compute u'w' for the total model domain at upward-facing surfaces. !-- First compute the corresponding component of u* and square it. IF ( .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%usws(m) = kappa * ( u(k,j,i) - u(k-1,j,i) ) & / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / surf%ol(m) ) & + psi_m( surf%z0(m) / surf%ol(m) ) ) ! !-- Please note, the computation of usws is not fully accurate. Actually !-- a further interpolation of us onto the u-grid, where usws is defined, !-- is required. However, this is not done as this would require several !-- data transfers between 2D-grid and the surf-type. !-- The impact of the missing interpolation is negligible as several !-- tests had shown. !-- Same also for ol. surf%usws(m) = -surf%usws(m) * surf%us(m) * rho_air_zw(k-1) ENDDO ! !-- At downward-facing surfaces ELSE !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%usws(m) = kappa * u(k,j,i) / LOG( z_mo / surf%z0(m) ) surf%usws(m) = surf%usws(m) * surf%us(m) * rho_air_zw(k) ENDDO ENDIF ! !-- Compute v'w' for the total model domain. !-- First compute the corresponding component of u* and square it. !-- Upward-facing surfaces IF ( .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%vsws(m) = kappa * ( v(k,j,i) - v(k-1,j,i) ) & / ( LOG( z_mo / surf%z0(m) ) & - psi_m( z_mo / surf%ol(m) ) & + psi_m( surf%z0(m) / surf%ol(m) ) ) ! !-- Please note, the computation of vsws is not fully accurate. Actually !-- a further interpolation of us onto the v-grid, where vsws is defined, !-- is required. However, this is not done as this would require several !-- data transfers between 2D-grid and the surf-type. !-- The impact of the missing interpolation is negligible as several !-- tests had shown. !-- Same also for ol. surf%vsws(m) = -surf%vsws(m) * surf%us(m) * rho_air_zw(k-1) ENDDO ! !-- Downward-facing surfaces ELSE !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%vsws(m) = kappa * v(k,j,i) / LOG( z_mo / surf%z0(m) ) surf%vsws(m) = surf%vsws(m) * surf%us(m) * rho_air_zw(k) ENDDO ENDIF ! !-- Compute the vertical kinematic heat flux IF ( .NOT. constant_heatflux .AND. ( ( time_since_reference_point& <= skip_time_do_lsm .AND. simulated_time > 0.0_wp ) .OR. & .NOT. land_surface ) .AND. .NOT. urban_surface .AND. & .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%shf(m) = -surf%ts(m) * surf%us(m) * rho_air_zw(k-1) ENDDO ENDIF ! !-- Compute the vertical water flux IF ( .NOT. constant_waterflux .AND. humidity .AND. & ( ( time_since_reference_point <= skip_time_do_lsm .AND. & simulated_time > 0.0_wp ) .OR. .NOT. land_surface ) .AND. & .NOT. urban_surface .AND. .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%qsws(m) = -surf%qs(m) * surf%us(m) * rho_air_zw(k-1) ENDDO ENDIF ! !-- Compute the vertical scalar flux IF ( .NOT. constant_scalarflux .AND. passive_scalar .AND. & .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%ssws(m) = -surf%ss(m) * surf%us(m) ENDDO ENDIF ! !-- Compute the vertical chemical species' flux DO lsp = 1, nvar IF ( .NOT. constant_csflux(lsp) .AND. air_chemistry .AND. & .NOT. downward ) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%cssws(lsp,m) = -surf%css(lsp,m) * surf%us(m) ENDDO ENDIF ENDDO ! !-- Compute (turbulent) fluxes of cloud water content and cloud drop conc. IF ( bulk_cloud_model .AND. microphysics_morrison .AND. & .NOT. downward) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%qcsws(m) = -surf%qcs(m) * surf%us(m) surf%ncsws(m) = -surf%ncs(m) * surf%us(m) ENDDO ENDIF ! !-- Compute (turbulent) fluxes of rain water content and rain drop conc. IF ( bulk_cloud_model .AND. microphysics_seifert .AND. & .NOT. downward) THEN !$OMP PARALLEL DO PRIVATE( i, j ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) surf%qrsws(m) = -surf%qrs(m) * surf%us(m) surf%nrsws(m) = -surf%nrs(m) * surf%us(m) ENDDO ENDIF ! !-- Bottom boundary condition for the TKE. IF ( ibc_e_b == 2 ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) e(k,j,i) = ( surf%us(m) / 0.1_wp )**2 ! !-- As a test: cm = 0.4 ! e(k,j,i) = ( us(j,i) / 0.4_wp )**2 e(k-1,j,i) = e(k,j,i) ENDDO ENDIF ! !-- Calcuate surface fluxes at vertical surfaces. No stability is considered. ELSE ! !-- Compute usvs l={0,1} and vsus l={2,3} IF ( mom_uv ) THEN ! !-- Generalize computation by introducing flags. At north- and south- !-- facing surfaces u-component is used, at east- and west-facing !-- surfaces v-component is used. flag_u = MERGE( 1.0_wp, 0.0_wp, l == 0 .OR. l == 1 ) flag_v = MERGE( 1.0_wp, 0.0_wp, l == 2 .OR. l == 3 ) !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%mom_flux_uv(m) = kappa * & ( flag_u * u(k,j,i) + flag_v * v(k,j,i) ) / & LOG( z_mo / surf%z0(m) ) surf%mom_flux_uv(m) = & - surf%mom_flux_uv(m) * surf%us(m) ENDDO ENDIF ! !-- Compute wsus l={0,1} and wsvs l={2,3} IF ( mom_w ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) z_mo = surf%z_mo(m) surf%mom_flux_w(m) = kappa * w(k,j,i) / LOG( z_mo / surf%z0(m) ) surf%mom_flux_w(m) = & - surf%mom_flux_w(m) * surf%us(m) ENDDO ENDIF ! !-- Compute momentum fluxes used for subgrid-scale TKE production at !-- vertical surfaces. In constrast to the calculated momentum fluxes at !-- vertical surfaces before, which are defined on the u/v/w-grid, !-- respectively), the TKE fluxes are defined at the scalar grid. !-- IF ( mom_tke ) THEN ! !-- Precalculate velocity components at scalar grid point. ALLOCATE( u_i(1:surf%ns) ) ALLOCATE( v_i(1:surf%ns) ) ALLOCATE( w_i(1:surf%ns) ) IF ( l == 0 .OR. l == 1 ) THEN !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i(m) = 0.5_wp * ( u(k,j,i) + u(k,j,i+1) ) v_i(m) = 0.0_wp w_i(m) = 0.5_wp * ( w(k,j,i) + w(k-1,j,i) ) ENDDO ELSE !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) u_i(m) = 0.0_wp v_i(m) = 0.5_wp * ( v(k,j,i) + v(k,j+1,i) ) w_i(m) = 0.5_wp * ( w(k,j,i) + w(k-1,j,i) ) ENDDO ENDIF !$OMP PARALLEL DO PRIVATE( i, j, dum, z_mo ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) z_mo = surf%z_mo(m) dum = kappa / LOG( z_mo / surf%z0(m) ) ! !-- usvs (l=0,1) and vsus (l=2,3) surf%mom_flux_tke(0,m) = dum * ( u_i(m) + v_i(m) ) ! !-- wsvs (l=0,1) and wsus (l=2,3) surf%mom_flux_tke(1,m) = dum * w_i(m) surf%mom_flux_tke(0:1,m) = & - surf%mom_flux_tke(0:1,m) * surf%us(m) ENDDO ! !-- Deallocate temporary arrays DEALLOCATE( u_i ) DEALLOCATE( v_i ) DEALLOCATE( w_i ) ENDIF ENDIF END SUBROUTINE calc_surface_fluxes !------------------------------------------------------------------------------! ! Description: ! ------------ !> Calculates temperature near surface (10 cm) for indoor model or 2 m !> temperature for output !------------------------------------------------------------------------------! SUBROUTINE calc_pt_near_surface ( z_char ) IMPLICIT NONE CHARACTER (LEN = *), INTENT(IN) :: z_char !< string identifier to identify z level INTEGER(iwp) :: i, j, k, l, m !< running indices SELECT CASE ( z_char) CASE ( '10cm' ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%pt_10cm(m) = surf%pt_surface(m) + surf%ts(m) / kappa & * ( log( 0.1_wp / surf%z0h(m) ) & - psi_h( 0.1_wp / surf%ol(m) ) & + psi_h( surf%z0h(m) / surf%ol(m) ) ) ENDDO CASE ( '2m' ) DO m = 1, surf%ns i = surf%i(m) j = surf%j(m) k = surf%k(m) surf%pt_2m(m) = surf%pt_surface(m) + surf%ts(m) / kappa & * ( log( 2.0_wp / surf%z0h(m) ) & - psi_h( 2.0_wp / surf%ol(m) ) & + psi_h( surf%z0h(m) / surf%ol(m) ) ) ENDDO END SELECT END SUBROUTINE calc_pt_near_surface ! !-- Integrated stability function for momentum FUNCTION psi_m( zeta ) USE kinds IMPLICIT NONE REAL(wp) :: psi_m !< Integrated similarity function result REAL(wp) :: zeta !< Stability parameter z/L REAL(wp) :: x !< dummy variable REAL(wp), PARAMETER :: a = 1.0_wp !< constant REAL(wp), PARAMETER :: b = 0.66666666666_wp !< constant REAL(wp), PARAMETER :: c = 5.0_wp !< constant REAL(wp), PARAMETER :: d = 0.35_wp !< constant REAL(wp), PARAMETER :: c_d_d = c / d !< constant REAL(wp), PARAMETER :: bc_d_d = b * c / d !< constant IF ( zeta < 0.0_wp ) THEN x = SQRT( SQRT( 1.0_wp - 16.0_wp * zeta ) ) psi_m = pi * 0.5_wp - 2.0_wp * ATAN( x ) + LOG( ( 1.0_wp + x )**2 & * ( 1.0_wp + x**2 ) * 0.125_wp ) ELSE psi_m = - b * ( zeta - c_d_d ) * EXP( -d * zeta ) - a * zeta & - bc_d_d ! !-- Old version for stable conditions (only valid for z/L < 0.5) !-- psi_m = - 5.0_wp * zeta ENDIF END FUNCTION psi_m ! !-- Integrated stability function for heat and moisture FUNCTION psi_h( zeta ) USE kinds IMPLICIT NONE REAL(wp) :: psi_h !< Integrated similarity function result REAL(wp) :: zeta !< Stability parameter z/L REAL(wp) :: x !< dummy variable REAL(wp), PARAMETER :: a = 1.0_wp !< constant REAL(wp), PARAMETER :: b = 0.66666666666_wp !< constant REAL(wp), PARAMETER :: c = 5.0_wp !< constant REAL(wp), PARAMETER :: d = 0.35_wp !< constant REAL(wp), PARAMETER :: c_d_d = c / d !< constant REAL(wp), PARAMETER :: bc_d_d = b * c / d !< constant IF ( zeta < 0.0_wp ) THEN x = SQRT( 1.0_wp - 16.0_wp * zeta ) psi_h = 2.0_wp * LOG( (1.0_wp + x ) / 2.0_wp ) ELSE psi_h = - b * ( zeta - c_d_d ) * EXP( -d * zeta ) - (1.0_wp & + 0.66666666666_wp * a * zeta )**1.5_wp - bc_d_d & + 1.0_wp ! !-- Old version for stable conditions (only valid for z/L < 0.5) !-- psi_h = - 5.0_wp * zeta ENDIF END FUNCTION psi_h !------------------------------------------------------------------------------! ! Description: ! ------------ !> Calculates stability function for momentum !> !> @author Hauke Wurps !------------------------------------------------------------------------------! FUNCTION phi_m( zeta ) IMPLICIT NONE REAL(wp) :: phi_m !< Value of the function REAL(wp) :: zeta !< Stability parameter z/L REAL(wp), PARAMETER :: a = 16.0_wp !< constant REAL(wp), PARAMETER :: c = 5.0_wp !< constant IF ( zeta < 0.0_wp ) THEN phi_m = 1.0_wp / SQRT( SQRT( 1.0_wp - a * zeta ) ) ELSE phi_m = 1.0_wp + c * zeta ENDIF END FUNCTION phi_m END MODULE surface_layer_fluxes_mod