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