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

source: branches/nemo_v3_3_beta/NEMOGCM/NEMO/OPA_SRC/stpctl.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: 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.3 , NEMO Consortium (2010)
30   !! $Id$
31   !! Software governed by the CeCILL licence (NEMOGCM/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      !!----------------------------------------------------------------------
59
60      IF( kt == nit000 .AND. lwp ) THEN
61         WRITE(numout,*)
62         WRITE(numout,*) 'stp_ctl : time-stepping control'
63         WRITE(numout,*) '~~~~~~~'
64         ! open time.step file
65         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
66      ENDIF
67
68      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
69      IF(lwp) REWIND( numstp )                       !  --------------------------
70
71      !                                              !* Test maximum of velocity (zonal only)
72      !                                              !  ------------------------
73      !! zumax = MAXVAL( ABS( un(:,:,:) ) )                ! slower than the following loop on NEC SX5
74      zumax = 0.e0
75      DO jk = 1, jpk
76         DO jj = 1, jpj
77            DO ji = 1, jpi
78               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
79          END DO
80        END DO
81      END DO       
82      IF( lk_mpp )   CALL mpp_max( zumax )                 ! max over the global domain
83      !
84      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
85      !
86      IF( zumax > 20.e0 ) THEN
87         IF( lk_mpp ) THEN
88            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
89         ELSE
90            ilocu = MAXLOC( ABS( un(:,:,:) ) )
91            ii = ilocu(1) + nimpp - 1
92            ij = ilocu(2) + njmpp - 1
93            ik = ilocu(3)
94         ENDIF
95         IF(lwp) THEN
96            WRITE(numout,cform_err)
97            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
98            WRITE(numout,*) ' ====== '
99            WRITE(numout,9400) kt, zumax, ii, ij, ik
100            WRITE(numout,*)
101            WRITE(numout,*) '          output of last fields in numwso'
102         ENDIF
103         kindic = -3
104      ENDIF
1059400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
106
107      !                                              !* Test minimum of salinity
108      !                                              !  ------------------------
109      !! zsmin = MINVAL( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
110      zsmin = 100.e0
111      DO jj = 2, jpjm1
112         DO ji = 1, jpi
113            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,sn(ji,jj,1))
114         END DO
115      END DO
116      IF( lk_mpp )   CALL mpp_min( zsmin )                ! min over the global domain
117      !
118      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
119      !
120      IF( zsmin < 0.) THEN
121         IF (lk_mpp) THEN
122            CALL mpp_minloc ( sn(:,:,1),tmask(:,:,1), zsmin, ii,ij )
123         ELSE
124            ilocs = MINLOC( sn(:,:,1), mask = tmask(:,:,1) == 1.e0 )
125            ii = ilocs(1) + nimpp - 1
126            ij = ilocs(2) + njmpp - 1
127         ENDIF
128         !
129         IF(lwp) THEN
130            WRITE(numout,cform_err)
131            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
132            WRITE(numout,*) '======= '
133            WRITE(numout,9500) kt, zsmin, ii, ij
134            WRITE(numout,*)
135            WRITE(numout,*) '          output of last fields in numwso'
136         ENDIF
137         kindic = -3
138      ENDIF
1399500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
140
141      ! log file (solver or ssh statistics)
142      ! --------
143      IF( lk_dynspg_flt ) THEN      ! elliptic solver statistics (if required)
144         !
145         IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps       ! Solver
146         !
147         IF( kindic < 0 .AND. zsmin > 0.e0 .AND. zumax <= 20.e0 ) THEN   ! create a abort file if problem found
148            IF(lwp) THEN
149               WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
150               WRITE(numout,*) ' ====== '
151               WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
152               WRITE(numout,*)
153               WRITE(numout,*) ' stpctl: output of last fields'
154               WRITE(numout,*) ' ======  '
155            ENDIF
156         ENDIF
157         !
158      ELSE                                   !* ssh statistics (and others...)
159         IF( kt == nit000 .AND. lwp ) THEN   ! open ssh statistics file (put in solver.stat file)
160            CALL ctl_opn( numsol, 'solver.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
161         ENDIF
162         !
163         zssh2 = SUM( sshn(:,:) * sshn(:,:) * tmask_i(:,:) )
164         IF( lk_mpp )   CALL mpp_sum( zssh2 )      ! sum over the global domain
165         !
166         IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
167         !
168      ENDIF
169
1709200  FORMAT('it:', i8, ' iter:', i4, ' r: ',e16.10, ' b: ',e16.10 )
1719300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
172      !
173   END SUBROUTINE stp_ctl
174
175   !!======================================================================
176END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.