Skip to content

Commit

Permalink
move all external functions to inline methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mjburton committed Oct 25, 2017
1 parent 03bc29a commit 288aa00
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
12 changes: 5 additions & 7 deletions gpkitmodels/GP/aircraft/wing/chord_spar_loading.py
@@ -1,14 +1,14 @@
" cap spar "
from gpkit import Model, Variable, Vectorize
from constant_taper_chord import c_bar
from gpkitmodels.GP.beam.beam import Beam

#pylint: disable=invalid-name

class ChordSparL(Model):
"spar loading model"
def setup(self, static, Wcent):

Nmax = Variable("N_{max}", 5, "-", "max loading")
cbar, _, _, _ = c_bar(0.5, static.N)

sigmacfrp = Variable("\\sigma_{CFRP}", 1700e6, "Pa", "CFRP max stress")
taucfrp = Variable("\\tau_{CFRP}", 450e6, "Pa", "CFRP fabric stress")
Expand All @@ -17,14 +17,12 @@ def setup(self, static, Wcent):
with Vectorize(static.N-1):
Mr = Variable("M_r", "N*m", "wing section root moment")

with Vectorize(static.N):
qbar = Variable("\\bar{q}", "-", "normalized loading")

beam = Beam(static.N, qbar)
beam = Beam(static.N)

constraints = [
# dimensionalize moment of inertia and young's modulus
qbar == static["\\bar{c}"],
beam["\\bar{q}"] == static["\\bar{c}"],
beam["dx"] == static["d\\eta"],
beam["\\bar{EI}"] <= (8*static["E"]*static["I"]/Nmax
/ Wcent/static["b"]**2),
Mr == (beam["\\bar{M}"][:-1]*Wcent*Nmax*static["b"]/4),
Expand Down
25 changes: 12 additions & 13 deletions gpkitmodels/GP/aircraft/wing/gustloading.py
@@ -1,21 +1,18 @@
" spar loading for gust case "
import os
from numpy import pi, hstack, cos
import pandas as pd
from gpkit import Model, Variable, Vectorize
from constant_taper_chord import c_bar
from gpkitmodels.GP.beam.beam import Beam
# from gpkitmodels.tools.fit_constraintset import FitCS
from gpfit.fit_constraintset import FitCS
from numpy import pi
import numpy as np
import pandas as pd
import os

#pylint: disable=invalid-name, no-member, too-many-locals

class GustL(Model):
"spar loading model"
def setup(self, static, Wcent, Wwing, V, CL):
# def setup(self, static, Wcent, rho, V, S):

Nmax = Variable("N_{max}", 2, "-", "load safety factor")
cbar, eta, _, _ = c_bar(0.5, static.N)

sigmacfrp = Variable("\\sigma_{CFRP}", 1700e6, "Pa", "CFRP max stress")
taucfrp = Variable("\\tau_{CFRP}", 450e6, "Pa", "CFRP fabric stress")
Expand All @@ -28,20 +25,22 @@ def setup(self, static, Wcent, Wwing, V, CL):

with Vectorize(static.N):
agust = Variable("\\alpha_{gust}", "-", "gust angle of attack")
qbar = Variable("\\bar{q}", "-", "normalized loading")
cosminus1 = Variable("1-cos(\\eta)",
np.hstack([1e-10, 1-np.cos(eta[1:]*pi/2)]),
return_cosm1 = lambda c: hstack(
[1e-10, 1-cos(c[static["\\eta"]][1:]*pi/2)])
cosminus1 = Variable("1-cos(\\eta)", return_cosm1,
"-", "1 minus cosine factor")

beam = Beam(static.N, qbar)
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(
orient="records")[0]

constraints = [
# fit for arctan from 0 to 1, RMS = 0.044
FitCS(df, agust, [cosminus1*vgust/V]),
qbar >= cbar*(1 + 2*pi*agust/CL*(1+Wwing/Wcent)),
beam["\\bar{q}"] >= static["\\bar{c}"]*(
1 + 2*pi*agust/CL*(1+Wwing/Wcent)),
beam["dx"] == static["d\\eta"],
# dimensionalize moment of inertia and young's modulus
beam["\\bar{EI}"] <= (8*static["E"]*static["I"]/Nmax
/ Wcent/static["b"]**2),
Expand Down
6 changes: 3 additions & 3 deletions gpkitmodels/GP/beam/beam.py
Expand Up @@ -3,13 +3,15 @@

class Beam(Model):
"discretized beam bending model"
def setup(self, N, qbar):
def setup(self, N):

with Vectorize(N-1):
EIbar = Variable("\\bar{EI}", "-",
"normalized YM and moment of inertia")
dx = Variable("dx", "-", "normalized length of element")

with Vectorize(N):
qbar = Variable("\\bar{q}", "-", "normalized loading")
Sbar = Variable("\\bar{S}", "-", "normalized shear")
Mbar = Variable("\\bar{M}", "-", "normalized moment")
th = Variable("\\theta", "-", "deflection slope")
Expand All @@ -21,7 +23,6 @@ def setup(self, N, qbar):
throot = Variable("\\theta_{root}", 1e-10, "-", "Base angle")
dbarroot = Variable("\\bar{\\delta}_{root}", 1e-10, "-",
"Base deflection")
dx = Variable("dx", "-", "normalized length of element")

constraints = [
Sbar[:-1] >= Sbar[1:] + 0.5*dx*(qbar[:-1] + qbar[1:]),
Expand All @@ -32,7 +33,6 @@ def setup(self, N, qbar):
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]),
1 == (N-1)*dx,
]

return constraints

0 comments on commit 288aa00

Please sign in to comment.