diff --git a/Project.toml b/Project.toml index 592eeb16..5c9ed345 100644 --- a/Project.toml +++ b/Project.toml @@ -12,5 +12,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/VortexStepMethod.jl b/src/VortexStepMethod.jl index e0623806..42b4b51c 100644 --- a/src/VortexStepMethod.jl +++ b/src/VortexStepMethod.jl @@ -1,6 +1,7 @@ module VortexStepMethod using LinearAlgebra +using StaticArrays using Logging using Statistics using Colors @@ -18,6 +19,21 @@ export add_section!, set_va! export calculate_span, calculate_projected_area export plot_wing, plot_circulation_distribution, plot_geometry, plot_distribution, plot_polars +""" + const MVec3 = MVector{3, Float64} + +Basic 3-dimensional vector, stack allocated, mutable. +""" +const MVec3 = MVector{3, Float64} + +""" + const PosVector=Union{MVec3, Vector} + +Position vector, either a `MVec3` or a `Vector` for use in function signatures. +""" +const PosVector=Union{MVec3, Vector} +const VelVector=Union{MVec3, Vector} + # Include core functionality include("wing_geometry.jl") include("filament.jl") diff --git a/src/filament.jl b/src/filament.jl index 25b56b5c..1d6229b5 100644 --- a/src/filament.jl +++ b/src/filament.jl @@ -19,7 +19,7 @@ struct BoundFilament <: Filament length::Float64 # Filament length r0::Vector{Float64} # Vector from x1 to x2 - function BoundFilament(x1::Vector{Float64}, x2::Vector{Float64}) + function BoundFilament(x1::PosVector, x2::PosVector) new(x1, x2, norm(x2 - x1), x2 - x1) end end @@ -31,9 +31,9 @@ end Calculate induced velocity by a bound vortex filament at a point in space. """ function velocity_3D_bound_vortex!( - vel::Vector{Float64}, + vel::VelVector, filament::BoundFilament, - XVP::Vector{Float64}, + XVP::PosVector, gamma::Float64, core_radius_fraction::Float64, work_vectors::NTuple{10, Vector{Float64}} @@ -95,9 +95,9 @@ Reference: Rick Damiani et al. "A vortex step method for nonlinear airfoil polar as implemented in KiteAeroDyn". """ function velocity_3D_trailing_vortex!( - vel::Vector{Float64}, + vel::VelVector, filament::BoundFilament, - XVP::Vector{Float64}, + XVP::PosVector, gamma::Float64, Uinf::Float64, work_vectors::NTuple{10,Vector{Float64}} @@ -162,10 +162,10 @@ end Calculate induced velocity by a semi-infinite trailing vortex filament. """ function velocity_3D_trailing_vortex_semiinfinite!( - vel::Vector{Float64}, + vel::VelVector, filament::SemiInfiniteFilament, - Vf::Vector{Float64}, - XVP::Vector{Float64}, + Vf::VelVector, + XVP::PosVector, GAMMA::Float64, Uinf::Float64, work_vectors::NTuple{10,Vector{Float64}} diff --git a/src/panel.jl b/src/panel.jl index c974b9d6..f572cac0 100644 --- a/src/panel.jl +++ b/src/panel.jl @@ -50,10 +50,10 @@ mutable struct Panel function Panel( section_1::Section, section_2::Section, - aerodynamic_center::Vector{Float64}, - control_point::Vector{Float64}, - bound_point_1::Vector{Float64}, - bound_point_2::Vector{Float64}, + aerodynamic_center::PosVector, + control_point::PosVector, + bound_point_1::PosVector, + bound_point_2::PosVector, x_airf::Vector{Float64}, y_airf::Vector{Float64}, z_airf::Vector{Float64} @@ -352,10 +352,10 @@ Calculate the velocity induced by a vortex ring at a control point. """ function calculate_velocity_induced_single_ring_semiinfinite( panel::Panel, - evaluation_point::Vector{Float64}, + evaluation_point::PosVector, evaluation_point_on_bound::Bool, va_norm::Float64, - va_unit::Vector{Float64}, + va_unit::VelVector, gamma::Float64, core_radius_fraction::Float64, work_vectors::NTuple{10,Vector{Float64}} @@ -421,7 +421,7 @@ Only needed for VSM, as LLT bound and filament align, thus no induced velocity. """ function calculate_velocity_induced_bound_2D( panel::Panel, - evaluation_point::Vector{Float64} + evaluation_point::PosVector ) # r3 perpendicular to the bound vortex r3 = evaluation_point - (panel.bound_point_1 + panel.bound_point_2) / 2 diff --git a/src/wing_aerodynamics.jl b/src/wing_aerodynamics.jl index b318ca3f..db56ca07 100644 --- a/src/wing_aerodynamics.jl +++ b/src/wing_aerodynamics.jl @@ -83,10 +83,10 @@ end Structure to hold calculated panel properties. """ struct PanelProperties - aero_centers::Vector{Vector{Float64}} - control_points::Vector{Vector{Float64}} - bound_points_1::Vector{Vector{Float64}} - bound_points_2::Vector{Vector{Float64}} + aero_centers::Vector{PosVector} + control_points::Vector{PosVector} + bound_points_1::Vector{PosVector} + bound_points_2::Vector{PosVector} x_airf::Vector{Vector{Float64}} y_airf::Vector{Vector{Float64}} z_airf::Vector{Vector{Float64}} diff --git a/src/wing_geometry.jl b/src/wing_geometry.jl index d89e5c2f..be662d19 100644 --- a/src/wing_geometry.jl +++ b/src/wing_geometry.jl @@ -62,8 +62,8 @@ mutable struct Wing end """ - add_section!(wing::Wing, LE_point::Vector{Float64}, - TE_point::Vector{Float64}, aero_input::Vector{Any}) + add_section!(wing::Wing, LE_point::PosVector, + TE_point::PosVector, aero_input::Vector{Any}) Add a new section to the wing. """ diff --git a/test/test_semi_infinite_filament.jl b/test/test_semi_infinite_filament.jl index b566d896..f220ff9b 100644 --- a/test/test_semi_infinite_filament.jl +++ b/test/test_semi_infinite_filament.jl @@ -3,7 +3,7 @@ using LinearAlgebra using Test using BenchmarkTools -function create_test_filament() +function create_test_filament2() x1 = [0.0, 0.0, 0.0] direction = [1.0, 0.0, 0.0] filament_direction = 1 @@ -41,7 +41,7 @@ end work_vectors = ntuple(_ -> Vector{Float64}(undef, 3), 10) @testset "Allocation Tests" begin - filament = create_test_filament() + filament = create_test_filament2() control_point = [0.5, 0.5, 2.0] induced_velocity = zeros(3) @@ -60,7 +60,7 @@ end end @testset "Calculate Induced Velocity" begin - filament = create_test_filament() + filament = create_test_filament2() control_point = [0.5, 0.5, 2.0] induced_velocity = zeros(3) @@ -83,7 +83,7 @@ end end @testset "Point on Filament" begin - filament = create_test_filament() + filament = create_test_filament2() test_points = [ [0.0, 0.0, 0.0], # Start point [0.5, 0.0, 0.0], # Along filament @@ -106,7 +106,7 @@ end end @testset "Different Gamma Values" begin - filament = create_test_filament() + filament = create_test_filament2() control_point = [0.5, 1.0, 0.0] v1 = zeros(3) v2 = zeros(3) @@ -121,7 +121,7 @@ end end @testset "Symmetry" begin - filament = create_test_filament() + filament = create_test_filament2() vel_pos = zeros(3) vel_neg = zeros(3)