PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/dyn_nmm/module_SMOOTH_TERRAIN.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 401 lines | 290 code | 61 blank | 50 comment | 37 complexity | 53a08d2bfbccc0418729c3cdf97fd6f5 MD5 | raw file
Possible License(s): AGPL-1.0
  1. module module_SMOOTH_TERRAIN
  2. #if (NMM_NEST == 1)
  3. contains
  4. subroutine smooth_terrain(grid,lines,nsmud, &
  5. IDS,IDE,JDS,JDE,KDS,KDE, &
  6. IMS,IME,JMS,JME,KMS,KME, &
  7. IPS,IPE,JPS,JPE,KPS,KPE)
  8. ! Parallelized smoothing routine for NMM domain terrain heights.
  9. ! Also supports serial setups.
  10. !
  11. ! Author: Sam Trahan, September 2011
  12. ! This is a replacement for, and based on, SMDHLD, which can be
  13. ! found lower down in this module. This smooths boundaries of the
  14. ! grid%HRES_AVC.
  15. ! Two grid%variables are used: HRES_LND (land mask) and HRES_AVC.
  16. ! Those are initialized in NEST_TERRAIN and module_TERRAIN's
  17. ! terrain_for. This routine is not sensitive to the units of
  18. ! HRES_AVC, so it could potentially be called on HRES_FIS instead.
  19. USE MODULE_DOMAIN, ONLY : DOMAIN, GET_IJK_FROM_GRID
  20. #ifdef DM_PARALLEL
  21. USE MODULE_COMM_DM, ONLY: HALO_NMM_TERRAIN_SMOOTH_sub
  22. USE MODULE_DM, ONLY: ntasks_x, ntasks_y, mytask, ntasks, local_communicator
  23. #endif
  24. implicit none
  25. INTEGER :: IDS,IDE,JDS,JDE,KDS,KDE
  26. INTEGER :: IMS,IME,JMS,JME,KMS,KME
  27. INTEGER :: IPS,IPE,JPS,JPE,KPS,KPE
  28. integer, intent(in) :: lines,nsmud
  29. character(len=256) :: message
  30. type(domain) :: grid
  31. integer :: i,j,k,jmelin,ibas,buf
  32. integer :: im,jm
  33. integer :: ihl,ihh,ks,m2l,imid,jmid,itgt,jtgt
  34. real :: hbms(ips:ipe,jps:jpe)
  35. integer :: ihw((jps-2):(jpe+2)),ihe((jps-2):(jpe+2))
  36. real :: hse((ips-1):(ipe+1),(jps-1):(jpe+1))
  37. real :: hne((ips-1):(ipe+1),(jps-1):(jpe+1))
  38. !-----------------------------------------------------------------------
  39. im=ide-1
  40. jm=jde-1
  41. imid=(ips+ipe)/2
  42. jmid=(jps+jpe)/2
  43. itgt=1
  44. jtgt=143
  45. buf=1
  46. !-----------------------------------------------------------------------
  47. do j=max(1,jps-2),min(jm,jpe+2)
  48. ihw(j)=-mod(j,2)
  49. ihe(j)=ihw(j)+1
  50. enddo
  51. !-----------------------------------------------------------------------
  52. do j=jps,jpe
  53. do i=ips,ipe
  54. hbms(i,j)=grid%hres_lnd(i,j)
  55. enddo
  56. enddo
  57. !
  58. jmelin=jm-lines+1
  59. ibas=lines/2
  60. m2l=mod(lines,2)
  61. !
  62. do j=max(jps,lines),min(jpe,jmelin)
  63. ihl=ibas+mod(j,2)+m2l*mod(j+1,2)
  64. ihh=im-ibas-m2l*mod(j+1,2)
  65. !
  66. do i=max(ihl,ips),min(ihh,ipe)
  67. hbms(i,j)=0.
  68. enddo
  69. enddo
  70. !-----------------------------------------------------------------------
  71. smooth_loop: do ks=1,nsmud
  72. #ifdef DM_PARALLEL
  73. # include "HALO_NMM_TERRAIN_SMOOTH.inc"
  74. #endif
  75. do j=max(jps-1,1),min(jpe+1,jm-1)
  76. do i=max(ips-1,1),min(ipe+1,im-1)
  77. hne(i,j)=grid%hres_avc(i+ihe(j),j+1)-grid%hres_avc(i,j)
  78. enddo
  79. enddo
  80. do j=max(jps-1,2),min(jpe+1,jm)
  81. do i=max(ips-1,1),min(ipe+1,im-1)
  82. hse(i,j)=grid%hres_avc(i+ihe(j),j-1)-grid%hres_avc(i,j)
  83. enddo
  84. enddo
  85. !
  86. do j=max(jps,2),min(jpe,jm-1)
  87. do i=max(ips,1+mod(j,2)),min(ipe,im-1)
  88. grid%hres_avc(i,j)=(hne(i,j)-hne(i+ihw(j),j-1) &
  89. & +hse(i,j)-hse(i+ihw(j),j+1))*hbms(i,j)*0.125+grid%hres_avc(i,j)
  90. enddo
  91. enddo
  92. !--------------------------------------------------------------------
  93. ! smooth around boundary somehow?
  94. ! special treatment for four corners
  95. wbound: if(1>=ips .and. 1<=ipe) then
  96. if(1>=jps .and. 1<=jpe) then
  97. if (hbms(1,1) .eq. 1) then
  98. grid%hres_avc(1,1)=0.75*grid%hres_avc(1,1)+0.125*grid%hres_avc(1+ihe(1),2)+ &
  99. 0.0625*(grid%hres_avc(2,1)+grid%hres_avc(1,3))
  100. endif
  101. endif
  102. if(jm>=jps .and. jm<=jpe) then
  103. if (hbms(1,jm) .eq. 1) then
  104. grid%hres_avc(1,jm)=0.75*grid%hres_avc(1,jm)+0.125*grid%hres_avc(1+ihe(jm),jm-1)+ &
  105. 0.0625*(grid%hres_avc(2,jm)+grid%hres_avc(1,jm-2))
  106. endif
  107. endif
  108. endif wbound
  109. ebound: if(im>=ips .and. im<=ipe) then
  110. if(1>=jps .and. 1<=jpe) then
  111. if (hbms(im,1) .eq. 1) then
  112. grid%hres_avc(im,1)=0.75*grid%hres_avc(im,1)+0.125*grid%hres_avc(im+ihw(1),2)+ &
  113. 0.0625*(grid%hres_avc(im-1,1)+grid%hres_avc(im,3))
  114. endif
  115. endif
  116. if(jm>=jps .and. jm<=jpe) then
  117. if (hbms(im,jm) .eq. 1) then
  118. grid%hres_avc(im,jm)=0.75*grid%hres_avc(im,jm)+0.125*grid%hres_avc(im+ihw(jm),jm-1)+ &
  119. 0.0625*(grid%hres_avc(im-1,jm)+grid%hres_avc(im,jm-2))
  120. endif
  121. endif
  122. endif ebound
  123. #ifdef DM_PARALLEL
  124. # include "HALO_NMM_TERRAIN_SMOOTH.inc"
  125. #endif
  126. ! S bound
  127. if(1>=jps .and. 1<=jpe) then
  128. J=1
  129. do I=max(ips,2),min(ipe,im-1)
  130. if (hbms(I,J) .eq. 1) then
  131. hne(i,j)=0.125*(grid%hres_avc(I+ihw(J),J+1)+grid%hres_avc(I+ihe(J),J+1))
  132. endif
  133. enddo
  134. do I=max(ips,2),min(ipe,im-1)
  135. if (hbms(I,J) .eq. 1) then
  136. grid%hres_avc(I,J)=0.75*grid%hres_avc(I,J)+hne(i,j)
  137. endif
  138. enddo
  139. endif
  140. ! N bound
  141. if(jm>=jps .and. jm<=jpe) then
  142. J=JM
  143. do I=max(ips,2),min(ipe,im-1)
  144. if (hbms(I,J) .eq. 1) then
  145. grid%hres_avc(I,J)=0.75*grid%hres_avc(I,J)+0.125*(grid%hres_avc(I+ihw(J),J-1)+grid%hres_avc(I+ihe(J),J-1))
  146. endif
  147. enddo
  148. do I=max(ips,2),min(ipe,im-1)
  149. if (hbms(I,J) .eq. 1) then
  150. hne(i,j)=0.125*(grid%hres_avc(I+ihw(J),J-1)+grid%hres_avc(I+ihe(J),J-1))
  151. endif
  152. enddo
  153. endif
  154. ! W bound
  155. if(1>=ips .and. 1<=ipe) then
  156. I=1
  157. do J=max(jps,3),min(jpe,jm-2)
  158. if (hbms(I,J) .eq. 1) then
  159. hne(i,j)=0.125*(grid%hres_avc(I+ihe(J),J+1)+grid%hres_avc(I+ihe(J),J-1))
  160. endif
  161. enddo
  162. do J=max(jps,3),min(jpe,jm-2)
  163. if (hbms(I,J) .eq. 1) then
  164. grid%hres_avc(I,J)=0.75*grid%hres_avc(I,J)+hne(i,j)
  165. endif
  166. enddo
  167. endif
  168. ! E bound
  169. if(im>=ips .and. im<=ipe) then
  170. I=IM
  171. do J=max(jps,3),min(jpe,jm-2)
  172. if (hbms(I,J) .eq. 1) then
  173. hne(i,j)=0.125*(grid%hres_avc(I+ihw(J),J+1)+grid%hres_avc(I+ihw(J),J-1))
  174. endif
  175. enddo
  176. do J=max(jps,3),min(jpe,jm-2)
  177. if (hbms(I,J) .eq. 1) then
  178. grid%hres_avc(I,J)=0.75*grid%hres_avc(I,J)+hne(i,j)
  179. endif
  180. enddo
  181. endif
  182. enddo smooth_loop
  183. #ifdef DM_PARALLEL
  184. # include "HALO_NMM_TERRAIN_SMOOTH.inc"
  185. #endif
  186. !-------------4-point averaging of mountains along inner boundary-------
  187. if(2>=jps .and. 2<=jpe) then
  188. do i=max(ips,1),min(ipe,im-1)
  189. grid%hres_avc(i,2)=0.25*(grid%hres_avc(i,1)+grid%hres_avc(i+1,1)+ &
  190. & grid%hres_avc(i,3)+grid%hres_avc(i+1,3))
  191. enddo
  192. endif
  193. if(jm-1>=jps .and. jm-1<=jpe) then
  194. do i=max(ips,1),min(ipe,im-1)
  195. grid%hres_avc(i,jm-1)=0.25*(grid%hres_avc(i,jm-2)+grid%hres_avc(i+1,jm-2)+ &
  196. & grid%hres_avc(i,jm)+grid%hres_avc(i+1,jm))
  197. enddo
  198. endif
  199. #ifdef DM_PARALLEL
  200. # include "HALO_NMM_TERRAIN_SMOOTH.inc"
  201. #endif
  202. if(2>=ips .and. 2<=ipe) then
  203. do j=4,jm-3,2
  204. if(j>=jps .and. j<=jpe) then
  205. grid%hres_avc(1,j)=0.25*(grid%hres_avc(1,j-1)+ &
  206. grid%hres_avc(2,j-1)+grid%hres_avc(1,j+1)+ &
  207. grid%hres_avc(2,j+1))
  208. endif
  209. enddo
  210. endif
  211. if(im-1>=ips .and. im-1<=ipe) then
  212. do j=4,jm-3,2
  213. if(j>=jps .and. j<=jpe) then
  214. grid%hres_avc(im-1,j)=0.25*(grid%hres_avc(im-1,j-1)+ &
  215. grid%hres_avc(im,j-1)+grid%hres_avc(im-1,j+1)+ &
  216. grid%hres_avc(im,j+1))
  217. endif
  218. enddo
  219. endif
  220. end subroutine smooth_terrain
  221. ! ---------------------------------------------------------------------
  222. ! ---------------------------------------------------------------------
  223. subroutine smdhld(ids,ide,jds,jde,h,s1,lines,nsmud)
  224. ! This is the old serial smoothing routine from NMM_NEST_UTILS1.F
  225. character(len=255) :: message
  226. dimension ihw(jde-1),ihe(jde-1)
  227. dimension h(ids:ide,jds:jde),s1(ids:ide,jds:jde) &
  228. & ,hbms(ide-1,jde-1),hne(ide-1,jde-1),hse(ide-1,jde-1)
  229. jm=jde-1
  230. im=ide-1
  231. !-----------------------------------------------------------------------
  232. do j=1,jm
  233. ihw(j)=-mod(j,2)
  234. ihe(j)=ihw(j)+1
  235. enddo
  236. !-----------------------------------------------------------------------
  237. do j=1,jm
  238. do i=1,im
  239. hbms(i,j)=s1(i,j)
  240. enddo
  241. enddo
  242. !
  243. jmelin=jm-lines+1
  244. ibas=lines/2
  245. m2l=mod(lines,2)
  246. !
  247. do j=lines,jmelin
  248. ihl=ibas+mod(j,2)+m2l*mod(j+1,2)
  249. ihh=im-ibas-m2l*mod(j+1,2)
  250. !
  251. do i=ihl,ihh
  252. hbms(i,j)=0.
  253. enddo
  254. enddo
  255. !-----------------------------------------------------------------------
  256. ks_loop: do ks=1,nsmud
  257. !-----------------------------------------------------------------------
  258. do j=1,jm-1
  259. do i=1,im-1
  260. hne(i,j)=h(i+ihe(j),j+1)-h(i,j)
  261. enddo
  262. enddo
  263. do j=2,jm
  264. do i=1,im-1
  265. hse(i,j)=h(i+ihe(j),j-1)-h(i,j)
  266. enddo
  267. enddo
  268. !
  269. do j=2,jm-1
  270. do i=1+mod(j,2),im-1
  271. h(i,j)=(hne(i,j)-hne(i+ihw(j),j-1) &
  272. & +hse(i,j)-hse(i+ihw(j),j+1))*hbms(i,j)*0.125+h(i,j)
  273. enddo
  274. enddo
  275. !-----------------------------------------------------------------------
  276. ! smooth around boundary somehow?
  277. ! special treatment for four corners
  278. if (hbms(1,1) .eq. 1) then
  279. h(1,1)=0.75*h(1,1)+0.125*h(1+ihe(1),2)+ &
  280. & 0.0625*(h(2,1)+h(1,3))
  281. endif
  282. if (hbms(im,1) .eq. 1) then
  283. h(im,1)=0.75*h(im,1)+0.125*h(im+ihw(1),2)+ &
  284. & 0.0625*(h(im-1,1)+h(im,3))
  285. endif
  286. if (hbms(1,jm) .eq. 1) then
  287. h(1,jm)=0.75*h(1,jm)+0.125*h(1+ihe(jm),jm-1)+ &
  288. & 0.0625*(h(2,jm)+h(1,jm-2))
  289. endif
  290. if (hbms(im,jm) .eq. 1) then
  291. h(im,jm)=0.75*h(im,jm)+0.125*h(im+ihw(jm),jm-1)+ &
  292. & 0.0625*(h(im-1,jm)+h(im,jm-2))
  293. endif
  294. ! S bound
  295. J=1
  296. do I=2,im-1
  297. if (hbms(I,J) .eq. 1) then
  298. h(I,J)=0.75*h(I,J)+0.125*(h(I+ihw(J),J+1)+h(I+ihe(J),J+1))
  299. endif
  300. enddo
  301. ! N bound
  302. J=JM
  303. do I=2,im-1
  304. if (hbms(I,J) .eq. 1) then
  305. h(I,J)=0.75*h(I,J)+0.125*(h(I+ihw(J),J-1)+h(I+ihe(J),J-1))
  306. endif
  307. enddo
  308. ! W bound
  309. I=1
  310. do J=3,jm-2
  311. if (hbms(I,J) .eq. 1) then
  312. h(I,J)=0.75*h(I,J)+0.125*(h(I+ihe(J),J+1)+h(I+ihe(J),J-1))
  313. endif
  314. enddo
  315. ! E bound
  316. I=IM
  317. do J=3,jm-2
  318. if (hbms(I,J) .eq. 1) then
  319. h(I,J)=0.75*h(I,J)+0.125*(h(I+ihw(J),J+1)+h(I+ihw(J),J-1))
  320. endif
  321. enddo
  322. enddo ks_loop
  323. !-------------4-point averaging of mountains along inner boundary-------
  324. do i=1,im-1
  325. h(i,2)=0.25*(h(i,1)+h(i+1,1)+h(i,3)+h(i+1,3))
  326. enddo
  327. do i=1,im-1
  328. h(i,jm-1)=0.25*(h(i,jm-2)+h(i+1,jm-2)+h(i,jm)+h(i+1,jm))
  329. enddo
  330. do j=4,jm-3,2
  331. h(1,j)=0.25*(h(1,j-1)+h(2,j-1)+h(1,j+1)+h(2,j+1))
  332. enddo
  333. do j=4,jm-3,2
  334. h(im-1,j)=0.25*(h(im-1,j-1)+h(im,j-1)+h(im-1,j+1)+h(im,j+1))
  335. enddo
  336. !-----------------------------------------------------------------------
  337. return
  338. end subroutine smdhld
  339. #endif
  340. end module module_SMOOTH_TERRAIN