Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative error control on Rosenbrock23 algebraic equations #2079

Merged
merged 9 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion src/perform_step/rosenbrock_perform_step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ end
veck₃ = _vec(k₃)
vectmp = _vec(tmp)
@.. broadcast=false vectmp=ifelse(cache.algebraic_vars,
dto6 * (veck₁ - 2 * veck₂ + veck₃))
false, dto6 * (veck₁ - 2 * veck₂ + veck₃))
end
calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol,
integrator.opts.reltol, integrator.opts.internalnorm, t)
integrator.EEst = integrator.opts.internalnorm(atmp, t)

if mass_matrix !== I
@.. broadcast=false atmp = ifelse(cache.algebraic_vars,fsallast,false)/integrator.opts.abstol
integrator.EEst += integrator.opts.internalnorm(atmp, t)
end
end
cache.linsolve = linres.cache
end
Expand Down Expand Up @@ -245,6 +250,19 @@ end
calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol,
integrator.opts.reltol, integrator.opts.internalnorm, t)
integrator.EEst = integrator.opts.internalnorm(atmp, t)

if mass_matrix !== I
if integrator.opts.abstol isa AbstractVector
@inbounds @simd ivdep for i in 1:length(vectmp)
vectmp[i] = ifelse(cache.algebraic_vars[i],fsallast[i],false)/integrator.opts.abstol[i]
end
else
@inbounds @simd ivdep for i in 1:length(vectmp)
vectmp[i] = ifelse(cache.algebraic_vars[i],fsallast[i],false)/integrator.opts.abstol
end
end
integrator.EEst += integrator.opts.internalnorm(vectmp, t)
end
end
cache.linsolve = linres.cache
end
Expand Down Expand Up @@ -337,6 +355,11 @@ end
calculate_residuals!(atmp, tmp, uprev, u, integrator.opts.abstol,
integrator.opts.reltol, integrator.opts.internalnorm, t)
integrator.EEst = integrator.opts.internalnorm(atmp, t)

if mass_matrix !== I
@.. broadcast=false atmp = ifelse(cache.algebraic_vars,fsallast,false)/integrator.opts.abstol
integrator.EEst += integrator.opts.internalnorm(atmp, t)
end
end
cache.linsolve = linres.cache
end
Expand Down Expand Up @@ -399,6 +422,11 @@ end
atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol,
integrator.opts.reltol, integrator.opts.internalnorm, t)
integrator.EEst = integrator.opts.internalnorm(atmp, t)

if mass_matrix !== I
atmp = @. ifelse(!integrator.differential_vars,integrator.fsallast,false)./integrator.opts.abstol
integrator.EEst += integrator.opts.internalnorm(atmp, t)
end
end
integrator.k[1] = k₁
integrator.k[2] = k₂
Expand Down Expand Up @@ -466,6 +494,11 @@ end
atmp = calculate_residuals(utilde, uprev, u, integrator.opts.abstol,
integrator.opts.reltol, integrator.opts.internalnorm, t)
integrator.EEst = integrator.opts.internalnorm(atmp, t)

if mass_matrix !== I
atmp = @. ifelse(!integrator.differential_vars,integrator.fsallast,false)./integrator.opts.abstol
integrator.EEst += integrator.opts.internalnorm(atmp, t)
end
end

integrator.k[1] = k₁
Expand Down
6 changes: 3 additions & 3 deletions test/regression/hard_dae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ cb = DiscreteCallback(condition, affect!)

prob = ODEProblem(f, deepcopy(res.zero), (0, 20.0), deepcopy(p_inv))
refsol = solve(prob, Rodas4(), saveat = 0.1, callback = cb, tstops = [1.0], reltol = 1e-12,
abstol = 1e-18)
abstol = 1e-17)

for solver in (Rodas4, Rodas4P, Rodas5, Rodas5P, FBDF, QNDF, Rosenbrock23)
@show solver
prob = ODEProblem(f, deepcopy(res.zero), (0, 20.0), deepcopy(p_inv))
sol = solve(prob, solver(), saveat = 0.1, callback = cb, tstops = [1.0], reltol = 1e-12,
abstol = 1e-16)
sol = solve(prob, solver(), saveat = 0.1, callback = cb, tstops = [1.0], reltol = 1e-14,
abstol = 1e-14)
@test sol.retcode == ReturnCode.Success
@test sol.t[end] == 20.0
@test maximum(sol - refsol) < 1e-11
Expand Down