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/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/UKMO/dev_1d_bugfixes_tocommit/NEMOGCM/NEMO/OPA_SRC/stpctl.F90 @ 13190

Last change on this file since 13190 was 10302, checked in by dford, 5 years ago

Merge in revisions 8447:10159 of dev_r5518_GO6_package.

File size: 10.9 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 sbc_oce         ! surface boundary conditions variables
20   USE in_out_manager  ! I/O manager
21   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
22   USE lib_mpp         ! distributed memory computing
23   USE dynspg_oce      ! pressure gradient schemes
24   USE c1d             ! 1D vertical configuration
25
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC stp_ctl           ! routine called by step.F90
31   !!----------------------------------------------------------------------
32   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
33   !! $Id$
34   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
35   !!----------------------------------------------------------------------
36
37CONTAINS
38
39   SUBROUTINE stp_ctl( kt, kindic )
40      !!----------------------------------------------------------------------
41      !!                    ***  ROUTINE stp_ctl  ***
42      !!                     
43      !! ** Purpose :   Control the run
44      !!
45      !! ** Method  : - Save the time step in numstp
46      !!              - Print it each 50 time steps
47      !!              - Print solver statistics in numsol
48      !!              - Stop the run IF problem for the solver ( indec < 0 )
49      !!
50      !! ** Actions :   'time.step' file containing the last ocean time-step
51      !!               
52      !!----------------------------------------------------------------------
53      INTEGER, INTENT( in ) ::   kt         ! ocean time-step index
54      INTEGER, INTENT( inout ) ::   kindic  ! indicator of solver convergence
55      !!
56      CHARACTER(len = 32) ::        clfname ! time stepping output file name
57      INTEGER  ::   ji, jj, jk              ! dummy loop indices
58      INTEGER  ::   ii, ij, ik              ! temporary integers
59      REAL(wp) ::   zumax, zsmin, zssh2     ! temporary scalars
60      REAL(wp) ::   ztmax, ztmin            ! Scalar to get temperature extreme
61                                            ! values and warn if they're out of Range
62      INTEGER, DIMENSION(3) ::   ilocu      !
63      INTEGER, DIMENSION(2) ::   ilocs      !
64      !!----------------------------------------------------------------------
65
66      IF( kt == nit000 .AND. lwp ) THEN
67         WRITE(numout,*)
68         WRITE(numout,*) 'stp_ctl : time-stepping control'
69         WRITE(numout,*) '~~~~~~~'
70         ! open time.step file with special treatment for SAS
71         IF ( nn_components == jp_iam_sas ) THEN
72            clfname = 'time.step.sas'
73         ELSE
74            clfname = 'time.step'
75         ENDIF
76         CALL ctl_opn( numstp, TRIM(clfname), 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
77      ENDIF
78
79      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
80      IF(lwp) REWIND( numstp )                       !  --------------------------
81
82      !                                              !* Test maximum of velocity (zonal only)
83      !                                              !  ------------------------
84      !! zumax = MAXVAL( ABS( un(:,:,:) ) )                ! slower than the following loop on NEC SX5
85      zumax = 0.e0
86      DO jk = 1, jpk
87         DO jj = 1, jpj
88            DO ji = 1, jpi
89               zumax = MAX(zumax,ABS(un(ji,jj,jk)))
90          END DO
91        END DO
92      END DO       
93      IF( lk_mpp )   CALL mpp_max( zumax )                 ! max over the global domain
94      !
95      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' abs(U) max: ', zumax
96      !
97      IF( zumax > 20.e0 ) THEN
98         IF( lk_mpp ) THEN
99            CALL mpp_maxloc(ABS(un),umask,zumax,ii,ij,ik)
100         ELSE
101            ilocu = MAXLOC( ABS( un(:,:,:) ) )
102            ii = ilocu(1) + nimpp - 1
103            ij = ilocu(2) + njmpp - 1
104            ik = ilocu(3)
105         ENDIF
106         IF(lwp) THEN
107            WRITE(numout,cform_err)
108            WRITE(numout,*) ' stpctl: the zonal velocity is larger than 20 m/s'
109            WRITE(numout,*) ' ====== '
110            WRITE(numout,9400) kt, zumax, ii, ij, ik
111            WRITE(numout,*)
112            WRITE(numout,*) '          output of last fields in numwso'
113         ENDIF
114         kindic = -3
115      ENDIF
1169400  FORMAT (' kt=',i6,' max abs(U): ',1pg11.4,', i j k: ',3i5)
117
118      !                                              !* Test minimum of salinity
119      !                                              !  ------------------------
120      !! zsmin = MINVAL( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )  slower than the following loop on NEC SX5
121      zsmin = 100.e0
122      DO jj = 2, jpjm1
123         DO ji = 1, jpi
124            IF( tmask(ji,jj,1) == 1) zsmin = MIN(zsmin,tsn(ji,jj,1,jp_sal))
125         END DO
126      END DO
127      IF( lk_mpp )   CALL mpp_min( zsmin )                ! min over the global domain
128      !
129      IF( MOD( kt, nwrite ) == 1 .AND. lwp )   WRITE(numout,*) ' ==>> time-step= ',kt,' SSS min:', zsmin
130      !
131      IF( zsmin < 0.) THEN
132         IF (lk_mpp) THEN
133            CALL mpp_minloc ( tsn(:,:,1,jp_sal),tmask(:,:,1), zsmin, ii,ij )
134         ELSE
135            ilocs = MINLOC( tsn(:,:,1,jp_sal), mask = tmask(:,:,1) == 1.e0 )
136            ii = ilocs(1) + nimpp - 1
137            ij = ilocs(2) + njmpp - 1
138         ENDIF
139         !
140         IF(lwp) THEN
141            WRITE(numout,cform_err)
142            WRITE(numout,*) 'stp_ctl : NEGATIVE sea surface salinity'
143            WRITE(numout,*) '======= '
144            WRITE(numout,9500) kt, zsmin, ii, ij
145            WRITE(numout,*)
146            WRITE(numout,*) '          output of last fields in numwso'
147         ENDIF
148         kindic = -3
149      ENDIF
1509500  FORMAT (' kt=',i6,' min SSS: ',1pg11.4,', i j: ',2i5)
151
152! ====================================================================================================
153! ====================================================================================================
154      !                                              !AXY (25/10/17)
155      !                                              !* Test max/min limits of temperature
156      !                                              !  ----------------------------------
157      ztmax =  -5.e0  ! arbitrary  low maximum value
158      ztmin = 100.e0  ! arbitrary high minimum value
159      DO jj = 2, jpjm1
160         DO ji = 2, jpim1
161            IF( tmask(ji,jj,1) == 1) THEN
162               ztmax = MAX(ztmax,tsn(ji,jj,1,jp_tem))     ! find local maximum
163               ztmin = MIN(ztmin,tsn(ji,jj,1,jp_tem))     ! find local minimum
164            ENDIF
165         END DO
166      END DO
167      IF( lk_mpp )   CALL mpp_max( ztmax )                ! max over the global domain
168      IF( lk_mpp )   CALL mpp_min( ztmin )                ! min over the global domain
169      !
170      IF( ztmax > 40.) THEN  ! we've got a problem
171         IF (lk_mpp) THEN
172            CALL mpp_maxloc ( tsn(:,:,1,jp_tem),tmask(:,:,1), ztmax, ii,ij )
173         ELSE
174            ilocs = MAXLOC( tsn(:,:,1,jp_tem), mask = tmask(:,:,1) == 1.e0 )
175            ii = ilocs(1) + nimpp - 1
176            ij = ilocs(2) + njmpp - 1
177         ENDIF
178         !
179         IF(lwp) THEN
180            WRITE(numout,*) 'stp_ctl:tracer anomaly: *****    WARNING     *****'
181            WRITE(numout,*) 'stp_ctl:tracer anomaly: sea surface temperature > 40C'
182            WRITE(numout,9600) kt, ztmax, ii, ij
183            WRITE(numout,*) 'stp_ctl:tracer anomaly: ***** END OF WARNING *****'
184         ENDIF
185      ENDIF
186      !
187      IF( ztmin < -10.) THEN  ! we've got a problem
188         IF (lk_mpp) THEN
189            CALL mpp_minloc ( tsn(:,:,1,jp_tem),tmask(:,:,1), ztmin, ii,ij )
190         ELSE
191            ilocs = MINLOC( tsn(:,:,1,jp_tem), mask = tmask(:,:,1) == 1.e0 )
192            ii = ilocs(1) + nimpp - 1
193            ij = ilocs(2) + njmpp - 1
194         ENDIF
195         !
196         IF(lwp) THEN
197            WRITE(numout,*) 'stp_ctl:tracer anomaly: *****    WARNING     *****'
198            WRITE(numout,*) 'stp_ctl:tracer anomaly: sea surface temperature < -10C'
199            WRITE(numout,9700) kt, ztmin, ii, ij
200            WRITE(numout,*) 'stp_ctl:tracer anomaly: ***** END OF WARNING *****'
201         ENDIF
202      ENDIF
2039600  FORMAT ('stp_ctl:tracer anomaly: kt=',i6,' max SST: ',f16.10,', i j: ',2i5)
2049700  FORMAT ('stp_ctl:tracer anomaly: kt=',i6,' min SST: ',f16.10,', i j: ',2i5)
205! ====================================================================================================
206! ====================================================================================================
207     
208      IF( lk_c1d )  RETURN          ! No log file in case of 1D vertical configuration
209
210      ! log file (solver or ssh statistics)
211      ! --------
212      IF( lk_dynspg_flt ) THEN      ! elliptic solver statistics (if required)
213         !
214         IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps       ! Solver
215         !
216         IF( kindic < 0 .AND. zsmin > 0.e0 .AND. zumax <= 20.e0 ) THEN   ! create a abort file if problem found
217            IF(lwp) THEN
218               WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
219               WRITE(numout,*) ' ====== '
220               WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
221               WRITE(numout,*)
222               WRITE(numout,*) ' stpctl: output of last fields'
223               WRITE(numout,*) ' ======  '
224            ENDIF
225         ENDIF
226         !
227      ELSE                                   !* ssh statistics (and others...)
228         IF( kt == nit000 .AND. lwp ) THEN   ! open ssh statistics file (put in solver.stat file)
229            CALL ctl_opn( numsol, 'solver.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
230         ENDIF
231         !
232         zssh2 = SUM( sshn(:,:) * sshn(:,:) * tmask_i(:,:) )
233         IF( lk_mpp )   CALL mpp_sum( zssh2 )      ! sum over the global domain
234         !
235         IF(lwp) WRITE(numsol,9300) kt, zssh2, zumax, zsmin      ! ssh statistics
236         !
237      ENDIF
238
2399200  FORMAT('it:', i8, ' iter:', i4, ' r: ',e16.10, ' b: ',e16.10 )
2409300  FORMAT(' it :', i8, ' ssh2: ', e16.10, ' Umax: ',e16.10,' Smin: ',e16.10)
241      !
242   END SUBROUTINE stp_ctl
243
244   !!======================================================================
245END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.