Skip to content

Commit 333e37f

Browse files
committed
Test nonlinear solvers
1 parent 6ca84b1 commit 333e37f

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
2020
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
2121
SimpleNonlinearSolve = "727e6d20-b764-4bd8-a329-72de5adea6c7"
2222
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
23+
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
2324

2425
# [sources]
2526
# FastMultipole = {url = "https://github.com/byuflowlab/FastMultipole", rev = "d21d242d081ea8c9c19655097d83413b1f783d2d"}

examples/liftingline_weber.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ include(joinpath(pnl.examples_path, "plotformat.jl"))
2525
import CSV
2626
import DataFrames: DataFrame
2727

28+
import SIAMFANLEquations
29+
2830

2931
run_name = "ll-weber" # Name of this run
3032

@@ -112,8 +114,16 @@ sigmafactor = 0.0 # Dragging line amplification fa
112114
sigmaexponent = 4.0 # Dragging line amplification exponent (no effects if `sigmafactor==0.0`)
113115

114116
# Nonlinear solver
115-
solver = pnl.SimpleNonlinearSolve.SimpleDFSane() # Indifferent to initial guess, but somewhat not robust
117+
# solver = pnl.SimpleNonlinearSolve.SimpleDFSane() # Indifferent to initial guess, but somewhat not robust
116118
# solver = pnl.SimpleNonlinearSolve.SimpleTrustRegion() # Trust region needs a good initial guess, but it converges very reliably
119+
solver = pnl.NonlinearSolve.SimpleBroyden() # <---- Wining
120+
# solver = pnl.NonlinearSolve.NLsolveJL(method = :trust_region)
121+
# solver = pnl.NonlinearSolve.SIAMFANLEquationsJL(method = :anderson)
122+
# solver = pnl.NonlinearSolve.FixedPointAccelerationJL(; algorithm = :Newton)
123+
# solver = pnl.NonlinearSolve.FixedPointAccelerationJL(; algorithm = :Newton)
124+
# solver = pnl.NonlinearSolve.NonlinearSolveQuasiNewton.Broyden(; autodiff = ADTypes.AutoForwardDiff(), init_jacobian=Val(:true_jacobian))
125+
# solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNLLSPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff()), # <--- WINING
126+
# solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNonlinearPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff(), prefer_simplenonlinearsolve = Val(true))
117127

