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 @ 14227

Last change on this file since 14227 was 14227, checked in by smasson, 3 years ago

trunk: replace remaining OPA by OCE

File size: 22.4 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  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         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_iomput
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_iomput
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, jperio )
264      ELSE                              ! user-defined namelist
265         CALL usr_def_nam( cn_cfg, nn_cfg, Ni0glo, Nj0glo, jpkglo, jperio )
266      ENDIF
267      !
268      IF(lwm)   WRITE( numond, namcfg )
269      !
270      !                             !-----------------------------------------!
271      !                             ! mpp parameters and domain decomposition !
272      !                             !-----------------------------------------!
273      CALL mpp_init
274
275      CALL halo_mng_init()
276      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
277      CALL nemo_alloc()
278
279      ! Initialise time level indices
280      Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
281     
282      !                             !-------------------------------!
283      !                             !  NEMO general initialization  !
284      !                             !-------------------------------!
285
286      CALL nemo_ctl                          ! Control prints of namctl and namcfg
287      !
288      !                                      ! General initialization
289      IF( ln_timing    )   CALL timing_init     ! timing
290      IF( ln_timing    )   CALL timing_start( 'nemo_init')
291      !
292                           CALL     phy_cst         ! Physical constants
293      !
294      !                                             ! SWE: Set rho0 and associated variables (eosbn2 not used)
295                           rho0        = 1026._wp                 !: volumic mass of reference     [kg/m3]
296                           rcp         = 3991.86795711963_wp      !: heat capacity     [J/K]
297                           rho0_rcp    = rho0 * rcp 
298                           r1_rho0     = 1._wp / rho0
299                           r1_rcp      = 1._wp / rcp
300                           r1_rho0_rcp = 1._wp / rho0_rcp 
301      !
302                           CALL     dom_init( Nbb, Nnn, Naa ) ! Domain
303
304      IF( sn_cfctl%l_prtctl )   &
305         &                 CALL prt_ctl_init        ! Print control
306
307                           CALL  istate_init( Nbb, Nnn, Naa )    ! ocean initial state (Dynamics and tracers)
308
309      !                                      ! external forcing
310                           CALL     sbc_init( Nbb, Nnn, Naa )    ! surface boundary conditions (including sea-ice)
311
312      !                                      ! Ocean physics                                   
313      !                                         ! Lateral physics
314                           CALL ldf_dyn_init      ! Lateral ocean momentum physics
315                           
316      !                                      ! Dynamics
317                           CALL dyn_adv_init         ! advection (vector or flux form)
318                           CALL dyn_vor_init         ! vorticity term including Coriolis
319                           CALL dyn_ldf_init         ! lateral mixing
320
321      !                                      ! Diagnostics
322      IF( ln_diacfl    )   CALL dia_cfl_init    ! Initialise CFL diagnostics
323      !                                         ! Trends diag: switched off
324                           l_trddyn = .FALSE.        ! No trend diagnostics
325
326      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
327      !
328      IF( ln_timing    )   CALL timing_stop( 'nemo_init')
329      !
330   END SUBROUTINE nemo_init
331
332
333   SUBROUTINE nemo_ctl
334      !!----------------------------------------------------------------------
335      !!                     ***  ROUTINE nemo_ctl  ***
336      !!
337      !! ** Purpose :   control print setting
338      !!
339      !! ** Method  : - print namctl and namcfg information and check some consistencies
340      !!----------------------------------------------------------------------
341      !
342      IF(lwp) THEN                  ! control print
343         WRITE(numout,*)
344         WRITE(numout,*) 'nemo_ctl: Control prints'
345         WRITE(numout,*) '~~~~~~~~'
346         WRITE(numout,*) '   Namelist namctl'
347         WRITE(numout,*) '                              sn_cfctl%l_runstat = ', sn_cfctl%l_runstat
348         WRITE(numout,*) '                              sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat
349         WRITE(numout,*) '                              sn_cfctl%l_oceout  = ', sn_cfctl%l_oceout
350         WRITE(numout,*) '                              sn_cfctl%l_layout  = ', sn_cfctl%l_layout
351         WRITE(numout,*) '                              sn_cfctl%l_prtctl  = ', sn_cfctl%l_prtctl
352         WRITE(numout,*) '                              sn_cfctl%l_prttrc  = ', sn_cfctl%l_prttrc
353         WRITE(numout,*) '                              sn_cfctl%l_oasout  = ', sn_cfctl%l_oasout
354         WRITE(numout,*) '                              sn_cfctl%procmin   = ', sn_cfctl%procmin 
355         WRITE(numout,*) '                              sn_cfctl%procmax   = ', sn_cfctl%procmax 
356         WRITE(numout,*) '                              sn_cfctl%procincr  = ', sn_cfctl%procincr 
357         WRITE(numout,*) '                              sn_cfctl%ptimincr  = ', sn_cfctl%ptimincr 
358         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
359         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
360      ENDIF
361      !
362      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file
363      IF(lwp) THEN                  ! control print
364         WRITE(numout,*)
365         WRITE(numout,*) '   Namelist namcfg'
366         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
367         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
368         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea
369         WRITE(numout,*) '      create a configuration definition file        ln_write_cfg     = ', ln_write_cfg
370         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
371         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
372      ENDIF
373      !
374      IF( 1._wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.',  &
375         &                                                'Compile with key_nosignedzero enabled:',   &
376         &                                                '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' )
377      !
378#if defined key_agrif
379      IF( ln_timing )   CALL ctl_stop( 'AGRIF not implemented with ln_timing = true')
380#endif
381      !
382   END SUBROUTINE nemo_ctl
383
384
385   SUBROUTINE nemo_closefile
386      !!----------------------------------------------------------------------
387      !!                     ***  ROUTINE nemo_closefile  ***
388      !!
389      !! ** Purpose :   Close the files
390      !!----------------------------------------------------------------------
391      !
392      IF( lk_mpp )   CALL mppsync
393      !
394      CALL iom_close                                 ! close all input/output files managed by iom_*
395      !
396      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
397      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics file
398      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
399      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
400      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
401      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
402      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
403      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
404      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
405      !
406      numout = 6                                     ! redefine numout in case it is used after this point...
407      !
408   END SUBROUTINE nemo_closefile
409
410
411   SUBROUTINE nemo_alloc
412      !!----------------------------------------------------------------------
413      !!                     ***  ROUTINE nemo_alloc  ***
414      !!
415      !! ** Purpose :   Allocate all the dynamic arrays of the OCE modules
416      !!
417      !! ** Method  :
418      !!----------------------------------------------------------------------
419      USE diawri    , ONLY : dia_wri_alloc
420      USE dom_oce   , ONLY : dom_oce_alloc
421      !
422      INTEGER :: ierr
423      !!----------------------------------------------------------------------
424      !
425      ierr =        oce_SWE_alloc()    ! ocean
426      ierr = ierr + dia_wri_alloc()
427      ierr = ierr + dom_oce_alloc()    ! ocean domain
428      ierr = ierr + zdf_oce_alloc()    ! ocean vertical physics
429      !
430      CALL mpp_sum( 'nemogcm', ierr )
431      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
432      !
433   END SUBROUTINE nemo_alloc
434
435
436   SUBROUTINE nemo_set_cfctl(sn_cfctl, setto )
437      !!----------------------------------------------------------------------
438      !!                     ***  ROUTINE nemo_set_cfctl  ***
439      !!
440      !! ** Purpose :   Set elements of the output control structure to setto.
441      !!
442      !! ** Method  :   Note this routine can be used to switch on/off some
443      !!                types of output for selected areas.
444      !!----------------------------------------------------------------------
445      TYPE(sn_ctl), INTENT(inout) :: sn_cfctl
446      LOGICAL     , INTENT(in   ) :: setto
447      !!----------------------------------------------------------------------
448      sn_cfctl%l_runstat = setto
449      sn_cfctl%l_trcstat = setto
450      sn_cfctl%l_oceout  = setto
451      sn_cfctl%l_layout  = setto
452      sn_cfctl%l_prtctl  = setto
453      sn_cfctl%l_prttrc  = setto
454      sn_cfctl%l_oasout  = setto
455   END SUBROUTINE nemo_set_cfctl
456
457   !!======================================================================
458END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.