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.1_icesheet_and_river_coupling/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.1_icesheet_and_river_coupling/src/OCE/SBC/cpl_oasis3.F90 @ 12675

Last change on this file since 12675 was 12675, checked in by dancopsey, 4 years ago

Fix compile errors.

File size: 36.6 KB
Line 
1MODULE cpl_oasis3
2   !!======================================================================
3   !!                    ***  MODULE cpl_oasis  ***
4   !! Coupled O/A : coupled ocean-atmosphere case using OASIS3-MCT
5   !!=====================================================================
6   !! History :  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=60   ! 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      CALL oasis_enddef(nerror)
405      IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')
406      !
407      IF ( ltmp_wapatch ) THEN
408         nldi = nldi_save   ;   nlei = nlei_save
409         nldj = nldj_save   ;   nlej = nlej_save
410      ENDIF
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      ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define
429      IF ( ltmp_wapatch ) THEN
430         nldi_save = nldi   ;   nlei_save = nlei
431         nldj_save = nldj   ;   nlej_save = nlej
432         IF( nimpp           ==      1 ) nldi = 1
433         IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
434         IF( njmpp           ==      1 ) nldj = 1
435         IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
436      ENDIF
437      !
438      ! snd data to OASIS3
439      !
440      DO jc = 1, ssnd(kid)%nct
441         DO jm = 1, ssnd(kid)%ncplmodel
442       
443            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN
444               CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )
445               
446               IF ( ln_ctl ) THEN       
447                  IF ( kinfo == OASIS_Sent     .OR. kinfo == OASIS_ToRest .OR.   &
448                     & kinfo == OASIS_SentOut  .OR. kinfo == OASIS_ToRestOut ) THEN
449                     WRITE(numout,*) '****************'
450                     WRITE(numout,*) 'oasis_put: Outgoing ', ssnd(kid)%clname
451                     WRITE(numout,*) 'oasis_put: ivarid ', ssnd(kid)%nid(jc,jm)
452                     WRITE(numout,*) 'oasis_put:  kstep ', kstep
453                     WRITE(numout,*) 'oasis_put:   info ', kinfo
454                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
455                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
456                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
457                     WRITE(numout,*) '****************'
458                  ENDIF
459               ENDIF
460               
461            ENDIF
462           
463         ENDDO
464      ENDDO
465      IF ( ltmp_wapatch ) THEN
466         nldi = nldi_save   ;   nlei = nlei_save
467         nldj = nldj_save   ;   nlej = nlej_save
468      ENDIF
469      !
470    END SUBROUTINE cpl_snd
471
472
473   SUBROUTINE cpl_rcv( kid, kstep, pdata, pmask, kinfo )
474      !!---------------------------------------------------------------------
475      !!              ***  ROUTINE cpl_rcv  ***
476      !!
477      !! ** Purpose : - At each coupling time-step,this routine receives fields
478      !!      like stresses and fluxes from the coupler or remote application.
479      !!----------------------------------------------------------------------
480      INTEGER                   , INTENT(in   ) ::   kid       ! variable index in the array
481      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
482      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdata     ! IN to keep the value if nothing is done
483      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pmask     ! coupling mask
484      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument
485      !!
486      INTEGER                                   ::   jc,jm     ! local loop index
487      LOGICAL                                   ::   llaction, llfisrt
488      !!--------------------------------------------------------------------
489      ! patch to restore wraparound rows in cpl_send, cpl_rcv, cpl_define
490      IF ( ltmp_wapatch ) THEN
491         nldi_save = nldi   ;   nlei_save = nlei
492         nldj_save = nldj   ;   nlej_save = nlej
493      ENDIF
494      !
495      ! receive local data from OASIS3 on every process
496      !
497      kinfo = OASIS_idle
498      !
499      DO jc = 1, srcv(kid)%nct
500         IF ( ltmp_wapatch ) THEN
501            IF( nimpp           ==      1 ) nldi = 1
502            IF( nimpp + jpi - 1 == jpiglo ) nlei = jpi
503            IF( njmpp           ==      1 ) nldj = 1
504            IF( njmpp + jpj - 1 == jpjglo ) nlej = jpj
505         ENDIF
506         llfisrt = .TRUE.
507
508         DO jm = 1, srcv(kid)%ncplmodel
509
510            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
511
512               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )         
513               
514               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
515                  &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
516               
517               IF ( ln_ctl )   WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
518               
519               IF ( llaction ) THEN
520                 
521                  kinfo = OASIS_Rcv
522                  IF( llfisrt ) THEN
523                     pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
524                     llfisrt = .FALSE.
525                  ELSE
526                     pdata(nldi:nlei,nldj:nlej,jc) = pdata(nldi:nlei,nldj:nlej,jc) + exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)
527                  ENDIF
528                 
529                  IF ( ln_ctl ) THEN       
530                     WRITE(numout,*) '****************'
531                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
532                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
533                     WRITE(numout,*) 'oasis_get:   kstep', kstep
534                     WRITE(numout,*) 'oasis_get:   info ', kinfo
535                     WRITE(numout,*) '     - Minimum value is ', MINVAL(pdata(:,:,jc))
536                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:,:,jc))
537                     WRITE(numout,*) '     -     Sum value is ', SUM(pdata(:,:,jc))
538                     WRITE(numout,*) '****************'
539                  ENDIF
540                 
541               ENDIF
542               
543            ENDIF
544           
545         ENDDO
546
547         IF ( ltmp_wapatch ) THEN
548            nldi = nldi_save   ;   nlei = nlei_save
549            nldj = nldj_save   ;   nlej = nlej_save
550         ENDIF
551         !--- Fill the overlap areas and extra hallows (mpp)
552         !--- check periodicity conditions (all cases)
553         IF( .not. llfisrt ) THEN
554            CALL lbc_lnk( 'cpl_oasis3', pdata(:,:,jc), srcv(kid)%clgrid, srcv(kid)%nsgn )   
555         ENDIF
556 
557      ENDDO
558      !
559   END SUBROUTINE cpl_rcv
560
561
562   SUBROUTINE cpl_rcv_1d( kid, kstep, pdata, nitems, kinfo )
563      !!---------------------------------------------------------------------
564      !!              ***  ROUTINE cpl_rcv_1d  ***
565      !!
566      !! ** Purpose : - A special version of cpl_rcv to deal exclusively with
567      !! receipt of 0D or 1D fields.
568      !! The fields are recieved into a 1D array buffer which is simply a
569      !! dynamically sized sized array (which may be of size 1)
570      !! of 0 dimensional fields. This allows us to pass miltiple 0D
571      !! fields via a single put/get operation. 
572      !!----------------------------------------------------------------------
573      INTEGER , INTENT(in   ) ::   nitems      ! Number of 0D items to recieve
574                                               ! during this get operation. i.e.
575                                               ! The size of the 1D array in which
576                                               ! 0D items are passed.   
577      INTEGER , INTENT(in   ) ::   kid         ! ID index of the incoming
578                                               ! data. 
579      INTEGER , INTENT(in   ) ::   kstep       ! ocean time-step in seconds
580      REAL(wp), INTENT(inout) ::   pdata(1:nitems) ! The original value(s), 
581                                                   ! unchanged if nothing is
582                                                   ! received
583      INTEGER , INTENT(  out) ::   kinfo       ! OASIS3 info argument
584      !!
585      REAL(wp) ::   recvfld(1:nitems)          ! Local receive field buffer
586      INTEGER  ::   jc,jm     ! local loop index
587      INTEGER  ::   ierr
588      LOGICAL  ::   llaction
589      INTEGER  ::   MPI_WORKING_PRECISION
590      INTEGER  ::   number_to_print 
591      !!--------------------------------------------------------------------
592      !
593      ! receive local data from OASIS3 on every process
594      !
595      kinfo = OASIS_idle
596      !
597      ! 0D and 1D fields won't have categories or any other form of "pseudo level"
598      ! so we only cater for a single set of values and thus don't bother
599      ! with a loop over the jc index
600      jc = 1
601
602      DO jm = 1, srcv(kid)%ncplmodel
603
604         IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN
605
606            IF ( ( srcv(kid)%dimensions <= 1) .AND. (nproc == 0) ) THEN
607               ! Since there is no concept of data decomposition for zero
608               ! dimension fields, they must only be exchanged through the master PE,
609               ! unlike "normal" 2D field cases where every PE is involved.
610
611               CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, recvfld, kinfo )   
612               
613               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
614                           kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
615               
616               IF ( ln_ctl ) WRITE(numout,*) "llaction, kinfo, kstep, ivarid: " , &
617                                     llaction, kinfo, kstep, srcv(kid)%nid(jc,jm)
618               
619               IF ( llaction ) THEN
620                 
621                  kinfo = OASIS_Rcv
622                  pdata(1:nitems) = recvfld(1:nitems) 
623                 
624                  IF ( ln_ctl ) THEN       
625                     number_to_print = 10
626                     IF ( nitems < number_to_print ) number_to_print = nitems
627                     WRITE(numout,*) '****************'
628                     WRITE(numout,*) 'oasis_get: Incoming ', srcv(kid)%clname
629                     WRITE(numout,*) 'oasis_get: ivarid '  , srcv(kid)%nid(jc,jm)
630                     WRITE(numout,*) 'oasis_get:   kstep', kstep
631                     WRITE(numout,*) 'oasis_get:   info ', kinfo
632                     WRITE(numout,*) '     - Minimum Value is ', MINVAL(pdata(:))
633                     WRITE(numout,*) '     - Maximum value is ', MAXVAL(pdata(:))
634                     WRITE(numout,*) '     - Start of data is ', pdata(1:number_to_print)
635                     WRITE(numout,*) '****************'
636                  ENDIF
637                 
638               ENDIF
639            ENDIF   
640          ENDIF
641           
642       ENDDO
643
644#if defined key_mpp_mpi
645       ! Set the precision that we want to broadcast using MPI_BCAST
646       SELECT CASE( wp )
647       CASE( sp ) 
648         MPI_WORKING_PRECISION = MPI_REAL                ! Single precision
649       CASE( dp )
650         MPI_WORKING_PRECISION = MPI_DOUBLE_PRECISION    ! Double precision
651       CASE default
652         CALL oasis_abort( ncomp_id, "cpl_rcv_1d", "Could not find precision for coupling 0d or 1d field" )
653       END SELECT
654
655       ! We have to broadcast (potentially) received values from PE 0 to all
656       ! the others. If no new data has been received we're just
657       ! broadcasting the existing values but there's no more efficient way
658       ! to deal with that w/o NEMO adopting a UM-style test mechanism
659       ! to determine active put/get timesteps.
660       CALL mpi_bcast( pdata, nitems, MPI_WORKING_PRECISION, localRoot, mpi_comm_oce, ierr )
661#else
662       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." )
663#endif
664
665      !
666   END SUBROUTINE cpl_rcv_1d
667
668
669   INTEGER FUNCTION cpl_freq( cdfieldname ) 
670      !!---------------------------------------------------------------------
671      !!              ***  ROUTINE cpl_freq  ***
672      !!
673      !! ** Purpose : - send back the coupling frequency for a particular field
674      !!----------------------------------------------------------------------
675      CHARACTER(len = *), INTENT(in) ::   cdfieldname    ! field name as set in namcouple file
676      !!
677      INTEGER               :: id
678      INTEGER               :: info
679      INTEGER, DIMENSION(1) :: itmp
680      INTEGER               :: ji,jm     ! local loop index
681      INTEGER               :: mop
682      !!----------------------------------------------------------------------
683      cpl_freq = 0   ! defaut definition
684      id = -1        ! defaut definition
685      !
686      DO ji = 1, nsnd
687         IF (ssnd(ji)%laction ) THEN
688            DO jm = 1, ncplmodel
689               IF( ssnd(ji)%nid(1,jm) /= -1 ) THEN
690                  IF( TRIM(cdfieldname) == TRIM(ssnd(ji)%clname) ) THEN
691                     id = ssnd(ji)%nid(1,jm)
692                     mop = OASIS_Out
693                  ENDIF
694               ENDIF
695            ENDDO
696         ENDIF
697      ENDDO
698      DO ji = 1, nrcv
699         IF (srcv(ji)%laction ) THEN
700            DO jm = 1, ncplmodel
701               IF( srcv(ji)%nid(1,jm) /= -1 ) THEN
702                  IF( TRIM(cdfieldname) == TRIM(srcv(ji)%clname) ) THEN
703                     id = srcv(ji)%nid(1,jm)
704                     mop = OASIS_In
705                  ENDIF
706               ENDIF
707            ENDDO
708         ENDIF
709      ENDDO
710      !
711      IF( id /= -1 ) THEN
712#if ! defined key_oa3mct_v1v2
713         CALL oasis_get_freqs(id, mop, 1, itmp, info)
714#else
715         CALL oasis_get_freqs(id,      1, itmp, info)
716#endif
717         cpl_freq = itmp(1)
718      ENDIF
719      !
720   END FUNCTION cpl_freq
721
722
723   SUBROUTINE cpl_finalize
724      !!---------------------------------------------------------------------
725      !!              ***  ROUTINE cpl_finalize  ***
726      !!
727      !! ** Purpose : - Finalizes the coupling. If MPI_init has not been
728      !!      called explicitly before cpl_init it will also close
729      !!      MPI communication.
730      !!----------------------------------------------------------------------
731      !
732      DEALLOCATE( exfld )
733      IF (nstop == 0) THEN
734         CALL oasis_terminate( nerror )         
735      ELSE
736         CALL oasis_abort( ncomp_id, "cpl_finalize", "NEMO ABORT STOP" )
737      ENDIF       
738      !
739   END SUBROUTINE cpl_finalize
740
741#if ! defined key_oasis3
742
743   !!----------------------------------------------------------------------
744   !!   No OASIS Library          OASIS3 Dummy module...
745   !!----------------------------------------------------------------------
746
747   SUBROUTINE oasis_init_comp(k1,cd1,k2)
748      CHARACTER(*), INTENT(in   ) ::  cd1
749      INTEGER     , INTENT(  out) ::  k1,k2
750      k1 = -1 ; k2 = -1
751      WRITE(numout,*) 'oasis_init_comp: Error you sould not be there...', cd1
752   END SUBROUTINE oasis_init_comp
753
754   SUBROUTINE oasis_abort(k1,cd1,cd2)
755      INTEGER     , INTENT(in   ) ::  k1
756      CHARACTER(*), INTENT(in   ) ::  cd1,cd2
757      WRITE(numout,*) 'oasis_abort: Error you sould not be there...', cd1, cd2
758   END SUBROUTINE oasis_abort
759
760   SUBROUTINE oasis_get_localcomm(k1,k2)
761      INTEGER     , INTENT(  out) ::  k1,k2
762      k1 = -1 ; k2 = -1
763      WRITE(numout,*) 'oasis_get_localcomm: Error you sould not be there...'
764   END SUBROUTINE oasis_get_localcomm
765
766   SUBROUTINE oasis_def_partition(k1,k2,k3,k4)
767      INTEGER     , INTENT(  out) ::  k1,k3
768      INTEGER     , INTENT(in   ) ::  k2(5)
769      INTEGER     , INTENT(in   ) ::  k4
770      k1 = k2(1) ; k3 = k2(5)+k4
771      WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
772   END SUBROUTINE oasis_def_partition
773
774   SUBROUTINE oasis_def_var(k1,cd1,k2,k3,k4,k5,k6,k7)
775      CHARACTER(*), INTENT(in   ) ::  cd1
776      INTEGER     , INTENT(in   ) ::  k2,k3(2),k4,k5(*),k6
777      INTEGER     , INTENT(  out) ::  k1,k7
778      k1 = -1 ; k7 = -1
779      WRITE(numout,*) 'oasis_def_var: Error you sould not be there...', cd1
780   END SUBROUTINE oasis_def_var
781
782   SUBROUTINE oasis_enddef(k1)
783      INTEGER     , INTENT(  out) ::  k1
784      k1 = -1
785      WRITE(numout,*) 'oasis_enddef: Error you sould not be there...'
786   END SUBROUTINE oasis_enddef
787 
788   SUBROUTINE oasis_put(k1,k2,p1,k3)
789      REAL(wp), DIMENSION(:,:), INTENT(in   ) ::  p1
790      INTEGER                 , INTENT(in   ) ::  k1,k2
791      INTEGER                 , INTENT(  out) ::  k3
792      k3 = -1
793      WRITE(numout,*) 'oasis_put: Error you sould not be there...'
794   END SUBROUTINE oasis_put
795
796   SUBROUTINE oasis_get_1d(k1,k2,p1,k3)
797      REAL(wp), DIMENSION(:)  , INTENT(  out) ::  p1
798      INTEGER                 , INTENT(in   ) ::  k1,k2
799      INTEGER                 , INTENT(  out) ::  k3
800      p1(1) = -1. ; k3 = -1
801      WRITE(numout,*) 'oasis_get_1d: Error you sould not be there...'
802   END SUBROUTINE oasis_get_1d
803
804   SUBROUTINE oasis_get_2d(k1,k2,p1,k3)
805      REAL(wp), DIMENSION(:,:), INTENT(  out) ::  p1
806      INTEGER                 , INTENT(in   ) ::  k1,k2
807      INTEGER                 , INTENT(  out) ::  k3
808      p1(1,1) = -1. ; k3 = -1
809      WRITE(numout,*) 'oasis_get_2d: Error you sould not be there...'
810   END SUBROUTINE oasis_get_2d
811
812   SUBROUTINE oasis_get_freqs(k1,k5,k2,k3,k4)
813      INTEGER              , INTENT(in   ) ::  k1,k2
814      INTEGER, DIMENSION(1), INTENT(  out) ::  k3
815      INTEGER              , INTENT(  out) ::  k4,k5
816      k3(1) = k1 ; k4 = k2 ; k5 = k2
817      WRITE(numout,*) 'oasis_get_freqs: Error you sould not be there...'
818   END SUBROUTINE oasis_get_freqs
819
820   SUBROUTINE oasis_terminate(k1)
821      INTEGER     , INTENT(  out) ::  k1
822      k1 = -1
823      WRITE(numout,*) 'oasis_terminate: Error you sould not be there...'
824   END SUBROUTINE oasis_terminate
825   
826#endif
827
828   !!=====================================================================
829END MODULE cpl_oasis3
Note: See TracBrowser for help on using the repository browser.