Пример #1
0
def distance(vinit="10.0 m/s", acc="9.80665 m/s**2", time="30 s"):
    """
        Calculate the distance traveled by an object with some initial velocity,
        and a constant acceleration over a given time.

        Note that any units available in RocketUnits may be used
        as inputs for vinit, acc and time.

        Args:
            vinit (float): Initial velocity, m/s
            acc (float): Acceleration(standard gravity=9.80665), m/s**2
            time (float): Time, s
        
        Returns:
            float: Distance traveled, m
    """
    # let Units inspect the distance interface and get locals() values
    my_units = Units(distance, vars())
    GETVAL = my_units.get_input_value  # a convenience method

    # let Units convert inputs into internal units
    vinit = GETVAL("vinit")
    acc = my_units.get_input_value("acc")
    time = my_units.get_input_value("time")

    # with internal units, do the calculation
    d = vinit * time + acc * time**2 / 2.0
    return d  # d will always be in units of meters, m
Пример #2
0
    def __init__(self, x="4 ft**2", y="None psia", pdiff="10 psid"):
        self.my_io = Units( self.__class__, locals() )

        self.x = self.my_io.get_input_value("x")
        self.y = self.my_io.get_input_value("y")

        self.pdiff = self.my_io.get_input_value("pdiff")
        self.my_io.set_vars_dict( vars(self) )
        self.my_io.set_print_template( template="%s = %s %s")
Пример #3
0
class Bar:
    def __init__(self, xxx, x="4 ft**2", y="5 s", z="6 ft/s**2", j=66,
                 output_units="Both"):
        self.my_io = Units( self.__class__, locals() )

        self.x = self.my_io.get_input_value("x")
        self.y = self.my_io.get_input_value("y")
        self.z = self.my_io.get_input_value("z")
        self.j = j

        self.xxx = self.my_io.get_input_value("xxx", def_units="deg")

        self.xxx_x3 = 3.0 * self.xxx
        self.my_io.set_units_same_as("xxx_x3", "xxx")

    def summ_print(self):

        # give Units object the current locals()/vars()
        self.my_io.set_vars_dict( vars(self) )
        self.my_io.set_print_template( template="%12s = %-45s %s")

        u_print = self.my_io.u_print
        for name in self.my_io.default_unitsD.keys():
            u_print(name)

        print()
Пример #4
0
    def __init__(self, xxx, x="4 ft**2", y="5 s", z="6 ft/s**2", j=66,
                 output_units="Both"):
        self.my_io = Units( self.__class__, locals() )

        self.x = self.my_io.get_input_value("x")
        self.y = self.my_io.get_input_value("y")
        self.z = self.my_io.get_input_value("z")
        self.j = j

        self.xxx = self.my_io.get_input_value("xxx", def_units="deg")

        self.xxx_x3 = 3.0 * self.xxx
        self.my_io.set_units_same_as("xxx_x3", "xxx")
Пример #5
0
    def __init__(self, xxx, x="4 ft**2", y="5 s", z="6 ft/s**2", j=66, k=99,
                 output_units="Both", my_flag=True):
        self.my_io = Units( self.__class__, locals() )

        self.x = self.my_io.get_input_value("x")
        self.y = self.my_io.get_input_value("y")
        self.z = self.my_io.get_input_value("z")
        self.j = j

        self.xxx = self.my_io.get_input_value("xxx", def_units="deg")

        self.my_io.set_vars_dict( vars(self) )

        self.my_io.set_print_template( template="%s = %s %s")
Пример #6
0
    def __init__(self, d1="1 in", d2="2 inch", a1="1 in**2", a2="2 in**2",
                 v1="1 in**3", v2="2 inch**3", output_units="English"):
        self.my_io = Units( self.__class__, locals() )

        self.d1 = self.my_io.get_input_value("d1")
        self.d2 = self.my_io.get_input_value("d2")

        self.a1 = self.my_io.get_input_value("a1")
        self.a2 = self.my_io.get_input_value("a2")

        self.v1 = self.my_io.get_input_value("v1")
        self.v2 = self.my_io.get_input_value("v2")

        self.my_io.set_vars_dict( vars(self) )
        self.my_io.set_print_template( template="%s = %s %s")
