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 | !!---------------------------------------------------------------------- |
---|
18 | USE oce ! ocean dynamics and tracers variables |
---|
19 | USE dom_oce ! ocean space and time domain variables |
---|
20 | USE c1d ! 1D vertical configuration |
---|
21 | USE diawri ! Standard run outputs (dia_wri_state routine) |
---|
22 | ! |
---|
23 | USE in_out_manager ! I/O manager |
---|
24 | USE lbclnk ! ocean lateral boundary conditions (or mpp link) |
---|
25 | USE lib_mpp ! distributed memory computing |
---|
26 | USE zdf_oce , ONLY : ln_zad_Aimp ! ocean vertical physics variables |
---|
27 | USE wet_dry, ONLY : ll_wd, ssh_ref ! reference depth for negative bathy |
---|
28 | |
---|
29 | USE netcdf ! NetCDF library |
---|
30 | IMPLICIT NONE |
---|
31 | PRIVATE |
---|
32 | |
---|
33 | PUBLIC stp_ctl ! routine called by step.F90 |
---|
34 | |
---|
35 | INTEGER :: idrun, idtime, idssh, idu, ids1, ids2, idt1, idt2, idc1, idw1, istatus |
---|
36 | !!---------------------------------------------------------------------- |
---|
37 | !! NEMO/OCE 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 ) |
---|
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: |ssh| maximum larger than 10 m |
---|
53 | !! |U| maximum larger than 10 m/s |
---|
54 | !! negative sea surface salinity |
---|
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 | !! |
---|
62 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
63 | INTEGER, DIMENSION(3) :: ih, iu, is1, is2 ! min/max loc indices |
---|
64 | INTEGER, DIMENSION(9) :: iareasum, iareamin, iareamax |
---|
65 | REAL(wp) :: zzz ! local real |
---|
66 | REAL(wp), DIMENSION(9) :: zmax, zmaxlocal |
---|
67 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns |
---|
68 | CHARACTER(len=20) :: clname |
---|
69 | !!---------------------------------------------------------------------- |
---|
70 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
71 | ! |
---|
72 | ll_wrtstp = ( MOD( kt-nit000, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) |
---|
73 | ll_colruns = ll_wrtstp .AND. sn_cfctl%l_runstat .AND. jpnij > 1 |
---|
74 | ll_wrtruns = ( ll_colruns .OR. jpnij == 1 ) .AND. lwm |
---|
75 | ! |
---|
76 | IF( kt == nit000 ) THEN |
---|
77 | ! |
---|
78 | IF( lwp ) THEN |
---|
79 | WRITE(numout,*) |
---|
80 | WRITE(numout,*) 'stp_ctl : time-stepping control' |
---|
81 | WRITE(numout,*) '~~~~~~~' |
---|
82 | ENDIF |
---|
83 | ! ! open time.step file |
---|
84 | IF( lwm ) CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
85 | ! ! open run.stat file(s) at start whatever |
---|
86 | ! ! the value of sn_cfctl%ptimincr |
---|
87 | IF( ll_wrtruns ) THEN |
---|
88 | CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
89 | clname = 'run.stat.nc' |
---|
90 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
91 | istatus = NF90_CREATE( TRIM(clname), NF90_CLOBBER, idrun ) |
---|
92 | istatus = NF90_DEF_DIM( idrun, 'time', NF90_UNLIMITED, idtime ) |
---|
93 | istatus = NF90_DEF_VAR( idrun, 'abs_ssh_max', NF90_DOUBLE, (/ idtime /), idssh ) |
---|
94 | istatus = NF90_DEF_VAR( idrun, 'abs_u_max', NF90_DOUBLE, (/ idtime /), idu ) |
---|
95 | istatus = NF90_DEF_VAR( idrun, 's_min', NF90_DOUBLE, (/ idtime /), ids1 ) |
---|
96 | istatus = NF90_DEF_VAR( idrun, 's_max', NF90_DOUBLE, (/ idtime /), ids2 ) |
---|
97 | istatus = NF90_DEF_VAR( idrun, 't_min', NF90_DOUBLE, (/ idtime /), idt1 ) |
---|
98 | istatus = NF90_DEF_VAR( idrun, 't_max', NF90_DOUBLE, (/ idtime /), idt2 ) |
---|
99 | IF( ln_zad_Aimp ) THEN |
---|
100 | istatus = NF90_DEF_VAR( idrun, 'abs_wi_max', NF90_DOUBLE, (/ idtime /), idw1 ) |
---|
101 | istatus = NF90_DEF_VAR( idrun, 'Cf_max', NF90_DOUBLE, (/ idtime /), idc1 ) |
---|
102 | ENDIF |
---|
103 | istatus = NF90_ENDDEF(idrun) |
---|
104 | ENDIF |
---|
105 | ENDIF |
---|
106 | ! |
---|
107 | IF(lwm .AND. ll_wrtstp) THEN !== current time step ==! ("time.step" file) |
---|
108 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
109 | REWIND( numstp ) |
---|
110 | ENDIF |
---|
111 | ! |
---|
112 | ! !== test of extrema ==! |
---|
113 | IF( ll_wd ) THEN |
---|
114 | zmax(1) = MAXVAL( ABS( sshn(:,:) + ssh_ref*tmask(:,:,1) ) ) ! ssh max |
---|
115 | ELSE |
---|
116 | zmax(1) = MAXVAL( ABS( sshn(:,:) ) ) ! ssh max |
---|
117 | ENDIF |
---|
118 | zmax(2) = MAXVAL( ABS( un(:,:,:) ) ) ! velocity max (zonal only) |
---|
119 | zmax(3) = MAXVAL( -tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp ) ! minus salinity max |
---|
120 | zmax(4) = MAXVAL( tsn(:,:,:,jp_sal) , mask = tmask(:,:,:) == 1._wp ) ! salinity max |
---|
121 | IF( ll_colruns ) THEN ! following variables are used only in the netcdf file |
---|
122 | zmax(5) = MAXVAL( -tsn(:,:,:,jp_tem) , mask = tmask(:,:,:) == 1._wp ) ! minus temperature max |
---|
123 | zmax(6) = MAXVAL( tsn(:,:,:,jp_tem) , mask = tmask(:,:,:) == 1._wp ) ! temperature max |
---|
124 | IF( ln_zad_Aimp ) THEN |
---|
125 | zmax(8) = MAXVAL( ABS( wi(:,:,:) ) , mask = wmask(:,:,:) == 1._wp ) ! implicit vertical vel. max |
---|
126 | zmax(9) = MAXVAL( Cu_adv(:,:,:) , mask = tmask(:,:,:) == 1._wp ) ! partitioning coeff. max |
---|
127 | ELSE |
---|
128 | zmax(8:9) = 0._wp |
---|
129 | ENDIF |
---|
130 | ELSE |
---|
131 | zmax(5:9) = 0._wp |
---|
132 | ENDIF |
---|
133 | zmax(7) = REAL( nstop , wp ) ! stop indicator |
---|
134 | ! |
---|
135 | IF( ll_colruns ) THEN |
---|
136 | zmaxlocal(:) = zmax(:) |
---|
137 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain |
---|
138 | nstop = NINT( zmax(7) ) ! nstop indicator sheared among all local domains |
---|
139 | ENDIF |
---|
140 | ! !== run statistics ==! ("run.stat" files) |
---|
141 | IF( ll_wrtruns ) THEN |
---|
142 | WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4) |
---|
143 | istatus = NF90_PUT_VAR( idrun, idssh, (/ zmax(1)/), (/kt/), (/1/) ) |
---|
144 | istatus = NF90_PUT_VAR( idrun, idu, (/ zmax(2)/), (/kt/), (/1/) ) |
---|
145 | istatus = NF90_PUT_VAR( idrun, ids1, (/-zmax(3)/), (/kt/), (/1/) ) |
---|
146 | istatus = NF90_PUT_VAR( idrun, ids2, (/ zmax(4)/), (/kt/), (/1/) ) |
---|
147 | istatus = NF90_PUT_VAR( idrun, idt1, (/-zmax(5)/), (/kt/), (/1/) ) |
---|
148 | istatus = NF90_PUT_VAR( idrun, idt2, (/ zmax(6)/), (/kt/), (/1/) ) |
---|
149 | IF( ln_zad_Aimp ) THEN |
---|
150 | istatus = NF90_PUT_VAR( idrun, idw1, (/ zmax(8)/), (/kt/), (/1/) ) |
---|
151 | istatus = NF90_PUT_VAR( idrun, idc1, (/ zmax(9)/), (/kt/), (/1/) ) |
---|
152 | ENDIF |
---|
153 | IF( kt == nitend ) istatus = NF90_CLOSE(idrun) |
---|
154 | END IF |
---|
155 | ! !== error handling ==! |
---|
156 | IF( zmax(1) > 20._wp .OR. & ! too large sea surface height ( > 20 m ) |
---|
157 | & zmax(2) > 10._wp .OR. & ! too large velocity ( > 10 m/s) |
---|
158 | & zmax(3) >= 0._wp .OR. & ! negative or zero sea surface salinity |
---|
159 | & zmax(4) >= 100._wp .OR. & ! too large sea surface salinity ( > 100 ) |
---|
160 | & zmax(4) < 0._wp .OR. & ! too large sea surface salinity (keep this line for sea-ice) |
---|
161 | & ISNAN( zmax(1) + zmax(2) + zmax(3) ) .OR. & ! NaN encounter in the tests |
---|
162 | & ABS( zmax(1) + zmax(2) + zmax(3) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
163 | IF( ll_colruns ) THEN |
---|
164 | ! first: close the netcdf file, so we can read it |
---|
165 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(idrun) |
---|
166 | CALL mpp_maxloc( 'stpctl', ABS(sshn) , ssmask(:,:) , zzz, ih(1:2) ) ; ih(3) = 0 |
---|
167 | CALL mpp_maxloc( 'stpctl', ABS(un) , umask (:,:,:), zzz, iu ) |
---|
168 | CALL mpp_minloc( 'stpctl', tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, is1 ) |
---|
169 | CALL mpp_maxloc( 'stpctl', tsn(:,:,:,jp_sal), tmask (:,:,:), zzz, is2 ) |
---|
170 | ! find which subdomain has the max. |
---|
171 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
172 | DO ji = 1, 9 |
---|
173 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
174 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
175 | ENDIF |
---|
176 | END DO |
---|
177 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
178 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
179 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
180 | ELSE |
---|
181 | ih(1:2)= MAXLOC( ABS( sshn(:,:) ) ) + (/ nimpp - 1, njmpp - 1 /) ; ih(3) = 0 |
---|
182 | iu(:) = MAXLOC( ABS( un (:,:,:) ) ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
183 | is1(:) = MINLOC( tsn(:,:,:,jp_sal), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
184 | is2(:) = MAXLOC( tsn(:,:,:,jp_sal), mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
185 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
186 | ENDIF |
---|
187 | ! |
---|
188 | WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m or |U| > 10 m/s or S <= 0 or S >= 100 or NaN encounter in the tests' |
---|
189 | CALL wrt_line(ctmp2, kt, ' |ssh| max ', zmax(1), ih , iareasum(1), iareamin(1), iareamax(1) ) |
---|
190 | CALL wrt_line(ctmp3, kt, ' |U| max ', zmax(2), iu , iareasum(2), iareamin(2), iareamax(2) ) |
---|
191 | CALL wrt_line(ctmp4, kt, ' Sal min ', - zmax(3), is1, iareasum(3), iareamin(3), iareamax(3) ) |
---|
192 | CALL wrt_line(ctmp5, kt, ' Sal max ', zmax(4), is2, iareasum(4), iareamin(4), iareamax(4) ) |
---|
193 | IF( Agrif_Root() ) THEN |
---|
194 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
195 | ELSE |
---|
196 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
197 | ENDIF |
---|
198 | ! |
---|
199 | CALL dia_wri_state( 'output.abort' ) ! create an output.abort file |
---|
200 | ! |
---|
201 | IF( ll_colruns .or. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
202 | IF(lwp) CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
203 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
204 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
205 | ENDIF |
---|
206 | ! |
---|
207 | IF( nstop == 0 ) nstop = 1 |
---|
208 | ngrdstop = Agrif_Fixed() |
---|
209 | ! |
---|
210 | ENDIF |
---|
211 | ! |
---|
212 | 9500 FORMAT(' it :', i8, ' |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16) |
---|
213 | ! |
---|
214 | END SUBROUTINE stp_ctl |
---|
215 | |
---|
216 | |
---|
217 | SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax ) |
---|
218 | !!---------------------------------------------------------------------- |
---|
219 | !! *** ROUTINE wrt_line *** |
---|
220 | !! |
---|
221 | !! ** Purpose : write information line |
---|
222 | !! |
---|
223 | !!---------------------------------------------------------------------- |
---|
224 | CHARACTER(len=*), INTENT( out) :: cdline |
---|
225 | CHARACTER(len=*), INTENT(in ) :: cdprefix |
---|
226 | REAL(wp), INTENT(in ) :: pval |
---|
227 | INTEGER, DIMENSION(3), INTENT(in ) :: kloc |
---|
228 | INTEGER, INTENT(in ) :: kt, ksum, kmin, kmax |
---|
229 | ! |
---|
230 | CHARACTER(len=80) :: clsuff |
---|
231 | CHARACTER(len=9 ) :: clkt, clsum, clmin, clmax |
---|
232 | CHARACTER(len=9 ) :: cli, clj, clk |
---|
233 | CHARACTER(len=1 ) :: clfmt |
---|
234 | CHARACTER(len=4 ) :: cl4 ! needed to be able to compile with Agrif, I don't know why |
---|
235 | INTEGER :: ifmtk |
---|
236 | !!---------------------------------------------------------------------- |
---|
237 | WRITE(clkt , '(i9)') kt |
---|
238 | |
---|
239 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij ,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
240 | !!! WRITE(clsum, '(i'//clfmt//')') ksum ! this is creating a compilation error with AGRIF |
---|
241 | cl4 = '(i'//clfmt//')' ; WRITE(clsum, cl4) ksum |
---|
242 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij-1,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
243 | cl4 = '(i'//clfmt//')' ; WRITE(clmin, cl4) kmin-1 |
---|
244 | WRITE(clmax, cl4) kmax-1 |
---|
245 | ! |
---|
246 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1 ! how many digits to we need to write jpiglo? (we decide max = 9) |
---|
247 | cl4 = '(i'//clfmt//')' ; WRITE(cli, cl4) kloc(1) ! this is ok with AGRIF |
---|
248 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1 ! how many digits to we need to write jpjglo? (we decide max = 9) |
---|
249 | cl4 = '(i'//clfmt//')' ; WRITE(clj, cl4) kloc(2) ! this is ok with AGRIF |
---|
250 | ! |
---|
251 | IF( ksum == 1 ) THEN ; WRITE(clsuff,9100) TRIM(clmin) |
---|
252 | ELSE ; WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax) |
---|
253 | ENDIF |
---|
254 | IF(kloc(3) == 0) THEN |
---|
255 | ifmtk = INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
256 | clk = REPEAT(' ', ifmtk) ! create the equivalent in blank string |
---|
257 | WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff) |
---|
258 | ELSE |
---|
259 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
260 | !!! WRITE(clk, '(i'//clfmt//')') kloc(3) ! this is creating a compilation error with AGRIF |
---|
261 | cl4 = '(i'//clfmt//')' ; WRITE(clk, cl4) kloc(3) ! this is ok with AGRIF |
---|
262 | WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), TRIM(clk), TRIM(clsuff) |
---|
263 | ENDIF |
---|
264 | ! |
---|
265 | 9100 FORMAT('MPI rank ', a) |
---|
266 | 9200 FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a) |
---|
267 | 9300 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j ', a, ' ', a, ' ', a, ' ', a) |
---|
268 | 9400 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a) |
---|
269 | ! |
---|
270 | END SUBROUTINE wrt_line |
---|
271 | |
---|
272 | |
---|
273 | !!====================================================================== |
---|
274 | END MODULE stpctl |
---|