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.4_GO8_paquage_branch/src/OCE/SBC – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.4_GO8_paquage_branch/src/OCE/SBC/cpl_oasis3.F90 @ 15702

Last change on this file since 15702 was 15702, checked in by jpalmier, 2 years ago

Richard Hills fix cpl

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