1 | MODULE stpctl |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE stpctl *** |
---|
4 | !! Ocean run control : gross check of the ocean time stepping |
---|
5 | !! version for STATION_ASF test-case |
---|
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.7 ! 2016-09 (G. Madec) Remove solver |
---|
13 | !! 4.0 ! 2017-04 (G. Madec) regroup global communications |
---|
14 | !!---------------------------------------------------------------------- |
---|
15 | |
---|
16 | !!---------------------------------------------------------------------- |
---|
17 | !! stp_ctl : Control the run |
---|
18 | !!---------------------------------------------------------------------- |
---|
19 | USE dom_oce ! ocean space and time domain variables |
---|
20 | USE sbc_oce ! surface fluxes and stuff |
---|
21 | ! |
---|
22 | USE diawri ! Standard run outputs (dia_wri_state routine) |
---|
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 | ! |
---|
27 | USE netcdf ! NetCDF library |
---|
28 | IMPLICIT NONE |
---|
29 | PRIVATE |
---|
30 | |
---|
31 | PUBLIC stp_ctl ! routine called by step.F90 |
---|
32 | |
---|
33 | INTEGER, PARAMETER :: jpvar = 3 |
---|
34 | INTEGER :: nrunid ! netcdf file id |
---|
35 | INTEGER, DIMENSION(jpvar) :: nvarid ! netcdf variable id |
---|
36 | !!---------------------------------------------------------------------- |
---|
37 | !! NEMO/SAS 4.0 , NEMO Consortium (2018) |
---|
38 | !! $Id: stpctl.F90 10603 2019-01-29 11:18:09Z acc $ |
---|
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 | !! - Stop the run IF problem encountered by setting nstop > 0 |
---|
51 | !! Problems checked: wind stress module max larger than 5 N/m^2 |
---|
52 | !! non-solar heat flux max larger than 2000 W/m^2 |
---|
53 | !! Evaporation-Precip max larger than 1.E-3 kg/m^2/s |
---|
54 | !! |
---|
55 | !! ** Actions : "time.step" file = last ocean time-step |
---|
56 | !! "run.stat" file = run statistics |
---|
57 | !! nstop indicator sheared among all local domain |
---|
58 | !!---------------------------------------------------------------------- |
---|
59 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
60 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
61 | !! |
---|
62 | INTEGER, PARAMETER :: jptst = 3 |
---|
63 | INTEGER :: ji ! dummy loop indices |
---|
64 | INTEGER :: idtime, istatus |
---|
65 | INTEGER , DIMENSION(jptst) :: iareasum, iareamin, iareamax |
---|
66 | INTEGER , DIMENSION(3,jptst) :: iloc ! min/max loc indices |
---|
67 | REAL(wp) :: zzz ! local real |
---|
68 | REAL(wp), DIMENSION(jpvar+1) :: zmax |
---|
69 | REAL(wp), DIMENSION(jptst) :: zmaxlocal |
---|
70 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns, ll_0oce |
---|
71 | LOGICAL, DIMENSION(jpi,jpj) :: llmsk |
---|
72 | CHARACTER(len=20) :: clname |
---|
73 | !!---------------------------------------------------------------------- |
---|
74 | IF( nstop > 0 .AND. ngrdstop > -1 ) RETURN ! stpctl was already called by a child grid |
---|
75 | ! |
---|
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 |
---|
92 | CALL ctl_opn( numrun, 'run.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea ) |
---|
93 | ! ! open run.stat.nc netcdf file, done only by 1st subdomain |
---|
94 | clname = 'run.stat.nc' |
---|
95 | IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//"_"//TRIM(clname) |
---|
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, 'tau_max', NF90_DOUBLE, (/ idtime /), nvarid(1) ) |
---|
99 | istatus = NF90_DEF_VAR( nrunid, 'qns_max', NF90_DOUBLE, (/ idtime /), nvarid(2) ) |
---|
100 | istatus = NF90_DEF_VAR( nrunid, 'emp_max', NF90_DOUBLE, (/ idtime /), nvarid(3) ) |
---|
101 | istatus = NF90_ENDDEF(nrunid) |
---|
102 | ENDIF |
---|
103 | ! |
---|
104 | ENDIF |
---|
105 | ! |
---|
106 | ! !== write current time step ==! |
---|
107 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
108 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
109 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
110 | REWIND( numstp ) |
---|
111 | ENDIF |
---|
112 | ! !== test of local extrema ==! |
---|
113 | ! !== done by all processes at every time step ==! |
---|
114 | ! |
---|
115 | llmsk( 1:nn_hls,:) = .FALSE. ! exclude halos from the checked region |
---|
116 | llmsk(Nie0+1: jpi,:) = .FALSE. |
---|
117 | llmsk(:, 1:nn_hls) = .FALSE. |
---|
118 | llmsk(:,Nje0+1: jpj) = .FALSE. |
---|
119 | ! |
---|
120 | llmsk(Nis0:Nie0,Njs0:Nje0) = tmask(Nis0:Nie0,Njs0:Nje0,1) == 1._wp ! test only the inner domain |
---|
121 | ! |
---|
122 | ll_0oce = .NOT. ANY( llmsk(:,:) ) ! no ocean point in the inner domain? |
---|
123 | ! |
---|
124 | zmax(1) = MAXVAL( taum(:,:) , mask = llmsk ) ! max wind stress module |
---|
125 | zmax(2) = MAXVAL( ABS( qns(:,:) ), mask = llmsk ) ! max non-solar heat flux |
---|
126 | zmax(3) = MAXVAL( ABS( emp(:,:) ), mask = llmsk ) ! max E-P |
---|
127 | zmax(jpvar+1) = REAL( nstop, wp ) ! stop indicator |
---|
128 | ! |
---|
129 | ! !== get global extrema ==! |
---|
130 | ! !== done by all processes if writting run.stat ==! |
---|
131 | IF( ll_colruns ) THEN |
---|
132 | zmaxlocal(:) = zmax(1:jptst) |
---|
133 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain: ok even of ll_0oce = .true. |
---|
134 | nstop = NINT( zmax(jpvar+1) ) ! update nstop indicator (now sheared among all local domains) |
---|
135 | ELSE |
---|
136 | ! if no ocean point: MAXVAL returns -HUGE => we must overwrite this value to avoid error handling bellow. |
---|
137 | IF( ll_0oce ) zmax(1:jptst) = 0._wp ! default "valid" values... |
---|
138 | ENDIF |
---|
139 | ! !== write "run.stat" files ==! |
---|
140 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
141 | IF( ll_wrtruns ) THEN |
---|
142 | WRITE(numrun,9500) kt, zmax(1:jptst) |
---|
143 | DO ji = 1, jpvar |
---|
144 | istatus = NF90_PUT_VAR( nrunid, nvarid(ji), (/zmax(ji)/), (/kt/), (/1/) ) |
---|
145 | END DO |
---|
146 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
147 | END IF |
---|
148 | ! !== error handling ==! |
---|
149 | ! !== done by all processes at every time step ==! |
---|
150 | ! |
---|
151 | IF( zmax(1) > 5._wp .OR. & ! too large wind stress ( > 5 N/m^2 ) |
---|
152 | & zmax(2) > 2000._wp .OR. & ! too large non-solar heat flux ( > 2000 W/m^2 ) |
---|
153 | & zmax(3) > 1.E-3_wp .OR. & ! too large net freshwater flux ( > 1.E-3 kg/m^2/s ) |
---|
154 | & ISNAN( SUM(zmax(1:jptst)) ) .OR. & ! NaN encounter in the tests |
---|
155 | & ABS( SUM(zmax(1:jptst)) ) > HUGE(1._wp) ) THEN ! Infinity encounter in the tests |
---|
156 | ! |
---|
157 | iloc(:,:) = 0 |
---|
158 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
159 | ! first: close the netcdf file, so we can read it |
---|
160 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
161 | ! get global loc on the min/max |
---|
162 | CALL mpp_maxloc( 'stpctl', taum(:,:) , llmsk, zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
163 | CALL mpp_maxloc( 'stpctl',ABS( qns(:,:) ), llmsk, zzz, iloc(1:2,2) ) |
---|
164 | CALL mpp_minloc( 'stpctl',ABS( emp(:,:) ), llmsk, zzz, iloc(1:2,3) ) |
---|
165 | ! find which subdomain has the max. |
---|
166 | iareamin(:) = jpnij+1 ; iareamax(:) = 0 ; iareasum(:) = 0 |
---|
167 | DO ji = 1, jptst |
---|
168 | IF( zmaxlocal(ji) == zmax(ji) ) THEN |
---|
169 | iareamin(ji) = narea ; iareamax(ji) = narea ; iareasum(ji) = 1 |
---|
170 | ENDIF |
---|
171 | END DO |
---|
172 | CALL mpp_min( "stpctl", iareamin ) ! min over the global domain |
---|
173 | CALL mpp_max( "stpctl", iareamax ) ! max over the global domain |
---|
174 | CALL mpp_sum( "stpctl", iareasum ) ! sum over the global domain |
---|
175 | ELSE ! find local min and max locations: |
---|
176 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
177 | iloc(1:2,1) = MAXLOC( taum(:,:) , mask = llmsk ) |
---|
178 | iloc(1:2,2) = MAXLOC( ABS( qns(:,:) ), mask = llmsk ) |
---|
179 | iloc(1:2,3) = MINLOC( ABS( emp(:,:) ), mask = llmsk ) |
---|
180 | DO ji = 1, jptst ! local domain indices ==> global domain indices, excluding halos |
---|
181 | iloc(1:2,ji) = (/ mig0(iloc(1,ji)), mjg0(iloc(2,ji)) /) |
---|
182 | END DO |
---|
183 | iareamin(:) = narea ; iareamax(:) = narea ; iareasum(:) = 1 ! this is local information |
---|
184 | ENDIF |
---|
185 | ! |
---|
186 | WRITE(ctmp1,*) ' stp_ctl: |tau_mod| > 5 N/m2 or |qns| > 2000 W/m2 or |emp| > 1.E-3 or NaN encounter in the tests' |
---|
187 | CALL wrt_line( ctmp2, kt, '|tau| max', zmax(1), iloc(:,1), iareasum(1), iareamin(1), iareamax(1) ) |
---|
188 | CALL wrt_line( ctmp3, kt, '|qns| max', zmax(2), iloc(:,2), iareasum(2), iareamin(2), iareamax(2) ) |
---|
189 | CALL wrt_line( ctmp4, kt, 'emp max', zmax(3), iloc(:,3), iareasum(3), iareamin(3), iareamax(3) ) |
---|
190 | IF( Agrif_Root() ) THEN |
---|
191 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
192 | ELSE |
---|
193 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
194 | ENDIF |
---|
195 | ! |
---|
196 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
197 | ! |
---|
198 | IF( ll_colruns .OR. jpnij == 1 ) THEN ! all processes synchronized -> use lwp to print in opened ocean.output files |
---|
199 | IF(lwp) THEN ; CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
200 | ELSE ; nstop = MAX(1, nstop) ! make sure nstop > 0 (automatically done when calling ctl_stop) |
---|
201 | ENDIF |
---|
202 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
203 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
204 | ENDIF |
---|
205 | ! |
---|
206 | ENDIF |
---|
207 | ! |
---|
208 | IF( nstop > 0 ) THEN ! an error was detected and we did not abort yet... |
---|
209 | ngrdstop = Agrif_Fixed() ! store which grid got this error |
---|
210 | IF( .NOT. ll_colruns .AND. jpnij > 1 ) CALL ctl_stop( 'STOP' ) ! we must abort here to avoid MPI deadlock |
---|
211 | ENDIF |
---|
212 | ! |
---|
213 | 9500 FORMAT(' it :', i8, ' tau_max: ', D23.16, ' |qns|_max: ', D23.16,' |emp|_max: ', D23.16) |
---|
214 | ! |
---|
215 | END SUBROUTINE stp_ctl |
---|
216 | |
---|
217 | |
---|
218 | SUBROUTINE wrt_line( cdline, kt, cdprefix, pval, kloc, ksum, kmin, kmax ) |
---|
219 | !!---------------------------------------------------------------------- |
---|
220 | !! *** ROUTINE wrt_line *** |
---|
221 | !! |
---|
222 | !! ** Purpose : write information line |
---|
223 | !! |
---|
224 | !!---------------------------------------------------------------------- |
---|
225 | CHARACTER(len=*), INTENT( out) :: cdline |
---|
226 | CHARACTER(len=*), INTENT(in ) :: cdprefix |
---|
227 | REAL(wp), INTENT(in ) :: pval |
---|
228 | INTEGER, DIMENSION(3), INTENT(in ) :: kloc |
---|
229 | INTEGER, INTENT(in ) :: kt, ksum, kmin, kmax |
---|
230 | ! |
---|
231 | CHARACTER(len=80) :: clsuff |
---|
232 | CHARACTER(len=9 ) :: clkt, clsum, clmin, clmax |
---|
233 | CHARACTER(len=9 ) :: cli, clj, clk |
---|
234 | CHARACTER(len=1 ) :: clfmt |
---|
235 | CHARACTER(len=4 ) :: cl4 ! needed to be able to compile with Agrif, I don't know why |
---|
236 | INTEGER :: ifmtk |
---|
237 | !!---------------------------------------------------------------------- |
---|
238 | WRITE(clkt , '(i9)') kt |
---|
239 | |
---|
240 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpnij ,wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
241 | !!! WRITE(clsum, '(i'//clfmt//')') ksum ! this is creating a compilation error with AGRIF |
---|
242 | cl4 = '(i'//clfmt//')' ; WRITE(clsum, cl4) ksum |
---|
243 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1 ! how many digits to we need to write ? (we decide max = 9) |
---|
244 | cl4 = '(i'//clfmt//')' ; WRITE(clmin, cl4) kmin-1 |
---|
245 | WRITE(clmax, cl4) kmax-1 |
---|
246 | ! |
---|
247 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpiglo,wp))) + 1 ! how many digits to we need to write jpiglo? (we decide max = 9) |
---|
248 | cl4 = '(i'//clfmt//')' ; WRITE(cli, cl4) kloc(1) ! this is ok with AGRIF |
---|
249 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpjglo,wp))) + 1 ! how many digits to we need to write jpjglo? (we decide max = 9) |
---|
250 | cl4 = '(i'//clfmt//')' ; WRITE(clj, cl4) kloc(2) ! this is ok with AGRIF |
---|
251 | ! |
---|
252 | IF( ksum == 1 ) THEN ; WRITE(clsuff,9100) TRIM(clmin) |
---|
253 | ELSE ; WRITE(clsuff,9200) TRIM(clsum), TRIM(clmin), TRIM(clmax) |
---|
254 | ENDIF |
---|
255 | IF(kloc(3) == 0) THEN |
---|
256 | ifmtk = INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
257 | clk = REPEAT(' ', ifmtk) ! create the equivalent in blank string |
---|
258 | WRITE(cdline,9300) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), clk(1:ifmtk), TRIM(clsuff) |
---|
259 | ELSE |
---|
260 | WRITE(clfmt, '(i1)') INT(LOG10(REAL(jpk,wp))) + 1 ! how many digits to we need to write jpk? (we decide max = 9) |
---|
261 | !!! WRITE(clk, '(i'//clfmt//')') kloc(3) ! this is creating a compilation error with AGRIF |
---|
262 | cl4 = '(i'//clfmt//')' ; WRITE(clk, cl4) kloc(3) ! this is ok with AGRIF |
---|
263 | WRITE(cdline,9400) TRIM(ADJUSTL(clkt)), TRIM(ADJUSTL(cdprefix)), pval, TRIM(cli), TRIM(clj), TRIM(clk), TRIM(clsuff) |
---|
264 | ENDIF |
---|
265 | ! |
---|
266 | 9100 FORMAT('MPI rank ', a) |
---|
267 | 9200 FORMAT('found in ', a, ' MPI tasks, spread out among ranks ', a, ' to ', a) |
---|
268 | 9300 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j ', a, ' ', a, ' ', a, ' ', a) |
---|
269 | 9400 FORMAT('kt ', a, ' ', a, ' ', 1pg11.4, ' at i j k ', a, ' ', a, ' ', a, ' ', a) |
---|
270 | ! |
---|
271 | END SUBROUTINE wrt_line |
---|
272 | |
---|
273 | |
---|
274 | !!====================================================================== |
---|
275 | END MODULE stpctl |
---|