Skip to content

Commit

Permalink
new parse_variables syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Aug 31, 2019
1 parent 4e2bfe5 commit 63ae132
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 87 deletions.
8 changes: 2 additions & 6 deletions gpkitmodels/GP/aircraft/fuselage/elliptical_fuselage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class FuselageAero(Model):
mfac 1.0 [-] fuselage drag margin
"""
@parse_variables(__doc__, globals())
def setup(self, static, state):
exec parse_variables(FuselageAero.__doc__)

V = state.V
rho = state.rho
l = static.l
Expand Down Expand Up @@ -54,9 +53,8 @@ class Fuselage(Model):
material = cfrpfabric
flight_model = FuselageAero

@parse_variables(__doc__, globals())
def setup(self):
exec parse_variables(Fuselage.__doc__)

rhocfrp = self.material.rho
tmin = self.material.tmin

Expand All @@ -70,5 +68,3 @@ def setup(self):
]

return constraints


20 changes: 5 additions & 15 deletions gpkitmodels/GP/aircraft/motor/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class MotorPerf(Model):
i [amps] current
v [V] woltage
"""
@parse_variables(__doc__, globals())
def setup(self, static, state):
exec parse_variables(MotorPerf.__doc__)

Kv = static.Kv
R = static.R
i0 = static.i0
Expand Down Expand Up @@ -55,22 +54,19 @@ class Motor(Model):

flight_model = MotorPerf

@parse_variables(__doc__, globals())
def setup(self):
exec parse_variables(Motor.__doc__)

constraints = [W >= Qstar*Qmax*g,
Kv >= Kv_min,
Kv <= Kv_max]

return constraints

class PropulsorPerf(Model):
"""Propulsor Performance Model
"""
"Propulsor Performance Model"

@parse_variables(__doc__, globals())
def setup(self, static, state):
exec parse_variables(PropulsorPerf.__doc__)
self.prop = static.prop.flight_model(static.prop, state)
self.motor = static.motor.flight_model(static.motor, state)

Expand All @@ -93,18 +89,12 @@ class Propulsor(Model):
flight_model = PropulsorPerf
prop_flight_model = ActuatorProp


@parse_variables(__doc__, globals())
def setup(self):
exec parse_variables(Propulsor.__doc__)

Propeller.flight_model = self.prop_flight_model
self.prop = Propeller()
self.motor = Motor()

components = [self.prop, self.motor]

return [self.W >= self.prop.W + self.motor.W], components




7 changes: 3 additions & 4 deletions gpkitmodels/GP/aircraft/prop/propeller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class ActuatorProp(Model):
def helper(self, c):
return 2. - 1./c(self.etaadd)

@parse_variables(__doc__, globals())
def setup(self, static, state):
exec parse_variables(ActuatorProp.__doc__)

V = state.V
rho = state.rho
R = static.R
Expand Down Expand Up @@ -73,7 +72,7 @@ class Propeller(Model):

flight_model = ActuatorProp

def setup(self, N = 5):
exec parse_variables(Propeller.__doc__)
@parse_variables(__doc__, globals())
def setup(self, N=5):
self.N = N
return [W >= K*T_m*R**2]
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/tail/empennage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ class Empennage(Model):
mfac m_{\\mathrm{fac}}
"""
@parse_variables(__doc__, globals())
def setup(self, N=2):
exec parse_variables(Empennage.__doc__)

self.htail = HorizontalTail()
self.hSparModel = self.htail.sparModel
self.htail.substitutions.update({self.htail.mfac: 1.1})
Expand Down
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/tail/horizontal_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class HorizontalTail(Wing):
fillModel = WingCore
sparModel = None

@parse_variables(__doc__, globals())
def setup(self, N=3):
exec parse_variables(HorizontalTail.__doc__)

self.ascs = Wing.setup(self, N)
self.planform.substitutions.update(
{self.planform.AR: 4, self.planform.lam: 0.8})
Expand Down
2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/tail/tail_aero.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class TailAero(Model):
Cd C_d
"""
@parse_variables(__doc__, globals())
def setup(self, static, state):
self.state = state
exec parse_variables(TailAero.__doc__)

