-
-
Notifications
You must be signed in to change notification settings - Fork 239
BUG: Cld divided by zero #122
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
BUG: Cld divided by zero #122
Conversation
|
@MateusStano, just to make sure we are in the same page, this problem is caused by the following approximation, correct? |
|
To be honest, I am not convinced that the solution given is the best one possible. The freestream speed will most likely be zero only when the roll rate Furthermore, if we detect that the angle of attack becomes too high (high roll rate and low freestream speed), perhaps we should raise a warning since the equations being used loose validity. |
Yes, this is causing the problem
Think everything you said here makes sense. But one question, when should I consider that the angle of attack is too high? Any way you recommend checking that? |
What if, at the end of the simulation, you check if there's a value higher than Xº on the angle of attack vector and if so you print a warning? That X value could be, let's say, 10 degress? With this solution you would perfom only 1 extra if in the simulation, |
|
I partially agree with @Gui-FernandesBR. I believe implementing a couple of lines of code in the Flight.postProcess method could be useful to calculate the highest angle of attack along the flight and print this detail in the RocketPy does not usually warn users in case something is bad in the simulation... but according to @Projeto-Jupiter/back-end's OKRs, we should do that from now on. I would raise a warning only if the angle of attack becomes greater than 20 degrees, but this is an arbitrary value, for sure. Another interesting metric would be for how long the angle of attack remains greater than a specified value, be it 10 or 20 degrees. Anyways, I trust you to establish a reasonable threshold for such warning @MateusStano. |
|
Hey @giovaniceotto @Gui-FernandesBR! Changed quite a bit of the roll implementation and now everything seems to be in order. I changed the description of the PR and added some stuff to it. Just a couple of things:
|
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.
Explendid work @MateusStano. I believe the new code is, overall, significantly more reliable and trustworthy. We can finally say that RocketPy has a great roll model. Furthermore, I really like the fact that you are starting to add compressibility corrections by introducing Mach number as an argument to some functions.
Here are my main comments:
- I know that this isn't new here, but I am concerned that our code is relying quite heavily on the
Function.differentiatemethod. As we know, its implementation is not ready for production and should be enhanced. Something to add to our development roadmap @Gui-FernandesBR. - I know we have talked about this, by I really like the new names used for some variables, such as renaming
cldatatocland usingclalphaSingleFin. - Any reason λ and tau are being used in lines 594 - 614, instead of lambda and tau or λ and τ? I am afraid that using special chars such as λ and τ can make the code a little bit harder to maintain, but it does improve readability quite significantly!
- I am worried that using
fin = [(0, 0, cpz), cl, rollParameters, "Fins"]together withnose = [(0, 0, cpz), cl, "Nose Cone"]can be a bad choice. For fins, the third element of the list is roll parameters, while for the nose cone, the third element is the name. Furthermore,Rocket.addTail,Rocket.addNose,Rocket.addFinsall say that...storing its parameters as part of the aerodynamicSurfaces list. Its parameters are the axial position along the rocket and its derivative of the coefficient of lift in respect to angle of attack., which do not include the roll parameters. Perhaps we should make everything follow the same convetion, such as[(cpx, cpy, cpz), cl, clfDelta*cantAngleRad, cldOmega, "Surface Name"]or something similar? I am not against moving away from lists and starting to store this info in a custom class as well...
Here are my requests:
- Could the description of
clin lines 421, 479, and 565 ofRocket.pybe improved? Saying it contains the lift data is quite vague. Perhaps we can specify the inputs and outputs of the function to make it clearer. - Could you add a comment to line 585 of
Rocket.py(aspect ratio AR definition), describing that this is Barrowmans convetion? The 2 multiplying is quite weird to understand otherwise. - Could functions
betaandfinNumCorrectionhave a short docstring instead of comments on top of them? I believe this is more in line with our formatting practices. Furthermore, functionfinNumCorrectioncould benefit from a reference to where we got the numbers[2.37, 2.74, 2.99, 3.24]. - Would removing
Arefanddfrom lines 1259 and 1260 ofFlight.pybe problematic? I believe the convention the remaining of theFlight.uDotmethod is to useself.rocket.areaand2 * self.rocket.radiusexplicitly. Checking the code formatter by black, I believe spacing is not a problem. Therefore, using their explicit form can make the code easier to understand.
Final remarks:
- I have not independently verified the equations to make sure there are no typos. I am not the best person to do so considering I was involved when you coded them.
Make sure you re-request my review when you are done!
@giovaniceotto about the list and positioning thing you mentioned, we could, of course implement a class to handle aerodynamic surfaces, but a simple alternative woud be to use a dictionary, at least it is more comprehensive and a lot less confusing than having to remember the indices of each element. And also for being easier to maintain, if two branches want to add something new to the aerodynamic surfaces, it becomes a great mess really fast. |
Agreed. Another option are named tuples. Here is an example from its documentation: >>> # Basic example
>>> Point = namedtuple('Point', ['x', 'y'])
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
>>> p[0] + p[1] # indexable like the plain tuple (11, 22)
33
>>> x, y = p # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y # fields also accessible by name
33
>>> p # readable __repr__ with a name=value style
Point(x=11, y=22) |
|
Let's go guys, we have a lot to-do here. 1st, many thanks for implementing this, @MateusStano !! Now my comments
Stay hungry guys, we are close to solve this one |
I believe it would. I will try it out. |
|
Actually I don't know if I can contribute because the branch is on @MateusStano's personal github. I can make the changes, but I am not sure how to integrate them here. |
|
This version with dictionaries is far more readable and much easier to maintain if compared to lists. So far changed only on `Flight.py`.
This version with dictionaries is far more readable and much easier to maintain if compared to lists.
|
Ok, I think it is done @Gui-FernandesBR. |
|
Here is what is left:
I'll approve this PR as soon as these are done. |
Yes, rad/s.
Okay, I think it's for a few reasons but here is a list of all the differences I could find:
Items 1 and 2 are the most relevant for the result differences I believe. Removing the interference factors and substituting Cnalpha1 for 2π/beta in the roll damping coefficient equation in RocketPy wields the following results: These are very similar to OpenRocket's. Also, the little bump you can see right before the 5 seconds mark is coherent with the way we defined beta. |
|
Okay, it is getting intersting guys... awesome! I'll review equations comparing with the barrowman theory this weekend. Meanwhile, I think it is important to estabilish a new test just like Giovani mentioned "What would be needed is a new test with a rocket with cantAngle != 0. There currently exist no tests for this. A particularly important one would be when wind is 0, which was the error which helped us find this bug in the first case." I mean, it's important we ensure the error doesn't be repeated on future PR, right? |
|
Let me correct... Actually I think you already created the test file. Correct me if I'm mistaken pls |
Yep. It is already done :)
I recommend checking Roll Equations.pdf and seeing all that is there is correct |
|
Question: when you make Is that what is happening? |
rocketpy/Rocket.py
Outdated
| @@ -579,20 +590,93 @@ def addFins( | |||
| Ymac = ( | |||
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 could not find this definition on Barrowman's equations, do you remember where did you find?
Not saying it's wrong, but I didn't understand
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.
Gui-FernandesBR
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.
This pull request seems aumost done!! Really awesome @MateusStano !!!
I have some questions but, as I said I'm not an expert on aerodynamics formulation, therefore you might face them as simple question from curiosity, and never think I'm say you're wrong.
Changed Ymac to Yma. Corrected the PDF
Gui-FernandesBR
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.
Awesome work by Stano!!!
|
@giovaniceotto I believe we are ready to merge already. However, as you requested changes we are asking re-approval here. Could you see this by the weekend? We are holding another bug on merge queue |
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.
Great work @MateusStano and @Gui-FernandesBR.
In my last review, I noticed what could be a bug. @MateusStano, what would happen in case we create a rocket with fins with cantAngle=0 and used the initialSolution argument to launch it with angular velocity? Would a damping moment be calculated and applied?
It wouldn't..... but now it works!! |
|
Ready to merge @giovaniceotto ? |
|
Yes! The only checks failing have to do with formatting. @MateusStano, will you do the honor of merging? |




Pull request type
Pull request checklist
Code base additions (for bug fixes / features):
black rocketpy) has passed locally and any fixes were madepytest --runslow) have passed locallyWhat is the current behavior?
Currently, RocketPy is only calculating the difference between the roll forcing and roll damping coefficients and passing that as the roll moment. Obviously, this led to some issues with the code and inaccuracies with the results
What is the new behavior?
Now RocketPy calculates the roll moment accordingly. All equations and considerations used are documented in the Roll_Equations.pdf file. The calculations for the fins lift coefficient also changed. A more general formula is now used since it allowed for easy access to some of the coefficients needed.
Does this introduce a breaking change?
Other information
Unfortunately, I didn't find any data on angular velocity of any subsonic rockets to validate the results from the moment equations. I ended up resorting to simulating the same rocket on RocketPy and on Open Rocket and comparing the results... and they weren't very promising.
In comparison to open rocket, rocketpy's calculated angular velocity were much higher. However, in Open Rocket's documentation they compare their results to experimental ones:
It seems Open Rocket understates the Roll rate. I think it's coherent that RocketPy's results for the roll rate are bigger.
Still, it would be useful to compare RocketPy's roll calculations results to an experimental launch.