Skip to content

Commit

Permalink
modularize beam model; to allow for different qbar and Sbar functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mjburton committed Nov 2, 2017
1 parent b41184c commit a4a77d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
17 changes: 15 additions & 2 deletions gpkitmodels/GP/aircraft/wing/chord_spar_loading.py
@@ -1,4 +1,5 @@
" cap spar "
from numpy import flip
from gpkit import Model, Variable, Vectorize
from gpkitmodels.GP.beam.beam import Beam

Expand All @@ -17,12 +18,24 @@ def setup(self, static, Wcent):
with Vectorize(static.N-1):
Mr = Variable("M_r", "N*m", "wing section root moment")

def new_qbarFun(_, c):
" define qbar model for chord loading "
return [f(c) for f in static.substitutions["\\bar{c}"]]
def new_SbarFun(bmodel, c):
" define Sbar model for chord loading "
Sb = [1e-10]*static.N
for i in flip(range(static.N-1), 0):
Sb[i] = (Sb[i+1] + static.substitutions["d\\eta"][i](c)
* (new_qbarFun(bmodel, c)[i]
+ new_qbarFun(bmodel, c)[i+1])/2)
return Sb

Beam.qbarFun = new_qbarFun
Beam.SbarFun = new_SbarFun
beam = Beam(static.N)
beam.substitutions["\\bar{q}"] = static.substitutions["\\bar{c}"]

constraints = [
# dimensionalize moment of inertia and young's modulus
# beam["\\bar{q}"] == static["\\bar{c}"],
beam["dx"] == static["d\\eta"],
beam["\\bar{EI}"] <= (8*static["E"]*static["I"]/Nmax
/ Wcent/static["b"]**2),
Expand Down
8 changes: 5 additions & 3 deletions gpkitmodels/GP/aircraft/wing/wing_test.py
Expand Up @@ -23,10 +23,12 @@ def wing_test():
W.substitutions[W.topvar("W")] = 50
fs = FlightState()
perf = W.flight_model(W, fs)
loading = W.loading(W, Wcent, W.topvar("W"), fs["V"], perf["C_L"])
# loading = W.loading(W, Wcent, W.topvar("W"), fs["V"], perf["C_L"])
loading = W.loading(W, Wcent)

m = Model(perf["C_d"], [W, fs, perf, loading])
m.solve("mosek")
s = m.solve("mosek")
return s

if __name__ == "__main__":
wing_test()
s = wing_test()
22 changes: 16 additions & 6 deletions gpkitmodels/GP/beam/beam.py
@@ -1,8 +1,13 @@
" discretized beam model "
from gpkit import Model, Variable, Vectorize

#pylint: disable=invalid-name

class Beam(Model):
"discretized beam bending model"
qbarFun = None
SbarFun = None

def setup(self, N):

with Vectorize(N-1):
Expand All @@ -11,8 +16,8 @@ def setup(self, N):
dx = Variable("dx", "-", "normalized length of element")

with Vectorize(N):
qbar = Variable("\\bar{q}", "-", "normalized loading")
Sbar = Variable("\\bar{S}", "-", "normalized shear")
qbar = Variable("\\bar{q}", self.qbarFun, "-", "normalized loading")
Sbar = Variable("\\bar{S}", self.SbarFun, "-", "normalized shear")
Mbar = Variable("\\bar{M}", "-", "normalized moment")
th = Variable("\\theta", "-", "deflection slope")
dbar = Variable("\\bar{\\delta}", "-", "normalized displacement")
Expand All @@ -24,15 +29,20 @@ def setup(self, N):
dbarroot = Variable("\\bar{\\delta}_{root}", 1e-10, "-",
"Base deflection")

constraints = [
Sbar[:-1] >= Sbar[1:] + 0.5*dx*(qbar[:-1] + qbar[1:]),
Sbar[-1] >= Sbartip,
constraints = []
if self.SbarFun is None:
constraints.extend([
Sbar[:-1] >= Sbar[1:] + 0.5*dx*(qbar[:-1] + qbar[1:]),
Sbar[-1] >= Sbartip])

constraints.extend([
Mbar[:-1] >= Mbar[1:] + 0.5*dx*(Sbar[:-1] + Sbar[1:]),
Mbar[-1] >= Mbartip,
th[0] >= throot,
th[1:] >= th[:-1] + 0.5*dx*(Mbar[1:] + Mbar[:-1])/EIbar,
dbar[0] >= dbarroot,
dbar[1:] >= dbar[:-1] + 0.5*dx*(th[1:] + th[:-1]),
]
])

return constraints

0 comments on commit a4a77d9

Please sign in to comment.