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