source: lmdz_wrf/WRFV3/dyn_em/module_initialize_seabreeze2d_x.F @ 1

Last change on this file since 1 was 1, checked in by lfita, 10 years ago
  • -- --- Opening of the WRF+LMDZ coupling repository --- -- -

WRF: version v3.3
LMDZ: version v1818

More details in:

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