From 288aa00e5125ed9ac51fe9d9eab5eec3417c21e9 Mon Sep 17 00:00:00 2001 From: mjburton Date: Wed, 25 Oct 2017 12:38:02 -0400 Subject: [PATCH] move all external functions to inline methods --- .../GP/aircraft/wing/chord_spar_loading.py | 12 ++++----- gpkitmodels/GP/aircraft/wing/gustloading.py | 25 +++++++++---------- gpkitmodels/GP/beam/beam.py | 6 ++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/gpkitmodels/GP/aircraft/wing/chord_spar_loading.py b/gpkitmodels/GP/aircraft/wing/chord_spar_loading.py index a93b2ae7..7e10f127 100644 --- a/gpkitmodels/GP/aircraft/wing/chord_spar_loading.py +++ b/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") @@ -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), diff --git a/gpkitmodels/GP/aircraft/wing/gustloading.py b/gpkitmodels/GP/aircraft/wing/gustloading.py index 25ff1844..ed871bca 100644 --- a/gpkitmodels/GP/aircraft/wing/gustloading.py +++ b/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") @@ -28,12 +25,12 @@ 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] @@ -41,7 +38,9 @@ def setup(self, static, Wcent, Wwing, V, CL): 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), diff --git a/gpkitmodels/GP/beam/beam.py b/gpkitmodels/GP/beam/beam.py index 8f3744f8..40ad0c94 100644 --- a/gpkitmodels/GP/beam/beam.py +++ b/gpkitmodels/GP/beam/beam.py @@ -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") @@ -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:]), @@ -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