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

source: branches/devukmo2010/NEMO/OPA_SRC/opa.F90 @ 2129

Last change on this file since 2129 was 2129, checked in by rfurner, 14 years ago

pervious merge had mised bits of OBS branch, adding these now

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 21.0 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 defined key_oasis3 || defined key_oasis4
215      IF( Agrif_Root() ) THEN
216         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
217         CALL init_ioclient()                    ! io_server will get its communicators (if needed) from oasis (we don't see it)
218      ENDIF
219# else
220      IF( Agrif_Root() ) THEN
221         CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server
222      ENDIF
223# endif
224      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection
225
226#else
227# if defined key_oasis3 || defined key_oasis4
228      IF( Agrif_Root() ) THEN
229         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
230      ENDIF
231      narea = mynode( cltxt, ilocal_comm )    ! Nodes selection (control print return in cltxt)
232# else
233      narea = mynode( cltxt )                 ! Nodes selection (control print return in cltxt)
234# endif
235#endif
236      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
237
238      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
239
240      IF(lwp) THEN                            ! open listing units
241         !
242         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
243         !
244         WRITE(numout,*)
245         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
246         WRITE(numout,*) '                       NEMO team'
247         WRITE(numout,*) '            Ocean General Circulation Model'
248         WRITE(numout,*) '                  version 3.2  (2009) '
249         WRITE(numout,*)
250         WRITE(numout,*)
251         DO ji = 1, SIZE(cltxt) 
252            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
253         END DO
254         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
255         !
256      ENDIF
257      !                             !--------------------------------!
258      !                             !  Model general initialization  !
259      !                             !--------------------------------!
260
261      CALL opa_flg                          ! Control prints & Benchmark
262
263                                            ! Domain decomposition
264      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
265      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
266      ENDIF
267     
268      CALL phy_cst                          ! Physical constants
269      CALL eos_init                         ! Equation of state
270      CALL dom_cfg                          ! Domain configuration
271      CALL dom_init                         ! Domain
272!!gm c1d case can be moved in dom_init routine
273      IF( lk_c1d ) THEN                          ! 1D configuration
274         CALL cor_c1d                            ! Coriolis defined at T-point
275         umask(:,:,:) = tmask(:,:,:)             ! U, V and T-points are the same
276         vmask(:,:,:) = tmask(:,:,:)             !
277      ENDIF
278!!gm c1d end
279
280      IF( ln_ctl )   CALL prt_ctl_init      ! Print control
281
282      IF( lk_obc )   CALL obc_init          ! Open boundaries
283      IF( lk_bdy )   CALL bdy_init          ! Unstructured open boundaries
284
285      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
286
287      !                                     ! Ocean physics
288      CALL sbc_init                             ! Read namsbc namelist : surface module (needed for iom_init)
289      CALL ldf_tra_init                         ! Lateral ocean tracer physics
290      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
291      CALL zdf_init                             ! Vertical ocean physics
292
293#if defined key_top
294      CALL trc_ini                          ! Passive tracers
295#endif
296
297      !                                     ! diagnostics
298      CALL iom_init                             ! iom_put initialization
299
300      IF( lk_diaobs ) THEN
301         CALL dia_obs_init                  ! Initialize observational data
302         CALL dia_obs( nit000 - 1 )         ! Observation operator for restart
303      ENDIF     
304
305      CALL dia_ptr_init                         ! Poleward TRansports initialization
306      CALL trd_mod_init                         ! Mixed-layer/Vorticity/Integral constraints trends
307
308      IF( lk_asminc ) CALL asm_inc_init     ! Initialize assimilation increments
309      IF(lwp) WRITE(numout,*)'Euler time step switch is ', neuler
310
311      !
312   END SUBROUTINE opa_init
313
314
315   SUBROUTINE opa_flg
316      !!----------------------------------------------------------------------
317      !!                     ***  ROUTINE opa  ***
318      !!
319      !! ** Purpose :   Initialise logical flags that control the choice of
320      !!              some algorithm or control print
321      !!
322      !! ** Method  : - print namctl information
323      !!              - Read in namilist namflg logical flags
324      !!----------------------------------------------------------------------
325      NAMELIST/namdyn_hpg/ ln_hpg_zco   , ln_hpg_zps   , ln_hpg_sco, ln_hpg_hel,   &
326         &                 ln_hpg_wdj   , ln_hpg_djc   , ln_hpg_rot, rn_gamma  ,   &
327         &                 ln_dynhpg_imp, nn_dynhpg_rst
328      !!----------------------------------------------------------------------
329
330      IF(lwp) THEN                 ! Parameter print
331         WRITE(numout,*)
332         WRITE(numout,*) 'opa_flg: Control prints & Benchmark'
333         WRITE(numout,*) '~~~~~~~ '
334         WRITE(numout,*) '   Namelist namctl'
335         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
336         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
337         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
338         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
339         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
340         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
341         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
342         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
343         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
344         WRITE(numout,*) '      bit comparison mode (0/1)       nn_bit_cmp = ', nn_bit_cmp
345      ENDIF
346
347      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
348      nictls    = nn_ictls
349      nictle    = nn_ictle
350      njctls    = nn_jctls
351      njctle    = nn_jctle
352      isplt     = nn_isplt
353      jsplt     = nn_jsplt
354      nbench    = nn_bench
355      nbit_cmp  = nn_bit_cmp
356
357      !                           ! Parameter control
358      !
359      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
360         IF( lk_mpp ) THEN
361            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
362         ELSE
363            IF( isplt == 1 .AND. jsplt == 1  ) THEN
364               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
365                  &           ' - the print control will be done over the whole domain' )
366            ENDIF
367            ijsplt = isplt * jsplt            ! total number of processors ijsplt
368         ENDIF
369         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
370         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
371         !
372         !                              ! indices used for the SUM control
373         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
374            lsp_area = .FALSE.                       
375         ELSE                                             ! print control done over a specific  area
376            lsp_area = .TRUE.
377            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
378               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
379               nictls = 1
380            ENDIF
381            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
382               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
383               nictle = jpiglo
384            ENDIF
385            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
386               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
387               njctls = 1
388            ENDIF
389            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
390               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
391               njctle = jpjglo
392            ENDIF
393         ENDIF
394      ENDIF
395
396      IF( nbench == 1 )   THEN            ! Benchmark
397         SELECT CASE ( cp_cfg )
398         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
399         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
400            &                                 ' key_gyre must be used or set nbench = 0' )
401         END SELECT
402      ENDIF
403
404      IF( nbit_cmp == 1 )   THEN          ! Bit compare
405         CALL ctl_warn( ' Bit comparison enabled. Single and multiple processor results must bit compare', &
406              &         ' WARNING: RESULTS ARE NOT PHYSICAL.' )
407      ENDIF
408
409      REWIND( numnam )              ! Read Namelist namdyn_hpg : ln_dynhpg_imp must be read at the initialisation phase
410      READ  ( numnam, namdyn_hpg )
411      !
412   END SUBROUTINE opa_flg
413
414
415   SUBROUTINE opa_closefile
416      !!----------------------------------------------------------------------
417      !!                     ***  ROUTINE opa_closefile  ***
418      !!
419      !! ** Purpose :   Close the files
420      !!----------------------------------------------------------------------
421      USE dtatem        ! temperature data
422      USE dtasal        ! salinity data
423      !!----------------------------------------------------------------------
424      !
425      IF( lk_mpp )   CALL mppsync
426      !
427      CALL iom_close                                 ! close all input/output files managed by iom_*
428      !
429      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
430      IF( numsol     /= -1 )   CLOSE( numsol     )   ! solver file
431      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
432      IF( numnam_ice /= -1 )   CLOSE( numnam_ice )   ! ice namelist
433      IF( numevo_ice /= -1 )   CLOSE( numevo_ice )   ! ice variables (temp. evolution)
434      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
435      numout = 6   ! redefine numout in case it is used after this point...
436      !
437   END SUBROUTINE opa_closefile
438
439   !!======================================================================
440END MODULE opa
Note: See TracBrowser for help on using the repository browser.