Пример #7
0
class RocketDeltaV:

    gc = 32.174  # gravitational converstion factor lbm-ft/lbf-sec**2

    def __init__(self,
                 Isp="330.0 sec",
                 mass="10000.0 lbm",
                 prop_mass_frac=0.8):
        """
        Calculate the ideal rocket velocity based on the percent of propellant burned.
        (see: https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation)
        (or: https://www.translatorscafe.com/unit-converter/en-US/calculator/rocket-equation/)

        Args:
            Isp (float): specific impulse, sec (https://en.wikipedia.org/wiki/Specific_impulse)
            mass (float): total rocket mass, lbm
            prop_mass_frac (float): mass fraction of rocket that is propellant
        """
        # let Units inspect the class interface and get locals() values
        self.my_io = Units(self.__class__, locals())

        # let Units convert inputs into internal units (sec and lbm)
        self.Isp = self.my_io.get_input_value("Isp")
        self.mass = self.my_io.get_input_value("mass")
        self.prop_mass_frac = prop_mass_frac  # note: mass fraction is unitless

    def delta_v(self, pcent_burned=100.0):
        """
        Assuming a given percentage of the propellant is burned, 
        calculate the ideal change in velocity, ft/sec

        Args:
            pcent_burned (float): percent of propellant burned
        Returns:
            delta_v (float): ideal rocket velocity, ft/s
        """
        if pcent_burned < 0.0 or pcent_burned > 100.0:
            raise Exception("pcent_burned must be >=0 and <=100")
        prop_mass = (pcent_burned / 100.0) * self.prop_mass_frac * self.mass
        delta_v = self.gc * self.Isp * log(self.mass / (self.mass - prop_mass))
        return delta_v  # ft/s
Пример #8
0
    def __init__(self,
                 Isp="330.0 sec",
                 mass="10000.0 lbm",
                 prop_mass_frac=0.8):
        """
        Calculate the ideal rocket velocity based on the percent of propellant burned.
        (see: https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation)
        (or: https://www.translatorscafe.com/unit-converter/en-US/calculator/rocket-equation/)

        Args:
            Isp (float): specific impulse, sec (https://en.wikipedia.org/wiki/Specific_impulse)
            mass (float): total rocket mass, lbm
            prop_mass_frac (float): mass fraction of rocket that is propellant
        """
        # let Units inspect the class interface and get locals() values
        self.my_io = Units(self.__class__, locals())

        # let Units convert inputs into internal units (sec and lbm)
        self.Isp = self.my_io.get_input_value("Isp")
        self.mass = self.my_io.get_input_value("mass")
        self.prop_mass_frac = prop_mass_frac  # note: mass fraction is unitless
Пример #9
0
class Bar:
    def __init__(self,
                 xxx,
                 x="4 ft**2",
                 y="5 s",
                 z="6 ft/s**2",
                 j=66,
                 output_units="Both"):
        self.my_io = Units(self.__class__, locals())

        self.x = self.my_io.get_input_value("x")
        self.y = self.my_io.get_input_value("y")
        self.z = self.my_io.get_input_value("z")
        self.j = j

        self.xxx = self.my_io.get_input_value("xxx", def_units="deg")

    def summ_print(self):

        # give Units object the current locals()/vars()
        self.my_io.set_vars_dict(vars(self))
        self.my_io.set_print_template(template="%12s = %-45s | %s")

        print()
        u_print = self.my_io.u_print
        u_print("x", "area of interest")
        u_print("x")
        u_print("x", "area of interest", "inch**2", added_units="cm**2")

        print()
        u_print("xxx", desc="Angle of interest")
        u_print("xxx", primary_units="rad", desc="Angle of interest")
        u_print("xxx", "Angle of interest", "rad", "circle")

        print()
        u_print("y", desc="Time of flight", added_units="hr")
        u_print("j", desc="Just a Number")
