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

source: branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/opa.F90 @ 2287

Last change on this file since 2287 was 2287, checked in by smasson, 14 years ago

update licence of all NEMO files...

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