motorlib.geometry
¶
This module includes the geometry methods that openMotor uses in its calculations
-
motorlib.geometry.
circleArea
(dia)¶ Returns the area of a circle with diameter dia
-
motorlib.geometry.
circleDiameterFromArea
(area)¶ Returns the diameter of a circle with area ‘area’
-
motorlib.geometry.
circlePerimeter
(dia)¶ Returns the perimeter (circumference) of a circle with diameter dia
-
motorlib.geometry.
clean
(contour, mapSize, tolerance)¶ Returns a contour with the same points as the input, omitting any within ‘tolerace’ of a circle of diameter ‘mapSize’
-
motorlib.geometry.
cylinderArea
(dia, height)¶ Returns the surface area of a cylinder with diameter ‘dia’ and height ‘height’
-
motorlib.geometry.
cylinderVolume
(dia, height)¶ Returns the volume of a cylinder with diameter ‘dia’ and height ‘height’
-
motorlib.geometry.
dist
(point1, point2)¶ Returns the distance between two points [x1, y1], [x2, y2]
-
motorlib.geometry.
length
(contour, mapSize, tolerance=3)¶ Returns the total length of all segments in a contour that aren’t within ‘tolerance’ of the edge of a circle with diameter ‘mapSize’
-
motorlib.geometry.
tubeArea
(dia, height)¶ Returns the surface area of a tube (cylinder without endcaps) with diameter ‘dia’ and height ‘height’
motorlib.grain
¶
This module includes the base classes from which all grain classes should inherit. None of these objects should be instantiated directly.
-
class
motorlib.grain.
FmmGrain
¶ A grain that uses the fast marching method to calculate its regression. All a subclass has to do is provide an implementation of generateCoreMap that makes an image of a cross section of the grain.
-
areaToMap
(value)¶ Used to convert sqm to sq pixels, like on the regression map.
-
abstract
generateCoreMap
()¶ Use self.mapX and self.mapY to generate an image of the grain cross section in self.coreMap. A 0 in the image means propellant, and a 1 means no propellant.
-
generateRegressionMap
()¶ Uses the fast marching method to generate an image of how the grain regresses from the core map. The map is stored under self.regressionMap.
-
getCorePerimeter
(regDist)¶ Returns the perimeter of the core after the grain has regressed a distance of ‘regDist’.
-
getFaceArea
(regDist)¶ Returns the area of the grain face after it has regressed a distance of ‘regDist’. This is the same as the area of an equal-diameter endburning grain minus the grain’s port area.
-
getFaceImage
(mapDim)¶ Returns an image of the grain’s cross section, with resolution (mapDim, mapDim).
-
getRegressionData
(mapDim, numContours=15, coreBlack=True)¶ Returns a tuple that includes a grain face image as described in ‘getFaceImage’, a regression map where color maps to regression depth, a list of contours (lists of (x,y) points in image space) of equal regression depth, and a list of corresponding contour lengths. The contours are equally spaced between 0 regression and burnout.
-
initGeometry
(mapDim)¶ Set up an empty core map and reset the regression map. Takes in the dimension of both maps.
-
lengthToMap
(value)¶ Converts meters to pixels. Used to compare real distances to pixel distances in the regression map.
-
mapToArea
(value)¶ Used to convert sq pixels to sqm. For extracting real areas from the regression map.
-
mapToLength
(value)¶ Converts pixels to meters. Used to extract real distances from pixel distances such as contour lengths
-
normalize
(value)¶ Transforms real unit quantities into self.mapX, self.mapY coordinates. For use in indexing into the coremap.
-
simulationSetup
(config)¶ Do anything needed to prepare this grain for simulation
-
unNormalize
(value)¶ Transforms self.mapX, self.mapY coordinates to real unit quantities. Used to determine real lengths in coremap.
-
-
class
motorlib.grain.
Grain
¶ A basic propellant grain. This is the class that all grains inherit from. It provides a few properties and composed methods but otherwise it is up to the subclass to make a functional grain.
-
getDetailsString
(preferences)¶ Returns a short string describing the grain, formatted using the units of the preferences object that was passed in.
-
abstract
getEndPositions
(regDist)¶ Returns the positions of the grain ends relative to the original (unburned) grain top
-
getGeometryErrors
()¶ Returns a list of simAlerts that detail any issues with the geometry of the grain. Errors should be used for any condition that prevents simulation of the grain, while warnings can be used to notify the user of possible non-fatal mistakes in their entered numbers. Subclasses should still call the superclass method, as it performs checks that still apply to its subclasses.
-
abstract
getMassFlux
(massIn, dTime, regDist, dRegDist, position, density)¶ Returns the mass flux at a point along the grain. Takes in the mass flow into the grain, a timestep, the distance the grain has regressed so far, the additional distance it will regress during the timestep, a position along the grain measured from the head end, and the density of the propellant.
-
getPeakMassFlux
(massIn, dTime, regDist, dRegDist, density)¶ Uses the grain’s mass flux method to return the max. Assumes that it will be at the port of the grain!
-
abstract
getPortArea
(regDist)¶ Returns the area of the grain’s port when it has regressed a distance of ‘regDist’
-
getRegressedLength
(regDist)¶ Returns the length of the grain when it has regressed a distance of ‘regDist’, taking any possible inhibition into account.
-
abstract
getSurfaceAreaAtRegression
(regDist)¶ Returns the surface area of the grain after it has regressed a linear distance of ‘regDist’
-
abstract
getVolumeAtRegression
(regDist)¶ Returns the volume of propellant in the grain after it has regressed a linear distance ‘regDist’
-
getVolumeSlice
(regDist, dRegDist)¶ Returns the amount of propellant volume consumed as the grain regresses from a distance of ‘regDist’ to regDist + dRegDist
-
abstract
getWebLeft
(regDist)¶ Returns the shortest distance the grain has to regress to burn out
-
isWebLeft
(regDist, burnoutThres=1e-05)¶ Returns True if the grain has propellant left to burn after it has regressed a distance of ‘regDist’
-
abstract
simulationSetup
(config)¶ Do anything needed to prepare this grain for simulation
-
-
class
motorlib.grain.
PerforatedGrain
¶ A grain with a hole of some shape through the center. Adds abstract methods related to the core to the basic grain class
-
abstract
getCorePerimeter
(regDist)¶ Returns the perimeter of the core after the grain has regressed a distance of ‘regDist’.
-
getCoreSurfaceArea
(regDist)¶ Returns the surface area of the grain’s core after it has regressed a distance of ‘regDist’
-
getEndPositions
(regDist)¶ Returns the positions of the grain ends relative to the original (unburned) grain top
-
abstract
getFaceArea
(regDist)¶ Returns the area of the grain face after it has regressed a distance of ‘regDist’. This is the same as the area of an equal-diameter endburning grain minus the grain’s port area.
-
abstract
getFaceImage
(mapDim)¶ Returns an image of the grain’s cross section, with resolution (mapDim, mapDim).
-
getMassFlux
(massIn, dTime, regDist, dRegDist, position, density)¶ Returns the mass flux at a point along the grain. Takes in the mass flow into the grain, a timestep, the distance the grain has regressed so far, the additional distance it will regress during the timestep, a position along the grain measured from the head end, and the density of the propellant.
-
getPortArea
(regDist)¶ Returns the area of the grain’s port when it has regressed a distance of ‘regDist’
-
abstract
getRegressionData
(mapDim, numContours=15, coreBlack=True)¶ Returns a tuple that includes a grain face image as described in ‘getFaceImage’, a regression map where color maps to regression depth, a list of contours (lists of (x,y) points in image space) of equal regression depth, and a list of corresponding contour lengths. The contours are equally spaced between 0 regression and burnout.
-
getSurfaceAreaAtRegression
(regDist)¶ Returns the surface area of the grain after it has regressed a linear distance of ‘regDist’
-
getVolumeAtRegression
(regDist)¶ Returns the volume of propellant in the grain after it has regressed a linear distance ‘regDist’
-
getWebLeft
(regDist)¶ Returns the shortest distance the grain has to regress to burn out
-
abstract
motorlib.motor
¶
Conains the motor class and a supporting configuration property collection.
-
class
motorlib.motor.
Motor
(propDict=None)¶ The motor class stores a number of grains, a nozzle instance, a propellant, and a configuration that it uses to run simulations. Simulations return a simRes object that includes any warnings or errors associated with the simulation and the data. The propellant field may be None if the motor has no propellant set, and the grains list is allowed to be empty. The nozzle field and config must be filled, even if they are empty property collections.
-
applyDict
(dictionary)¶ Makes the motor copy properties from the dictionary that is passed in, which must be formatted like the result passed out by ‘getDict’
-
calcForce
(chamberPres)¶ Calculates the force of the motor at a given regression depth per grain. Calculates pressure by default, but can also use a value passed in. This method uses a combination of the techniques described in these resources to adjust the thrust coefficient: https://apps.dtic.mil/dtic/tr/fulltext/u2/a099791.pdf and http://rasaero.com/dloads/Departures%20from%20Ideal%20Performance.pdf.
-
calcIdealPressure
(regDepth, kn=None, burnoutWebThres=1e-05)¶ Returns the steady-state pressure of the motor at a given reg. Kn is calculated automatically, but it can optionally be passed in to save time on motors where calculating surface area is expensive.
-
calcIdealThrustCoeff
(chamberPres)¶ Calculates C_f, the ideal thrust coefficient for the motor’s nozzle and propellant, and the given chamber pressure.
-
calcKN
(regDepth, burnoutThres=1e-05)¶ Returns the motor’s Kn when it has each grain has regressed by its value in regDepth, which should be a list with the same number of elements as there are grains in the motor. The optional burnoutThres argument sets the minimum web that a grain must have to still be burning.
-
getDict
()¶ Returns a serializable representation of the motor. The dictionary has keys ‘nozzle’, ‘propellant’, ‘grains’, and ‘config’, which hold to the properties of their corresponding fields. Grains is a list of dicts, each containing a type and properties. Propellant may be None if the motor has no propellant set.
-
runSimulation
(callback=None)¶ Runs a simulation of the motor and returns a simRes instance with the results. Constraints are checked, including the number of grains, if the motor has a propellant set, and if the grains have geometry errors. If all of these tests are passed, the motor’s operation is simulated by calculating Kn, using this value to get pressure, and using pressure to determine thrust and other statistics. The next timestep is then prepared by using the pressure to determine how the motor will regress in the given timestep at the current pressure. This process is repeated and regression tracked until all grains have burned out, when the results and any warnings are returned.
-
-
class
motorlib.motor.
MotorConfig
¶ Contains the settings required for simulation, including environmental conditions and details about how to run the simulation.
motorlib.nozzle
¶
This submodule houses the nozzle object and functions related to isentropic flow
-
class
motorlib.nozzle.
Nozzle
¶ An object that contains the details about a motor’s nozzle.
-
calcExpansion
()¶ Returns the nozzle’s expansion ratio.
-
getDetailsString
(preferences)¶ Returns a human-readable string containing some details about the nozzle.
-
getDivergenceLosses
()¶ Returns nozzle efficiency losses due to divergence angle
-
getExitArea
()¶ Return the area of the nozzle’s exit.
-
getExitPressure
(k, inputPressure)¶ Solves for the nozzle’s exit pressure, given an input pressure and the gas’s specific heat ratio.
-
getGeometryErrors
()¶ Returns a list containing any errors with the nozzle’s properties.
-
getSkinLosses
()¶ Returns the losses due to drag on the nozzle surface as described here: https://apps.dtic.mil/dtic/tr/fulltext/u2/a099791.pdf. This is a constant for now, as people likely don’t have a way to measure this themselves.
-
getThroatArea
()¶ Returns the area of the nozzle’s throat.
-
getThroatLosses
()¶ Returns the losses caused by the throat aspect ratio as described in this document: http://rasaero.com/dloads/Departures%20from%20Ideal%20Performance.pdf
-
-
motorlib.nozzle.
eRatioFromPRatio
(k, pRatio)¶ Returns the expansion ratio of a nozzle given the pressure ratio it causes.
motorlib.propellant
¶
Propellant submodule that contains the propellant class.
motorlib.properties
¶
This module includes a properties, which are objects that contain different datatypes and enforce conditions on them, such as allowed ranges. They also can optionally associate a unit with the value, which aids with display and conversion of the value.
-
class
motorlib.properties.
EnumProperty
(dispName, values)¶ This property operates on strings, but only allows values from a list that is set when the property is defined
-
contains
(value)¶ Checks if a value is in the allowed list
-
setValue
(value)¶ Set the value of the property, casting if necessary
-
-
class
motorlib.properties.
FloatProperty
(dispName, unit, minValue, maxValue)¶ A property that handles floats. It forces the value to be in a certain range.
-
dispFormat
(unit)¶ Returns a human-readable version of the property’s current value, including the unit.
-
setValue
(value)¶ Set the value of the property, casting if necessary
-
-
class
motorlib.properties.
IntProperty
(dispName, unit, minValue, maxValue)¶ A property with an integer as the value that is clamped to a certain range.
-
setValue
(value)¶ Set the value of the property, casting if necessary
-
-
class
motorlib.properties.
PolygonProperty
(dispName)¶ A property that contains a list of polygons, each a list of points
-
class
motorlib.properties.
Property
(dispName, unit, valueType)¶ The base class that properties inherit from. It associates a human-readable display name with the data, as well as a unit and value type that it casts all inputs to.
-
dispFormat
(unit)¶ Returns a human-readable version of the property’s current value, including the unit.
-
getValue
()¶ Returns the value of the property
-
setValue
(value)¶ Set the value of the property, casting if necessary
-
-
class
motorlib.properties.
PropertyCollection
¶ Holds a set of properties and allows batch operations on them through dictionaries
-
getProperties
(props=None)¶ Get a dictionary of property names and values. The optional argument is a list of which properties are being requested. It defaults to None, which returns all properties.
-
getProperty
(prop)¶ Returns the value of a specific property.
-
setProperties
(props)¶ Sets the value(s) of one of more properties at a time by passing in a dictionary of property names and values
-
setProperty
(prop, value)¶ Set the value of a specific property
-
-
class
motorlib.properties.
StringProperty
(dispName)¶ A property that works on the set of all strings
motorlib.simResult
¶
This module contains the classes that are returned from a simulation, including the main results class and the channels and components that it is comprised of.
-
class
motorlib.simResult.
LogChannel
(name, valueType, unit)¶ A log channel accepts data from a single source throughout a simulation. It has a human-readable name such as ‘Pressure’ to help the user interpret the result, a value type that data passed in will be cast to, and a unit to aid in conversion and display. The data type can either be a scalar (float or int) or a list (list or tuple).
-
addData
(data)¶ Adds a new datapoint to the end.
-
getAverage
()¶ Returns the average of the datapoints.
-
getData
(unit=None)¶ Return all of the data in the channel, converting it if a type is specified.
-
getLast
()¶ Returns the last datapoint.
-
getMax
()¶ Returns the maximum value of all datapoints. For list datatypes, this operation finds the largest single value in any list.
-
getPoint
(i)¶ Returns a specific datapoint by index.
-
-
class
motorlib.simResult.
SimAlert
(level, alertType, description, location=None)¶ A sim alert signifies a possible problem with a motor. It has levels of severity including ‘error’ (simulation should not continue or has failed), ‘warning’ (values entered appear incorrect but can be simulated), and ‘message’ (other information). The type describes the variety of issue the alert is associated with, and the description is a human-readable version string with more details about the problem. The location can either be None or a string to help the user find the problem.
-
class
motorlib.simResult.
SimAlertLevel
¶ Levels of severity for sim alerts
-
class
motorlib.simResult.
SimAlertType
¶ Types of sim alerts
-
class
motorlib.simResult.
SimulationResult
(motor)¶ A SimulationResult instance contains all results from a single simulation. It has a number of LogChannels, each capturing a single stream of outputs from the simulation. It also includes a flag of whether the simulation was considered a sucess, along with a list of alerts that the simulation produced while it was running.
-
addAlert
(alert)¶ Add an entry to the list of alerts for the simulation.
-
getAlertsByLevel
(level)¶ Returns all simulation alerts of the specified level.
-
getAverageForce
()¶ Returns the average force the motor produced during its burn.
-
getAveragePressure
()¶ Returns the average chamber pressure observed during the simulation.
-
getBurnTime
()¶ Returns the burntime of the simulated motor, which is the time from the start when it was last producing thrust above the user’s defined threshold.
-
getCSV
(pref=None, exclude=[])¶ Returns a string that contains a CSV of the simulated data. Preferences can be passed in to set units that the values will be converted to. All log channels are included unless their names are in the include argument.
-
getDesignation
()¶ Returns the standard amateur rocketry designation (H128, M1297) for the motor.
-
getISP
(index=None)¶ Returns the specific impulse that the simulated motor delivered.
-
getImpulse
(stop=None)¶ Returns the impulse the simulated motor produced. If ‘stop’ is set to a value other than None, only the impulse to that point in the data is returned.
-
getInitialKN
()¶ Returns the motor’s Kn before it started firing.
-
getMaxPressure
()¶ Returns the highest chamber pressure that was observed during the motor’s burn.
-
getPeakKN
()¶ Returns the highest Kn that was observed during the motor’s burn.
-
getPeakMassFlux
()¶ Returns the maximum mass flux observed at any grain end.
-
getPeakMassFluxLocation
()¶ Returns the grain number at which the peak mass flux was observed.
-
getPortRatio
()¶ Returns the port/throat ratio of the motor, or None if it doesn’t have a port.
-
getPropellantLength
()¶ Returns the total length of all propellant before the simulated burn.
-
getPropellantMass
(index=0)¶ Returns the total mass of all propellant before the simulated burn. Optionally accepts a index that the mass will be sampled at.
-
shouldContinueSim
(thrustThres)¶ Returns if the simulation should continue based on the thrust from the last timestep.
-
motorlib.units
¶
This module contains tables of units and their long form names, their conversion rates with other units, and functions for performing conversion.
-
motorlib.units.
convFormat
(quantity, originUnit, destUnit, places=3)¶ Takes in a quantity in originUnit, converts it to destUnit and outputs a rounded and formatted string that includes the unit appended to the end.
-
motorlib.units.
convert
(quantity, originUnit, destUnit)¶ Returns the value of ‘quantity’ when it is converted from ‘originUnit’ to ‘destUnit’.
-
motorlib.units.
convertAll
(quantities, originUnit, destUnit)¶ Converts a list of values from ‘originUnit’ to ‘destUnit’.
-
motorlib.units.
getAllConversions
(unit)¶ Returns a list of all units that the passed unit can be converted to.
-
motorlib.units.
getConversion
(originUnit, destUnit)¶ Returns the ratio to convert between the two units. If the conversion does not exist, an exception is raised.