Skip to content

Strip theory #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ authors = ["Taylor McDonnell <taylormcd@byu.edu", "Andrew Ning <aning@byu.edu>"]
version = "0.1.1"

[deps]
FLOWMath = "6cb5d3fb-0fe8-4cc2-bd89-9fe0b19a99d3"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
julia = "1.5"
Interpolations = "0.13"
StaticArrays = "0.12, 1.0"
WriteVTK = "1.8"
julia = "1.5"
51 changes: 51 additions & 0 deletions docs/src/XFLR-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Alpha Cd_inviscid Cd

-9.5 0.023835 0.03856
-9.0 0.021442 0.03514
-8.5 0.019169 0.03228
-8.0 0.017016 0.029664
-7.5 0.014985 0.027179
-7.0 0.013078 0.024689
-6.5 0.011295 0.022417
-6.0 0.00964 0.020362
-5.5 0.008112 0.018402
-5.0 0.006713 0.016632
-4.5 0.005444 0.014998
-4.0 0.004306 0.013492
-3.5 0.0033 0.012164
-3.0 0.002427 0.010992
-2.5 0.001686 0.00995
-2.0 0.00108 0.009057
-1.5 0.000608 0.008318
-1.0 0.00027 0.007735
-0.5 6.8e-5 0.007295
0.0 0.0 0.007003
0.5 6.8e-5 0.006857
1.0 0.00027 0.006849
1.5 0.000608 0.006967
2.0 0.00108 0.007248
2.5 0.001686 0.007713
3.0 0.002427 0.00835
3.5 0.0033 0.009155
4.0 0.004306 0.010135
4.5 0.005444 0.011317
5.0 0.006713 0.012691
5.5 0.008112 0.014216
6.0 0.00964 0.015882
6.5 0.011295 0.017685
7.0 0.013078 0.019625
7.5 0.014985 0.021699
8.0 0.017016 0.023931
8.5 0.019169 0.026317
9.0 0.021442 0.028874
9.5 0.023835 0.031628
10.0 0.026344 0.034562
10.5 0.028968 0.037681
11.0 0.031705 0.040997
11.5 0.034553 0.044462
12.0 0.03751 0.048052
12.5 0.040573 0.051761
13.0 0.043741 0.0556
13.5 0.04701 0.059561
14.0 0.050378 0.063659
14.5 0.053843 0.067949
187 changes: 187 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,193 @@ write_vtk("wing-tail", surfaces, properties; symmetric)

![](wing-tail.png)

## Viscous Drag Correction

This example shows how to make corerections to account for Viscous Drag

```@example viscous-drag
#geometry of right half of wing
xle = [0.0, 0.4]
yle = [0.0, 7.5]
zle = [0.0, 0.0]
chords = [2.2, 1.8]
theta = [0.0*pi/180, 0.0*pi/180]
phi = [0.0, 0.0]
fc = fill((xc) -> 0, 2) # camberline function for each section

# discretization parameters
ns = 12
nc = 1
spacing_s = Uniform()
spacing_c = Uniform()

# reference parameters
Sref = 30.0
cref = 2.0
bref = 15.0
rref = [0.50, 0.0, 0.0]
rho = 1.225
mu = 1.81e-5
Vinf = 1
ref = Reference(Sref, cref, bref, rref, Vinf)

# freestream parameters
alpha = 0.0*pi/180
beta = 0.0
Omega = [0.0; 0.0; 0.0]
fs = Freestream(Vinf, alpha, beta, Omega)

# construct surface
grid, surface = wing_to_surface_panels(xle, yle, zle, chords, theta, phi, ns, nc;
fc = fc, spacing_s=spacing_s, spacing_c=spacing_c)

# combine all grid representations of surfaces into a single vector
grids = [grid]

# calculate lifting line geometry
r, c = lifting_line_geometry(grids)

```
We will now read in the airfoil data, provide the reynolds number, and perform a sweep over angle of attack.

