Пример #1
0
def season(lats, days=[80, 52, 21, 355]):
    " trade seasonal availibility with weight "
    V = Aircraft(sp=False)
    data = {}
    for l in lats:
        failed = False
        mtows = []
        for d in days:
            if failed:
                mtows = mtows + [np.nan] * (4 - len(mtows))
                break
            M = Mission(V, latitude=range(1, l + 1, 1), day=d)
            M.cost = M[M.aircraft.Wtotal]
            try:
                sol = M.solve()
                mtow = sol(M.aircraft.Wtotal).magnitude
                mtows.append(mtow)
            except RuntimeWarning:
                mtows.append(np.nan)
                failed = True

        mtows = np.hstack(mtows)
        data[l] = mtows

    df = pd.DataFrame(data)
    return df
Пример #2
0
def build_solar(lat=15, day=140, sp=True):
    " try different battery specific energies "
    M = Mission(latitude=lat, day=day, sp=sp)
    M.cost = M["W_{total}"]
    M.substitutions.update({"W_{pay}": 0})
    for vk in M.varkeys["P_{avn}"]:
        M.substitutions.update({vk: 50})

    for h in [150, 200, 260]:
        M.substitutions.update({"h_{batt}": h})
        try:
            sol = M.localsolve("mosek", verbosity=2) if sp else M.solve("mosek")
            print sol.table(["W_{total}", "b_Mission/Aircraft/Wing", "S",
                             "W_Mission/Aircraft/Wing",
                             "W_Mission/Aircraft/Battery",
                             "P_{oper}"])
        except RuntimeWarning:
            print "Not feasible"

    return M
Пример #3
0
    ax.legend(["Positive", "Negative"])
    ax.set_ylabel("sensitivities")
    return fig, ax


