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

source: trunk/NEMO/OPA_SRC/stpctl.F90 @ 1561

Last change on this file since 1561 was 1561, checked in by ctlod, 15 years ago

Fix output state following an error state trapped by stpctl.F90, see ticket: #496

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.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   !!----------------------------------------------------------------------
12
13   !!----------------------------------------------------------------------
14   !!   stp_ctl      : Control the run
15   !!----------------------------------------------------------------------
16   USE oce             ! ocean dynamics and tracers variables
17   USE dom_oce         ! ocean space and time domain variables
18   USE sol_oce         ! ocean space and time domain variables
19   USE in_out_manager  ! I/O manager
20   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
21   USE lib_mpp         ! distributed memory computing
22   USE dynspg_oce      ! pressure gradient schemes
23
24   IMPLICIT NONE
25   PRIVATE
26
27   PUBLIC stp_ctl           ! routine called by step.F90
28   !!----------------------------------------------------------------------
29   !! NEMO/OPA 3.2 , LOCEAN-IPSL (2009)
30   !! $Id$
31   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
32   !!----------------------------------------------------------------------
33
34CONTAINS
35
36   SUBROUTINE stp_ctl( kt, kindic )
37      !!----------------------------------------------------------------------
38      !!                    ***  ROUTINE stp_ctl  ***
39      !!                     
40      !! ** Purpose :   Control the run
41      !!
42      !! ** Method  : - Save the time step in numstp
43      !!              - Print it each 50 time steps
44      !!              - Print solver statistics in numsol
45      !!              - Stop the run IF problem for the solver ( indec < 0 )
46      !!
47      !! ** Actions :   'time.step' file containing the last ocean time-step
48      !!               
49      !!----------------------------------------------------------------------
50      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
51      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
52      !!
53      INTEGER  ::   ji, jj, jk              ! dummy loop indices
54      INTEGER  ::   ii, ij, ik              ! temporary integers
55      REAL(wp) ::   zumax, zsmin, zssh2     ! temporary scalars
56      INTEGER, DIMENSION(3) ::   ilocu      !
57      INTEGER, DIMENSION(2) ::   ilocs      !
58      CHARACTER(len=80) :: clname
59      !!----------------------------------------------------------------------
60
61      IF( kt == nit000 .AND. lwp ) THEN
62         WRITE(numout,*)
63         WRITE(numout,*) 'stp_ctl : time-stepping control'
64         WRITE(numout,*) '~~~~~~~'
65         ! open time.step file
66         clname = 'time.step'
67         CALL ctlopn( numstp, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
68      ENDIF
69
70      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
71      IF(lwp) REWIND( numstp )                       !  --------------------------
72
73      !                                              !* Test maximum of velocity (zonal only)
74      !                                              !  ------------------------
75      !! zumax = MAXVAL( ABS( un(:,:,:) ) )                ! slower than the following loop on NEC SX5
76      zumax = 0.e0
77      DO jk = 1, jpk
78         DO jj = 1, jpj
79            DO ji = 1, jpi
80               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
81          END DO
82        END DO
83      END DO       
84      IF( lk_mpp )   CALL mpp_max( zumax )                 ! max over the global domain
85      !
86      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
87      !
88      IF( zumax > 20.e0 ) THEN
89         IF( lk_mpp ) THEN
90            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
91         ELSE
92            ilocu = MAXLOC( ABS( un(:,:,:) ) )
93            ii = ilocu(1) + nimpp - 1
94            ij = ilocu(2) + njmpp - 1
95            ik = ilocu(3)
96         ENDIF
97         IF(lwp) THEN
98            WRITE(numout,cform_err)
99            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
100            WRITE(numout,*) ' ====== '
101            WRITE(numout,9400) kt, zumax, ii, ij, ik
102            WRITE(numout,*)
103            WRITE(numout,*) '          output of last fields in numwso'
104         ENDIF
105         kindic = -3
106      ENDIF
1079400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
108
109      !                                              !* Test minimum of salinity
110      !                                              !  ------------------------
111      !! zsmin = MINVAL( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
112      zsmin = 100.e0
113      DO jj = 2, jpjm1
114         DO ji = 1, jpi
115            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,sn(ji,jj,1))
116         END DO
117      END DO
118      IF( lk_mpp )   CALL mpp_min( zsmin )                ! min over the global domain
119      !
120      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
121      !
122      IF( zsmin < 0.) THEN
123         IF (lk_mpp) THEN
124            CALL mpp_minloc ( sn(:,:,1),tmask(:,:,1), zsmin, ii,ij )
125         ELSE
126            ilocs = MINLOC( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )
127            ii = ilocs(1) + nimpp - 1
128            ij = ilocs(2) + njmpp - 1
129         ENDIF
130         !
131         IF(lwp) THEN
132            WRITE(numout,cform_err)
133            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
134            WRITE(numout,*) '======= '
135            WRITE(numout,9500) kt, zsmin, ii, ij
136            WRITE(numout,*)
137            WRITE(numout,*) '          output of last fields in numwso'
138         ENDIF
139         kindic = -3
140      ENDIF
1419500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
142
143      ! log file (solver or ssh statistics)
144      ! --------
145      IF( lk_dynspg_flt ) THEN      ! elliptic solver statistics (if required)
146         !
147         IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps      ! Solver
148         !
149         IF( kindic < 0 .AND. zsmin > 0.e0 .AND. zumax <= 20.e0 ) THEN                                          ! create a abort file if problem found
150            IF(lwp) THEN
151               WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
152               WRITE(numout,*) ' ====== '
153               WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
154               WRITE(numout,*)
155               WRITE(numout,*) ' stpctl: output of last fields'
156               WRITE(numout,*) ' ======  '
157            ENDIF
158         ENDIF
159         !
160      ELSE                                            !* ssh statistics (and others...)
161         IF( kt == nit000 ) THEN      ! open ssh statistics file (put in solver.stat file)
162            CALL ctlopn( numsol, 'solver.stat', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
163         ENDIF
164         !
165         zssh2 = SUM( sshn(:,:) * sshn(:,:) * tmask_i(:,:) )
166         IF( lk_mpp )   CALL mpp_sum( zssh2 )      ! sum over the global domain
167         !
168         IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
169         !
170      ENDIF
171
1729200  FORMAT(' it :', i8, ' niter :', i4, ' res :',e20.10,' b :',e20.10)
1739300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
174      !
175   END SUBROUTINE stp_ctl
176
177   !!======================================================================
178END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.