Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding files to solve error switching branches
- Loading branch information
Showing
5 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
from numpy import exp, log10, vstack | ||
from numpy import arccos,arange | ||
from gpfit.fit import fit | ||
from numpy.random import random_sample | ||
i = arange(0.0001,1,.001) | ||
j = arccos(exp(-i)) | ||
|
||
x = log(i) | ||
y = log(j) | ||
K = 1 | ||
|
||
cstrt, rmsErr = fit(x,y,K,"SMA") | ||
print rmsErr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lb1,lb0,ub0,d,e11,e10,K,e21,e20,e00,e01,a1,ftype,max_err,c2,c1,c0,rms_err,ub1 | ||
50000.00000000001,0.4742,1.4495,2,-0.8108155563264187,6.320590230366453,3,-2.8766519103828543,42.173818269878126,-0.7631609541518628,-5.0062373433526455,6.153287557875197,SMA,0.32163665175749223,2.655008812201457,8.068321204642572e-09,309019700605405.5,0.09733995717389085,700000.0000000002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
126
gpkitmodels/GP/aircraft/prop/dae51polars/dae_polarfits.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
"jho1_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 Actuator_Propeller | ||
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(Actuator_Propeller)) | ||
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") |