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 utils/tools_ticket2457/DOMAINcfg/src – NEMO

source: utils/tools_ticket2457/DOMAINcfg/src/nemogcm.F90 @ 12871

Last change on this file since 12871 was 12414, checked in by smueller, 4 years ago

Reintegration of 2019 development branch /utils/tools_MERGE_2019 into the tools directory (/utils/tools)

File size: 21.7 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   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_northcomms
31   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE
32   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
33   !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication
34   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla)
35   !!----------------------------------------------------------------------
36
37   !!----------------------------------------------------------------------
38   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
39   !!   nemo_init     : initialization of the NEMO system
40   !!   nemo_ctl      : initialisation of the contol print
41   !!   nemo_closefile: close remaining open files
42   !!   nemo_alloc    : dynamical allocation
43   !!   nemo_partition: calculate MPP domain decomposition
44   !!   factorise     : calculate the factors of the no. of MPI processes
45   !!----------------------------------------------------------------------
46   USE dom_oce        ! ocean space and time domain variables
47   USE in_out_manager ! I/O manager
48   USE iom            !
49   USE domcfg         ! domain configuration               (dom_cfg routine)
50   USE mppini         ! shared/distributed memory setting (mpp_init routine)
51   USE domain         ! domain initialization             (dom_init routine)
52   USE phycst         ! physical constant                  (par_cst routine)
53   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
54   USE lib_mpp        ! distributed memory computing
55
56   USE lbcnfd , ONLY  : isendto, nsndto, nfsloop, nfeloop   ! Setup of north fold exchanges
57
58   IMPLICIT NONE
59   PRIVATE
60
61   PUBLIC   nemo_gcm    ! called by model.F90
62   PUBLIC   nemo_init   ! needed by AGRIF
63   PUBLIC   nemo_alloc  ! needed by TAM
64
65   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
66   
67#if defined key_agrif 
68   external agrif_boundary_connections, agrif_update_all, agrif_recompute_scalefactors
69#endif
70
71   !!----------------------------------------------------------------------
72   !! NEMO/OPA 3.7 , NEMO Consortium (2015)
73   !! $Id: nemogcm.F90 6152 2015-12-21 22:33:57Z acc $
74   !! Software governed by the CeCILL licence     (./LICENSE)
75   !!----------------------------------------------------------------------
76CONTAINS
77
78   SUBROUTINE nemo_gcm
79      !!----------------------------------------------------------------------
80      !!                     ***  ROUTINE nemo_gcm  ***
81      !!
82      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
83      !!              curvilinear mesh on the sphere.
84      !!
85      !! ** Method  : - model general initialization
86      !!              - launch the time-stepping (stp routine)
87      !!              - finalize the run by closing files and communications
88      !!
89      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
90      !!              Madec, 2008, internal report, IPSL.
91      !!----------------------------------------------------------------------
92      INTEGER ::   istp       ! time step index
93      !!----------------------------------------------------------------------
94      !
95#if defined key_agrif
96      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
97#endif
98      !                            !-----------------------!
99      CALL nemo_init               !==  Initialisations  ==!
100      !                            !-----------------------!
101
102#if defined key_agrif   
103      CALL Agrif_Regrid()
104     
105      CALL Agrif_Step_Child(agrif_boundary_connections)
106     
107      CALL Agrif_Step_Child_adj(agrif_update_all)
108     
109      CALL Agrif_Step_Child(agrif_recompute_scalefactors)
110     
111      CALL Agrif_Step_Child(cfg_write)
112#endif
113
114      ! check that all process are still there... If some process have an error,
115      ! they will never enter in step and other processes will wait until the end of the cpu time!
116      IF( lk_mpp )   CALL mpp_max( 'nemogcm',nstop )
117
118      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
119
120      !                            !-----------------------!
121      !                            !==  finalize the run  ==!
122      !                            !------------------------!
123      !
124      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
125         WRITE(numout,cform_err)
126         WRITE(numout,*) nstop, ' error have been found'
127      ENDIF
128      !
129      !
130      CALL nemo_closefile
131      !
132      !
133   END SUBROUTINE nemo_gcm
134
135
136   SUBROUTINE nemo_init
137      !!----------------------------------------------------------------------
138      !!                     ***  ROUTINE nemo_init  ***
139      !!
140      !! ** Purpose :   initialization of the NEMO GCM
141      !!----------------------------------------------------------------------
142      INTEGER  ::   ji                 ! dummy loop indices
143      INTEGER  ::   ios, ilocal_comm   ! local integers
144      CHARACTER(len=120), DIMENSION(60) ::   cltxt, cltxt2, clnam
145      !!
146      NAMELIST/namctl/ ln_ctl   , sn_cfctl, nn_print, nn_ictls, nn_ictle,   &
147         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,             &
148         &             ln_timing, ln_diacfl
149      NAMELIST/namcfg/ ln_e3_dep,                                &
150         &             cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
151         &             jperio, ln_use_jattr, ln_domclo
152      !!----------------------------------------------------------------------
153      !
154      cltxt = ''
155      !
156      !                             ! Open reference namelist and configuration namelist files
157      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
158      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
159      !
160      REWIND( numnam_ref )              ! Namelist namctl in reference namelist
161      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
162901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
163      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
164      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
165902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
166      !
167      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist
168      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
169903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
170      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist
171      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
172904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
173
174! Force values for AGRIF zoom (cf. agrif_user.F90)
175      !
176      !                             !--------------------------------------------!
177      !                             !  set communicator & select the local node  !
178      !                             !  NB: mynode also opens output.namelist.dyn !
179      !                             !      on unit number numond on first proc   !
180      !                             !--------------------------------------------!
181      ! Nodes selection (control print return in cltxt)
182      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
183      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
184
185      lwm = (narea == 1)                                    ! control of output namelists
186      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
187
188      IF(lwm) THEN
189         ! write merged namelists from earlier to output namelist now that the
190         ! file has been opened in call to mynode. nammpp has already been
191         ! written in mynode (if lk_mpp_mpi)
192         WRITE( numond, namctl )
193         WRITE( numond, namcfg )
194      ENDIF
195
196        IF(lwp) THEN                            ! open listing units
197         !
198         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
199         !
200         WRITE(numout,*)
201         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
202         WRITE(numout,*) '                       NEMO team'
203         WRITE(numout,*) '            Ocean General Circulation Model'
204         WRITE(numout,*) '                NEMO version 4.0  (2019) '
205         WRITE(numout,*)
206         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
207         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
208         WRITE(numout,*)
209         WRITE(numout,*) "           o         _,           _,             "
210         WRITE(numout,*) "            o      .' (        .-' /             "
211         WRITE(numout,*) "           o     _/..._'.    .'   /              "
212         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
213         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
214         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
215         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
216         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
217         WRITE(numout,*) "       )  )                        `     (   (   "
218         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
219         WRITE(numout,*)
220         
221         DO ji = 1, SIZE(cltxt)
222            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) TRIM(cltxt(ji))    ! control print of mynode
223         END DO
224         WRITE(numout,*)
225         WRITE(numout,*)
226   !      DO ji = 1, SIZE(cltxt2)
227   !         IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) TRIM(cltxt2(ji))   ! control print of domain size
228   !      END DO
229         !
230         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
231         !
232      ENDIF
233      ! open /dev/null file to be able to supress output write easily
234   !   CALL ctl_opn( numnul, '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
235      !
236      !                                      ! Domain decomposition
237      CALL mpp_init                          ! MPP
238
239 !    IF( Agrif_Root() ) THEN
240 !        jpi = ( jpiglo     -2*jpreci + (jpni-1) ) / jpni + 2*jpreci    ! first  dim.
241 !        jpj = ( jpjglo     -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj    ! second dim.
242 !     ENDIF
243         jpk = jpkdta                                             ! third dim
244         jpim1 = jpi-1                                            ! inner domain indices
245         jpjm1 = jpj-1                                            !   "           "
246         jpkm1 = jpk-1                                            !   "           "
247         jpij  = jpi*jpj                                          !  jpi x j
248
249#if defined key_agrif
250      CALL Agrif_Declare_Var
251#endif
252
253      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
254      CALL nemo_alloc()
255
256      !                             !-------------------------------!
257      !                             !  NEMO general initialization  !
258      !                             !-------------------------------!
259
260      CALL nemo_ctl                          ! Control prints & Benchmark
261
262      !                                      ! Domain decomposition
263        !
264      !                                      ! General initialization
265                            CALL     phy_cst    ! Physical constants
266                            CALL     dom_cfg    ! Domain configuration
267                            CALL     dom_init   ! Domain
268      !
269   END SUBROUTINE nemo_init
270
271
272   SUBROUTINE nemo_ctl
273      !!----------------------------------------------------------------------
274      !!                     ***  ROUTINE nemo_ctl  ***
275      !!
276      !! ** Purpose :   control print setting
277      !!
278      !! ** Method  : - print namctl information and check some consistencies
279      !!----------------------------------------------------------------------
280      !
281      IF(lwp) THEN                  ! control print
282         WRITE(numout,*)
283         WRITE(numout,*) 'nemo_ctl: Control prints'
284         WRITE(numout,*) '~~~~~~~~'
285         WRITE(numout,*) '   Namelist namctl'
286         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
287         WRITE(numout,*) '       finer control over o/p sn_cfctl%l_config  = ', sn_cfctl%l_config
288         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
289         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
290         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
291         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
292         WRITE(numout,*) '                              sn_cfctl%l_mppout  = ', sn_cfctl%l_mppout
293         WRITE(numout,*) '                              sn_cfctl%l_mpptop  = ', sn_cfctl%l_mpptop
294         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
295         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
296         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
297         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
298         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
299         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
300         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
301         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
302         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
303         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
304         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
305         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
306         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
307      ENDIF
308      !
309      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
310      nictls    = nn_ictls
311      nictle    = nn_ictle
312      njctls    = nn_jctls
313      njctle    = nn_jctle
314      isplt     = nn_isplt
315      jsplt     = nn_jsplt
316
317      !
318      !                             ! Parameter control
319      !
320      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
321         IF( lk_mpp .AND. jpnij > 1 ) THEN
322            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
323         ELSE
324            IF( isplt == 1 .AND. jsplt == 1  ) THEN
325               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
326                  &           ' - the print control will be done over the whole domain' )
327            ENDIF
328            ijsplt = isplt * jsplt            ! total number of processors ijsplt
329         ENDIF
330         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
331         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
332         !
333         !                              ! indices used for the SUM control
334         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
335            lsp_area = .FALSE.
336         ELSE                                             ! print control done over a specific  area
337            lsp_area = .TRUE.
338            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
339               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
340               nictls = 1
341            ENDIF
342            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
343               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
344               nictle = jpiglo
345            ENDIF
346            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
347               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
348               njctls = 1
349            ENDIF
350            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
351               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
352               njctle = jpjglo
353            ENDIF
354         ENDIF
355      ENDIF
356      !
357!      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
358!         &                                                'Compile with key_nosignedzero enabled:',   &
359!         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
360      !
361#if defined key_agrif
362      IF( ln_timing )   CALL ctl_stop( 'AGRIF not implemented with ln_timing = true')
363#endif
364      !
365   END SUBROUTINE nemo_ctl
366
367
368   SUBROUTINE nemo_closefile
369      !!----------------------------------------------------------------------
370      !!                     ***  ROUTINE nemo_closefile  ***
371      !!
372      !! ** Purpose :   Close the files
373      !!----------------------------------------------------------------------
374      !
375      IF( lk_mpp )   CALL mppsync
376      !
377      CALL iom_close                                 ! close all input/output files managed by iom_*
378      !
379      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
380      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
381      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
382      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
383      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
384      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
385      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
386      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
387      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
388      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
389      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
390      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
391      !
392      numout = 6                                     ! redefine numout in case it is used after this point...
393      !
394   END SUBROUTINE nemo_closefile
395
396
397   SUBROUTINE nemo_alloc
398      !!----------------------------------------------------------------------
399      !!                     ***  ROUTINE nemo_alloc  ***
400      !!
401      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
402      !!
403      !! ** Method  :
404      !!----------------------------------------------------------------------
405      USE dom_oce   , ONLY: dom_oce_alloc
406      !
407      INTEGER :: ierr
408      !!----------------------------------------------------------------------
409      !
410      ierr = dom_oce_alloc   ()          ! ocean domain
411      !
412      CALL mpp_sum( 'nemogcm', ierr )
413      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
414      !
415   END SUBROUTINE nemo_alloc
416
417
418
419   !!======================================================================
420END MODULE nemogcm
421
Note: See TracBrowser for help on using the repository browser.