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