@@ -171,6 +171,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
171
171
p3:: floatType
172
172
p4:: floatType
173
173
ϵ:: floatType
174
+ iter_arr:: SVector{5, Float64} # can be modified to take variable length input
174
175
175
176
function TrustRegionCache {iip} (f:: fType , alg:: algType , u:: uType , fu:: resType , p:: pType ,
176
177
uf:: ufType , linsolve:: L , J:: jType ,
@@ -185,7 +186,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
185
186
g:: resType , shrink_counter:: Int , step_size:: su2Type ,
186
187
u_tmp:: tmpType , fu_new:: resType , make_new_J:: Bool ,
187
188
r:: floatType , p1:: floatType , p2:: floatType , p3:: floatType ,
188
- p4:: floatType , ϵ:: floatType ) where {iip, fType, algType, uType,
189
+ p4:: floatType , ϵ:: floatType , iter_arr :: SVector{5, Float64} ) where {iip, fType, algType, uType,
189
190
resType, pType, INType,
190
191
tolType, probType, ufType, L,
191
192
jType, JC, floatType, trustType,
@@ -201,7 +202,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
201
202
expand_factor, loss,
202
203
loss_new, H, g, shrink_counter,
203
204
step_size, u_tmp, fu_new,
204
- make_new_J, r, p1, p2, p3, p4, ϵ)
205
+ make_new_J, r, p1, p2, p3, p4, ϵ, iter_arr )
205
206
end
206
207
end
207
208
@@ -323,14 +324,15 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
323
324
p4 = convert (eltype (u), 1.0e18 ) # M
324
325
initial_trust_radius = convert (eltype (u), p1 * (norm (fu)^ 0.99 ))
325
326
end
327
+ iter_arr = zeros (SVector{5 })
326
328
327
329
return TrustRegionCache {iip} (f, alg, u, fu, p, uf, linsolve, J, jac_config,
328
330
1 , false , maxiters, internalnorm,
329
331
ReturnCode. Default, abstol, prob, radius_update_scheme, initial_trust_radius,
330
332
max_trust_radius, step_threshold, shrink_threshold,
331
333
expand_threshold, shrink_factor, expand_factor, loss,
332
334
loss_new, H, g, shrink_counter, step_size, u_tmp, fu_new,
333
- make_new_J, r, p1, p2, p3, p4, ϵ)
335
+ make_new_J, r, p1, p2, p3, p4, ϵ, iter_arr )
334
336
end
335
337
336
338
function perform_step! (cache:: TrustRegionCache{true} )
@@ -539,6 +541,9 @@ function SciMLBase.solve!(cache::TrustRegionCache)
539
541
while ! cache. force_stop && cache. iter < cache. maxiters &&
540
542
cache. shrink_counter < cache. alg. max_shrink_times
541
543
perform_step! (cache)
544
+ if cache. iter <= 5
545
+ cache. iter_arr[cache. iter] = cache. u[end ]
546
+ end
542
547
cache. iter += 1
543
548
end
544
549
0 commit comments