1 | !> @file diffusion_s.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-2017 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ------------------ |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: diffusion_s.f90 2119 2017-01-17 16:51:50Z maronga $ |
---|
27 | ! |
---|
28 | ! 2118 2017-01-17 16:38:49Z raasch |
---|
29 | ! OpenACC version of subroutine removed |
---|
30 | ! |
---|
31 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
32 | ! Anelastic approximation implemented |
---|
33 | ! |
---|
34 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
35 | ! Forced header and separation lines into 80 columns |
---|
36 | ! |
---|
37 | ! 1873 2016-04-18 14:50:06Z maronga |
---|
38 | ! Module renamed (removed _mod) |
---|
39 | ! |
---|
40 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
41 | ! Module renamed |
---|
42 | ! |
---|
43 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
44 | ! Formatting corrections. |
---|
45 | ! |
---|
46 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
47 | ! Code annotations made doxygen readable |
---|
48 | ! |
---|
49 | ! 1374 2014-04-25 12:55:07Z raasch |
---|
50 | ! missing variables added to ONLY list |
---|
51 | ! |
---|
52 | ! 1340 2014-03-25 19:45:13Z kanani |
---|
53 | ! REAL constants defined as wp-kind |
---|
54 | ! |
---|
55 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
56 | ! ONLY-attribute added to USE-statements, |
---|
57 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
58 | ! kinds are defined in new module kinds, |
---|
59 | ! revision history before 2012 removed, |
---|
60 | ! comment fields (!:) to be used for variable explanations added to |
---|
61 | ! all variable declaration statements |
---|
62 | ! |
---|
63 | ! 1257 2013-11-08 15:18:40Z raasch |
---|
64 | ! openacc loop and loop vector clauses removed |
---|
65 | ! |
---|
66 | ! 1128 2013-04-12 06:19:32Z raasch |
---|
67 | ! loop index bounds in accelerator version replaced by i_left, i_right, j_south, |
---|
68 | ! j_north |
---|
69 | ! |
---|
70 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
71 | ! unused variables removed |
---|
72 | ! |
---|
73 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
74 | ! code put under GPL (PALM 3.9) |
---|
75 | ! |
---|
76 | ! 1015 2012-09-27 09:23:24Z raasch |
---|
77 | ! accelerator version (*_acc) added |
---|
78 | ! |
---|
79 | ! 1010 2012-09-20 07:59:54Z raasch |
---|
80 | ! cpp switch __nopointer added for pointer free version |
---|
81 | ! |
---|
82 | ! 1001 2012-09-13 14:08:46Z raasch |
---|
83 | ! some arrays comunicated by module instead of parameter list |
---|
84 | ! |
---|
85 | ! Revision 1.1 2000/04/13 14:54:02 schroeter |
---|
86 | ! Initial revision |
---|
87 | ! |
---|
88 | ! |
---|
89 | ! Description: |
---|
90 | ! ------------ |
---|
91 | !> Diffusion term of scalar quantities (temperature and water content) |
---|
92 | !------------------------------------------------------------------------------! |
---|
93 | MODULE diffusion_s_mod |
---|
94 | |
---|
95 | |
---|
96 | PRIVATE |
---|
97 | PUBLIC diffusion_s |
---|
98 | |
---|
99 | INTERFACE diffusion_s |
---|
100 | MODULE PROCEDURE diffusion_s |
---|
101 | MODULE PROCEDURE diffusion_s_ij |
---|
102 | END INTERFACE diffusion_s |
---|
103 | |
---|
104 | CONTAINS |
---|
105 | |
---|
106 | |
---|
107 | !------------------------------------------------------------------------------! |
---|
108 | ! Description: |
---|
109 | ! ------------ |
---|
110 | !> Call for all grid points |
---|
111 | !------------------------------------------------------------------------------! |
---|
112 | SUBROUTINE diffusion_s( s, s_flux_b, s_flux_t, wall_s_flux ) |
---|
113 | |
---|
114 | USE arrays_3d, & |
---|
115 | ONLY: ddzu, ddzw, kh, tend, drho_air, rho_air_zw |
---|
116 | |
---|
117 | USE control_parameters, & |
---|
118 | ONLY: use_surface_fluxes, use_top_fluxes |
---|
119 | |
---|
120 | USE grid_variables, & |
---|
121 | ONLY: ddx2, ddy2, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y |
---|
122 | |
---|
123 | USE indices, & |
---|
124 | ONLY: nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, & |
---|
125 | nzb_diff_s_inner, nzb_s_inner, nzb_s_outer, nzt, nzt_diff |
---|
126 | |
---|
127 | USE kinds |
---|
128 | |
---|
129 | IMPLICIT NONE |
---|
130 | |
---|
131 | INTEGER(iwp) :: i !< |
---|
132 | INTEGER(iwp) :: j !< |
---|
133 | INTEGER(iwp) :: k !< |
---|
134 | REAL(wp) :: wall_s_flux(0:4) !< |
---|
135 | REAL(wp), DIMENSION(nysg:nyng,nxlg:nxrg) :: s_flux_b, s_flux_t !< |
---|
136 | #if defined( __nopointer ) |
---|
137 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: s !< |
---|
138 | #else |
---|
139 | REAL(wp), DIMENSION(:,:,:), POINTER :: s !< |
---|
140 | #endif |
---|
141 | |
---|
142 | DO i = nxl, nxr |
---|
143 | DO j = nys,nyn |
---|
144 | ! |
---|
145 | !-- Compute horizontal diffusion |
---|
146 | DO k = nzb_s_outer(j,i)+1, nzt |
---|
147 | |
---|
148 | tend(k,j,i) = tend(k,j,i) & |
---|
149 | + 0.5_wp * ( & |
---|
150 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
151 | - ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
152 | ) * ddx2 & |
---|
153 | + 0.5_wp * ( & |
---|
154 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
155 | - ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
156 | ) * ddy2 |
---|
157 | ENDDO |
---|
158 | |
---|
159 | ! |
---|
160 | !-- Apply prescribed horizontal wall heatflux where necessary |
---|
161 | IF ( ( wall_w_x(j,i) /= 0.0_wp ) .OR. ( wall_w_y(j,i) /= 0.0_wp ) & |
---|
162 | ) THEN |
---|
163 | DO k = nzb_s_inner(j,i)+1, nzb_s_outer(j,i) |
---|
164 | |
---|
165 | tend(k,j,i) = tend(k,j,i) & |
---|
166 | + ( fwxp(j,i) * 0.5_wp * & |
---|
167 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
168 | + ( 1.0_wp - fwxp(j,i) ) * wall_s_flux(1) & |
---|
169 | -fwxm(j,i) * 0.5_wp * & |
---|
170 | ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
171 | + ( 1.0_wp - fwxm(j,i) ) * wall_s_flux(2) & |
---|
172 | ) * ddx2 & |
---|
173 | + ( fwyp(j,i) * 0.5_wp * & |
---|
174 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
175 | + ( 1.0_wp - fwyp(j,i) ) * wall_s_flux(3) & |
---|
176 | -fwym(j,i) * 0.5_wp * & |
---|
177 | ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
178 | + ( 1.0_wp - fwym(j,i) ) * wall_s_flux(4) & |
---|
179 | ) * ddy2 |
---|
180 | ENDDO |
---|
181 | ENDIF |
---|
182 | |
---|
183 | ! |
---|
184 | !-- Compute vertical diffusion. In case that surface fluxes have been |
---|
185 | !-- prescribed or computed at bottom and/or top, index k starts/ends at |
---|
186 | !-- nzb+2 or nzt-1, respectively. |
---|
187 | DO k = nzb_diff_s_inner(j,i), nzt_diff |
---|
188 | |
---|
189 | tend(k,j,i) = tend(k,j,i) & |
---|
190 | + 0.5_wp * ( & |
---|
191 | ( kh(k,j,i) + kh(k+1,j,i) ) * ( s(k+1,j,i)-s(k,j,i) ) * ddzu(k+1) & |
---|
192 | * rho_air_zw(k) & |
---|
193 | - ( kh(k,j,i) + kh(k-1,j,i) ) * ( s(k,j,i)-s(k-1,j,i) ) * ddzu(k) & |
---|
194 | * rho_air_zw(k-1) & |
---|
195 | ) * ddzw(k) * drho_air(k) |
---|
196 | ENDDO |
---|
197 | |
---|
198 | ! |
---|
199 | !-- Vertical diffusion at the first computational gridpoint along |
---|
200 | !-- z-direction |
---|
201 | IF ( use_surface_fluxes ) THEN |
---|
202 | |
---|
203 | k = nzb_s_inner(j,i)+1 |
---|
204 | |
---|
205 | tend(k,j,i) = tend(k,j,i) & |
---|
206 | + ( 0.5_wp * ( kh(k,j,i)+kh(k+1,j,i) ) & |
---|
207 | * ( s(k+1,j,i)-s(k,j,i) ) & |
---|
208 | * ddzu(k+1) & |
---|
209 | * rho_air_zw(k) & |
---|
210 | + s_flux_b(j,i) & |
---|
211 | ) * ddzw(k) * drho_air(k) |
---|
212 | |
---|
213 | ENDIF |
---|
214 | |
---|
215 | ! |
---|
216 | !-- Vertical diffusion at the last computational gridpoint along |
---|
217 | !-- z-direction |
---|
218 | IF ( use_top_fluxes ) THEN |
---|
219 | |
---|
220 | k = nzt |
---|
221 | |
---|
222 | tend(k,j,i) = tend(k,j,i) & |
---|
223 | + ( - s_flux_t(j,i) & |
---|
224 | - 0.5_wp * ( kh(k-1,j,i)+kh(k,j,i) )& |
---|
225 | * ( s(k,j,i)-s(k-1,j,i) ) & |
---|
226 | * ddzu(k) & |
---|
227 | * rho_air_zw(k-1) & |
---|
228 | ) * ddzw(k) * drho_air(k) |
---|
229 | |
---|
230 | ENDIF |
---|
231 | |
---|
232 | ENDDO |
---|
233 | ENDDO |
---|
234 | |
---|
235 | END SUBROUTINE diffusion_s |
---|
236 | |
---|
237 | |
---|
238 | !------------------------------------------------------------------------------! |
---|
239 | ! Description: |
---|
240 | ! ------------ |
---|
241 | !> Call for grid point i,j |
---|
242 | !------------------------------------------------------------------------------! |
---|
243 | SUBROUTINE diffusion_s_ij( i, j, s, s_flux_b, s_flux_t, wall_s_flux ) |
---|
244 | |
---|
245 | USE arrays_3d, & |
---|
246 | ONLY: ddzu, ddzw, kh, tend, drho_air, rho_air_zw |
---|
247 | |
---|
248 | USE control_parameters, & |
---|
249 | ONLY: use_surface_fluxes, use_top_fluxes |
---|
250 | |
---|
251 | USE grid_variables, & |
---|
252 | ONLY: ddx2, ddy2, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y |
---|
253 | |
---|
254 | USE indices, & |
---|
255 | ONLY: nxlg, nxrg, nyng, nysg, nzb, nzb_diff_s_inner, nzb_s_inner, & |
---|
256 | nzb_s_outer, nzt, nzt_diff |
---|
257 | |
---|
258 | USE kinds |
---|
259 | |
---|
260 | IMPLICIT NONE |
---|
261 | |
---|
262 | INTEGER(iwp) :: i !< |
---|
263 | INTEGER(iwp) :: j !< |
---|
264 | INTEGER(iwp) :: k !< |
---|
265 | REAL(wp) :: wall_s_flux(0:4) !< |
---|
266 | REAL(wp), DIMENSION(nysg:nyng,nxlg:nxrg) :: s_flux_b !< |
---|
267 | REAL(wp), DIMENSION(nysg:nyng,nxlg:nxrg) :: s_flux_t !< |
---|
268 | #if defined( __nopointer ) |
---|
269 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: s !< |
---|
270 | #else |
---|
271 | REAL(wp), DIMENSION(:,:,:), POINTER :: s !< |
---|
272 | #endif |
---|
273 | |
---|
274 | ! |
---|
275 | !-- Compute horizontal diffusion |
---|
276 | DO k = nzb_s_outer(j,i)+1, nzt |
---|
277 | |
---|
278 | tend(k,j,i) = tend(k,j,i) & |
---|
279 | + 0.5_wp * ( & |
---|
280 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
281 | - ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
282 | ) * ddx2 & |
---|
283 | + 0.5_wp * ( & |
---|
284 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
285 | - ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
286 | ) * ddy2 |
---|
287 | ENDDO |
---|
288 | |
---|
289 | ! |
---|
290 | !-- Apply prescribed horizontal wall heatflux where necessary |
---|
291 | IF ( ( wall_w_x(j,i) /= 0.0_wp ) .OR. ( wall_w_y(j,i) /= 0.0_wp ) ) & |
---|
292 | THEN |
---|
293 | DO k = nzb_s_inner(j,i)+1, nzb_s_outer(j,i) |
---|
294 | |
---|
295 | tend(k,j,i) = tend(k,j,i) & |
---|
296 | + ( fwxp(j,i) * 0.5_wp * & |
---|
297 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
298 | + ( 1.0_wp - fwxp(j,i) ) * wall_s_flux(1) & |
---|
299 | -fwxm(j,i) * 0.5_wp * & |
---|
300 | ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
301 | + ( 1.0_wp - fwxm(j,i) ) * wall_s_flux(2) & |
---|
302 | ) * ddx2 & |
---|
303 | + ( fwyp(j,i) * 0.5_wp * & |
---|
304 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
305 | + ( 1.0_wp - fwyp(j,i) ) * wall_s_flux(3) & |
---|
306 | -fwym(j,i) * 0.5_wp * & |
---|
307 | ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
308 | + ( 1.0_wp - fwym(j,i) ) * wall_s_flux(4) & |
---|
309 | ) * ddy2 |
---|
310 | ENDDO |
---|
311 | ENDIF |
---|
312 | |
---|
313 | ! |
---|
314 | !-- Compute vertical diffusion. In case that surface fluxes have been |
---|
315 | !-- prescribed or computed at bottom and/or top, index k starts/ends at |
---|
316 | !-- nzb+2 or nzt-1, respectively. |
---|
317 | DO k = nzb_diff_s_inner(j,i), nzt_diff |
---|
318 | |
---|
319 | tend(k,j,i) = tend(k,j,i) & |
---|
320 | + 0.5_wp * ( & |
---|
321 | ( kh(k,j,i) + kh(k+1,j,i) ) * ( s(k+1,j,i)-s(k,j,i) ) * ddzu(k+1) & |
---|
322 | * rho_air_zw(k) & |
---|
323 | - ( kh(k,j,i) + kh(k-1,j,i) ) * ( s(k,j,i)-s(k-1,j,i) ) * ddzu(k) & |
---|
324 | * rho_air_zw(k-1) & |
---|
325 | ) * ddzw(k) * drho_air(k) |
---|
326 | ENDDO |
---|
327 | |
---|
328 | ! |
---|
329 | !-- Vertical diffusion at the first computational gridpoint along z-direction |
---|
330 | IF ( use_surface_fluxes ) THEN |
---|
331 | |
---|
332 | k = nzb_s_inner(j,i)+1 |
---|
333 | |
---|
334 | tend(k,j,i) = tend(k,j,i) + ( 0.5_wp * ( kh(k,j,i)+kh(k+1,j,i) ) & |
---|
335 | * ( s(k+1,j,i)-s(k,j,i) ) & |
---|
336 | * ddzu(k+1) & |
---|
337 | * rho_air_zw(k) & |
---|
338 | + s_flux_b(j,i) & |
---|
339 | ) * ddzw(k) * drho_air(k) |
---|
340 | |
---|
341 | ENDIF |
---|
342 | |
---|
343 | ! |
---|
344 | !-- Vertical diffusion at the last computational gridpoint along z-direction |
---|
345 | IF ( use_top_fluxes ) THEN |
---|
346 | |
---|
347 | k = nzt |
---|
348 | |
---|
349 | tend(k,j,i) = tend(k,j,i) + ( - s_flux_t(j,i) & |
---|
350 | - 0.5_wp * ( kh(k-1,j,i)+kh(k,j,i) ) & |
---|
351 | * ( s(k,j,i)-s(k-1,j,i) ) & |
---|
352 | * ddzu(k) & |
---|
353 | * rho_air_zw(k-1) & |
---|
354 | ) * ddzw(k) * drho_air(k) |
---|
355 | |
---|
356 | ENDIF |
---|
357 | |
---|
358 | END SUBROUTINE diffusion_s_ij |
---|
359 | |
---|
360 | END MODULE diffusion_s_mod |
---|