Skip to content

Commit

Permalink
Update finiteschemesolve.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugomez committed Aug 2, 2024
1 parent 654c0a2 commit 4310c2a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/finiteschemesolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

# Implicit time step
function implicit_timestep(G!, ypost, Δ; is_algebraic = fill(false, size(ypost)...), iterations = 100, verbose = true, method = :newton, autodiff = :forward, maxdist = sqrt(eps()), J0c = (nothing, nothing), y̲ = fill(-Inf, length(ypost)), ȳ = fill(Inf, length(ypost)), reformulation = :smooth, autoscale = true, kwargs...)
#G_helper!(ydot, y) = (G!(ydot, y) ; ydot .-= .!is_algebraic .* (ypost .- y) ./ Δ)
#
#if any(is_algebraic)
G_helper!(ydot, y) = (G!(ydot, y) ; ydot .*= 1 .+ .!is_algebraic .*- 1) ; ydot .-= .!is_algebraic .* (ypost .- y))
#end
# One option is
# G_helper!(ydot, y) = (G!(ydot, y) ; ydot .*= 1 .+ .!is_algebraic .* (Δ - 1) ; ydot .-= .!is_algebraic .* (ypost .- y))
# however does not work if Δ is Inf
G_helper!(ydot, y) = (G!(ydot, y) ; ydot .-= .!is_algebraic .* (ypost .- y) ./ Δ)
J0, colorvec = J0c
if J0 == nothing
if method == :linearization
Expand Down Expand Up @@ -46,6 +48,7 @@ end
function finiteschemesolve(G!, y0; Δ = 1.0, is_algebraic = fill(false, size(y0)...), iterations = 100, inner_iterations = 10, verbose = true, inner_verbose = false, method = :newton, autodiff = :forward, maxdist = sqrt(eps()), innerdist = sqrt(eps()), scale = 10.0, J0c = (nothing, nothing), minΔ = 1e-9, y̲ = fill(-Inf, length(y0)), ȳ = fill(Inf, length(y0)), reformulation = :smooth, maxΔ = Inf, autoscale = true, kwargs...)
ypost = y0
ydot = zero(y0)
# check that does not return NAN or zero
G!(ydot, ypost)
residual_norm = norm(ydot) / length(ydot)
isnan(residual_norm) && throw("G! returns NaN with the initial value")
Expand Down

0 comments on commit 4310c2a

Please sign in to comment.