Пример #10
0
def distance(vinit="10.0 m/s",
             acc="9.80665 m/s**2",
             time="30 s",
             output_units="SI"):
    """
        Calculate the distance traveled by an object with some initial velocity,
        and a constant acceleration over a given time.

        Note that any units available in RocketUnits may be used
        as inputs for vinit, acc and time.

        Args:
            vinit (float): Initial velocity, m/s
            acc (float): Acceleration(standard gravity=9.80665), m/s**2
            time (float): Time, s
        
        Returns:
            float: Distance traveled, m
    """
    # let Units inspect the distance interface and get locals() values
    my_units = Units(distance, vars())

    # let Units convert inputs into internal units
    vinit = my_units.get_input_value("vinit")
    acc = my_units.get_input_value("acc")
    time = my_units.get_input_value("time")

    # If using Units for output, tell Units the internal units for "d"
    my_units.set_units("d", "m")
    d = vinit * time + acc * time**2 / 2.0  # do the calculation with internal units

    # give local variable values to Units
    my_units.set_vars_dict(vars())
    # set a desired output template
    my_units.set_print_template(template="%8s = %-40s %s")
    # make a convenience copy of my_units.u_print
    u_print = my_units.u_print

    u_print("vinit", "Initial velocity")  # optional , fmt="%g"
    u_print("acc", "Acceleration")
    u_print("time", "Time")
    u_print("d", primary_units="km", added_units="yd")

    return d
Пример #11
0
class RocketDeltaV:

    gc = 32.174  # gravitational converstion factor lbm-ft/lbf-sec**2

    def __init__(self,
                 Isp="330.0 sec",
                 mass="10000.0 lbm",
                 prop_mass_frac=0.8):
        """
        Calculate the ideal rocket velocity based on the percent of propellant burned.
        (see: https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation)
        (or: https://www.translatorscafe.com/unit-converter/en-US/calculator/rocket-equation/)

        Args:
            Isp (float): specific impulse, sec (https://en.wikipedia.org/wiki/Specific_impulse)
            mass (float): total rocket mass, lbm
            prop_mass_frac (float): mass fraction of rocket that is propellant
        """
        # let Units inspect the class interface and get locals() values
        self.my_io = Units(self.__class__, locals())

        # let Units convert inputs into internal units (sec and lbm)
        self.Isp = self.my_io.get_input_value("Isp")
        self.mass = self.my_io.get_input_value("mass")
        self.prop_mass_frac = prop_mass_frac  # note: mass fraction is unitless

    def summarize_delta_v(self, pcent_burned=100.0, output_units="Both"):
        """
        Assuming a given percentage of the propellant is burned, 
        calculate the ideal change in velocity, ft/sec
        Print a summary of the calculation.

        Args:
            pcent_burned (float): percent of propellant burned
        Returns:
            delta_v (float): ideal rocket velocity, ft/s
        """
        if pcent_burned < 0.0 or pcent_burned > 100.0:
            raise Exception("pcent_burned must be >=0 and <=100")

        self.pcent_burned = pcent_burned
        self.prop_mass = (pcent_burned /
                          100.0) * self.prop_mass_frac * self.mass
        self.final_mass = self.mass - self.prop_mass
        self.delta_v = self.gc * self.Isp * log(self.mass / self.final_mass)

        # give Units object the current locals()/vars()
        self.my_io.set_output_units(output_units=output_units)
        self.my_io.set_vars_dict(vars(self))
        self.my_io.set_print_template(template="%16s = %-45s %s")
        self.my_io.set_units('prop_mass', 'lbm')
        self.my_io.set_units('pcent_burned', '')
        self.my_io.set_units('final_mass', 'lbm')
        self.my_io.set_units('delta_v', 'ft/s')

        # make a convenience copy of my_units.u_print
        u_print = self.my_io.u_print

        # lazy way to iterate over object parameters known to Units.
        for name in self.my_io.default_unitsD.keys():
            u_print(name)

        u_print("delta_v", primary_units="km/hr", added_units="mile/hr")
        print()