示例#1
0
 def test_get_mod(self):
     gas = Gas(0.4, 0.6, 0)
     assert gas.get_mod() == pytest.approx(25, 0.1)
     assert gas.get_mod(surf_pressure=0.8) == pytest.approx(27, 0.1)
     assert gas.get_mod(1.6) == pytest.approx(30, 0.1)
     assert gas.get_mod(1.6, surf_pressure=0.8) == pytest.approx(32, 0.1)
     assert gas.get_mod(0.18) == 0
示例#2
0
    def test_valid_nitrox(self):
        f_o2 = 0.7
        f_n = 0.2
        f_he = 0.1
        gas = Gas(f_o2, f_n, f_he)

        assert gas.o2 == f_o2
        assert gas.n == f_n
        assert gas.he == f_he
示例#3
0
def solve_parameters(params):
    """
    Calculate results for gas, bed particle, biomass particle, and BFB reactor.

    Parameters
    ----------
    params : module
        Parameters from module file.

    Returns
    -------
    results : dict
        Results from calculations.
    """

    pm = params
    results = {}

    # Gas results
    gas = Gas(pm.gas['sp'], pm.gas['x'], pm.gas['p'], pm.gas['tk'])

    results['mw'] = gas.mw
    results['mug'] = gas.mu
    results['rhog'] = gas.rho

    # Bed particle results
    bed = Particle.from_params(pm.bed)

    umb = bed.calc_umb(gas)
    umb_umf = bed.calc_umb_umf(gas)
    umf_ergun = bed.calc_umf_ergun(pm.reactor['ep'], gas)
    umf_wenyu = bed.calc_umf_wenyu(gas)
    ut_bed_ganser = bed.calc_ut_ganser(gas)
    ut_bed_haider = bed.calc_ut_haider(gas)

    results['umb'] = umb
    results['umb_umf'] = umb_umf
    results['umf_ergun'] = umf_ergun
    results['umf_wenyu'] = umf_wenyu
    results['ut_bed_ganser'] = ut_bed_ganser
    results['ut_bed_haider'] = ut_bed_haider

    # Biomass particle results
    bio = Particle.from_params(pm.biomass)

    t_hc = bio.build_time_vector(pm.biomass['nt'], pm.biomass['t_max'])
    tk_hc = bio.calc_trans_hc(pm.biomass['b'], pm.biomass['h'],
                              pm.biomass['k'], pm.biomass['m'],
                              pm.biomass['mc'], t_hc, pm.biomass['tk_init'],
                              gas.tk)
    t_ref = bio.calc_time_tkinf(t_hc, tk_hc, gas.tk)
    tv, tv_min, tv_max = bio.calc_devol_time(gas.tk)
    ut_bio_ganser = bio.calc_ut_ganser(gas)
    ut_bio_haider = bio.calc_ut_haider(gas)

    results['t_hc'] = t_hc
    results['tk_hc'] = tk_hc
    results['t_ref'] = t_ref
    results['tv'] = tv
    results['tv_min'] = tv_min
    results['tv_max'] = tv_max
    results['ut_bio_ganser'] = ut_bio_ganser
    results['ut_bio_haider'] = ut_bio_haider

    # BFB reactor results
    bfb = BfbReactor(pm.reactor['di'], pm.reactor['q'], pm.reactor['zmf'])

    us = bfb.calc_us(gas)
    us_umf_ergun = bfb.calc_us_umf(us, umf_ergun)
    us_umf_wenyu = bfb.calc_us_umf(us, umf_wenyu)
    tdh_chan = bfb.calc_tdh_chan(us)
    tdh_horio = bfb.calc_tdh_horio(us)
    zexp_ergun = bfb.calc_zexp_ergun(bed, gas, umf_ergun, us)
    zexp_wenyu = bfb.calc_zexp_wenyu(bed, gas, umf_wenyu, us)

    results['ac'] = bfb.ac
    results['us'] = us
    results['us_umf_ergun'] = us_umf_ergun
    results['us_umf_wenyu'] = us_umf_wenyu
    results['tdh_chan'] = tdh_chan
    results['tdh_horio'] = tdh_horio
    results['zexp_ergun'] = zexp_ergun
    results['zexp_wenyu'] = zexp_wenyu

    return results
