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.
nemogcm.F90 in branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 3837

Last change on this file since 3837 was 3837, checked in by trackstand2, 11 years ago

Merge of finiss

  • Property svn:keywords set to Id
File size: 40.4 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            4.0  ! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!----------------------------------------------------------------------
31
32   !!----------------------------------------------------------------------
33   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
34   !!   nemo_init      : initialization of the NEMO system
35   !!   nemo_ctl       : initialisation of the contol print
36   !!   nemo_closefile : close remaining open files
37   !!   nemo_alloc     : dynamical allocation
38   !!   nemo_partition : calculate MPP domain decomposition
39   !!   sqfact         : calculate factors of the no. of MPI processes
40   !!----------------------------------------------------------------------
41   USE step_oce        ! module used in the ocean time stepping module
42   USE sbc_oce         ! surface boundary condition: ocean
43   USE cla             ! cross land advection               (tra_cla routine)
44   USE domcfg          ! domain configuration               (dom_cfg routine)
45   USE mppini          ! shared/distributed memory setting (mpp_init routine)
46   USE domain          ! domain initialization             (dom_init routine)
47   USE obcini          ! open boundary cond. initialization (obc_ini routine)
48   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
49   USE istate          ! initial state setting          (istate_init routine)
50   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
51   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
52   USE zdfini          ! vertical physics setting          (zdf_init routine)
53   USE phycst          ! physical constant                  (par_cst routine)
54   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
55   USE asminc          ! assimilation increments       (asm_inc_init routine)
56   USE asmtrj          ! writing out state trajectory
57   USE sshwzv          ! vertical velocity used in asm
58   USE diaptr          ! poleward transports           (dia_ptr_init routine)
59   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
60   USE step            ! NEMO time-stepping                 (stp     routine)
61#if defined key_oasis3
62   USE cpl_oasis3      ! OASIS3 coupling
63#elif defined key_oasis4
64   USE cpl_oasis4      ! OASIS4 coupling (not working)
65#endif
66   USE c1d             ! 1D configuration
67   USE step_c1d        ! Time stepping loop for the 1D configuration
68#if defined key_top
69   USE trcini          ! passive tracer initialisation
70#endif
71   USE lib_mpp         ! distributed memory computing
72#if defined key_iomput
73   USE mod_ioclient
74#endif
75   USE partition_mod   ! irregular domain partitioning
76   USE timing, ONLY: timing_init, timing_finalize, timing_disable, timing_enable
77
78#define ARPDEBUG
79
80   IMPLICIT NONE
81   PRIVATE
82
83   PUBLIC   nemo_gcm    ! called by model.F90
84   PUBLIC   nemo_init   ! needed by AGRIF
85
86   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
87
88   !!----------------------------------------------------------------------
89   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
90   !! $Id$
91   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
92   !!----------------------------------------------------------------------
93CONTAINS
94
95   SUBROUTINE nemo_gcm
96      !!----------------------------------------------------------------------
97      !!                     ***  ROUTINE nemo_gcm  ***
98      !!
99      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
100      !!              curvilinear mesh on the sphere.
101      !!
102      !! ** Method  : - model general initialization
103      !!              - launch the time-stepping (stp routine)
104      !!              - finalize the run by closing files and communications
105      !!
106      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
107      !!              Madec, 2008, internal report, IPSL.
108      !!----------------------------------------------------------------------
109      INTEGER ::   istp       ! time step index
110      !!----------------------------------------------------------------------
111      !
112#if defined key_agrif
113      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
114#endif
115
116      !                            !-----------------------!
117      CALL nemo_init               !==  Initialisations  ==!
118      !                            !-----------------------!
119#if defined key_agrif
120      CALL Agrif_Declare_Var       ! AGRIF: set the meshes
121# if defined key_top
122      CALL Agrif_Declare_Var_Top   ! AGRIF: set the meshes
123# endif
124#endif
125      ! check that all process are still there... If some process have an error,
126      ! they will never enter in step and other processes will wait until the end of the cpu time!
127      IF( lk_mpp )   CALL mpp_max( nstop )
128
129      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
130
131      CALL timing_enable()
132      !                            !-----------------------!
133      !                            !==   time stepping   ==!
134      !                            !-----------------------!
135      istp = nit000
136#if defined key_c1d
137         DO WHILE ( istp <= nitend .AND. nstop == 0 )
138            CALL stp_c1d( istp )
139            istp = istp + 1
140         END DO
141#else
142          IF( lk_asminc ) THEN
143             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
144             IF( ln_trjwri ) CALL asm_trj_wri( nit000 - 1 )    ! Output trajectory fields
145             IF( ln_asmdin ) THEN                        ! Direct initialization
146                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
147                IF( ln_dyninc ) THEN
148                   CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
149                   IF ( ln_asmdin ) CALL ssh_wzv ( nit000 - 1 )      ! update vertical velocity
150                ENDIF
151                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
152             ENDIF
153          ENDIF
154       
155         DO WHILE ( istp <= nitend .AND. nstop == 0 )
156#if defined key_agrif
157            CALL Agrif_Step( stp )           ! AGRIF: time stepping
158#else
159            CALL stp( istp )                 ! standard time stepping
160#endif
161            istp = istp + 1
162            IF( lk_mpp )   CALL mpp_max( nstop )
163         END DO
164#endif
165
166      IF( lk_diaobs ) CALL dia_obs_wri
167       
168      !                            !------------------------!
169      !                            !==  finalize the run  ==!
170      !                            !------------------------!
171      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
172      !
173      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
174         WRITE(numout,cform_err)
175         WRITE(numout,*) nstop, ' error have been found' 
176      ENDIF
177      !
178      CALL timing_finalize              ! Timing report
179
180      CALL nemo_closefile
181#if defined key_oasis3 || defined key_oasis4
182      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
183#else
184      IF( lk_mpp )   CALL mppstop       ! end mpp communications
185#endif
186      !
187   END SUBROUTINE nemo_gcm
188
189
190   SUBROUTINE nemo_init
191      !!----------------------------------------------------------------------
192      !!                     ***  ROUTINE nemo_init  ***
193      !!
194      !! ** Purpose :   initialization of the NEMO GCM
195      !!----------------------------------------------------------------------
196      INTEGER ::   ji            ! dummy loop indices
197      INTEGER ::   ilocal_comm   ! local integer
198      CHARACTER(len=80), DIMENSION(24) ::   cltxt
199      !!
200      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
201         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench
202      !!----------------------------------------------------------------------
203      !
204      cltxt(:) = ''
205      !
206      !                             ! open Namelist file
207      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
208      !
209      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
210      !
211      !                             !--------------------------------------------!
212      !                             !  set communicator & select the local node  !
213      !                             !--------------------------------------------!
214#if defined key_iomput
215      IF( Agrif_Root() ) THEN
216# if defined key_oasis3 || defined key_oasis4
217         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
218# endif
219         CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server
220      ENDIF
221      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
222#else
223# if defined key_oasis3 || defined key_oasis4
224      IF( Agrif_Root() ) THEN
225         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
226      ENDIF
227      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
228# else
229      ilocal_comm = 0
230      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
231# endif
232#endif
233      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
234
235      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
236
237      ! Calculate domain z dimensions as needed when partitioning.
238      ! This used to be done in par_oce.F90 when they were parameters rather
239      ! than variables
240      IF( Agrif_Root() ) THEN
241         jpk = jpkdta                                             ! third dim
242         jpkm1 = jpk-1                                            ! inner domain indices
243      ENDIF
244
245      CALL timing_init                                      ! Init timing module
246      CALL timing_disable                                   ! but disable during startup
247
248      ! If dimensions of processor grid weren't specified in the namelist file
249      ! then we calculate them here now that we have our communicator size
250      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
251#if   defined key_mpp_mpi
252#if   defined key_mpp_rkpart
253         IF( Agrif_Root() ) CALL nemo_recursive_partition(mppsize)
254#else
255         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
256#endif
257#else
258         jpni  = 1
259         jpnj  = 1
260         jpnij = jpni*jpnj
261#endif
262
263#if   defined key_mpp_rkpart
264      ELSE
265         CALL ctl_stop( 'STOP', 'nemo_init : invalid inputs in namelist - cannot specify jpn{i,j}>0 when using recursive k-section paritioning!' )
266#endif
267      END IF
268
269      ! Calculate domain dimensions given calculated jpni and jpnj
270      ! This used to be done in par_oce.F90 when they were parameters rather
271      ! than variables
272      IF( Agrif_Root() ) THEN
273#if ! defined key_mpp_rkpart
274         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
275         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
276         jpim1 = jpi-1                                            ! inner domain indices
277         jpjm1 = jpj-1                                            !   "           "
278         jpij  = jpi*jpj                                          !  jpi x j
279#endif
280      ENDIF
281
282      IF(lwp) THEN                            ! open listing units
283         !
284         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
285         !
286         WRITE(numout,*)
287         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
288         WRITE(numout,*) '                       NEMO team'
289         WRITE(numout,*) '            Ocean General Circulation Model'
290         WRITE(numout,*) '                  version 3.3  (2010) '
291         WRITE(numout,*)
292         WRITE(numout,*)
293         DO ji = 1, SIZE(cltxt,1) 
294            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
295         END DO
296         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
297         !
298      ENDIF
299
300      ! Now we know the dimensions of the grid and numout has been set we can
301      ! allocate arrays
302      CALL nemo_alloc()
303
304      !                             !-------------------------------!
305      !                             !  NEMO general initialization  !
306      !                             !-------------------------------!
307
308      CALL nemo_ctl                          ! Control prints & Benchmark
309
310      !                                      ! Domain decomposition
311#if defined key_mpp_rkpart
312                                          CALL mpp_init3     ! Remainder of set-up for
313                                                             ! recursive partitioning
314#else
315      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
316      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
317      ENDIF
318#endif
319      !
320      !                                      ! General initialization
321!                            CALL     timing_init! Timing module
322                            CALL     phy_cst    ! Physical constants
323                            CALL     eos_init   ! Equation of state
324                            CALL     dom_cfg    ! Domain configuration
325                            CALL     dom_init   ! Domain
326
327      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
328
329      IF( lk_obc        )   CALL     obc_init   ! Open boundaries
330      IF( lk_bdy        )   CALL     bdy_init   ! Unstructured open boundaries
331
332                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
333
334      !                                     ! Ocean physics
335                            CALL     sbc_init   ! Forcings : surface module
336      !                                         ! Vertical physics
337                            CALL     zdf_init      ! namelist read
338                            CALL zdf_bfr_init      ! bottom friction
339      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
340      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
341      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
342      IF( lk_zdfkpp     )   CALL zdf_kpp_init      ! KPP closure scheme
343      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
344      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   & 
345         &                  CALL zdf_ddm_init      ! double diffusive mixing
346      !                                         ! Lateral physics
347                            CALL ldf_tra_init      ! Lateral ocean tracer physics
348                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
349      IF( lk_ldfslp     )   CALL ldf_slp_init      ! slope of lateral mixing
350
351      !                                     ! Active tracers
352                            CALL tra_qsr_init   ! penetrative solar radiation qsr
353                            CALL tra_bbc_init   ! bottom heat flux
354      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
355      IF( lk_tradmp     )   CALL tra_dmp_init   ! internal damping trends
356                            CALL tra_adv_init   ! horizontal & vertical advection
357                            CALL tra_ldf_init   ! lateral mixing
358                            CALL tra_zdf_init   ! vertical mixing and after tracer fields
359
360      !                                     ! Dynamics
361                            CALL dyn_adv_init   ! advection (vector or flux form)
362                            CALL dyn_vor_init   ! vorticity term including Coriolis
363                            CALL dyn_ldf_init   ! lateral mixing
364                            CALL dyn_hpg_init   ! horizontal gradient of Hydrostatic pressure
365                            CALL dyn_zdf_init   ! vertical diffusion
366                            CALL dyn_spg_init   ! surface pressure gradient
367                           
368      !                                     ! Misc. options
369      IF( nn_cla == 1   )   CALL cla_init       ! Cross Land Advection
370     
371#if defined key_top
372      !                                     ! Passive tracers
373                            CALL     trc_init
374#endif
375      !                                     ! Diagnostics
376                            CALL     iom_init   ! iom_put initialization
377      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
378      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
379                            CALL dia_ptr_init   ! Poleward TRansports initialization
380                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
381                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
382      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
383                            CALL dia_obs_init            ! Initialize observational data
384                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
385      ENDIF     
386      !                                     ! Assimilation increments
387      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
388      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
389      !
390   END SUBROUTINE nemo_init
391
392
393   SUBROUTINE nemo_ctl
394      !!----------------------------------------------------------------------
395      !!                     ***  ROUTINE nemo_ctl  ***
396      !!
397      !! ** Purpose :   control print setting
398      !!
399      !! ** Method  : - print namctl information and check some consistencies
400      !!----------------------------------------------------------------------
401      !
402      IF(lwp) THEN                  ! control print
403         WRITE(numout,*)
404         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
405         WRITE(numout,*) '~~~~~~~ '
406         WRITE(numout,*) '   Namelist namctl'
407         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
408         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
409         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
410         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
411         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
412         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
413         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
414         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
415         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
416      ENDIF
417      !
418      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
419      nictls    = nn_ictls
420      nictle    = nn_ictle
421      njctls    = nn_jctls
422      njctle    = nn_jctle
423      isplt     = nn_isplt
424      jsplt     = nn_jsplt
425      nbench    = nn_bench
426      !                             ! Parameter control
427      !
428      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
429         IF( lk_mpp ) THEN
430            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
431         ELSE
432            IF( isplt == 1 .AND. jsplt == 1  ) THEN
433               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
434                  &           ' - the print control will be done over the whole domain' )
435            ENDIF
436            ijsplt = isplt * jsplt            ! total number of processors ijsplt
437         ENDIF
438         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
439         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
440         !
441         !                              ! indices used for the SUM control
442         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
443            lsp_area = .FALSE.                       
444         ELSE                                             ! print control done over a specific  area
445            lsp_area = .TRUE.
446            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
447               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
448               nictls = 1
449            ENDIF
450            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
451               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
452               nictle = jpiglo
453            ENDIF
454            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
455               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
456               njctls = 1
457            ENDIF
458            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
459               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
460               njctle = jpjglo
461            ENDIF
462         ENDIF
463      ENDIF
464      !
465      IF( nbench == 1 ) THEN              ! Benchmark
466         SELECT CASE ( cp_cfg )
467         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
468         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
469            &                                 ' key_gyre must be used or set nbench = 0' )
470         END SELECT
471      ENDIF
472      !
473      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
474         &                                               'with the IOM Input/Output manager. '         ,   &
475         &                                               'Compile with key_iomput enabled' )
476      !
477   END SUBROUTINE nemo_ctl
478
479
480   SUBROUTINE nemo_closefile
481      !!----------------------------------------------------------------------
482      !!                     ***  ROUTINE nemo_closefile  ***
483      !!
484      !! ** Purpose :   Close the files
485      !!----------------------------------------------------------------------
486      !
487      IF( lk_mpp )   CALL mppsync
488      !
489      CALL iom_close                                 ! close all input/output files managed by iom_*
490      !
491      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
492      IF( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
493      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
494      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
495      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
496      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
497      !
498      numout = 6                                     ! redefine numout in case it is used after this point...
499      !
500   END SUBROUTINE nemo_closefile
501
502
503   SUBROUTINE nemo_alloc
504      !!----------------------------------------------------------------------
505      !!                     ***  ROUTINE nemo_alloc  ***
506      !!
507      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
508      !!
509      !! ** Method  :
510      !!----------------------------------------------------------------------
511      USE diawri    , ONLY: dia_wri_alloc
512      USE dom_oce   , ONLY: dom_oce_alloc
513      USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc
514      USE ldftra_oce, ONLY: ldftra_oce_alloc
515      USE trc_oce   , ONLY: trc_oce_alloc
516      USE wrk_nemo  , ONLY: wrk_alloc
517      USE exchmod   , ONLY: exchmod_alloc
518      !
519      INTEGER :: ierr
520      !!----------------------------------------------------------------------
521      !
522      ierr =        oce_alloc       ()          ! ocean
523      ierr = ierr + dia_wri_alloc   ()
524      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
525      ierr = ierr + ldfdyn_oce_alloc()          ! ocean lateral  physics : dynamics
526      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
527      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
528      !
529      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
530      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
531      !
532      ierr = ierr + wrk_alloc(numout, lwp)      ! workspace
533      !
534      ierr = ierr + exchmod_alloc()             ! New mpp msg framework
535      !
536      IF( lk_mpp    )   CALL mpp_sum( ierr )
537      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
538      !
539   END SUBROUTINE nemo_alloc
540
541
542   SUBROUTINE nemo_partition( num_pes )
543      USE mapcomm_mod, ONLY: trimmed
544      !!----------------------------------------------------------------------
545      !!                 ***  ROUTINE nemo_partition  ***
546      !!
547      !! ** Purpose : Work out a sensible factorisation of the number of
548      !!              processors for the x and y dimensions.
549      !! ** Method  :
550      !!----------------------------------------------------------------------
551      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
552      !
553      INTEGER             :: ifact1, ifact2 ! factors of num_pes, ifact1 <= ifact2
554      !!----------------------------------------------------------------------
555
556      ! Factorise the number of processors into ifact1*ifact2, such that
557      ! ifact1 and ifact2 are as nearly equal as possible.
558
559      CALL sqfact( num_pes, ifact1, ifact2 )
560
561      ! Make sure that the smaller dimension of the processor grid
562      ! is given the smaller dimension of the global domain
563      IF( jpiglo <= jpjglo) THEN
564         jpni = ifact1
565         jpnj = ifact2
566      ELSE
567         jpni = ifact2
568         jpnj = ifact1
569      ENDIF
570
571      ! This should never happen
572      IF( (jpni*jpnj) /= num_pes) THEN
573         WRITE (numout, *) 'WARNING: internal error - factorisation of number of PEs failed'
574      ENDIF
575
576      ! This should only happen if num_pes is prime
577      IF( ifact1 <= 1 ) THEN
578         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
579         WRITE (numout, *) '       : using grid of ',jpni,' x ',jpnj
580      ENDIF
581      !
582      jpnij = jpni*jpnj
583      !
584
585      ! Array that stores whether domain boundaries have been trimmed. Not used in
586      ! this case (regular domain decomp.) so set all to false.
587      ALLOCATE(trimmed(4,jpnij))
588      trimmed(:,:) = .FALSE.
589
590   END SUBROUTINE nemo_partition
591
592
593   SUBROUTINE nemo_recursive_partition( num_pes )
594      USE in_out_manager, ONLY: numnam
595      USE dom_oce,        ONLY: ln_zco, ntopo
596      USE dom_oce,        ONLY: gdepw_0, gdept_0, e3w_0, e3t_0, &
597                                mig, mjg, mi0, mi1, mj0, mj1,  mbathy, bathy
598      USE domzgr,         ONLY: zgr_z, zgr_bat, namzgr, zgr_zco, zgr_zps
599      USE closea,         ONLY: dom_clo
600      USE domain,         ONLY: dom_nam
601      USE iom,            ONLY: jpiglo, jpjglo, wp, jpdom_unknown, &
602                                iom_open, iom_get, iom_close
603      USE mapcomm_mod, ONLY: ielb, ieub, pielb, pjelb, pieub, pjeub, &
604                             iesub, jesub, jeub, ilbext, iubext, jubext, &
605                             jlbext, pnactive, piesub, pjesub, jelb, pilbext, &
606                             piubext, pjlbext, pjubext, LAND, msgtrim_z
607      USE partition_mod, ONLY: partition_rk, partition_mca_rk, &
608                               imask, ibotlevel, partition_mask_alloc, &
609                               smooth_global_bathy, global_bot_level
610      USE par_oce,       ONLY: do_exchanges
611#if defined key_mpp_mpi
612      USE mpi
613#endif
614      !!----------------------------------------------------------------------
615      !!                 ***  ROUTINE nemo_recursive_partition  ***
616      !!
617      !! ** Purpose : Work out a sensible factorisation of the number of
618      !!              processors for the x and y dimensions.
619      !! ** Method  :
620      !!----------------------------------------------------------------------
621      IMPLICIT none
622      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
623      ! Local vars
624      INTEGER :: ierr                          ! Error flag
625      INTEGER :: inum                          ! temporary logical unit
626      INTEGER :: ii,jj,iproc                   ! Loop index
627      INTEGER :: jparray(2)                    ! Small array for gathering
628      CHARACTER(LEN=8) :: lstr                 ! Local string for reading env. var.
629      INTEGER          :: lztrim               ! Local int for      "      "    "
630      REAL(wp), ALLOCATABLE, DIMENSION(:,:) :: zdta  ! temporary data workspace
631      !!----------------------------------------------------------------------
632
633      ! Allocate masking arrays used in partitioning
634      CALL partition_mask_alloc(jpiglo,jpjglo,ierr)
635      IF(ierr /= 0)THEN
636         CALL ctl_stop('nemo_recursive_partition: failed to allocate masking arrays')
637         RETURN
638      END IF
639
640      ! Allocate local workspace array for this routine
641      ALLOCATE(zdta(jpiglo,jpjglo), Stat=ierr)
642      IF(ierr /= 0)THEN
643         CALL ctl_stop('nemo_recursive_partition: failed to allocate workspace arrays')
644         RETURN
645      END IF
646
647      ! Check whether user has specified halo trimming in z via environment variable
648      ! Halo trimming in z is on by default
649      msgtrim_z = .TRUE.
650      CALL GET_ENVIRONMENT_VARIABLE(NAME='NEMO_MSGTRIM_Z', VALUE=lstr, STATUS=ierr)
651      IF( ierr == 0)THEN
652         READ(lstr,FMT="(I)",IOSTAT=ierr) lztrim
653         IF(ierr == 0)THEN
654            IF (lztrim == 0) msgtrim_z = .FALSE.
655         ELSE
656            CALL ctl_warn('nemo_recursive_partition: failed to parse value of NEMO_MSGTRIM_Z environment variable: '//TRIM(lstr))
657         END IF
658      END IF
659
660      WRITE(*,*) 'ARPDBG: msgtrim_z = ',msgtrim_z
661
662      ! Factorise the number of MPI PEs to get jpi and jpj as usual
663      CALL nemo_partition(num_pes)
664
665      ! ============================
666      ! Generate a global mask from the model bathymetry
667      ! ============================
668
669      ! Read the z-coordinate options from the namelist file
670      REWIND(numnam)
671      READ  (numnam, namzgr)
672
673      ! Read domain options from namelist file
674      CALL dom_nam()
675
676      ! Allocate these arrays so we can use domzgr::zgr_z routine; free them at
677      ! when we're done so as not to upset the 'official' allocation once
678      ! the domain decomposition is done.
679      ALLOCATE(gdepw_0(jpk), gdept_0(jpk), e3w_0(jpk), e3t_0(jpk), &
680               ! Need many global, 3D arrays if zgr_zco is to be called
681               !gdepw(jpiglo,jpjglo,jpk), gdept(jpiglo,jpjglo,jpk), &
682               !gdep3w(jpiglo,jpjglo,jpk), e3t(jpiglo,jpjglo,jpk),  &
683               mig(jpiglo), mjg(jpjglo), &
684               mbathy(jpiglo,jpjglo), bathy(jpiglo,jpjglo), Stat=ierr)
685      IF(ierr /= 0)THEN
686         CALL ctl_stop('nemo_recursive_partition: failed to allocate zgr_z() arrays')
687         RETURN
688      END IF
689
690      ! Set-up reference depth coordinates
691      CALL zgr_z()
692
693      ! Set-up sub-domain limits as global domain for zgr_bat()
694      nldi = 2 ; nlci = jpiglo - 1
695      nldj = 2 ; nlcj = jpjglo - 1
696      jpi = jpiglo
697      jpj = jpjglo
698
699      ! Set-up fake m{i,j}g arrays for zgr_bat() call
700      DO ii = 1, jpiglo, 1
701         mig(ii) = ii
702         mi0(ii) = ii
703         mi1(ii) = ii
704      END DO
705      DO jj = 1, jpjglo, 1
706         mjg(jj) = jj
707         mj0(jj) = jj
708         mj1(jj) = jj
709      END DO
710
711      ! Initialise closed seas so loop over closed seas in zgr_bat works
712      CALL dom_clo()
713
714      ! Read-in bathy (if required) of global domain
715      CALL zgr_bat(.TRUE.)
716
717      ! land/sea mask (zero on land, 1 otherwise) over the global/zoom domain
718      imask(:,:)=1
719
720      ! Copy bathymetry in case we need to smooth it
721      zdta(:,:) = bathy(:,:)
722
723      IF(ln_sco)THEN
724         ! If ln_sco defined then the bathymetry gets smoothed before the
725         ! simulation begins and that process can alter the coastlines (bug!)
726         ! therefore we do it here too before calculating our mask.
727         CALL smooth_global_bathy(zdta, mbathy)
728      ELSE IF(ln_zps)THEN
729         CALL zgr_zps(.TRUE.)
730      ELSE IF(ln_zco)THEN
731         ! Not certain this is required since mbathy computed in zgr_bat()
732         ! in this case.
733         !CALL zgr_zco()
734      END IF
735
736      ! Compute the deepest/last ocean level for every point on the grid
737      ibotlevel(:,:) = mbathy(:,:)
738      CALL global_bot_level(ibotlevel)
739
740      ! Comment-out line below to achieve a regular partition
741      WHERE ( zdta(:,:) <= 1.0E-20 ) imask = LAND
742
743      ! Allocate partitioning arrays.
744
745      IF ( .not.allocated(pielb) ) THEN
746         ALLOCATE (pielb(num_pes),   pieub(num_pes), piesub(num_pes),     &
747                   pilbext(num_pes), piubext(num_pes),                    &
748                   pjelb(num_pes),   pjeub(num_pes), pjesub(num_pes),     &
749                   pjlbext(num_pes), pjubext(num_pes), pnactive(num_pes), &
750                   Stat = ierr)
751         IF(ierr /= 0)THEN
752            CALL ctl_stop('STOP', &
753                          'nemo_recursive_partition: failed to allocate partitioning arrays')
754            RETURN
755         END IF
756      ENDIF
757
758      ! Now we can do recursive k-section partitioning
759      ! ARPDBG - BUG if limits on array below are set to anything other than
760      ! 1 and jp{i,j}glo then check for external boundaries in a few lines
761      ! time WILL FAIL!
762      !      CALL partition_rk ( imask, 1, jpiglo, 1, jpjglo, ierr )
763
764      ! Multi-core aware version of recursive k-section partitioning. Currently
765      ! only accounts for whether a grid point is wet or dry. It has no knowledge
766      ! of the number of wet levels at a point.
767      CALL partition_mca_rk ( imask, 1, jpiglo, 1, jpjglo, ierr )
768
769      ! Check the error code from partitioning.
770      IF ( ierr /= 0 ) THEN
771         CALL ctl_stop('STOP','nemo_recursive_partition: Partitioning failed')
772         RETURN
773      ENDIF
774
775      ! If we used generate_fake_land() above then we must set
776      ! the mask correctly now we've partitioned. This is only
777      ! necessary when testing.
778      !WHERE ( zdta(:,:) <= 0. ) imask = 0
779
780      ! ARPDBG Quick and dirty dump to stdout in gnuplot form
781      IF(narea == 1)THEN
782         OPEN(UNIT=998, FILE="imask.dat", &
783              STATUS='REPLACE', ACTION='WRITE', IOSTAT=jj)
784         IF( jj == 0 )THEN
785            WRITE (998,*) '# Depth map'
786            WRITE (998,*) '# i   j  bathy  imask   ibotlevel   mbathy'
787            DO jj = 1, jpjglo, 1
788               DO ii = 1, jpiglo, 1
789                  WRITE (998,"(I4,1x,I4,1x,E16.6,1x,I4,1x,I4,1x,I4)") &
790                  ii, jj, zdta(ii,jj), imask(ii,jj), ibotlevel(ii,jj), mbathy(ii,jj)
791               END DO
792               WRITE (998,*)
793            END DO
794            CLOSE(998)
795         END IF
796      END IF
797
798      jpkm1 = jpk - 1
799
800      ! This chunk taken directly from original mpp_ini - not sure why nbondi
801      ! is reset? However, if it isn't reset then bad things happen in dommsk
802      ! so I'm doing what the original code does...
803      nperio = 0
804      nbondi = 0
805      IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
806         IF( jpni == 1 )THEN
807            nbondi = 2
808            nperio = 1
809         END IF
810      END IF
811
812#if defined ARPDEBUG
813      ! This output is REQUIRED by the check_nemo_comms.pl test script
814      WRITE (*,FMT="(I4,' : ARPDBG: ielb, ieub, iesub = ',3I5)") narea-1,&
815            ielb, ieub, iesub
816      WRITE (*,FMT="(I4,' : ARPDBG: jelb, jeub, jesub = ',3I5)") narea-1,&
817            jelb, jeub, jesub
818      WRITE (*,FMT="(I4,' : ARPDBG: nldi, nlei, nlci = ',3I5)") narea-1, &
819            nldi, nlei, nlci
820      WRITE (*,FMT="(I4,' : ARPDBG: nldj, nlej, nlcj = ',3I5)") narea-1, &
821            nldj, nlej, nlcj
822      WRITE (*,FMT="(I4,' : ARPDBG: jpi, jpj = ',2I5)") narea-1, jpi, jpj
823      WRITE (*,FMT="(I4,' : ARPDBG: nimpp, njmpp = ',2I5)") narea-1, &
824            nimpp, njmpp
825#endif
826
827      ! Debugging option - can turn off all halo exchanges by setting this to
828      ! false.
829      do_exchanges = .TRUE.
830
831      ! Free the domzgr/_oce member arrays that we used earlier in zgr_z() and
832      ! zgr_bat().
833      DEALLOCATE(gdepw_0, gdept_0, e3w_0, e3t_0, mig, mjg,  &
834                 mbathy, bathy)
835
836   END SUBROUTINE nemo_recursive_partition
837
838
839   SUBROUTINE sqfact ( kn, kna, knb )
840      !!----------------------------------------------------------------------
841      !!                     ***  ROUTINE sqfact  ***
842      !!
843      !! ** Purpose :   return factors (kna, knb) of kn, such that
844      !!                (1) kna*knb=kn
845      !!                (2) kna and knb are as near equal as possible
846      !!                (3) kna < knb
847      !! ** Method  :   Search backwards from the square root of kn,
848      !!                until we find an integer that cleanly divides kn
849      !! ** Preconditions : kn must be positive
850      !!----------------------------------------------------------------------
851      INTEGER, INTENT(in   ) ::   kn
852      INTEGER, INTENT(  out) ::   kna, knb
853       
854      ! Search backwards from the square root of n.
855
856      fact_loop: DO kna=SQRT(REAL(kn)),1,-1
857         IF ( kn/kna*kna == kn ) THEN
858            EXIT fact_loop
859         ENDIF
860      END DO fact_loop
861
862      IF( kna < 1 ) kna = 1 
863
864      ! kna divides kn cleanly. Work out the other factor.
865      knb = kn/kna
866
867   END SUBROUTINE sqfact
868
869
870   SUBROUTINE generate_fake_land(imask)
871      !!----------------------------------------------------------------------
872      !! Generate a fake land mass to test the decomposition code
873      !!----------------------------------------------------------------------
874      USE par_oce, ONLY: jpiglo, jpjglo
875      USE partition_mod, ONLY: write_partition_map
876      IMPLICIT none
877      INTEGER, DIMENSION(jpiglo,jpjglo), INTENT(inout) :: imask
878      ! Locals
879      INTEGER :: ii, jj
880      INTEGER :: icentre, jcentre
881      INTEGER :: iwidth, iheight
882      INTEGER :: istart, istop
883
884      ! imask is zero on land points , unity on ocean points
885      iwidth = jpiglo/8
886      iheight = jpjglo/8
887
888      icentre = jpiglo/2
889      jcentre = jpjglo/2
890
891      istart = icentre - iwidth
892      istop = icentre + iwidth
893      DO jj = jcentre, jcentre - iheight, -1
894         imask(istart:istop,jj) = 0
895         istart = istart + 1
896         istop = istop - 1
897      END DO
898      istart = icentre - iwidth
899      istop = icentre + iwidth
900      DO jj = jcentre+1, jcentre + iheight, 1
901         imask(istart:istop,jj) = 0
902         istart = istart + 1
903         istop = istop - 1
904      END DO
905
906! Quick and dirty dump to stdout in gnuplot form
907!!$      WRITE (*,*) 'GNUPLOT MAP'
908!!$      DO jj = 1, jpjglo, 1
909!!$         DO ii = 1, jpiglo, 1
910!!$            WRITE (*,*) ii, jj, imask(ii,jj)
911!!$         END DO
912!!$         WRITE (*,*)
913!!$      END DO
914!!$      WRITE (*,*) 'END GNUPLOT MAP'
915
916   END SUBROUTINE generate_fake_land
917
918   !!======================================================================
919END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.