1 | !> @file sor.f90 |
---|
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 | ! |
---|
16 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: sor.f90 1683 2015-10-07 23:57:51Z hoffmann $ |
---|
26 | ! |
---|
27 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
28 | ! Code annotations made doxygen readable |
---|
29 | ! |
---|
30 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
31 | ! REAL constants provided with KIND-attribute |
---|
32 | ! |
---|
33 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
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 |
---|
41 | ! |
---|
42 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
43 | ! code put under GPL (PALM 3.9) |
---|
44 | ! |
---|
45 | ! Revision 1.1 1997/08/11 06:25:56 raasch |
---|
46 | ! Initial revision |
---|
47 | ! |
---|
48 | ! |
---|
49 | ! Description: |
---|
50 | ! ------------ |
---|
51 | !> Solve the Poisson-equation with the SOR-Red/Black-scheme. |
---|
52 | !------------------------------------------------------------------------------! |
---|
53 | SUBROUTINE sor( d, ddzu, ddzw, p ) |
---|
54 | |
---|
55 | |
---|
56 | USE grid_variables, & |
---|
57 | ONLY: ddx2, ddy2 |
---|
58 | |
---|
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 | |
---|
69 | IMPLICIT NONE |
---|
70 | |
---|
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 !< |
---|
79 | |
---|
80 | REAL(wp) :: ddzu(1:nz+1) !< |
---|
81 | REAL(wp) :: ddzw(1:nzt+1) !< |
---|
82 | |
---|
83 | REAL(wp) :: d(nzb+1:nzt,nys:nyn,nxl:nxr) !< |
---|
84 | REAL(wp) :: p(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
85 | |
---|
86 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f1 !< |
---|
87 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f2 !< |
---|
88 | REAL(wp), DIMENSION(:), ALLOCATABLE :: f3 !< |
---|
89 | |
---|
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) |
---|
97 | f1(k) = 2.0_wp * ( ddx2 + ddy2 ) + f2(k) + f3(k) |
---|
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. |
---|
151 | CALL exchange_horiz( p, nbgp ) |
---|
152 | |
---|
153 | ! |
---|
154 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
155 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
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 |
---|
159 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
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. |
---|
196 | CALL exchange_horiz( p, nbgp ) |
---|
197 | |
---|
198 | ! |
---|
199 | !-- Boundary conditions top/bottom. |
---|
200 | !-- Bottom boundary |
---|
201 | IF ( ibc_p_b == 1 ) THEN ! Neumann |
---|
202 | p(nzb,:,:) = p(nzb+1,:,:) |
---|
203 | ELSE ! Dirichlet |
---|
204 | p(nzb,:,:) = 0.0_wp |
---|
205 | ENDIF |
---|
206 | |
---|
207 | ! |
---|
208 | !-- Top boundary |
---|
209 | IF ( ibc_p_t == 1 ) THEN ! Neumann |
---|
210 | p(nzt+1,:,:) = p(nzt,:,:) |
---|
211 | ELSE ! Dirichlet |
---|
212 | p(nzt+1,:,:) = 0.0_wp |
---|
213 | ENDIF |
---|
214 | |
---|
215 | ! |
---|
216 | !-- Horizontal (Neumann) boundary conditions in case of non-cyclic boundaries |
---|
217 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
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 |
---|
221 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
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 | |
---|
226 | |
---|
227 | ENDDO |
---|
228 | |
---|
229 | DEALLOCATE( f1, f2, f3 ) |
---|
230 | |
---|
231 | END SUBROUTINE sor |
---|