Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ mutable struct DAEResidualJacobianWrapper{isAD, F, pType, duType, uType, alphaTy
tmp::tmpType
uprev::uprevType
t::tType
function DAEResidualJacobianWrapper(alg, f::F, p, α, invγdt, tmp, uprev, t) where F
ad = ADTypes.dense_ad(alg_autodiff(alg))
isautodiff = ad isa AutoForwardDiff
function DAEResidualJacobianWrapper(alg, f::F, p, α, invγdt, tmp, uprev, t) where {F}
ad = ADTypes.dense_ad(alg_autodiff(alg))
isautodiff = ad isa AutoForwardDiff
if isautodiff
tmp_du = dualcache(uprev)
tmp_u = dualcache(uprev)
Expand Down Expand Up @@ -161,7 +161,7 @@ end
function odenlf(ztmp, z, p)
tmp, ustep, γ, α, tstep, k, invγdt, method, _p, dt, f = p
_compute_rhs!(
tmp, ztmp, ustep, γ, α, tstep, k, invγdt, method, _p, dt, f, z)[1]
tmp, ztmp, ustep, γ, α, tstep, k, invγdt, method, _p, dt, f, z)[1]
end

function build_nlsolver(
Expand Down Expand Up @@ -212,7 +212,8 @@ function build_nlsolver(
end
J, W = build_J_W(alg, u, uprev, p, t, dt, f, jac_config, uEltypeNoUnits, Val(true))
linprob = LinearProblem(W, _vec(k); u0 = _vec(dz))
Pl, Pr = wrapprecs(
Pl,
Pr = wrapprecs(
alg.precs(W, nothing, u, p, t, nothing, nothing, nothing,
nothing)...,
weight, dz)
Expand All @@ -225,6 +226,7 @@ function build_nlsolver(
invγdt = inv(oneunit(t) * one(uTolType))

if nlalg isa NonlinearSolveAlg
γ = tTypeNoUnits(γ)
α = tTypeNoUnits(α)
dt = tTypeNoUnits(dt)
prob = if f.nlstep_data !== nothing
Expand Down Expand Up @@ -265,7 +267,7 @@ function build_nlsolver(
# build non-linear solver
ηold = one(t)

NLSolver{true, tTypeNoUnits}(z, tmp, ztmp, γ, c, α, nlalg, nlalg.κ,
NLSolver{true, tTypeNoUnits}(z, tmp, ztmp, tTypeNoUnits(γ), c, α, nlalg, nlalg.κ,
nlalg.fast_convergence_cutoff, ηold, 0, nlalg.max_iter,
Divergence, nlcache)
end
Expand Down Expand Up @@ -316,6 +318,7 @@ function build_nlsolver(

J, W = build_J_W(alg, u, uprev, p, t, dt, f, nothing, uEltypeNoUnits, Val(false))
if nlalg isa NonlinearSolveAlg
γ = tTypeNoUnits(γ)
α = tTypeNoUnits(α)
dt = tTypeNoUnits(dt)
nlf = isdae ? oopdaenlf : oopodenlf
Expand Down Expand Up @@ -351,7 +354,7 @@ function build_nlsolver(

# build non-linear solver
ηold = one(tTypeNoUnits)
NLSolver{false, tTypeNoUnits}(z, tmp, ztmp, γ, c, α, nlalg, nlalg.κ,
NLSolver{false, tTypeNoUnits}(z, tmp, ztmp, tTypeNoUnits(γ), c, α, nlalg, nlalg.κ,
nlalg.fast_convergence_cutoff, ηold, 0, nlalg.max_iter,
Divergence,
nlcache)
Expand Down Expand Up @@ -404,7 +407,8 @@ acceleration based on the current iterate `z` and the settings and history in th
while cond(R) > droptol && history > 1
qrdelete!(Q, R, history)
history -= 1
Qcur, Rcur = view(Q, :, 1:history),
Qcur,
Rcur = view(Q, :, 1:history),
UpperTriangular(view(R, 1:history, 1:history))
end
end
Expand Down Expand Up @@ -454,10 +458,10 @@ by performing Anderson acceleration based on the settings and history in the `ca
end

# update history of differences of z₊
@.. broadcast=false Δz₊s[history]=z - z₊old
@.. broadcast=false Δz₊s[history]=z-z₊old

# replace/add difference of residuals as right-most column to QR decomposition
@.. broadcast=false dzold=dz - dzold
@.. broadcast=false dzold=dz-dzold
qradd!(Q, R, _vec(dzold), history)

# update cached values
Expand All @@ -472,7 +476,8 @@ by performing Anderson acceleration based on the settings and history in the `ca
while cond(R) > droptol && history > 1
qrdelete!(Q, R, history)
history -= 1
Qcur, Rcur = view(Q, :, 1:history),
Qcur,
Rcur = view(Q, :, 1:history),
UpperTriangular(view(R, 1:history, 1:history))
end
end
Expand All @@ -486,7 +491,7 @@ by performing Anderson acceleration based on the settings and history in the `ca

# update next iterate
for i in 1:history
@.. broadcast=false z=z - γs[i] * Δz₊s[i]
@.. broadcast=false z=z-γs[i]*Δz₊s[i]
end

nothing
Expand Down Expand Up @@ -580,7 +585,7 @@ function qradd!(Q::AbstractMatrix, R::AbstractMatrix, v::AbstractVector, k::Int)
@inbounds begin
d = norm(v)
R[k, k] = d
@.. broadcast=false @view(Q[:, k])=v / d
@.. broadcast=false @view(Q[:, k])=v/d
end

Q, R
Expand Down
Loading