How to use the gpkit.ConstraintSet 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 / gplibrary / gpkitmodels / Commercial Sizing / engine_components.py View on Github external
constraints = [
                #define mtild
                mtildhc == mhc/mhcD,   #B.282

                #define ptild
                #SIGNOMIAL
                SignomialEquality(ptildhc * (pihcD-1), (pihc-1)),    #B.281
               
                #constrain the "knee" shape of the map, monomial is from gpfit
                ptildhc == ((N2**.28)*(mtildhc**-.00011))**10,
                ]
                
##            Model.__init__(self, 1/pihc, constraints, **kwargs)
            ConstraintSet.__init__(self, constraints, **kwargs)

class FanMap(ConstraintSet):
    """
    Implentation of TASOPT compressor map model. Map is claibrated with exponents from
    tables B.1 or B.2 of TASOPT, making the map realistic for the E3 fan.
    Map is used for off-design calculations, links with fan variables.
    """
    def __init__(self, **kwargs):
        #Temperature Variables
        Tt2 = Variable('T_{t_2}', 'K', 'Stagnation Temperature at the Fan Inlet (2)')
        Tref = Variable('T_{ref}', 'K', 'Reference Stagnation Temperature')

        #Mass Flow Variables
        mf = Variable('m_{f}', 'kg/s', 'Fan Corrected Mass Flow')
        mFan = Variable('m_{fan}', 'kg/s', 'Fan Mass Flow')
        mtildf = Variable('m_{tild_f}', '-', 'Fan Normalized Mass Flow')
        mFanD = Variable('m_{fan_D}', 'kg/s', 'Fan On-Design Mass Flow')
        mFanBarD = Variable('m_{fan_bar_D}', 'kg/s', 'Fan On-Design Corrected Mass Flow')
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components_offD.py View on Github external
import numpy as np
from gpkit import Model, Variable, SignomialsEnabled, units, SignomialEquality, ConstraintSet
from gpkit.constraints.tight import TightConstraintSet as TCS

#Cp and gamma values estimated from https://www.ohio.edu/mechanical/thermo/propeRy_tables/air/air_Cp_Cv.html

class FanAndLPC1(ConstraintSet):
    """
    Free Stream, Fan, and LPC Calcs for the Engine Model
    """
    def __init__(self, **kwargs):
        #air propeRies
        R = Variable('R', 287, 'J/kg/K', 'R')
        gammaAir = Variable('gamma_{air}', 1.4, '-', 'Specific Heat Ratio for Ambient Air')
        Cpair = Variable('Cp_{air}', 1003, 'J/kg/K', "Cp Value for Air at 250K")
        Cp1 = Variable('Cp_{1}', 1008, 'J/kg/K', "Cp Value for Air at 350K")#gamma = 1.398
        Cp2 = Variable('Cp_{2}', 1099, 'J/kg/K', "Cp Value for Air at 800K") #gamma = 1.354
        c1 = Variable('c1', 1.128, '-', 'Constant in Stagnation Eqn')

        #free stream
        T0 = Variable('T_0', 'K', 'Free Stream Stagnation Temperature')
        P0 = Variable('P_0', 'kPa', 'Free Stream Static Pressure')
        M0 = Variable('M_0', '-', 'Free Stream Mach Number')
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_atm.py View on Github external
lpcmap = LPCMap()
        hpcmap = HPCMap()

        res7 = 0
        m5opt = 0
        m7opt = 1
        
        offD = OffDesign(res7, m5opt, m7opt)

        #only add the HPCmap if residual 7 specifies a thrust
        if res7 ==0:
            self.submodels = [lpc, combustor, turbine, thrust, offD, fanmap, lpcmap, hpcmap]
        else:
            self.submodels = [lpc, combustor, turbine, thrust, offD, fanmap, lpcmap]
            
        constraints = ConstraintSet([self.submodels])

        constraints.subinplace({'TSFC_E': 'TSFC_E6', 'F_{spec}': 'F_{spec6}', 'M_0': 'M_0_6',
                                'T_0': 'T_0_6', 'P_0':'P_0_6'})
    

        lc = LinkedConstraintSet(constraints)

        substitutions = {
            'T_0_6': 240,   #36K feet
##            'P_0_6': 30,  
            'M_0_6': 0.8,
        }
        Model.__init__(self, None, lc, substitutions, **kwargs)
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_atm.py View on Github external
res7 = 1
        m5opt = 0
        m7opt = 0
        
        offD = OffDesign(res7, m5opt, m7opt)

        #only add the HPCmap if residual 7 specifies a thrust
        if res7 ==0:
            self.submodels = [lpc, combustor, turbine, thrust, offD, fanmap, lpcmap, hpcmap]
        else:
            self.submodels = [lpc, combustor, turbine, thrust, offD, fanmap, lpcmap, hpcmap]
            
        with SignomialsEnabled():

            constraints = ConstraintSet([self.submodels])

            constraints.subinplace({'M_0': 'M_0_1', 'T_0': 'T_0_1', 'P_0':'P_0_1'})

            lc = LinkedConstraintSet([self.submodels])

            substitutions = {
                'T_0_1': 240,#260,   #36K feet
                'T_{t_{4spec}}': 1400,
##                'P_0_1': 88,  
##                'M_0': 0.8,
            }
        
        Model.__init__(self, None, lc, substitutions, **kwargs)
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components.py View on Github external
])
                
            if m8opt == 1:
                #if M8 is greather than or equal to 1 add these constraints
                constraints.extend([
                    M7 == 1,
                    P7 == Pt7*(1.2)**(-3.5),
                    T7 == Tt7*(1.2)**-1
                    ])
                
        #objective is None because all constraints are equality so feasability region is a
        #single point which likely will not solve
