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_r13383_HPC-02_Daley_Tiling/src/SWE – NEMO

source: NEMO/branches/2020/dev_r13383_HPC-02_Daley_Tiling/src/SWE/stpctl.F90 @ 13553

Last change on this file since 13553 was 13553, checked in by hadcv, 4 years ago

Merge in trunk up to [13550]

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