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/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE – NEMO

source: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/SWE/nemogcm.F90 @ 13708

Last change on this file since 13708 was 13708, checked in by techene, 3 years ago

#2485 clean and update shallow water specific routines accordingly to qco AGRIF changes

File size: 21.9 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_mpp_mpi
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         CALL ctl_stop( ctmp1 )
130      ENDIF
131      !
132      IF( ln_timing )   CALL timing_finalize
133      !
134      CALL nemo_closefile
135      !
136#if defined key_iomput
137                       CALL xios_finalize  ! end mpp communications with xios
138#else
139      IF( lk_mpp   )   CALL mppstop      ! end mpp communications
140#endif
141      !
142      IF(lwm) THEN
143         IF( nstop == 0 ) THEN   ;   STOP 0
144         ELSE                    ;   STOP 123
145         ENDIF
146      ENDIF
147      !
148   END SUBROUTINE nemo_gcm
149
150
151   SUBROUTINE nemo_init
152      !!----------------------------------------------------------------------
153      !!                     ***  ROUTINE nemo_init  ***
154      !!
155      !! ** Purpose :   initialization of the NEMO GCM
156      !!----------------------------------------------------------------------
157      INTEGER ::   ios, ilocal_comm   ! local integers
158      !!
159      NAMELIST/namctl/ sn_cfctl, ln_timing, ln_diacfl, nn_isplt, nn_jsplt , nn_ictls,   &
160         &                                             nn_ictle, nn_jctls , nn_jctle
161      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr
162      !!----------------------------------------------------------------------
163      !
164      cxios_context = 'nemo'
165      !
166      !                             !-------------------------------------------------!
167      !                             !     set communicator & select the local rank    !
168      !                             !  must be done as soon as possible to get narea  !
169      !                             !-------------------------------------------------!
170      !
171#if defined key_iomput
172      CALL xios_initialize( "for_xios_mpi_id", return_comm=ilocal_comm )   ! nemo local communicator given by xios
173      CALL mpp_start( ilocal_comm )
174#else
175      CALL mpp_start( )
176#endif
177      !
178      narea = mpprank + 1               ! mpprank: the rank of proc (0 --> mppsize -1 )
179      lwm = (narea == 1)                ! control of output namelists
180      !
181      !                             !---------------------------------------------------------------!
182      !                             ! Open output files, reference and configuration namelist files !
183      !                             !---------------------------------------------------------------!
184      !
185      ! open ocean.output as soon as possible to get all output prints (including errors messages)
186      IF( lwm )   CALL ctl_opn(     numout,        'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
187      ! open reference and configuration namelist files
188                  CALL load_nml( numnam_ref,        'namelist_ref',                                           -1, lwm )
189                  CALL load_nml( numnam_cfg,        'namelist_cfg',                                           -1, lwm )
190      IF( lwm )   CALL ctl_opn(     numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
191      ! open /dev/null file to be able to supress output write easily
192                  CALL ctl_opn(     numnul,           '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE. )
193      !
194      !                             !--------------------!
195      !                             ! Open listing units !  -> need sn_cfctl from namctl to define lwp
196      !                             !--------------------!
197      !
198      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
199901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namctl in reference namelist' )
200      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
201902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist' )
202      !
203      ! finalize the definition of namctl variables
204      IF( narea < sn_cfctl%procmin .OR. narea > sn_cfctl%procmax .OR. MOD( narea - sn_cfctl%procmin, sn_cfctl%procincr ) /= 0 )   &
205         &   CALL nemo_set_cfctl( sn_cfctl, .FALSE. )
206      !
207      lwp = (narea == 1) .OR. sn_cfctl%l_oceout    ! control of all listing output print
208      !
209      IF(lwp) THEN                      ! open listing units
210         !
211         IF( .NOT. lwm )   &            ! alreay opened for narea == 1
212            &            CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, -1, .FALSE., narea )
213         !
214         WRITE(numout,*)
215         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - CMCC'
216         WRITE(numout,*) '                       NEMO team'
217         WRITE(numout,*) '            Ocean General Circulation Model'
218         WRITE(numout,*) '                NEMO version 4.0  (2019) '
219         WRITE(numout,*)
220         WRITE(numout,*) "           ._      ._      ._      ._      ._    "
221         WRITE(numout,*) "       _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ "
222         WRITE(numout,*)
223         WRITE(numout,*) "           o         _,           _,             "
224         WRITE(numout,*) "            o      .' (        .-' /             "
225         WRITE(numout,*) "           o     _/..._'.    .'   /              "
226         WRITE(numout,*) "      (    o .-'`      ` '-./  _.'               "
227         WRITE(numout,*) "       )    ( o)           ;= <_         (       "
228         WRITE(numout,*) "      (      '-.,\\__ __.-;`\   '.        )      "
229         WRITE(numout,*) "       )  )       \) |`\ \)  '.   \      (   (   "
230         WRITE(numout,*) "      (  (           \_/       '-._\      )   )  "
231         WRITE(numout,*) "       )  ) jgs                     `    (   (   "
232         WRITE(numout,*) "     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "
233         WRITE(numout,*)
234         
235         ! Print the working precision to ocean.output
236         IF (wp == dp) THEN
237            WRITE(numout,*) "Working precision = double-precision"
238         ELSE
239            WRITE(numout,*) "Working precision = single-precision"
240         ENDIF
241         WRITE(numout,*)
242         !
243         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
244         !
245      ENDIF
246      !
247      IF(lwm) WRITE( numond, namctl )
248      !
249      !                             !------------------------------------!
250      !                             !  Set global domain size parameters !
251      !                             !------------------------------------!
252      !
253      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
254903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist' )
255      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
256904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist' )   
257      !
258      IF( ln_read_cfg ) THEN            ! Read sizes in domain configuration file
259         CALL domain_cfg ( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
260      ELSE                              ! user-defined namelist
261         CALL usr_def_nam( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
262      ENDIF
263      !
264      IF(lwm)   WRITE( numond, namcfg )
265      !
266      !                             !-----------------------------------------!
267      !                             ! mpp parameters and domain decomposition !
268      !                             !-----------------------------------------!
269      CALL mpp_init
270
271      CALL halo_mng_init()
272      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
273      CALL nemo_alloc()
274
275      ! Initialise time level indices
276      Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
277     
278      !                             !-------------------------------!
279      !                             !  NEMO general initialization  !
280      !                             !-------------------------------!
281
282      CALL nemo_ctl                          ! Control prints
283      !
284      !                                      ! General initialization
285      IF( ln_timing    )   CALL timing_init     ! timing
286      IF( ln_timing    )   CALL timing_start( 'nemo_init')
287      !
288                           CALL     phy_cst         ! Physical constants
289      !
290      !                                             ! SWE: Set rho0 and associated variables (eosbn2 not used)
291                           rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
292                           rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
293                           rho0_rcp    = rho0 * rcp 
294                           r1_rho0     = 1._wp / rho0
295                           r1_rcp      = 1._wp / rcp
296                           r1_rho0_rcp = 1._wp / rho0_rcp 
297      !
298                           CALL     dom_init( Nbb, Nnn, Naa, "OPA") ! Domain
299
300      IF( sn_cfctl%l_prtctl )   &
301         &                 CALL prt_ctl_init        ! Print control
302
303                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
304
305      !                                      ! external forcing
306                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
307
308      !                                      ! Ocean physics                                   
309      !                                         ! Lateral physics
310                           CALL ldf_dyn_init      ! Lateral ocean momentum physics
311                           
312      !                                      ! Dynamics
313                           CALL dyn_adv_init         ! advection (vector or flux form)
314                           CALL dyn_vor_init         ! vorticity term including Coriolis
315                           CALL dyn_ldf_init         ! lateral mixing
316
317      !                                      ! Diagnostics
318      IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
319      !                                         ! Trends diag: switched off
320                           l_trddyn = .FALSE.        ! No trend diagnostics
321
322      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
323      !
324      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
325      !
326   END SUBROUTINE nemo_init
327
328
329   SUBROUTINE nemo_ctl
330      !!----------------------------------------------------------------------
331      !!                     ***  ROUTINE nemo_ctl  ***
332      !!
333      !! ** Purpose :   control print setting
334      !!
335      !! ** Method  : - print namctl and namcfg information and check some consistencies
336      !!----------------------------------------------------------------------
337      !
338      IF(lwp) THEN                  ! control print
339         WRITE(numout,*)
340         WRITE(numout,*) 'nemo_ctl: Control prints'
341         WRITE(numout,*) '~~~~~~~~'
342         WRITE(numout,*) '   Namelist namctl'
343         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
344         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
345         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
346         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
347         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
348         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
349         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
350         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
351         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
352         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
353         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
354         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
355         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
356      ENDIF
357      !
358      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
359      IF(lwp) THEN                  ! control print
360         WRITE(numout,*)
361         WRITE(numout,*) '   Namelist namcfg'
362         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
363         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
364         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
365         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
366         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
367         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
368      ENDIF
369      !
370      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
371         &                                                'Compile with key_nosignedzero enabled:',   &
372         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
373      !
374#if defined key_agrif
375      IF( ln_timing )   CALL ctl_stop( 'AGRIF not implemented with ln_timing = true')
376#endif
377      !
378   END SUBROUTINE nemo_ctl
379
380
381   SUBROUTINE nemo_closefile
382      !!----------------------------------------------------------------------
383      !!                     ***  ROUTINE nemo_closefile  ***
384      !!
385      !! ** Purpose :   Close the files
386      !!----------------------------------------------------------------------
387      !
388      IF( lk_mpp )   CALL mppsync
389      !
390      CALL iom_close                                 ! close all input/output files managed by iom_*
391      !
392      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
393      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
394      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
395      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
396      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
397      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
398      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
399      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
400      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
401      !
402      numout = 6                                     ! redefine numout in case it is used after this point...
403      !
404   END SUBROUTINE nemo_closefile
405
406
407   SUBROUTINE nemo_alloc
408      !!----------------------------------------------------------------------
409      !!                     ***  ROUTINE nemo_alloc  ***
410      !!
411      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
412      !!
413      !! ** Method  :
414      !!----------------------------------------------------------------------
415      USE diawri    , ONLY : dia_wri_alloc
416      USE dom_oce   , ONLY : dom_oce_alloc
417      !
418      INTEGER :: ierr
419      !!----------------------------------------------------------------------
420      !
421      ierr =        oce_SWE_alloc()    ! ocean
422      ierr = ierr + dia_wri_alloc()
423      ierr = ierr + dom_oce_alloc()    ! ocean domain
424      ierr = ierr + zdf_oce_alloc()    ! ocean vertical physics
425      !
426      CALL mpp_sum( 'nemogcm', ierr )
427      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
428      !
429   END SUBROUTINE nemo_alloc
430
431   
432   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
433      !!----------------------------------------------------------------------
434      !!                     ***  ROUTINE nemo_set_cfctl  ***
435      !!
436      !! ** Purpose :   Set elements of the output control structure to setto.
437      !!
438      !! ** Method  :   Note this routine can be used to switch on/off some
439      !!                types of output for selected areas.
440      !!----------------------------------------------------------------------
441      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
442      LOGICAL     , INTENT(in   ) :: setto
443      !!----------------------------------------------------------------------
444      sn_cfctl%l_runstat = setto
445      sn_cfctl%l_trcstat = setto
446      sn_cfctl%l_oceout  = setto
447      sn_cfctl%l_layout  = setto
448      sn_cfctl%l_prtctl  = setto
449      sn_cfctl%l_prttrc  = setto
450      sn_cfctl%l_oasout  = setto
451   END SUBROUTINE nemo_set_cfctl
452
453   !!======================================================================
454END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.