source: ICOSA_LMDZ/src/phylmd/interface_icosa_lmdz.F90 @ 5874

Last change on this file since 5874 was 5724, checked in by yann meurdesoif, 5 months ago

Due to dynamico module reorganization, some module imports were missing.
YM

File size: 31.9 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, req_z
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_vort(:)   
20  TYPE(t_field),POINTER,SAVE :: f_vortc(:)   
21  TYPE(t_field),POINTER,SAVE :: f_dulon(:)
22  TYPE(t_field),POINTER,SAVE :: f_dulat(:)
23  TYPE(t_field),POINTER,SAVE :: f_dTemp(:)
24  TYPE(t_field),POINTER,SAVE :: f_dq(:)
25  TYPE(t_field),POINTER,SAVE :: f_dps(:)
26  TYPE(t_field),POINTER,SAVE :: f_duc(:)
27  TYPE(t_field),POINTER,SAVE :: f_bounds_lon(:)
28  TYPE(t_field),POINTER,SAVE :: f_bounds_lat(:)
29
30  INTEGER :: start_clock
31  INTEGER :: stop_clock
32  INTEGER :: count_clock=0
33 
34  INTEGER,SAVE :: nbp_phys
35  INTEGER,SAVE :: nbp_phys_glo
36
37
38CONTAINS
39
40  SUBROUTINE pre_initialize_physics
41  USE etat0_plugin_mod, ONLY : init_etat0_plugin, etat0_plugin
42  USE icolmdz_etat0, ONLY : init_etat0, etat0
43  USE icolmdz_param_gravity_wave, ONLY: init_param_gravity_wave
44  IMPLICIT NONE
45  !$OMP PARALLEL
46    init_etat0_plugin => init_etat0
47    etat0_plugin => etat0
48    CALL init_param_gravity_wave
49  !$OMP END PARALLEL
50  END SUBROUTINE pre_initialize_physics
51
52  SUBROUTINE initialize_physics
53  USE distrib_icosa_lmdz_mod, ONLY : init_distrib_icosa_lmdz, transfer_icosa_to_lmdz
54! from dynamico
55  USE domain_mod
56  USE dimensions
57  USE mpi_mod
58  USE mpipara
59  USE disvert_mod
60  USE xios_mod
61  USE time_mod , init_time_icosa=> init_time
62  USE transfert_mod
63  USE nudging_mod, ONLY : lam_halo_scheme
64 
65! from LMDZ
66  USE mod_grid_phy_lmdz, ONLY : unstructured
67  USE mod_phys_lmdz_omp_data, ONLY: klon_omp
68  USE transfert_mod
69  USE physics_distribution_mod, ONLY : init_physics_distribution
70  USE infotrac_phy, ONLY: init_infotrac_phy
71  USE icolmdz_param_gravity_wave, ONLY: param_gravity_wave
72
73   
74 
75  IMPLICIT NONE
76  INTEGER  :: ind,i,j,ij,pos,h
77  REAL(rstd),POINTER :: bounds_lon(:,:)
78  REAL(rstd),POINTER :: bounds_lat(:,:)
79 
80  REAL(rstd),ALLOCATABLE :: latfi(:)
81  REAL(rstd),ALLOCATABLE :: lonfi(:)
82  REAL(rstd),ALLOCATABLE :: airefi(:)
83  REAL(rstd),ALLOCATABLE :: bounds_latfi(:,:)
84  REAL(rstd),ALLOCATABLE :: bounds_lonfi(:,:)
85  LOGICAL   ,ALLOCATABLE :: outside(:,:)
86  LOGICAL   ,ALLOCATABLE :: outside_tmp(:,:)
87  LOGICAL   ,POINTER     :: out(:,:)
88!  REAL(rstd) :: pseudoalt(llm)
89
90  INTEGER :: nbp_phys, nbp_phys_glo
91 
92!$OMP PARALLEL
93    CALL allocate_field(f_bounds_lon,field_t,type_real,6)
94    CALL allocate_field(f_bounds_lat,field_t,type_real,6)
95    CALL allocate_field(f_p,field_t,type_real,llm+1,name="p_in")
96    CALL allocate_field(f_pks,field_t,type_real)
97    CALL allocate_field(f_pk,field_t,type_real,llm)
98    CALL allocate_field(f_p_layer,field_t,type_real,llm,name="p_layer_in")
99    CALL allocate_field(f_theta,field_t,type_real,llm)
100    CALL allocate_field(f_phi,field_t,type_real,llm,name="phi_in")
101    CALL allocate_field(f_Temp,field_t,type_real,llm,name="Temp_in")
102    CALL allocate_field(f_ulon,field_t,type_real,llm,name="ulon_in")
103    CALL allocate_field(f_ulat,field_t,type_real,llm,name="ulat_in")
104    CALL allocate_field(f_vort,field_z,type_real,llm,name="vort_in")
105    CALL allocate_field(f_vortc,field_t,type_real,llm,name="vortc_in")
106    CALL allocate_field(f_dulon,field_t,type_real,llm,name="dulon_out")
107    CALL allocate_field(f_dulat,field_t,type_real,llm,name="dulat_out")
108    CALL allocate_field(f_dTemp,field_t,type_real,llm,name="dTemp_out")
109    CALL allocate_field(f_dq,field_t,type_real,llm,nqtot,name="dq_out")
110    CALL allocate_field(f_dps,field_t,type_real,name="dps_out")
111    CALL allocate_field(f_duc,field_t,type_real,3,llm)   
112
113    CALL init_message(f_dps,req_i0,req_dps0)
114    CALL init_message(f_dulon,req_i0,req_dulon0)
115    CALL init_message(f_dulat,req_i0,req_dulat0)
116    CALL init_message(f_dTemp,req_i0,req_dTemp0)
117    CALL init_message(f_dq,req_i0,req_dq0)
118!$OMP END PARALLEL   
119
120    nbp_phys=0
121    DO ind=1,ndomain
122      CALL swap_dimensions(ind)
123
124      ALLOCATE(outside(ii_begin:ii_end,jj_begin:jj_end)) ! for limited area : don't take cells arround the border
125      ALLOCATE(outside_tmp(ii_begin-1:ii_end+1,jj_begin-1:jj_end+1)) ! for limited area : don't take cells arround the border
126      out=>domain(ind)%outside
127      DO j=jj_begin,jj_end
128        DO i=ii_begin,ii_end
129          outside(i,j)=  out(i+1,j)     .OR. & ! right
130                         out(i,j+1    ) .OR. & ! rup
131                         out(i-1  ,j+1) .OR. & ! lup
132                         out(i-1  ,j)   .OR. & !left
133                         out(i    ,j-1) .OR. & !ldown
134                         out(i+1,j-1)          !rdown   
135        ENDDO
136      ENDDO
137
138      outside_tmp=.FALSE.
139      outside_tmp(ii_begin:ii_end,jj_begin:jj_end)=outside
140     
141      DO h=1,lam_halo_scheme-1 ! do not compute physic on limited area halo
142        DO j=jj_begin,jj_end
143          DO i=ii_begin,ii_end
144              outside(i,j) = outside_tmp(i,j)       .OR. &
145                             outside_tmp(i+1,j)     .OR. & ! right
146                             outside_tmp(i,j+1    ) .OR. & ! rup
147                             outside_tmp(i-1  ,j+1) .OR. & ! lup
148                             outside_tmp(i-1  ,j)   .OR. & !left
149                             outside_tmp(i    ,j-1) .OR. & !ldown
150                             outside_tmp(i+1,j-1)          !rdown
151           ENDDO
152        ENDDO
153        outside_tmp(ii_begin:ii_end,jj_begin:jj_end)=outside
154      ENDDO
155     
156      DO j=jj_begin,jj_end
157        DO i=ii_begin,ii_end
158          IF (domain(ind)%own(i,j) .AND. .NOT.outside(i,j)) nbp_phys=nbp_phys+1
159        ENDDO
160      ENDDO
161      DEALLOCATE(outside)
162      DEALLOCATE(outside_tmp)
163    ENDDO
164   
165
166!initialize LMDZ5 physic mpi decomposition
167    CALL MPI_ALLREDUCE(nbp_phys,nbp_phys_glo,1,MPI_INTEGER,MPI_SUM,comm_icosa,ierr)
168    CALL init_physics_distribution(unstructured, 6, nbp_phys, 1, nbp_phys_glo, llm, comm_icosa)
169   
170    DO ind=1,ndomain
171        CALL swap_dimensions(ind)
172        CALL swap_geometry(ind)
173        bounds_lon=f_bounds_lon(ind)
174        bounds_lat=f_bounds_lat(ind)
175        DO j=jj_begin,jj_end
176          DO i=ii_begin,ii_end
177            ij=(j-1)*iim+i
178            CALL xyz2lonlat(xyz_v(ij+z_rup,:), bounds_lon(ij,1), bounds_lat(ij,1))
179            CALL xyz2lonlat(xyz_v(ij+z_up,:), bounds_lon(ij,2), bounds_lat(ij,2))
180            CALL xyz2lonlat(xyz_v(ij+z_lup,:), bounds_lon(ij,3), bounds_lat(ij,3))
181            CALL xyz2lonlat(xyz_v(ij+z_ldown,:), bounds_lon(ij,4), bounds_lat(ij,4))
182            CALL xyz2lonlat(xyz_v(ij+z_down,:), bounds_lon(ij,5), bounds_lat(ij,5))
183            CALL xyz2lonlat(xyz_v(ij+z_rdown,:), bounds_lon(ij,6), bounds_lat(ij,6))
184         ENDDO
185       ENDDO           
186    ENDDO
187
188  CALL init_infotrac_phy
189
190         
191!$OMP PARALLEL
192    CALL initialize_physics_omp
193    CALL param_gravity_wave
194!$OMP END PARALLEL           
195
196    CALL xios_set_context   
197
198  END SUBROUTINE initialize_physics
199
200
201  SUBROUTINE initialize_physics_omp
202  USE distrib_icosa_lmdz_mod, ONLY : init_distrib_icosa_lmdz, transfer_icosa_to_lmdz
203! from dynamico
204  USE domain_mod
205  USE dimensions
206  USE mpi_mod
207  USE mpipara
208  USE disvert_mod
209  USE xios_mod
210  USE time_mod , init_time_icosa=> init_time
211  USE omp_para
212  USE earth_const
213
214! from LMDZ
215  USE mod_grid_phy_lmdz, ONLY : unstructured, klon_glo
216  USE mod_phys_lmdz_para, ONLY: klon_omp, reduce_min_lmdz => reduce_min , gather_lmdz => gather , bcast_lmdz => bcast
217  USE time_phylmdz_mod, ONLY: init_time_lmdz => init_time
218  USE transfert_mod
219!  USE physics_distribution_mod, ONLY : init_physics_distribution
220  USE geometry_mod, ONLY : init_geometry
221  USE vertical_layers_mod, ONLY : init_vertical_layers
222  USE infotrac_phy, ONLY : init_infotrac_phy
223  USE inifis_mod, ONLY : inifis
224  USE readTracFiles_mod, ONLY: trac_type, isot_type
225  USE tracer_icosa_mod, ONLY : tracs
226  USE readTracFiles_mod, ONLY: delPhase
227!  USE phyaqua_mod, ONLY : iniaqua
228  USE phystokenc_mod, ONLY : init_phystokenc       !  use to generate mass flow files for offline mode
229 
230  IMPLICIT NONE
231
232
233
234  INTEGER  :: ind,i,j,k,ij,pos
235  REAL(rstd),POINTER :: bounds_lon(:,:)
236  REAL(rstd),POINTER :: bounds_lat(:,:)
237 
238  REAL(rstd),ALLOCATABLE :: latfi(:)
239  REAL(rstd),ALLOCATABLE :: lonfi(:)
240  REAL(rstd),ALLOCATABLE :: airefi(:)
241  REAL(rstd),ALLOCATABLE :: bounds_latfi(:,:)
242  REAL(rstd),ALLOCATABLE :: bounds_lonfi(:,:)
243  REAL(rstd),ALLOCATABLE :: ind_cell_glo_r(:)
244  INTEGER,   ALLOCATABLE :: ind_cell_glo(:)
245  INTEGER,   ALLOCATABLE :: ind_cell_glo_tot(:)
246  INTEGER,   ALLOCATABLE :: cell_glo_tot(:)
247  INTEGER :: ncell_glo_tot
248
249  REAL(rstd) :: pseudoalt(llm)
250  REAL(rstd) :: aps(llm)
251  REAL(rstd) :: bps(llm)
252  REAL(rstd) :: scaleheight
253
254  INTEGER :: run_length 
255  REAL :: day_length ! length of a day (s) ! SAVEd to be OpenMP shared <--- NO!!!!
256  INTEGER :: annee_ref 
257  INTEGER :: day_ref   
258  INTEGER :: day_ini   
259  REAL    :: start_time
260  REAL    :: physics_timestep   
261
262  ! Tracer stuff (SAVEd when needed to be OpenMP shared)
263  INTEGER :: nq
264  INTEGER                       :: nqo, nbtr, nbtr_inca
265  CHARACTER(len=256)              :: type_trac
266  INTEGER,ALLOCATABLE           :: conv_flg(:) ! conv_flg(it)=0 : convection desactivated for tracer number it
267  INTEGER,ALLOCATABLE           :: pbl_flg(:)  ! pbl_flg(it)=0  : boundary layer diffusion desactivaded for tracer number it
268  CHARACTER(len=8),ALLOCATABLE  :: solsym(:)  ! tracer name from inca
269
270  TYPE(t_field),POINTER,SAVE    :: f_ind_cell_glo(:)
271 
272  INTEGER :: iflag_phys   
273
274  INTEGER, ALLOCATABLE, DIMENSION(:) :: hadv_inca  ! index of horizontal trasport schema
275  INTEGER, ALLOCATABLE, DIMENSION(:) :: vadv_inca  ! index of vertical trasport schema
276
277   TYPE(trac_type) ::  tracers_ico2lmdz(nqtot)    !=== TRACERS DESCRIPTORS VECTOR
278   TYPE(isot_type) :: isotopes_ico2lmdz(1)        !=== ISOTOPES PARAMETERS VECTOR
279   INTEGER :: iq
280
281   CHARACTER(LEN=3)      :: descrq(30)            !--- Advection scheme description tags
282   logical, save :: first = .TRUE.
283
284   LOGICAL :: offline
285   INTEGER :: offline_time
286
287
288    CALL init_distrib_icosa_lmdz
289   
290    ALLOCATE(latfi(klon_omp))
291    ALLOCATE(lonfi(klon_omp))
292    ALLOCATE(airefi(klon_omp))
293    ALLOCATE(bounds_latfi(klon_omp,6))
294    ALLOCATE(bounds_lonfi(klon_omp,6))
295    ALLOCATE(ind_cell_glo_r(klon_omp))
296    ALLOCATE(ind_cell_glo(klon_omp))
297
298    CALL transfer_icosa_to_lmdz(geom%lat_i,latfi)
299    CALL transfer_icosa_to_lmdz(geom%lon_i,lonfi)
300    CALL transfer_icosa_to_lmdz(f_bounds_lat,bounds_latfi)
301    CALL transfer_icosa_to_lmdz(f_bounds_lon,bounds_lonfi)
302    CALL transfer_icosa_to_lmdz(geom%Ai,airefi)
303
304    CALL allocate_field(f_ind_cell_glo,field_t,type_real)
305   
306    DO ind=1,ndomain
307      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master ) CYCLE
308      CALL swap_dimensions(ind)
309      CALL swap_geometry(ind)
310      DO j=jj_begin,jj_end
311        DO i=ii_begin,ii_end
312          ij=(j-1)*iim+i
313          f_ind_cell_glo(ind)%rval2d(ij)=domain(ind)%assign_cell_glo(i,j)
314        ENDDO
315      ENDDO
316    ENDDO
317
318     
319   CALL transfer_icosa_to_lmdz(f_ind_cell_glo,ind_cell_glo_r)
320   CALL deallocate_field(f_ind_cell_glo)
321   ind_cell_glo=INT(ind_cell_glo_r)
322   DEALLOCATE(ind_cell_glo_r)   
323   
324   
325   CALL reduce_min_lmdz(MINVAL(-ind_cell_glo),ncell_glo_tot) ! reduce_max does not exist in lmdz, use reduce_min
326   CALL bcast_lmdz(ncell_glo_tot)
327   ncell_glo_tot=-ncell_glo_tot
328   ALLOCATE(cell_glo_tot(0:ncell_glo_tot))
329   ALLOCATE(ind_cell_glo_tot(klon_glo))
330   CALL gather_lmdz(ind_cell_glo,ind_cell_glo_tot)
331   CALL bcast_lmdz(ind_cell_glo_tot)
332   
333   cell_glo_tot=-1
334   DO i=1,klon_glo
335     cell_glo_tot(ind_cell_glo_tot(i))= 0
336   ENDDO
337   
338   pos=0
339   DO i=0,ncell_glo_tot
340     IF (cell_glo_tot(i)/=-1) THEN
341       cell_glo_tot(i) = pos
342       pos=pos + 1
343     ENDIF
344   ENDDO
345
346   DO i=1,klon_omp
347     ind_cell_glo(i)=cell_glo_tot(ind_cell_glo(i))
348   ENDDO 
349
350   ind_cell_glo = ind_cell_glo + 1 ! lmdz expect global indices begining to 1 not 0
351 
352   
353!   CALL MPI_ALLGATHER(ncell,1,MPI_INTEGER,ncell_mpi,1,MPI_INTEGER,comm_icosa,ierr)
354!
355!   displ(0)=0
356!   DO i=1,mpi_size-1
357!     displ(i)=displ(i-1)+ncell_mpi(i-1)
358!   ENDDO
359!   
360!   ALLOCATE(ind_glo_tot(ncell_tot))
361!   ALLOCATE(cell_glo_tot(0:ncell_glo_tot-1))
362!   
363!   cell_glo_tot(:)= -1
364!   CALL MPI_ALLGATHERV(ind_glo, ncell, MPI_INTEGER, ind_glo_tot, ncell_mpi, displ, MPI_INTEGER, comm_icosa,ierr)
365!   
366!   DO i=1,ncell_tot
367!     cell_glo_tot(ind_glo_tot(i))= 0
368!   ENDDO
369!
370!   ncell_glo=0
371!   DO i=0,ncell_glo_tot-1
372!     IF (cell_glo_tot(i)/=-1) THEN
373!       cell_glo_tot(i) = ncell_glo
374!       ncell_glo=ncell_glo + 1
375!     ENDIF
376!   ENDDO
377!
378!   DO i=1,ncell
379!     ind_glo(i)=cell_glo_tot(ind_glo(i))
380!   ENDDO 
381
382             
383    CALL init_geometry(klon_omp,lonfi, latfi, bounds_lonfi, bounds_latfi, airefi, ind_cell_glo)
384
385    scaleheight=scale_height/1000. ! Atmospheric scale height (km)
386    aps(1:llm)=0.5*(ap(1:llm)+ap(2:llm+1))
387    bps(1:llm)=0.5*(bp(1:llm)+bp(2:llm+1))
388    pseudoalt(:)=-scaleheight*log(presnivs(:)/preff)
389    CALL init_vertical_layers(llm,preff,scaleheight,ap,bp,aps,bps,presnivs,presinter,pseudoalt)
390
391    ! Initialize tracer names, numbers, etc. for physics
392    !Config  Key  = type_trac
393    !Config  Desc = Choix de couplage avec model de chimie INCA ou REPROBUS
394    !Config  Def  = lmdz
395    !Config  Help =
396    !Config  'lmdz' = pas de couplage, pur LMDZ
397    !Config  'lmdz|inca' = model de chime INCA
398    !Config  'lmdz|repr' = model de chime REPROBUS
399    type_trac = 'lmdz'
400    CALL getin('type_trac',type_trac)
401
402    descrq( 1: 2) = ['LMV','BAK']
403    descrq(10:20) = ['VL1','VLP','FH1','FH2','VLH','   ','PPM','PPS','PPP','   ','SLP']
404    descrq(30)    =  'PRA'
405
406    nqo = 0
407    DO iq=1,nqtot
408
409       tracers_ico2lmdz(iq)%name = tracs(iq)%name
410       
411       tracers_ico2lmdz(iq)%gen0Name = tracs(iq)%name
412       tracers_ico2lmdz(iq)%phase = tracs(iq)%phase
413       tracers_ico2lmdz(iq)%iadv = tracs(iq)%iadv
414         
415       IF (tracs(iq)%component .eq. "dynamico") then
416          tracers_ico2lmdz(iq)%component='lmdz'
417       ELSE
418          tracers_ico2lmdz(iq)%component=tracs(iq)%component
419       ENDIF
420
421       tracers_ico2lmdz(iq)%longName   = tracers_ico2lmdz(iq)%name
422       IF(tracers_ico2lmdz(iq)%iadv > 0) tracers_ico2lmdz(iq)%longName=TRIM(tracers_ico2lmdz(iq)%name)//descrq(tracers_ico2lmdz(iq)%iadv)
423
424       tracers_ico2lmdz(iq)%iGeneration = 0
425
426    ENDDO
427
428    nqo = COUNT(delPhase(tracs(:)%name) == 'H2O' .AND. tracers_ico2lmdz(:)%component == 'lmdz') !--- Number of water phases
429
430    isotopes_ico2lmdz(1)%parent='H2O'
431    isotopes_ico2lmdz(1)%phase='gls'
432    isotopes_ico2lmdz(1)%nphas=3
433     
434
435    nbtr=nqtot-nqo
436
437    ALLOCATE(conv_flg(nbtr))
438    ALLOCATE(pbl_flg(nbtr))
439
440    conv_flg(:) = 1 ! convection activated for all tracers
441    pbl_flg(:)  = 1 ! boundary layer activated for all tracers
442       
443
444    CALL init_infotrac_phy
445
446   ! Initialize physical constant
447    day_length=86400
448    CALL getin('day_length',day_length)
449    CALL inifis(day_length,radius,g,kappa*cpp,cpp)
450 
451
452   
453  ! init time
454    annee_ref=2015
455    CALL getin("anneeref",annee_ref)
456   
457    day_ref=1
458    CALL getin("dayref",day_ref)
459   
460    physics_timestep=dt*itau_physics
461    run_length=itaumax*dt
462    ndays=NINT(run_length/day_length)
463   
464    day_ini=INT(itau0*dt/day_length)+day_ref
465    start_time= itau0*dt/day_length-INT(itau0*dt/day_length)
466
467    CALL init_time_lmdz(annee_ref, day_ref, day_ini, start_time, int(ndays), physics_timestep)
468
469
470    ! Init Offline mode
471    offline = .FALSE.
472    CALL getin('offline',offline)
473
474    !  Choosing storage frequencies for offline mass flow files 
475    !  offline_time=12    2h=1day/12
476    !  offline_time=8     3h=1day/8
477    offline_time = 8
478    CALL getin('offline_time',offline_time)
479
480    ! Copy over "offline" settings
481    ! Flag and number of time steps for flux calculation and output
482    CALL init_phystokenc(offline,int(day_length/(offline_time*physics_timestep)))
483
484   
485!  Additional initializations for aquaplanets
486!    CALL getin("iflag_phys",iflag_phys)
487!    IF (iflag_phys>=100) THEN
488!      CALL iniaqua(klon_omp, iflag_phys)
489!    END IF
490
491 
492
493#ifdef INCA
494    CONTAINS
495
496      SUBROUTINE init_chem_trac()
497        IMPLICIT NONE
498
499        CALL  Init_chem_inca_trac(nbtr)
500
501      END SUBROUTINE init_chem_trac
502
503      SUBROUTINE init_chem_transport()
504
505        IMPLICIT NONE
506
507        CALL init_transport(solsym, conv_flg,pbl_flg, hadv_inca, vadv_inca)
508
509      END SUBROUTINE init_chem_transport
510
511
512#else
513    CONTAINS
514      SUBROUTINE init_chem_trac()
515        IMPLICIT NONE
516
517      END SUBROUTINE init_chem_trac
518
519      SUBROUTINE init_chem_transport()
520
521        IMPLICIT NONE
522
523      END SUBROUTINE init_chem_transport
524
525
526#endif
527
528
529
530  END SUBROUTINE  initialize_physics_omp
531 
532 
533
534
535  SUBROUTINE physics
536  USE icosa
537  USE time_mod
538  USE disvert_mod
539  USE transfert_mod
540  USE mpipara
541  USE xios_mod
542  USE wxios_mod
543  USE trace
544  USE distrib_icosa_lmdz_mod, ONLY : transfer_icosa_to_lmdz, transfer_lmdz_to_icosa
545  USE physics_external_mod, ONLY : it, f_phis, f_ps, f_theta_rhodz, f_u, f_wflux, f_q
546  USE write_field_mod
547  USE checksum_mod
548  USE vorticity_mod
549  USE earth_const
550
551! from LMDZ
552  USE mod_phys_lmdz_omp_data, ONLY: klon_omp
553  USE geometry_mod, ONLY : cell_area
554  USE physiq_mod, ONLY: physiq
555  USE icolmdz_param_gravity_wave, ONLY: param_gravity_wave
556  IMPLICIT NONE
557 
558    REAL(rstd),POINTER :: phis(:)
559    REAL(rstd),POINTER :: ps(:)
560    REAL(rstd),POINTER :: theta_rhodz(:,:,:)
561    REAL(rstd),POINTER :: u(:,:)
562    REAL(rstd),POINTER :: wflux(:,:)
563    REAL(rstd),POINTER :: q(:,:,:)
564    REAL(rstd),POINTER :: p(:,:)
565    REAL(rstd),POINTER :: pks(:)
566    REAL(rstd),POINTER :: pk(:,:)
567    REAL(rstd),POINTER :: p_layer(:,:)
568    REAL(rstd),POINTER :: theta(:,:)
569    REAL(rstd),POINTER :: phi(:,:)
570    REAL(rstd),POINTER :: Temp(:,:)
571    REAL(rstd),POINTER :: ulon(:,:)
572    REAL(rstd),POINTER :: ulat(:,:)
573    REAL(rstd),POINTER :: vort(:,:)
574    REAL(rstd),POINTER :: vortc(:,:)
575    REAL(rstd),POINTER :: dulon(:,:)
576    REAL(rstd),POINTER :: dulat(:,:)
577    REAL(rstd),POINTER :: dTemp(:,:)
578    REAL(rstd),POINTER :: dq(:,:,:)
579    REAL(rstd),POINTER :: dps(:)
580    REAL(rstd),POINTER :: duc(:,:,:)
581
582
583    INTEGER :: ind,l
584   
585    REAL(rstd),ALLOCATABLE,SAVE :: ps_phy(:)
586!$OMP THREADPRIVATE(ps_phy)
587    REAL(rstd),ALLOCATABLE,SAVE :: p_phy(:,:)
588!$OMP THREADPRIVATE(p_phy)
589    REAL(rstd),ALLOCATABLE,SAVE :: p_layer_phy(:,:)
590!$OMP THREADPRIVATE(p_layer_phy)
591    REAL(rstd),ALLOCATABLE,SAVE :: Temp_phy(:,:)
592!$OMP THREADPRIVATE(Temp_phy)
593    REAL(rstd),ALLOCATABLE,SAVE :: phis_phy(:)
594!$OMP THREADPRIVATE(phis_phy)
595    REAL(rstd),ALLOCATABLE,SAVE :: phi_phy(:,:)
596!$OMP THREADPRIVATE(phi_phy)
597    REAL(rstd),ALLOCATABLE,SAVE :: ulon_phy(:,:)
598!$OMP THREADPRIVATE(ulon_phy)
599    REAL(rstd),ALLOCATABLE,SAVE :: ulat_phy(:,:)
600!$OMP THREADPRIVATE(ulat_phy)
601    REAL(rstd),ALLOCATABLE,SAVE :: rot_phy(:,:)
602!$OMP THREADPRIVATE(rot_phy)
603    REAL(rstd),ALLOCATABLE,SAVE :: q_phy(:,:,:)
604!$OMP THREADPRIVATE(q_phy)
605    REAL(rstd),ALLOCATABLE,SAVE :: wflux_phy(:,:)
606!$OMP THREADPRIVATE(wflux_phy)
607    REAL(rstd),ALLOCATABLE,SAVE :: dulon_phy(:,:)
608!$OMP THREADPRIVATE(dulon_phy)
609    REAL(rstd),ALLOCATABLE,SAVE :: dulat_phy(:,:)
610!$OMP THREADPRIVATE(dulat_phy)
611    REAL(rstd),ALLOCATABLE,SAVE :: dTemp_phy(:,:)
612!$OMP THREADPRIVATE(dTemp_phy)
613    REAL(rstd),ALLOCATABLE,SAVE :: dq_phy(:,:,:)
614!$OMP THREADPRIVATE(dq_phy)
615    REAL(rstd),ALLOCATABLE,SAVE :: dps_phy(:)
616!$OMP THREADPRIVATE(dps_phy)
617    REAL(rstd)   :: dtphy
618    LOGICAL      :: debut
619    LOGICAL      :: lafin
620    LOGICAL,SAVE :: first=.TRUE.
621!$OMP THREADPRIVATE(first)
622
623   
624    IF(first) THEN
625      debut=.TRUE.
626    ELSE
627      debut=.FALSE.
628    ENDIF
629
630
631    IF(it-itau0>=itaumax) THEN
632      lafin=.TRUE.
633    ELSE
634      lafin=.FALSE.
635    ENDIF
636
637    IF (first) THEN
638      first=.FALSE.
639      CALL init_message(f_u,req_e1_vect,req_u)
640      CALL init_message(f_vort,req_z1_scal,req_z)
641      ALLOCATE(ps_phy(klon_omp))
642      ALLOCATE(p_phy(klon_omp,llm+1))
643      ALLOCATE(p_layer_phy(klon_omp,llm))
644      ALLOCATE(Temp_phy(klon_omp,llm))
645      ALLOCATE(phis_phy(klon_omp))
646      ALLOCATE(phi_phy(klon_omp,llm))
647      ALLOCATE(ulon_phy(klon_omp,llm))
648      ALLOCATE(ulat_phy(klon_omp,llm))
649      ALLOCATE(rot_phy(klon_omp,llm))
650      ALLOCATE(q_phy(klon_omp,llm,nqtot))
651      ALLOCATE(wflux_phy(klon_omp,llm))
652      ALLOCATE(dulon_phy(klon_omp,llm))
653      ALLOCATE(dulat_phy(klon_omp,llm))
654      ALLOCATE(dTemp_phy(klon_omp,llm))
655      ALLOCATE(dq_phy(klon_omp,llm,nqtot))
656      ALLOCATE(dps_phy(klon_omp))
657!$OMP BARRIER
658     
659!      CALL param_gravity_wave
660    ENDIF
661
662
663!$OMP MASTER       
664!    CALL update_calendar(it)
665!$OMP END MASTER
666!$OMP BARRIER
667    dtphy=itau_physics*dt
668   
669   
670   
671    CALL transfert_message(f_u,req_u)
672    DO ind=1,ndomain
673      IF (assigned_domain(ind)) THEN
674        CALL swap_dimensions(ind)
675        CALL swap_geometry(ind)
676        u=f_u(ind)
677        vort=f_vort(ind)
678        CALL compute_vorticity(u,vort)
679      ENDIF
680    ENDDO
681
682    CALL transfert_message(f_vort,req_z)
683
684   
685    DO ind=1,ndomain
686      CALL swap_dimensions(ind)
687      IF (assigned_domain(ind)) THEN
688        CALL swap_geometry(ind)
689     
690        phis=f_phis(ind)
691        ps=f_ps(ind)
692        theta_rhodz=f_theta_rhodz(ind)
693        u=f_u(ind)
694        q=f_q(ind)
695        wflux=f_wflux(ind)
696        p=f_p(ind)
697        pks=f_pks(ind)
698        pk=f_pk(ind)
699        p_layer=f_p_layer(ind)
700        theta=f_theta(ind)
701        phi=f_phi(ind)
702        Temp=f_Temp(ind)
703        ulon=f_ulon(ind)
704        ulat=f_ulat(ind)
705        vort=f_vort(ind)
706        vortc=f_vortc(ind)
707           
708        CALL grid_icosa_to_physics
709
710      ENDIF
711    ENDDO
712   
713!$OMP BARRIER
714!$OMP MASTER
715    CALL SYSTEM_CLOCK(start_clock)
716!$OMP END MASTER
717    CALL trace_start("physic")
718!    CALL trace_off()
719
720
721!    CALL writeField("p_in",f_p)
722!    CALL writeField("p_layer_in",f_p_layer)
723!    CALL writeField("phi_in",f_phi)
724!    CALL writeField("phis_in",f_phis)
725!    CALL writeField("ulon_in",f_ulon)
726!    CALL writeField("ulat_in",f_ulat)
727!    CALL writeField("Temp_in",f_Temp)
728!    CALL writeField("q_in",f_q)
729!    CALL writeField("wflux_in",f_wflux)
730!     CALL writeField("vortc",f_vortc)
731
732!    CALL checksum(f_p)
733!    CALL checksum(f_p_layer)
734!    CALL checksum(f_phi)
735!    CALL checksum(f_phis)
736!    CALL checksum(f_ulon)
737!    CALL checksum(f_ulat)
738!    CALL checksum(f_Temp)
739!    CALL checksum(f_q)
740!    CALL checksum(f_wflux)
741
742    CALL transfer_icosa_to_lmdz(f_p      , p_phy)
743    CALL transfer_icosa_to_lmdz(f_p_layer, p_layer_phy)
744    CALL transfer_icosa_to_lmdz(f_phi    , phi_phy)
745    CALL transfer_icosa_to_lmdz(f_phis   , phis_phy )
746    CALL transfer_icosa_to_lmdz(f_ulon   , ulon_phy )
747    CALL transfer_icosa_to_lmdz(f_ulat   , ulat_phy)
748    CALL transfer_icosa_to_lmdz(f_vortc   , rot_phy)
749    CALL transfer_icosa_to_lmdz(f_Temp   , Temp_phy)
750    CALL transfer_icosa_to_lmdz(f_q      , q_phy)
751    CALL transfer_icosa_to_lmdz(f_wflux  , wflux_phy)
752
753    DO l=1,llm
754      wflux_phy(:,l) = - wflux_phy(:,l)*cell_area(:)
755      phi_phy(:,l)=phi_phy(:,l)-phis_phy(:)
756    ENDDO
757   
758    CALL wxios_set_context()
759 
760    ! Ehouarn: rot_phy() not implemented!! Set it to zero for now
761!    rot_phy(:,:)=0
762    CALL physiq(klon_omp, llm, debut, lafin, dtphy, &
763                p_phy, p_layer_phy, phi_phy, phis_phy, presnivs, &
764                ulon_phy, ulat_phy, rot_phy, Temp_phy, q_phy, wflux_phy, &
765                dulon_phy, dulat_phy, dTemp_phy, dq_phy, dps_phy)
766   
767    CALL transfer_lmdz_to_icosa(dulon_phy, f_dulon )
768    CALL transfer_lmdz_to_icosa(dulat_phy, f_dulat )
769    CALL transfer_lmdz_to_icosa(dTemp_phy, f_dTemp )
770    CALL transfer_lmdz_to_icosa(dq_phy   , f_dq )
771    CALL transfer_lmdz_to_icosa(dps_phy  , f_dps )
772 
773!    CALL writeField("dulon_out",f_dulon)
774!    CALL writeField("dulat_out",f_dulat)
775!    CALL writeField("dTemp_out",f_dTemp)
776!    CALL writeField("dq_out",f_dq)
777!    CALL writeField("dps_out",f_dps)
778
779!    CALL checksum(f_dulon)
780!    CALL checksum(f_dulat)
781!    CALL checksum(f_dTemp)
782!    CALL checksum(f_dq)
783!    CALL checksum(f_dps)
784   
785    CALL send_message(f_dps,req_dps0)
786    CALL send_message(f_dulon,req_dulon0)
787    CALL send_message(f_dulat,req_dulat0)
788    CALL send_message(f_dTemp,req_dTemp0)
789    CALL send_message(f_dq,req_dq0)
790
791    CALL wait_message(req_dps0)
792    CALL wait_message(req_dulon0)
793    CALL wait_message(req_dulat0)
794    CALL wait_message(req_dTemp0)
795    CALL wait_message(req_dq0)
796
797
798!    CALL trace_on()
799    CALL trace_end("physic")
800!$OMP MASTER
801    CALL SYSTEM_CLOCK(stop_clock)
802    count_clock=count_clock+stop_clock-start_clock
803!$OMP END MASTER
804
805!$OMP BARRIER                       
806
807    DO ind=1,ndomain
808      CALL swap_dimensions(ind)
809      IF (assigned_domain(ind)) THEN
810        CALL swap_geometry(ind)
811
812        theta_rhodz=f_theta_rhodz(ind)
813        u=f_u(ind)
814        q=f_q(ind)
815        ps=f_ps(ind)
816        dulon=f_dulon(ind)
817        dulat=f_dulat(ind)
818        Temp=f_temp(ind)
819        dTemp=f_dTemp(ind)
820        dq=f_dq(ind)
821        dps=f_dps(ind)
822        duc=f_duc(ind)
823        p=f_p(ind)
824        pks=f_pks(ind)
825        pk=f_pk(ind)
826     
827        CALL grid_physics_to_icosa
828      ENDIF
829    ENDDO
830
831!$OMP BARRIER
832    CALL xios_set_context   
833   
834 
835  CONTAINS
836
837    SUBROUTINE grid_icosa_to_physics
838    USE pression_mod
839    USE exner_mod
840    USE theta2theta_rhodz_mod
841    USE geopotential_mod
842    USE wind_from_lonlat_mod
843    USE omp_para
844    IMPLICIT NONE
845   
846    REAL(rstd) :: uc(3)
847    INTEGER :: i,j,ij,l
848
849! compute pression
850
851      DO    l    = ll_begin,ll_endp1
852        DO j=jj_begin,jj_end
853          DO i=ii_begin,ii_end
854            ij=(j-1)*iim+i
855            p(ij,l) = ap(l) + bp(l) * ps(ij)
856          ENDDO
857        ENDDO
858      ENDDO
859
860!$OMP BARRIER
861
862! compute exner
863       
864       IF (is_omp_first_level) THEN
865         DO j=jj_begin,jj_end
866            DO i=ii_begin,ii_end
867               ij=(j-1)*iim+i
868               pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
869            ENDDO
870         ENDDO
871       ENDIF
872
873       ! 3D : pk
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                pk(ij,l) = cpp * ((.5/preff)*(p(ij,l)+p(ij,l+1))) ** kappa
879             ENDDO
880          ENDDO
881       ENDDO
882
883!$OMP BARRIER
884
885!   compute theta, temperature and pression at layer
886    DO    l    = ll_begin, ll_end
887      DO j=jj_begin,jj_end
888        DO i=ii_begin,ii_end
889          ij=(j-1)*iim+i
890          theta(ij,l) = theta_rhodz(ij,l,1) / ((p(ij,l)-p(ij,l+1))/g)
891          Temp(ij,l) = theta(ij,l) * pk(ij,l) / cpp
892          p_layer(ij,l)=preff*(pk(ij,l)/cpp)**(1./kappa)
893        ENDDO
894      ENDDO
895    ENDDO
896
897
898!!! Compute geopotential
899       
900  ! for first layer
901  IF (is_omp_first_level) THEN
902    DO j=jj_begin,jj_end
903      DO i=ii_begin,ii_end
904        ij=(j-1)*iim+i
905        phi( ij,1 ) = phis( ij ) + theta(ij,1) * ( pks(ij) - pk(ij,1) )
906      ENDDO
907    ENDDO
908  ENDIF
909!!-> implicit flush on phi(:,1)
910
911!$OMP BARRIER
912         
913  ! for other layers
914  DO l = ll_beginp1, ll_end
915    DO j=jj_begin,jj_end
916      DO i=ii_begin,ii_end
917        ij=(j-1)*iim+i
918        phi(ij,l) =  0.5 * ( theta(ij,l)  + theta(ij,l-1) )  &
919                         * (  pk(ij,l-1) -  pk(ij,l)    )
920      ENDDO
921    ENDDO
922  ENDDO       
923
924!$OMP BARRIER
925
926
927  IF (is_omp_first_level) THEN
928    DO l = 2, llm
929      DO j=jj_begin,jj_end
930! ---> Bug compilo intel ici en openmp
931! ---> Couper la boucle
932       IF (j==jj_end+1) PRINT*,"this message must not be printed"
933        DO i=ii_begin,ii_end
934          ij=(j-1)*iim+i
935          phi(ij,l) = phi(ij,l)+ phi(ij,l-1)
936        ENDDO
937      ENDDO
938    ENDDO
939! --> IMPLICIT FLUSH on phi --> non
940  ENDIF
941
942! compute wind centered lon lat compound
943    DO l=ll_begin,ll_end
944      DO j=jj_begin,jj_end
945        DO i=ii_begin,ii_end
946          ij=(j-1)*iim+i
947          uc(:)=1/Ai(ij)*                                                                                                &
948                        ( 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,:))  &
949                         + 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,:))          &
950                         + 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,:))          &
951                         + 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,:))    &
952                         + 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,:))&
953                         + 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,:)))
954          ulon(ij,l)=sum(uc(:)*elon_i(ij,:))
955          ulat(ij,l)=sum(uc(:)*elat_i(ij,:))
956        ENDDO
957      ENDDO
958    ENDDO
959
960
961! compute centered vorticity
962   
963    DO l=ll_begin,ll_end
964      DO j=jj_begin,jj_end
965        DO i=ii_begin,ii_end
966          ij=(j-1)*iim+i
967          vortc(ij,l) =  Riv(ij,vup)    * vort(ij+z_up,l)    + &
968                         Riv(ij,vlup)  * vort(ij+z_lup,l)   + &
969                         Riv(ij,vldown)* vort(ij+z_ldown,l) + &
970                         Riv(ij,vdown) * vort(ij+z_down,l)  + &
971                         Riv(ij,vrdown)* vort(ij+z_rdown,l) + &
972                         Riv(ij,vrup)  * vort(ij+z_rup,l)
973      ENDDO
974    ENDDO
975  ENDDO
976
977
978
979!$OMP BARRIER
980    END SUBROUTINE grid_icosa_to_physics
981
982
983    SUBROUTINE grid_physics_to_icosa
984    USE theta2theta_rhodz_mod
985    USE omp_para
986    IMPLICIT NONE
987      INTEGER :: i,j,ij,l,iq
988         
989      DO l=ll_begin,ll_end
990        DO j=jj_begin,jj_end
991          DO i=ii_begin,ii_end
992            ij=(j-1)*iim+i
993            duc(ij,:,l)=dulon(ij,l)*elon_i(ij,:)+dulat(ij,l)*elat_i(ij,:)
994          ENDDO
995        ENDDO
996      ENDDO
997
998      DO l=ll_begin,ll_end
999        DO j=jj_begin,jj_end
1000          DO i=ii_begin,ii_end
1001            ij=(j-1)*iim+i
1002            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,:) )
1003            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,:) )
1004            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,:) )
1005          ENDDO
1006        ENDDO
1007      ENDDO         
1008
1009      DO l=ll_begin,ll_end
1010        DO j=jj_begin,jj_end
1011          DO i=ii_begin,ii_end
1012            ij=(j-1)*iim+i
1013            Temp(ij,l)=Temp(ij,l)+ dtphy * dTemp(ij,l)
1014          ENDDO
1015        ENDDO
1016      ENDDO         
1017     
1018      DO iq=1,nqtot
1019        DO l=ll_begin,ll_end
1020          DO j=jj_begin,jj_end
1021            DO i=ii_begin,ii_end
1022              ij=(j-1)*iim+i
1023              q(ij,l,iq)=q(ij,l,iq)+ dtphy * dq(ij,l,iq)
1024            ENDDO
1025          ENDDO
1026        ENDDO
1027      ENDDO
1028
1029!$OMP BARRIER
1030     
1031     IF (is_omp_first_level) THEN
1032       DO j=jj_begin,jj_end
1033         DO i=ii_begin,ii_end
1034           ij=(j-1)*iim+i
1035           ps(ij)=ps(ij)+ dtphy * dps(ij)
1036          ENDDO
1037       ENDDO
1038     ENDIF
1039
1040!     CALL compute_temperature2theta_rhodz(ps,Temp,theta_rhodz,0)
1041
1042! compute pression
1043!$OMP BARRIER
1044      DO    l    = ll_begin,ll_endp1
1045        DO j=jj_begin,jj_end
1046          DO i=ii_begin,ii_end
1047            ij=(j-1)*iim+i
1048            p(ij,l) = ap(l) + bp(l) * ps(ij)
1049          ENDDO
1050        ENDDO
1051      ENDDO
1052
1053!$OMP BARRIER
1054
1055! compute exner
1056       
1057       IF (is_omp_first_level) THEN
1058         DO j=jj_begin,jj_end
1059            DO i=ii_begin,ii_end
1060               ij=(j-1)*iim+i
1061               pks(ij) = cpp * ( ps(ij)/preff ) ** kappa
1062            ENDDO
1063         ENDDO
1064       ENDIF
1065
1066       ! 3D : pk
1067       DO l = ll_begin,ll_end
1068          DO j=jj_begin,jj_end
1069             DO i=ii_begin,ii_end
1070                ij=(j-1)*iim+i
1071                pk(ij,l) = cpp * ((.5/preff)*(p(ij,l)+p(ij,l+1))) ** kappa
1072             ENDDO
1073          ENDDO
1074       ENDDO
1075
1076!$OMP BARRIER
1077
1078!   compute theta, temperature and pression at layer
1079    DO    l    = ll_begin, ll_end
1080      DO j=jj_begin,jj_end
1081        DO i=ii_begin,ii_end
1082          ij=(j-1)*iim+i
1083          theta_rhodz(ij,l,1) = temp(ij,l) * ((p(ij,l)-p(ij,l+1))/g) / (pk(ij,l) / cpp )
1084        ENDDO
1085      ENDDO
1086    ENDDO
1087   
1088    END SUBROUTINE grid_physics_to_icosa
1089
1090
1091
1092  END SUBROUTINE physics
1093
1094
1095
1096
1097
1098END MODULE interface_icosa_lmdz_mod
Note: See TracBrowser for help on using the repository browser.