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