PageRenderTime 51ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/dyn_em/start_em.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 1384 lines | 921 code | 179 blank | 284 comment | 21 complexity | e3c03e161a53959e527bf6ad04cf0a39 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !-------------------------------------------------------------------
  2. SUBROUTINE start_domain_em ( grid, allowed_to_read &
  3. ! Actual arguments generated from Registry
  4. # include "dummy_new_args.inc"
  5. !
  6. )
  7. USE module_domain, ONLY : domain, wrfu_timeinterval, get_ijk_from_grid, &
  8. domain_setgmtetc
  9. USE module_state_description
  10. USE module_model_constants
  11. USE module_bc, ONLY : boundary_condition_check, set_physical_bc2d
  12. USE module_bc_em
  13. USE module_configure, ONLY : grid_config_rec_type
  14. USE module_tiles, ONLY : set_tiles
  15. #ifdef DM_PARALLEL
  16. USE module_dm, ONLY : wrf_dm_min_real, wrf_dm_max_real, wrf_dm_maxval, &
  17. ntasks_x, ntasks_y, &
  18. local_communicator_periodic, local_communicator, mytask, ntasks
  19. #else
  20. USE module_dm, ONLY : wrf_dm_min_real, wrf_dm_max_real
  21. #endif
  22. USE module_comm_dm
  23. USE module_physics_init
  24. USE module_fr_sfire_driver_wrf, ONLY : sfire_driver_em_init
  25. USE module_stoch, ONLY : SETUP_STOCH,rand_seed, update_stoch
  26. #ifdef WRF_CHEM
  27. USE module_aerosols_sorgam, ONLY: sum_pm_sorgam
  28. USE module_gocart_aerosols, ONLY: sum_pm_gocart
  29. USE module_mosaic_driver, ONLY: sum_pm_mosaic
  30. USE module_input_tracer, ONLY: initialize_tracer
  31. USE module_aerosols_soa_vbs, only: sum_pm_soa_vbs
  32. #endif
  33. !!debug
  34. !USE module_compute_geop
  35. USE module_model_constants
  36. USE module_avgflx_em, ONLY : zero_avgflx
  37. IMPLICIT NONE
  38. ! Input data.
  39. TYPE (domain) :: grid
  40. LOGICAL , INTENT(IN) :: allowed_to_read
  41. ! Definitions of dummy arguments to this routine (generated from Registry).
  42. # include "dummy_new_decl.inc"
  43. ! Structure that contains run-time configuration (namelist) data for domain
  44. TYPE (grid_config_rec_type) :: config_flags
  45. ! Local data
  46. INTEGER :: &
  47. ids, ide, jds, jde, kds, kde, &
  48. ims, ime, jms, jme, kms, kme, &
  49. ips, ipe, jps, jpe, kps, kpe, &
  50. its, ite, jts, jte, kts, kte, &
  51. ij,i,j,k,ii,jj,kk,loop,error,l
  52. INTEGER :: imsx, imex, jmsx, jmex, kmsx, kmex, &
  53. ipsx, ipex, jpsx, jpex, kpsx, kpex, &
  54. imsy, imey, jmsy, jmey, kmsy, kmey, &
  55. ipsy, ipey, jpsy, jpey, kpsy, kpey
  56. INTEGER :: i_m
  57. REAL :: p00, t00, a, tiso, p_surf, pd_surf, temp
  58. #ifdef WRF_CHEM
  59. REAL RGASUNIV ! universal gas constant [ J/mol-K ]
  60. PARAMETER ( RGASUNIV = 8.314510 )
  61. REAL,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) :: &
  62. z_at_w,convfac
  63. REAL :: tempfac
  64. #endif
  65. REAL :: qvf1, qvf2, qvf
  66. REAL :: pfu, pfd, phm
  67. REAL :: MPDT
  68. REAL :: spongeweight
  69. LOGICAL :: first_trip_for_this_domain, start_of_simulation, fill_w_flag
  70. LOGICAL, EXTERNAL :: wrf_dm_on_monitor
  71. #ifndef WRF_CHEM
  72. REAL,ALLOCATABLE,DIMENSION(:,:,:) :: cldfra_old
  73. #endif
  74. REAL :: lat1 , lat2 , lat3 , lat4
  75. REAL :: lon1 , lon2 , lon3 , lon4
  76. INTEGER :: num_points_lat_lon , iloc , jloc
  77. CHARACTER (LEN=132) :: message
  78. TYPE(WRFU_TimeInterval) :: stepTime
  79. REAL, DIMENSION(:,:), ALLOCATABLE :: clat_glob
  80. logical :: f_flux ! flag for computing averaged fluxes in cu_gd
  81. INTEGER :: idex, jdex
  82. INTEGER :: im1,ip1,jm1,jp1
  83. REAL :: hx,hy,pi
  84. REAL :: w_max, w_min
  85. LOGICAL :: w_needs_to_be_set
  86. !
  87. ! paj: define variable local
  88. REAL :: alpha
  89. CALL get_ijk_from_grid ( grid , &
  90. ids, ide, jds, jde, kds, kde, &
  91. ims, ime, jms, jme, kms, kme, &
  92. ips, ipe, jps, jpe, kps, kpe, &
  93. imsx, imex, jmsx, jmex, kmsx, kmex, &
  94. ipsx, ipex, jpsx, jpex, kpsx, kpex, &
  95. imsy, imey, jmsy, jmey, kmsy, kmey, &
  96. ipsy, ipey, jpsy, jpey, kpsy, kpey )
  97. kts = kps ; kte = kpe ! note that tile is entire patch
  98. its = ips ; ite = ipe ! note that tile is entire patch
  99. jts = jps ; jte = jpe ! note that tile is entire patch
  100. #ifndef WRF_CHEM
  101. ALLOCATE(CLDFRA_OLD(IMS:IME,KMS:KME,JMS:JME),STAT=I) ; CLDFRA_OLD = 0.
  102. #endif
  103. CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
  104. IF ( ( MOD (ide-ids,config_flags%parent_grid_ratio) .NE. 0 ) .OR. &
  105. ( MOD (jde-jds,config_flags%parent_grid_ratio) .NE. 0 ) ) THEN
  106. WRITE(message, FMT='("Nested dimensions are illegal for domain ",I2,": Both &
  107. &MOD(",I4,"-",I1,",",I2,") and MOD(",I4,"-",I1,",",I2,") must = 0" )') &
  108. grid%id,ide,ids,config_flags%parent_grid_ratio,jde,jds,config_flags%parent_grid_ratio
  109. CALL wrf_error_fatal ( message )
  110. END IF
  111. IF ( config_flags%polar ) THEN
  112. !write(0,*)__FILE__,__LINE__,' clat ',ips,ipe,jps,jpe
  113. !do j = jps,jpe
  114. !write(0,*)__FILE__,__LINE__,' clat ',ids,j,grid%clat(ips,j)
  115. !enddo
  116. #ifdef DM_PARALLEL
  117. ! WARNING: this might present scaling issues on very large numbers of processors
  118. ALLOCATE( clat_glob(ids:ide,jds:jde) )
  119. CALL wrf_patch_to_global_real ( grid%clat, clat_glob, grid%domdesc, 'xy', 'xy', &
  120. ids, ide, jds, jde, 1, 1, &
  121. ims, ime, jms, jme, 1, 1, &
  122. its, ite, jts, jte, 1, 1 )
  123. CALL wrf_dm_bcast_real ( clat_glob , (ide-ids+1)*(jde-jds+1) )
  124. grid%clat_xxx(ipsx:ipex,jpsx:jpex) = clat_glob(ipsx:ipex,jpsx:jpex)
  125. DEALLOCATE( clat_glob )
  126. #endif
  127. ENDIF
  128. ! here we check to see if the boundary conditions are set properly
  129. CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
  130. !kludge - need to stop CG from resetting precip and phys tendencies to zero
  131. ! when we are in here due to a nest being spawned, we want to still
  132. ! recompute the base state, but that is about it
  133. ! This is temporary and will need to be changed when grid%itimestep is removed.
  134. IF ( grid%itimestep .EQ. 0 ) THEN
  135. first_trip_for_this_domain = .TRUE.
  136. ELSE
  137. first_trip_for_this_domain = .FALSE.
  138. END IF
  139. IF ( .not. ( config_flags%restart .or. grid%moved ) ) THEN
  140. grid%itimestep=0
  141. ENDIF
  142. IF ( config_flags%restart .or. grid%moved ) THEN
  143. first_trip_for_this_domain = .TRUE.
  144. ENDIF
  145. ! --- SETUP AND INITIALIZE STOCHASTIC KINETIC ENERGY BACKSCATTER SCHEME ---
  146. IF ( first_trip_for_this_domain ) THEN
  147. grid%did_stoch = .FALSE.
  148. END IF
  149. IF ( ( grid%id == 1 ) .AND. &
  150. ( NINT(grid%stoch_force_global_opt) == 1 ) .AND. &
  151. ( .NOT. grid%did_stoch ) ) THEN
  152. grid%did_stoch = .TRUE.
  153. IF ( wrf_dm_on_monitor () ) THEN
  154. CALL rand_seed ( config_flags, grid%SEED1, grid%SEED2, grid%NENS )
  155. ENDIF
  156. #ifdef DM_PARALLEL
  157. CALL wrf_dm_bcast_bytes ( grid%SEED1, IWORDSIZE )
  158. CALL wrf_dm_bcast_bytes ( grid%SEED2, IWORDSIZE )
  159. #endif
  160. call SETUP_STOCH(grid%VERTSTRUCC,grid%VERTSTRUCS, &
  161. grid%SPT_AMP,grid%SPSTREAM_AMP, &
  162. grid%stoch_vertstruc_opt, &
  163. grid%SEED1,grid%SEED2,grid%time_step, &
  164. grid%DX,grid%DY, &
  165. grid%TOT_BACKSCAT_PSI,grid%TOT_BACKSCAT_T, &
  166. ids, ide, jds, jde, kds, kde, &
  167. ims, ime, jms, jme, kms, kme, &
  168. its, ite, jts, jte, kts, kte )
  169. END IF
  170. ! --- END SETUP STOCHASTIC KINETIC ENERGY BACKSCATTER SCHEME ----------
  171. ! wig: Add a combined exponential+linear weight on the mother boundaries
  172. ! following code changes by Ruby Leung. For the nested grid, there
  173. ! appears to be some problems when a sponge is used. The points where
  174. ! processors meet have problematic values.
  175. CALL lbc_fcx_gcx ( grid%fcx , grid%gcx , grid%spec_bdy_width , &
  176. grid%spec_zone , grid%relax_zone , grid%dt , config_flags%spec_exp , &
  177. config_flags%specified , config_flags%nested )
  178. IF ( config_flags%nested ) THEN
  179. grid%dtbc = 0.
  180. ENDIF
  181. IF ( ( grid%id .NE. 1 ) .AND. ( .NOT. config_flags%input_from_file ) ) THEN
  182. ! Every time a domain starts or every time a domain moves, this routine is called. We want
  183. ! the center (middle) lat/lon of the grid for the metacode. The lat/lon values are
  184. ! defined at mass points. Depending on the even/odd points in the SN and WE directions,
  185. ! we end up with the middle point as either 1 point or an average of either 2 or 4 points.
  186. ! Add to this, the need to make sure that we are on the correct patch to retrieve the
  187. ! value of the lat/lon, AND that the lat/lons (for an average) may not all be on the same
  188. ! patch. Once we find the correct value for lat lon, we need to keep it around on all patches,
  189. ! which is where the wrf_dm_min_real calls come in.
  190. ! If this is the most coarse domain, we do not go in here. Also, if there is an input file
  191. ! (which has the right values for the middle lat/lon) we do not go in this IF test.
  192. IF ( ( MOD(ide,2) .EQ. 0 ) .AND. ( MOD(jde,2) .EQ. 0 ) ) THEN
  193. num_points_lat_lon = 1
  194. iloc = ide/2
  195. jloc = jde/2
  196. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  197. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  198. lat1 = grid%xlat (iloc,jloc)
  199. lon1 = grid%xlong(iloc,jloc)
  200. ELSE
  201. lat1 = 99999.
  202. lon1 = 99999.
  203. END IF
  204. lat1 = wrf_dm_min_real ( lat1 )
  205. lon1 = wrf_dm_min_real ( lon1 )
  206. CALL nl_set_cen_lat ( grid%id , lat1 )
  207. CALL nl_set_cen_lon ( grid%id , lon1 )
  208. ELSE IF ( ( MOD(ide,2) .NE. 0 ) .AND. ( MOD(jde,2) .EQ. 0 ) ) THEN
  209. num_points_lat_lon = 2
  210. iloc = (ide-1)/2
  211. jloc = jde /2
  212. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  213. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  214. lat1 = grid%xlat (iloc,jloc)
  215. lon1 = grid%xlong(iloc,jloc)
  216. ELSE
  217. lat1 = 99999.
  218. lon1 = 99999.
  219. END IF
  220. lat1 = wrf_dm_min_real ( lat1 )
  221. lon1 = wrf_dm_min_real ( lon1 )
  222. iloc = (ide+1)/2
  223. jloc = jde /2
  224. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  225. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  226. lat2 = grid%xlat (iloc,jloc)
  227. lon2 = grid%xlong(iloc,jloc)
  228. ELSE
  229. lat2 = 99999.
  230. lon2 = 99999.
  231. END IF
  232. lat2 = wrf_dm_min_real ( lat2 )
  233. lon2 = wrf_dm_min_real ( lon2 )
  234. CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 ) * 0.50 )
  235. CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 ) * 0.50 )
  236. ELSE IF ( ( MOD(ide,2) .EQ. 0 ) .AND. ( MOD(jde,2) .NE. 0 ) ) THEN
  237. num_points_lat_lon = 2
  238. iloc = ide /2
  239. jloc = (jde-1)/2
  240. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  241. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  242. lat1 = grid%xlat (iloc,jloc)
  243. lon1 = grid%xlong(iloc,jloc)
  244. ELSE
  245. lat1 = 99999.
  246. lon1 = 99999.
  247. END IF
  248. lat1 = wrf_dm_min_real ( lat1 )
  249. lon1 = wrf_dm_min_real ( lon1 )
  250. iloc = ide /2
  251. jloc = (jde+1)/2
  252. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  253. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  254. lat2 = grid%xlat (iloc,jloc)
  255. lon2 = grid%xlong(iloc,jloc)
  256. ELSE
  257. lat2 = 99999.
  258. lon2 = 99999.
  259. END IF
  260. lat2 = wrf_dm_min_real ( lat2 )
  261. lon2 = wrf_dm_min_real ( lon2 )
  262. CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 ) * 0.50 )
  263. CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 ) * 0.50 )
  264. ELSE IF ( ( MOD(ide,2) .NE. 0 ) .AND. ( MOD(jde,2) .NE. 0 ) ) THEN
  265. num_points_lat_lon = 4
  266. iloc = (ide-1)/2
  267. jloc = (jde-1)/2
  268. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  269. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  270. lat1 = grid%xlat (iloc,jloc)
  271. lon1 = grid%xlong(iloc,jloc)
  272. ELSE
  273. lat1 = 99999.
  274. lon1 = 99999.
  275. END IF
  276. lat1 = wrf_dm_min_real ( lat1 )
  277. lon1 = wrf_dm_min_real ( lon1 )
  278. iloc = (ide+1)/2
  279. jloc = (jde-1)/2
  280. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  281. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  282. lat2 = grid%xlat (iloc,jloc)
  283. lon2 = grid%xlong(iloc,jloc)
  284. ELSE
  285. lat2 = 99999.
  286. lon2 = 99999.
  287. END IF
  288. lat2 = wrf_dm_min_real ( lat2 )
  289. lon2 = wrf_dm_min_real ( lon2 )
  290. iloc = (ide-1)/2
  291. jloc = (jde+1)/2
  292. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  293. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  294. lat3 = grid%xlat (iloc,jloc)
  295. lon3 = grid%xlong(iloc,jloc)
  296. ELSE
  297. lat3 = 99999.
  298. lon3 = 99999.
  299. END IF
  300. lat3 = wrf_dm_min_real ( lat3 )
  301. lon3 = wrf_dm_min_real ( lon3 )
  302. iloc = (ide+1)/2
  303. jloc = (jde+1)/2
  304. IF ( ( ips .LE. iloc ) .AND. ( ipe .GE. iloc ) .AND. &
  305. ( jps .LE. jloc ) .AND. ( jpe .GE. jloc ) ) THEN
  306. lat4 = grid%xlat (iloc,jloc)
  307. lon4 = grid%xlong(iloc,jloc)
  308. ELSE
  309. lat4 = 99999.
  310. lon4 = 99999.
  311. END IF
  312. lat4 = wrf_dm_min_real ( lat4 )
  313. lon4 = wrf_dm_min_real ( lon4 )
  314. CALL nl_set_cen_lat ( grid%id , ( lat1 + lat2 + lat3 + lat4 ) * 0.25 )
  315. CALL nl_set_cen_lon ( grid%id , ( lon1 + lon2 + lon3 + lon4 ) * 0.25 )
  316. END IF
  317. END IF
  318. IF ( .NOT. config_flags%restart .AND. &
  319. (( config_flags%input_from_hires ) .OR. ( config_flags%input_from_file ))) THEN
  320. IF ( config_flags%map_proj .EQ. 0 ) THEN
  321. CALL wrf_error_fatal ( 'start_domain: Idealized case cannot have a separate nested input file' )
  322. END IF
  323. IF ( config_flags%use_baseparam_fr_nml ) then
  324. CALL nl_get_base_pres ( 1 , p00 )
  325. CALL nl_get_base_temp ( 1 , t00 )
  326. CALL nl_get_base_lapse ( 1 , a )
  327. CALL nl_get_iso_temp ( 1 , tiso )
  328. ELSE
  329. ! get these constants from model data
  330. t00 = grid%t00
  331. p00 = grid%p00
  332. a = grid%tlp
  333. tiso = grid%tiso
  334. IF (t00 .LT. 100. .or. p00 .LT. 10000.) THEN
  335. WRITE(wrf_err_message,*)&
  336. 'start_em: did not find base state parameters in wrfinput. Add use_baseparam_fr_nml = .t. in &dynamics and rerun'
  337. CALL wrf_error_fatal(TRIM(wrf_err_message))
  338. ENDIF
  339. ENDIF
  340. ! Base state potential temperature and inverse density (alpha = 1/rho) from
  341. ! the half eta levels and the base-profile surface pressure. Compute 1/rho
  342. ! from equation of state. The potential temperature is a perturbation from t0.
  343. DO j = jts, MIN(jte,jde-1)
  344. DO i = its, MIN(ite,ide-1)
  345. ! Base state pressure is a function of eta level and terrain, only, plus
  346. ! the hand full of constants: p00 (sea level pressure, Pa), t00 (sea level
  347. ! temperature, K), and A (temperature difference, from 1000 mb to 300 mb, K).
  348. p_surf = p00 * EXP ( -t00/a + ( (t00/a)**2 - 2.*g*grid%ht(i,j)/a/r_d ) **0.5 )
  349. DO k = 1, kte-1
  350. grid%pb(i,k,j) = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
  351. temp = MAX ( tiso, t00 + A*LOG(grid%pb(i,k,j)/p00) )
  352. grid%t_init(i,k,j) = temp*(p00/grid%pb(i,k,j))**(r_d/cp) - t0
  353. ! grid%t_init(i,k,j) = (t00 + A*LOG(grid%pb(i,k,j)/p00))*(p00/grid%pb(i,k,j))**(r_d/cp) - t0
  354. grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
  355. END DO
  356. ! Base state mu is defined as base state surface pressure minus grid%p_top
  357. grid%mub(i,j) = p_surf - grid%p_top
  358. ! Integrate base geopotential, starting at terrain elevation. This assures that
  359. ! the base state is in exact hydrostatic balance with respect to the model equations.
  360. ! This field is on full levels.
  361. grid%phb(i,1,j) = grid%ht(i,j) * g
  362. IF ( config_flags%hypsometric_opt .EQ. 1 ) THEN
  363. DO k = 2,kte
  364. 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)
  365. END DO
  366. ELSE IF ( config_flags%hypsometric_opt .EQ. 2 ) THEN
  367. DO k = 2,kte
  368. pfu = grid%mub(i,j)*grid%znw(k) + grid%p_top
  369. pfd = grid%mub(i,j)*grid%znw(k-1) + grid%p_top
  370. phm = grid%mub(i,j)*grid%znu(k-1) + grid%p_top
  371. grid%phb(i,k,j) = grid%phb(i,k-1,j) + grid%alb(i,k-1,j)*phm*LOG(pfd/pfu)
  372. END DO
  373. END IF
  374. END DO
  375. END DO
  376. ENDIF
  377. IF(.not.config_flags%restart)THEN
  378. ! if this is for a nested domain, the defined/interpolated fields are the _2
  379. IF ( first_trip_for_this_domain ) THEN
  380. ! data that is expected to be zero must be explicitly initialized as such
  381. ! grid%h_diabatic = 0.
  382. DO j = jts,min(jte,jde-1)
  383. DO k = kts,kte-1
  384. DO i = its, min(ite,ide-1)
  385. IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
  386. grid%t_1(i,k,j)=grid%t_2(i,k,j)
  387. ENDIF
  388. ENDDO
  389. ENDDO
  390. ENDDO
  391. DO j = jts,min(jte,jde-1)
  392. DO k = kts,kte
  393. DO i = its, min(ite,ide-1)
  394. grid%ph_1(i,k,j)=grid%ph_2(i,k,j)
  395. ENDDO
  396. ENDDO
  397. ENDDO
  398. DO j = jts,min(jte,jde-1)
  399. DO i = its, min(ite,ide-1)
  400. IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
  401. grid%mu_1(i,j)=grid%mu_2(i,j)
  402. ENDIF
  403. ENDDO
  404. ENDDO
  405. END IF
  406. ! reconstitute base-state fields
  407. IF(config_flags%max_dom .EQ. 1)THEN
  408. ! with single domain, grid%t_init from wrfinput is OK to use
  409. DO j = jts,min(jte,jde-1)
  410. DO k = kts,kte-1
  411. DO i = its, min(ite,ide-1)
  412. IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
  413. grid%pb(i,k,j) = grid%znu(k)*grid%mub(i,j)+grid%p_top
  414. grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
  415. ENDIF
  416. ENDDO
  417. ENDDO
  418. ENDDO
  419. ELSE
  420. ! with nests, grid%t_init generally needs recomputations (since it is not interpolated)
  421. DO j = jts,min(jte,jde-1)
  422. DO k = kts,kte-1
  423. DO i = its, min(ite,ide-1)
  424. IF ( grid%imask_nostag(i,j) .EQ. 1 ) THEN
  425. grid%pb(i,k,j) = grid%znu(k)*grid%mub(i,j)+grid%p_top
  426. grid%alb(i,k,j) = -grid%rdnw(k)*(grid%phb(i,k+1,j)-grid%phb(i,k,j))/grid%mub(i,j)
  427. grid%t_init(i,k,j) = grid%alb(i,k,j)*(p1000mb/r_d)/((grid%pb(i,k,j)/p1000mb)**cvpm) - t0
  428. ENDIF
  429. ENDDO
  430. ENDDO
  431. ENDDO
  432. ENDIF
  433. ! Use equations from calc_p_rho_phi to derive p and al from ph: linear in log p
  434. IF ( config_flags%hypsometric_opt .EQ. 1 ) THEN
  435. DO j=jts,min(jte,jde-1)
  436. DO k=kts,kte-1
  437. DO i=its,min(ite,ide-1)
  438. grid%al(i,k,j)=-1./(grid%mub(i,j)+grid%mu_1(i,j))*(grid%alb(i,k,j)*grid%mu_1(i,j) &
  439. +grid%rdnw(k)*(grid%ph_1(i,k+1,j)-grid%ph_1(i,k,j)))
  440. ENDDO
  441. ENDDO
  442. ENDDO
  443. ELSE IF ( config_flags%hypsometric_opt .EQ. 2 ) THEN
  444. DO j=jts,min(jte,jde-1)
  445. DO k=kts,kte-1
  446. DO i=its,min(ite,ide-1)
  447. pfu = (grid%mub(i,j)+grid%mu_1(i,j))*grid%znw(k+1)+grid%p_top
  448. pfd = (grid%mub(i,j)+grid%mu_1(i,j))*grid%znw(k) +grid%p_top
  449. phm = (grid%mub(i,j)+grid%mu_1(i,j))*grid%znu(k) +grid%p_top
  450. grid%al(i,k,j) = (grid%ph_1(i,k+1,j)-grid%ph_1(i,k,j)+grid%phb(i,k+1,j)-grid%phb(i,k,j)) &
  451. /phm/LOG(pfd/pfu)-grid%alb(i,k,j)
  452. ENDDO
  453. ENDDO
  454. ENDDO
  455. END IF
  456. DO j=jts,min(jte,jde-1)
  457. DO k=kts,kte-1
  458. DO i=its,min(ite,ide-1)
  459. qvf = 1.+rvovrd*moist(i,k,j,P_QV)
  460. grid%p(i,k,j)=p1000mb*( (r_d*(t0+grid%t_1(i,k,j))*qvf)/ &
  461. (p1000mb*(grid%al(i,k,j)+grid%alb(i,k,j))) )**cpovcv &
  462. -grid%pb(i,k,j)
  463. grid%p_hyd(i,k,j) = grid%p(i,k,j) + grid%pb(i,k,j)
  464. grid%alt(i,k,j) = grid%al(i,k,j) + grid%alb(i,k,j)
  465. ENDDO
  466. ENDDO
  467. ENDDO
  468. ENDIF
  469. IF ( grid%press_adj .and. ( grid%id .NE. 1 ) .AND. .NOT. ( config_flags%restart ) .AND. &
  470. ( ( config_flags%input_from_hires ) .OR. ( config_flags%input_from_file ) ) ) THEN
  471. DO j = jts, MIN(jte,jde-1)
  472. DO i = its, MIN(ite,ide-1)
  473. grid%mu_2(i,j) = grid%mu_2(i,j) + grid%al(i,1,j) / ( grid%alt(i,1,j) * grid%alb(i,1,j) ) * &
  474. g * ( grid%ht(i,j) - grid%ht_fine(i,j) )
  475. END DO
  476. END DO
  477. DO j = jts,min(jte,jde-1)
  478. DO i = its, min(ite,ide-1)
  479. grid%mu_1(i,j)=grid%mu_2(i,j)
  480. ENDDO
  481. ENDDO
  482. END IF
  483. IF ( first_trip_for_this_domain ) THEN
  484. CALL wrf_debug ( 100 , 'start_domain_em: Before call to phy_init' )
  485. ! namelist MPDT does not exist yet, so set it here
  486. ! MPDT is the call frequency for microphysics in minutes (0 means every step)
  487. MPDT = 0.
  488. ! set GMT outside of phy_init because phy_init may not be called on this
  489. ! process if, for example, it is a moving nest and if this part of the domain is not
  490. ! being initialized (not the leading edge).
  491. CALL domain_setgmtetc( grid, start_of_simulation )
  492. !-----------------------------------------------------------------------------
  493. ! Adaptive time step: Added by T. Hutchinson, WSI 11/6/07
  494. !
  495. !
  496. IF ( ( grid%use_adaptive_time_step ) .AND. &
  497. ( ( grid%dfi_opt .EQ. DFI_NODFI ) .OR. ( grid%dfi_stage .EQ. DFI_FST ) ) ) THEN
  498. ! Calculate any variables that were not set
  499. if (grid%starting_time_step == -1) then
  500. grid%starting_time_step = NINT(6 * MIN(grid%dx,grid%dy) / 1000)
  501. endif
  502. if (grid%max_time_step == -1) then
  503. grid%max_time_step = 3*grid%starting_time_step
  504. endif
  505. if (grid%min_time_step == -1) then
  506. grid%min_time_step = 0.5*grid%starting_time_step
  507. endif
  508. ! Set a starting timestep.
  509. grid%dt = grid%starting_time_step
  510. ! Initialize max cfl values
  511. grid%last_max_vert_cfl = 0
  512. grid%last_max_horiz_cfl = 0
  513. ! Check to assure that time_step_sound is to be dynamically set.
  514. CALL nl_set_time_step_sound ( 1 , 0 )
  515. grid%time_step_sound = 0
  516. grid%max_msftx=MAXVAL(grid%msftx)
  517. grid%max_msfty=MAXVAL(grid%msfty)
  518. #ifdef DM_PARALLEL
  519. CALL wrf_dm_maxval(grid%max_msftx, idex, jdex)
  520. CALL wrf_dm_maxval(grid%max_msfty, idex, jdex)
  521. #endif
  522. ! This first call just initializes variables.
  523. ! If a restart, get initialized variables from restart file
  524. IF ( .NOT. ( config_flags%restart ) ) then
  525. CALL adapt_timestep(grid, config_flags)
  526. END IF
  527. END IF
  528. ! End of adaptive time step modifications
  529. !-----------------------------------------------------------------------------
  530. CALL set_tiles ( grid , grid%imask_nostag, ims, ime, jms, jme, ips, ipe, jps, jpe )
  531. !
  532. ! Phy init can do reads and broadcasts when initializing physics -- landuse for example. However, if
  533. ! we're running on a reduced mesh (that is, some tasks don't have any work) we have to at least let them
  534. ! pass through this code so the broadcasts don't hang on the other, active tasks. Set the number of
  535. ! tiles to a minimum of 1 and assume that the backwards patch ranges (ips=0, ipe=-1) will prevent
  536. ! anything else from happening on the blank tasks. JM 20080605
  537. !
  538. if ( allowed_to_read ) grid%num_tiles = max(1,grid%num_tiles)
  539. !
  540. ! Phy_init is not necessarily thread-safe; do not multi-thread this loop.
  541. ! The tiling is to handle the fact that we may be masking off part of the computation.
  542. !
  543. DO ij = 1, grid%num_tiles
  544. !tgs do not need physics initialization for backward DFI integration
  545. IF ( grid%dfi_opt .NE. DFI_NODFI .and. grid%dfi_stage .EQ. DFI_FST) THEN !tgs
  546. grid%stepra=nint(grid%RADT*60./grid%DT)
  547. grid%stepra=max(grid%stepra,1)
  548. grid%stepbl=nint(grid%BLDT*60./grid%DT)
  549. grid%stepbl=max(grid%stepbl,1)
  550. grid%stepcu=nint(grid%CUDT*60./grid%DT)
  551. grid%stepcu=max(grid%stepcu,1)
  552. grid%stepfg=nint(grid%FGDT*60./grid%DT)
  553. grid%stepfg=max(grid%stepfg,1)
  554. ENDIF
  555. IF ( ( grid%dfi_opt .EQ. DFI_NODFI ) .or. &
  556. ( ( grid%dfi_stage .NE. DFI_BCK ) .and. &
  557. ( grid%dfi_stage .NE. DFI_STARTBCK ) ) ) THEN !tgs, mods by tah
  558. CALL phy_init ( grid%id , config_flags, grid%DT, grid%RESTART, grid%znw, grid%znu, &
  559. grid%p_top, grid%tsk, grid%RADT,grid%BLDT,grid%CUDT, MPDT, &
  560. grid%rucuten, grid%rvcuten, grid%rthcuten, &
  561. grid%rqvcuten, grid%rqrcuten, grid%rqccuten, &
  562. grid%rqscuten, grid%rqicuten, &
  563. grid%rushten, grid%rvshten, grid%rthshten, &
  564. grid%rqvshten, grid%rqrshten, grid%rqcshten, &
  565. grid%rqsshten, grid%rqishten, grid%rqgshten, &
  566. grid%rublten,grid%rvblten,grid%rthblten, &
  567. grid%rqvblten,grid%rqcblten,grid%rqiblten, &
  568. grid%rthraten,grid%rthratenlw,grid%rthratensw, &
  569. grid%stepbl,grid%stepra,grid%stepcu, &
  570. grid%w0avg, grid%rainnc, grid%rainc, grid%raincv, grid%rainncv, &
  571. grid%snownc, grid%snowncv, grid%graupelnc, grid%graupelncv, &
  572. grid%nca,grid%swrad_scat, &
  573. grid%cldefi,grid%lowlyr, &
  574. grid%mass_flux, &
  575. grid%rthften, grid%rqvften, &
  576. grid%cldfra, &
  577. #ifdef WRF_CHEM
  578. grid%cldfra_old, &
  579. #endif
  580. #ifndef WRF_CHEM
  581. cldfra_old, &
  582. #endif
  583. grid%glw,grid%gsw,grid%emiss,grid%embck, &
  584. grid%lu_index, &
  585. grid%landuse_ISICE, grid%landuse_LUCATS, &
  586. grid%landuse_LUSEAS, grid%landuse_ISN, &
  587. grid%lu_state, &
  588. grid%xlat,grid%xlong,grid%albedo,grid%albbck,grid%GMT,grid%JULYR,grid%JULDAY, &
  589. grid%levsiz, num_ozmixm, num_aerosolc, grid%paerlev, &
  590. grid%tmn,grid%xland,grid%znt,grid%z0,grid%ust,grid%mol,grid%pblh,grid%tke_pbl, &
  591. grid%exch_h,grid%thc,grid%snowc,grid%mavail,grid%hfx,grid%qfx,grid%rainbl, &
  592. grid%tslb,grid%zs,grid%dzs,config_flags%num_soil_layers,grid%warm_rain, &
  593. grid%adv_moist_cond, &
  594. grid%apr_gr,grid%apr_w,grid%apr_mc,grid%apr_st,grid%apr_as, &
  595. grid%apr_capma,grid%apr_capme,grid%apr_capmi, &
  596. grid%xice,grid%xicem,grid%vegfra,grid%snow,grid%canwat,grid%smstav, &
  597. grid%smstot, grid%sfcrunoff,grid%udrunoff,grid%grdflx,grid%acsnow, &
  598. grid%acsnom,grid%ivgtyp,grid%isltyp, grid%sfcevp,grid%smois, &
  599. grid%sh2o, grid%snowh, grid%smfr3d, &
  600. grid%snoalb, &
  601. grid%DX,grid%DY,grid%f_ice_phy,grid%f_rain_phy,grid%f_rimef_phy, &
  602. grid%mp_restart_state,grid%tbpvs_state,grid%tbpvs0_state,&
  603. allowed_to_read, grid%moved, start_of_simulation, &
  604. grid%LAGDAY, &
  605. ids, ide, jds, jde, kds, kde, &
  606. ims, ime, jms, jme, kms, kme, &
  607. grid%i_start(ij), grid%i_end(ij), grid%j_start(ij), grid%j_end(ij), kts, kte, &
  608. config_flags%num_urban_layers, & !multi-layer urban
  609. grid%raincv_a,grid%raincv_b, &
  610. grid%gd_cloud, grid%gd_cloud2, & ! Optional
  611. grid%gd_cloud_a, grid%gd_cloud2_a, & ! Optional
  612. grid%gd_cloud_b, grid%gd_cloud2_b, & ! Optional
  613. ozmixm,grid%pin, & ! Optional
  614. grid%m_ps_1,grid%m_ps_2,grid%m_hybi,aerosolc_1,aerosolc_2,& ! Optional
  615. grid%rundgdten,grid%rvndgdten,grid%rthndgdten, & ! Optional
  616. grid%rphndgdten,grid%rqvndgdten,grid%rmundgdten, & ! Optional
  617. grid%FGDT,grid%stepfg, & ! Optional
  618. grid%cugd_tten,grid%cugd_ttens,grid%cugd_qvten, & ! Optional
  619. grid%cugd_qvtens,grid%cugd_qcten, & ! Optional
  620. grid%ISNOWXY, grid%ZSNSOXY, grid%TSNOXY, & ! Optional Noah-MP
  621. grid%SNICEXY, grid%SNLIQXY, grid%TVXY, grid%TGXY, grid%CANICEXY, & ! Optional Noah-MP
  622. grid%CANLIQXY, grid%EAHXY, grid%TAHXY, grid%CMXY, & ! Optional Noah-MP
  623. grid%CHXY, grid%FWETXY, grid%SNEQVOXY, grid%ALBOLDXY, grid%QSNOWXY, & ! Optional Noah-MP
  624. grid%WSLAKEXY, grid%ZWTXY, grid%WAXY, grid%WTXY, grid%LFMASSXY, grid%RTMASSXY, & ! Optional Noah-MP
  625. grid%STMASSXY, grid%WOODXY, grid%STBLCPXY, grid%FASTCPXY, & ! Optional Noah-MP
  626. grid%XSAIXY, & ! Optional Noah-MP
  627. grid%T2MVXY, grid%T2MBXY, grid%CHSTARXY, & ! Optional Noah-MP
  628. grid%DZR, grid%DZB, grid%DZG, & !Optional urban
  629. grid%TR_URB2D,grid%TB_URB2D,grid%TG_URB2D,grid%TC_URB2D, & !Optional urban
  630. grid%QC_URB2D, grid%XXXR_URB2D,grid%XXXB_URB2D, & !Optional urban
  631. grid%XXXG_URB2D, grid%XXXC_URB2D, & !Optional urban
  632. grid%TRL_URB3D, grid%TBL_URB3D, grid%TGL_URB3D, & !Optional urban
  633. grid%SH_URB2D, grid%LH_URB2D, grid%G_URB2D, grid%RN_URB2D, & !Optional urban
  634. grid%TS_URB2D, grid%FRC_URB2D, grid%UTYPE_URB2D, & !Optional urban
  635. grid%TRB_URB4D,grid%TW1_URB4D,grid%TW2_URB4D,grid%TGB_URB4D,grid%TLEV_URB3D, & !multi-layer urban
  636. grid%QLEV_URB3D,grid%TW1LEV_URB3D,grid%TW2LEV_URB3D, & !multi-layer urban
  637. grid%TGLEV_URB3D,grid%TFLEV_URB3D,grid%SF_AC_URB3D, & !multi-layer urban
  638. grid%LF_AC_URB3D,grid%CM_AC_URB3D,grid%SFVENT_URB3D,grid%LFVENT_URB3D, & !multi-layer urban
  639. grid%SFWIN1_URB3D,grid%SFWIN2_URB3D, & !multi-layer urban
  640. grid%SFW1_URB3D,grid%SFW2_URB3D,grid%SFR_URB3D,grid%SFG_URB3D, & !multi-layer urban
  641. grid%A_U_BEP,grid%A_V_BEP,grid%A_T_BEP,grid%A_Q_BEP, & !multi-layer urban
  642. grid%A_E_BEP,grid%B_U_BEP,grid%B_V_BEP,grid%B_T_BEP, & !multi-layer urban
  643. grid%B_Q_BEP,grid%B_E_BEP,grid%DLG_BEP, & !multi-layer urban
  644. grid%DL_U_BEP,grid%SF_BEP,grid%VL_BEP, & !multi-layer urban
  645. grid%TML,grid%T0ML,grid%HML,grid%H0ML,grid%HUML,grid%HVML,grid%TMOML, & !Optional oml
  646. grid%itimestep, grid%fdob, &
  647. t00, p00, a, & ! for obs_nudge base state
  648. grid%TYR, grid%TYRA, grid%TDLY, grid%TLAG, grid%NYEAR, grid%NDAY,grid%tmn_update, &
  649. grid%achfx, grid%aclhf, grid%acgrdflx &
  650. ,grid%te_temf,grid%cf3d_temf,grid%wm_temf & ! WA
  651. ,grid%massflux_EDKF, grid%entr_EDKF, grid%detr_EDKF &
  652. ,grid%thl_up,grid%thv_up,grid%rt_up &
  653. ,grid%rv_up,grid%rc_up,grid%u_up,grid%v_up,grid%frac_up &
  654. )
  655. ENDIF !tgs
  656. ENDDO
  657. CALL wrf_debug ( 100 , 'start_domain_em: After call to phy_init' )
  658. IF (config_flags%do_avgflx_em .EQ. 1) THEN
  659. WRITE ( message , FMT = '("start_em: initializing avgflx on domain ",I3)' ) &
  660. & grid%id
  661. CALL wrf_message(trim(message))
  662. grid%avgflx_count = 0
  663. f_flux = config_flags%do_avgflx_cugd .EQ. 1 ! WA 9/24/10
  664. DO ij = 1, grid%num_tiles
  665. call wrf_debug(200,'In start_em, before zero_avgflx call')
  666. if (.not. grid%restart) call zero_avgflx(grid%avgflx_rum,grid%avgflx_rvm,grid%avgflx_wwm, &
  667. & ids, ide, jds, jde, kds, kde, &
  668. & ims, ime, jms, jme, kms, kme, &
  669. & grid%i_start(ij), grid%i_end(ij), grid%j_start(ij), grid%j_end(ij), kts, kte, f_flux, &
  670. & grid%avgflx_cfu1,grid%avgflx_cfd1,grid%avgflx_dfu1, &
  671. & grid%avgflx_efu1,grid%avgflx_dfd1,grid%avgflx_efd1 )
  672. call wrf_debug(200,'In start_em, after zero_avgflx call')
  673. ENDDO
  674. ENDIF
  675. #ifdef MCELIO
  676. grid%LU_MASK = 0.
  677. WHERE ( grid%lu_index .EQ. 16 ) grid%LU_MASK = 1.
  678. #endif
  679. END IF
  680. #if 0
  681. #include "CYCLE_TEST.inc"
  682. #endif
  683. !
  684. !
  685. ! set physical boundary conditions for all initialized variables
  686. !-----------------------------------------------------------------------
  687. ! Stencils for patch communications (WCS, 29 June 2001)
  688. ! Note: the size of this halo exchange reflects the
  689. ! fact that we are carrying the uncoupled variables
  690. ! as state variables in the mass coordinate model, as
  691. ! opposed to the coupled variables as in the height
  692. ! coordinate model.
  693. !
  694. ! * * * * *
  695. ! * * * * * * * * *
  696. ! * + * * + * * * + * *
  697. ! * * * * * * * * *
  698. ! * * * * *
  699. !
  700. !j grid%u_1 x
  701. !j grid%u_2 x
  702. !j grid%v_1 x
  703. !j grid%v_2 x
  704. !j grid%w_1 x
  705. !j grid%w_2 x
  706. !j grid%t_1 x
  707. !j grid%t_2 x
  708. !j grid%ph_1 x
  709. !j grid%ph_2 x
  710. !
  711. !j grid%t_init x
  712. !
  713. !j grid%phb x
  714. !j grid%ph0 x
  715. !j grid%php x
  716. !j grid%pb x
  717. !j grid%al x
  718. !j grid%alt x
  719. !j grid%alb x
  720. !
  721. ! the following are 2D (xy) variables
  722. !
  723. !j grid%mu_1 x
  724. !j grid%mu_2 x
  725. !j grid%mub x
  726. !j grid%mu0 x
  727. !j grid%ht x
  728. !j grid%msftx x
  729. !j grid%msfty x
  730. !j grid%msfux x
  731. !j grid%msfuy x
  732. !j grid%msfvx x
  733. !j grid%msfvy x
  734. !j grid%sina x
  735. !j grid%cosa x
  736. !j grid%e x
  737. !j grid%f x
  738. !
  739. ! 4D variables
  740. !
  741. ! moist x
  742. ! chem x
  743. !scalar x
  744. !--------------------------------------------------------------
  745. #ifdef DM_PARALLEL
  746. # include "HALO_EM_INIT_1.inc"
  747. # include "HALO_EM_INIT_2.inc"
  748. # include "HALO_EM_INIT_3.inc"
  749. # include "HALO_EM_INIT_4.inc"
  750. # include "HALO_EM_INIT_5.inc"
  751. # include "PERIOD_BDY_EM_INIT.inc"
  752. # include "PERIOD_BDY_EM_MOIST.inc"
  753. # include "PERIOD_BDY_EM_TKE.inc"
  754. # include "PERIOD_BDY_EM_SCALAR.inc"
  755. # include "PERIOD_BDY_EM_CHEM.inc"
  756. #endif
  757. CALL set_physical_bc3d( grid%u_1 , 'U' , config_flags , &
  758. ids , ide , jds , jde , kds , kde , &
  759. ims , ime , jms , jme , kms , kme , &
  760. its , ite , jts , jte , kts , kte , &
  761. its , ite , jts , jte , kts , kte )
  762. CALL set_physical_bc3d( grid%u_2 , 'U' , config_flags , &
  763. ids , ide , jds , jde , kds , kde , &
  764. ims , ime , jms , jme , kms , kme , &
  765. its , ite , jts , jte , kts , kte , &
  766. its , ite , jts , jte , kts , kte )
  767. CALL set_physical_bc3d( grid%v_1 , 'V' , config_flags , &
  768. ids , ide , jds , jde , kds , kde , &
  769. ims , ime , jms , jme , kms , kme , &
  770. its , ite , jts , jte , kts , kte , &
  771. its , ite , jts , jte , kts , kte )
  772. CALL set_physical_bc3d( grid%v_2 , 'V' , config_flags , &
  773. ids , ide , jds , jde , kds , kde , &
  774. ims , ime , jms , jme , kms , kme , &
  775. its , ite , jts , jte , kts , kte , &
  776. its , ite , jts , jte , kts , kte )
  777. ! set kinematic condition for w
  778. CALL set_physical_bc2d( grid%ht , 'r' , config_flags , &
  779. ids , ide , jds , jde , &
  780. ims , ime , jms , jme , &
  781. its , ite , jts , jte , &
  782. its , ite , jts , jte )
  783. ! Set the w at the surface. If this is the start of a forecast, or if this is a cycled run
  784. ! and the start of that forecast, we define the w field. However, if this a restart, then
  785. ! we leave w alone. Initial value is V dot grad(topo) at surface, then smoothly decaying
  786. ! above that.
  787. IF ( ( start_of_simulation .OR. config_flags%cycling ) .AND. ( .NOT. config_flags%restart ) ) THEN
  788. ! If W already exists (not zero), then we leave it alone. How to do this? We find the
  789. ! max/min on this node at the surface. If parallel, we collect the max/min from all procs.
  790. ! If the max/min throughout the entire domain at the surface is identically 0, then we say
  791. ! that the W field is NOT initialized, and we run the set_w_surface routines for the
  792. ! two time levels of W. If the field is already initialized, we do NOT run those two
  793. ! routines.
  794. w_max = grid%w_2(its,1,jts)
  795. w_min = grid%w_2(its,1,jts)
  796. DO j = jts, MIN(jte,jde-1)
  797. DO i = its, MIN(ite,ide-1)
  798. w_max = MAX ( w_max , grid%w_2(i,1,j) )
  799. w_min = MIN ( w_min , grid%w_2(i,1,j) )
  800. END DO
  801. END DO
  802. #ifdef DM_PARALLEL
  803. w_max = wrf_dm_max_real ( w_max )
  804. w_min = wrf_dm_min_real ( w_min )
  805. #endif
  806. IF ( ( ABS(w_max) .LT. 1.E-6 ) .AND. &
  807. ( ABS(w_min) .LT. 1.E-6 ) ) THEN
  808. w_needs_to_be_set = .TRUE.
  809. ELSE
  810. IF ( config_flags%use_input_w ) THEN
  811. w_needs_to_be_set = .FALSE.
  812. ELSE
  813. w_needs_to_be_set = .TRUE.
  814. END IF
  815. END IF
  816. IF ( w_needs_to_be_set ) THEN
  817. ! setting kinematic condition for w at the surface
  818. fill_w_flag = .true.
  819. CALL set_w_surface( config_flags, grid%znw, fill_w_flag, &
  820. grid%w_1, grid%ht, grid%u_1, grid%v_1, grid%cf1, &
  821. grid%cf2, grid%cf3, grid%rdx, grid%rdy, grid%msftx, grid%msfty, &
  822. ids, ide, jds, jde, kds, kde, &
  823. ims, ime, jms, jme, kms, kme, &
  824. its, ite, jts, jte, kts, kte )
  825. CALL set_w_surface( config_flags, grid%znw, fill_w_flag, &
  826. grid%w_2, grid%ht, grid%u_2, grid%v_2, grid%cf1, &
  827. grid%cf2, grid%cf3, grid%rdx, grid%rdy, grid%msftx, grid%msfty, &
  828. ids, ide, jds, jde, kds, kde, &
  829. ims, ime, jms, jme, kms, kme, &
  830. its, ite, jts, jte, kts, kte )
  831. END IF
  832. ! set up slope-radiation constant arrays based on topography
  833. ! paj: also computes laplacian for topo_wind
  834. !
  835. DO j = jts,min(jte,jde-1)
  836. DO i = its, min(ite,ide-1)
  837. im1 = max(i-1,ids)
  838. ip1 = min(i+1,ide-1)
  839. jm1 = max(j-1,jds)
  840. jp1 = min(j+1,jde-1)
  841. grid%toposlpx(i,j)=(grid%ht(ip1,j)-grid%ht(im1,j))*grid%msftx(i,j)*grid%rdx/(ip1-im1)
  842. grid%toposlpy(i,j)=(grid%ht(i,jp1)-grid%ht(i,jm1))*grid%msfty(i,j)*grid%rdy/(jp1-jm1)
  843. grid%lap_hgt(i,j)=(grid%ht(ip1,j)+grid%ht(im1,j)+grid%ht(i,jp1)+grid%ht(i,jm1)-grid%ht(i,j)*4.)/4.
  844. hx = grid%toposlpx(i,j)
  845. hy = grid%toposlpy(i,j)
  846. pi = 4.*atan(1.)
  847. grid%slope(i,j) = atan((hx**2+hy**2)**.5)
  848. if (grid%slope(i,j).lt.1.e-4) then
  849. grid%slope(i,j) = 0.
  850. grid%slp_azi(i,j) = 0.
  851. else
  852. grid%slp_azi(i,j) = atan2(hx,hy)+pi
  853. ! Rotate slope azimuth to lat-lon grid
  854. if (grid%cosa(i,j).ge.0) then
  855. grid%slp_azi(i,j) = grid%slp_azi(i,j) - asin(grid%sina(i,j))
  856. else
  857. grid%slp_azi(i,j) = grid%slp_azi(i,j) - (pi - asin(grid%sina(i,j)))
  858. endif
  859. endif
  860. ENDDO
  861. ENDDO
  862. !
  863. ! paj: computes ct and ct2 for topo_wind
  864. !
  865. grid%ctopo=1.
  866. grid%ctopo2=1.
  867. !
  868. if (config_flags%topo_wind.eq.1) then
  869. DO j = jts,min(jte,jde-1)
  870. DO i = its, min(ite,ide-1)
  871. if(grid%xland(i,j).lt.1.5)grid%ctopo(i,j)=sqrt(grid%var_sso(i,j))
  872. if (grid%ctopo(i,j).le.2.718) then
  873. grid%ctopo(i,j)=1.
  874. else
  875. grid%ctopo(i,j)=alog(grid%ctopo(i,j))
  876. endif
  877. !
  878. if (grid%lap_hgt(i,j).gt.-10.) then
  879. grid%ctopo(i,j)=grid%ctopo(i,j)
  880. else
  881. if (grid%lap_hgt(i,j).ge.-20) then
  882. alpha=(grid%lap_hgt(i,j)+20.)/10.
  883. grid%ctopo(i,j)=alpha*grid%ctopo(i,j)+(1-alpha)
  884. else
  885. if (grid%lap_hgt(i,j).ge.-30.) then
  886. grid%ctopo(i,j)=(grid%lap_hgt(i,j)+30.)/10.
  887. grid%ctopo2(i,j)=(grid%lap_hgt(i,j)+30.)/10.
  888. else
  889. grid%ctopo(i,j)=0.
  890. grid%ctopo2(i,j)=0.
  891. endif
  892. endif
  893. endif
  894. ENDDO
  895. ENDDO
  896. endif
  897. END IF
  898. CALL set_physical_bc3d( grid%w_1 , 'W' , config_flags , &
  899. ids , ide , jds , jde , kds , kde , &
  900. ims , ime , jms , jme , kms , kme , &
  901. its , ite , jts , jte , kts , kte , &
  902. its , ite , jts , jte , kts , kte )
  903. CALL set_physical_bc3d( grid%w_2 , 'W' , config_flags , &
  904. ids , ide , jds , jde , kds , kde , &
  905. ims , ime , jms , jme , kms , kme , &
  906. its , ite , jts , jte , kts , kte , &
  907. its , ite , jts , jte , kts , kte )
  908. CALL set_physical_bc3d( grid%ph_1 , 'W' , config_flags , &
  909. ids , ide , jds , jde , kds , kde , &
  910. ims , ime , jms , jme , kms , kme , &
  911. its , ite , jts , jte , kts , kte , &
  912. its , ite , jts , jte , kts , kte )
  913. CALL set_physical_bc3d( grid%ph_2 , 'W' , config_flags , &
  914. ids , ide , jds , jde , kds , kde , &
  915. ims , ime , jms , jme , kms , kme , &
  916. its , ite , jts , jte , kts , kte , &
  917. its , ite , jts , jte , kts , kte )
  918. CALL set_physical_bc3d( grid%t_1 , 't' , config_flags , &
  919. ids , ide , jds , jde , kds , kde , &
  920. ims , ime , jms , jme , kms , kme , &
  921. its , ite , jts , jte , kts , kte , &
  922. its , ite , jts , jte , kts , kte )
  923. CALL set_physical_bc3d( grid%t_2 , 't' , config_flags , &
  924. ids , ide , jds , jde , kds , kde , &
  925. ims , ime , jms , jme , kms , kme , &
  926. its , ite , jts , jte , kts , kte , &
  927. its , ite , jts , jte , kts , kte )
  928. CALL set_physical_bc2d( grid%mu_1, 't' , config_flags , &
  929. ids , ide , jds , jde , &
  930. ims , ime , jms , jme , &
  931. its , ite , jts , jte , &
  932. its , ite , jts , jte )
  933. CALL set_physical_bc2d( grid%mu_2, 't' , config_flags , &
  934. ids , ide , jds , jde , &
  935. ims , ime , jms , jme , &
  936. its , ite , jts , jte , &
  937. its , ite , jts , jte )
  938. CALL set_physical_bc2d( grid%mub , 't' , config_flags , &
  939. ids , ide , jds , jde , &
  940. ims , ime , jms , jme , &
  941. its , ite , jts , jte , &
  942. its , ite , jts , jte )
  943. ! CALL set_physical_bc2d( grid%mu0 , 't' , config_flags , &
  944. ! ids , ide , jds , jde , &
  945. ! ims , ime , jms , jme , &
  946. ! its , ite , jts , jte , &
  947. ! its , ite , jts , jte )
  948. CALL set_physical_bc3d( grid%phb , 'W' , config_flags , &
  949. ids , ide , jds , jde , kds , kde , &
  950. ims , ime , jms , jme , kms , kme , &
  951. its , ite , jts , jte , kts , kte , &
  952. its , ite , jts , jte , kts , kte )
  953. CALL set_physical_bc3d( grid%ph0 , 'W' , config_flags , &
  954. ids , ide , jds , jde , kds , kde , &
  955. ims , ime , jms , jme , kms , kme , &
  956. its , ite , jts , jte , kts , kte , &
  957. its , ite , jts , jte , kts , kte )
  958. CALL set_physical_bc3d( grid%php , 'W' , config_flags , &
  959. ids , ide , jds , jde , kds , kde , &
  960. ims , ime , jms , jme , kms , kme , &
  961. its , ite , jts , jte , kts , kte , &
  962. its , ite , jts , jte , kts , kte )
  963. CALL set_physical_bc3d( grid%pb , 't' , config_flags , &
  964. ids , ide , jds , jde , kds , kde , &
  965. ims , ime , jms , jme , kms , kme , &
  966. its , ite , jts , jte , kts , kte , &
  967. its , ite , jts , jte , kts , kte )
  968. CALL set_physical_bc3d( grid%al , 't' , config_flags , &
  969. ids , ide , jds , jde , kds , kde , &
  970. ims , ime , jms , jme , kms , kme , &
  971. its , ite , jts , jte , kts , kte , &
  972. its , ite , jts , jte , kts , kte )
  973. CALL set_physical_bc3d( grid%alt , 't' , config_flags , &
  974. ids , ide , jds , jde , kds , kde , &
  975. ims , ime , jms , jme , kms , kme , &
  976. its , ite , jts , jte , kts , kte , &
  977. its , ite , jts , jte , kts , kte )
  978. CALL set_physical_bc3d( grid%alb , 't' , config_flags , &
  979. ids , ide , jds , jde , kds , kde , &
  980. ims , ime , jms , jme , kms , kme , &
  981. its , ite , jts , jte , kts , kte , &
  982. its , ite , jts , jte , kts , kte )
  983. CALL set_physical_bc3d(grid%t_init, 't' , config_flags , &
  984. ids , ide , jds , jde , kds , kde , &
  985. ims , ime , jms , jme , kms , kme , &
  986. its , ite , jts , jte , kts , kte , &
  987. its , ite , jts , jte , kts , kte )
  988. CALL set_physical_bc3d(grid%tke_2, 't' , config_flags , &
  989. ids , ide , jds , jde , kds , kde , &
  990. ims , ime , jms , jme , kms , kme , &
  991. its , ite , jts , jte , kts , kte , &
  992. its , ite , jts , jte , kts , kte )
  993. IF (num_moist > 0) THEN
  994. ! use of (:,:,:,loop) not efficient on DEC, but (ims,kms,jms,loop) not portable to SGI/Cray
  995. loop_3d_m : DO loop = 1 , num_moist
  996. CALL set_physical_bc3d( moist(:,:,:,loop) , 'r' , config_flags , &
  997. ids , ide , jds , jde , kds , kde , &
  998. ims , ime , jms , jme , kms , kme , &
  999. its , ite , jts , jte , kts , kte , &
  1000. its , ite , jts , jte , kts , kte )
  1001. END DO loop_3d_m
  1002. ENDIF
  1003. IF (num_scalar > 0) THEN
  1004. ! use of (:,:,:,loop) not efficient on DEC, but (ims,kms,jms,loop) not portable to SGI/Cray
  1005. loop_3d_s : DO loop = 1 , num_scalar
  1006. CALL set_physical_bc3d( scalar(:,:,:,loop) , 'r' , config_flags , &
  1007. ids , ide , jds , jde , kds , kde , &
  1008. ims , ime , jms , jme , kms , kme , &
  1009. its , ite , jts , jte , kts , kte , &
  1010. its , ite , jts , jte , kts , kte )
  1011. END DO loop_3d_s
  1012. ENDIF
  1013. #ifdef WRF_CHEM
  1014. if(config_flags%tracer_opt > 0 )then
  1015. call initialize_tracer (tracer,config_flags%chem_in_opt, &
  1016. config_flags%tracer_opt,num_tracer, &
  1017. ids,ide, jds,jde, kds,kde, & ! domain dims
  1018. ims,ime, jms,jme, kms,kme, & ! memory dims
  1019. ips,ipe, jps,jpe, kps,kpe, & ! patch dims
  1020. its,ite, jts,jte, kts,kte )
  1021. endif
  1022. !
  1023. ! we do this here, so we only have one chem_init routine for either core....
  1024. !
  1025. do j=jts,min(jte,jde-1)
  1026. do i=its,min(ite,ide-1)
  1027. do k=kts,kte
  1028. z_at_w(i,k,j)=(grid%ph_2(i,k,j)+grid%phb(i,k,j))/g
  1029. enddo
  1030. do k=kts,min(kte,kde-1)
  1031. tempfac=(grid%t_1(i,k,j) + t0)*((grid%p(i,k,j) + grid%pb(i,k,j))/p1000mb)**rcp
  1032. convfac(i,k,j) = (grid%p(i,k,j)+grid%pb(i,k,j))/rgasuniv/tempfac
  1033. enddo
  1034. enddo
  1035. enddo
  1036. CALL chem_init (grid%id,chem,emis_ant,scalar,grid%dt,grid%bioemdt,grid%photdt, &
  1037. grid%chemdt, &
  1038. grid%stepbioe,grid%stepphot,grid%stepchem,grid%stepfirepl, &
  1039. grid%plumerisefire_frq,z_at_w,grid%xlat,grid%xlong,g, &
  1040. grid%aerwrf,config_flags,grid, &
  1041. grid%alt,grid%t_1,grid%p,convfac,grid%ttday,grid%tcosz, &
  1042. grid%julday,grid%gmt,&
  1043. grid%tauaer1,grid%tauaer2,grid%tauaer3,grid%tauaer4, &
  1044. grid%gaer1,grid%gaer2,grid%gaer3,grid%gaer4, &
  1045. grid%waer1,grid%waer2,grid%waer3,grid%waer4, &
  1046. grid%l2aer,grid%l3aer,grid%l4aer,grid%l5aer,grid%l6aer,grid%l7aer, &
  1047. grid%extaerlw1,grid%extaerlw2,grid%extaerlw3,grid%extaerlw4, &
  1048. grid%extaerlw5,grid%extaerlw6,grid%extaerlw7,grid%extaerlw8, &
  1049. grid%extaerlw9,grid%extaerlw10,grid%extaerlw11,grid%extaerlw12, &
  1050. grid%extaerlw13,grid%extaerlw14,grid%extaerlw15,grid%extaerlw16, &
  1051. grid%tauaerlw1,grid%tauaerlw2,grid%tauaerlw3,grid%tauaerlw4, &
  1052. grid%tauaerlw5,grid%tauaerlw6,grid%tauaerlw7,grid%tauaerlw8, &
  1053. grid%tauaerlw9,grid%tauaerlw10,grid%tauaerlw11,grid%tauaerlw12, &
  1054. grid%tauaerlw13,grid%tauaerlw14,grid%tauaerlw15,grid%tauaerlw16, &
  1055. grid%pm2_5_dry,grid%pm2_5_water,grid%pm2_5_dry_ec, &
  1056. grid%last_chem_time_year,grid%last_chem_time_month, &
  1057. grid%last_chem_time_day,grid%last_chem_time_hour, &
  1058. grid%last_chem_time_minute,grid%last_chem_time_second, &
  1059. grid%chem_in_opt,grid%kemit, &
  1060. ids , ide , jds , jde , kds , kde , &
  1061. ims , ime , jms , jme , kms , kme , &
  1062. its , ite , jts , jte , kts , kte )
  1063. !
  1064. ! calculate initial pm
  1065. !
  1066. ! print *,'calculating initial pm'
  1067. select case (config_flags%chem_opt)
  1068. case (GOCART_SIMPLE,GOCARTRACM_KPP,GOCARTRADM2,GOCARTRADM2_KPP)
  1069. call sum_pm_gocart ( &
  1070. grid%alt, chem, grid%pm2_5_dry, grid%pm2_5_dry_ec,grid%pm10,&
  1071. ids,ide, jds,jde, kds,kde, &
  1072. ims,ime, jms,jme, kms,kme, &
  1073. its,ite, jts,jte, kts,kte-1 )
  1074. case (RADM2SORG,RADM2SORG_AQ,RADM2SORG_AQCHEM,RADM2SORG_KPP,RACMSORG_AQ,RACMSORG_AQCHEM,RACMSORG_KPP)
  1075. call sum_pm_sorgam ( &
  1076. grid%alt, chem, grid%h2oaj, grid%h2oai, &
  1077. grid%pm2_5_dry, grid%pm2_5_water, grid%pm2_5_dry_ec, grid%pm10, &
  1078. grid%dust_opt,ids,ide, jds,jde, kds,kde, &
  1079. ims,ime, jms,jme, kms,kme, &
  1080. its,ite, jts,jte, kts,kte-1 )
  1081. case (RACM_SOA_VBS_KPP)
  1082. call sum_pm_soa_vbs ( &
  1083. grid%alt, chem, grid%h2oaj, grid%h2oai, &
  1084. grid%pm2_5_dry, grid%pm2_5_water, grid%pm2_5_dry_ec, grid%pm10, &
  1085. config_flags%dust_opt,ids,ide, jds,jde, kds,kde, &
  1086. ims,ime, jms,jme, kms,kme, &
  1087. its,ite, jts,jte, kts,kte-1 )
  1088. case (CBMZ_MOSAIC_4BIN,CBMZ_MOSAIC_8BIN,CBMZ_MOSAIC_4BIN_AQ,CBMZ_MOSAIC_8BIN_AQ, &
  1089. CBMZ_MOSAIC_DMS_4BIN, CBMZ_MOSAIC_DMS_8BIN, CBMZ_MOSAIC_DMS_4BIN_AQ, &
  1090. CBMZ_MOSAIC_DMS_8BIN_AQ)
  1091. call sum_pm_mosaic ( &
  1092. grid%alt, chem, &
  1093. grid%pm2_5_dry, grid%pm2_5_water, grid%pm2_5_dry_ec, grid%pm10, &
  1094. ids,ide, jds,jde, kds,kde, &
  1095. ims,ime, jms,jme, kms,kme, &
  1096. its,ite, jts,jte, kts,kte-1 )
  1097. case default
  1098. do j=jts,min(jte,jde-1)
  1099. do k=kts,min(kte,kde-1)
  1100. do i=its,min(ite,ide-1)
  1101. grid%pm2_5_dry(i,k,j) = 0.
  1102. grid%pm2_5_water(i,k,j) = 0.
  1103. grid%pm2_5_dry_ec(i,k,j) = 0.
  1104. grid%pm10(i,k,j) = 0.
  1105. enddo
  1106. enddo
  1107. enddo
  1108. end select
  1109. ! initialize advective tendency diagnostics for chem
  1110. if ( grid%itimestep .eq. 0 .and. config_flags%chemdiag .eq. USECHEMDIAG ) then
  1111. grid%advh_ct(:,:,:,:) = 0.
  1112. grid%advz_ct(:,:,:,:) = 0.
  1113. endif
  1114. #endif
  1115. ! initialize advective tendency diagnostics for non-chem
  1116. if ( grid%itimestep .eq. 0 .and. config_flags%tenddiag .eq. USETENDDIAG ) then
  1117. grid%advh_t(:,:,:,:) = 0.
  1118. grid%advz_t(:,:,:,:) = 0.
  1119. endif
  1120. IF (num_chem >= PARAM_FIRST_SCALAR ) THEN
  1121. ! use of (:,:,:,loop) not efficient on DEC, but (ims,kms,jms,loop) not portable to SGI/Cray
  1122. loop_3d_c : DO loop = PARAM_FIRST_SCALAR , num_chem
  1123. CALL set_physical_bc3d( chem(:,:,:,loop) , 'r' , config_flags , &
  1124. ids , ide , jds , jde , kds , kde , &
  1125. ims , ime , jms , jme , kms , kme , &
  1126. its , ite , jts , jte , kts , kte , &
  1127. its , ite , jts , jte , kts , kte )
  1128. END DO loop_3d_c
  1129. ENDIF
  1130. CALL set_physical_bc2d( grid%msftx , 'r' , config_flags , &
  1131. ids , ide , jds , jde , &
  1132. ims , ime , jms , jme , &
  1133. its , ite , jts , jte , &
  1134. its , ite , jts , jte )
  1135. CALL set_physical_bc2d( grid%msfty , 'r' , config_flags , &
  1136. ids , ide , jds , jde , &
  1137. ims , ime , jms , jme , &
  1138. its , ite , jts , jte , &
  1139. its , ite , jts , jte )
  1140. CALL set_physical_bc2d( grid%msfux , 'x' , config_flags , &
  1141. ids , ide , jds , jde , &
  1142. ims , ime , jms , jme , &
  1143. its , ite , jts , jte , &
  1144. its , ite , jts , jte )
  1145. CALL set_physical_bc2d( grid%msfuy , 'x' , config_flags , &
  1146. ids , ide , jds , jde , &
  1147. ims , ime , jms , jme , &
  1148. its , ite , jts , jte , &
  1149. its , ite , jts , jte )
  1150. CALL set_physical_bc2d( grid%msfvx , 'y' , config_flags , &
  1151. ids , ide , jds , jde , &
  1152. ims , ime , jms , jme , &
  1153. its , ite , jts , jte , &
  1154. its , ite , jts , jte )
  1155. CALL set_physical_bc2d( grid%msfvy , 'y' , config_flags , &
  1156. ids , ide , jds , jde , &
  1157. ims , ime , jms , jme , &
  1158. its , ite , jts , jte , &
  1159. its , ite , jts , jte )
  1160. CALL set_physical_bc2d( grid%sina , 'r' , config_flags , &
  1161. ids , ide , jds , jde , &
  1162. ims , ime , jms , jme , &
  1163. its , ite , jts , jte , &
  1164. its , ite , jts , jte )
  1165. CALL set_physical_bc2d( grid%cosa , 'r' , config_flags , &
  1166. ids , ide , jds , jde , &
  1167. ims , ime , jms , jme , &
  1168. its , ite , jts , jte , &
  1169. its , ite , jts , jte )
  1170. CALL set_physical_bc2d( grid%e , 'r' , config_flags , &
  1171. ids , ide , jds , jde , &
  1172. ims , ime , jms , jme , &
  1173. its , ite , jts , jte , &
  1174. its , ite , jts , jte )
  1175. CALL set_physical_bc2d( grid%f , 'r' , config_flags , &
  1176. ids , ide , jds , jde , &
  1177. ims , ime , jms , jme , &
  1178. its , ite , jts , jte , &
  1179. its , ite , jts , jte )
  1180. #ifndef WRF_CHEM
  1181. DEALLOCATE(CLDFRA_OLD)
  1182. #endif
  1183. #ifdef DM_PARALLEL
  1184. # include "HALO_EM_INIT_1.inc"
  1185. # include "HALO_EM_INIT_2.inc"
  1186. # include "HALO_EM_INIT_3.inc"
  1187. # include "HALO_EM_INIT_4.inc"
  1188. # include "HALO_EM_INIT_5.inc"
  1189. # include "PERIOD_BDY_EM_INIT.inc"
  1190. # include "PERIOD_BDY_EM_MOIST.inc"
  1191. # include "PERIOD_BDY_EM_TKE.inc"
  1192. # include "PERIOD_BDY_EM_SCALAR.inc"
  1193. # include "PERIOD_BDY_EM_CHEM.inc"
  1194. #endif
  1195. ! FIRE
  1196. if(config_flags%ifire.eq.2)then
  1197. call sfire_driver_em_init ( grid , config_flags &
  1198. ,ids,ide, kds,kde, jds,jde &
  1199. ,ims,ime, kms,kme, jms,jme &
  1200. ,ips,ipe, kps,kpe, jps,jpe )
  1201. CALL wrf_debug ( 100 , 'start_domain_em: After call to sfire_driver_em_init' )
  1202. endif
  1203. CALL wrf_debug ( 100 , 'start_domain_em: Returning' )
  1204. RETURN
  1205. END SUBROUTINE start_domain_em