```@example viscous-drag

#read in xfoil data
res = [150000 320000 490000 660000 830000 1000000]
cls = [
-0.647901 -0.865237 -0.897876 -0.921655 -0.924562 -0.912016
-0.688353 -0.839616 -0.868863 -0.886064 -0.865452 -0.848249
-0.719029 -0.815164 -0.835761 -0.819934 -0.798952 -0.785489
-0.724569 -0.780939 -0.790784 -0.75616 -0.734558 -0.722138
-0.709499 -0.745029 -0.722006 -0.691479 -0.670796 -0.653588
-0.684209 -0.706653 -0.656801 -0.622444 -0.599316 -0.582615
-0.649806 -0.650326 -0.586158 -0.548678 -0.530815 -0.522789
-0.611421 -0.575085 -0.509326 -0.483783 -0.466995 -0.460582
-0.569993 -0.501801 -0.444908 -0.414056 -0.407301 -0.407514
-0.526773 -0.4288 -0.370251 -0.353972 -0.349998 -0.354136
-0.481819 -0.354335 -0.306358 -0.29439 -0.29748 -0.300658
-0.437417 -0.283642 -0.239317 -0.239731 -0.243597 -0.24657
-0.355987 -0.206903 -0.183994 -0.18603 -0.189385 -0.191869
-0.272751 -0.142592 -0.129707 -0.132465 -0.135185 -0.137191
-0.19158 -0.0804409 -0.0758313 -0.0786082 -0.0808187 -0.0825197
-0.113186 -0.0229882 -0.0221598 -0.0245126 -0.0263089 -0.0275698
-0.0424867 0.02954 0.0306951 0.0293735 0.0280789 0.026986
0.0246814 0.0807037 0.0829588 0.0828598 0.0825106 0.082028
0.106665 0.131261 0.135121 0.136025 0.13604 0.136118
0.231398 0.18 0.186528 0.188861 0.18975 0.190195
0.332249 0.236334 0.235567 0.24062 0.243155 0.244114
0.379965 0.309605 0.28689 0.289299 0.293824 0.296698
0.426923 0.395662 0.349986 0.341236 0.343296 0.346701
0.47316 0.470653 0.427291 0.4041 0.396623 0.397817
0.520035 0.517771 0.508826 0.477587 0.461357 0.454366
0.567195 0.564904 0.566138 0.555519 0.53455 0.521906
0.614409 0.612375 0.613351 0.615857 0.610176 0.594746
0.661897 0.659498 0.660533 0.663514 0.665885 0.668431
0.709736 0.706256 0.708341 0.710808 0.713209 0.715556
0.75633 0.753501 0.755084 0.758106 0.760814 0.76251
0.802545 0.800147 0.80302 0.805617 0.807281 0.80878
0.848128 0.846923 0.849982 0.85223 0.853764 0.855129
0.891559 0.892859 0.895978 0.898479 0.900326 0.90197
0.933165 0.936628 0.940798 0.944134 0.946547 0.948488
0.971578 0.978011 0.984136 0.988182 0.991548 0.994097
1.00277 1.01615 1.02564 1.03238 1.03724 1.04163
1.02813 1.05281 1.06639 1.07653 1.08365 1.08834
1.056 1.08886 1.10721 1.12135 1.12849 1.13565
1.08774 1.1238 1.14938 1.16289 1.1746 1.17986
1.12409 1.15418 1.184 1.2062 1.21487 1.2263
1.16485 1.18227 1.22046 1.24182 1.25905 1.27023
1.20165 1.21108 1.25208 1.27826 1.29944 1.30683
1.24163 1.23119 1.27154 1.31085 1.32602 1.34906
1.26658 1.25802 1.29801 1.33667 1.36192 1.38469
1.29076 1.28117 1.32457 1.35789 1.39391 1.41224
1.29915 1.29855 1.343 1.38634 1.41698 1.44162
]
cds = [
0.0654349 0.0296189 0.0228493 0.0190337 0.0179236 0.0159423
0.0553959 0.0277749 0.0208117 0.018136 0.015916 0.0148696
0.0459334 0.023951 0.0193385 0.0172538 0.0150951 0.0137197
0.0385589 0.0226159 0.018273 0.0154623 0.0143091 0.0129814
0.0338295 0.0210759 0.0172401 0.0144747 0.0130531 0.0123372
0.0296124 0.0200311 0.0153633 0.0136195 0.0121329 0.0112241
0.0263312 0.0176739 0.0143444 0.0125092 0.0114031 0.0105385
0.0242647 0.0165613 0.0135285 0.0116141 0.0106384 0.00998252
0.0225039 0.0151111 0.0123357 0.0108986 0.00996728 0.00937767
0.0204981 0.0141967 0.0114408 0.0101346 0.00934501 0.00887346
0.0190007 0.0131301 0.0106836 0.00952052 0.0087898 0.00836871
0.0179213 0.0122845 0.0100597 0.00899888 0.00840774 0.00796738
0.0168996 0.0114676 0.00949084 0.00858268 0.00803717 0.00766273
0.0161244 0.0107389 0.00892733 0.00811376 0.00766265 0.00735471
0.0152867 0.0100302 0.00841999 0.00771093 0.00730886 0.00704231
0.0143646 0.00934181 0.00795968 0.00736196 0.00699525 0.00677437
0.0135524 0.00865968 0.00750625 0.00701264 0.00672623 0.0065265
0.0130552 0.0081212 0.00706139 0.00664781 0.00643271 0.00628345
0.0129214 0.00770648 0.00674272 0.00634507 0.00613936 0.00601957
0.0126324 0.00750968 0.00649519 0.00611761 0.00591863 0.00580701
0.0121033 0.00757967 0.00633231 0.00595413 0.00578714 0.00567214
0.0117236 0.00775288 0.00641919 0.00585671 0.00561447 0.00554661
0.0115409 0.00794312 0.00665121 0.00599588 0.00563508 0.00546568
0.01155 0.00811528 0.00692937 0.00625737 0.00583928 0.00558312
0.0116789 0.00830769 0.00722311 0.00656245 0.00610511 0.00579274
0.0119019 0.00855542 0.0074681 0.0068753 0.0064166 0.00607888
0.0121988 0.00884388 0.00774843 0.00713832 0.00673198 0.00638581
0.012564 0.00918564 0.00806183 0.00740902 0.00702941 0.00674493
0.0129882 0.00956289 0.00837725 0.00775605 0.00736807 0.00708523
0.0134068 0.00996367 0.00879841 0.00816252 0.00775411 0.00750858
0.0138772 0.0104175 0.00923359 0.0086287 0.00829339 0.00805655
0.0144083 0.0109608 0.00982798 0.00927505 0.00894606 0.00870128
0.0149293 0.0116238 0.0105898 0.0100486 0.00969578 0.0094194
0.0156143 0.0125228 0.0115174 0.0109321 0.0105371 0.0102365
0.0165971 0.0136909 0.0126092 0.011985 0.0115137 0.0111661
0.0182657 0.0151833 0.0138636 0.0130141 0.0124229 0.0119165
0.0206356 0.0167678 0.0151394 0.0140169 0.0132418 0.0127244
0.022962 0.0182899 0.016323 0.0149031 0.0141601 0.013441
0.0253224 0.0197913 0.0172989 0.0159966 0.0148978 0.0143806
0.0274142 0.021502 0.0187484 0.0168503 0.0160522 0.0150538
0.0303662 0.0231384 0.0199176 0.0181825 0.0167942 0.0158637
0.0327772 0.024691 0.0210983 0.0192633 0.0177298 0.0171334
0.0366253 0.0273164 0.023116 0.0203368 0.0192977 0.0178622
0.0395347 0.0291617 0.0247909 0.021866 0.0201695 0.0187629
0.0425926 0.0312784 0.026501 0.023791 0.0213097 0.020106
0.0479709 0.0343795 0.0289269 0.0253349 0.0230689 0.0213966
]

#generate cl to cd function (this is generating the template funciton provided)
cl_2_cd = VortexLattice.generate_cl_2_cd(cls,cds,res)

#select operating reynolds number and set freestream
re = 1000000
Vinf = re*mu/(c[1][1]*rho)
ref = Reference(Sref, cref, bref, rref, Vinf)

#calculate the width of each panel (this works only for uniform spacing)
w = (yle[2] - yle[1])/ns

#initialization for alpha sweep
alphas = -10:.5:20 #discrete angles of attack
viscous = zeros(n_alphas) #Cd_total for each value of alpha
inviscid = zeros(n_alphas) #Cd_induced for each value of alpha
local_viscous = zeros(3,ns,n_alphas) #cfs_local_total for each spanwise location
local_inviscid = zeros(3,ns,n_alphas) #cfs_local_induced for each spanwise location
n_alphas = length(cls[:,1]) #number of discrete angles of attack


#sweep of angle of attack
for j in 1:n_alphas
local_freestream = Freestream(Vinf, alphas[j]*pi/180, beta, Omega);
system_local = steady_analysis!(system, surfaces, ref, local_freestream; symmetric);
cfs, cms = lifting_line_coefficients(system_local, r, c; frame=Wind());
local_inviscid[:,:,j] = cfs[1]
inviscid[j] = body_forces(system_local; frame=Wind())[1][1]
local_viscous[:,:,j] = VortexLattice.strip_theory_drag!(cfs, cms, system_local, r, c, cl_2_cd, re)[1]
viscous[j] = sum((local_viscous[1,:,j]) .*c_local)*w*2/Sref
end

```

