PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/dyn_em/module_initialize_les.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 841 lines | 493 code | 182 blank | 166 comment | 13 complexity | 9650c994df886568daf138f4c29a949b MD5 | raw file
Possible License(s): AGPL-1.0
  1. !IDEAL:MODEL_LAYER:INITIALIZATION
  2. !
  3. ! This MODULE holds the routines which are used to perform various initializations
  4. ! for the individual domains.
  5. ! This MODULE CONTAINS the following routines:
  6. ! initialize_field_test - 1. Set different fields to different constant
  7. ! values. This is only a test. If the correct
  8. ! domain is not found (based upon the "id")
  9. ! then a fatal error is issued.
  10. !-----------------------------------------------------------------------
  11. MODULE module_initialize_ideal
  12. USE module_domain
  13. USE module_io_domain
  14. USE module_state_description
  15. USE module_model_constants
  16. USE module_bc
  17. USE module_timing
  18. USE module_configure
  19. USE module_init_utilities
  20. #ifdef DM_PARALLEL
  21. USE module_dm
  22. #endif
  23. CONTAINS
  24. !-------------------------------------------------------------------
  25. ! this is a wrapper for the solver-specific init_domain routines.
  26. ! Also dereferences the grid variables and passes them down as arguments.
  27. ! This is crucial, since the lower level routines may do message passing
  28. ! and this will get fouled up on machines that insist on passing down
  29. ! copies of assumed-shape arrays (by passing down as arguments, the
  30. ! data are treated as assumed-size -- ie. f77 -- arrays and the copying
  31. ! business is avoided). Fie on the F90 designers. Fie and a pox.
  32. SUBROUTINE init_domain ( grid )
  33. IMPLICIT NONE
  34. ! Input data.
  35. TYPE (domain), POINTER :: grid
  36. ! Local data.
  37. INTEGER :: idum1, idum2
  38. CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
  39. CALL init_domain_rk( grid &
  40. !
  41. #include <actual_new_args.inc>
  42. !
  43. )
  44. END SUBROUTINE init_domain
  45. !-------------------------------------------------------------------
  46. SUBROUTINE init_domain_rk ( grid &
  47. !
  48. # include <dummy_new_args.inc>
  49. !
  50. )
  51. IMPLICIT NONE
  52. ! Input data.
  53. TYPE (domain), POINTER :: grid
  54. # include <dummy_new_decl.inc>
  55. TYPE (grid_config_rec_type) :: config_flags
  56. ! Local data
  57. INTEGER :: &
  58. ids, ide, jds, jde, kds, kde, &
  59. ims, ime, jms, jme, kms, kme, &
  60. its, ite, jts, jte, kts, kte, &
  61. i, j, k
  62. ! Local data
  63. INTEGER, PARAMETER :: nl_max = 1000
  64. REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
  65. INTEGER :: nl_in
  66. INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc
  67. REAL :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
  68. REAL :: z_scale, xrad, yrad, zrad, rad, delt, cof1, cof2
  69. ! REAL, EXTERNAL :: interp_0
  70. REAL :: hm
  71. REAL :: pi
  72. ! stuff from original initialization that has been dropped from the Registry
  73. REAL :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
  74. REAL :: qvf1, qvf2, pd_surf
  75. INTEGER :: it
  76. real :: thtmp, ptmp, temp(3)
  77. LOGICAL :: moisture_init
  78. LOGICAL :: stretch_grid, dry_sounding
  79. INTEGER :: xs , xe , ys , ye
  80. REAL :: mtn_ht
  81. LOGICAL, EXTERNAL :: wrf_dm_on_monitor
  82. ! For LES, add randx
  83. real :: randx
  84. #ifdef DM_PARALLEL
  85. # include <data_calls.inc>
  86. #endif
  87. SELECT CASE ( model_data_order )
  88. CASE ( DATA_ORDER_ZXY )
  89. kds = grid%sd31 ; kde = grid%ed31 ;
  90. ids = grid%sd32 ; ide = grid%ed32 ;
  91. jds = grid%sd33 ; jde = grid%ed33 ;
  92. kms = grid%sm31 ; kme = grid%em31 ;
  93. ims = grid%sm32 ; ime = grid%em32 ;
  94. jms = grid%sm33 ; jme = grid%em33 ;
  95. kts = grid%sp31 ; kte = grid%ep31 ; ! note that tile is entire patch
  96. its = grid%sp32 ; ite = grid%ep32 ; ! note that tile is entire patch
  97. jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
  98. CASE ( DATA_ORDER_XYZ )
  99. ids = grid%sd31 ; ide = grid%ed31 ;
  100. jds = grid%sd32 ; jde = grid%ed32 ;
  101. kds = grid%sd33 ; kde = grid%ed33 ;
  102. ims = grid%sm31 ; ime = grid%em31 ;
  103. jms = grid%sm32 ; jme = grid%em32 ;
  104. kms = grid%sm33 ; kme = grid%em33 ;
  105. its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
  106. jts = grid%sp32 ; jte = grid%ep32 ; ! note that tile is entire patch
  107. kts = grid%sp33 ; kte = grid%ep33 ; ! note that tile is entire patch
  108. CASE ( DATA_ORDER_XZY )
  109. ids = grid%sd31 ; ide = grid%ed31 ;
  110. kds = grid%sd32 ; kde = grid%ed32 ;
  111. jds = grid%sd33 ; jde = grid%ed33 ;
  112. ims = grid%sm31 ; ime = grid%em31 ;
  113. kms = grid%sm32 ; kme = grid%em32 ;
  114. jms = grid%sm33 ; jme = grid%em33 ;
  115. its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
  116. kts = grid%sp32 ; kte = grid%ep32 ; ! note that tile is entire patch
  117. jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
  118. END SELECT
  119. ! stretch_grid = .true.
  120. ! FOR LES, set stretch to false
  121. stretch_grid = .false.
  122. delt = 3.
  123. ! z_scale = .50
  124. z_scale = .40
  125. pi = 2.*asin(1.0)
  126. write(6,*) ' pi is ',pi
  127. nxc = (ide-ids)/2
  128. nyc = (jde-jds)/2
  129. CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
  130. ! here we check to see if the boundary conditions are set properly
  131. CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
  132. moisture_init = .true.
  133. grid%itimestep=0
  134. #ifdef DM_PARALLEL
  135. CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
  136. CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
  137. #endif
  138. CALL nl_set_mminlu(1, ' ')
  139. CALL nl_set_iswater(1,0)
  140. CALL nl_set_cen_lat(1,40.)
  141. CALL nl_set_cen_lon(1,-105.)
  142. CALL nl_set_truelat1(1,0.)
  143. CALL nl_set_truelat2(1,0.)
  144. CALL nl_set_moad_cen_lat (1,0.)
  145. CALL nl_set_stand_lon (1,0.)
  146. CALL nl_set_pole_lon (1,0.)
  147. CALL nl_set_pole_lat (1,90.)
  148. CALL nl_set_map_proj(1,0)
  149. ! here we initialize data we currently is not initialized
  150. ! in the input data
  151. DO j = jts, jte
  152. DO i = its, ite
  153. grid%msftx(i,j) = 1.
  154. grid%msfty(i,j) = 1.
  155. grid%msfux(i,j) = 1.
  156. grid%msfuy(i,j) = 1.
  157. grid%msfvx(i,j) = 1.
  158. grid%msfvx_inv(i,j)= 1.
  159. grid%msfvy(i,j) = 1.
  160. grid%sina(i,j) = 0.
  161. grid%cosa(i,j) = 1.
  162. grid%e(i,j) = 0.
  163. ! for LES, include Coriolis force
  164. grid%f(i,j) = 1.e-4
  165. END DO
  166. END DO
  167. DO j = jts, jte
  168. DO k = kts, kte
  169. DO i = its, ite
  170. grid%ww(i,k,j) = 0.
  171. END DO
  172. END DO
  173. END DO
  174. grid%step_number = 0
  175. ! set up the grid
  176. IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
  177. DO k=1, kde
  178. grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
  179. (1.-exp(-1./z_scale))
  180. ENDDO
  181. ELSE
  182. DO k=1, kde
  183. grid%znw(k) = 1. - float(k-1)/float(kde-1)
  184. ENDDO
  185. ENDIF
  186. DO k=1, kde-1
  187. grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
  188. grid%rdnw(k) = 1./grid%dnw(k)
  189. grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
  190. ENDDO
  191. DO k=2, kde-1
  192. grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
  193. grid%rdn(k) = 1./grid%dn(k)
  194. grid%fnp(k) = .5* grid%dnw(k )/grid%dn(k)
  195. grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
  196. ENDDO
  197. cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
  198. cof2 = grid%dn(2) /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
  199. grid%cf1 = grid%fnp(2) + cof1
  200. grid%cf2 = grid%fnm(2) - cof1 - cof2
  201. grid%cf3 = cof2
  202. grid%cfn = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
  203. grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
  204. grid%rdx = 1./config_flags%dx
  205. grid%rdy = 1./config_flags%dy
  206. ! get the sounding from the ascii sounding file, first get dry sounding and
  207. ! calculate base state
  208. dry_sounding = .true.
  209. IF ( wrf_dm_on_monitor() ) THEN
  210. write(6,*) ' getting dry sounding for base state '
  211. CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
  212. ENDIF
  213. CALL wrf_dm_bcast_real( zk , nl_max )
  214. CALL wrf_dm_bcast_real( p_in , nl_max )
  215. CALL wrf_dm_bcast_real( pd_in , nl_max )
  216. CALL wrf_dm_bcast_real( theta , nl_max )
  217. CALL wrf_dm_bcast_real( rho , nl_max )
  218. CALL wrf_dm_bcast_real( u , nl_max )
  219. CALL wrf_dm_bcast_real( v , nl_max )
  220. CALL wrf_dm_bcast_real( qv , nl_max )
  221. CALL wrf_dm_bcast_integer ( nl_in , 1 )
  222. write(6,*) ' returned from reading sounding, nl_in is ',nl_in
  223. ! find ptop for the desired ztop (ztop is input from the namelist),
  224. ! and find surface pressure
  225. grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
  226. DO j=jts,jte
  227. DO i=its,ite
  228. grid%ht(i,j) = 0.
  229. ENDDO
  230. ENDDO
  231. xs=ide/2 -3
  232. xs=ids -3
  233. xe=xs + 6
  234. ys=jde/2 -3
  235. ye=ys + 6
  236. mtn_ht = 500
  237. #ifdef MTN
  238. DO j=max(ys,jds),min(ye,jde-1)
  239. DO i=max(xs,ids),min(xe,ide-1)
  240. grid%ht(i,j) = mtn_ht * 0.25 * &
  241. ( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) ) * &
  242. ( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
  243. ENDDO
  244. ENDDO
  245. #endif
  246. #ifdef EW_RIDGE
  247. DO j=max(ys,jds),min(ye,jde-1)
  248. DO i=ids,ide
  249. grid%ht(i,j) = mtn_ht * 0.50 * &
  250. ( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
  251. ENDDO
  252. ENDDO
  253. #endif
  254. #ifdef NS_RIDGE
  255. DO j=jds,jde
  256. DO i=max(xs,ids),min(xe,ide-1)
  257. grid%ht(i,j) = mtn_ht * 0.50 * &
  258. ( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) )
  259. ENDDO
  260. ENDDO
  261. #endif
  262. DO j=jts,jte
  263. DO i=its,ite
  264. grid%phb(i,1,j) = g * grid%ht(i,j)
  265. grid%ph0(i,1,j) = g * grid%ht(i,j)
  266. ENDDO
  267. ENDDO
  268. DO J = jts, jte
  269. DO I = its, ite
  270. p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
  271. grid%mub(i,j) = p_surf-grid%p_top
  272. ! this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
  273. ! interp theta (from interp) and compute 1/rho from eqn. of state
  274. DO K = 1, kte-1
  275. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  276. grid%pb(i,k,j) = p_level
  277. grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
  278. grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
  279. ENDDO
  280. ! calc hydrostatic balance (alternatively we could interp the geopotential from the
  281. ! sounding, but this assures that the base state is in exact hydrostatic balance with
  282. ! respect to the model eqns.
  283. DO k = 2,kte
  284. grid%phb(i,k,j) = grid%phb(i,k-1,j) - grid%dnw(k-1)*grid%mub(i,j)*grid%alb(i,k-1,j)
  285. ENDDO
  286. ENDDO
  287. ENDDO
  288. IF ( wrf_dm_on_monitor() ) THEN
  289. write(6,*) ' ptop is ',grid%p_top
  290. write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
  291. ENDIF
  292. ! calculate full state for each column - this includes moisture.
  293. write(6,*) ' getting moist sounding for full state '
  294. dry_sounding = .false.
  295. CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
  296. DO J = jts, min(jde-1,jte)
  297. DO I = its, min(ide-1,ite)
  298. ! At this point grid%p_top is already set. find the DRY mass in the column
  299. ! by interpolating the DRY pressure.
  300. pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
  301. ! compute the perturbation mass and the full mass
  302. grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
  303. grid%mu_2(i,j) = grid%mu_1(i,j)
  304. grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
  305. ! given the dry pressure and coordinate system, interp the potential
  306. ! temperature and qv
  307. do k=1,kde-1
  308. p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
  309. moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
  310. grid%t_1(i,k,j) = interp_0( theta, pd_in, p_level, nl_in ) - t0
  311. grid%t_2(i,k,j) = grid%t_1(i,k,j)
  312. enddo
  313. ! integrate the hydrostatic equation (from the RHS of the bigstep
  314. ! vertical momentum equation) down from the top to get grid%p.
  315. ! first from the top of the model to the top pressure
  316. k = kte-1 ! top level
  317. qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
  318. qvf2 = 1./(1.+qvf1)
  319. qvf1 = qvf1*qvf2
  320. ! grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
  321. grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
  322. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  323. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  324. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  325. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  326. ! down the column
  327. do k=kte-2,1,-1
  328. qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
  329. qvf2 = 1./(1.+qvf1)
  330. qvf1 = qvf1*qvf2
  331. grid%p(i,k,j) = grid%p(i,k+1,j) - (grid%mu_1(i,j) + qvf1*grid%mub(i,j))/qvf2/grid%rdn(k+1)
  332. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  333. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  334. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  335. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  336. enddo
  337. ! this is the hydrostatic equation used in the model after the
  338. ! small timesteps. In the model, grid%al (inverse density)
  339. ! is computed from the geopotential.
  340. grid%ph_1(i,1,j) = 0.
  341. DO k = 2,kte
  342. grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*( &
  343. (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
  344. grid%mu_1(i,j)*grid%alb(i,k-1,j) )
  345. grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
  346. grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
  347. ENDDO
  348. IF ( wrf_dm_on_monitor() ) THEN
  349. if((i==2) .and. (j==2)) then
  350. write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
  351. grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
  352. grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
  353. endif
  354. ENDIF
  355. ENDDO
  356. ENDDO
  357. !#if 0
  358. ! thermal perturbation to kick off convection
  359. write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
  360. write(6,*) ' delt for perturbation ',delt
  361. ! For LES, change the initial random perturbations
  362. ! For 2D test, call randx outside I-loop
  363. ! For 3D runs, call randx inside both I-J loops
  364. DO J = jts, min(jde-1,jte)
  365. ! yrad = config_flags%dy*float(j-nyc)/10000.
  366. yrad = 0.
  367. DO I = its, min(ide-1,ite)
  368. ! xrad = config_flags%dx*float(i-nxc)/10000.
  369. xrad = 0.
  370. call random_number (randx)
  371. randx = randx - 0.5
  372. ! DO K = 1, kte-1
  373. DO K = 1, 4
  374. ! No bubbles for LES!
  375. ! put in preturbation theta (bubble) and recalc density. note,
  376. ! the mass in the column is not changing, so when theta changes,
  377. ! we recompute density and geopotential
  378. ! zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j) &
  379. ! +grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
  380. ! zrad = (zrad-1500.)/1500.
  381. zrad = 0.
  382. RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
  383. IF(RAD <= 1.) THEN
  384. ! grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
  385. grid%t_1(i,k,j)=grid%t_1(i,k,j)+ 0.1 *randx
  386. grid%t_2(i,k,j)=grid%t_1(i,k,j)
  387. qvf = 1. + rvovrd*moist(i,k,j,P_QV)
  388. grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
  389. (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
  390. grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
  391. ENDIF
  392. ENDDO
  393. ! rebalance hydrostatically
  394. DO k = 2,kte
  395. grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*( &
  396. (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
  397. grid%mu_1(i,j)*grid%alb(i,k-1,j) )
  398. grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
  399. grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
  400. ENDDO
  401. ENDDO
  402. ENDDO
  403. !#endif
  404. IF ( wrf_dm_on_monitor() ) THEN
  405. write(6,*) ' grid%mu_1 from comp ', grid%mu_1(1,1)
  406. write(6,*) ' full state sounding from comp, ph, grid%p, grid%al, grid%t_1, qv '
  407. do k=1,kde-1
  408. write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1)+grid%phb(1,k,1), &
  409. grid%p(1,k,1)+grid%pb(1,k,1), grid%alt(1,k,1), &
  410. grid%t_1(1,k,1)+t0, moist(1,k,1,P_QV)
  411. enddo
  412. write(6,*) ' pert state sounding from comp, grid%ph_1, pp, alp, grid%t_1, qv '
  413. do k=1,kde-1
  414. write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1), &
  415. grid%p(1,k,1), grid%al(1,k,1), &
  416. grid%t_1(1,k,1), moist(1,k,1,P_QV)
  417. enddo
  418. ENDIF
  419. ! interp v
  420. DO J = jts, jte
  421. DO I = its, min(ide-1,ite)
  422. IF (j == jds) THEN
  423. z_at_v = grid%phb(i,1,j)/g
  424. ELSE IF (j == jde) THEN
  425. z_at_v = grid%phb(i,1,j-1)/g
  426. ELSE
  427. z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
  428. END IF
  429. p_surf = interp_0( p_in, zk, z_at_v, nl_in )
  430. DO K = 1, kte-1
  431. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  432. grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
  433. grid%v_2(i,k,j) = grid%v_1(i,k,j)
  434. ENDDO
  435. ENDDO
  436. ENDDO
  437. ! interp u
  438. DO J = jts, min(jde-1,jte)
  439. DO I = its, ite
  440. IF (i == ids) THEN
  441. z_at_u = grid%phb(i,1,j)/g
  442. ELSE IF (i == ide) THEN
  443. z_at_u = grid%phb(i-1,1,j)/g
  444. ELSE
  445. z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
  446. END IF
  447. p_surf = interp_0( p_in, zk, z_at_u, nl_in )
  448. DO K = 1, kte-1
  449. p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  450. grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
  451. grid%u_2(i,k,j) = grid%u_1(i,k,j)
  452. ENDDO
  453. ENDDO
  454. ENDDO
  455. ! set w
  456. DO J = jts, min(jde-1,jte)
  457. DO K = kts, kte
  458. DO I = its, min(ide-1,ite)
  459. grid%w_1(i,k,j) = 0.
  460. grid%w_2(i,k,j) = 0.
  461. ENDDO
  462. ENDDO
  463. ENDDO
  464. ! set a few more things
  465. DO J = jts, min(jde-1,jte)
  466. DO K = kts, kte-1
  467. DO I = its, min(ide-1,ite)
  468. grid%h_diabatic(i,k,j) = 0.
  469. ENDDO
  470. ENDDO
  471. ENDDO
  472. IF ( wrf_dm_on_monitor() ) THEN
  473. DO k=1,kte-1
  474. grid%t_base(k) = grid%t_1(1,k,1)
  475. grid%qv_base(k) = moist(1,k,1,P_QV)
  476. grid%u_base(k) = grid%u_1(1,k,1)
  477. grid%v_base(k) = grid%v_1(1,k,1)
  478. grid%z_base(k) = 0.5*(grid%phb(1,k,1)+grid%phb(1,k+1,1)+grid%ph_1(1,k,1)+grid%ph_1(1,k+1,1))/g
  479. ENDDO
  480. ENDIF
  481. CALL wrf_dm_bcast_real( grid%t_base , kte )
  482. CALL wrf_dm_bcast_real( grid%qv_base , kte )
  483. CALL wrf_dm_bcast_real( grid%u_base , kte )
  484. CALL wrf_dm_bcast_real( grid%v_base , kte )
  485. CALL wrf_dm_bcast_real( grid%z_base , kte )
  486. DO J = jts, min(jde-1,jte)
  487. DO I = its, min(ide-1,ite)
  488. thtmp = grid%t_2(i,1,j)+t0
  489. ptmp = grid%p(i,1,j)+grid%pb(i,1,j)
  490. temp(1) = thtmp * (ptmp/p1000mb)**rcp
  491. thtmp = grid%t_2(i,2,j)+t0
  492. ptmp = grid%p(i,2,j)+grid%pb(i,2,j)
  493. temp(2) = thtmp * (ptmp/p1000mb)**rcp
  494. thtmp = grid%t_2(i,3,j)+t0
  495. ptmp = grid%p(i,3,j)+grid%pb(i,3,j)
  496. temp(3) = thtmp * (ptmp/p1000mb)**rcp
  497. ! For LES-CBL, add 5 degrees to the surface temperature!
  498. !
  499. ! grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
  500. grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)+5.
  501. grid%tmn(I,J)=grid%tsk(I,J)-0.5
  502. ENDDO
  503. ENDDO
  504. END SUBROUTINE init_domain_rk
  505. SUBROUTINE init_module_initialize
  506. END SUBROUTINE init_module_initialize
  507. !---------------------------------------------------------------------
  508. ! test driver for get_sounding
  509. !
  510. ! implicit none
  511. ! integer n
  512. ! parameter(n = 1000)
  513. ! real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
  514. ! logical dry
  515. ! integer nl,k
  516. !
  517. ! dry = .false.
  518. ! dry = .true.
  519. ! call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
  520. ! write(6,*) ' input levels ',nl
  521. ! write(6,*) ' sounding '
  522. ! write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
  523. ! do k=1,nl
  524. ! write(6,'(1x,i3,8(1x,1pe10.3))') k, zk(k), p(k), pd(k), theta(k), rho(k), u(k), v(k), qv(k)
  525. ! enddo
  526. ! end
  527. !
  528. !---------------------------------------------------------------------------
  529. subroutine get_sounding( zk, p, p_dry, theta, rho, &
  530. u, v, qv, dry, nl_max, nl_in )
  531. implicit none
  532. integer nl_max, nl_in
  533. real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
  534. u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
  535. logical dry
  536. integer n
  537. parameter(n=1000)
  538. logical debug
  539. parameter( debug = .true.)
  540. ! input sounding data
  541. real p_surf, th_surf, qv_surf
  542. real pi_surf, pi(n)
  543. real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
  544. ! diagnostics
  545. real rho_surf, p_input(n), rho_input(n)
  546. real pm_input(n) ! this are for full moist sounding
  547. ! local data
  548. real r
  549. parameter (r = r_d)
  550. integer k, it, nl
  551. real qvf, qvf1, dz
  552. ! first, read the sounding
  553. call read_sounding( p_surf, th_surf, qv_surf, &
  554. h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
  555. if(dry) then
  556. do k=1,nl
  557. qv_input(k) = 0.
  558. enddo
  559. endif
  560. if(debug) write(6,*) ' number of input levels = ',nl
  561. nl_in = nl
  562. if(nl_in .gt. nl_max ) then
  563. write(6,*) ' too many levels for input arrays ',nl_in,nl_max
  564. call wrf_error_fatal ( ' too many levels for input arrays ' )
  565. end if
  566. ! compute diagnostics,
  567. ! first, convert qv(g/kg) to qv(g/g)
  568. do k=1,nl
  569. qv_input(k) = 0.001*qv_input(k)
  570. enddo
  571. p_surf = 100.*p_surf ! convert to pascals
  572. qvf = 1. + rvovrd*qv_input(1)
  573. rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
  574. pi_surf = (p_surf/p1000mb)**(r/cp)
  575. if(debug) then
  576. write(6,*) ' surface density is ',rho_surf
  577. write(6,*) ' surface pi is ',pi_surf
  578. end if
  579. ! integrate moist sounding hydrostatically, starting from the
  580. ! specified surface pressure
  581. ! -> first, integrate from surface to lowest level
  582. qvf = 1. + rvovrd*qv_input(1)
  583. qvf1 = 1. + qv_input(1)
  584. rho_input(1) = rho_surf
  585. dz = h_input(1)
  586. do it=1,10
  587. pm_input(1) = p_surf &
  588. - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
  589. rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
  590. enddo
  591. ! integrate up the column
  592. do k=2,nl
  593. rho_input(k) = rho_input(k-1)
  594. dz = h_input(k)-h_input(k-1)
  595. qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
  596. qvf = 1. + rvovrd*qv_input(k) ! qv is in g/kg here
  597. do it=1,10
  598. pm_input(k) = pm_input(k-1) &
  599. - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
  600. rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
  601. enddo
  602. enddo
  603. ! we have the moist sounding
  604. ! next, compute the dry sounding using p at the highest level from the
  605. ! moist sounding and integrating down.
  606. p_input(nl) = pm_input(nl)
  607. do k=nl-1,1,-1
  608. dz = h_input(k+1)-h_input(k)
  609. p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
  610. enddo
  611. do k=1,nl
  612. zk(k) = h_input(k)
  613. p(k) = pm_input(k)
  614. p_dry(k) = p_input(k)
  615. theta(k) = th_input(k)
  616. rho(k) = rho_input(k)
  617. u(k) = u_input(k)
  618. v(k) = v_input(k)
  619. qv(k) = qv_input(k)
  620. enddo
  621. if(debug) then
  622. write(6,*) ' sounding '
  623. write(6,*) ' k height(m) press (Pa) pd(Pa) theta (K) den(kg/m^3) u(m/s) v(m/s) qv(g/g) '
  624. do k=1,nl
  625. write(6,'(1x,i3,8(1x,1pe10.3))') k, zk(k), p(k), p_dry(k), theta(k), rho(k), u(k), v(k), qv(k)
  626. enddo
  627. end if
  628. end subroutine get_sounding
  629. !-------------------------------------------------------
  630. subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
  631. implicit none
  632. integer n,nl
  633. real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
  634. logical end_of_file
  635. logical debug
  636. integer k
  637. open(unit=10,file='input_sounding',form='formatted',status='old')
  638. rewind(10)
  639. read(10,*) ps, ts, qvs
  640. if(debug) then
  641. write(6,*) ' input sounding surface parameters '
  642. write(6,*) ' surface pressure (mb) ',ps
  643. write(6,*) ' surface pot. temp (K) ',ts
  644. write(6,*) ' surface mixing ratio (g/kg) ',qvs
  645. end if
  646. end_of_file = .false.
  647. k = 0
  648. do while (.not. end_of_file)
  649. read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
  650. k = k+1
  651. if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
  652. go to 110
  653. 100 end_of_file = .true.
  654. 110 continue
  655. enddo
  656. nl = k
  657. close(unit=10,status = 'keep')
  658. end subroutine read_sounding
  659. END MODULE module_initialize_ideal