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