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_r2191_3partymerge2010/NEMO/OPA_SRC – NEMO

source: branches/DEV_r2191_3partymerge2010/NEMO/OPA_SRC/opa.F90 @ 2207

Last change on this file since 2207 was 2207, checked in by acc, 14 years ago

#733 DEV_r2191_3partymerge2010. Merged in changes from devukmo2010 branch

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