Examples
These examples show how to use Xfoil.jl.
Manual Angle of Attack Sweep
This first example shows how to manually perform an angle of attack sweep.
using Xfoil, Printf
# read airfoil into XFOIL
open("naca2412.dat", "r") do f
x = Float64[]
y = Float64[]
for line in eachline(f)
entries = split(chomp(line))
push!(x, parse(Float64, entries[1]))
push!(y, parse(Float64, entries[2]))
end
Xfoil.set_coordinates(x,y)
end
# repanel using XFOIL's `PANE` command
Xfoil.pane()
# set operating conditions
alpha = -10:1:10
re = 1e5
mach = 0.0
# initialize outputs
n_a = length(alpha)
c_l = zeros(n_a)
c_d = zeros(n_a)
c_dp = zeros(n_a)
c_m = zeros(n_a)
converged = zeros(Bool, n_a)
for i = 1:n_a
c_l[i], c_d[i], c_dp[i], c_m[i], converged[i] = Xfoil.solve_alpha(alpha[i], re; mach, iter=100)
end
# print results
println("Angle\t\tCl\t\tCd\t\tCm\t\tConverged")
for i = 1:n_a
@printf("%8f\t%8f\t%8f\t%8f\t%d\n",alpha[i],c_l[i],c_d[i],c_m[i],converged[i])
endAngle Cl Cd Cm Converged
-10.000000 -0.464031 0.108164 -0.021557 1
-9.000000 -0.466796 0.093346 -0.026590 1
-8.000000 -0.521766 0.076927 -0.033820 1
-7.000000 -0.635832 0.034981 -0.035654 1
-6.000000 -0.568476 0.027869 -0.029951 1
-5.000000 -0.484882 0.023137 -0.026257 1
-4.000000 -0.395129 0.020376 -0.023719 1
-3.000000 -0.306835 0.018702 -0.021919 1
-2.000000 -0.144444 0.017012 -0.032525 1
-1.000000 0.084503 0.017323 -0.052484 1
0.000000 0.273953 0.016614 -0.068255 1
1.000000 0.406827 0.015799 -0.070669 1
2.000000 0.511046 0.015537 -0.066991 1
3.000000 0.608250 0.015873 -0.062339 1
4.000000 0.707389 0.016509 -0.058131 1
5.000000 0.802921 0.017368 -0.053541 1
6.000000 0.893771 0.018322 -0.048318 1
7.000000 0.975327 0.019445 -0.041884 1
8.000000 1.034578 0.022188 -0.033045 1
9.000000 1.085745 0.027443 -0.024469 1
10.000000 1.156664 0.033658 -0.019314 1Suppose we want to find the derivative of c_l, c_d, and c_m with respect to alpha at the same angles of attack. One approach to calculate these derivatives would be to use the finite difference method.
using Xfoil, Printf
# read airfoil into XFOIL
open("naca2412.dat", "r") do f
x = Float64[]
y = Float64[]
for line in eachline(f)
entries = split(chomp(line))
push!(x, parse(Float64, entries[1]))
push!(y, parse(Float64, entries[2]))
end
Xfoil.set_coordinates(x,y)
end
# repanel using XFOIL's `PANE` command
Xfoil.pane()
# set operating conditions
alpha = -10:1:10
re = 1e5
mach = 0.0
# set step size
h = 1e-6
# initialize outputs
n_a = length(alpha)
c_l_a = zeros(n_a)
c_d_a = zeros(n_a)
c_dp_a = zeros(n_a)
c_m_a = zeros(n_a)
converged = zeros(Bool, n_a)
for i = 1:n_a
c_l1, c_d1, c_dp1, c_m1, converged[i] = Xfoil.solve_alpha(alpha[i], re; mach, iter=100)
c_l2, c_d2, c_dp2, c_m2, converged[i] = Xfoil.solve_alpha(alpha[i]+h, re; mach, iter=100)
c_l_a[i] = (c_l2 - c_l1)/h * 180/pi
c_d_a[i] = (c_d2 - c_d1)/h * 180/pi
c_m_a[i] = (c_m2 - c_m1)/h * 180/pi
end
# print results
println("Angle\t\tdClda\t\tdCdda\t\tdCmda\t\tConverged")
for i = 1:n_a
@printf("%8f\t%8f\t%8f\t%8f\t%d\n",alpha[i],c_l_a[i],c_d_a[i],c_m_a[i],converged[i])
endAngle dClda dCdda dCmda Converged
-10.000000 3.779719 -0.604610 0.342606 1
-9.000000 2.626080 -0.687377 0.207316 1
-8.000000 1.006273 -0.792112 0.301047 1
-7.000000 2.642149 -0.399279 0.532187 1
-6.000000 4.343322 -0.211069 0.375840 1
-5.000000 5.022881 -0.158689 0.205753 1
-4.000000 5.134982 -0.084520 0.150924 1
-3.000000 5.158002 -0.019555 0.078398 1
-2.000000 9.126479 -0.035567 -0.320871 1
-1.000000 10.271401 -0.023298 -0.912901 1
0.000000 12.325168 -0.091335 -1.041678 1
1.000000 8.742740 -0.089399 -0.226087 1
2.000000 3.010501 0.095911 0.575110 1
3.000000 6.005368 0.009855 0.220494 1
4.000000 3.444125 0.110609 0.458157 1
5.000000 6.530404 0.033534 0.153271 1
6.000000 4.517164 0.061409 0.380156 1
7.000000 4.538258 0.086789 0.398239 1
8.000000 2.098868 0.317527 0.617265 1
9.000000 3.166303 0.322161 0.398941 1
10.000000 3.873508 0.340185 0.341636 1A better approach might be to use the complex step method.
using Xfoil, Printf
# read airfoil into XFOIL
open("naca2412.dat", "r") do f
x = Float64[]
y = Float64[]
for line in eachline(f)
entries = split(chomp(line))
push!(x, parse(Float64, entries[1]))
push!(y, parse(Float64, entries[2]))
end
Xfoil.set_coordinates_cs(x,y)
end
# repanel using XFOIL's `PANE` command
Xfoil.pane_cs()
# set operating conditions
alpha = -10:1:10
re = 1e5
mach = 0.0
# set step size
h = 1e-20im
# initialize outputs
n_a = length(alpha)
c_l_a = zeros(n_a)
c_d_a = zeros(n_a)
c_dp_a = zeros(n_a)
c_m_a = zeros(n_a)
converged = zeros(Bool, n_a)
for i = 1:n_a
c_l, c_d, c_dp, c_m, converged[i] = Xfoil.solve_alpha_cs(alpha[i]+h, re; mach, iter=100)
c_l_a[i] = imag(c_l)/imag(h) * 180/pi
c_d_a[i] = imag(c_d)/imag(h) * 180/pi
c_m_a[i] = imag(c_m)/imag(h) * 180/pi
end
# print results
println("Angle\t\tdClda\t\tdCdda\t\tdCmda\t\tConverged")
for i = 1:n_a
@printf("%8f\t%8f\t%8f\t%8f\t%d\n",alpha[i],c_l_a[i],c_d_a[i],c_m_a[i],converged[i])
endAngle dClda dCdda dCmda Converged
-10.000000 3.836778 -0.606239 0.338542 1
-9.000000 -308.222983 -90.101663 30.291607 1
-8.000000 1.015039 -0.792379 0.301010 1
-7.000000 2.646253 -0.399401 0.531807 1
-6.000000 4.350507 -0.211193 0.374933 1
-5.000000 5.032753 -0.158907 0.204315 1
-4.000000 5.147571 -0.084773 0.148990 1
-3.000000 5.174246 -0.019851 0.075819 1
-2.000000 9.134179 -0.035749 -0.321986 1
-1.000000 10.271136 -0.023432 -0.912764 1
0.000000 12.326638 -0.091378 -1.041800 1
1.000000 8.744871 -0.089444 -0.226340 1
2.000000 3.012825 0.095849 0.574821 1
3.000000 6.007896 0.009783 0.220178 1
4.000000 3.446835 0.110536 0.457792 1
5.000000 6.534067 0.033438 0.152758 1
6.000000 4.521577 0.061297 0.379486 1
7.000000 4.544736 0.086650 0.397209 1
8.000000 2.108494 0.317512 0.615544 1
9.000000 3.184692 0.322179 0.395689 1
10.000000 3.899871 0.340231 0.337307 1Automatic Angle of Attack Sweep
For performing angle of attack sweeps, the function alpha_sweep may also be used.
using Xfoil, Printf
# extract geometry
x = Float64[]
y = Float64[]
f = open("naca2412.dat", "r")
for line in eachline(f)
entries = split(chomp(line))
push!(x, parse(Float64, entries[1]))
push!(y, parse(Float64, entries[2]))
end
close(f)
# set operating conditions
alpha = -10:1:10
re = 1e5
c_l, c_d, c_dp, c_m, converged = Xfoil.alpha_sweep(x, y, alpha, re, iter=100, zeroinit=false, printdata=true)
Angle Cl Cd Cm Converged
-10.000000 -0.464031 0.108164 -0.021557 1
-9.000000 -0.466796 0.093346 -0.026590 1
-8.000000 -0.521766 0.076927 -0.033820 1
-7.000000 -0.635832 0.034981 -0.035654 1
-6.000000 -0.568476 0.027869 -0.029951 1
-5.000000 -0.484882 0.023137 -0.026257 1
-4.000000 -0.395129 0.020376 -0.023719 1
-3.000000 -0.306835 0.018702 -0.021919 1
-2.000000 -0.144444 0.017012 -0.032525 1
-1.000000 0.084503 0.017323 -0.052484 1
0.000000 0.273953 0.016614 -0.068255 1
1.000000 0.406827 0.015799 -0.070669 1
2.000000 0.511046 0.015537 -0.066991 1
3.000000 0.608250 0.015873 -0.062339 1
4.000000 0.707389 0.016509 -0.058131 1
5.000000 0.802921 0.017368 -0.053541 1
6.000000 0.893771 0.018322 -0.048318 1
7.000000 0.975327 0.019445 -0.041884 1
8.000000 1.034578 0.022188 -0.033045 1
9.000000 1.085745 0.027443 -0.024469 1
10.000000 1.156664 0.033658 -0.019314 1A version of alpha_sweep has also been implemented for use with the complex step version of XFOIL.
using Xfoil, Printf
# extract geometry
x = Float64[]
y = Float64[]
f = open("naca2412.dat", "r")
for line in eachline(f)
entries = split(chomp(line))
push!(x, parse(Float64, entries[1]))
push!(y, parse(Float64, entries[2]))
end
close(f)
# set operating conditions
alpha = -10:1:10
re = 1e5
mach = 0.0
# set step size
h = 1e-20im
c_l, c_d, c_dp, c_m, converged = Xfoil.alpha_sweep_cs(x, y, alpha .+ h,
re, mach=mach, iter=100, zeroinit=false, printdata=true)
println("Angle\t\tdClda\t\tdCdda\t\tdCmda\t\tConverged")
for i = 1:length(alpha)
@printf("%8f\t%8f\t%8f\t%8f\t%d\n", alpha[i], imag(c_l[i])/imag(h)*180/pi, imag(c_d[i])/imag(h)*180/pi, imag(c_m[i])/imag(h)*180/pi, converged[i])
end
Angle Cl Cd Cm Converged
-10.000000 -0.464031 0.108164 -0.021557 1
-9.000000 -0.466796 0.093346 -0.026590 1
-8.000000 -0.521766 0.076927 -0.033820 1
-7.000000 -0.635832 0.034981 -0.035654 1
-6.000000 -0.568476 0.027869 -0.029951 1
-5.000000 -0.484882 0.023137 -0.026257 1
-4.000000 -0.395129 0.020376 -0.023719 1
-3.000000 -0.306835 0.018702 -0.021919 1
-2.000000 -0.144444 0.017012 -0.032525 1
-1.000000 0.084503 0.017323 -0.052484 1
0.000000 0.273953 0.016614 -0.068255 1
1.000000 0.406827 0.015799 -0.070669 1
2.000000 0.511046 0.015537 -0.066991 1
3.000000 0.608250 0.015873 -0.062339 1
4.000000 0.707389 0.016509 -0.058131 1
5.000000 0.802921 0.017368 -0.053541 1
6.000000 0.893771 0.018322 -0.048318 1
7.000000 0.975327 0.019445 -0.041884 1
8.000000 1.034578 0.022188 -0.033045 1
9.000000 1.085745 0.027443 -0.024469 1
10.000000 1.156664 0.033658 -0.019314 1
Angle dClda dCdda dCmda Converged
-10.000000 3.836778 -0.606239 0.338542 1
-9.000000 -308.222983 -90.101663 30.291607 1
-8.000000 1.015039 -0.792379 0.301010 1
-7.000000 2.646253 -0.399401 0.531807 1
-6.000000 4.350507 -0.211193 0.374933 1
-5.000000 5.032753 -0.158907 0.204315 1
-4.000000 5.147571 -0.084773 0.148990 1
-3.000000 5.174246 -0.019851 0.075819 1
-2.000000 9.134179 -0.035749 -0.321986 1
-1.000000 10.271136 -0.023432 -0.912764 1
0.000000 12.326638 -0.091378 -1.041800 1
1.000000 8.744871 -0.089444 -0.226340 1
2.000000 3.012825 0.095849 0.574821 1
3.000000 6.007896 0.009783 0.220178 1
4.000000 3.446835 0.110536 0.457792 1
5.000000 6.534067 0.033438 0.152758 1
6.000000 4.521577 0.061297 0.379486 1
7.000000 4.544736 0.086650 0.397209 1
8.000000 2.108494 0.317512 0.615544 1
9.000000 3.184692 0.322179 0.395689 1
10.000000 3.899871 0.340231 0.337307 1