Skip to content

Commit c7a9df9

Browse files
authored
Add the turnrate vector omega (#65)
* add omega * use set_va * fix tests * remove second parameter yaw rate comment * rename Uinf to v_a
1 parent 6360cda commit c7a9df9

File tree

13 files changed

+63
-67
lines changed

13 files changed

+63
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ wa = BodyAerodynamics([wing])
114114

115115
# Set inflow conditions
116116
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
117-
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
117+
set_va!(wa, vel_app)
118118
```
119119
It is possible to import the wing geometry using an `.obj` file as shown in the example `ram_air_kite.jl`.
120120

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ wa = BodyAerodynamics([wing])
115115

116116
# Set inflow conditions
117117
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
118-
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
118+
set_va!(wa, vel_app)
119119
```
120120
It is possible to import the wing geometry using an `.obj` file as shown in the example `ram_air_kite.jl`.
121121

examples/bench.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ wa = BodyAerodynamics([wing])
3131

3232
# Set inflow conditions
3333
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
34-
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
34+
set_va!(wa, vel_app)
3535

3636
# Step 4: Initialize solvers for both LLT and VSM methods
3737
llt_solver = Solver(aerodynamic_model_type=:LLT)

examples/ram_air_kite.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vel_app = [
3636
sin(side_slip),
3737
sin(aoa_rad)
3838
] * v_a
39-
body_aero.va = vel_app
39+
set_va!(body_aero, vel_app)
4040

4141
# Plotting geometry
4242
plot && plot_geometry(

examples/rectangular_wing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ wa = BodyAerodynamics([wing])
3131

3232
# Set inflow conditions
3333
vel_app = [cos(alpha), 0.0, sin(alpha)] .* v_a
34-
set_va!(wa, (vel_app, 0.0)) # Second parameter is yaw rate
34+
set_va!(wa, vel_app, [0, 0, 0.1])
3535

3636
# Step 4: Initialize solvers for both LLT and VSM methods
3737
llt_solver = Solver(aerodynamic_model_type=:LLT)

examples/stall_model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ vel_app = [
6363
sin(side_slip),
6464
sin(aoa_rad)
6565
] * v_a
66-
body_aero_CAD_19ribs.va = vel_app
66+
set_va!(body_aero_CAD_19ribs, vel_app)
6767

6868
# Plotting geometry
6969
plot && plot_geometry(

src/body_aerodynamics.jl

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Main structure for calculating aerodynamic properties of bodies.
66
# Fields
77
- panels::Vector{Panel}: Vector of Panel structs
88
- wings::Vector{AbstractWing}: a vector of wings; a body can have multiple wings
9-
- `_va`::Union{Nothing, Vector{Float64}, Tuple{MVec3, Float64}}: A vector of the apparent wind speed,
10-
or a tuple of the v_a vector and yaw rate (rad/s).
9+
- `va`::Union{Nothing, MVec3}: A vector of the apparent wind speed
10+
- `omega`::Union{Nothing, MVec3}: A vector of the turn rate around the kite body axes
1111
- `gamma_distribution`::Union{Nothing, Vector{Float64}}: unclear, please defined
1212
- `alpha_uncorrected`::Union{Nothing, Vector{Float64}}: unclear, please define
1313
- `alpha_corrected`::Union{Nothing, Vector{Float64}}: unclear, please define
@@ -16,7 +16,8 @@ Main structure for calculating aerodynamic properties of bodies.
1616
mutable struct BodyAerodynamics
1717
panels::Vector{Panel}
1818
wings::Vector{AbstractWing} # can be a vector of Wings, or of KiteWings
19-
_va::Union{Nothing, Vector{Float64}, Tuple{MVec3, Float64}}
19+
_va::Union{Nothing, Vector{Float64}}
20+
omega::Union{Nothing, MVec3}
2021
gamma_distribution::Union{Nothing, Vector{Float64}}
2122
alpha_uncorrected::Union{Nothing, Vector{Float64}}
2223
alpha_corrected::Union{Nothing, Vector{Float64}}
@@ -75,6 +76,7 @@ mutable struct BodyAerodynamics
7576
panels,
7677
wings,
7778
nothing, # va
79+
nothing, # omega
7880
nothing, # gamma_distribution
7981
nothing, # alpha_uncorrected
8082
nothing, # alpha_corrected
@@ -95,7 +97,7 @@ function Base.getproperty(obj::BodyAerodynamics, sym::Symbol)
9597
end
9698

9799
function Base.setproperty!(obj::BodyAerodynamics, sym::Symbol, val)
98-
if sym === :va
100+
if sym === :va || sym === :omega
99101
set_va!(obj, val)
100102
else
101103
setfield!(obj, sym, val)
@@ -639,49 +641,43 @@ end
639641

640642

641643
"""
642-
set_va!(body_aero::BodyAerodynamics, va::Union{Vector{Float64}, Tuple{Vector{Float64}, Float64}})
644+
set_va!(body_aero::BodyAerodynamics, va, omega=zeros(3))
643645
644646
Set velocity array and update wake filaments.
645647
646648
# Arguments
647-
- `va`: Either a velocity vector or tuple of (velocity vector, yaw_rate)
649+
- `va`: Either a velocity vector or a list of velocity vectors
650+
- `omega`: Turn rate around x y and z axis
648651
"""
649-
function set_va!(body_aero::BodyAerodynamics, va)
650-
# Add length check for va_vec
652+
function set_va!(body_aero::BodyAerodynamics, va, omega=zeros(MVec3))
653+
omega = MVec3(omega)
654+
655+
# Add length check for va
651656
if va isa Vector{Float64} && length(va) != 3 && length(va) != length(body_aero.panels)
652657
throw(ArgumentError("va must be length 3 or match number of panels"))
653658
end
654-
# Handle input types
655-
va_vec, yaw_rate = if va isa Tuple && length(va) == 2
656-
va
657-
else
658-
(va, 0.0)
659-
end
660-
661-
# Validate input
662-
va_vec = convert(Vector{Float64}, va_vec)
663659

664660
# Calculate va_distribution based on input type
665-
va_distribution = if length(va_vec) == 3 && yaw_rate == 0.0
666-
repeat(reshape(va_vec, 1, 3), length(body_aero.panels))
667-
elseif length(va_vec) == length(body_aero.panels)
668-
va_vec
669-
elseif yaw_rate != 0.0 && length(va_vec) == 3
670-
va_dist = Vector{Float64}[]
661+
va_distribution = if length(va) == 3 && all(omega .== 0.0)
662+
repeat(reshape(va, 1, 3), length(body_aero.panels))
663+
elseif length(va) == length(body_aero.panels)
664+
va
665+
elseif !all(omega .== 0.0) && length(va) == 3
666+
va_dist = zeros(length(body_aero.panels), 3)
671667

672668
for wing in body_aero.wings
673669
# Get spanwise positions
674-
spanwise_positions = [panel.control_point[2] for panel in body_aero.panels]
670+
spanwise_positions = [panel.control_point for panel in body_aero.panels]
675671

676672
# Calculate velocities for each panel
677673
for i in 1:wing.n_panels
678-
yaw_rate_apparent_velocity = [-yaw_rate * spanwise_positions[i], 0.0, 0.0]
679-
push!(va_dist, yaw_rate_apparent_velocity + va_vec)
674+
omega_va = -omega × spanwise_positions[i]
675+
va_dist[i, :] .= omega_va .+ va
680676
end
681677
end
682-
reduce(vcat, va_dist)
678+
va_dist
683679
else
684-
throw(ArgumentError("Invalid va distribution: length(va)=$(length(va_vec)) ≠ n_panels=$(length(body_aero.panels))"))
680+
throw(ArgumentError("Invalid va distribution: length(va)=$(length(va)) ≠ n_panels=$(length(body_aero.panels))"))
685681
end
686682

687683
# Update panel velocities
@@ -691,5 +687,6 @@ function set_va!(body_aero::BodyAerodynamics, va)
691687

692688
# Update wake elements
693689
body_aero.panels = frozen_wake(va_distribution, body_aero.panels)
694-
body_aero._va = va_vec
690+
body_aero._va = va
691+
return nothing
695692
end

src/filament.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ end
8686
velocity_3D_trailing_vortex(filament::BoundFilament,
8787
XVP::Vector{Float64},
8888
gamma::Float64,
89-
Uinf::Float64)
89+
v_a::Float64)
9090
9191
Calculate induced velocity by a trailing vortex filament.
9292
9393
# Arguments
9494
- `XVP`: Control point coordinates
9595
- `gamma`: Vortex strength
96-
- `Uinf`: Inflow velocity magnitude
96+
- `v_a`: Inflow velocity magnitude
9797
9898
Reference: Rick Damiani et al. "A vortex step method for nonlinear airfoil polar data
9999
as implemented in KiteAeroDyn".
@@ -103,7 +103,7 @@ as implemented in KiteAeroDyn".
103103
filament::BoundFilament,
104104
XVP,
105105
gamma,
106-
Uinf,
106+
v_a,
107107
work_vectors
108108
)
109109
r0, r1, r2, r_perp, r1Xr2, r1Xr0, r2Xr0, normr1r2 = work_vectors[1:8]
@@ -115,7 +115,7 @@ as implemented in KiteAeroDyn".
115115
r_perp .= dot(r1, r0) .* r0 ./ (norm(r0)^2)
116116

117117
# Cut-off radius
118-
epsilon = sqrt(4 * ALPHA0 * NU * norm(r_perp) / Uinf)
118+
epsilon = sqrt(4 * ALPHA0 * NU * norm(r_perp) / v_a)
119119

120120
cross3!(r1Xr2, r1, r2)
121121
cross3!(r1Xr0, r1, r0)
@@ -161,7 +161,7 @@ end
161161
"""
162162
velocity_3D_trailing_vortex_semiinfinite(filament::SemiInfiniteFilament,
163163
Vf::Vector{Float64}, XVP::Vector{Float64},
164-
GAMMA::Float64, Uinf::Float64)
164+
GAMMA::Float64, v_a::Float64)
165165
166166
Calculate induced velocity by a semi-infinite trailing vortex filament.
167167
"""
@@ -171,7 +171,7 @@ function velocity_3D_trailing_vortex_semiinfinite!(
171171
Vf,
172172
XVP,
173173
GAMMA,
174-
Uinf,
174+
v_a,
175175
work_vectors
176176
)
177177
r1, r_perp, r1XVf = work_vectors[1:3]
@@ -180,7 +180,7 @@ function velocity_3D_trailing_vortex_semiinfinite!(
180180

181181
# Calculate core radius
182182
r_perp .= dot(r1, Vf) .* Vf
183-
epsilon = sqrt(4 * ALPHA0 * NU * norm(r_perp) / Uinf)
183+
epsilon = sqrt(4 * ALPHA0 * NU * norm(r_perp) / v_a)
184184

185185
cross3!(r1XVf, r1, Vf)
186186

src/plotting.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ function plot_polars(
639639
# Read all data first
640640
data = readdlm(path, ',')
641641
# Skip the header row by taking data from row 2 onwards
642-
@show data[1, :]
643642
data = data[2:end, :]
644643
push!(polar_data_list, [data[:, 3], data[:, 1], data[:, 2], zeros(length(data[:, 1]))])
645644
end

src/solver.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function gamma_loop(
221221
induced_velocity_all = zeros(n_panels, 3)
222222
relative_velocity_array = similar(va_array)
223223
relative_velocity_crossz = similar(relative_velocity_array)
224-
Uinfcrossz_array = similar(va_array)
224+
v_acrossz_array = similar(va_array)
225225
cl_array = zeros(n_panels)
226226
damp = zeros(length(gamma))
227227
v_normal_array = zeros(n_panels)
@@ -249,7 +249,7 @@ function gamma_loop(
249249
view(relative_velocity_array, i, :),
250250
view(z_airf_array, i, :)
251251
)
252-
Uinfcrossz_array[i, :] .= cross3(
252+
v_acrossz_array[i, :] .= cross3(
253253
view(va_array, i, :),
254254
view(z_airf_array, i, :)
255255
)
@@ -263,7 +263,7 @@ function gamma_loop(
263263

264264
for i in 1:n_panels
265265
@views v_a_array[i] = norm(relative_velocity_crossz[i, :])
266-
@views Umagw_array[i] = norm(Uinfcrossz_array[i, :])
266+
@views Umagw_array[i] = norm(v_acrossz_array[i, :])
267267
end
268268

269269
for (i, (panel, alpha)) in enumerate(zip(panels, alpha_array))

0 commit comments

Comments
 (0)