Skip to content

Commit 186bbbe

Browse files
committed
Define analysis_solver and optimization_solver
1 parent 333e37f commit 186bbbe

File tree

9 files changed

+39
-21
lines changed

9 files changed

+39
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +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"
23+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
2424

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

examples/liftingline_a50k27.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ sigmafactor = 0.0 # Dragging line amplification fa
109109
sigmaexponent = 1.0 # Dragging line amplification exponent (no effects if `sigmafactor==0.0`)
110110

111111
# Nonlinear solver
112-
solver = pnl.SimpleNonlinearSolve.SimpleDFSane() # Indifferent to initial guess, but somewhat not robust
113-
# solver = pnl.SimpleNonlinearSolve.SimpleTrustRegion() # Trust region needs a good initial guess, but it converges very reliably
112+
solver = pnl.analysis_solver # Very robust and physically accurate, but it can take a long time post-stall (not AD compatible)
113+
# solver = pnl.optimization_solver # Robus, fast, and ForwardDiff compatible, but often times it returns the secondary solution that is unphysical post stall
114114

115115
solver_optargs = (;
116116
abstol = 1e-9,

examples/liftingline_weber.jl

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

28-
import SIAMFANLEquations
29-
3028

3129
run_name = "ll-weber" # Name of this run
3230

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

116114
# Nonlinear solver
117-
# solver = pnl.SimpleNonlinearSolve.SimpleDFSane() # Indifferent to initial guess, but somewhat not robust
118-
# 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))
115+
solver = pnl.analysis_solver # Very robust and physically accurate, but it can take a long time post-stall (not AD compatible)
116+
# solver = pnl.optimization_solver # Robus, fast, and ForwardDiff compatible, but often times it returns the secondary solution that is unphysical post stall
127117

128118
solver_optargs = (;
129119
abstol = 1e-9,

src/FLOWPanel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import Dierckx
2424
import LinearAlgebra as LA
2525
import LinearAlgebra: I
2626
import Krylov
27-
import NLsolve
2827
import NonlinearSolve
2928
import SimpleNonlinearSolve
29+
import ADTypes
3030
import Requires: @require
3131

3232
# ------------ FLOW LAB MODULES ------------------------------------------------

src/liftingline/nonlinearsolver.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@
2222
* License : MIT License
2323
=###############################################################################
2424

25+
"""
26+
Robust, fast, and ForwardDiff compatible (though solver might be a bit noise, so
27+
set optimizer tol ~5e-5). Often it returns the secondary solution that is
28+
unphysical post stall. Not CSDA compatible.
29+
"""
30+
const optimization_solver = NonlinearSolve.FastShortcutNonlinearPolyalg(;
31+
autodiff = :forward,
32+
vjp_autodiff = :forward, jvp_autodiff = :forward,
33+
prefer_simplenonlinearsolve = Val(true)
34+
)
35+
36+
"""
37+
Very robust and physically accurate, but it can take a long time.
38+
Not ForwardDiff nor CSDA compatible.
39+
"""
40+
const analysis_solver = NonlinearSolve.FastShortcutNLLSPolyalg(;
41+
autodiff = ADTypes.AutoForwardDiff(),
42+
# vjp_autodiff = ADTypes.AutoForwardDiff(),
43+
# jvp_autodiff = ADTypes.AutoForwardDiff(),
44+
)
45+
46+
47+
48+
49+
2550
function solve(self::LiftingLine, Uinf::AbstractVector,
2651
args...; optargs...)
2752
solve(self, repeat(Uinf, 1, self.nelements), args...; optargs...)

src/liftingline/optimization.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,13 @@ function run_liftingline(;
134134
# Nonlinear solver
135135
# 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)
136136
# 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)
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)
138138
# 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)
139139
# 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
140140
# solver = NonlinearSolve.SIAMFANLEquationsJL(method = :newton, autodiff=ADTypes.AutoForwardDiff()), # Also robust in linear and mild stall regions, but much faster
141141
# 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
142142
# 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)
143+
solver = optimization_solver,
143144

144145
solver_optargs = (;
145146
abstol = 1e-13,

test/runtests_liftingline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ v_lvl = 0
104104
# deltajoint = 0.15 # Joint distance, deltajoint = dx/c
105105
deltajoint = 1.0
106106
# Nonlinear solver
107-
solver = pnl.SimpleNonlinearSolve.SimpleDFSane()
107+
solver = pnl.analysis_solver
108108
solver_optargs = (; abstol = 1e-9)
109109

110110
Dhat = Uinf/norm(Uinf) # Drag direction

test/runtests_liftingline_optimization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ v_lvl = 0
266266
sigmaexponent = 4.0, # Dragging line amplification exponent (no effects if `sigmafactor==0.0`)
267267

268268
# Nonlinear solver
269-
solver = pnl.SimpleNonlinearSolve.SimpleDFSane(), # Indifferent to initial guess, but somewhat not robust
269+
solver = pnl.optimization_solver,
270270

271271
solver_optargs = (;
272272
abstol = 1e-9,

test/runtests_liftingline_optimization_snopt.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ v_lvl = 0
130130
# solver = pnl.NonlinearSolve.SimpleBroyden(), # This seems to converge well while being compatible with ForwardDiff
131131
# solver = pnl.NonlinearSolve.NLsolveJL(method = :trust_region), # Converges very well with ForwardDiff, not compatible with CSDA
132132

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)
133+
# solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNLLSPolyalg(; autodiff = ADTypes.AutoForwardDiff(), vjp_autodiff = ADTypes.AutoForwardDiff(), jvp_autodiff = ADTypes.AutoForwardDiff()),
134+
# solver = pnl.NonlinearSolve.NonlinearSolve.FastShortcutNonlinearPolyalg(; autodiff = :forward, vjp_autodiff = :forward, jvp_autodiff = :forward, prefer_simplenonlinearsolve = Val(true)), # Robust, fast, and ForwardDiff compatible (though solver might be a bit noise, so set optimizer tol ~5e-5)
135+
136+
solver = pnl.optimization_solver,
135137

136138
solver_optargs = (;
137139
abstol = 1e-12, # <-- tight tolerance to converge derivatives

0 commit comments

Comments
 (0)