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