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.
stpctl.F90 in NEMO/branches/2020/dev_r12527_Gurvan_ShallowWater/src/SWE – NEMO

source: NEMO/branches/2020/dev_r12527_Gurvan_ShallowWater/src/SWE/stpctl.F90 @ 12614

Last change on this file since 12614 was 12614, checked in by gm, 4 years ago

first Shallow Water Eq. update

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1MODULE stpctl
2   !!======================================================================
3   !!                       ***  MODULE  stpctl  ***
4   !! Ocean run control :  gross check of the ocean time stepping
5   !!======================================================================
6   !! History :  OPA  ! 1991-03  (G. Madec) Original code
7   !!            6.0  ! 1992-06  (M. Imbard)
8   !!            8.0  ! 1997-06  (A.M. Treguier)
9   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
10   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
11   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
12   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
13   !!----------------------------------------------------------------------
14
15   !!----------------------------------------------------------------------
16   !!   stp_ctl      : Control the run
17   !!----------------------------------------------------------------------
18   USE oce             ! ocean dynamics and tracers variables
19   USE dom_oce         ! ocean space and time domain variables
20   USE c1d             ! 1D vertical configuration
21   USE diawri          ! Standard run outputs       (dia_wri_state routine)
22   !
23   USE in_out_manager  ! I/O manager
24   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
25   USE lib_mpp         ! distributed memory computing
26   USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
27   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
28
29   USE netcdf          ! NetCDF library
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC stp_ctl           ! routine called by step.F90
34
35   INTEGER  ::   idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus
36   LOGICAL  ::   lsomeoce
37   !!----------------------------------------------------------------------
38   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
39   !! $Id$
40   !! Software governed by the CeCILL license (see ./LICENSE)
41   !!----------------------------------------------------------------------
42CONTAINS
43
44   SUBROUTINE stp_ctl( kt, Kbb, Kmm, kindic )
45      !!----------------------------------------------------------------------
46      !!                    ***  ROUTINE stp_ctl  ***
47      !!                     
48      !! ** Purpose :   Control the run
49      !!
50      !! ** Method  : - Save the time step in numstp
51      !!              - Print it each 50 time steps
52      !!              - Stop the run IF problem encountered by setting indic=-3
53      !!                Problems checked: |ssh| maximum larger than 10 m
54      !!                                  |U|   maximum larger than 10 m/s
55      !!                                  negative sea surface salinity
56      !!
57      !! ** Actions :   "time.step" file = last ocean time-step
58      !!                "run.stat"  file = run statistics
59      !!                nstop indicator sheared among all local domain (lk_mpp=T)
60      !!----------------------------------------------------------------------
61      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
62      INTEGER, INTENT(in   ) ::   Kbb, Kmm      ! ocean time level index
63      INTEGER, INTENT(inout) ::   kindic   ! error indicator
64      !!
65      INTEGER                ::   ji, jj, jk          ! dummy loop indices
66      INTEGER, DIMENSION(2)  ::   ih                  ! min/max loc indices
67      INTEGER, DIMENSION(3)  ::   iu, is1, is2        ! min/max loc indices
68      REAL(wp)               ::   zzz                 ! local real
69      REAL(wp), DIMENSION(3) ::   zmax
70      LOGICAL                ::   ll_wrtstp, ll_colruns, ll_wrtruns
71      CHARACTER(len=20) :: clname
72      !!----------------------------------------------------------------------
73      !
74      ll_wrtstp  = ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
75      ll_colruns = ll_wrtstp .AND. ( sn_cfctl%l_runstat )
76      ll_wrtruns = ll_colruns .AND. lwm
77      IF( kt == nit000 .AND. lwp ) THEN
78         WRITE(numout,*)
79         WRITE(numout,*) 'stp_ctl : time-stepping control'
80         WRITE(numout,*) '~~~~~~~'
81         !                                ! open time.step file
82         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
83         !                                ! open run.stat file(s) at start whatever
84         !                                ! the value of sn_cfctl%ptimincr
85         IF( lwm .AND. ( sn_cfctl%l_runstat ) ) THEN
86            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
87            clname = 'run.stat.nc'
88            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
89            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun )
90            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
91            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
92            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu   )
93            istatus = NF90_ENDDEF(idrun)
94         ENDIF
95      ENDIF
96      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
97      !
98      IF(lwm .AND. ll_wrtstp) THEN        !==  current time step  ==!   ("time.step" file)
99         WRITE ( numstp, '(1x, i8)' )   kt
100         REWIND( numstp )
101      ENDIF
102      !
103      !                                   !==  test of extrema  ==!
104      IF( ll_wd ) THEN
105         zmax(1) = MAXVAL(  ABS( ssh(:,:,Kmm) + ssh_ref*tmask(:,:,1) )  )        ! ssh max
106      ELSE
107         zmax(1) = MINVAL( e3t(:,:,1,Kmm)  )                                         ! ssh min
108      ENDIF
109      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) )  )                                  ! velocity max (zonal only)
110      zmax(3) = REAL( nstop , wp )                                            ! stop indicator
111      !
112      IF( ll_colruns ) THEN
113         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
114         nstop = NINT( zmax(3) )                 ! nstop indicator sheared among all local domains
115      ENDIF
116      !                                   !==  run statistics  ==!   ("run.stat" files)
117      IF( ll_wrtruns ) THEN
118         WRITE(numrun,9500) kt, zmax(1), zmax(2)
119         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
120         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
121         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
122         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
123      END IF
124      !                                   !==  error handling  ==!
125      IF( ( sn_cfctl%l_glochk .OR. lsomeoce ) .AND. (   &  ! domain contains some ocean points, check for sensible ranges
126         &  zmax(1) <    0._wp .OR.   &                    ! negative sea surface height
127         &  zmax(2) >   10._wp .OR.   &                    ! too large velocity ( > 10 m/s)
128         &  ISNAN( zmax(1) + zmax(2) ) ) ) THEN            ! NaN encounter in the tests
129         IF( lk_mpp .AND. sn_cfctl%l_glochk ) THEN
130            ! have use mpp_max (because sn_cfctl%l_glochk=.T. and distributed)
131            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,Kmm))        , ssmask(:,:)  , zzz, ih  )
132            CALL mpp_maxloc( 'stpctl', ABS(uu(:,:,:,Kmm))          , umask (:,:,:), zzz, iu  )
133         ELSE
134            ! find local min and max locations
135            ih(:)  = MAXLOC( ABS( ssh(:,:,Kmm)   )                              ) + (/ nimpp - 1, njmpp - 1    /)
136            iu(:)  = MAXLOC( ABS( uu  (:,:,:,Kmm) )                              ) + (/ nimpp - 1, njmpp - 1, 0 /)
137         ENDIF
138         
139         WRITE(ctmp1,*) ' stp_ctl: (e3t0) ssh < 0 m  or  |U| > 10 m/s  or  NaN encounter in the tests'
140         WRITE(ctmp2,9100) kt,   zmax(1), ih(1) , ih(2)
141         WRITE(ctmp3,9200) kt,   zmax(2), iu(1) , iu(2) , iu(3)
142         WRITE(ctmp4,*) '      ===> output of last computed fields in output.abort.nc file'
143         
144         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
145         
146         IF( .NOT. sn_cfctl%l_glochk ) THEN
147            WRITE(ctmp8,*) 'E R R O R message from sub-domain: ', narea
148            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp8, ' ', ctmp2, ctmp3, ctmp4 )
149         ELSE
150            CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4 )
151         ENDIF
152
153         kindic = -3
154         !
155      ENDIF
156      !
1579100  FORMAT (' kt=',i8,'   |ssh| min: ',1pg11.4,', at  i j  : ',2i5)
1589200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
1599500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16)
160      !
161   END SUBROUTINE stp_ctl
162
163   !!======================================================================
164END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.