Skip to content

Commit

Permalink
Added polar creation files
Browse files Browse the repository at this point in the history
  • Loading branch information
courtin committed Apr 23, 2018
1 parent a8d127c commit 6345b01
Show file tree
Hide file tree
Showing 7 changed files with 2,122 additions and 1,389 deletions.
4 changes: 1 addition & 3 deletions gpkitmodels/GP/aircraft/prop/arccos_fit.py
Expand Up @@ -5,11 +5,9 @@
from numpy.random import random_sample
i = arange(0.0001,3,.001)
j = arccos(exp(-i))
#P = Vdd**2 + 30*Vdd*exp(-(Vth-0.06*Vdd)/0.039)
#u = vstack((Vdd,Vth))
x = log(i)
y = log(j)
K = 8
K = 1

cstrt, rmsErr = fit(x,y,K,"SMA")
print rmsErr
1,388 changes: 2 additions & 1,386 deletions gpkitmodels/GP/aircraft/prop/dae51_fitdata.csv

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions gpkitmodels/GP/aircraft/prop/dae51polars/dae51.dat
@@ -0,0 +1,83 @@
DAE 51
# Daedalus propeller airfoil
1.000000 -0.000051
0.989166 0.001996
0.975819 0.004501
0.957448 0.007991
0.931599 0.013004
0.901654 0.018957
0.870818 0.025167
0.839998 0.031363
0.809336 0.037430
0.778839 0.043301
0.748503 0.048933
0.718326 0.054243
0.688314 0.059175
0.658443 0.063716
0.628653 0.067839
0.598855 0.071530
0.569004 0.074792
0.539074 0.077652
0.509071 0.080095
0.479015 0.082100
0.448934 0.083641
0.418877 0.084690
0.388863 0.085217
0.358908 0.085197
0.329049 0.084600
0.299321 0.083399
0.269760 0.081570
0.240419 0.079081
0.211388 0.075895
0.182766 0.071967
0.154699 0.067243
0.127404 0.061670
0.101193 0.055204
0.076503 0.047832
0.054060 0.039675
0.034881 0.031085
0.020059 0.022737
0.010052 0.015405
0.004208 0.009557
0.001251 0.005050
0.000113 0.001479
0.000123 -0.001494
0.001002 -0.004085
0.002793 -0.006422
0.006019 -0.008524
0.011960 -0.010609
0.022698 -0.012727
0.040333 -0.014554
0.064233 -0.015717
0.091882 -0.016173
0.121305 -0.016067
0.151560 -0.015570
0.182231 -0.014790
0.213149 -0.013797
0.244240 -0.012649
0.275464 -0.011392
0.306798 -0.010061
0.338230 -0.008690
0.369725 -0.007318
0.401184 -0.005962
0.432597 -0.004640
0.463976 -0.003366
0.495325 -0.002147
0.526644 -0.000994
0.557930 0.000082
0.589182 0.001071
0.620390 0.001960
0.651547 0.002731
0.682648 0.003367
0.713694 0.003847
0.744690 0.004152
0.775644 0.004269
0.806546 0.004190
0.837373 0.003898
0.868134 0.003359
0.898985 0.002532
0.929868 0.001410
0.956572 0.000219
0.975393 -0.000742
0.988983 -0.001472
1.000000 -0.002051
81 changes: 81 additions & 0 deletions gpkitmodels/GP/aircraft/prop/dae51polars/dae51.txt
@@ -0,0 +1,81 @@
1.000000 -0.000051
0.989166 0.001996
0.975819 0.004501
0.957448 0.007991
0.931599 0.013004
0.901654 0.018957
0.870818 0.025167
0.839998 0.031363
0.809336 0.037430
0.778839 0.043301
0.748503 0.048933
0.718326 0.054243
0.688314 0.059175
0.658443 0.063716
0.628653 0.067839
0.598855 0.071530
0.569004 0.074792
0.539074 0.077652
0.509071 0.080095
0.479015 0.082100
0.448934 0.083641
0.418877 0.084690
0.388863 0.085217
0.358908 0.085197
0.329049 0.084600
0.299321 0.083399
0.269760 0.081570
0.240419 0.079081
0.211388 0.075895
0.182766 0.071967
0.154699 0.067243
0.127404 0.061670
0.101193 0.055204
0.076503 0.047832
0.054060 0.039675
0.034881 0.031085
0.020059 0.022737
0.010052 0.015405
0.004208 0.009557
0.001251 0.005050
0.000113 0.001479
0.000123 -0.001494
0.001002 -0.004085
0.002793 -0.006422
0.006019 -0.008524
0.011960 -0.010609
0.022698 -0.012727
0.040333 -0.014554
0.064233 -0.015717
0.091882 -0.016173
0.121305 -0.016067
0.151560 -0.015570
0.182231 -0.014790
0.213149 -0.013797
0.244240 -0.012649
0.275464 -0.011392
0.306798 -0.010061
0.338230 -0.008690
0.369725 -0.007318
0.401184 -0.005962
0.432597 -0.004640
0.463976 -0.003366
0.495325 -0.002147
0.526644 -0.000994
0.557930 0.000082
0.589182 0.001071
0.620390 0.001960
0.651547 0.002731
0.682648 0.003367
0.713694 0.003847
0.744690 0.004152
0.775644 0.004269
0.806546 0.004190
0.837373 0.003898
0.868134 0.003359
0.898985 0.002532
0.929868 0.001410
0.956572 0.000219
0.975393 -0.000742
0.988983 -0.001472
1.000000 -0.002051
126 changes: 126 additions & 0 deletions gpkitmodels/GP/aircraft/prop/dae51polars/dae51_polarfits.py
@@ -0,0 +1,126 @@
"dae51_polarfits.py"
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from gpfit.fit import fit
import sys
from gpkitmodels.GP.aircraft.wing.wing import Wing
from gpkitmodels.GP.aircraft.prop.propeller import ActuatorProp
import inspect
import os

