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

source: branches/UKMO/dev_r5518_cleanup_1d_cpl/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 @ 10046

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

Re-enable 2D coupling of icesheet mass. To switch between 2D to 0D coupling of ice mass change sn_rcv_grnm%cldes from 'coupled' to 'coupled0d' (with a similar change to sn_rcv_antm).

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