Skip to content

Commit

Permalink
Merge 73fc5ee into c8cf2b3
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Jan 8, 2022
2 parents c8cf2b3 + 73fc5ee commit 0c72b40
Show file tree
Hide file tree
Showing 45 changed files with 2,120 additions and 389 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -83,7 +83,7 @@ attr-rgx=[a-z_][a-z0-9_]{2,30}$
attr-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}|nu|la|ax$
argument-rgx=[a-z_][a-z0-9_]{2,30}|nu|la|ax|vk$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
Expand Down
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
2 changes: 1 addition & 1 deletion docs/source/examples/beam.py
Expand Up @@ -68,7 +68,7 @@ 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))
print(sol.table(tables=["cost breakdown"], maxcolumns=6))
w_gp = sol("w") # deflection along beam

L, EI, q = sol("L"), sol("EI"), sol("q")
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])

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

# the code to create solar.p is in ./breakdowns/solartest.py
filepath = os.path.dirname(os.path.realpath(__file__)) + os.sep + "solar.p"
print(filepath)
sol = pickle.load(open(filepath, "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)

# you can also produce Plotly treemaps/icicle plots of your breakdowns
fig = bds.treemap("model sensitivities", returnfig=True)
fig = bds.icicle("cost", returnfig=True)
# uncommenting any of the below makes and shows the plot directly
# bds.icicle("model sensitivities")
# bds.treemap("cost")
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╶⎨
┃┃ ┃ (370lbf) ┃ (165,913kJ)
┃┃ ┃ ┃
┃┃ ┃ ┃
Cost╺┫┃ ┃ ┃
(699lbf) ┃┣╸Wtotal ┛ ┛
┃┃ (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
┃┛ ┛
┃┓ ┣╸Planform╶⎨
Aircraft╺┫┃ ┛
┃┣╸Wing ┣╸BoxSpar╶⎨
┃┃ ┛
┃┛ ┣╸[4 terms]
┃┣╸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)
35 changes: 32 additions & 3 deletions docs/source/examples/docstringparsing_output.txt
Expand Up @@ -29,9 +29,38 @@ h = self.h = Variable('h', 1, 'm', 'minimum height') # from 'h 1 [m] min
# way that makes the most sense to someone else reading your model.
#

Optimal Cost
------------
1.465
┃┓ ┓ /┓
┃┃ ┃ ┃
┃┃ ┣╸s[0] /┣╸h
Cost╺┫┃ ┃ (0.316m) ┃ (1m, fixed)
(1.46m²) ┃┣╸A ┛ /┛
┃┃ (1.46m²) ┓ ┓
┃┃ ┣╸s[2] ┣╸h
┃┛ ┛ (1m) ┛



┃┓ ┓
┃┃ ┃
┃┃ ┃
┃┃ ┃
┃┃ ┣╸A ≥ 2·(s[0]·s[1] + s[1]·s[2] + s[2]·s[0])
┃┃ ┃
┃┃ ┃
┃┃ ┛
┃┃ ┓
Model╺┫┃ ┃
┃┣╸Cube ┣╸V = 100l
┃┃ ┛
┃┃ ┓
┃┃ ┃
┃┃ ┣╸V ≤ s[:].prod()
┃┃ ┛
┃┃ ┣╸h = 1m
┃┃ ┛
┃┃ ┣╸s[2] ≥ h
┃┛ ┛


Free Variables
--------------
Expand Down

0 comments on commit 0c72b40

Please sign in to comment.