Skip to content

ENH: variable gravity #338

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

Merged
merged 25 commits into from
Apr 27, 2023
Merged

ENH: variable gravity #338

merged 25 commits into from
Apr 27, 2023

Conversation

FranzYuri
Copy link
Contributor

Pull request type

Please check the type of change your PR introduces:

  • Code base additions (bugfix, features)
  • Code maintenance (refactoring, formatting, renaming, tests)
  • ReadMe, Docs and GitHub maintenance
  • Other (please describe):

Pull request checklist

Please check if your PR fulfills the following requirements, depending on the type of PR:

  • ReadMe, Docs and GitHub maintenance:

    • Spelling has been verified
    • Code docs are working correctly
  • Code base maintenance (refactoring, formatting, renaming):

    • Docs have been reviewed and added / updated if needed
    • Lint (black rocketpy) has passed locally and any fixes were made
    • All tests (pytest --runslow) have passed locally
  • Code base additions (for bug fixes / features):

    • Tests for the changes have been added
    • Docs have been reviewed and added / updated if needed
    • Lint (black rocketpy) has passed locally and any fixes were made
    • All tests (pytest --runslow) have passed locally

What is the current behavior?

currently gravity is a constant equal to 9,80665 m/s²

What is the new behavior?

Now, env.g is a callable that returns the gravity given the height.
On the other hand, env.standard_gravity will store the constant value of 9,80665 m/s².

Does this introduce a breaking change?

  • Yes
  • No

Other information

Enter text here...

@phmbressan phmbressan self-requested a review March 11, 2023 19:15
@MateusStano MateusStano self-requested a review March 11, 2023 20:52
@MateusStano MateusStano added Environment Enviroment Class related features Enhancement New feature or request, including adjustments in current codes labels Mar 11, 2023
@MateusStano MateusStano added this to the Release v1.0.0 milestone Mar 11, 2023
Copy link
Member

@MateusStano MateusStano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what is going on here. Does the gravity only vary if the user passes gravity = "variable"? Shouldn't it be calculated just by getting the elevation? The gravity argument should be an optional argument that sets it to a constant value, just in case anyone wants to try to simulate another planet or something.

Am I getting something wrong here?

@MateusStano MateusStano linked an issue Mar 23, 2023 that may be closed by this pull request
@phmbressan
Copy link
Collaborator

phmbressan commented Apr 4, 2023

@MateusStano

I believe this PR may be reaching its final steps. Just a few things that I wanted to point out before finishing reviews and merging:

Flight class PotentialEnergy changes:

  • The method was wrong since inputting self.z (a Function) to the environment gravity Function yielded an error at interpolation.
  • Trying to multiply Function by possible arrays (such as self.env.g(self.z.source[,:1])) does not help.
  • Temporary fix was to perform the multiplication "manually".

Environment class gravity parameter:

  • I personally don't think that I took the best decision here, i.e., the default None leads to variable gravity, however, since the parameter is a Function input, the options were limited. I am open to better suggestions.

Gravity Function being discrete:

  • The Environment discretizes the gravity function height domain for two main reasons: 1) It is likely faster in the case of Somigliana's formula (but there might be a small performance hit compared a constant valued case); 2) Using lambda sources raises an error at the plotting class when the .source[] attributes are used, since it turns many Functions of the Flight class also lambda based (being a performance hit also).

Nota bene: the fin flutter tests still do not pass for me locally.

@MateusStano
Copy link
Member

Nota bene: the fin flutter tests still do not pass for me locally.

Hey, seems that in this case the test actually did its job. The change in the gravity model actually changed the simulation by just enough to make the test break. It seems flutter analysis is very very sensitive

I think I fixed it now, please just try to run it locally to make sure

@giovaniceotto
Copy link
Member

giovaniceotto commented Apr 9, 2023

@MateusStano, I see you changed the values for the fin flutter test. Shouldn't we keep a test with the old values, but using constant gravity, just to be safe?

To be clear, I mean we should keep both tests: the old one and the new one.

@@ -2121,8 +2121,7 @@ def potentialEnergy(self):
# Redefine totalMass time grid to allow for efficient Function algebra
totalMass = deepcopy(self.rocket.totalMass)
totalMass.setDiscreteBasedOnModel(self.z)
# TODO: change calculation method to account for variable gravity
potentialEnergy = totalMass * self.env.gravity.compose(self.z)
potentialEnergy = totalMass * self.env.gravity.compose(self.z) * self.z
Copy link
Member

@giovaniceotto giovaniceotto Apr 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this formula, $U_g (z) = mg(z)z$, is no longer valid for variable gravity. Instead, we should use $U_g (R) = \frac{GMm}{R}$ where $R$ is the rocket's center of mass position vector magnitude relative to Earth's center.

Reference: https://en.wikipedia.org/wiki/Gravitational_energy

Copy link
Member

@MateusStano MateusStano Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I implemented this in 90b2bdb with the following code:

        potentialEnergy = (
            GM
            * totalMass
            * (1 / (self.z + self.env.earthRadius) - 1 / self.env.earthRadius)
        )

So what we are calculating here is the potential energy in relation to the sea level. All good now right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the result for Calisto:

Figure 38

@giovaniceotto giovaniceotto self-requested a review April 9, 2023 21:55
@MateusStano MateusStano merged commit d0beefd into beta/v1.0.0 Apr 27, 2023
@MateusStano MateusStano mentioned this pull request May 4, 2023
@Gui-FernandesBR Gui-FernandesBR deleted the enh/variable-gravity branch May 26, 2023 00:53
@Gui-FernandesBR Gui-FernandesBR changed the title Enh/variable gravity ENH: variable gravity Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request, including adjustments in current codes Environment Enviroment Class related features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable Gravity
6 participants