[1682] | 1 | !> @file disturb_field.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 | ! |
---|
[2101] | 17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[1318] | 21 | ! ------------------ |
---|
[1354] | 22 | ! |
---|
[2233] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: disturb_field.f90 2696 2017-12-14 17:12:51Z raasch $ |
---|
[2300] | 27 | ! NEC related code removed |
---|
| 28 | ! |
---|
| 29 | ! 2233 2017-05-30 18:08:54Z suehring |
---|
[1321] | 30 | ! |
---|
[2233] | 31 | ! 2232 2017-05-30 17:47:52Z suehring |
---|
| 32 | ! Modify referenced parameter for disturb_field, instead of nzb_uv_inner, pass |
---|
| 33 | ! character to identify the respective grid (u- or v-grid). |
---|
| 34 | ! Set perturbations within topography to zero using flags. |
---|
| 35 | ! |
---|
[2173] | 36 | ! 2172 2017-03-08 15:55:25Z knoop |
---|
| 37 | ! Bugfix removed id_random_array from USE list |
---|
| 38 | ! |
---|
[2001] | 39 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 40 | ! Forced header and separation lines into 80 columns |
---|
| 41 | ! |
---|
[1683] | 42 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 43 | ! Code annotations made doxygen readable |
---|
| 44 | ! |
---|
[1426] | 45 | ! 1425 2014-07-05 10:57:53Z knoop |
---|
| 46 | ! bugfix: Parallel random number generator loop: print-statement no needed |
---|
| 47 | ! |
---|
[1401] | 48 | ! 1400 2014-05-09 14:03:54Z knoop |
---|
| 49 | ! Parallel random number generator added |
---|
| 50 | ! |
---|
[1354] | 51 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 52 | ! REAL constants provided with KIND-attribute |
---|
| 53 | ! |
---|
[1323] | 54 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 55 | ! REAL constants defined as wp-kind |
---|
| 56 | ! |
---|
[1321] | 57 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 58 | ! ONLY-attribute added to USE-statements, |
---|
| 59 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 60 | ! kinds are defined in new module kinds, |
---|
| 61 | ! revision history before 2012 removed, |
---|
| 62 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 63 | ! all variable declaration statements |
---|
[1] | 64 | ! |
---|
[1037] | 65 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 66 | ! code put under GPL (PALM 3.9) |
---|
| 67 | ! |
---|
[1] | 68 | ! Revision 1.1 1998/02/04 15:40:45 raasch |
---|
| 69 | ! Initial revision |
---|
| 70 | ! |
---|
| 71 | ! |
---|
| 72 | ! Description: |
---|
| 73 | ! ------------ |
---|
[1682] | 74 | !> Imposing a random perturbation on a 3D-array. |
---|
| 75 | !> On parallel computers, the random number generator is as well called for all |
---|
| 76 | !> gridpoints of the total domain to ensure, regardless of the number of PEs |
---|
| 77 | !> used, that the elements of the array have the same values in the same |
---|
| 78 | !> order in every case. The perturbation range is steered by dist_range. |
---|
[1] | 79 | !------------------------------------------------------------------------------! |
---|
[2232] | 80 | SUBROUTINE disturb_field( var_char, dist1, field ) |
---|
[1682] | 81 | |
---|
[1] | 82 | |
---|
[2232] | 83 | USE control_parameters, & |
---|
[1320] | 84 | ONLY: dist_nxl, dist_nxr, dist_nyn, dist_nys, dist_range, & |
---|
| 85 | disturbance_amplitude, disturbance_created, & |
---|
| 86 | disturbance_level_ind_b, disturbance_level_ind_t, iran, & |
---|
| 87 | random_generator, topography |
---|
| 88 | |
---|
| 89 | USE cpulog, & |
---|
| 90 | ONLY: cpu_log, log_point |
---|
| 91 | |
---|
| 92 | USE indices, & |
---|
[2232] | 93 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzb_max, & |
---|
| 94 | nzt, wall_flags_0 |
---|
[1320] | 95 | |
---|
| 96 | USE kinds |
---|
| 97 | |
---|
| 98 | USE random_function_mod, & |
---|
| 99 | ONLY: random_function |
---|
[1400] | 100 | |
---|
| 101 | USE random_generator_parallel, & |
---|
| 102 | ONLY: random_number_parallel, random_seed_parallel, random_dummy, & |
---|
[2172] | 103 | seq_random_array |
---|
[1] | 104 | |
---|
| 105 | IMPLICIT NONE |
---|
| 106 | |
---|
[2232] | 107 | CHARACTER (LEN = *) :: var_char !< flag to distinguish betwenn u- and v-component |
---|
[1] | 108 | |
---|
[2232] | 109 | INTEGER(iwp) :: flag_nr !< number of respective flag for u- or v-grid |
---|
| 110 | INTEGER(iwp) :: i !< index variable |
---|
| 111 | INTEGER(iwp) :: j !< index variable |
---|
| 112 | INTEGER(iwp) :: k !< index variable |
---|
| 113 | |
---|
[1682] | 114 | REAL(wp) :: randomnumber !< |
---|
[1320] | 115 | |
---|
[1682] | 116 | REAL(wp) :: dist1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
| 117 | REAL(wp) :: field(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
[1320] | 118 | |
---|
[1682] | 119 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: dist2 !< |
---|
[1] | 120 | |
---|
| 121 | |
---|
| 122 | CALL cpu_log( log_point(20), 'disturb_field', 'start' ) |
---|
| 123 | ! |
---|
[2232] | 124 | !-- Set flag number, 20 for u-grid, 21 for v-grid, required to mask topography |
---|
| 125 | flag_nr = MERGE( 20, 21, TRIM(var_char) == 'u' ) |
---|
| 126 | ! |
---|
[1] | 127 | !-- Create an additional temporary array and initialize the arrays needed |
---|
| 128 | !-- to store the disturbance |
---|
[667] | 129 | ALLOCATE( dist2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1353] | 130 | dist1 = 0.0_wp |
---|
| 131 | dist2 = 0.0_wp |
---|
[1] | 132 | |
---|
| 133 | ! |
---|
| 134 | !-- Create the random perturbation and store it on temporary array |
---|
| 135 | IF ( random_generator == 'numerical-recipes' ) THEN |
---|
| 136 | DO i = dist_nxl(dist_range), dist_nxr(dist_range) |
---|
| 137 | DO j = dist_nys(dist_range), dist_nyn(dist_range) |
---|
| 138 | DO k = disturbance_level_ind_b, disturbance_level_ind_t |
---|
[1322] | 139 | randomnumber = 3.0_wp * disturbance_amplitude * & |
---|
| 140 | ( random_function( iran ) - 0.5_wp ) |
---|
[1320] | 141 | IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. & |
---|
| 142 | nyn >= j ) & |
---|
[1] | 143 | THEN |
---|
| 144 | dist1(k,j,i) = randomnumber |
---|
| 145 | ENDIF |
---|
| 146 | ENDDO |
---|
| 147 | ENDDO |
---|
| 148 | ENDDO |
---|
[1400] | 149 | ELSEIF ( random_generator == 'random-parallel' ) THEN |
---|
| 150 | DO i = dist_nxl(dist_range), dist_nxr(dist_range) |
---|
| 151 | DO j = dist_nys(dist_range), dist_nyn(dist_range) |
---|
| 152 | CALL random_seed_parallel( put=seq_random_array(:, j, i) ) |
---|
| 153 | DO k = disturbance_level_ind_b, disturbance_level_ind_t |
---|
| 154 | CALL random_number_parallel( random_dummy ) |
---|
| 155 | randomnumber = 3.0_wp * disturbance_amplitude * & |
---|
| 156 | ( random_dummy - 0.5_wp ) |
---|
| 157 | IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. & |
---|
| 158 | nyn >= j ) & |
---|
| 159 | THEN |
---|
| 160 | dist1(k,j,i) = randomnumber |
---|
| 161 | ENDIF |
---|
| 162 | ENDDO |
---|
| 163 | CALL random_seed_parallel( get=seq_random_array(:, j, i) ) |
---|
| 164 | ENDDO |
---|
| 165 | ENDDO |
---|
[1] | 166 | ELSEIF ( random_generator == 'system-specific' ) THEN |
---|
| 167 | DO i = dist_nxl(dist_range), dist_nxr(dist_range) |
---|
| 168 | DO j = dist_nys(dist_range), dist_nyn(dist_range) |
---|
| 169 | DO k = disturbance_level_ind_b, disturbance_level_ind_t |
---|
| 170 | CALL RANDOM_NUMBER( randomnumber ) |
---|
[1322] | 171 | randomnumber = 3.0_wp * disturbance_amplitude * & |
---|
| 172 | ( randomnumber - 0.5_wp ) |
---|
[1320] | 173 | IF ( nxl <= i .AND. nxr >= i .AND. nys <= j .AND. nyn >= j ) & |
---|
[1] | 174 | THEN |
---|
| 175 | dist1(k,j,i) = randomnumber |
---|
| 176 | ENDIF |
---|
| 177 | ENDDO |
---|
| 178 | ENDDO |
---|
| 179 | ENDDO |
---|
| 180 | |
---|
| 181 | ENDIF |
---|
| 182 | |
---|
| 183 | ! |
---|
| 184 | !-- Exchange of ghost points for the random perturbation |
---|
[420] | 185 | |
---|
[667] | 186 | CALL exchange_horiz( dist1, nbgp ) |
---|
[1] | 187 | ! |
---|
| 188 | !-- Applying the Shuman filter in order to smooth the perturbations. |
---|
| 189 | !-- Neighboured grid points in all three directions are used for the |
---|
| 190 | !-- filter operation. |
---|
[420] | 191 | !-- Loop has been splitted to make runs reproducible on HLRN systems using |
---|
| 192 | !-- compiler option -O3 |
---|
| 193 | DO i = nxl, nxr |
---|
| 194 | DO j = nys, nyn |
---|
[1] | 195 | DO k = disturbance_level_ind_b-1, disturbance_level_ind_t+1 |
---|
[1320] | 196 | dist2(k,j,i) = ( dist1(k,j,i-1) + dist1(k,j,i+1) & |
---|
| 197 | + dist1(k,j+1,i) + dist1(k+1,j,i) & |
---|
[1322] | 198 | ) / 12.0_wp |
---|
[420] | 199 | ENDDO |
---|
| 200 | DO k = disturbance_level_ind_b-1, disturbance_level_ind_t+1 |
---|
| 201 | dist2(k,j,i) = dist2(k,j,i) + ( dist1(k,j-1,i) + dist1(k-1,j,i) & |
---|
[1322] | 202 | + 6.0_wp * dist1(k,j,i) & |
---|
| 203 | ) / 12.0_wp |
---|
[1] | 204 | ENDDO |
---|
[420] | 205 | ENDDO |
---|
| 206 | ENDDO |
---|
[1] | 207 | |
---|
| 208 | ! |
---|
| 209 | !-- Exchange of ghost points for the filtered perturbation. |
---|
| 210 | !-- Afterwards, filter operation and exchange of ghost points are repeated. |
---|
[667] | 211 | CALL exchange_horiz( dist2, nbgp ) |
---|
[420] | 212 | |
---|
[1] | 213 | DO i = nxl, nxr |
---|
| 214 | DO j = nys, nyn |
---|
| 215 | DO k = disturbance_level_ind_b-2, disturbance_level_ind_t+2 |
---|
| 216 | dist1(k,j,i) = ( dist2(k,j,i-1) + dist2(k,j,i+1) + dist2(k,j-1,i) & |
---|
| 217 | + dist2(k,j+1,i) + dist2(k+1,j,i) + dist2(k-1,j,i) & |
---|
[1322] | 218 | + 6.0_wp * dist2(k,j,i) & |
---|
| 219 | ) / 12.0_wp |
---|
[1] | 220 | ENDDO |
---|
| 221 | ENDDO |
---|
| 222 | ENDDO |
---|
[420] | 223 | |
---|
[667] | 224 | CALL exchange_horiz( dist1, nbgp ) |
---|
[1] | 225 | |
---|
| 226 | ! |
---|
| 227 | !-- Remove perturbations below topography (including one gridpoint above it |
---|
| 228 | !-- in order to allow for larger timesteps at the beginning of the simulation |
---|
| 229 | !-- (diffusion criterion)) |
---|
| 230 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
[667] | 231 | DO i = nxlg, nxrg |
---|
| 232 | DO j = nysg, nyng |
---|
[2232] | 233 | DO k = nzb, nzb_max |
---|
| 234 | dist1(k,j,i) = MERGE( dist1(k,j,i), 0.0_wp, & |
---|
| 235 | BTEST( wall_flags_0(k,j,i), flag_nr ) & |
---|
| 236 | ) |
---|
| 237 | ENDDO |
---|
[1] | 238 | ENDDO |
---|
| 239 | ENDDO |
---|
| 240 | ENDIF |
---|
| 241 | |
---|
| 242 | ! |
---|
| 243 | !-- Random perturbation is added to the array to be disturbed. |
---|
[667] | 244 | DO i = nxlg, nxrg |
---|
| 245 | DO j = nysg, nyng |
---|
[1] | 246 | DO k = disturbance_level_ind_b-2, disturbance_level_ind_t+2 |
---|
| 247 | field(k,j,i) = field(k,j,i) + dist1(k,j,i) |
---|
| 248 | ENDDO |
---|
| 249 | ENDDO |
---|
| 250 | ENDDO |
---|
| 251 | |
---|
| 252 | ! |
---|
| 253 | !-- Deallocate the temporary array |
---|
| 254 | DEALLOCATE( dist2 ) |
---|
| 255 | |
---|
| 256 | ! |
---|
| 257 | !-- Set a flag, which indicates that a random perturbation is imposed |
---|
| 258 | disturbance_created = .TRUE. |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | CALL cpu_log( log_point(20), 'disturb_field', 'stop' ) |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | END SUBROUTINE disturb_field |
---|