Skip to content

Commit

Permalink
more timestepping improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 30, 2023
1 parent d105a5d commit c82ef35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
10 changes: 5 additions & 5 deletions examples/Example107_NonlinearStorage1D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ end

using Test
function runtests()
testval = 175.20261258406646
@test main(; unknown_storage = :sparse, assembly = :edgewise) testval
@test main(; unknown_storage = :dense, assembly = :edgewise) testval
@test main(; unknown_storage = :sparse, assembly = :cellwise) testval
@test main(; unknown_storage = :dense, assembly = :cellwise) testval
testval = 174.72418935404414
@test main(; unknown_storage = :sparse, assembly = :edgewise)testval rtol=1.0e-5
@test main(; unknown_storage = :dense, assembly = :edgewise)testval rtol=1.0e-5
@test main(; unknown_storage = :sparse, assembly = :cellwise)testval rtol=1.0e-5
@test main(; unknown_storage = :dense, assembly = :cellwise)testval rtol=1.0e-5
end

end
24 changes: 14 additions & 10 deletions src/vfvm_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function CommonSolve.solve(inival,
Δλ_min = control.Δt_min
Δλ_max = control.Δt_max
Δλ_grow = control.Δt_grow
Δλ_decrease = control.Δt_decrease
else # λ is embedding parameter
Δλ = control.Δp
Δλ_min = control.Δp_min
Expand Down Expand Up @@ -350,6 +351,7 @@ function CommonSolve.solve(inival,
# Try to solve, possibly with stepsize decrease
while !solved
solved = true
forced = false
try # check for non-converging newton
λ = λ0 + Δλ
control.pre(solution, λ)
Expand Down Expand Up @@ -392,29 +394,31 @@ function CommonSolve.solve(inival,
end
end
if !solved
# reduce time step
Δλ = Δλ * Δt_decrease
if Δλ < Δλ_min
if Δλ Δλ_min
if !(control.force_first_step && istep == 0)
err = """
At $(λstr)=$(λ|>rd): Δ$(λstr)_min=$(Δλ_min|>rd) reached while Δu=$(Δu|>rd) and Δu_opt=$(control.Δu_opt|>rd).
Returning prematurely before $(λstr)=$(lambdas[end]|>rd)
At $(λstr)=$(λ|>rd): Δ$(λstr)_min=$(Δλ_min|>rd) reached while Δu/Δu_opt=$(Δu/Δu_opt|>rd).
Returning prematurely before $(λstr)[end]=$(lambdas[end]|>rd)
"""
if control.handle_exceptions
@warn err
else
throw(DomainError(err))
throw(ErrorException(err))
end
break # give up lowering stepsize, break out if "while !solved" loop
else
if doprint(control, 'e')
println("[e]volution: forced first timestep: Δ$(λstr)=$(Δλ), Δu=$(Δu|>rd), Δu_opt=$(control.Δu_opt|>rd)")
println("[e]volution: forced first timestep: Δu/Δu_opt=$(Δu/Δu_opt|>rd)")
end
forced = true
solved = true
end
end
if doprint(control, 'e')
@printf("[e]volution: Δu=%.3e => retry: Δ%s=%.3e\n", Δu, λstr, Δλ)
else
# reduce time step
Δλ = max(Δλ_min, Δλ * Δλ_decrease)
if doprint(control, 'e')
@printf("[e]volution: Δu/Δu_opt=%.3e => retry: Δ%s=%.3e\n", Δu/Δu_opt, λstr, Δλ)
end
end
end
end # while !solved
Expand Down
5 changes: 5 additions & 0 deletions src/vfvm_solvercontrol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ Base.@kwdef mutable struct SolverControl
"""
Δp_grow::Float64 = 1.0

"""
Parameter step decrease factor upon rejection
"""
Δp_decrease::Float64 = 0.5

"""
Initial time step size.
"""
Expand Down

0 comments on commit c82ef35

Please sign in to comment.