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 @ 10195

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

Make code compatible with ocean only runs.

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