cmac = self.cmac = static.planform.cmac
b = self.b = static.planform.b
Expand Down
16 changes: 8 additions & 8 deletions gpkitmodels/GP/aircraft/tail/tail_boom.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class TailBoomAero(Model):
Cf C_f
"""
@parse_variables(__doc__, globals())
def setup(self, static, state):
self.state = state
exec parse_variables(TailBoomAero.__doc__)

l = self.l = static.l
rho = self.rho = state.rho
Expand All @@ -56,8 +56,9 @@ class TailBoomState(Model):
Vne V_{\\mathrm{NE}}
"""
@parse_variables(__doc__, globals())
def setup(self):
exec parse_variables(TailBoomState.__doc__)
pass


class VerticalBoomTorsion(Model):
Expand All @@ -81,9 +82,8 @@ class VerticalBoomTorsion(Model):
taucfrp \\tau_{\\mathrm{CFRP}}
"""
@parse_variables(__doc__, globals())
def setup(self, tailboom, vtail, state):
exec parse_variables(VerticalBoomTorsion.__doc__)

J = self.J = tailboom.J
d0 = self.d0 = tailboom.d
b = self.b = vtail.planform.b
Expand All @@ -106,8 +106,8 @@ class TailBoomBending(Model):
kappa 0.1 [-] max tail boom deflection
Nsafety 1.0 [-] safety load factor
Variables of length N-1
-----------------------
Variables of length tailboom.N-1
--------------------------------
Mr [N*m] section root moment
Expand All @@ -128,12 +128,12 @@ class TailBoomBending(Model):
thmax \\theta_{\\mathrm{max}}
"""
@parse_variables(__doc__, globals())
def setup(self, tailboom, htail, state):
N = self.N = tailboom.N
self.state = state
self.htail = htail
self.tailboom = tailboom
exec parse_variables(TailBoomBending.__doc__)

Beam.qbarFun = [1e-10]*N
Beam.SbarFun = [1.]*N
Expand Down Expand Up @@ -186,9 +186,9 @@ class TailBoom(TubeSpar):
tailLoad = TailBoomBending
secondaryWeight = None

@parse_variables(__doc__, globals())
def setup(self, N=5):
self.N = N
exec parse_variables(TailBoom.__doc__)
self.spar = super(TailBoom, self).setup(N, self)

if self.secondaryWeight:
Expand Down
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/tail/tube_spar.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class TubeSpar(Model):
minusk2 = lambda self, c: 1-c(self.k)/2.
material = cfrpfabric

@parse_variables(__doc__, globals())
def setup(self, N, surface):
exec parse_variables(TubeSpar.__doc__)

deta = surface.deta
tmin = self.material.tmin
rho = self.material.rho
Expand Down
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/tail/vertical_tail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class VerticalTail(Wing):
fillModel = WingCore
sparModel = None

@parse_variables(__doc__, globals())
def setup(self, N=3):
exec parse_variables(VerticalTail.__doc__)

self.ascs = Wing.setup(self, N)
self.planform.substitutions.update(
{self.planform.lam: 0.8, self.planform.AR: 4})
Expand Down
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/wing/boxspar.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class BoxSpar(Model):
shearMaterial = cfrpfabric
coreMaterial = foamhd

@parse_variables(__doc__, globals())
def setup(self, N, surface):
self.surface = surface
exec parse_variables(BoxSpar.__doc__)

b = self.b = surface.b
cave = self.cave = surface.cave
Expand Down Expand Up @@ -89,4 +89,3 @@ def setup(self, N, surface):
]

return constraints

2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/wing/capspar.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class CapSpar(Model):
shearMaterial = cfrpfabric
coreMaterial = foamhd

@parse_variables(__doc__, globals())
def setup(self, N, surface):
self.surface = surface
exec parse_variables(CapSpar.__doc__)

