source: trunk/ICOSA_LMDZ/src/phyvenus/interface_icosa_lmdz.f90 @ 2236

Last change on this file since 2236 was 2084, checked in by emillour, 6 years ago

Update the Dynamico-Venus interface to ensure that the initial local time for the physics is coherent.
Add the possibility to reset local time (to midnight at longitude 0) using flag raz_date in def file
(raz_date=1 to trigger reset of local time to midnight at longitude 0; default: raz_date=0 to do nothing).
EM

File size: 28.6 KB
Line 
1MODULE interface_icosa_lmdz_mod
2
3  USE field_mod, ONLY: t_field
4  USE transfert_mod, ONLY: t_message
5 
6 
7  TYPE(t_message),SAVE :: req_u
8  TYPE(t_message),SAVE :: req_dps0, req_dulon0, req_dulat0, req_dTemp0, req_dq0
9
10  TYPE(t_field),POINTER,SAVE :: f_p(:)
11  TYPE(t_field),POINTER,SAVE :: f_pks(:) 
12  TYPE(t_field),POINTER,SAVE :: f_pk(:) 
13  TYPE(t_field),POINTER,SAVE :: f_p_layer(:)   
14  TYPE(t_field),POINTER,SAVE :: f_theta(:)   
15  TYPE(t_field),POINTER,SAVE :: f_phi(:)   
16  TYPE(t_field),POINTER,SAVE :: f_Temp(:)   
17  TYPE(t_field),POINTER,SAVE :: f_ulon(:)   
18  TYPE(t_field),POINTER,SAVE :: f_ulat(:)   
19  TYPE(t_field),POINTER,SAVE :: f_dulon(:)
20  TYPE(t_field),POINTER,SAVE :: f_dulat(:)
21  TYPE(t_field),POINTER,SAVE :: f_dTemp(:)
22  TYPE(t_field),POINTER,SAVE :: f_dq(:)
23  TYPE(t_field),POINTER,SAVE :: f_dps(:)
24  TYPE(t_field),POINTER,SAVE :: f_duc(:)
25  TYPE(t_field),POINTER,SAVE :: f_bounds_lon(:)
26  TYPE(t_field),POINTER,SAVE :: f_bounds_lat(:)
27
28  INTEGER,SAVE :: start_clock
29  INTEGER,SAVE :: stop_clock
30  INTEGER,SAVE :: count_clock=0
31 
32  REAL,SAVE :: day_length ! length of a day (s)
33!  REAL,SAVE :: year_length ! length of a year (s)
34  INTEGER,SAVE :: start_day ! reference sol value at beginning of the run wrt Ls=0
35 
36  INTEGER,SAVE :: nbp_phys
37  INTEGER,SAVE :: nbp_phys_glo
38 
39  CHARACTER(len=30),SAVE,ALLOCATABLE :: tname(:) ! tracer names
40  CHARACTER(len=33),SAVE,ALLOCATABLE :: ttext(:) ! tracer long name for diagnostics
41  REAL,SAVE :: pday ! number of ellapsed sols since Ls=0
42  REAL,SAVE :: ptime ! "universal time" as fraction of sol (e.g. 0.5 for noon)
43
44
45CONTAINS
46
47  SUBROUTINE initialize_physics
48  USE distrib_icosa_lmdz_mod, ONLY : init_distrib_icosa_lmdz, transfer_icosa_to_lmdz
49! from dynamico
50  USE domain_mod
51  USE dimensions
52  USE mpi_mod
53  USE mpipara
54  USE disvert_mod
55  USE xios_mod
56  USE time_mod , init_time_icosa=> init_time
57  USE transfert_mod
58 
59! from LMDZ
60  USE mod_grid_phy_lmdz, ONLY : unstructured
61  USE mod_phys_lmdz_omp_data, ONLY: klon_omp
62  USE transfert_mod
63  USE physics_distribution_mod, ONLY : init_physics_distribution
64   
65 
66  IMPLICIT NONE
67  INTEGER  :: ind,i,j,ij,pos
68  REAL(rstd),POINTER :: bounds_lon(:,:)
69  REAL(rstd),POINTER :: bounds_lat(:,:)
70 
71  REAL(rstd),ALLOCATABLE :: latfi(:)
72  REAL(rstd),ALLOCATABLE :: lonfi(:)
73  REAL(rstd),ALLOCATABLE :: airefi(:)
74  REAL(rstd),ALLOCATABLE :: bounds_latfi(:,:)
75  REAL(rstd),ALLOCATABLE :: bounds_lonfi(:,:)
76  REAL(rstd) :: pseudoalt(llm)
77
78  INTEGER :: nbp_phys, nbp_phys_glo
79 
80!$OMP PARALLEL
81    CALL allocate_field(f_bounds_lon,field_t,type_real,6)
82    CALL allocate_field(f_bounds_lat,field_t,type_real,6)
83    CALL allocate_field(f_p,field_t,type_real,llm+1,name="p_in")
84    CALL allocate_field(f_pks,field_t,type_real)
85    CALL allocate_field(f_pk,field_t,type_real,llm)
86    CALL allocate_field(f_p_layer,field_t,type_real,llm,name="p_layer_in")
87    CALL allocate_field(f_theta,field_t,type_real,llm)
88    CALL allocate_field(f_phi,field_t,type_real,llm,name="phi_in")
89    CALL allocate_field(f_Temp,field_t,type_real,llm,name="Temp_in")
90    CALL allocate_field(f_ulon,field_t,type_real,llm,name="ulon_in")
91    CALL allocate_field(f_ulat,field_t,type_real,llm,name="ulat_in")
92    CALL allocate_field(f_dulon,field_t,type_real,llm,name="dulon_out")
93    CALL allocate_field(f_dulat,field_t,type_real,llm,name="dulat_out")
94    CALL allocate_field(f_dTemp,field_t,type_real,llm,name="dTemp_out")
95    CALL allocate_field(f_dq,field_t,type_real,llm,nqtot,name="dq_out")
96    CALL allocate_field(f_dps,field_t,type_real,name="dps_out")
97    CALL allocate_field(f_duc,field_t,type_real,3,llm)   
98
99    CALL init_message(f_dps,req_i0,req_dps0)
100    CALL init_message(f_dulon,req_i0,req_dulon0)
101    CALL init_message(f_dulat,req_i0,req_dulat0)
102    CALL init_message(f_dTemp,req_i0,req_dTemp0)
103    CALL init_message(f_dq,req_i0,req_dq0)
104!$OMP END PARALLEL   
105
106    nbp_phys=0
107    DO ind=1,ndomain
108      CALL swap_dimensions(ind)
109      DO j=jj_begin,jj_end
110        DO i=ii_begin,ii_end
111          IF (domain(ind)%own(i,j)) nbp_phys=nbp_phys+1
112        ENDDO
113      ENDDO
114    ENDDO
115   
116
117!initialize LMDZ5 physic mpi decomposition
118    CALL MPI_ALLREDUCE(nbp_phys,nbp_phys_glo,1,MPI_INTEGER,MPI_SUM,comm_icosa,ierr)
119    CALL init_physics_distribution(unstructured, 6, nbp_phys, 1, nbp_phys_glo, llm, comm_icosa)
120   
121    DO ind=1,ndomain
122        CALL swap_dimensions(ind)
123        CALL swap_geometry(ind)
124        bounds_lon=f_bounds_lon(ind)
125        bounds_lat=f_bounds_lat(ind)
126        DO j=jj_begin,jj_end
127          DO i=ii_begin,ii_end
128            ij=(j-1)*iim+i
129            CALL xyz2lonlat(xyz_v(ij+z_rup,:), bounds_lon(ij,1), bounds_lat(ij,1))
130            CALL xyz2lonlat(xyz_v(ij+z_up,:), bounds_lon(ij,2), bounds_lat(ij,2))
131            CALL xyz2lonlat(xyz_v(ij+z_lup,:), bounds_lon(ij,3), bounds_lat(ij,3))
132            CALL xyz2lonlat(xyz_v(ij+z_ldown,:), bounds_lon(ij,4), bounds_lat(ij,4))
133            CALL xyz2lonlat(xyz_v(ij+z_down,:), bounds_lon(ij,5), bounds_lat(ij,5))
134            CALL xyz2lonlat(xyz_v(ij+z_rdown,:), bounds_lon(ij,6), bounds_lat(ij,6))
135         ENDDO
136       ENDDO           
137    ENDDO
138         
139!$OMP PARALLEL
140    CALL initialize_physics_omp
141!$OMP END PARALLEL           
142
143    CALL xios_set_context   
144
145
146     
147
148  END SUBROUTINE initialize_physics
149
150
151  SUBROUTINE initialize_physics_omp
152  USE distrib_icosa_lmdz_mod, ONLY : init_distrib_icosa_lmdz, transfer_icosa_to_lmdz
153! from dynamico
154  USE domain_mod
155  USE dimensions
156  USE mpi_mod
157  USE mpipara
158  USE disvert_mod
159  USE xios_mod
160  USE time_mod , ONLY: init_time_icosa=> init_time, dt, itaumax, itau_physics
161  USE omp_para
162
163! from LMDZ
164  USE mod_grid_phy_lmdz, ONLY : unstructured
165  USE mod_phys_lmdz_omp_data, ONLY: klon_omp
166  USE time_phylmdz_mod, ONLY: init_time_lmdz => init_time
167  USE transfert_mod
168  USE physics_distribution_mod, ONLY : init_physics_distribution
169  USE dimphy, ONLY: init_dimphy
170  USE geometry_mod, ONLY : init_geometry
171  USE vertical_layers_mod, ONLY : init_vertical_layers
172!  USE planete_mod, ONLY: ini_planete_mod
173  USE cpdet_phy_mod, ONLY: init_cpdet_phy
174  USE infotrac_phy, ONLY: init_infotrac_phy
175 
176  USE netcdf 
177 
178  IMPLICIT NONE
179
180
181
182  INTEGER  :: ind,i,j,k,ij,pos
183  REAL(rstd),POINTER :: bounds_lon(:,:)
184  REAL(rstd),POINTER :: bounds_lat(:,:)
185 
186  REAL(rstd),ALLOCATABLE :: latfi(:)
187  REAL(rstd),ALLOCATABLE :: lonfi(:)
188  REAL(rstd),ALLOCATABLE :: airefi(:)
189  REAL(rstd),ALLOCATABLE :: bounds_latfi(:,:)
190  REAL(rstd),ALLOCATABLE :: bounds_lonfi(:,:)
191  REAL(rstd),ALLOCATABLE :: ind_cell_glo(:)
192  REAL(rstd),ALLOCATABLE :: dx(:)
193  REAL(rstd),ALLOCATABLE :: dy(:)
194
195  REAL(rstd) :: pseudoalt(llm)
196  REAL(rstd) :: aps(llm)
197  REAL(rstd) :: bps(llm)
198  real(rstd) :: scaleheight
199
200  ! For Cp(T)
201  REAL(rstd) :: nu_venus
202  REAL(rstd) :: t0_venus
203
204  ! Calendar related stuff
205  REAL(rstd) :: ptimestep
206  REAL(rstd) :: run_length 
207  INTEGER :: annee_ref 
208  INTEGER :: day_ref   
209  INTEGER :: day_ini
210  INTEGER :: day_end
211  INTEGER :: raz_date
212
213  ! Tracer related information
214  INTEGER :: iflag_trac
215  CHARACTER(len=4)              :: type_trac
216!  CHARACTER(len=30),ALLOCATABLE :: tname(:)    ! tracer short name for restart and diagnostics
217!  CHARACTER(len=33),ALLOCATABLE :: ttext(:)     ! tracer long name for diagnostics
218  TYPE(t_field),POINTER,SAVE    :: f_ind_cell_glo(:)
219 
220  INTEGER :: iflag_phys   
221  INTEGER :: nq
222
223  !! to get values from startphy.nc controle array
224  !! ---------------------------------------------
225  logical :: startphy_file
226  ! NetCDF stuff
227  integer :: status ! NetCDF return code
228  integer :: ncid ! NetCDF file ID
229  integer :: varid ! NetCDF variable ID
230  real :: tab_cntrl(100)
231
232    CALL init_distrib_icosa_lmdz
233   
234    ALLOCATE(latfi(klon_omp))
235    ALLOCATE(lonfi(klon_omp))
236    ALLOCATE(airefi(klon_omp))
237    ALLOCATE(bounds_latfi(klon_omp,6))
238    ALLOCATE(bounds_lonfi(klon_omp,6))
239    ALLOCATE(ind_cell_glo(klon_omp))
240    ALLOCATE(dx(klon_omp))
241    ALLOCATE(dy(klon_omp))
242
243    CALL transfer_icosa_to_lmdz(geom%lat_i,latfi)
244    CALL transfer_icosa_to_lmdz(geom%lon_i,lonfi)
245    CALL transfer_icosa_to_lmdz(f_bounds_lat,bounds_latfi)
246    CALL transfer_icosa_to_lmdz(f_bounds_lon,bounds_lonfi)
247    CALL transfer_icosa_to_lmdz(geom%Ai,airefi)
248
249    CALL allocate_field(f_ind_cell_glo,field_t,type_real)
250   
251    DO ind=1,ndomain
252      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master ) CYCLE
253      CALL swap_dimensions(ind)
254      CALL swap_geometry(ind)
255      DO j=jj_begin,jj_end
256        DO i=ii_begin,ii_end
257          ij=(j-1)*iim+i
258          f_ind_cell_glo(ind)%rval2d(ij)=domain(ind)%assign_cell_glo(i,j)
259        ENDDO
260      ENDDO
261    ENDDO
262
263     
264    CALL transfer_icosa_to_lmdz(f_ind_cell_glo,ind_cell_glo)
265    CALL deallocate_field(f_ind_cell_glo)
266     
267             
268    ! Initialize dimphy module
269    CALL init_dimphy(klon_omp,llm)
270
271    ! Dummy initializations for dx(),dy() In principle these are not used
272    ! in the physics; but this should be checked further...
273    dx(:)=1 ; dy(:)=1
274    CALL init_geometry(klon_omp,lonfi,latfi,bounds_lonfi,bounds_latfi,&
275                       airefi,INT(ind_cell_glo),dx,dy)
276
277    scaleheight=scale_height/1000. ! Atmospheric scale height (km)
278    aps(1:llm)=0.5*(ap(1:llm)+ap(2:llm+1))
279    bps(1:llm)=0.5*(bp(1:llm)+bp(2:llm+1))
280    pseudoalt(:)=-scaleheight*log(presnivs(:)/preff)
281    CALL init_vertical_layers(llm,preff,scaleheight,ap,bp,aps,bps,presnivs,pseudoalt)
282
283    ! Initialize planet_mod (quite redundant wrt vertical_levels...)
284!    CALL ini_planete_mod(llm,preff,ap,bp)
285
286    ! Initialize tracer names, numbers, etc. for physics
287
288! init tracers model for standard lmdz case
289!$OMP MASTER
290    ALLOCATE(tname(nqtot))
291    ALLOCATE(ttext(nqtot))
292!$OMP END MASTER
293!$OMP BARRIER
294
295! read tname() from traceur.def file
296    IF (is_mpi_root) THEN
297!$OMP MASTER
298    OPEN(unit=42,file="traceur.def",form="formatted",status="old",iostat=ierr)
299    IF (ierr==0) THEN
300      READ(42,*) nq ! should be the same as nqtot
301      IF (nq /= nqtot) THEN
302        WRITE(*,*) "Error: number of tracers in tracer.def should match nqtot!"
303        WRITE(*,*) "       will just use nqtot=",nqtot," tracers"
304      ENDIF
305      DO i=1,nqtot
306        READ(42,*) j,k,tname(i)
307        ttext(i)=trim(tname(i))//"VL1"
308      ENDDO
309      CLOSE(42)
310    ENDIF
311!$OMP END MASTER
312!$OMP BARRIER
313    ENDIF ! of (is_mpi_root)
314
315    DO i=1,nqtot
316      CALL bcast(tname(i))
317      CALL bcast(ttext(i))
318    ENDDO
319
320   ! Get/set some constants for the physics
321
322
323    startphy_file=.true.
324    CALL getin('startphy_file',startphy_file)
325
326    ! value in physics daysec=10087066.76s, important for solar radiation,
327    ! for the rest ptime/timeofday is what matters. To well estimate them,
328    ! day_length must be multiple of dt*itau_physics. Error order:1e-4.
329    day_length=10087000   
330    CALL getin('day_length',day_length)
331   
332    run_length=day_length ! default
333    CALL getin('run_length',run_length)
334   
335    raz_date=0 ! default: 0: no change in date
336    CALL getin('raz_date',raz_date)
337
338    IF (startphy_file) THEN
339      ! Read in some information from the startphy.nc file
340
341      IF (is_mpi_root) THEN
342!$OMP MASTER     
343      status=nf90_open('startphy.nc',NF90_NOWRITE,ncid)
344      if (status.ne.nf90_noerr) then
345        write(*,*)"Failed to open startphy.nc"
346        write(*,*)trim(nf90_strerror(status))
347        stop
348      endif
349
350      status=nf90_inq_varid(ncid,"controle",varid)
351      if (status.ne.nf90_noerr) then
352        write(*,*)"Failed to find controle variable"
353        write(*,*)trim(nf90_strerror(status))
354        stop
355      endif
356
357      status=nf90_get_var(ncid,varid,tab_cntrl)
358      ! extract needed variables from tab_cntrl
359      day_ini=tab_cntrl(13)
360      annee_ref=tab_cntrl(14)
361      ! check if tab_cntrl(1), the stored physics time step
362      ! is the same as the current physics time step (within roundoff precision)
363      if (abs(((itau_physics*dt)-tab_cntrl(1))/(itau_physics*dt))<=1.e-8) then
364        ! Everything OK
365        ptime=modulo((tab_cntrl(15)*tab_cntrl(1))/day_length,1.0)
366      else ! unless raz_date == 1 , we have a problem
367        if (raz_date==1) then
368          ! we reset date to midnight at lon=0 in the physics
369          ptime=0.0
370        else
371          write(*,*)"Error: physics time step in startphy.nc is different"
372          write(*,*)"       from what is specified via run_icosa.def"
373          write(*,*)"       From run_icosa.def:    ",itau_physics*dt
374          write(*,*)"       From startphy.nc file: ",tab_cntrl(1)
375          write(*,*)"       You must reset date to midnight at lon=0"
376          write(*,*)"       by specifying raz_date=1 in your def file"
377          call abort
378        endif
379      endif
380
381      status=nf90_close(ncid)
382!$OMP END MASTER     
383!$OMP BARRIER
384      ENDIF ! of !IF (is_mpi_root)
385     
386      CALL bcast(day_ini)
387      CALL bcast(annee_ref)
388      CALL bcast(ptime)
389
390    ELSE
391      ! required information that is not in tab_cntrl
392      ! has to be default or read from def files
393      day_ini=0
394      annee_ref=1
395      CALL getin('annee_ref',annee_ref)
396      ptime=0.
397    ENDIF
398
399    day_end=day_ini+nint(run_length/day_length)
400
401    ! Other required values which have to be read from def files
402    day_ref=1
403    CALL getin('day_ref',day_ref)
404    iflag_trac=0
405    CALL getin('iflag_trac',iflag_trac)
406
407
408    ! Initialize some physical constants
409    CALL suphec
410
411    ! Initialize cpdet_phy module
412    nu_venus=0.35
413    t0_venus=460.
414    CALL init_cpdet_phy(cpp,nu_venus,t0_venus)
415 
416    ! Initialize some "temporal and calendar" related variables
417    ptimestep=itau_physics*dt
418    CALL init_time_lmdz(annee_ref,day_ref,day_ini,day_end,ptimestep)
419 
420    ! Initialize tracers in physics
421    CALL init_infotrac_phy(iflag_trac,nqtot,tname,ttext)
422   
423   
424    ! Initializations of some module variables
425   
426!$OMP MASTER
427    ! initialize pday
428    pday = day_ini
429!$OMP END MASTER
430!$OMP BARRIER
431 
432  END SUBROUTINE  initialize_physics_omp
433 
434 
435
436
437  SUBROUTINE physics
438  USE icosa
439  USE time_mod
440  USE disvert_mod
441  USE transfert_mod
442  USE mpipara
443  USE xios_mod
444  USE wxios
445  USE trace
446  USE distrib_icosa_lmdz_mod, ONLY : transfer_icosa_to_lmdz, transfer_lmdz_to_icosa
447  USE physics_external_mod, ONLY : it, f_phis, f_ps, f_theta_rhodz, f_u, f_wflux, f_q
448  USE write_field_mod
449  USE checksum_mod
450! from LMDZ
451  USE mod_phys_lmdz_omp_data, ONLY: klon_omp
452  USE geometry_mod, ONLY : cell_area
453  USE physiq_mod, ONLY: physiq
454  IMPLICIT NONE
455 
456    REAL(rstd),POINTER :: phis(:)
457    REAL(rstd),POINTER :: ps(:)
458    REAL(rstd),POINTER :: theta_rhodz(:,:,:)
459    REAL(rstd),POINTER :: u(:,:)
460    REAL(rstd),POINTER :: wflux(:,:)
461    REAL(rstd),POINTER :: q(:,:,:)
462    REAL(rstd),POINTER :: p(:,:)
463    REAL(rstd),POINTER :: pks(:)
464    REAL(rstd),POINTER :: pk(:,:)
465    REAL(rstd),POINTER :: p_layer(:,:)
466    REAL(rstd),POINTER :: theta(:,:)
467    REAL(rstd),POINTER :: phi(:,:)
468    REAL(rstd),POINTER :: Temp(:,:)
469    REAL(rstd),POINTER :: ulon(:,:)
470    REAL(rstd),POINTER :: ulat(:,:)
471    REAL(rstd),POINTER :: dulon(:,:)
472    REAL(rstd),POINTER :: dulat(:,:)
473    REAL(rstd),POINTER :: dTemp(:,:)
474    REAL(rstd),POINTER :: dq(:,:,:)
475    REAL(rstd),POINTER :: dps(:)
476    REAL(rstd),POINTER :: duc(:,:,:)
477
478
479    INTEGER :: ind,l
480   
481    REAL(rstd),ALLOCATABLE,SAVE :: ps_phy(:)
482!$OMP THREADPRIVATE(ps_phy)
483    REAL(rstd),ALLOCATABLE,SAVE :: p_phy(:,:)
484!$OMP THREADPRIVATE(p_phy)
485    REAL(rstd),ALLOCATABLE,SAVE :: p_layer_phy(:,:)
486!$OMP THREADPRIVATE(p_layer_phy)
487    REAL(rstd),ALLOCATABLE,SAVE :: pk_phy(:,:)
488!$OMP THREADPRIVATE(p_layer_phy)
489    REAL(rstd),ALLOCATABLE,SAVE :: Temp_phy(:,:)
490!$OMP THREADPRIVATE(Temp_phy)
491    REAL(rstd),ALLOCATABLE,SAVE :: phis_phy(:)
492!$OMP THREADPRIVATE(phis_phy)
493    REAL(rstd),ALLOCATABLE,SAVE :: phi_phy(:,:)
494!$OMP THREADPRIVATE(phi_phy)
495    REAL(rstd),ALLOCATABLE,SAVE :: ulon_phy(:,:)
496!$OMP THREADPRIVATE(ulon_phy)
497    REAL(rstd),ALLOCATABLE,SAVE :: ulat_phy(:,:)
498!$OMP THREADPRIVATE(ulat_phy)
499    REAL(rstd),ALLOCATABLE,SAVE :: q_phy(:,:,:)
500!$OMP THREADPRIVATE(q_phy)
501    REAL(rstd),ALLOCATABLE,SAVE :: wflux_phy(:,:)
502!$OMP THREADPRIVATE(wflux_phy)
503    REAL(rstd),ALLOCATABLE,SAVE :: dulon_phy(:,:)
504!$OMP THREADPRIVATE(dulon_phy)
505    REAL(rstd),ALLOCATABLE,SAVE :: dulat_phy(:,:)
506!$OMP THREADPRIVATE(dulat_phy)
507    REAL(rstd),ALLOCATABLE,SAVE :: dTemp_phy(:,:)
508!$OMP THREADPRIVATE(dTemp_phy)
509    REAL(rstd),ALLOCATABLE,SAVE :: dq_phy(:,:,:)
510!$OMP THREADPRIVATE(dq_phy)
511    REAL(rstd),ALLOCATABLE,SAVE :: dps_phy(:)
512!$OMP THREADPRIVATE(dps_phy)
513    REAL(rstd)   :: dtphy
514    LOGICAL      :: debut
515    LOGICAL      :: lafin
516    LOGICAL,SAVE :: first=.TRUE.
517!$OMP THREADPRIVATE(first)
518    REAL(rstd),ALLOCATABLE,SAVE :: plevmoy(:)
519!$OMP THREADPRIVATE(plevmoy)
520    REAL(rstd),ALLOCATABLE,SAVE :: tmoy(:)
521!$OMP THREADPRIVATE(tmoy)
522   
523    IF(first) THEN
524      debut=.TRUE.
525    ELSE
526      debut=.FALSE.
527    ENDIF
528
529
530    IF(it-itau0>=itaumax) THEN
531      lafin=.TRUE.
532    ELSE
533      lafin=.FALSE.
534    ENDIF
535
536    IF (first) THEN
537      first=.FALSE.
538      CALL init_message(f_u,req_e1_vect,req_u)
539      ALLOCATE(ps_phy(klon_omp))
540      ALLOCATE(p_phy(klon_omp,llm+1))
541      ALLOCATE(p_layer_phy(klon_omp,llm))
542      ALLOCATE(pk_phy(klon_omp,llm))
543      ALLOCATE(Temp_phy(klon_omp,llm))
544      ALLOCATE(phis_phy(klon_omp))
545      ALLOCATE(phi_phy(klon_omp,llm))
546      ALLOCATE(ulon_phy(klon_omp,llm))
547      ALLOCATE(ulat_phy(klon_omp,llm))
548      ALLOCATE(q_phy(klon_omp,llm,nqtot))
549      ALLOCATE(wflux_phy(klon_omp,llm))
550      ALLOCATE(dulon_phy(klon_omp,llm))
551      ALLOCATE(dulat_phy(klon_omp,llm))
552      ALLOCATE(dTemp_phy(klon_omp,llm))
553      ALLOCATE(dq_phy(klon_omp,llm,nqtot))
554      ALLOCATE(dps_phy(klon_omp))
555      ALLOCATE(plevmoy(llm+1))
556      ALLOCATE(tmoy(llm))
557!$OMP BARRIER
558    ENDIF
559
560
561!$OMP MASTER       
562!    CALL update_calendar(it)
563!$OMP END MASTER
564!$OMP BARRIER
565    dtphy=itau_physics*dt
566   
567   
568   
569    CALL transfert_message(f_u,req_u)
570   
571    DO ind=1,ndomain
572      CALL swap_dimensions(ind)
573      IF (assigned_domain(ind)) THEN
574        CALL swap_geometry(ind)
575     
576        phis=f_phis(ind)
577        ps=f_ps(ind)
578        theta_rhodz=f_theta_rhodz(ind)
579        u=f_u(ind)
580        q=f_q(ind)
581        wflux=f_wflux(ind)
582        p=f_p(ind)
583        pks=f_pks(ind)
584        pk=f_pk(ind)
585        p_layer=f_p_layer(ind)
586        theta=f_theta(ind)
587        phi=f_phi(ind)
588        Temp=f_Temp(ind)
589        ulon=f_ulon(ind)
590        ulat=f_ulat(ind)
591           
592        CALL grid_icosa_to_physics
593
594      ENDIF
595    ENDDO
596   
597!$OMP BARRIER
598!$OMP MASTER
599    CALL SYSTEM_CLOCK(start_clock)
600!$OMP END MASTER
601    CALL trace_start("physic")
602!    CALL trace_off()
603
604
605!    CALL writeField("p_in",f_p)
606!    CALL writeField("p_layer_in",f_p_layer)
607!    CALL writeField("phi_in",f_phi)
608!    CALL writeField("phis_in",f_phis)
609!    CALL writeField("ulon_in",f_ulon)
610!    CALL writeField("ulat_in",f_ulat)
611!    CALL writeField("Temp_in",f_Temp)
612!    CALL writeField("q_in",f_q)
613!    CALL writeField("wflux_in",f_wflux)
614
615!    CALL checksum(f_p)
616!    CALL checksum(f_p_layer)
617!    CALL checksum(f_phi)
618!    CALL checksum(f_phis)
619!    CALL checksum(f_ulon)
620!    CALL checksum(f_ulat)
621!    CALL checksum(f_Temp)
622!    CALL checksum(f_q)
623!    CALL checksum(f_wflux)
624
625    CALL transfer_icosa_to_lmdz(f_p      , p_phy)
626    CALL transfer_icosa_to_lmdz(f_p_layer, p_layer_phy)
627    CALL transfer_icosa_to_lmdz(f_pk     , pk_phy)
628    CALL transfer_icosa_to_lmdz(f_phi    , phi_phy)
629    CALL transfer_icosa_to_lmdz(f_phis   , phis_phy )
630    CALL transfer_icosa_to_lmdz(f_ulon   , ulon_phy )
631    CALL transfer_icosa_to_lmdz(f_ulat   , ulat_phy)
632    CALL transfer_icosa_to_lmdz(f_Temp   , Temp_phy)
633    CALL transfer_icosa_to_lmdz(f_q      , q_phy)
634    CALL transfer_icosa_to_lmdz(f_wflux  , wflux_phy)
635
636    DO l=1,llm
637      ! Warning: In the physics, vertical flux convention is positive if downwards!
638      wflux_phy(:,l)= - wflux_phy(:,l)*cell_area(:)
639      ! Compute relative geopotential
640      phi_phy(:,l)=phi_phy(:,l)-phis_phy(:)
641    ENDDO
642   
643    CALL wxios_set_context()
644
645    ! Update pday and ptime to send to physics
646!$OMP MASTER
647    ptime=ptime+dtphy/day_length
648    IF (ptime >= 1.) THEN
649      ptime=ptime-1
650      pday=pday+1
651    ENDIF
652!$OMP END MASTER
653!$OMP BARRIER   
654
655! NB: arguments plevmoy(:) planet-averaged mean pressure (Pa) at interlayers
656!     and tmoy(:) planet-averaged mean temperature (K) at mid-layers
657!     are an issue. For now we just set them to unphysical values
658    plevmoy(:)=-999
659    tmoy(:)=-999
660    ! Ehouarn test: add some noise to ulon_phy and vlon_phy if they are zero
661    IF(minval(ulon_phy).eq.maxval(ulon_phy)) ulon_phy(:,:)=1.e-15
662    IF(minval(ulat_phy).eq.maxval(ulat_phy)) ulat_phy(:,:)=-1.e-15
663    CALL physiq(klon_omp, llm, nqtot, &
664                debut, lafin, &
665                pday, ptime, dtphy, &
666                p_phy, p_layer_phy, pk_phy, &
667                phi_phy, phis_phy, presnivs, &
668                ulon_phy, ulat_phy, Temp_phy, q_phy, &
669                wflux_phy, plevmoy, tmoy, &
670                dulon_phy, dulat_phy, dTemp_phy, dq_phy, dps_phy)
671   
672    CALL transfer_lmdz_to_icosa(dulon_phy, f_dulon )
673    CALL transfer_lmdz_to_icosa(dulat_phy, f_dulat )
674    CALL transfer_lmdz_to_icosa(dTemp_phy, f_dTemp )
675    CALL transfer_lmdz_to_icosa(dq_phy   , f_dq )
676    CALL transfer_lmdz_to_icosa(dps_phy  , f_dps )
677 
678!    CALL writeField("dulon_out",f_dulon)
679!    CALL writeField("dulat_out",f_dulat)
680!    CALL writeField("dTemp_out",f_dTemp)
681!    CALL writeField("dq_out",f_dq)
682!    CALL writeField("dps_out",f_dps)
683
684!    CALL checksum(f_dulon)
685!    CALL checksum(f_dulat)
686!    CALL checksum(f_dTemp)
687!    CALL checksum(f_dq)
688!    CALL checksum(f_dps)
689   
690    CALL send_message(f_dps,req_dps0)
691    CALL send_message(f_dulon,req_dulon0)
692    CALL send_message(f_dulat,req_dulat0)
693    CALL send_message(f_dTemp,req_dTemp0)
694    CALL send_message(f_dq,req_dq0)
695
696    CALL wait_message(req_dps0)
697    CALL wait_message(req_dulon0)
698    CALL wait_message(req_dulat0)
699    CALL wait_message(req_dTemp0)
700    CALL wait_message(req_dq0)
701
702
703!    CALL trace_on()
704    CALL trace_end("physic")
705!$OMP MASTER
706    CALL SYSTEM_CLOCK(stop_clock)
707    count_clock=count_clock+stop_clock-start_clock
708!$OMP END MASTER
709
710!$OMP BARRIER                       
711
712    DO ind=1,ndomain
713      CALL swap_dimensions(ind)
714      IF (assigned_domain(ind)) THEN
715        CALL swap_geometry(ind)
716
717        theta_rhodz=f_theta_rhodz(ind)
718        u=f_u(ind)
719        q=f_q(ind)
720        ps=f_ps(ind)
721        dulon=f_dulon(ind)
722        dulat=f_dulat(ind)
723        Temp=f_temp(ind)
724        dTemp=f_dTemp(ind)
725        dq=f_dq(ind)
726        dps=f_dps(ind)
727        duc=f_duc(ind)
728        p=f_p(ind)
729        pks=f_pks(ind)
730        pk=f_pk(ind)
731     
732        CALL grid_physics_to_icosa
733      ENDIF
734    ENDDO
735
736!$OMP BARRIER
737    CALL xios_set_context   
738   
739 
740  CONTAINS
741
742    SUBROUTINE grid_icosa_to_physics
743    USE pression_mod
744    USE exner_mod
745    USE theta2theta_rhodz_mod
746    USE geopotential_mod
747    USE wind_mod
748    USE omp_para
749    IMPLICIT NONE
750   
751    REAL(rstd) :: uc(3)
752    INTEGER :: i,j,ij,l
753   
754
755! compute pression
756
757      DO    l    = ll_begin,ll_endp1
758        DO j=jj_begin,jj_end
759          DO i=ii_begin,ii_end
760            ij=(j-1)*iim+i
761            p(ij,l) = ap(l) + bp(l) * ps(ij)
762          ENDDO
763        ENDDO
764      ENDDO
765
766!$OMP BARRIER
767
768! compute exner
769       
770       IF (is_omp_first_level) THEN
771         DO j=jj_begin,jj_end
772            DO i=ii_begin,ii_end
773               ij=(j-1)*iim+i
774               pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
775            ENDDO
776         ENDDO
777       ENDIF
778
779       ! 3D : pk
780       DO l = ll_begin,ll_end
781          DO j=jj_begin,jj_end
782             DO i=ii_begin,ii_end
783                ij=(j-1)*iim+i
784                pk(ij,l) = cpp * ((.5/preff)*(p(ij,l)+p(ij,l+1))) ** kappa
785             ENDDO
786          ENDDO
787       ENDDO
788
789!$OMP BARRIER
790
791!   compute theta, temperature and pression at layer
792    DO    l    = ll_begin, ll_end
793      DO j=jj_begin,jj_end
794        DO i=ii_begin,ii_end
795          ij=(j-1)*iim+i
796          theta(ij,l) = theta_rhodz(ij,l,1) / ((p(ij,l)-p(ij,l+1))/g)
797          Temp(ij,l) = theta(ij,l) * pk(ij,l) / cpp
798          p_layer(ij,l)=preff*(pk(ij,l)/cpp)**(1./kappa)
799        ENDDO
800      ENDDO
801    ENDDO
802
803
804!!! Compute geopotential
805       
806  ! for first layer
807  IF (is_omp_first_level) THEN
808    DO j=jj_begin,jj_end
809      DO i=ii_begin,ii_end
810        ij=(j-1)*iim+i
811        phi( ij,1 ) = phis( ij ) + theta(ij,1) * ( pks(ij) - pk(ij,1) )
812      ENDDO
813    ENDDO
814  ENDIF
815!!-> implicit flush on phi(:,1)
816         
817  ! for other layers
818  DO l = ll_beginp1, ll_end
819    DO j=jj_begin,jj_end
820      DO i=ii_begin,ii_end
821        ij=(j-1)*iim+i
822        phi(ij,l) =  0.5 * ( theta(ij,l)  + theta(ij,l-1) )  &
823                         * (  pk(ij,l-1) -  pk(ij,l)    )
824      ENDDO
825    ENDDO
826  ENDDO       
827
828!$OMP BARRIER
829
830
831  IF (is_omp_first_level) THEN
832    DO l = 2, llm
833      DO j=jj_begin,jj_end
834! ---> Bug compilo intel ici en openmp
835! ---> Couper la boucle
836       IF (j==jj_end+1) PRINT*,"this message must not be printed"
837        DO i=ii_begin,ii_end
838          ij=(j-1)*iim+i
839          phi(ij,l) = phi(ij,l)+ phi(ij,l-1)
840        ENDDO
841      ENDDO
842    ENDDO
843! --> IMPLICIT FLUSH on phi --> non
844  ENDIF
845
846! compute wind centered lon lat compound
847    DO l=ll_begin,ll_end
848      DO j=jj_begin,jj_end
849        DO i=ii_begin,ii_end
850          ij=(j-1)*iim+i
851          uc(:)=1/Ai(ij)*                                                                                                &
852                        ( ne(ij,right)*u(ij+u_right,l)*le(ij+u_right)*((xyz_v(ij+z_rdown,:)+xyz_v(ij+z_rup,:))/2-centroid(ij,:))  &
853                         + ne(ij,rup)*u(ij+u_rup,l)*le(ij+u_rup)*((xyz_v(ij+z_rup,:)+xyz_v(ij+z_up,:))/2-centroid(ij,:))          &
854                         + ne(ij,lup)*u(ij+u_lup,l)*le(ij+u_lup)*((xyz_v(ij+z_up,:)+xyz_v(ij+z_lup,:))/2-centroid(ij,:))          &
855                         + ne(ij,left)*u(ij+u_left,l)*le(ij+u_left)*((xyz_v(ij+z_lup,:)+xyz_v(ij+z_ldown,:))/2-centroid(ij,:))    &
856                         + ne(ij,ldown)*u(ij+u_ldown,l)*le(ij+u_ldown)*((xyz_v(ij+z_ldown,:)+xyz_v(ij+z_down,:))/2-centroid(ij,:))&
857                         + ne(ij,rdown)*u(ij+u_rdown,l)*le(ij+u_rdown)*((xyz_v(ij+z_down,:)+xyz_v(ij+z_rdown,:))/2-centroid(ij,:)))
858          ulon(ij,l)=sum(uc(:)*elon_i(ij,:))
859          ulat(ij,l)=sum(uc(:)*elat_i(ij,:))
860        ENDDO
861      ENDDO
862    ENDDO
863
864!$OMP BARRIER
865    END SUBROUTINE grid_icosa_to_physics
866
867
868    SUBROUTINE grid_physics_to_icosa
869    USE theta2theta_rhodz_mod
870    USE omp_para
871    IMPLICIT NONE
872      INTEGER :: i,j,ij,l,iq
873         
874      DO l=ll_begin,ll_end
875        DO j=jj_begin,jj_end
876          DO i=ii_begin,ii_end
877            ij=(j-1)*iim+i
878            duc(ij,:,l)=dulon(ij,l)*elon_i(ij,:)+dulat(ij,l)*elat_i(ij,:)
879          ENDDO
880        ENDDO
881      ENDDO
882
883      DO l=ll_begin,ll_end
884        DO j=jj_begin,jj_end
885          DO i=ii_begin,ii_end
886            ij=(j-1)*iim+i
887            u(ij+u_right,l) = u(ij+u_right,l) + dtphy * sum( 0.5*(duc(ij,:,l) + duc(ij+t_right,:,l))*ep_e(ij+u_right,:) )
888            u(ij+u_lup,l) = u(ij+u_lup,l) + dtphy * sum( 0.5*(duc(ij,:,l) + duc(ij+t_lup,:,l))*ep_e(ij+u_lup,:) )
889            u(ij+u_ldown,l) = u(ij+u_ldown,l) + dtphy*sum( 0.5*(duc(ij,:,l) + duc(ij+t_ldown,:,l))*ep_e(ij+u_ldown,:) )
890          ENDDO
891        ENDDO
892      ENDDO         
893
894      DO l=ll_begin,ll_end
895        DO j=jj_begin,jj_end
896          DO i=ii_begin,ii_end
897            ij=(j-1)*iim+i
898            Temp(ij,l)=Temp(ij,l)+ dtphy * dTemp(ij,l)
899          ENDDO
900        ENDDO
901      ENDDO         
902     
903      DO iq=1,nqtot
904        DO l=ll_begin,ll_end
905          DO j=jj_begin,jj_end
906            DO i=ii_begin,ii_end
907              ij=(j-1)*iim+i
908              q(ij,l,iq)=q(ij,l,iq)+ dtphy * dq(ij,l,iq)
909            ENDDO
910          ENDDO
911        ENDDO
912      ENDDO
913
914!$OMP BARRIER
915     
916     IF (is_omp_first_level) THEN
917       DO j=jj_begin,jj_end
918         DO i=ii_begin,ii_end
919           ij=(j-1)*iim+i
920           ps(ij)=ps(ij)+ dtphy * dps(ij)
921          ENDDO
922       ENDDO
923     ENDIF
924
925!     CALL compute_temperature2theta_rhodz(ps,Temp,theta_rhodz,0)
926
927! compute pression
928!$OMP BARRIER
929      DO    l    = ll_begin,ll_endp1
930        DO j=jj_begin,jj_end
931          DO i=ii_begin,ii_end
932            ij=(j-1)*iim+i
933            p(ij,l) = ap(l) + bp(l) * ps(ij)
934          ENDDO
935        ENDDO
936      ENDDO
937
938!$OMP BARRIER
939
940! compute exner
941       
942       IF (is_omp_first_level) THEN
943         DO j=jj_begin,jj_end
944            DO i=ii_begin,ii_end
945               ij=(j-1)*iim+i
946               pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
947            ENDDO
948         ENDDO
949       ENDIF
950
951       ! 3D : pk
952       DO l = ll_begin,ll_end
953          DO j=jj_begin,jj_end
954             DO i=ii_begin,ii_end
955                ij=(j-1)*iim+i
956                pk(ij,l) = cpp * ((.5/preff)*(p(ij,l)+p(ij,l+1))) ** kappa
957             ENDDO
958          ENDDO
959       ENDDO
960
961!$OMP BARRIER
962
963!   compute theta, temperature and pression at layer
964    DO    l    = ll_begin, ll_end
965      DO j=jj_begin,jj_end
966        DO i=ii_begin,ii_end
967          ij=(j-1)*iim+i
968          theta_rhodz(ij,l,1) = temp(ij,l) * ((p(ij,l)-p(ij,l+1))/g) / (pk(ij,l) / cpp )
969        ENDDO
970      ENDDO
971    ENDDO
972   
973    END SUBROUTINE grid_physics_to_icosa
974
975
976
977  END SUBROUTINE physics
978
979
980
981
982
983END MODULE interface_icosa_lmdz_mod
Note: See TracBrowser for help on using the repository browser.