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