source: LMDZ6/trunk/libf/dyn3dmem/mod_xios_dyn3dmem.F90 @ 4526

Last change on this file since 4526 was 4371, checked in by Laurent Fairhead, 2 years ago

Bug fix for xios writing in the dynamics. Problem was that a variable that I thought was shared
actually was not leading to undefind values in the variables written out to XIOS
LF

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