Skip to content

Commit

Permalink
move functions to attribute level
Browse files Browse the repository at this point in the history
  • Loading branch information
mjburton committed Nov 3, 2017
1 parent a4a77d9 commit f672dd4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
32 changes: 18 additions & 14 deletions gpkitmodels/GP/aircraft/wing/chord_spar_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@

class ChordSparL(Model):
"spar loading model"

def new_qbarFun(self, c):
" define qbar model for chord loading "
return [f(c) for f in self.static.substitutions["\\bar{c}"]]

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

def setup(self, static, Wcent):

self.static = static
Nmax = Variable("N_{max}", 5, "-", "max loading")

sigmacfrp = Variable("\\sigma_{CFRP}", 1700e6, "Pa", "CFRP max stress")
Expand All @@ -18,20 +33,9 @@ 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.qbarFun = self.new_qbarFun
Beam.SbarFun = self.new_SbarFun
beam = Beam(static.N)

constraints = [
Expand Down
2 changes: 2 additions & 0 deletions gpkitmodels/GP/aircraft/wing/gustloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def setup(self, static, Wcent, Wwing, V, CL):
cosminus1 = Variable("1-cos(\\eta)", return_cosm1,
"-", "1 minus cosine factor")

Beam.qbarFun = None
Beam.SbarFun = None
beam = Beam(static.N)
path = os.path.abspath(__file__).replace(os.path.basename(__file__), "")
df = pd.read_csv(path + os.sep + "arctan_fit.csv").to_dict(
Expand Down
2 changes: 1 addition & 1 deletion gpkitmodels/GP/aircraft/wing/wing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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])
Expand Down
10 changes: 7 additions & 3 deletions gpkitmodels/GP/beam/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Beam(Model):
"discretized beam bending model"
qbarFun = None
SbarFun = None
MbarFun = None

def setup(self, N):

Expand All @@ -18,7 +19,7 @@ def setup(self, N):
with Vectorize(N):
qbar = Variable("\\bar{q}", self.qbarFun, "-", "normalized loading")
Sbar = Variable("\\bar{S}", self.SbarFun, "-", "normalized shear")
Mbar = Variable("\\bar{M}", "-", "normalized moment")
Mbar = Variable("\\bar{M}", self.MbarFun, "-", "normalized moment")
th = Variable("\\theta", "-", "deflection slope")
dbar = Variable("\\bar{\\delta}", "-", "normalized displacement")

Expand All @@ -35,9 +36,12 @@ def setup(self, N):
Sbar[:-1] >= Sbar[1:] + 0.5*dx*(qbar[:-1] + qbar[1:]),
Sbar[-1] >= Sbartip])

if self.MbarFun is None:
constraints.extend([
Mbar[:-1] >= Mbar[1:] + 0.5*dx*(Sbar[:-1] + Sbar[1:]),
Mbar[-1] >= Mbartip])

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,
Expand Down

0 comments on commit f672dd4

Please sign in to comment.