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/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE – NEMO

source: NEMO/branches/2018/dev_r10164_HPC09_ESIWACE_PREP_MERGE/src/OCE/stpctl.F90 @ 10368

Last change on this file since 10368 was 10368, checked in by smasson, 5 years ago

dev_r10164_HPC09_ESIWACE_PREP_MERGE: merge with trunk@10365, see #2133

  • Property svn:keywords set to Id
File size: 11.2 KB
RevLine 
[3]1MODULE stpctl
[1489]2   !!======================================================================
[3]3   !!                       ***  MODULE  stpctl  ***
4   !! Ocean run control :  gross check of the ocean time stepping
[1489]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
[9019]11   !!            3.7  ! 2016-09  (G. Madec)  Remove solver
12   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
[1489]13   !!----------------------------------------------------------------------
[3]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
[6140]20   USE c1d             ! 1D vertical configuration
[9210]21   USE diawri          ! Standard run outputs       (dia_wri_state routine)
[6140]22   !
[3]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
[10368]26   USE zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
[9210]27   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
[3]28
[9441]29   USE netcdf          ! NetCDF library
[3]30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC stp_ctl           ! routine called by step.F90
[9441]34
[10368]35   INTEGER  ::   idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus
[10358]36   LOGICAL  ::   lsomeoce
[3]37   !!----------------------------------------------------------------------
[9598]38   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[1489]39   !! $Id$
[10068]40   !! Software governed by the CeCILL license (see ./LICENSE)
[1489]41   !!----------------------------------------------------------------------
[3]42CONTAINS
43
44   SUBROUTINE stp_ctl( kt, 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
[9019]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
[3]56      !!
[9019]57      !! ** Actions :   "time.step" file = last ocean time-step
58      !!                "run.stat"  file = run statistics
[9210]59      !!                nstop indicator sheared among all local domain (lk_mpp=T)
[3]60      !!----------------------------------------------------------------------
[6140]61      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
62      INTEGER, INTENT(inout) ::   kindic   ! error indicator
[1489]63      !!
[10358]64      INTEGER                ::   ji, jj, jk          ! dummy loop indices
65      INTEGER, DIMENSION(2)  ::   ih                  ! min/max loc indices
66      INTEGER, DIMENSION(3)  ::   iu, is1, is2        ! min/max loc indices
67      REAL(wp)               ::   zzz                 ! local real
[10368]68      REAL(wp), DIMENSION(9) ::   zmax
[9565]69      CHARACTER(len=20) :: clname
[3]70      !!----------------------------------------------------------------------
[6140]71      !
[3]72      IF( kt == nit000 .AND. lwp ) THEN
73         WRITE(numout,*)
74         WRITE(numout,*) 'stp_ctl : time-stepping control'
[79]75         WRITE(numout,*) '~~~~~~~'
[9019]76         !                                ! open time.step file
[10358]77         IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
[9019]78         !                                ! open run.stat file
[10358]79         IF( ln_ctl .AND. lwm ) THEN
80            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
[9565]81            clname = 'run.stat.nc'
82            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
83            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun )
[9441]84            istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime )
85            istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh )
[9808]86            istatus = NF90_DEF_VAR( idrun,   'abs_u_max', NF90_DOUBLE, (/ idtime /), idu   )
87            istatus = NF90_DEF_VAR( idrun,       's_min', NF90_DOUBLE, (/ idtime /), ids1  )
88            istatus = NF90_DEF_VAR( idrun,       's_max', NF90_DOUBLE, (/ idtime /), ids2  )
[10368]89            istatus = NF90_DEF_VAR( idrun,       't_min', NF90_DOUBLE, (/ idtime /), idt1  )
90            istatus = NF90_DEF_VAR( idrun,       't_max', NF90_DOUBLE, (/ idtime /), idt2  )
91            IF( ln_zad_Aimp ) THEN
92               istatus = NF90_DEF_VAR( idrun,   'abs_wi_max', NF90_DOUBLE, (/ idtime /), idw1  )
93               istatus = NF90_DEF_VAR( idrun,       'Cu_max', NF90_DOUBLE, (/ idtime /), idc1  )
94            ENDIF
[9441]95            istatus = NF90_ENDDEF(idrun)
[10368]96            zmax(8:9) = 0._wp    ! initialise to zero in case ln_zad_Aimp option is not in use
[9441]97         ENDIF
[3]98      ENDIF
[10358]99      IF( kt == nit000 )   lsomeoce = COUNT( ssmask(:,:) == 1._wp ) > 0
[6140]100      !
[10358]101      IF(lwm) THEN                        !==  current time step  ==!   ("time.step" file)
[9019]102         WRITE ( numstp, '(1x, i8)' )   kt
103         REWIND( numstp )
[3]104      ENDIF
[6140]105      !
[9019]106      !                                   !==  test of extrema  ==!
[9023]107      IF( ll_wd ) THEN
[9210]108         zmax(1) = MAXVAL(  ABS( sshn(:,:) + ssh_ref*tmask(:,:,1) )  )        ! ssh max
[9023]109      ELSE
[9210]110         zmax(1) = MAXVAL(  ABS( sshn(:,:) )  )                               ! ssh max
[9023]111      ENDIF
[9019]112      zmax(2) = MAXVAL(  ABS( un(:,:,:) )  )                                  ! velocity max (zonal only)
113      zmax(3) = MAXVAL( -tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )   ! minus salinity max
[9808]114      zmax(4) = MAXVAL(  tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp )   !       salinity max
[10368]115      zmax(5) = MAXVAL( -tsn(:,:,:,jp_tem) , mask = tmask(:,:,:) == 1._wp )   ! minus temperature max
116      zmax(6) = MAXVAL(  tsn(:,:,:,jp_tem) , mask = tmask(:,:,:) == 1._wp )   !       temperature max
117      zmax(7) = REAL( nstop , wp )                                            ! stop indicator
118      IF( ln_zad_Aimp ) THEN
119         zmax(8) = MAXVAL(  ABS( wi(:,:,:) ) , mask = wmask(:,:,:) == 1._wp ) ! implicit vertical vel. max
120         zmax(9) = MAXVAL(   Cu_adv(:,:,:)   , mask = tmask(:,:,:) == 1._wp ) !       cell Courant no. max
121      ENDIF
[1489]122      !
[10358]123      IF( lk_mpp .AND. ln_ctl ) THEN
124         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
[10368]125         nstop = NINT( zmax(7) )                 ! nstop indicator sheared among all local domains
[9210]126      ENDIF
[10358]127      !                                   !==  run statistics  ==!   ("run.stat" files)
128      IF( ln_ctl .AND. lwm ) THEN
129         WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4)
130         istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) )
131         istatus = NF90_PUT_VAR( idrun,   idu, (/ zmax(2)/), (/kt/), (/1/) )
132         istatus = NF90_PUT_VAR( idrun,  ids1, (/-zmax(3)/), (/kt/), (/1/) )
133         istatus = NF90_PUT_VAR( idrun,  ids2, (/ zmax(4)/), (/kt/), (/1/) )
[10368]134         istatus = NF90_PUT_VAR( idrun,  idt1, (/-zmax(5)/), (/kt/), (/1/) )
135         istatus = NF90_PUT_VAR( idrun,  idt2, (/ zmax(6)/), (/kt/), (/1/) )
136         IF( ln_zad_Aimp ) THEN
137            istatus = NF90_PUT_VAR( idrun,  idw1, (/ zmax(8)/), (/kt/), (/1/) )
138            istatus = NF90_PUT_VAR( idrun,  idc1, (/ zmax(9)/), (/kt/), (/1/) )
139         ENDIF
[10358]140         IF( MOD( kt , 100 ) == 0 ) istatus = NF90_SYNC(idrun)
141         IF( kt == nitend         ) istatus = NF90_CLOSE(idrun)
142      END IF
143      !                                   !==  error handling  ==!
144      IF( ( ln_ctl .OR. lsomeoce ) .AND. (   &             ! have use mpp_max (because ln_ctl=.T.) or contains some ocean points
145         &  zmax(1) >   15._wp .OR.   &                    ! too large sea surface height ( > 15 m )
[9808]146         &  zmax(2) >   10._wp .OR.   &                    ! too large velocity ( > 10 m/s)
147         &  zmax(3) >=   0._wp .OR.   &                    ! negative or zero sea surface salinity
148         &  zmax(4) >= 100._wp .OR.   &                    ! too large sea surface salinity ( > 100 )
149         &  zmax(4) <    0._wp .OR.   &                    ! too large sea surface salinity (keep this line for sea-ice)
[10358]150         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) ) ) THEN   ! NaN encounter in the tests
151         IF( lk_mpp .AND. ln_ctl ) THEN
[10314]152            CALL mpp_maxloc( 'stpctl', ABS(sshn)        , ssmask(:,:)  , zzz, ih  )
153            CALL mpp_maxloc( 'stpctl', ABS(un)          , umask (:,:,:), zzz, iu  )
154            CALL mpp_minloc( 'stpctl', tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, is1 )
155            CALL mpp_maxloc( 'stpctl', tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, is2 )
[7852]156         ELSE
[10358]157            ih(:)  = MAXLOC( ABS( sshn(:,:)   )                              ) + (/ nimpp - 1, njmpp - 1    /)
158            iu(:)  = MAXLOC( ABS( un  (:,:,:) )                              ) + (/ nimpp - 1, njmpp - 1, 0 /)
159            is1(:) = MINLOC( tsn(:,:,:,jp_sal), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
160            is2(:) = MAXLOC( tsn(:,:,:,jp_sal), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
[7852]161         ENDIF
[10358]162         IF( numout == 6 )   &   ! force to open ocean.output file
163            CALL ctl_opn( numout, 'ocean.output', 'APPEND', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
164
165         WRITE(numout,cform_err)
166         WRITE(numout,*) ' stp_ctl: |ssh| > 10 m  or  |U| > 10 m/s  or  S <= 0  or  S >= 100  or  NaN encounter in the tests'
167         WRITE(numout,*) ' ======= '
168         IF( lk_mpp .AND. .NOT. ln_ctl ) WRITE(numout,*) 'E R R O R message from sub-domain: ', narea
169         WRITE(numout,9100) kt,   zmax(1), ih(1) , ih(2)
170         WRITE(numout,9200) kt,   zmax(2), iu(1) , iu(2) , iu(3)
171         WRITE(numout,9300) kt, - zmax(3), is1(1), is1(2), is1(3)
172         WRITE(numout,9400) kt,   zmax(4), is2(1), is2(2), is2(3)
173         WRITE(numout,*)
174         WRITE(numout,*) '          output of last computed fields in output.abort.nc file'
175         
176         CALL dia_wri_state( 'output.abort' )     ! create an output.abort file
177         
178         IF( ln_ctl ) THEN
179            kindic = -3
180            nstop = nstop + 1                            ! increase nstop by 1 (on all local domains)
181         ELSE
182            CALL ctl_stop()
183            CALL mppstop(ld_force_abort = .true.)
[7852]184         ENDIF
[9210]185         !
[7852]186      ENDIF
[10358]187      !
[9019]1889100  FORMAT (' kt=',i8,'   |ssh| max: ',1pg11.4,', at  i j  : ',2i5)
1899200  FORMAT (' kt=',i8,'   |U|   max: ',1pg11.4,', at  i j k: ',3i5)
[9808]1909300  FORMAT (' kt=',i8,'   S     min: ',1pg11.4,', at  i j k: ',3i5)
1919400  FORMAT (' kt=',i8,'   S     max: ',1pg11.4,', at  i j k: ',3i5)
1929500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
[7852]193      !
[3]194   END SUBROUTINE stp_ctl
195
196   !!======================================================================
197END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.