1 | MODULE caldyn_kernels_base_mod |
---|
2 | USE icosa |
---|
3 | USE transfert_mod |
---|
4 | USE disvert_mod |
---|
5 | USE omp_para |
---|
6 | USE trace |
---|
7 | IMPLICIT NONE |
---|
8 | PRIVATE |
---|
9 | |
---|
10 | INTEGER, PARAMETER,PUBLIC :: energy=1, enstrophy=2 |
---|
11 | TYPE(t_field),POINTER,PUBLIC :: f_out_u(:), f_qu(:), f_qv(:) |
---|
12 | REAL(rstd),SAVE,POINTER :: out_u(:,:), p(:,:), qu(:,:) |
---|
13 | !$OMP THREADPRIVATE(out_u, p, qu) |
---|
14 | |
---|
15 | ! temporary shared variables for caldyn |
---|
16 | TYPE(t_field),POINTER,PUBLIC :: f_pk(:),f_wwuu(:),f_planetvel(:), & |
---|
17 | f_Fel(:), f_gradPhi2(:), f_wil(:), f_Wetadot(:) |
---|
18 | |
---|
19 | INTEGER, PUBLIC :: caldyn_conserv |
---|
20 | !$OMP THREADPRIVATE(caldyn_conserv) |
---|
21 | |
---|
22 | TYPE(t_message),PUBLIC :: req_ps, req_mass, req_theta_rhodz, req_u, req_qu, req_geopot, req_w |
---|
23 | |
---|
24 | PUBLIC :: compute_geopot, compute_caldyn_vert, compute_caldyn_vert_nh |
---|
25 | |
---|
26 | CONTAINS |
---|
27 | |
---|
28 | !**************************** Geopotential ***************************** |
---|
29 | |
---|
30 | SUBROUTINE compute_geopot(rhodz,theta, ps,pk,geopot) |
---|
31 | REAL(rstd),INTENT(IN) :: rhodz(iim*jjm,llm) |
---|
32 | REAL(rstd),INTENT(IN) :: theta(iim*jjm,llm,nqdyn) ! active scalars : theta/entropy, moisture, ... |
---|
33 | REAL(rstd),INTENT(INOUT) :: ps(iim*jjm) |
---|
34 | REAL(rstd),INTENT(OUT) :: pk(iim*jjm,llm) ! Exner function (compressible) /Lagrange multiplier (Boussinesq) |
---|
35 | REAL(rstd),INTENT(INOUT) :: geopot(iim*jjm,llm+1) ! geopotential |
---|
36 | |
---|
37 | INTEGER :: i,j,ij,l |
---|
38 | REAL(rstd) :: Rd, p_ik, exner_ik, temp_ik, qv, chi, Rmix, gv |
---|
39 | INTEGER :: ij_omp_begin_ext, ij_omp_end_ext |
---|
40 | |
---|
41 | CALL trace_start("compute_geopot") |
---|
42 | |
---|
43 | !$OMP BARRIER |
---|
44 | |
---|
45 | CALL distrib_level(ij_begin_ext,ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext) |
---|
46 | |
---|
47 | Rd = kappa*cpp |
---|
48 | |
---|
49 | IF(dysl_geopot) THEN |
---|
50 | #include "../kernels/compute_geopot.k90" |
---|
51 | ELSE |
---|
52 | ! Pressure is computed first top-down (temporarily stored in pk) |
---|
53 | ! Then Exner pressure and geopotential are computed bottom-up |
---|
54 | ! Works also when caldyn_eta=eta_mass |
---|
55 | |
---|
56 | IF(boussinesq) THEN ! compute geopotential and pk=Lagrange multiplier |
---|
57 | ! specific volume 1 = dphi/g/rhodz |
---|
58 | ! IF (is_omp_level_master) THEN ! no openMP on vertical due to dependency |
---|
59 | DO l = 1,llm |
---|
60 | !DIR$ SIMD |
---|
61 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
62 | geopot(ij,l+1) = geopot(ij,l) + g*rhodz(ij,l) |
---|
63 | ENDDO |
---|
64 | ENDDO |
---|
65 | ! use hydrostatic balance with theta*rhodz to find pk (Lagrange multiplier=pressure) |
---|
66 | ! uppermost layer |
---|
67 | !DIR$ SIMD |
---|
68 | DO ij=ij_begin_ext,ij_end_ext |
---|
69 | pk(ij,llm) = ptop + (.5*g)*theta(ij,llm,1)*rhodz(ij,llm) |
---|
70 | END DO |
---|
71 | ! other layers |
---|
72 | DO l = llm-1, 1, -1 |
---|
73 | ! !$OMP DO SCHEDULE(STATIC) |
---|
74 | !DIR$ SIMD |
---|
75 | DO ij=ij_begin_ext,ij_end_ext |
---|
76 | pk(ij,l) = pk(ij,l+1) + (.5*g)*(theta(ij,l,1)*rhodz(ij,l)+theta(ij,l+1,1)*rhodz(ij,l+1)) |
---|
77 | END DO |
---|
78 | END DO |
---|
79 | ! now pk contains the Lagrange multiplier (pressure) |
---|
80 | ELSE ! non-Boussinesq, compute pressure, Exner pressure or temperature, then geopotential |
---|
81 | ! uppermost layer |
---|
82 | |
---|
83 | SELECT CASE(caldyn_thermo) |
---|
84 | CASE(thermo_theta, thermo_entropy) |
---|
85 | !DIR$ SIMD |
---|
86 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
87 | pk(ij,llm) = ptop + (.5*g)*rhodz(ij,llm) |
---|
88 | END DO |
---|
89 | ! other layers |
---|
90 | DO l = llm-1, 1, -1 |
---|
91 | !DIR$ SIMD |
---|
92 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
93 | pk(ij,l) = pk(ij,l+1) + (.5*g)*(rhodz(ij,l)+rhodz(ij,l+1)) |
---|
94 | END DO |
---|
95 | END DO |
---|
96 | ! surface pressure (for diagnostics) |
---|
97 | IF(caldyn_eta==eta_lag) THEN |
---|
98 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
99 | ps(ij) = pk(ij,1) + (.5*g)*rhodz(ij,1) |
---|
100 | END DO |
---|
101 | END IF |
---|
102 | CASE(thermo_moist) ! theta(ij,l,2) = qv = mv/md |
---|
103 | !DIR$ SIMD |
---|
104 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
105 | pk(ij,llm) = ptop + (.5*g)*rhodz(ij,llm)*(1.+theta(ij,l,2)) |
---|
106 | END DO |
---|
107 | ! other layers |
---|
108 | DO l = llm-1, 1, -1 |
---|
109 | !DIR$ SIMD |
---|
110 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
111 | pk(ij,l) = pk(ij,l+1) + (.5*g)*( & |
---|
112 | rhodz(ij,l) *(1.+theta(ij,l,2)) + & |
---|
113 | rhodz(ij,l+1)*(1.+theta(ij,l+1,2)) ) |
---|
114 | END DO |
---|
115 | END DO |
---|
116 | ! surface pressure (for diagnostics) |
---|
117 | IF(caldyn_eta==eta_lag) THEN |
---|
118 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
119 | ps(ij) = pk(ij,1) + (.5*g)*rhodz(ij,1)*(1.+theta(ij,l,2)) |
---|
120 | END DO |
---|
121 | END IF |
---|
122 | END SELECT |
---|
123 | |
---|
124 | DO l = 1,llm |
---|
125 | SELECT CASE(caldyn_thermo) |
---|
126 | CASE(thermo_theta) |
---|
127 | !DIR$ SIMD |
---|
128 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
129 | p_ik = pk(ij,l) |
---|
130 | exner_ik = cpp * (p_ik/preff) ** kappa |
---|
131 | pk(ij,l) = exner_ik |
---|
132 | ! specific volume v = kappa*theta*pi/p = dphi/g/rhodz |
---|
133 | geopot(ij,l+1) = geopot(ij,l) + (g*kappa)*rhodz(ij,l)*theta(ij,l,1)*exner_ik/p_ik |
---|
134 | ENDDO |
---|
135 | CASE(thermo_entropy) ! theta is in fact entropy = cpp*log(theta/Treff) = cpp*log(T/Treff) - Rd*log(p/preff) |
---|
136 | !DIR$ SIMD |
---|
137 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
138 | p_ik = pk(ij,l) |
---|
139 | temp_ik = Treff*exp((theta(ij,l,1) + Rd*log(p_ik/preff))/cpp) |
---|
140 | pk(ij,l) = temp_ik |
---|
141 | ! specific volume v = Rd*T/p = dphi/g/rhodz |
---|
142 | geopot(ij,l+1) = geopot(ij,l) + (g*Rd)*rhodz(ij,l)*temp_ik/p_ik |
---|
143 | ENDDO |
---|
144 | CASE(thermo_moist) ! theta is moist pseudo-entropy per dry air mass |
---|
145 | DO ij=ij_omp_begin_ext,ij_omp_end_ext |
---|
146 | p_ik = pk(ij,l) |
---|
147 | qv = theta(ij,l,2) ! water vaper mixing ratio = mv/md |
---|
148 | Rmix = Rd+qv*Rv |
---|
149 | chi = ( theta(ij,l,1) + Rmix*log(p_ik/preff) ) / (cpp + qv*cppv) ! log(T/Treff) |
---|
150 | temp_ik = Treff*exp(chi) |
---|
151 | pk(ij,l) = temp_ik |
---|
152 | ! specific volume v = R*T/p = dphi/g/rhodz |
---|
153 | ! R = (Rd + qv.Rv)/(1+qv) |
---|
154 | geopot(ij,l+1) = geopot(ij,l) + g*Rmix*rhodz(ij,l)*temp_ik/(p_ik*(1+qv)) |
---|
155 | ENDDO |
---|
156 | CASE DEFAULT |
---|
157 | STOP |
---|
158 | END SELECT |
---|
159 | ENDDO |
---|
160 | END IF |
---|
161 | |
---|
162 | END IF ! dysl |
---|
163 | |
---|
164 | !ym flush geopot |
---|
165 | !$OMP BARRIER |
---|
166 | |
---|
167 | CALL trace_end("compute_geopot") |
---|
168 | |
---|
169 | END SUBROUTINE compute_geopot |
---|
170 | |
---|
171 | SUBROUTINE compute_caldyn_vert(u,theta,rhodz,convm, wflux,wwuu, dps,dtheta_rhodz,du) |
---|
172 | REAL(rstd),INTENT(IN) :: u(iim*3*jjm,llm) |
---|
173 | REAL(rstd),INTENT(IN) :: theta(iim*jjm,llm,nqdyn) |
---|
174 | REAL(rstd),INTENT(IN) :: rhodz(iim*jjm,llm) |
---|
175 | REAL(rstd),INTENT(INOUT) :: convm(iim*jjm,llm) ! mass flux convergence |
---|
176 | |
---|
177 | REAL(rstd),INTENT(INOUT) :: wflux(iim*jjm,llm+1) ! vertical mass flux (kg/m2/s) |
---|
178 | REAL(rstd),INTENT(INOUT) :: wwuu(iim*3*jjm,llm+1) |
---|
179 | REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm) |
---|
180 | REAL(rstd),INTENT(INOUT) :: dtheta_rhodz(iim*jjm,llm,nqdyn) |
---|
181 | REAL(rstd),INTENT(OUT) :: dps(iim*jjm) |
---|
182 | |
---|
183 | ! temporary variable |
---|
184 | INTEGER :: i,j,ij,l,iq |
---|
185 | REAL(rstd) :: p_ik, exner_ik |
---|
186 | INTEGER :: ij_omp_begin, ij_omp_end |
---|
187 | |
---|
188 | CALL trace_start("compute_caldyn_vert") |
---|
189 | |
---|
190 | CALL distrib_level(ij_begin,ij_end, ij_omp_begin,ij_omp_end) |
---|
191 | |
---|
192 | ! REAL(rstd) :: wwuu(iim*3*jjm,llm+1) ! tmp var, don't know why but gain 30% on the whole code in opemp |
---|
193 | ! need to be understood |
---|
194 | |
---|
195 | ! wwuu=wwuu_out |
---|
196 | CALL trace_start("compute_caldyn_vert") |
---|
197 | |
---|
198 | !$OMP BARRIER |
---|
199 | !!! cumulate mass flux convergence from top to bottom |
---|
200 | ! IF (is_omp_level_master) THEN |
---|
201 | DO l = llm-1, 1, -1 |
---|
202 | ! IF (caldyn_conserv==energy) CALL test_message(req_qu) |
---|
203 | |
---|
204 | !!$OMP DO SCHEDULE(STATIC) |
---|
205 | !DIR$ SIMD |
---|
206 | DO ij=ij_omp_begin,ij_omp_end |
---|
207 | convm(ij,l) = convm(ij,l) + convm(ij,l+1) |
---|
208 | ENDDO |
---|
209 | ENDDO |
---|
210 | ! ENDIF |
---|
211 | |
---|
212 | !$OMP BARRIER |
---|
213 | ! FLUSH on convm |
---|
214 | !!!!!!!!!!!!!!!!!!!!!!!!! |
---|
215 | |
---|
216 | ! compute dps |
---|
217 | IF (is_omp_first_level) THEN |
---|
218 | !DIR$ SIMD |
---|
219 | DO ij=ij_begin,ij_end |
---|
220 | ! dps/dt = -int(div flux)dz |
---|
221 | dps(ij) = convm(ij,1) |
---|
222 | ENDDO |
---|
223 | ENDIF |
---|
224 | |
---|
225 | !!! Compute vertical mass flux (l=1,llm+1 done by caldyn_BC) |
---|
226 | DO l=ll_beginp1,ll_end |
---|
227 | ! IF (caldyn_conserv==energy) CALL test_message(req_qu) |
---|
228 | !DIR$ SIMD |
---|
229 | DO ij=ij_begin,ij_end |
---|
230 | ! w = int(z,ztop,div(flux)dz) + B(eta)dps/dt |
---|
231 | ! => w>0 for upward transport |
---|
232 | wflux( ij, l ) = bp(l) * convm( ij, 1 ) - convm( ij, l ) |
---|
233 | ENDDO |
---|
234 | ENDDO |
---|
235 | |
---|
236 | !--> flush wflux |
---|
237 | !$OMP BARRIER |
---|
238 | |
---|
239 | DO iq=1,nqdyn |
---|
240 | DO l=ll_begin,ll_endm1 |
---|
241 | !DIR$ SIMD |
---|
242 | DO ij=ij_begin,ij_end |
---|
243 | dtheta_rhodz(ij, l, iq) = dtheta_rhodz(ij, l, iq) - 0.5 * & |
---|
244 | ( wflux(ij,l+1) * (theta(ij,l,iq) + theta(ij,l+1,iq))) |
---|
245 | END DO |
---|
246 | END DO |
---|
247 | DO l=ll_beginp1,ll_end |
---|
248 | !DIR$ SIMD |
---|
249 | DO ij=ij_begin,ij_end |
---|
250 | dtheta_rhodz(ij, l, iq) = dtheta_rhodz(ij, l, iq) + 0.5 * & |
---|
251 | ( wflux(ij,l) * (theta(ij,l-1,iq) + theta(ij,l,iq) ) ) |
---|
252 | END DO |
---|
253 | END DO |
---|
254 | END DO |
---|
255 | |
---|
256 | ! Compute vertical transport |
---|
257 | DO l=ll_beginp1,ll_end |
---|
258 | !DIR$ SIMD |
---|
259 | DO ij=ij_begin,ij_end |
---|
260 | wwuu(ij+u_right,l) = 0.5*( wflux(ij,l) + wflux(ij+t_right,l)) * (u(ij+u_right,l) - u(ij+u_right,l-1)) |
---|
261 | wwuu(ij+u_lup,l) = 0.5* ( wflux(ij,l) + wflux(ij+t_lup,l)) * (u(ij+u_lup,l) - u(ij+u_lup,l-1)) |
---|
262 | wwuu(ij+u_ldown,l) = 0.5*( wflux(ij,l) + wflux(ij+t_ldown,l)) * (u(ij+u_ldown,l) - u(ij+u_ldown,l-1)) |
---|
263 | ENDDO |
---|
264 | ENDDO |
---|
265 | |
---|
266 | !--> flush wwuu |
---|
267 | !$OMP BARRIER |
---|
268 | |
---|
269 | ! Add vertical transport to du |
---|
270 | DO l=ll_begin,ll_end |
---|
271 | !DIR$ SIMD |
---|
272 | DO ij=ij_begin,ij_end |
---|
273 | du(ij+u_right, l ) = du(ij+u_right,l) - (wwuu(ij+u_right,l+1)+ wwuu(ij+u_right,l)) / (rhodz(ij,l)+rhodz(ij+t_right,l)) |
---|
274 | du(ij+u_lup, l ) = du(ij+u_lup,l) - (wwuu(ij+u_lup,l+1) + wwuu(ij+u_lup,l)) / (rhodz(ij,l)+rhodz(ij+t_lup,l)) |
---|
275 | du(ij+u_ldown, l ) = du(ij+u_ldown,l) - (wwuu(ij+u_ldown,l+1)+ wwuu(ij+u_ldown,l)) / (rhodz(ij,l)+rhodz(ij+t_ldown,l)) |
---|
276 | ENDDO |
---|
277 | ENDDO |
---|
278 | |
---|
279 | ! DO l=ll_beginp1,ll_end |
---|
280 | !!DIR$ SIMD |
---|
281 | ! DO ij=ij_begin,ij_end |
---|
282 | ! wwuu_out(ij+u_right,l) = wwuu(ij+u_right,l) |
---|
283 | ! wwuu_out(ij+u_lup,l) = wwuu(ij+u_lup,l) |
---|
284 | ! wwuu_out(ij+u_ldown,l) = wwuu(ij+u_ldown,l) |
---|
285 | ! ENDDO |
---|
286 | ! ENDDO |
---|
287 | |
---|
288 | CALL trace_end("compute_caldyn_vert") |
---|
289 | |
---|
290 | END SUBROUTINE compute_caldyn_vert |
---|
291 | |
---|
292 | SUBROUTINE compute_caldyn_vert_NH(mass,geopot,W,wflux, W_etadot, du,dPhi,dW) |
---|
293 | REAL(rstd),INTENT(IN) :: mass(iim*jjm,llm) |
---|
294 | REAL(rstd),INTENT(IN) :: geopot(iim*jjm,llm+1) |
---|
295 | REAL(rstd),INTENT(IN) :: W(iim*jjm,llm+1) |
---|
296 | REAL(rstd),INTENT(IN) :: wflux(iim*jjm,llm+1) |
---|
297 | REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm) |
---|
298 | REAL(rstd),INTENT(INOUT) :: dPhi(iim*jjm,llm+1) |
---|
299 | REAL(rstd),INTENT(INOUT) :: dW(iim*jjm,llm+1) |
---|
300 | REAL(rstd) :: W_etadot(iim*jjm,llm) ! vertical flux of vertical momentum |
---|
301 | ! local arrays |
---|
302 | REAL(rstd) :: eta_dot(iim*jjm, llm) ! eta_dot in full layers |
---|
303 | REAL(rstd) :: wcov(iim*jjm,llm) ! covariant vertical momentum in full layers |
---|
304 | ! indices and temporary values |
---|
305 | INTEGER :: ij, l |
---|
306 | REAL(rstd) :: wflux_ij, w_ij |
---|
307 | |
---|
308 | CALL trace_start("compute_caldyn_vert_nh") |
---|
309 | |
---|
310 | IF(dysl) THEN |
---|
311 | !$OMP BARRIER |
---|
312 | #include "../kernels/caldyn_vert_NH.k90" |
---|
313 | !$OMP BARRIER |
---|
314 | ELSE |
---|
315 | #define ETA_DOT(ij) eta_dot(ij,1) |
---|
316 | #define WCOV(ij) wcov(ij,1) |
---|
317 | |
---|
318 | DO l=ll_begin,ll_end |
---|
319 | ! compute the local arrays |
---|
320 | !DIR$ SIMD |
---|
321 | DO ij=ij_begin_ext,ij_end_ext |
---|
322 | wflux_ij = .5*(wflux(ij,l)+wflux(ij,l+1)) |
---|
323 | w_ij = .5*(W(ij,l)+W(ij,l+1))/mass(ij,l) |
---|
324 | W_etadot(ij,l) = wflux_ij*w_ij |
---|
325 | ETA_DOT(ij) = wflux_ij / mass(ij,l) |
---|
326 | WCOV(ij) = w_ij*(geopot(ij,l+1)-geopot(ij,l)) |
---|
327 | ENDDO |
---|
328 | ! add NH term to du |
---|
329 | !DIR$ SIMD |
---|
330 | DO ij=ij_begin,ij_end |
---|
331 | du(ij+u_right,l) = du(ij+u_right,l) & |
---|
332 | - .5*(WCOV(ij+t_right)+WCOV(ij)) & |
---|
333 | *ne_right*(ETA_DOT(ij+t_right)-ETA_DOT(ij)) |
---|
334 | du(ij+u_lup,l) = du(ij+u_lup,l) & |
---|
335 | - .5*(WCOV(ij+t_lup)+WCOV(ij)) & |
---|
336 | *ne_lup*(ETA_DOT(ij+t_lup)-ETA_DOT(ij)) |
---|
337 | du(ij+u_ldown,l) = du(ij+u_ldown,l) & |
---|
338 | - .5*(WCOV(ij+t_ldown)+WCOV(ij)) & |
---|
339 | *ne_ldown*(ETA_DOT(ij+t_ldown)-ETA_DOT(ij)) |
---|
340 | END DO |
---|
341 | ENDDO |
---|
342 | ! add NH terms to dW, dPhi |
---|
343 | ! FIXME : TODO top and bottom |
---|
344 | DO l=ll_beginp1,ll_end ! inner interfaces only |
---|
345 | !DIR$ SIMD |
---|
346 | DO ij=ij_begin,ij_end |
---|
347 | dPhi(ij,l) = dPhi(ij,l) - wflux(ij,l) & |
---|
348 | * (geopot(ij,l+1)-geopot(ij,l-1))/(mass(ij,l-1)+mass(ij,l)) |
---|
349 | END DO |
---|
350 | END DO |
---|
351 | DO l=ll_begin,ll_end |
---|
352 | !DIR$ SIMD |
---|
353 | DO ij=ij_begin,ij_end |
---|
354 | dW(ij,l+1) = dW(ij,l+1) + W_etadot(ij,l) ! update inner+top interfaces |
---|
355 | dW(ij,l) = dW(ij,l) - W_etadot(ij,l) ! update bottom+inner interfaces |
---|
356 | END DO |
---|
357 | END DO |
---|
358 | |
---|
359 | #undef ETA_DOT |
---|
360 | #undef WCOV |
---|
361 | |
---|
362 | END IF ! dysl |
---|
363 | CALL trace_end("compute_caldyn_vert_nh") |
---|
364 | |
---|
365 | END SUBROUTINE compute_caldyn_vert_NH |
---|
366 | END MODULE caldyn_kernels_base_mod |
---|