[12983] | 1 | MODULE stpctl |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE stpctl *** |
---|
| 4 | !! Ocean run control : gross check of the ocean time stepping |
---|
[14053] | 5 | !! *** Shallow Water Equation (SWE) case *** |
---|
| 6 | !! ( No test on temperature and salinity ) |
---|
[12983] | 7 | !!====================================================================== |
---|
[14053] | 8 | !! History : SWE ! 2020-09 (A. Nasser, S. Techene ) OCE/stpctl adaptated to SWE |
---|
[12983] | 9 | !!---------------------------------------------------------------------- |
---|
| 10 | |
---|
| 11 | !!---------------------------------------------------------------------- |
---|
| 12 | !! stp_ctl : Control the run |
---|
| 13 | !!---------------------------------------------------------------------- |
---|
| 14 | USE oce ! ocean dynamics and tracers variables |
---|
| 15 | USE dom_oce ! ocean space and time domain variables |
---|
| 16 | USE c1d ! 1D vertical configuration |
---|
[13458] | 17 | USE zdf_oce , ONLY : ln_zad_Aimp ! ocean vertical physics variables |
---|
| 18 | USE wet_dry, ONLY : ll_wd, ssh_ref ! reference depth for negative bathy |
---|
[14053] | 19 | ! |
---|
[12983] | 20 | USE diawri ! Standard run outputs (dia_wri_state routine) |
---|
| 21 | USE in_out_manager ! I/O manager |
---|
| 22 | USE lbclnk ! ocean lateral boundary conditions (or mpp link) |
---|
| 23 | USE lib_mpp ! distributed memory computing |
---|
| 24 | USE netcdf ! NetCDF library |
---|
[14053] | 25 | |
---|
[12983] | 26 | IMPLICIT NONE |
---|
| 27 | PRIVATE |
---|
| 28 | |
---|
| 29 | PUBLIC stp_ctl ! routine called by step.F90 |
---|
| 30 | |
---|
[13458] | 31 | INTEGER :: nrunid ! netcdf file id |
---|
| 32 | INTEGER, DIMENSION(2) :: nvarid ! netcdf variable id |
---|
[14053] | 33 | |
---|
| 34 | # include "domzgr_substitute.h90" |
---|
[12983] | 35 | !!---------------------------------------------------------------------- |
---|
| 36 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
[13458] | 37 | !! $Id: stpctl.F90 13216 2020-07-02 09:25:49Z rblod $ |
---|
[12983] | 38 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
| 39 | !!---------------------------------------------------------------------- |
---|
| 40 | CONTAINS |
---|
| 41 | |
---|
[13458] | 42 | SUBROUTINE stp_ctl( kt, Kmm ) |
---|
[12983] | 43 | !!---------------------------------------------------------------------- |
---|
| 44 | !! *** ROUTINE stp_ctl *** |
---|
| 45 | !! |
---|
| 46 | !! ** Purpose : Control the run |
---|
| 47 | !! |
---|
| 48 | !! ** Method : - Save the time step in numstp |
---|
[14053] | 49 | !! - Print it each 50 time steps |
---|
[13458] | 50 | !! - Stop the run IF problem encountered by setting nstop > 0 |
---|
[14053] | 51 | !! Problems checked: e3t0+ssh minimum smaller that 0 |
---|
[12983] | 52 | !! |U| maximum larger than 10 m/s |
---|
[14053] | 53 | !! ( not for SWE : negative sea surface salinity ) |
---|
[12983] | 54 | !! |
---|
| 55 | !! ** Actions : "time.step" file = last ocean time-step |
---|
| 56 | !! "run.stat" file = run statistics |
---|
[13458] | 57 | !! nstop indicator sheared among all local domain |
---|
[12983] | 58 | !!---------------------------------------------------------------------- |
---|
| 59 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
[13458] | 60 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
[12983] | 61 | !! |
---|
[13458] | 62 | INTEGER :: ji ! dummy loop indices |
---|
| 63 | INTEGER :: idtime, istatus |
---|
| 64 | INTEGER , DIMENSION(3) :: iareasum, iareamin, iareamax |
---|
[14053] | 65 | INTEGER , DIMENSION(3,4) :: iloc ! min/max loc indices |
---|
[13458] | 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 |
---|
[12983] | 71 | !!---------------------------------------------------------------------- |
---|
[13458] | 72 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
[12983] | 73 | ! |
---|
[14053] | 74 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
| 75 | ! |
---|
[13458] | 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( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
| 89 | ! |
---|
| 90 | IF( ll_wrtruns ) THEN |
---|
| 91 | ! ! open run.stat ascii file, done only by 1st subdomain |
---|
[12983] | 92 | CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
[13458] | 93 | ! ! open run.stat.nc netcdf file, done only by 1st subdomain |
---|
[12983] | 94 | clname = 'run.stat.nc' |
---|
| 95 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
[13458] | 96 | istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, nrunid ) |
---|
| 97 | istatus = NF90_DEF_DIM( nrunid, 'time', NF90_UNLIMITED, idtime ) |
---|
| 98 | istatus = NF90_DEF_VAR( nrunid, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), nvarid(1) ) |
---|
| 99 | istatus = NF90_DEF_VAR( nrunid, 'abs_u_max', NF90_DOUBLE, (/ idtime /), nvarid(2) ) |
---|
| 100 | istatus = NF90_ENDDEF(nrunid) |
---|
[12983] | 101 | ENDIF |
---|
[13458] | 102 | ! |
---|
[12983] | 103 | ENDIF |
---|
| 104 | ! |
---|
[13458] | 105 | ! !== write current time step ==! |
---|
| 106 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
| 107 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
[12983] | 108 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
| 109 | REWIND( numstp ) |
---|
| 110 | ENDIF |
---|
[13458] | 111 | ! !== test of local extrema ==! |
---|
| 112 | ! !== done by all processes at every time step ==! |
---|
[14053] | 113 | zmax(1) = MINVAL( e3t_0(:,:,1)+ssh(:,:,Kmm) ) ! e3t_Kmm min |
---|
| 114 | llmsk(:,:,:) = umask(:,:,:) == 1._wp |
---|
| 115 | zmax(2) = MAXVAL( ABS( uu(:,:,:,Kmm) ), mask = llmsk ) ! velocity max (zonal only) |
---|
| 116 | zmax(3) = REAL( nstop , wp ) ! stop indicator |
---|
| 117 | ! !== get global extrema ==! |
---|
| 118 | ! !== done by all processes if writting run.stat ==! |
---|
[13458] | 119 | llmsk(Nis0:Nie0,Njs0:Nje0,1) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp ! define only the inner domain |
---|
| 120 | zmax(1) = MAXVAL( -e3t(:,:,1,Kmm) ), mask = llmsk(:,:,1) ) ! ssh max |
---|
| 121 | llmsk(Nis0:Nie0,Njs0:Nje0,:) = umask(Nis0:Nie0,Njs0:Nje0,:) == 1._wp ! define only the inner domain |
---|
| 122 | zmax(2) = MAXVAL( ABS( uu(:,:,:,Kmm) ), mask = llmsk(:,:,:) ) ! velocity max (zonal only) |
---|
| 123 | zmax(3) = REAL( nstop, wp ) ! stop indicator |
---|
| 124 | ! !== get global extrema ==! |
---|
| 125 | ! !== done by all processes if writting run.stat ==! |
---|
[12983] | 126 | IF( ll_colruns ) THEN |
---|
[13458] | 127 | zmaxlocal(:) = zmax(:) |
---|
[12983] | 128 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain |
---|
[13458] | 129 | nstop = NINT( zmax(3) ) ! update nstop indicator (now sheared among all local domains) |
---|
[12983] | 130 | ENDIF |
---|
[13458] | 131 | ! !== write "run.stat" files ==! |
---|
| 132 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
[12983] | 133 | IF( ll_wrtruns ) THEN |
---|
| 134 | WRITE(numrun,9500) kt, zmax(1), zmax(2) |
---|
[14053] | 135 | istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) ) |
---|
| 136 | istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) ) |
---|
[13458] | 137 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
[14053] | 138 | ENDIF |
---|
[13458] | 139 | ! !== error handling ==! |
---|
| 140 | ! !== done by all processes at every time step ==! |
---|
| 141 | ! |
---|
[14053] | 142 | !!SWE specific : start |
---|
| 143 | IF( zmax(1) <= 0._wp .OR. & ! negative e3t_Kmm |
---|
| 144 | & zmax(2) > 10._wp .OR. & ! too large velocity ( > 10 m/s) |
---|
[13458] | 145 | & ISNAN( zmax(1) + zmax(2) ) .OR. & ! NaN encounter in the tests |
---|
| 146 | & ABS( zmax(1) + zmax(2) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
| 147 | ! |
---|
| 148 | iloc(:,:) = 0 |
---|
| 149 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
| 150 | ! first: close the netcdf file, so we can read it |
---|
| 151 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
| 152 | ! get global loc on the min/max |
---|
[14053] | 153 | CALL mpp_minloc( 'stpctl', e3t_0(:,:,1) + ssh(:,:,Kmm), ssmask(:,: ), zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
| 154 | CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:,Kmm)) , umask(:,:,:), zzz, iloc(1:3,2) ) |
---|
[13458] | 155 | ! find which subdomain has the max. |
---|
| 156 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
| 157 | DO ji = 1, 3 |
---|
| 158 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
| 159 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
| 160 | ENDIF |
---|
| 161 | END DO |
---|
| 162 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
| 163 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
| 164 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
| 165 | ELSE ! find local min and max locations: |
---|
| 166 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
[14053] | 167 | iloc(1:2,1) = MINLOC( e3t_0(:,:,1) + ssh(:,:,Kmm), mask = ssmask(:,: ) == 1._wp ) + (/ nimpp - 1, njmpp - 1 /) |
---|
| 168 | iloc(1:3,2) = MAXLOC( ABS( uu(:,:,:, Kmm)), mask = umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
[13458] | 169 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
| 170 | ENDIF |
---|
| 171 | ! |
---|
[14053] | 172 | WRITE(ctmp1,*) ' stp_ctl: e3t0+ssh < 0 m or |U| > 10 m/s or NaN encounter in the tests' |
---|
| 173 | CALL wrt_line( ctmp2, kt, 'e3t0+ssh min', zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) ) |
---|
| 174 | CALL wrt_line( ctmp3, kt, '|U| max' , zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) ) |
---|
[13458] | 175 | IF( Agrif_Root() ) THEN |
---|
| 176 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
[12983] | 177 | ELSE |
---|
[13458] | 178 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
[12983] | 179 | ENDIF |
---|
[13458] | 180 | ! |
---|
[12983] | 181 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
[13458] | 182 | ! |
---|
| 183 | IF( ll_colruns .or. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
| 184 | IF(lwp) THEN ; CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 ) |
---|
| 185 | ELSE ; nstop = MAX(1, nstop) ! make sure nstop > 0 (automatically done when calling ctl_stop) |
---|
| 186 | ENDIF |
---|
| 187 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
| 188 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ' ', ctmp6 ) |
---|
[12983] | 189 | ENDIF |
---|
| 190 | ! |
---|
| 191 | ENDIF |
---|
[14053] | 192 | !!SWE specific : end |
---|
[12983] | 193 | ! |
---|
[13458] | 194 | IF( nstop > 0 ) THEN ! an error was detected and we did not abort yet... |
---|
| 195 | ngrdstop = Agrif_Fixed() ! store which grid got this error |
---|
| 196 | IF( .NOT. ll_colruns .AND. jpnij > 1 ) CALL ctl_stop( 'STOP' ) ! we must abort here to avoid MPI deadlock |
---|
| 197 | ENDIF |
---|
[12983] | 198 | ! |
---|
[14053] | 199 | 9500 FORMAT(' it :', i8, ' e3t_min: ', D23.16, ' |U|_max: ', D23.16) |
---|
[13458] | 200 | ! |
---|
[12983] | 201 | END SUBROUTINE stp_ctl |
---|
| 202 | |
---|
[13458] | 203 | |
---|
| 204 | SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax ) |
---|
| 205 | !!---------------------------------------------------------------------- |
---|
| 206 | !! *** ROUTINE wrt_line *** |
---|
| 207 | !! |
---|
| 208 | !! ** Purpose : write information line |
---|
| 209 | !! |
---|
| 210 | !!---------------------------------------------------------------------- |
---|
| 211 | CHARACTER(len=*), INTENT( out) :: cdline |
---|
| 212 | CHARACTER(len=*), INTENT(in ) :: cdprefix |
---|
| 213 | REAL(wp), INTENT(in ) :: pval |
---|
| 214 | INTEGER, DIMENSION(3), INTENT(in ) :: kloc |
---|
| 215 | INTEGER, INTENT(in ) :: kt, ksum, kmin, kmax |
---|
| 216 | ! |
---|
| 217 | CHARACTER(len=80) :: clsuff |
---|
| 218 | CHARACTER(len=9 ) :: clkt, clsum, clmin, clmax |
---|
| 219 | CHARACTER(len=9 ) :: cli, clj, clk |
---|
| 220 | CHARACTER(len=1 ) :: clfmt |
---|
| 221 | CHARACTER(len=4 ) :: cl4 ! needed to be able to compile with Agrif, I don't know why |
---|
| 222 | INTEGER :: ifmtk |
---|
| 223 | !!---------------------------------------------------------------------- |
---|
| 224 | WRITE(clkt , '(i9)') kt |
---|
| 225 | |
---|
| 226 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij ,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
| 227 | !!! WRITE(clsum, '(i'//clfmt//')') ksum ! this is creating a compilation error with AGRIF |
---|
| 228 | cl4 = '(i'//clfmt//')' ; WRITE(clsum, cl4) ksum |
---|
| 229 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
| 230 | cl4 = '(i'//clfmt//')' ; WRITE(clmin, cl4) kmin-1 |
---|
| 231 | WRITE(clmax, cl4) kmax-1 |
---|
| 232 | ! |
---|
| 233 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1 ! how many digits to we need to write jpiglo? (we decide max = 9) |
---|
| 234 | cl4 = '(i'//clfmt//')' ; WRITE(cli, cl4) kloc(1) ! this is ok with AGRIF |
---|
| 235 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1 ! how many digits to we need to write jpjglo? (we decide max = 9) |
---|
| 236 | cl4 = '(i'//clfmt//')' ; WRITE(clj, cl4) kloc(2) ! this is ok with AGRIF |
---|
| 237 | ! |
---|
| 238 | IF( ksum == 1 ) THEN ; WRITE(clsuff,9100) TRIM(clmin) |
---|
| 239 | ELSE ; WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax) |
---|
| 240 | ENDIF |
---|
| 241 | IF(kloc(3) == 0) THEN |
---|
| 242 | ifmtk = INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 243 | clk = REPEAT(' ', ifmtk) ! create the equivalent in blank string |
---|
| 244 | WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff) |
---|
| 245 | ELSE |
---|
| 246 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
| 247 | !!! WRITE(clk, '(i'//clfmt//')') kloc(3) ! this is creating a compilation error with AGRIF |
---|
| 248 | cl4 = '(i'//clfmt//')' ; WRITE(clk, cl4) kloc(3) ! this is ok with AGRIF |
---|
| 249 | WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), TRIM(clk), TRIM(clsuff) |
---|
| 250 | ENDIF |
---|
| 251 | ! |
---|
| 252 | 9100 FORMAT('MPI rank ', a) |
---|
| 253 | 9200 FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a) |
---|
| 254 | 9300 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j ', a, ' ', a, ' ', a, ' ', a) |
---|
| 255 | 9400 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a) |
---|
| 256 | ! |
---|
| 257 | END SUBROUTINE wrt_line |
---|
| 258 | |
---|
| 259 | |
---|
[12983] | 260 | !!====================================================================== |
---|
| 261 | END MODULE stpctl |
---|