1 | MODULE diffusion_s_mod |
---|
2 | |
---|
3 | !------------------------------------------------------------------------------! |
---|
4 | ! Actual revisions: |
---|
5 | ! ----------------- |
---|
6 | ! replace wall_heatflux by wall_s_flux that is now included in the parameter |
---|
7 | ! list, bugfix for assignment of fluxes at walls |
---|
8 | ! |
---|
9 | ! Former revisions: |
---|
10 | ! ----------------- |
---|
11 | ! $Id: diffusion_s.f90 129 2007-10-30 12:12:24Z letzel $ |
---|
12 | ! |
---|
13 | ! 20 2007-02-26 00:12:32Z raasch |
---|
14 | ! Bugfix: ddzw dimensioned 1:nzt"+1" |
---|
15 | ! Calculation extended for gridpoint nzt, fluxes can be given at top, |
---|
16 | ! +s_flux_t in parameter list, s_flux renamed s_flux_b |
---|
17 | ! |
---|
18 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
19 | ! |
---|
20 | ! Revision 1.8 2006/02/23 10:34:17 raasch |
---|
21 | ! nzb_2d replaced by nzb_s_outer in horizontal diffusion and by nzb_s_inner |
---|
22 | ! or nzb_diff_s_inner, respectively, in vertical diffusion, prescribed surface |
---|
23 | ! fluxes at vertically oriented topography |
---|
24 | ! |
---|
25 | ! Revision 1.1 2000/04/13 14:54:02 schroeter |
---|
26 | ! Initial revision |
---|
27 | ! |
---|
28 | ! |
---|
29 | ! Description: |
---|
30 | ! ------------ |
---|
31 | ! Diffusion term of scalar quantities (temperature and water content) |
---|
32 | !------------------------------------------------------------------------------! |
---|
33 | |
---|
34 | PRIVATE |
---|
35 | PUBLIC diffusion_s |
---|
36 | |
---|
37 | INTERFACE diffusion_s |
---|
38 | MODULE PROCEDURE diffusion_s |
---|
39 | MODULE PROCEDURE diffusion_s_ij |
---|
40 | END INTERFACE diffusion_s |
---|
41 | |
---|
42 | CONTAINS |
---|
43 | |
---|
44 | |
---|
45 | !------------------------------------------------------------------------------! |
---|
46 | ! Call for all grid points |
---|
47 | !------------------------------------------------------------------------------! |
---|
48 | SUBROUTINE diffusion_s( ddzu, ddzw, kh, s, s_flux_b, s_flux_t, & |
---|
49 | wall_s_flux, tend ) |
---|
50 | |
---|
51 | USE control_parameters |
---|
52 | USE grid_variables |
---|
53 | USE indices |
---|
54 | |
---|
55 | IMPLICIT NONE |
---|
56 | |
---|
57 | INTEGER :: i, j, k |
---|
58 | REAL :: vertical_gridspace |
---|
59 | REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1) |
---|
60 | REAL :: tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) |
---|
61 | REAL :: wall_s_flux(0:4) |
---|
62 | REAL, DIMENSION(:,:), POINTER :: s_flux_b, s_flux_t |
---|
63 | REAL, DIMENSION(:,:,:), POINTER :: kh, s |
---|
64 | |
---|
65 | DO i = nxl, nxr |
---|
66 | DO j = nys,nyn |
---|
67 | ! |
---|
68 | !-- Compute horizontal diffusion |
---|
69 | DO k = nzb_s_outer(j,i)+1, nzt |
---|
70 | |
---|
71 | tend(k,j,i) = tend(k,j,i) & |
---|
72 | + 0.5 * ( & |
---|
73 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
74 | - ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
75 | ) * ddx2 & |
---|
76 | + 0.5 * ( & |
---|
77 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
78 | - ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
79 | ) * ddy2 |
---|
80 | ENDDO |
---|
81 | |
---|
82 | ! |
---|
83 | !-- Apply prescribed horizontal wall heatflux where necessary |
---|
84 | IF ( ( wall_w_x(j,i) .NE. 0.0 ) .OR. ( wall_w_y(j,i) .NE. 0.0 ) ) & |
---|
85 | THEN |
---|
86 | DO k = nzb_s_inner(j,i)+1, nzb_s_outer(j,i) |
---|
87 | |
---|
88 | tend(k,j,i) = tend(k,j,i) & |
---|
89 | + 0.5 * ( fwxp(j,i) * & |
---|
90 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
91 | + ( 1.0 - fwxp(j,i) ) * wall_s_flux(1) & |
---|
92 | -fwxm(j,i) * & |
---|
93 | ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
94 | + ( 1.0 - fwxm(j,i) ) * wall_s_flux(2) & |
---|
95 | ) * ddx2 & |
---|
96 | + 0.5 * ( fwyp(j,i) * & |
---|
97 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
98 | + ( 1.0 - fwyp(j,i) ) * wall_s_flux(3) & |
---|
99 | -fwym(j,i) * & |
---|
100 | ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
101 | + ( 1.0 - fwym(j,i) ) * wall_s_flux(4) & |
---|
102 | ) * ddy2 |
---|
103 | ENDDO |
---|
104 | ENDIF |
---|
105 | |
---|
106 | ! |
---|
107 | !-- Compute vertical diffusion. In case that surface fluxes have been |
---|
108 | !-- prescribed or computed at bottom and/or top, index k starts/ends at |
---|
109 | !-- nzb+2 or nzt-1, respectively. |
---|
110 | DO k = nzb_diff_s_inner(j,i), nzt_diff |
---|
111 | |
---|
112 | tend(k,j,i) = tend(k,j,i) & |
---|
113 | + 0.5 * ( & |
---|
114 | ( kh(k,j,i) + kh(k+1,j,i) ) * ( s(k+1,j,i)-s(k,j,i) ) * ddzu(k+1) & |
---|
115 | - ( kh(k,j,i) + kh(k-1,j,i) ) * ( s(k,j,i)-s(k-1,j,i) ) * ddzu(k) & |
---|
116 | ) * ddzw(k) |
---|
117 | ENDDO |
---|
118 | |
---|
119 | ! |
---|
120 | !-- Vertical diffusion at the first computational gridpoint along |
---|
121 | !-- z-direction |
---|
122 | IF ( use_surface_fluxes ) THEN |
---|
123 | |
---|
124 | k = nzb_s_inner(j,i)+1 |
---|
125 | |
---|
126 | tend(k,j,i) = tend(k,j,i) & |
---|
127 | + ( 0.5 * ( kh(k,j,i)+kh(k+1,j,i) ) & |
---|
128 | * ( s(k+1,j,i)-s(k,j,i) ) & |
---|
129 | * ddzu(k+1) & |
---|
130 | + s_flux_b(j,i) & |
---|
131 | ) * ddzw(k) |
---|
132 | |
---|
133 | ENDIF |
---|
134 | |
---|
135 | ! |
---|
136 | !-- Vertical diffusion at the last computational gridpoint along |
---|
137 | !-- z-direction |
---|
138 | IF ( use_top_fluxes ) THEN |
---|
139 | |
---|
140 | k = nzt |
---|
141 | |
---|
142 | tend(k,j,i) = tend(k,j,i) & |
---|
143 | + ( - s_flux_t(j,i) & |
---|
144 | - 0.5 * ( kh(k-1,j,i)+kh(k,j,i) ) & |
---|
145 | * ( s(k,j,i)-s(k-1,j,i) ) & |
---|
146 | * ddzu(k) & |
---|
147 | ) * ddzw(k) |
---|
148 | |
---|
149 | ENDIF |
---|
150 | |
---|
151 | ENDDO |
---|
152 | ENDDO |
---|
153 | |
---|
154 | END SUBROUTINE diffusion_s |
---|
155 | |
---|
156 | |
---|
157 | !------------------------------------------------------------------------------! |
---|
158 | ! Call for grid point i,j |
---|
159 | !------------------------------------------------------------------------------! |
---|
160 | SUBROUTINE diffusion_s_ij( i, j, ddzu, ddzw, kh, s, s_flux_b, s_flux_t, & |
---|
161 | wall_s_flux, tend ) |
---|
162 | |
---|
163 | USE control_parameters |
---|
164 | USE grid_variables |
---|
165 | USE indices |
---|
166 | |
---|
167 | IMPLICIT NONE |
---|
168 | |
---|
169 | INTEGER :: i, j, k |
---|
170 | REAL :: vertical_gridspace |
---|
171 | REAL :: ddzu(1:nzt+1), ddzw(1:nzt+1) |
---|
172 | REAL :: tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) |
---|
173 | REAL :: wall_s_flux(0:4) |
---|
174 | REAL, DIMENSION(:,:), POINTER :: s_flux_b, s_flux_t |
---|
175 | REAL, DIMENSION(:,:,:), POINTER :: kh, s |
---|
176 | |
---|
177 | ! |
---|
178 | !-- Compute horizontal diffusion |
---|
179 | DO k = nzb_s_outer(j,i)+1, nzt |
---|
180 | |
---|
181 | tend(k,j,i) = tend(k,j,i) & |
---|
182 | + 0.5 * ( & |
---|
183 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
184 | - ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
185 | ) * ddx2 & |
---|
186 | + 0.5 * ( & |
---|
187 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
188 | - ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
189 | ) * ddy2 |
---|
190 | ENDDO |
---|
191 | |
---|
192 | ! |
---|
193 | !-- Apply prescribed horizontal wall heatflux where necessary |
---|
194 | IF ( ( wall_w_x(j,i) .NE. 0.0 ) .OR. ( wall_w_y(j,i) .NE. 0.0 ) ) & |
---|
195 | THEN |
---|
196 | DO k = nzb_s_inner(j,i)+1, nzb_s_outer(j,i) |
---|
197 | |
---|
198 | tend(k,j,i) = tend(k,j,i) & |
---|
199 | + 0.5 * ( fwxp(j,i) * & |
---|
200 | ( kh(k,j,i) + kh(k,j,i+1) ) * ( s(k,j,i+1)-s(k,j,i) ) & |
---|
201 | + ( 1.0 - fwxp(j,i) ) * wall_s_flux(1) & |
---|
202 | -fwxm(j,i) * & |
---|
203 | ( kh(k,j,i) + kh(k,j,i-1) ) * ( s(k,j,i)-s(k,j,i-1) ) & |
---|
204 | + ( 1.0 - fwxm(j,i) ) * wall_s_flux(2) & |
---|
205 | ) * ddx2 & |
---|
206 | + 0.5 * ( fwyp(j,i) * & |
---|
207 | ( kh(k,j,i) + kh(k,j+1,i) ) * ( s(k,j+1,i)-s(k,j,i) ) & |
---|
208 | + ( 1.0 - fwyp(j,i) ) * wall_s_flux(3) & |
---|
209 | -fwym(j,i) * & |
---|
210 | ( kh(k,j,i) + kh(k,j-1,i) ) * ( s(k,j,i)-s(k,j-1,i) ) & |
---|
211 | + ( 1.0 - fwym(j,i) ) * wall_s_flux(4) & |
---|
212 | ) * ddy2 |
---|
213 | ENDDO |
---|
214 | ENDIF |
---|
215 | |
---|
216 | ! |
---|
217 | !-- Compute vertical diffusion. In case that surface fluxes have been |
---|
218 | !-- prescribed or computed at bottom and/or top, index k starts/ends at |
---|
219 | !-- nzb+2 or nzt-1, respectively. |
---|
220 | DO k = nzb_diff_s_inner(j,i), nzt_diff |
---|
221 | |
---|
222 | tend(k,j,i) = tend(k,j,i) & |
---|
223 | + 0.5 * ( & |
---|
224 | ( kh(k,j,i) + kh(k+1,j,i) ) * ( s(k+1,j,i)-s(k,j,i) ) * ddzu(k+1) & |
---|
225 | - ( kh(k,j,i) + kh(k-1,j,i) ) * ( s(k,j,i)-s(k-1,j,i) ) * ddzu(k) & |
---|
226 | ) * ddzw(k) |
---|
227 | ENDDO |
---|
228 | |
---|
229 | ! |
---|
230 | !-- Vertical diffusion at the first computational gridpoint along z-direction |
---|
231 | IF ( use_surface_fluxes ) THEN |
---|
232 | |
---|
233 | k = nzb_s_inner(j,i)+1 |
---|
234 | |
---|
235 | tend(k,j,i) = tend(k,j,i) + ( 0.5 * ( kh(k,j,i)+kh(k+1,j,i) ) & |
---|
236 | * ( s(k+1,j,i)-s(k,j,i) ) & |
---|
237 | * ddzu(k+1) & |
---|
238 | + s_flux_b(j,i) & |
---|
239 | ) * ddzw(k) |
---|
240 | |
---|
241 | ENDIF |
---|
242 | |
---|
243 | ! |
---|
244 | !-- Vertical diffusion at the last computational gridpoint along z-direction |
---|
245 | IF ( use_top_fluxes ) THEN |
---|
246 | |
---|
247 | k = nzt |
---|
248 | |
---|
249 | tend(k,j,i) = tend(k,j,i) + ( - s_flux_t(j,i) & |
---|
250 | - 0.5 * ( kh(k-1,j,i)+kh(k,j,i) ) & |
---|
251 | * ( s(k,j,i)-s(k-1,j,i) ) & |
---|
252 | * ddzu(k) & |
---|
253 | ) * ddzw(k) |
---|
254 | |
---|
255 | ENDIF |
---|
256 | |
---|
257 | END SUBROUTINE diffusion_s_ij |
---|
258 | |
---|
259 | END MODULE diffusion_s_mod |
---|