Skip to content

Commit 80ff4a7

Browse files
fix: fix homotopy and implement taylor
1 parent a048ca0 commit 80ff4a7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/NonlinearSolveHomotopyContinuation/src/interface_types.jl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,50 @@ end
135135
@concrete struct GuessHomotopy <: HC.AbstractHomotopy
136136
sys <: HC.AbstractSystem
137137
fu0
138+
taylorbuffer::HC.ModelKit.TaylorVector{5, ComplexF64}
139+
end
140+
141+
function GuessHomotopy(sys, fu0)
142+
return GuessHomotopy(sys, fu0, HC.ModelKit.TaylorVector{5}(ComplexF64, length(fu0)))
138143
end
139144

140145
Base.size(h::GuessHomotopy) = size(h.sys)
141146

147+
# H(x, t) = (1 - t) * F(x) + t * (F(x) - F(x0))
148+
# = F(x) - t * F(x0)
142149
function HC.ModelKit.evaluate!(u, h::GuessHomotopy, x, t, p = nothing)
143150
HC.ModelKit.evaluate!(u, h.sys, x, p)
144151
@inbounds for i in eachindex(u)
145-
u[i] += (t + 1) * h.fu0[i]
152+
u[i] -= t * h.fu0[i]
146153
end
154+
return u
147155
end
148156

149157
function HC.ModelKit.evaluate_and_jacobian!(u, U, h::GuessHomotopy, x, t, p = nothing)
150158
HC.ModelKit.evaluate_and_jacobian!(u, U, h.sys, x, p)
151159
@inbounds for i in eachindex(u)
152-
u[i] += (t + 1) * h.fu0[i]
160+
u[i] -= t * h.fu0[i]
161+
end
162+
return u, U
163+
end
164+
165+
HC.ModelKit.taylor!(u, v::Val{N}, H::GuessHomotopy, tx, t, incremental::Bool) where {N} =
166+
HC.ModelKit.taylor!(u, v, H, tx, t)
167+
168+
function HC.ModelKit.taylor!(u, ::Val{1}, h::GuessHomotopy, x::AbstractVector{<:Number}, t, p = nothing)
169+
HC.ModelKit.evaluate!(u, h.sys, x, p)
170+
@inbounds for i in eachindex(u)
171+
u[i] -= h.fu0[i]
172+
end
173+
return u
174+
end
175+
176+
function HC.ModelKit.taylor!(u, ::Val{N}, h::GuessHomotopy, x, t, p = nothing) where {N}
177+
HC.ModelKit.taylor!(h.taylorbuffer, Val(N), h.sys, x, p)
178+
@inbounds for i in eachindex(u)
179+
h.taylorbuffer[i, 1] -= t * h.fu0[i]
180+
h.taylorbuffer[i, 2] -= h.fu0[i]
181+
u[i] = h.taylorbuffer[i, N + 1]
153182
end
183+
return u
154184
end

0 commit comments

Comments
 (0)