Skip to content

Commit 6b6135d

Browse files
committed
iteration array
1 parent c1267c8 commit 6b6135d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/trustRegion.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
171171
p3::floatType
172172
p4::floatType
173173
ϵ::floatType
174+
iter_arr::SVector{5, Float64} #can be modified to take variable length input
174175

175176
function TrustRegionCache{iip}(f::fType, alg::algType, u::uType, fu::resType, p::pType,
176177
uf::ufType, linsolve::L, J::jType,
@@ -185,7 +186,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
185186
g::resType, shrink_counter::Int, step_size::su2Type,
186187
u_tmp::tmpType, fu_new::resType, make_new_J::Bool,
187188
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,
189190
resType, pType, INType,
190191
tolType, probType, ufType, L,
191192
jType, JC, floatType, trustType,
@@ -201,7 +202,7 @@ mutable struct TrustRegionCache{iip, fType, algType, uType, resType, pType,
201202
expand_factor, loss,
202203
loss_new, H, g, shrink_counter,
203204
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)
205206
end
206207
end
207208

@@ -323,14 +324,15 @@ function SciMLBase.__init(prob::NonlinearProblem{uType, iip}, alg::TrustRegion,
323324
p4 = convert(eltype(u), 1.0e18) # M
324325
initial_trust_radius = convert(eltype(u), p1 * (norm(fu)^0.99))
325326
end
327+
iter_arr = zeros(SVector{5})
326328

327329
return TrustRegionCache{iip}(f, alg, u, fu, p, uf, linsolve, J, jac_config,
328330
1, false, maxiters, internalnorm,
329331
ReturnCode.Default, abstol, prob, radius_update_scheme, initial_trust_radius,
330332
max_trust_radius, step_threshold, shrink_threshold,
331333
expand_threshold, shrink_factor, expand_factor, loss,
332334
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)
334336
end
335337

336338
function perform_step!(cache::TrustRegionCache{true})
@@ -539,6 +541,9 @@ function SciMLBase.solve!(cache::TrustRegionCache)
539541
while !cache.force_stop && cache.iter < cache.maxiters &&
540542
cache.shrink_counter < cache.alg.max_shrink_times
541543
perform_step!(cache)
544+
if cache.iter <= 5
545+
cache.iter_arr[cache.iter] = cache.u[end]
546+
end
542547
cache.iter += 1
543548
end
544549

0 commit comments

Comments
 (0)