示例#4
0
def solve_diameters(params):
    """
    Calculate results for gas, bed particle, biomass particle, and BFB reactor
    for a range of particle diameters.

    Parameters
    ----------
    params : module
        Parameters from module file.

    Returns
    -------
    results : dict
        Results from calculations.
    """

    pm = params

    # Range of particle diameters for calculations
    dpmin = 0.00001
    dpmax = 0.001
    dps = np.linspace(dpmin, dpmax)

    # Calculations
    gas = Gas(pm.gas['sp'], pm.gas['x'], pm.gas['p'], pm.gas['tk'])
    bed = Particle.from_params(pm.bed)
    bio = Particle.from_params(pm.biomass)
    bfb = BfbReactor(pm.reactor['di'], pm.reactor['q'], pm.reactor['zmf'])

    ep = pm.reactor['ep']
    us = bfb.calc_us(gas)

    umf_ergun = []
    umf_wenyu = []
    ut_bed_ganser = []
    ut_bed_haider = []
    ut_bio_ganser = []
    ut_bio_haider = []

    for dp in dps:
        bed.dp = dp
        bio.dp = dp

        umfergun = bed.calc_umf_ergun(ep, gas)
        umfwenyu = bed.calc_umf_wenyu(gas)
        utbed_ganser = bed.calc_ut_ganser(gas)
        utbed_haider = bed.calc_ut_haider(gas)
        utbio_ganser = bio.calc_ut_ganser(gas)
        utbio_haider = bio.calc_ut_haider(gas)

        umf_ergun.append(umfergun)
        umf_wenyu.append(umfwenyu)
        ut_bed_ganser.append(utbed_ganser)
        ut_bed_haider.append(utbed_haider)
        ut_bio_ganser.append(utbio_ganser)
        ut_bio_haider.append(utbio_haider)

    # Store results
    results = {}
    results['dps'] = dps
    results['us'] = us
    results['umf_ergun'] = umf_ergun
    results['umf_wenyu'] = umf_wenyu
    results['ut_bed_ganser'] = ut_bed_ganser
    results['ut_bed_haider'] = ut_bed_haider
    results['ut_bio_ganser'] = ut_bio_ganser
    results['ut_bio_haider'] = ut_bio_haider

    return results
def solve_temperatures(params):
    """
    Calculate results for gas, bed particle, biomass particle, and BFB reactor
    for a range of temperatures.

    Parameters
    ----------
    params : module
        Parameters from module file.

    Returns
    -------
    results : dict
        Results from calculations.
    """

    pm = params

    # Range of temperatures for calculations
    tk = pm.gas['tk']
    tk_min = pm.gas['tk_min']
    tk_max = pm.gas['tk_max']
    tks = [tk_min, tk, tk_max]

    # Calculations
    bed = Particle.from_params(pm.bed)
    bio = Particle.from_params(pm.biomass)
    bfb = BfbReactor(pm.reactor['di'], pm.reactor['q'], pm.reactor['zmf'])

    ep = pm.reactor['ep']
    tv_list = []
    tv_min_list = []
    tv_max_list = []
    umb_list = []
    umb_umf_list = []
    umf_ergun_list = []
    umf_wenyu_list = []
    us_list = []
    us_umf_ergun_list = []
    us_umf_wenyu_list = []
    ut_bed_ganser_list = []
    ut_bed_haider_list = []
    ut_bio_ganser_list = []
    ut_bio_haider_list = []

    for tk in tks:
        gas = Gas(pm.gas['sp'], pm.gas['x'], pm.gas['p'], tk)

        tv, tv_min, tv_max = bio.calc_devol_time(tk)
        umb = bed.calc_umb(gas)
        umb_umf = bed.calc_umb_umf(gas)
        umf_ergun = bed.calc_umf_ergun(ep, gas)
        umf_wenyu = bed.calc_umf_wenyu(gas)
        us = bfb.calc_us(gas)
        us_umf_ergun = bfb.calc_us_umf(us, umf_ergun)
        us_umf_wenyu = bfb.calc_us_umf(us, umf_wenyu)
        ut_bed_ganser = bed.calc_ut_ganser(gas)
        ut_bed_haider = bed.calc_ut_haider(gas)
        ut_bio_ganser = bio.calc_ut_ganser(gas)
        ut_bio_haider = bio.calc_ut_haider(gas)

        tv_list.append(tv)
        tv_min_list.append(tv_min)
        tv_max_list.append(tv_max)
        umb_list.append(umb)
        umb_umf_list.append(umb_umf)
        umf_ergun_list.append(umf_ergun)
        umf_wenyu_list.append(umf_wenyu)
        us_list.append(us)
        us_umf_ergun_list.append(us_umf_ergun)
        us_umf_wenyu_list.append(us_umf_wenyu)
        ut_bed_ganser_list.append(ut_bed_ganser)
        ut_bed_haider_list.append(ut_bed_haider)
        ut_bio_ganser_list.append(ut_bio_ganser)
        ut_bio_haider_list.append(ut_bio_haider)

    # Store results
    results = {}
    results['tks'] = tks
    results['tv'] = tv_list
    results['tv_min'] = tv_min_list
    results['tv_max'] = tv_max_list
    results['umb'] = umb_list
    results['umb_umf'] = umb_umf_list
    results['umf_ergun'] = umf_ergun_list
    results['umf_wenyu'] = umf_wenyu_list
    results['us'] = us_list
    results['us_umf_ergun'] = us_umf_ergun_list
    results['us_umf_wenyu'] = us_umf_wenyu_list
    results['ut_bed_ganser'] = ut_bed_ganser_list
    results['ut_bed_haider'] = ut_bed_haider_list
    results['ut_bio_ganser'] = ut_bio_ganser_list
    results['ut_bio_haider'] = ut_bio_haider_list

    return results
