Skip to content

Commit 06fc11c

Browse files
committed
Add nonlinear solver
1 parent c9d0686 commit 06fc11c

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1919
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2020
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
2121
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
22+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2223
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
2324
SharedArrays = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
2425
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
@@ -55,6 +56,7 @@ Parameters = "0.12"
5556
Pkg = "1"
5657
PreallocationTools = "0.4.25"
5758
PrecompileTools = "1.2.1"
59+
SciMLBase = "2.79.0"
5860
Serialization = "1"
5961
SharedArrays = "1"
6062
StaticArrays = "1"

examples/ram_air_kite.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ end
2525
vsm_solver = Solver(body_aero;
2626
aerodynamic_model_type=VSM,
2727
is_with_artificial_damping=false,
28-
allowed_error=1e-8
28+
allowed_error=1e-8,
29+
solver_type=NONLIN
2930
)
3031

3132
# Setting velocity conditions

src/VortexStepMethod.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using PreallocationTools
1919
using PrecompileTools
2020
using Pkg
2121
using DifferentiationInterface
22+
import SciMLBase: succesful_retcode
2223

2324
# Export public interface
2425
export Wing, Section, RamAirWing
@@ -33,6 +34,7 @@ export AeroModel, LEI_AIRFOIL_BREUKELS, POLAR_VECTORS, POLAR_MATRICES, INVISCID
3334
export PanelDistribution, LINEAR, COSINE, COSINE_VAN_GARREL, SPLIT_PROVIDED, UNCHANGED
3435
export InitialGammaDistribution, ELLIPTIC, ZEROS
3536
export SolverStatus, FEASIBLE, INFEASIBLE, FAILURE
37+
export SolverType, LOOP, NONLIN
3638

3739
export plot_geometry, plot_distribution, plot_circulation_distribution, plot_geometry, plot_polars, save_plot, show_plot, plot_polar_data
3840

src/solver.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function solve_base!(solver::Solver, body_aero::BodyAerodynamics, gamma_distribu
402402
# Run main iteration loop
403403
gamma_loop!(solver, body_aero, panels, relaxation_factor; log)
404404
# Try again with reduced relaxation factor if not converged
405-
if ! solver.lr.converged && relaxation_factor > 1e-3
405+
if solver.solver_type == LOOP && !solver.lr.converged && relaxation_factor > 1e-3
406406
log && @warn "Running again with half the relaxation_factor = $(relaxation_factor/2)"
407407
solver.lr.gamma_new .= gamma_initial
408408
gamma_loop!(solver, body_aero, panels, relaxation_factor/2; log)
@@ -453,9 +453,7 @@ function gamma_loop!(
453453
velocity_view_y = @view induced_velocity_all[:, 2]
454454
velocity_view_z = @view induced_velocity_all[:, 3]
455455

456-
function calc_gamma_new!(gamma_new, gamma)
457-
gamma .= gamma_new
458-
456+
function calc_gamma_new!(gamma_new, gamma)
459457
# Calculate induced velocities
460458
mul!(velocity_view_x, AIC_x, gamma)
461459
mul!(velocity_view_y, AIC_y, gamma)
@@ -493,15 +491,16 @@ function gamma_loop!(
493491
d_gamma .= solver.lr.gamma_new .- gamma
494492
nothing
495493
end
496-
d_gamma = abs_gamma_new
497-
prob = NonlinearProblem(f_nonlin!, d_gamma, solver.lr.gamma_new, p)
498-
sol = solve(prob, NewtonRaphson())
494+
prob = NonlinearProblem(f_nonlin!, solver.lr.gamma_new, nothing)
495+
sol = NonlinearSolve.solve(prob, NewtonRaphson(autodiff=AutoFiniteDiff()))
499496
gamma .= sol.u
500497
solver.lr.gamma_new .= sol.u
498+
solver.lr.converged = succesful_retcode(sol)
501499
end
502500

503501
if solver.solver_type == LOOP
504502
function f_loop!(gamma_new, gamma, damp)
503+
gamma .= gamma_new
505504
calc_gamma_new!(gamma_new, gamma)
506505
# Update gamma with relaxation and damping
507506
@. gamma_new = (1 - relaxation_factor) * gamma +

test/bench.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ using LinearAlgebra
140140
0.5;
141141
log = false
142142
) samples=1 evals=1
143-
@test result.allocs 20
143+
@test result.allocs 10
144144
@info "Model: $model \t Aero_model: $aero_model \t Allocations: $(result.allocs) Memory: $(result.memory)"
145145
end
146146
end

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ println("Running tests...")
2121
@testset verbose = true "Testing VortexStepMethod..." begin
2222
if build_is_production_build
2323
include("bench.jl")
24-
include("bench2.jl")
2524
end
2625
include("test_bound_filament.jl")
2726
include("test_panel.jl")

0 commit comments

Comments
 (0)