[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 | ! |
---|
[2038] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: sor.f90 2718 2018-01-02 08:49:38Z knoop $ |
---|
[2716] | 27 | ! Corrected "Former revisions" section |
---|
| 28 | ! |
---|
| 29 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 30 | ! - Change in file header (GPL part) |
---|
[2696] | 31 | ! - Large-scale forcing implemented (MS) |
---|
| 32 | ! |
---|
| 33 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1321] | 34 | ! |
---|
[2038] | 35 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
| 36 | ! Anelastic approximation implemented |
---|
| 37 | ! |
---|
[2001] | 38 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 39 | ! Forced header and separation lines into 80 columns |
---|
| 40 | ! |
---|
[1763] | 41 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 42 | ! Introduction of nested domain feature |
---|
| 43 | ! |
---|
[1683] | 44 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 45 | ! Code annotations made doxygen readable |
---|
| 46 | ! |
---|
[1354] | 47 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 48 | ! REAL constants provided with KIND-attribute |
---|
| 49 | ! |
---|
[1321] | 50 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 51 | ! ONLY-attribute added to USE-statements, |
---|
| 52 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 53 | ! kinds are defined in new module kinds, |
---|
| 54 | ! old module precision_kind is removed, |
---|
| 55 | ! revision history before 2012 removed, |
---|
| 56 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 57 | ! all variable declaration statements |
---|
[1] | 58 | ! |
---|
[1037] | 59 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 60 | ! code put under GPL (PALM 3.9) |
---|
| 61 | ! |
---|
[1] | 62 | ! Revision 1.1 1997/08/11 06:25:56 raasch |
---|
| 63 | ! Initial revision |
---|
| 64 | ! |
---|
| 65 | ! |
---|
| 66 | ! Description: |
---|
| 67 | ! ------------ |
---|
[1682] | 68 | !> Solve the Poisson-equation with the SOR-Red/Black-scheme. |
---|
[3] | 69 | !------------------------------------------------------------------------------! |
---|
[1682] | 70 | SUBROUTINE sor( d, ddzu, ddzw, p ) |
---|
[1] | 71 | |
---|
[2037] | 72 | USE arrays_3d, & |
---|
| 73 | ONLY: rho_air, rho_air_zw |
---|
| 74 | |
---|
[1320] | 75 | USE grid_variables, & |
---|
| 76 | ONLY: ddx2, ddy2 |
---|
[1] | 77 | |
---|
[1320] | 78 | USE indices, & |
---|
| 79 | ONLY: nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nz, nzb, nzt |
---|
| 80 | |
---|
| 81 | USE kinds |
---|
| 82 | |
---|
| 83 | USE control_parameters, & |
---|
[2696] | 84 | ONLY: bc_lr_cyc, bc_ns_cyc, force_bound_l, force_bound_n, & |
---|
| 85 | force_bound_r, force_bound_s, ibc_p_b, ibc_p_t, inflow_l, & |
---|
| 86 | inflow_n, inflow_r, inflow_s, nest_bound_l, nest_bound_n, & |
---|
| 87 | nest_bound_r, nest_bound_s, n_sor, omega_sor, outflow_l, & |
---|
| 88 | outflow_n, outflow_r, outflow_s |
---|
[1320] | 89 | |
---|
[1] | 90 | IMPLICIT NONE |
---|
| 91 | |
---|
[1682] | 92 | INTEGER(iwp) :: i !< |
---|
| 93 | INTEGER(iwp) :: j !< |
---|
| 94 | INTEGER(iwp) :: k !< |
---|
| 95 | INTEGER(iwp) :: n !< |
---|
| 96 | INTEGER(iwp) :: nxl1 !< |
---|
| 97 | INTEGER(iwp) :: nxl2 !< |
---|
| 98 | INTEGER(iwp) :: nys1 !< |
---|
| 99 | INTEGER(iwp) :: nys2 !< |
---|
[1] | 100 | |
---|
[1682] | 101 | REAL(wp) :: ddzu(1:nz+1) !< |
---|
| 102 | REAL(wp) :: ddzw(1:nzt+1) !< |
---|
[1320] | 103 | |
---|
[1682] | 104 | REAL(wp) :: d(nzb+1:nzt,nys:nyn,nxl:nxr) !< |
---|
| 105 | REAL(wp) :: p(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
[1320] | 106 | |
---|
[1682] | 107 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f1 !< |
---|
| 108 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f2 !< |
---|
| 109 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f3 !< |
---|
[1320] | 110 | |
---|
[1] | 111 | ALLOCATE( f1(1:nz), f2(1:nz), f3(1:nz) ) |
---|
| 112 | |
---|
| 113 | ! |
---|
| 114 | !-- Compute pre-factors. |
---|
| 115 | DO k = 1, nz |
---|
[2037] | 116 | f2(k) = ddzu(k+1) * ddzw(k) * rho_air_zw(k) |
---|
| 117 | f3(k) = ddzu(k) * ddzw(k) * rho_air_zw(k-1) |
---|
| 118 | f1(k) = 2.0_wp * ( ddx2 + ddy2 ) * rho_air(k) + f2(k) + f3(k) |
---|
[1] | 119 | ENDDO |
---|
| 120 | |
---|
| 121 | ! |
---|
| 122 | !-- Limits for RED- and BLACK-part. |
---|
| 123 | IF ( MOD( nxl , 2 ) == 0 ) THEN |
---|
| 124 | nxl1 = nxl |
---|
| 125 | nxl2 = nxl + 1 |
---|
| 126 | ELSE |
---|
| 127 | nxl1 = nxl + 1 |
---|
| 128 | nxl2 = nxl |
---|
| 129 | ENDIF |
---|
| 130 | IF ( MOD( nys , 2 ) == 0 ) THEN |
---|
| 131 | nys1 = nys |
---|
| 132 | nys2 = nys + 1 |
---|
| 133 | ELSE |
---|
| 134 | nys1 = nys + 1 |
---|
| 135 | nys2 = nys |
---|
| 136 | ENDIF |
---|
| 137 | |
---|
| 138 | DO n = 1, n_sor |
---|
| 139 | |
---|
| 140 | ! |
---|
| 141 | !-- RED-part |
---|
| 142 | DO i = nxl1, nxr, 2 |
---|
| 143 | DO j = nys2, nyn, 2 |
---|
| 144 | DO k = nzb+1, nzt |
---|
| 145 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 146 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 147 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 148 | f2(k) * p(k+1,j,i) + & |
---|
| 149 | f3(k) * p(k-1,j,i) - & |
---|
| 150 | d(k,j,i) - & |
---|
| 151 | f1(k) * p(k,j,i) ) |
---|
[1] | 152 | ENDDO |
---|
| 153 | ENDDO |
---|
| 154 | ENDDO |
---|
| 155 | |
---|
| 156 | DO i = nxl2, nxr, 2 |
---|
| 157 | DO j = nys1, nyn, 2 |
---|
| 158 | DO k = nzb+1, nzt |
---|
[2037] | 159 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
| 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 | ! |
---|
| 171 | !-- Exchange of boundary values for p. |
---|
[667] | 172 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 173 | |
---|
| 174 | ! |
---|
| 175 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 176 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2696] | 177 | IF ( inflow_l .OR. outflow_l .OR. & |
---|
| 178 | nest_bound_l .OR. force_bound_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 179 | IF ( inflow_r .OR. outflow_r .OR. & |
---|
| 180 | nest_bound_r .OR. force_bound_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 181 | ENDIF |
---|
[707] | 182 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2696] | 183 | IF ( inflow_n .OR. outflow_n .OR. & |
---|
| 184 | nest_bound_n .OR. force_bound_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 185 | IF ( inflow_s .OR. outflow_s .OR. & |
---|
| 186 | nest_bound_s .OR. force_bound_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 187 | ENDIF |
---|
| 188 | |
---|
| 189 | ! |
---|
| 190 | !-- BLACK-part |
---|
| 191 | DO i = nxl1, nxr, 2 |
---|
| 192 | DO j = nys1, nyn, 2 |
---|
| 193 | DO k = nzb+1, nzt |
---|
| 194 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 195 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 196 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 197 | f2(k) * p(k+1,j,i) + & |
---|
| 198 | f3(k) * p(k-1,j,i) - & |
---|
| 199 | d(k,j,i) - & |
---|
| 200 | f1(k) * p(k,j,i) ) |
---|
[1] | 201 | ENDDO |
---|
| 202 | ENDDO |
---|
| 203 | ENDDO |
---|
| 204 | |
---|
| 205 | DO i = nxl2, nxr, 2 |
---|
| 206 | DO j = nys2, nyn, 2 |
---|
| 207 | DO k = nzb+1, nzt |
---|
| 208 | p(k,j,i) = p(k,j,i) + omega_sor / f1(k) * ( & |
---|
[2037] | 209 | rho_air(k) * ddx2 * ( p(k,j,i+1) + p(k,j,i-1) ) + & |
---|
| 210 | rho_air(k) * ddy2 * ( p(k,j+1,i) + p(k,j-1,i) ) + & |
---|
| 211 | f2(k) * p(k+1,j,i) + & |
---|
| 212 | f3(k) * p(k-1,j,i) - & |
---|
| 213 | d(k,j,i) - & |
---|
| 214 | f1(k) * p(k,j,i) ) |
---|
[1] | 215 | ENDDO |
---|
| 216 | ENDDO |
---|
| 217 | ENDDO |
---|
| 218 | |
---|
| 219 | ! |
---|
| 220 | !-- Exchange of boundary values for p. |
---|
[667] | 221 | CALL exchange_horiz( p, nbgp ) |
---|
[1] | 222 | |
---|
| 223 | ! |
---|
| 224 | !-- Boundary conditions top/bottom. |
---|
| 225 | !-- Bottom boundary |
---|
[667] | 226 | IF ( ibc_p_b == 1 ) THEN ! Neumann |
---|
[1] | 227 | p(nzb,:,:) = p(nzb+1,:,:) |
---|
[667] | 228 | ELSE ! Dirichlet |
---|
[1353] | 229 | p(nzb,:,:) = 0.0_wp |
---|
[1] | 230 | ENDIF |
---|
| 231 | |
---|
| 232 | ! |
---|
| 233 | !-- Top boundary |
---|
[667] | 234 | IF ( ibc_p_t == 1 ) THEN ! Neumann |
---|
[1] | 235 | p(nzt+1,:,:) = p(nzt,:,:) |
---|
[667] | 236 | ELSE ! Dirichlet |
---|
[1353] | 237 | p(nzt+1,:,:) = 0.0_wp |
---|
[1] | 238 | ENDIF |
---|
| 239 | |
---|
| 240 | ! |
---|
| 241 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
[707] | 242 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2696] | 243 | IF ( inflow_l .OR. outflow_l .OR. & |
---|
| 244 | nest_bound_l .OR. force_bound_l ) p(:,:,nxl-1) = p(:,:,nxl) |
---|
| 245 | IF ( inflow_r .OR. outflow_r .OR. & |
---|
| 246 | nest_bound_r .OR. force_bound_r ) p(:,:,nxr+1) = p(:,:,nxr) |
---|
[1] | 247 | ENDIF |
---|
[707] | 248 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2696] | 249 | IF ( inflow_n .OR. outflow_n .OR. & |
---|
| 250 | nest_bound_n .OR. force_bound_n ) p(:,nyn+1,:) = p(:,nyn,:) |
---|
| 251 | IF ( inflow_s .OR. outflow_s .OR. & |
---|
| 252 | nest_bound_s .OR. force_bound_s ) p(:,nys-1,:) = p(:,nys,:) |
---|
[1] | 253 | ENDIF |
---|
| 254 | |
---|
[667] | 255 | |
---|
[1] | 256 | ENDDO |
---|
| 257 | |
---|
| 258 | DEALLOCATE( f1, f2, f3 ) |
---|
| 259 | |
---|
| 260 | END SUBROUTINE sor |
---|