[1850] | 1 | !> @file tridia_solver_mod.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1212] | 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. |
---|
[1212] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[2718] | 17 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1212] | 19 | ! |
---|
| 20 | ! Current revisions: |
---|
| 21 | ! ------------------ |
---|
[1851] | 22 | ! |
---|
[2119] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: tridia_solver_mod.f90 2718 2018-01-02 08:49:38Z kanani $ |
---|
[2716] | 27 | ! Corrected "Former revisions" section |
---|
| 28 | ! |
---|
| 29 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 30 | ! Change in file header (GPL part) |
---|
[1321] | 31 | ! |
---|
[2716] | 32 | ! 2119 2017-01-17 16:51:50Z raasch |
---|
| 33 | ! |
---|
[2119] | 34 | ! 2118 2017-01-17 16:38:49Z raasch |
---|
| 35 | ! OpenACC directives removed |
---|
| 36 | ! |
---|
[2038] | 37 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
| 38 | ! Anelastic approximation implemented |
---|
| 39 | ! |
---|
[2001] | 40 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 41 | ! Forced header and separation lines into 80 columns |
---|
| 42 | ! |
---|
[1851] | 43 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
| 44 | ! Module renamed |
---|
| 45 | ! |
---|
| 46 | ! |
---|
[1816] | 47 | ! 1815 2016-04-06 13:49:59Z raasch |
---|
| 48 | ! cpp-switch intel11 removed |
---|
| 49 | ! |
---|
[1809] | 50 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 51 | ! test output removed |
---|
| 52 | ! |
---|
[1805] | 53 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
| 54 | ! Removed code for parameter file check (__check) |
---|
| 55 | ! |
---|
[1683] | 56 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 57 | ! Code annotations made doxygen readable |
---|
| 58 | ! |
---|
[1407] | 59 | ! 1406 2014-05-16 13:47:01Z raasch |
---|
| 60 | ! bugfix for pgi 14.4: declare create moved after array declaration |
---|
| 61 | ! |
---|
[1343] | 62 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
| 63 | ! REAL constants defined as wp-kind |
---|
| 64 | ! |
---|
[1323] | 65 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 66 | ! REAL functions provided with KIND-attribute |
---|
| 67 | ! |
---|
[1321] | 68 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 69 | ! ONLY-attribute added to USE-statements, |
---|
| 70 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 71 | ! kinds are defined in new module kinds, |
---|
| 72 | ! old module precision_kind is removed, |
---|
| 73 | ! revision history before 2012 removed, |
---|
| 74 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 75 | ! all variable declaration statements |
---|
[1213] | 76 | ! |
---|
[1258] | 77 | ! 1257 2013-11-08 15:18:40Z raasch |
---|
| 78 | ! openacc loop and loop vector clauses removed, declare create moved after |
---|
| 79 | ! the FORTRAN declaration statement |
---|
| 80 | ! |
---|
[1222] | 81 | ! 1221 2013-09-10 08:59:13Z raasch |
---|
| 82 | ! dummy argument tri in 1d-routines replaced by tri_for_1d because of name |
---|
| 83 | ! conflict with arry tri in module arrays_3d |
---|
| 84 | ! |
---|
[1217] | 85 | ! 1216 2013-08-26 09:31:42Z raasch |
---|
| 86 | ! +tridia_substi_overlap for handling overlapping fft / transposition |
---|
| 87 | ! |
---|
[1213] | 88 | ! 1212 2013-08-15 08:46:27Z raasch |
---|
[1212] | 89 | ! Initial revision. |
---|
| 90 | ! Routines have been moved to seperate module from former file poisfft to here. |
---|
| 91 | ! The tridiagonal matrix coefficients of array tri are calculated only once at |
---|
| 92 | ! the beginning, i.e. routine split is called within tridia_init. |
---|
| 93 | ! |
---|
| 94 | ! |
---|
| 95 | ! Description: |
---|
| 96 | ! ------------ |
---|
[1682] | 97 | !> solves the linear system of equations: |
---|
| 98 | !> |
---|
| 99 | !> -(4 pi^2(i^2/(dx^2*nnx^2)+j^2/(dy^2*nny^2))+ |
---|
| 100 | !> 1/(dzu(k)*dzw(k))+1/(dzu(k-1)*dzw(k)))*p(i,j,k)+ |
---|
| 101 | !> 1/(dzu(k)*dzw(k))*p(i,j,k+1)+1/(dzu(k-1)*dzw(k))*p(i,j,k-1)=d(i,j,k) |
---|
| 102 | !> |
---|
| 103 | !> by using the Thomas algorithm |
---|
[1212] | 104 | !------------------------------------------------------------------------------! |
---|
[1682] | 105 | MODULE tridia_solver |
---|
| 106 | |
---|
[1212] | 107 | |
---|
[1320] | 108 | USE indices, & |
---|
| 109 | ONLY: nx, ny, nz |
---|
[1212] | 110 | |
---|
[1320] | 111 | USE kinds |
---|
| 112 | |
---|
| 113 | USE transpose_indices, & |
---|
| 114 | ONLY: nxl_z, nyn_z, nxr_z, nys_z |
---|
| 115 | |
---|
[1212] | 116 | IMPLICIT NONE |
---|
| 117 | |
---|
[1682] | 118 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: ddzuw !< |
---|
[1212] | 119 | |
---|
| 120 | PRIVATE |
---|
| 121 | |
---|
| 122 | INTERFACE tridia_substi |
---|
| 123 | MODULE PROCEDURE tridia_substi |
---|
| 124 | END INTERFACE tridia_substi |
---|
| 125 | |
---|
[1216] | 126 | INTERFACE tridia_substi_overlap |
---|
| 127 | MODULE PROCEDURE tridia_substi_overlap |
---|
| 128 | END INTERFACE tridia_substi_overlap |
---|
[1212] | 129 | |
---|
[1216] | 130 | PUBLIC tridia_substi, tridia_substi_overlap, tridia_init, tridia_1dd |
---|
| 131 | |
---|
[1212] | 132 | CONTAINS |
---|
| 133 | |
---|
| 134 | |
---|
[1682] | 135 | !------------------------------------------------------------------------------! |
---|
| 136 | ! Description: |
---|
| 137 | ! ------------ |
---|
| 138 | !> @todo Missing subroutine description. |
---|
| 139 | !------------------------------------------------------------------------------! |
---|
[1212] | 140 | SUBROUTINE tridia_init |
---|
| 141 | |
---|
[1320] | 142 | USE arrays_3d, & |
---|
[2037] | 143 | ONLY: ddzu_pres, ddzw, rho_air_zw |
---|
[1212] | 144 | |
---|
[1320] | 145 | USE kinds |
---|
| 146 | |
---|
[1212] | 147 | IMPLICIT NONE |
---|
| 148 | |
---|
[1682] | 149 | INTEGER(iwp) :: k !< |
---|
[1212] | 150 | |
---|
| 151 | ALLOCATE( ddzuw(0:nz-1,3) ) |
---|
| 152 | |
---|
| 153 | DO k = 0, nz-1 |
---|
[2037] | 154 | ddzuw(k,1) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) |
---|
| 155 | ddzuw(k,2) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) |
---|
[1342] | 156 | ddzuw(k,3) = -1.0_wp * & |
---|
[2037] | 157 | ( ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) + & |
---|
| 158 | ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) ) |
---|
[1212] | 159 | ENDDO |
---|
| 160 | ! |
---|
| 161 | !-- Calculate constant coefficients of the tridiagonal matrix |
---|
| 162 | CALL maketri |
---|
| 163 | CALL split |
---|
| 164 | |
---|
| 165 | END SUBROUTINE tridia_init |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | !------------------------------------------------------------------------------! |
---|
[1682] | 169 | ! Description: |
---|
| 170 | ! ------------ |
---|
| 171 | !> Computes the i- and j-dependent component of the matrix |
---|
| 172 | !> Provide the constant coefficients of the tridiagonal matrix for solution |
---|
| 173 | !> of the Poisson equation in Fourier space. |
---|
| 174 | !> The coefficients are computed following the method of |
---|
| 175 | !> Schmidt et al. (DFVLR-Mitteilung 84-15), which departs from Stephan |
---|
| 176 | !> Siano's original version by discretizing the Poisson equation, |
---|
| 177 | !> before it is Fourier-transformed. |
---|
[1212] | 178 | !------------------------------------------------------------------------------! |
---|
[1682] | 179 | SUBROUTINE maketri |
---|
[1212] | 180 | |
---|
[1682] | 181 | |
---|
[1320] | 182 | USE arrays_3d, & |
---|
[2037] | 183 | ONLY: tric, rho_air |
---|
[1212] | 184 | |
---|
[1320] | 185 | USE constants, & |
---|
| 186 | ONLY: pi |
---|
| 187 | |
---|
| 188 | USE control_parameters, & |
---|
| 189 | ONLY: ibc_p_b, ibc_p_t |
---|
| 190 | |
---|
| 191 | USE grid_variables, & |
---|
| 192 | ONLY: dx, dy |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | USE kinds |
---|
| 196 | |
---|
[1212] | 197 | IMPLICIT NONE |
---|
| 198 | |
---|
[1682] | 199 | INTEGER(iwp) :: i !< |
---|
| 200 | INTEGER(iwp) :: j !< |
---|
| 201 | INTEGER(iwp) :: k !< |
---|
| 202 | INTEGER(iwp) :: nnxh !< |
---|
| 203 | INTEGER(iwp) :: nnyh !< |
---|
[1212] | 204 | |
---|
[1682] | 205 | REAL(wp) :: ll(nxl_z:nxr_z,nys_z:nyn_z) !< |
---|
[1212] | 206 | |
---|
| 207 | |
---|
| 208 | nnxh = ( nx + 1 ) / 2 |
---|
| 209 | nnyh = ( ny + 1 ) / 2 |
---|
| 210 | |
---|
| 211 | DO j = nys_z, nyn_z |
---|
| 212 | DO i = nxl_z, nxr_z |
---|
| 213 | IF ( j >= 0 .AND. j <= nnyh ) THEN |
---|
| 214 | IF ( i >= 0 .AND. i <= nnxh ) THEN |
---|
[1342] | 215 | ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / & |
---|
| 216 | REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + & |
---|
| 217 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / & |
---|
| 218 | REAL( ny+1, KIND=wp ) ) ) / ( dy * dy ) |
---|
[1212] | 219 | ELSE |
---|
[1342] | 220 | ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / & |
---|
| 221 | REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + & |
---|
| 222 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / & |
---|
| 223 | REAL( ny+1, KIND=wp ) ) ) / ( dy * dy ) |
---|
[1212] | 224 | ENDIF |
---|
| 225 | ELSE |
---|
| 226 | IF ( i >= 0 .AND. i <= nnxh ) THEN |
---|
[1342] | 227 | ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / & |
---|
| 228 | REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + & |
---|
| 229 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) / & |
---|
| 230 | REAL( ny+1, KIND=wp ) ) ) / ( dy * dy ) |
---|
[1212] | 231 | ELSE |
---|
[1342] | 232 | ll(i,j) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / & |
---|
| 233 | REAL( nx+1, KIND=wp ) ) ) / ( dx * dx ) + & |
---|
| 234 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( ny+1-j ) ) / & |
---|
| 235 | REAL( ny+1, KIND=wp ) ) ) / ( dy * dy ) |
---|
[1212] | 236 | ENDIF |
---|
| 237 | ENDIF |
---|
| 238 | ENDDO |
---|
| 239 | ENDDO |
---|
| 240 | |
---|
| 241 | DO k = 0, nz-1 |
---|
| 242 | DO j = nys_z, nyn_z |
---|
| 243 | DO i = nxl_z, nxr_z |
---|
[2037] | 244 | tric(i,j,k) = ddzuw(k,3) - ll(i,j) * rho_air(k+1) |
---|
[1212] | 245 | ENDDO |
---|
| 246 | ENDDO |
---|
| 247 | ENDDO |
---|
| 248 | |
---|
| 249 | IF ( ibc_p_b == 1 ) THEN |
---|
| 250 | DO j = nys_z, nyn_z |
---|
| 251 | DO i = nxl_z, nxr_z |
---|
| 252 | tric(i,j,0) = tric(i,j,0) + ddzuw(0,1) |
---|
| 253 | ENDDO |
---|
| 254 | ENDDO |
---|
| 255 | ENDIF |
---|
| 256 | IF ( ibc_p_t == 1 ) THEN |
---|
| 257 | DO j = nys_z, nyn_z |
---|
| 258 | DO i = nxl_z, nxr_z |
---|
| 259 | tric(i,j,nz-1) = tric(i,j,nz-1) + ddzuw(nz-1,2) |
---|
| 260 | ENDDO |
---|
| 261 | ENDDO |
---|
| 262 | ENDIF |
---|
| 263 | |
---|
| 264 | END SUBROUTINE maketri |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | !------------------------------------------------------------------------------! |
---|
[1682] | 268 | ! Description: |
---|
| 269 | ! ------------ |
---|
| 270 | !> Substitution (Forward and Backward) (Thomas algorithm) |
---|
[1212] | 271 | !------------------------------------------------------------------------------! |
---|
[1682] | 272 | SUBROUTINE tridia_substi( ar ) |
---|
[1212] | 273 | |
---|
[1682] | 274 | |
---|
[1320] | 275 | USE arrays_3d, & |
---|
| 276 | ONLY: tri |
---|
[1212] | 277 | |
---|
[1320] | 278 | USE control_parameters, & |
---|
| 279 | ONLY: ibc_p_b, ibc_p_t |
---|
| 280 | |
---|
| 281 | USE kinds |
---|
| 282 | |
---|
[1212] | 283 | IMPLICIT NONE |
---|
| 284 | |
---|
[1682] | 285 | INTEGER(iwp) :: i !< |
---|
| 286 | INTEGER(iwp) :: j !< |
---|
| 287 | INTEGER(iwp) :: k !< |
---|
[1212] | 288 | |
---|
[1682] | 289 | REAL(wp) :: ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz) !< |
---|
[1212] | 290 | |
---|
[1682] | 291 | REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) :: ar1 !< |
---|
[1212] | 292 | |
---|
| 293 | ! |
---|
| 294 | !-- Forward substitution |
---|
| 295 | DO k = 0, nz - 1 |
---|
| 296 | DO j = nys_z, nyn_z |
---|
| 297 | DO i = nxl_z, nxr_z |
---|
| 298 | |
---|
| 299 | IF ( k == 0 ) THEN |
---|
| 300 | ar1(i,j,k) = ar(i,j,k+1) |
---|
| 301 | ELSE |
---|
| 302 | ar1(i,j,k) = ar(i,j,k+1) - tri(i,j,k,2) * ar1(i,j,k-1) |
---|
| 303 | ENDIF |
---|
| 304 | |
---|
| 305 | ENDDO |
---|
| 306 | ENDDO |
---|
| 307 | ENDDO |
---|
| 308 | |
---|
| 309 | ! |
---|
| 310 | !-- Backward substitution |
---|
| 311 | !-- Note, the 1.0E-20 in the denominator is due to avoid divisions |
---|
| 312 | !-- by zero appearing if the pressure bc is set to neumann at the top of |
---|
| 313 | !-- the model domain. |
---|
| 314 | DO k = nz-1, 0, -1 |
---|
| 315 | DO j = nys_z, nyn_z |
---|
| 316 | DO i = nxl_z, nxr_z |
---|
| 317 | |
---|
| 318 | IF ( k == nz-1 ) THEN |
---|
[1342] | 319 | ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,j,k,1) + 1.0E-20_wp ) |
---|
[1212] | 320 | ELSE |
---|
| 321 | ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) & |
---|
| 322 | / tri(i,j,k,1) |
---|
| 323 | ENDIF |
---|
| 324 | ENDDO |
---|
| 325 | ENDDO |
---|
| 326 | ENDDO |
---|
| 327 | |
---|
| 328 | ! |
---|
| 329 | !-- Indices i=0, j=0 correspond to horizontally averaged pressure. |
---|
| 330 | !-- The respective values of ar should be zero at all k-levels if |
---|
| 331 | !-- acceleration of horizontally averaged vertical velocity is zero. |
---|
| 332 | IF ( ibc_p_b == 1 .AND. ibc_p_t == 1 ) THEN |
---|
| 333 | IF ( nys_z == 0 .AND. nxl_z == 0 ) THEN |
---|
| 334 | DO k = 1, nz |
---|
[1342] | 335 | ar(nxl_z,nys_z,k) = 0.0_wp |
---|
[1212] | 336 | ENDDO |
---|
| 337 | ENDIF |
---|
| 338 | ENDIF |
---|
| 339 | |
---|
| 340 | END SUBROUTINE tridia_substi |
---|
| 341 | |
---|
| 342 | |
---|
[1216] | 343 | !------------------------------------------------------------------------------! |
---|
[1682] | 344 | ! Description: |
---|
| 345 | ! ------------ |
---|
| 346 | !> Substitution (Forward and Backward) (Thomas algorithm) |
---|
[1216] | 347 | !------------------------------------------------------------------------------! |
---|
[1682] | 348 | SUBROUTINE tridia_substi_overlap( ar, jj ) |
---|
[1216] | 349 | |
---|
[1682] | 350 | |
---|
[1320] | 351 | USE arrays_3d, & |
---|
| 352 | ONLY: tri |
---|
[1216] | 353 | |
---|
[1320] | 354 | USE control_parameters, & |
---|
| 355 | ONLY: ibc_p_b, ibc_p_t |
---|
| 356 | |
---|
| 357 | USE kinds |
---|
| 358 | |
---|
[1216] | 359 | IMPLICIT NONE |
---|
| 360 | |
---|
[1682] | 361 | INTEGER(iwp) :: i !< |
---|
| 362 | INTEGER(iwp) :: j !< |
---|
| 363 | INTEGER(iwp) :: jj !< |
---|
| 364 | INTEGER(iwp) :: k !< |
---|
[1216] | 365 | |
---|
[1682] | 366 | REAL(wp) :: ar(nxl_z:nxr_z,nys_z:nyn_z,1:nz) !< |
---|
[1216] | 367 | |
---|
[1682] | 368 | REAL(wp), DIMENSION(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) :: ar1 !< |
---|
[1216] | 369 | |
---|
| 370 | ! |
---|
| 371 | !-- Forward substitution |
---|
| 372 | DO k = 0, nz - 1 |
---|
| 373 | DO j = nys_z, nyn_z |
---|
| 374 | DO i = nxl_z, nxr_z |
---|
| 375 | |
---|
| 376 | IF ( k == 0 ) THEN |
---|
| 377 | ar1(i,j,k) = ar(i,j,k+1) |
---|
| 378 | ELSE |
---|
| 379 | ar1(i,j,k) = ar(i,j,k+1) - tri(i,jj,k,2) * ar1(i,j,k-1) |
---|
| 380 | ENDIF |
---|
| 381 | |
---|
| 382 | ENDDO |
---|
| 383 | ENDDO |
---|
| 384 | ENDDO |
---|
| 385 | |
---|
| 386 | ! |
---|
| 387 | !-- Backward substitution |
---|
| 388 | !-- Note, the 1.0E-20 in the denominator is due to avoid divisions |
---|
| 389 | !-- by zero appearing if the pressure bc is set to neumann at the top of |
---|
| 390 | !-- the model domain. |
---|
| 391 | DO k = nz-1, 0, -1 |
---|
| 392 | DO j = nys_z, nyn_z |
---|
| 393 | DO i = nxl_z, nxr_z |
---|
| 394 | |
---|
| 395 | IF ( k == nz-1 ) THEN |
---|
[1342] | 396 | ar(i,j,k+1) = ar1(i,j,k) / ( tri(i,jj,k,1) + 1.0E-20_wp ) |
---|
[1216] | 397 | ELSE |
---|
| 398 | ar(i,j,k+1) = ( ar1(i,j,k) - ddzuw(k,2) * ar(i,j,k+2) ) & |
---|
| 399 | / tri(i,jj,k,1) |
---|
| 400 | ENDIF |
---|
| 401 | ENDDO |
---|
| 402 | ENDDO |
---|
| 403 | ENDDO |
---|
| 404 | |
---|
| 405 | ! |
---|
| 406 | !-- Indices i=0, j=0 correspond to horizontally averaged pressure. |
---|
| 407 | !-- The respective values of ar should be zero at all k-levels if |
---|
| 408 | !-- acceleration of horizontally averaged vertical velocity is zero. |
---|
| 409 | IF ( ibc_p_b == 1 .AND. ibc_p_t == 1 ) THEN |
---|
| 410 | IF ( nys_z == 0 .AND. nxl_z == 0 ) THEN |
---|
| 411 | DO k = 1, nz |
---|
[1342] | 412 | ar(nxl_z,nys_z,k) = 0.0_wp |
---|
[1216] | 413 | ENDDO |
---|
| 414 | ENDIF |
---|
| 415 | ENDIF |
---|
| 416 | |
---|
| 417 | END SUBROUTINE tridia_substi_overlap |
---|
| 418 | |
---|
| 419 | |
---|
[1212] | 420 | !------------------------------------------------------------------------------! |
---|
[1682] | 421 | ! Description: |
---|
| 422 | ! ------------ |
---|
| 423 | !> Splitting of the tridiagonal matrix (Thomas algorithm) |
---|
[1212] | 424 | !------------------------------------------------------------------------------! |
---|
[1682] | 425 | SUBROUTINE split |
---|
[1212] | 426 | |
---|
[1682] | 427 | |
---|
[1320] | 428 | USE arrays_3d, & |
---|
| 429 | ONLY: tri, tric |
---|
[1212] | 430 | |
---|
[1320] | 431 | USE kinds |
---|
| 432 | |
---|
[1212] | 433 | IMPLICIT NONE |
---|
| 434 | |
---|
[1682] | 435 | INTEGER(iwp) :: i !< |
---|
| 436 | INTEGER(iwp) :: j !< |
---|
| 437 | INTEGER(iwp) :: k !< |
---|
[1212] | 438 | ! |
---|
| 439 | !-- Splitting |
---|
| 440 | DO j = nys_z, nyn_z |
---|
| 441 | DO i = nxl_z, nxr_z |
---|
| 442 | tri(i,j,0,1) = tric(i,j,0) |
---|
| 443 | ENDDO |
---|
| 444 | ENDDO |
---|
| 445 | |
---|
| 446 | DO k = 1, nz-1 |
---|
| 447 | DO j = nys_z, nyn_z |
---|
| 448 | DO i = nxl_z, nxr_z |
---|
| 449 | tri(i,j,k,2) = ddzuw(k,1) / tri(i,j,k-1,1) |
---|
| 450 | tri(i,j,k,1) = tric(i,j,k) - ddzuw(k-1,2) * tri(i,j,k,2) |
---|
| 451 | ENDDO |
---|
| 452 | ENDDO |
---|
| 453 | ENDDO |
---|
| 454 | |
---|
| 455 | END SUBROUTINE split |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | !------------------------------------------------------------------------------! |
---|
[1682] | 459 | ! Description: |
---|
| 460 | ! ------------ |
---|
| 461 | !> Solves the linear system of equations for a 1d-decomposition along x (see |
---|
| 462 | !> tridia) |
---|
| 463 | !> |
---|
| 464 | !> @attention when using the intel compilers older than 12.0, array tri must |
---|
| 465 | !> be passed as an argument to the contained subroutines. Otherwise |
---|
| 466 | !> addres faults will occur. This feature can be activated with |
---|
| 467 | !> cpp-switch __intel11 |
---|
| 468 | !> On NEC, tri should not be passed (except for routine substi_1dd) |
---|
| 469 | !> because this causes very bad performance. |
---|
[1212] | 470 | !------------------------------------------------------------------------------! |
---|
[1682] | 471 | |
---|
| 472 | SUBROUTINE tridia_1dd( ddx2, ddy2, nx, ny, j, ar, tri_for_1d ) |
---|
[1212] | 473 | |
---|
[1682] | 474 | |
---|
[1320] | 475 | USE arrays_3d, & |
---|
[2037] | 476 | ONLY: ddzu_pres, ddzw, rho_air, rho_air_zw |
---|
[1212] | 477 | |
---|
[1320] | 478 | USE control_parameters, & |
---|
| 479 | ONLY: ibc_p_b, ibc_p_t |
---|
[1212] | 480 | |
---|
[1320] | 481 | USE kinds |
---|
| 482 | |
---|
[1212] | 483 | IMPLICIT NONE |
---|
| 484 | |
---|
[1682] | 485 | INTEGER(iwp) :: i !< |
---|
| 486 | INTEGER(iwp) :: j !< |
---|
| 487 | INTEGER(iwp) :: k !< |
---|
| 488 | INTEGER(iwp) :: nnyh !< |
---|
| 489 | INTEGER(iwp) :: nx !< |
---|
| 490 | INTEGER(iwp) :: ny !< |
---|
| 491 | INTEGER(iwp) :: omp_get_thread_num !< |
---|
| 492 | INTEGER(iwp) :: tn !< |
---|
[1212] | 493 | |
---|
[1682] | 494 | REAL(wp) :: ddx2 !< |
---|
| 495 | REAL(wp) :: ddy2 !< |
---|
[1212] | 496 | |
---|
[1682] | 497 | REAL(wp), DIMENSION(0:nx,1:nz) :: ar !< |
---|
| 498 | REAL(wp), DIMENSION(5,0:nx,0:nz-1) :: tri_for_1d !< |
---|
[1212] | 499 | |
---|
| 500 | |
---|
| 501 | nnyh = ( ny + 1 ) / 2 |
---|
| 502 | |
---|
| 503 | ! |
---|
| 504 | !-- Define constant elements of the tridiagonal matrix. |
---|
| 505 | !-- The compiler on SX6 does loop exchange. If 0:nx is a high power of 2, |
---|
| 506 | !-- the exchanged loops create bank conflicts. The following directive |
---|
| 507 | !-- prohibits loop exchange and the loops perform much better. |
---|
| 508 | !CDIR NOLOOPCHG |
---|
| 509 | DO k = 0, nz-1 |
---|
| 510 | DO i = 0,nx |
---|
[2037] | 511 | tri_for_1d(2,i,k) = ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) |
---|
| 512 | tri_for_1d(3,i,k) = ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) |
---|
[1212] | 513 | ENDDO |
---|
| 514 | ENDDO |
---|
| 515 | |
---|
| 516 | IF ( j <= nnyh ) THEN |
---|
| 517 | CALL maketri_1dd( j ) |
---|
| 518 | ELSE |
---|
| 519 | CALL maketri_1dd( ny+1-j ) |
---|
| 520 | ENDIF |
---|
[1815] | 521 | |
---|
[1212] | 522 | CALL split_1dd |
---|
[1221] | 523 | CALL substi_1dd( ar, tri_for_1d ) |
---|
[1212] | 524 | |
---|
| 525 | CONTAINS |
---|
| 526 | |
---|
[1682] | 527 | |
---|
| 528 | !------------------------------------------------------------------------------! |
---|
| 529 | ! Description: |
---|
| 530 | ! ------------ |
---|
| 531 | !> computes the i- and j-dependent component of the matrix |
---|
| 532 | !------------------------------------------------------------------------------! |
---|
[1212] | 533 | SUBROUTINE maketri_1dd( j ) |
---|
| 534 | |
---|
[1320] | 535 | USE constants, & |
---|
| 536 | ONLY: pi |
---|
[1212] | 537 | |
---|
[1320] | 538 | USE kinds |
---|
| 539 | |
---|
[1212] | 540 | IMPLICIT NONE |
---|
| 541 | |
---|
[1682] | 542 | INTEGER(iwp) :: i !< |
---|
| 543 | INTEGER(iwp) :: j !< |
---|
| 544 | INTEGER(iwp) :: k !< |
---|
| 545 | INTEGER(iwp) :: nnxh !< |
---|
[1212] | 546 | |
---|
[1682] | 547 | REAL(wp) :: a !< |
---|
| 548 | REAL(wp) :: c !< |
---|
[1212] | 549 | |
---|
[1682] | 550 | REAL(wp), DIMENSION(0:nx) :: l !< |
---|
[1320] | 551 | |
---|
[1212] | 552 | |
---|
| 553 | nnxh = ( nx + 1 ) / 2 |
---|
| 554 | ! |
---|
| 555 | !-- Provide the tridiagonal matrix for solution of the Poisson equation in |
---|
| 556 | !-- Fourier space. The coefficients are computed following the method of |
---|
| 557 | !-- Schmidt et al. (DFVLR-Mitteilung 84-15), which departs from Stephan |
---|
| 558 | !-- Siano's original version by discretizing the Poisson equation, |
---|
| 559 | !-- before it is Fourier-transformed |
---|
| 560 | DO i = 0, nx |
---|
| 561 | IF ( i >= 0 .AND. i <= nnxh ) THEN |
---|
[1342] | 562 | l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * i ) / & |
---|
| 563 | REAL( nx+1, KIND=wp ) ) ) * ddx2 + & |
---|
| 564 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / & |
---|
| 565 | REAL( ny+1, KIND=wp ) ) ) * ddy2 |
---|
[1212] | 566 | ELSE |
---|
[1342] | 567 | l(i) = 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * ( nx+1-i ) ) / & |
---|
| 568 | REAL( nx+1, KIND=wp ) ) ) * ddx2 + & |
---|
| 569 | 2.0_wp * ( 1.0_wp - COS( ( 2.0_wp * pi * j ) / & |
---|
| 570 | REAL( ny+1, KIND=wp ) ) ) * ddy2 |
---|
[1212] | 571 | ENDIF |
---|
| 572 | ENDDO |
---|
| 573 | |
---|
| 574 | DO k = 0, nz-1 |
---|
| 575 | DO i = 0, nx |
---|
[2037] | 576 | a = -1.0_wp * ddzu_pres(k+2) * ddzw(k+1) * rho_air_zw(k+1) |
---|
| 577 | c = -1.0_wp * ddzu_pres(k+1) * ddzw(k+1) * rho_air_zw(k) |
---|
| 578 | tri_for_1d(1,i,k) = a + c - l(i) * rho_air(k+1) |
---|
[1212] | 579 | ENDDO |
---|
| 580 | ENDDO |
---|
| 581 | IF ( ibc_p_b == 1 ) THEN |
---|
| 582 | DO i = 0, nx |
---|
[1221] | 583 | tri_for_1d(1,i,0) = tri_for_1d(1,i,0) + tri_for_1d(2,i,0) |
---|
[1212] | 584 | ENDDO |
---|
| 585 | ENDIF |
---|
| 586 | IF ( ibc_p_t == 1 ) THEN |
---|
| 587 | DO i = 0, nx |
---|
[1221] | 588 | tri_for_1d(1,i,nz-1) = tri_for_1d(1,i,nz-1) + tri_for_1d(3,i,nz-1) |
---|
[1212] | 589 | ENDDO |
---|
| 590 | ENDIF |
---|
| 591 | |
---|
| 592 | END SUBROUTINE maketri_1dd |
---|
| 593 | |
---|
| 594 | |
---|
[1682] | 595 | !------------------------------------------------------------------------------! |
---|
| 596 | ! Description: |
---|
| 597 | ! ------------ |
---|
| 598 | !> Splitting of the tridiagonal matrix (Thomas algorithm) |
---|
| 599 | !------------------------------------------------------------------------------! |
---|
[1212] | 600 | SUBROUTINE split_1dd |
---|
| 601 | |
---|
| 602 | IMPLICIT NONE |
---|
| 603 | |
---|
[1682] | 604 | INTEGER(iwp) :: i !< |
---|
| 605 | INTEGER(iwp) :: k !< |
---|
[1212] | 606 | |
---|
| 607 | |
---|
| 608 | ! |
---|
| 609 | !-- Splitting |
---|
| 610 | DO i = 0, nx |
---|
[1221] | 611 | tri_for_1d(4,i,0) = tri_for_1d(1,i,0) |
---|
[1212] | 612 | ENDDO |
---|
| 613 | DO k = 1, nz-1 |
---|
| 614 | DO i = 0, nx |
---|
[1221] | 615 | tri_for_1d(5,i,k) = tri_for_1d(2,i,k) / tri_for_1d(4,i,k-1) |
---|
| 616 | tri_for_1d(4,i,k) = tri_for_1d(1,i,k) - tri_for_1d(3,i,k-1) * tri_for_1d(5,i,k) |
---|
[1212] | 617 | ENDDO |
---|
| 618 | ENDDO |
---|
| 619 | |
---|
| 620 | END SUBROUTINE split_1dd |
---|
| 621 | |
---|
| 622 | |
---|
| 623 | !------------------------------------------------------------------------------! |
---|
[1682] | 624 | ! Description: |
---|
| 625 | ! ------------ |
---|
| 626 | !> Substitution (Forward and Backward) (Thomas algorithm) |
---|
[1212] | 627 | !------------------------------------------------------------------------------! |
---|
[1682] | 628 | SUBROUTINE substi_1dd( ar, tri_for_1d ) |
---|
[1212] | 629 | |
---|
[1682] | 630 | |
---|
[1212] | 631 | IMPLICIT NONE |
---|
| 632 | |
---|
[1682] | 633 | INTEGER(iwp) :: i !< |
---|
| 634 | INTEGER(iwp) :: k !< |
---|
[1212] | 635 | |
---|
[1682] | 636 | REAL(wp), DIMENSION(0:nx,nz) :: ar !< |
---|
| 637 | REAL(wp), DIMENSION(0:nx,0:nz-1) :: ar1 !< |
---|
| 638 | REAL(wp), DIMENSION(5,0:nx,0:nz-1) :: tri_for_1d !< |
---|
[1212] | 639 | |
---|
| 640 | ! |
---|
| 641 | !-- Forward substitution |
---|
| 642 | DO i = 0, nx |
---|
| 643 | ar1(i,0) = ar(i,1) |
---|
| 644 | ENDDO |
---|
| 645 | DO k = 1, nz-1 |
---|
| 646 | DO i = 0, nx |
---|
[1221] | 647 | ar1(i,k) = ar(i,k+1) - tri_for_1d(5,i,k) * ar1(i,k-1) |
---|
[1212] | 648 | ENDDO |
---|
| 649 | ENDDO |
---|
| 650 | |
---|
| 651 | ! |
---|
| 652 | !-- Backward substitution |
---|
| 653 | !-- Note, the add of 1.0E-20 in the denominator is due to avoid divisions |
---|
| 654 | !-- by zero appearing if the pressure bc is set to neumann at the top of |
---|
| 655 | !-- the model domain. |
---|
| 656 | DO i = 0, nx |
---|
[1342] | 657 | ar(i,nz) = ar1(i,nz-1) / ( tri_for_1d(4,i,nz-1) + 1.0E-20_wp ) |
---|
[1212] | 658 | ENDDO |
---|
| 659 | DO k = nz-2, 0, -1 |
---|
| 660 | DO i = 0, nx |
---|
[1221] | 661 | ar(i,k+1) = ( ar1(i,k) - tri_for_1d(3,i,k) * ar(i,k+2) ) & |
---|
| 662 | / tri_for_1d(4,i,k) |
---|
[1212] | 663 | ENDDO |
---|
| 664 | ENDDO |
---|
| 665 | |
---|
| 666 | ! |
---|
| 667 | !-- Indices i=0, j=0 correspond to horizontally averaged pressure. |
---|
| 668 | !-- The respective values of ar should be zero at all k-levels if |
---|
| 669 | !-- acceleration of horizontally averaged vertical velocity is zero. |
---|
| 670 | IF ( ibc_p_b == 1 .AND. ibc_p_t == 1 ) THEN |
---|
| 671 | IF ( j == 0 ) THEN |
---|
| 672 | DO k = 1, nz |
---|
[1342] | 673 | ar(0,k) = 0.0_wp |
---|
[1212] | 674 | ENDDO |
---|
| 675 | ENDIF |
---|
| 676 | ENDIF |
---|
| 677 | |
---|
| 678 | END SUBROUTINE substi_1dd |
---|
| 679 | |
---|
| 680 | END SUBROUTINE tridia_1dd |
---|
| 681 | |
---|
| 682 | |
---|
| 683 | END MODULE tridia_solver |
---|