GENERATE = True
plt.rcParams.update({'font.size':15})

def text_to_df(filename):
"parse XFOIL polars and concatente data in DataFrame"
lines = list(open(filename))
for i, l in enumerate(lines):
lines[i] = l.split("\n")[0]
for j in 10-np.arange(9):
if " "*j in lines[i]:
lines[i] = lines[i].replace(" "*j, " ")
if "---" in lines[i]:
start = i
data = {}
titles = lines[start-1].split(" ")[1:]
for t in titles:
data[t] = []

for l in lines[start+1:]:
for i, v in enumerate(l.split(" ")[1:]):
data[titles[i]].append(v)

df = pd.DataFrame(data)
return df

def fit_setup(Re_range):
"set up x and y parameters for gp fitting"
CL = []
CD = []
RE = []
fig, ax = plt.subplots()
for r in Re_range:
dataf = text_to_df("dae51.ncrit09.Re%dk.pol" % r)
if r < 150:
cl = dataf["CL"].values.astype(np.float)
cd = dataf["CD"].values.astype(np.float)
CL.append(np.hstack([cl[cl >= 1.0]]*1))
CD.append(np.hstack([cd[cl >= 1.0]]*1))
elif r < 200:
cl = dataf["CL"].values.astype(np.float)
cd = dataf["CD"].values.astype(np.float)
CL.append(cl[cl >= 0.9])
CD.append(cd[cl >= 0.9])
else:
CL.append(dataf["CL"].values.astype(np.float))
CD.append(dataf["CD"].values.astype(np.float))
ax.plot(dataf["CL"].values.astype(np.float), dataf["CD"].values.astype(np.float))
ax.legend(["%d" % re for re in Re_range])
RE.append([r*1000.0]*len(CL[-1]))

fig.savefig("polarstest.pdf")

u1 = np.hstack(CL)
u2 = np.hstack(RE)
w = np.hstack(CD)
u = [u1, u2]
xx = np.log(u2)
x = np.log(u)
y = np.log(w)
return x, y

def return_fit(cl, re):
"polar fit for the dae51 airfoil"
cd = (3.0902e14*cl**-.763161*re**-5.00624
+ 8.06832e-09*cl**6.32059*re**-0.810816
+ 2.65501*cl**42.1738*re**-2.87665 )**(1/6.1539)
# SMA function, K=3, max RMS error = 0.09734
return cd

def plot_fits(re, cnstr, x, y):
"plot fit compared to data"
# colors = ["k", "m", "b", "g", "y"]
colors = ["#084081", "#0868ac", "#2b8cbe", "#4eb3d3", "#7bccc4"]
assert len(re) == len(colors)
lre, ind = np.unique(X[1], return_index=True)
xre = np.exp(lre)
xcl = [np.exp(X[0][ind[i-1]:ind[i]]) for i in range(1, len(ind))]
cds = [np.exp(Y[ind[i-1]:ind[i]]) for i in range(1, len(ind))]
yfit = cnstr.evaluate(x)
cdf = [np.exp(yfit[ind[i-1]:ind[i]]) for i in range(1, len(ind))]
fig, ax = plt.subplots()
i = 0
for r, cl, cd, fi in zip(xre, xcl, cds, cdf):
roundre = int(np.round(r)/1000)
if roundre in re:
ax.plot(cl, cd, "o", mec=colors[i], mfc="none", mew=1.5)
ax.plot(cl, fi, c=colors[i], label="Re = %dk" % roundre, lw=2)
i += 1
ax.set_xlabel("$C_L$")
ax.set_ylabel("$c_{d_p}$")
ax.legend(loc=2)
ax.grid()
return fig, ax

if __name__ == "__main__":
Re = np.array([50, 75, 125, 150, 200, 300, 400, 500, 600, 700])
X, Y = fit_setup(Re) # call fit(X, Y, 4, "SMA") to get fit
np.random.seed(0)
cn, err = fit(X, Y, 3, "SMA")
print "RMS error: %.5f" % err
df = cn.get_dataframe()
if GENERATE:
path = os.path.dirname(inspect.getfile(ActuatorProp))
df.to_csv(path + os.sep + "dae51_fitdata.csv", index=False)
else:
df.to_csv("dae51fitdata.csv", index=False)

# replot = np.array([150, 200, 300, 350, 400])
replot = np.array([300, 350, 400, 450, 500])
F, A = plot_fits(replot, cn, X, Y)
if len(sys.argv) > 1:
path = sys.argv[1]
F.savefig(path + "dae51polarfit1.eps", bbox_inches="tight")
else:
F.savefig("dae51polarfit1.eps", bbox_inches="tight")

0 comments on commit 6345b01

Please sign in to comment.