-
Notifications
You must be signed in to change notification settings - Fork 114
Motor: update type hints and tests #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Motor: update type hints and tests #253
Conversation
reilleya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of thoughts! Thanks for this!
motorlib/motor.py
Outdated
| using the pressure to determine how the motor will regress in the given timestep at the current pressure. | ||
| def runSimulation(self, callback=None) -> SimulationResult: | ||
| """ | ||
| Runs a simulation of the motor and returns a simRes instance with the results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess breaking these up ("google style"?) could make them easier to read, but I don't think they were all that long to begin with. Maybe revert this for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, reverted
motorlib/motor.py
Outdated
| """ | ||
| if not self.propellant: | ||
| raise ValueError( | ||
| "Ideal pressure cannot be calculated. Propelant is missing." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: propelant -> propellant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, thanks )
| optionally be passed in to save time on motors where calculating surface area is expensive. | ||
| """ | ||
| if not self.propellant: | ||
| raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception is correct here rather than a simAlert. simAlerts are intended for cases where the user has done something that they need to be alerted about. If this function is ever called without a propellant set, it is likely a software bug that should bubble up as an exception.
motorlib/motor.py
Outdated
| """Calculates the mach number in the core of a grain for a given chamber pressure and mass flux.""" | ||
| if not self.propellant: | ||
| raise ValueError( | ||
| "Ideal pressure cannot be calculated. Propelant is missing." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Ideal pressure -> Mach number, Propelant -> Propellant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed, thanks )
motorlib/motor.py
Outdated
| simRes.channels["volumeLoading"].addData( | ||
| 100 * (1 - (self.calcFreeVolume(perGrainReg) / motorVolume)) | ||
| ) | ||
| simRes.channels["massFlow"].addData([0] * len(self.grains)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a really minor potential performance improvement given that this isn't in a loop or anything. Maybe not worth the diff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, reverted
motorlib/motor.py
Outdated
| for g, r in zip(self.grains, perGrainReg) | ||
| ] | ||
| ) | ||
| if callback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like a lot of what ruff has done, but this just reads worse to me. Absolutely no reason to split a line this short with one function call with one arg over so many lines... I'll look into if there's a way to configure ruff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, reverted
| maximumRefDiameter = 6.6 | ||
|
|
||
| # Max core Mach number subsonic limit | ||
| machSubsonicLimit: float = 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little bit silly because this is always going to be exactly 1.0. Maybe only worth doing if we think we are going to change the type someday? Certainly not going to have to update this value in multiple places. Up to you if you want to keep it or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main point here is to update raw float value into meaningful constant, which from my prospective makes code easier to read and understand, even if it looks silly :)
motorlib/utils.py
Outdated
| @@ -0,0 +1,52 @@ | |||
| """Module for utils functions to prevent reassign values from an outer scope.""" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow, can you give an example of what this is trying to avoid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for the lack of clarity. My intent with this module description is not to implement a language feature, but to enforce a code convention that avoids a specific type of subtle bug and confusion.
| ) -> float: | ||
| """Calculates the objective function for finding the Mach number. | ||
| This function represents a rearranged form of the isentropic mass flow equation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this!
651bfe9 to
0a5c3bf
Compare
Motor module updates.
self.propellantbecause it could be None and could cause errors (I have added ValueError but I might need to be converted into SimAllert, @reilleya wdyt?)