source: LMDZ6/branches/Amaury_dev/libf/dyn3dmem/mod_xios_dyn3dmem.F90 @ 5139

Last change on this file since 5139 was 5136, checked in by abarral, 3 months ago

Put comgeom.h, comgeom2.h into modules

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