118128
solver_optargs = (;
119129
abstol = 1e-9,

src/FLOWPanel.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Dierckx
2424
import LinearAlgebra as LA
2525
import LinearAlgebra: I
2626
import Krylov
27+
import NLsolve
2728
import NonlinearSolve
2829
import SimpleNonlinearSolve
2930
import Requires: @require

src/liftingline/optimization.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,14 @@ function run_liftingline(;
132132
sigmaexponent = 4.0, # Dragging line amplification exponent (no effects if `sigmafactor==0.0`)
133133

134134
# Nonlinear solver
135-
# solver = SimpleNonlinearSolve.SimpleDFSane(), # Indifferent to initial guess, but somewhat not robust <---- NOT COMPATIBLE WITH FORWARDDIFF
136-
# solver = SimpleNonlinearSolve.SimpleTrustRegion(), # Trust region needs a good initial guess, but it converges very reliably
137-
solver = NonlinearSolve.SimpleBroyden(), # This seems to converge well while being compatible with ForwardDiff
135+
# solver = SimpleNonlinearSolve.SimpleDFSane(), # Indifferent to initial guess, but somewhat not robust post stall <---- NOT COMPATIBLE WITH FORWARDDIFF (but compatible with CSDA and optimization converges well)
136+
# solver = SimpleNonlinearSolve.SimpleTrustRegion(), # Trust region needs a good initial guess, but solver converges very reliably post stall, not compatible with CSDA nor ForwardDiff
137+
solver = NonlinearSolve.SimpleBroyden(), # Optimization converges well while being compatible with ForwardDiff (not compatible with CSDA). EXTREMELY ROBUST ACROSS LINEAR, MILD STALL, AND DEEP STALL (it returns an answer, but it might be noise and not accurate)
138+
# solver = NonlinearSolve.NonlinearSolveQuasiNewton.Broyden(; autodiff = ADTypes.AutoForwardDiff(), init_jacobian=Val(:true_jacobian)) # Also extremely robust across regions (it returns an answer, but it might be noise and not accurate)
139+
# solver = NonlinearSolve.NLsolveJL(method = :trust_region),# Optimization converges very well with ForwardDiff, not compatible with CSDA. Solver converges slowly but realibly in linear and mild stall regions, does not converge post stall
140+
# solver = NonlinearSolve.SIAMFANLEquationsJL(method = :newton, autodiff=ADTypes.AutoForwardDiff()), # Also robust in linear and mild stall regions, but much faster
141+
# solver = NonlinearSolve.NonlinearSolve.FastShortcutNLLSPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff()) # Very robust, but it can take a long time. Not ForwardDiff nor CSDA compatible
142+
# solver = NonlinearSolve.NonlinearSolve.FastShortcutNonlinearPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff(), prefer_simplenonlinearsolve = Val(true)) # 100% convergence, and super fast, but it might return the wrong solution. ForwardDiff compatible (though solver might be a bit noise, so set optimizer tol ~5e-5)
138143

139144
solver_optargs = (;
140145
abstol = 1e-13,

test/runtests_liftingline_optimization_snopt.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import FLOWPanel: mean, norm, dot, cross
1010

1111
import ForwardDiff: Dual, Partials, value, partials, jacobian
1212
import Snopt
13+
# import NLsolve
14+
import ADTypes
1315
import SNOW: minimize, Options, SNOPT, ForwardAD, ComplexStep
1416

1517
try
@@ -123,9 +125,13 @@ v_lvl = 0
123125
sigmaexponent = 4.0, # Dragging line amplification exponent (no effects if `sigmafactor==0.0`)
124126

125127
# Nonlinear solver
126-
solver = pnl.SimpleNonlinearSolve.SimpleDFSane(), # Indifferent to initial guess, but somewhat not robust <---- NOT COMPATIBLE WITH FORWARDDIFF
128+
# solver = pnl.SimpleNonlinearSolve.SimpleDFSane(), # Indifferent to initial guess, but somewhat not robust <---- NOT COMPATIBLE WITH FORWARDDIFF
127129
# solver = pnl.SimpleNonlinearSolve.SimpleTrustRegion(), # Trust region needs a good initial guess, but it converges very reliably
128130
# solver = pnl.NonlinearSolve.SimpleBroyden(), # This seems to converge well while being compatible with ForwardDiff
131+
# solver = pnl.NonlinearSolve.NLsolveJL(method = :trust_region), # Converges very well with ForwardDiff, not compatible with CSDA
132+
133+
# solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNLLSPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff()),
134+
solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNonlinearPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff(), prefer_simplenonlinearsolve = Val(true)), # Robust, fast, and ForwardDiff compatible (though solver might be a bit noise, so set optimizer tol ~5e-5)
129135

130136
solver_optargs = (;
131137
abstol = 1e-12, # <-- tight tolerance to converge derivatives
@@ -167,11 +173,13 @@ v_lvl = 0
167173

168174
snopt_options = Dict(
169175
"Major iterations limit" => 50,
176+
"Major optimality tolerance" => 5e-5,
177+
"Minor optimality tolerance" => 5e-5,
170178
)
171179
solver = SNOPT(options=snopt_options)
172180

173-
# options = Options(; solver, derivatives=ForwardAD())
174-
options = Options(; solver, derivatives=ComplexStep())
181+
options = Options(; solver, derivatives=ForwardAD())
182+
# options = Options(; solver, derivatives=ComplexStep())
175183

176184
model_cache = Dict()
177185

@@ -254,7 +262,7 @@ v_lvl = 0
254262
@testset "Derivative verification" begin
255263
for (lbl, (f, dfdx), (atol1, atol2)) in (
256264
("Finite Difference", (f_diff, dfdx_diff), (1e-10, 1e-6)),
257-
("CSDA", (f_csda, dfdx_csda), (1e-10, 5e-4)),
265+
# ("CSDA", (f_csda, dfdx_csda), (1e-10, 5e-4)),
258266
("Dual", (f_dual, dfdx_dual), (1e-10, 1e-6)),
259267
)
260268

0 commit comments

Comments
 (0)