source: trunk/WRF.COMMON/WRFV3/dyn_em/module_initialize_seabreeze2d_x.F @ 2759

Last change on this file since 2759 was 2759, checked in by aslmd, 2 years ago

adding unmodified code from WRFV3.0.1.1, expurged from useless data +1M size

File size: 24.7 KB
Line 
1!IDEAL:MODEL_LAYER:INITIALIZATION
2!
3
4!  This MODULE holds the routines which are used to perform various initializations
5!  for the individual domains. 
6
7!  This MODULE CONTAINS the following routines:
8
9!  initialize_field_test - 1. Set different fields to different constant
10!                             values.  This is only a test.  If the correct
11!                             domain is not found (based upon the "id")
12!                             then a fatal error is issued.               
13
14!-----------------------------------------------------------------------
15
16MODULE module_initialize_ideal
17
18   USE module_domain
19   USE module_io_domain
20   USE module_state_description
21   USE module_model_constants
22   USE module_bc
23   USE module_timing
24   USE module_configure
25   USE module_init_utilities
26   USE module_soil_pre
27#ifdef DM_PARALLEL
28   USE module_dm
29#endif
30
31
32CONTAINS
33
34
35!-------------------------------------------------------------------
36! this is a wrapper for the solver-specific init_domain routines.
37! Also dereferences the grid variables and passes them down as arguments.
38! This is crucial, since the lower level routines may do message passing
39! and this will get fouled up on machines that insist on passing down
40! copies of assumed-shape arrays (by passing down as arguments, the
41! data are treated as assumed-size -- ie. f77 -- arrays and the copying
42! business is avoided).  Fie on the F90 designers.  Fie and a pox.
43! NOTE:  Modified to remove all but arrays of rank 4 or more from the
44!        argument list.  Arrays with rank>3 are still problematic due to the
45!        above-noted fie- and pox-ities.  TBH 20061129. 
46
47   SUBROUTINE init_domain ( grid )
48
49   IMPLICIT NONE
50
51   !  Input data.
52   TYPE (domain), POINTER :: grid
53   !  Local data.
54   INTEGER :: idum1, idum2
55
56   CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
57
58     CALL init_domain_rk( grid &
59!
60#include <actual_new_args.inc>
61!
62                        )
63   END SUBROUTINE init_domain
64
65!-------------------------------------------------------------------
66
67   SUBROUTINE init_domain_rk ( grid &
68!
69# include <dummy_new_args.inc>
70!
71)
72   IMPLICIT NONE
73
74   !  Input data.
75   TYPE (domain), POINTER :: grid
76
77# include <dummy_new_decl.inc>
78
79   TYPE (grid_config_rec_type)              :: config_flags
80
81   !  Local data
82   INTEGER                             ::                       &
83                                  ids, ide, jds, jde, kds, kde, &
84                                  ims, ime, jms, jme, kms, kme, &
85                                  its, ite, jts, jte, kts, kte, &
86                                  i, j, k
87
88   ! Local data
89
90   INTEGER, PARAMETER :: nl_max = 1000
91   REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
92   INTEGER :: nl_in
93
94
95   INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc, lm
96   REAL    :: u_mean,v_mean, f0, p_surf, p_level, qvf, z_at_v, z_at_u
97   REAL    :: z_scale, xrad, yrad, zrad, rad, delt, cof1, cof2
98!   REAL, EXTERNAL :: interp_0
99   REAL    :: pi, rnd
100
101!  stuff from original initialization that has been dropped from the Registry
102   REAL    :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
103   REAL    :: qvf1, qvf2, pd_surf
104   INTEGER :: it
105   real :: thtmp, ptmp, temp(3)
106
107   LOGICAL :: moisture_init
108   LOGICAL :: stretch_grid, dry_sounding
109
110   
111#ifdef DM_PARALLEL
112#    include <data_calls.inc>
113#endif
114
115
116   SELECT CASE ( model_data_order )
117         CASE ( DATA_ORDER_ZXY )
118   kds = grid%sd31 ; kde = grid%ed31 ;
119   ids = grid%sd32 ; ide = grid%ed32 ;
120   jds = grid%sd33 ; jde = grid%ed33 ;
121
122   kms = grid%sm31 ; kme = grid%em31 ;
123   ims = grid%sm32 ; ime = grid%em32 ;
124   jms = grid%sm33 ; jme = grid%em33 ;
125
126   kts = grid%sp31 ; kte = grid%ep31 ;   ! note that tile is entire patch
127   its = grid%sp32 ; ite = grid%ep32 ;   ! note that tile is entire patch
128   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
129         CASE ( DATA_ORDER_XYZ )
130   ids = grid%sd31 ; ide = grid%ed31 ;
131   jds = grid%sd32 ; jde = grid%ed32 ;
132   kds = grid%sd33 ; kde = grid%ed33 ;
133
134   ims = grid%sm31 ; ime = grid%em31 ;
135   jms = grid%sm32 ; jme = grid%em32 ;
136   kms = grid%sm33 ; kme = grid%em33 ;
137
138   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
139   jts = grid%sp32 ; jte = grid%ep32 ;   ! note that tile is entire patch
140   kts = grid%sp33 ; kte = grid%ep33 ;   ! note that tile is entire patch
141         CASE ( DATA_ORDER_XZY )
142   ids = grid%sd31 ; ide = grid%ed31 ;
143   kds = grid%sd32 ; kde = grid%ed32 ;
144   jds = grid%sd33 ; jde = grid%ed33 ;
145
146   ims = grid%sm31 ; ime = grid%em31 ;
147   kms = grid%sm32 ; kme = grid%em32 ;
148   jms = grid%sm33 ; jme = grid%em33 ;
149
150   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
151   kts = grid%sp32 ; kte = grid%ep32 ;   ! note that tile is entire patch
152   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
153
154   END SELECT
155
156
157   stretch_grid = .true.
158   delt = 6.
159!   z_scale = .50
160   z_scale = .40
161   pi = 2.*asin(1.0)
162   write(6,*) ' pi is ',pi
163   nxc = (ide-ids)/2
164   nyc = jde/2
165   icm = ide/2
166! lm is the half width of the land in terms of grid points
167   lm = 25
168   write(6,*) 'lm,icm-lm,icm+lm = ', lm,icm-lm,icm+lm
169
170   CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
171
172! here we check to see if the boundary conditions are set properly
173
174   CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
175
176   moisture_init = .true.
177
178    grid%itimestep=0
179
180#ifdef DM_PARALLEL
181   CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
182   CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
183#endif
184
185    CALL nl_set_mminlu(1, 'USGS')
186    CALL nl_set_iswater(1,16)
187    CALL nl_set_isice(1,3)
188    CALL nl_set_cen_lat(1,20.)
189    CALL nl_set_cen_lon(1,-105.)
190    CALL nl_set_truelat1(1,0.)
191    CALL nl_set_truelat2(1,0.)
192    CALL nl_set_moad_cen_lat (1,0.)
193    CALL nl_set_stand_lon (1,0.)
194    CALL nl_set_map_proj(1,0)
195!   CALL model_to_grid_config_rec(1,model_config_rec,config_flags)
196    CALL nl_get_iswater(1,grid%iswater)
197
198!  here we initialize data that currently is not initialized
199!  in the input data
200
201    DO j = jts, jte
202      DO i = its, ite
203         grid%msft(i,j)     = 1.
204         grid%msfu(i,j)     = 1.
205         grid%msfv(i,j)     = 1.
206         grid%msftx(i,j)    = 1.
207         grid%msfty(i,j)    = 1.
208         grid%msfux(i,j)    = 1.
209         grid%msfuy(i,j)    = 1.
210         grid%msfvx(i,j)    = 1.
211         grid%msfvy(i,j)    = 1.
212         grid%msfvx_inv(i,j)= 1.
213         grid%sina(i,j)     = 0.
214         grid%cosa(i,j)     = 1.
215         grid%e(i,j)        = 0.
216         grid%f(i,j)        = 0.
217         grid%xlat(i,j)     = 30.
218         grid%xlong(i,j)     = 0.
219! Hard-wire the ocean-land configuration
220        if (i .ge. (icm-lm) .and. i .lt. (icm+lm)) then
221         grid%xland(i,j)     = 1.
222         grid%lu_index(i,j)  = 18
223         grid%tsk(i,j) = 280.0
224         grid%tmn(i,j) = 280.0
225        else
226         grid%xland(i,j)     = 2.
227         grid%lu_index(i,j)  = 16
228         grid%tsk(i,j) = 287.0
229         grid%tmn(i,j) = 280.0
230        end if
231      END DO
232   END DO
233
234! for Noah LSM, additional variables need to be initialized
235
236   other_masked_fields : SELECT CASE ( model_config_rec%sf_surface_physics(grid%id) )
237
238      CASE (SLABSCHEME)
239
240      CASE (LSMSCHEME)
241
242        DO j = jts , MIN(jde-1,jte)
243           DO i = its , MIN(ide-1,ite)
244              IF (grid%xland(i,j) .lt. 1.5) THEN
245                 grid%vegfra(i,j) = 0.5
246                 grid%canwat(i,j) = 0.
247                 grid%ivgtyp(i,j) = 18
248                 grid%isltyp(i,j) = 8
249                 grid%xice(i,j) = 0.
250                 grid%snow(i,j) = 0.
251              ELSE
252                 grid%vegfra(i,j) = 0.
253                 grid%canwat(i,j) = 0.
254                 grid%ivgtyp(i,j) = 16
255                 grid%isltyp(i,j) = 14
256                 grid%xice(i,j) = 0.
257                 grid%snow(i,j) = 0.
258              ENDIF
259           END DO
260        END DO
261
262      CASE (RUCLSMSCHEME)
263
264   END SELECT other_masked_fields
265
266   DO j = jts, jte
267    DO k = kts, kte
268      DO i = its, ite
269         grid%ww(i,k,j)     = 0.
270      END DO
271    END DO
272   END DO
273
274   grid%step_number = 0
275
276! Process the soil; note that there are some things hard-wired into share/module_soil_pre.F
277      CALL process_soil_ideal(grid%xland,grid%xice,grid%vegfra,grid%snow,grid%canwat, &
278                     grid%ivgtyp,grid%isltyp,grid%tslb,grid%smois, &
279                     grid%tsk,grid%tmn,grid%zs,grid%dzs,model_config_rec%num_soil_layers, &
280                     model_config_rec%sf_surface_physics(grid%id), &
281                                   ids,ide, jds,jde, kds,kde,&
282                                   ims,ime, jms,jme, kms,kme,&
283                                   its,ite, jts,jte, kts,kte )
284
285! set up the grid
286
287   IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
288     DO k=1, kde
289      grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
290                                (1.-exp(-1./z_scale))
291     ENDDO
292   ELSE
293     DO k=1, kde
294      grid%znw(k) = 1. - float(k-1)/float(kde-1)
295     ENDDO
296   ENDIF
297
298   DO k=1, kde-1
299    grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
300    grid%rdnw(k) = 1./grid%dnw(k)
301    grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
302   ENDDO
303   DO k=2, kde-1
304    grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
305    grid%rdn(k) = 1./grid%dn(k)
306    grid%fnp(k) = .5* grid%dnw(k  )/grid%dn(k)
307    grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
308   ENDDO
309
310   cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
311   cof2 =     grid%dn(2)        /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
312   grid%cf1  = grid%fnp(2) + cof1
313   grid%cf2  = grid%fnm(2) - cof1 - cof2
314   grid%cf3  = cof2       
315
316   grid%cfn  = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
317   grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
318   grid%rdx = 1./config_flags%dx
319   grid%rdy = 1./config_flags%dy
320
321!  get the sounding from the ascii sounding file, first get dry sounding and
322!  calculate base state
323
324  write(6,*) ' getting dry sounding for base state '
325  dry_sounding = .true.
326  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
327
328  write(6,*) ' returned from reading sounding, nl_in is ',nl_in
329
330!  find ptop for the desired ztop (ztop is input from the namelist),
331!  and find surface pressure
332
333  grid%p_top = interp_0( p_in, zk, config_flags%ztop, nl_in )
334
335  DO j=jts,jte
336  DO i=its,ite  ! flat surface
337    grid%phb(i,1,j) = 0.
338    grid%php(i,1,j) = 0.
339    grid%ph0(i,1,j) = 0.
340    grid%ht(i,j) = 0.
341  ENDDO
342  ENDDO
343
344  DO J = jts, jte
345  DO I = its, ite
346
347    p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
348    grid%mub(i,j) = p_surf-grid%p_top
349
350!  this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
351!  interp theta (from interp) and compute 1/rho from eqn. of state
352
353    DO K = 1, kte-1
354      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
355      grid%pb(i,k,j) = p_level
356      grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
357      grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
358    ENDDO
359
360!  calc hydrostatic balance (alternatively we could interp the geopotential from the
361!  sounding, but this assures that the base state is in exact hydrostatic balance with
362!  respect to the model eqns.
363
364    DO k  = 2,kte
365      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)
366    ENDDO
367
368  ENDDO
369  ENDDO
370
371  write(6,*) ' ptop is ',grid%p_top
372  write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
373
374!  calculate full state for each column - this includes moisture.
375
376  write(6,*) ' getting moist sounding for full state '
377  dry_sounding = .false.
378  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
379
380  DO J = jts, min(jde-1,jte)
381  DO I = its, min(ide-1,ite)
382
383!  At this point grid%p_top is already set. find the DRY mass in the column
384!  by interpolating the DRY pressure. 
385
386   pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
387
388!  compute the perturbation mass and the full mass
389
390    grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
391    grid%mu_2(i,j) = grid%mu_1(i,j)
392    grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
393
394! given the dry pressure and coordinate system, interp the potential
395! temperature and qv
396
397    do k=1,kde-1
398
399      p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
400
401      moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
402      grid%t_1(i,k,j)          = interp_0( theta, pd_in, p_level, nl_in ) - t0
403      grid%t_2(i,k,j)          = grid%t_1(i,k,j)
404     
405
406    enddo
407
408!  integrate the hydrostatic equation (from the RHS of the bigstep
409!  vertical momentum equation) down from the top to get grid%p.
410!  first from the top of the model to the top pressure
411
412    k = kte-1  ! top level
413
414    qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
415    qvf2 = 1./(1.+qvf1)
416    qvf1 = qvf1*qvf2
417
418!    grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
419    grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
420    qvf = 1. + rvovrd*moist(i,k,j,P_QV)
421    grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
422                (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
423    grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
424
425!  down the column
426
427    do k=kte-2,1,-1
428      qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
429      qvf2 = 1./(1.+qvf1)
430      qvf1 = qvf1*qvf2
431      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)
432      qvf = 1. + rvovrd*moist(i,k,j,P_QV)
433      grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
434                  (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
435      grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
436    enddo
437
438!  this is the hydrostatic equation used in the model after the
439!  small timesteps.  In the model, grid%al (inverse density)
440!  is computed from the geopotential.
441
442
443    grid%ph_1(i,1,j) = 0.
444    DO k  = 2,kte
445      grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
446                   (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
447                    grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
448                                                   
449      grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
450      grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
451    ENDDO
452
453    if((i==2) .and. (j==2)) then
454     write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
455                              grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
456                              grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
457    endif
458
459  ENDDO
460  ENDDO
461
462   if (0.gt.1) then
463!#if 0
464!  The seabreeze case is adapted from the squall line case
465!  so we just turn off the thermal perturbation
466
467!  thermal perturbation to kick off convection
468        call random_seed
469  write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
470  write(6,*) ' delt for perturbation ',delt
471
472  DO J = jts, min(jde-1,jte)
473!    yrad = config_flags%dy*float(j-nyc)/4000.
474     yrad = 0.
475    DO I = its, min(ide-1,ite)
476      xrad = config_flags%dx*float(i-nxc)/10000.
477!     xrad = 0.
478      DO K = 1, 35
479
480!  put in preturbation theta (bubble) and recalc density.  note,
481!  the mass in the column is not changing, so when theta changes,
482!  we recompute density and geopotential
483        zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j)  &
484                   +grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
485        zrad = (zrad-1500.)/1500.
486        RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
487!        IF(RAD <= 1.) THEN
488        call RANDOM_NUMBER(rnd)
489          grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*(rnd-0.5)
490         !  grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
491           grid%t_2(i,k,j)=grid%t_1(i,k,j)
492           qvf = 1. + rvovrd*moist(i,k,j,P_QV)
493           grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
494                        (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
495           grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
496!        ENDIF
497      ENDDO
498
499!  rebalance hydrostatically
500
501      DO k  = 2,kte
502        grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
503                     (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
504                      grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
505                                                   
506        grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
507        grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
508      ENDDO
509
510    ENDDO
511  ENDDO
512        endif
513!#endif
514
515   write(6,*) ' grid%mu_1 from comp ', grid%mu_1(1,1)
516   write(6,*) ' full state sounding from comp, ph, grid%p, grid%al, grid%t_1, qv '
517   do k=1,kde-1
518     write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1)+grid%phb(1,k,1), &
519                                      grid%p(1,k,1)+grid%pb(1,k,1), grid%alt(1,k,1), &
520                                      grid%t_1(1,k,1)+t0, moist(1,k,1,P_QV)
521   enddo
522
523   write(6,*) ' pert state sounding from comp, grid%ph_1, pp, alp, grid%t_1, qv '
524   do k=1,kde-1
525     write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1), &
526                                      grid%p(1,k,1), grid%al(1,k,1), &
527                                      grid%t_1(1,k,1), moist(1,k,1,P_QV)
528   enddo
529
530! interp v
531
532  DO J = jts, jte
533  DO I = its, min(ide-1,ite)
534
535    IF (j == jds) THEN
536      z_at_v = grid%phb(i,1,j)/g
537    ELSE IF (j == jde) THEN
538      z_at_v = grid%phb(i,1,j-1)/g
539    ELSE
540      z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
541    END IF
542
543    p_surf = interp_0( p_in, zk, z_at_v, nl_in )
544
545    DO K = 1, kte
546      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
547      grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
548      grid%v_2(i,k,j) = grid%v_1(i,k,j)
549    ENDDO
550
551  ENDDO
552  ENDDO
553
554! interp u
555
556  DO J = jts, min(jde-1,jte)
557  DO I = its, ite
558
559    IF (i == ids) THEN
560      z_at_u = grid%phb(i,1,j)/g
561    ELSE IF (i == ide) THEN
562      z_at_u = grid%phb(i-1,1,j)/g
563    ELSE
564      z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
565    END IF
566
567    p_surf = interp_0( p_in, zk, z_at_u, nl_in )
568
569    DO K = 1, kte
570      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
571      grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
572      grid%u_2(i,k,j) = grid%u_1(i,k,j)
573    ENDDO
574
575  ENDDO
576  ENDDO
577
578!  set w
579
580  DO J = jts, min(jde-1,jte)
581  DO K = kts, kte
582  DO I = its, min(ide-1,ite)
583    grid%w_1(i,k,j) = 0.
584    grid%w_2(i,k,j) = 0.
585  ENDDO
586  ENDDO
587  ENDDO
588
589!  set a few more things
590
591  DO J = jts, min(jde-1,jte)
592  DO K = kts, kte-1
593  DO I = its, min(ide-1,ite)
594    grid%h_diabatic(i,k,j) = 0.
595  ENDDO
596  ENDDO
597  ENDDO
598
599  DO k=1,kte-1
600    grid%t_base(k) = grid%t_1(1,k,1)
601    grid%qv_base(k) = moist(1,k,1,P_QV)
602    grid%u_base(k) = grid%u_1(1,k,1)
603    grid%v_base(k) = grid%v_1(1,k,1)
604    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
605  ENDDO
606
607  DO J = jts, min(jde-1,jte)
608  DO I = its, min(ide-1,ite)
609     thtmp   = grid%t_2(i,1,j)+t0
610     ptmp    = grid%p(i,1,j)+grid%pb(i,1,j)
611     temp(1) = thtmp * (ptmp/p1000mb)**rcp
612     thtmp   = grid%t_2(i,2,j)+t0
613     ptmp    = grid%p(i,2,j)+grid%pb(i,2,j)
614     temp(2) = thtmp * (ptmp/p1000mb)**rcp
615     thtmp   = grid%t_2(i,3,j)+t0
616     ptmp    = grid%p(i,3,j)+grid%pb(i,3,j)
617     temp(3) = thtmp * (ptmp/p1000mb)**rcp
618
619!     grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
620     grid%tmn(I,J)=grid%tsk(I,J)-0.5
621  ENDDO
622  ENDDO
623
624  RETURN
625
626 END SUBROUTINE init_domain_rk
627
628   SUBROUTINE init_module_initialize
629   END SUBROUTINE init_module_initialize
630
631!---------------------------------------------------------------------
632
633!  test driver for get_sounding
634!
635!      implicit none
636!      integer n
637!      parameter(n = 1000)
638!      real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
639!      logical dry
640!      integer nl,k
641!
642!      dry = .false.
643!      dry = .true.
644!      call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
645!      write(6,*) ' input levels ',nl
646!      write(6,*) ' sounding '
647!      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
648!      do k=1,nl
649!        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)
650!      enddo
651!      end
652!
653!---------------------------------------------------------------------------
654
655      subroutine get_sounding( zk, p, p_dry, theta, rho, &
656                               u, v, qv, dry, nl_max, nl_in )
657      implicit none
658
659      integer nl_max, nl_in
660      real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
661           u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
662      logical dry
663
664      integer n
665      parameter(n=3000)
666      logical debug
667      parameter( debug = .true.)
668
669! input sounding data
670
671      real p_surf, th_surf, qv_surf
672      real pi_surf, pi(n)
673      real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
674
675! diagnostics
676
677      real rho_surf, p_input(n), rho_input(n)
678      real pm_input(n)  !  this are for full moist sounding
679
680! local data
681
682      real p1000mb,cv,cp,r,cvpm,g
683      parameter (p1000mb = 1.e+05, r = 287, cp = 1003., cv = cp-r, cvpm = -cv/cp, g=9.81 )
684      integer k, it, nl
685      real qvf, qvf1, dz
686
687!  first, read the sounding
688
689      call read_sounding( p_surf, th_surf, qv_surf, &
690                          h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
691
692      if(dry) then
693       do k=1,nl
694         qv_input(k) = 0.
695       enddo
696      endif
697
698      if(debug) write(6,*) ' number of input levels = ',nl
699
700        nl_in = nl
701        if(nl_in .gt. nl_max ) then
702          write(6,*) ' too many levels for input arrays ',nl_in,nl_max
703          call wrf_error_fatal ( ' too many levels for input arrays ' )
704        end if
705
706!  compute diagnostics,
707!  first, convert qv(g/kg) to qv(g/g)
708
709      do k=1,nl
710        qv_input(k) = 0.001*qv_input(k)
711      enddo
712
713      p_surf = 100.*p_surf  ! convert to pascals
714      qvf = 1. + rvovrd*qv_input(1)
715      rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
716      pi_surf = (p_surf/p1000mb)**(r/cp)
717
718      if(debug) then
719        write(6,*) ' surface density is ',rho_surf
720        write(6,*) ' surface pi is      ',pi_surf
721      end if
722
723
724!  integrate moist sounding hydrostatically, starting from the
725!  specified surface pressure
726!  -> first, integrate from surface to lowest level
727
728          qvf = 1. + rvovrd*qv_input(1)
729          qvf1 = 1. + qv_input(1)
730          rho_input(1) = rho_surf
731          dz = h_input(1)
732          do it=1,10
733            pm_input(1) = p_surf &
734                    - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
735            rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
736          enddo
737
738! integrate up the column
739
740          do k=2,nl
741            rho_input(k) = rho_input(k-1)
742            dz = h_input(k)-h_input(k-1)
743            qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
744            qvf = 1. + rvovrd*qv_input(k)   ! qv is in g/kg here
745 
746            do it=1,10
747              pm_input(k) = pm_input(k-1) &
748                      - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
749              rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
750            enddo
751          enddo
752
753!  we have the moist sounding
754
755!  next, compute the dry sounding using p at the highest level from the
756!  moist sounding and integrating down.
757
758        p_input(nl) = pm_input(nl)
759
760          do k=nl-1,1,-1
761            dz = h_input(k+1)-h_input(k)
762            p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
763          enddo
764
765
766        do k=1,nl
767! For the seabreeze case, we can hard-wire the winds and qv fields
768          zk(k) = h_input(k)
769          p(k) = pm_input(k)
770          p_dry(k) = p_input(k)
771          theta(k) = th_input(k)
772          rho(k) = rho_input(k)
773          u(k) = u_input(k)
774          v(k) = v_input(k)
775          qv(k) = qv_input(k)
776
777        enddo
778
779     if(debug) then
780      write(6,*) ' sounding '
781      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
782      do k=1,nl
783        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)
784      enddo
785
786     end if
787
788      end subroutine get_sounding
789
790!-------------------------------------------------------
791
792      subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
793      implicit none
794      integer n,nl
795      real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
796      logical end_of_file
797      logical debug
798
799      integer k
800
801      open(unit=10,file='input_sounding',form='formatted',status='old')
802      rewind(10)
803      read(10,*) ps, ts, qvs
804      if(debug) then
805        write(6,*) ' input sounding surface parameters '
806        write(6,*) ' surface pressure (mb) ',ps
807        write(6,*) ' surface pot. temp (K) ',ts
808        write(6,*) ' surface mixing ratio (g/kg) ',qvs
809      end if
810
811      end_of_file = .false.
812      k = 0
813
814      do while (.not. end_of_file)
815
816        read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
817        k = k+1
818        if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
819        go to 110
820 100    end_of_file = .true.
821 110    continue
822      enddo
823
824      nl = k
825
826      close(unit=10,status = 'keep')
827
828      end subroutine read_sounding
829
830END MODULE module_initialize_ideal
Note: See TracBrowser for help on using the repository browser.