We can see that the results match those from Xflr5 identically.

![](strip-theory-verification.png)

## Sudden Acceleration of a Rectangular Wing into a Constant-Speed Forward Flight

This example shows how to predict the transient forces and moments on a rectangular wing when suddenly accelerated into forward flight at a five degree angle.
Expand Down
Binary file added docs/src/strip-theory-verification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/VortexLattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module VortexLattice
using LinearAlgebra
using StaticArrays
using Interpolations
using FLOWMath
using WriteVTK

# value for dimensionalizing, included just for clarity in the algorithms
Expand Down
118 changes: 118 additions & 0 deletions src/nearfield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,124 @@ function lifting_line_coefficients!(cf, cm, system, r, c; frame=Body())
return cf, cm
end

"""
Convenience function for strip_theory_drag!()
"""
function strip_theory_drag(cf, afs, Res)
@assert system.near_field_analysis[] "Near field analysis required"
TF = promote_type(eltype(system), eltype(eltype(r)), eltype(eltype(c)))
nsurf = length(system.surfaces)
cf = Vector{Matrix{TF}}(undef, nsurf)
cm = Vector{Matrix{TF}}(undef, nsurf)
return strip_theory_drag!(cf, afs, Res)
end

"""
strip_theory_drag!(cf, cm, system, r, c, cl_to_cd)

Return the updated force coefficients per unit span for each spanwise segment using
strip theory to account for viscous affects

This function requires that a near-field analysis has been performed on `system`
to obtain panel forces.

# Arguments
- `cf`: Vector with length equal to the number of surfaces, with each element
being a matrix with size (3, ns) which contains the x, y, and z components of
force coefficients (per unit span) for each spanwise segment.
- `cm`: Vector with length equal to the number of surfaces, with each element
being a matrix with size (3, ns) which contains the x, y, and z components of
moment coefficients (per unit span) for each spanwise segment.
- `r`: Vector with length equal to the number of surfaces, with each element
being a matrix with size (3, ns+1) which contains the x, y, and z coordinates
of the resulting lifting line coordinates
- `c`: Vector with length equal to the number of surfaces, with each element
being a vector of length `ns+1` which contains the chord lengths at each
lifting line coordinate.
- `cl_2_cd`: A function accepting lift coefficient and reynolds number, and returning
viscous drag coefficent.

# Return Arguments:
- `cf`: Vector with length equal to the number of surfaces, with each element
being a matrix with size (3, ns) which contains the x, y, and z direction
force coefficients (per unit span) in the wind frame for each spanwise segment.
The x element of these matrices includes a viscous drag correction.
"""
function strip_theory_drag!(cf, Res) # TODO: attach airfoils to surface
# iterate over each surface
nsurf = length(cf)
CDv = 0.0
CM = 0.0

