Skip to content

Commit

Permalink
plot payload contours
Browse files Browse the repository at this point in the history
  • Loading branch information
mjburton committed Apr 30, 2018
1 parent cae6cc3 commit 2a07136
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 5 deletions.
108 changes: 108 additions & 0 deletions solar/payloadcon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
" contour plots "
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sys
from solar import Mission, Aircraft
from plotting import labelLines
from gpkit.tools.autosweep import autosweep_1d

N = 100
plt.rcParams.update({'font.size':15})

def payloadcon(latitudes):
time = 0
numsolves = 0
etamax = []
lines = []
midx = []
data = {}
passing = True
wmin = 0.01
pmin = 0.01
for lat in latitudes:
if passing:
V = Aircraft(sp=True)
M = Mission(V, latitude=[lat])
del M.substitutions["Wpay"]
M.substitutions.update({"Ppay": pmin})
M.cost = 1./M["Wpay"]
try:
sol = M.localsolve("mosek")
except RuntimeWarning:
break
time += sol["soltime"]
numsolves += 1
wmax = sol("Wpay").magnitude - 1e-3
if wmin >= wmax:
break
del M.substitutions["Ppay"]
M.cost = 1./M["Ppay"]
wpays = np.linspace(wmin, wmax, 10)
tol = 0.01
notpassing = True
ppays = []
for w in wpays:
M.substitutions["Wpay"] = w
try:
sol = M.localsolve("mosek")
time += sol["soltime"]
numsolves += 1
ppays.append(sol("Ppay").magnitude)
except RuntimeWarning:
ppays.append(np.NaN)
data["%d-W" % lat] = wpays
data["%d-P" % lat] = ppays

df = pd.DataFrame(data)
return df

def plot_payloadcon(df, lats):

lats = np.array(lats)
maxlat = int(df.columns[-1][0:2])
lats = lats[lats <= 30]
fig, ax = plt.subplots()
lines = []
midx = []
maxps = []
for la in lats:
wpays, ppays= df["%d-W" % la], df["%d-P" % la]
maxps.append(max(ppays))
if la % 4 == 0:
l = ax.plot(wpays, ppays, "k", label="%d$^{\\circ}$ Lat" % la)
if la is not 20:
lines.append(l[0])
midx.append(np.median(wpays))
elif la % 2 == 0:
l = ax.plot(wpays, ppays, "--", c="0.5", label="%d$^{\\circ}$ Lat" % la)

labelLines(lines, align=False, xvals=midx, zorder=[10]*len(lines))
ax.set_ylabel("Payload Power [W]")
ax.set_xlabel("Payload Weight [lbf]")
ax.set_xlim([0, 500])
ax.set_ylim([0, max(maxps)])
ax.grid()
return fig, ax

def test():
_, _ = plot_battsolarcon()

if __name__ == "__main__":
if len(sys.argv) > 1:
path = sys.argv[1]
GENERATE = True if sys.argv[2] == "GEN" else False
else:
path = ""
GENERATE = False

Lats = range(16, 30, 2)
if GENERATE:
DF = payloadcon(Lats)
DF.to_csv("payloadcon.generated.csv")
else:
DF = pd.read_csv("payloadcon.generated.csv")
del DF["Unnamed: 0"]

fig, ax = plot_payloadcon(DF, Lats)
fig.savefig(path + "paycon.pdf", bbox_inches="tight")
8 changes: 5 additions & 3 deletions solar/sens_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def get_highestsens(model, res, varnames=None, N=10):
for vname in varnames:
sen = res["sensitivities"]["constants"][vname]
if hasattr(sen, "__len__"):
print vname
print sen
val = max(np.abs(sen.values()))
vk = [svk for svk in sen if abs(sen[svk]) == val][0]
sen = sum(sen.values())
Expand Down Expand Up @@ -118,9 +120,9 @@ def test():
M.aircraft.battery.etadischarge: "$\\eta_{\\mathrm{discharge}}$",
M.aircraft.battery.hbatt: "$h_{\\mathrm{batt}}$",
M.aircraft.solarcells.etasolar: "$\\eta_{\\mathrm{solar}}$",
"Nmax": "$N_{\\mathrm{max}}$",
"e": "$e$", "etaprop": "$\\eta_{\\mathrm{prop}}$"}
M.mission[1].winggust.Nmax: "$N_{\\mathrm{load}}$",
M.mission[1].aircraftPerf.drag.wing.e: "$e$"}

sd = get_highestsens(M, sol, N=10)
sd = get_highestsens(M, sol, vns)
f, a = plot_chart(sd)
f.savefig(path + "sensbar.pdf", bbox_inches="tight")
5 changes: 3 additions & 2 deletions solar/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class AircraftDrag(Model):
mfac 1.05 [-] drag margin factor
Pshaft [hp] shaft power
Pavn 200 [W] avionics power draw
Ppay 100 [W] payload power draw
Poper [W] operating power
mpower 1.05 [-] power margin
T [lbf] thrust
Expand Down Expand Up @@ -119,6 +118,7 @@ def setup(self, static, state, onDesign = False):
Qmotor = self.motor.Q
RPMmotor = self.motor.omega
Pelec = self.motor.Pelec
Ppay = static.Ppay


self.wing.substitutions[e] = 0.95
Expand Down Expand Up @@ -153,6 +153,7 @@ class Aircraft(Model):
Variables
---------
Wpay 11 [lbf] payload weight
Ppay 100 [W] payload power draw
Wavn 22 [lbf] avionics weight
Wtotal [lbf] aircraft weight
Wwing [lbf] wing weight
Expand Down Expand Up @@ -678,7 +679,7 @@ def test():
post_process(s)

if __name__ == "__main__":
SP = False
SP = True
Vehicle = Aircraft(Npod=0, sp=SP)
M = Mission(Vehicle, latitude=[20])
M.cost = M[M.aircraft.Wtotal]
Expand Down

0 comments on commit 2a07136

Please sign in to comment.