@@ -74,7 +74,7 @@ subroutine output_sub(nr,xold,x,y,iha,qa,irtrn)
7474
7575 ! > Semi-implicit Runge-Kutta integrator routine
7676 !
77- subroutine stiff3 (n ,fun ,dfun ,x0 ,x1 ,h0 ,eps ,w ,y ,solout )
77+ subroutine stiff3 (n ,fun ,dfun ,x0 ,x1 ,h0 ,eps ,w ,y ,solout , stats )
7878 integer , intent (in ) :: n
7979 ! ! Number of equations to be integrated.
8080 procedure (rhs_sub) :: fun
@@ -95,6 +95,8 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
9595 ! ! dependent variables at `x1`.
9696 procedure (output_sub), optional :: solout
9797 ! ! User supplied subprogram for output.
98+ integer , intent (out ), optional :: stats(3 )
99+ ! ! Statistics array with `[nfev, njev, nlu]`.
98100
99101 real (wp), dimension (n) :: yk1, yk2, ya, yold, yold1, f, fold
100102 ! ! Workspace for solution vector and right-hand side
@@ -104,6 +106,7 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
104106 ! ! Workspace for the pivot array
105107
106108 integer :: icon, iha, i, j, nr, irtrn
109+ integer :: nfev, njev, nlu
107110 real (wp) :: x, xold, h, e, es, q, qa
108111
109112 ! icon = 0 except for last step which ends exactly at x1
@@ -112,6 +115,9 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
112115 nr = 0
113116 x = x0
114117 h = h0
118+ nfev = 0
119+ njev = 0
120+ nlu = 0
115121
116122 outer: do
117123
@@ -131,7 +137,9 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
131137 ! evaluate function and jacobian
132138
133139 call fun(n,y,f)
140+ nfev = nfev + 1
134141 call dfun(n,y,df)
142+ njev = njev + 1
135143
136144 ! keep values which are used in half-step integration
137145
@@ -145,7 +153,7 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
145153
146154 ! perform full integration step
147155
148- call sirk3(n,fun,ip,f,y,yk1,yk2,df,2 * h)
156+ call sirk3(n,fun,ip,f,y,yk1,yk2,df,2 * h,nfev,nlu )
149157
150158 do i = 1 , n
151159 ya(i) = y(i)
@@ -163,13 +171,15 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
163171 inner: do
164172 iha = iha + 1
165173
166- call sirk3(n,fun,ip,f,y,yk1,yk2,df,h)
174+ call sirk3(n,fun,ip,f,y,yk1,yk2,df,h,nfev,nlu )
167175 call fun(n,y,f)
176+ nfev = nfev + 1
168177 call dfun(n,y,df)
178+ njev = njev + 1
169179
170180 yold1 = y
171181
172- call sirk3(n,fun,ip,f,y,yk1,yk2,df,h)
182+ call sirk3(n,fun,ip,f,y,yk1,yk2,df,h,nfev,nlu )
173183
174184 ! half step integration finished
175185 ! compute deviation and compare with tolerance
@@ -223,6 +233,7 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
223233 call solout(nr,xold,x,y,iha,qa,irtrn)
224234 if (irtrn < 0 ) then
225235 h0 = h
236+ if (present (stats)) stats = [nfev, njev, nlu]
226237 return
227238 end if
228239 end if
@@ -231,6 +242,7 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
231242
232243 if (icon == 1 ) then
233244 h0 = h
245+ if (present (stats)) stats = [nfev, njev, nlu]
234246 return
235247 end if
236248
@@ -241,7 +253,7 @@ subroutine stiff3(n,fun,dfun,x0,x1,h0,eps,w,y,solout)
241253
242254 ! > Single-step semi-implicit integration
243255 !
244- subroutine sirk3 (n ,fun ,ipiv ,f ,y ,yk1 ,yk2 ,df ,h )
256+ subroutine sirk3 (n ,fun ,ipiv ,f ,y ,yk1 ,yk2 ,df ,h , nfev , nlu )
245257 integer , intent (in ) :: n
246258 ! ! Size of the system of ODEs
247259 procedure (rhs_sub) :: fun
@@ -260,6 +272,10 @@ subroutine sirk3(n,fun,ipiv,f,y,yk1,yk2,df,h)
260272 ! ! On output contains the factorized matrix (I - h a J) = LU
261273 real (wp), intent (in ) :: h
262274 ! ! Step size of the independent variable
275+ integer , intent (inout ) :: nfev
276+ ! ! Number of right-hand side evaluations
277+ integer , intent (inout ) :: nlu
278+ ! ! Number of LU decompositions
263279
264280 integer :: i
265281
@@ -281,13 +297,15 @@ subroutine sirk3(n,fun,ipiv,f,y,yk1,yk2,df,h)
281297 ! perform triangular decomposition and evaluate k1
282298 !
283299 call lu(df,ipiv)
300+ nlu = nlu + 1
284301 call back(df,f,ipiv)
285302
286303 do i = 1 , n
287304 yk1(i) = h* f(i)
288305 yk2(i) = y(i) + 0.75_wp * yk1(i)
289306 end do
290307 call fun(n,yk2,f)
308+ nfev = nfev + 1
291309 call back(df,f,ipiv)
292310
293311 !
0 commit comments