1 !IDEAL:MODEL_LAYER:INITIALIZATION
3 ! This MODULE holds the routines which are used to perform various initializations
4 ! for the individual domains.
6 !-----------------------------------------------------------------------
8 MODULE module_initialize_ideal
10 USE module_domain ! frame/module_domain.F
11 USE module_io_domain ! share
12 USE module_state_description ! frame
13 USE module_model_constants ! share
15 USE module_timing ! frame
16 USE module_configure ! frame
17 USE module_init_utilities ! dyn_em
26 !-------------------------------------------------------------------
27 ! this is a wrapper for the solver-specific init_domain routines.
28 ! Also dereferences the grid variables and passes them down as arguments.
29 ! This is crucial, since the lower level routines may do message passing
30 ! and this will get fouled up on machines that insist on passing down
31 ! copies of assumed-shape arrays (by passing down as arguments, the
32 ! data are treated as assumed-size -- ie. f77 -- arrays and the copying
33 ! business is avoided). Fie on the F90 designers. Fie and a pox.
35 SUBROUTINE init_domain ( grid )
40 TYPE (domain), POINTER :: grid
42 INTEGER :: idum1, idum2
44 CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
46 CALL init_domain_rk( grid &
48 #include <actual_new_args.inc>
52 END SUBROUTINE init_domain
54 !-------------------------------------------------------------------
56 SUBROUTINE init_domain_rk ( grid &
58 # include <dummy_new_args.inc>
64 TYPE (domain), POINTER :: grid
66 # include <dummy_decl.inc>
68 TYPE (grid_config_rec_type) :: config_flags
72 ids, ide, jds, jde, kds, kde, &
73 ims, ime, jms, jme, kms, kme, &
74 its, ite, jts, jte, kts, kte, &
77 INTEGER :: nxx, nyy, ig, jg, im, error
79 REAL :: dlam, dphi, vlat, tperturb
80 REAL :: p_surf, p_level, pd_surf, qvf1, qvf2, qvf
81 REAL :: thtmp, ptmp, temp(3), cof1, cof2
85 SELECT CASE ( model_data_order )
86 CASE ( DATA_ORDER_ZXY )
87 kds = grid%sd31 ; kde = grid%ed31 ;
88 ids = grid%sd32 ; ide = grid%ed32 ;
89 jds = grid%sd33 ; jde = grid%ed33 ;
91 kms = grid%sm31 ; kme = grid%em31 ;
92 ims = grid%sm32 ; ime = grid%em32 ;
93 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 ;
103 ims = grid%sm31 ; ime = grid%em31 ;
104 jms = grid%sm32 ; jme = grid%em32 ;
105 kms = grid%sm33 ; kme = grid%em33 ;
107 its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
108 jts = grid%sp32 ; jte = grid%ep32 ; ! note that tile is entire patch
109 kts = grid%sp33 ; kte = grid%ep33 ; ! note that tile is entire patch
110 CASE ( DATA_ORDER_XZY )
111 ids = grid%sd31 ; ide = grid%ed31 ;
112 kds = grid%sd32 ; kde = grid%ed32 ;
113 jds = grid%sd33 ; jde = grid%ed33 ;
115 ims = grid%sm31 ; ime = grid%em31 ;
116 kms = grid%sm32 ; kme = grid%em32 ;
117 jms = grid%sm33 ; jme = grid%em33 ;
119 its = grid%sp31 ; ite = grid%ep31 ; ! note that tile is entire patch
120 kts = grid%sp32 ; kte = grid%ep32 ; ! note that tile is entire patch
121 jts = grid%sp33 ; jte = grid%ep33 ; ! note that tile is entire patch
125 CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
127 ! here we check to see if the boundary conditions are set properly
129 CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
136 CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
137 CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
140 ! Initialize 2D surface arrays
142 nxx = ide-ids ! Don't include u-stagger
143 nyy = jde-jds ! Don't include v-stagger
144 dphi = 180./REAL(nyy)
145 dlam = 360./REAL(nxx)
149 ! ig is the I index in the global (domain) span of the array.
150 ! jg is the J index in the global (domain) span of the array.
151 ig = i - ids + 1 ! ids is not necessarily 1
152 jg = j - jds + 1 ! jds is not necessarily 1
154 grid%xlat(i,j) = (REAL(jg)-0.5)*dphi-90.
155 grid%xlong(i,j) = (REAL(ig)-0.5)*dlam-180.
156 vlat = grid%xlat(i,j) - 0.5*dphi
158 grid%clat(i,j) = grid%xlat(i,j)
159 grid%clong(i,j) = grid%xlong(i,j)
161 grid%msftx(i,j) = 1./COS(grid%xlat(i,j)*degrad)
163 grid%msfux(i,j) = 1./COS(grid%xlat(i,j)*degrad)
165 grid%e(i,j) = 2*EOMEG*COS(grid%xlat(i,j)*degrad)
166 grid%f(i,j) = 2*EOMEG*SIN(grid%xlat(i,j)*degrad)
168 ! The following two are the cosine and sine of the rotation
169 ! of projection. Simple cylindrical is *simple* ... no rotation!
176 ! DO j = max(jds+1,jts), min(jde-1,jte)
179 vlat = grid%xlat(i,j) - 0.5*dphi
180 grid%msfvx(i,j) = 1./COS(vlat*degrad)
182 grid%msfvx_inv(i,j) = 1./grid%msfvx(i,j)
188 grid%msfvx(i,jts) = 00.
189 grid%msfvx_inv(i,jts) = 0.
195 grid%msfvx(i,jte) = 00.
196 grid%msfvx_inv(i,jte) = 0.
201 vlat = grid%xlat(its,j) - 0.5*dphi
202 write(6,*) j,vlat,grid%msfvx(its,j),grid%msfvx_inv(its,j)
209 grid%albedo(i,j) = 0.
210 grid%thc(i,j) = 1000.
214 grid%lu_index(i,j) = REAL(ivgtyp(i,j))
216 grid%mavail(i,j) = 0.
220 grid%dx = dlam*degrad/reradius
221 grid%dy = dphi*degrad/reradius
222 grid%rdx = 1./grid%dx
223 grid%rdy = 1./grid%dy
226 !WRITE(*,'(A,1PG14.6,A,1PG14.6)') ' For the namelist: dx =',grid%dx,', dy =',grid%dy
228 CALL nl_set_mminlu(1,' ')
234 grid%moad_cen_lat = 0.
236 ! Apparently, map projection 0 is "none" which actually turns out to be
237 ! a regular grid of latitudes and longitudes, the simple cylindrical projection
241 grid%znw(k) = 1. - REAL(k-kds)/REAL(kde-kds)
245 grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
246 grid%rdnw(k) = 1./grid%dnw(k)
247 grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
250 grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
251 grid%rdn(k) = 1./grid%dn(k)
252 grid%fnp(k) = .5* grid%dnw(k )/grid%dn(k)
253 grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
256 cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
257 cof2 = grid%dn(2) /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
258 grid%cf1 = grid%fnp(2) + cof1
259 grid%cf2 = grid%fnm(2) - cof1 - cof2
262 grid%cfn = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
263 grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
266 ! Need to add perturbations to initial profile. Set up random number
270 ! General assumption from here after is that the initial temperature
271 ! profile is isothermal at a value of T0, and the initial winds are
274 ! find ptop for the desired ztop (ztop is input from the namelist)
275 grid%p_top = p0 * EXP(-(g*config_flags%ztop)/(r_d*T0))
278 ! Values of geopotential (base, perturbation, and at p0) at the surface
281 grid%phb(i,1,j) = grid%ht(i,j)*g
282 grid%php(i,1,j) = 0. ! This is perturbation geopotential
283 ! Since this is an initial condition, there
284 ! should be no perturbation!
285 grid%ph0(i,1,j) = grid%ht(i,j)*g
293 p_surf = p0 * EXP(-(g*grid%phb(i,1,j)/g)/(r_d*T0))
294 grid%mub(i,j) = p_surf-grid%p_top
296 ! given p (coordinate), calculate theta and compute 1/rho from equation
300 p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
301 grid%pb(i,k,j) = p_level
303 grid%t_init(i,k,j) = T0*(p0/p_level)**rcp
304 grid%t_init(i,k,j) = grid%t_init(i,k,j) - t0
306 grid%alb(i,k,j)=(r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
309 ! calculate hydrostatic balance (alternatively we could interpolate
310 ! the geopotential from the sounding, but this assures that the base
311 ! state is in exact hydrostatic balance with respect to the model eqns.
314 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)
320 DO im = PARAM_FIRST_SCALAR, num_moist
324 grid%moist(i,k,j,im) = 0.
330 ! Now calculate the full (hydrostatically-balanced) state for each column
331 ! We will include moisture
335 ! At this point p_top is already set. find the DRY mass in the column
336 pd_surf = p0 * EXP(-(g*grid%phb(i,1,j)/g)/(r_d*T0))
338 ! compute the perturbation mass (mu/mu_1/mu_2) and the full mass
339 grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
340 grid%mu_2(i,j) = grid%mu_1(i,j)
341 grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
343 ! given the dry pressure and coordinate system, calculate the
344 ! perturbation potential temperature (t/t_1/t_2)
347 p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
348 grid%t_1(i,k,j) = T0*(p0/p_level)**rcp
349 ! Add a small perturbation to initial isothermal profile
350 CALL random_number(tperturb)
351 grid%t_1(i,k,j)=grid%t_1(i,k,j)*(1.0+0.004*(tperturb-0.5))
352 grid%t_1(i,k,j) = grid%t_1(i,k,j)-t0
353 grid%t_2(i,k,j) = grid%t_1(i,k,j)
357 ! integrate the hydrostatic equation (from the RHS of the bigstep
358 ! vertical momentum equation) down from the top to get p.
359 ! first from the top of the model to the top pressure
361 k = kte-1 ! top level
363 qvf1 = 0.5*(grid%moist(i,k,j,P_QV)+grid%moist(i,k,j,P_QV))
367 ! grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
368 grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
369 qvf = 1. + rvovrd*grid%moist(i,k,j,P_QV)
370 grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
371 (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
372 grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
377 qvf1 = 0.5*(grid%moist(i,k,j,P_QV)+grid%moist(i,k+1,j,P_QV))
380 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)
381 qvf = 1. + rvovrd*grid%moist(i,k,j,P_QV)
382 grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
383 (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
384 grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
387 ! this is the hydrostatic equation used in the model after the
388 ! small timesteps. In the model, al (inverse density)
389 ! is computed from the geopotential.
391 grid%ph_1(i,1,j) = 0.
393 grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*( &
394 (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
395 grid%mu_1(i,j)*grid%alb(i,k-1,j) )
397 grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
398 grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
425 grid%h_diabatic(i,k,j) = 0.
432 grid%t_base(k) = grid%t_init(its,k,jts)
438 ! One subsurface layer: infinite slab at constant temperature below
439 ! the surface. Surface temperature is an infinitely thin "skin" on
440 ! top of a half-infinite slab. The temperature of both the skin and
441 ! the slab are determined from the initial nearest-surface-air-layer
443 DO J = jts, MIN(jte, jde-1)
444 DO I = its, MIN(ite, ide-1)
445 thtmp = grid%t_2(i,1,j)+t0
446 ptmp = grid%p(i,1,j)+grid%pb(i,1,j)
447 temp(1) = thtmp * (ptmp/p1000mb)**rcp
448 thtmp = grid%t_2(i,2,j)+t0
449 ptmp = grid%p(i,2,j)+grid%pb(i,2,j)
450 temp(2) = thtmp * (ptmp/p1000mb)**rcp
451 thtmp = grid%t_2(i,3,j)+t0
452 ptmp = grid%p(i,3,j)+grid%pb(i,3,j)
453 temp(3) = thtmp * (ptmp/p1000mb)**rcp
454 grid%tsk(I,J)=cf1*temp(1)+cf2*temp(2)+cf3*temp(3)
455 grid%tmn(I,J)=grid%tsk(I,J)-0.5
461 END SUBROUTINE init_domain_rk
463 !---------------------------------------------------------------------
465 SUBROUTINE init_module_initialize
466 END SUBROUTINE init_module_initialize
468 !---------------------------------------------------------------------
470 END MODULE module_initialize_ideal