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 :: nrunid ! netcdf file id |
---|
36 | INTEGER, DIMENSION(8) :: nvarid ! netcdf variable id |
---|
37 | !!---------------------------------------------------------------------- |
---|
38 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
39 | !! $Id$ |
---|
40 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
41 | !!---------------------------------------------------------------------- |
---|
42 | CONTAINS |
---|
43 | |
---|
44 | SUBROUTINE stp_ctl( kt, Kmm ) |
---|
45 | !!---------------------------------------------------------------------- |
---|
46 | !! *** ROUTINE stp_ctl *** |
---|
47 | !! |
---|
48 | !! ** Purpose : Control the run |
---|
49 | !! |
---|
50 | !! ** Method : - Save the time step in numstp |
---|
51 | !! - Print it each 50 time steps |
---|
52 | !! - Stop the run IF problem encountered by setting nstop > 0 |
---|
53 | !! Problems checked: |ssh| maximum larger than 10 m |
---|
54 | !! |U| maximum larger than 10 m/s |
---|
55 | !! negative sea surface salinity |
---|
56 | !! |
---|
57 | !! ** Actions : "time.step" file = last ocean time-step |
---|
58 | !! "run.stat" file = run statistics |
---|
59 | !! nstop indicator sheared among all local domain |
---|
60 | !!---------------------------------------------------------------------- |
---|
61 | INTEGER, INTENT(in ) :: kt ! ocean time-step index |
---|
62 | INTEGER, INTENT(in ) :: Kmm ! ocean time level index |
---|
63 | !! |
---|
64 | INTEGER :: ji ! dummy loop indices |
---|
65 | INTEGER :: idtime, istatus |
---|
66 | INTEGER, DIMENSION(3,4) :: iloc ! min/max loc indices |
---|
67 | REAL(wp) :: zzz ! local real |
---|
68 | REAL(wp), DIMENSION(9) :: zmax, zmaxlocal, zarea |
---|
69 | LOGICAL :: ll_wrtstp, ll_colruns, ll_wrtruns |
---|
70 | LOGICAL, DIMENSION(jpi,jpj,jpk) :: 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 |
---|
77 | ll_wrtruns = ll_colruns .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, 'abs_ssh_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, 's_min', NF90_DOUBLE, (/ idtime /), nvarid(3) ) |
---|
100 | istatus = NF90_DEF_VAR( nrunid, 's_max', NF90_DOUBLE, (/ idtime /), nvarid(4) ) |
---|
101 | istatus = NF90_DEF_VAR( nrunid, 't_min', NF90_DOUBLE, (/ idtime /), nvarid(5) ) |
---|
102 | istatus = NF90_DEF_VAR( nrunid, 't_max', NF90_DOUBLE, (/ idtime /), nvarid(6) ) |
---|
103 | IF( ln_zad_Aimp ) THEN |
---|
104 | istatus = NF90_DEF_VAR( nrunid, 'Cf_max', NF90_DOUBLE, (/ idtime /), nvarid(7) ) |
---|
105 | istatus = NF90_DEF_VAR( nrunid,'abs_wi_max',NF90_DOUBLE, (/ idtime /), nvarid(8) ) |
---|
106 | ENDIF |
---|
107 | istatus = NF90_ENDDEF(nrunid) |
---|
108 | ENDIF |
---|
109 | ! |
---|
110 | ENDIF |
---|
111 | ! |
---|
112 | ! !== write current time step ==! |
---|
113 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
114 | IF( lwm .AND. ll_wrtstp ) THEN |
---|
115 | WRITE ( numstp, '(1x, i8)' ) kt |
---|
116 | REWIND( numstp ) |
---|
117 | ENDIF |
---|
118 | ! !== test of local extrema ==! |
---|
119 | ! !== done by all processes at every time step ==! |
---|
120 | llmsk(:,:,1) = ssmask(:,:) == 1._wp |
---|
121 | IF( ll_wd ) THEN |
---|
122 | zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) + ssh_ref ), mask = llmsk(:,:,1) ) ! ssh max |
---|
123 | ELSE |
---|
124 | zmax(1) = MAXVAL( ABS( ssh(:,:,Kmm) ), mask = llmsk(:,:,1) ) ! ssh max |
---|
125 | ENDIF |
---|
126 | llmsk(:,:,:) = umask(:,:,:) == 1._wp |
---|
127 | zmax(2) = MAXVAL( ABS( uu(:,:,:,Kmm) ), mask = llmsk ) ! velocity max (zonal only) |
---|
128 | llmsk(:,:,:) = tmask(:,:,:) == 1._wp |
---|
129 | zmax(3) = MAXVAL( -ts(:,:,:,jp_sal,Kmm), mask = llmsk ) ! minus salinity max |
---|
130 | zmax(4) = MAXVAL( ts(:,:,:,jp_sal,Kmm), mask = llmsk ) ! salinity max |
---|
131 | IF( ll_colruns ) THEN ! following variables are used only in the netcdf file |
---|
132 | zmax(5) = MAXVAL( -ts(:,:,:,jp_tem,Kmm), mask = llmsk ) ! minus temperature max |
---|
133 | zmax(6) = MAXVAL( ts(:,:,:,jp_tem,Kmm), mask = llmsk ) ! temperature max |
---|
134 | IF( ln_zad_Aimp ) THEN |
---|
135 | zmax(7) = MAXVAL( Cu_adv(:,:,:) , mask = llmsk ) ! partitioning coeff. max |
---|
136 | llmsk(:,:,:) = wmask(:,:,:) == 1._wp |
---|
137 | zmax(8) = MAXVAL( ABS( wi(:,:,:) ) , mask = llmsk ) ! implicit vertical vel. max |
---|
138 | ELSE |
---|
139 | zmax(7:8) = 0._wp |
---|
140 | ENDIF |
---|
141 | ELSE |
---|
142 | zmax(5:8) = 0._wp |
---|
143 | ENDIF |
---|
144 | zmax(9) = REAL( nstop, wp ) ! stop indicator |
---|
145 | ! !== get global extrema ==! |
---|
146 | ! !== done by all processes if writting run.stat ==! |
---|
147 | IF( ll_colruns ) THEN |
---|
148 | zmaxlocal(:) = zmax(:) |
---|
149 | CALL mpp_max( "stpctl", zmax ) ! max over the global domain |
---|
150 | nstop = NINT( zmax(9) ) ! update nstop indicator (now sheared among all local domains) |
---|
151 | ENDIF |
---|
152 | ! !== write "run.stat" files ==! |
---|
153 | ! !== done only by 1st subdomain at writting timestep ==! |
---|
154 | IF( ll_wrtruns ) THEN |
---|
155 | WRITE(numrun,9500) kt, zmax(1), zmax(2), -zmax(3), zmax(4) |
---|
156 | istatus = NF90_PUT_VAR( nrunid, nvarid(1), (/ zmax(1)/), (/kt/), (/1/) ) |
---|
157 | istatus = NF90_PUT_VAR( nrunid, nvarid(2), (/ zmax(2)/), (/kt/), (/1/) ) |
---|
158 | istatus = NF90_PUT_VAR( nrunid, nvarid(3), (/-zmax(3)/), (/kt/), (/1/) ) |
---|
159 | istatus = NF90_PUT_VAR( nrunid, nvarid(4), (/ zmax(4)/), (/kt/), (/1/) ) |
---|
160 | istatus = NF90_PUT_VAR( nrunid, nvarid(5), (/-zmax(5)/), (/kt/), (/1/) ) |
---|
161 | istatus = NF90_PUT_VAR( nrunid, nvarid(6), (/ zmax(6)/), (/kt/), (/1/) ) |
---|
162 | IF( ln_zad_Aimp ) THEN |
---|
163 | istatus = NF90_PUT_VAR( nrunid, nvarid(7), (/ zmax(7)/), (/kt/), (/1/) ) |
---|
164 | istatus = NF90_PUT_VAR( nrunid, nvarid(8), (/ zmax(8)/), (/kt/), (/1/) ) |
---|
165 | ENDIF |
---|
166 | IF( kt == nitend ) istatus = NF90_CLOSE(nrunid) |
---|
167 | END IF |
---|
168 | ! !== error handling ==! |
---|
169 | ! !== done by all processes at every time step ==! |
---|
170 | ! |
---|
171 | IF( zmax(1) > 20._wp .OR. & ! too large sea surface height ( > 20 m ) |
---|
172 | & zmax(2) > 10._wp .OR. & ! too large velocity ( > 10 m/s) |
---|
173 | & zmax(3) >= 0._wp .OR. & ! negative or zero sea surface salinity |
---|
174 | & zmax(4) >= 100._wp .OR. & ! too large sea surface salinity ( > 100 ) |
---|
175 | & zmax(4) < 0._wp .OR. & ! too large sea surface salinity (keep this line for sea-ice) |
---|
176 | & ISNAN( zmax(1) + zmax(2) + zmax(3) ) ) THEN ! NaN encounter in the tests |
---|
177 | ! |
---|
178 | IF( ll_colruns ) THEN ! zmax is global, so it is the same on all subdomains -> no dead lock with mpp_maxloc |
---|
179 | ! first: close the netcdf file, so we can read it |
---|
180 | IF( lwm .AND. kt /= nitend ) istatus = NF90_CLOSE(nrunid) |
---|
181 | ! get global loc on the min/max |
---|
182 | CALL mpp_maxloc( 'stpctl', ABS(ssh(:,:, Kmm)), ssmask(:,: ), zzz, iloc(1:2,1) ) ! mpp_maxloc ok if mask = F |
---|
183 | CALL mpp_maxloc( 'stpctl', ABS( uu(:,:,:, Kmm)), umask(:,:,:), zzz, iloc(1:3,2) ) |
---|
184 | CALL mpp_minloc( 'stpctl', ts(:,:,:,jp_sal,Kmm) , tmask(:,:,:), zzz, iloc(1:3,3) ) |
---|
185 | CALL mpp_maxloc( 'stpctl', ts(:,:,:,jp_sal,Kmm) , tmask(:,:,:), zzz, iloc(1:3,4) ) |
---|
186 | ! find which subdomain has the max. |
---|
187 | zarea(:) = 0._wp |
---|
188 | DO ji = 1, 9 |
---|
189 | IF( zmaxlocal(ji) == zmax(ji) ) zarea(ji) = narea |
---|
190 | END DO |
---|
191 | CALL mpp_max( "stpctl", zarea ) ! max over the global domain |
---|
192 | ELSE ! find local min and max locations: |
---|
193 | ! if we are here, this means that the subdomain contains some oce points -> no need to test the mask used in maxloc |
---|
194 | iloc(1:2,1) = MAXLOC( ABS( ssh(:,:, Kmm)), mask = ssmask(:,: ) == 1._wp ) + (/ nimpp - 1, njmpp - 1 /) |
---|
195 | iloc(1:3,2) = MAXLOC( ABS( uu(:,:,:, Kmm)), mask = umask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
196 | iloc(1:3,3) = MINLOC( ts(:,:,:,jp_sal,Kmm) , mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
197 | iloc(1:3,4) = MAXLOC( ts(:,:,:,jp_sal,Kmm) , mask = tmask(:,:,:) == 1._wp ) + (/ nimpp - 1, njmpp - 1, 0 /) |
---|
198 | zarea(:) = narea ! this is local information |
---|
199 | ENDIF |
---|
200 | ! |
---|
201 | WRITE(ctmp1,*) ' stp_ctl: |ssh| > 20 m or |U| > 10 m/s or S <= 0 or S >= 100 or NaN encounter in the tests' |
---|
202 | WRITE(ctmp2,9100) kt, ' |ssh| max ', zmax(1), iloc(1,1), iloc(2,1), NINT(zarea(1))-1 |
---|
203 | WRITE(ctmp3,9200) kt, ' |U| max ', zmax(2), iloc(1,2), iloc(2,2), iloc(3,2), NINT(zarea(2))-1 |
---|
204 | WRITE(ctmp4,9200) kt, ' Sal min ', -zmax(3), iloc(1,3), iloc(2,3), iloc(3,3), NINT(zarea(3))-1 |
---|
205 | WRITE(ctmp5,9200) kt, ' Sal max ', zmax(4), iloc(1,4), iloc(2,4), iloc(3,4), NINT(zarea(4))-1 |
---|
206 | IF( Agrif_Root() ) THEN |
---|
207 | WRITE(ctmp6,*) ' ===> output of last computed fields in output.abort* files' |
---|
208 | ELSE |
---|
209 | WRITE(ctmp6,*) ' ===> output of last computed fields in '//TRIM(Agrif_CFixed())//'_output.abort* files' |
---|
210 | ENDIF |
---|
211 | ! |
---|
212 | CALL dia_wri_state( Kmm, 'output.abort' ) ! create an output.abort file |
---|
213 | ! |
---|
214 | IF( ll_colruns ) THEN ! all processes are synchronized -> use lwp to do the print in opened ocean.output files |
---|
215 | IF(lwp) CALL ctl_stop( ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
216 | ELSE ! only mpi subdomains with errors are here -> STOP now |
---|
217 | CALL ctl_stop( 'STOP', ctmp1, ' ', ctmp2, ctmp3, ctmp4, ctmp5, ' ', ctmp6 ) |
---|
218 | ENDIF |
---|
219 | ! |
---|
220 | IF( nstop == 0 ) nstop = 1 |
---|
221 | ngrdstop = Agrif_Fixed() |
---|
222 | ! |
---|
223 | ENDIF |
---|
224 | ! |
---|
225 | 9100 FORMAT(' kt ',i8,a,1pg11.4,' at i j ',2i6, 6x,' MPI rank',i6) |
---|
226 | 9200 FORMAT(' kt ',i8,a,1pg11.4,' at i j k',2i6, i6,' MPI rank',i6) |
---|
227 | 9500 FORMAT(' it :', i8, ' |ssh|_max: ', D23.16, ' |U|_max: ', D23.16,' S_min: ', D23.16,' S_max: ', D23.16) |
---|
228 | ! |
---|
229 | END SUBROUTINE stp_ctl |
---|
230 | |
---|
231 | !!====================================================================== |
---|
232 | END MODULE stpctl |
---|