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 NEMO/branches/2019/dev_r11514_HPC-02_single-core-extrahalo/src/SAO – NEMO

source: NEMO/branches/2019/dev_r11514_HPC-02_single-core-extrahalo/src/SAO/nemogcm.F90 @ 11719

Last change on this file since 11719 was 11719, checked in by francesca, 5 years ago

add extra halo support- ticket #2009

  • Property svn:keywords set to Id
File size: 22.3 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 :  3.6  ! 2015-12  (A. Ryan) Original code   (from OCE/)
7   !!            4.0  ! 2016-11  (G. Madec, S. Flavoni)  domain configuration / user defined interface
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
12   !!   nemo_init     : initialization of the NEMO system
13   !!   nemo_ctl      : initialisation of the contol print
14   !!   nemo_closefile: close remaining open files
15   !!   nemo_alloc    : dynamical allocation
16   !!----------------------------------------------------------------------
17   USE step_oce       ! module used in the ocean time stepping module (step.F90)
18   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
19   USE istate         ! initial state setting          (istate_init routine)
20   USE phycst         ! physical constant                  (par_cst routine)
21   USE step           ! NEMO time-stepping                 (stp     routine)
22   USE cpl_oasis3     ! OASIS3 coupling
23   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
24#if defined key_nemocice_decomp
25   USE ice_domain_size, only: nx_global, ny_global
26#endif
27   !           ! Stand Alone Observation operator modules
28   USE sao_data
29   USE sao_intp
30   !
31   USE lib_mpp        ! distributed memory computing
32   USE mppini         ! shared/distributed memory setting (mpp_init routine)
33   USE lbcnfd  , ONLY : isendto, nsndto ! Setup of north fold exchanges
34   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
35#if defined key_iomput
36   USE xios           ! xIOserver
37#endif
38   USE halo_mng
39
40   IMPLICIT NONE
41   PRIVATE
42
43   PUBLIC   nemo_gcm    ! called by model.F90
44   PUBLIC   nemo_init   ! needed by AGRIF
45   PUBLIC   nemo_alloc  ! needed by TAM
46
47   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
48
49   !!----------------------------------------------------------------------
50   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
51   !! $Id$
52   !! Software governed by the CeCILL license (see ./LICENSE)
53   !!----------------------------------------------------------------------
54CONTAINS
55
56   SUBROUTINE nemo_gcm
57         !!----------------------------------------------------------------------
58         !!                    ***  SUBROUTINE offline_obs_oper ***
59         !!
60         !! ** Purpose : To use NEMO components to interpolate model fields
61         !!              to observation space.
62         !!
63         !! ** Method : 1. Initialise NEMO
64         !!             2. Initialise offline obs_oper
65         !!             3. Cycle through match ups
66         !!             4. Write results to file
67         !!----------------------------------------------------------------------
68         !
69         CALL nemo_init       ! Initialise NEMO
70         !
71         CALL sao_data_init   ! Initialise Stand Alone Observation operator data
72         !
73         CALL dia_obs_init    ! Initialise obs_operator
74         !
75         CALL sao_interp      ! Interpolate to observation space
76         !
77         CALL dia_obs_wri     ! Pipe to output files
78         !
79         CALL dia_obs_dealloc ! Reset the obs_oper between
80         !
81         IF(lk_mpp)   CALL mppstop  ! Safely stop MPI (end mpp communications)
82         !
83   END SUBROUTINE nemo_gcm
84
85
86   SUBROUTINE nemo_init
87      !!----------------------------------------------------------------------
88      !!                     ***  ROUTINE nemo_init  ***
89      !!
90      !! ** Purpose :   initialization of the NEMO GCM
91      !!----------------------------------------------------------------------
92      INTEGER ::   ios, ilocal_comm   ! local integer
93      !
94      NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
95         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
96         &             ln_timing, ln_diacfl
97      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
98      !!----------------------------------------------------------------------
99      !
100      cxios_context = 'nemo'
101      nn_hls = 1
102      !
103      !                             !-------------------------------------------------!
104      !                             !     set communicator & select the local rank    !
105      !                             !  must be done as soon as possible to get narea  !
106      !                             !-------------------------------------------------!
107      !
108#if defined key_iomput
109      IF( Agrif_Root() ) THEN
110         IF( lk_oasis ) THEN
111            CALL cpl_init( "oceanx", ilocal_comm )                               ! nemo local communicator given by oasis
112            CALL xios_initialize( "not used"       , local_comm =ilocal_comm )   ! send nemo communicator to xios
113         ELSE
114            CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
115         ENDIF
116      ENDIF
117      CALL mpp_start( ilocal_comm )
118#else
119      IF( lk_oasis ) THEN
120         IF( Agrif_Root() ) THEN
121            CALL cpl_init( "oceanx", ilocal_comm )          ! nemo local communicator given by oasis
122         ENDIF
123         CALL mpp_start( ilocal_comm )
124      ELSE
125         CALL mpp_start( )
126      ENDIF
127#endif
128      !
129      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
130      lwm = (narea == 1)                ! control of output namelists
131      !
132      !                             !---------------------------------------------------------------!
133      !                             ! Open output files, reference and configuration namelist files !
134      !                             !---------------------------------------------------------------!
135      !
136      ! open ocean.output as soon as possible to get all output prints (including errors messages)
137      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
138      ! open reference and configuration namelist files
139                  CALL ctl_opn( numnam_ref,        'namelist_ref',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
140                  CALL ctl_opn( numnam_cfg,        'namelist_cfg',     'OLD', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
141      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
142      ! open /dev/null file to be able to supress output write easily
143                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
144      !
145      !                             !--------------------!
146      !                             ! Open listing units !  -> need ln_ctl from namctl to define lwp
147      !                             !--------------------!
148      !
149      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
150      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
151901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
152      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
153      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
154902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
155      !
156      lwp = (narea == 1) .OR. ln_ctl    ! control of all listing output print
157      !
158      IF(lwp) THEN                      ! open listing units
159         !
160         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
161            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
162         !
163         WRITE(numout,*)
164         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
165         WRITE(numout,*) '                       NEMO team'
166         WRITE(numout,*) '            Stand Alone Observation operator'
167         WRITE(numout,*) '                NEMO version 4.0  (2019) '
168         WRITE(numout,*)
169         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
170         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
171         WRITE(numout,*)
172         WRITE(numout,*) "           o         _,           _,             "
173         WRITE(numout,*) "            o      .' (        .-' /             "
174         WRITE(numout,*) "           o     _/..._'.    .'   /              "
175         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
176         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
177         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
178         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
179         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
180         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
181         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
182         WRITE(numout,*)
183         !
184         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
185         !
186      ENDIF
187      !
188      ! finalize the definition of namctl variables
189      IF( sn_cfctl%l_config ) THEN
190         ! Activate finer control of report outputs
191         ! optionally switch off output from selected areas (note this only
192         ! applies to output which does not involve global communications)
193         IF( ( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax  ) .OR. &
194           & ( MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 ) )    &
195           &   CALL nemo_set_cfctl( sn_cfctl, .FALSE., .FALSE. )
196      ELSE
197         ! Use ln_ctl to turn on or off all options.
198         CALL nemo_set_cfctl( sn_cfctl, ln_ctl, .TRUE. )
199      ENDIF
200      !
201      IF(lwm) WRITE( numond, namctl )
202      !
203      !                             !------------------------------------!
204      !                             !  Set global domain size parameters !
205      !                             !------------------------------------!
206      !
207      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
208      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
209903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
210      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
211      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
212904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
213      !
214      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
215         CALL domain_cfg ( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
216      ELSE                              ! user-defined namelist
217         CALL usr_def_nam( cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
218      ENDIF
219      !
220      IF(lwm)   WRITE( numond, namcfg )
221      !
222      !                             !-----------------------------------------!
223      !                             ! mpp parameters and domain decomposition !
224      !                             !-----------------------------------------!
225      CALL mpp_init
226
227      CALL halo_mng_init()
228      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
229      CALL nemo_alloc()
230
231      !                             !-------------------------------!
232      !                             !  NEMO general initialization  !
233      !                             !-------------------------------!
234
235      CALL nemo_ctl                          ! Control prints
236      !
237      !                                         ! General initialization
238      IF( ln_timing    )   CALL timing_init     ! timing
239      IF( ln_timing    )   CALL timing_start( 'nemo_init')
240      !
241                           CALL phy_cst            ! Physical constants
242                           CALL eos_init           ! Equation of state
243                           CALL dom_init('SAO')    ! Domain
244
245
246      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control
247
248                           CALL istate_init     ! ocean initial state (Dynamics and tracers)
249   END SUBROUTINE nemo_init
250
251
252   SUBROUTINE nemo_ctl
253      !!----------------------------------------------------------------------
254      !!                     ***  ROUTINE nemo_ctl  ***
255      !!
256      !! ** Purpose :   control print setting
257      !!
258      !! ** Method  : - print namctl information and check some consistencies
259      !!----------------------------------------------------------------------
260      !
261      IF(lwp) THEN                  ! control print
262         WRITE(numout,*)
263         WRITE(numout,*) 'nemo_ctl: Control prints'
264         WRITE(numout,*) '~~~~~~~~'
265         WRITE(numout,*) '   Namelist namctl'
266         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
267         WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
268         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
269         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
270         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
271         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
272         WRITE(numout,*) '                              sn_cfctl%l_mppout  = ', sn_cfctl%l_mppout
273         WRITE(numout,*) '                              sn_cfctl%l_mpptop  = ', sn_cfctl%l_mpptop
274         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
275         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
276         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
277         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
278         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
279         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
280         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
281         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
282         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
283         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
284         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
285         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
286         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
287      ENDIF
288      !
289      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
290      nictls    = nn_ictls
291      nictle    = nn_ictle
292      njctls    = nn_jctls
293      njctle    = nn_jctle
294      isplt     = nn_isplt
295      jsplt     = nn_jsplt
296
297      IF(lwp) THEN                  ! control print
298         WRITE(numout,*)
299         WRITE(numout,*) '   Namelist namcfg'
300         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
301         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
302         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
303         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
304         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
305         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
306      ENDIF
307      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
308      !
309      !                             ! Parameter control
310      !
311      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
312         IF( lk_mpp .AND. jpnij > 1 ) THEN
313            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
314         ELSE
315            IF( isplt == 1 .AND. jsplt == 1  ) THEN
316               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
317                  &           ' - the print control will be done over the whole domain' )
318            ENDIF
319            ijsplt = isplt * jsplt            ! total number of processors ijsplt
320         ENDIF
321         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
322         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
323         !
324         !                              ! indices used for the SUM control
325         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
326            lsp_area = .FALSE.
327         ELSE                                             ! print control done over a specific  area
328            lsp_area = .TRUE.
329            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
330               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
331               nictls = 1
332            ENDIF
333            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
334               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
335               nictle = jpiglo
336            ENDIF
337            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
338               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
339               njctls = 1
340            ENDIF
341            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
342               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
343               njctle = jpjglo
344            ENDIF
345         ENDIF
346      ENDIF
347      !
348      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
349         &                                                'Compile with key_nosignedzero enabled:',   &
350         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
351      !
352   END SUBROUTINE nemo_ctl
353
354
355   SUBROUTINE nemo_closefile
356      !!----------------------------------------------------------------------
357      !!                     ***  ROUTINE nemo_closefile  ***
358      !!
359      !! ** Purpose :   Close the files
360      !!----------------------------------------------------------------------
361      !
362      IF( lk_mpp )   CALL mppsync
363      !
364      CALL iom_close                                 ! close all input/output files managed by iom_*
365      !
366      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
367      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
368      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
369      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
370      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
371      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
372      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
373      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
374      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
375      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
376      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
377      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
378      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
379      !
380      numout = 6                                     ! redefine numout in case it is used after this point...
381      !
382   END SUBROUTINE nemo_closefile
383
384
385   SUBROUTINE nemo_alloc
386      !!----------------------------------------------------------------------
387      !!                     ***  ROUTINE nemo_alloc  ***
388      !!
389      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
390      !!
391      !! ** Method  :
392      !!----------------------------------------------------------------------
393      USE diawri    , ONLY: dia_wri_alloc
394      USE dom_oce   , ONLY: dom_oce_alloc
395      !
396      INTEGER :: ierr
397      !!----------------------------------------------------------------------
398      !
399      ierr =        oce_alloc       ()          ! ocean
400      ierr = ierr + dia_wri_alloc   ()
401      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
402      !
403      CALL mpp_sum( 'nemogcm', ierr )
404      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
405      !
406   END SUBROUTINE nemo_alloc
407
408   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto, for_all )
409      !!----------------------------------------------------------------------
410      !!                     ***  ROUTINE nemo_set_cfctl  ***
411      !!
412      !! ** Purpose :   Set elements of the output control structure to setto.
413      !!                for_all should be .false. unless all areas are to be
414      !!                treated identically.
415      !!
416      !! ** Method  :   Note this routine can be used to switch on/off some
417      !!                types of output for selected areas but any output types
418      !!                that involve global communications (e.g. mpp_max, glob_sum)
419      !!                should be protected from selective switching by the
420      !!                for_all argument
421      !!----------------------------------------------------------------------
422      LOGICAL :: setto, for_all
423      TYPE(sn_ctl) :: sn_cfctl
424      !!----------------------------------------------------------------------
425      IF( for_all ) THEN
426         sn_cfctl%l_runstat = setto
427         sn_cfctl%l_trcstat = setto
428      ENDIF
429      sn_cfctl%l_oceout  = setto
430      sn_cfctl%l_layout  = setto
431      sn_cfctl%l_mppout  = setto
432      sn_cfctl%l_mpptop  = setto
433   END SUBROUTINE nemo_set_cfctl
434
435   !!======================================================================
436END MODULE nemogcm
437
Note: See TracBrowser for help on using the repository browser.