for i = 1:nsurf
# extract for this surface
forces = cf[i]
af1 = surface. # TODO
af2 = surface.
Re = Res[i]
y = surface. # TODO

# broadcast across each airfoil, cl, Re
viscous = cl_2_cd.(Ref(af1), Ref(af2), forces[3, :], Re, y)
cd = getindex.(viscous, 1)
cm = getindex.(viscous, 1)

forces[1, :] .+= cd
forces[2, :] .+= cm

multiplier = symmetric[i] ? 2.0 : 1.0
CDv += multiplier * cd * c * panel_width / ref.S
# TODO: add cm
end

return cf, CDv
end

struct AirfoilData{TM, TV, TI}
cl::TM
cd::TM
cm::TM
Re::TV
clcache::TV
cdcache::TV
cmcache::TV
nalpha::TI
end

function AirfoilData(cl, cd, cm, Re)
nalpha = length(cl[:, 1])
clcache = zeros(nalpha)
cdcache = zeros(nalpha)
cmcache = zeros(nalpha)

return AirfoilData(cl, cd, cm, Re, clcache, cdcache, cmcache, nalpha)
end


function cl_2_cd(af1, af2, cl, Re, eta)

cd1, cm1 = cl_2_cd(af1, cl, Re)
cd2, cm2 = cl_2_cd(af2, cl, Re)
cd = cd1 + eta*(cd2 - cd1)
cm = cm1 + eta*(cm2 - cm1)

return cd, cm
end

function cl_2_cd(af, cl, Re)

for i in 1:af.nalpha
af.clcache[i] = linear(af.Res, view(af.cl, i, :), Re)
af.cdcache[i] = linear(af.Res, view(af.cd, i, :), Re)
af.cmcache[i] = linear(af.Res, view(af.cm, i, :), Re)
end
cd = linear(af.clcache, af.cdcache, cl)
cm = linear(af.clcache, af.cmcache, cl)

return cd, cm
end


"""
body_to_frame(CF, CM, reference, freestream, frame)

Expand Down