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/UKMO/dev_r5518_GO6_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC – NEMO

source: branches/UKMO/dev_r5518_GO6_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 10176

Last change on this file since 10176 was 10176, checked in by dancopsey, 6 years ago

Merged in dev_r5518_cleanup_1d_cpl branch.

File size: 34.6 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-MCT
18   !!   'key_oa3mct_v3'                 to be added for OASIS3-MCT version 3
19   !!----------------------------------------------------------------------
20   !!   cpl_init     : initialization of coupled mode communication
21   !!   cpl_define   : definition of grid and fields
22   !!   cpl_snd     : snd out fields in coupled mode
23   !!   cpl_rcv     : receive fields in coupled mode
24   !!   cpl_finalize : finalize the coupled mode communication
25   !!----------------------------------------------------------------------
26#if defined key_oasis3
27   USE mod_oasis                    ! OASIS3-MCT module
28#endif
29   USE par_oce                      ! ocean parameters
30   USE cpl_rnf_1d, ONLY: nn_cpl_river   ! Variables used in 1D river outflow
31   USE dom_oce                      ! ocean space and time domain
32   USE in_out_manager               ! I/O manager
33   USE lbclnk                       ! ocean lateral boundary conditions (or mpp link)
34   
35   IMPLICIT NONE
36   PRIVATE
37
38   PUBLIC   cpl_init
39   PUBLIC   cpl_define
40   PUBLIC   cpl_snd
41   PUBLIC   cpl_rcv
42   PUBLIC   cpl_rcv_1d
43   PUBLIC   cpl_freq
44   PUBLIC   cpl_finalize
45#if defined key_mpp_mpi
46   INCLUDE 'mpif.h'
47#endif
48   
49   INTEGER, PARAMETER         :: localRoot  = 0
50   LOGICAL                    :: commRank            ! true for ranks doing OASIS communication
51#if defined key_cpl_rootexchg
52   LOGICAL                    :: rootexchg =.true.   ! logical switch
53#else
54   LOGICAL                    :: rootexchg =.false.  ! logical switch
55#endif
56
57   INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field
58   INTEGER, PUBLIC            ::   OASIS_idle = 0    !: return code if nothing done by oasis
59   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
60   INTEGER                    ::   nerror            ! return error code
61#if ! defined key_oasis3
62   ! OASIS Variables not used. defined only for compilation purpose
63   INTEGER                    ::   OASIS_Out         = -1
64   INTEGER                    ::   OASIS_REAL        = -1
65   INTEGER                    ::   OASIS_Ok          = -1
66   INTEGER                    ::   OASIS_In          = -1
67   INTEGER                    ::   OASIS_Sent        = -1
68   INTEGER                    ::   OASIS_SentOut     = -1
69   INTEGER                    ::   OASIS_ToRest      = -1
70   INTEGER                    ::   OASIS_ToRestOut   = -1
71   INTEGER                    ::   OASIS_Recvd       = -1
72   INTEGER                    ::   OASIS_RecvOut     = -1
73   INTEGER                    ::   OASIS_FromRest    = -1
74   INTEGER                    ::   OASIS_FromRestOut = -1
75#endif
76
77   INTEGER                    ::   nrcv         ! total number of fields received
78   INTEGER                    ::   nsnd         ! total number of fields sent
79   INTEGER                    ::   ncplmodel    ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
80   INTEGER, PUBLIC, PARAMETER ::   nmaxfld=50   ! Maximum number of coupling fields
81   INTEGER, PUBLIC, PARAMETER ::   nmaxcat=5    ! Maximum number of coupling fields
82   INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields
83   
84   TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
85      LOGICAL               ::   laction   ! To be coupled or not
86      CHARACTER(len = 8)    ::   clname    ! Name of the coupling field   
87      CHARACTER(len = 1)    ::   clgrid    ! Grid type 
88      REAL(wp)              ::   nsgn      ! Control of the sign change
89      INTEGER, DIMENSION(nmaxcat,nmaxcpl) ::   nid   ! Id of the field (no more than 9 categories and 9 extrena models)
90      INTEGER               ::   nct       ! Number of categories in field
91      INTEGER               ::   ncplmodel ! Maximum number of models to/from which this variable may be sent/received
92      INTEGER               ::   dimensions ! Number of dimensions of coupling field
93   END TYPE FLD_CPL
94
95   TYPE(FLD_CPL), DIMENSION(nmaxfld), PUBLIC ::   srcv, ssnd   !: Coupling fields
96
97   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   exfld   ! Temporary buffer for receiving
98   INTEGER, PUBLIC :: localComm 
99     
100   !!----------------------------------------------------------------------
101   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
102   !! $Id$
103   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
104   !!----------------------------------------------------------------------
105CONTAINS
106
107   SUBROUTINE cpl_init( cd_modname, kl_comm )
108      !!-------------------------------------------------------------------
109      !!             ***  ROUTINE cpl_init  ***
110      !!
111      !! ** Purpose :   Initialize coupled mode communication for ocean
112      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
113      !!
114      !! ** Method  :   OASIS3 MPI communication
115      !!--------------------------------------------------------------------
116      CHARACTER(len = *), INTENT(in) ::   cd_modname   ! model name as set in namcouple file
117      INTEGER          , INTENT(out) ::   kl_comm      ! local communicator of the model
118      !!--------------------------------------------------------------------
119
120      ! WARNING: No write in numout in this routine
121      !============================================
122
123      !------------------------------------------------------------------
124      ! 1st Initialize the OASIS system for the application
125      !------------------------------------------------------------------
126      CALL oasis_init_comp ( ncomp_id, TRIM(cd_modname), nerror )
127      IF ( nerror /= OASIS_Ok ) &
128         CALL oasis_abort (ncomp_id, 'cpl_init', 'Failure in oasis_init_comp')
129
130      !------------------------------------------------------------------
131      ! 3rd Get an MPI communicator for OPA local communication
132      !------------------------------------------------------------------
133
134      CALL oasis_get_localcomm ( kl_comm, nerror )
135      IF ( nerror /= OASIS_Ok ) &
136         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' )
137      localComm = kl_comm 
138      !
139   END SUBROUTINE cpl_init
140
141
142   SUBROUTINE cpl_define( krcv, ksnd, kcplmodel )
143      !!-------------------------------------------------------------------
144      !!             ***  ROUTINE cpl_define  ***
145      !!
146      !! ** Purpose :   Define grid and field information for ocean
147      !!    exchange between AGCM, OGCM and COUPLER. (OASIS3 software)
148      !!
149      !! ** Method  :   OASIS3 MPI communication
150      !!--------------------------------------------------------------------
151      INTEGER, INTENT(in) ::   krcv, ksnd     ! Number of received and sent coupling fields
152      INTEGER, INTENT(in) ::   kcplmodel      ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
153      !
154      INTEGER :: id_part
155      INTEGER :: id_part_0d     ! Partition for 0d fields
156      INTEGER :: id_part_rnf_1d ! Partition for 1d river outflow fields
157      INTEGER :: id_part_temp   ! Temperary partition used to choose either 0d or 1d partitions
158      INTEGER :: vector_length  ! Length of 0d or 1d variables (0d variables will have vector_length=1)
159      INTEGER :: paral(5)       ! OASIS3 box partition
160      INTEGER :: ishape(4)      ! Shape of arrays passed to PSMILe.
161                                ! Redundant from OASIS3-MCT vn4.0 onwards but required
162                                ! to satisfy interface and for backward compatibility.
163      INTEGER :: var_nodims(2)  ! Number of coupling field dimensions.
164                                ! var_nodims(1) is redundant from OASIS3-MCT vn4.0 onwards
165                                ! but retained for backward compatibility.
166                                ! var_nodims(2) is the number of fields in a bundle
167                                ! or 1 for unbundled fields (bundles are not yet catered for
168                                ! in NEMO hence we default to 1). 
169      INTEGER :: ji,jc,jm       ! local loop indicees
170      CHARACTER(LEN=64) :: zclname
171      CHARACTER(LEN=2) :: cli2
172      !!--------------------------------------------------------------------
173
174      IF(lwp) WRITE(numout,*)
175      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
176      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
177      IF(lwp) WRITE(numout,*)
178
179      ncplmodel = kcplmodel
180      IF( kcplmodel > nmaxcpl ) THEN
181         CALL oasis_abort ( ncomp_id, 'cpl_define', 'ncplmodel is larger than nmaxcpl, increase nmaxcpl')   ;   RETURN
182      ENDIF
183
184      nrcv = krcv
185      IF( nrcv > nmaxfld ) THEN
186         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nrcv is larger than nmaxfld, increase nmaxfld')   ;   RETURN
187      ENDIF
188
189      nsnd = ksnd
190      IF( nsnd > nmaxfld ) THEN
191         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nsnd is larger than nmaxfld, increase nmaxfld')   ;   RETURN
192      ENDIF
193
194      !
195      ! ... Define the shape for the area that excludes the halo
196      !     For serial configuration (key_mpp_mpi not being active)
197      !     nl* is set to the global values 1 and jp*glo.
198      !
199      ishape(1) = 1
200      ishape(2) = nlei-nldi+1
201      ishape(3) = 1
202      ishape(4) = nlej-nldj+1
203
204
205      !
206      ! ... Allocate memory for data exchange
207      !
208      ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
209      IF( nerror > 0 ) THEN
210         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
211      ENDIF     
212      !
213      ! -----------------------------------------------------------------
214      ! ... Define the partition
215      ! -----------------------------------------------------------------
216           
217      paral(1) = 2                                              ! box partitioning
218      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset   
219      paral(3) = nlei-nldi+1                                    ! local extent in i
220      paral(4) = nlej-nldj+1                                    ! local extent in j
221      paral(5) = jpiglo                                         ! global extent in x
222     
223      IF( ln_ctl ) THEN
224         WRITE(numout,*) ' multiexchg: paral (1:5)', paral
225         WRITE(numout,*) ' multiexchg: jpi, jpj =', jpi, jpj
226         WRITE(numout,*) ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
227         WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
228      ENDIF
229     
230      CALL oasis_def_partition ( id_part, paral, nerror, jpiglo*jpjglo)
231
232      ! A special partition is needed for 0D fields
233     
234      paral(1) = 0                                       ! serial partitioning
235      paral(2) = 0   
236      IF ( nproc == 0) THEN
237         paral(3) = 1                   ! Size of array to couple (scalar)
238      ELSE
239         paral(3) = 0                   ! Dummy size for PE's not involved
240      END IF
241      paral(4) = 0
242      paral(5) = 0
243       
244      CALL oasis_def_partition ( id_part_0d, paral, nerror, 1 )
245
246      ! Another partition is needed for 1D river routing fields
247     
248      paral(1) = 0                                       ! serial partitioning
249      paral(2) = 0   
250      IF ( nproc == 0) THEN
251         paral(3) = nn_cpl_river                   ! Size of array to couple (vector)
252      ELSE
253         paral(3) = 0                   ! Dummy size for PE's not involved
254      END IF
255      paral(4) = 0
256      paral(5) = 0
257
258
259      CALL oasis_def_partition ( id_part_rnf_1d, paral, nerror, nn_cpl_river )
260 
261      !
262      ! ... Announce send variables.
263      !
264      ssnd(:)%ncplmodel = kcplmodel
265      !
266      DO ji = 1, ksnd
267         IF ( ssnd(ji)%laction ) THEN
268
269            IF( ssnd(ji)%nct > nmaxcat ) THEN
270               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
271                  &              TRIM(ssnd(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
272               RETURN
273            ENDIF
274           
275            DO jc = 1, ssnd(ji)%nct
276               DO jm = 1, kcplmodel
277
278                  IF ( ssnd(ji)%nct .GT. 1 ) THEN
279                     WRITE(cli2,'(i2.2)') jc
280                     zclname = TRIM(ssnd(ji)%clname)//'_cat'//cli2
281                  ELSE
282                     zclname = ssnd(ji)%clname
283                  ENDIF
284                  IF ( kcplmodel  > 1 ) THEN
285                     WRITE(cli2,'(i2.2)') jm
286                     zclname = 'model'//cli2//'_'//TRIM(zclname)
287                  ENDIF
288#if defined key_agrif
289                  IF( agrif_fixed() /= 0 ) THEN
290                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
291                  END IF
292#endif
293                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_Out
294
295                  !
296                  ! ... Set the field dimension and bundle count
297                  var_nodims(1) = 2
298                  var_nodims(2) = 1 ! Modify this value to cater for bundled fields.   
299
300                  CALL oasis_def_var (ssnd(ji)%nid(jc,jm), zclname, id_part   , var_nodims,   &
301                     &                OASIS_Out          , ishape , OASIS_REAL, nerror )
302                  IF ( nerror /= OASIS_Ok ) THEN
303                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
304                     CALL oasis_abort ( ssnd(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
305                  ENDIF
306                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
307                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
308               END DO
309            END DO
310         ENDIF
311      END DO     
312      !
313      ! ... Announce received variables.
314      !
315      srcv(:)%ncplmodel = kcplmodel
316      !
317      DO ji = 1, krcv
318         IF ( srcv(ji)%laction ) THEN
319           
320            IF( srcv(ji)%nct > nmaxcat ) THEN
321               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
322                  &              TRIM(srcv(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
323               RETURN
324            ENDIF
325           
326            DO jc = 1, srcv(ji)%nct
327               DO jm = 1, kcplmodel
328                 
329                  IF ( srcv(ji)%nct .GT. 1 ) THEN
330                     WRITE(cli2,'(i2.2)') jc
331                     zclname = TRIM(srcv(ji)%clname)//'_cat'//cli2
332                  ELSE
333                     zclname = srcv(ji)%clname
334                  ENDIF
335                  IF ( kcplmodel  > 1 ) THEN
336                     WRITE(cli2,'(i2.2)') jm
337                     zclname = 'model'//cli2//'_'//TRIM(zclname)
338                  ENDIF
339#if defined key_agrif
340                  IF( agrif_fixed() /= 0 ) THEN
341                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
342                  END IF
343#endif
344                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_In
345                  flush(numout)
346
347                  ! Define 0D (Greenland or Antarctic ice mass) or 1D (river outflow) coupling fields
348                  IF (srcv(ji)%dimensions <= 1) THEN
349                    var_nodims(1) = 1
350                    var_nodims(2) = 1 ! Modify this value to cater for bundled fields. 
351                    IF (nproc == 0) THEN                   
352                       
353                       IF (srcv(ji)%dimensions == 0) THEN
354                       
355                          ! If 0D then set temporary variables to 0D components
356                          id_part_temp = id_part_0d
357                          vector_length = 1
358                       ELSE
359                       
360                          ! If 1D then set temporary variables to river outflow components
361                          id_part_temp = id_part_rnf_1d
362                          vector_length = nn_cpl_river
363                         
364                       END IF
365                       
366                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_temp   , var_nodims,   &
367                                   OASIS_In           , (/ 1, vector_length /) , OASIS_REAL, nerror )
368                    ELSE
369                       ! Dummy call to keep OASIS3-MCT happy.
370                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_0d   , var_nodims,   &
371                                   OASIS_In           , (/ 0, 0 /) , OASIS_REAL, nerror )
372                    END IF
373                  ELSE 
374                    ! It's a "normal" 2D (or pseudo 3D) coupling field.
375                    ! ... Set the field dimension and bundle count
376                    var_nodims(1) = 2
377                    var_nodims(2) = 1 ! Modify this value to cater for bundled fields.     
378
379                    CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part   , var_nodims,   &
380                                         OASIS_In           , ishape , OASIS_REAL, nerror )
381                  ENDIF
382
383                  IF ( nerror /= OASIS_Ok ) THEN
384                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
385                     CALL oasis_abort ( srcv(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
386                  ENDIF
387                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
388                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
389
390               END DO
391            END DO
392         ENDIF
393      END DO
394     
395      !------------------------------------------------------------------
396      ! End of definition phase
397      !------------------------------------------------------------------
398     
399      CALL oasis_enddef(nerror)
400      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
401      !
402   END SUBROUTINE cpl_define
403   
404   
405   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
406      !!---------------------------------------------------------------------
407      !!              ***  ROUTINE cpl_snd  ***
408      !!
409      !! ** Purpose : - At each coupling time-step,this routine sends fields
410      !!      like sst or ice cover to the coupler or remote application.
411      !!----------------------------------------------------------------------
412      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
413      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
414      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
415      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
416      !!
417      INTEGER                                   ::   jc,jm     ! local loop index
418      !!--------------------------------------------------------------------
419      !
420      ! snd data to OASIS3
421      !
422      DO jc = 1, ssnd(kid)%nct
423         DO jm = 1, ssnd(kid)%ncplmodel
424       
425            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
426               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
427               
428               IF ( ln_ctl ) THEN       
429                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
430                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
431                     WRITE(numout,*) '****************'
432                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
433                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
434                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
435                     WRITE(numout,*) 'oasis_put:   info ', kinfo
436                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
437                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
438                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
439                     WRITE(numout,*) '****************'
440                  ENDIF
441               ENDIF
442               
443            ENDIF
444           
445         ENDDO
446      ENDDO
447      !
448    END SUBROUTINE cpl_snd
449
450
451   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
452      !!---------------------------------------------------------------------
453      !!              ***  ROUTINE cpl_rcv  ***
454      !!
455      !! ** Purpose : - At each coupling time-step,this routine receives fields
456      !!      like stresses and fluxes from the coupler or remote application.
457      !!----------------------------------------------------------------------
458      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
459      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
460      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
461      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
462      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
463      !!
464      INTEGER                                   ::   jc,jm     ! local loop index
465      LOGICAL                                   ::   llaction, llfisrt
466      !!--------------------------------------------------------------------
467      !
468      ! receive local data from OASIS3 on every process
469      !
470      kinfo = OASIS_idle
471      !
472      DO jc = 1, srcv(kid)%nct
473         llfisrt = .TRUE.
474
475         DO jm = 1, srcv(kid)%ncplmodel
476
477            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
478
479               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )   
480               
481               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
482                &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
483               
484               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
485               
486               IF ( llaction ) THEN
487                 
488                  kinfo = OASIS_Rcv
489                  IF( llfisrt ) THEN
490                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm) 
491                     llfisrt = .FALSE.
492                  ELSE
493                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
494                  ENDIF
495                 
496                  IF ( ln_ctl ) THEN       
497                     WRITE(numout,*) '****************'
498                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
499                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
500                     WRITE(numout,*) 'oasis_get:   kstep', kstep
501                     WRITE(numout,*) 'oasis_get:   info ', kinfo
502                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
503                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
504                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
505                     WRITE(numout,*) '****************'
506                  ENDIF
507
508               ENDIF
509
510            ENDIF
511           
512         ENDDO
513
514         !--- Fill the overlap areas and extra hallows (mpp)
515         !--- check periodicity conditions (all cases)
516         IF( .not. llfisrt )   CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
517 
518      ENDDO
519      !
520   END SUBROUTINE cpl_rcv
521
522   SUBROUTINE cpl_rcv_1d( kid, kstep, pdata, nitems, kinfo )
523      !!---------------------------------------------------------------------
524      !!              ***  ROUTINE cpl_rcv_1d  ***
525      !!
526      !! ** Purpose : - A special version of cpl_rcv to deal exclusively with
527      !! receipt of 0D or 1D fields.
528      !! The fields are recieved into a 1D array buffer which is simply a
529      !! dynamically sized sized array (which may be of size 1)
530      !! of 0 dimensional fields. This allows us to pass miltiple 0D
531      !! fields via a single put/get operation. 
532      !!----------------------------------------------------------------------
533      INTEGER , INTENT(in   ) ::   nitems      ! Number of 0D items to recieve
534                                               ! during this get operation. i.e.
535                                               ! The size of the 1D array in which
536                                               ! 0D items are passed.   
537      INTEGER , INTENT(in   ) ::   kid         ! ID index of the incoming
538                                               ! data. 
539      INTEGER , INTENT(in   ) ::   kstep       ! ocean time-step in seconds
540      REAL(wp), INTENT(inout) ::   pdata(1:nitems) ! The original value(s), 
541                                                   ! unchanged if nothing is
542                                                   ! received
543      INTEGER , INTENT(  out) ::   kinfo       ! OASIS3 info argument
544      !!
545      REAL(wp) ::   recvfld(1:nitems)          ! Local receive field buffer
546      INTEGER  ::   jc,jm     ! local loop index
547      INTEGER  ::   ierr
548      LOGICAL  ::   llaction
549      INTEGER  ::   MPI_WORKING_PRECISION
550      INTEGER  ::   number_to_print 
551      !!--------------------------------------------------------------------
552      !
553      ! receive local data from OASIS3 on every process
554      !
555      kinfo = OASIS_idle
556      !
557      ! 0D and 1D fields won't have categories or any other form of "pseudo level"
558      ! so we only cater for a single set of values and thus don't bother
559      ! with a loop over the jc index
560      jc = 1
561
562      DO jm = 1, srcv(kid)%ncplmodel
563
564         IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
565
566            IF ( ( srcv(kid)%dimensions <= 1) .AND. (nproc == 0) ) THEN
567               ! Since there is no concept of data decomposition for zero
568               ! dimension fields, they must only be exchanged through the master PE,
569               ! unlike "normal" 2D field cases where every PE is involved.
570
571               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, recvfld, kinfo )   
572               
573               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
574                           kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
575               
576               IF ( ln_ctl ) WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , &
577                                     llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
578               
579               IF ( llaction ) THEN
580                 
581                  kinfo = OASIS_Rcv
582                  pdata(1:nitems) = recvfld(1:nitems) 
583                 
584                  IF ( ln_ctl ) THEN       
585                     number_to_print = 10
586                     IF ( nitems < number_to_print ) number_to_print = nitems
587                     WRITE(numout,*) '****************'
588                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
589                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
590                     WRITE(numout,*) 'oasis_get:   kstep', kstep
591                     WRITE(numout,*) 'oasis_get:   info ', kinfo
592                     WRITE(numout,*) '     - Minimum Value is ', MINVAL(pdata(:))
593                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:))
594                     WRITE(numout,*) '     - Start of data is ', pdata(1:number_to_print)
595                     WRITE(numout,*) '****************'
596                  ENDIF
597                 
598               ENDIF
599            ENDIF   
600          ENDIF
601           
602       ENDDO
603       
604       ! Set the precision that we want to broadcast using MPI_BCAST
605       SELECT CASE( wp )
606       CASE( sp ) 
607         MPI_WORKING_PRECISION = MPI_REAL                ! Single precision
608       CASE( dp )
609         MPI_WORKING_PRECISION = MPI_DOUBLE_PRECISION    ! Double precision
610       CASE default
611         CALL oasis_abort( ncomp_id, "cpl_rcv_1d", "Could not find precision for coupling 0d or 1d field" )
612       END SELECT
613
614       ! We have to broadcast (potentially) received values from PE 0 to all
615       ! the others. If no new data has been received we're just
616       ! broadcasting the existing values but there's no more efficient way
617       ! to deal with that w/o NEMO adopting a UM-style test mechanism
618       ! to determine active put/get timesteps.
619       CALL mpi_bcast( pdata, nitems, MPI_WORKING_PRECISION, localRoot, mpi_comm_opa, ierr )
620
621      !
622   END SUBROUTINE cpl_rcv_1d
623
624
625   INTEGER FUNCTION cpl_freq( cdfieldname ) 
626      !!---------------------------------------------------------------------
627      !!              ***  ROUTINE cpl_freq  ***
628      !!
629      !! ** Purpose : - send back the coupling frequency for a particular field
630      !!----------------------------------------------------------------------
631      CHARACTER(len = *), INTENT(in) ::   cdfieldname    ! field name as set in namcouple file
632      !!
633      INTEGER               :: id
634      INTEGER               :: info
635      INTEGER, DIMENSION(1) :: itmp
636      INTEGER               :: ji,jm     ! local loop index
637      INTEGER               :: mop
638      !!----------------------------------------------------------------------
639      cpl_freq = 0   ! defaut definition
640      id = -1        ! defaut definition
641      !
642      DO ji = 1, nsnd
643         IF (ssnd(ji)%laction ) THEN
644            DO jm = 1, ncplmodel
645               IF( ssnd(ji)%nid(1,jm) /= -1 ) THEN
646                  IF( TRIM(cdfieldname) == TRIM(ssnd(ji)%clname) ) THEN
647                     id = ssnd(ji)%nid(1,jm)
648                     mop = OASIS_Out
649                  ENDIF
650               ENDIF
651            ENDDO
652         ENDIF
653      ENDDO
654      DO ji = 1, nrcv
655         IF (srcv(ji)%laction ) THEN
656            DO jm = 1, ncplmodel
657               IF( srcv(ji)%nid(1,jm) /= -1 ) THEN
658                  IF( TRIM(cdfieldname) == TRIM(srcv(ji)%clname) ) THEN
659                     id = srcv(ji)%nid(1,jm)
660                     mop = OASIS_In
661                  ENDIF
662               ENDIF
663            ENDDO
664         ENDIF
665      ENDDO
666      !
667      IF( id /= -1 ) THEN
668#if defined key_oa3mct_v3
669         CALL oasis_get_freqs(id, mop, 1, itmp, info)
670#else
671#if defined key_oasis3 
672         itmp(1) = namflddti( id )
673#else
674         CALL oasis_get_freqs(id,      1, itmp, info)
675#endif
676#endif
677         cpl_freq = itmp(1)
678      ENDIF
679      !
680   END FUNCTION cpl_freq
681
682
683   SUBROUTINE cpl_finalize
684      !!---------------------------------------------------------------------
685      !!              ***  ROUTINE cpl_finalize  ***
686      !!
687      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
688      !!      called explicitly before cpl_init it will also close
689      !!      MPI communication.
690      !!----------------------------------------------------------------------
691      !
692      DEALLOCATE( exfld )
693      IF (nstop == 0) THEN
694         CALL oasis_terminate( nerror )         
695      ELSE
696         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
697      ENDIF       
698      !
699   END SUBROUTINE cpl_finalize
700
701#if ! defined key_oasis3
702
703   !!----------------------------------------------------------------------
704   !!   No OASIS Library          OASIS3 Dummy module...
705   !!----------------------------------------------------------------------
706
707   SUBROUTINE oasis_init_comp(k1,cd1,k2)
708      CHARACTER(*), INTENT(in   ) ::  cd1
709      INTEGER     , INTENT(  out) ::  k1,k2
710      k1 = -1 ; k2 = -1
711      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
712   END SUBROUTINE oasis_init_comp
713
714   SUBROUTINE oasis_abort(k1,cd1,cd2)
715      INTEGER     , INTENT(in   ) ::  k1
716      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
717      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
718   END SUBROUTINE oasis_abort
719
720   SUBROUTINE oasis_get_localcomm(k1,k2)
721      INTEGER     , INTENT(  out) ::  k1,k2
722      k1 = -1 ; k2 = -1
723      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
724   END SUBROUTINE oasis_get_localcomm
725
726   SUBROUTINE oasis_def_partition(k1,k2,k3,K4)
727      INTEGER     , INTENT(  out) ::  k1,k3
728      INTEGER     , INTENT(in   ) ::  k2(5)
729      INTEGER     , OPTIONAL, INTENT(in   ) ::  k4
730      k1 = k2(1) ; k3 = k2(5)
731      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
732   END SUBROUTINE oasis_def_partition
733
734   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
735      CHARACTER(*), INTENT(in   ) ::  cd1
736      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
737      INTEGER     , INTENT(  out) ::  k1,k7
738      k1 = -1 ; k7 = -1
739      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
740   END SUBROUTINE oasis_def_var
741
742   SUBROUTINE oasis_enddef(k1)
743      INTEGER     , INTENT(  out) ::  k1
744      k1 = -1
745      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
746   END SUBROUTINE oasis_enddef
747 
748   SUBROUTINE oasis_put(k1,k2,p1,k3)
749      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
750      INTEGER                 , INTENT(in   ) ::  k1,k2
751      INTEGER                 , INTENT(  out) ::  k3
752      k3 = -1
753      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
754   END SUBROUTINE oasis_put
755
756   SUBROUTINE oasis_get(k1,k2,p1,k3)
757      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
758      INTEGER                 , INTENT(in   ) ::  k1,k2
759      INTEGER                 , INTENT(  out) ::  k3
760      p1(1,1) = -1. ; k3 = -1
761      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
762   END SUBROUTINE oasis_get
763
764   SUBROUTINE oasis_get_freqs(k1,k2,k3,k4)
765      INTEGER              , INTENT(in   ) ::  k1,k2
766      INTEGER, DIMENSION(1), INTENT(  out) ::  k3
767      INTEGER              , INTENT(  out) ::  k4
768      k3(1) = k1 ; k4 = k2
769      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
770   END SUBROUTINE oasis_get_freqs
771
772   SUBROUTINE oasis_terminate(k1)
773      INTEGER     , INTENT(  out) ::  k1
774      k1 = -1
775      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
776   END SUBROUTINE oasis_terminate
777   
778#endif
779
780   !!=====================================================================
781END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.