if __name__ == "__main__":
    sols = []
    Ms = []
    for l in [25, 29]:
        for p in [85, 90]:
            M = Mission(latitude=l)
            M.cost = M["W_{total}"]
            Ms.append(M)
            for vk in M.varkeys["p_{wind}"]:
                M.substitutions.update({vk: p/100.0})
            sol = M.solve("mosek")
            sols.append(sol)

    varns = ["p_{wind}", "\\eta_Mission/Aircraft/SolarCells",
             "\\eta_{charge}", "\\eta_{discharge}", "\\rho_{solar}",
             "t_{night}", "(E/S)_{irr}", "h_{batt}", "W_{pay}",
             "\\eta_{prop}"]
    latns = ["$p_{\\mathrm{wind}}$", "$\\eta_{\\mathrm{solar}}$",
             "$\\eta_{\\mathrm{charge}}$", "$\\eta_{\\mathrm{discharge}}$",
             "$\\rho_{\\mathrm{solar}}$",
             "$t_{\\mathrm{night}}$", "$(E/S)_{\\mathrm{irr}}$",
             "$h_{\\mathrm{batt}}$", "$W_{\\mathrm{pay}}$",
             "$\\eta_{\\mathrm{prop}}$"]

    fig, ax = plot_sens(M, sols[3], varns)
    varnsw = ["e", "t_{min}_Mission/Aircraft/Wing/WingSkin", "\\rho_{CFRP}",
Пример #4
0
from solar import Aircraft, Mission
from gpkitmodels.GP.aircraft.fuselage.elliptical_fuselage import Fuselage

Aircraft.fuseModel = Fuselage
m = Mission(latitude=[20])
sol = m.solve()
Пример #5
0
def plot_contours(path=None):
    N = 100
    stime = 0.0
    numsolves = 0
    plt.rcParams.update({'font.size': 19})
    hmin = 250.0
    hmax = 400.0
    for av in [80, 85, 90]:
        for lat in [25, 30, 35]:
            zo = 10
            if lat == 25:
                bs = range(30, 80, 5)
            elif lat == 30:
                bs = range(35, 80, 5)
                if av == 90:
                    del bs[0]
            else:
                bs = range(45, 80, 5)
                if av == 90:
                    del bs[0]
            fig, ax = plt.subplots()
            M = Mission(latitude=lat)
            M.substitutions.update({"W_{pay}": 10})
            for vk in M.varkeys["\\eta_{prop}"]:
                M.substitutions.update({vk: 0.75})
            for vk in M.varkeys["p_{wind}"]:
                M.substitutions.update({vk: av / 100.0})
            del M.substitutions["\\eta_Mission/Aircraft/SolarCells"]
            del M.substitutions["h_{batt}"]
            M.cost = M["h_{batt}"]
            lines = []
            midx = []
            for b in bs:
                etamax = 0.4
                etamin = 0.15
                M.substitutions.update({"b_Mission/Aircraft/Wing": b})
                M.substitutions.update(
                    {"\\eta_Mission/Aircraft/SolarCells": etamax})
                sol = M.solve("mosek")
                stime += sol["soltime"]
                numsolves += 1
                del M.substitutions["\\eta_Mission/Aircraft/SolarCells"]
                if sol("h_{batt}").magnitude < hmin:
                    M.substitutions.update({"h_{batt}": hmin})
                    M.cost = M["\\eta_Mission/Aircraft/SolarCells"]
                    sol = M.solve("mosek")
                    stime += sol["soltime"]
                    numsolves += sol["soltime"]
                    etamax = sol("\\eta_Mission/Aircraft/SolarCells")

                M.substitutions.update({"h_{batt}": hmax})
                M.cost = M["\\eta_Mission/Aircraft/SolarCells"]
                sol = M.solve("mosek")
                stime += sol["soltime"]
                numsolves += 1
                etamin = sol("\\eta_Mission/Aircraft/SolarCells")

                if etamin > etamax:
                    continue

                del M.substitutions["h_{batt}"]
                M.cost = M["h_{batt}"]
                xmin_ = np.linspace(etamin, etamax, 100)
                tol = 0.01
                bst = autosweep_1d(M,
                                   tol,
                                   M["\\eta_Mission/Aircraft/SolarCells"],
                                   [etamin, etamax],
                                   solver="mosek")
                bsts = find_sols([bst])
                sols = np.hstack([bs.sols for bs in bsts])
                stime += sum(np.unique([s["soltime"] for s in sols]))
                numsolves += bst.nsols

                if b % 10 == 0:
                    l = ax.plot(xmin_,
                                bst.sample_at(xmin_)["cost"],
                                "k",
                                label="%d [ft]" % b,
                                zorder=zo)
                    zo += 2
                    lines.append(l[0])
                    midx.append(np.median(xmin_))
                else:
                    ax.plot(xmin_,
                            bst.sample_at(xmin_)["cost"],
                            "--",
                            c="0.5",
                            zorder=100)

            # parato fontier
            del M.substitutions["b_Mission/Aircraft/Wing"]
            M.substitutions.update(
                {"\\eta_Mission/Aircraft/SolarCells": etamax})
            M.cost = M["h_{batt}"]
            sol = M.solve("mosek")
            etamax = 0.4
            stime += sol["soltime"]
            numsolves += 1
            del M.substitutions["\\eta_Mission/Aircraft/SolarCells"]
            if sol("h_{batt}").magnitude < hmin:
                M.substitutions.update({"h_{batt}": hmin})
                M.cost = M["\\eta_Mission/Aircraft/SolarCells"]
                sol = M.solve("mosek")
                stime += sol["soltime"]
                numsolves += sol["soltime"]
                etamax = sol("\\eta_Mission/Aircraft/SolarCells")

            M.substitutions.update({"h_{batt}": hmax})
            M.cost = M["\\eta_Mission/Aircraft/SolarCells"]
            sol = M.solve("mosek")
            stime += sol["soltime"]
            numsolves += 1
            etamin = sol("\\eta_Mission/Aircraft/SolarCells")

            if etamin > etamax:
                break
            del M.substitutions["h_{batt}"]
            M.cost = M["h_{batt}"]
            xmin_ = np.linspace(etamin, etamax, 100)
            tol = 0.01
            bst = autosweep_1d(M,
                               tol,
                               M["\\eta_Mission/Aircraft/SolarCells"],
                               [etamin, etamax],
                               solver="mosek")
            bsts = find_sols([bst])
            sols = np.hstack([b.sols for b in bsts])
            stime += sum(np.unique([s["soltime"] for s in sols]))
            numsolves += bst.nsols

            ax.set_xlabel("Solar Cell Efficiency")
            ax.set_ylabel("Battery Specific Energy [Whr/kg]")
            labelLines(lines[:-1],
                       align=True,
                       xvals=midx,
                       zorder=[11, 13, 15, 17])
            ax.fill_between(np.hstack([0.15, xmin_]),
                            0,
                            np.hstack([hmax,
                                       bst.sample_at(xmin_)["cost"]]),
                            edgecolor="r",
                            lw=2,
                            hatch="/",
                            facecolor="None",
                            zorder=100)
            ax.text(0.17, 260, "Infeasible", fontsize=19)
            ax.set_xlim([0.15, 0.4])
            ax.set_ylim([250, 400])
            if path:
                fig.savefig(path + "bcontourl%da%d.pdf" % (lat, av),
                            bbox_inches="tight")
            else:
                fig.savefig("bcontourl%da%d.pdf" % (lat, av))

    print "%d solves in %.4f seconds" % (numsolves, stime)
Пример #6
0
def plot_battsolarcon():
    fig, ax = plt.subplots()
    time = 0
    numsolves = 0
    etamax = []
    lines = []
    midx = []
    passing = True
    for lat in range(20, 44, 1):
        if passing:
            hmax = 500
            M = Mission(latitude=lat)
            M.substitutions.update({"W_{pay}": 10})
            for vk in M.varkeys["\\eta_{prop}"]:
                M.substitutions.update({vk: 0.75})
            for vk in M.varkeys["p_{wind}"]:
                M.substitutions.update({vk: 90 / 100.0})
            del M.substitutions["h_{batt}"]
            M.substitutions.update({"\\eta_Mission/Aircraft/SolarCells": 0.4})
            M.cost = M["h_{batt}"]
            sol = M.solve("mosek")
            time += sol["soltime"]
            numsolves += 1
            hmin = sol["cost"].magnitude + 1e-3
            if hmin >= hmax:
                break
            del M.substitutions["\\eta_Mission/Aircraft/SolarCells"]
            M.cost = M["\\eta_Mission/Aircraft/SolarCells"]
            xmin_ = np.linspace(hmin, hmax, 100)
            tol = 0.01
            notpassing = True
            try:
                bst = autosweep_1d(M,
                                   tol,
                                   M["h_{batt}"], [hmin, hmax],
                                   solver="mosek")
                bsts = find_sols([bst])
                sols = np.hstack([b.sols for b in bsts])
                time += sum(np.unique([s["soltime"] for s in sols]))
                numsolves += bst.nsols
                if lat % 4 == 0:
                    l = ax.plot(xmin_,
                                bst.sample_at(xmin_)["cost"],
                                "k",
                                label="%d$^{\\circ}$ Lat" % lat)
                    lines.append(l[0])
                    etamax.append(max(bst.sample_at(xmin_)["cost"].magnitude))
                    midx.append(np.median(xmin_))
                elif lat % 2 == 0:
                    l = ax.plot(xmin_,
                                bst.sample_at(xmin_)["cost"],
                                "--",
                                c="0.5",
                                label="%d$^{\\circ}$ Lat" % lat)
            except RuntimeWarning:
                passing = False

    # ax.fill_between(xmin_, bst.sample_at(xmin_)["cost"], max(etamax),
    #                 edgecolor="r", lw=2, hatch="/", facecolor="None", zorder=100)
    print "%d solves in %.4f seconds" % (numsolves, time)
    labelLines(lines, align=False, xvals=midx, zorder=[10] * len(lines))
    # ax.text(425, 0.36, "Infeasible")
    ax.set_ylabel("Solar Cell Efficiency")
    ax.set_xlabel("Battery Specific Energy [Whr/kg]")
    ax.set_xlim([250, 500])
    ax.set_ylim([0.1, max(etamax)])
    ax.grid()
    return fig, ax