From 3c622290749351007ff1535122774b59773e6504 Mon Sep 17 00:00:00 2001 From: John Omotani Date: Mon, 9 Dec 2024 13:49:33 +0000 Subject: [PATCH] Comment out line search in Newton iteration The line search seems to just slow down simulations, not make them more robust (which was the hope). It is probably better to just fail faster and decrease the timestep, etc. --- moment_kinetics/src/nonlinear_solvers.jl | 75 ++++++++++++------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/moment_kinetics/src/nonlinear_solvers.jl b/moment_kinetics/src/nonlinear_solvers.jl index 3fc169069..361547970 100644 --- a/moment_kinetics/src/nonlinear_solvers.jl +++ b/moment_kinetics/src/nonlinear_solvers.jl @@ -478,43 +478,44 @@ old_precon_iterations = nl_solver_params.precon_iterations[] if isnan(residual_norm) error("NaN in Newton iteration at iteration $counter") end - if residual_norm > previous_residual_norm - # Do a line search between x and x+delta_x to try to find an update that does - # decrease residual_norm - s = 0.5 - while s > 1.0e-2 - parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) - residual_func!(residual, x) - residual_norm = distributed_norm(solver_type, residual, norm_params...) - if residual_norm ≤ previous_residual_norm - break - end - s *= 0.5 - end - - #if residual_norm > previous_residual_norm - # # Failed to find a point that decreases the residual, so try a negative - # # step - # s = -1.0e-5 - # parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) - # residual_func!(residual, x) - # residual_norm = distributed_norm(solver_type, residual, norm_params...) - # if residual_norm > previous_residual_norm - # # That didn't work either, so just take the full step and hope for - # # convergence later - # parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) - # residual_func!(residual, x) - # residual_norm = distributed_norm(solver_type, residual, norm_params...) - # end - #end - if residual_norm > previous_residual_norm - # Line search didn't work, so just take the full step and hope for - # convergence later - parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) - residual_func!(residual, x) - residual_norm = distributed_norm(solver_type, residual, norm_params...) - end - end +# if residual_norm > previous_residual_norm +# # Do a line search between x and x+delta_x to try to find an update that does +# # decrease residual_norm +# s = 0.5 +# while s > 1.0e-2 +# parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) +# residual_func!(residual, x) +# residual_norm = distributed_norm(solver_type, residual, norm_params...) +# if residual_norm ≤ previous_residual_norm +# break +# end +# s *= 0.5 +# end +# println("line search s ", s) +# +# #if residual_norm > previous_residual_norm +# # # Failed to find a point that decreases the residual, so try a negative +# # # step +# # s = -1.0e-5 +# # parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) +# # residual_func!(residual, x) +# # residual_norm = distributed_norm(solver_type, residual, norm_params...) +# # if residual_norm > previous_residual_norm +# # # That didn't work either, so just take the full step and hope for +# # # convergence later +# # parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) +# # residual_func!(residual, x) +# # residual_norm = distributed_norm(solver_type, residual, norm_params...) +# # end +# #end +# if residual_norm > previous_residual_norm +# # Line search didn't work, so just take the full step and hope for +# # convergence later +# parallel_map(solver_type, (x,delta_x,s) -> x + s * delta_x, w, x, delta_x, s) +# residual_func!(residual, x) +# residual_norm = distributed_norm(solver_type, residual, norm_params...) +# end +# end parallel_map(solver_type, (w) -> w, x, w) previous_residual_norm = residual_norm