source: LMDZ6/trunk/libf/dyn3dmem/mod_xios_dyn3dmem.f90 @ 5407

Last change on this file since 5407 was 5310, checked in by abarral, 6 weeks ago

unify abort_gcm
rename wxios -> wxios_mod

File size: 7.2 KB
Line 
1!
2! $Id$
3!
4! This module contains the interface between the LMDZ dynamics dyn3dmem module and XIOS.
5!
6! Lists of subroutines
7!      xios_dyn3dmem_init : context / calendar / domain / axis initialisations
8!
9! Initialisation of communicator between LMDZ and XIOS is done elsewhere: wxios_init called by init_const_mpi
10!                                                                         (one of the first calls in gcm.F90)
11! L. Fairhead 11/2017
12!
13!
14
15MODULE mod_xios_dyn3dmem
16
17     USE lmdz_xios
18     use wxios_mod, ONLY : g_comm
19     CHARACTER(len=100), SAVE :: dyn3d_ctx_name = "LMDZDYN"
20     TYPE(xios_context), SAVE :: dyn3d_ctx_handle
21!$OMP THREADPRIVATE(dyn3d_ctx_name, dyn3d_ctx_handle)
22 
23  INTERFACE writefield_dyn_u
24     MODULE PROCEDURE writefield_dyn1d_u, writefield_dyn2d_u
25  END INTERFACE writefield_dyn_u
26
27  INTERFACE writefield_dyn_v
28     MODULE PROCEDURE writefield_dyn1d_v, writefield_dyn2d_v
29  END INTERFACE writefield_dyn_v
30
31     REAL, ALLOCATABLE, SAVE :: NewField_U(:,:,:), NewField_V(:,:,:)
32 
33
34   CONTAINS
35
36   SUBROUTINE xios_dyn3dmem_init(xios_cal_type, anref, moisref, jourref,heureref, an, mois, jour, heure, zdtvr)
37
38
39     USE comgeom_mod_h
40     USE comvert_mod, ONLY: presnivs
41     USE parallel_lmdz
42
43     USE dimensions_mod, ONLY: iim, jjm, llm, ndm
44USE paramet_mod_h
45IMPLICIT NONE
46
47
48
49
50     TYPE(xios_duration) :: tstep_xios
51     TYPE(xios_date)                :: start_date
52     TYPE(xios_date)                :: time_origin
53     INTEGER :: an, mois, jour
54     REAL :: heure
55     CHARACTER (len=10) :: xios_cal_type
56     INTEGER :: anref, moisref, jourref
57     REAL :: heureref
58     REAL :: zdtvr
59     TYPE(xios_domain) :: dom_grid_U, dom_grid_V, dom_grid_T
60     REAL :: rlong(iip1), rlat(jjp1)
61     REAL :: pi
62     INTEGER :: ii, jj, jjb, jje, jjn
63
64!      WRITE(*,*)'Entree mod_xios_dyn3dmem'
65
66! 0 Initialisations
67     pi = 4. * ATAN (1.)
68! allocation of fields passed to xios
69!$OMP BARRIER
70!$OMP MASTER
71     allocate(NewField_U(iip1, jj_begin:jj_end, llm))
72     allocate(NewField_V(iip1, jj_begin:jj_end, llm))     
73!$OMP END MASTER
74!$OMP BARRIER
75
76! 1 Context initialisation
77!$OMP MASTER
78     CALL xios_context_initialize(dyn3d_ctx_name, g_comm)
79     CALL xios_get_handle(dyn3d_ctx_name, dyn3d_ctx_handle)
80     CALL xios_set_current_context(dyn3d_ctx_handle) 
81
82!     WRITE(*,*)'apres context initialisation mod_xios_dyn3dmem'
83
84! 2 calendar stuff
85
86     tstep_xios%second=zdtvr
87     CALL xios_define_calendar(type=xios_cal_type, start_date=xios_date(an, mois, jour,INT(heure),0,0), &
88            time_origin=xios_date(anref,moisref,jourref,INT(heureref),0,0), timestep=tstep_xios)
89
90!     WRITE(*,*)'apres  calendrier mod_xios_dyn3dmem'
91
92! 3 domain / grids / axis
93! Domains:
94      rlong(:) = rlonu(:) * 180. / pi
95      rlat(:) = rlatu(:) * 180. / pi
96
97      CALL xios_set_domain_attr("domain_U", ni_glo=iip1, nj_glo=jjp1,          &
98          type="rectilinear",ibegin=0, ni=iip1, jbegin=jj_begin-1, nj=jj_nb,   &
99          data_dim = 2, lonvalue_1d=rlong(1:iip1), latvalue_1d=rlat(jj_begin:jj_end))
100
101      jjb=jj_begin
102      jje=jj_end
103      jjn=jj_nb
104      IF (pole_sud) jjn=jjn-1
105      IF (pole_sud) jje=jje-1
106
107
108      rlong(:) = rlonv(:) * 180. / pi
109      do jj = jjb, jje
110        rlat(jj) = rlatv(jj) * 180. / pi
111      enddo
112     
113      CALL xios_set_domain_attr("domain_V", ni_glo=iip1, nj_glo=jjm,            &
114          type="rectilinear",ibegin=0, ni=iip1, jbegin=jj_begin-1, nj=jjn,   &
115          data_dim = 2, lonvalue_1d=rlong(1:iip1), latvalue_1d=rlat(jjb:jje))
116
117
118      rlong(:) = rlonv(:) * 180. / pi
119      rlat(:) = rlatu(:) * 180. / pi
120      CALL xios_set_domain_attr("domain_T", ni_glo=iip1, nj_glo=jjp1,          &
121          type="rectilinear",ibegin=0, ni=iip1, jbegin=jj_begin-1, nj=jj_nb,   &
122          data_dim = 2, lonvalue_1d=rlong(1:iip1), latvalue_1d=rlat(jj_begin:jj_end))
123     
124!     WRITE(*,*)'apres  domaine mod_xios_dyn3dmem'
125! Vertical axis
126       CALL xios_set_axis_attr("presnivs",n_glo=llm,value=presnivs)
127!     WRITE(*,*)'apres  vertical axis mod_xios_dyn3dmem'
128! 4 end of context definition
129       CALL xios_close_context_definition()
130!     WRITE(*,*)'apres close context init. axis mod_xios_dyn3dmem'
131!$OMP END MASTER
132   END SUBROUTINE xios_dyn3dmem_init
133
134   SUBROUTINE  writefield_dyn1d_u(name,Field)
135
136     USE parallel_lmdz
137     USE dimensions_mod, ONLY: iim, jjm, llm, ndm
138USE paramet_mod_h
139IMPLICIT NONE
140
141
142     CHARACTER(LEN=*)   :: name
143     REAL, DIMENSION(ij_begin:ij_end) :: Field
144     REAL, DIMENSION(iip1,  jj_begin:jj_end) :: NewField
145      LOGICAL,SAVE :: debuglf=.true.
146!$OMP THREADPRIVATE(debuglf)
147     
148     NewField(:,jj_begin:jj_end)=reshape(Field(ij_begin:ij_end),(/iip1,jj_nb/))
149
150!$OMP BARRIER       
151!$OMP MASTER
152     CALL xios_send_field(name, NewField)
153!$OMP END MASTER   
154 
155   END SUBROUTINE  writefield_dyn1d_u
156
157   SUBROUTINE  writefield_dyn2d_u(name,Field)
158
159     USE parallel_lmdz
160     USE dimensions_mod, ONLY: iim, jjm, llm, ndm
161USE paramet_mod_h
162IMPLICIT NONE
163
164
165     CHARACTER(LEN=*)   :: name
166     REAL, DIMENSION(ij_begin:ij_end,llm) :: Field
167!     REAL, ALLOCATABLE, SAVE :: NewField(:,:,:)
168     INTEGER :: i,j,l, count
169
170!!!!!$OMP BARRIER
171!!!!!$OMP MASTER
172!!!!     allocate(NewField(iip1, jj_begin:jj_end, llm))
173!!!!!$OMP END MASTER
174!!!!!$OMP BARRIER
175
176
177!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
178     DO l = 1, llm
179       NewField_U(:,jj_begin:jj_end,l)=reshape(Field(ij_begin:ij_end,l),(/iip1,jj_nb/))
180     ENDDO
181!$OMP ENDDO
182!$OMP BARRIER
183
184!$OMP MASTER
185     CALL xios_send_field(name, NewField_U)
186!!!!     DEALLOCATE(NewField)
187!$OMP END MASTER   
188!$OMP BARRIER
189 
190   END SUBROUTINE  writefield_dyn2d_u
191
192   SUBROUTINE  writefield_dyn1d_v(name,Field)
193
194     USE parallel_lmdz
195     USE dimensions_mod, ONLY: iim, jjm, llm, ndm
196USE paramet_mod_h
197IMPLICIT NONE
198
199
200     CHARACTER(LEN=*)   :: name
201     REAL, DIMENSION(ij_begin:ij_end) :: Field
202     REAL, DIMENSION(iip1,  jj_begin:jj_end) :: NewField
203     INTEGER ::  jje, ije, jjn
204
205     IF (pole_sud) THEN
206       jje=jj_end-1
207       ije=ij_end-iip1
208       jjn=jj_nb-1
209     ELSE
210       jje=jj_end
211       ije=ij_end
212       jjn=jj_nb
213     ENDIF
214
215     NewField(:,jj_begin:jje)=reshape(Field(ij_begin:ije),(/iip1,jjn/))
216
217!$OMP BARRIER       
218!$OMP MASTER
219     CALL xios_send_field(name, NewField(:,jj_begin:jje))
220!$OMP END MASTER   
221 
222   END SUBROUTINE  writefield_dyn1d_v
223
224   SUBROUTINE  writefield_dyn2d_v(name,Field)
225
226     USE parallel_lmdz
227     USE dimensions_mod, ONLY: iim, jjm, llm, ndm
228USE paramet_mod_h
229IMPLICIT NONE
230
231
232     CHARACTER(LEN=*)   :: name
233     REAL, DIMENSION(ij_begin:ij_end,llm) :: Field
234!!!!     REAL, ALLOCATABLE, SAVE :: NewField(:,:,:)
235     INTEGER :: l, jje, ije, jjn
236
237!!!!!$OMP BARRIER
238!!!!!$OMP MASTER
239!!!!     allocate(NewField(iip1,  jj_begin:jj_end,llm))
240!!!!!$OMP END MASTER
241!!!!!$OMP BARRIER
242
243     IF (pole_sud) THEN
244       jje=jj_end-1
245       ije=ij_end-iip1
246       jjn=jj_nb-1
247     ELSE
248       jje=jj_end
249       ije=ij_end
250       jjn=jj_nb
251     ENDIF
252
253
254!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
255     DO l = 1, llm
256        NewField_V(:,jj_begin:jje,l)=reshape(Field(ij_begin:ije,l),(/iip1,jjn/))
257     ENDDO
258!$OMP ENDDO
259!$OMP BARRIER       
260
261!$OMP MASTER
262     CALL xios_send_field(name, NewField_V(:,jj_begin:jje,:))
263!!!!     DEALLOCATE(NewField)
264!$OMP END MASTER   
265!$OMP BARRIER
266 
267   END SUBROUTINE  writefield_dyn2d_v
268   
269END MODULE mod_xios_dyn3dmem
270
Note: See TracBrowser for help on using the repository browser.