[1682] | 1 | !> @file sor.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[2718] | 17 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1354] | 22 | ! |
---|
[3183] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: sor.f90 3183 2018-07-27 14:25:55Z knoop $ |
---|
[3183] | 27 | ! Rename variables in mesoscale-offline nesting mode |
---|
| 28 | ! |
---|
| 29 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
[2716] | 30 | ! Corrected "Former revisions" section |
---|
| 31 | ! |
---|
[3182] | 32 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
| 33 | ! Corrected "Former revisions" section |
---|
| 34 | ! |
---|
[2716] | 35 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 36 | ! - Change in file header (GPL part) |
---|
[2696] | 37 | ! - Large-scale forcing implemented (MS) |
---|
| 38 | ! |
---|
| 39 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1321] | 40 | ! |
---|
[2038] | 41 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
| 42 | ! Anelastic approximation implemented |
---|
| 43 | ! |
---|
[2001] | 44 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 45 | ! Forced header and separation lines into 80 columns |
---|
| 46 | ! |
---|
[1763] | 47 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 48 | ! Introduction of nested domain feature |
---|
| 49 | ! |
---|
[1683] | 50 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 51 | ! Code annotations made doxygen readable |
---|
| 52 | ! |
---|
[1354] | 53 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 54 | ! REAL constants provided with KIND-attribute |
---|
| 55 | ! |
---|
[1321] | 56 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 57 | ! ONLY-attribute added to USE-statements, |
---|
| 58 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 59 | ! kinds are defined in new module kinds, |
---|
| 60 | ! old module precision_kind is removed, |
---|
| 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 1997/08/11 06:25:56 raasch |
---|
| 69 | ! Initial revision |
---|
| 70 | ! |
---|
| 71 | ! |
---|
| 72 | ! Description: |
---|
| 73 | ! ------------ |
---|
[1682] | 74 | !> Solve the Poisson-equation with the SOR-Red/Black-scheme. |
---|
[3] | 75 | !------------------------------------------------------------------------------! |
---|
[1682] | 76 | SUBROUTINE sor( d, ddzu, ddzw, p ) |
---|
[1] | 77 | |
---|
[2037] | 78 | USE arrays_3d, & |
---|
| 79 | ONLY: rho_air, rho_air_zw |
---|
| 80 | |
---|
[1320] | 81 | USE grid_variables, & |
---|
| 82 | ONLY: ddx2, ddy2 |
---|
[1] | 83 | |
---|
[1320] | 84 | USE indices, & |
---|
| 85 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nz, nzb, nzt |
---|
| 86 | |
---|
| 87 | USE kinds |
---|
| 88 | |
---|
| 89 | USE control_parameters, & |
---|
[3182] | 90 | ONLY: bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, & |
---|
| 91 | bc_dirichlet_s, bc_lr_cyc, bc_ns_cyc, bc_radiation_l, & |
---|
| 92 | bc_radiation_n, bc_radiation_r, bc_radiation_s, ibc_p_b, & |
---|
| 93 | ibc_p_t, n_sor, omega_sor |
---|
[1320] | 94 | |
---|
[1] | 95 | IMPLICIT NONE |
---|
| 96 | |
---|
[1682] | 97 | INTEGER(iwp) :: i !< |
---|
| 98 | INTEGER(iwp) :: j !< |
---|
| 99 | INTEGER(iwp) :: k !< |
---|
| 100 | INTEGER(iwp) :: n !< |
---|
| 101 | INTEGER(iwp) :: nxl1 !< |
---|
| 102 | INTEGER(iwp) :: nxl2 !< |
---|
| 103 | INTEGER(iwp) :: nys1 !< |
---|
| 104 | INTEGER(iwp) :: nys2 !< |
---|
[1] | 105 | |
---|
[1682] | 106 | REAL(wp) :: ddzu(1:nz+1) !< |
---|
| 107 | REAL(wp) :: ddzw(1:nzt+1) !< |
---|
[1320] | 108 | |
---|
[1682] | 109 | REAL(wp) :: d(nzb+1:nzt,nys:nyn,nxl:nxr) !< |
---|
| 110 | REAL(wp) :: p(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
[1320] | 111 | |
---|
[1682] | 112 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f1 !< |
---|
| 113 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f2 !< |
---|
| 114 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f3 !< |
---|
[1320] | 115 | |
---|
[1] | 116 | ALLOCATE( f1(1:nz), f2(1:nz), f3(1:nz) ) |
---|
| 117 | |
---|
| 118 | ! |
---|
| 119 | !-- Compute pre-factors. |
---|
| 120 | DO k = 1, nz |
---|
[2037] | 121 | f2(k) = ddzu(k+1) * ddzw(k) * rho_air_zw(k) |
---|
| 122 | f3(k) = ddzu(k) * ddzw(k) * rho_air_zw(k-1) |
---|
| 123 | f1(k) = 2.0_wp * ( ddx2 + ddy2 ) * rho_air(k) + f2(k) + f3(k) |
---|
[1] | 124 | ENDDO |
---|
| 125 | |
---|
| 126 | ! |
---|
| 127 | !-- Limits for RED- and BLACK-part. |
---|
| 128 | IF ( MOD( nxl , 2 ) == 0 ) THEN |
---|
| 129 | nxl1 = nxl |
---|
| 130 | nxl2 = nxl + 1 |
---|
| 131 | ELSE |
---|
| 132 | nxl1 = nxl + 1 |
---|
| 133 | nxl2 = nxl |
---|
| 134 | ENDIF |
---|
| 135 | IF ( MOD( nys , 2 ) == 0 ) THEN |
---|
| 136 | nys1 = nys |
---|
| 137 | nys2 = nys + 1 |
---|
| 138 | ELSE |
---|
| 139 | nys1 = nys + 1 |
---|
| 140 | nys2 = nys |
---|
| 141 | ENDIF |
---|
| 142 | |
---|
| 143 | DO n = 1, n_sor |
---|
| 144 | |
---|
| 145 | ! |
---|
| 146 | !-- RED-part |
---|
| 147 | DO i = nxl1, nxr, 2 |
---|
| 148 | DO j = nys2, nyn, 2 |
---|
| 149 | DO k = nzb+1, nzt |
---|
| 150 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 151 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 152 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 153 | f2(k) * p(k+1,j,i) + & |
---|
| 154 | f3(k) * p(k-1,j,i) - & |
---|
| 155 | d(k,j,i) - & |
---|
| 156 | f1(k) * p(k,j,i) ) |
---|
[1] | 157 | ENDDO |
---|
| 158 | ENDDO |
---|
| 159 | ENDDO |
---|
| 160 | |
---|
| 161 | DO i = nxl2, nxr, 2 |
---|
| 162 | DO j = nys1, nyn, 2 |
---|
| 163 | DO k = nzb+1, nzt |
---|
[2037] | 164 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 165 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 166 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 167 | f2(k) * p(k+1,j,i) + & |
---|
| 168 | f3(k) * p(k-1,j,i) - & |
---|
| 169 | d(k,j,i) - & |
---|
| 170 | f1(k) * p(k,j,i) ) |
---|
[1] | 171 | ENDDO |
---|
| 172 | ENDDO |
---|
| 173 | ENDDO |
---|
| 174 | |
---|
| 175 | ! |
---|
| 176 | !-- Exchange of boundary values for p. |
---|
[667] | 177 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 178 | |
---|
| 179 | ! |
---|
| 180 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 181 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[3182] | 182 | IF ( bc_dirichlet_l .OR. bc_radiation_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 183 | IF ( bc_dirichlet_r .OR. bc_radiation_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 184 | ENDIF |
---|
[707] | 185 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[3182] | 186 | IF ( bc_dirichlet_n .OR. bc_radiation_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 187 | IF ( bc_dirichlet_s .OR. bc_radiation_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 188 | ENDIF |
---|
| 189 | |
---|
| 190 | ! |
---|
| 191 | !-- BLACK-part |
---|
| 192 | DO i = nxl1, nxr, 2 |
---|
| 193 | DO j = nys1, nyn, 2 |
---|
| 194 | DO k = nzb+1, nzt |
---|
| 195 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 196 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 197 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 198 | f2(k) * p(k+1,j,i) + & |
---|
| 199 | f3(k) * p(k-1,j,i) - & |
---|
| 200 | d(k,j,i) - & |
---|
| 201 | f1(k) * p(k,j,i) ) |
---|
[1] | 202 | ENDDO |
---|
| 203 | ENDDO |
---|
| 204 | ENDDO |
---|
| 205 | |
---|
| 206 | DO i = nxl2, nxr, 2 |
---|
| 207 | DO j = nys2, nyn, 2 |
---|
| 208 | DO k = nzb+1, nzt |
---|
| 209 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 210 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 211 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 212 | f2(k) * p(k+1,j,i) + & |
---|
| 213 | f3(k) * p(k-1,j,i) - & |
---|
| 214 | d(k,j,i) - & |
---|
| 215 | f1(k) * p(k,j,i) ) |
---|
[1] | 216 | ENDDO |
---|
| 217 | ENDDO |
---|
| 218 | ENDDO |
---|
| 219 | |
---|
| 220 | ! |
---|
| 221 | !-- Exchange of boundary values for p. |
---|
[667] | 222 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 223 | |
---|
| 224 | ! |
---|
| 225 | !-- Boundary conditions top/bottom. |
---|
| 226 | !-- Bottom boundary |
---|
[667] | 227 | IF ( ibc_p_b == 1 ) THEN ! Neumann |
---|
[1] | 228 | p(nzb,:,:) = p(nzb+1,:,:) |
---|
[667] | 229 | ELSE ! Dirichlet |
---|
[1353] | 230 | p(nzb,:,:) = 0.0_wp |
---|
[1] | 231 | ENDIF |
---|
| 232 | |
---|
| 233 | ! |
---|
| 234 | !-- Top boundary |
---|
[667] | 235 | IF ( ibc_p_t == 1 ) THEN ! Neumann |
---|
[1] | 236 | p(nzt+1,:,:) = p(nzt,:,:) |
---|
[667] | 237 | ELSE ! Dirichlet |
---|
[1353] | 238 | p(nzt+1,:,:) = 0.0_wp |
---|
[1] | 239 | ENDIF |
---|
| 240 | |
---|
| 241 | ! |
---|
| 242 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 243 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[3182] | 244 | IF ( bc_dirichlet_l .OR. bc_radiation_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 245 | IF ( bc_dirichlet_r .OR. bc_radiation_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 246 | ENDIF |
---|
[707] | 247 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[3182] | 248 | IF ( bc_dirichlet_n .OR. bc_radiation_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 249 | IF ( bc_dirichlet_s .OR. bc_radiation_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 250 | ENDIF |
---|
| 251 | |
---|
[667] | 252 | |
---|
[1] | 253 | ENDDO |
---|
| 254 | |
---|
| 255 | DEALLOCATE( f1, f2, f3 ) |
---|
| 256 | |
---|
| 257 | END SUBROUTINE sor |
---|