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

source: branches/UKMO/dev_r5518_GO6_XIOS25_cpl/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90

Last change on this file was 12796, checked in by andmirek, 4 years ago

GMED developmemnt; Ticket 538 add call to xios function

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