Skip to content
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

Function to return Total Energy in physics/mechanics #16202

Closed
wants to merge 13 commits into from
Closed

Function to return Total Energy in physics/mechanics #16202

wants to merge 13 commits into from

Conversation

ritesh99rakesh
Copy link
Member

@ritesh99rakesh ritesh99rakesh commented Mar 8, 2019

Fixes #16201

Brief description of what is fixed or changed

At present, we have function to get the kinetic energy and potential energy of rigid body, but we do not have any function to give the total energy of the rigid body. This PR adds a function under sympy/physics/mechanics/rigidbody.py to return the total energy of the body.
I have defined total_energy = kinetic_energy + potential_energy

Other comments

Please review it and comment your suggestions.

Release Notes

  • physics.mechanics
    • added functions total_energy, rotational_kinetic_energy, and translational_kinetic_energy, in rigidbody.py
    • added function total_energy in particle.py

@sympy-bot
Copy link

sympy-bot commented Mar 8, 2019

Hi, I am the SymPy bot (v145). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • physics.mechanics

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->
Fixes #16201 

#### Brief description of what is fixed or changed
At present, we have function to get the kinetic energy and potential energy of rigid body, but we do not have any function to give the total energy of the rigid body. This PR adds a function under ```sympy/physics/mechanics/rigidbody.py``` to return the total energy of the body. 
I have defined total_energy = kinetic_energy + potential_energy

#### Other comments
Please review it and comment your suggestions.

#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.mechanics
    * added functions total_energy, rotational_kinetic_energy, and translational_kinetic_energy, in rigidbody.py
    * added function total_energy in particle.py


<!-- END RELEASE NOTES -->

…ticle.py and better comment in rigidbody.py for total_energy
@codecov
Copy link

codecov bot commented Mar 8, 2019

Codecov Report

Merging #16202 into master will increase coverage by 0.123%.
The diff coverage is 100%.

@@              Coverage Diff              @@
##            master    #16202       +/-   ##
=============================================
+ Coverage   73.596%   73.719%   +0.123%     
=============================================
  Files          618       619        +1     
  Lines       158481    158455       -26     
  Branches     37187     37134       -53     
=============================================
+ Hits        116636    116813      +177     
+ Misses       36417     36219      -198     
+ Partials      5428      5423        -5

@shiksha11
Copy link
Contributor

shiksha11 commented Mar 10, 2019

@ritesh99rakesh
Copy link
Member Author

Why in the total energy expression roatational kinetic energy is not I*(w**2)/2 ?

Also I had the same doubt but it is due to the function which calculates the I and we get the expression for rotational kinetic energy as (w**2)/2

@ritesh99rakesh
Copy link
Member Author

ritesh99rakesh commented Mar 10, 2019

I have added new functions rotational_kinetic_energy and translational_kinetic_energy which will the return the rotational and translational component of kinetic energy, repectively. Please let me know if these are needed or should I remove these. Ping @moorepants, @oscargus .

@oscargus
Copy link
Contributor

I do not know much about the physics module so there are others who are more suitable to review the functionality.

@smichr
Copy link
Member

smichr commented Mar 17, 2019

please add release notes, too

@ritesh99rakesh
Copy link
Member Author

Thank you for your reply @smichr. Also what exactly do I have to write in release notes?

@smichr
Copy link
Member

smichr commented Mar 19, 2019

👓 See this for more information
on how to write release notes. for suggestions on release notes. You added new functions. someone reading the release notes will be interested.

@ritesh99rakesh
Copy link
Member Author

@smichr I have added release notes, please reivew them. Regards.

@oscargus
Copy link
Contributor

I think something like:
added functions total_energy, rotational_kinetic_energy, and translational_kinetic_energy, in rigidbody.py
added function total_energy in particle.py

would do.

@ritesh99rakesh
Copy link
Member Author

If this PR looks fine, please merge it. Ping @oscargus, @smichr

@ritesh99rakesh
Copy link
Member Author

@oscargus could you guide me what has to be done to complete this PR?

>>> B.total_energy(N)
M*g*h + M*v**2/2 + omega**2/2
"""
return self.kinetic_energy(frame) + self.potential_energy
Copy link
Member

Choose a reason for hiding this comment

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

This should raise an error if potential energy is not defined.

g*h*m + m*v**2/2

"""
return self.kinetic_energy(frame) + self.potential_energy
Copy link
Member

Choose a reason for hiding this comment

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

Should raise an error if potential_energy is not defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

At present, potential_energy for a body for which potential_energy is not explicitly defined is taken as zero. I think this makes sense. What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

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

It is a bit misleading. If I type "total_energy" I'm expecting to get KE + PE, but if PE is zero by default I'm not getting any PE contribution. I feel like it would be best to inform the user that they aren't getting what they ask for. Maybe a warning message that tells the user that PE is zero and not set is sufficient.

@moorepants
Copy link
Member

This looks useful, I've provided some comments.

@ritesh99rakesh
Copy link
Member Author

@moorepants please review the changes.

@moorepants
Copy link
Member

If you add warnings when PE is zero for the total_energy functions then it LGTM.

@ritesh99rakesh
Copy link
Member Author

If you add warnings when PE is zero for the total_energy functions then it LGTM.

@moorepants I was trying to complete this PR. I have the following

>>> from sympy.physics.mechanics import RigidBody, Point, outer, ReferenceFrame
>>> from sympy import symbols
>>> M, g, h = symbols('M g h')
>>> b = ReferenceFrame('b')
>>> P = Point('P')
>>> I = outer (b.x, b.x)
>>> Inertia_tuple = (I, P)
>>> B = RigidBody('B', P, b, M, Inertia_tuple)
>>> B.potential_energy
0
>>> B.potential_energy = 0
>>> B.potential_energy
0

Therefore, in both cases when potential_energy is not set and when potential_energy is set to zero, the output is same. So, how would I distinguish between both?
Ping @smichr

@czgdp1807
Copy link
Member

@ritesh99rakesh Would you like to complete this PR?

@czgdp1807
Copy link
Member

IMO, K.E. + P.E. is total mechanical energy, so the name should be changed accordingly.
Looks like a nice addition.

@ritesh99rakesh
Copy link
Member Author

Closed in favour of #18838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function to return Total Energy in physics/mechanics
8 participants