Skip to content

Commit 0630f78

Browse files
committed
Remove a lot of unnecessary function signature types
1 parent 003cb29 commit 0630f78

File tree

2 files changed

+79
-73
lines changed

2 files changed

+79
-73
lines changed

src/body_aerodynamics.jl

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Main structure for calculating aerodynamic properties of bodies.
88
- wings::Union{Vector{Wing}, Vector{RamAirWing}}: A vector of wings; a body can have multiple wings
99
- `_va`::MVec3 = zeros(MVec3): A vector of the apparent wind speed, see: [MVec3](@ref)
1010
- `omega`::MVec3 = zeros(MVec3): A vector of the turn rates around the kite body axes
11-
- `gamma_distribution`::Vector{Float64}=zeros(Float64, P): A vector of the circulation
11+
- `gamma_distribution`=zeros(Float64, P): A vector of the circulation
1212
of the velocity field; Length: Number of segments. [m²/s]
13-
- `alpha_uncorrected`::Vector{Float64}=zeros(Float64, P): angles of attack per panel
14-
- `alpha_corrected`::Vector{Float64}=zeros(Float64, P): corrected angles of attack per panel
15-
- `stall_angle_list`::Vector{Float64}=zeros(Float64, P): stall angle per panel
16-
- `alpha_array`::Vector{Float64} = zeros(Float64, P)
17-
- `v_a_array`::Vector{Float64} = zeros(Float64, P)
13+
- `alpha_uncorrected`=zeros(Float64, P): angles of attack per panel
14+
- `alpha_corrected`=zeros(Float64, P): corrected angles of attack per panel
15+
- `stall_angle_list`=zeros(Float64, P): stall angle per panel
16+
- `alpha_array` = zeros(Float64, P)
17+
- `v_a_array` = zeros(Float64, P)
1818
- `work_vectors`::NTuple{10, MVec3} = ntuple(_ -> zeros(MVec3), 10)
1919
- AIC::Array{Float64, 3} = zeros(3, P, P)
2020
- `projected_area`::Float64 = 1.0: The area projected onto the xy-plane of the kite body reference frame [m²]
@@ -155,9 +155,9 @@ end
155155

156156
"""
157157
calculate_AIC_matrices!(body_aero::BodyAerodynamics, model::Model,
158-
core_radius_fraction::Float64,
159-
va_norm_array::Vector{Float64},
160-
va_unit_array::Matrix{Float64})
158+
core_radius_fraction,
159+
va_norm_array,
160+
va_unit_array)
161161
162162
Calculate Aerodynamic Influence Coefficient matrices.
163163
@@ -166,9 +166,9 @@ See also: [BodyAerodynamics](@ref), [Model](@ref)
166166
Returns: nothing
167167
"""
168168
@inline function calculate_AIC_matrices!(body_aero::BodyAerodynamics, model::Model,
169-
core_radius_fraction::Float64,
170-
va_norm_array::Vector{Float64},
171-
va_unit_array::Matrix{Float64})
169+
core_radius_fraction,
170+
va_norm_array,
171+
va_unit_array)
172172
# Determine evaluation point based on model
173173
evaluation_point = model == VSM ? :control_point : :aero_center
174174
evaluation_point_on_bound = model == LLT
@@ -208,13 +208,13 @@ Returns: nothing
208208
end
209209

210210
"""
211-
calculate_circulation_distribution_elliptical_wing(body_aero::BodyAerodynamics, gamma_0::Float64=1.0)
211+
calculate_circulation_distribution_elliptical_wing(body_aero::BodyAerodynamics, gamma_0=1.0)
212212
213213
Calculate circulation distribution for an elliptical wing.
214214
215215
Returns: nothing
216216
"""
217-
function calculate_circulation_distribution_elliptical_wing(gamma_i, body_aero::BodyAerodynamics, gamma_0::Float64=1.0)
217+
function calculate_circulation_distribution_elliptical_wing(gamma_i, body_aero::BodyAerodynamics, gamma_0=1.0)
218218
length(body_aero.wings) == 1 || throw(ArgumentError("Multiple wings not yet implemented"))
219219

220220
wing_span = body_aero.wings[1].span
@@ -235,23 +235,23 @@ end
235235

