Skip to content

Commit 003cb29

Browse files
committed
Add nonlin test
1 parent 06fc11c commit 003cb29

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

examples/ram_air_kite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
vsm_solver = Solver(body_aero;
2626
aerodynamic_model_type=VSM,
2727
is_with_artificial_damping=false,
28-
allowed_error=1e-8,
28+
rtol=1e-8,
2929
solver_type=NONLIN
3030
)
3131

src/VortexStepMethod.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ using PreallocationTools
1919
using PrecompileTools
2020
using Pkg
2121
using DifferentiationInterface
22-
import SciMLBase: succesful_retcode
22+
import SciMLBase: successful_retcode
2323

2424
# Export public interface
2525
export Wing, Section, RamAirWing

src/solver.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Main solver structure for the Vortex Step Method.See also: [solve](@ref)
7373
- `aerodynamic_model_type`::Model = VSM: The model type, see: [Model](@ref)
7474
- density::Float64 = 1.225: Air density [kg/m³]
7575
- `max_iterations`::Int64 = 1500
76-
- `allowed_error`::Float64 = 1e-5: relative error
76+
- `rtol`::Float64 = 1e-5: relative error
7777
- `tol_reference_error`::Float64 = 0.001
7878
- `relaxation_factor`::Float64 = 0.03: Relaxation factor for convergence
7979
@@ -96,7 +96,8 @@ sol::VSMSolution = VSMSolution(): The result of calling [solve!](@ref)
9696
aerodynamic_model_type::Model = VSM
9797
density::Float64 = 1.225
9898
max_iterations::Int64 = 1500
99-
allowed_error::Float64 = 1e-5
99+
atol::Float64 = 1e-5
100+
rtol::Float64 = 1e-5
100101
tol_reference_error::Float64 = 0.001
101102
relaxation_factor::Float64 = 0.03
102103

@@ -492,10 +493,10 @@ function gamma_loop!(
492493
nothing
493494
end
494495
prob = NonlinearProblem(f_nonlin!, solver.lr.gamma_new, nothing)
495-
sol = NonlinearSolve.solve(prob, NewtonRaphson(autodiff=AutoFiniteDiff()))
496+
sol = NonlinearSolve.solve(prob, NewtonRaphson(autodiff=AutoFiniteDiff()); abstol=solver.atol, reltol=solver.rtol)
496497
gamma .= sol.u
497498
solver.lr.gamma_new .= sol.u
498-
solver.lr.converged = succesful_retcode(sol)
499+
solver.lr.converged = SciMLBase.successful_retcode(sol)
499500
end
500501

501502
if solver.solver_type == LOOP
@@ -532,7 +533,7 @@ function gamma_loop!(
532533

533534
@debug "Iteration: $i, normalized_error: $normalized_error, is_damping_applied: $is_damping_applied"
534535

535-
if normalized_error < solver.allowed_error
536+
if normalized_error < solver.rtol
536537
solver.lr.converged = true
537538
break
538539
end

test/test_body_aerodynamics.jl

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,34 +146,49 @@ end
146146

147147
# Run analysis
148148
P = length(body_aero.panels)
149-
solver_object = Solver{P}(
149+
loop_solver = Solver{P}(
150150
aerodynamic_model_type=model,
151-
core_radius_fraction=core_radius_fraction
151+
core_radius_fraction=core_radius_fraction,
152+
solver_type=LOOP,
153+
atol=1e-8,
154+
rtol=1e-8
152155
)
153-
results_NEW = solve(solver_object, body_aero; reference_point=[0,1,0])
156+
nonlin_solver = Solver{P}(
157+
aerodynamic_model_type=model,
158+
core_radius_fraction=core_radius_fraction,
159+
solver_type=NONLIN,
160+
atol=1e-8,
161+
rtol=1e-8
162+
)
163+
results_NEW = solve(loop_solver, body_aero; reference_point=[0,1,0])
154164
# println(results_NEW)
155165

156166
@test results_NEW isa Dict
157167

158-
sol = solve!(solver_object, body_aero; reference_point=[0,1,0])
168+
@testset "Loop and nonlin solve!" begin
169+
loop_sol = solve!(loop_solver, body_aero; reference_point=[0,1,0])
170+
nonlin_sol = solve!(nonlin_solver, body_aero; reference_point=[0,1,0])
159171

160-
@test sol.force.x -117.97225244011436 atol=1e-4
161-
@test sol.force.y 0.0 atol=1e-10
162-
@test sol.force.z 1481.996390329679 atol=1e-4 rtol= 1e-4
172+
@test all(isapprox.(nonlin_sol.gamma_distribution, loop_sol.gamma_distribution; atol=1e-4))
163173

164-
@test sol.moment.x -1481.996390329678 atol=1e-4 rtol= 1e-4
165-
@test sol.moment.y 0.0 atol=1e-10
166-
@test sol.moment.z -117.97225244011435 atol=1e-4
174+
@test loop_sol.force.x -117.96518414816444 atol=1e-4
175+
@test loop_sol.force.y 0.0 atol=1e-10
176+
@test loop_sol.force.z 1481.996390329679 atol=1e-4 rtol= 1e-4
167177

168-
@test sol.force_coefficients[1] -0.039050322560956294 atol=1e-4 # CFx
169-
@test sol.force_coefficients[2] 0.0 atol=1e-4 # CFy
170-
@test sol.force_coefficients[3] 0.49055973654418716 atol=1e-4 # CFz
171-
@test sol.force_coefficients[3] / sol.force_coefficients[1] sol.force[3] / sol.force[1]
172-
@test sol.moment_distribution[1] -0.0006683746751654071 atol=1e-8
173-
@test sol.moment_coeff_dist[1] -2.212405554436003e-7 atol=1e-10
174-
@test sol.moment_distribution[1] / sol.moment_distribution[2] sol.moment_coeff_dist[1] / sol.moment_coeff_dist[2]
178+
@test loop_sol.moment.x -1481.996390329678 atol=1e-4 rtol= 1e-4
179+
@test loop_sol.moment.y 0.0 atol=1e-10
180+
@test loop_sol.moment.z -117.9651841481644 atol=1e-4
175181

176-
@test sol.solver_status == FEASIBLE
182+
@test loop_sol.force_coefficients[1] -0.039050322560956294 atol=1e-4 # CFx
183+
@test loop_sol.force_coefficients[2] 0.0 atol=1e-4 # CFy
184+
@test loop_sol.force_coefficients[3] 0.49055973654418716 atol=1e-4 # CFz
185+
@test loop_sol.force_coefficients[3] / loop_sol.force_coefficients[1] loop_sol.force[3] / loop_sol.force[1]
186+
@test loop_sol.moment_distribution[1] -0.0006683569356186426 atol=1e-8
187+
@test loop_sol.moment_coeff_dist[1] -2.212405554436003e-7 atol=1e-10
188+
@test loop_sol.moment_distribution[1] / loop_sol.moment_distribution[2] loop_sol.moment_coeff_dist[1] / loop_sol.moment_coeff_dist[2]
189+
190+
@test loop_sol.solver_status == FEASIBLE
191+
end
177192

178193
# Calculate forces using uncorrected alpha
179194
alpha = results_NEW["alpha_uncorrected"]

0 commit comments

Comments
 (0)