How to use the gpkit.Model function in gpkit

To help you get started, we’ve selected a few gpkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github convexengineering / SPaircraft / stand_alone_simple_profiel.py View on Github external
TSFC = Variable('TSFC', '1/hr', 'Thrust Specific Fuel Consumption')
        thrust = Variable('thrust', 'N', 'Thrust')
        
        #constraints
        constraints = []

        constraints.extend([
            TSFC == TSFC,

            thrust == thrust, #want thrust to enter the model
            ])

        Model.__init__(self, None, constraints)


class Wing(Model):
    """
    place holder wing model
    """
    def __init__(self, ** kwargs):
        #new variables
        W_wing = Variable('W_{wing}', 'N', 'Wing Weight')
                           
        #aircraft geometry
        S = Variable('S', 'm^2', 'Wing Planform Area')
        AR = Variable('AR', '-', 'Aspect Ratio')
        span = Variable('b', 'm', 'Wing Span')
        span_max = Variable('b_{max}', 'm', 'Max Wing Span')

        K = Variable('K', '-', 'K for Parametric Drag Model')
        e = Variable('e', '-', 'Oswald Span Efficiency Factor')
github convexengineering / SPaircraft / Commerical_Flight_Profile_Simple.py View on Github external
dhftClimb[icl] == hftCruise/Nclimb,

            #constrain the max wing loading
            WLoadClimb <= WLoadmax,

            thrustcl <= 2 * thrustcr[0],
            ])

        for i in range(0, Nclimb):
            constraints.extend([
                #speed of sound
                aClimb[i]  == (gamma * R * TClimb[i])**.5,
                TSFCcl[i] == .7*units('1/hr'),
                ])
        
        Model.__init__(self, None, constraints, **kwargs)
github convexengineering / SPaircraft / HT_debug.py View on Github external
#constraints
        constraints = []

        constraints.extend([
            Dfuse == Cdfuse * (.5 * fuse['A_{fuse}'] * state.atm['\\rho'] * state['V']**2),

            Cdfuse == .005,

            Cmfu == .05,
            ])

        Model.__init__(self, None, constraints)
    

class Mission(Model):
    """
    mission class, links together all subclasses
    """
    def __init__(self, subs = None, **kwargs):
        #define the number of each flight segment
        Nclimb = 2
        Ncruise = 1

        #build required submodels
        ac = Aircraft()

        #vectorize
##        with vectorize(Nclimb):
##            climb = ClimbSegment(ac)

        with vectorize(Ncruise):
github convexengineering / SPaircraft / stand_alone_simple_profile.py View on Github external
constraints = []

        constraints.extend([
            V == V, #required so velocity variable enters the model

            #compute the speed of sound with the state
            a  == (gamma * R * self.atm['T_{atm}'])**.5,

            #compute the mach number
            V == M * a,
            ])

        #build the model
        return constraints, self.alt, self.atm

class Altitude(Model):
    """
    holds the altitdue variable

    Upper Unbounded
    ---------------
    h

    Lower Unbounded
    ---------------
    h
    """
    def setup(self, **kwargs):
        #define altitude variables
        h = self.h = Variable('h', 'm', 'Segment Altitude [meters]')
        hft = Variable('hft', 'feet', 'Segment Altitude [feet]')
github convexengineering / SPaircraft / new_CFP.py View on Github external
#Dfuse == Cdfuse * (.5 * fuse['A_{fuse}'] * state.atm['\\rho'] * state['V']**2),
            # fineness ratio
            f == fuse['l_{fuse}'] / ((4 / np.pi * fuse['A_{fuse}'])**0.5),
            FF >= 1 + 60 / f**3 + f / 400,  # form factor
            Dfrict >= FF * np.pi * fuse['R_{fuse}'] * state.atm['\\mu'] * state['V'] * 0.074 * (state.atm['\\rho'] * state['V']
                                                                                                * fuse['l_{fuse}'] / state.atm['\\mu'])**0.8,
            # Monomial fit of tan(phi)
            1.13226 * phi**1.03759 == fuse['R_{fuse}'] / fuse['l_{cone}'],
            Dupswp >= 3.83 * phi**2.5 * fuse['A_{fuse}'] * 0.5 * state.atm['\\rho'] * state['V']**2,
            Dfuse >= Dfrict + Dupswp,
            Dfuse == 0.5 * state.atm['\\rho'] * state['V']**2 * Cdfuse * fuse['A_{fuse}'],
        ])

        return constraints