示例#6
0
from machine import I2C

i2c = I2C(0, I2C.MASTER)
from gas import Gas

g = Gas(i2c)
g.gas_dump()
示例#7
0
 def __init__(self):
     Vehicle.__init__(self, "Dodge", "Ram", 120, 4)
     Gas.__init__(self, 26)
示例#8
0
 def drive(self):
     Electric.drive(self, 2)
     Gas.drive(self, 0.5)
示例#9
0
        "Density of the fluid diving in (decimal, kg/m^3) [1000]: ",
        0,
        15000,
        default_value=1000)
    gravity = UserInput().getFloatInput(
        "Gravitational acceleration (decimal, m/s^2) [9.81]: ",
        0,
        25,
        default_value=9.81)
    ppo2 = UserInput().getFloatInput("Max PPO2 (decimal, bar) [1.4]: ",
                                     0,
                                     100,
                                     default_value=1.4)

    f_n = 1 - f_o2 - f_he
    gas = Gas(f_o2, f_n, f_he)

    round_places = 2
    mod = gas.get_mod(ppo2=ppo2,
                      density=density,
                      surf_pressure=surf_pressure,
                      gravity=gravity)

    print("")
    print("MOD at " + str(ppo2) + " bars for " + str(gas))
    print("With a surface pressure of " + str(surf_pressure) + " bar")
    print("Density of fluid: " + str(density) + " kg/m^3")
    print("Gravitational acceleration: " + str(gravity) + " m/s^2")
    print("MOD: " + str(round(mod, 2)) + " m")
    print("")