236236
"""
237237
calculate_stall_angle_list(panels::Vector{Panel};
238-
begin_aoa::Float64=9.0,
239-
end_aoa::Float64=22.0,
240-
step_aoa::Float64=1.0,
241-
stall_angle_if_none_detected::Float64=50.0,
242-
cl_initial::Float64=-10.0)
238+
begin_aoa=9.0,
239+
end_aoa=22.0,
240+
step_aoa=1.0,
241+
stall_angle_if_none_detected=50.0,
242+
cl_initial=-10.0)
243243
244244
Calculate stall angles for each panel.
245245
246246
Returns:
247247
Vector{Float64}: Stall angles in radians
248248
"""
249249
function calculate_stall_angle_list(panels::Vector{Panel};
250-
begin_aoa::Float64=9.0,
251-
end_aoa::Float64=22.0,
252-
step_aoa::Float64=1.0,
253-
stall_angle_if_none_detected::Float64=50.0,
254-
cl_initial::Float64=-10.0)
250+
begin_aoa=9.0,
251+
end_aoa=22.0,
252+
step_aoa=1.0,
253+
stall_angle_if_none_detected=50.0,
254+
cl_initial=-10.0)
255255

256256
aoa_range = deg2rad.(range(begin_aoa, end_aoa, step=step_aoa))
257257
stall_angles = Float64[]
@@ -282,13 +282,13 @@ end
282282
const cache_body = [LazyBufferCache() for _ in 1:5]
283283

284284
"""
285-
update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics, gamma::Vector{Float64},
286-
core_radius_fraction::Float64,
287-
z_airf_array::Matrix{Float64},
288-
x_airf_array::Matrix{Float64},
289-
va_array::Matrix{Float64},
290-
va_norm_array::Vector{Float64},
291-
va_unit_array::Matrix{Float64})
285+
update_effective_angle_of_attack_if_VSM(body_aero::BodyAerodynamics, gamma,
286+
core_radius_fraction,
287+
z_airf_array,
288+
x_airf_array,
289+
va_array,
290+
va_norm_array,
291+
va_unit_array)
292292
293293
Update angle of attack at aerodynamic center for VSM method.
294294
@@ -297,13 +297,13 @@ Returns:
297297
"""
298298
function update_effective_angle_of_attack!(alpha_corrected,
299299
body_aero::BodyAerodynamics,
300-
gamma::Vector{Float64},
301-
core_radius_fraction::Float64,
302-
z_airf_array::Matrix{Float64},
303-
x_airf_array::Matrix{Float64},
304-
va_array::Matrix{Float64},
305-
va_norm_array::Vector{Float64},
306-
va_unit_array::Matrix{Float64})
300+
gamma,
301+
core_radius_fraction,
302+
z_airf_array,
303+
x_airf_array,
304+
va_array,
305+
va_norm_array,
306+
va_unit_array)
307307

