[1682] | 1 | !> @file init_3d_model.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 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[254] | 20 | ! Current revisions: |
---|
[732] | 21 | ! ------------------ |
---|
[2233] | 22 | ! |
---|
[3589] | 23 | ! |
---|
[2233] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: init_3d_model.f90 4548 2020-05-28 19:36:45Z raasch $ |
---|
[4548] | 27 | ! Bugfix, move call for lsf_forcing_surf after lsf_init is called |
---|
| 28 | ! |
---|
| 29 | ! 4514 2020-04-30 16:29:59Z suehring |
---|
[4514] | 30 | ! Add possibility to initialize surface sensible and latent heat fluxes via |
---|
| 31 | ! a static driver. |
---|
| 32 | ! |
---|
| 33 | ! 4493 2020-04-10 09:49:43Z pavelkrc |
---|
[4365] | 34 | ! Overwrite u_init, v_init, pt_init, q_init and s_init with hom for all |
---|
| 35 | ! cyclic_fill-cases, not only for turbulent_inflow = .TRUE. |
---|
| 36 | ! |
---|
| 37 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4346] | 38 | ! Introduction of wall_flags_total_0, which currently sets bits based on static |
---|
| 39 | ! topography information used in wall_flags_static_0 |
---|
| 40 | ! |
---|
| 41 | ! 4329 2019-12-10 15:46:36Z motisi |
---|
[4329] | 42 | ! Renamed wall_flags_0 to wall_flags_static_0 |
---|
| 43 | ! |
---|
| 44 | ! 4286 2019-10-30 16:01:14Z resler |
---|
[4227] | 45 | ! implement new palm_date_time_mod |
---|
| 46 | ! |
---|
| 47 | ! 4223 2019-09-10 09:20:47Z gronemeier |
---|
[4187] | 48 | ! Deallocate temporary string array since it may be re-used to read different |
---|
| 49 | ! input data in other modules |
---|
| 50 | ! |
---|
| 51 | ! 4186 2019-08-23 16:06:14Z suehring |
---|
[4186] | 52 | ! Design change, use variables defined in netcdf_data_input_mod to read netcd |
---|
| 53 | ! variables rather than define local ones. |
---|
| 54 | ! |
---|
| 55 | ! 4185 2019-08-23 13:49:38Z oliver.maas |
---|
[4185] | 56 | ! For initializing_actions = ' cyclic_fill': |
---|
| 57 | ! Overwrite u_init, v_init, pt_init, q_init and s_init with the |
---|
| 58 | ! (temporally) and horizontally averaged vertical profiles from the end |
---|
| 59 | ! of the prerun, because these profiles shall be used as the basic state |
---|
| 60 | ! for the rayleigh damping and the pt_damping. |
---|
| 61 | ! |
---|
| 62 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
[4182] | 63 | ! Corrected "Former revisions" section |
---|
| 64 | ! |
---|
| 65 | ! 4168 2019-08-16 13:50:17Z suehring |
---|
[4168] | 66 | ! Replace function get_topography_top_index by topo_top_ind |
---|
| 67 | ! |
---|
| 68 | ! 4151 2019-08-09 08:24:30Z suehring |
---|
[4151] | 69 | ! Add netcdf directive around input calls (fix for last commit) |
---|
| 70 | ! |
---|
| 71 | ! 4150 2019-08-08 20:00:47Z suehring |
---|
[4150] | 72 | ! Input of additional surface variables independent on land- or urban-surface |
---|
| 73 | ! model |
---|
| 74 | ! |
---|
| 75 | ! 4131 2019-08-02 11:06:18Z monakurppa |
---|
[4131] | 76 | ! Allocate sums and sums_l to allow profile output for salsa variables. |
---|
| 77 | ! |
---|
| 78 | ! 4130 2019-08-01 13:04:13Z suehring |
---|
[4130] | 79 | ! Effectively reduce 3D initialization to 1D initial profiles. This is because |
---|
| 80 | ! 3D initialization produces structures in the w-component that are correlated |
---|
| 81 | ! with the processor grid for some unknown reason |
---|
| 82 | ! |
---|
| 83 | ! 4090 2019-07-11 15:06:47Z Giersch |
---|
[4090] | 84 | ! Unused variables removed |
---|
| 85 | ! |
---|
| 86 | ! 4088 2019-07-11 13:57:56Z Giersch |
---|
[4088] | 87 | ! Pressure and density profile calculations revised using basic functions |
---|
| 88 | ! |
---|
| 89 | ! 4048 2019-06-21 21:00:21Z knoop |
---|
[4028] | 90 | ! Further modularization of particle code components |
---|
| 91 | ! |
---|
| 92 | ! 4017 2019-06-06 12:16:46Z schwenkel |
---|
[3987] | 93 | ! Convert most location messages to debug messages to reduce output in |
---|
| 94 | ! job logfile to a minimum |
---|
| 95 | ! |
---|
| 96 | ! |
---|
[3939] | 97 | ! unused variable removed |
---|
| 98 | ! |
---|
| 99 | ! 3937 2019-04-29 15:09:07Z suehring |
---|
[3937] | 100 | ! Move initialization of synthetic turbulence generator behind initialization |
---|
| 101 | ! of offline nesting. Remove call for stg_adjust, as this is now already done |
---|
| 102 | ! in stg_init. |
---|
| 103 | ! |
---|
| 104 | ! 3900 2019-04-16 15:17:43Z suehring |
---|
[3900] | 105 | ! Fix problem with LOD = 2 initialization |
---|
| 106 | ! |
---|
| 107 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
[3885] | 108 | ! Changes related to global restructuring of location messages and introduction |
---|
| 109 | ! of additional debug messages |
---|
| 110 | ! |
---|
| 111 | ! 3849 2019-04-01 16:35:16Z knoop |
---|
[3747] | 112 | ! Move initialization of rmask before initializing user_init_arrays |
---|
| 113 | ! |
---|
| 114 | ! 3711 2019-01-31 13:44:26Z knoop |
---|
[3711] | 115 | ! Introduced module_interface_init_checks for post-init checks in modules |
---|
| 116 | ! |
---|
| 117 | ! 3700 2019-01-26 17:03:42Z knoop |
---|
[3685] | 118 | ! Some interface calls moved to module_interface + cleanup |
---|
| 119 | ! |
---|
| 120 | ! 3648 2019-01-02 16:35:46Z suehring |
---|
[3648] | 121 | ! Rename subroutines for surface-data output |
---|
[3569] | 122 | ! |
---|
[4182] | 123 | ! Revision 1.1 1998/03/09 16:22:22 raasch |
---|
| 124 | ! Initial revision |
---|
| 125 | ! |
---|
| 126 | ! |
---|
[1] | 127 | ! Description: |
---|
| 128 | ! ------------ |
---|
[1682] | 129 | !> Allocation of arrays and initialization of the 3D model via |
---|
| 130 | !> a) pre-run the 1D model |
---|
| 131 | !> or |
---|
| 132 | !> b) pre-set constant linear profiles |
---|
| 133 | !> or |
---|
| 134 | !> c) read values of a previous run |
---|
[1] | 135 | !------------------------------------------------------------------------------! |
---|
[1682] | 136 | SUBROUTINE init_3d_model |
---|
[1] | 137 | |
---|
[3298] | 138 | |
---|
[667] | 139 | USE advec_ws |
---|
[1320] | 140 | |
---|
[1] | 141 | USE arrays_3d |
---|
[1849] | 142 | |
---|
[3274] | 143 | USE basic_constants_and_equations_mod, & |
---|
[4090] | 144 | ONLY: c_p, g, l_v, pi, exner_function, exner_function_invers, & |
---|
[3274] | 145 | ideal_gas_law_rho, ideal_gas_law_rho_pt, barometric_formula |
---|
| 146 | |
---|
| 147 | USE bulk_cloud_model_mod, & |
---|
[3685] | 148 | ONLY: bulk_cloud_model |
---|
[3274] | 149 | |
---|
[3298] | 150 | USE chem_modules, & |
---|
[3685] | 151 | ONLY: max_pr_cs ! ToDo: this dependency needs to be removed cause it is ugly #new_dom |
---|
[3298] | 152 | |
---|
[1] | 153 | USE control_parameters |
---|
[3298] | 154 | |
---|
[1320] | 155 | USE grid_variables, & |
---|
[2037] | 156 | ONLY: dx, dy, ddx2_mg, ddy2_mg |
---|
[2817] | 157 | |
---|
[1] | 158 | USE indices |
---|
[3469] | 159 | |
---|
[1320] | 160 | USE kinds |
---|
[1496] | 161 | |
---|
[2320] | 162 | USE lsf_nudging_mod, & |
---|
[3685] | 163 | ONLY: ls_forcing_surf |
---|
[1849] | 164 | |
---|
[2338] | 165 | USE model_1d_mod, & |
---|
[3241] | 166 | ONLY: init_1d_model, l1d, u1d, v1d |
---|
[2338] | 167 | |
---|
[3685] | 168 | USE module_interface, & |
---|
[3711] | 169 | ONLY: module_interface_init_arrays, & |
---|
| 170 | module_interface_init, & |
---|
| 171 | module_interface_init_checks |
---|
[3685] | 172 | |
---|
[3159] | 173 | USE multi_agent_system_mod, & |
---|
| 174 | ONLY: agents_active, mas_init |
---|
| 175 | |
---|
[1783] | 176 | USE netcdf_interface, & |
---|
[3700] | 177 | ONLY: dots_max |
---|
[2696] | 178 | |
---|
[2906] | 179 | USE netcdf_data_input_mod, & |
---|
[4150] | 180 | ONLY: char_fill, & |
---|
| 181 | check_existence, & |
---|
| 182 | close_input_file, & |
---|
| 183 | get_attribute, & |
---|
| 184 | get_variable, & |
---|
| 185 | init_3d, & |
---|
| 186 | input_pids_static, & |
---|
| 187 | inquire_num_variables, & |
---|
| 188 | inquire_variable_names, & |
---|
| 189 | input_file_static, & |
---|
| 190 | netcdf_data_input_init_3d, & |
---|
[4186] | 191 | num_var_pids, & |
---|
[4150] | 192 | open_read_file, & |
---|
[4186] | 193 | pids_id, & |
---|
| 194 | real_2d, & |
---|
| 195 | vars_pids |
---|
[4150] | 196 | |
---|
[3347] | 197 | USE nesting_offl_mod, & |
---|
| 198 | ONLY: nesting_offl_init |
---|
[3294] | 199 | |
---|
[4227] | 200 | USE palm_date_time_mod, & |
---|
| 201 | ONLY: set_reference_date_time |
---|
| 202 | |
---|
[1] | 203 | USE pegrid |
---|
[3298] | 204 | |
---|
[3524] | 205 | #if defined( __parallel ) |
---|
[2934] | 206 | USE pmc_interface, & |
---|
| 207 | ONLY: nested_run |
---|
[3524] | 208 | #endif |
---|
[2934] | 209 | |
---|
[1320] | 210 | USE random_function_mod |
---|
[3685] | 211 | |
---|
[1400] | 212 | USE random_generator_parallel, & |
---|
[2172] | 213 | ONLY: init_parallel_random_generator |
---|
[3685] | 214 | |
---|
[2894] | 215 | USE read_restart_data_mod, & |
---|
[3685] | 216 | ONLY: rrd_read_parts_of_global, rrd_local |
---|
| 217 | |
---|
[1320] | 218 | USE statistics, & |
---|
[1738] | 219 | ONLY: hom, hom_sum, mean_surface_level_height, pr_palm, rmask, & |
---|
[1833] | 220 | statistic_regions, sums, sums_divnew_l, sums_divold_l, sums_l, & |
---|
[2277] | 221 | sums_l_l, sums_wsts_bc_l, ts_value, & |
---|
[1833] | 222 | weight_pres, weight_substep |
---|
[2259] | 223 | |
---|
| 224 | USE synthetic_turbulence_generator_mod, & |
---|
[3939] | 225 | ONLY: stg_init, use_syn_turb_gen |
---|
[3685] | 226 | |
---|
[1691] | 227 | USE surface_layer_fluxes_mod, & |
---|
| 228 | ONLY: init_surface_layer_fluxes |
---|
[2232] | 229 | |
---|
| 230 | USE surface_mod, & |
---|
[4150] | 231 | ONLY : init_single_surface_properties, & |
---|
| 232 | init_surface_arrays, & |
---|
| 233 | init_surfaces, & |
---|
| 234 | surf_def_h, & |
---|
| 235 | surf_def_v, & |
---|
| 236 | surf_lsm_h, & |
---|
[4168] | 237 | surf_usm_h |
---|
[3685] | 238 | |
---|
[3849] | 239 | #if defined( _OPENACC ) |
---|
| 240 | USE surface_mod, & |
---|
| 241 | ONLY : bc_h |
---|
| 242 | #endif |
---|
| 243 | |
---|
[3648] | 244 | USE surface_data_output_mod, & |
---|
| 245 | ONLY: surface_data_output_init |
---|
[3685] | 246 | |
---|
[2007] | 247 | USE transpose_indices |
---|
[1] | 248 | |
---|
| 249 | IMPLICIT NONE |
---|
[4150] | 250 | |
---|
| 251 | INTEGER(iwp) :: i !< grid index in x direction |
---|
| 252 | INTEGER(iwp) :: ind_array(1) !< dummy used to determine start index for external pressure forcing |
---|
| 253 | INTEGER(iwp) :: j !< grid index in y direction |
---|
| 254 | INTEGER(iwp) :: k !< grid index in z direction |
---|
| 255 | INTEGER(iwp) :: k_surf !< surface level index |
---|
| 256 | INTEGER(iwp) :: l !< running index over surface orientation |
---|
| 257 | INTEGER(iwp) :: m !< index of surface element in surface data type |
---|
| 258 | INTEGER(iwp) :: nz_u_shift !< topography-top index on u-grid, used to vertically shift initial profiles |
---|
| 259 | INTEGER(iwp) :: nz_v_shift !< topography-top index on v-grid, used to vertically shift initial profiles |
---|
| 260 | INTEGER(iwp) :: nz_w_shift !< topography-top index on w-grid, used to vertically shift initial profiles |
---|
| 261 | INTEGER(iwp) :: nz_s_shift !< topography-top index on scalar-grid, used to vertically shift initial profiles |
---|
| 262 | INTEGER(iwp) :: nz_u_shift_l !< topography-top index on u-grid, used to vertically shift initial profiles |
---|
| 263 | INTEGER(iwp) :: nz_v_shift_l !< topography-top index on v-grid, used to vertically shift initial profiles |
---|
| 264 | INTEGER(iwp) :: nz_w_shift_l !< topography-top index on w-grid, used to vertically shift initial profiles |
---|
| 265 | INTEGER(iwp) :: nz_s_shift_l !< topography-top index on scalar-grid, used to vertically shift initial profiles |
---|
| 266 | INTEGER(iwp) :: nzt_l !< index of top PE boundary for multigrid level |
---|
| 267 | INTEGER(iwp) :: sr !< index of statistic region |
---|
[1] | 268 | |
---|
[3547] | 269 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: ngp_2dh_l !< toal number of horizontal grid points in statistical region on subdomain |
---|
[1] | 270 | |
---|
[3547] | 271 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: ngp_2dh_outer_l !< number of horizontal non-wall bounded grid points on subdomain |
---|
| 272 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: ngp_2dh_s_inner_l !< number of horizontal non-topography grid points on subdomain |
---|
[1] | 273 | |
---|
[4150] | 274 | |
---|
| 275 | |
---|
[3182] | 276 | REAL(wp), DIMENSION(:), ALLOCATABLE :: init_l !< dummy array used for averaging 3D data to obtain inital profiles |
---|
[2037] | 277 | REAL(wp), DIMENSION(:), ALLOCATABLE :: p_hydrostatic !< hydrostatic pressure |
---|
| 278 | |
---|
| 279 | REAL(wp) :: dx_l !< grid spacing along x on different multigrid level |
---|
| 280 | REAL(wp) :: dy_l !< grid spacing along y on different multigrid level |
---|
| 281 | |
---|
[3547] | 282 | REAL(wp), DIMENSION(1:3) :: volume_flow_area_l !< area of lateral and top model domain surface on local subdomain |
---|
| 283 | REAL(wp), DIMENSION(1:3) :: volume_flow_initial_l !< initial volume flow into model domain |
---|
[1] | 284 | |
---|
[3547] | 285 | REAL(wp), DIMENSION(:), ALLOCATABLE :: mean_surface_level_height_l !< mean surface level height on subdomain |
---|
| 286 | REAL(wp), DIMENSION(:), ALLOCATABLE :: ngp_3d_inner_l !< total number of non-topography grid points on subdomain |
---|
| 287 | REAL(wp), DIMENSION(:), ALLOCATABLE :: ngp_3d_inner_tmp !< total number of non-topography grid points |
---|
[1] | 288 | |
---|
[4150] | 289 | TYPE(real_2d) :: tmp_2d !< temporary variable to input additional surface-data from static file |
---|
| 290 | |
---|
[3987] | 291 | CALL location_message( 'model initialization', 'start' ) |
---|
[4227] | 292 | ! |
---|
| 293 | !-- Set reference date-time |
---|
| 294 | CALL set_reference_date_time( date_time_str=origin_date_time ) |
---|
[3987] | 295 | |
---|
| 296 | IF ( debug_output ) CALL debug_message( 'allocating arrays', 'start' ) |
---|
[1] | 297 | ! |
---|
| 298 | !-- Allocate arrays |
---|
[1788] | 299 | ALLOCATE( mean_surface_level_height(0:statistic_regions), & |
---|
| 300 | mean_surface_level_height_l(0:statistic_regions), & |
---|
| 301 | ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions), & |
---|
| 302 | ngp_3d(0:statistic_regions), & |
---|
| 303 | ngp_3d_inner(0:statistic_regions), & |
---|
| 304 | ngp_3d_inner_l(0:statistic_regions), & |
---|
| 305 | ngp_3d_inner_tmp(0:statistic_regions), & |
---|
| 306 | sums_divnew_l(0:statistic_regions), & |
---|
[1] | 307 | sums_divold_l(0:statistic_regions) ) |
---|
[1195] | 308 | ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) ) |
---|
[1788] | 309 | ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions), & |
---|
| 310 | ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions), & |
---|
| 311 | ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions), & |
---|
| 312 | ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions), & |
---|
| 313 | rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions), & |
---|
[4131] | 314 | sums(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa), & |
---|
| 315 | sums_l(nzb:nzt+1,pr_palm+max_pr_user+max_pr_cs+max_pr_salsa,0:threads_per_task-1), & |
---|
[1788] | 316 | sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1), & |
---|
[3700] | 317 | sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions) ) |
---|
| 318 | ALLOCATE( ts_value(dots_max,0:statistic_regions) ) |
---|
[978] | 319 | ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) ) |
---|
[1] | 320 | |
---|
[1788] | 321 | ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr), & |
---|
| 322 | p(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
[1010] | 323 | tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 324 | |
---|
[2696] | 325 | ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
[1788] | 326 | pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 327 | u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 328 | u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 329 | u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 330 | v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 331 | v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 332 | v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 333 | w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 334 | w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
[667] | 335 | w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1788] | 336 | IF ( .NOT. neutral ) THEN |
---|
[1032] | 337 | ALLOCATE( pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 338 | ENDIF |
---|
[673] | 339 | ! |
---|
[3747] | 340 | !-- Pre-set masks for regional statistics. Default is the total model domain. |
---|
| 341 | !-- Ghost points are excluded because counting values at the ghost boundaries |
---|
| 342 | !-- would bias the statistics |
---|
| 343 | rmask = 1.0_wp |
---|
| 344 | rmask(:,nxlg:nxl-1,:) = 0.0_wp; rmask(:,nxr+1:nxrg,:) = 0.0_wp |
---|
| 345 | rmask(nysg:nys-1,:,:) = 0.0_wp; rmask(nyn+1:nyng,:,:) = 0.0_wp |
---|
| 346 | ! |
---|
[707] | 347 | !-- Following array is required for perturbation pressure within the iterative |
---|
| 348 | !-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds |
---|
| 349 | !-- the weighted average of the substeps and cannot be used in the Poisson |
---|
| 350 | !-- solver. |
---|
| 351 | IF ( psolver == 'sor' ) THEN |
---|
| 352 | ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1575] | 353 | ELSEIF ( psolver(1:9) == 'multigrid' ) THEN |
---|
[707] | 354 | ! |
---|
| 355 | !-- For performance reasons, multigrid is using one ghost layer only |
---|
| 356 | ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) |
---|
[673] | 357 | ENDIF |
---|
[1] | 358 | |
---|
[1111] | 359 | ! |
---|
| 360 | !-- Array for storing constant coeffficients of the tridiagonal solver |
---|
| 361 | IF ( psolver == 'poisfft' ) THEN |
---|
[1212] | 362 | ALLOCATE( tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,2) ) |
---|
[1111] | 363 | ALLOCATE( tric(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) ) |
---|
| 364 | ENDIF |
---|
| 365 | |
---|
[1960] | 366 | IF ( humidity ) THEN |
---|
[1] | 367 | ! |
---|
[1960] | 368 | !-- 3D-humidity |
---|
[1788] | 369 | ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 370 | q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
[3011] | 371 | q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 372 | vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 373 | ENDIF |
---|
[1960] | 374 | |
---|
| 375 | IF ( passive_scalar ) THEN |
---|
[1] | 376 | |
---|
[1960] | 377 | ! |
---|
| 378 | !-- 3D scalar arrays |
---|
| 379 | ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 380 | s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 381 | s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[3636] | 382 | |
---|
[1960] | 383 | ENDIF |
---|
| 384 | |
---|
[1] | 385 | ! |
---|
[3302] | 386 | !-- Allocate and set 1d-profiles for Stokes drift velocity. It may be set to |
---|
| 387 | !-- non-zero values later in ocean_init |
---|
| 388 | ALLOCATE( u_stokes_zu(nzb:nzt+1), u_stokes_zw(nzb:nzt+1), & |
---|
| 389 | v_stokes_zu(nzb:nzt+1), v_stokes_zw(nzb:nzt+1) ) |
---|
| 390 | u_stokes_zu(:) = 0.0_wp |
---|
| 391 | u_stokes_zw(:) = 0.0_wp |
---|
| 392 | v_stokes_zu(:) = 0.0_wp |
---|
| 393 | v_stokes_zw(:) = 0.0_wp |
---|
| 394 | |
---|
| 395 | ! |
---|
[2037] | 396 | !-- Allocation of anelastic and Boussinesq approximation specific arrays |
---|
| 397 | ALLOCATE( p_hydrostatic(nzb:nzt+1) ) |
---|
| 398 | ALLOCATE( rho_air(nzb:nzt+1) ) |
---|
| 399 | ALLOCATE( rho_air_zw(nzb:nzt+1) ) |
---|
| 400 | ALLOCATE( drho_air(nzb:nzt+1) ) |
---|
| 401 | ALLOCATE( drho_air_zw(nzb:nzt+1) ) |
---|
| 402 | ! |
---|
[4088] | 403 | !-- Density profile calculation for anelastic and Boussinesq approximation |
---|
| 404 | !-- In case of a Boussinesq approximation, a constant density is calculated |
---|
| 405 | !-- mainly for output purposes. This density do not need to be considered |
---|
| 406 | !-- in the model's system of equations. |
---|
| 407 | IF ( TRIM( approximation ) == 'anelastic' ) THEN |
---|
[2037] | 408 | DO k = nzb, nzt+1 |
---|
[4088] | 409 | p_hydrostatic(k) = barometric_formula(zu(k), pt_surface * & |
---|
| 410 | exner_function(surface_pressure * 100.0_wp), & |
---|
| 411 | surface_pressure * 100.0_wp) |
---|
| 412 | |
---|
| 413 | rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(k)) |
---|
[2037] | 414 | ENDDO |
---|
[4088] | 415 | |
---|
[2037] | 416 | DO k = nzb, nzt |
---|
| 417 | rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) ) |
---|
| 418 | ENDDO |
---|
[4088] | 419 | |
---|
[2037] | 420 | rho_air_zw(nzt+1) = rho_air_zw(nzt) & |
---|
| 421 | + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt) ) |
---|
[4088] | 422 | |
---|
[2037] | 423 | ELSE |
---|
[2252] | 424 | DO k = nzb, nzt+1 |
---|
[4088] | 425 | p_hydrostatic(k) = barometric_formula(zu(nzb), pt_surface * & |
---|
| 426 | exner_function(surface_pressure * 100.0_wp), & |
---|
| 427 | surface_pressure * 100.0_wp) |
---|
| 428 | |
---|
| 429 | rho_air(k) = ideal_gas_law_rho_pt(p_hydrostatic(k), pt_init(nzb)) |
---|
[2252] | 430 | ENDDO |
---|
[4088] | 431 | |
---|
[2252] | 432 | DO k = nzb, nzt |
---|
| 433 | rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) ) |
---|
| 434 | ENDDO |
---|
[4088] | 435 | |
---|
[2252] | 436 | rho_air_zw(nzt+1) = rho_air_zw(nzt) & |
---|
| 437 | + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt) ) |
---|
[4088] | 438 | |
---|
[2037] | 439 | ENDIF |
---|
[2696] | 440 | ! |
---|
[2037] | 441 | !-- compute the inverse density array in order to avoid expencive divisions |
---|
| 442 | drho_air = 1.0_wp / rho_air |
---|
| 443 | drho_air_zw = 1.0_wp / rho_air_zw |
---|
| 444 | |
---|
| 445 | ! |
---|
| 446 | !-- Allocation of flux conversion arrays |
---|
| 447 | ALLOCATE( heatflux_input_conversion(nzb:nzt+1) ) |
---|
| 448 | ALLOCATE( waterflux_input_conversion(nzb:nzt+1) ) |
---|
| 449 | ALLOCATE( momentumflux_input_conversion(nzb:nzt+1) ) |
---|
| 450 | ALLOCATE( heatflux_output_conversion(nzb:nzt+1) ) |
---|
| 451 | ALLOCATE( waterflux_output_conversion(nzb:nzt+1) ) |
---|
| 452 | ALLOCATE( momentumflux_output_conversion(nzb:nzt+1) ) |
---|
| 453 | |
---|
| 454 | ! |
---|
| 455 | !-- calculate flux conversion factors according to approximation and in-/output mode |
---|
| 456 | DO k = nzb, nzt+1 |
---|
| 457 | |
---|
| 458 | IF ( TRIM( flux_input_mode ) == 'kinematic' ) THEN |
---|
| 459 | heatflux_input_conversion(k) = rho_air_zw(k) |
---|
| 460 | waterflux_input_conversion(k) = rho_air_zw(k) |
---|
| 461 | momentumflux_input_conversion(k) = rho_air_zw(k) |
---|
| 462 | ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN |
---|
[3274] | 463 | heatflux_input_conversion(k) = 1.0_wp / c_p |
---|
[2037] | 464 | waterflux_input_conversion(k) = 1.0_wp / l_v |
---|
| 465 | momentumflux_input_conversion(k) = 1.0_wp |
---|
| 466 | ENDIF |
---|
| 467 | |
---|
| 468 | IF ( TRIM( flux_output_mode ) == 'kinematic' ) THEN |
---|
| 469 | heatflux_output_conversion(k) = drho_air_zw(k) |
---|
| 470 | waterflux_output_conversion(k) = drho_air_zw(k) |
---|
| 471 | momentumflux_output_conversion(k) = drho_air_zw(k) |
---|
| 472 | ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN |
---|
[3274] | 473 | heatflux_output_conversion(k) = c_p |
---|
[2037] | 474 | waterflux_output_conversion(k) = l_v |
---|
| 475 | momentumflux_output_conversion(k) = 1.0_wp |
---|
| 476 | ENDIF |
---|
| 477 | |
---|
| 478 | IF ( .NOT. humidity ) THEN |
---|
| 479 | waterflux_input_conversion(k) = 1.0_wp |
---|
| 480 | waterflux_output_conversion(k) = 1.0_wp |
---|
| 481 | ENDIF |
---|
| 482 | |
---|
| 483 | ENDDO |
---|
| 484 | |
---|
| 485 | ! |
---|
| 486 | !-- In case of multigrid method, compute grid lengths and grid factors for the |
---|
| 487 | !-- grid levels with respective density on each grid |
---|
| 488 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
| 489 | |
---|
| 490 | ALLOCATE( ddx2_mg(maximum_grid_level) ) |
---|
| 491 | ALLOCATE( ddy2_mg(maximum_grid_level) ) |
---|
| 492 | ALLOCATE( dzu_mg(nzb+1:nzt+1,maximum_grid_level) ) |
---|
| 493 | ALLOCATE( dzw_mg(nzb+1:nzt+1,maximum_grid_level) ) |
---|
| 494 | ALLOCATE( f1_mg(nzb+1:nzt,maximum_grid_level) ) |
---|
| 495 | ALLOCATE( f2_mg(nzb+1:nzt,maximum_grid_level) ) |
---|
| 496 | ALLOCATE( f3_mg(nzb+1:nzt,maximum_grid_level) ) |
---|
| 497 | ALLOCATE( rho_air_mg(nzb:nzt+1,maximum_grid_level) ) |
---|
| 498 | ALLOCATE( rho_air_zw_mg(nzb:nzt+1,maximum_grid_level) ) |
---|
| 499 | |
---|
| 500 | dzu_mg(:,maximum_grid_level) = dzu |
---|
| 501 | rho_air_mg(:,maximum_grid_level) = rho_air |
---|
| 502 | ! |
---|
| 503 | !-- Next line to ensure an equally spaced grid. |
---|
| 504 | dzu_mg(1,maximum_grid_level) = dzu(2) |
---|
| 505 | rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) + & |
---|
| 506 | (rho_air(nzb) - rho_air(nzb+1)) |
---|
| 507 | |
---|
| 508 | dzw_mg(:,maximum_grid_level) = dzw |
---|
| 509 | rho_air_zw_mg(:,maximum_grid_level) = rho_air_zw |
---|
| 510 | nzt_l = nzt |
---|
| 511 | DO l = maximum_grid_level-1, 1, -1 |
---|
| 512 | dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1) |
---|
| 513 | dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1) |
---|
| 514 | rho_air_mg(nzb,l) = rho_air_mg(nzb,l+1) + (rho_air_mg(nzb,l+1) - rho_air_mg(nzb+1,l+1)) |
---|
| 515 | rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + (rho_air_zw_mg(nzb,l+1) - rho_air_zw_mg(nzb+1,l+1)) |
---|
| 516 | rho_air_mg(nzb+1,l) = rho_air_mg(nzb+1,l+1) |
---|
| 517 | rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1) |
---|
| 518 | nzt_l = nzt_l / 2 |
---|
| 519 | DO k = 2, nzt_l+1 |
---|
| 520 | dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1) |
---|
| 521 | dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1) |
---|
| 522 | rho_air_mg(k,l) = rho_air_mg(2*k-1,l+1) |
---|
| 523 | rho_air_zw_mg(k,l) = rho_air_zw_mg(2*k-1,l+1) |
---|
| 524 | ENDDO |
---|
| 525 | ENDDO |
---|
| 526 | |
---|
| 527 | nzt_l = nzt |
---|
| 528 | dx_l = dx |
---|
| 529 | dy_l = dy |
---|
| 530 | DO l = maximum_grid_level, 1, -1 |
---|
| 531 | ddx2_mg(l) = 1.0_wp / dx_l**2 |
---|
| 532 | ddy2_mg(l) = 1.0_wp / dy_l**2 |
---|
| 533 | DO k = nzb+1, nzt_l |
---|
| 534 | f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) ) |
---|
| 535 | f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l) * dzw_mg(k,l) ) |
---|
| 536 | f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) ) & |
---|
| 537 | * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l) |
---|
| 538 | ENDDO |
---|
| 539 | nzt_l = nzt_l / 2 |
---|
| 540 | dx_l = dx_l * 2.0_wp |
---|
| 541 | dy_l = dy_l * 2.0_wp |
---|
| 542 | ENDDO |
---|
| 543 | |
---|
| 544 | ENDIF |
---|
| 545 | |
---|
| 546 | ! |
---|
[1299] | 547 | !-- 1D-array for large scale subsidence velocity |
---|
[1361] | 548 | IF ( .NOT. ALLOCATED( w_subs ) ) THEN |
---|
| 549 | ALLOCATE ( w_subs(nzb:nzt+1) ) |
---|
| 550 | w_subs = 0.0_wp |
---|
| 551 | ENDIF |
---|
[1299] | 552 | |
---|
| 553 | ! |
---|
[106] | 554 | !-- Arrays to store velocity data from t-dt and the phase speeds which |
---|
| 555 | !-- are needed for radiation boundary conditions |
---|
[3182] | 556 | IF ( bc_radiation_l ) THEN |
---|
[1788] | 557 | ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2), & |
---|
| 558 | v_m_l(nzb:nzt+1,nysg:nyng,0:1), & |
---|
[667] | 559 | w_m_l(nzb:nzt+1,nysg:nyng,0:1) ) |
---|
[73] | 560 | ENDIF |
---|
[3182] | 561 | IF ( bc_radiation_r ) THEN |
---|
[1788] | 562 | ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx), & |
---|
| 563 | v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx), & |
---|
[667] | 564 | w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) ) |
---|
[73] | 565 | ENDIF |
---|
[3182] | 566 | IF ( bc_radiation_l .OR. bc_radiation_r ) THEN |
---|
[1788] | 567 | ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng), & |
---|
[667] | 568 | c_w(nzb:nzt+1,nysg:nyng) ) |
---|
[106] | 569 | ENDIF |
---|
[3182] | 570 | IF ( bc_radiation_s ) THEN |
---|
[1788] | 571 | ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg), & |
---|
| 572 | v_m_s(nzb:nzt+1,1:2,nxlg:nxrg), & |
---|
[667] | 573 | w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) ) |
---|
[73] | 574 | ENDIF |
---|
[3182] | 575 | IF ( bc_radiation_n ) THEN |
---|
[1788] | 576 | ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg), & |
---|
| 577 | v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg), & |
---|
[667] | 578 | w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) ) |
---|
[73] | 579 | ENDIF |
---|
[3182] | 580 | IF ( bc_radiation_s .OR. bc_radiation_n ) THEN |
---|
[1788] | 581 | ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg), & |
---|
[667] | 582 | c_w(nzb:nzt+1,nxlg:nxrg) ) |
---|
[106] | 583 | ENDIF |
---|
[3182] | 584 | IF ( bc_radiation_l .OR. bc_radiation_r .OR. bc_radiation_s .OR. & |
---|
| 585 | bc_radiation_n ) THEN |
---|
[978] | 586 | ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) ) |
---|
| 587 | ALLOCATE( c_u_m(nzb:nzt+1), c_v_m(nzb:nzt+1), c_w_m(nzb:nzt+1) ) |
---|
| 588 | ENDIF |
---|
[73] | 589 | |
---|
| 590 | ! |
---|
[1] | 591 | !-- Initial assignment of the pointers |
---|
[1032] | 592 | IF ( .NOT. neutral ) THEN |
---|
| 593 | pt => pt_1; pt_p => pt_2; tpt_m => pt_3 |
---|
| 594 | ELSE |
---|
| 595 | pt => pt_1; pt_p => pt_1; tpt_m => pt_3 |
---|
| 596 | ENDIF |
---|
[1001] | 597 | u => u_1; u_p => u_2; tu_m => u_3 |
---|
| 598 | v => v_1; v_p => v_2; tv_m => v_3 |
---|
| 599 | w => w_1; w_p => w_2; tw_m => w_3 |
---|
[1] | 600 | |
---|
[1960] | 601 | IF ( humidity ) THEN |
---|
[1001] | 602 | q => q_1; q_p => q_2; tq_m => q_3 |
---|
[3274] | 603 | vpt => vpt_1 |
---|
[1001] | 604 | ENDIF |
---|
[1960] | 605 | |
---|
| 606 | IF ( passive_scalar ) THEN |
---|
| 607 | s => s_1; s_p => s_2; ts_m => s_3 |
---|
| 608 | ENDIF |
---|
[1] | 609 | |
---|
| 610 | ! |
---|
[2696] | 611 | !-- Initialize surface arrays |
---|
[2232] | 612 | CALL init_surface_arrays |
---|
| 613 | ! |
---|
[3294] | 614 | !-- Allocate arrays for other modules |
---|
[3685] | 615 | CALL module_interface_init_arrays |
---|
[1551] | 616 | |
---|
[1914] | 617 | |
---|
[2320] | 618 | ! |
---|
[709] | 619 | !-- Allocate arrays containing the RK coefficient for calculation of |
---|
| 620 | !-- perturbation pressure and turbulent fluxes. At this point values are |
---|
| 621 | !-- set for pressure calculation during initialization (where no timestep |
---|
| 622 | !-- is done). Further below the values needed within the timestep scheme |
---|
| 623 | !-- will be set. |
---|
[1788] | 624 | ALLOCATE( weight_substep(1:intermediate_timestep_count_max), & |
---|
[1878] | 625 | weight_pres(1:intermediate_timestep_count_max) ) |
---|
[1340] | 626 | weight_substep = 1.0_wp |
---|
| 627 | weight_pres = 1.0_wp |
---|
[1918] | 628 | intermediate_timestep_count = 0 ! needed when simulated_time = 0.0 |
---|
[673] | 629 | |
---|
[3987] | 630 | IF ( debug_output ) CALL debug_message( 'allocating arrays', 'end' ) |
---|
[1918] | 631 | |
---|
[673] | 632 | ! |
---|
[3014] | 633 | !-- Initialize time series |
---|
| 634 | ts_value = 0.0_wp |
---|
| 635 | |
---|
| 636 | ! |
---|
[1918] | 637 | !-- Initialize local summation arrays for routine flow_statistics. |
---|
| 638 | !-- This is necessary because they may not yet have been initialized when they |
---|
| 639 | !-- are called from flow_statistics (or - depending on the chosen model run - |
---|
| 640 | !-- are never initialized) |
---|
| 641 | sums_divnew_l = 0.0_wp |
---|
| 642 | sums_divold_l = 0.0_wp |
---|
| 643 | sums_l_l = 0.0_wp |
---|
| 644 | sums_wsts_bc_l = 0.0_wp |
---|
[3182] | 645 | |
---|
[1918] | 646 | ! |
---|
[1] | 647 | !-- Initialize model variables |
---|
[1788] | 648 | IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND. & |
---|
[328] | 649 | TRIM( initializing_actions ) /= 'cyclic_fill' ) THEN |
---|
[1] | 650 | ! |
---|
[2696] | 651 | !-- Initialization with provided input data derived from larger-scale model |
---|
| 652 | IF ( INDEX( initializing_actions, 'inifor' ) /= 0 ) THEN |
---|
[3987] | 653 | IF ( debug_output ) CALL debug_message( 'initializing with INIFOR', 'start' ) |
---|
[2696] | 654 | ! |
---|
[3051] | 655 | !-- Read initial 1D profiles or 3D data from NetCDF file, depending |
---|
| 656 | !-- on the provided level-of-detail. |
---|
[2696] | 657 | !-- At the moment, only u, v, w, pt and q are provided. |
---|
| 658 | CALL netcdf_data_input_init_3d |
---|
| 659 | ! |
---|
[3182] | 660 | !-- Please note, Inifor provides data from nzb+1 to nzt. |
---|
| 661 | !-- Bottom and top boundary conditions for Inifor profiles are already |
---|
| 662 | !-- set (just after reading), so that this is not necessary here. |
---|
| 663 | !-- Depending on the provided level-of-detail, initial Inifor data is |
---|
| 664 | !-- either stored on data type (lod=1), or directly on 3D arrays (lod=2). |
---|
| 665 | !-- In order to obtain also initial profiles in case of lod=2 (which |
---|
| 666 | !-- is required for e.g. damping), average over 3D data. |
---|
| 667 | IF( init_3d%lod_u == 1 ) THEN |
---|
| 668 | u_init = init_3d%u_init |
---|
| 669 | ELSEIF( init_3d%lod_u == 2 ) THEN |
---|
| 670 | ALLOCATE( init_l(nzb:nzt+1) ) |
---|
| 671 | DO k = nzb, nzt+1 |
---|
| 672 | init_l(k) = SUM( u(k,nys:nyn,nxl:nxr) ) |
---|
| 673 | ENDDO |
---|
| 674 | init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp ) |
---|
[1384] | 675 | |
---|
[3182] | 676 | #if defined( __parallel ) |
---|
| 677 | CALL MPI_ALLREDUCE( init_l, u_init, nzt+1-nzb+1, & |
---|
| 678 | MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 679 | #else |
---|
| 680 | u_init = init_l |
---|
| 681 | #endif |
---|
| 682 | DEALLOCATE( init_l ) |
---|
[3051] | 683 | |
---|
[2696] | 684 | ENDIF |
---|
[3182] | 685 | |
---|
| 686 | IF( init_3d%lod_v == 1 ) THEN |
---|
| 687 | v_init = init_3d%v_init |
---|
| 688 | ELSEIF( init_3d%lod_v == 2 ) THEN |
---|
| 689 | ALLOCATE( init_l(nzb:nzt+1) ) |
---|
| 690 | DO k = nzb, nzt+1 |
---|
| 691 | init_l(k) = SUM( v(k,nys:nyn,nxl:nxr) ) |
---|
| 692 | ENDDO |
---|
| 693 | init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp ) |
---|
[2696] | 694 | |
---|
[3182] | 695 | #if defined( __parallel ) |
---|
| 696 | CALL MPI_ALLREDUCE( init_l, v_init, nzt+1-nzb+1, & |
---|
| 697 | MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 698 | #else |
---|
| 699 | v_init = init_l |
---|
| 700 | #endif |
---|
| 701 | DEALLOCATE( init_l ) |
---|
| 702 | ENDIF |
---|
| 703 | IF( .NOT. neutral ) THEN |
---|
| 704 | IF( init_3d%lod_pt == 1 ) THEN |
---|
| 705 | pt_init = init_3d%pt_init |
---|
| 706 | ELSEIF( init_3d%lod_pt == 2 ) THEN |
---|
| 707 | ALLOCATE( init_l(nzb:nzt+1) ) |
---|
| 708 | DO k = nzb, nzt+1 |
---|
| 709 | init_l(k) = SUM( pt(k,nys:nyn,nxl:nxr) ) |
---|
| 710 | ENDDO |
---|
| 711 | init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp ) |
---|
| 712 | |
---|
| 713 | #if defined( __parallel ) |
---|
| 714 | CALL MPI_ALLREDUCE( init_l, pt_init, nzt+1-nzb+1, & |
---|
| 715 | MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 716 | #else |
---|
| 717 | pt_init = init_l |
---|
| 718 | #endif |
---|
| 719 | DEALLOCATE( init_l ) |
---|
| 720 | ENDIF |
---|
| 721 | ENDIF |
---|
| 722 | |
---|
| 723 | |
---|
| 724 | IF( humidity ) THEN |
---|
| 725 | IF( init_3d%lod_q == 1 ) THEN |
---|
| 726 | q_init = init_3d%q_init |
---|
| 727 | ELSEIF( init_3d%lod_q == 2 ) THEN |
---|
| 728 | ALLOCATE( init_l(nzb:nzt+1) ) |
---|
| 729 | DO k = nzb, nzt+1 |
---|
| 730 | init_l(k) = SUM( q(k,nys:nyn,nxl:nxr) ) |
---|
| 731 | ENDDO |
---|
| 732 | init_l = init_l / REAL( ( nx + 1 ) * ( ny + 1 ), KIND = wp ) |
---|
| 733 | |
---|
| 734 | #if defined( __parallel ) |
---|
| 735 | CALL MPI_ALLREDUCE( init_l, q_init, nzt+1-nzb+1, & |
---|
| 736 | MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 737 | #else |
---|
| 738 | q_init = init_l |
---|
| 739 | #endif |
---|
| 740 | DEALLOCATE( init_l ) |
---|
| 741 | ENDIF |
---|
| 742 | ENDIF |
---|
| 743 | |
---|
[2696] | 744 | ! |
---|
[4130] | 745 | !-- Write initial profiles onto 3D arrays. |
---|
| 746 | !-- Work-around, 3D initialization of u,v,w creates artificial |
---|
| 747 | !-- structures wich correlate with the processor grid. The reason |
---|
| 748 | !-- for this is still unknown. To work-around this, 3D initialization |
---|
| 749 | !-- will be effectively reduce to a 1D initialization where no such |
---|
| 750 | !-- artificial structures appear. |
---|
[2696] | 751 | DO i = nxlg, nxrg |
---|
| 752 | DO j = nysg, nyng |
---|
[4130] | 753 | IF( init_3d%lod_u == 1 .OR. init_3d%lod_u == 2 ) & |
---|
| 754 | u(:,j,i) = u_init(:) |
---|
| 755 | IF( init_3d%lod_v == 1 .OR. init_3d%lod_u == 2 ) & |
---|
| 756 | v(:,j,i) = v_init(:) |
---|
| 757 | IF( .NOT. neutral .AND. & |
---|
| 758 | ( init_3d%lod_pt == 1 .OR. init_3d%lod_pt == 2 ) ) & |
---|
[3051] | 759 | pt(:,j,i) = pt_init(:) |
---|
[4130] | 760 | IF( humidity .AND. & |
---|
| 761 | ( init_3d%lod_q == 1 .OR. init_3d%lod_q == 2 ) ) & |
---|
| 762 | q(:,j,i) = q_init(:) |
---|
[2696] | 763 | ENDDO |
---|
| 764 | ENDDO |
---|
| 765 | ! |
---|
[3182] | 766 | !-- Set geostrophic wind components. |
---|
[2938] | 767 | IF ( init_3d%from_file_ug ) THEN |
---|
| 768 | ug(:) = init_3d%ug_init(:) |
---|
| 769 | ENDIF |
---|
| 770 | IF ( init_3d%from_file_vg ) THEN |
---|
| 771 | vg(:) = init_3d%vg_init(:) |
---|
| 772 | ENDIF |
---|
[3404] | 773 | ! |
---|
| 774 | !-- Set bottom and top boundary condition for geostrophic wind |
---|
[2938] | 775 | ug(nzt+1) = ug(nzt) |
---|
| 776 | vg(nzt+1) = vg(nzt) |
---|
[3404] | 777 | ug(nzb) = ug(nzb+1) |
---|
| 778 | vg(nzb) = vg(nzb+1) |
---|
[2696] | 779 | ! |
---|
| 780 | !-- Set inital w to 0 |
---|
| 781 | w = 0.0_wp |
---|
| 782 | |
---|
| 783 | IF ( passive_scalar ) THEN |
---|
| 784 | DO i = nxlg, nxrg |
---|
| 785 | DO j = nysg, nyng |
---|
| 786 | s(:,j,i) = s_init |
---|
| 787 | ENDDO |
---|
| 788 | ENDDO |
---|
| 789 | ENDIF |
---|
| 790 | |
---|
| 791 | ! |
---|
| 792 | !-- Set velocity components at non-atmospheric / oceanic grid points to |
---|
| 793 | !-- zero. |
---|
[4346] | 794 | u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) ) |
---|
| 795 | v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) ) |
---|
| 796 | w = MERGE( w, 0.0_wp, BTEST( wall_flags_total_0, 3 ) ) |
---|
[2700] | 797 | ! |
---|
| 798 | !-- Initialize surface variables, e.g. friction velocity, momentum |
---|
| 799 | !-- fluxes, etc. |
---|
| 800 | CALL init_surfaces |
---|
[2696] | 801 | |
---|
[3987] | 802 | IF ( debug_output ) CALL debug_message( 'initializing with INIFOR', 'end' ) |
---|
[2696] | 803 | ! |
---|
| 804 | !-- Initialization via computed 1D-model profiles |
---|
| 805 | ELSEIF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 ) THEN |
---|
| 806 | |
---|
[3987] | 807 | IF ( debug_output ) CALL debug_message( 'initializing with 1D model profiles', 'start' ) |
---|
[1] | 808 | ! |
---|
| 809 | !-- Use solutions of the 1D model as initial profiles, |
---|
| 810 | !-- start 1D model |
---|
| 811 | CALL init_1d_model |
---|
| 812 | ! |
---|
| 813 | !-- Transfer initial profiles to the arrays of the 3D model |
---|
[667] | 814 | DO i = nxlg, nxrg |
---|
| 815 | DO j = nysg, nyng |
---|
[1] | 816 | pt(:,j,i) = pt_init |
---|
| 817 | u(:,j,i) = u1d |
---|
| 818 | v(:,j,i) = v1d |
---|
| 819 | ENDDO |
---|
| 820 | ENDDO |
---|
| 821 | |
---|
[1960] | 822 | IF ( humidity ) THEN |
---|
[667] | 823 | DO i = nxlg, nxrg |
---|
| 824 | DO j = nysg, nyng |
---|
[1] | 825 | q(:,j,i) = q_init |
---|
| 826 | ENDDO |
---|
| 827 | ENDDO |
---|
| 828 | ENDIF |
---|
[2292] | 829 | |
---|
[1960] | 830 | IF ( passive_scalar ) THEN |
---|
| 831 | DO i = nxlg, nxrg |
---|
| 832 | DO j = nysg, nyng |
---|
| 833 | s(:,j,i) = s_init |
---|
| 834 | ENDDO |
---|
| 835 | ENDDO |
---|
| 836 | ENDIF |
---|
[1] | 837 | ! |
---|
| 838 | !-- Store initial profiles for output purposes etc. |
---|
[2696] | 839 | IF ( .NOT. constant_diffusion ) THEN |
---|
[1] | 840 | hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 ) |
---|
| 841 | ENDIF |
---|
| 842 | ! |
---|
[2696] | 843 | !-- Set velocities back to zero |
---|
[4346] | 844 | u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) ) |
---|
| 845 | v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) ) |
---|
[1] | 846 | ! |
---|
[2696] | 847 | !-- WARNING: The extra boundary conditions set after running the |
---|
| 848 | !-- ------- 1D model impose an error on the divergence one layer |
---|
| 849 | !-- below the topography; need to correct later |
---|
| 850 | !-- ATTENTION: Provisional correction for Piacsek & Williams |
---|
| 851 | !-- --------- advection scheme: keep u and v zero one layer below |
---|
| 852 | !-- the topography. |
---|
| 853 | IF ( ibc_uv_b == 1 ) THEN |
---|
[667] | 854 | ! |
---|
[2696] | 855 | !-- Neumann condition |
---|
| 856 | DO i = nxl-1, nxr+1 |
---|
| 857 | DO j = nys-1, nyn+1 |
---|
| 858 | u(nzb,j,i) = u(nzb+1,j,i) |
---|
| 859 | v(nzb,j,i) = v(nzb+1,j,i) |
---|
[1] | 860 | ENDDO |
---|
[2696] | 861 | ENDDO |
---|
[1] | 862 | |
---|
| 863 | ENDIF |
---|
[2618] | 864 | ! |
---|
| 865 | !-- Initialize surface variables, e.g. friction velocity, momentum |
---|
| 866 | !-- fluxes, etc. |
---|
| 867 | CALL init_surfaces |
---|
[1] | 868 | |
---|
[3987] | 869 | IF ( debug_output ) CALL debug_message( 'initializing with 1D model profiles', 'end' ) |
---|
[1384] | 870 | |
---|
[1788] | 871 | ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 ) & |
---|
[1] | 872 | THEN |
---|
[1241] | 873 | |
---|
[3987] | 874 | IF ( debug_output ) CALL debug_message( 'initializing with constant profiles', 'start' ) |
---|
[2259] | 875 | |
---|
| 876 | ! |
---|
[1] | 877 | !-- Use constructed initial profiles (velocity constant with height, |
---|
| 878 | !-- temperature profile with constant gradient) |
---|
[667] | 879 | DO i = nxlg, nxrg |
---|
| 880 | DO j = nysg, nyng |
---|
[1] | 881 | pt(:,j,i) = pt_init |
---|
| 882 | u(:,j,i) = u_init |
---|
| 883 | v(:,j,i) = v_init |
---|
| 884 | ENDDO |
---|
| 885 | ENDDO |
---|
| 886 | ! |
---|
[2758] | 887 | !-- Mask topography |
---|
[4346] | 888 | u = MERGE( u, 0.0_wp, BTEST( wall_flags_total_0, 1 ) ) |
---|
| 889 | v = MERGE( v, 0.0_wp, BTEST( wall_flags_total_0, 2 ) ) |
---|
[2758] | 890 | ! |
---|
[292] | 891 | !-- Set initial horizontal velocities at the lowest computational grid |
---|
| 892 | !-- levels to zero in order to avoid too small time steps caused by the |
---|
| 893 | !-- diffusion limit in the initial phase of a run (at k=1, dz/2 occurs |
---|
[2758] | 894 | !-- in the limiting formula!). |
---|
| 895 | !-- Please note, in case land- or urban-surface model is used and a |
---|
| 896 | !-- spinup is applied, masking the lowest computational level is not |
---|
| 897 | !-- possible as MOST as well as energy-balance parametrizations will not |
---|
| 898 | !-- work with zero wind velocity. |
---|
| 899 | IF ( ibc_uv_b /= 1 .AND. .NOT. spinup ) THEN |
---|
[1815] | 900 | DO i = nxlg, nxrg |
---|
| 901 | DO j = nysg, nyng |
---|
[2232] | 902 | DO k = nzb, nzt |
---|
| 903 | u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, & |
---|
[4346] | 904 | BTEST( wall_flags_total_0(k,j,i), 20 ) ) |
---|
[2232] | 905 | v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, & |
---|
[4346] | 906 | BTEST( wall_flags_total_0(k,j,i), 21 ) ) |
---|
[2232] | 907 | ENDDO |
---|
[1815] | 908 | ENDDO |
---|
| 909 | ENDDO |
---|
| 910 | ENDIF |
---|
[1] | 911 | |
---|
[1960] | 912 | IF ( humidity ) THEN |
---|
[667] | 913 | DO i = nxlg, nxrg |
---|
| 914 | DO j = nysg, nyng |
---|
[1] | 915 | q(:,j,i) = q_init |
---|
| 916 | ENDDO |
---|
| 917 | ENDDO |
---|
| 918 | ENDIF |
---|
[1960] | 919 | |
---|
| 920 | IF ( passive_scalar ) THEN |
---|
| 921 | DO i = nxlg, nxrg |
---|
| 922 | DO j = nysg, nyng |
---|
| 923 | s(:,j,i) = s_init |
---|
| 924 | ENDDO |
---|
| 925 | ENDDO |
---|
| 926 | ENDIF |
---|
[1] | 927 | |
---|
[1920] | 928 | ! |
---|
[1] | 929 | !-- Compute initial temperature field and other constants used in case |
---|
| 930 | !-- of a sloping surface |
---|
| 931 | IF ( sloping_surface ) CALL init_slope |
---|
[2618] | 932 | ! |
---|
| 933 | !-- Initialize surface variables, e.g. friction velocity, momentum |
---|
| 934 | !-- fluxes, etc. |
---|
| 935 | CALL init_surfaces |
---|
[3579] | 936 | |
---|
[3987] | 937 | IF ( debug_output ) CALL debug_message( 'initializing with constant profiles', 'end' ) |
---|
[1384] | 938 | |
---|
[1788] | 939 | ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 ) & |
---|
[46] | 940 | THEN |
---|
[1384] | 941 | |
---|
[3987] | 942 | IF ( debug_output ) CALL debug_message( 'initializing by user', 'start' ) |
---|
[46] | 943 | ! |
---|
[2618] | 944 | !-- Pre-initialize surface variables, i.e. setting start- and end-indices |
---|
| 945 | !-- at each (j,i)-location. Please note, this does not supersede |
---|
| 946 | !-- user-defined initialization of surface quantities. |
---|
| 947 | CALL init_surfaces |
---|
| 948 | ! |
---|
[46] | 949 | !-- Initialization will completely be done by the user |
---|
| 950 | CALL user_init_3d_model |
---|
| 951 | |
---|
[3987] | 952 | IF ( debug_output ) CALL debug_message( 'initializing by user', 'end' ) |
---|
[1384] | 953 | |
---|
[1] | 954 | ENDIF |
---|
[1384] | 955 | |
---|
[3987] | 956 | IF ( debug_output ) CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'start' ) |
---|
[1384] | 957 | |
---|
[667] | 958 | ! |
---|
| 959 | !-- Bottom boundary |
---|
| 960 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN |
---|
[1340] | 961 | u(nzb,:,:) = 0.0_wp |
---|
| 962 | v(nzb,:,:) = 0.0_wp |
---|
[667] | 963 | ENDIF |
---|
[1] | 964 | |
---|
| 965 | ! |
---|
[151] | 966 | !-- Apply channel flow boundary condition |
---|
[132] | 967 | IF ( TRIM( bc_uv_t ) == 'dirichlet_0' ) THEN |
---|
[1340] | 968 | u(nzt+1,:,:) = 0.0_wp |
---|
| 969 | v(nzt+1,:,:) = 0.0_wp |
---|
[132] | 970 | ENDIF |
---|
| 971 | |
---|
| 972 | ! |
---|
[1] | 973 | !-- Calculate virtual potential temperature |
---|
[1960] | 974 | IF ( humidity ) vpt = pt * ( 1.0_wp + 0.61_wp * q ) |
---|
[1] | 975 | |
---|
| 976 | ! |
---|
[2696] | 977 | !-- Store initial profiles for output purposes etc.. Please note, in case of |
---|
| 978 | !-- initialization of u, v, w, pt, and q via output data derived from larger |
---|
| 979 | !-- scale models, data will not be horizontally homogeneous. Actually, a mean |
---|
| 980 | !-- profile should be calculated before. |
---|
[1] | 981 | hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 ) |
---|
| 982 | hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 ) |
---|
[667] | 983 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2) THEN |
---|
[1340] | 984 | hom(nzb,1,5,:) = 0.0_wp |
---|
| 985 | hom(nzb,1,6,:) = 0.0_wp |
---|
[1] | 986 | ENDIF |
---|
| 987 | hom(:,1,7,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 ) |
---|
| 988 | |
---|
[75] | 989 | IF ( humidity ) THEN |
---|
[1] | 990 | ! |
---|
| 991 | !-- Store initial profile of total water content, virtual potential |
---|
| 992 | !-- temperature |
---|
| 993 | hom(:,1,26,:) = SPREAD( q(:,nys,nxl), 2, statistic_regions+1 ) |
---|
| 994 | hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 ) |
---|
[2696] | 995 | ! |
---|
[3040] | 996 | !-- Store initial profile of mixing ratio and potential |
---|
[2696] | 997 | !-- temperature |
---|
[3274] | 998 | IF ( bulk_cloud_model .OR. cloud_droplets ) THEN |
---|
[1] | 999 | hom(:,1,27,:) = SPREAD( q(:,nys,nxl), 2, statistic_regions+1 ) |
---|
| 1000 | hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 ) |
---|
| 1001 | ENDIF |
---|
| 1002 | ENDIF |
---|
| 1003 | |
---|
[2696] | 1004 | ! |
---|
| 1005 | !-- Store initial scalar profile |
---|
[1] | 1006 | IF ( passive_scalar ) THEN |
---|
[2513] | 1007 | hom(:,1,121,:) = SPREAD( s(:,nys,nxl), 2, statistic_regions+1 ) |
---|
[1] | 1008 | ENDIF |
---|
| 1009 | |
---|
| 1010 | ! |
---|
[1400] | 1011 | !-- Initialize the random number generators (from numerical recipes) |
---|
| 1012 | CALL random_function_ini |
---|
[1429] | 1013 | |
---|
[1400] | 1014 | IF ( random_generator == 'random-parallel' ) THEN |
---|
[3241] | 1015 | CALL init_parallel_random_generator( nx, nys, nyn, nxl, nxr ) |
---|
[1400] | 1016 | ENDIF |
---|
| 1017 | ! |
---|
[1179] | 1018 | !-- Set the reference state to be used in the buoyancy terms (for ocean runs |
---|
| 1019 | !-- the reference state will be set (overwritten) in init_ocean) |
---|
| 1020 | IF ( use_single_reference_value ) THEN |
---|
[1788] | 1021 | IF ( .NOT. humidity ) THEN |
---|
[1179] | 1022 | ref_state(:) = pt_reference |
---|
| 1023 | ELSE |
---|
| 1024 | ref_state(:) = vpt_reference |
---|
| 1025 | ENDIF |
---|
| 1026 | ELSE |
---|
[1788] | 1027 | IF ( .NOT. humidity ) THEN |
---|
[1179] | 1028 | ref_state(:) = pt_init(:) |
---|
| 1029 | ELSE |
---|
| 1030 | ref_state(:) = vpt(:,nys,nxl) |
---|
| 1031 | ENDIF |
---|
| 1032 | ENDIF |
---|
[152] | 1033 | |
---|
| 1034 | ! |
---|
[707] | 1035 | !-- For the moment, vertical velocity is zero |
---|
[1340] | 1036 | w = 0.0_wp |
---|
[1] | 1037 | |
---|
| 1038 | ! |
---|
| 1039 | !-- Initialize array sums (must be defined in first call of pres) |
---|
[1340] | 1040 | sums = 0.0_wp |
---|
[1] | 1041 | |
---|
| 1042 | ! |
---|
[707] | 1043 | !-- In case of iterative solvers, p must get an initial value |
---|
[1575] | 1044 | IF ( psolver(1:9) == 'multigrid' .OR. psolver == 'sor' ) p = 0.0_wp |
---|
[707] | 1045 | ! |
---|
[1] | 1046 | !-- Impose vortex with vertical axis on the initial velocity profile |
---|
| 1047 | IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 ) THEN |
---|
| 1048 | CALL init_rankine |
---|
| 1049 | ENDIF |
---|
| 1050 | |
---|
| 1051 | ! |
---|
[3035] | 1052 | !-- Impose temperature anomaly (advection test only) or warm air bubble |
---|
| 1053 | !-- close to surface |
---|
| 1054 | IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 .OR. & |
---|
| 1055 | INDEX( initializing_actions, 'initialize_bubble' ) /= 0 ) THEN |
---|
[1] | 1056 | CALL init_pt_anomaly |
---|
| 1057 | ENDIF |
---|
[3035] | 1058 | |
---|
[1] | 1059 | ! |
---|
| 1060 | !-- If required, change the surface temperature at the start of the 3D run |
---|
[1340] | 1061 | IF ( pt_surface_initial_change /= 0.0_wp ) THEN |
---|
[1] | 1062 | pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change |
---|
| 1063 | ENDIF |
---|
| 1064 | |
---|
| 1065 | ! |
---|
| 1066 | !-- If required, change the surface humidity/scalar at the start of the 3D |
---|
| 1067 | !-- run |
---|
[1960] | 1068 | IF ( humidity .AND. q_surface_initial_change /= 0.0_wp ) & |
---|
[1] | 1069 | q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change |
---|
[1960] | 1070 | |
---|
| 1071 | IF ( passive_scalar .AND. s_surface_initial_change /= 0.0_wp ) & |
---|
| 1072 | s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change |
---|
| 1073 | |
---|
[1] | 1074 | |
---|
| 1075 | ! |
---|
| 1076 | !-- Initialize old and new time levels. |
---|
[2696] | 1077 | tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp |
---|
| 1078 | pt_p = pt; u_p = u; v_p = v; w_p = w |
---|
[1] | 1079 | |
---|
[1960] | 1080 | IF ( humidity ) THEN |
---|
[1340] | 1081 | tq_m = 0.0_wp |
---|
[1] | 1082 | q_p = q |
---|
| 1083 | ENDIF |
---|
[1960] | 1084 | |
---|
| 1085 | IF ( passive_scalar ) THEN |
---|
| 1086 | ts_m = 0.0_wp |
---|
| 1087 | s_p = s |
---|
| 1088 | ENDIF |
---|
[1] | 1089 | |
---|
[3987] | 1090 | IF ( debug_output ) CALL debug_message( 'initializing statistics, boundary conditions, etc.', 'end' ) |
---|
[94] | 1091 | |
---|
[1788] | 1092 | ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data' .OR. & |
---|
[2232] | 1093 | TRIM( initializing_actions ) == 'cyclic_fill' ) & |
---|
[1] | 1094 | THEN |
---|
[1384] | 1095 | |
---|
[3987] | 1096 | IF ( debug_output ) CALL debug_message( 'initializing in case of restart / cyclic_fill', 'start' ) |
---|
[1] | 1097 | ! |
---|
[3609] | 1098 | !-- Initialize surface elements and its attributes, e.g. heat- and |
---|
| 1099 | !-- momentumfluxes, roughness, scaling parameters. As number of surface |
---|
| 1100 | !-- elements might be different between runs, e.g. in case of cyclic fill, |
---|
| 1101 | !-- and not all surface elements are read, surface elements need to be |
---|
| 1102 | !-- initialized before. |
---|
| 1103 | !-- Please note, in case of cyclic fill, surfaces should be initialized |
---|
| 1104 | !-- after restart data is read, else, individual settings of surface |
---|
| 1105 | !-- parameters will be overwritten from data of precursor run, hence, |
---|
| 1106 | !-- init_surfaces is called a second time after reading the restart data. |
---|
| 1107 | CALL init_surfaces |
---|
| 1108 | ! |
---|
[767] | 1109 | !-- When reading data for cyclic fill of 3D prerun data files, read |
---|
| 1110 | !-- some of the global variables from the restart file which are required |
---|
| 1111 | !-- for initializing the inflow |
---|
[328] | 1112 | IF ( TRIM( initializing_actions ) == 'cyclic_fill' ) THEN |
---|
[559] | 1113 | |
---|
[759] | 1114 | DO i = 0, io_blocks-1 |
---|
| 1115 | IF ( i == io_group ) THEN |
---|
[2894] | 1116 | CALL rrd_read_parts_of_global |
---|
[759] | 1117 | ENDIF |
---|
| 1118 | #if defined( __parallel ) |
---|
| 1119 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1120 | #endif |
---|
| 1121 | ENDDO |
---|
[328] | 1122 | |
---|
[767] | 1123 | ENDIF |
---|
| 1124 | |
---|
[151] | 1125 | ! |
---|
[2894] | 1126 | !-- Read processor specific binary data from restart file |
---|
[767] | 1127 | DO i = 0, io_blocks-1 |
---|
| 1128 | IF ( i == io_group ) THEN |
---|
[2894] | 1129 | CALL rrd_local |
---|
[767] | 1130 | ENDIF |
---|
| 1131 | #if defined( __parallel ) |
---|
| 1132 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1133 | #endif |
---|
| 1134 | ENDDO |
---|
[4365] | 1135 | |
---|
| 1136 | |
---|
| 1137 | IF ( TRIM( initializing_actions ) == 'cyclic_fill' ) THEN |
---|
| 1138 | |
---|
[3608] | 1139 | ! |
---|
[4365] | 1140 | !-- In case of cyclic fill, call init_surfaces a second time, so that |
---|
| 1141 | !-- surface properties such as heat fluxes are initialized as prescribed. |
---|
[3609] | 1142 | CALL init_surfaces |
---|
[767] | 1143 | |
---|
[328] | 1144 | ! |
---|
[4365] | 1145 | !-- Overwrite u_init, v_init, pt_init, q_init and s_init with the |
---|
| 1146 | !-- horizontally mean (hom) vertical profiles from the end |
---|
| 1147 | !-- of the prerun, because these profiles shall be used as the reference |
---|
| 1148 | !-- state for the rayleigh damping and the pt_damping. This is especially |
---|
| 1149 | !-- important for the use of large_scale_subsidence, because the |
---|
| 1150 | !-- reference temperature in the free atmosphere changes in time. |
---|
| 1151 | u_init(:) = hom_sum(:,1,0) |
---|
| 1152 | v_init(:) = hom_sum(:,2,0) |
---|
| 1153 | pt_init(:) = hom_sum(:,4,0) |
---|
| 1154 | IF ( humidity ) & |
---|
| 1155 | q_init(:) = hom_sum(:,41,0) |
---|
| 1156 | IF ( passive_scalar ) & |
---|
| 1157 | s_init(:) = hom_sum(:,115,0) |
---|
| 1158 | ENDIF |
---|
| 1159 | ! |
---|
[2550] | 1160 | !-- In case of complex terrain and cyclic fill method as initialization, |
---|
| 1161 | !-- shift initial data in the vertical direction for each point in the |
---|
| 1162 | !-- x-y-plane depending on local surface height |
---|
| 1163 | IF ( complex_terrain .AND. & |
---|
| 1164 | TRIM( initializing_actions ) == 'cyclic_fill' ) THEN |
---|
| 1165 | DO i = nxlg, nxrg |
---|
| 1166 | DO j = nysg, nyng |
---|
[4168] | 1167 | nz_u_shift = topo_top_ind(j,i,1) |
---|
| 1168 | nz_v_shift = topo_top_ind(j,i,2) |
---|
| 1169 | nz_w_shift = topo_top_ind(j,i,3) |
---|
| 1170 | nz_s_shift = topo_top_ind(j,i,0) |
---|
[2550] | 1171 | |
---|
| 1172 | u(nz_u_shift:nzt+1,j,i) = u(0:nzt+1-nz_u_shift,j,i) |
---|
| 1173 | |
---|
| 1174 | v(nz_v_shift:nzt+1,j,i) = v(0:nzt+1-nz_v_shift,j,i) |
---|
| 1175 | |
---|
| 1176 | w(nz_w_shift:nzt+1,j,i) = w(0:nzt+1-nz_w_shift,j,i) |
---|
| 1177 | |
---|
| 1178 | p(nz_s_shift:nzt+1,j,i) = p(0:nzt+1-nz_s_shift,j,i) |
---|
| 1179 | pt(nz_s_shift:nzt+1,j,i) = pt(0:nzt+1-nz_s_shift,j,i) |
---|
| 1180 | ENDDO |
---|
| 1181 | ENDDO |
---|
| 1182 | ENDIF |
---|
| 1183 | ! |
---|
[767] | 1184 | !-- Initialization of the turbulence recycling method |
---|
[1788] | 1185 | IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND. & |
---|
[767] | 1186 | turbulent_inflow ) THEN |
---|
| 1187 | ! |
---|
| 1188 | !-- First store the profiles to be used at the inflow. |
---|
| 1189 | !-- These profiles are the (temporally) and horizontally averaged vertical |
---|
| 1190 | !-- profiles from the prerun. Alternatively, prescribed profiles |
---|
[4185] | 1191 | !-- for u,v-components can be used. |
---|
[3288] | 1192 | ALLOCATE( mean_inflow_profiles(nzb:nzt+1,1:num_mean_inflow_profiles) ) |
---|
[151] | 1193 | |
---|
[767] | 1194 | IF ( use_prescribed_profile_data ) THEN |
---|
| 1195 | mean_inflow_profiles(:,1) = u_init ! u |
---|
| 1196 | mean_inflow_profiles(:,2) = v_init ! v |
---|
| 1197 | ELSE |
---|
[328] | 1198 | mean_inflow_profiles(:,1) = hom_sum(:,1,0) ! u |
---|
| 1199 | mean_inflow_profiles(:,2) = hom_sum(:,2,0) ! v |
---|
[767] | 1200 | ENDIF |
---|
| 1201 | mean_inflow_profiles(:,4) = hom_sum(:,4,0) ! pt |
---|
[1960] | 1202 | IF ( humidity ) & |
---|
| 1203 | mean_inflow_profiles(:,6) = hom_sum(:,41,0) ! q |
---|
| 1204 | IF ( passive_scalar ) & |
---|
| 1205 | mean_inflow_profiles(:,7) = hom_sum(:,115,0) ! s |
---|
[4365] | 1206 | |
---|
[2550] | 1207 | ! |
---|
| 1208 | !-- In case of complex terrain, determine vertical displacement at inflow |
---|
| 1209 | !-- boundary and adjust mean inflow profiles |
---|
| 1210 | IF ( complex_terrain ) THEN |
---|
| 1211 | IF ( nxlg <= 0 .AND. nxrg >= 0 .AND. nysg <= 0 .AND. nyng >= 0 ) THEN |
---|
[4168] | 1212 | nz_u_shift_l = topo_top_ind(j,i,1) |
---|
| 1213 | nz_v_shift_l = topo_top_ind(j,i,2) |
---|
| 1214 | nz_w_shift_l = topo_top_ind(j,i,3) |
---|
| 1215 | nz_s_shift_l = topo_top_ind(j,i,0) |
---|
[2550] | 1216 | ELSE |
---|
| 1217 | nz_u_shift_l = 0 |
---|
| 1218 | nz_v_shift_l = 0 |
---|
| 1219 | nz_w_shift_l = 0 |
---|
| 1220 | nz_s_shift_l = 0 |
---|
| 1221 | ENDIF |
---|
[151] | 1222 | |
---|
[2550] | 1223 | #if defined( __parallel ) |
---|
| 1224 | CALL MPI_ALLREDUCE(nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER, & |
---|
| 1225 | MPI_MAX, comm2d, ierr) |
---|
| 1226 | CALL MPI_ALLREDUCE(nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER, & |
---|
| 1227 | MPI_MAX, comm2d, ierr) |
---|
| 1228 | CALL MPI_ALLREDUCE(nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER, & |
---|
| 1229 | MPI_MAX, comm2d, ierr) |
---|
| 1230 | CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER, & |
---|
| 1231 | MPI_MAX, comm2d, ierr) |
---|
| 1232 | #else |
---|
| 1233 | nz_u_shift = nz_u_shift_l |
---|
| 1234 | nz_v_shift = nz_v_shift_l |
---|
| 1235 | nz_w_shift = nz_w_shift_l |
---|
| 1236 | nz_s_shift = nz_s_shift_l |
---|
| 1237 | #endif |
---|
| 1238 | |
---|
| 1239 | mean_inflow_profiles(:,1) = 0.0_wp |
---|
| 1240 | mean_inflow_profiles(nz_u_shift:nzt+1,1) = hom_sum(0:nzt+1-nz_u_shift,1,0) ! u |
---|
| 1241 | |
---|
| 1242 | mean_inflow_profiles(:,2) = 0.0_wp |
---|
| 1243 | mean_inflow_profiles(nz_v_shift:nzt+1,2) = hom_sum(0:nzt+1-nz_v_shift,2,0) ! v |
---|
| 1244 | |
---|
| 1245 | mean_inflow_profiles(nz_s_shift:nzt+1,4) = hom_sum(0:nzt+1-nz_s_shift,4,0) ! pt |
---|
| 1246 | |
---|
| 1247 | ENDIF |
---|
| 1248 | |
---|
[151] | 1249 | ! |
---|
[767] | 1250 | !-- If necessary, adjust the horizontal flow field to the prescribed |
---|
| 1251 | !-- profiles |
---|
| 1252 | IF ( use_prescribed_profile_data ) THEN |
---|
| 1253 | DO i = nxlg, nxrg |
---|
[667] | 1254 | DO j = nysg, nyng |
---|
[328] | 1255 | DO k = nzb, nzt+1 |
---|
[767] | 1256 | u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k) |
---|
| 1257 | v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k) |
---|
[328] | 1258 | ENDDO |
---|
[151] | 1259 | ENDDO |
---|
[767] | 1260 | ENDDO |
---|
| 1261 | ENDIF |
---|
[151] | 1262 | |
---|
| 1263 | ! |
---|
[767] | 1264 | !-- Use these mean profiles at the inflow (provided that Dirichlet |
---|
| 1265 | !-- conditions are used) |
---|
[3182] | 1266 | IF ( bc_dirichlet_l ) THEN |
---|
[767] | 1267 | DO j = nysg, nyng |
---|
| 1268 | DO k = nzb, nzt+1 |
---|
| 1269 | u(k,j,nxlg:-1) = mean_inflow_profiles(k,1) |
---|
| 1270 | v(k,j,nxlg:-1) = mean_inflow_profiles(k,2) |
---|
[1340] | 1271 | w(k,j,nxlg:-1) = 0.0_wp |
---|
[767] | 1272 | pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4) |
---|
[1960] | 1273 | IF ( humidity ) & |
---|
[1615] | 1274 | q(k,j,nxlg:-1) = mean_inflow_profiles(k,6) |
---|
[1960] | 1275 | IF ( passive_scalar ) & |
---|
| 1276 | s(k,j,nxlg:-1) = mean_inflow_profiles(k,7) |
---|
[767] | 1277 | ENDDO |
---|
| 1278 | ENDDO |
---|
| 1279 | ENDIF |
---|
| 1280 | |
---|
[151] | 1281 | ! |
---|
[767] | 1282 | !-- Calculate the damping factors to be used at the inflow. For a |
---|
| 1283 | !-- turbulent inflow the turbulent fluctuations have to be limited |
---|
| 1284 | !-- vertically because otherwise the turbulent inflow layer will grow |
---|
| 1285 | !-- in time. |
---|
[1340] | 1286 | IF ( inflow_damping_height == 9999999.9_wp ) THEN |
---|
[767] | 1287 | ! |
---|
| 1288 | !-- Default: use the inversion height calculated by the prerun; if |
---|
| 1289 | !-- this is zero, inflow_damping_height must be explicitly |
---|
| 1290 | !-- specified. |
---|
[1340] | 1291 | IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp ) THEN |
---|
[767] | 1292 | inflow_damping_height = hom_sum(nzb+6,pr_palm,0) |
---|
| 1293 | ELSE |
---|
[1788] | 1294 | WRITE( message_string, * ) 'inflow_damping_height must be ', & |
---|
| 1295 | 'explicitly specified because&the inversion height ', & |
---|
[767] | 1296 | 'calculated by the prerun is zero.' |
---|
| 1297 | CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 ) |
---|
[292] | 1298 | ENDIF |
---|
[151] | 1299 | |
---|
[767] | 1300 | ENDIF |
---|
| 1301 | |
---|
[1340] | 1302 | IF ( inflow_damping_width == 9999999.9_wp ) THEN |
---|
[151] | 1303 | ! |
---|
[767] | 1304 | !-- Default for the transition range: one tenth of the undamped |
---|
| 1305 | !-- layer |
---|
[1340] | 1306 | inflow_damping_width = 0.1_wp * inflow_damping_height |
---|
[151] | 1307 | |
---|
[767] | 1308 | ENDIF |
---|
[151] | 1309 | |
---|
[767] | 1310 | ALLOCATE( inflow_damping_factor(nzb:nzt+1) ) |
---|
[151] | 1311 | |
---|
[767] | 1312 | DO k = nzb, nzt+1 |
---|
[151] | 1313 | |
---|
[767] | 1314 | IF ( zu(k) <= inflow_damping_height ) THEN |
---|
[1340] | 1315 | inflow_damping_factor(k) = 1.0_wp |
---|
[996] | 1316 | ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) ) THEN |
---|
[1340] | 1317 | inflow_damping_factor(k) = 1.0_wp - & |
---|
[996] | 1318 | ( zu(k) - inflow_damping_height ) / & |
---|
| 1319 | inflow_damping_width |
---|
[767] | 1320 | ELSE |
---|
[1340] | 1321 | inflow_damping_factor(k) = 0.0_wp |
---|
[767] | 1322 | ENDIF |
---|
[151] | 1323 | |
---|
[767] | 1324 | ENDDO |
---|
[151] | 1325 | |
---|
[147] | 1326 | ENDIF |
---|
| 1327 | |
---|
[152] | 1328 | ! |
---|
[2696] | 1329 | !-- Inside buildings set velocities back to zero |
---|
[1788] | 1330 | IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND. & |
---|
[359] | 1331 | topography /= 'flat' ) THEN |
---|
| 1332 | ! |
---|
[2696] | 1333 | !-- Inside buildings set velocities back to zero. |
---|
| 1334 | !-- Other scalars (pt, q, s, p, sa, ...) are ignored at present, |
---|
[359] | 1335 | !-- maybe revise later. |
---|
[1001] | 1336 | DO i = nxlg, nxrg |
---|
| 1337 | DO j = nysg, nyng |
---|
[2232] | 1338 | DO k = nzb, nzt |
---|
| 1339 | u(k,j,i) = MERGE( u(k,j,i), 0.0_wp, & |
---|
[4346] | 1340 | BTEST( wall_flags_total_0(k,j,i), 1 ) ) |
---|
[2232] | 1341 | v(k,j,i) = MERGE( v(k,j,i), 0.0_wp, & |
---|
[4346] | 1342 | BTEST( wall_flags_total_0(k,j,i), 2 ) ) |
---|
[2232] | 1343 | w(k,j,i) = MERGE( w(k,j,i), 0.0_wp, & |
---|
[4346] | 1344 | BTEST( wall_flags_total_0(k,j,i), 3 ) ) |
---|
[2232] | 1345 | ENDDO |
---|
[359] | 1346 | ENDDO |
---|
[1001] | 1347 | ENDDO |
---|
[359] | 1348 | |
---|
| 1349 | ENDIF |
---|
| 1350 | |
---|
| 1351 | ! |
---|
[1] | 1352 | !-- Calculate initial temperature field and other constants used in case |
---|
| 1353 | !-- of a sloping surface |
---|
| 1354 | IF ( sloping_surface ) CALL init_slope |
---|
| 1355 | |
---|
| 1356 | ! |
---|
| 1357 | !-- Initialize new time levels (only done in order to set boundary values |
---|
| 1358 | !-- including ghost points) |
---|
[2696] | 1359 | pt_p = pt; u_p = u; v_p = v; w_p = w |
---|
[1960] | 1360 | IF ( humidity ) THEN |
---|
[1053] | 1361 | q_p = q |
---|
| 1362 | ENDIF |
---|
[1960] | 1363 | IF ( passive_scalar ) s_p = s |
---|
[181] | 1364 | ! |
---|
| 1365 | !-- Allthough tendency arrays are set in prognostic_equations, they have |
---|
| 1366 | !-- have to be predefined here because they are used (but multiplied with 0) |
---|
| 1367 | !-- there before they are set. |
---|
[2696] | 1368 | tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp |
---|
[1960] | 1369 | IF ( humidity ) THEN |
---|
[1340] | 1370 | tq_m = 0.0_wp |
---|
[1053] | 1371 | ENDIF |
---|
[1960] | 1372 | IF ( passive_scalar ) ts_m = 0.0_wp |
---|
[181] | 1373 | |
---|
[3987] | 1374 | IF ( debug_output ) CALL debug_message( 'initializing in case of restart / cyclic_fill', 'end' ) |
---|
[1384] | 1375 | |
---|
[1] | 1376 | ELSE |
---|
| 1377 | ! |
---|
| 1378 | !-- Actually this part of the programm should not be reached |
---|
[254] | 1379 | message_string = 'unknown initializing problem' |
---|
| 1380 | CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 ) |
---|
[1] | 1381 | ENDIF |
---|
| 1382 | |
---|
[151] | 1383 | |
---|
| 1384 | IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN |
---|
[1] | 1385 | ! |
---|
[151] | 1386 | !-- Initialize old timelevels needed for radiation boundary conditions |
---|
[3182] | 1387 | IF ( bc_radiation_l ) THEN |
---|
[151] | 1388 | u_m_l(:,:,:) = u(:,:,1:2) |
---|
| 1389 | v_m_l(:,:,:) = v(:,:,0:1) |
---|
| 1390 | w_m_l(:,:,:) = w(:,:,0:1) |
---|
| 1391 | ENDIF |
---|
[3182] | 1392 | IF ( bc_radiation_r ) THEN |
---|
[151] | 1393 | u_m_r(:,:,:) = u(:,:,nx-1:nx) |
---|
| 1394 | v_m_r(:,:,:) = v(:,:,nx-1:nx) |
---|
| 1395 | w_m_r(:,:,:) = w(:,:,nx-1:nx) |
---|
| 1396 | ENDIF |
---|
[3182] | 1397 | IF ( bc_radiation_s ) THEN |
---|
[151] | 1398 | u_m_s(:,:,:) = u(:,0:1,:) |
---|
| 1399 | v_m_s(:,:,:) = v(:,1:2,:) |
---|
| 1400 | w_m_s(:,:,:) = w(:,0:1,:) |
---|
| 1401 | ENDIF |
---|
[3182] | 1402 | IF ( bc_radiation_n ) THEN |
---|
[151] | 1403 | u_m_n(:,:,:) = u(:,ny-1:ny,:) |
---|
| 1404 | v_m_n(:,:,:) = v(:,ny-1:ny,:) |
---|
| 1405 | w_m_n(:,:,:) = w(:,ny-1:ny,:) |
---|
| 1406 | ENDIF |
---|
[667] | 1407 | |
---|
[151] | 1408 | ENDIF |
---|
[680] | 1409 | |
---|
[667] | 1410 | ! |
---|
| 1411 | !-- Calculate the initial volume flow at the right and north boundary |
---|
[709] | 1412 | IF ( conserve_volume_flow ) THEN |
---|
[151] | 1413 | |
---|
[767] | 1414 | IF ( use_prescribed_profile_data ) THEN |
---|
[667] | 1415 | |
---|
[1340] | 1416 | volume_flow_initial_l = 0.0_wp |
---|
| 1417 | volume_flow_area_l = 0.0_wp |
---|
[732] | 1418 | |
---|
[667] | 1419 | IF ( nxr == nx ) THEN |
---|
| 1420 | DO j = nys, nyn |
---|
[2232] | 1421 | DO k = nzb+1, nzt |
---|
[4346] | 1422 | volume_flow_initial_l(1) = volume_flow_initial_l(1) + & |
---|
| 1423 | u_init(k) * dzw(k) & |
---|
| 1424 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1425 | BTEST( wall_flags_total_0(k,j,nxr), 1 )& |
---|
[2232] | 1426 | ) |
---|
| 1427 | |
---|
[4346] | 1428 | volume_flow_area_l(1) = volume_flow_area_l(1) + dzw(k) & |
---|
| 1429 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1430 | BTEST( wall_flags_total_0(k,j,nxr), 1 )& |
---|
[2232] | 1431 | ) |
---|
[767] | 1432 | ENDDO |
---|
| 1433 | ENDDO |
---|
| 1434 | ENDIF |
---|
| 1435 | |
---|
| 1436 | IF ( nyn == ny ) THEN |
---|
| 1437 | DO i = nxl, nxr |
---|
[2232] | 1438 | DO k = nzb+1, nzt |
---|
[4346] | 1439 | volume_flow_initial_l(2) = volume_flow_initial_l(2) + & |
---|
| 1440 | v_init(k) * dzw(k) & |
---|
| 1441 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1442 | BTEST( wall_flags_total_0(k,nyn,i), 2 )& |
---|
[2232] | 1443 | ) |
---|
[4346] | 1444 | volume_flow_area_l(2) = volume_flow_area_l(2) + dzw(k) & |
---|
| 1445 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1446 | BTEST( wall_flags_total_0(k,nyn,i), 2 )& |
---|
[2232] | 1447 | ) |
---|
[767] | 1448 | ENDDO |
---|
| 1449 | ENDDO |
---|
| 1450 | ENDIF |
---|
| 1451 | |
---|
| 1452 | #if defined( __parallel ) |
---|
| 1453 | CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),& |
---|
| 1454 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 1455 | CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), & |
---|
| 1456 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 1457 | |
---|
| 1458 | #else |
---|
| 1459 | volume_flow_initial = volume_flow_initial_l |
---|
| 1460 | volume_flow_area = volume_flow_area_l |
---|
| 1461 | #endif |
---|
| 1462 | |
---|
| 1463 | ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' ) THEN |
---|
| 1464 | |
---|
[1340] | 1465 | volume_flow_initial_l = 0.0_wp |
---|
| 1466 | volume_flow_area_l = 0.0_wp |
---|
[767] | 1467 | |
---|
| 1468 | IF ( nxr == nx ) THEN |
---|
| 1469 | DO j = nys, nyn |
---|
[2232] | 1470 | DO k = nzb+1, nzt |
---|
[4346] | 1471 | volume_flow_initial_l(1) = volume_flow_initial_l(1) + & |
---|
| 1472 | hom_sum(k,1,0) * dzw(k) & |
---|
| 1473 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1474 | BTEST( wall_flags_total_0(k,j,nx), 1 ) & |
---|
[2232] | 1475 | ) |
---|
[4346] | 1476 | volume_flow_area_l(1) = volume_flow_area_l(1) + dzw(k) & |
---|
| 1477 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1478 | BTEST( wall_flags_total_0(k,j,nx), 1 ) & |
---|
[2232] | 1479 | ) |
---|
[667] | 1480 | ENDDO |
---|
| 1481 | ENDDO |
---|
| 1482 | ENDIF |
---|
| 1483 | |
---|
| 1484 | IF ( nyn == ny ) THEN |
---|
| 1485 | DO i = nxl, nxr |
---|
[2232] | 1486 | DO k = nzb+1, nzt |
---|
[4346] | 1487 | volume_flow_initial_l(2) = volume_flow_initial_l(2) + & |
---|
| 1488 | hom_sum(k,2,0) * dzw(k) & |
---|
| 1489 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1490 | BTEST( wall_flags_total_0(k,ny,i), 2 ) & |
---|
[2232] | 1491 | ) |
---|
[4346] | 1492 | volume_flow_area_l(2) = volume_flow_area_l(2) + dzw(k) & |
---|
| 1493 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1494 | BTEST( wall_flags_total_0(k,ny,i), 2 ) & |
---|
[2232] | 1495 | ) |
---|
[667] | 1496 | ENDDO |
---|
| 1497 | ENDDO |
---|
| 1498 | ENDIF |
---|
| 1499 | |
---|
[732] | 1500 | #if defined( __parallel ) |
---|
| 1501 | CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),& |
---|
| 1502 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 1503 | CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), & |
---|
| 1504 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 1505 | |
---|
| 1506 | #else |
---|
| 1507 | volume_flow_initial = volume_flow_initial_l |
---|
| 1508 | volume_flow_area = volume_flow_area_l |
---|
| 1509 | #endif |
---|
| 1510 | |
---|
[667] | 1511 | ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN |
---|
| 1512 | |
---|
[1340] | 1513 | volume_flow_initial_l = 0.0_wp |
---|
| 1514 | volume_flow_area_l = 0.0_wp |
---|
[732] | 1515 | |
---|
[667] | 1516 | IF ( nxr == nx ) THEN |
---|
| 1517 | DO j = nys, nyn |
---|
[2232] | 1518 | DO k = nzb+1, nzt |
---|
[4346] | 1519 | volume_flow_initial_l(1) = volume_flow_initial_l(1) + & |
---|
| 1520 | u(k,j,nx) * dzw(k) & |
---|
| 1521 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1522 | BTEST( wall_flags_total_0(k,j,nx), 1 ) & |
---|
[2232] | 1523 | ) |
---|
[4346] | 1524 | volume_flow_area_l(1) = volume_flow_area_l(1) + dzw(k) & |
---|
| 1525 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1526 | BTEST( wall_flags_total_0(k,j,nx), 1 ) & |
---|
[2232] | 1527 | ) |
---|
[667] | 1528 | ENDDO |
---|
| 1529 | ENDDO |
---|
| 1530 | ENDIF |
---|
| 1531 | |
---|
| 1532 | IF ( nyn == ny ) THEN |
---|
| 1533 | DO i = nxl, nxr |
---|
[2232] | 1534 | DO k = nzb+1, nzt |
---|
[4346] | 1535 | volume_flow_initial_l(2) = volume_flow_initial_l(2) + & |
---|
| 1536 | v(k,ny,i) * dzw(k) & |
---|
| 1537 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1538 | BTEST( wall_flags_total_0(k,ny,i), 2 ) & |
---|
[2232] | 1539 | ) |
---|
[4346] | 1540 | volume_flow_area_l(2) = volume_flow_area_l(2) + dzw(k) & |
---|
| 1541 | * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 1542 | BTEST( wall_flags_total_0(k,ny,i), 2 ) & |
---|
[2232] | 1543 | ) |
---|
[667] | 1544 | ENDDO |
---|
| 1545 | ENDDO |
---|
| 1546 | ENDIF |
---|
| 1547 | |
---|
| 1548 | #if defined( __parallel ) |
---|
[732] | 1549 | CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),& |
---|
| 1550 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
| 1551 | CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), & |
---|
| 1552 | 2, MPI_REAL, MPI_SUM, comm2d, ierr ) |
---|
[667] | 1553 | |
---|
| 1554 | #else |
---|
[732] | 1555 | volume_flow_initial = volume_flow_initial_l |
---|
| 1556 | volume_flow_area = volume_flow_area_l |
---|
[667] | 1557 | #endif |
---|
| 1558 | |
---|
[732] | 1559 | ENDIF |
---|
| 1560 | |
---|
[151] | 1561 | ! |
---|
[709] | 1562 | !-- In case of 'bulk_velocity' mode, volume_flow_initial is calculated |
---|
| 1563 | !-- from u|v_bulk instead |
---|
[680] | 1564 | IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' ) THEN |
---|
| 1565 | volume_flow_initial(1) = u_bulk * volume_flow_area(1) |
---|
| 1566 | volume_flow_initial(2) = v_bulk * volume_flow_area(2) |
---|
| 1567 | ENDIF |
---|
[667] | 1568 | |
---|
[680] | 1569 | ENDIF |
---|
[2232] | 1570 | ! |
---|
[4150] | 1571 | !-- In the following, surface properties can be further initialized with |
---|
| 1572 | !-- input from static driver file. |
---|
| 1573 | !-- At the moment this affects only default surfaces. For example, |
---|
| 1574 | !-- roughness length or sensible / latent heat fluxes can be initialized |
---|
| 1575 | !-- heterogeneously for default surfaces. Therefore, a generic routine |
---|
| 1576 | !-- from netcdf_data_input_mod is called to read a 2D array. |
---|
| 1577 | IF ( input_pids_static ) THEN |
---|
| 1578 | ! |
---|
[4151] | 1579 | !-- Allocate memory for possible static input |
---|
| 1580 | ALLOCATE( tmp_2d%var(nys:nyn,nxl:nxr) ) |
---|
| 1581 | tmp_2d%var = 0.0_wp |
---|
| 1582 | ! |
---|
[4150] | 1583 | !-- Open the static input file |
---|
[4151] | 1584 | #if defined( __netcdf ) |
---|
[4150] | 1585 | CALL open_read_file( TRIM( input_file_static ) // & |
---|
| 1586 | TRIM( coupling_char ), & |
---|
[4186] | 1587 | pids_id ) |
---|
[4150] | 1588 | |
---|
[4186] | 1589 | CALL inquire_num_variables( pids_id, num_var_pids ) |
---|
[4150] | 1590 | ! |
---|
| 1591 | !-- Allocate memory to store variable names and read them |
---|
[4186] | 1592 | ALLOCATE( vars_pids(1:num_var_pids) ) |
---|
| 1593 | CALL inquire_variable_names( pids_id, vars_pids ) |
---|
[4150] | 1594 | ! |
---|
| 1595 | !-- Input roughness length. |
---|
[4186] | 1596 | IF ( check_existence( vars_pids, 'z0' ) ) THEN |
---|
[4150] | 1597 | ! |
---|
| 1598 | !-- Read _FillValue attribute |
---|
[4186] | 1599 | CALL get_attribute( pids_id, char_fill, tmp_2d%fill, & |
---|
[4150] | 1600 | .FALSE., 'z0' ) |
---|
| 1601 | ! |
---|
| 1602 | !-- Read variable |
---|
[4186] | 1603 | CALL get_variable( pids_id, 'z0', tmp_2d%var, & |
---|
[4150] | 1604 | nxl, nxr, nys, nyn ) |
---|
| 1605 | ! |
---|
| 1606 | !-- Initialize roughness length. Note, z0 will be only initialized at |
---|
| 1607 | !-- default-type surfaces. At natural or urban z0 is implicitly |
---|
[4514] | 1608 | !-- initialized by the respective parameter lists. |
---|
[4150] | 1609 | !-- Initialize horizontal surface elements. |
---|
| 1610 | CALL init_single_surface_properties( surf_def_h(0)%z0, & |
---|
| 1611 | tmp_2d%var, & |
---|
| 1612 | surf_def_h(0)%ns, & |
---|
| 1613 | tmp_2d%fill, & |
---|
| 1614 | surf_def_h(0)%i, & |
---|
| 1615 | surf_def_h(0)%j ) |
---|
| 1616 | ! |
---|
| 1617 | !-- Initialize roughness also at vertical surface elements. |
---|
| 1618 | !-- Note, the actual 2D input arrays are only defined on the |
---|
| 1619 | !-- subdomain. Therefore, pass the index arrays with their respective |
---|
| 1620 | !-- offset values. |
---|
| 1621 | DO l = 0, 3 |
---|
| 1622 | CALL init_single_surface_properties( & |
---|
| 1623 | surf_def_v(l)%z0, & |
---|
| 1624 | tmp_2d%var, & |
---|
| 1625 | surf_def_v(l)%ns, & |
---|
| 1626 | tmp_2d%fill, & |
---|
| 1627 | surf_def_v(l)%i + surf_def_v(l)%ioff, & |
---|
| 1628 | surf_def_v(l)%j + surf_def_v(l)%joff ) |
---|
| 1629 | ENDDO |
---|
| 1630 | |
---|
| 1631 | ENDIF |
---|
| 1632 | ! |
---|
[4514] | 1633 | !-- Input surface sensible heat flux. |
---|
| 1634 | IF ( check_existence( vars_pids, 'shf' ) ) THEN |
---|
| 1635 | ! |
---|
| 1636 | !-- Read _FillValue attribute |
---|
| 1637 | CALL get_attribute( pids_id, char_fill, tmp_2d%fill, & |
---|
| 1638 | .FALSE., 'shf' ) |
---|
| 1639 | ! |
---|
| 1640 | !-- Read variable |
---|
| 1641 | CALL get_variable( pids_id, 'shf', tmp_2d%var, & |
---|
| 1642 | nxl, nxr, nys, nyn ) |
---|
| 1643 | ! |
---|
| 1644 | !-- Initialize heat flux. Note, shf will be only initialized at |
---|
| 1645 | !-- default-type surfaces. At natural or urban shf is implicitly |
---|
| 1646 | !-- initialized by the respective parameter lists. |
---|
| 1647 | !-- Initialize horizontal surface elements. |
---|
| 1648 | CALL init_single_surface_properties( surf_def_h(0)%shf, & |
---|
| 1649 | tmp_2d%var, & |
---|
| 1650 | surf_def_h(0)%ns, & |
---|
| 1651 | tmp_2d%fill, & |
---|
| 1652 | surf_def_h(0)%i, & |
---|
| 1653 | surf_def_h(0)%j ) |
---|
| 1654 | ! |
---|
| 1655 | !-- Initialize heat flux also at vertical surface elements. |
---|
| 1656 | !-- Note, the actual 2D input arrays are only defined on the |
---|
| 1657 | !-- subdomain. Therefore, pass the index arrays with their respective |
---|
| 1658 | !-- offset values. |
---|
| 1659 | DO l = 0, 3 |
---|
| 1660 | CALL init_single_surface_properties( & |
---|
| 1661 | surf_def_v(l)%shf, & |
---|
| 1662 | tmp_2d%var, & |
---|
| 1663 | surf_def_v(l)%ns, & |
---|
| 1664 | tmp_2d%fill, & |
---|
| 1665 | surf_def_v(l)%i + surf_def_v(l)%ioff, & |
---|
| 1666 | surf_def_v(l)%j + surf_def_v(l)%joff ) |
---|
| 1667 | ENDDO |
---|
| 1668 | |
---|
| 1669 | ENDIF |
---|
| 1670 | ! |
---|
| 1671 | !-- Input surface sensible heat flux. |
---|
| 1672 | IF ( check_existence( vars_pids, 'qsws' ) ) THEN |
---|
| 1673 | ! |
---|
| 1674 | !-- Read _FillValue attribute |
---|
| 1675 | CALL get_attribute( pids_id, char_fill, tmp_2d%fill, & |
---|
| 1676 | .FALSE., 'qsws' ) |
---|
| 1677 | ! |
---|
| 1678 | !-- Read variable |
---|
| 1679 | CALL get_variable( pids_id, 'qsws', tmp_2d%var, & |
---|
| 1680 | nxl, nxr, nys, nyn ) |
---|
| 1681 | ! |
---|
| 1682 | !-- Initialize latent heat flux. Note, qsws will be only initialized at |
---|
| 1683 | !-- default-type surfaces. At natural or urban qsws is implicitly |
---|
| 1684 | !-- initialized by the respective parameter lists. |
---|
| 1685 | !-- Initialize horizontal surface elements. |
---|
| 1686 | CALL init_single_surface_properties( surf_def_h(0)%qsws, & |
---|
| 1687 | tmp_2d%var, & |
---|
| 1688 | surf_def_h(0)%ns, & |
---|
| 1689 | tmp_2d%fill, & |
---|
| 1690 | surf_def_h(0)%i, & |
---|
| 1691 | surf_def_h(0)%j ) |
---|
| 1692 | ! |
---|
| 1693 | !-- Initialize latent heat flux also at vertical surface elements. |
---|
| 1694 | !-- Note, the actual 2D input arrays are only defined on the |
---|
| 1695 | !-- subdomain. Therefore, pass the index arrays with their respective |
---|
| 1696 | !-- offset values. |
---|
| 1697 | DO l = 0, 3 |
---|
| 1698 | CALL init_single_surface_properties( & |
---|
| 1699 | surf_def_v(l)%qsws, & |
---|
| 1700 | tmp_2d%var, & |
---|
| 1701 | surf_def_v(l)%ns, & |
---|
| 1702 | tmp_2d%fill, & |
---|
| 1703 | surf_def_v(l)%i + surf_def_v(l)%ioff, & |
---|
| 1704 | surf_def_v(l)%j + surf_def_v(l)%joff ) |
---|
| 1705 | ENDDO |
---|
| 1706 | |
---|
| 1707 | ENDIF |
---|
| 1708 | ! |
---|
| 1709 | !-- Additional variables, can be initialized the |
---|
[4150] | 1710 | !-- same way. |
---|
[4514] | 1711 | |
---|
[4150] | 1712 | ! |
---|
[4187] | 1713 | !-- Finally, close the input file and deallocate temporary arrays |
---|
| 1714 | DEALLOCATE( vars_pids ) |
---|
| 1715 | |
---|
[4186] | 1716 | CALL close_input_file( pids_id ) |
---|
[4151] | 1717 | #endif |
---|
| 1718 | DEALLOCATE( tmp_2d%var ) |
---|
[4150] | 1719 | ENDIF |
---|
| 1720 | ! |
---|
[2618] | 1721 | !-- Finally, if random_heatflux is set, disturb shf at horizontal |
---|
| 1722 | !-- surfaces. Actually, this should be done in surface_mod, where all other |
---|
| 1723 | !-- initializations of surface quantities are done. However, this |
---|
| 1724 | !-- would create a ring dependency, hence, it is done here. Maybe delete |
---|
| 1725 | !-- disturb_heatflux and tranfer the respective code directly into the |
---|
| 1726 | !-- initialization in surface_mod. |
---|
[2232] | 1727 | IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND. & |
---|
| 1728 | TRIM( initializing_actions ) /= 'cyclic_fill' ) THEN |
---|
[2618] | 1729 | |
---|
[2232] | 1730 | IF ( use_surface_fluxes .AND. constant_heatflux .AND. & |
---|
| 1731 | random_heatflux ) THEN |
---|
| 1732 | IF ( surf_def_h(0)%ns >= 1 ) CALL disturb_heatflux( surf_def_h(0) ) |
---|
| 1733 | IF ( surf_lsm_h%ns >= 1 ) CALL disturb_heatflux( surf_lsm_h ) |
---|
| 1734 | IF ( surf_usm_h%ns >= 1 ) CALL disturb_heatflux( surf_usm_h ) |
---|
| 1735 | ENDIF |
---|
| 1736 | ENDIF |
---|
[680] | 1737 | |
---|
[787] | 1738 | ! |
---|
[3747] | 1739 | !-- Compute total sum of grid points and the mean surface level height for each |
---|
| 1740 | !-- statistic region. These are mainly used for horizontal averaging of |
---|
| 1741 | !-- turbulence statistics. |
---|
[2696] | 1742 | !-- ngp_2dh: number of grid points of a horizontal cross section through the |
---|
[3747] | 1743 | !-- respective statistic region |
---|
| 1744 | !-- ngp_3d: number of grid points of the respective statistic region |
---|
[2696] | 1745 | ngp_2dh_outer_l = 0 |
---|
| 1746 | ngp_2dh_outer = 0 |
---|
| 1747 | ngp_2dh_s_inner_l = 0 |
---|
| 1748 | ngp_2dh_s_inner = 0 |
---|
| 1749 | ngp_2dh_l = 0 |
---|
| 1750 | ngp_2dh = 0 |
---|
| 1751 | ngp_3d_inner_l = 0.0_wp |
---|
| 1752 | ngp_3d_inner = 0 |
---|
| 1753 | ngp_3d = 0 |
---|
| 1754 | ngp_sums = ( nz + 2 ) * ( pr_palm + max_pr_user ) |
---|
| 1755 | |
---|
| 1756 | mean_surface_level_height = 0.0_wp |
---|
| 1757 | mean_surface_level_height_l = 0.0_wp |
---|
| 1758 | ! |
---|
| 1759 | !-- To do: New concept for these non-topography grid points! |
---|
| 1760 | DO sr = 0, statistic_regions |
---|
| 1761 | DO i = nxl, nxr |
---|
| 1762 | DO j = nys, nyn |
---|
| 1763 | IF ( rmask(j,i,sr) == 1.0_wp ) THEN |
---|
| 1764 | ! |
---|
| 1765 | !-- All xy-grid points |
---|
| 1766 | ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1 |
---|
| 1767 | ! |
---|
| 1768 | !-- Determine mean surface-level height. In case of downward- |
---|
| 1769 | !-- facing walls are present, more than one surface level exist. |
---|
| 1770 | !-- In this case, use the lowest surface-level height. |
---|
| 1771 | IF ( surf_def_h(0)%start_index(j,i) <= & |
---|
| 1772 | surf_def_h(0)%end_index(j,i) ) THEN |
---|
| 1773 | m = surf_def_h(0)%start_index(j,i) |
---|
| 1774 | k = surf_def_h(0)%k(m) |
---|
| 1775 | mean_surface_level_height_l(sr) = & |
---|
| 1776 | mean_surface_level_height_l(sr) + zw(k-1) |
---|
| 1777 | ENDIF |
---|
| 1778 | IF ( surf_lsm_h%start_index(j,i) <= & |
---|
| 1779 | surf_lsm_h%end_index(j,i) ) THEN |
---|
| 1780 | m = surf_lsm_h%start_index(j,i) |
---|
| 1781 | k = surf_lsm_h%k(m) |
---|
| 1782 | mean_surface_level_height_l(sr) = & |
---|
| 1783 | mean_surface_level_height_l(sr) + zw(k-1) |
---|
| 1784 | ENDIF |
---|
| 1785 | IF ( surf_usm_h%start_index(j,i) <= & |
---|
| 1786 | surf_usm_h%end_index(j,i) ) THEN |
---|
| 1787 | m = surf_usm_h%start_index(j,i) |
---|
| 1788 | k = surf_usm_h%k(m) |
---|
| 1789 | mean_surface_level_height_l(sr) = & |
---|
| 1790 | mean_surface_level_height_l(sr) + zw(k-1) |
---|
| 1791 | ENDIF |
---|
| 1792 | |
---|
| 1793 | k_surf = k - 1 |
---|
| 1794 | |
---|
| 1795 | DO k = nzb, nzt+1 |
---|
| 1796 | ! |
---|
| 1797 | !-- xy-grid points above topography |
---|
| 1798 | ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr) + & |
---|
[4346] | 1799 | MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 24 ) ) |
---|
[2696] | 1800 | |
---|
| 1801 | ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) + & |
---|
[4346] | 1802 | MERGE( 1, 0, BTEST( wall_flags_total_0(k,j,i), 22 ) ) |
---|
[2696] | 1803 | |
---|
| 1804 | ENDDO |
---|
| 1805 | ! |
---|
| 1806 | !-- All grid points of the total domain above topography |
---|
| 1807 | ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + ( nz - k_surf + 2 ) |
---|
| 1808 | |
---|
| 1809 | |
---|
| 1810 | |
---|
| 1811 | ENDIF |
---|
| 1812 | ENDDO |
---|
| 1813 | ENDDO |
---|
| 1814 | ENDDO |
---|
[3747] | 1815 | |
---|
[2696] | 1816 | sr = statistic_regions + 1 |
---|
| 1817 | #if defined( __parallel ) |
---|
| 1818 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1819 | CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM, & |
---|
| 1820 | comm2d, ierr ) |
---|
| 1821 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1822 | CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr, & |
---|
| 1823 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
| 1824 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1825 | CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0), & |
---|
| 1826 | (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
| 1827 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1828 | CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL, & |
---|
| 1829 | MPI_SUM, comm2d, ierr ) |
---|
| 1830 | ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) ) |
---|
| 1831 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1832 | CALL MPI_ALLREDUCE( mean_surface_level_height_l(0), & |
---|
| 1833 | mean_surface_level_height(0), sr, MPI_REAL, & |
---|
| 1834 | MPI_SUM, comm2d, ierr ) |
---|
| 1835 | mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh ) |
---|
| 1836 | #else |
---|
| 1837 | ngp_2dh = ngp_2dh_l |
---|
| 1838 | ngp_2dh_outer = ngp_2dh_outer_l |
---|
| 1839 | ngp_2dh_s_inner = ngp_2dh_s_inner_l |
---|
| 1840 | ngp_3d_inner = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) ) |
---|
| 1841 | mean_surface_level_height = mean_surface_level_height_l / REAL( ngp_2dh_l ) |
---|
| 1842 | #endif |
---|
| 1843 | |
---|
| 1844 | ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * & |
---|
| 1845 | INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) ) |
---|
| 1846 | |
---|
| 1847 | ! |
---|
| 1848 | !-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics, |
---|
| 1849 | !-- buoyancy, etc. A zero value will occur for cases where all grid points of |
---|
| 1850 | !-- the respective subdomain lie below the surface topography |
---|
| 1851 | ngp_2dh_outer = MAX( 1, ngp_2dh_outer(:,:) ) |
---|
| 1852 | ngp_3d_inner = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )), & |
---|
| 1853 | ngp_3d_inner(:) ) |
---|
| 1854 | ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) |
---|
| 1855 | |
---|
| 1856 | DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l, & |
---|
| 1857 | ngp_3d_inner_l, ngp_3d_inner_tmp ) |
---|
[4548] | 1858 | |
---|
[2696] | 1859 | ! |
---|
[3347] | 1860 | !-- Initializae 3D offline nesting in COSMO model and read data from |
---|
| 1861 | !-- external NetCDF file. |
---|
| 1862 | IF ( nesting_offline ) CALL nesting_offl_init |
---|
| 1863 | ! |
---|
[787] | 1864 | !-- Initialize quantities for special advections schemes |
---|
| 1865 | CALL init_advec |
---|
[680] | 1866 | |
---|
[667] | 1867 | ! |
---|
[680] | 1868 | !-- Impose random perturbation on the horizontal velocity field and then |
---|
| 1869 | !-- remove the divergences from the velocity field at the initial stage |
---|
[1788] | 1870 | IF ( create_disturbances .AND. disturbance_energy_limit /= 0.0_wp .AND. & |
---|
| 1871 | TRIM( initializing_actions ) /= 'read_restart_data' .AND. & |
---|
[680] | 1872 | TRIM( initializing_actions ) /= 'cyclic_fill' ) THEN |
---|
| 1873 | |
---|
[3987] | 1874 | IF ( debug_output ) CALL debug_message( 'creating disturbances + applying pressure solver', 'start' ) |
---|
[3849] | 1875 | ! |
---|
| 1876 | !-- Needed for both disturb_field and pres |
---|
| 1877 | !$ACC DATA & |
---|
| 1878 | !$ACC CREATE(tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) & |
---|
| 1879 | !$ACC COPY(u(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) & |
---|
| 1880 | !$ACC COPY(v(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) |
---|
| 1881 | |
---|
[2232] | 1882 | CALL disturb_field( 'u', tend, u ) |
---|
| 1883 | CALL disturb_field( 'v', tend, v ) |
---|
[1384] | 1884 | |
---|
[3849] | 1885 | !$ACC DATA & |
---|
| 1886 | !$ACC CREATE(d(nzb+1:nzt,nys:nyn,nxl:nxr)) & |
---|
| 1887 | !$ACC COPY(w(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) & |
---|
| 1888 | !$ACC COPY(p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) & |
---|
| 1889 | !$ACC COPYIN(rho_air(nzb:nzt+1), rho_air_zw(nzb:nzt+1)) & |
---|
| 1890 | !$ACC COPYIN(ddzu(1:nzt+1), ddzw(1:nzt+1)) & |
---|
[4346] | 1891 | !$ACC COPYIN(wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) & |
---|
[3849] | 1892 | !$ACC COPYIN(bc_h(0:1)) & |
---|
| 1893 | !$ACC COPYIN(bc_h(0)%i(1:bc_h(0)%ns)) & |
---|
| 1894 | !$ACC COPYIN(bc_h(0)%j(1:bc_h(0)%ns)) & |
---|
| 1895 | !$ACC COPYIN(bc_h(0)%k(1:bc_h(0)%ns)) & |
---|
| 1896 | !$ACC COPYIN(bc_h(1)%i(1:bc_h(1)%ns)) & |
---|
| 1897 | !$ACC COPYIN(bc_h(1)%j(1:bc_h(1)%ns)) & |
---|
| 1898 | !$ACC COPYIN(bc_h(1)%k(1:bc_h(1)%ns)) |
---|
| 1899 | |
---|
[680] | 1900 | n_sor = nsor_ini |
---|
| 1901 | CALL pres |
---|
| 1902 | n_sor = nsor |
---|
[1384] | 1903 | |
---|
[3849] | 1904 | !$ACC END DATA |
---|
| 1905 | !$ACC END DATA |
---|
| 1906 | |
---|
[3987] | 1907 | IF ( debug_output ) CALL debug_message( 'creating disturbances + applying pressure solver', 'end' ) |
---|
| 1908 | |
---|
[680] | 1909 | ENDIF |
---|
| 1910 | |
---|
[3294] | 1911 | IF ( .NOT. ocean_mode ) THEN |
---|
[3274] | 1912 | |
---|
| 1913 | ALLOCATE( hyp(nzb:nzt+1) ) |
---|
| 1914 | ALLOCATE( d_exner(nzb:nzt+1) ) |
---|
| 1915 | ALLOCATE( exner(nzb:nzt+1) ) |
---|
| 1916 | ALLOCATE( hyrho(nzb:nzt+1) ) |
---|
[1849] | 1917 | ! |
---|
[3274] | 1918 | !-- Check temperature in case of too large domain height |
---|
| 1919 | DO k = nzb, nzt+1 |
---|
| 1920 | IF ( ( pt_surface * exner_function(surface_pressure * 100.0_wp) - g/c_p * zu(k) ) < 0.0_wp ) THEN |
---|
| 1921 | WRITE( message_string, * ) 'absolute temperature < 0.0 at zu(', k, & |
---|
| 1922 | ') = ', zu(k) |
---|
[3685] | 1923 | CALL message( 'init_3d_model', 'PA0142', 1, 2, 0, 6, 0 ) |
---|
[3274] | 1924 | ENDIF |
---|
| 1925 | ENDDO |
---|
| 1926 | |
---|
| 1927 | ! |
---|
| 1928 | !-- Calculate vertical profile of the hydrostatic pressure (hyp) |
---|
| 1929 | hyp = barometric_formula(zu, pt_surface * exner_function(surface_pressure * 100.0_wp), surface_pressure * 100.0_wp) |
---|
| 1930 | d_exner = exner_function_invers(hyp) |
---|
| 1931 | exner = 1.0_wp / exner_function_invers(hyp) |
---|
| 1932 | hyrho = ideal_gas_law_rho_pt(hyp, pt_init) |
---|
| 1933 | ! |
---|
| 1934 | !-- Compute reference density |
---|
| 1935 | rho_surface = ideal_gas_law_rho(surface_pressure * 100.0_wp, pt_surface * exner_function(surface_pressure * 100.0_wp)) |
---|
| 1936 | |
---|
[96] | 1937 | ENDIF |
---|
[1] | 1938 | |
---|
| 1939 | ! |
---|
| 1940 | !-- If required, initialize particles |
---|
[3159] | 1941 | IF ( agents_active ) CALL mas_init |
---|
| 1942 | ! |
---|
[3937] | 1943 | !-- Initialization of synthetic turbulence generator |
---|
| 1944 | IF ( use_syn_turb_gen ) CALL stg_init |
---|
[2696] | 1945 | ! |
---|
[3685] | 1946 | !-- Initializing actions for all other modules |
---|
| 1947 | CALL module_interface_init |
---|
[2696] | 1948 | ! |
---|
[3685] | 1949 | !-- Initialize surface layer (done after LSM as roughness length are required |
---|
| 1950 | !-- for initialization |
---|
| 1951 | IF ( constant_flux_layer ) CALL init_surface_layer_fluxes |
---|
[2977] | 1952 | ! |
---|
[3421] | 1953 | !-- Initialize surface data output |
---|
[3685] | 1954 | IF ( surface_output ) CALL surface_data_output_init |
---|
[3472] | 1955 | ! |
---|
[673] | 1956 | !-- Initialize the ws-scheme. |
---|
[3448] | 1957 | IF ( ws_scheme_sca .OR. ws_scheme_mom ) CALL ws_init |
---|
[3711] | 1958 | ! |
---|
| 1959 | !-- Perform post-initializing checks for all other modules |
---|
| 1960 | CALL module_interface_init_checks |
---|
[1] | 1961 | |
---|
| 1962 | ! |
---|
[4548] | 1963 | !-- Initialize surface forcing corresponding to large-scale forcing. Therein, |
---|
| 1964 | !-- initialize heat-fluxes, etc. via datatype. Revise it later! |
---|
| 1965 | IF ( large_scale_forcing .AND. lsf_surf ) THEN |
---|
| 1966 | IF ( use_surface_fluxes .AND. constant_heatflux ) THEN |
---|
| 1967 | CALL ls_forcing_surf ( simulated_time ) |
---|
| 1968 | ENDIF |
---|
| 1969 | ENDIF |
---|
| 1970 | ! |
---|
[709] | 1971 | !-- Setting weighting factors for calculation of perturbation pressure |
---|
[1762] | 1972 | !-- and turbulent quantities from the RK substeps |
---|
[709] | 1973 | IF ( TRIM(timestep_scheme) == 'runge-kutta-3' ) THEN ! for RK3-method |
---|
| 1974 | |
---|
[1322] | 1975 | weight_substep(1) = 1._wp/6._wp |
---|
| 1976 | weight_substep(2) = 3._wp/10._wp |
---|
| 1977 | weight_substep(3) = 8._wp/15._wp |
---|
[709] | 1978 | |
---|
[1322] | 1979 | weight_pres(1) = 1._wp/3._wp |
---|
| 1980 | weight_pres(2) = 5._wp/12._wp |
---|
| 1981 | weight_pres(3) = 1._wp/4._wp |
---|
[709] | 1982 | |
---|
| 1983 | ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' ) THEN ! for RK2-method |
---|
| 1984 | |
---|
[1322] | 1985 | weight_substep(1) = 1._wp/2._wp |
---|
| 1986 | weight_substep(2) = 1._wp/2._wp |
---|
[673] | 1987 | |
---|
[1322] | 1988 | weight_pres(1) = 1._wp/2._wp |
---|
| 1989 | weight_pres(2) = 1._wp/2._wp |
---|
[709] | 1990 | |
---|
[1001] | 1991 | ELSE ! for Euler-method |
---|
[709] | 1992 | |
---|
[1340] | 1993 | weight_substep(1) = 1.0_wp |
---|
| 1994 | weight_pres(1) = 1.0_wp |
---|
[709] | 1995 | |
---|
[673] | 1996 | ENDIF |
---|
| 1997 | |
---|
| 1998 | ! |
---|
[1] | 1999 | !-- Initialize Rayleigh damping factors |
---|
[1340] | 2000 | rdf = 0.0_wp |
---|
| 2001 | rdf_sc = 0.0_wp |
---|
| 2002 | IF ( rayleigh_damping_factor /= 0.0_wp ) THEN |
---|
[3294] | 2003 | |
---|
| 2004 | IF ( .NOT. ocean_mode ) THEN |
---|
[108] | 2005 | DO k = nzb+1, nzt |
---|
| 2006 | IF ( zu(k) >= rayleigh_damping_height ) THEN |
---|
[1788] | 2007 | rdf(k) = rayleigh_damping_factor * & |
---|
[1340] | 2008 | ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height ) & |
---|
[1788] | 2009 | / ( zu(nzt) - rayleigh_damping_height ) ) & |
---|
[1] | 2010 | )**2 |
---|
[108] | 2011 | ENDIF |
---|
| 2012 | ENDDO |
---|
| 2013 | ELSE |
---|
[3294] | 2014 | ! |
---|
| 2015 | !-- In ocean mode, rayleigh damping is applied in the lower part of the |
---|
| 2016 | !-- model domain |
---|
[108] | 2017 | DO k = nzt, nzb+1, -1 |
---|
| 2018 | IF ( zu(k) <= rayleigh_damping_height ) THEN |
---|
[1788] | 2019 | rdf(k) = rayleigh_damping_factor * & |
---|
[1340] | 2020 | ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) ) & |
---|
[1788] | 2021 | / ( rayleigh_damping_height - zu(nzb+1) ) ) & |
---|
[108] | 2022 | )**2 |
---|
| 2023 | ENDIF |
---|
| 2024 | ENDDO |
---|
| 2025 | ENDIF |
---|
[3294] | 2026 | |
---|
[1] | 2027 | ENDIF |
---|
[785] | 2028 | IF ( scalar_rayleigh_damping ) rdf_sc = rdf |
---|
[1] | 2029 | |
---|
| 2030 | ! |
---|
[240] | 2031 | !-- Initialize the starting level and the vertical smoothing factor used for |
---|
| 2032 | !-- the external pressure gradient |
---|
[1340] | 2033 | dp_smooth_factor = 1.0_wp |
---|
[240] | 2034 | IF ( dp_external ) THEN |
---|
| 2035 | ! |
---|
| 2036 | !-- Set the starting level dp_level_ind_b only if it has not been set before |
---|
| 2037 | !-- (e.g. in init_grid). |
---|
| 2038 | IF ( dp_level_ind_b == 0 ) THEN |
---|
| 2039 | ind_array = MINLOC( ABS( dp_level_b - zu ) ) |
---|
| 2040 | dp_level_ind_b = ind_array(1) - 1 + nzb |
---|
| 2041 | ! MINLOC uses lower array bound 1 |
---|
| 2042 | ENDIF |
---|
| 2043 | IF ( dp_smooth ) THEN |
---|
[1340] | 2044 | dp_smooth_factor(:dp_level_ind_b) = 0.0_wp |
---|
[240] | 2045 | DO k = dp_level_ind_b+1, nzt |
---|
[1340] | 2046 | dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi * & |
---|
| 2047 | ( REAL( k - dp_level_ind_b, KIND=wp ) / & |
---|
| 2048 | REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) ) |
---|
[240] | 2049 | ENDDO |
---|
| 2050 | ENDIF |
---|
| 2051 | ENDIF |
---|
| 2052 | |
---|
| 2053 | ! |
---|
[978] | 2054 | !-- Initialize damping zone for the potential temperature in case of |
---|
| 2055 | !-- non-cyclic lateral boundaries. The damping zone has the maximum value |
---|
| 2056 | !-- at the inflow boundary and decreases to zero at pt_damping_width. |
---|
[1340] | 2057 | ptdf_x = 0.0_wp |
---|
| 2058 | ptdf_y = 0.0_wp |
---|
[1159] | 2059 | IF ( bc_lr_dirrad ) THEN |
---|
[996] | 2060 | DO i = nxl, nxr |
---|
[978] | 2061 | IF ( ( i * dx ) < pt_damping_width ) THEN |
---|
[1340] | 2062 | ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp * & |
---|
| 2063 | REAL( pt_damping_width - i * dx, KIND=wp ) / ( & |
---|
[1788] | 2064 | REAL( pt_damping_width, KIND=wp ) ) ) )**2 |
---|
[73] | 2065 | ENDIF |
---|
| 2066 | ENDDO |
---|
[1159] | 2067 | ELSEIF ( bc_lr_raddir ) THEN |
---|
[996] | 2068 | DO i = nxl, nxr |
---|
[978] | 2069 | IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) ) THEN |
---|
[1322] | 2070 | ptdf_x(i) = pt_damping_factor * & |
---|
[1340] | 2071 | SIN( pi * 0.5_wp * & |
---|
| 2072 | ( ( i - nx ) * dx + pt_damping_width ) / & |
---|
| 2073 | REAL( pt_damping_width, KIND=wp ) )**2 |
---|
[73] | 2074 | ENDIF |
---|
[978] | 2075 | ENDDO |
---|
[1159] | 2076 | ELSEIF ( bc_ns_dirrad ) THEN |
---|
[996] | 2077 | DO j = nys, nyn |
---|
[978] | 2078 | IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) ) THEN |
---|
[1322] | 2079 | ptdf_y(j) = pt_damping_factor * & |
---|
[1340] | 2080 | SIN( pi * 0.5_wp * & |
---|
| 2081 | ( ( j - ny ) * dy + pt_damping_width ) / & |
---|
| 2082 | REAL( pt_damping_width, KIND=wp ) )**2 |
---|
[1] | 2083 | ENDIF |
---|
[978] | 2084 | ENDDO |
---|
[1159] | 2085 | ELSEIF ( bc_ns_raddir ) THEN |
---|
[996] | 2086 | DO j = nys, nyn |
---|
[978] | 2087 | IF ( ( j * dy ) < pt_damping_width ) THEN |
---|
[1322] | 2088 | ptdf_y(j) = pt_damping_factor * & |
---|
[1340] | 2089 | SIN( pi * 0.5_wp * & |
---|
| 2090 | ( pt_damping_width - j * dy ) / & |
---|
| 2091 | REAL( pt_damping_width, KIND=wp ) )**2 |
---|
[1] | 2092 | ENDIF |
---|
[73] | 2093 | ENDDO |
---|
[1] | 2094 | ENDIF |
---|
[51] | 2095 | |
---|
[1] | 2096 | ! |
---|
| 2097 | !-- Input binary data file is not needed anymore. This line must be placed |
---|
| 2098 | !-- after call of user_init! |
---|
| 2099 | CALL close_file( 13 ) |
---|
[2934] | 2100 | ! |
---|
| 2101 | !-- In case of nesting, put an barrier to assure that all parent and child |
---|
| 2102 | !-- domains finished initialization. |
---|
| 2103 | #if defined( __parallel ) |
---|
| 2104 | IF ( nested_run ) CALL MPI_BARRIER( MPI_COMM_WORLD, ierr ) |
---|
| 2105 | #endif |
---|
[1] | 2106 | |
---|
[2934] | 2107 | |
---|
[3987] | 2108 | CALL location_message( 'model initialization', 'finished' ) |
---|
[1] | 2109 | |
---|
| 2110 | END SUBROUTINE init_3d_model |
---|