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.
step.F90 in branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/step.F90 @ 3837

Last change on this file since 3837 was 3837, checked in by trackstand2, 11 years ago

Merge of finiss

  • Property svn:keywords set to Id
File size: 21.1 KB
Line 
1MODULE step
2   !!======================================================================
3   !!                       ***  MODULE step  ***
4   !! Time-stepping    : manager of the ocean, tracer and ice time stepping
5   !!======================================================================
6   !! History :  OPA  !  1991-03  (G. Madec)  Original code
7   !!             -   !  1991-11  (G. Madec)
8   !!             -   !  1992-06  (M. Imbard)  add a first output record
9   !!             -   !  1996-04  (G. Madec)  introduction of dynspg
10   !!             -   !  1996-04  (M.A. Foujols)  introduction of passive tracer
11   !!            8.0  !  1997-06  (G. Madec)  new architecture of call
12   !!            8.2  !  1997-06  (G. Madec, M. Imbard, G. Roullet)  free surface
13   !!             -   !  1999-02  (G. Madec, N. Grima)  hpg implicit
14   !!             -   !  2000-07  (J-M Molines, M. Imbard)  Open Bondary Conditions
15   !!   NEMO     1.0  !  2002-06  (G. Madec)  free form, suppress macro-tasking
16   !!             -   !  2004-08  (C. Talandier) New trends organization
17   !!             -   !  2005-01  (C. Ethe) Add the KPP closure scheme
18   !!             -   !  2005-11  (G. Madec)  Reorganisation of tra and dyn calls
19   !!             -   !  2006-01  (L. Debreu, C. Mazauric)  Agrif implementation
20   !!             -   !  2006-07  (S. Masson)  restart using iom
21   !!            3.2  !  2009-02  (G. Madec, R. Benshila)  reintroduicing z*-coordinate
22   !!             -   !  2009-06  (S. Masson, G. Madec)  TKE restart compatible with key_cpl
23   !!            3.3  !  2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
24   !!             -   !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
25   !!                 !  2011-05  (S. Pickles) dCSE NEMO optimisations - z index first
26   !!----------------------------------------------------------------------
27
28   !!----------------------------------------------------------------------
29   !!   stp             : OPA system time-stepping
30   !!----------------------------------------------------------------------
31   USE step_oce         ! time stepping definition modules
32#if defined key_top
33   USE trcstp           ! passive tracer time-stepping      (trc_stp routine)
34#endif
35#if defined key_agrif
36   USE agrif_opa_sponge ! Momemtum and tracers sponges
37#endif
38   USE asminc           ! assimilation increments    (tra_asm_inc, dyn_asm_inc routines)
39   USE timing, ONLY: timing_start, timing_stop, timing_reset, timing_disable
40   USE arpdebugging, ONLY: dump_array
41   IMPLICIT NONE
42   PRIVATE
43
44   PUBLIC   stp   ! called by opa.F90
45
46   !! * Control permutation of array indices
47   !! DCSE_NEMO: warning! dom_oce and zdf_oce public variables are made available
48   !! through the use of step_oce
49#  include "dom_oce_ftrans.h90"
50#  include "zdf_oce_ftrans.h90"
51
52   !! * Substitutions
53#  include "domzgr_substitute.h90"
54#  include "zdfddm_substitute.h90"
55   !!----------------------------------------------------------------------
56   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
57   !! $Id$
58   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
59   !!----------------------------------------------------------------------
60CONTAINS
61
62#if defined key_agrif
63   SUBROUTINE stp( )
64      INTEGER             ::   kstp   ! ocean time-step index
65#else
66   SUBROUTINE stp( kstp )
67      INTEGER, INTENT(in) ::   kstp   ! ocean time-step index
68#endif
69      !!----------------------------------------------------------------------
70      !!                     ***  ROUTINE stp  ***
71      !!                     
72      !! ** Purpose : - Time stepping of OPA (momentum and active tracer eqs.)
73      !!              - Time stepping of LIM (dynamic and thermodynamic eqs.)
74      !!              - Tme stepping  of TRC (passive tracer eqs.)
75      !!
76      !! ** Method  : -1- Update forcings and data 
77      !!              -2- Update ocean physics
78      !!              -3- Compute the t and s trends
79      !!              -4- Update t and s
80      !!              -5- Compute the momentum trends
81      !!              -6- Update the horizontal velocity
82      !!              -7- Compute the diagnostics variables (rd,N2, div,cur,w)
83      !!              -8- Outputs and diagnostics
84      !!----------------------------------------------------------------------
85      INTEGER ::   jk       ! dummy loop indice
86      INTEGER ::   indic    ! error indicator if < 0
87#if defined key_z_first
88      INTEGER ::   ji, jj   ! dummy loop indices
89#endif
90      !! ---------------------------------------------------------------------
91                         CALL timing_start('Step') 
92
93#if defined key_agrif
94      kstp = nit000 + Agrif_Nb_Step()
95!      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
96!      IF (lwp) Write(*,*) 'Grid Number',Agrif_Fixed(),' time step ',kstp
97# if defined key_iomput
98      IF( Agrif_Nbstepint() == 0 )   CALL iom_swap
99# endif   
100#endif   
101                             indic = 0                ! reset to no error condition
102      IF( kstp /= nit000 )   CALL day( kstp )         ! Calendar (day was already called at nit000 in day_init)
103                             CALL iom_setkt( kstp )   ! say to iom that we are at time step kstp
104
105      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
106      ! Update data, open boundaries, surface boundary condition (including sea-ice)
107      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
108                         CALL timing_start('Boundaries') 
109      IF( lk_dtatem  )   CALL dta_tem( kstp )         ! update 3D temperature data
110      IF( lk_dtasal  )   CALL dta_sal( kstp )         ! update 3D salinity data
111                         CALL sbc    ( kstp )         ! Sea Boundary Condition (including sea-ice)
112      IF( lk_obc     )   CALL obc_dta( kstp )         ! update dynamic and tracer data at open boundaries
113      IF( lk_obc     )   CALL obc_rad( kstp )         ! compute phase velocities at open boundaries
114      IF( lk_bdy     )   CALL bdy_dta_frs( kstp )     ! update dynamic and tracer data for FRS conditions (BDY)
115                         ! ARP - no 'section' arg here so the time taken
116                         ! in this region (which can involve IO) is
117                         ! subtracted from the time
118                         ! taken to do the whole step.
119                         CALL timing_stop('Boundaries') 
120
121      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
122      !  Ocean dynamics : ssh, wn, hdiv, rot                                 !
123      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
124                         CALL timing_start('Ocean Dyn.') 
125                         CALL ssh_wzv( kstp )         ! after ssh & vertical velocity
126                         CALL timing_stop('Ocean Dyn.','section') 
127
128      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
129      ! Ocean physics update                (ua, va, ta, sa used as workspace)
130      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
131                         CALL timing_start('Ocean Phys.') 
132                         CALL bn2( tsb, rn2b )        ! before Brunt-Vaisala frequency
133                         CALL bn2( tsn, rn2  )        ! now    Brunt-Vaisala frequency
134                         CALL timing_stop('Ocean Phys.','section') 
135      !
136      !  VERTICAL PHYSICS 
137                         CALL timing_start('Vert. Phys.') 
138                         CALL zdf_bfr( kstp )         ! bottom friction
139                         
140      !                                               ! Vertical eddy viscosity and diffusivity coefficients
141      IF( lk_zdfric  )   CALL zdf_ric( kstp )            ! Richardson number dependent Kz
142      IF( lk_zdftke  )   CALL zdf_tke( kstp )            ! TKE closure scheme for Kz
143      IF( lk_zdfgls  )   CALL zdf_gls( kstp )            ! GLS closure scheme for Kz
144      IF( lk_zdfkpp  )   CALL zdf_kpp( kstp )            ! KPP closure scheme for Kz
145      IF( lk_zdfcst  )   THEN                            ! Constant Kz (reset avt, avm[uv] to the background value)
146         avt (:,:,:) = rn_avt0 * tmask(:,:,:)
147         avmu(:,:,:) = rn_avm0 * umask(:,:,:)
148         avmv(:,:,:) = rn_avm0 * vmask(:,:,:)
149      ENDIF
150      IF( ln_rnf_mouth ) THEN                         ! increase diffusivity at rivers mouths
151#if defined key_z_first
152         DO ji = 1, jpi
153            DO jj = 1, jpj
154               DO jk = 2, nkrnf 
155                  avt(ji,jj,jk) = avt(ji,jj,jk) + 2.e0 * rn_avt_rnf * rnfmsk(ji,jj) * tmask(ji,jj,jk)
156               END DO
157            END DO
158         END DO
159#else
160         DO jk = 2, nkrnf
161            avt(:,:,jk) = avt(:,:,jk) + 2.e0 * rn_avt_rnf * rnfmsk(:,:) * tmask(:,:,jk)
162         END DO
163#endif
164      ENDIF
165      IF( ln_zdfevd  )   CALL zdf_evd( kstp )         ! enhanced vertical eddy diffusivity
166
167      IF( lk_zdftmx  )   CALL zdf_tmx( kstp )         ! tidal vertical mixing
168
169      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
170         &               CALL zdf_ddm( kstp )         ! double diffusive mixing
171         
172                         CALL zdf_mxl( kstp )         ! mixed layer depth
173
174                                                      ! write TKE or GLS information in the restart file
175      IF( lrst_oce .AND. lk_zdftke )   CALL tke_rst( kstp, 'WRITE' )
176      IF( lrst_oce .AND. lk_zdfgls )   CALL gls_rst( kstp, 'WRITE' )
177
178                         CALL timing_stop('Vert. Phys.','section') 
179      !
180      !  LATERAL  PHYSICS
181      !
182                         CALL timing_start('Lateral Phys.') 
183      !
184      IF( lk_ldfslp ) THEN                            ! slope of lateral mixing
185                         CALL eos( tsb, rhd )                ! before in situ density
186         IF( ln_zps )    CALL zps_hde( kstp, jpts, tsb, gtsu, gtsv,  &    ! Partial steps: before horizontal gradient
187            &                                      rhd, gru , grv  )      ! of t, s, rd at the last ocean level
188         IF( ln_traldf_grif ) THEN                           ! before slope for Griffies operator
189                         CALL ldf_slp_grif( kstp )
190         ELSE
191                         CALL ldf_slp( kstp, rhd, rn2b )     ! before slope for Madec operator
192         ENDIF
193      ENDIF
194#if defined key_traldf_c2d
195      IF( lk_traldf_eiv )   CALL ldf_eiv( kstp )      ! eddy induced velocity coefficient
196#endif
197                         CALL timing_stop('Lateral Phys.','section') 
198
199      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
200      ! diagnostics and outputs             (ua, va, ta, sa used as workspace)
201      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
202                         CALL timing_start('Diagnostics') 
203      IF( lk_floats  )   CALL flo_stp( kstp )         ! drifting Floats
204      IF( lk_diahth  )   CALL dia_hth( kstp )         ! Thermocline depth (20 degres isotherm depth)
205      IF( lk_diafwb  )   CALL dia_fwb( kstp )         ! Fresh water budget diagnostics
206      IF( ln_diaptr  )   CALL dia_ptr( kstp )         ! Poleward TRansports diagnostics
207      IF( lk_diaar5  )   CALL dia_ar5( kstp )         ! ar5 diag
208                         CALL dia_wri( kstp )         ! ocean model: outputs
209                         CALL timing_stop('Diagnostics','section') 
210
211#if defined key_top
212      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
213      ! Passive Tracer Model
214      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
215                         CALL trc_stp( kstp )         ! time-stepping
216#endif
217
218      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
219      ! Active tracers                              (ua, va used as workspace)
220      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
221                             CALL timing_start('Active tracers') 
222
223                             tsa(:,:,:,:) = 0.e0            ! set tracer trends to zero
224
225      IF(  ln_asmiau .AND. &
226         & ln_trainc     )   CALL tra_asm_inc( kstp )       ! apply tracer assimilation increment
227                             CALL tra_sbc    ( kstp )       ! surface boundary condition
228      IF( ln_traqsr      )   CALL tra_qsr    ( kstp )       ! penetrative solar radiation qsr
229      IF( ln_trabbc      )   CALL tra_bbc    ( kstp )       ! bottom heat flux
230      IF( lk_trabbl      )   CALL tra_bbl    ( kstp )       ! advective (and/or diffusive) bottom boundary layer scheme
231      IF( lk_tradmp      )   CALL tra_dmp    ( kstp )       ! internal damping trends
232                             CALL tra_adv    ( kstp )       ! horizontal & vertical advection
233      IF( lk_zdfkpp      )   CALL tra_kpp    ( kstp )       ! KPP non-local tracer fluxes
234                             CALL tra_ldf    ( kstp )       ! lateral mixing
235#if defined key_agrif
236                             CALL tra_unswap
237      IF(.NOT. Agrif_Root()) CALL Agrif_Sponge_tra          ! tracers sponge
238                             CALL tra_swap
239#endif
240                             CALL tra_zdf    ( kstp )       ! vertical mixing and after tracer fields
241
242      IF( ln_dynhpg_imp  ) THEN                             ! semi-implicit hpg (time stepping then eos)
243         IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
244                             CALL tra_nxt( kstp )                ! tracer fields at next time step
245                             CALL eos    ( tsa, rhd, rhop )      ! Time-filtered in situ density for hpg computation
246         IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsa, gtsu, gtsv,  &    ! zps: time filtered hor. derivative
247            &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
248         
249      ELSE                                                  ! centered hpg  (eos then time stepping)
250                             CALL eos    ( tsn, rhd, rhop )      ! now in situ density for hpg computation
251         IF( ln_zps      )   CALL zps_hde( kstp, jpts, tsn, gtsu, gtsv,  &    ! zps: now hor. derivative
252            &                                          rhd, gru , grv  )      ! of t, s, rd at the last ocean level
253         IF( ln_zdfnpc   )   CALL tra_npc( kstp )                ! update after fields by non-penetrative convection
254                             CALL tra_nxt( kstp )                ! tracer fields at next time step
255      ENDIF
256                             CALL tra_unswap                ! udate T & S 3D arrays  (to be suppressed)
257                             CALL timing_stop('Active tracers','section') 
258
259      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
260      ! Dynamics                                    (ta, sa used as workspace)
261      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
262                               CALL timing_start('Dynamics') 
263
264                               ua(:,:,:) = 0.e0             ! set dynamics trends to zero
265                               va(:,:,:) = 0.e0
266
267      IF(  ln_asmiau .AND. &
268         & ln_dyninc       )   CALL dyn_asm_inc( kstp )     ! apply dynamics assimilation increment
269                               !CALL dump_array(kstp,'un_pre_adv',un(:,:,27), &
270                               !                withHalos=.TRUE.)
271
272                               !CALL timing_start('dyn_adv')
273                               CALL dyn_adv( kstp )         ! advection (vector or flux form)
274                               !CALL timing_stop('dyn_adv','section')
275
276                               !CALL dump_array(kstp,'ua_pre_vor',ua(:,:,27), &
277                               !                withHalos=.TRUE.)
278
279                               !CALL timing_start('dyn_vor')
280                               CALL dyn_vor( kstp )         ! vorticity term including Coriolis
281                               !CALL timing_stop('dyn_vor','section')
282
283                               !CALL dump_array(kstp,'ua_pre_ldf',ua(:,:,27), &
284                               !                withHalos=.TRUE.)
285
286                               !CALL timing_start('dyn_ldf')
287                               CALL dyn_ldf( kstp )         ! lateral mixing
288                               !CALL timing_stop('dyn_ldf','section')
289
290#if defined key_agrif
291      IF(.NOT. Agrif_Root())   CALL Agrif_Sponge_dyn        ! momemtum sponge
292#endif
293                               !CALL dump_array(kstp,'ua_pre_hpg',ua(:,:,27), &
294                               !                withHalos=.TRUE.)
295
296                               !CALL timing_start('dyn_hpg')
297                               CALL dyn_hpg( kstp )         ! horizontal gradient of Hydrostatic pressure
298                               !CALL timing_stop('dyn_hpg','section')
299
300                               !CALL dump_array(kstp,'ua_pre_bfr',ua(:,:,27), &
301                               !                withHalos=.TRUE.)
302
303                               !CALL timing_start('dyn_bfr')
304                               CALL dyn_bfr( kstp )         ! bottom friction   
305                               !CALL timing_stop('dyn_bfr','section')
306                               
307                               !CALL dump_array(kstp,'ua_pre_zdf',ua(:,:,27), &
308                               !                withHalos=.TRUE.)
309
310                               !CALL timing_start('dyn_zdf')
311                               CALL dyn_zdf( kstp )         ! vertical diffusion
312                               !CALL timing_stop('dyn_zdf','section')
313                               
314                               !CALL dump_array(kstp,'ua_pre_spg',ua(:,:,27), &
315                               !                withHalos=.TRUE.)
316
317                               !CALL timing_start('dyn_spg')
318                               CALL dyn_spg( kstp, indic )  ! surface pressure gradient
319                               !CALL timing_stop('dyn_spg','section')
320                               !CALL dump_array(kstp,'ua_spg',ua(:,:,27), &
321                               !                withHalos=.TRUE.)
322
323                               !CALL timing_start('dyn_nxt')
324                               CALL dyn_nxt( kstp )         ! lateral velocity at next time step
325                               !CALL timing_stop('dyn_nxt','section')
326
327                               !CALL timing_stop('dyn_nxt','section')
328
329                               !CALL timing_start('ssh_nxt')
330                               CALL ssh_nxt( kstp )         ! sea surface height at next time step
331                               !CALL timing_stop('ssh_nxt','section')
332
333      IF( ln_diahsb        )   CALL dia_hsb( kstp )         ! - ML - global conservation diagnostics
334      IF( lk_diaobs  )         CALL dia_obs( kstp )         ! obs-minus-model (assimilation) diagnostics
335                               !                            ! (call after dynamics update)
336                               CALL timing_stop('Dynamics','section') 
337
338      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
339      ! Control and restarts
340      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
341                               CALL timing_start('Control') 
342
343                               CALL stp_ctl( kstp, indic )
344      IF( indic < 0        )   THEN
345                               CALL ctl_stop( 'step: indic < 0' )
346                               CALL dia_wri_state( 'output.abort', kstp )
347      ENDIF
348      IF( kstp == nit000   )   CALL iom_close( numror )     ! close input  ocean restart file
349      IF( lrst_oce         )   CALL rst_write    ( kstp )   ! write output ocean restart file
350      IF( lk_obc           )   CALL obc_rst_write( kstp )   ! write open boundary restart file
351                               ! ARP - no 'section' arg here so the time taken
352                               ! in this region (which can involve IO) is
353                               ! subtracted from the time
354                               ! taken to do the whole step.
355                               CALL timing_stop('Control') 
356      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
357      ! Trends                              (ua, va, ta, sa used as workspace)
358      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
359      IF( nstop == 0 ) THEN                         
360         IF( lk_trddyn     )   CALL trd_dwr( kstp )         ! trends: dynamics
361         IF( lk_trdtra     )   CALL trd_twr( kstp )         ! trends: active tracers
362         IF( lk_trdmld     )   CALL trd_mld( kstp )         ! trends: Mixed-layer
363         IF( lk_trdvor     )   CALL trd_vor( kstp )         ! trends: vorticity budget
364      ENDIF
365
366      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
367      ! Coupled mode
368      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
369      IF( lk_cpl           )   CALL sbc_cpl_snd( kstp )     ! coupled mode : field exchanges
370      !
371                               CALL timing_stop('Step', 'section') 
372
373      !
374      IF( kstp == nit000   )   CALL timing_reset            ! Exclude first step from timing
375      IF( kstp == (nitend-2) ) CALL timing_disable()        ! Turn off timing two steps from end to avoid the IO
376      !
377
378   END SUBROUTINE stp
379
380   !!======================================================================
381END MODULE step
Note: See TracBrowser for help on using the repository browser.