[1] | 1 | SUBROUTINE sor( d, ddzu, ddzw, p ) |
---|
| 2 | |
---|
[1036] | 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 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 | ! |
---|
[1310] | 17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1354] | 22 | ! |
---|
| 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: sor.f90 1354 2014-04-08 15:22:57Z heinze $ |
---|
| 27 | ! |
---|
[1354] | 28 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 29 | ! REAL constants provided with KIND-attribute |
---|
| 30 | ! |
---|
[1321] | 31 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 32 | ! ONLY-attribute added to USE-statements, |
---|
| 33 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 34 | ! kinds are defined in new module kinds, |
---|
| 35 | ! old module precision_kind is removed, |
---|
| 36 | ! revision history before 2012 removed, |
---|
| 37 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 38 | ! all variable declaration statements |
---|
[1] | 39 | ! |
---|
[1037] | 40 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 41 | ! code put under GPL (PALM 3.9) |
---|
| 42 | ! |
---|
[1] | 43 | ! Revision 1.1 1997/08/11 06:25:56 raasch |
---|
| 44 | ! Initial revision |
---|
| 45 | ! |
---|
| 46 | ! |
---|
| 47 | ! Description: |
---|
| 48 | ! ------------ |
---|
| 49 | ! Solve the Poisson-equation with the SOR-Red/Black-scheme. |
---|
[3] | 50 | !------------------------------------------------------------------------------! |
---|
[1] | 51 | |
---|
[1320] | 52 | USE grid_variables, & |
---|
| 53 | ONLY: ddx2, ddy2 |
---|
[1] | 54 | |
---|
[1320] | 55 | USE indices, & |
---|
| 56 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nz, nzb, nzt |
---|
| 57 | |
---|
| 58 | USE kinds |
---|
| 59 | |
---|
| 60 | USE control_parameters, & |
---|
| 61 | ONLY: bc_lr_cyc, bc_ns_cyc, ibc_p_b, ibc_p_t, inflow_l, inflow_n, & |
---|
| 62 | inflow_r, inflow_s, n_sor, omega_sor, outflow_l, outflow_n, & |
---|
| 63 | outflow_r, outflow_s |
---|
| 64 | |
---|
[1] | 65 | IMPLICIT NONE |
---|
| 66 | |
---|
[1320] | 67 | INTEGER(iwp) :: i !: |
---|
| 68 | INTEGER(iwp) :: j !: |
---|
| 69 | INTEGER(iwp) :: k !: |
---|
| 70 | INTEGER(iwp) :: n !: |
---|
| 71 | INTEGER(iwp) :: nxl1 !: |
---|
| 72 | INTEGER(iwp) :: nxl2 !: |
---|
| 73 | INTEGER(iwp) :: nys1 !: |
---|
| 74 | INTEGER(iwp) :: nys2 !: |
---|
[1] | 75 | |
---|
[1320] | 76 | REAL(wp) :: ddzu(1:nz+1) !: |
---|
| 77 | REAL(wp) :: ddzw(1:nzt+1) !: |
---|
| 78 | |
---|
| 79 | REAL(wp) :: d(nzb+1:nzt,nys:nyn,nxl:nxr) !: |
---|
| 80 | REAL(wp) :: p(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !: |
---|
| 81 | |
---|
| 82 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f1 !: |
---|
| 83 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f2 !: |
---|
| 84 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f3 !: |
---|
| 85 | |
---|
[1] | 86 | ALLOCATE( f1(1:nz), f2(1:nz), f3(1:nz) ) |
---|
| 87 | |
---|
| 88 | ! |
---|
| 89 | !-- Compute pre-factors. |
---|
| 90 | DO k = 1, nz |
---|
| 91 | f2(k) = ddzu(k+1) * ddzw(k) |
---|
| 92 | f3(k) = ddzu(k) * ddzw(k) |
---|
[1353] | 93 | f1(k) = 2.0_wp * ( ddx2 + ddy2 ) + f2(k) + f3(k) |
---|
[1] | 94 | ENDDO |
---|
| 95 | |
---|
| 96 | ! |
---|
| 97 | !-- Limits for RED- and BLACK-part. |
---|
| 98 | IF ( MOD( nxl , 2 ) == 0 ) THEN |
---|
| 99 | nxl1 = nxl |
---|
| 100 | nxl2 = nxl + 1 |
---|
| 101 | ELSE |
---|
| 102 | nxl1 = nxl + 1 |
---|
| 103 | nxl2 = nxl |
---|
| 104 | ENDIF |
---|
| 105 | IF ( MOD( nys , 2 ) == 0 ) THEN |
---|
| 106 | nys1 = nys |
---|
| 107 | nys2 = nys + 1 |
---|
| 108 | ELSE |
---|
| 109 | nys1 = nys + 1 |
---|
| 110 | nys2 = nys |
---|
| 111 | ENDIF |
---|
| 112 | |
---|
| 113 | DO n = 1, n_sor |
---|
| 114 | |
---|
| 115 | ! |
---|
| 116 | !-- RED-part |
---|
| 117 | DO i = nxl1, nxr, 2 |
---|
| 118 | DO j = nys2, nyn, 2 |
---|
| 119 | DO k = nzb+1, nzt |
---|
| 120 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 121 | ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 122 | ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 123 | f2(k) * p(k+1,j,i) + & |
---|
| 124 | f3(k) * p(k-1,j,i) - & |
---|
| 125 | d(k,j,i) - & |
---|
| 126 | f1(k) * p(k,j,i) ) |
---|
| 127 | ENDDO |
---|
| 128 | ENDDO |
---|
| 129 | ENDDO |
---|
| 130 | |
---|
| 131 | DO i = nxl2, nxr, 2 |
---|
| 132 | DO j = nys1, nyn, 2 |
---|
| 133 | DO k = nzb+1, nzt |
---|
| 134 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 135 | ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 136 | ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 137 | f2(k) * p(k+1,j,i) + & |
---|
| 138 | f3(k) * p(k-1,j,i) - & |
---|
| 139 | d(k,j,i) - & |
---|
| 140 | f1(k) * p(k,j,i) ) |
---|
| 141 | ENDDO |
---|
| 142 | ENDDO |
---|
| 143 | ENDDO |
---|
| 144 | |
---|
| 145 | ! |
---|
| 146 | !-- Exchange of boundary values for p. |
---|
[667] | 147 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 148 | |
---|
| 149 | ! |
---|
| 150 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 151 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[1] | 152 | IF ( inflow_l .OR. outflow_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 153 | IF ( inflow_r .OR. outflow_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
| 154 | ENDIF |
---|
[707] | 155 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[1] | 156 | IF ( inflow_n .OR. outflow_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 157 | IF ( inflow_s .OR. outflow_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
| 158 | ENDIF |
---|
| 159 | |
---|
| 160 | ! |
---|
| 161 | !-- BLACK-part |
---|
| 162 | DO i = nxl1, nxr, 2 |
---|
| 163 | DO j = nys1, nyn, 2 |
---|
| 164 | DO k = nzb+1, nzt |
---|
| 165 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 166 | ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 167 | ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 168 | f2(k) * p(k+1,j,i) + & |
---|
| 169 | f3(k) * p(k-1,j,i) - & |
---|
| 170 | d(k,j,i) - & |
---|
| 171 | f1(k) * p(k,j,i) ) |
---|
| 172 | ENDDO |
---|
| 173 | ENDDO |
---|
| 174 | ENDDO |
---|
| 175 | |
---|
| 176 | DO i = nxl2, nxr, 2 |
---|
| 177 | DO j = nys2, nyn, 2 |
---|
| 178 | DO k = nzb+1, nzt |
---|
| 179 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 180 | ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 181 | ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 182 | f2(k) * p(k+1,j,i) + & |
---|
| 183 | f3(k) * p(k-1,j,i) - & |
---|
| 184 | d(k,j,i) - & |
---|
| 185 | f1(k) * p(k,j,i) ) |
---|
| 186 | ENDDO |
---|
| 187 | ENDDO |
---|
| 188 | ENDDO |
---|
| 189 | |
---|
| 190 | ! |
---|
| 191 | !-- Exchange of boundary values for p. |
---|
[667] | 192 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 193 | |
---|
| 194 | ! |
---|
| 195 | !-- Boundary conditions top/bottom. |
---|
| 196 | !-- Bottom boundary |
---|
[667] | 197 | IF ( ibc_p_b == 1 ) THEN ! Neumann |
---|
[1] | 198 | p(nzb,:,:) = p(nzb+1,:,:) |
---|
[667] | 199 | ELSE ! Dirichlet |
---|
[1353] | 200 | p(nzb,:,:) = 0.0_wp |
---|
[1] | 201 | ENDIF |
---|
| 202 | |
---|
| 203 | ! |
---|
| 204 | !-- Top boundary |
---|
[667] | 205 | IF ( ibc_p_t == 1 ) THEN ! Neumann |
---|
[1] | 206 | p(nzt+1,:,:) = p(nzt,:,:) |
---|
[667] | 207 | ELSE ! Dirichlet |
---|
[1353] | 208 | p(nzt+1,:,:) = 0.0_wp |
---|
[1] | 209 | ENDIF |
---|
| 210 | |
---|
| 211 | ! |
---|
| 212 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 213 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[1] | 214 | IF ( inflow_l .OR. outflow_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 215 | IF ( inflow_r .OR. outflow_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
| 216 | ENDIF |
---|
[707] | 217 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[1] | 218 | IF ( inflow_n .OR. outflow_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 219 | IF ( inflow_s .OR. outflow_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
| 220 | ENDIF |
---|
| 221 | |
---|
[667] | 222 | |
---|
[1] | 223 | ENDDO |
---|
| 224 | |
---|
| 225 | DEALLOCATE( f1, f2, f3 ) |
---|
| 226 | |
---|
| 227 | END SUBROUTINE sor |
---|