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

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

merged branches OBS, ASM, Rivers, BDY & mixed_dynldf ready for vn3.3 merge

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