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