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

source: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 10269

Last change on this file since 10269 was 10269, checked in by frrh, 5 years ago

Merged Dan's runoff and 0d field coupling chnages from
branches/UKMO/dev_r5518_GO6_new_runoff_coupling using command:

svn merge -r 10174:10215 svn+ssh://forge.ipsl.jussieu.fr/ipsl/forge/projets/nemo/svn/branches/UKMO/dev_r5518_GO6_new_runoff_coupling

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