Skip to content

Commit

Permalink
Merge c594718 into 6f3b1e4
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Oct 8, 2021
2 parents 6f3b1e4 + c594718 commit b8fd905
Show file tree
Hide file tree
Showing 44 changed files with 2,245 additions and 394 deletions.
5 changes: 5 additions & 0 deletions docs/source/_static/css/custom.css
@@ -0,0 +1,5 @@
@import 'theme.css';

div[class^='highlight-breakdowns'] pre {
line-height: 1.2 !important;
}
6 changes: 6 additions & 0 deletions docs/source/conf.py
Expand Up @@ -139,6 +139,12 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = [
'css/custom.css',
]

html_style = 'css/custom.css'

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
Expand Down
21 changes: 11 additions & 10 deletions docs/source/examples/beam.py
Expand Up @@ -3,8 +3,9 @@
Euler-Bernoulli beam equations for a constant distributed load
"""
import numpy as np
from gpkit import parse_variables, Model, ureg
from gpkit.small_scripts import mag
from gpkit import parse_variables, Model
# from gpkit import parse_variables, Model, ureg
# from gpkit.small_scripts import mag

eps = 2e-4 # has to be quite large for consistent cvxopt printouts;
# normally you'd set this to something more like 1e-20
Expand Down Expand Up @@ -68,14 +69,14 @@ def setup(self, N=4):

b = Beam(N=6, substitutions={"L": 6, "EI": 1.1e4, "q": 110*np.ones(6)})
sol = b.solve(verbosity=0)
print(sol.summary(maxcolumns=6))
w_gp = sol("w") # deflection along beam

L, EI, q = sol("L"), sol("EI"), sol("q")
x = np.linspace(0, mag(L), len(q))*ureg.m # position along beam
q = q[0] # assume uniform loading for the check below
w_exact = q/(24*EI) * x**2 * (x**2 - 4*L*x + 6*L**2) # analytic soln
assert max(abs(w_gp - w_exact)) <= 1.1*ureg.cm
print(sol.table(tables=["cost breakdown"], maxcolumns=6))
# w_gp = sol("w") # deflection along beam
#
# L, EI, q = sol("L"), sol("EI"), sol("q")
# x = np.linspace(0, mag(L), len(q))*ureg.m # position along beam
# q = q[0] # assume uniform loading for the check below
# w_exact = q/(24*EI) * x**2 * (x**2 - 4*L*x + 6*L**2) # analytic soln
# assert max(abs(w_gp - w_exact)) <= 1.1*ureg.cm

PLOT = False
if PLOT: # pragma: no cover
Expand Down
44 changes: 20 additions & 24 deletions docs/source/examples/beam_output.txt
@@ -1,27 +1,23 @@

Optimal Cost
------------
1.621
┃┓ ┓ ┓ ┓ ┓
┃┃ ┃ ┃ ┃ ┣╸th[2]╶⎨
┃┃ ┃ ┃ ┣╸w[2] ┛ (0.285)
┃┃ ┃ ┃ ┃ (0.384m) ┣╸th[1]╶⎨
┃┃ ┃ ┣╸w[3] ┛ ┣╸w[1]╶⎨
┃┃ ┃ ┃ (0.76m) ┣╸th[3] ┣╸th[2]╶⎨
┃┃ ┃ ┃ ┛ (0.341) ┛
┃┃ ┣╸w[4] ┃ ┣╸th[2]╶⎨
┃┃ ┃ (1.18m) ┛ ┛
Cost╺┫┃ ┃ ┣╸th[3] ┣╸th[2]╶⎨
(1.62m) ┃┣╸w[5] ┃ ┛ ┛
┃┃ (1.62m) ┃ ┓ ┓
┃┃ ┃ ┣╸th[4] ┣╸th[2]╶⎨
┃┃ ┛ ┛ (0.363) ┛
┃┃ ┓ ┓
┃┃ ┣╸th[5] ┣╸th[2]╶⎨
┃┃ ┛ (0.367) ┛
┃┃ ┓ ┓
┃┃ ┣╸th[4] ┣╸th[2]╶⎨
┃┛ ┛ ┛

Free Variables
--------------
dx : 1.2 [m] Length of an element
M : [ 1.98e+03 1.27e+03 713 317 79.2 0.0002 ] [N·m] Internal moment
V : [ 660 528 396 264 132 0.0002 ] [N] Internal shear
th : [ 0.0002 0.177 0.285 0.341 0.363 0.367 ] Slope
w : [ 0.0002 0.107 0.384 0.76 1.18 1.62 ] [m] Displacement

Most Sensitive Variables
------------------------
L : +4 Overall beam length
EI : -1 Bending stiffness
q : [ +0.0072 +0.042 +0.12 +0.23 +0.37 +0.22 ] Distributed load

Most Sensitive Constraints
--------------------------
+4 : L = 5·dx
+1 : w[5] ≥ w[4] + 0.5·dx·(th[5] + th[4])
+0.74 : th[2] ≥ th[1] + 0.5·dx·(M[2] + M[1])/EI
+0.73 : w[4] ≥ w[3] + 0.5·dx·(th[4] + th[3])
+0.64 : M[1] ≥ M[2] + 0.5·dx·(V[1] + V[2])

40 changes: 40 additions & 0 deletions docs/source/examples/breakdowns.py
@@ -0,0 +1,40 @@
"An example to show off Breakdowns"
import pickle
from gpkit.breakdowns import Breakdowns

# the code to create solar.p is in ./breakdowns/solartest.py
sol = pickle.load(open("solar.p", "rb"))
bds = Breakdowns(sol)

print("Cost breakdown (you may be familiar with this from solution tables)")
print("==============")
bds.plot("cost")

print("Variable breakdowns (note the two methods of access)")
print("===================")
varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf"
".AircraftDrag.Poper")]
bds.plot(varkey)
bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q")

print("Combining the two above by increasing maxwidth")
print("----------------------------------------------")
bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105)

print("Model sensitivity breakdowns (note the two methods of access)")
print("============================")
bds.plot("model sensitivities")
bds.plot("Aircraft")

print("Exhaustive variable breakdown traces (and configuration arguments)")
print("====================================")
# often useful as a reference point when reading traces
bds.plot("AircraftPerf.AircraftDrag.Poper", height=12)
# includes factors, can be useful for reading traces as well
bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True)
print("\nPermissivity = 2 (the default)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper")
print("\nPermissivity = 1 (stops at Pelec = v·i)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1)
6 changes: 6 additions & 0 deletions docs/source/examples/breakdowns/solartest.py
@@ -0,0 +1,6 @@
from solar.solar import *
Vehicle = Aircraft(Npod=3, sp=True)
M = Mission(Vehicle, latitude=[20])
M.cost = M[M.aircraft.Wtotal]

M.localsolve().save("solar.p")
210 changes: 210 additions & 0 deletions docs/source/examples/breakdowns_output.txt
@@ -0,0 +1,210 @@
Cost breakdown (you may be familiar with this from solution tables)
==============

┃┓ ┓ ┓ ┓
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┣╸Battery.W ┣╸Battery.E ┣╸AircraftPerf.AircraftDrag.Poper╶⎨
┃┃ ┃ (370lbf) ┃ (165,913kJ) ┃ (3,194W)
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
Cost╺┫┃ ┃ ┃ ┛
(699lbf) ┃┣╸Wtotal ┛ ┛ ┣╸SolarCells.S
┃┃ (699lbf) ┓ ┓
┃┃ ┃ ┣╸Wing.BoxSpar.W╶⎨
┃┃ ┣╸Wing.W ┛ (96.1lbf)
┃┃ ┛ (139lbf) ┣╸Wing.WingSecondStruct.W╶⎨
┃┃ ┣╸Motor.W╶⎨
┃┃ ┣╸SolarCells.W╶⎨
┃┃ ┣╸Empennage.W
┃┃ ┣╸Wavn
┃┛ ┣╸[6 terms]

Variable breakdowns (note the two methods of access)
===================

┃┓ ┓ ┓
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┣╸MotorPerf.Q╶⎨
AircraftPerf.AircraftDrag.Poper╺┫┣╸MotorPerf.Pelec ┣╸MotorPerf.i ┃ (4.8N·m)
(3,194W) ┃┃ (0.685kW) ┃ (36.8A) ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┛
┃┃ ┃ ┣╸i0
┃┛ ┛ ┛ (4.5A, fixed)
┃┣╸Pavn
┃┣╸Ppay


┃┓
AircraftPerf.AircraftDrag.MotorPerf.Q╺┫┃
(4.8N·m) ┃┣╸..ActuatorProp.CP
┃┛ (0.00291)

Combining the two above by increasing maxwidth
----------------------------------------------

┃┓ ┓ ┓ ┓
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┣╸MotorPerf.Q ┣╸ActuatorProp.CP
AircraftPerf.AircraftDrag.Poper╺┫┣╸MotorPerf.Pelec ┣╸MotorPerf.i ┃ (4.8N·m) ┃ (0.00291)
(3,194W) ┃┃ (0.685kW) ┃ (36.8A) ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃
┃┃ ┃ ┛ ┛
┃┃ ┃ ┣╸i0
┃┛ ┛ ┛ (4.5A, fixed)
┃┣╸Pavn
┃┣╸Ppay

Model sensitivity breakdowns (note the two methods of access)
============================

┃┓ ┓ ┓ ┓ ┓
┃┃ ┃ ┃ ┃ ┃
┃┃ ┃ ┃ ┃ ┣╸ActuatorProp╶⎨
┃┃ ┃ ┃ ┃ ┛
┃┃ ┃ ┣╸AircraftPerf ┣╸AircraftDrag ┣╸MotorPerf╶⎨
┃┃ ┃ ┃ ┃ ┓
┃┣╸Mission ┣╸FlightSegment ┃ ┃ ┣╸[17 terms]
┃┃ ┃ ┛ ┛ ┛
┃┃ ┃ ┣╸FlightState╶⎨
Model╺┫┃ ┃ ┣╸GustL╶⎨
┃┃ ┃ ┣╸SteadyLevelFlight╶⎨
┃┃ ┛ ┣╸[49 terms]
┃┛ ┣╸Climb╶⎨
┃┓
┃┃
┃┃
┃┣╸Aircraft╶⎨
┃┃
┃┛
┃┣╸g = 9.81m/s²


┃┓ ┣╸etadischarge = 0.98
┃┃ ┛
┃┃ ┣╸W ≥ E·minSOC/hbatt/etaRTE/etapack·g
┃┃ ┣╸etaRTE = 0.95
┃┣╸Battery ┣╸etapack = 0.85
┃┃ ┣╸hbatt = 350W·hr/kg
┃┃ ┣╸minSOC = 1.03
┃┛ ┛
┃┓
Aircraft╺┫┃
┃┣╸Wing╶⎨
┃┃
┃┛
┃┣╸Wtotal/mfac ≥ Fuselage.W[0,0] + Fuselage.W[1,0] + Fuselage.W[2,0] …
┃┛
┃┣╸mfac = 1.05
┃┛
┃┣╸Empennage╶⎨
┃┣╸[23 terms]
┃┛

Exhaustive variable breakdown traces (and configuration arguments)
====================================

┃┓ ┓ ┓
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┃
AircraftPerf.AircraftDrag.Poper╺┫┣╸MotorPerf.Pelec ┣╸MotorPerf.i ┣╸MotorPerf.Q╶⎨
(3,194W) ┃┃ (0.685kW) ┃ (36.8A) ┃ (4.8N·m)
┃┃ ┃ ┃
┃┃ ┃ ┃
┃┃ ┃ ┛
┃┛ ┛ ┣╸i0
┃┣╸Pavn


┃╤╤┯╤┯╤┯┯╤┓
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│DCBA┣╸ActuatorProp.CP
AircraftPerf.AircraftDrag.Poper╺┫╎HGFE╎││╎┃ (0.00291)
(3,194W) ┃J╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╎││╎┃
┃╎╎│╎│╧┷┷╧┛
┃╎╎│╎│┣╸i0 (4.5A, fixed)
┃╎╧┷╧┷┛
┃╎┣╸Pavn (200W, fixed)
┃╧┣╸Ppay (100W, fixed)

A 4.53e-05·FlightState.rho·ActuatorProp.omega²·Propeller.R⁵ ×1,653N·m [free factor]
B ActuatorProp.Q = 4.8N·m
C MotorPerf.Q = 4.8N·m
D Kv ×64.2rpm/V [free factor]
E MotorPerf.i = 36.8A
F MotorPerf.v ×18.6V [free factor]
G MotorPerf.Pelec = 0.685kW
H Nprop ×4, fixed
J mpower ×1.05, fixed

Permissivity = 2 (the default)
----------------

AircraftPerf.AircraftDrag.Poper (3,194W)
which in: Poper/mpower ≥ Pavn + Ppay + Pelec·Nprop (sensitivity +5.6)
{ through a factor of AircraftPerf.AircraftDrag.mpower (1.05, fixed) }
breaks down into 3 monomials:
1) forming 90% of the RHS and 90% of the total:
{ through a factor of Nprop (4, fixed) }
AircraftPerf.AircraftDrag.MotorPerf.Pelec (0.685kW)
which in: Pelec = v·i (sensitivity -5.1)
breaks down into:
{ through a factor of AircraftPerf.AircraftDrag.MotorPerf.v (18.6V) }
AircraftPerf.AircraftDrag.MotorPerf.i (36.8A)
which in: i ≥ Q·Kv + i0 (sensitivity +5.4)
breaks down into 2 monomials:
1) forming 87% of the RHS and 79% of the total:
{ through a factor of Kv (64.2rpm/V) }
AircraftPerf.AircraftDrag.MotorPerf.Q (4.8N·m)
which in: Q = Q (sensitivity -4.7)
breaks down into:
AircraftPerf.AircraftDrag.ActuatorProp.Q (4.8N·m)
which in: CP ≤ Q·omega/(0.5·rho·(omega·R)³·π·R²) (sensitivity +4.7)
{ through a factor of 4.53e-05·FlightState.rho·AircraftPerf.AircraftDrag.ActuatorProp.omega²·Propeller.R⁵ (1,653N·m) }
breaks down into:
AircraftPerf.AircraftDrag.ActuatorProp.CP (0.00291)
2) forming 12% of the RHS and 11% of the total:
i0 (4.5A, fixed)
2) forming 6% of the RHS and 6% of the total:
AircraftPerf.AircraftDrag.Pavn (200W, fixed)
3) forming 3% of the RHS and 3% of the total:
AircraftPerf.AircraftDrag.Ppay (100W, fixed)

Permissivity = 1 (stops at Pelec = v·i)
----------------

AircraftPerf.AircraftDrag.Poper (3,194W)
which in: Poper/mpower ≥ Pavn + Ppay + Pelec·Nprop (sensitivity +5.6)
{ through a factor of AircraftPerf.AircraftDrag.mpower (1.05, fixed) }
breaks down into 3 monomials:
1) forming 90% of the RHS and 90% of the total:
{ through a factor of Nprop (4, fixed) }
AircraftPerf.AircraftDrag.MotorPerf.Pelec (0.685kW)
which in: Pelec = v·i (sensitivity -5.1)
breaks down into:
AircraftPerf.AircraftDrag.MotorPerf.i·AircraftPerf.AircraftDrag.MotorPerf.v (685A·V)
2) forming 6% of the RHS and 6% of the total:
AircraftPerf.AircraftDrag.Pavn (200W, fixed)
3) forming 3% of the RHS and 3% of the total:
AircraftPerf.AircraftDrag.Ppay (100W, fixed)

0 comments on commit b8fd905

Please sign in to comment.