source: trunk/mesoscale/LMD_LES_MARS/modif_mars/module_initialize_les.F @ 92

Last change on this file since 92 was 92, checked in by aslmd, 14 years ago

LMD_LES_MARS: (nouvelle physique) reparations mineures liees aux mises a jour recentes cote LMD_MM_MARS. le modele compile a nouveau correctement.

File size: 27.3 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#ifdef DM_PARALLEL
27   USE module_dm
28#endif
29
30
31CONTAINS
32
33
34!-------------------------------------------------------------------
35! this is a wrapper for the solver-specific init_domain routines.
36! Also dereferences the grid variables and passes them down as arguments.
37! This is crucial, since the lower level routines may do message passing
38! and this will get fouled up on machines that insist on passing down
39! copies of assumed-shape arrays (by passing down as arguments, the
40! data are treated as assumed-size -- ie. f77 -- arrays and the copying
41! business is avoided).  Fie on the F90 designers.  Fie and a pox.
42
43   SUBROUTINE init_domain ( grid )
44
45   IMPLICIT NONE
46
47   !  Input data.
48   TYPE (domain), POINTER :: grid
49   !  Local data.
50   INTEGER :: idum1, idum2
51
52   CALL set_scalar_indices_from_config ( head_grid%id , idum1, idum2 )
53
54     CALL init_domain_rk( grid &
55!
56#include <actual_new_args.inc>
57!
58                        )
59
60   END SUBROUTINE init_domain
61
62!-------------------------------------------------------------------
63
64   SUBROUTINE init_domain_rk ( grid &
65!
66# include <dummy_new_args.inc>
67!
68)
69   IMPLICIT NONE
70
71   !  Input data.
72   TYPE (domain), POINTER :: grid
73
74# include <dummy_new_decl.inc>
75
76   TYPE (grid_config_rec_type)              :: config_flags
77
78   !  Local data
79   INTEGER                             ::                       &
80                                  ids, ide, jds, jde, kds, kde, &
81                                  ims, ime, jms, jme, kms, kme, &
82                                  its, ite, jts, jte, kts, kte, &
83                                  i, j, k
84
85   ! Local data
86
87   INTEGER, PARAMETER :: nl_max = 1000
88   REAL, DIMENSION(nl_max) :: zk, p_in, theta, rho, u, v, qv, pd_in
89   INTEGER :: nl_in
90
91
92   INTEGER :: icm,jcm, ii, im1, jj, jm1, loop, error, fid, nxc, nyc
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    :: hm
97   REAL    :: pi
98
99!  stuff from original initialization that has been dropped from the Registry
100   REAL    :: vnu, xnu, xnus, dinit0, cbh, p0_temp, t0_temp, zd, zt
101   REAL    :: qvf1, qvf2, pd_surf
102   INTEGER :: it
103   real :: thtmp, ptmp, temp(3)
104
105   LOGICAL :: moisture_init
106   LOGICAL :: stretch_grid, dry_sounding
107
108  INTEGER :: xs , xe , ys , ye
109  REAL :: mtn_ht
110   LOGICAL, EXTERNAL :: wrf_dm_on_monitor
111!  For LES, add randx
112   real :: randx
113
114!!MARS
115 REAL :: lon_input, lat_input, alt_input, tsurf_input
116!!MARS
117
118#ifdef DM_PARALLEL
119#    include <data_calls.inc>
120#endif
121
122
123   SELECT CASE ( model_data_order )
124         CASE ( DATA_ORDER_ZXY )
125   kds = grid%sd31 ; kde = grid%ed31 ;
126   ids = grid%sd32 ; ide = grid%ed32 ;
127   jds = grid%sd33 ; jde = grid%ed33 ;
128
129   kms = grid%sm31 ; kme = grid%em31 ;
130   ims = grid%sm32 ; ime = grid%em32 ;
131   jms = grid%sm33 ; jme = grid%em33 ;
132
133   kts = grid%sp31 ; kte = grid%ep31 ;   ! note that tile is entire patch
134   its = grid%sp32 ; ite = grid%ep32 ;   ! note that tile is entire patch
135   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
136         CASE ( DATA_ORDER_XYZ )
137   ids = grid%sd31 ; ide = grid%ed31 ;
138   jds = grid%sd32 ; jde = grid%ed32 ;
139   kds = grid%sd33 ; kde = grid%ed33 ;
140
141   ims = grid%sm31 ; ime = grid%em31 ;
142   jms = grid%sm32 ; jme = grid%em32 ;
143   kms = grid%sm33 ; kme = grid%em33 ;
144
145   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
146   jts = grid%sp32 ; jte = grid%ep32 ;   ! note that tile is entire patch
147   kts = grid%sp33 ; kte = grid%ep33 ;   ! note that tile is entire patch
148         CASE ( DATA_ORDER_XZY )
149   ids = grid%sd31 ; ide = grid%ed31 ;
150   kds = grid%sd32 ; kde = grid%ed32 ;
151   jds = grid%sd33 ; jde = grid%ed33 ;
152
153   ims = grid%sm31 ; ime = grid%em31 ;
154   kms = grid%sm32 ; kme = grid%em32 ;
155   jms = grid%sm33 ; jme = grid%em33 ;
156
157   its = grid%sp31 ; ite = grid%ep31 ;   ! note that tile is entire patch
158   kts = grid%sp32 ; kte = grid%ep32 ;   ! note that tile is entire patch
159   jts = grid%sp33 ; jte = grid%ep33 ;   ! note that tile is entire patch
160
161   END SELECT
162
163
164!  stretch_grid = .true.
165!  FOR LES, set stretch to false
166   stretch_grid = .false.
167   delt = 3.
168!   z_scale = .50
169   z_scale = .40
170   pi = 2.*asin(1.0)
171   write(6,*) ' pi is ',pi
172   nxc = (ide-ids)/2
173   nyc = (jde-jds)/2
174
175   CALL model_to_grid_config_rec ( grid%id , model_config_rec , config_flags )
176
177! here we check to see if the boundary conditions are set properly
178
179   CALL boundary_condition_check( config_flags, bdyzone, error, grid%id )
180
181   moisture_init = .true.
182
183    grid%itimestep=0
184
185#ifdef DM_PARALLEL
186   CALL wrf_dm_bcast_bytes( icm , IWORDSIZE )
187   CALL wrf_dm_bcast_bytes( jcm , IWORDSIZE )
188#endif
189
190    CALL nl_set_mminlu(1, '    ')
191    CALL nl_set_iswater(1,0)
192    CALL nl_set_cen_lat(1,40.)
193    CALL nl_set_cen_lon(1,-105.)
194    CALL nl_set_truelat1(1,0.)
195    CALL nl_set_truelat2(1,0.)
196    CALL nl_set_moad_cen_lat (1,0.)
197    CALL nl_set_stand_lon (1,0.)
198    CALL nl_set_map_proj(1,0)
199
200
201!  here we initialize data we currently is not initialized
202!  in the input data
203
204    DO j = jts, jte
205      DO i = its, ite
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%msfvx_inv(i,j)= 1.
212         grid%msfvy(i,j)    = 1.
213         grid%sina(i,j)     = 0.
214         grid%cosa(i,j)     = 1.
215         grid%e(i,j)        = 0.
216!  for LES, include Coriolis force
217         grid%f(i,j)        = 0.  !!MARS MARS 1.e-4
218!!      grid%f(i,j)     = 2*EOMEG*SIN(grid%xlat(i,j)*degrad)
219      END DO
220   END DO
221
222    DO j = jts, jte
223    DO k = kts, kte
224      DO i = its, ite
225         grid%ww(i,k,j)     = 0.
226      END DO
227   END DO
228   END DO
229
230   grid%step_number = 0
231
232! set up the grid
233
234   IF (stretch_grid) THEN ! exponential stretch for eta (nearly constant dz)
235     DO k=1, kde
236      grid%znw(k) = (exp(-(k-1)/float(kde-1)/z_scale) - exp(-1./z_scale))/ &
237                                (1.-exp(-1./z_scale))
238     ENDDO
239   ELSE
240
241!!!MARS
242grid%znw(1)=1.000
243grid%znw(2)=0.9995 !5m
244grid%znw(3)=0.9980 !20m
245grid%znw(4)=0.9950 !55m
246DO k=5, kde
247   grid%znw(k) = grid%znw(4) * ( 1. - float(k-4)/float(kde-4) )
248ENDDO
249!!!!MARS
250!!
251!     DO k=1, kde
252!      grid%znw(k) = 1. - float(k-1)/float(kde-1)
253!     ENDDO
254
255   ENDIF
256
257   DO k=1, kde-1
258    grid%dnw(k) = grid%znw(k+1) - grid%znw(k)
259    grid%rdnw(k) = 1./grid%dnw(k)
260    grid%znu(k) = 0.5*(grid%znw(k+1)+grid%znw(k))
261   ENDDO
262   DO k=2, kde-1
263    grid%dn(k) = 0.5*(grid%dnw(k)+grid%dnw(k-1))
264    grid%rdn(k) = 1./grid%dn(k)
265    grid%fnp(k) = .5* grid%dnw(k  )/grid%dn(k)
266    grid%fnm(k) = .5* grid%dnw(k-1)/grid%dn(k)
267   ENDDO
268
269   cof1 = (2.*grid%dn(2)+grid%dn(3))/(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(2)
270   cof2 =     grid%dn(2)        /(grid%dn(2)+grid%dn(3))*grid%dnw(1)/grid%dn(3)
271   grid%cf1  = grid%fnp(2) + cof1
272   grid%cf2  = grid%fnm(2) - cof1 - cof2
273   grid%cf3  = cof2       
274
275   grid%cfn  = (.5*grid%dnw(kde-1)+grid%dn(kde-1))/grid%dn(kde-1)
276   grid%cfn1 = -.5*grid%dnw(kde-1)/grid%dn(kde-1)
277   grid%rdx = 1./config_flags%dx
278   grid%rdy = 1./config_flags%dy
279
280!  get the sounding from the ascii sounding file, first get dry sounding and
281!  calculate base state
282
283  dry_sounding = .true.
284  IF ( wrf_dm_on_monitor() ) THEN
285  write(6,*) ' getting dry sounding for base state '
286
287  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
288  ENDIF
289  CALL wrf_dm_bcast_real( zk , nl_max )
290  CALL wrf_dm_bcast_real( p_in , nl_max )
291  CALL wrf_dm_bcast_real( pd_in , nl_max )
292  CALL wrf_dm_bcast_real( theta , nl_max )
293  CALL wrf_dm_bcast_real( rho , nl_max )
294  CALL wrf_dm_bcast_real( u , nl_max )
295  CALL wrf_dm_bcast_real( v , nl_max )
296  CALL wrf_dm_bcast_real( qv , nl_max )
297  CALL wrf_dm_bcast_integer ( nl_in , 1 )
298
299  write(6,*) ' returned from reading sounding, nl_in is ',nl_in
300
301!!MARS
302!!MARS
303  open(unit=14,file='input_coord',form='formatted',status='old')
304  rewind(14)
305  read(14,*) lon_input
306  read(14,*) lat_input
307  close(14)
308  write(6,*) ' lon is ',lon_input
309  write(6,*) ' lat is ',lat_input
310!!MARS
311!!MARS
312
313!!MARS
314!!MARS
315  open(unit=18,file='input_more',form='formatted',status='old')
316  rewind(18)
317  read(18,*) alt_input, tsurf_input
318  close(18)
319  write(6,*) ' alt is ',alt_input
320  write(6,*) ' tsurf is ',tsurf_input
321!!MARS
322!!MARS
323
324!  find ptop for the desired ztop (ztop is input from the namelist),
325!  and find surface pressure
326
327  write(6,*) ' ztop above ground is ',config_flags%ztop
328  write(6,*) ' real ztop is ',config_flags%ztop + alt_input
329  grid%p_top = interp_0( p_in, zk, config_flags%ztop + alt_input, nl_in )
330
331  DO j=jts,jte
332  DO i=its,ite
333!!MARS
334    grid%ht(i,j) = alt_input
335    grid%tsk(i,j) = tsurf_input
336!!MARS
337    grid%xlat(i,j) = lat_input !+ float(j)*config_flags%dy/59000.
338    grid%xlong(i,j) = lon_input !+ float(i)*config_flags%dx/59000.
339    grid%mars_emiss(i,j)=0.95
340    grid%mars_cice(i,j)=0.
341    grid%mars_wice(i,j)=0.
342    grid%slpx(i,j) = 0.
343    grid%slpy(i,j) = 0.
344   DO k=1,config_flags%num_soil_layers
345    grid%mars_tsoil(i,k,j) = 0.
346   ENDDO
347    grid%mars_gw(i,1,j) = 0.
348    grid%mars_gw(i,2,j) = 0.
349    grid%mars_gw(i,3,j) = 0.
350    grid%mars_gw(i,4,j) = 0.
351    grid%mars_gw(i,5,j) = 0.
352!!MARS
353  ENDDO
354  ENDDO
355
356  xs=ide/2 -3
357  xs=ids   -3
358  xe=xs + 6
359  ys=jde/2 -3
360  ye=ys + 6
361  mtn_ht = 500
362#ifdef MTN
363  DO j=max(ys,jds),min(ye,jde-1)
364  DO i=max(xs,ids),min(xe,ide-1)
365     grid%ht(i,j) = mtn_ht * 0.25 * &
366               ( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) ) * &
367               ( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
368  ENDDO
369  ENDDO
370#endif
371#ifdef EW_RIDGE
372  DO j=max(ys,jds),min(ye,jde-1)
373  DO i=ids,ide
374     grid%ht(i,j) = mtn_ht * 0.50 * &
375               ( 1. + COS ( 2*pi/(ye-ys) * ( j-ys ) + pi ) )
376  ENDDO
377  ENDDO
378#endif
379#ifdef NS_RIDGE
380  DO j=jds,jde
381  DO i=max(xs,ids),min(xe,ide-1)
382     grid%ht(i,j) = mtn_ht * 0.50 * &
383               ( 1. + COS ( 2*pi/(xe-xs) * ( i-xs ) + pi ) )
384  ENDDO
385  ENDDO
386#endif
387  DO j=jts,jte
388  DO i=its,ite
389    grid%phb(i,1,j) = g * grid%ht(i,j)
390    grid%ph0(i,1,j) = g * grid%ht(i,j)
391  ENDDO
392  ENDDO
393
394  DO J = jts, jte
395  DO I = its, ite
396
397    p_surf = interp_0( p_in, zk, grid%phb(i,1,j)/g, nl_in )
398    grid%mub(i,j) = p_surf-grid%p_top
399
400!  this is dry hydrostatic sounding (base state), so given grid%p (coordinate),
401!  interp theta (from interp) and compute 1/rho from eqn. of state
402
403    DO K = 1, kte-1
404      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
405      grid%pb(i,k,j) = p_level
406      grid%t_init(i,k,j) = interp_0( theta, p_in, p_level, nl_in ) - t0
407      grid%alb(i,k,j) = (r_d/p1000mb)*(grid%t_init(i,k,j)+t0)*(grid%pb(i,k,j)/p1000mb)**cvpm
408    ENDDO
409
410!  calc hydrostatic balance (alternatively we could interp the geopotential from the
411!  sounding, but this assures that the base state is in exact hydrostatic balance with
412!  respect to the model eqns.
413
414    DO k  = 2,kte
415      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)
416    ENDDO
417
418  ENDDO
419  ENDDO
420
421  IF ( wrf_dm_on_monitor() ) THEN
422    write(6,*) ' ptop is ',grid%p_top
423    write(6,*) ' base state grid%mub(1,1), p_surf is ',grid%mub(1,1),grid%mub(1,1)+grid%p_top
424  ENDIF
425
426!  calculate full state for each column - this includes moisture.
427
428  write(6,*) ' getting moist sounding for full state '
429  dry_sounding = .false.
430  CALL get_sounding( zk, p_in, pd_in, theta, rho, u, v, qv, dry_sounding, nl_max, nl_in )
431
432  DO J = jts, min(jde-1,jte)
433  DO I = its, min(ide-1,ite)
434
435!  At this point grid%p_top is already set. find the DRY mass in the column
436!  by interpolating the DRY pressure. 
437
438   pd_surf = interp_0( pd_in, zk, grid%phb(i,1,j)/g, nl_in )
439
440!  compute the perturbation mass and the full mass
441
442    grid%mu_1(i,j) = pd_surf-grid%p_top - grid%mub(i,j)
443    grid%mu_2(i,j) = grid%mu_1(i,j)
444    grid%mu0(i,j) = grid%mu_1(i,j) + grid%mub(i,j)
445
446! given the dry pressure and coordinate system, interp the potential
447! temperature and qv
448
449    do k=1,kde-1
450
451      p_level = grid%znu(k)*(pd_surf - grid%p_top) + grid%p_top
452
453      moist(i,k,j,P_QV) = interp_0( qv, pd_in, p_level, nl_in )
454      grid%t_1(i,k,j)          = interp_0( theta, pd_in, p_level, nl_in ) - t0
455      grid%t_2(i,k,j)          = grid%t_1(i,k,j)
456     
457
458    enddo
459
460!  integrate the hydrostatic equation (from the RHS of the bigstep
461!  vertical momentum equation) down from the top to get grid%p.
462!  first from the top of the model to the top pressure
463
464    k = kte-1  ! top level
465
466    qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k,j,P_QV))
467    qvf2 = 1./(1.+qvf1)
468    qvf1 = qvf1*qvf2
469
470!    grid%p(i,k,j) = - 0.5*grid%mu_1(i,j)/grid%rdnw(k)
471    grid%p(i,k,j) = - 0.5*(grid%mu_1(i,j)+qvf1*grid%mub(i,j))/grid%rdnw(k)/qvf2
472    qvf = 1. + rvovrd*moist(i,k,j,P_QV)
473    grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
474                (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
475    grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
476
477!  down the column
478
479    do k=kte-2,1,-1
480      qvf1 = 0.5*(moist(i,k,j,P_QV)+moist(i,k+1,j,P_QV))
481      qvf2 = 1./(1.+qvf1)
482      qvf1 = qvf1*qvf2
483      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)
484      qvf = 1. + rvovrd*moist(i,k,j,P_QV)
485      grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
486                  (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
487      grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
488    enddo
489
490!  this is the hydrostatic equation used in the model after the
491!  small timesteps.  In the model, grid%al (inverse density)
492!  is computed from the geopotential.
493
494
495    grid%ph_1(i,1,j) = 0.
496    DO k  = 2,kte
497      grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
498                   (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
499                    grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
500                                                   
501      grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
502      grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
503    ENDDO
504
505    IF ( wrf_dm_on_monitor() ) THEN
506    if((i==2) .and. (j==2)) then
507     write(6,*) ' grid%ph_1 calc ',grid%ph_1(2,1,2),grid%ph_1(2,2,2),&
508                              grid%mu_1(2,2)+grid%mub(2,2),grid%mu_1(2,2), &
509                              grid%alb(2,1,2),grid%al(1,2,1),grid%rdnw(1)
510    endif
511    ENDIF
512
513  ENDDO
514  ENDDO
515
516!#if 0
517
518!  thermal perturbation to kick off convection
519
520  write(6,*) ' nxc, nyc for perturbation ',nxc,nyc
521  write(6,*) ' delt for perturbation ',delt
522
523! For LES, change the initial random perturbations
524! For 2D test, call randx outside I-loop
525! For 3D runs, call randx inside both I-J loops
526
527  DO J = jts, min(jde-1,jte)
528!   yrad = config_flags%dy*float(j-nyc)/10000.
529    yrad = 0.
530    DO I = its, min(ide-1,ite)
531!     xrad = config_flags%dx*float(i-nxc)/10000.
532      xrad = 0.
533      call random_number (randx)
534      randx = randx - 0.5
535!     DO K = 1, kte-1
536      DO K = 1, 4
537
538!  No bubbles for LES!
539!  put in preturbation theta (bubble) and recalc density.  note,
540!  the mass in the column is not changing, so when theta changes,
541!  we recompute density and geopotential
542
543!       zrad = 0.5*(grid%ph_1(i,k,j)+grid%ph_1(i,k+1,j)  &
544!                  +grid%phb(i,k,j)+grid%phb(i,k+1,j))/g
545!       zrad = (zrad-1500.)/1500.
546        zrad = 0.
547        RAD=SQRT(xrad*xrad+yrad*yrad+zrad*zrad)
548        IF(RAD <= 1.) THEN
549!          grid%t_1(i,k,j)=grid%t_1(i,k,j)+delt*COS(.5*PI*RAD)**2
550           grid%t_1(i,k,j)=grid%t_1(i,k,j)+ 0.1 *randx
551           grid%t_2(i,k,j)=grid%t_1(i,k,j)
552           qvf = 1. + rvovrd*moist(i,k,j,P_QV)
553           grid%alt(i,k,j) = (r_d/p1000mb)*(grid%t_1(i,k,j)+t0)*qvf* &
554                        (((grid%p(i,k,j)+grid%pb(i,k,j))/p1000mb)**cvpm)
555           grid%al(i,k,j) = grid%alt(i,k,j) - grid%alb(i,k,j)
556        ENDIF
557      ENDDO
558
559!  rebalance hydrostatically
560
561      DO k  = 2,kte
562        grid%ph_1(i,k,j) = grid%ph_1(i,k-1,j) - (1./grid%rdnw(k-1))*(       &
563                     (grid%mub(i,j)+grid%mu_1(i,j))*grid%al(i,k-1,j)+ &
564                      grid%mu_1(i,j)*grid%alb(i,k-1,j)  )
565                                                   
566        grid%ph_2(i,k,j) = grid%ph_1(i,k,j)
567        grid%ph0(i,k,j) = grid%ph_1(i,k,j) + grid%phb(i,k,j)
568      ENDDO
569
570    ENDDO
571  ENDDO
572
573!#endif
574
575   IF ( wrf_dm_on_monitor() ) THEN
576   write(6,*) ' grid%mu_1 from comp ', grid%mu_1(1,1)
577   write(6,*) ' full state sounding from comp, ph/g, grid%p, grid%al, grid%t_1, qv '
578   do k=1,kde-1
579     write(6,'(i3,1x,5(1x,1pe10.3))') k, (grid%ph_1(1,k,1)+grid%phb(1,k,1))/g, &
580                                      grid%p(1,k,1)+grid%pb(1,k,1), grid%alt(1,k,1), &
581                                      grid%t_1(1,k,1)+t0, moist(1,k,1,P_QV)
582   enddo
583
584   write(6,*) ' pert state sounding from comp, grid%ph_1, pp, alp, grid%t_1, qv '
585   do k=1,kde-1
586     write(6,'(i3,1x,5(1x,1pe10.3))') k, grid%ph_1(1,k,1), &
587                                      grid%p(1,k,1), grid%al(1,k,1), &
588                                      grid%t_1(1,k,1), moist(1,k,1,P_QV)
589   enddo
590   ENDIF
591
592! interp v
593
594  DO J = jts, jte
595  DO I = its, min(ide-1,ite)
596
597    IF (j == jds) THEN
598      z_at_v = grid%phb(i,1,j)/g
599    ELSE IF (j == jde) THEN
600      z_at_v = grid%phb(i,1,j-1)/g
601    ELSE
602      z_at_v = 0.5*(grid%phb(i,1,j)+grid%phb(i,1,j-1))/g
603    END IF
604    p_surf = interp_0( p_in, zk, z_at_v, nl_in )
605
606    DO K = 1, kte-1
607      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
608      grid%v_1(i,k,j) = interp_0( v, p_in, p_level, nl_in )
609      grid%v_2(i,k,j) = grid%v_1(i,k,j)
610    ENDDO
611
612  ENDDO
613  ENDDO
614
615! interp u
616
617  DO J = jts, min(jde-1,jte)
618  DO I = its, ite
619
620    IF (i == ids) THEN
621      z_at_u = grid%phb(i,1,j)/g
622    ELSE IF (i == ide) THEN
623      z_at_u = grid%phb(i-1,1,j)/g
624    ELSE
625      z_at_u = 0.5*(grid%phb(i,1,j)+grid%phb(i-1,1,j))/g
626    END IF
627
628    p_surf = interp_0( p_in, zk, z_at_u, nl_in )
629
630    DO K = 1, kte-1
631      p_level = grid%znu(k)*(p_surf - grid%p_top) + grid%p_top
632      grid%u_1(i,k,j) = interp_0( u, p_in, p_level, nl_in )
633      grid%u_2(i,k,j) = grid%u_1(i,k,j)
634    ENDDO
635
636  ENDDO
637  ENDDO
638
639!  set w
640
641  DO J = jts, min(jde-1,jte)
642  DO K = kts, kte
643  DO I = its, min(ide-1,ite)
644    grid%w_1(i,k,j) = 0.
645    grid%w_2(i,k,j) = 0.
646  ENDDO
647  ENDDO
648  ENDDO
649
650!!!MARS MARS
651IF (config_flags%init_MU .ne. 0.) THEN
652  grid%u_1 = grid%u_1*config_flags%init_MU
653  grid%u_2 = grid%u_2*config_flags%init_MU
654  print *, 'multiply zonal wind ', config_flags%init_MU
655ENDIF
656IF (config_flags%init_MV .ne. 0.) THEN
657  grid%v_1 = grid%v_1*config_flags%init_MV
658  grid%v_2 = grid%v_2*config_flags%init_MV
659  print *, 'multiply meridional wind ', config_flags%init_MV
660ENDIF
661IF (config_flags%init_U .ne. 0.) THEN
662  DO J = jts, min(jde-1,jte)
663  DO K = kts, kte-1
664  DO I = its, min(ide-1,ite)
665    grid%u_1(i,k,j) = config_flags%init_U
666    grid%u_2(i,k,j) = config_flags%init_U
667  ENDDO
668  ENDDO
669  ENDDO
670  print *, 'constant zonal wind ', config_flags%init_U
671  !!! ****** ou autre possibilité
672  !!! >   grid%u_1 = grid%u_1*0. + config_flags%init_U
673  !!! >   grid%u_2 = grid%u_2*0. + config_flags%init_U
674ENDIF
675IF (config_flags%init_V .ne. 0.) THEN
676  DO J = jts, min(jde-1,jte)
677  DO K = kts, kte-1
678  DO I = its, min(ide-1,ite)
679    grid%v_1(i,k,j) = config_flags%init_V
680    grid%v_2(i,k,j) = config_flags%init_V
681  ENDDO
682  ENDDO
683  ENDDO
684  print *, 'constant meridional wind ', config_flags%init_V
685ENDIF
686!!!MARS MARS
687
688
689!  set a few more things
690
691  DO J = jts, min(jde-1,jte)
692  DO K = kts, kte-1
693  DO I = its, min(ide-1,ite)
694    grid%h_diabatic(i,k,j) = 0.
695      !!!!! MARS NO WIND CASE
696      !grid%u_1(i,k,j) = 0.
697      !grid%u_2(i,k,j) = 0.
698      !grid%v_1(i,k,j) = 0.
699      !grid%v_2(i,k,j) = 0.
700      !!!!! MARS NO WIND CASE
701  ENDDO
702  ENDDO
703  ENDDO
704
705  IF ( wrf_dm_on_monitor() ) THEN
706  DO k=1,kte-1
707    grid%t_base(k) = grid%t_1(1,k,1)
708    grid%qv_base(k) = moist(1,k,1,P_QV)
709    grid%u_base(k) = grid%u_1(1,k,1)
710    grid%v_base(k) = grid%v_1(1,k,1)
711    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
712
713!!!!! MARS SIMPLE LES (PURE BUOYANCY)
714!!      grid%t_base(k)  = grid%t_init(its,k,jts)
715!      grid%t_base(k) = 0.
716!      grid%qv_base(k) = 0.
717!      grid%u_base(k)  = 0.
718!      grid%v_base(k)  = 0.
719!      grid%z_base(k) = 0.
720!!!!! MARS SIMPLE LES
721
722  ENDDO
723  ENDIF
724  CALL wrf_dm_bcast_real( grid%t_base , kte )
725  CALL wrf_dm_bcast_real( grid%qv_base , kte )
726  CALL wrf_dm_bcast_real( grid%u_base , kte )
727  CALL wrf_dm_bcast_real( grid%v_base , kte )
728  CALL wrf_dm_bcast_real( grid%z_base , kte )
729
730  DO J = jts, min(jde-1,jte)
731  DO I = its, min(ide-1,ite)
732     thtmp   = grid%t_2(i,1,j)+t0
733     ptmp    = grid%p(i,1,j)+grid%pb(i,1,j)
734     temp(1) = thtmp * (ptmp/p1000mb)**rcp
735     thtmp   = grid%t_2(i,2,j)+t0
736     ptmp    = grid%p(i,2,j)+grid%pb(i,2,j)
737     temp(2) = thtmp * (ptmp/p1000mb)**rcp
738     thtmp   = grid%t_2(i,3,j)+t0
739     ptmp    = grid%p(i,3,j)+grid%pb(i,3,j)
740     temp(3) = thtmp * (ptmp/p1000mb)**rcp
741
742!!    For LES-CBL, add 5 degrees to the surface temperature!
743!!
744!     grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)
745!!     grid%tsk(I,J)=grid%cf1*temp(1)+grid%cf2*temp(2)+grid%cf3*temp(3)+5.
746     grid%tmn(I,J)=grid%tsk(I,J)-0.5
747
748  ENDDO
749  ENDDO
750
751 END SUBROUTINE init_domain_rk
752
753   SUBROUTINE init_module_initialize
754   END SUBROUTINE init_module_initialize
755
756!---------------------------------------------------------------------
757
758!  test driver for get_sounding
759!
760!      implicit none
761!      integer n
762!      parameter(n = 1000)
763!      real zk(n),p(n),theta(n),rho(n),u(n),v(n),qv(n),pd(n)
764!      logical dry
765!      integer nl,k
766!
767!      dry = .false.
768!      dry = .true.
769!      call get_sounding( zk, p, pd, theta, rho, u, v, qv, dry, n, nl )
770!      write(6,*) ' input levels ',nl
771!      write(6,*) ' sounding '
772!      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
773!      do k=1,nl
774!        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)
775!      enddo
776!      end
777!
778!---------------------------------------------------------------------------
779
780      subroutine get_sounding( zk, p, p_dry, theta, rho, &
781                               u, v, qv, dry, nl_max, nl_in )
782      implicit none
783
784      integer nl_max, nl_in
785      real zk(nl_max), p(nl_max), theta(nl_max), rho(nl_max), &
786           u(nl_max), v(nl_max), qv(nl_max), p_dry(nl_max)
787      logical dry
788
789      integer n
790      parameter(n=1000)
791      logical debug
792      parameter( debug = .true.)
793
794! input sounding data
795
796      real p_surf, th_surf, qv_surf
797      real pi_surf, pi(n)
798      real h_input(n), th_input(n), qv_input(n), u_input(n), v_input(n)
799
800! diagnostics
801
802      real rho_surf, p_input(n), rho_input(n)
803      real pm_input(n)  !  this are for full moist sounding
804
805! local data
806
807      real p1000mb,cv,cp,r,cvpm,g
808!      parameter (p1000mb = 1.e+05, r = 287, cp = 1003., cv = cp-r, cvpm = -cv/cp, g=9.81 )
809!      parameter (p1000mb = 610., r = 192., cp = 844.6, cv = cp-r, cvpm = -cv/cp, g=3.72)
810      parameter (p1000mb = 610., r = 191., cp = 744.5, cv = cp-r, cvpm = -cv/cp, g=3.72)
811      integer k, it, nl
812      real qvf, qvf1, dz
813
814!  first, read the sounding
815
816      call read_sounding( p_surf, th_surf, qv_surf, &
817                          h_input, th_input, qv_input, u_input, v_input,n, nl, debug )
818
819      if(dry) then
820       do k=1,nl
821         qv_input(k) = 0.
822       enddo
823      endif
824
825      if(debug) write(6,*) ' number of input levels = ',nl
826
827        nl_in = nl
828        if(nl_in .gt. nl_max ) then
829          write(6,*) ' too many levels for input arrays ',nl_in,nl_max
830          call wrf_error_fatal ( ' too many levels for input arrays ' )
831        end if
832
833!  compute diagnostics,
834!  first, convert qv(g/kg) to qv(g/g)
835
836      do k=1,nl
837        qv_input(k) = 0.001*qv_input(k)
838      enddo
839
840      p_surf = 100.*p_surf  ! convert to pascals
841      qvf = 1. + rvovrd*qv_input(1)
842      rho_surf = 1./((r/p1000mb)*th_surf*qvf*((p_surf/p1000mb)**cvpm))
843      pi_surf = (p_surf/p1000mb)**(r/cp)
844
845      if(debug) then
846        write(6,*) ' surface density is ',rho_surf
847        write(6,*) ' surface pi is      ',pi_surf
848      end if
849
850
851!  integrate moist sounding hydrostatically, starting from the
852!  specified surface pressure
853!  -> first, integrate from surface to lowest level
854
855          qvf = 1. + rvovrd*qv_input(1)
856          qvf1 = 1. + qv_input(1)
857          rho_input(1) = rho_surf
858          dz = h_input(1)
859          do it=1,10
860!            pm_input(1) = p_surf &
861!                    - 0.5*dz*(rho_surf+rho_input(1))*g*qvf1
862!!!MARS MARS MARS
863            pm_input(1) = p_surf
864            rho_input(1) = 1./((r/p1000mb)*th_input(1)*qvf*((pm_input(1)/p1000mb)**cvpm))
865          enddo
866
867! integrate up the column
868
869          do k=2,nl
870            rho_input(k) = rho_input(k-1)
871            dz = h_input(k)-h_input(k-1)
872            qvf1 = 0.5*(2.+(qv_input(k-1)+qv_input(k)))
873            qvf = 1. + rvovrd*qv_input(k)   ! qv is in g/kg here
874 
875            do it=1,10
876              pm_input(k) = pm_input(k-1) &
877                      - 0.5*dz*(rho_input(k)+rho_input(k-1))*g*qvf1
878              rho_input(k) = 1./((r/p1000mb)*th_input(k)*qvf*((pm_input(k)/p1000mb)**cvpm))
879            enddo
880          enddo
881
882!  we have the moist sounding
883
884!  next, compute the dry sounding using p at the highest level from the
885!  moist sounding and integrating down.
886
887        p_input(nl) = pm_input(nl)
888
889          do k=nl-1,1,-1
890            dz = h_input(k+1)-h_input(k)
891            p_input(k) = p_input(k+1) + 0.5*dz*(rho_input(k)+rho_input(k+1))*g
892          enddo
893
894
895        do k=1,nl
896
897          zk(k) = h_input(k)
898          p(k) = pm_input(k)
899          p_dry(k) = p_input(k)
900          theta(k) = th_input(k)
901          rho(k) = rho_input(k)
902          u(k) = u_input(k)
903          v(k) = v_input(k)
904          qv(k) = qv_input(k)
905
906        enddo
907
908     if(debug) then
909      write(6,*) ' sounding '
910      write(6,*) '  k  height(m)  press (Pa) pd(Pa) theta (K) den(kg/m^3)  u(m/s)     v(m/s)    qv(g/g) '
911      do k=1,nl
912        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)
913      enddo
914
915     end if
916
917      end subroutine get_sounding
918
919!-------------------------------------------------------
920
921      subroutine read_sounding( ps,ts,qvs,h,th,qv,u,v,n,nl,debug )
922      implicit none
923      integer n,nl
924      real ps,ts,qvs,h(n),th(n),qv(n),u(n),v(n)
925      logical end_of_file
926      logical debug
927
928      integer k
929
930      open(unit=10,file='input_sounding',form='formatted',status='old')
931      rewind(10)
932      read(10,*) ps, ts, qvs
933      if(debug) then
934        write(6,*) ' input sounding surface parameters '
935        write(6,*) ' surface pressure (mb) ',ps
936        write(6,*) ' surface pot. temp (K) ',ts
937        write(6,*) ' surface mixing ratio (g/kg) ',qvs
938      end if
939
940      end_of_file = .false.
941      k = 0
942
943      do while (.not. end_of_file)
944
945        read(10,*,end=100) h(k+1), th(k+1), qv(k+1), u(k+1), v(k+1)
946        k = k+1
947        if(debug) write(6,'(1x,i3,5(1x,e10.3))') k, h(k), th(k), qv(k), u(k), v(k)
948        go to 110
949 100    end_of_file = .true.
950 110    continue
951      enddo
952
953      nl = k
954
955      close(unit=10,status = 'keep')
956
957      end subroutine read_sounding
958
959END MODULE module_initialize_ideal
Note: See TracBrowser for help on using the repository browser.