-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangular_wing.jl
More file actions
103 lines (89 loc) · 2.91 KB
/
Copy pathrectangular_wing.jl
File metadata and controls
103 lines (89 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Pkg
if Base.active_project() != joinpath(@__DIR__, "Project.toml")
Pkg.activate(@__DIR__)
end
using LinearAlgebra
using GLMakie
using MakieControlPlots
using VortexStepMethod
PLOT = true
SAVE_ALL = false
USE_TEX = false
OUTPUT_DIR = joinpath(dirname(@__DIR__), "output")
# Step 1: Define wing parameters
n_panels = 20 # Number of panels
span = 20.0 # Wing span [m]
chord = 1.0 # Chord length [m]
va = 20.0 # Magnitude of inflow velocity [m/s]
density = 1.225 # Air density [kg/m³]
alpha_deg = 30.0 # Angle of attack [degrees]
alpha = deg2rad(alpha_deg)
# Step 2: Create wing geometry with linear panel distribution
wing = Wing(n_panels, spanwise_distribution=LINEAR)
# Add wing sections - defining only tip sections with inviscid airfoil model
add_section!(wing,
[0.0, span/2, 0.0], # Left tip LE
[chord, span/2, 0.0], # Left tip TE
INVISCID)
add_section!(wing,
[0.0, -span/2, 0.0], # Right tip LE
[chord, -span/2, 0.0], # Right tip TE
INVISCID)
# Refine mesh
refine!(wing)
# Step 3: Initialize aerodynamics
body_aero = BodyAerodynamics([wing])
# Set inflow conditions
va_vec = apparent_wind(alpha, 0.0, va)
set_va!(body_aero, va_vec, [0, 0, 0.1])
# Step 4: Initialize solvers for both LLT and VSM methods
llt_solver = Solver(wing.n_panels, wing.n_unrefined_sections; aerodynamic_model_type=LLT)
vsm_solver = Solver(wing.n_panels, wing.n_unrefined_sections; aerodynamic_model_type=VSM)
# Step 5: Solve using both methods
results_llt = solve(llt_solver, body_aero)
results_vsm = solve(vsm_solver, body_aero)
@time solve(llt_solver, body_aero)
@time solve(vsm_solver, body_aero)
# Print results comparison
println("\nLifting Line Theory Results:")
println("CL = $(round(results_llt["cl"], digits=4))")
println("CD = $(round(results_llt["cd"], digits=4))")
println("\nVortex Step Method Results:")
println("CL = $(round(results_vsm["cl"], digits=4))")
println("CD = $(round(results_vsm["cd"], digits=4))")
println("Projected area = $(round(results_vsm["projected_area"], digits=4)) m²")
# Step 6: Plot geometry
PLOT && plot_geometry(
body_aero,
"Rectangular wing geometry";
save_path=OUTPUT_DIR,
is_save=false || SAVE_ALL,
is_show=true,
use_tex=USE_TEX
)
# Step 7: Plot spanwise distributions
y_coordinates = [panel.aero_center[2] for panel in body_aero.panels]
PLOT && plot_distribution(
[y_coordinates, y_coordinates],
[results_vsm, results_llt],
["VSM", "LLT"],
title="Spanwise Distributions",
save_path=OUTPUT_DIR,
is_save=false || SAVE_ALL,
use_tex=USE_TEX
)
# Step 8: Plot polar curves
angle_range = range(0, 20, 20)
PLOT && plot_polars(
[llt_solver, vsm_solver],
[body_aero, body_aero],
["LLT", "VSM"];
angle_range,
angle_type="angle_of_attack",
v_a=va,
title="Rectangular Wing Polars",
save_path=OUTPUT_DIR,
is_save=false || SAVE_ALL,
use_tex=USE_TEX
)
nothing