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.
opa.F90 in branches/DEV_r1837_MLF/NEMO/OPA_SRC – NEMO

source: branches/DEV_r1837_MLF/NEMO/OPA_SRC/opa.F90 @ 2112

Last change on this file since 2112 was 2112, checked in by mlelod, 14 years ago

ticket: #663 introduce dia_hsb_init routine (called by opa_init)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 19.8 KB
Line 
1MODULE opa
2   !!==============================================================================
3   !!                       ***  MODULE opa   ***
4   !! Ocean system   : OPA ocean dynamics (including on-line tracers 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   !!----------------------------------------------------------------------
28
29   !!----------------------------------------------------------------------
30   !!   opa_model      : solve ocean dynamics, tracer and/or sea-ice
31   !!   opa_init       : initialization of the opa model
32   !!   opa_flg        : initialisation of algorithm flag
33   !!   opa_closefile  : close remaining files
34   !!----------------------------------------------------------------------
35   USE oce             ! dynamics and tracers variables
36   USE dom_oce         ! ocean space domain variables
37   USE sbc_oce         ! surface boundary condition: ocean
38   USE trdmod_oce      ! ocean variables trends
39   USE domcfg          ! domain configuration               (dom_cfg routine)
40   USE mppini          ! shared/distributed memory setting (mpp_init routine)
41   USE domain          ! domain initialization             (dom_init routine)
42   USE obc_par         ! open boundary cond. parameters
43   USE obcini          ! open boundary cond. initialization (obc_ini routine)
44   USE bdy_par         ! unstructured open boundary cond. parameters
45   USE bdyini          ! unstructured open boundary cond. initialization (bdy_init routine)
46   USE istate          ! initial state setting          (istate_init routine)
47   USE sbcmod          ! surface boundary condition
48   USE eosbn2          ! equation of state                 (eos_init routine)
49   USE dynhpg          ! hydrostatic pressure gradient
50   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
51   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
52   USE zdfini
53   USE phycst          ! physical constant                  (par_cst routine)
54   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
55   USE diaptr          ! poleward transports           (dia_ptr_init routine)
56   USE diahsb          ! heat, salt and volume budgets (dia_hsb_init routine)
57   USE step            ! OPA time-stepping                  (stp     routine)
58#if defined key_oasis3
59   USE cpl_oasis3      ! OASIS3 coupling
60#elif defined key_oasis4
61   USE cpl_oasis4      ! OASIS4 coupling (not working)
62#endif
63   USE dynspg_oce      ! Control choice of surface pressure gradient schemes
64   USE prtctl          ! Print control                 (prt_ctl_init routine)
65   USE c1d             ! 1D configuration
66   USE dyncor_c1d      ! Coriolis factor at T-point
67   USE step_c1d        ! Time stepping loop for the 1D configuration
68#if defined key_top
69   USE trcini          ! passive tracer initialisation
70#endif
71   
72   USE iom
73   USE in_out_manager  ! I/O manager
74   USE lib_mpp         ! distributed memory computing
75#if defined key_iomput
76   USE mod_ioclient
77#endif
78
79   IMPLICIT NONE
80   PRIVATE
81
82   PUBLIC   opa_model   ! called by model.F90
83   PUBLIC   opa_init    ! needed by AGRIF
84
85   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
86
87   !!----------------------------------------------------------------------
88   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009)
89   !! $Id$
90   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
91   !!----------------------------------------------------------------------
92
93CONTAINS
94
95   SUBROUTINE opa_model
96      !!----------------------------------------------------------------------
97      !!                     ***  ROUTINE opa  ***
98      !!
99      !! ** Purpose :   opa solves the primitive equations on an orthogonal
100      !!              curvilinear mesh on the sphere.
101      !!
102      !! ** Method  : - model general initialization
103      !!              - launch the time-stepping (stp routine)
104      !!              - finalize the run by closing files and communications
105      !!
106      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
107      !!              Madec, 2008, internal report, IPSL.
108      !!----------------------------------------------------------------------
109      INTEGER ::   istp       ! time step index
110      !!----------------------------------------------------------------------
111
112#if defined key_agrif
113      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
114#endif
115
116      !                            !-----------------------!
117      CALL opa_init                !==  Initialisations  ==!
118      !                            !-----------------------!
119
120      ! check that all process are still there... If some process have an error,
121      ! they will never enter in step and other processes will wait until the end of the cpu time!
122      IF( lk_mpp )   CALL mpp_max( nstop )
123
124      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
125
126      !                            !-----------------------!
127      !                            !==   time stepping   ==!
128      !                            !-----------------------!
129      istp = nit000
130      IF( lk_c1d ) THEN                 !==  1D configuration  ==!
131         DO WHILE ( istp <= nitend .AND. nstop == 0 )
132            CALL stp_c1d( istp )
133            istp = istp + 1
134         END DO
135      ELSE                              !==  3D ocean with  ==!
136         DO WHILE ( istp <= nitend .AND. nstop == 0 )
137#if defined key_agrif
138            CALL Agrif_Step( stp )           ! AGRIF: time stepping
139#else
140            CALL stp( istp )                 ! standard time stepping
141#endif
142            istp = istp + 1
143            IF( lk_mpp )   CALL mpp_max( nstop )
144         END DO
145      ENDIF
146       
147      !                            !------------------------!
148      !                            !==  finalize the run  ==!
149      !                            !------------------------!
150      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
151      !
152      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
153         WRITE(numout,cform_err)
154         WRITE(numout,*) nstop, ' error have been found' 
155      ENDIF
156      !
157      CALL opa_closefile
158#if defined key_oasis3 || defined key_oasis4
159      IF( Agrif_Root() ) THEN
160         CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
161     ENDIF 
162#else
163      IF( lk_mpp )   CALL mppstop       ! end mpp communications
164#endif
165      !
166   END SUBROUTINE opa_model
167
168
169   SUBROUTINE opa_init
170      !!----------------------------------------------------------------------
171      !!                     ***  ROUTINE opa_init  ***
172      !!
173      !! ** Purpose :   initialization of the opa model
174      !!
175      !!----------------------------------------------------------------------
176#if defined key_oasis3 || defined key_oasis4 || defined key_iomput
177      INTEGER :: ilocal_comm
178#endif
179      CHARACTER(len=80),dimension(10) ::   cltxt = ''
180      INTEGER                         ::   ji   ! local loop indices
181      !!
182      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
183         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle, nn_bench, nn_bit_cmp, ln_hsb
184      !!----------------------------------------------------------------------
185      !
186      !                             ! open Namelist file
187      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
188      !
189      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
190      !
191      !                             !--------------------------------------------!
192      !                             !  set communicator & select the local node  !
193      !                             !--------------------------------------------!
194#if defined key_iomput
195# if defined key_oasis3 || defined key_oasis4
196      IF( Agrif_Root() ) THEN
197         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
198         CALL init_ioclient()                    ! io_server will get its communicators (if needed) from oasis (we don't see it)
199      ENDIF
200# else
201      IF( Agrif_Root() ) THEN
202         CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server
203      ENDIF
204# endif
205      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
206
207#else
208# if defined key_oasis3 || defined key_oasis4
209      IF( Agrif_Root() ) THEN
210         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
211      ENDIF
212      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection (control print return in cltxt)
213# else
214      narea = mynode( cltxt )                 ! Nodes selection (control print return in cltxt)
215# endif
216#endif
217      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
218
219      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
220
221      IF(lwp) THEN                            ! open listing units
222         !
223         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
224         !
225         WRITE(numout,*)
226         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
227         WRITE(numout,*) '                       NEMO team'
228         WRITE(numout,*) '            Ocean General Circulation Model'
229         WRITE(numout,*) '                  version 3.2  (2009) '
230         WRITE(numout,*)
231         WRITE(numout,*)
232         DO ji = 1, SIZE(cltxt) 
233            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
234         END DO
235         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
236         !
237      ENDIF
238      !                             !--------------------------------!
239      !                             !  Model general initialization  !
240      !                             !--------------------------------!
241
242      CALL opa_flg                          ! Control prints & Benchmark
243
244                                            ! Domain decomposition
245      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
246      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
247      ENDIF
248     
249      CALL phy_cst                          ! Physical constants
250      CALL eos_init                         ! Equation of state
251      CALL dom_cfg                          ! Domain configuration
252      CALL dom_init                         ! Domain
253!!gm c1d case can be moved in dom_init routine
254      IF( lk_c1d ) THEN                          ! 1D configuration
255         CALL cor_c1d                            ! Coriolis defined at T-point
256         umask(:,:,:) = tmask(:,:,:)             ! U, V and T-points are the same
257         vmask(:,:,:) = tmask(:,:,:)             !
258      ENDIF
259!!gm c1d end
260
261      IF( ln_ctl )   CALL prt_ctl_init      ! Print control
262
263      IF( lk_obc )   CALL obc_init          ! Open boundaries
264      IF( lk_bdy )   CALL bdy_init          ! Unstructured open boundaries
265
266      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
267
268      !                                     ! Ocean physics
269      CALL sbc_init                             ! Read namsbc namelist : surface module (needed for iom_init)
270      CALL ldf_tra_init                         ! Lateral ocean tracer physics
271      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
272      CALL zdf_init                             ! Vertical ocean physics
273
274#if defined key_top
275      CALL trc_ini                          ! Passive tracers
276#endif
277
278      !                                     ! diagnostics
279      CALL iom_init                             ! iom_put initialization
280      CALL dia_ptr_init                         ! Poleward TRansports initialization
281      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
282      IF(ln_hsb)   CALL dia_hsb_init            ! heat content, salt content and volume budgets
283      !
284   END SUBROUTINE opa_init
285
286
287   SUBROUTINE opa_flg
288      !!----------------------------------------------------------------------
289      !!                     ***  ROUTINE opa  ***
290      !!
291      !! ** Purpose :   Initialise logical flags that control the choice of
292      !!              some algorithm or control print
293      !!
294      !! ** Method  : - print namctl information
295      !!              - Read in namilist namflg logical flags
296      !!----------------------------------------------------------------------
297      NAMELIST/namdyn_hpg/ ln_hpg_zco   , ln_hpg_zps   , ln_hpg_sco, ln_hpg_hel,   &
298         &                 ln_hpg_wdj   , ln_hpg_djc   , ln_hpg_rot, rn_gamma  ,   &
299         &                 ln_dynhpg_imp, nn_dynhpg_rst
300      !!----------------------------------------------------------------------
301
302      IF(lwp) THEN                 ! Parameter print
303         WRITE(numout,*)
304         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
305         WRITE(numout,*) '~~~~~~~ '
306         WRITE(numout,*) '   Namelist namctl'
307         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
308         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
309         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
310         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
311         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
312         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
313         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
314         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
315         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
316         WRITE(numout,*) '      bit comparison mode (0/1)       nn_bit_cmp = ', nn_bit_cmp
317         WRITE(numout,*) '      check the heat and salt budgets ln_hsb     = ', ln_hsb
318      ENDIF
319
320      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
321      nictls    = nn_ictls
322      nictle    = nn_ictle
323      njctls    = nn_jctls
324      njctle    = nn_jctle
325      isplt     = nn_isplt
326      jsplt     = nn_jsplt
327      nbench    = nn_bench
328      nbit_cmp  = nn_bit_cmp
329
330      !                           ! Parameter control
331      !
332      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
333         IF( lk_mpp ) THEN
334            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
335         ELSE
336            IF( isplt == 1 .AND. jsplt == 1  ) THEN
337               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
338                  &           ' - the print control will be done over the whole domain' )
339            ENDIF
340            ijsplt = isplt * jsplt            ! total number of processors ijsplt
341         ENDIF
342         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
343         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
344         !
345         !                              ! indices used for the SUM control
346         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
347            lsp_area = .FALSE.                       
348         ELSE                                             ! print control done over a specific  area
349            lsp_area = .TRUE.
350            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
351               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
352               nictls = 1
353            ENDIF
354            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
355               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
356               nictle = jpiglo
357            ENDIF
358            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
359               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
360               njctls = 1
361            ENDIF
362            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
363               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
364               njctle = jpjglo
365            ENDIF
366         ENDIF
367      ENDIF
368
369      IF( nbench == 1 )   THEN            ! Benchmark
370         SELECT CASE ( cp_cfg )
371         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
372         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
373            &                                 ' key_gyre must be used or set nbench = 0' )
374         END SELECT
375      ENDIF
376
377      IF( nbit_cmp == 1 )   THEN          ! Bit compare
378         CALL ctl_warn( ' Bit comparison enabled. Single and multiple processor results must bit compare', &
379              &         ' WARNING: RESULTS ARE NOT PHYSICAL.' )
380      ENDIF
381
382      REWIND( numnam )              ! Read Namelist namdyn_hpg : ln_dynhpg_imp must be read at the initialisation phase
383      READ  ( numnam, namdyn_hpg )
384      !
385   END SUBROUTINE opa_flg
386
387
388   SUBROUTINE opa_closefile
389      !!----------------------------------------------------------------------
390      !!                     ***  ROUTINE opa_closefile  ***
391      !!
392      !! ** Purpose :   Close the files
393      !!----------------------------------------------------------------------
394      USE dtatem        ! temperature data
395      USE dtasal        ! salinity data
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( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
404      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
405      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
406      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
407      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
408      numout = 6   ! redefine numout in case it is used after this point...
409      !
410   END SUBROUTINE opa_closefile
411
412   !!======================================================================
413END MODULE opa
Note: See TracBrowser for help on using the repository browser.