class StateLinking(Model):
    """
    link all the state model variables
    """
    def setup(self, climbstate, cruisestate, enginestate, Nclimb, Ncruise):
        statevarkeys = ['p_{sl}', 'T_{sl}', 'L_{atm}', 'M_{atm}', 'P_{atm}', 'R_{atm}',
                        '\\rho', 'T_{atm}', '\\mu', 'T_s', 'C_1', 'h', 'hft', 'V', 'a', 'R', '\\gamma', 'M']
        constraints = []
        for i in range(len(statevarkeys)):
            varkey = statevarkeys[i]
            for i in range(Nclimb):
                constraints.extend([
                    climbstate[varkey][i] == enginestate[varkey][i]
                    ])
            for i in range(Ncruise):
                constraints.extend([
                    cruisestate[varkey][i] == enginestate[varkey][i+Nclimb]
github convexengineering / SPaircraft / wing_performance.py View on Github external
"""
    Philippe's thesis wing model
    """
    def __init__(self, **kwargs):
        self.wns = WingNoStruct()
        self.wb = WingBox(self.wns)

        Model.__init__(self, None, self.wns + self.wb)
        
    def dynamic(self, state):
        """
        returns an instance of the wing perofrmance model
        """
        return WingPerformance(self, state)

class WingNoStruct(Model):
    """
    Philippe's wing model minus structure
    """
    def __init__(self, **kwargs):
        #declare variables
               #Variables
        Afuel   = Variable('\\bar{A}_{fuel, max}', '-', 'Non-dim. fuel area')
        
        CLwmax  = Variable('C_{L_{wmax}}', '-', 'Max lift coefficient, wing')
        
        
        Vfuel   = Variable('V_{fuel, max}', 'm^3', 'Available fuel volume')
github convexengineering / gplibrary / 1682 / gas_male / gasmale.py View on Github external
W_nplus1 = VectorVariable(N, "W_{N+1}", "lbf", "vector-end weight")
        W_fuel = VectorVariable(N, "W_{fuel}", "lbf",
                                "Segment-fuel weight")
        g = Variable("g", 9.81, "m/s^2", "Gravitational acceleration")
        W_n = VectorVariable(N, "W_{N}", "lbf", "vector-begin weight")

        constraints = [
            z_bre >= P_shafttot*t*bsfc*g/(W_nplus1*W_n)**0.5,
            # TCS([z_bre >= P_shafttot*t*bsfc*g/(W_nplus1*W_n)**0.5]),
            # TCS([z_bre >= P_shafttot*t*bsfc*g/W_nplus1]),
            f_fueloil*W_fuel/W_nplus1 >= te_exp_minus1(z_bre, 3)
            ]

        Model.__init__(self, None, constraints, **kwargs)

class ComponentDrag(Model):
    def __init__(self, N, comp, **kwargs):

        CDA = VectorVariable(N, "CDA", "-",
                             "%s area drag normalized by wing area" % comp.name)
        Cf = VectorVariable(N, "C_f", "-",
                            "%s skin friction coefficient" % comp.name)
        Re = VectorVariable(N, "Re", "-", "%s reynolds number" % comp.name)
        S = Variable("S", "ft^2", "wing area")
        rho = VectorVariable(N, "\\rho", "kg/m^3", "Air density")
        mu_atm = VectorVariable(N, "\\mu", "N*s/m^2", "Dynamic viscosity")
        V = VectorVariable(N, "V", "m/s", "Cruise speed")

        constraints = [CDA >= Cf*comp["S_{ref}"]/S,
                       Re == V*rho*comp["l_{ref}"]/mu_atm,
                       Cf >= 0.455/Re**0.3
                      ]
github convexengineering / SPaircraft / VT_simple_profile_int.py View on Github external
#compute fuel burn from TSFC
            W_burn == aircraft['numeng']*self.engineP['TSFC'] * thours * self.engineP['thrust'],
               
            #time unit conversion
            t == thours,

            #make lift equal weight --> small angle approx in climb
            self.wingP['L_{wing}'] == W_avg,

            self.aircraft['l_{fuse}'] >= self.aircraft['\\Delta x_{lead_v}'] + self.fuseP['x_{CG}'],
            self.aircraft['x_{CG_{vt}}'] >= self.fuseP['x_{CG}']+(self.aircraft['\\Delta x_{lead_v}']+self.aircraft['\\Delta x_{trail_v}'])/2,
            ])

        Model.__init__(self, None, [self.Pmodels + constraints], **kwargs)

class ClimbP(Model):
    """
    Climb constraints
    """
    def __init__(self, aircraft, state, **kwargs):
        #submodels
        self.aircraft = aircraft
        self.aircraftP = AircraftP(aircraft, state)
        self.wingP = self.aircraftP.wingP
        self.fuseP = self.aircraftP.fuseP
        self.engineP = self.aircraftP.engineP
                                  
        #variable definitions
        theta = Variable('\\theta', '-', 'Aircraft Climb Angle')
        excessP = Variable('excessP', 'W', 'Excess Power During Climb')
        RC = Variable('RC', 'feet/min', 'Rate of Climb/Decent')
        dhft = Variable('dhft', 'feet', 'Change in Altitude Per Climb Segment [feet]')