Skip to content

Commit

Permalink
Merge pull request #260 from ajwheeler/converge_more
Browse files Browse the repository at this point in the history
Retry chemical equilibrium solver with very small initial $n_e$ if it fails to converge
  • Loading branch information
ajwheeler authored Feb 7, 2024
2 parents 5e5d8e8 + 3dae8fc commit 1dc2a75
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/statmech.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ function _solve_chemical_equilibrium(temp, nₜ, absolute_abundances, neutral_fr
sol = try
nlsolve(residuals!, x0; method=:newton, iterations=1_000, store_trace=true, ftol=1e-8, autodiff=:forward)
catch e
throw(ChemicalEquilibriumError("solver failed: $e"))
try
# try again with the nₑ guess set to be very small. Much smaller than this and we start
# to get noninvertible matrices in the solver
x0[end] = 1e-5
nlsolve(residuals!, x0; method=:newton, iterations=1_000, store_trace=true, ftol=1e-8, autodiff=:forward)
catch e
throw(ChemicalEquilibriumError("solver failed: $e"))
end
end

if !sol.f_converged
Expand Down

0 comments on commit 1dc2a75

Please sign in to comment.