PageRenderTime 58ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 1ms

/wrfv2_fire/dyn_em/module_diffusion_em.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 6015 lines | 3731 code | 1233 blank | 1051 comment | 10 complexity | 4a8d72e31f9f2c2d1120d5720275b558 MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. ! WRF:MODEL_LAYER:PHYSICS
  2. MODULE module_diffusion_em
  3. USE module_bc, only: set_physical_bc3d
  4. USE module_state_description, only: p_m23, p_m13, p_m22, p_m33, p_r23, p_r13, p_r12, p_m12, p_m11
  5. USE module_big_step_utilities_em, only: grid_config_rec_type, param_first_scalar, p_qv, p_qi, p_qc
  6. USE module_model_constants
  7. CONTAINS
  8. !=======================================================================
  9. !=======================================================================
  10. SUBROUTINE cal_deform_and_div( config_flags, u, v, w, div, &
  11. defor11, defor22, defor33, &
  12. defor12, defor13, defor23, &
  13. nba_rij, n_nba_rij, & !JDM
  14. u_base, v_base, msfux, msfuy, &
  15. msfvx, msfvy, msftx, msfty, &
  16. rdx, rdy, dn, dnw, rdz, rdzw, &
  17. fnm, fnp, cf1, cf2, cf3, zx, zy, &
  18. ids, ide, jds, jde, kds, kde, &
  19. ims, ime, jms, jme, kms, kme, &
  20. its, ite, jts, jte, kts, kte )
  21. ! History: Sep 2003 Changes by Jason Knievel and George Bryan, NCAR
  22. ! Oct 2001 Converted to mass core by Bill Skamarock, NCAR
  23. ! ... ...
  24. ! Purpose: This routine calculates deformation and 3-d divergence.
  25. ! References: Klemp and Wilhelmson (JAS 1978)
  26. ! Chen and Dudhia (NCAR WRF physics report 2000)
  27. !-----------------------------------------------------------------------
  28. ! Comments 10-MAR-05
  29. ! Equations 13a-f, Chen and Dudhia 2000, Appendix A:
  30. ! Eqn 13a: D11=defor11= 2m^2 * (partial du^/dX + partial dpsi/dx * partial du^/dpsi)
  31. ! Eqn 13b: D22=defor22= 2m^2 * (partial dv^/dY + partial dpsi/dy * partial dv^/dpsi)
  32. ! Eqn 13c: D33=defor33= 2 * partial dw/dz [SIMPLER FORM]
  33. ! Eqn 13d: D12=defor12= m^2 * (partial dv^/dX + partial du^/dY +
  34. ! partial dpsi/dx * partial dv^/dpsi +
  35. ! partial dpsi/dy * partial du^/dpsi)
  36. ! Eqn 13e: D13=defor13= m^2 * (partial dw^/dX + partial dpsi/dx * partial dw^/dpsi)
  37. ! + partial du/dz [SIMPLER FORM]
  38. ! Eqn 13f: D23=defor23= m^2 * (partial dw^/dY + partial dpsi/dy * partial dw^/dpsi)
  39. ! + partial dv/dz [SIMPLER FORM]
  40. !-----------------------------------------------------------------------
  41. ! Begin declarations.
  42. IMPLICIT NONE
  43. TYPE( grid_config_rec_type ), INTENT( IN ) &
  44. :: config_flags
  45. INTEGER, INTENT( IN ) &
  46. :: ids, ide, jds, jde, kds, kde, &
  47. ims, ime, jms, jme, kms, kme, &
  48. its, ite, jts, jte, kts, kte
  49. REAL, INTENT( IN ) &
  50. :: rdx, rdy, cf1, cf2, cf3
  51. REAL, DIMENSION( kms:kme ), INTENT( IN ) &
  52. :: fnm, fnp, dn, dnw, u_base, v_base
  53. REAL, DIMENSION( ims:ime , jms:jme ), INTENT( IN ) &
  54. :: msfux, msfuy, msfvx, msfvy, msftx, msfty
  55. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( IN ) &
  56. :: u, v, w, zx, zy, rdz, rdzw
  57. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( INOUT ) &
  58. :: defor11, defor22, defor33, defor12, defor13, defor23, div
  59. INTEGER, INTENT( IN ) :: n_nba_rij !JDM
  60. REAL , DIMENSION(ims:ime, kms:kme, jms:jme, n_nba_rij), INTENT(INOUT) & !JDM
  61. :: nba_rij
  62. ! Local variables.
  63. INTEGER &
  64. :: i, j, k, ktf, ktes1, ktes2, i_start, i_end, j_start, j_end
  65. REAL &
  66. :: tmp, tmpzx, tmpzy, tmpzeta_z, cft1, cft2
  67. REAL, DIMENSION( its:ite, jts:jte ) &
  68. :: mm, zzavg, zeta_zd12
  69. REAL, DIMENSION( its-2:ite+2, kts:kte, jts-2:jte+2 ) &
  70. :: tmp1, hat, hatavg
  71. ! End declarations.
  72. !-----------------------------------------------------------------------
  73. ! Comments 10-MAR-2005
  74. ! Treat all differentials as 'div-style' [or 'curl-style'],
  75. ! i.e., du/dX becomes (in map coordinate space) mx*my * d(u/my)/dx,
  76. ! NB - all equations referred to here are from Chen and Dudhia 2002, from the
  77. ! WRF physics documents web pages:
  78. ! http://www.mmm.ucar.edu/wrf/users/docs/wrf-doc-physics.pdf
  79. !=======================================================================
  80. ! In the following section, calculate 3-d divergence and the first three
  81. ! (defor11, defor22, defor33) of six deformation terms.
  82. ktes1 = kte-1
  83. ktes2 = kte-2
  84. cft2 = - 0.5 * dnw(ktes1) / dn(ktes1)
  85. cft1 = 1.0 - cft2
  86. ktf = MIN( kte, kde-1 )
  87. i_start = its
  88. i_end = MIN( ite, ide-1 )
  89. j_start = jts
  90. j_end = MIN( jte, jde-1 )
  91. ! Square the map scale factor.
  92. DO j = j_start, j_end
  93. DO i = i_start, i_end
  94. mm(i,j) = msftx(i,j) * msfty(i,j)
  95. END DO
  96. END DO
  97. !-----------------------------------------------------------------------
  98. ! Calculate du/dx.
  99. ! Apply a coordinate transformation to zonal velocity, u.
  100. DO j = j_start, j_end
  101. DO k = kts, ktf
  102. DO i = i_start, i_end+1
  103. hat(i,k,j) = u(i,k,j) / msfuy(i,j)
  104. END DO
  105. END DO
  106. END DO
  107. ! Average in x and z.
  108. DO j=j_start,j_end
  109. DO k=kts+1,ktf
  110. DO i=i_start,i_end
  111. hatavg(i,k,j) = 0.5 * &
  112. ( fnm(k) * ( hat(i,k ,j) + hat(i+1, k,j) ) + &
  113. fnp(k) * ( hat(i,k-1,j) + hat(i+1,k-1,j) ) )
  114. END DO
  115. END DO
  116. END DO
  117. ! Extrapolate to top and bottom of domain (to w levels).
  118. DO j = j_start, j_end
  119. DO i = i_start, i_end
  120. hatavg(i,1,j) = 0.5 * ( &
  121. cf1 * hat(i ,1,j) + &
  122. cf2 * hat(i ,2,j) + &
  123. cf3 * hat(i ,3,j) + &
  124. cf1 * hat(i+1,1,j) + &
  125. cf2 * hat(i+1,2,j) + &
  126. cf3 * hat(i+1,3,j) )
  127. hatavg(i,kte,j) = 0.5 * ( &
  128. cft1 * ( hat(i,ktes1,j) + hat(i+1,ktes1,j) ) + &
  129. cft2 * ( hat(i,ktes2,j) + hat(i+1,ktes2,j) ) )
  130. END DO
  131. END DO
  132. ! Comments 10-MAR-05
  133. ! Eqn 13a: D11=defor11= 2m^2 * (partial du^/dX + partial dpsi/dx * partial du^/dpsi)
  134. ! Below, D11 is set = 2*tmp1
  135. ! => tmp1 = m^2 * (partial du^/dX + partial dpsi/dx * partial du^/dpsi)
  136. ! tmpzx = averaged value of dpsi/dx (=zx)
  137. DO j = j_start, j_end
  138. DO k = kts, ktf
  139. DO i = i_start, i_end
  140. tmpzx = 0.25 * ( &
  141. zx(i,k ,j) + zx(i+1,k ,j) + &
  142. zx(i,k+1,j) + zx(i+1,k+1,j) )
  143. tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) *tmpzx * rdzw(i,k,j)
  144. ! tmp1 to here = partial dpsi/dx * partial du^/dpsi:
  145. END DO
  146. END DO
  147. END DO
  148. DO j = j_start, j_end
  149. DO k = kts, ktf
  150. DO i = i_start, i_end
  151. tmp1(i,k,j) = mm(i,j) * ( rdx * ( hat(i+1,k,j) - hat(i,k,j) ) - &
  152. tmp1(i,k,j))
  153. END DO
  154. END DO
  155. END DO
  156. ! End calculation of du/dx.
  157. !-----------------------------------------------------------------------
  158. !-----------------------------------------------------------------------
  159. ! Calculate defor11 (2*du/dx).
  160. ! Comments 10-MAR-05
  161. ! Eqn 13a: D11=defor11= 2 m^2 * (partial du^/dX + partial dpsi/dx * partial du^/dpsi)
  162. ! = 2*tmp1
  163. DO j = j_start, j_end
  164. DO k = kts, ktf
  165. DO i = i_start, i_end
  166. defor11(i,k,j) = 2.0 * tmp1(i,k,j)
  167. END DO
  168. END DO
  169. END DO
  170. ! End calculation of defor11.
  171. !-----------------------------------------------------------------------
  172. !-----------------------------------------------------------------------
  173. ! Calculate zonal divergence (du/dx) and add it to the divergence array.
  174. DO j = j_start, j_end
  175. DO k = kts, ktf
  176. DO i = i_start, i_end
  177. div(i,k,j) = tmp1(i,k,j)
  178. END DO
  179. END DO
  180. END DO
  181. ! End calculation of zonal divergence.
  182. !-----------------------------------------------------------------------
  183. !-----------------------------------------------------------------------
  184. ! Calculate dv/dy.
  185. ! Apply a coordinate transformation to meridional velocity, v.
  186. DO j = j_start, j_end+1
  187. DO k = kts, ktf
  188. DO i = i_start, i_end
  189. ! Because msfvx at the poles will be undefined (1./0.), we will have
  190. ! trouble. But we are OK since v at the poles is 0., and that takes
  191. ! precedence in this case.
  192. IF ((config_flags%polar) .AND. ((j == jds) .OR. (j == jde))) THEN
  193. hat(i,k,j) = 0.
  194. ELSE ! normal code
  195. hat(i,k,j) = v(i,k,j) / msfvx(i,j)
  196. ENDIF
  197. END DO
  198. END DO
  199. END DO
  200. ! Account for the slope in y of eta surfaces.
  201. DO j=j_start,j_end
  202. DO k=kts+1,ktf
  203. DO i=i_start,i_end
  204. hatavg(i,k,j) = 0.5 * ( &
  205. fnm(k) * ( hat(i,k ,j) + hat(i,k ,j+1) ) + &
  206. fnp(k) * ( hat(i,k-1,j) + hat(i,k-1,j+1) ) )
  207. END DO
  208. END DO
  209. END DO
  210. ! Extrapolate to top and bottom of domain (to w levels).
  211. DO j = j_start, j_end
  212. DO i = i_start, i_end
  213. hatavg(i,1,j) = 0.5 * ( &
  214. cf1 * hat(i,1,j ) + &
  215. cf2 * hat(i,2,j ) + &
  216. cf3 * hat(i,3,j ) + &
  217. cf1 * hat(i,1,j+1) + &
  218. cf2 * hat(i,2,j+1) + &
  219. cf3 * hat(i,3,j+1) )
  220. hatavg(i,kte,j) = 0.5 * ( &
  221. cft1 * ( hat(i,ktes1,j) + hat(i,ktes1,j+1) ) + &
  222. cft2 * ( hat(i,ktes2,j) + hat(i,ktes2,j+1) ) )
  223. END DO
  224. END DO
  225. ! Comments 10-MAR-05
  226. ! Eqn 13b: D22=defor22= 2m^2 * (partial dv^/dY + partial dpsi/dy * partial dv^/dpsi)
  227. ! Below, D22 is set = 2*tmp1
  228. ! => tmp1 = m^2 * (partial dv^/dY + partial dpsi/dy * partial dv^/dpsi)
  229. ! tmpzy = averaged value of dpsi/dy (=zy)
  230. DO j = j_start, j_end
  231. DO k = kts, ktf
  232. DO i = i_start, i_end
  233. tmpzy = 0.25 * ( &
  234. zy(i,k ,j) + zy(i,k ,j+1) + &
  235. zy(i,k+1,j) + zy(i,k+1,j+1) )
  236. tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * tmpzy * rdzw(i,k,j)
  237. ! tmp1 to here = partial dpsi/dy * partial dv^/dpsi:
  238. END DO
  239. END DO
  240. END DO
  241. DO j = j_start, j_end
  242. DO k = kts, ktf
  243. DO i = i_start, i_end
  244. tmp1(i,k,j) = mm(i,j) * ( &
  245. rdy * ( hat(i,k,j+1) - hat(i,k,j) ) - tmp1(i,k,j) )
  246. END DO
  247. END DO
  248. END DO
  249. ! End calculation of dv/dy.
  250. !-----------------------------------------------------------------------
  251. !-----------------------------------------------------------------------
  252. ! Calculate defor22 (2*dv/dy).
  253. ! Comments 10-MAR-05
  254. ! Eqn 13b: D22=defor22= 2 m^2 * (partial dv^/dY + partial dpsi/dy * partial dv^/dpsi)
  255. ! = 2*tmp1
  256. DO j = j_start, j_end
  257. DO k = kts, ktf
  258. DO i = i_start, i_end
  259. defor22(i,k,j) = 2.0 * tmp1(i,k,j)
  260. END DO
  261. END DO
  262. END DO
  263. ! End calculation of defor22.
  264. !-----------------------------------------------------------------------
  265. !-----------------------------------------------------------------------
  266. ! Calculate meridional divergence (dv/dy) and add it to the divergence
  267. ! array.
  268. DO j = j_start, j_end
  269. DO k = kts, ktf
  270. DO i = i_start, i_end
  271. div(i,k,j) = div(i,k,j) + tmp1(i,k,j)
  272. END DO
  273. END DO
  274. END DO
  275. ! End calculation of meridional divergence.
  276. !-----------------------------------------------------------------------
  277. !-----------------------------------------------------------------------
  278. ! Comments 10-MAR-05
  279. ! Eqn 13c: D33=defor33= 2 * partial dw/dz
  280. ! Below, D33 is set = 2*tmp1
  281. ! => tmp1 = partial dw/dz
  282. ! Calculate dw/dz.
  283. DO j = j_start, j_end
  284. DO k = kts, ktf
  285. DO i = i_start, i_end
  286. tmp1(i,k,j) = ( w(i,k+1,j) - w(i,k,j) ) * rdzw(i,k,j)
  287. END DO
  288. END DO
  289. END DO
  290. ! End calculation of dw/dz.
  291. !-----------------------------------------------------------------------
  292. !-----------------------------------------------------------------------
  293. ! Calculate defor33 (2*dw/dz).
  294. DO j = j_start, j_end
  295. DO k = kts, ktf
  296. DO i = i_start, i_end
  297. defor33(i,k,j) = 2.0 * tmp1(i,k,j)
  298. END DO
  299. END DO
  300. END DO
  301. ! End calculation of defor33.
  302. !-----------------------------------------------------------------------
  303. !-----------------------------------------------------------------------
  304. ! Calculate vertical divergence (dw/dz) and add it to the divergence
  305. ! array.
  306. DO j = j_start, j_end
  307. DO k = kts, ktf
  308. DO i = i_start, i_end
  309. div(i,k,j) = div(i,k,j) + tmp1(i,k,j)
  310. END DO
  311. END DO
  312. END DO
  313. ! End calculation of vertical divergence.
  314. !-----------------------------------------------------------------------
  315. ! Three-dimensional divergence is now finished and values are in array
  316. ! "div." Also, the first three (defor11, defor22, defor33) of six
  317. ! deformation terms are now calculated at pressure points.
  318. !=======================================================================
  319. ! Comments 10-MAR-2005
  320. ! Treat all differentials as 'div-style' [or 'curl-style'],
  321. ! i.e., du/dY becomes (in map coordinate space) mx*my * d(u/mx)/dy,
  322. ! dv/dX becomes (in map coordinate space) mx*my * d(v/my)/dx,
  323. ! (see e.g. Haltiner and Williams p. 441)
  324. !=======================================================================
  325. ! Calculate the final three deformations (defor12, defor13, defor23) at
  326. ! vorticity points.
  327. i_start = its
  328. i_end = ite
  329. j_start = jts
  330. j_end = jte
  331. IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
  332. config_flags%nested) i_start = MAX( ids+1, its )
  333. IF ( config_flags%open_xe .OR. config_flags%specified .OR. &
  334. config_flags%nested) i_end = MIN( ide-1, ite )
  335. IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
  336. config_flags%nested) j_start = MAX( jds+1, jts )
  337. IF ( config_flags%open_ye .OR. config_flags%specified .OR. &
  338. config_flags%nested) j_end = MIN( jde-1, jte )
  339. IF ( config_flags%periodic_x ) i_start = its
  340. IF ( config_flags%periodic_x ) i_end = ite
  341. !-----------------------------------------------------------------------
  342. ! Calculate du/dy.
  343. ! First, calculate an average mapscale factor.
  344. ! Comments 10-MAR-05
  345. ! du/dy => need u map scale factor in x (which is defined at u points)
  346. ! averaged over j and j-1
  347. ! dv/dx => need v map scale factor in y (which is defined at v points)
  348. ! averaged over i and i-1
  349. DO j = j_start, j_end
  350. DO i = i_start, i_end
  351. mm(i,j) = 0.25 * ( msfux(i,j-1) + msfux(i,j) ) * ( msfvy(i-1,j) + msfvy(i,j) )
  352. END DO
  353. END DO
  354. ! Apply a coordinate transformation to zonal velocity, u.
  355. DO j =j_start-1, j_end
  356. DO k =kts, ktf
  357. DO i =i_start, i_end
  358. ! Fixes to set_physical_bc2/3d for polar boundary conditions
  359. ! remove issues with loop over j
  360. hat(i,k,j) = u(i,k,j) / msfux(i,j)
  361. END DO
  362. END DO
  363. END DO
  364. ! Average in y and z.
  365. DO j=j_start,j_end
  366. DO k=kts+1,ktf
  367. DO i=i_start,i_end
  368. hatavg(i,k,j) = 0.5 * ( &
  369. fnm(k) * ( hat(i,k ,j-1) + hat(i,k ,j) ) + &
  370. fnp(k) * ( hat(i,k-1,j-1) + hat(i,k-1,j) ) )
  371. END DO
  372. END DO
  373. END DO
  374. ! Extrapolate to top and bottom of domain (to w levels).
  375. DO j = j_start, j_end
  376. DO i = i_start, i_end
  377. hatavg(i,1,j) = 0.5 * ( &
  378. cf1 * hat(i,1,j-1) + &
  379. cf2 * hat(i,2,j-1) + &
  380. cf3 * hat(i,3,j-1) + &
  381. cf1 * hat(i,1,j ) + &
  382. cf2 * hat(i,2,j ) + &
  383. cf3 * hat(i,3,j ) )
  384. hatavg(i,kte,j) = 0.5 * ( &
  385. cft1 * ( hat(i,ktes1,j-1) + hat(i,ktes1,j) ) + &
  386. cft2 * ( hat(i,ktes2,j-1) + hat(i,ktes2,j) ) )
  387. END DO
  388. END DO
  389. ! tmpzy = averaged value of dpsi/dy (=zy) on vorticity grid
  390. ! tmp1 = partial dpsi/dy * partial du^/dpsi
  391. DO j = j_start, j_end
  392. DO k = kts, ktf
  393. DO i = i_start, i_end
  394. tmpzy = 0.25 * ( &
  395. zy(i-1,k ,j) + zy(i,k ,j) + &
  396. zy(i-1,k+1,j) + zy(i,k+1,j) )
  397. tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * &
  398. 0.25 * tmpzy * ( rdzw(i,k,j) + rdzw(i-1,k,j) + &
  399. rdzw(i-1,k,j-1) + rdzw(i,k,j-1) )
  400. END DO
  401. END DO
  402. END DO
  403. ! End calculation of du/dy.
  404. !----------------------------------------------------------------------
  405. !-----------------------------------------------------------------------
  406. ! Add the first term to defor12 (du/dy+dv/dx) at vorticity points.
  407. ! Comments 10-MAR-05
  408. ! Eqn 13d: D12=defor12= m^2 * (partial dv^/dX + partial du^/dY +
  409. ! partial dpsi/dx * partial dv^/dpsi +
  410. ! partial dpsi/dy * partial du^/dpsi)
  411. ! Here deal with m^2 * (partial du^/dY + partial dpsi/dy * partial du^/dpsi)
  412. ! Still need to add v^ terms:
  413. ! m^2 * (partial dv^/dX + partial dpsi/dx * partial dv^/dpsi)
  414. DO j = j_start, j_end
  415. DO k = kts, ktf
  416. DO i = i_start, i_end
  417. defor12(i,k,j) = mm(i,j) * ( &
  418. rdy * ( hat(i,k,j) - hat(i,k,j-1) ) - tmp1(i,k,j) )
  419. END DO
  420. END DO
  421. END DO
  422. ! End addition of the first term to defor12.
  423. !-----------------------------------------------------------------------
  424. !-----------------------------------------------------------------------
  425. ! Calculate dv/dx.
  426. ! Apply a coordinate transformation to meridional velocity, v.
  427. DO j = j_start, j_end
  428. DO k = kts, ktf
  429. DO i = i_start-1, i_end
  430. hat(i,k,j) = v(i,k,j) / msfvy(i,j)
  431. END DO
  432. END DO
  433. END DO
  434. ! Account for the slope in x of eta surfaces.
  435. DO j = j_start, j_end
  436. DO k = kts+1, ktf
  437. DO i = i_start, i_end
  438. hatavg(i,k,j) = 0.5 * ( &
  439. fnm(k) * ( hat(i-1,k ,j) + hat(i,k ,j) ) + &
  440. fnp(k) * ( hat(i-1,k-1,j) + hat(i,k-1,j) ) )
  441. END DO
  442. END DO
  443. END DO
  444. ! Extrapolate to top and bottom of domain (to w levels).
  445. DO j = j_start, j_end
  446. DO i = i_start, i_end
  447. hatavg(i,1,j) = 0.5 * ( &
  448. cf1 * hat(i-1,1,j) + &
  449. cf2 * hat(i-1,2,j) + &
  450. cf3 * hat(i-1,3,j) + &
  451. cf1 * hat(i ,1,j) + &
  452. cf2 * hat(i ,2,j) + &
  453. cf3 * hat(i ,3,j) )
  454. hatavg(i,kte,j) = 0.5 * ( &
  455. cft1 * ( hat(i,ktes1,j) + hat(i-1,ktes1,j) ) + &
  456. cft2 * ( hat(i,ktes2,j) + hat(i-1,ktes2,j) ) )
  457. END DO
  458. END DO
  459. ! Fixes to set_physical_bc2/3d have made any check for polar B.C.'s
  460. ! unnecessary in this place. zx, rdzw, and hatavg are all defined
  461. ! in places they need to be and the values at the poles are replications
  462. ! of the values one grid point in, so the averaging over j and j-1 works
  463. ! to act as just using the value at j or j-1 (with out extra code).
  464. !
  465. ! tmpzx = averaged value of dpsi/dx (=zx) on vorticity grid
  466. ! tmp1 = partial dpsi/dx * partial dv^/dpsi
  467. DO j = j_start, j_end
  468. DO k = kts, ktf
  469. DO i = i_start, i_end
  470. tmpzx = 0.25 * ( &
  471. zx(i,k ,j-1) + zx(i,k ,j) + &
  472. zx(i,k+1,j-1) + zx(i,k+1,j) )
  473. tmp1(i,k,j) = ( hatavg(i,k+1,j) - hatavg(i,k,j) ) * &
  474. 0.25 * tmpzx * ( rdzw(i,k,j) + rdzw(i,k,j-1) + &
  475. rdzw(i-1,k,j-1) + rdzw(i-1,k,j) )
  476. END DO
  477. END DO
  478. END DO
  479. ! End calculation of dv/dx.
  480. !-----------------------------------------------------------------------
  481. !-----------------------------------------------------------------------
  482. ! Add the second term to defor12 (du/dy+dv/dx) at vorticity points.
  483. ! Comments 10-MAR-05
  484. ! Eqn 13d: D12=defor12= m^2 * (partial dv^/dX + partial du^/dY +
  485. ! partial dpsi/dx * partial dv^/dpsi +
  486. ! partial dpsi/dy * partial du^/dpsi)
  487. ! Here adding v^ terms:
  488. ! m^2 * (partial dv^/dX + partial dpsi/dx * partial dv^/dpsi)
  489. IF ( config_flags%sfs_opt .GT. 0 ) THEN ! NBA--
  490. !JDM____________________________________________________________________
  491. !
  492. ! s12 = du/dy + dv/dx
  493. ! = (du/dy - dz/dy*du/dz) + (dv/dx - dz/dx*dv/dz)
  494. ! ______defor12______ ___tmp1___
  495. !
  496. ! r12 = du/dy - dv/dx
  497. ! = (du/dy - dz/dy*du/dz) - (dv/dx - dz/dx*dv/dz)
  498. ! ______defor12______ ___tmp1___
  499. !_______________________________________________________________________
  500. DO j = j_start, j_end
  501. DO k = kts, ktf
  502. DO i = i_start, i_end
  503. nba_rij(i,k,j,P_r12) = defor12(i,k,j) - &
  504. mm(i,j) * ( &
  505. rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
  506. defor12(i,k,j) = defor12(i,k,j) + &
  507. mm(i,j) * ( &
  508. rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
  509. END DO
  510. END DO
  511. END DO
  512. ! End addition of the second term to defor12.
  513. !-----------------------------------------------------------------------
  514. !-----------------------------------------------------------------------
  515. ! Update the boundary for defor12 (might need to change later).
  516. IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
  517. DO j = jts, jte
  518. DO k = kts, kte
  519. defor12(ids,k,j) = defor12(ids+1,k,j)
  520. nba_rij(ids,k,j,P_r12) = nba_rij(ids+1,k,j,P_r12)
  521. END DO
  522. END DO
  523. END IF
  524. IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
  525. DO k = kts, kte
  526. DO i = its, ite
  527. defor12(i,k,jds) = defor12(i,k,jds+1)
  528. nba_rij(i,k,jds,P_r12) = nba_rij(i,k,jds+1,P_r12)
  529. END DO
  530. END DO
  531. END IF
  532. IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
  533. DO j = jts, jte
  534. DO k = kts, kte
  535. defor12(ide,k,j) = defor12(ide-1,k,j)
  536. nba_rij(ide,k,j,P_r12) = nba_rij(ide-1,k,j,P_r12)
  537. END DO
  538. END DO
  539. END IF
  540. IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
  541. DO k = kts, kte
  542. DO i = its, ite
  543. defor12(i,k,jde) = defor12(i,k,jde-1)
  544. nba_rij(i,k,jde,P_r12) = nba_rij(i,k,jde-1,P_r12)
  545. END DO
  546. END DO
  547. END IF
  548. ELSE ! NOT NBA--------------------------------------------------------
  549. DO j = j_start, j_end
  550. DO k = kts, ktf
  551. DO i = i_start, i_end
  552. defor12(i,k,j) = defor12(i,k,j) + &
  553. mm(i,j) * ( &
  554. rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
  555. END DO
  556. END DO
  557. END DO
  558. ! End addition of the second term to defor12.
  559. !-----------------------------------------------------------------------
  560. !-----------------------------------------------------------------------
  561. ! Update the boundary for defor12 (might need to change later).
  562. IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1 ) THEN
  563. DO j = jts, jte
  564. DO k = kts, kte
  565. defor12(ids,k,j) = defor12(ids+1,k,j)
  566. END DO
  567. END DO
  568. END IF
  569. IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
  570. DO k = kts, kte
  571. DO i = its, ite
  572. defor12(i,k,jds) = defor12(i,k,jds+1)
  573. END DO
  574. END DO
  575. END IF
  576. IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
  577. DO j = jts, jte
  578. DO k = kts, kte
  579. defor12(ide,k,j) = defor12(ide-1,k,j)
  580. END DO
  581. END DO
  582. END IF
  583. IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
  584. DO k = kts, kte
  585. DO i = its, ite
  586. defor12(i,k,jde) = defor12(i,k,jde-1)
  587. END DO
  588. END DO
  589. END IF
  590. ENDIF ! NBA-----------------------------------------------------------
  591. ! End update of boundary for defor12.
  592. !-----------------------------------------------------------------------
  593. ! Comments 10-MAR-05
  594. ! Further deformation terms not needed for 2-dimensional Smagorinsky diffusion,
  595. ! so those terms have not been dealt with yet.
  596. ! A "y" has simply been added to all map scale factors to allow the model to
  597. ! compile without errors.
  598. !-----------------------------------------------------------------------
  599. ! Calculate dw/dx.
  600. i_start = its
  601. i_end = MIN( ite, ide-1 )
  602. j_start = jts
  603. j_end = MIN( jte, jde-1 )
  604. IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
  605. config_flags%nested) i_start = MAX( ids+1, its )
  606. IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
  607. config_flags%nested) j_start = MAX( jds+1, jts )
  608. IF ( config_flags%periodic_x ) i_start = its
  609. IF ( config_flags%periodic_x ) i_end = MIN( ite, ide )
  610. IF ( config_flags%periodic_y ) j_end = MIN( jte, jde )
  611. ! Square the mapscale factor.
  612. DO j = jts, jte
  613. DO i = its, ite
  614. mm(i,j) = msfux(i,j) * msfuy(i,j)
  615. END DO
  616. END DO
  617. ! Apply a coordinate transformation to vertical velocity, w. This is for both
  618. ! defor13 and defor23.
  619. DO j = j_start, j_end
  620. DO k = kts, kte
  621. DO i = i_start, i_end
  622. hat(i,k,j) = w(i,k,j) / msfty(i,j)
  623. END DO
  624. END DO
  625. END DO
  626. i = i_start-1
  627. DO j = j_start, MIN( jte, jde-1 )
  628. DO k = kts, kte
  629. hat(i,k,j) = w(i,k,j) / msfty(i,j)
  630. END DO
  631. END DO
  632. j = j_start-1
  633. DO k = kts, kte
  634. DO i = i_start, MIN( ite, ide-1 )
  635. hat(i,k,j) = w(i,k,j) / msfty(i,j)
  636. END DO
  637. END DO
  638. ! QUESTION: What is this for?
  639. DO j = j_start, j_end
  640. DO k = kts, ktf
  641. DO i = i_start, i_end
  642. hatavg(i,k,j) = 0.25 * ( &
  643. hat(i ,k ,j) + &
  644. hat(i ,k+1,j) + &
  645. hat(i-1,k ,j) + &
  646. hat(i-1,k+1,j) )
  647. END DO
  648. END DO
  649. END DO
  650. ! Calculate dw/dx.
  651. DO j = j_start, j_end
  652. DO k = kts+1, ktf
  653. DO i = i_start, i_end
  654. tmp1(i,k,j) = ( hatavg(i,k,j) - hatavg(i,k-1,j) ) * zx(i,k,j) * &
  655. 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
  656. END DO
  657. END DO
  658. END DO
  659. ! End calculation of dw/dx.
  660. !-----------------------------------------------------------------------
  661. !-----------------------------------------------------------------------
  662. ! Add the first term (dw/dx) to defor13 (dw/dx+du/dz) at vorticity
  663. ! points.
  664. DO j = j_start, j_end
  665. DO k = kts+1, ktf
  666. DO i = i_start, i_end
  667. defor13(i,k,j) = mm(i,j) * ( &
  668. rdx * ( hat(i,k,j) - hat(i-1,k,j) ) - tmp1(i,k,j) )
  669. END DO
  670. END DO
  671. END DO
  672. DO j = j_start, j_end
  673. DO i = i_start, i_end
  674. defor13(i,kts,j ) = 0.0
  675. defor13(i,ktf+1,j) = 0.0
  676. END DO
  677. END DO
  678. ! End addition of the first term to defor13.
  679. !-----------------------------------------------------------------------
  680. !-----------------------------------------------------------------------
  681. ! Calculate du/dz.
  682. IF ( config_flags%mix_full_fields ) THEN
  683. DO j = j_start, j_end
  684. DO k = kts+1, ktf
  685. DO i = i_start, i_end
  686. tmp1(i,k,j) = ( u(i,k,j) - u(i,k-1,j) ) * &
  687. 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
  688. END DO
  689. END DO
  690. END DO
  691. ELSE
  692. DO j = j_start, j_end
  693. DO k = kts+1, ktf
  694. DO i = i_start, i_end
  695. tmp1(i,k,j) = ( u(i,k,j) - u_base(k) - u(i,k-1,j) + u_base(k-1) ) * &
  696. 0.5 * ( rdz(i,k,j) + rdz(i-1,k,j) )
  697. END DO
  698. END DO
  699. END DO
  700. END IF
  701. !-----------------------------------------------------------------------
  702. ! Add the second term (du/dz) to defor13 (dw/dx+du/dz) at vorticity
  703. ! points.
  704. IF ( config_flags%sfs_opt .GT. 0 ) THEN ! NBA--
  705. !JDM____________________________________________________________________
  706. !
  707. ! s13 = du/dz + dw/dx
  708. ! = du/dz + (dw/dx - dz/dx*dw/dz)
  709. ! = tmp1 + ______defor13______
  710. !
  711. ! r13 = du/dz - dw/dx
  712. ! = du/dz - (dw/dx - dz/dx*dw/dz)
  713. ! = tmp1 - ______defor13______
  714. !_______________________________________________________________________
  715. DO j = j_start, j_end
  716. DO k = kts+1, ktf
  717. DO i = i_start, i_end
  718. nba_rij(i,k,j,P_r13) = tmp1(i,k,j) - defor13(i,k,j)
  719. defor13(i,k,j) = defor13(i,k,j) + tmp1(i,k,j)
  720. END DO
  721. END DO
  722. END DO
  723. DO j = j_start, j_end !change for different surface B. C.
  724. DO i = i_start, i_end
  725. nba_rij(i,kts ,j,P_r13) = 0.0
  726. nba_rij(i,ktf+1,j,P_r13) = 0.0
  727. END DO
  728. END DO
  729. ELSE ! NOT NBA--------------------------------------------------------
  730. DO j = j_start, j_end
  731. DO k = kts+1, ktf
  732. DO i = i_start, i_end
  733. defor13(i,k,j) = defor13(i,k,j) + tmp1(i,k,j)
  734. END DO
  735. END DO
  736. END DO
  737. ENDIF ! NBA-----------------------------------------------------------
  738. ! End addition of the second term to defor13.
  739. !-----------------------------------------------------------------------
  740. !-----------------------------------------------------------------------
  741. ! Calculate dw/dy.
  742. i_start = its
  743. i_end = MIN( ite, ide-1 )
  744. j_start = jts
  745. j_end = MIN( jte, jde-1 )
  746. IF ( config_flags%open_xs .OR. config_flags%specified .OR. &
  747. config_flags%nested) i_start = MAX( ids+1, its )
  748. IF ( config_flags%open_ys .OR. config_flags%specified .OR. &
  749. config_flags%nested) j_start = MAX( jds+1, jts )
  750. IF ( config_flags%periodic_y ) j_end = MIN( jte, jde )
  751. IF ( config_flags%periodic_x ) i_start = its
  752. IF ( config_flags%periodic_x ) i_end = MIN( ite, ide-1 )
  753. ! Square mapscale factor.
  754. DO j = jts, jte
  755. DO i = its, ite
  756. mm(i,j) = msfvx(i,j) * msfvy(i,j)
  757. END DO
  758. END DO
  759. ! Apply a coordinate transformation to vertical velocity, w. Added by CW 7/19/07
  760. DO j = j_start, j_end
  761. DO k = kts, kte
  762. DO i = i_start, i_end
  763. hat(i,k,j) = w(i,k,j) / msftx(i,j)
  764. END DO
  765. END DO
  766. END DO
  767. i = i_start-1
  768. DO j = j_start, MIN( jte, jde-1 )
  769. DO k = kts, kte
  770. hat(i,k,j) = w(i,k,j) / msftx(i,j)
  771. END DO
  772. END DO
  773. j = j_start-1
  774. DO k = kts, kte
  775. DO i = i_start, MIN( ite, ide-1 )
  776. hat(i,k,j) = w(i,k,j) / msftx(i,j)
  777. END DO
  778. END DO
  779. ! QUESTION: What is this for?
  780. DO j = j_start, j_end
  781. DO k = kts, ktf
  782. DO i = i_start, i_end
  783. hatavg(i,k,j) = 0.25 * ( &
  784. hat(i,k ,j ) + &
  785. hat(i,k+1,j ) + &
  786. hat(i,k ,j-1) + &
  787. hat(i,k+1,j-1) )
  788. END DO
  789. END DO
  790. END DO
  791. ! Calculate dw/dy and store in tmp1.
  792. DO j = j_start, j_end
  793. DO k = kts+1, ktf
  794. DO i = i_start, i_end
  795. tmp1(i,k,j) = ( hatavg(i,k,j) - hatavg(i,k-1,j) ) * zy(i,k,j) * &
  796. 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
  797. END DO
  798. END DO
  799. END DO
  800. ! End calculation of dw/dy.
  801. !-----------------------------------------------------------------------
  802. !-----------------------------------------------------------------------
  803. ! Add the first term (dw/dy) to defor23 (dw/dy+dv/dz) at vorticity
  804. ! points.
  805. DO j = j_start, j_end
  806. DO k = kts+1, ktf
  807. DO i = i_start, i_end
  808. defor23(i,k,j) = mm(i,j) * ( &
  809. rdy * ( hat(i,k,j) - hat(i,k,j-1) ) - tmp1(i,k,j) )
  810. END DO
  811. END DO
  812. END DO
  813. DO j = j_start, j_end
  814. DO i = i_start, i_end
  815. defor23(i,kts,j ) = 0.0
  816. defor23(i,ktf+1,j) = 0.0
  817. END DO
  818. END DO
  819. ! End addition of the first term to defor23.
  820. !-----------------------------------------------------------------------
  821. !-----------------------------------------------------------------------
  822. ! Calculate dv/dz.
  823. IF ( config_flags%mix_full_fields ) THEN
  824. DO j = j_start, j_end
  825. DO k = kts+1, ktf
  826. DO i = i_start, i_end
  827. tmp1(i,k,j) = ( v(i,k,j) - v(i,k-1,j) ) * &
  828. 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
  829. END DO
  830. END DO
  831. END DO
  832. ELSE
  833. DO j = j_start, j_end
  834. DO k = kts+1, ktf
  835. DO i = i_start, i_end
  836. tmp1(i,k,j) = ( v(i,k,j) - v_base(k) - v(i,k-1,j) + v_base(k-1) ) * &
  837. 0.5 * ( rdz(i,k,j) + rdz(i,k,j-1) )
  838. END DO
  839. END DO
  840. END DO
  841. END IF
  842. ! End calculation of dv/dz.
  843. !-----------------------------------------------------------------------
  844. !-----------------------------------------------------------------------
  845. ! Add the second term (dv/dz) to defor23 (dw/dy+dv/dz) at vorticity
  846. ! points.
  847. IF ( config_flags%sfs_opt .GT. 0 ) THEN ! NBA--
  848. !JDM___________________________________________________________________
  849. !
  850. ! s23 = dv/dz + dw/dy
  851. ! = dv/dz + (dw/dy - dz/dy*dw/dz)
  852. ! tmp1 + ______defor23______
  853. !
  854. ! r23 = dv/dz - dw/dy
  855. ! = dv/dz - (dw/dy - dz/dy*dw/dz)
  856. ! = tmp1 - ______defor23______
  857. ! Add tmp1 to defor23.
  858. DO j = j_start, j_end
  859. DO k = kts+1, ktf
  860. DO i = i_start, i_end
  861. nba_rij(i,k,j,P_r23) = tmp1(i,k,j) - defor23(i,k,j)
  862. defor23(i,k,j) = defor23(i,k,j) + tmp1(i,k,j)
  863. END DO
  864. END DO
  865. END DO
  866. DO j = j_start, j_end
  867. DO i = i_start, i_end
  868. nba_rij(i,kts ,j,P_r23) = 0.0
  869. nba_rij(i,ktf+1,j,P_r23) = 0.0
  870. END DO
  871. END DO
  872. ! End addition of the second term to defor23.
  873. !-----------------------------------------------------------------------
  874. !-----------------------------------------------------------------------
  875. ! Update the boundary for defor13 and defor23 (might need to change
  876. ! later).
  877. IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
  878. DO j = jts, jte
  879. DO k = kts, kte
  880. defor13(ids,k,j) = defor13(ids+1,k,j)
  881. defor23(ids,k,j) = defor23(ids+1,k,j)
  882. nba_rij(ids,k,j,P_r13) = nba_rij(ids+1,k,j,P_r13)
  883. nba_rij(ids,k,j,P_r23) = nba_rij(ids+1,k,j,P_r23)
  884. END DO
  885. END DO
  886. END IF
  887. IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
  888. DO k = kts, kte
  889. DO i = its, ite
  890. defor13(i,k,jds) = defor13(i,k,jds+1)
  891. defor23(i,k,jds) = defor23(i,k,jds+1)
  892. nba_rij(i,k,jds,P_r13) = nba_rij(i,k,jds+1,P_r13)
  893. nba_rij(i,k,jds,P_r23) = nba_rij(i,k,jds+1,P_r23)
  894. END DO
  895. END DO
  896. END IF
  897. IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
  898. DO j = jts, jte
  899. DO k = kts, kte
  900. defor13(ide,k,j) = defor13(ide-1,k,j)
  901. defor23(ide,k,j) = defor23(ide-1,k,j)
  902. nba_rij(ide,k,j,P_r13) = nba_rij(ide-1,k,j,P_r13)
  903. nba_rij(ide,k,j,P_r23) = nba_rij(ide-1,k,j,P_r23)
  904. END DO
  905. END DO
  906. END IF
  907. IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
  908. DO k = kts, kte
  909. DO i = its, ite
  910. defor13(i,k,jde) = defor13(i,k,jde-1)
  911. defor23(i,k,jde) = defor23(i,k,jde-1)
  912. nba_rij(i,k,jde,P_r13) = nba_rij(i,k,jde-1,P_r13)
  913. nba_rij(i,k,jde,P_r23) = nba_rij(i,k,jde-1,P_r23)
  914. END DO
  915. END DO
  916. END IF
  917. ELSE ! NOT NBA--------------------------------------------------------
  918. ! Add tmp1 to defor23.
  919. DO j = j_start, j_end
  920. DO k = kts+1, ktf
  921. DO i = i_start, i_end
  922. defor23(i,k,j) = defor23(i,k,j) + tmp1(i,k,j)
  923. END DO
  924. END DO
  925. END DO
  926. ! End addition of the second term to defor23.
  927. !-----------------------------------------------------------------------
  928. !-----------------------------------------------------------------------
  929. ! Update the boundary for defor13 and defor23 (might need to change
  930. ! later).
  931. IF ( .NOT. config_flags%periodic_x .AND. i_start .EQ. ids+1) THEN
  932. DO j = jts, jte
  933. DO k = kts, kte
  934. defor13(ids,k,j) = defor13(ids+1,k,j)
  935. defor23(ids,k,j) = defor23(ids+1,k,j)
  936. END DO
  937. END DO
  938. END IF
  939. IF ( .NOT. config_flags%periodic_y .AND. j_start .EQ. jds+1) THEN
  940. DO k = kts, kte
  941. DO i = its, ite
  942. defor13(i,k,jds) = defor13(i,k,jds+1)
  943. defor23(i,k,jds) = defor23(i,k,jds+1)
  944. END DO
  945. END DO
  946. END IF
  947. IF ( .NOT. config_flags%periodic_x .AND. i_end .EQ. ide-1) THEN
  948. DO j = jts, jte
  949. DO k = kts, kte
  950. defor13(ide,k,j) = defor13(ide-1,k,j)
  951. defor23(ide,k,j) = defor23(ide-1,k,j)
  952. END DO
  953. END DO
  954. END IF
  955. IF ( .NOT. config_flags%periodic_y .AND. j_end .EQ. jde-1) THEN
  956. DO k = kts, kte
  957. DO i = its, ite
  958. defor13(i,k,jde) = defor13(i,k,jde-1)
  959. defor23(i,k,jde) = defor23(i,k,jde-1)
  960. END DO
  961. END DO
  962. END IF
  963. ENDIF ! NBA-----------------------------------------------------------
  964. ! End update of boundary for defor13 and defor23.
  965. !-----------------------------------------------------------------------
  966. ! The second three (defor12, defor13, defor23) of six deformation terms
  967. ! are now calculated at vorticity points.
  968. !=======================================================================
  969. END SUBROUTINE cal_deform_and_div
  970. !=======================================================================
  971. !=======================================================================
  972. SUBROUTINE calculate_km_kh( config_flags, dt, &
  973. dampcoef, zdamp, damp_opt, &
  974. xkmh, xkmv, xkhh, xkhv, &
  975. BN2, khdif, kvdif, div, &
  976. defor11, defor22, defor33, &
  977. defor12, defor13, defor23, &
  978. tke, p8w, t8w, theta, t, p, moist, &
  979. dn, dnw, dx, dy, rdz, rdzw, isotropic, &
  980. n_moist, cf1, cf2, cf3, warm_rain, &
  981. mix_upper_bound, &
  982. msftx, msfty, &
  983. ids, ide, jds, jde, kds, kde, &
  984. ims, ime, jms, jme, kms, kme, &
  985. its, ite, jts, jte, kts, kte )
  986. ! History: Sep 2003 Changes by George Bryan and Jason Knievel, NCAR
  987. ! Oct 2001 Converted to mass core by Bill Skamarock, NCAR
  988. ! ... ...
  989. ! Purpose: This routine calculates exchange coefficients for the TKE
  990. ! scheme.
  991. ! References: Klemp and Wilhelmson (JAS 1978)
  992. ! Deardorff (B-L Meteor 1980)
  993. ! Chen and Dudhia (NCAR WRF physics report 2000)
  994. !-----------------------------------------------------------------------
  995. ! Begin declarations.
  996. IMPLICIT NONE
  997. TYPE( grid_config_rec_type ), INTENT( IN ) &
  998. :: config_flags
  999. INTEGER, INTENT( IN ) &
  1000. :: n_moist, damp_opt, isotropic, &
  1001. ids, ide, jds, jde, kds, kde, &
  1002. ims, ime, jms, jme, kms, kme, &
  1003. its, ite, jts, jte, kts, kte
  1004. LOGICAL, INTENT( IN ) &
  1005. :: warm_rain
  1006. REAL, INTENT( IN ) &
  1007. :: dx, dy, zdamp, dt, dampcoef, cf1, cf2, cf3, khdif, kvdif
  1008. REAL, DIMENSION( kms:kme ), INTENT( IN ) &
  1009. :: dnw, dn
  1010. REAL, DIMENSION( ims:ime, kms:kme, jms:jme, n_moist ), INTENT( INOUT ) &
  1011. :: moist
  1012. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( INOUT ) &
  1013. :: xkmv, xkmh, xkhv, xkhh, BN2
  1014. REAL, DIMENSION( ims:ime , kms:kme, jms:jme ), INTENT( IN ) &
  1015. :: defor11, defor22, defor33, defor12, defor13, defor23, &
  1016. div, rdz, rdzw, p8w, t8w, theta, t, p
  1017. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( INOUT ) &
  1018. :: tke
  1019. REAL, INTENT( IN ) &
  1020. :: mix_upper_bound
  1021. REAL, DIMENSION( ims:ime, jms:jme ), INTENT( IN ) &
  1022. :: msftx, msfty
  1023. ! Local variables.
  1024. INTEGER &
  1025. :: i_start, i_end, j_start, j_end, ktf, i, j, k
  1026. ! End declarations.
  1027. !-----------------------------------------------------------------------
  1028. ktf = MIN( kte, kde-1 )
  1029. i_start = its
  1030. i_end = MIN( ite, ide-1 )
  1031. j_start = jts
  1032. j_end = MIN( jte, jde-1 )
  1033. CALL calculate_N2( config_flags, BN2, moist, &
  1034. theta, t, p, p8w, t8w, &
  1035. dnw, dn, rdz, rdzw, &
  1036. n_moist, cf1, cf2, cf3, warm_rain, &
  1037. ids, ide, jds, jde, kds, kde, &
  1038. ims, ime, jms, jme, kms, kme, &
  1039. its, ite, jts, jte, kts, kte )
  1040. ! Select a scheme for calculating diffusion coefficients.
  1041. km_coef: SELECT CASE( config_flags%km_opt )
  1042. CASE (1)
  1043. CALL isotropic_km( config_flags, xkmh, xkmv, &
  1044. xkhh, xkhv, khdif, kvdif, &
  1045. ids, ide, jds, jde, kds, kde, &
  1046. ims, ime, jms, jme, kms, kme, &
  1047. its, ite, jts, jte, kts, kte )
  1048. CASE (2)
  1049. CALL tke_km( config_flags, xkmh, xkmv, &
  1050. xkhh, xkhv, BN2, tke, p8w, t8w, theta, &
  1051. rdz, rdzw, dx, dy, dt, isotropic, &
  1052. mix_upper_bound, msftx, msfty, &
  1053. ids, ide, jds, jde, kds, kde, &
  1054. ims, ime, jms, jme, kms, kme, &
  1055. its, ite, jts, jte, kts, kte )
  1056. CASE (3)
  1057. CALL smag_km( config_flags, xkmh, xkmv, &
  1058. xkhh, xkhv, BN2, div, &
  1059. defor11, defor22, defor33, &
  1060. defor12, defor13, defor23, &
  1061. rdzw, dx, dy, dt, isotropic, &
  1062. mix_upper_bound, msftx, msfty, &
  1063. ids, ide, jds, jde, kds, kde, &
  1064. ims, ime, jms, jme, kms, kme, &
  1065. its, ite, jts, jte, kts, kte )
  1066. CASE (4)
  1067. CALL smag2d_km( config_flags, xkmh, xkmv, &
  1068. xkhh, xkhv, defor11, defor22, defor12, &
  1069. rdzw, dx, dy, msftx, msfty, &
  1070. ids, ide, jds, jde, kds, kde, &
  1071. ims, ime, jms, jme, kms, kme, &
  1072. its, ite, jts, jte, kts, kte )
  1073. CASE DEFAULT
  1074. CALL wrf_error_fatal( 'Please choose diffusion coefficient scheme' )
  1075. END SELECT km_coef
  1076. IF ( damp_opt .eq. 1 ) THEN
  1077. CALL cal_dampkm( config_flags, xkmh, xkhh, xkmv, xkhv, &
  1078. dx, dy, dt, dampcoef, rdz, rdzw, zdamp, &
  1079. msftx, msfty, &
  1080. ids, ide, jds, jde, kds, kde, &
  1081. ims, ime, jms, jme, kms, kme, &
  1082. its, ite, jts, jte, kts, kte )
  1083. END IF
  1084. END SUBROUTINE calculate_km_kh
  1085. !=======================================================================
  1086. SUBROUTINE cal_dampkm( config_flags,xkmh,xkhh,xkmv,xkhv, &
  1087. dx,dy,dt,dampcoef, &
  1088. rdz, rdzw ,zdamp, &
  1089. msftx, msfty, &
  1090. ids,ide, jds,jde, kds,kde, &
  1091. ims,ime, jms,jme, kms,kme, &
  1092. its,ite, jts,jte, kts,kte )
  1093. !-----------------------------------------------------------------------
  1094. ! Begin declarations.
  1095. IMPLICIT NONE
  1096. TYPE(grid_config_rec_type) , INTENT(IN ) :: config_flags
  1097. INTEGER , INTENT(IN ) :: ids, ide, jds, jde, kds, kde, &
  1098. ims, ime, jms, jme, kms, kme, &
  1099. its, ite, jts, jte, kts, kte
  1100. REAL , INTENT(IN ) :: zdamp,dx,dy,dt,dampcoef
  1101. REAL , DIMENSION( ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: xkmh , &
  1102. xkhh , &
  1103. xkmv , &
  1104. xkhv
  1105. REAL , DIMENSION( ims:ime, kms:kme, jms:jme), INTENT(IN ) :: rdz, &
  1106. rdzw
  1107. REAL , DIMENSION( ims:ime, jms:jme), INTENT(IN ) :: msftx, &
  1108. msfty
  1109. ! LOCAL VARS
  1110. INTEGER :: i_start, i_end, j_start, j_end, ktf, ktfm1, i, j, k
  1111. REAL :: kmmax,kmmvmax,degrad90,dz,tmp
  1112. REAL :: ds
  1113. REAL , DIMENSION( its:ite ) :: deltaz
  1114. REAL , DIMENSION( its:ite, kts:kte, jts:jte) :: dampk,dampkv
  1115. ! End declarations.
  1116. !-----------------------------------------------------------------------
  1117. ktf = min(kte,kde-1)
  1118. ktfm1 = ktf-1
  1119. i_start = its
  1120. i_end = MIN(ite,ide-1)
  1121. j_start = jts
  1122. j_end = MIN(jte,jde-1)
  1123. ! keep upper damping diffusion away from relaxation zones at boundaries if used
  1124. IF(config_flags%specified .OR. config_flags%nested)THEN
  1125. i_start = MAX(i_start,ids+config_flags%spec_bdy_width-1)
  1126. i_end = MIN(i_end,ide-config_flags%spec_bdy_width)
  1127. j_start = MAX(j_start,jds+config_flags%spec_bdy_width-1)
  1128. j_end = MIN(j_end,jde-config_flags%spec_bdy_width)
  1129. ENDIF
  1130. kmmax=dx*dx/dt
  1131. degrad90=DEGRAD*90.
  1132. DO j = j_start, j_end
  1133. k=ktf
  1134. DO i = i_start, i_end
  1135. ! Unmodified dx used above may produce very large diffusivities
  1136. ! when msftx is very large. And the above formula ignores the fact
  1137. ! that dy may now be different from dx as well. Let's fix that by
  1138. ! defining a "ds" as the minimum of the "real-space" (physical
  1139. ! distance) values of dx and dy, and then using that smallest value
  1140. ! to calculate a point-by-point kmmax
  1141. ds = MIN(dx/msftx(i,j),dy/msfty(i,j))
  1142. kmmax=ds*ds/dt
  1143. ! deltaz(i)=0.5*dnw(k)/zeta_z(i,j)
  1144. ! dz=dnw(k)/zeta_z(i,j)
  1145. dz = 1./rdzw(i,k,j)
  1146. deltaz(i) = 0.5*dz
  1147. kmmvmax=dz*dz/dt
  1148. tmp=min(deltaz(i)/zdamp,1.)
  1149. dampk(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
  1150. dampkv(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax*dampcoef
  1151. ! set upper limit on vertical K (based on horizontal K)
  1152. dampkv(i,k,j)=min(dampkv(i,k,j),dampk(i,k,j))
  1153. ENDDO
  1154. DO k = ktfm1,kts,-1
  1155. DO i = i_start, i_end
  1156. ! Unmodified dx used above may produce very large diffusivities
  1157. ! when msftx is very large. And the above formula ignores the fact
  1158. ! that dy may now be different from dx as well. Let's fix that by
  1159. ! defining a "ds" as the minimum of the "real-space" (physical
  1160. ! distance) values of dx and dy, and then using that smallest value
  1161. ! to calculate a point-by-point kmmax
  1162. ds = MIN(dx/msftx(i,j),dy/msfty(i,j))
  1163. kmmax=ds*ds/dt
  1164. ! deltaz(i)=deltaz(i)+dn(k)/zeta_z(i,j)
  1165. ! dz=dnw(k)/zeta_z(i,j)
  1166. dz = 1./rdz(i,k,j)
  1167. deltaz(i) = deltaz(i) + dz
  1168. dz = 1./rdzw(i,k,j)
  1169. kmmvmax=dz*dz/dt
  1170. tmp=min(deltaz(i)/zdamp,1.)
  1171. dampk(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmax*dampcoef
  1172. dampkv(i,k,j)=cos(degrad90*tmp)*cos(degrad90*tmp)*kmmvmax*dampcoef
  1173. ! set upper limit on vertical K (based on horizontal K)
  1174. dampkv(i,k,j)=min(dampkv(i,k,j),dampk(i,k,j))
  1175. ENDDO
  1176. ENDDO
  1177. ENDDO
  1178. DO j = j_start, j_end
  1179. DO k = kts,ktf
  1180. DO i = i_start, i_end
  1181. xkmh(i,k,j)=max(xkmh(i,k,j),dampk(i,k,j))
  1182. xkhh(i,k,j)=max(xkhh(i,k,j),dampk(i,k,j))
  1183. xkmv(i,k,j)=max(xkmv(i,k,j),dampkv(i,k,j))
  1184. xkhv(i,k,j)=max(xkhv(i,k,j),dampkv(i,k,j))
  1185. ENDDO
  1186. ENDDO
  1187. ENDDO
  1188. END SUBROUTINE cal_dampkm
  1189. !=======================================================================
  1190. !=======================================================================
  1191. SUBROUTINE calculate_N2( config_flags, BN2, moist, &
  1192. theta, t, p, p8w, t8w, &
  1193. dnw, dn, rdz, rdzw, &
  1194. n_moist, cf1, cf2, cf3, warm_rain, &
  1195. ids, ide, jds, jde, kds, kde, &
  1196. ims, ime, jms, jme, kms, kme, &
  1197. its, ite, jts, jte, kts, kte )
  1198. !-----------------------------------------------------------------------
  1199. ! Begin declarations.
  1200. IMPLICIT NONE
  1201. TYPE( grid_config_rec_type ), INTENT( IN ) &
  1202. :: config_flags
  1203. INTEGER, INTENT( IN ) &
  1204. :: n_moist, &
  1205. ids, ide, jds, jde, kds, kde, &
  1206. ims, ime, jms, jme, kms, kme, &
  1207. its, ite, jts, jte, kts, kte
  1208. LOGICAL, INTENT( IN ) &
  1209. :: warm_rain
  1210. REAL, INTENT( IN ) &
  1211. :: cf1, cf2, cf3
  1212. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( INOUT ) &
  1213. :: BN2
  1214. REAL, DIMENSION( ims:ime, kms:kme, jms:jme ), INTENT( IN ) &
  1215. :: rdz, rdzw, theta, t, p, p8w, t8w
  1216. REAL, DIMENSION( kms:kme ), INTENT( IN ) &
  1217. :: dnw, dn
  1218. REAL, DIMENSION( ims:ime, kms:kme, jms:jme, n_moist), INTENT( INOUT ) &
  1219. :: moist
  1220. ! Local variables.
  1221. INTEGER &
  1222. :: i, j, k, ktf, ispe, ktes1, ktes2, &
  1223. i_start, i_end, j_start, j_end
  1224. REAL &
  1225. :: coefa, thetaep1, thetaem1, qc_cr, es, tc, qlpqi, qsw, qsi, &
  1226. tmpdz, xlvqv, thetaesfc, thetasfc, qvtop, qvsfc, thetatop, thetaetop
  1227. REAL, DIMENSION( its:ite, jts:jte ) &
  1228. :: tmp1sfc, tmp1top
  1229. REAL, DIMENSION( its:ite, kts:kte, jts:jte ) &
  1230. :: tmp1, qvs, qctmp
  1231. ! End declarations.
  1232. !-------

Large files files are truncated, but you can click here to view the full file