##        Model.__init__(self, None, constraints, **kwargs)
        ConstraintSet.__init__(self, constraints, **kwargs)
    
class LPCMap(ConstraintSet):
    """
    Implentation of TASOPT compressor map model. Map is claibrated with exponents from
    tables B.1 or B.2 of TASOPT, making the maps realistic for the E3 compressor.
    Map is used for off-design calculations.
    Variables link with off design LPC variables.
    """
    def __init__(self, **kwargs):
        #Temperature Variables
        Tt2 = Variable('T_{t_2}', 'K', 'Stagnation Temperature at the Fan Inlet (2)')
        Tref = Variable('T_{ref}', 'K', 'Reference Stagnation Temperature')

        #Mass Flow Variables
        mlc = Variable('m_{lc}', 'kg/s', 'LPC Corrected Mass Flow')
        mCore = Variable('m_{core}', 'kg/s', 'Core Mass Flow')
        mtildlc = Variable('m_{tild_lc}', '-', 'LPC Normalized Mass Flow')
        mlcD = Variable('m_{lc_D}', 'kg/s', 'On Design LPC Corrected Mass Flow')
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components_offD.py View on Github external
#LPC exit (station 2.5)
            Pt25 == pilc * Pt2,
            Tt25 == Tt2 * pilc ** (.320961),
            ht25 == Tt25 * Cp1,

            #HPC Exit
            Pt3 == pihc * Pt25,
            Tt3 == Tt25 * pihc ** (.2947548622),
            ht3 == Cp2 * Tt3
            ]
##        Model.__init__(self, ht3, constraints, **kwargs)
        ConstraintSet.__init__(self, constraints, **kwargs)
        

class CombustorCooling1(ConstraintSet):
    """
    class to represent the engine's combustor and perform calculations
    on engine cooling bleed flow...cooling flow is currently not implemented
    """
    def __init__(self, **kwargs):
        #new vars
        #gas propeRies
        Cpc = Variable('Cp_c', 1204, 'J/kg/K', "Cp Value for Fuel/Air Mix in Combustor") #1400K
        
        #HPC exit state variables (station 3)
        Pt3 = Variable('P_{t_3}', 'kPa', 'Stagnation Pressure at the HPC Exit (3)')
        ht3 = Variable('h_{t_3}', 'J/kg', 'Stagnation Enthalpy at the HPC Exit (3)')
        
        #combustor exit state variables..recall Tt4 is already set in Engine class
        Pt4 = Variable('P_{t_4}', 'kPa', 'Stagnation Pressure at the Combustor Exit (4)')
        ht4 = Variable('h_{t_4}', 'J/kg', 'Stagnation Enthalpy at the Combustor Exit (4)')
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components_offD.py View on Github external
##                TCS([mhc == mCore*((Tt25/Tref)**.5)/(Pt25/Pref)]),    #B.280

                #define ptild
                #SIGNOMIAL
                SignomialEquality(ptildhc * (pihcD-1), (pihc-1)),    #B.281
               
                #constrain the "knee" shape of the map, monomial is from gpfit
                ptildhc == ((N2**.28)*(mtildhc**-.00011))**10,
                ]
                
##            Model.__init__(self, 1/pihc, constraints, **kwargs)
            ConstraintSet.__init__(self, constraints, **kwargs)
        


class FanMap1(ConstraintSet):
    """
    Implentation of TASOPT compressor map model. Map is claibrated with exponents from
    tables B.1 or B.2 of TASOPT, making the map realistic for the E3 fan.
    Map is used for off-design calculations, links with fan variables.
    """
    def __init__(self, **kwargs):
        #Temperature Variables
        Tt2 = Variable('T_{t_2}', 'K', 'Stagnation Temperature at the Fan Inlet (2)')
        Tref = Variable('T_{ref}', 'K', 'Reference Stagnation Temperature')

        #Mass Flow Variables
        mf = Variable('m_{f}', 'kg/s', 'Fan Corrected Mass Flow')
        mFan = Variable('m_{fan}', 'kg/s', 'Fan Mass Flow')
        mtildf = Variable('m_{tild_f}', '-', 'Fan Normalized Mass Flow')
        mFanD = Variable('m_{fan_D}', 'kg/s', 'Fan On-Design Mass Flow')
        mFanBarD = Variable('m_{fan_bar_D}', 'kg/s', 'Fan On-Design Corrected Mass Flow')
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components_offD.py View on Github external
##                
##            if m8opt == 1:
##                #if M8 is greather than or equal to 1 add these constraints
##                constraints.extend([
##                    M7 == 1,
##                    P7 == Pt7*(1.2)**(-3.5),
##                    T7 == Tt7*(1.2)**-1
##                    ])
                
        #objective is None because all constraints are equality so feasability region is a
        #single point which likely will not solve
