[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 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 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 4360 2020-01-07 11:25:50Z oliver.maas $ |
---|
[4182] | 27 | ! Corrected "Former revisions" section |
---|
| 28 | ! |
---|
| 29 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3183] | 30 | ! Rename variables in mesoscale-offline nesting mode |
---|
[1321] | 31 | ! |
---|
[4182] | 32 | ! Revision 1.1 1997/08/11 06:25:56 raasch |
---|
| 33 | ! Initial revision |
---|
| 34 | ! |
---|
| 35 | ! |
---|
[1] | 36 | ! Description: |
---|
| 37 | ! ------------ |
---|
[1682] | 38 | !> Solve the Poisson-equation with the SOR-Red/Black-scheme. |
---|
[3] | 39 | !------------------------------------------------------------------------------! |
---|
[1682] | 40 | SUBROUTINE sor( d, ddzu, ddzw, p ) |
---|
[1] | 41 | |
---|
[2037] | 42 | USE arrays_3d, & |
---|
| 43 | ONLY: rho_air, rho_air_zw |
---|
| 44 | |
---|
[1320] | 45 | USE grid_variables, & |
---|
| 46 | ONLY: ddx2, ddy2 |
---|
[1] | 47 | |
---|
[1320] | 48 | USE indices, & |
---|
| 49 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nz, nzb, nzt |
---|
| 50 | |
---|
| 51 | USE kinds |
---|
| 52 | |
---|
| 53 | USE control_parameters, & |
---|
[3182] | 54 | ONLY: bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, & |
---|
| 55 | bc_dirichlet_s, bc_lr_cyc, bc_ns_cyc, bc_radiation_l, & |
---|
| 56 | bc_radiation_n, bc_radiation_r, bc_radiation_s, ibc_p_b, & |
---|
| 57 | ibc_p_t, n_sor, omega_sor |
---|
[1320] | 58 | |
---|
[1] | 59 | IMPLICIT NONE |
---|
| 60 | |
---|
[1682] | 61 | INTEGER(iwp) :: i !< |
---|
| 62 | INTEGER(iwp) :: j !< |
---|
| 63 | INTEGER(iwp) :: k !< |
---|
| 64 | INTEGER(iwp) :: n !< |
---|
| 65 | INTEGER(iwp) :: nxl1 !< |
---|
| 66 | INTEGER(iwp) :: nxl2 !< |
---|
| 67 | INTEGER(iwp) :: nys1 !< |
---|
| 68 | INTEGER(iwp) :: nys2 !< |
---|
[1] | 69 | |
---|
[1682] | 70 | REAL(wp) :: ddzu(1:nz+1) !< |
---|
| 71 | REAL(wp) :: ddzw(1:nzt+1) !< |
---|
[1320] | 72 | |
---|
[1682] | 73 | REAL(wp) :: d(nzb+1:nzt,nys:nyn,nxl:nxr) !< |
---|
| 74 | REAL(wp) :: p(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
[1320] | 75 | |
---|
[1682] | 76 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f1 !< |
---|
| 77 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f2 !< |
---|
| 78 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f3 !< |
---|
[1320] | 79 | |
---|
[1] | 80 | ALLOCATE( f1(1:nz), f2(1:nz), f3(1:nz) ) |
---|
| 81 | |
---|
| 82 | ! |
---|
| 83 | !-- Compute pre-factors. |
---|
| 84 | DO k = 1, nz |
---|
[2037] | 85 | f2(k) = ddzu(k+1) * ddzw(k) * rho_air_zw(k) |
---|
| 86 | f3(k) = ddzu(k) * ddzw(k) * rho_air_zw(k-1) |
---|
| 87 | f1(k) = 2.0_wp * ( ddx2 + ddy2 ) * rho_air(k) + f2(k) + f3(k) |
---|
[1] | 88 | ENDDO |
---|
| 89 | |
---|
| 90 | ! |
---|
| 91 | !-- Limits for RED- and BLACK-part. |
---|
| 92 | IF ( MOD( nxl , 2 ) == 0 ) THEN |
---|
| 93 | nxl1 = nxl |
---|
| 94 | nxl2 = nxl + 1 |
---|
| 95 | ELSE |
---|
| 96 | nxl1 = nxl + 1 |
---|
| 97 | nxl2 = nxl |
---|
| 98 | ENDIF |
---|
| 99 | IF ( MOD( nys , 2 ) == 0 ) THEN |
---|
| 100 | nys1 = nys |
---|
| 101 | nys2 = nys + 1 |
---|
| 102 | ELSE |
---|
| 103 | nys1 = nys + 1 |
---|
| 104 | nys2 = nys |
---|
| 105 | ENDIF |
---|
| 106 | |
---|
| 107 | DO n = 1, n_sor |
---|
| 108 | |
---|
| 109 | ! |
---|
| 110 | !-- RED-part |
---|
| 111 | DO i = nxl1, nxr, 2 |
---|
| 112 | DO j = nys2, nyn, 2 |
---|
| 113 | DO k = nzb+1, nzt |
---|
| 114 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 115 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 116 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 117 | f2(k) * p(k+1,j,i) + & |
---|
| 118 | f3(k) * p(k-1,j,i) - & |
---|
| 119 | d(k,j,i) - & |
---|
| 120 | f1(k) * p(k,j,i) ) |
---|
[1] | 121 | ENDDO |
---|
| 122 | ENDDO |
---|
| 123 | ENDDO |
---|
| 124 | |
---|
| 125 | DO i = nxl2, nxr, 2 |
---|
| 126 | DO j = nys1, nyn, 2 |
---|
| 127 | DO k = nzb+1, nzt |
---|
[2037] | 128 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 129 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 130 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 131 | f2(k) * p(k+1,j,i) + & |
---|
| 132 | f3(k) * p(k-1,j,i) - & |
---|
| 133 | d(k,j,i) - & |
---|
| 134 | f1(k) * p(k,j,i) ) |
---|
[1] | 135 | ENDDO |
---|
| 136 | ENDDO |
---|
| 137 | ENDDO |
---|
| 138 | |
---|
| 139 | ! |
---|
| 140 | !-- Exchange of boundary values for p. |
---|
[667] | 141 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 142 | |
---|
| 143 | ! |
---|
| 144 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 145 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[3182] | 146 | IF ( bc_dirichlet_l .OR. bc_radiation_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 147 | IF ( bc_dirichlet_r .OR. bc_radiation_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 148 | ENDIF |
---|
[707] | 149 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[3182] | 150 | IF ( bc_dirichlet_n .OR. bc_radiation_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 151 | IF ( bc_dirichlet_s .OR. bc_radiation_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 152 | ENDIF |
---|
| 153 | |
---|
| 154 | ! |
---|
| 155 | !-- BLACK-part |
---|
| 156 | DO i = nxl1, nxr, 2 |
---|
| 157 | DO j = nys1, nyn, 2 |
---|
| 158 | DO k = nzb+1, nzt |
---|
| 159 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 160 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 161 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 162 | f2(k) * p(k+1,j,i) + & |
---|
| 163 | f3(k) * p(k-1,j,i) - & |
---|
| 164 | d(k,j,i) - & |
---|
| 165 | f1(k) * p(k,j,i) ) |
---|
[1] | 166 | ENDDO |
---|
| 167 | ENDDO |
---|
| 168 | ENDDO |
---|
| 169 | |
---|
| 170 | DO i = nxl2, nxr, 2 |
---|
| 171 | DO j = nys2, nyn, 2 |
---|
| 172 | DO k = nzb+1, nzt |
---|
| 173 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 174 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 175 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 176 | f2(k) * p(k+1,j,i) + & |
---|
| 177 | f3(k) * p(k-1,j,i) - & |
---|
| 178 | d(k,j,i) - & |
---|
| 179 | f1(k) * p(k,j,i) ) |
---|
[1] | 180 | ENDDO |
---|
| 181 | ENDDO |
---|
| 182 | ENDDO |
---|
| 183 | |
---|
| 184 | ! |
---|
| 185 | !-- Exchange of boundary values for p. |
---|
[667] | 186 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 187 | |
---|
| 188 | ! |
---|
| 189 | !-- Boundary conditions top/bottom. |
---|
| 190 | !-- Bottom boundary |
---|
[667] | 191 | IF ( ibc_p_b == 1 ) THEN ! Neumann |
---|
[1] | 192 | p(nzb,:,:) = p(nzb+1,:,:) |
---|
[667] | 193 | ELSE ! Dirichlet |
---|
[1353] | 194 | p(nzb,:,:) = 0.0_wp |
---|
[1] | 195 | ENDIF |
---|
| 196 | |
---|
| 197 | ! |
---|
| 198 | !-- Top boundary |
---|
[667] | 199 | IF ( ibc_p_t == 1 ) THEN ! Neumann |
---|
[1] | 200 | p(nzt+1,:,:) = p(nzt,:,:) |
---|
[667] | 201 | ELSE ! Dirichlet |
---|
[1353] | 202 | p(nzt+1,:,:) = 0.0_wp |
---|
[1] | 203 | ENDIF |
---|
| 204 | |
---|
| 205 | ! |
---|
| 206 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 207 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[3182] | 208 | IF ( bc_dirichlet_l .OR. bc_radiation_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 209 | IF ( bc_dirichlet_r .OR. bc_radiation_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 210 | ENDIF |
---|
[707] | 211 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[3182] | 212 | IF ( bc_dirichlet_n .OR. bc_radiation_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 213 | IF ( bc_dirichlet_s .OR. bc_radiation_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 214 | ENDIF |
---|
| 215 | |
---|
[667] | 216 | |
---|
[1] | 217 | ENDDO |
---|
| 218 | |
---|
| 219 | DEALLOCATE( f1, f2, f3 ) |
---|
| 220 | |
---|
[3467] | 221 | END SUBROUTINE sor |
---|