[3331] | 1 | MODULE 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) |
---|
[9267] | 13 | !! 4.0 ! 2017-04 (G. Madec) regroup global communications |
---|
[3331] | 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 |
---|
[9267] | 21 | USE ice , ONLY : vt_i, u_ice, tm_i |
---|
[13458] | 22 | USE phycst , ONLY : rt0 |
---|
[13538] | 23 | USE sbc_oce , ONLY : lk_oasis |
---|
[9267] | 24 | ! |
---|
[12933] | 25 | USE diawri ! Standard run outputs (dia_wri_state routine) |
---|
[3331] | 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 |
---|
[12933] | 29 | ! |
---|
[9441] | 30 | USE netcdf ! NetCDF library |
---|
[3331] | 31 | IMPLICIT NONE |
---|
| 32 | PRIVATE |
---|
| 33 | |
---|
| 34 | PUBLIC stp_ctl ! routine called by step.F90 |
---|
[9441] | 35 | |
---|
[12933] | 36 | INTEGER :: nrunid ! netcdf file id |
---|
| 37 | INTEGER, DIMENSION(3) :: nvarid ! netcdf variable id |
---|
[3331] | 38 | !!---------------------------------------------------------------------- |
---|
[10068] | 39 | !! NEMO/SAS 4.0 , NEMO Consortium (2018) |
---|
[5215] | 40 | !! $Id$ |
---|
[10068] | 41 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
[3331] | 42 | !!---------------------------------------------------------------------- |
---|
| 43 | CONTAINS |
---|
| 44 | |
---|
[12933] | 45 | SUBROUTINE stp_ctl( kt, Kmm ) |
---|
[3331] | 46 | !!---------------------------------------------------------------------- |
---|
| 47 | !! *** ROUTINE stp_ctl *** |
---|
| 48 | !! |
---|
| 49 | !! ** Purpose : Control the run |
---|
| 50 | !! |
---|
| 51 | !! ** Method : - Save the time step in numstp |
---|
[12933] | 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 |
---|
[3331] | 56 | !! |
---|
[9267] | 57 | !! ** Actions : "time.step" file = last ocean time-step |
---|
| 58 | !! "run.stat" file = run statistics |
---|
[12933] | 59 | !! nstop indicator sheared among all local domain |
---|
[3331] | 60 | !!---------------------------------------------------------------------- |
---|
[12933] | 61 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
| 62 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
[9267] | 63 | !! |
---|
[12933] | 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 |
---|
[13616] | 70 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns, ll_0oce |
---|
[12933] | 71 | LOGICAL, DIMENSION(jpi,jpj) :: llmsk |
---|
| 72 | CHARACTER(len=20) :: clname |
---|
[3331] | 73 | !!---------------------------------------------------------------------- |
---|
[12933] | 74 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
[10603] | 75 | ! |
---|
[12933] | 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 |
---|
[13538] | 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 ) |
---|
[12933] | 92 | ! |
---|
| 93 | IF( ll_wrtruns ) THEN |
---|
[13538] | 94 | IF( lk_oasis ) THEN ; clname = 'run_sas.stat' |
---|
| 95 | ELSE ; clname = 'run.stat' |
---|
| 96 | ENDIF |
---|
[12933] | 97 | ! ! open run.stat ascii file, done only by 1st subdomain |
---|
[13538] | 98 | CALL ctl_opn( numrun, clname, 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
[12933] | 99 | ! ! open run.stat.nc netcdf file, done only by 1st subdomain |
---|
[13546] | 100 | clname = TRIM(clname)//'.nc' |
---|
[10425] | 101 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
[12933] | 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) |
---|
[9441] | 108 | ENDIF |
---|
[12933] | 109 | ! |
---|
[3331] | 110 | ENDIF |
---|
[9267] | 111 | ! |
---|
[12933] | 112 | ! !== write current time step ==! |
---|
| 113 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
| 114 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
[9267] | 115 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
| 116 | REWIND( numstp ) |
---|
| 117 | ENDIF |
---|
[12933] | 118 | ! !== test of local extrema ==! |
---|
| 119 | ! !== done by all processes at every time step ==! |
---|
[13458] | 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 | ! |
---|
[13616] | 126 | llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp ! test only the inner domain |
---|
| 127 | ! |
---|
| 128 | ll_0oce = .NOT. ANY( llmsk(:,:) ) ! no ocean point in the inner domain? |
---|
| 129 | ! |
---|
| 130 | zmax(1) = MAXVAL( vt_i (:,:) , mask = llmsk ) ! max ice thickness |
---|
| 131 | zmax(2) = MAXVAL( ABS( u_ice(:,:) ) , mask = llmsk ) ! max ice velocity (zonal only) |
---|
| 132 | zmax(3) = MAXVAL( -tm_i (:,:) + rt0, mask = llmsk ) ! min ice temperature (in degC) |
---|
| 133 | zmax(4) = REAL( nstop, wp ) ! stop indicator |
---|
| 134 | ! |
---|
[12933] | 135 | ! !== get global extrema ==! |
---|
| 136 | ! !== done by all processes if writting run.stat ==! |
---|
[10603] | 137 | IF( ll_colruns ) THEN |
---|
[12933] | 138 | zmaxlocal(:) = zmax(:) |
---|
[13616] | 139 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain: ok even of ll_0oce = .true. |
---|
[12933] | 140 | nstop = NINT( zmax(4) ) ! update nstop indicator (now sheared among all local domains) |
---|
[13616] | 141 | ELSE |
---|
| 142 | ! if no ocean point: MAXVAL returns -HUGE => we must overwrite this value to avoid error handling bellow. |
---|
| 143 | IF( ll_0oce ) zmax(1:3) = 0._wp ! default "valid" values... |
---|
[12933] | 144 | ENDIF |
---|
[13616] | 145 | ! |
---|
| 146 | zmax(3) = -zmax(3) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 147 | IF( ll_colruns ) zmaxlocal(3) = -zmaxlocal(3) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 148 | ! |
---|
[12933] | 149 | ! !== write "run.stat" files ==! |
---|
| 150 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
[10603] | 151 | IF( ll_wrtruns ) THEN |
---|
[13616] | 152 | WRITE(numrun,9500) kt, zmax(1), zmax(2), zmax(3) |
---|
| 153 | DO ji = 1, 3 |
---|
| 154 | istatus = NF90_PUT_VAR( nrunid, nvarid(ji), (/zmax(ji)/), (/kt/), (/1/) ) |
---|
| 155 | END DO |
---|
[12933] | 156 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
[9441] | 157 | END IF |
---|
[12933] | 158 | ! !== error handling ==! |
---|
| 159 | ! !== done by all processes at every time step ==! |
---|
[9267] | 160 | ! |
---|
[12933] | 161 | IF( zmax(1) > 100._wp .OR. & ! too large ice thickness maximum ( > 100 m) |
---|
| 162 | & zmax(2) > 10._wp .OR. & ! too large ice velocity ( > 10 m/s) |
---|
[13616] | 163 | & zmax(3) < -101._wp .OR. & ! too cold ice temperature ( < -100 degC) |
---|
[12933] | 164 | & ISNAN( zmax(1) + zmax(2) + zmax(3) ) .OR. & ! NaN encounter in the tests |
---|
| 165 | & ABS( zmax(1) + zmax(2) + zmax(3) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
| 166 | ! |
---|
| 167 | iloc(:,:) = 0 |
---|
| 168 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
| 169 | ! first: close the netcdf file, so we can read it |
---|
| 170 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
| 171 | ! get global loc on the min/max |
---|
[13458] | 172 | CALL mpp_maxloc( 'stpctl', vt_i(:,:) , llmsk, zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
| 173 | CALL mpp_maxloc( 'stpctl',ABS( u_ice(:,:) ) , llmsk, zzz, iloc(1:2,2) ) |
---|
| 174 | CALL mpp_minloc( 'stpctl', tm_i(:,:) - rt0, llmsk, zzz, iloc(1:2,3) ) |
---|
[12933] | 175 | ! find which subdomain has the max. |
---|
| 176 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
| 177 | DO ji = 1, 4 |
---|
| 178 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
| 179 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
| 180 | ENDIF |
---|
| 181 | END DO |
---|
| 182 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
| 183 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
| 184 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
| 185 | ELSE ! find local min and max locations: |
---|
| 186 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
[13458] | 187 | iloc(1:2,1) = MAXLOC( vt_i(:,:) , mask = llmsk ) |
---|
| 188 | iloc(1:2,2) = MAXLOC( ABS( u_ice(:,:) ) , mask = llmsk ) |
---|
| 189 | iloc(1:2,3) = MINLOC( tm_i(:,:) - rt0, mask = llmsk ) |
---|
| 190 | DO ji = 1, 3 ! local domain indices ==> global domain indices, excluding halos |
---|
| 191 | iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /) |
---|
| 192 | END DO |
---|
[12933] | 193 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
| 194 | ENDIF |
---|
| 195 | ! |
---|
| 196 | 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' |
---|
[13616] | 197 | CALL wrt_line( ctmp2, kt, 'ice_thick max', zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) ) |
---|
| 198 | CALL wrt_line( ctmp3, kt, '|ice_vel| max', zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) ) |
---|
| 199 | CALL wrt_line( ctmp4, kt, 'ice_temp min', zmax(3), iloc(:,3), iareasum(3), iareamin(3), iareamax(3) ) |
---|
[12933] | 200 | IF( Agrif_Root() ) THEN |
---|
| 201 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
| 202 | ELSE |
---|
| 203 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
| 204 | ENDIF |
---|
| 205 | ! |
---|
| 206 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
| 207 | ! |
---|
| 208 | IF( ll_colruns .or. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
[13115] | 209 | IF(lwp) THEN ; CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
| 210 | ELSE ; nstop = MAX(1, nstop) ! make sure nstop > 0 (automatically done when calling ctl_stop) |
---|
| 211 | ENDIF |
---|
[12933] | 212 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
| 213 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
| 214 | ENDIF |
---|
| 215 | ! |
---|
| 216 | ENDIF |
---|
| 217 | ! |
---|
[13115] | 218 | IF( nstop > 0 ) THEN ! an error was detected and we did not abort yet... |
---|
| 219 | ngrdstop = Agrif_Fixed() ! store which grid got this error |
---|
| 220 | IF( .NOT. ll_colruns .AND. jpnij > 1 ) CALL ctl_stop( 'STOP' ) ! we must abort here to avoid MPI deadlock |
---|
| 221 | ENDIF |
---|
| 222 | ! |
---|
[10425] | 223 | 9500 FORMAT(' it :', i8, ' vt_i_max: ', D23.16, ' |u|_max: ', D23.16,' tm_i_min: ', D23.16) |
---|
[9267] | 224 | ! |
---|
[3331] | 225 | END SUBROUTINE stp_ctl |
---|
| 226 | |
---|
[12933] | 227 | |
---|
| 228 | SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax ) |
---|
| 229 | !!---------------------------------------------------------------------- |
---|
| 230 | !! *** ROUTINE wrt_line *** |
---|
| 231 | !! |
---|
| 232 | !! ** Purpose : write information line |
---|
| 233 | !! |
---|
| 234 | !!---------------------------------------------------------------------- |
---|
| 235 | CHARACTER(len=*), INTENT( out) :: cdline |
---|
| 236 | CHARACTER(len=*), INTENT(in ) :: cdprefix |
---|
| 237 | REAL(wp), INTENT(in ) :: pval |
---|
| 238 | INTEGER, DIMENSION(3), INTENT(in ) :: kloc |
---|
| 239 | INTEGER, INTENT(in ) :: kt, ksum, kmin, kmax |
---|
| 240 | ! |
---|
| 241 | CHARACTER(len=80) :: clsuff |
---|
| 242 | CHARACTER(len=9 ) :: clkt, clsum, clmin, clmax |
---|
| 243 | CHARACTER(len=9 ) :: cli, clj, clk |
---|
| 244 | CHARACTER(len=1 ) :: clfmt |
---|
| 245 | CHARACTER(len=4 ) :: cl4 ! needed to be able to compile with Agrif, I don't know why |
---|
| 246 | INTEGER :: ifmtk |
---|
| 247 | !!---------------------------------------------------------------------- |
---|
| 248 | WRITE(clkt , '(i9)') kt |
---|
| 249 | |
---|
| 250 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij ,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
| 251 | !!! WRITE(clsum, '(i'//clfmt//')') ksum ! this is creating a compilation error with AGRIF |
---|
| 252 | cl4 = '(i'//clfmt//')' ; WRITE(clsum, cl4) ksum |
---|
[13009] | 253 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
[12933] | 254 | cl4 = '(i'//clfmt//')' ; WRITE(clmin, cl4) kmin-1 |
---|
| 255 | WRITE(clmax, cl4) kmax-1 |
---|
| 256 | ! |
---|
| 257 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1 ! how many digits to we need to write jpiglo? (we decide max = 9) |
---|
| 258 | cl4 = '(i'//clfmt//')' ; WRITE(cli, cl4) kloc(1) ! this is ok with AGRIF |
---|
| 259 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1 ! how many digits to we need to write jpjglo? (we decide max = 9) |
---|
| 260 | cl4 = '(i'//clfmt//')' ; WRITE(clj, cl4) kloc(2) ! this is ok with AGRIF |
---|
| 261 | ! |
---|
| 262 | IF( ksum == 1 ) THEN ; WRITE(clsuff,9100) TRIM(clmin) |
---|
| 263 | ELSE ; WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax) |
---|
| 264 | ENDIF |
---|
| 265 | IF(kloc(3) == 0) THEN |
---|
| 266 | ifmtk = INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 267 | clk = REPEAT(' ', ifmtk) ! create the equivalent in blank string |
---|
| 268 | WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff) |
---|
| 269 | ELSE |
---|
| 270 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 271 | !!! WRITE(clk, '(i'//clfmt//')') kloc(3) ! this is creating a compilation error with AGRIF |
---|
| 272 | cl4 = '(i'//clfmt//')' ; WRITE(clk, cl4) kloc(3) ! this is ok with AGRIF |
---|
| 273 | WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), TRIM(clk), TRIM(clsuff) |
---|
| 274 | ENDIF |
---|
| 275 | ! |
---|
| 276 | 9100 FORMAT('MPI rank ', a) |
---|
| 277 | 9200 FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a) |
---|
| 278 | 9300 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j ', a, ' ', a, ' ', a, ' ', a) |
---|
| 279 | 9400 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a) |
---|
| 280 | ! |
---|
| 281 | END SUBROUTINE wrt_line |
---|
| 282 | |
---|
| 283 | |
---|
[3331] | 284 | !!====================================================================== |
---|
| 285 | END MODULE stpctl |
---|