cave = self.cave = surface.cave
b = self.b = surface.b
Expand Down
2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/wing/gustloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def return_cosm1(self, c):
eta = c(self.wing.planform.eta).to("dimensionless").magnitude
return hstack([adnumber(1e-10), 1-array(cos(eta[1:]*pi/2))])

@parse_variables(__doc__, globals())
def setup(self, wing, state, out=False):
exec parse_variables(GustL.__doc__)
self.load = SparLoading.setup(self, wing, state, out=out)

cbar = self.wing.planform.cbar
Expand Down
2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/wing/sparloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def new_qbarFun(self, c):

new_SbarFun = None

@parse_variables(__doc__, globals())
def setup(self, wing, state, out=False):
self.wing = wing
exec parse_variables(SparLoading.__doc__)

b = self.b = self.wing.planform.b
I = self.I = self.wing.spar.I
Expand Down
11 changes: 4 additions & 7 deletions gpkitmodels/GP/aircraft/wing/wing.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def return_cmac(self, c):
+ self.return_c(c)[1:])/2.
return_deta = lambda self, c: np.diff(c(self.eta))

@parse_variables(__doc__, globals())
def setup(self, N):
exec parse_variables(Planform.__doc__)

return [b**2 == S*AR,
cave == cbave*S/b,
croot == S/b*cbar[0],
Expand Down Expand Up @@ -117,11 +116,10 @@ class WingAero(Model):
cdp c_{d_p}
"""
def setup(self, static, state,
fitdata=dirname(abspath(__file__)) + sep + "jho_fitdata.csv"):
@parse_variables(__doc__, globals())
def setup(self, static, state, fitdata=dirname(abspath(__file__)) + sep + "jho_fitdata.csv"): # TODO: make multi-line work
self.state = state
self.static = static
exec parse_variables(WingAero.__doc__)

df = pd.read_csv(fitdata)
fd = df.to_dict(orient="records")[0]
Expand Down Expand Up @@ -178,10 +176,9 @@ class Wing(Model):
skinModel = WingSkin
sparJ = False

@parse_variables(__doc__, globals())
def setup(self, N=5):
self.N = N
exec parse_variables(Wing.__doc__)

self.planform = Planform(N)
self.components = []

Expand Down
2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/wing/wing_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class WingCore(Model):
"""
material = foamhd

@parse_variables(__doc__, globals())
def setup(self, surface):
self.surface = surface
exec parse_variables(WingCore.__doc__)

cave = self.cave = surface.cave
b = self.b = surface.b
Expand Down
16 changes: 8 additions & 8 deletions gpkitmodels/GP/aircraft/wing/wing_skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class WingSkin(Model):
Upper Unbounded
---------------
W, croot
W, surface.croot
Lower Unbounded
---------------
S
surface.S
LaTex Strings
-------------
Expand All @@ -35,16 +35,17 @@ class WingSkin(Model):
"""
material = cfrpfabric

@parse_variables(__doc__, globals())
def setup(self, surface):
exec parse_variables(WingSkin.__doc__)
self.surface = surface

croot = self.croot = surface.croot
S = self.S = surface.S
croot = surface.croot
S = surface.S
rho = self.material.rho
tau = self.material.tau
tmin = self.material.tmin

return [W >= rho*surface.S*2*t*g,
return [W >= rho*S*2*t*g,
t >= tmin,
tau >= 1/Jtbar/croot**2/t*Cmw*S*rhosl*Vne**2]

Expand All @@ -70,9 +71,8 @@ class WingSecondStruct(Model):
rhoA \\rho_{A}
"""
@parse_variables(__doc__, globals())
def setup(self, surface):
exec parse_variables(WingSecondStruct.__doc__)

S = self.S = surface.S

return [W >= rhoA*S*g]
3 changes: 1 addition & 2 deletions gpkitmodels/GP/aircraft/wing/wing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class FlightState(Model):
qne [kg/s^2/m] never exceed dynamic pressure
"""
@parse_variables(__doc__, globals())
def setup(self):
exec parse_variables(FlightState.__doc__)

return [qne == V**2*rho*1.2]

def wing_test():
Expand Down
Loading

0 comments on commit 63ae132

Please sign in to comment.