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