[3] | 1 | MODULE stpctl |
---|
[1489] | 2 | !!====================================================================== |
---|
[3] | 3 | !! *** MODULE stpctl *** |
---|
| 4 | !! Ocean run control : gross check of the ocean time stepping |
---|
[1489] | 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 |
---|
[9019] | 11 | !! 3.7 ! 2016-09 (G. Madec) Remove solver |
---|
| 12 | !! 4.0 ! 2017-04 (G. Madec) regroup global communications |
---|
[1489] | 13 | !!---------------------------------------------------------------------- |
---|
[3] | 14 | |
---|
| 15 | !!---------------------------------------------------------------------- |
---|
| 16 | !! stp_ctl : Control the run |
---|
[14143] | 17 | !! stp_ctl_SWE : Control the run (SWE only) |
---|
[3] | 18 | !!---------------------------------------------------------------------- |
---|
| 19 | USE oce ! ocean dynamics and tracers variables |
---|
| 20 | USE dom_oce ! ocean space and time domain variables |
---|
[6140] | 21 | USE c1d ! 1D vertical configuration |
---|
[12933] | 22 | USE zdf_oce , ONLY : ln_zad_Aimp ! ocean vertical physics variables |
---|
| 23 | USE wet_dry, ONLY : ll_wd, ssh_ref ! reference depth for negative bathy |
---|
| 24 | ! |
---|
[9210] | 25 | USE diawri ! Standard run outputs (dia_wri_state routine) |
---|
[3] | 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 |
---|
[14131] | 29 | USE eosbn2, ONLY: ln_SEOS, rn_b0 |
---|
[14127] | 30 | ! |
---|
[9441] | 31 | USE netcdf ! NetCDF library |
---|
[3] | 32 | IMPLICIT NONE |
---|
| 33 | PRIVATE |
---|
| 34 | |
---|
| 35 | PUBLIC stp_ctl ! routine called by step.F90 |
---|
[14143] | 36 | PUBLIC stp_ctl_SWE ! routine called by stpmlf.F90 |
---|
[9441] | 37 | |
---|
[12933] | 38 | INTEGER :: nrunid ! netcdf file id |
---|
| 39 | INTEGER, DIMENSION(8) :: nvarid ! netcdf variable id |
---|
[14143] | 40 | INTEGER, DIMENSION(2) :: nvarid_SWE ! netcdf variable id (SWE only) |
---|
[3] | 41 | !!---------------------------------------------------------------------- |
---|
[9598] | 42 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
[1489] | 43 | !! $Id$ |
---|
[10068] | 44 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
[1489] | 45 | !!---------------------------------------------------------------------- |
---|
[3] | 46 | CONTAINS |
---|
| 47 | |
---|
[12933] | 48 | SUBROUTINE stp_ctl( kt, Kmm ) |
---|
[3] | 49 | !!---------------------------------------------------------------------- |
---|
| 50 | !! *** ROUTINE stp_ctl *** |
---|
| 51 | !! |
---|
| 52 | !! ** Purpose : Control the run |
---|
| 53 | !! |
---|
| 54 | !! ** Method : - Save the time step in numstp |
---|
[12933] | 55 | !! - Stop the run IF problem encountered by setting nstop > 0 |
---|
[10425] | 56 | !! Problems checked: |ssh| maximum larger than 10 m |
---|
[9019] | 57 | !! |U| maximum larger than 10 m/s |
---|
| 58 | !! negative sea surface salinity |
---|
[3] | 59 | !! |
---|
[9019] | 60 | !! ** Actions : "time.step" file = last ocean time-step |
---|
| 61 | !! "run.stat" file = run statistics |
---|
[12933] | 62 | !! nstop indicator sheared among all local domain |
---|
[3] | 63 | !!---------------------------------------------------------------------- |
---|
[6140] | 64 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
[12933] | 65 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
[1489] | 66 | !! |
---|
[12933] | 67 | INTEGER :: ji ! dummy loop indices |
---|
| 68 | INTEGER :: idtime, istatus |
---|
| 69 | INTEGER , DIMENSION(9) :: iareasum, iareamin, iareamax |
---|
| 70 | INTEGER , DIMENSION(3,4) :: iloc ! min/max loc indices |
---|
[14127] | 71 | REAL(wp) :: zzz, zminsal, zmaxsal ! local real |
---|
[12933] | 72 | REAL(wp), DIMENSION(9) :: zmax, zmaxlocal |
---|
[13616] | 73 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns, ll_0oce |
---|
[12933] | 74 | LOGICAL, DIMENSION(jpi,jpj,jpk) :: llmsk |
---|
| 75 | CHARACTER(len=20) :: clname |
---|
[3] | 76 | !!---------------------------------------------------------------------- |
---|
[12933] | 77 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
[6140] | 78 | ! |
---|
[12933] | 79 | ll_wrtstp = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) |
---|
| 80 | ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 |
---|
| 81 | ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm |
---|
| 82 | ! |
---|
| 83 | IF( kt == nit000 ) THEN |
---|
| 84 | ! |
---|
| 85 | IF( lwp ) THEN |
---|
| 86 | WRITE(numout,*) |
---|
| 87 | WRITE(numout,*) 'stp_ctl : time-stepping control' |
---|
| 88 | WRITE(numout,*) '~~~~~~~' |
---|
| 89 | ENDIF |
---|
| 90 | ! ! open time.step ascii file, done only by 1st subdomain |
---|
| 91 | IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
| 92 | ! |
---|
| 93 | IF( ll_wrtruns ) THEN |
---|
| 94 | ! ! open run.stat ascii file, done only by 1st subdomain |
---|
[10425] | 95 | CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
[12933] | 96 | ! ! open run.stat.nc netcdf file, done only by 1st subdomain |
---|
[9565] | 97 | clname = 'run.stat.nc' |
---|
| 98 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
[12933] | 99 | istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid ) |
---|
| 100 | istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime ) |
---|
| 101 | istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) ) |
---|
| 102 | istatus = NF90_DEF_VAR( nrunid, 'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) ) |
---|
| 103 | istatus = NF90_DEF_VAR( nrunid, 's_min', NF90_DOUBLE, (/ idtime /), nvarid(3) ) |
---|
| 104 | istatus = NF90_DEF_VAR( nrunid, 's_max', NF90_DOUBLE, (/ idtime /), nvarid(4) ) |
---|
| 105 | istatus = NF90_DEF_VAR( nrunid, 't_min', NF90_DOUBLE, (/ idtime /), nvarid(5) ) |
---|
| 106 | istatus = NF90_DEF_VAR( nrunid, 't_max', NF90_DOUBLE, (/ idtime /), nvarid(6) ) |
---|
[10364] | 107 | IF( ln_zad_Aimp ) THEN |
---|
[12933] | 108 | istatus = NF90_DEF_VAR( nrunid, 'Cf_max', NF90_DOUBLE, (/ idtime /), nvarid(7) ) |
---|
| 109 | istatus = NF90_DEF_VAR( nrunid,'abs_wi_max',NF90_DOUBLE, (/ idtime /), nvarid(8) ) |
---|
[10364] | 110 | ENDIF |
---|
[12933] | 111 | istatus = NF90_ENDDEF(nrunid) |
---|
[9441] | 112 | ENDIF |
---|
[12933] | 113 | ! |
---|
[3] | 114 | ENDIF |
---|
[6140] | 115 | ! |
---|
[12933] | 116 | ! !== write current time step ==! |
---|
| 117 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
| 118 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
[9019] | 119 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
| 120 | REWIND( numstp ) |
---|
[3] | 121 | ENDIF |
---|
[12933] | 122 | ! !== test of local extrema ==! |
---|
| 123 | ! !== done by all processes at every time step ==! |
---|
[13458] | 124 | ! |
---|
| 125 | llmsk( 1:Nis1,:,:) = .FALSE. ! exclude halos from the checked region |
---|
| 126 | llmsk(Nie1: jpi,:,:) = .FALSE. |
---|
| 127 | llmsk(:, 1:Njs1,:) = .FALSE. |
---|
| 128 | llmsk(:,Nje1: jpj,:) = .FALSE. |
---|
| 129 | ! |
---|
| 130 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0) == 1._wp ! define only the inner domain |
---|
[13616] | 131 | ! |
---|
| 132 | ll_0oce = .NOT. ANY( llmsk(:,:,1) ) ! no ocean point in the inner domain? |
---|
| 133 | ! |
---|
[13216] | 134 | IF( ll_wd ) THEN |
---|
| 135 | zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) ) ! ssh max |
---|
| 136 | ELSE |
---|
| 137 | zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) ), mask = llmsk(:,:,1) ) ! ssh max |
---|
[9023] | 138 | ENDIF |
---|
[13458] | 139 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
[13216] | 140 | zmax(2) = MAXVAL( ABS( uu(:,:,:,Kmm) ), mask = llmsk ) ! velocity max (zonal only) |
---|
[13458] | 141 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
[13216] | 142 | zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk ) ! minus salinity max |
---|
| 143 | zmax(4) = MAXVAL( ts(:,:,:,jp_sal,Kmm), mask = llmsk ) ! salinity max |
---|
| 144 | IF( ll_colruns .OR. jpnij == 1 ) THEN ! following variables are used only in the netcdf file |
---|
| 145 | zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm), mask = llmsk ) ! minus temperature max |
---|
| 146 | zmax(6) = MAXVAL( ts(:,:,:,jp_tem,Kmm), mask = llmsk ) ! temperature max |
---|
| 147 | IF( ln_zad_Aimp ) THEN |
---|
| 148 | zmax(7) = MAXVAL( Cu_adv(:,:,:) , mask = llmsk ) ! partitioning coeff. max |
---|
| 149 | llmsk(:,:,:) = wmask(:,:,:) == 1._wp |
---|
| 150 | zmax(8) = MAXVAL( ABS( wi(:,:,:) ) , mask = llmsk ) ! implicit vertical vel. max |
---|
| 151 | ELSE |
---|
| 152 | zmax(7:8) = 0._wp |
---|
[12933] | 153 | ENDIF |
---|
[13216] | 154 | ELSE |
---|
| 155 | zmax(5:8) = 0._wp |
---|
[10364] | 156 | ENDIF |
---|
[13458] | 157 | zmax(9) = REAL( nstop, wp ) ! stop indicator |
---|
[13616] | 158 | ! |
---|
[12933] | 159 | ! !== get global extrema ==! |
---|
| 160 | ! !== done by all processes if writting run.stat ==! |
---|
[10570] | 161 | IF( ll_colruns ) THEN |
---|
[12933] | 162 | zmaxlocal(:) = zmax(:) |
---|
[13616] | 163 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain: ok even of ll_0oce = .true. |
---|
[12933] | 164 | nstop = NINT( zmax(9) ) ! update nstop indicator (now sheared among all local domains) |
---|
[13616] | 165 | ELSE |
---|
| 166 | ! if no ocean point: MAXVAL returns -HUGE => we must overwrite this value to avoid error handling bellow. |
---|
| 167 | IF( ll_0oce ) zmax(1:4) = (/ 0._wp, 0._wp, -1._wp, 1._wp /) ! default "valid" values... |
---|
[9210] | 168 | ENDIF |
---|
[13616] | 169 | ! |
---|
| 170 | zmax(3) = -zmax(3) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 171 | zmax(5) = -zmax(5) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 172 | IF( ll_colruns ) THEN |
---|
| 173 | zmaxlocal(3) = -zmaxlocal(3) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 174 | zmaxlocal(5) = -zmaxlocal(5) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 175 | ENDIF |
---|
| 176 | ! |
---|
[12933] | 177 | ! !== write "run.stat" files ==! |
---|
| 178 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
[10570] | 179 | IF( ll_wrtruns ) THEN |
---|
[13616] | 180 | WRITE(numrun,9500) kt, zmax(1), zmax(2), zmax(3), zmax(4) |
---|
| 181 | DO ji = 1, 6 + 2 * COUNT( (/ln_zad_Aimp/) ) |
---|
| 182 | istatus = NF90_PUT_VAR( nrunid, nvarid(ji), (/zmax(ji)/), (/kt/), (/1/) ) |
---|
| 183 | END DO |
---|
[12933] | 184 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
[14127] | 185 | END IF |
---|
[12933] | 186 | ! !== error handling ==! |
---|
| 187 | ! !== done by all processes at every time step ==! |
---|
| 188 | ! |
---|
[14131] | 189 | IF ( ln_SEOS.AND.(rn_b0==0._wp) ) THEN ! Discard checks on salinity |
---|
[14127] | 190 | zmaxsal = +1.e38 ! if not used in eos |
---|
| 191 | zminsal = -1.e38 |
---|
| 192 | ELSE |
---|
| 193 | zmaxsal = 100._wp |
---|
| 194 | zminsal = 0._wp |
---|
| 195 | ENDIF |
---|
| 196 | ! |
---|
[13616] | 197 | IF( zmax(1) > 20._wp .OR. & ! too large sea surface height ( > 20 m ) |
---|
| 198 | & zmax(2) > 10._wp .OR. & ! too large velocity ( > 10 m/s) |
---|
[14127] | 199 | & zmax(3) <= zminsal .OR. & ! negative or zero sea surface salinity |
---|
| 200 | & zmax(4) >= zmaxsal .OR. & ! too large sea surface salinity ( > 100 ) |
---|
| 201 | & zmax(4) < zminsal .OR. & ! too large sea surface salinity (keep this line for sea-ice) |
---|
[13616] | 202 | & ISNAN( zmax(1) + zmax(2) + zmax(3) ) .OR. & ! NaN encounter in the tests |
---|
| 203 | & ABS( zmax(1) + zmax(2) + zmax(3) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
[12933] | 204 | ! |
---|
| 205 | iloc(:,:) = 0 |
---|
| 206 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
| 207 | ! first: close the netcdf file, so we can read it |
---|
| 208 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
| 209 | ! get global loc on the min/max |
---|
[13458] | 210 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp ! define only the inner domain |
---|
| 211 | CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:, Kmm)), llmsk(:,:,1), zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
| 212 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 213 | CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:, Kmm)), llmsk(:,:,:), zzz, iloc(1:3,2) ) |
---|
| 214 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 215 | CALL mpp_minloc( 'stpctl', ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,3) ) |
---|
| 216 | CALL mpp_maxloc( 'stpctl', ts(:,:,:,jp_sal,Kmm) , llmsk(:,:,:), zzz, iloc(1:3,4) ) |
---|
[12933] | 217 | ! find which subdomain has the max. |
---|
| 218 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
| 219 | DO ji = 1, 9 |
---|
| 220 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
| 221 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
| 222 | ENDIF |
---|
| 223 | END DO |
---|
| 224 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
| 225 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
| 226 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
| 227 | ELSE ! find local min and max locations: |
---|
| 228 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
[13458] | 229 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp ! define only the inner domain |
---|
| 230 | iloc(1:2,1) = MAXLOC( ABS( ssh(:,:, Kmm)), mask = llmsk(:,:,1) ) |
---|
| 231 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 232 | iloc(1:3,2) = MAXLOC( ABS( uu(:,:,:, Kmm)), mask = llmsk(:,:,:) ) |
---|
| 233 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 234 | iloc(1:3,3) = MINLOC( ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) ) |
---|
| 235 | iloc(1:3,4) = MAXLOC( ts(:,:,:,jp_sal,Kmm) , mask = llmsk(:,:,:) ) |
---|
| 236 | DO ji = 1, 4 ! local domain indices ==> global domain indices, excluding halos |
---|
| 237 | iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /) |
---|
| 238 | END DO |
---|
[12933] | 239 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
[7852] | 240 | ENDIF |
---|
[12933] | 241 | ! |
---|
[10425] | 242 | WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m or |U| > 10 m/s or S <= 0 or S >= 100 or NaN encounter in the tests' |
---|
[13616] | 243 | CALL wrt_line( ctmp2, kt, '|ssh| max', zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) ) |
---|
| 244 | CALL wrt_line( ctmp3, kt, '|U| max', zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) ) |
---|
| 245 | CALL wrt_line( ctmp4, kt, 'Sal min', zmax(3), iloc(:,3), iareasum(3), iareamin(3), iareamax(3) ) |
---|
| 246 | CALL wrt_line( ctmp5, kt, 'Sal max', zmax(4), iloc(:,4), iareasum(4), iareamin(4), iareamax(4) ) |
---|
[12933] | 247 | IF( Agrif_Root() ) THEN |
---|
| 248 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
[10425] | 249 | ELSE |
---|
[12933] | 250 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
[7852] | 251 | ENDIF |
---|
[9210] | 252 | ! |
---|
[12933] | 253 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
| 254 | ! |
---|
| 255 | IF( ll_colruns .or. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
[13115] | 256 | IF(lwp) THEN ; CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
| 257 | ELSE ; nstop = MAX(1, nstop) ! make sure nstop > 0 (automatically done when calling ctl_stop) |
---|
| 258 | ENDIF |
---|
[12933] | 259 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
| 260 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
| 261 | ENDIF |
---|
| 262 | ! |
---|
[7852] | 263 | ENDIF |
---|
[10425] | 264 | ! |
---|
[13115] | 265 | IF( nstop > 0 ) THEN ! an error was detected and we did not abort yet... |
---|
| 266 | ngrdstop = Agrif_Fixed() ! store which grid got this error |
---|
| 267 | IF( .NOT. ll_colruns .AND. jpnij > 1 ) CALL ctl_stop( 'STOP' ) ! we must abort here to avoid MPI deadlock |
---|
| 268 | ENDIF |
---|
| 269 | ! |
---|
[9808] | 270 | 9500 FORMAT(' it :', i8, ' |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16) |
---|
[7852] | 271 | ! |
---|
[3] | 272 | END SUBROUTINE stp_ctl |
---|
| 273 | |
---|
[12933] | 274 | |
---|
[14143] | 275 | SUBROUTINE stp_ctl_SWE( kt, Kmm ) |
---|
| 276 | !!---------------------------------------------------------------------- |
---|
| 277 | !! *** ROUTINE stp_ctl_SWE *** |
---|
| 278 | !! |
---|
| 279 | !! ** Purpose : Control the run |
---|
| 280 | !! |
---|
| 281 | !! ** Method : - Save the time step in numstp |
---|
| 282 | !! - Print it each 50 time steps |
---|
| 283 | !! - Stop the run IF problem encountered by setting nstop > 0 |
---|
| 284 | !! Problems checked: e3t0+ssh minimum smaller that 0 |
---|
| 285 | !! |U| maximum larger than 10 m/s |
---|
| 286 | !! ( not for SWE : negative sea surface salinity ) |
---|
| 287 | !! |
---|
| 288 | !! ** Actions : "time.step" file = last ocean time-step |
---|
| 289 | !! "run.stat" file = run statistics |
---|
| 290 | !! nstop indicator sheared among all local domain |
---|
| 291 | !!---------------------------------------------------------------------- |
---|
| 292 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
| 293 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
| 294 | !! |
---|
| 295 | INTEGER :: ji ! dummy loop indices |
---|
| 296 | INTEGER :: idtime, istatus |
---|
| 297 | INTEGER , DIMENSION(3) :: iareasum, iareamin, iareamax |
---|
| 298 | INTEGER , DIMENSION(3,4) :: iloc ! min/max loc indices |
---|
| 299 | REAL(wp) :: zzz ! local real |
---|
| 300 | REAL(wp), DIMENSION(3) :: zmax, zmaxlocal |
---|
| 301 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns, ll_0oce |
---|
| 302 | LOGICAL, DIMENSION(jpi,jpj,jpk) :: llmsk |
---|
| 303 | CHARACTER(len=20) :: clname |
---|
| 304 | !!---------------------------------------------------------------------- |
---|
| 305 | ! |
---|
| 306 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
| 307 | ! |
---|
| 308 | ll_wrtstp = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) |
---|
| 309 | ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 |
---|
| 310 | ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm |
---|
| 311 | ! |
---|
| 312 | IF( kt == nit000 ) THEN |
---|
| 313 | ! |
---|
| 314 | IF( lwp ) THEN |
---|
| 315 | WRITE(numout,*) |
---|
| 316 | WRITE(numout,*) 'stp_ctl_SWE : time-stepping control' |
---|
| 317 | WRITE(numout,*) '~~~~~~~~~~~' |
---|
| 318 | ENDIF |
---|
| 319 | ! ! open time.step ascii file, done only by 1st subdomain |
---|
| 320 | IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
| 321 | ! |
---|
| 322 | IF( ll_wrtruns ) THEN |
---|
| 323 | ! ! open run.stat ascii file, done only by 1st subdomain |
---|
| 324 | CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
| 325 | ! ! open run.stat.nc netcdf file, done only by 1st subdomain |
---|
| 326 | clname = 'run.stat.nc' |
---|
| 327 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
| 328 | istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid ) |
---|
| 329 | istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime ) |
---|
| 330 | istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid_SWE(1) ) |
---|
| 331 | istatus = NF90_DEF_VAR( nrunid, 'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid_SWE(2) ) |
---|
| 332 | istatus = NF90_ENDDEF(nrunid) |
---|
| 333 | ENDIF |
---|
| 334 | ! |
---|
| 335 | ENDIF |
---|
| 336 | ! |
---|
| 337 | ! !== write current time step ==! |
---|
| 338 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
| 339 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
| 340 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
| 341 | REWIND( numstp ) |
---|
| 342 | ENDIF |
---|
| 343 | ! !== test of local extrema ==! |
---|
| 344 | ! !== done by all processes at every time step ==! |
---|
| 345 | ! |
---|
| 346 | llmsk( 1:Nis1,:,:) = .FALSE. ! exclude halos from the checked region |
---|
| 347 | llmsk(Nie1: jpi,:,:) = .FALSE. |
---|
| 348 | llmsk(:, 1:Njs1,:) = .FALSE. |
---|
| 349 | llmsk(:,Nje1: jpj,:) = .FALSE. |
---|
| 350 | ! |
---|
| 351 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0) == 1._wp ! define only the inner domain |
---|
| 352 | ! |
---|
| 353 | ll_0oce = .NOT. ANY( llmsk(:,:,1) ) ! no ocean point in the inner domain? |
---|
| 354 | ! |
---|
| 355 | zmax(1) = MINVAL( -e3t_0(:,:,1)-ssh(:,:,Kmm) , mask = llmsk(:,:,1) ) ! e3t_Kmm min |
---|
| 356 | ! |
---|
| 357 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 358 | zmax(2) = MAXVAL( ABS( uu(:,:,:,Kmm) ) , mask = llmsk(:,:,:) ) ! velocity max (zonal only) |
---|
| 359 | zmax(3) = REAL( nstop , wp ) ! stop indicator |
---|
| 360 | |
---|
| 361 | ! !== get global extrema ==! |
---|
| 362 | ! !== done by all processes if writting run.stat ==! |
---|
| 363 | IF( ll_colruns ) THEN |
---|
| 364 | zmaxlocal(:) = zmax(:) |
---|
| 365 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain |
---|
| 366 | nstop = NINT( zmax(3) ) ! update nstop indicator (now sheared among all local domains) |
---|
| 367 | ELSE |
---|
| 368 | ! if no ocean point: MAXVAL returns -HUGE => we must overwrite this value to avoid error handling bellow. |
---|
| 369 | IF( ll_0oce ) zmax(1:4) = (/ 0._wp, 0._wp, -1._wp, 1._wp /) ! default "valid" values... |
---|
| 370 | ENDIF |
---|
| 371 | ! |
---|
| 372 | zmax(1) = -zmax(1) ! move back from max(-zz) to min(zz) : easier to manage! |
---|
| 373 | ! |
---|
| 374 | ! !== write "run.stat" files ==! |
---|
| 375 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
| 376 | IF( ll_wrtruns ) THEN |
---|
| 377 | WRITE(numrun,9500) kt, zmax(1), zmax(2) |
---|
| 378 | istatus = NF90_PUT_VAR( nrunid, nvarid_SWE(1), (/ zmax(1)/), (/kt/), (/1/) ) |
---|
| 379 | istatus = NF90_PUT_VAR( nrunid, nvarid_SWE(2), (/ zmax(2)/), (/kt/), (/1/) ) |
---|
| 380 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
| 381 | ENDIF |
---|
| 382 | ! !== error handling ==! |
---|
| 383 | ! !== done by all processes at every time step ==! |
---|
| 384 | ! |
---|
| 385 | !!SWE specific : start |
---|
| 386 | IF( zmax(1) <= 0._wp .OR. & ! negative e3t_Kmm |
---|
| 387 | & zmax(2) > 10._wp .OR. & ! too large velocity ( > 10 m/s) |
---|
| 388 | & ISNAN( zmax(1) + zmax(2) ) .OR. & ! NaN encounter in the tests |
---|
| 389 | & ABS( zmax(1) + zmax(2) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
| 390 | ! |
---|
| 391 | iloc(:,:) = 0 |
---|
| 392 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
| 393 | ! first: close the netcdf file, so we can read it |
---|
| 394 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
| 395 | ! get global loc on the min/max |
---|
| 396 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp ! define only the inner domain |
---|
| 397 | CALL mpp_minloc( 'stpctl', e3t_0(:,:,1) + ssh(:,:,Kmm), llmsk(:,:,1), zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
| 398 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = tmask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 399 | CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,Kmm)) , llmsk(:,:,:), zzz, iloc(1:3,2) ) |
---|
| 400 | ! find which subdomain has the max. |
---|
| 401 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
| 402 | DO ji = 1, 3 |
---|
| 403 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
| 404 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
| 405 | ENDIF |
---|
| 406 | END DO |
---|
| 407 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
| 408 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
| 409 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
| 410 | ELSE ! find local min and max locations: |
---|
| 411 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
| 412 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = ssmask(Nis0:Nie0,Njs0:Nje0 ) == 1._wp ! define only the inner domain |
---|
| 413 | iloc(1:2,1) = MINLOC( e3t_0(:,:,1) + ssh(:,:,Kmm), mask = llmsk(:,:,1) ) |
---|
| 414 | ! |
---|
| 415 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 416 | iloc(1:3,2) = MAXLOC( ABS( uu(:,:,:, Kmm)), mask = llmsk(:,:,:) ) |
---|
| 417 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
| 418 | ENDIF |
---|
| 419 | ! |
---|
| 420 | WRITE(ctmp1,*) ' stp_ctl_SWE: e3t0+ssh < 0 m or |U| > 10 m/s or NaN encounter in the tests' |
---|
| 421 | CALL wrt_line( ctmp2, kt, 'e3t0+ssh min', zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) ) |
---|
| 422 | CALL wrt_line( ctmp3, kt, '|U| max' , zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) ) |
---|
| 423 | IF( Agrif_Root() ) THEN |
---|
| 424 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
| 425 | ELSE |
---|
| 426 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
| 427 | ENDIF |
---|
| 428 | ! |
---|
| 429 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
| 430 | ! |
---|
| 431 | IF( ll_colruns .or. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
| 432 | IF(lwp) THEN ; CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 ) |
---|
| 433 | ELSE ; nstop = MAX(1, nstop) ! make sure nstop > 0 (automatically done when calling ctl_stop) |
---|
| 434 | ENDIF |
---|
| 435 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
| 436 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 ) |
---|
| 437 | ENDIF |
---|
| 438 | ! |
---|
| 439 | ENDIF |
---|
| 440 | !!SWE specific : end |
---|
| 441 | ! |
---|
| 442 | IF( nstop > 0 ) THEN ! an error was detected and we did not abort yet... |
---|
| 443 | ngrdstop = Agrif_Fixed() ! store which grid got this error |
---|
| 444 | IF( .NOT. ll_colruns .AND. jpnij > 1 ) CALL ctl_stop( 'STOP' ) ! we must abort here to avoid MPI deadlock |
---|
| 445 | ENDIF |
---|
| 446 | ! |
---|
| 447 | 9500 FORMAT(' it :', i8, ' e3t_min: ', D23.16, ' |U|_max: ', D23.16) |
---|
| 448 | ! |
---|
| 449 | END SUBROUTINE stp_ctl_SWE |
---|
| 450 | |
---|
| 451 | |
---|
[12933] | 452 | SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax ) |
---|
| 453 | !!---------------------------------------------------------------------- |
---|
| 454 | !! *** ROUTINE wrt_line *** |
---|
| 455 | !! |
---|
| 456 | !! ** Purpose : write information line |
---|
| 457 | !! |
---|
| 458 | !!---------------------------------------------------------------------- |
---|
| 459 | CHARACTER(len=*), INTENT( out) :: cdline |
---|
| 460 | CHARACTER(len=*), INTENT(in ) :: cdprefix |
---|
| 461 | REAL(wp), INTENT(in ) :: pval |
---|
| 462 | INTEGER, DIMENSION(3), INTENT(in ) :: kloc |
---|
| 463 | INTEGER, INTENT(in ) :: kt, ksum, kmin, kmax |
---|
| 464 | ! |
---|
| 465 | CHARACTER(len=80) :: clsuff |
---|
| 466 | CHARACTER(len=9 ) :: clkt, clsum, clmin, clmax |
---|
| 467 | CHARACTER(len=9 ) :: cli, clj, clk |
---|
| 468 | CHARACTER(len=1 ) :: clfmt |
---|
| 469 | CHARACTER(len=4 ) :: cl4 ! needed to be able to compile with Agrif, I don't know why |
---|
| 470 | INTEGER :: ifmtk |
---|
| 471 | !!---------------------------------------------------------------------- |
---|
| 472 | WRITE(clkt , '(i9)') kt |
---|
| 473 | |
---|
| 474 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij ,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
| 475 | !!! WRITE(clsum, '(i'//clfmt//')') ksum ! this is creating a compilation error with AGRIF |
---|
| 476 | cl4 = '(i'//clfmt//')' ; WRITE(clsum, cl4) ksum |
---|
[13009] | 477 | 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] | 478 | cl4 = '(i'//clfmt//')' ; WRITE(clmin, cl4) kmin-1 |
---|
| 479 | WRITE(clmax, cl4) kmax-1 |
---|
| 480 | ! |
---|
| 481 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1 ! how many digits to we need to write jpiglo? (we decide max = 9) |
---|
| 482 | cl4 = '(i'//clfmt//')' ; WRITE(cli, cl4) kloc(1) ! this is ok with AGRIF |
---|
| 483 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1 ! how many digits to we need to write jpjglo? (we decide max = 9) |
---|
| 484 | cl4 = '(i'//clfmt//')' ; WRITE(clj, cl4) kloc(2) ! this is ok with AGRIF |
---|
| 485 | ! |
---|
| 486 | IF( ksum == 1 ) THEN ; WRITE(clsuff,9100) TRIM(clmin) |
---|
| 487 | ELSE ; WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax) |
---|
| 488 | ENDIF |
---|
| 489 | IF(kloc(3) == 0) THEN |
---|
| 490 | ifmtk = INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 491 | clk = REPEAT(' ', ifmtk) ! create the equivalent in blank string |
---|
| 492 | WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff) |
---|
| 493 | ELSE |
---|
| 494 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 495 | !!! WRITE(clk, '(i'//clfmt//')') kloc(3) ! this is creating a compilation error with AGRIF |
---|
| 496 | cl4 = '(i'//clfmt//')' ; WRITE(clk, cl4) kloc(3) ! this is ok with AGRIF |
---|
| 497 | WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), TRIM(clk), TRIM(clsuff) |
---|
| 498 | ENDIF |
---|
| 499 | ! |
---|
| 500 | 9100 FORMAT('MPI rank ', a) |
---|
| 501 | 9200 FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a) |
---|
| 502 | 9300 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j ', a, ' ', a, ' ', a, ' ', a) |
---|
| 503 | 9400 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a) |
---|
| 504 | ! |
---|
| 505 | END SUBROUTINE wrt_line |
---|
| 506 | |
---|
| 507 | |
---|
[3] | 508 | !!====================================================================== |
---|
| 509 | END MODULE stpctl |
---|