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/trunk/src/SWE – NEMO

source: NEMO/trunk/src/SWE/nemogcm.F90 @ 14903

Last change on this file since 14903 was 14834, checked in by hadcv, 3 years ago

#2600: Merge in dev_r14273_HPC-02_Daley_Tiling

File size: 22.6 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 :  4.0  !  2020-05  (A. Nasser, G. Madec)  Original code from 4.0.2
7   !!             -   !  2020-10  (S. Techene, G. Madec)  cleanning
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   !
19   USE phycst         ! physical constant                  (par_cst routine)
20   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
21   USE usrdef_nam     ! user defined configuration
22   USE bdyini         ! open boundary cond. setting       (bdy_init routine)
23   USE istate         ! initial state setting          (istate_init routine)
24   USE trd_oce , ONLY : l_trddyn         ! dynamical trend logical
25#if defined key_RK3
26   USE stprk3         ! NEMO time-stepping               (stp_RK3   routine)
27#else
28   USE stpmlf         ! NEMO time-stepping               (stp_MLF   routine)
29#endif
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   USE halo_mng       ! halo manager
36
37   IMPLICIT NONE
38   PRIVATE
39
40   PUBLIC   nemo_gcm    ! called by model.F90
41   PUBLIC   nemo_init   ! needed by AGRIF
42   PUBLIC   nemo_alloc  ! needed by TAM
43
44   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
45
46#if ! defined key_mpi_off
47   ! need MPI_Wtime
48   INCLUDE 'mpif.h'
49#endif
50
51   !!----------------------------------------------------------------------
52   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
53   !! $Id: nemogcm.F90 12614 2020-03-26 14:59:52Z gm $
54   !! Software governed by the CeCILL license (see ./LICENSE)
55   !!----------------------------------------------------------------------
56CONTAINS
57
58   SUBROUTINE nemo_gcm
59      !!----------------------------------------------------------------------
60      !!                     ***  ROUTINE nemo_gcm  ***
61      !!
62      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
63      !!              curvilinear mesh on the sphere.
64      !!
65      !! ** Method  : - model general initialization
66      !!              - launch the time-stepping (stp routine)
67      !!              - finalize the run by closing files and communications
68      !!
69      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
70      !!              Madec, 2008, internal report, IPSL.
71      !!----------------------------------------------------------------------
72      INTEGER ::   istp   ! time step index
73      REAL(wp)::   zstptiming   ! elapsed time for 1 time step
74      !!----------------------------------------------------------------------
75      !
76      !                            !-----------------------!
77      CALL nemo_init               !==  Initialisations  ==!
78      !                            !-----------------------!
79      ! check that all process are still there... If some process have an error,
80      ! they will never enter in step and other processes will wait until the end of the cpu time!
81      !
82      !                                 ! SWE case: only with key_qco
83#if ! defined key_qco 
84      CALL ctl_stop( 'nemo_gcm (SWE): shallow water model requires key_qco' )
85#endif
86      !
87      CALL mpp_max( 'nemogcm', nstop )
88
89      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
90
91      !                            !-----------------------!
92      !                            !==   time stepping   ==!
93      !                            !-----------------------!
94      !
95      !                                               !== set the model time-step  ==!
96      !
97      istp = nit000
98      !
99      !                                               !==  Standard time-stepping  ==!
100      !
101      DO WHILE( istp <= nitend .AND. nstop == 0 )
102         !
103         ncom_stp = istp
104         IF( ln_timing ) THEN
105            zstptiming = MPI_Wtime()
106            IF ( istp == ( nit000 + 1 ) ) elapsed_time = zstptiming
107            IF ( istp ==         nitend ) elapsed_time = zstptiming - elapsed_time
108         ENDIF
109         !
110#if defined key_RK3
111         CALL stp_RK3    ( istp )
112#else
113         CALL stp_MLF     ( istp )
114#endif
115         istp = istp + 1
116         !
117         IF( lwp .AND. ln_timing )   WRITE(numtime,*) 'timing step ', istp-1, ' : ', MPI_Wtime() - zstptiming
118         !
119      END DO
120      !
121      !
122      !                            !------------------------!
123      !                            !==  finalize the run  ==!
124      !                            !------------------------!
125      IF(lwp) WRITE(numout,cform_aaa)        ! Flag AAAAAAA
126      !
127      IF( nstop /= 0 .AND. lwp ) THEN        ! error print
128         WRITE(ctmp1,*) '   ==>>>   nemo_gcm: a total of ', nstop, ' errors have been found'
129         WRITE(ctmp2,*) '           Look for "E R R O R" messages in all existing ocean_output* files'
130         CALL ctl_stop( ' ', ctmp1, ' ', ctmp2 )
131      ENDIF
132      !
133      IF( ln_timing )   CALL timing_finalize
134      !
135      CALL nemo_closefile
136      !
137#if defined key_xios
138                       CALL xios_finalize  ! end mpp communications with xios
139#else
140      IF( lk_mpp   )   CALL mppstop      ! end mpp communications
141#endif
142      !
143      IF(lwm) THEN
144         IF( nstop == 0 ) THEN   ;   STOP 0
145         ELSE                    ;   STOP 123
146         ENDIF
147      ENDIF
148      !
149   END SUBROUTINE nemo_gcm
150
151
152   SUBROUTINE nemo_init
153      !!----------------------------------------------------------------------
154      !!                     ***  ROUTINE nemo_init  ***
155      !!
156      !! ** Purpose :   initialization of the NEMO GCM
157      !!----------------------------------------------------------------------
158      INTEGER ::   ios, ilocal_comm   ! local integers
159      !!
160      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl, nn_isplt, nn_jsplt , nn_ictls,   &
161         &                                             nn_ictle, nn_jctls , nn_jctle
162      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
163      !!----------------------------------------------------------------------
164      !
165      cxios_context = 'nemo'
166      !
167      !                             !-------------------------------------------------!
168      !                             !     set communicator & select the local rank    !
169      !                             !  must be done as soon as possible to get narea  !
170      !                             !-------------------------------------------------!
171      !
172#if defined key_xios
173      CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
174      CALL mpp_start( ilocal_comm )
175#else
176      CALL mpp_start( )
177#endif
178      !
179      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
180      lwm = (narea == 1)                ! control of output namelists
181      !
182      !                             !---------------------------------------------------------------!
183      !                             ! Open output files, reference and configuration namelist files !
184      !                             !---------------------------------------------------------------!
185      !
186      ! open ocean.output as soon as possible to get all output prints (including errors messages)
187      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
188      ! open reference and configuration namelist files
189                  CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
190                  CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
191      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
192      ! open /dev/null file to be able to supress output write easily
193                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
194      !
195      !                             !--------------------!
196      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
197      !                             !--------------------!
198      !
199      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
200901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
201      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
202902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
203      !
204      ! finalize the definition of namctl variables
205      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
206         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
207      !
208      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
209      !
210      IF(lwp) THEN                      ! open listing units
211         !
212         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
213            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
214         !
215         WRITE(numout,*)
216         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
217         WRITE(numout,*) '                       NEMO team'
218         WRITE(numout,*) '            Ocean General Circulation Model'
219         WRITE(numout,*) '                NEMO version 4.0  (2020) '
220         WRITE(numout,*)
221         WRITE(numout,*) '                 Shallow Water Equation'
222         WRITE(numout,*) '                 ======================'
223         WRITE(numout,*)
224         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
225         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
226         WRITE(numout,*)
227         WRITE(numout,*) "           o         _,           _,             "
228         WRITE(numout,*) "            o      .' (        .-' /             "
229         WRITE(numout,*) "           o     _/..._'.    .'   /              "
230         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
231         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
232         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
233         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
234         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
235         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
236         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
237         WRITE(numout,*)
238         !
239         WRITE(numout,cform_aaa)    ! Flag AAAAAAA
240         !
241         !                          ! Control print of the working precision
242         WRITE(numout,*)
243         IF( wp == dp ) THEN   ;   WRITE(numout,*) "par_kind : wp = Working precision = dp = double-precision"
244         ELSE                  ;   WRITE(numout,*) "par_kind : wp = Working precision = sp = single-precision"
245         ENDIF
246                                   WRITE(numout,*) "~~~~~~~~                                 ****************"
247                                   WRITE(numout,*)
248         !
249      ENDIF
250      !
251      IF(lwm) WRITE( numond, namctl )
252      !
253      !                             !------------------------------------!
254      !                             !  Set global domain size parameters !
255      !                             !------------------------------------!
256      !
257      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
258903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
259      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
260904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
261      !
262      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
263         CALL domain_cfg ( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, l_Iperio, l_Jperio, l_NFold, c_NFtype )
264      ELSE                              ! user-defined namelist
265         CALL usr_def_nam( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, l_Iperio, l_Jperio, l_NFold, c_NFtype )
266      ENDIF
267      !
268      IF(lwm)   WRITE( numond, namcfg )
269      !
270      !                             !-----------------------------------------!
271      !                             ! mpp parameters and domain decomposition !
272      !                             !-----------------------------------------!
273      CALL mpp_init
274
275#if defined key_loop_fusion
276      IF( nn_hls == 1 ) THEN
277         CALL ctl_stop( 'STOP', 'nemogcm : Loop fusion can be used only with extra-halo' )
278      ENDIF
279#endif
280
281      CALL halo_mng_init()
282      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
283      CALL nemo_alloc()
284
285      ! Initialise time level indices
286      Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
287     
288      !                             !-------------------------------!
289      !                             !  NEMO general initialization  !
290      !                             !-------------------------------!
291
292      CALL nemo_ctl                          ! Control prints of namctl and namcfg
293      !
294      !                                      ! General initialization
295      IF( ln_timing    )   CALL timing_init     ! timing
296      IF( ln_timing    )   CALL timing_start( 'nemo_init')
297      !
298                           CALL     phy_cst         ! Physical constants
299      !
300      !                                             ! SWE: Set rho0 and associated variables (eosbn2 not used)
301                           rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
302                           rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
303                           rho0_rcp    = rho0 * rcp 
304                           r1_rho0     = 1._wp / rho0
305                           r1_rcp      = 1._wp / rcp
306                           r1_rho0_rcp = 1._wp / rho0_rcp 
307      !
308                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
309
310      IF( sn_cfctl%l_prtctl )   &
311         &                 CALL prt_ctl_init        ! Print control
312
313                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
314
315      !                                      ! external forcing
316                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
317
318      !                                      ! Ocean physics                                   
319      !                                         ! Lateral physics
320                           CALL ldf_dyn_init      ! Lateral ocean momentum physics
321                           
322      !                                      ! Dynamics
323                           CALL dyn_adv_init         ! advection (vector or flux form)
324                           CALL dyn_vor_init         ! vorticity term including Coriolis
325                           CALL dyn_ldf_init         ! lateral mixing
326
327      !                                      ! Diagnostics
328      IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
329      !                                         ! Trends diag: switched off
330                           l_trddyn = .FALSE.        ! No trend diagnostics
331
332      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
333      !
334      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
335      !
336   END SUBROUTINE nemo_init
337
338
339   SUBROUTINE nemo_ctl
340      !!----------------------------------------------------------------------
341      !!                     ***  ROUTINE nemo_ctl  ***
342      !!
343      !! ** Purpose :   control print setting
344      !!
345      !! ** Method  : - print namctl and namcfg information and check some consistencies
346      !!----------------------------------------------------------------------
347      !
348      IF(lwp) THEN                  ! control print
349         WRITE(numout,*)
350         WRITE(numout,*) 'nemo_ctl: Control prints'
351         WRITE(numout,*) '~~~~~~~~'
352         WRITE(numout,*) '   Namelist namctl'
353         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
354         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
355         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
356         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
357         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
358         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
359         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
360         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
361         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
362         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
363         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
364         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
365         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
366      ENDIF
367      !
368      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
369      IF(lwp) THEN                  ! control print
370         WRITE(numout,*)
371         WRITE(numout,*) '   Namelist namcfg'
372         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
373         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
374         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
375         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
376         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
377         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
378      ENDIF
379      !
380      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
381         &                                                'Compile with key_nosignedzero enabled:',   &
382         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
383      !
384#if defined key_agrif
385      IF( ln_timing )   CALL ctl_stop( 'AGRIF not implemented with ln_timing = true')
386#endif
387      !
388   END SUBROUTINE nemo_ctl
389
390
391   SUBROUTINE nemo_closefile
392      !!----------------------------------------------------------------------
393      !!                     ***  ROUTINE nemo_closefile  ***
394      !!
395      !! ** Purpose :   Close the files
396      !!----------------------------------------------------------------------
397      !
398      IF( lk_mpp )   CALL mppsync
399      !
400      CALL iom_close                                 ! close all input/output files managed by iom_*
401      !
402      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
403      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
404      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
405      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
406      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
407      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
408      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
409      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
410      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
411      !
412      numout = 6                                     ! redefine numout in case it is used after this point...
413      !
414   END SUBROUTINE nemo_closefile
415
416
417   SUBROUTINE nemo_alloc
418      !!----------------------------------------------------------------------
419      !!                     ***  ROUTINE nemo_alloc  ***
420      !!
421      !! ** Purpose :   Allocate all the dynamic arrays of the OCE modules
422      !!
423      !! ** Method  :
424      !!----------------------------------------------------------------------
425      USE diawri    , ONLY : dia_wri_alloc
426      USE dom_oce   , ONLY : dom_oce_alloc
427      !
428      INTEGER :: ierr
429      !!----------------------------------------------------------------------
430      !
431      ierr =        oce_SWE_alloc()    ! ocean
432      ierr = ierr + dia_wri_alloc()
433      ierr = ierr + dom_oce_alloc()    ! ocean domain
434      ierr = ierr + zdf_oce_alloc()    ! ocean vertical physics
435      !
436      CALL mpp_sum( 'nemogcm', ierr )
437      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
438      !
439   END SUBROUTINE nemo_alloc
440
441
442   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
443      !!----------------------------------------------------------------------
444      !!                     ***  ROUTINE nemo_set_cfctl  ***
445      !!
446      !! ** Purpose :   Set elements of the output control structure to setto.
447      !!
448      !! ** Method  :   Note this routine can be used to switch on/off some
449      !!                types of output for selected areas.
450      !!----------------------------------------------------------------------
451      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
452      LOGICAL     , INTENT(in   ) :: setto
453      !!----------------------------------------------------------------------
454      sn_cfctl%l_runstat = setto
455      sn_cfctl%l_trcstat = setto
456      sn_cfctl%l_oceout  = setto
457      sn_cfctl%l_layout  = setto
458      sn_cfctl%l_prtctl  = setto
459      sn_cfctl%l_prttrc  = setto
460      sn_cfctl%l_oasout  = setto
461   END SUBROUTINE nemo_set_cfctl
462
463   !!======================================================================
464END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.