New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
cpl_oasis3.F90 in branches/2014/dev_4728_CNRS04_coupled_interface/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/2014/dev_4728_CNRS04_coupled_interface/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 4859

Last change on this file since 4859 was 4859, checked in by smasson, 9 years ago

dev_4728_CNRS04_coupled_interface: cleaning of the coupling interface for OASIS3-MCT. 2

  • Property svn:keywords set to Id
File size: 19.0 KB
Line 
1MODULE cpl_oasis3
2   !!======================================================================
3   !!                    ***  MODULE cpl_oasis  ***
4   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3-MCT
5   !!=====================================================================
6   !! History :   
7   !!   9.0  !  04-06  (R. Redler, NEC Laboratories Europe, Germany) Original code
8   !!   " "  !  04-11  (R. Redler, NEC Laboratories Europe; N. Keenlyside, W. Park, IFM-GEOMAR, Germany) revision
9   !!   " "  !  04-11  (V. Gayler, MPI M&D) Grid writing
10   !!   " "  !  05-08  (R. Redler, W. Park) frld initialization, paral(2) revision
11   !!   " "  !  05-09  (R. Redler) extended to allow for communication over root only
12   !!   " "  !  06-01  (W. Park) modification of physical part
13   !!   " "  !  06-02  (R. Redler, W. Park) buffer array fix for root exchange
14   !!   3.4  !  11-11  (C. Harris) Changes to allow mutiple category fields
15   !!----------------------------------------------------------------------
16   !!----------------------------------------------------------------------
17   !!   'key_oasis3'                    coupled Ocean/Atmosphere via OASIS3
18   !!----------------------------------------------------------------------
19   !!   cpl_init     : initialization of coupled mode communication
20   !!   cpl_define   : definition of grid and fields
21   !!   cpl_snd     : snd out fields in coupled mode
22   !!   cpl_rcv     : receive fields in coupled mode
23   !!   cpl_finalize : finalize the coupled mode communication
24   !!----------------------------------------------------------------------
25#if defined key_oasis3
26   USE mod_oasis                    ! OASIS3-MCT module
27#endif
28   USE par_oce                      ! ocean parameters
29   USE dom_oce                      ! ocean space and time domain
30   USE in_out_manager               ! I/O manager
31   USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
32
33   IMPLICIT NONE
34   PRIVATE
35
36   PUBLIC   cpl_init
37   PUBLIC   cpl_define
38   PUBLIC   cpl_snd
39   PUBLIC   cpl_rcv
40   PUBLIC   cpl_freq
41   PUBLIC   cpl_finalize
42
43   INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field
44   INTEGER, PUBLIC            ::   OASIS_idle = 0    !: return code if nothing done by oasis
45   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
46   INTEGER                    ::   nerror            ! return error code
47#if ! defined key_oasis3
48   ! OASIS Variables not used. defined only for compilation purpose
49   INTEGER                    ::   OASIS_Out         = -1
50   INTEGER                    ::   OASIS_REAL        = -1
51   INTEGER                    ::   OASIS_Ok          = -1
52   INTEGER                    ::   OASIS_In          = -1
53   INTEGER                    ::   OASIS_Sent        = -1
54   INTEGER                    ::   OASIS_SentOut     = -1
55   INTEGER                    ::   OASIS_ToRest      = -1
56   INTEGER                    ::   OASIS_ToRestOut   = -1
57   INTEGER                    ::   OASIS_Recvd       = -1
58   INTEGER                    ::   OASIS_RecvOut     = -1
59   INTEGER                    ::   OASIS_FromRest    = -1
60   INTEGER                    ::   OASIS_FromRestOut = -1
61#endif
62
63   INTEGER, PARAMETER ::   nmaxfld=40    ! Maximum number of coupling fields
64   
65   TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
66      LOGICAL               ::   laction   ! To be coupled or not
67      CHARACTER(len = 8)    ::   clname    ! Name of the coupling field   
68      CHARACTER(len = 1)    ::   clgrid    ! Grid type 
69      REAL(wp)              ::   nsgn      ! Control of the sign change
70      INTEGER, DIMENSION(9) ::   nid       ! Id of the field (no more than 9 categories)
71      INTEGER               ::   nct       ! Number of categories in field
72   END TYPE FLD_CPL
73
74   TYPE(FLD_CPL), DIMENSION(nmaxfld), PUBLIC ::   srcv, ssnd   !: Coupling fields
75
76   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   exfld   ! Temporary buffer for receiving
77
78   !!----------------------------------------------------------------------
79   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
80   !! $Id$
81   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
82   !!----------------------------------------------------------------------
83CONTAINS
84
85   SUBROUTINE cpl_init( kl_comm )
86      !!-------------------------------------------------------------------
87      !!             ***  ROUTINE cpl_init  ***
88      !!
89      !! ** Purpose :   Initialize coupled mode communication for ocean
90      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
91      !!
92      !! ** Method  :   OASIS3 MPI communication
93      !!--------------------------------------------------------------------
94      INTEGER, INTENT(out) ::   kl_comm   ! local communicator of the model
95      !!--------------------------------------------------------------------
96
97      ! WARNING: No write in numout in this routine
98      !============================================
99
100      !------------------------------------------------------------------
101      ! 1st Initialize the OASIS system for the application
102      !------------------------------------------------------------------
103      CALL oasis_init_comp ( ncomp_id, 'oceanx', nerror )
104      IF ( nerror /= OASIS_Ok ) &
105         CALL oasis_abort (ncomp_id, 'cpl_init', 'Failure in oasis_init_comp')
106
107      !------------------------------------------------------------------
108      ! 3rd Get an MPI communicator for OPA local communication
109      !------------------------------------------------------------------
110
111      CALL oasis_get_localcomm ( kl_comm, nerror )
112      IF ( nerror /= OASIS_Ok ) &
113         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' )
114      !
115   END SUBROUTINE cpl_init
116
117
118   SUBROUTINE cpl_define( krcv, ksnd )
119      !!-------------------------------------------------------------------
120      !!             ***  ROUTINE cpl_define  ***
121      !!
122      !! ** Purpose :   Define grid and field information for ocean
123      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
124      !!
125      !! ** Method  :   OASIS3 MPI communication
126      !!--------------------------------------------------------------------
127      INTEGER, INTENT(in) ::   krcv, ksnd     ! Number of received and sent coupling fields
128      !
129      INTEGER :: id_part
130      INTEGER :: paral(5)       ! OASIS3 box partition
131      INTEGER :: ishape(2,2)    ! shape of arrays passed to PSMILe
132      INTEGER :: ji,jc          ! local loop indicees
133      CHARACTER(LEN=8) :: zclname
134      !!--------------------------------------------------------------------
135
136      IF(lwp) WRITE(numout,*)
137      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
138      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
139      IF(lwp) WRITE(numout,*)
140
141      !
142      ! ... Define the shape for the area that excludes the halo
143      !     For serial configuration (key_mpp_mpi not being active)
144      !     nl* is set to the global values 1 and jp*glo.
145      !
146      ishape(:,1) = (/ 1, nlei-nldi+1 /)
147      ishape(:,2) = (/ 1, nlej-nldj+1 /)
148      !
149      ! ... Allocate memory for data exchange
150      !
151      ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
152      IF( nerror > 0 ) THEN
153         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
154      ENDIF
155      !
156      ! -----------------------------------------------------------------
157      ! ... Define the partition
158      ! -----------------------------------------------------------------
159     
160      paral(1) = 2                                              ! box partitioning
161      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset   
162      paral(3) = nlei-nldi+1                                    ! local extent in i
163      paral(4) = nlej-nldj+1                                    ! local extent in j
164      paral(5) = jpiglo                                         ! global extent in x
165     
166      IF( ln_ctl ) THEN
167         WRITE(numout,*) ' multiexchg: paral (1:5)', paral
168         WRITE(numout,*) ' multiexchg: jpi, jpj =', jpi, jpj
169         WRITE(numout,*) ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
170         WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
171      ENDIF
172     
173      CALL oasis_def_partition ( id_part, paral, nerror )
174      !
175      ! ... Announce send variables.
176      !
177      DO ji = 1, ksnd
178         IF ( ssnd(ji)%laction ) THEN
179            DO jc = 1, ssnd(ji)%nct
180               IF ( ssnd(ji)%nct .gt. 1 ) THEN
181                  WRITE(zclname,'( a7, i1)') ssnd(ji)%clname,jc
182               ELSE
183                  zclname=ssnd(ji)%clname
184               ENDIF
185               WRITE(numout,*) "Define",ji,jc,zclname," for",OASIS_Out
186               CALL oasis_def_var (ssnd(ji)%nid(jc), zclname, id_part, (/ 2, 0/),   &
187                    OASIS_Out, ishape, OASIS_REAL, nerror)
188               IF ( nerror /= OASIS_Ok ) THEN
189                  WRITE(numout,*) 'Failed to define transient ', ji, TRIM(zclname)
190                  CALL oasis_abort ( ssnd(ji)%nid(jc), 'cpl_define', 'Failure in oasis_def_var')
191               ENDIF
192            END DO
193         ENDIF
194      END DO
195      !
196      ! ... Announce received variables.
197      !
198      DO ji = 1, krcv
199         IF ( srcv(ji)%laction ) THEN
200            DO jc = 1, srcv(ji)%nct
201               IF ( srcv(ji)%nct .gt. 1 ) THEN
202                  WRITE(zclname,'( a7, i1)') srcv(ji)%clname,jc
203               ELSE
204                  zclname=srcv(ji)%clname
205               ENDIF
206               WRITE(numout,*) "Define",ji,jc,zclname," for",OASIS_In
207               CALL oasis_def_var ( srcv(ji)%nid(jc), zclname, id_part, (/ 2, 0/),   &
208                    &                      OASIS_In    , ishape   , OASIS_REAL, nerror)
209               IF ( nerror /= OASIS_Ok ) THEN
210                  WRITE(numout,*) 'Failed to define transient ', ji, TRIM(zclname)
211                  CALL oasis_abort ( srcv(ji)%nid(jc), 'cpl_define', 'Failure in oasis_def_var')
212               ENDIF
213            END DO
214         ENDIF
215      END DO
216     
217      !------------------------------------------------------------------
218      ! End of definition phase
219      !------------------------------------------------------------------
220     
221      CALL oasis_enddef(nerror)
222      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
223      !
224   END SUBROUTINE cpl_define
225   
226   
227   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
228      !!---------------------------------------------------------------------
229      !!              ***  ROUTINE cpl_snd  ***
230      !!
231      !! ** Purpose : - At each coupling time-step,this routine sends fields
232      !!      like sst or ice cover to the coupler or remote application.
233      !!----------------------------------------------------------------------
234      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
235      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
236      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
237      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
238      !!
239      INTEGER                                   ::   jc        ! local loop index
240      !!--------------------------------------------------------------------
241      !
242      ! snd data to OASIS3
243      !
244      DO jc = 1, ssnd(kid)%nct
245
246         CALL oasis_put ( ssnd(kid)%nid(jc), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
247         
248         IF ( ln_ctl ) THEN       
249            IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
250                 & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
251               WRITE(numout,*) '****************'
252               WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
253               WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc)
254               WRITE(numout,*) 'oasis_put:  kstep ', kstep
255               WRITE(numout,*) 'oasis_put:   info ', kinfo
256               WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
257               WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
258               WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
259               WRITE(numout,*) '****************'
260            ENDIF
261         ENDIF
262
263      ENDDO
264      !
265    END SUBROUTINE cpl_snd
266
267
268   SUBROUTINE cpl_rcv( kid, kstep, pdata, kinfo )
269      !!---------------------------------------------------------------------
270      !!              ***  ROUTINE cpl_rcv  ***
271      !!
272      !! ** Purpose : - At each coupling time-step,this routine receives fields
273      !!      like stresses and fluxes from the coupler or remote application.
274      !!----------------------------------------------------------------------
275      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
276      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
277      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
278      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
279      !!
280      INTEGER                                   ::   jc        ! local loop index
281      LOGICAL                                   ::   llaction
282      !!--------------------------------------------------------------------
283      !
284      ! receive local data from OASIS3 on every process
285      !
286      DO jc = 1, srcv(kid)%nct
287
288         CALL oasis_get ( srcv(kid)%nid(jc), kstep, exfld, kinfo )         
289         
290         llaction = .false.
291         IF( kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
292              kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut )   llaction = .TRUE.
293         
294         IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc)
295         
296         IF ( llaction ) THEN
297           
298            kinfo = OASIS_Rcv
299            pdata(nldi:nlei, nldj:nlej,jc) = exfld(:,:)
300           
301            !--- Fill the overlap areas and extra hallows (mpp)
302            !--- check periodicity conditions (all cases)
303            CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
304           
305            IF ( ln_ctl ) THEN       
306               WRITE(numout,*) '****************'
307               WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
308               WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc)
309               WRITE(numout,*) 'oasis_get:   kstep', kstep
310               WRITE(numout,*) 'oasis_get:   info ', kinfo
311               WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
312               WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
313               WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
314               WRITE(numout,*) '****************'
315            ENDIF
316           
317         ELSE
318            kinfo = OASIS_idle     
319         ENDIF
320         
321      ENDDO
322      !
323   END SUBROUTINE cpl_rcv
324
325
326   INTEGER FUNCTION cpl_freq( kid ) 
327      !!---------------------------------------------------------------------
328      !!              ***  ROUTINE cpl_freq  ***
329      !!
330      !! ** Purpose : - send back the coupling frequency for a particular field
331      !!----------------------------------------------------------------------
332      INTEGER,INTENT(in) ::   kid   ! variable index
333      !!
334      INTEGER :: info
335      !!----------------------------------------------------------------------
336      CALL oasis_get_freqs(kid, 1, cpl_freq, info)
337      !
338   END FUNCTION cpl_freq
339
340
341   SUBROUTINE cpl_finalize
342      !!---------------------------------------------------------------------
343      !!              ***  ROUTINE cpl_finalize  ***
344      !!
345      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
346      !!      called explicitly before cpl_init it will also close
347      !!      MPI communication.
348      !!----------------------------------------------------------------------
349      !
350      DEALLOCATE( exfld )
351      IF (nstop == 0) THEN
352         CALL oasis_terminate( nerror )         
353      ELSE
354         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
355      ENDIF       
356      !
357   END SUBROUTINE cpl_finalize
358
359#if ! defined key_oasis3
360
361   !!----------------------------------------------------------------------
362   !!   No OASIS Library          OASIS3 Dummy module...
363   !!----------------------------------------------------------------------
364
365   SUBROUTINE oasis_init_comp(k1,cd1,k2)
366      CHARACTER(*), INTENT(in   ) ::  cd1
367      INTEGER     , INTENT(  out) ::  k1,k2
368      k1 = -1 ; k2 = -1
369      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
370   END SUBROUTINE oasis_init_comp
371
372   SUBROUTINE oasis_abort(k1,cd1,cd2)
373      INTEGER     , INTENT(in   ) ::  k1
374      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
375      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
376   END SUBROUTINE oasis_abort
377
378   SUBROUTINE oasis_get_localcomm(k1,k2)
379      INTEGER     , INTENT(  out) ::  k1,k2
380      k1 = -1 ; k2 = -1
381      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
382   END SUBROUTINE oasis_get_localcomm
383
384   SUBROUTINE oasis_def_partition(k1,k2,k3)
385      INTEGER     , INTENT(  out) ::  k1,k3
386      INTEGER     , INTENT(in   ) ::  k2(5)
387      k1 = k2(1) ; k3 = k2(5)
388      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
389   END SUBROUTINE oasis_def_partition
390
391   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
392      CHARACTER(*), INTENT(in   ) ::  cd1
393      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
394      INTEGER     , INTENT(  out) ::  k1,k7
395      k1 = -1 ; k7 = -1
396      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
397   END SUBROUTINE oasis_def_var
398
399   SUBROUTINE oasis_enddef(k1)
400      INTEGER     , INTENT(  out) ::  k1
401      k1 = -1
402      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
403   END SUBROUTINE oasis_enddef
404 
405   SUBROUTINE oasis_put(k1,k2,p1,k3)
406      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
407      INTEGER                 , INTENT(in   ) ::  k1,k2
408      INTEGER                 , INTENT(  out) ::  k3
409      k3 = -1
410      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
411   END SUBROUTINE oasis_put
412
413   SUBROUTINE oasis_get(k1,k2,p1,k3)
414      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
415      INTEGER                 , INTENT(in   ) ::  k1,k2
416      INTEGER                 , INTENT(  out) ::  k3
417      p1(1,1) = -1. ; k3 = -1
418      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
419   END SUBROUTINE oasis_get
420
421   SUBROUTINE oasis_get_freqs(k1,k2,k3,k4)
422      INTEGER     , INTENT(in   ) ::  k1,k2
423      INTEGER     , INTENT(  out) ::  k3,k4
424      k3 = k1 ; k4 = k2
425      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
426   END SUBROUTINE oasis_get_freqs
427
428   SUBROUTINE oasis_terminate(k1)
429      INTEGER     , INTENT(  out) ::  k1
430      k1 = -1
431      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
432   END SUBROUTINE oasis_terminate
433   
434#endif
435
436   !!=====================================================================
437END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.