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

source: branches/UKMO/dev_r5518_cleanup_1d_cpl/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 10046

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

Re-enable 2D coupling of icesheet mass. To switch between 2D to 0D coupling of ice mass change sn_rcv_grnm%cldes from 'coupled' to 'coupled0d' (with a similar change to sn_rcv_antm).

File size: 33.4 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(2,2)    ! shape of arrays passed to PSMILe
161      INTEGER :: ji,jc,jm       ! local loop indicees
162      CHARACTER(LEN=64) :: zclname
163      CHARACTER(LEN=2) :: cli2
164      !!--------------------------------------------------------------------
165
166      IF(lwp) WRITE(numout,*)
167      IF(lwp) WRITE(numout,*) 'cpl_define : initialization in coupled ocean/atmosphere case'
168      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~'
169      IF(lwp) WRITE(numout,*)
170
171      ncplmodel = kcplmodel
172      IF( kcplmodel > nmaxcpl ) THEN
173         CALL oasis_abort ( ncomp_id, 'cpl_define', 'ncplmodel is larger than nmaxcpl, increase nmaxcpl')   ;   RETURN
174      ENDIF
175
176      nrcv = krcv
177      IF( nrcv > nmaxfld ) THEN
178         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nrcv is larger than nmaxfld, increase nmaxfld')   ;   RETURN
179      ENDIF
180
181      nsnd = ksnd
182      IF( nsnd > nmaxfld ) THEN
183         CALL oasis_abort ( ncomp_id, 'cpl_define', 'nsnd is larger than nmaxfld, increase nmaxfld')   ;   RETURN
184      ENDIF
185
186      !
187      ! ... Define the shape for the area that excludes the halo
188      !     For serial configuration (key_mpp_mpi not being active)
189      !     nl* is set to the global values 1 and jp*glo.
190      !
191      ishape(:,1) = (/ 1, nlei-nldi+1 /)
192      ishape(:,2) = (/ 1, nlej-nldj+1 /)
193      !
194      ! ... Allocate memory for data exchange
195      !
196      ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror)
197      IF( nerror > 0 ) THEN
198         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN
199      ENDIF     
200      !
201      ! -----------------------------------------------------------------
202      ! ... Define the partition
203      ! -----------------------------------------------------------------
204           
205      paral(1) = 2                                              ! box partitioning
206      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset   
207      paral(3) = nlei-nldi+1                                    ! local extent in i
208      paral(4) = nlej-nldj+1                                    ! local extent in j
209      paral(5) = jpiglo                                         ! global extent in x
210     
211      IF( ln_ctl ) THEN
212         WRITE(numout,*) ' multiexchg: paral (1:5)', paral
213         WRITE(numout,*) ' multiexchg: jpi, jpj =', jpi, jpj
214         WRITE(numout,*) ' multiexchg: nldi, nlei, nimpp =', nldi, nlei, nimpp
215         WRITE(numout,*) ' multiexchg: nldj, nlej, njmpp =', nldj, nlej, njmpp
216      ENDIF
217     
218      CALL oasis_def_partition ( id_part, paral, nerror, jpiglo*jpjglo)
219
220      ! A special partition is needed for 0D fields
221     
222      paral(1) = 0                                       ! serial partitioning
223      paral(2) = 0   
224      IF ( nproc == 0) THEN
225         paral(3) = 1                   ! Size of array to couple (scalar)
226      ELSE
227         paral(3) = 0                   ! Dummy size for PE's not involved
228      END IF
229      paral(4) = 0
230      paral(5) = 0
231       
232      CALL oasis_def_partition ( id_part_0d, paral, nerror, 1 )
233
234      ! Another partition is needed for 1D river routing fields
235     
236      paral(1) = 0                                       ! serial partitioning
237      paral(2) = 0   
238      IF ( nproc == 0) THEN
239         paral(3) = nn_cpl_river                   ! Size of array to couple (vector)
240      ELSE
241         paral(3) = 0                   ! Dummy size for PE's not involved
242      END IF
243      paral(4) = 0
244      paral(5) = 0
245
246
247      CALL oasis_def_partition ( id_part_rnf_1d, paral, nerror, nn_cpl_river )
248 
249      !
250      ! ... Announce send variables.
251      !
252      ssnd(:)%ncplmodel = kcplmodel
253      !
254      DO ji = 1, ksnd
255         IF ( ssnd(ji)%laction ) THEN
256
257            IF( ssnd(ji)%nct > nmaxcat ) THEN
258               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
259                  &              TRIM(ssnd(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
260               RETURN
261            ENDIF
262           
263            DO jc = 1, ssnd(ji)%nct
264               DO jm = 1, kcplmodel
265
266                  IF ( ssnd(ji)%nct .GT. 1 ) THEN
267                     WRITE(cli2,'(i2.2)') jc
268                     zclname = TRIM(ssnd(ji)%clname)//'_cat'//cli2
269                  ELSE
270                     zclname = ssnd(ji)%clname
271                  ENDIF
272                  IF ( kcplmodel  > 1 ) THEN
273                     WRITE(cli2,'(i2.2)') jm
274                     zclname = 'model'//cli2//'_'//TRIM(zclname)
275                  ENDIF
276#if defined key_agrif
277                  IF( agrif_fixed() /= 0 ) THEN
278                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
279                  END IF
280#endif
281                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_Out
282                  CALL oasis_def_var (ssnd(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
283                     &                OASIS_Out          , ishape , OASIS_REAL, nerror )
284                  IF ( nerror /= OASIS_Ok ) THEN
285                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
286                     CALL oasis_abort ( ssnd(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
287                  ENDIF
288                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
289                  IF( ln_ctl .AND. ssnd(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
290               END DO
291            END DO
292         ENDIF
293      END DO     
294      !
295      ! ... Announce received variables.
296      !
297      srcv(:)%ncplmodel = kcplmodel
298      !
299      DO ji = 1, krcv
300         IF ( srcv(ji)%laction ) THEN
301           
302            IF( srcv(ji)%nct > nmaxcat ) THEN
303               CALL oasis_abort ( ncomp_id, 'cpl_define', 'Number of categories of '//   &
304                  &              TRIM(srcv(ji)%clname)//' is larger than nmaxcat, increase nmaxcat' )
305               RETURN
306            ENDIF
307           
308            DO jc = 1, srcv(ji)%nct
309               DO jm = 1, kcplmodel
310                 
311                  IF ( srcv(ji)%nct .GT. 1 ) THEN
312                     WRITE(cli2,'(i2.2)') jc
313                     zclname = TRIM(srcv(ji)%clname)//'_cat'//cli2
314                  ELSE
315                     zclname = srcv(ji)%clname
316                  ENDIF
317                  IF ( kcplmodel  > 1 ) THEN
318                     WRITE(cli2,'(i2.2)') jm
319                     zclname = 'model'//cli2//'_'//TRIM(zclname)
320                  ENDIF
321#if defined key_agrif
322                  IF( agrif_fixed() /= 0 ) THEN
323                     zclname=TRIM(Agrif_CFixed())//'_'//TRIM(zclname)
324                  END IF
325#endif
326                  IF( ln_ctl ) WRITE(numout,*) "Define", ji, jc, jm, " "//TRIM(zclname), " for ", OASIS_In
327flush(numout)
328
329                  ! Define 0D (Greenland or Antarctic ice mass) or 1D (river outflow) coupling fields
330                  IF (srcv(ji)%dimensions <= 1) THEN
331                    IF (nproc == 0) THEN                   
332                       
333                       IF (srcv(ji)%dimensions == 0) THEN
334                       
335                          ! If 0D then set temporary variables to 0D components
336                          id_part_temp = id_part_0d
337                          vector_length = 1
338                       ELSE
339                       
340                          ! If 1D then set temporary variables to river outflow components
341                          id_part_temp = id_part_rnf_1d
342                          vector_length = nn_cpl_river
343                         
344                       END IF
345                       
346                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_temp   , (/ 1, 0 /),   &
347                                   OASIS_In           , (/ 1, vector_length /) , OASIS_REAL, nerror )
348                    ELSE
349                       ! Dummy call to keep OASIS3-MCT happy.
350                       CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part_0d   , (/ 1, 0 /),   &
351                                   OASIS_In           , (/ 0, 0 /) , OASIS_REAL, nerror )
352                    END IF
353                  ELSE 
354                    ! It's a "normal" 2D (or pseudo 3D) coupling field. 
355                    CALL oasis_def_var (srcv(ji)%nid(jc,jm), zclname, id_part   , (/ 2, 0 /),   &
356                                         OASIS_In           , ishape , OASIS_REAL, nerror )
357                  ENDIF
358
359                  IF ( nerror /= OASIS_Ok ) THEN
360                     WRITE(numout,*) 'Failed to define transient ', ji, jc, jm, " "//TRIM(zclname)
361                     CALL oasis_abort ( srcv(ji)%nid(jc,jm), 'cpl_define', 'Failure in oasis_def_var' )
362                  ENDIF
363                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) /= -1 ) WRITE(numout,*) "variable defined in the namcouple"
364                  IF( ln_ctl .AND. srcv(ji)%nid(jc,jm) == -1 ) WRITE(numout,*) "variable NOT defined in the namcouple"
365
366               END DO
367            END DO
368         ENDIF
369      END DO
370     
371      !------------------------------------------------------------------
372      ! End of definition phase
373      !------------------------------------------------------------------
374     
375      CALL oasis_enddef(nerror)
376      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
377      !
378   END SUBROUTINE cpl_define
379   
380   
381   SUBROUTINE cpl_snd( kid, kstep, pdata, kinfo )
382      !!---------------------------------------------------------------------
383      !!              ***  ROUTINE cpl_snd  ***
384      !!
385      !! ** Purpose : - At each coupling time-step,this routine sends fields
386      !!      like sst or ice cover to the coupler or remote application.
387      !!----------------------------------------------------------------------
388      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
389      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
390      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
391      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata
392      !!
393      INTEGER                                   ::   jc,jm     ! local loop index
394      !!--------------------------------------------------------------------
395      !
396      ! snd data to OASIS3
397      !
398      DO jc = 1, ssnd(kid)%nct
399         DO jm = 1, ssnd(kid)%ncplmodel
400       
401            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
402               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
403               
404               IF ( ln_ctl ) THEN       
405                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
406                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
407                     WRITE(numout,*) '****************'
408                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
409                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
410                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
411                     WRITE(numout,*) 'oasis_put:   info ', kinfo
412                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
413                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
414                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
415                     WRITE(numout,*) '****************'
416                  ENDIF
417               ENDIF
418               
419            ENDIF
420           
421         ENDDO
422      ENDDO
423      !
424    END SUBROUTINE cpl_snd
425
426
427   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
428      !!---------------------------------------------------------------------
429      !!              ***  ROUTINE cpl_rcv  ***
430      !!
431      !! ** Purpose : - At each coupling time-step,this routine receives fields
432      !!      like stresses and fluxes from the coupler or remote application.
433      !!----------------------------------------------------------------------
434      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
435      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
436      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
437      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
438      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
439      !!
440      INTEGER                                   ::   jc,jm     ! local loop index
441      LOGICAL                                   ::   llaction, llfisrt
442      !!--------------------------------------------------------------------
443      !
444      ! receive local data from OASIS3 on every process
445      !
446      kinfo = OASIS_idle
447      !
448      DO jc = 1, srcv(kid)%nct
449         llfisrt = .TRUE.
450
451         DO jm = 1, srcv(kid)%ncplmodel
452
453            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
454
455               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )   
456               
457               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
458                &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
459               
460               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
461               
462               IF ( llaction ) THEN
463                 
464                  kinfo = OASIS_Rcv
465                  IF( llfisrt ) THEN
466                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm) 
467                     llfisrt = .FALSE.
468                  ELSE
469                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
470                  ENDIF
471                 
472                  IF ( ln_ctl ) THEN       
473                     WRITE(numout,*) '****************'
474                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
475                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
476                     WRITE(numout,*) 'oasis_get:   kstep', kstep
477                     WRITE(numout,*) 'oasis_get:   info ', kinfo
478                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
479                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
480                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
481                     WRITE(numout,*) '****************'
482                  ENDIF
483
484               ENDIF
485
486            ENDIF
487           
488         ENDDO
489
490         !--- Fill the overlap areas and extra hallows (mpp)
491         !--- check periodicity conditions (all cases)
492         IF( .not. llfisrt )   CALL lbc_lnk( pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
493 
494      ENDDO
495      !
496   END SUBROUTINE cpl_rcv
497
498   SUBROUTINE cpl_rcv_1d( kid, kstep, pdata, nitems, kinfo )
499      !!---------------------------------------------------------------------
500      !!              ***  ROUTINE cpl_rcv_1d  ***
501      !!
502      !! ** Purpose : - A special version of cpl_rcv to deal exclusively with
503      !! receipt of 0D or 1D fields.
504      !! The fields are recieved into a 1D array buffer which is simply a
505      !! dynamically sized sized array (which may be of size 1)
506      !! of 0 dimensional fields. This allows us to pass miltiple 0D
507      !! fields via a single put/get operation. 
508      !!----------------------------------------------------------------------
509      INTEGER , INTENT(in   ) ::   nitems      ! Number of 0D items to recieve
510                                               ! during this get operation. i.e.
511                                               ! The size of the 1D array in which
512                                               ! 0D items are passed.   
513      INTEGER , INTENT(in   ) ::   kid         ! ID index of the incoming
514                                               ! data. 
515      INTEGER , INTENT(in   ) ::   kstep       ! ocean time-step in seconds
516      REAL(wp), INTENT(inout) ::   pdata(1:nitems) ! The original value(s), 
517                                                   ! unchanged if nothing is
518                                                   ! received
519      INTEGER , INTENT(  out) ::   kinfo       ! OASIS3 info argument
520      !!
521      REAL(wp) ::   recvfld(1:nitems)          ! Local receive field buffer
522      INTEGER  ::   jc,jm     ! local loop index
523      INTEGER  ::   ierr
524      LOGICAL  ::   llaction
525      INTEGER  ::   MPI_WORKING_PRECISION
526      INTEGER  ::   number_to_print 
527      !!--------------------------------------------------------------------
528      !
529      ! receive local data from OASIS3 on every process
530      !
531      kinfo = OASIS_idle
532      !
533      ! 0D and 1D fields won't have categories or any other form of "pseudo level"
534      ! so we only cater for a single set of values and thus don't bother
535      ! with a loop over the jc index
536      jc = 1
537
538      DO jm = 1, srcv(kid)%ncplmodel
539
540         IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
541
542            IF ( ( srcv(kid)%dimensions <= 1) .AND. (nproc == 0) ) THEN
543               ! Since there is no concept of data decomposition for zero
544               ! dimension fields, they must only be exchanged through the master PE,
545               ! unlike "normal" 2D field cases where every PE is involved.
546
547               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, recvfld, kinfo )   
548               
549               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
550                           kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
551               
552               IF ( ln_ctl ) WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , &
553                                     llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
554               
555               IF ( llaction ) THEN
556                 
557                  kinfo = OASIS_Rcv
558                  pdata(1:nitems) = recvfld(1:nitems) 
559                 
560                  IF ( ln_ctl ) THEN       
561                     number_to_print = 10
562                     IF ( nitems < number_to_print ) number_to_print = nitems
563                     WRITE(numout,*) '****************'
564                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
565                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
566                     WRITE(numout,*) 'oasis_get:   kstep', kstep
567                     WRITE(numout,*) 'oasis_get:   info ', kinfo
568                     WRITE(numout,*) '     - Minimum Value is ', MINVAL(pdata(:))
569                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:))
570                     WRITE(numout,*) '     - Start of data is ', pdata(1:number_to_print)
571                     WRITE(numout,*) '****************'
572                  ENDIF
573                 
574               ENDIF
575            ENDIF   
576          ENDIF
577           
578       ENDDO
579       
580       ! Set the precision that we want to broadcast using MPI_BCAST
581       SELECT CASE( wp )
582       CASE( sp ) 
583         MPI_WORKING_PRECISION = MPI_REAL                ! Single precision
584       CASE( dp )
585         MPI_WORKING_PRECISION = MPI_DOUBLE_PRECISION    ! Double precision
586       CASE default
587         CALL oasis_abort( ncomp_id, "cpl_rcv_1d", "Could not find precision for coupling 0d or 1d field" )
588       END SELECT
589
590       ! We have to broadcast (potentially) received values from PE 0 to all
591       ! the others. If no new data has been received we're just
592       ! broadcasting the existing values but there's no more efficient way
593       ! to deal with that w/o NEMO adopting a UM-style test mechanism
594       ! to determine active put/get timesteps.
595       CALL mpi_bcast( pdata, nitems, MPI_WORKING_PRECISION, localRoot, mpi_comm_opa, ierr )
596
597      !
598   END SUBROUTINE cpl_rcv_1d
599
600
601   INTEGER FUNCTION cpl_freq( cdfieldname ) 
602      !!---------------------------------------------------------------------
603      !!              ***  ROUTINE cpl_freq  ***
604      !!
605      !! ** Purpose : - send back the coupling frequency for a particular field
606      !!----------------------------------------------------------------------
607      CHARACTER(len = *), INTENT(in) ::   cdfieldname    ! field name as set in namcouple file
608      !!
609      INTEGER               :: id
610      INTEGER               :: info
611      INTEGER, DIMENSION(1) :: itmp
612      INTEGER               :: ji,jm     ! local loop index
613      INTEGER               :: mop
614      !!----------------------------------------------------------------------
615      cpl_freq = 0   ! defaut definition
616      id = -1        ! defaut definition
617      !
618      DO ji = 1, nsnd
619         IF (ssnd(ji)%laction ) THEN
620            DO jm = 1, ncplmodel
621               IF( ssnd(ji)%nid(1,jm) /= -1 ) THEN
622                  IF( TRIM(cdfieldname) == TRIM(ssnd(ji)%clname) ) THEN
623                     id = ssnd(ji)%nid(1,jm)
624                     mop = OASIS_Out
625                  ENDIF
626               ENDIF
627            ENDDO
628         ENDIF
629      ENDDO
630      DO ji = 1, nrcv
631         IF (srcv(ji)%laction ) THEN
632            DO jm = 1, ncplmodel
633               IF( srcv(ji)%nid(1,jm) /= -1 ) THEN
634                  IF( TRIM(cdfieldname) == TRIM(srcv(ji)%clname) ) THEN
635                     id = srcv(ji)%nid(1,jm)
636                     mop = OASIS_In
637                  ENDIF
638               ENDIF
639            ENDDO
640         ENDIF
641      ENDDO
642      !
643      IF( id /= -1 ) THEN
644#if defined key_oa3mct_v3
645         CALL oasis_get_freqs(id, mop, 1, itmp, info)
646#else
647#if defined key_oasis3 
648         itmp(1) = namflddti( id )
649#else
650         CALL oasis_get_freqs(id,      1, itmp, info)
651#endif
652#endif
653         cpl_freq = itmp(1)
654      ENDIF
655      !
656   END FUNCTION cpl_freq
657
658
659   SUBROUTINE cpl_finalize
660      !!---------------------------------------------------------------------
661      !!              ***  ROUTINE cpl_finalize  ***
662      !!
663      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
664      !!      called explicitly before cpl_init it will also close
665      !!      MPI communication.
666      !!----------------------------------------------------------------------
667      !
668      DEALLOCATE( exfld )
669      IF (nstop == 0) THEN
670         CALL oasis_terminate( nerror )         
671      ELSE
672         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
673      ENDIF       
674      !
675   END SUBROUTINE cpl_finalize
676
677#if ! defined key_oasis3
678
679   !!----------------------------------------------------------------------
680   !!   No OASIS Library          OASIS3 Dummy module...
681   !!----------------------------------------------------------------------
682
683   SUBROUTINE oasis_init_comp(k1,cd1,k2)
684      CHARACTER(*), INTENT(in   ) ::  cd1
685      INTEGER     , INTENT(  out) ::  k1,k2
686      k1 = -1 ; k2 = -1
687      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
688   END SUBROUTINE oasis_init_comp
689
690   SUBROUTINE oasis_abort(k1,cd1,cd2)
691      INTEGER     , INTENT(in   ) ::  k1
692      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
693      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
694   END SUBROUTINE oasis_abort
695
696   SUBROUTINE oasis_get_localcomm(k1,k2)
697      INTEGER     , INTENT(  out) ::  k1,k2
698      k1 = -1 ; k2 = -1
699      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
700   END SUBROUTINE oasis_get_localcomm
701
702   SUBROUTINE oasis_def_partition(k1,k2,k3,K4)
703      INTEGER     , INTENT(  out) ::  k1,k3
704      INTEGER     , INTENT(in   ) ::  k2(5)
705      INTEGER     , OPTIONAL, INTENT(in   ) ::  k4
706      k1 = k2(1) ; k3 = k2(5)
707      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
708   END SUBROUTINE oasis_def_partition
709
710   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
711      CHARACTER(*), INTENT(in   ) ::  cd1
712      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(2,2),k6
713      INTEGER     , INTENT(  out) ::  k1,k7
714      k1 = -1 ; k7 = -1
715      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
716   END SUBROUTINE oasis_def_var
717
718   SUBROUTINE oasis_enddef(k1)
719      INTEGER     , INTENT(  out) ::  k1
720      k1 = -1
721      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
722   END SUBROUTINE oasis_enddef
723 
724   SUBROUTINE oasis_put(k1,k2,p1,k3)
725      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
726      INTEGER                 , INTENT(in   ) ::  k1,k2
727      INTEGER                 , INTENT(  out) ::  k3
728      k3 = -1
729      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
730   END SUBROUTINE oasis_put
731
732   SUBROUTINE oasis_get(k1,k2,p1,k3)
733      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
734      INTEGER                 , INTENT(in   ) ::  k1,k2
735      INTEGER                 , INTENT(  out) ::  k3
736      p1(1,1) = -1. ; k3 = -1
737      WRITE(numout,*) 'oasis_get: Error you sould not be there...'
738   END SUBROUTINE oasis_get
739
740   SUBROUTINE oasis_get_freqs(k1,k2,k3,k4)
741      INTEGER              , INTENT(in   ) ::  k1,k2
742      INTEGER, DIMENSION(1), INTENT(  out) ::  k3
743      INTEGER              , INTENT(  out) ::  k4
744      k3(1) = k1 ; k4 = k2
745      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
746   END SUBROUTINE oasis_get_freqs
747
748   SUBROUTINE oasis_terminate(k1)
749      INTEGER     , INTENT(  out) ::  k1
750      k1 = -1
751      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
752   END SUBROUTINE oasis_terminate
753   
754#endif
755
756   !!=====================================================================
757END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.