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 NEMO/branches/UKMO/NEMO_4.0.3_icesheet_and_river_coupling/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.3_icesheet_and_river_coupling/src/OCE/SBC/cpl_oasis3.F90 @ 13778

Last change on this file since 13778 was 13778, checked in by dancopsey, 3 years ago

Merge in existing changes from NEMO_4.0.1 version of this branch.

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