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/SAS – NEMO

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

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

Merge in trunk up to [13550]

  • Property svn:keywords set to Id
File size: 16.3 KB
Line 
1MODULE stpctl
2   !!======================================================================
3   !!                       ***  MODULE  stpctl  ***
4   !! Ocean run control :  gross check of the ocean time stepping
5   !!                      version for standalone surface scheme
6   !!======================================================================
7   !! History :  OPA  ! 1991-03  (G. Madec) Original code
8   !!            6.0  ! 1992-06  (M. Imbard)
9   !!            8.0  ! 1997-06  (A.M. Treguier)
10   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
11   !!            2.0  ! 2009-07  (G. Madec)  Add statistic for time-spliting
12   !!            3.5  ! 2012-03  (S. Alderson)
13   !!            4.0  ! 2017-04  (G. Madec)  regroup global communications
14   !!----------------------------------------------------------------------
15
16   !!----------------------------------------------------------------------
17   !!   stp_ctl      : Control the run
18   !!----------------------------------------------------------------------
19   USE oce             ! ocean dynamics and tracers variables
20   USE dom_oce         ! ocean space and time domain variables
21   USE ice      , ONLY : vt_i, u_ice, tm_i
22   USE phycst   , ONLY : rt0
23   USE sbc_oce  , ONLY : lk_oasis
24   !
25   USE diawri          ! Standard run outputs       (dia_wri_state routine)
26   USE in_out_manager  ! I/O manager
27   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
28   USE lib_mpp         ! distributed memory computing
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(3)  ::   nvarid   ! netcdf variable id
38   !!----------------------------------------------------------------------
39   !! NEMO/SAS 4.0 , NEMO Consortium (2018)
40   !! $Id$
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      !!              - Stop the run IF problem encountered by setting nstop > 0
53      !!                Problems checked: ice thickness maximum > 100 m
54      !!                                  ice velocity  maximum > 10 m/s
55      !!                                  min ice temperature   < -100 degC
56      !!
57      !! ** Actions :   "time.step" file = last ocean time-step
58      !!                "run.stat"  file = run statistics
59      !!                 nstop indicator sheared among all local domain
60      !!----------------------------------------------------------------------
61      INTEGER, INTENT(in   ) ::   kt       ! ocean time-step index
62      INTEGER, INTENT(in   ) ::   Kmm      ! ocean time level index
63      !!
64      INTEGER                         ::   ji                                    ! dummy loop indices
65      INTEGER                         ::   idtime, istatus
66      INTEGER , DIMENSION(4)          ::   iareasum, iareamin, iareamax
67      INTEGER , DIMENSION(3,3)        ::   iloc                                  ! min/max loc indices
68      REAL(wp)                        ::   zzz                                   ! local real
69      REAL(wp), DIMENSION(4)          ::   zmax, zmaxlocal
70      LOGICAL                         ::   ll_wrtstp, ll_colruns, ll_wrtruns
71      LOGICAL, DIMENSION(jpi,jpj)     ::   llmsk
72      CHARACTER(len=20)               ::   clname
73      !!----------------------------------------------------------------------
74      IF( nstop > 0 .AND. ngrdstop > -1 )   RETURN   !   stpctl was already called by a child grid
75      !
76      ll_wrtstp  = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend )
77      ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 
78      ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm
79      !
80      IF( kt == nit000 ) THEN
81         !
82         IF( lwp ) THEN
83            WRITE(numout,*)
84            WRITE(numout,*) 'stp_ctl : time-stepping control'
85            WRITE(numout,*) '~~~~~~~'
86         ENDIF
87         !                                ! open time.step    ascii file, done only by 1st subdomain
88         IF( lk_oasis ) THEN   ;   clname = 'time_sas.step'
89         ELSE                  ;   clname = 'time.step'
90         ENDIF
91         IF( lwm )   CALL ctl_opn( numstp, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
92         !
93         IF( ll_wrtruns ) THEN
94            IF( lk_oasis ) THEN   ;   clname = 'run_sas.stat'
95            ELSE                  ;   clname = 'run.stat'
96            ENDIF
97            !                             ! open run.stat     ascii file, done only by 1st subdomain
98            CALL ctl_opn( numrun, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
99            !                             ! open run.stat.nc netcdf file, done only by 1st subdomain
100            clname = TRIM(clname)//'.nc'
101            IF( .NOT. Agrif_Root() )   clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname)
102            istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid )
103            istatus = NF90_DEF_DIM( nrunid, 'time'     , NF90_UNLIMITED, idtime )
104            istatus = NF90_DEF_VAR( nrunid, 'vt_i_max' , NF90_DOUBLE, (/ idtime /), nvarid(1) )
105            istatus = NF90_DEF_VAR( nrunid, 'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) )
106            istatus = NF90_DEF_VAR( nrunid, 'tm_i_min' , NF90_DOUBLE, (/ idtime /), nvarid(3) )
107            istatus = NF90_ENDDEF(nrunid)
108         ENDIF
109         !   
110      ENDIF
111      !
112      !                                   !==              write current time step              ==!
113      !                                   !==  done only by 1st subdomain at writting timestep  ==!
114      IF( lwm .AND. ll_wrtstp ) THEN
115         WRITE ( numstp, '(1x, i8)' )   kt
116         REWIND( numstp )
117      ENDIF
118      !                                   !==            test of local extrema           ==!
119      !                                   !==  done by all processes at every time step  ==!
120      !
121      llmsk(   1:Nis1,:) = .FALSE.                                              ! exclude halos from the checked region
122      llmsk(Nie1: jpi,:) = .FALSE.
123      llmsk(:,   1:Njs1) = .FALSE.
124      llmsk(:,Nje1: jpj) = .FALSE.
125      !
126      llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp   ! test only the inner domain
127      IF( COUNT( llmsk(:,:) ) > 0 ) THEN   ! avoid huge values sent back for land processors...
128         zmax(1) = MAXVAL(      vt_i (:,:)      , mask = llmsk )   ! max ice thickness
129         zmax(2) = MAXVAL( ABS( u_ice(:,:) )    , mask = llmsk )   ! max ice velocity (zonal only)
130         zmax(3) = MAXVAL(     -tm_i (:,:) + rt0, mask = llmsk )   ! min ice temperature (in degC)
131      ELSE
132         IF( ll_colruns ) THEN    ! default value: must not be kept when calling mpp_max -> must be as small as possible
133            zmax(1:3) = -HUGE(1._wp)
134         ELSE                     ! default value: must not give true for any of the tests bellow (-> avoid manipulating HUGE...)
135            zmax(1:3) = 0._wp
136         ENDIF
137      ENDIF
138      zmax(4) = REAL( nstop, wp )                                     ! stop indicator
139      !                                   !==               get global extrema             ==!
140      !                                   !==  done by all processes if writting run.stat  ==!
141      IF( ll_colruns ) THEN
142         zmaxlocal(:) = zmax(:)
143         CALL mpp_max( "stpctl", zmax )          ! max over the global domain
144         nstop = NINT( zmax(4) )                 ! update nstop indicator (now sheared among all local domains)
145      ENDIF
146      !                                   !==              write "run.stat" files              ==!
147      !                                   !==  done only by 1st subdomain at writting timestep  ==!
148      IF( ll_wrtruns ) THEN
149         WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3)
150         istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) )
151         istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) )
152         istatus = NF90_PUT_VAR( nrunid, nvarid(3), (/-zmax(3)/), (/kt/), (/1/) )
153         IF( kt == nitend )   istatus = NF90_CLOSE(nrunid)
154      END IF
155      !                                   !==               error handling               ==!
156      !                                   !==  done by all processes at every time step  ==!
157      !
158      IF(   zmax(1) >  100._wp .OR.   &                   ! too large ice thickness maximum ( > 100 m)
159         &  zmax(2) >   10._wp .OR.   &                   ! too large ice velocity ( > 10 m/s)
160         &  zmax(3) >  101._wp .OR.   &                   ! too cold ice temperature ( < -100 degC)
161         &  ISNAN( zmax(1) + zmax(2) + zmax(3) ) .OR.   &               ! NaN encounter in the tests
162         &  ABS(   zmax(1) + zmax(2) + zmax(3) ) > HUGE(1._wp) ) THEN   ! Infinity encounter in the tests
163         !
164         iloc(:,:) = 0
165         IF( ll_colruns ) THEN   ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc
166            ! first: close the netcdf file, so we can read it
167            IF( lwm .AND. kt /= nitend )   istatus = NF90_CLOSE(nrunid)
168            ! get global loc on the min/max
169            CALL mpp_maxloc( 'stpctl',      vt_i(:,:)      , llmsk, zzz, iloc(1:2,1) )   ! mpp_maxloc ok if mask = F
170            CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) )    , llmsk, zzz, iloc(1:2,2) )
171            CALL mpp_minloc( 'stpctl',      tm_i(:,:) - rt0, llmsk, zzz, iloc(1:2,3) )
172            ! find which subdomain has the max.
173            iareamin(:) = jpnij+1   ;   iareamax(:) = 0   ;   iareasum(:) = 0
174            DO ji = 1, 4
175               IF( zmaxlocal(ji) == zmax(ji) ) THEN
176                  iareamin(ji) = narea   ;   iareamax(ji) = narea   ;   iareasum(ji) = 1
177               ENDIF
178            END DO
179            CALL mpp_min( "stpctl", iareamin )         ! min over the global domain
180            CALL mpp_max( "stpctl", iareamax )         ! max over the global domain
181            CALL mpp_sum( "stpctl", iareasum )         ! sum over the global domain
182         ELSE                    ! find local min and max locations:
183            ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc
184            iloc(1:2,1) = MAXLOC(       vt_i(:,:)      , mask = llmsk )
185            iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) )    , mask = llmsk )
186            iloc(1:2,3) = MINLOC(       tm_i(:,:) - rt0, mask = llmsk )
187            DO ji = 1, 3   ! local domain indices ==> global domain indices, excluding halos
188               iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /)
189            END DO
190            iareamin(:) = narea   ;   iareamax(:) = narea   ;   iareasum(:) = 1         ! this is local information
191         ENDIF
192         !
193         WRITE(ctmp1,*) ' stp_ctl: ice_thick > 100 m or |ice_vel| > 10 m/s or ice_temp < -100 degC or NaN encounter in the tests'
194         CALL wrt_line( ctmp2, kt, 'ice_thick max',  zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) )
195         CALL wrt_line( ctmp3, kt, '|ice_vel| max',  zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) )
196         CALL wrt_line( ctmp4, kt, 'ice_temp  min', -zmax(3), iloc(:,3), iareasum(3), iareamin(3), iareamax(3) )
197         IF( Agrif_Root() ) THEN
198            WRITE(ctmp6,*) '      ===> output of last computed fields in output.abort* files'
199         ELSE
200            WRITE(ctmp6,*) '      ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files'
201         ENDIF
202         !
203         CALL dia_wri_state( Kmm, 'output.abort' )     ! create an output.abort file
204         !
205         IF( ll_colruns .or. jpnij == 1 ) THEN   ! all processes synchronized -> use lwp to print in opened ocean.output files
206            IF(lwp) THEN   ;   CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
207            ELSE           ;   nstop = MAX(1, nstop)   ! make sure nstop > 0 (automatically done when calling ctl_stop)
208            ENDIF
209         ELSE                                    ! only mpi subdomains with errors are here -> STOP now
210            CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 )
211         ENDIF
212         !
213      ENDIF
214      !
215      IF( nstop > 0 ) THEN                                                  ! an error was detected and we did not abort yet...
216         ngrdstop = Agrif_Fixed()                                           ! store which grid got this error
217         IF( .NOT. ll_colruns .AND. jpnij > 1 )   CALL ctl_stop( 'STOP' )   ! we must abort here to avoid MPI deadlock
218      ENDIF
219      !
2209500  FORMAT(' it :', i8, '    vt_i_max: ', D23.16, ' |u|_max: ', D23.16,' tm_i_min: ', D23.16)
221      !
222   END SUBROUTINE stp_ctl
223
224
225   SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax )
226      !!----------------------------------------------------------------------
227      !!                     ***  ROUTINE wrt_line  ***
228      !!
229      !! ** Purpose :   write information line
230      !!
231      !!----------------------------------------------------------------------
232      CHARACTER(len=*),      INTENT(  out) ::   cdline
233      CHARACTER(len=*),      INTENT(in   ) ::   cdprefix
234      REAL(wp),              INTENT(in   ) ::   pval
235      INTEGER, DIMENSION(3), INTENT(in   ) ::   kloc
236      INTEGER,               INTENT(in   ) ::   kt, ksum, kmin, kmax
237      !
238      CHARACTER(len=80) ::   clsuff
239      CHARACTER(len=9 ) ::   clkt, clsum, clmin, clmax
240      CHARACTER(len=9 ) ::   cli, clj, clk
241      CHARACTER(len=1 ) ::   clfmt
242      CHARACTER(len=4 ) ::   cl4   ! needed to be able to compile with Agrif, I don't know why
243      INTEGER           ::   ifmtk
244      !!----------------------------------------------------------------------
245      WRITE(clkt , '(i9)') kt
246     
247      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij  ,wp))) + 1     ! how many digits to we need to write ? (we decide max = 9)
248      !!! WRITE(clsum, '(i'//clfmt//')') ksum                   ! this is creating a compilation error with AGRIF
249      cl4 = '(i'//clfmt//')'   ;   WRITE(clsum, cl4) ksum
250      WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1    ! how many digits to we need to write ? (we decide max = 9)
251      cl4 = '(i'//clfmt//')'   ;   WRITE(clmin, cl4) kmin-1
252                                   WRITE(clmax, cl4) kmax-1
253      !
254      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1      ! how many digits to we need to write jpiglo? (we decide max = 9)
255      cl4 = '(i'//clfmt//')'   ;   WRITE(cli, cl4) kloc(1)      ! this is ok with AGRIF
256      WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1      ! how many digits to we need to write jpjglo? (we decide max = 9)
257      cl4 = '(i'//clfmt//')'   ;   WRITE(clj, cl4) kloc(2)      ! this is ok with AGRIF
258      !
259      IF( ksum == 1 ) THEN   ;   WRITE(clsuff,9100) TRIM(clmin)
260      ELSE                   ;   WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax)
261      ENDIF
262      IF(kloc(3) == 0) THEN
263         ifmtk = INT(LOG10(REAL(jpk,wp))) + 1                   ! how many digits to we need to write jpk? (we decide max = 9)
264         clk = REPEAT(' ', ifmtk)                               ! create the equivalent in blank string
265         WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff)
266      ELSE
267         WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1      ! how many digits to we need to write jpk? (we decide max = 9)
268         !!! WRITE(clk, '(i'//clfmt//')') kloc(3)               ! this is creating a compilation error with AGRIF
269         cl4 = '(i'//clfmt//')'   ;   WRITE(clk, cl4) kloc(3)   ! this is ok with AGRIF
270         WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj),    TRIM(clk), TRIM(clsuff)
271      ENDIF
272      !
2739100  FORMAT('MPI rank ', a)
2749200  FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a)
2759300  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j   ', a, ' ', a, ' ', a, ' ', a)
2769400  FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a)
277      !
278   END SUBROUTINE wrt_line
279
280
281   !!======================================================================
282END MODULE stpctl
Note: See TracBrowser for help on using the repository browser.