##        Model.__init__(self, None, constraints, **kwargs)
        ConstraintSet.__init__(self, constraints, **kwargs)
        

class LPCMap1(ConstraintSet):
    """
    Implentation of TASOPT compressor map model. Map is claibrated with exponents from
    tables B.1 or B.2 of TASOPT, making the maps realistic for the E3 compressor.
    Map is used for off-design calculations.
    Variables link with off design LPC variables.
    """
    def __init__(self, **kwargs):
        #Temperature Variables
        Tt2 = Variable('T_{t_2}', 'K', 'Stagnation Temperature at the Fan Inlet (2)')
        Tref = Variable('T_{ref}', 'K', 'Reference Stagnation Temperature')

        #Mass Flow Variables
        mlc = Variable('m_{lc}', 'kg/s', 'LPC Corrected Mass Flow')
        mCore = Variable('m_{core}', 'kg/s', 'Core Mass Flow')
        mtildlc = Variable('m_{tild_lc}', '-', 'LPC Normalized Mass Flow')
        mlcD = Variable('m_{lc_D}', 'kg/s', 'On Design LPC Corrected Mass Flow')
github convexengineering / SPaircraft / Commerical_Flight_Profile_Simple_wing.py View on Github external
##            'V_{ne}': 144,
            '\\alpha_{max,w}': 0.1, # (6 deg)
            '\\cos(\\Lambda)': cos(sweep*pi/180),
            '\\eta_w': 0.97,
##            '\\rho_0': 1.225,
            '\\rho_{fuel}': 817, # Kerosene [TASOPT]
            '\\tan(\\Lambda)': tan(sweep*pi/180),
            'g': 9.81,
            }

        submodels = [cmc, climb, cruise, wing]

        for i in range(len(atmvec)):
            submodels.extend(atmvec[i])

        constraints = ConstraintSet([submodels])

        subs= {climb["AR"]: wing["AR_w"], cruise["AR"]: wing["AR_w"], cruise["S"]: wing["S_w"],
               climb["S"]: wing["S_w"], wing["W_{fuel}"]: cmc['W_{f_{total}}'],
               wing["W_{wing}"]: cmc['W_{wing}'], wing["b_w"]: cmc['span']}

        for i in range(Nclimb):
            subs.update({
                climb["\\rhoClimb"][i]: atmvec[i]["\\rho"],
                climb["TClimb"][i]: atmvec[i]["T_{atm}"], cmc['hftClimb'][i]: atmvec[i]["h"],
                wing["M"][i]: climb["MClimb"][i], climb['C_{D_wClimb}'] : wing['C_{D_w}'][i],
                climb['C_{L_{Climb}}']: wing["C_{L_w}"][i], climb['\\muClimb'][i]: atmvec[i]["\\mu"]
                })

        for i in range(Ncruise):
            subs.update({
                cruise["\\rhoCruise"][i]: atmvec[i + Nclimb]["\\rho"],
github convexengineering / gplibrary / gpkitmodels / Commercial Sizing / engine_components.py View on Github external
#define mtild
                mtildlc == mlc/mlcD,   #B.282

                #define ptild
                #SIGNOMIAL
                SignomialEquality(ptildlc * (pilcD-1), (pilc-1)),    #B.281
                
                #constrain the "knee" shape of the map, monomial is from gpfit
                ptildlc == ((N1**.28)*(mtildlc**-.00011))**10,
                ]
                
##            Model.__init__(self, 1/pilc, constraints, **kwargs)
            ConstraintSet.__init__(self, constraints, **kwargs)
        

class HPCMap(ConstraintSet):
    """
    Implentation of TASOPT compressor map model. Map is claibrated with exponents from
    tables B.1 or B.2 of TASOPT, making the maps realistic for the E3 compressor.
    Map is used for off-design calculations.
    Variables link with off design HPC variables.
    """
    def __init__(self, **kwargs):
        #Temperature Variables
        Tt25 = Variable('T_{t_2.5}', 'K', 'Stagnation Temperature at the LPC Exit (2.5)')
        Tref = Variable('T_{ref}', 'K', 'Reference Stagnation Temperature')

        #Mass Flow Variables
        mhc = Variable('m_{lc}', 'kg/s', 'HPC Corrected Mass Flow')
        mCore = Variable('m_{core}', 'kg/s', 'Core Mass Flow')
        mtildhc = Variable('m_{tild_hc}', '-', 'HPC Normalized Mass Flow')
        mhcD = Variable('m_{hc_D}', 'kg/s', 'On Design HPC Corrected Mass Flow')