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_r13312_AGRIF-03-04_jchanut_vinterp_tstep/tests/DOME/MY_SRC – NEMO

source: NEMO/branches/2020/dev_r13312_AGRIF-03-04_jchanut_vinterp_tstep/tests/DOME/MY_SRC/stpctl.F90 @ 13930

Last change on this file since 13930 was 13930, checked in by jchanut, 3 years ago

#2222, add DOME overflow experiment

File size: 18.2 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 zdf_oce ,  ONLY : ln_zad_Aimp       ! ocean vertical physics variables
22   USE wet_dry,   ONLY : ll_wd, ssh_ref    ! reference depth for negative bathy
23   
24   USE diawri          ! Standard run outputs       (dia_wri_state routine)
25   USE in_out_manager  ! I/O manager
26   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
27   USE lib_mpp         ! distributed memory computing
28   USE eosbn2
29   !
30   USE netcdf          ! NetCDF library
31   IMPLICIT NONE
32   PRIVATE
33
34   PUBLIC stp_ctl           ! routine called by step.F90
35
36   INTEGER                ::   nrunid   ! netcdf file id
37   INTEGER, DIMENSION(8)  ::   nvarid   ! netcdf variable id
38   !!----------------------------------------------------------------------
39   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
40   !! $Id: stpctl.F90 13216 2020-07-02 09:25:49Z rblod $
41   !! Software governed by the CeCILL license (see ./LICENSE)
42   !!----------------------------------------------------------------------
43CONTAINS
44
45   SUBROUTINE stp_ctl( kt, Kmm )
46      !!----------------------------------------------------------------------
47      !!                    ***  ROUTINE stp_ctl  ***
48      !!                     
49      !! ** Purpose :   Control the run
50      !!
51      !! ** Method  : - Save the time step in numstp
52      !!              - Print it each 50 time steps
53      !!              - Stop the run IF problem encountered by setting nstop > 0
54      !!                Problems checked: |ssh| maximum larger than 10 m
55      !!                                  |U|   maximum larger than 10 m/s
56      !!                                  negative sea surface salinity
57      !!
58      !! ** Actions :   "time.step" file = last ocean time-step
59      !!                "run.stat"  file = run statistics
60      !!                 nstop indicator sheared among all local domain
61      !!----------------------------------------------------------------------
62      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
63      INTEGER, INTENT(in   ) ::   Kmm      ! ocean time level index
64      !!
65      INTEGER                         ::   ji                                    ! dummy loop indices
66      INTEGER                         ::   idtime, istatus
67      INTEGER , DIMENSION(9)          ::   iareasum, iareamin, iareamax
68      INTEGER , DIMENSION(3,4)        ::   iloc                                  ! min/max loc indices
69      REAL(wp)                        ::   zzz                                   ! local real
70      REAL(wp), DIMENSION(9)          ::   zmax, zmaxlocal
71      LOGICAL                         ::   ll_wrtstp, ll_colruns, ll_wrtruns
72      LOGICAL, DIMENSION(jpi,jpj,jpk) ::   llmsk
73      CHARACTER(len=20)               ::   clname
74      !!----------------------------------------------------------------------
75      IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
76      !
77      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
78      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 
79      ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm
80      !
81      IF( kt == nit000 ) THEN
82         !
83         IF( lwp ) THEN
84            WRITE(numout,*)
85            WRITE(numout,*) 'stp_ctl : time-stepping control'
86            WRITE(numout,*) '~~~~~~~'
87         ENDIF
88         !                                ! open time.step    ascii file, done only by 1st subdomain
89         IF( lwm )   CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
90         !
91         IF( ll_wrtruns ) THEN
92            !                             ! open run.stat     ascii file, done only by 1st subdomain
93            CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
94            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
95            clname = 'run.stat.nc'
96            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
97            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
98            istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime )
99            istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) )
100            istatus = NF90_DEF_VAR( nrunid,   'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) )
101            istatus = NF90_DEF_VAR( nrunid,       's_min', NF90_DOUBLE, (/ idtime /), nvarid(3) )
102            istatus = NF90_DEF_VAR( nrunid,       's_max', NF90_DOUBLE, (/ idtime /), nvarid(4) )
103            istatus = NF90_DEF_VAR( nrunid,       't_min', NF90_DOUBLE, (/ idtime /), nvarid(5) )
104            istatus = NF90_DEF_VAR( nrunid,       't_max', NF90_DOUBLE, (/ idtime /), nvarid(6) )
105            IF( ln_zad_Aimp ) THEN
106               istatus = NF90_DEF_VAR( nrunid,   'Cf_max', NF90_DOUBLE, (/ idtime /), nvarid(7) )
107               istatus = NF90_DEF_VAR( nrunid,'abs_wi_max',NF90_DOUBLE, (/ idtime /), nvarid(8) )
108            ENDIF
109            istatus = NF90_ENDDEF(nrunid)
110         ENDIF
111         !   
112      ENDIF
113      !
114      !                                   !==              write current time step              ==!
115      !                                   !==  done only by 1st subdomain at writting timestep  ==!
116      IF( lwm .AND. ll_wrtstp ) THEN
117         WRITE ( numstp, '(1x, i8)' )   kt
118         REWIND( numstp )
119      ENDIF
120      !                                   !==            test of local extrema           ==!
121      !                                   !==  done by all processes at every time step  ==!
122      llmsk(:,:,1) = ssmask(:,:) == 1._wp
123      IF( ll_wd ) THEN
124         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) )   ! ssh max
125      ELSE
126         zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm)           ), mask = llmsk(:,:,1) )   ! ssh max
127      ENDIF
128      llmsk(:,:,:) = umask(:,:,:) == 1._wp
129      zmax(2) = MAXVAL(  ABS( uu(:,:,:,Kmm) ), mask = llmsk )                     ! velocity max (zonal only)
130      llmsk(:,:,:) = tmask(:,:,:) == 1._wp
131      IF ( ln_seos.AND.(rn_lambda2==0._wp) ) THEN ! Discard checks on salinity
132         zmax(3) = -99._wp
133         zmax(4) = 99._wp
134      ELSE
135         zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk )                  ! minus salinity max
136         zmax(4) = MAXVAL(  ts(:,:,:,jp_sal,Kmm), mask = llmsk )                  !       salinity max
137      ENDIF
138      IF( ll_colruns .OR. jpnij == 1 ) THEN     ! following variables are used only in the netcdf file
139         zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  ! minus temperature max
140         zmax(6) = MAXVAL(  ts(:,:,:,jp_tem,Kmm), mask = llmsk )                  !       temperature max
141         IF( ln_zad_Aimp ) THEN
142            zmax(7) = MAXVAL(   Cu_adv(:,:,:)   , mask = llmsk )                  ! partitioning coeff. max
143            llmsk(:,:,:) = wmask(:,:,:) == 1._wp
144            zmax(8) = MAXVAL(  ABS( wi(:,:,:) ) , mask = llmsk )                  ! implicit vertical vel. max
145         ELSE
146            zmax(7:8) = 0._wp
147         ENDIF
148      ELSE
149         zmax(5:8) = 0._wp
150      ENDIF
151      zmax(9) = REAL( nstop, wp )                                              ! stop indicator
152      !                                   !==               get global extrema             ==!
153      !                                   !==  done by all processes if writting run.stat  ==!
154      IF( ll_colruns ) THEN
155         zmaxlocal(:) = zmax(:)
156         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
157         nstop = NINT( zmax(9) )                 ! update nstop indicator (now sheared among all local domains)
158      ENDIF
159      !                                   !==              write "run.stat" files              ==!
160      !                                   !==  done only by 1st subdomain at writting timestep  ==!
161      IF( ll_wrtruns ) THEN
162         WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4)
163         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) )
164         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) )
165         istatus = NF90_PUT_VAR( nrunid, nvarid(3), (/-zmax(3)/), (/kt/), (/1/) )
166         istatus = NF90_PUT_VAR( nrunid, nvarid(4), (/ zmax(4)/), (/kt/), (/1/) )
167         istatus = NF90_PUT_VAR( nrunid, nvarid(5), (/-zmax(5)/), (/kt/), (/1/) )
168         istatus = NF90_PUT_VAR( nrunid, nvarid(6), (/ zmax(6)/), (/kt/), (/1/) )
169         IF( ln_zad_Aimp ) THEN
170            istatus = NF90_PUT_VAR( nrunid, nvarid(7), (/ zmax(7)/), (/kt/), (/1/) )
171            istatus = NF90_PUT_VAR( nrunid, nvarid(8), (/ zmax(8)/), (/kt/), (/1/) )
172         ENDIF
173         IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
174      END IF
175      !                                   !==               error handling               ==!
176      !                                   !==  done by all processes at every time step  ==!
177      !
178      IF(   zmax(1) >   20._wp .OR.   &                   ! too large sea surface height ( > 20 m )
179         &  zmax(2) >   10._wp .OR.   &                   ! too large velocity ( > 10 m/s)
180         &  zmax(3) >=   0._wp .OR.   &                   ! negative or zero sea surface salinity
181         &  zmax(4) >= 100._wp .OR.   &                   ! too large sea surface salinity ( > 100 )
182         &  zmax(4) <    0._wp .OR.   &                   ! too large sea surface salinity (keep this line for sea-ice)
183         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) .OR.   &               ! NaN encounter in the tests
184         &  ABS(   zmax(1) + zmax(2) + zmax(3) ) > HUGE(1._wp) ) THEN   ! Infinity encounter in the tests
185         !
186         iloc(:,:) = 0
187         IF( ll_colruns ) THEN   ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc
188            ! first: close the netcdf file, so we can read it
189            IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
190            ! get global loc on the min/max
191            CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:,         Kmm)), ssmask(:,:  ), zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F
192            CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,       Kmm)),  umask(:,:,:), zzz, iloc(1:3,2) )
193            CALL mpp_minloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,3) )
194            CALL mpp_maxloc( 'stpctl',      ts(:,:,:,jp_sal,Kmm) ,  tmask(:,:,:), zzz, iloc(1:3,4) )
195            ! find which subdomain has the max.
196            iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
197            DO ji = 1, 9
198               IF( zmaxlocal(ji) == zmax(ji) ) THEN
199                  iareamin(ji) = narea   ;   iareamax(ji) = narea   ;   iareasum(ji) = 1
200               ENDIF
201            END DO
202            CALL mpp_min( "stpctl", iareamin )         ! min over the global domain
203            CALL mpp_max( "stpctl", iareamax )         ! max over the global domain
204            CALL mpp_sum( "stpctl", iareasum )         ! sum over the global domain
205         ELSE                    ! find local min and max locations:
206            ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
207            iloc(1:2,1) = MAXLOC( ABS( ssh(:,:,         Kmm)), mask = ssmask(:,:  ) == 1._wp ) + (/ nimpp - 1, njmpp - 1    /)
208            iloc(1:3,2) = MAXLOC( ABS(  uu(:,:,:,       Kmm)), mask =  umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
209            iloc(1:3,3) = MINLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
210            iloc(1:3,4) = MAXLOC(       ts(:,:,:,jp_sal,Kmm) , mask =  tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /)
211            iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
212         ENDIF
213         !
214         WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m  or  |U| > 10 m/s  or  S <= 0  or  S >= 100  or  NaN encounter in the tests'
215         CALL wrt_line( ctmp2, kt, '|ssh| max',  zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
216         CALL wrt_line( ctmp3, kt, '|U|   max',  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
217         CALL wrt_line( ctmp4, kt, 'Sal   min', -zmax(3), iloc(:,3), iareasum(3), iareamin(3), iareamax(3) )
218         CALL wrt_line( ctmp5, kt, 'Sal   max',  zmax(4), iloc(:,4), iareasum(4), iareamin(4), iareamax(4) )
219         IF( Agrif_Root() ) THEN
220            WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort* files'
221         ELSE
222            WRITE(ctmp6,*) '      ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files'
223         ENDIF
224         !
225         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
226         !
227         IF( ll_colruns .or. jpnij == 1 ) THEN   ! all processes synchronized -> use lwp to print in opened ocean.output files
228            IF(lwp) THEN   ;   CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
229            ELSE           ;   nstop = MAX(1, nstop)   ! make sure nstop > 0 (automatically done when calling ctl_stop)
230            ENDIF
231         ELSE                                    ! only mpi subdomains with errors are here -> STOP now
232            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
233         ENDIF
234         !
235      ENDIF
236      !
237      IF( nstop > 0 ) THEN                                                  ! an error was detected and we did not abort yet...
238         ngrdstop = Agrif_Fixed()                                           ! store which grid got this error
239         IF( .NOT. ll_colruns .AND. jpnij > 1 )   CALL ctl_stop( 'STOP' )   ! we must abort here to avoid MPI deadlock
240      ENDIF
241      !
2429500  FORMAT(' it :', i8, '    |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16)
243      !
244   END SUBROUTINE stp_ctl
245
246
247   SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax )
248      !!----------------------------------------------------------------------
249      !!                     ***  ROUTINE wrt_line  ***
250      !!
251      !! ** Purpose :   write information line
252      !!
253      !!----------------------------------------------------------------------
254      CHARACTER(len=*),      INTENT(  out) ::   cdline
255      CHARACTER(len=*),      INTENT(in   ) ::   cdprefix
256      REAL(wp),              INTENT(in   ) ::   pval
257      INTEGER, DIMENSION(3), INTENT(in   ) ::   kloc
258      INTEGER,               INTENT(in   ) ::   kt, ksum, kmin, kmax
259      !
260      CHARACTER(len=80) ::   clsuff
261      CHARACTER(len=9 ) ::   clkt, clsum, clmin, clmax
262      CHARACTER(len=9 ) ::   cli, clj, clk
263      CHARACTER(len=1 ) ::   clfmt
264      CHARACTER(len=4 ) ::   cl4   ! needed to be able to compile with Agrif, I don't know why
265      INTEGER           ::   ifmtk
266      !!----------------------------------------------------------------------
267      WRITE(clkt , '(i9)') kt
268     
269      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij  ,wp))) + 1     ! how many digits to we need to write ? (we decide max = 9)
270      !!! WRITE(clsum, '(i'//clfmt//')') ksum                   ! this is creating a compilation error with AGRIF
271      cl4 = '(i'//clfmt//')'   ;   WRITE(clsum, cl4) ksum
272      WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1    ! how many digits to we need to write ? (we decide max = 9)
273      cl4 = '(i'//clfmt//')'   ;   WRITE(clmin, cl4) kmin-1
274                                   WRITE(clmax, cl4) kmax-1
275      !
276      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1      ! how many digits to we need to write jpiglo? (we decide max = 9)
277      cl4 = '(i'//clfmt//')'   ;   WRITE(cli, cl4) kloc(1)      ! this is ok with AGRIF
278      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1      ! how many digits to we need to write jpjglo? (we decide max = 9)
279      cl4 = '(i'//clfmt//')'   ;   WRITE(clj, cl4) kloc(2)      ! this is ok with AGRIF
280      !
281      IF( ksum == 1 ) THEN   ;   WRITE(clsuff,9100) TRIM(clmin)
282      ELSE                   ;   WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax)
283      ENDIF
284      IF(kloc(3) == 0) THEN
285         ifmtk = INT(LOG10(REAL(jpk,wp))) + 1                   ! how many digits to we need to write jpk? (we decide max = 9)
286         clk = REPEAT(' ', ifmtk)                               ! create the equivalent in blank string
287         WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff)
288      ELSE
289         WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1      ! how many digits to we need to write jpk? (we decide max = 9)
290         !!! WRITE(clk, '(i'//clfmt//')') kloc(3)               ! this is creating a compilation error with AGRIF
291         cl4 = '(i'//clfmt//')'   ;   WRITE(clk, cl4) kloc(3)   ! this is ok with AGRIF
292         WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj),    TRIM(clk), TRIM(clsuff)
293      ENDIF
294      !
2959100  FORMAT('MPI rank ', a)
2969200  FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a)
2979300  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j   ', a, ' ', a, ' ', a, ' ', a)
2989400  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a)
299      !
300   END SUBROUTINE wrt_line
301
302
303   !!======================================================================
304END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.