示例#10
0
while not extended_mode:
    print("")

    f_o2 = UserInput().getFloatInput("Fraction of oxygen (decimal) [0.21]: ",
                                     0.01,
                                     1,
                                     default_value=0.21)
    f_he = UserInput().getFloatInput("Fraction of helium (decimal) [0]: ",
                                     0, (1 - f_o2),
                                     default_value=0)
    surf_pressure = UserInput().getFloatInput(
        "Surface pressure (decimal, bar) [1]: ", 0, 1.1, default_value=1)
    f_n = 1 - f_o2 - f_he

    gas = Gas(f_o2, f_n, f_he)

    fresh_min_od = gas.get_mod(CONST.MIN_PPO2,
                               CONST.DENSITY_FRESHWATER,
                               surf_pressure=surf_pressure)
    fresh_mod = gas.get_mod(CONST.MAX_PPO2,
                            CONST.DENSITY_FRESHWATER,
                            surf_pressure=surf_pressure)
    fresh_mod_deco = gas.get_mod(CONST.MAX_PPO2_DECO,
                                 CONST.DENSITY_FRESHWATER,
                                 surf_pressure=surf_pressure)
    salt_min_od = gas.get_mod(CONST.MIN_PPO2,
                              CONST.DENSITY_SALTWATER,
                              surf_pressure=surf_pressure)
    salt_mod = gas.get_mod(CONST.MAX_PPO2,
                           CONST.DENSITY_SALTWATER,
示例#11
0
 def __init__(self):
     Vehicle.__init__(self, "Ford", "Mustang", 460, 4)
     Gas.__init__(self, 20)
def demo_of_methanol_equlibrium():
        fig = plt.figure()
        fig.subplots_adjust(bottom=0.2, left=0.2, right = 0.8) # Make room for x-label
        ratio = 0.61803398             # Golden mean
        ratio = 0.4                     # This figure should be very wide to span two columns
        fig_width = 14.5
        fig_width = fig_width /2.54     # width in cm converted to inches
        fig_height = fig_width*ratio
        fig.set_size_inches(fig_width,fig_height)
        axis = fig.add_subplot(1,1,1)
        axis.semilogy()
        axis2 = axis.twinx()
         # in K
        Y = {}
        for mol in [km.H2, km.CO2, km.CO, km.H2O, km.CH3OH]:
            Y[mol] = []
        Pressure = 2.5
        reaction1 = {km.CO2: 0.0, km.H2: -2.0, km.CO: -1.0, km.CH3OH: 1.0, km.H2O: 0.0}
        reaction2 = {km.CO2: -1.0, km.H2: -1.0, km.CO: 1.0, km.CH3OH: 0.0, km.H2O: 1.0}
        amount_of_CO = 0.0
        amount_of_CO2 = 0.25
        amount_of_H2 = float(1.0-float(amount_of_CO+amount_of_CO2))
        Temperature = 400.
        gas_0 = Gas({km.H2: amount_of_H2, 
                     km.CO: amount_of_CO,
                     km.CO2: amount_of_CO2,
                     km.CH3OH: 0.0,
                     km.H2O: 0.0},temperature=Temperature)
        gas_0.set_pressure(Pressure)
        guess_new = [0.001,0.001]
        eq_result_0 = gas_0.gas_equlibrium_v2([reaction1,reaction2], guess=guess_new, T=Temperature)
        guess_last = eq_result_0[1]
        guess_new = guess_last
        step = 0.5*max(abs(guess_last - guess_new))
        CS = MeOH_control_set(2.5,cH2=0.75,cCO2=0.25,cCO=0.0,cMeOH=0.0,cH2O=0.0)
        for mol in ['MeOH','CO2', 'H2', 'CO', 'H2O']:
            CS[mol] = np.array(CS[mol])/100.*Pressure
        CS['T'] = np.array(CS['T']) +273.15
        T = CS['T']
        for t_i in T:
            print('Temperature: ' + str(t_i))
            Temperature = t_i
            gas_0 = Gas({km.H2: amount_of_H2, 
                     km.CO: amount_of_CO,
                     km.CO2: amount_of_CO2,
                     km.CH3OH: 0.0,
                     km.H2O: 0.0},temperature=Temperature)
            gas_0.set_pressure(Pressure)
            eq_result_0 = gas_0.gas_equlibrium_v2([reaction1,reaction2], guess=guess_new, step=step, T=Temperature)
            guess_last = eq_result_0[1]
            guess_new = guess_last + 0.5*(guess_last - guess_new)
            step = 0.5*max(abs(guess_last - guess_new))
            #gas_0.plot_guess_historic(filename = 'fig-guess/' + str(t_i))
            for mol in [km.H2, km.CO2, km.CO, km.H2O, km.CH3OH]:
                Y[mol] += [eq_result_0[0].partial_pressures[mol]]
        for mol in [km.H2, km.CO2, km.CO, km.H2O, km.CH3OH]:
            Y[mol] = np.array(Y[mol])
        print('Calculation are Done')
        #print Y[km.CH3OH]
        color_list_mol = {km.CH3OH:'m', km.H2O:'b', km.CO:'r', km.CO2:'g', km.H2:'c'}
        for mol in [km.H2, km.CO2, km.CO, km.H2O, km.CH3OH]:
            axis.plot(T,Y[mol],color_list_mol[mol]+'-')
        color_list = {'MeOH':'m', 'H2O':'b', 'CO':'r', 'CO2':'g', 'H2':'c'}
        for mol in ['MeOH','CO2', 'H2', 'CO', 'H2O']:
            axis.plot(CS['T'], CS[mol],color_list[mol]+'--')
        axis2.plot(CS['T'], (Y[km.CH3OH] - CS['MeOH'])/CS['MeOH'], 'k-')
        """axis.annotate('6nm 20% coverage', xy=(15, 4calculate_partial_pressuresE-4),  xycoords='data',
                xytext=(10, 0.01), textcoords='data',
                horizontalalignment='left', verticalalignment='top',
                arrowprops=dict(arrowstyle='->',facecolor=color_list['MR260'],edgecolor=color_list['MR260']),fontsize=8,color=color_list['MR260']
                )"""
        #axis.set_ylim(1e-13,1E-6)
        axis2.set_ylim(-0.1,0.1)
        plt.xlim(300,600)
        #axis.legend(loc='upper right',prop={'size':6})
        axis.grid(False) 
        axis.tick_params(direction='in', length=6, width=1, colors='k',labelsize=8,axis='both',pad=3)
        axis2.tick_params(direction='in', length=6, width=1, colors='k',labelsize=8,axis='both',pad=3)
        axis.set_xlabel('Temperature / [C]', fontsize=8)
        axis.set_ylabel('Pressure / [bar]', fontsize=8)
        axis2.set_ylabel('Error in fraction', fontsize=8)
        #plt.tight_layout()
        #plt.show()
        print('Saving')
        plt.savefig('demo_2 test.png',dpi=600)
        plt.clf()
        plt.close()
        #del fig
        pass
示例#13
0
def run_rocket_config(ri, rf, L0, ngrain, Ae_At_0, At_0, mass_ballast_0, T_bi):

    # givens/constants
    n = 0.35
    a0 = 0.030 * units["(in / s) * (lbf / in^2) ^ -0.35"]
    sigma_p = 0.001 * units["1/F"]
    c_star = 5210 * units["ft/s"]
    rho_p = 0.065 * units["lb/in^3"]
    T_b0 = 70.0 * units["F"]
    # T_bi = 70.0 * units["F"]
    w_step = (0.01 * units["in"])
    k_exhaust = 1.3
    grain_spacing = 0.125 * units["in"]
    mass_ballast = mass_ballast_0
    mass_structure = 40.0 * units["lb"]
    mass_per_length = 0.25 * units["lb/in"]

    # maxes
    MAX_PRESSURE = 1000.0 * units["psi"]
    MAX_ACCELERATION = 15.0 * units[""]
    MAX_CASE_LENGTH = 34.0 * units["in"]

    # L[i]sts / dynamic vars
    r = []                      # radius of propellant
    L = []                      # length of propellant
    At = []                     # throat area
    Ae_At = []                  # area ratio
    w = []                      # web distance
    time = []                   # time 
    delDt = []                  # change in diameter at the throat
    CF = []                     # coefficient of thrust
    thrust = []                 # thrust
    It = []                     # total impulse
    Is = []                     # specific impulse
    rate = []                   # burn rate
    throat_diameter = []        # diameter at throat
    mass_propellant = []        # mass of propellant
    burn_area = []                 # area of burn
    p1 = []                     # chamber pressure
    ambient_gas = []              # list of gas properties (Gas class)
    Is_compute = []                     # specific impulse

    # pr4 / phyics variables
    altitude = []
    velocity = []
    acceleration = []
    mach = []
    drag_coeff = []
    drag = []
    F_M = []                    # force over mass term for force balance
    D_M = []                    # drag over mass term for force balance
    
    # vehicle characteristics
    vehicle_mass = []
    vehicle_diameter = 6.19 * units("in")
    vehicle_cx_area = np.pi * vehicle_diameter ** 2 / 4.0

    # initial values
    r.append(ri)    
    L.append(L0)
    At.append(At_0)
    Ae_At.append(Ae_At_0)
    w.append(0.0 * units["in"])
    time.append(0.0 * units["s"])
    It.append(0.0 * units["lbf * sec"])
    Is.append(0.0 * units["sec"])
    Is_compute.append(0.0 * units["sec"])
    throat_diameter.append(np.sqrt(4.0 * At[0] / np.pi))
    altitude.append(0 * units("ft"))                      # altitude of H untsville, AL

    # initial physics
    velocity.append(0.0 * units("ft/s"))
    
    # misc initial calculations
    Ae = Ae_At[0] * At[0]
    w_max = calc_w_max(r[0],rf,L[0])
    mass_case = 4.0 * mass_per_length * (L[0] + grain_spacing)

    burned_out = False
    output=[]
    physics_output=[]
    i = 0
    burnout_it = -1
    last_it = -1
    It_total = It[0]

    # pre-run design constraints
    Aport_At0 = np.pi * r[0] ** 2 / At[0]
    case_length = (L0 + grain_spacing) * ngrain 
    if(Aport_At0 < 2.0):
        print("Invalid Configuration: A_p,0 / A_t,0 > 2.0 (%s)" % Aport_At0)
        return 0.0        
    if(case_length > MAX_CASE_LENGTH):
        print("Invalid Configuration: case length > 34.0 in (%s)" % case_length)
        return 0.0

    # loop while propellant isn't burned out
    while(True):

        #time dependent values that rely on previous value
        if(i > 0):
            velocity.append(velocity[i-1] + acceleration[i-1] * (time[i] - time[i-1]))
            altitude.append(altitude[i-1] + (velocity[i] + velocity[i-1]) / 2 * (time[i] - time[i-1]))
            
            if(altitude[i] < 0.0):
                time.pop()
                altitude.pop()
                velocity.pop()
                break
        elif(i > 1000):
            print("Trajectory timeout!")
            break
            
        # update gas state
        ambient_gas.append(Gas("air",altitude[i]))

        #with T[i] calculate Mach number and the CD
        mach.append(velocity[i] / ambient_gas[i].speed_of_sound)
        drag_coeff.append(drag_coefficient_from_mach(mach[i]) * units[""])
        drag.append(0.5 * ambient_gas[i].density * drag_coeff[i] * velocity[i] ** 2 * vehicle_cx_area)

        if(velocity[i-1] < 0):
            time.pop()
            altitude.pop()
            velocity.pop()
            last_it = i
            break
            drag[i] *= -1
        
        # calculate area of current burn surface
        burn_area.append(burn_surface_area(L[i], r[i], rf, ngrain))

        # if propellant is still burning
        if(not burned_out):

            p1.append(chamber_pressure(burn_area[i], At[i], rho_p, T_bi, T_b0, a0, sigma_p, c_star, n))
            rate.append(burning_rate(T_bi, T_b0, a0, sigma_p, p1[i], n))

            # calculate force stuff
            # print("%s / %s = %s" % (p1[i], ambient_gas[i].pressure, p1[i] / ambient_gas[i].pressure))
            CF.append(CF2(k_exhaust,Ae_At[i], p1[i] / ambient_gas[i].pressure))
            thrust.append(CF[i] * p1[i] * At[i])
            mass_propellant.append(mass_of_propellant(L[i], r[i], rf, rho_p, ngrain))
            
            # after one iteration, we can calculate impulse
            if(i > 0):
                It.append(0.5*(thrust[i] + thrust[i - 1])*(time[i] - time[i - 1]))
                Is.append(It[i] * lbfToLbm / ((mass_propellant[i - 1] - mass_propellant[i]) * g0_EN))

            # check this or next step will burnout, if so, do half step instead
            if(w[i] >= w_max):
                burned_out = True
            else:

                w.append(w[i] + w_step)         # current web distance
                L.append(L[0] - 2 * w[i + 1])   # current grain length (decreases w[i]th burn)
                r.append(r[0] + w[i + 1])       # current radius (increases w[i]th burn)

                # calculate new time step from burn rate
                time.append(time[i] + w_step / rate[i]) 

                # calculate change in diameter at throat
                delDt.append(0.000087 * units["in ^ 3 / s / lbf"] * p1[i] * (time[i + 1] - time[i]))

                if(w[i + 1] + w_step > w_max):
                    w_step = 0.005 * units["in"]
                    burnout_it = i


        # else if propellant is all burned up
        else:
            It.append(0.0 * It[0])
            Is.append(0.0 * Is[0])
            p1.append(0.0 * p1[0])
            rate.append(0.0 * rate[0])
            CF.append(0.0 * CF[0])
            thrust.append(0.0 * thrust[0])

        # same as else above, but we want it to happen the first time burn is turned off
        if(burned_out):  

            mass_propellant.append(0 * mass_propellant[0])

            w.append(w[i])
            L.append(L[0] - 2 * w[i + 1])   # current grain length (decreases w[i]th burn)
            r.append(r[0] + w[i + 1])       # current radius (increases w[i]th burn)

            # switch to 0.1 time step
            time.append(time[i] + 0.1 * units["s"])
            delDt.append(0.0 * delDt[0])

        vehicle_mass.append(mass_ballast + mass_propellant[i] + mass_structure + mass_case)

        F_M.append(thrust[i] / vehicle_mass[i] * lbfToLbm)
        D_M.append(drag[i] / vehicle_mass[i])
        acceleration.append(F_M[i] - D_M[i] - g0_EN)

        ## New Step ## 
        # The following calcs had initial value and utilize the above values #
        # i.e. a lot of [i + 1]'s #

        # get new area at throat
        throat_diameter.append(throat_diameter[i] + delDt[i])
        At.append(np.pi * (throat_diameter[i + 1] / 2) ** 2)
        Ae_At.append(Ae / At[i + 1])
        # print("%s\t%s\t%s\t%s\n" % (time[i],vehicle_mass[i], w[i], velocity[i]))

        It_total += It[i]

        # check if iteration violates any condition
        if(acceleration[i] / g0_EN >= MAX_ACCELERATION):
            print("Invalid Configuration: exceeded max acceleration")
            print("--> %s >= %s" % (acceleration[i] / g0_EN, MAX_ACCELERATION))
            return 0.0
        if(p1[i] > MAX_PRESSURE):
            print("Invalid Configuration: exceeded max pressure")
            return 0.0
        if(CF[i] < CFmin(Ae_At[i]) and not burned_out):
            print("Invalid Configuration: below min CF")
            # pressure_p = np.array([val.magnitude for val in p1]) 
            # print("%f, %f, %f" %(np.min(pressure_p), np.mean(pressure_p), np.max(pressure_p)))

            return 0.0

        # output
        p1[i].ito("psi")
        output.append([w[i],burn_area[i],mass_propellant[i] ,time[i],throat_diameter[i],At[i] 
            ,p1[i] ,CF[i],thrust[i],It[i],rate[i],delDt[i],Ae_At[i]])
        physics_output.append([time[i],vehicle_mass[i],velocity[i],altitude[i],
            ambient_gas[i].pressure,ambient_gas[i].temperature,ambient_gas[i].speed_of_sound,mach[i],
            drag_coeff[i],ambient_gas[i].density,F_M[i],D_M[i],acceleration[i]])

        #increment i
        i += 1

    # for i in range(0,len(It)):
    #     print("%s \t %s \t %s" % (It[i], mass_propellant[i], Is[i]))
    # pressure_p = np.array([val.magnitude for val in p1]) 
    # print(np.mean(pressure_p))
    # return max(altitude).magnitude

    headers = ["web burned", "area", "mass", "time", "Dt ", "At", "P1_e", "C_F", "F_e", "I", "r", "del d", "Ae/At"]
    physics_headers = ["time", "Mveh", "velocity", "altitude", "p3", "temperature", "a", "Mach", "C_d", "rho_3", "F/M", "D/M", "acceleration"]
    # print_output_table(headers,output)
    # print_output_table(physics_headers,physics_output)
    # write_output_table(headers,output,"param_data.txt")
    # write_output_table(physics_headers,physics_output,"physics_data.txt")

    if(burnout_it == -1):
        # print("Warning: no burnout!")
        burnout_it = last_it        

    # convert pint arrays to numpy for plotting/processing
    Is_sub = Is[0:burnout_it]
    Is_p = np.array([val.to_base_units().magnitude for val in Is_sub]) 
    It_p = np.array([val.to_base_units().magnitude for val in It]) 
    time_p = np.array([val.to_base_units().magnitude for val in time]) 
    mp_p = np.array([val.magnitude for val in mass_propellant])
    p1_p = np.array([val.magnitude for val in p1]) 
    F_p = np.array([val.magnitude for val in thrust]) 
    CF_p = np.array([val.magnitude for val in CF]) 
    Ae_At_p = np.array([val.magnitude for val in Ae_At]) 
    acceleration_p = np.array([val.magnitude for val in acceleration]) 
    velocity_p = np.array([val.magnitude for val in velocity]) 
    altitude_p = np.array([val.magnitude for val in altitude]) 

    # Misc post calculations
    Is_ave = (It_total / mass_propellant[0].magnitude)
    max_altitude = max(altitude).magnitude

    config_folder = "results/final/%d" % int(max_altitude)
    if(not os.path.isdir(config_folder)):
        os.mkdir(config_folder)
    matplotlib.rcParams.update({'font.size': 14})
    plt.plot(time_p[:burnout_it],mp_p[:burnout_it])
    plt.xlabel("time [s]")
    plt.ylabel("mass of propellant [kg]")
    plt.savefig("results/final/%d/mass_propellant.png" % int(max_altitude))
    plt.clf()

    plt.plot(time_p[:burnout_it],p1_p[:burnout_it])
    plt.xlabel("time [s]")
    plt.ylabel("chamber pressure [kg]")
    plt.savefig("results/final/%d/chamber_pressure.png" % int(max_altitude))
    plt.clf()

    plt.plot(time_p[:burnout_it],F_p[:burnout_it])
    plt.xlabel("time [s]")
    plt.ylabel("thrust [kg]")
    plt.savefig("results/final/%d/thrust.png" % int(max_altitude))
    plt.clf()

    plt.plot(time_p,acceleration_p)
    plt.xlabel("time [s]")
    plt.ylabel("acceleration [ft/s^2]")
    plt.savefig("results/final/%d/acceleration.png" % int(max_altitude))
    plt.clf()

    plt.plot(time_p,velocity_p)
    plt.xlabel("time [s]")
    plt.ylabel("velocity [ft/s]")
    plt.savefig("results/final/%d/velocity.png" % int(max_altitude))
    plt.clf()

    plt.plot(time_p,altitude_p)
    plt.xlabel("time [s]")
    plt.ylabel("altitude [ft]")
    plt.savefig("results/final/%d/altitude.png" % int(max_altitude))
    plt.clf()

    Plot3_7_PR09(Ae_At_p[:burnout_it],CF_p[:burnout_it]).savefig("results/final/%d/thrust_coefficient.png" % int(max_altitude))
    plt.clf()
    # print("")
    # print("It_total: %s" % np.sum(It_p))
    # print("Is_ave: %s" % Is_ave)
    # print("P1_max %s" % max(p1))
    # print("F_max %s" % max(thrust))
    # print("Aport / At_0: %s" % Aport_At0)

    # print("A_max %s" % max(altitude))
    burnout_it = burnout_it - 1
    print("%.3f | %.3f | %.3f | %.3f |%.3f | %.3f | %.3f" % (mp_p[0],burn_area[0].magnitude,time[burnout_it].magnitude,
            Is_ave.magnitude, max(p1).magnitude,max(thrust).magnitude, Aport_At0.magnitude))
    print("%.3f | %.3f | %.3f | %.3f |%.3f | %.3f |%.3f | %.3f | %.3f" % (mass_case.magnitude, 
        vehicle_mass[0].magnitude, altitude[burnout_it].magnitude, velocity[burnout_it].magnitude, acceleration[burnout_it].magnitude,
        max_altitude, max(velocity).magnitude, max(acceleration).magnitude, max(acceleration).magnitude / g0_EN.magnitude))
    # print(" = %f ft" % max_altitude)
    return (mp_p[0],burn_area[0].magnitude,time[burnout_it].magnitude,
            Is_ave.magnitude, max(p1).magnitude,max(thrust).magnitude, Aport_At0.magnitude, 
            max_altitude, max(velocity).magnitude, max(acceleration).magnitude)
示例#14
0
 def __init__(self):
     Vehicle.__init__(self, "Subaru", "Crosstrek", 60, 4)
     Gas.__init__(self, 40)
     Electric.__init__(self, 6)
示例#15
0
    def test_pressure_at_ppo2(self):
        gas = Gas(0.21, 0.79, 0)

        assert gas.pressure_at_ppo2(1.4) == pytest.approx(6.66666666)
        assert gas.pressure_at_ppo2(1.6) == pytest.approx(7.61904761)
示例#16
0
 def drive(self):
     Gas.drive(self, 6)
示例#17
0
 def refuel(self):
     Electric.refuel(self)
     Gas.refuel(self)