308308
# Calculate AIC matrices (keep existing optimized view)
309309
calculate_AIC_matrices!(body_aero, LLT, core_radius_fraction, va_norm_array, va_unit_array)
@@ -355,14 +355,14 @@ function update_effective_angle_of_attack!(alpha_corrected,
355355
end
356356

357357
"""
358-
calculate_results(body_aero::BodyAerodynamics, gamma_new::Vector{Float64},
359-
density::Float64, aerodynamic_model_type::Model,
360-
core_radius_fraction::Float64, mu::Float64,
361-
alpha_array::Vector{Float64}, v_a_array::Vector{Float64},
362-
chord_array::Vector{Float64}, x_airf_array::Matrix{Float64},
363-
y_airf_array::Matrix{Float64}, z_airf_array::Matrix{Float64},
364-
va_array::Matrix{Float64}, va_norm_array::Vector{Float64},
365-
va_unit_array::Matrix{Float64}, panels::Vector{Panel},
358+
calculate_results(body_aero::BodyAerodynamics, gamma_new,
359+
density, aerodynamic_model_type::Model,
360+
core_radius_fraction, mu,
361+
alpha_array, v_a_array,
362+
chord_array, x_airf_array,
363+
y_airf_array, z_airf_array,
364+
va_array, va_norm_array,
365+
va_unit_array, panels::Vector{Panel},
366366
is_only_f_and_gamma_output::Bool)
367367
368368
Calculate final aerodynamic results. Reference point is in the kite body (KB) frame.
@@ -372,21 +372,21 @@ Returns:
372372
"""
373373
function calculate_results(
374374
body_aero::BodyAerodynamics,
375-
gamma_new::Vector{Float64},
376-
reference_point::AbstractVector,
377-
density::Float64,
375+
gamma_new,
376+
reference_point,
377+
density,
378378
aerodynamic_model_type::Model,
379-
core_radius_fraction::Float64,
380-
mu::Float64,
381-
alpha_array::Vector{Float64},
382-
v_a_array::Vector{Float64},
383-
chord_array::Vector{Float64},
384-
x_airf_array::Matrix{Float64},
385-
y_airf_array::Matrix{Float64},
386-
z_airf_array::Matrix{Float64},
387-
va_array::Matrix{Float64},
388-
va_norm_array::Vector{Float64},
389-
va_unit_array::Matrix{Float64},
379+
core_radius_fraction,
380+
mu,
381+
alpha_array,
382+
v_a_array,
383+
chord_array,
384+
x_airf_array,
385+
y_airf_array,
386+
z_airf_array,
387+
va_array,
388+
va_norm_array,
389+
va_unit_array,
390390
panels::Vector{Panel},
391391
is_only_f_and_gamma_output::Bool,
392392
)

src/solver.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ end
4848
# Output of the function gamma_loop!
4949
@with_kw mutable struct LoopResult{P}
5050
converged::Bool = false
51-
gamma_new::Vector{Float64} = zeros(P)
52-
alpha_array::Vector{Float64} = zeros(P) # TODO: Is this different from BodyAerodynamics.alpha_array ?
53-
v_a_array::Vector{Float64} = zeros(P)
51+
gamma_new::MVector{P, Float64} = zeros(MVector{P, Float64})
52+
alpha_array::MVector{P, Float64} = zeros(MVector{P, Float64}) # TODO: Is this different from BodyAerodynamics.alpha_array ?
53+
v_a_array::MVector{P, Float64} = zeros(MVector{P, Float64})
5454
end
5555

5656
function LoopResult(P)
@@ -90,16 +90,19 @@ Main solver structure for the Vortex Step Method.See also: [solve](@ref)
9090
## Solution
9191
sol::VSMSolution = VSMSolution(): The result of calling [solve!](@ref)
9292
"""
93-
@with_kw struct Solver{P}
93+
@with_kw mutable struct Solver{P}
9494
# General settings
9595
solver_type::SolverType = LOOP
9696
aerodynamic_model_type::Model = VSM
9797
density::Float64 = 1.225
9898
max_iterations::Int64 = 1500
99-
atol::Float64 = 1e-5
10099
rtol::Float64 = 1e-5
101100
tol_reference_error::Float64 = 0.001
102101
relaxation_factor::Float64 = 0.03
102+
103+
# Nonlin solver fields
104+
prob::Union{NonlinearProblem, Nothing} = nothing
105+
atol::Float64 = 1e-5
103106

104107
# Damping settings
105108
is_with_artificial_damping::Bool = false
@@ -487,16 +490,20 @@ function gamma_loop!(
487490
end
488491

489492
if solver.solver_type == NONLIN
490-
function f_nonlin!(d_gamma, gamma, p)
491-
calc_gamma_new!(solver.lr.gamma_new, gamma)
492-
d_gamma .= solver.lr.gamma_new .- gamma
493-
nothing
493+
if isnothing(solver.prob)
494+
function f_nonlin!(d_gamma, gamma, p)
495+
calc_gamma_new!(solver.lr.gamma_new, gamma)
496+
d_gamma .= solver.lr.gamma_new .- gamma
497+
nothing
498+
end
499+
solver.prob = NonlinearProblem(f_nonlin!, solver.lr.gamma_new, nothing)
494500
end
495-
prob = NonlinearProblem(f_nonlin!, solver.lr.gamma_new, nothing)
496-
sol = NonlinearSolve.solve(prob, NewtonRaphson(autodiff=AutoFiniteDiff()); abstol=solver.atol, reltol=solver.rtol)
501+
502+
sol = NonlinearSolve.solve(solver.prob, NewtonRaphson(autodiff=AutoFiniteDiff()); abstol=solver.atol, reltol=solver.rtol)
497503
gamma .= sol.u
498504
solver.lr.gamma_new .= sol.u
499505
solver.lr.converged = SciMLBase.successful_retcode(sol)
506+
return nothing
500507
end
501508

502509
if solver.solver_type == LOOP
@@ -544,9 +551,8 @@ function gamma_loop!(
544551
elseif log
545552
@warn "NO convergence after $(solver.max_iterations) iterations"
546553
end
554+
return nothing
547555
end
548-
549-
nothing
550556
end
551557

552558
"""

0 commit comments

Comments
 (0)