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
Closed
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
316b6fc
added total_energy
ritesh99rakesh b0f4cde
added total_energy and test for total_energy
ritesh99rakesh cf1ca7e
added total_energy for Particle, test for total_energy under test_par…
ritesh99rakesh 18fc488
removed trailing white spaces
ritesh99rakesh b30f11f
corrected test error
ritesh99rakesh 90db23b
Merge branch 'master' into 16201
ritesh99rakesh 16f2078
Merge branch 'master' into 16201
ritesh99rakesh 9d3db99
added functions for rotational and translational kinetic energy
ritesh99rakesh 0fd70ac
corrected example under translational_kinetic_energy
ritesh99rakesh b272238
made typo correction
ritesh99rakesh ec6c9c6
corrected test for total_energy and kinetic_energy
ritesh99rakesh 1960c3d
Merge branch 'master' of https://github.com/sympy/sympy into 16201
ritesh99rakesh 158f574
replace & with dot()
ritesh99rakesh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,89 @@ def angular_momentum(self, point, frame): | |
|
||
return I.dot(w) + r.cross(m * v) | ||
|
||
def rotational_kinetic_energy(self, frame): | ||
"""Rotational kinetic energy of the rigid body | ||
|
||
The rotational kinetic energy, T, of a rigid body, B, is given by | ||
|
||
'T = 1/2 (I omega^2)' | ||
|
||
where I is the central inertia dyadic of rigid body B, | ||
omega is the angular velocity of the body's | ||
mass center in the supplied ReferenceFrame. | ||
|
||
Parameters | ||
========== | ||
|
||
frame : ReferenceFrame | ||
The RigidBody's angular velocity and the velocity of it's mass | ||
center are typically defined with respect to an inertial frame but | ||
any relevant frame in which the velocities are known can be supplied. | ||
|
||
Examples | ||
======== | ||
|
||
>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer | ||
>>> from sympy.physics.mechanics import RigidBody | ||
>>> from sympy import symbols | ||
>>> M, v, r, omega = symbols('M v r omega') | ||
>>> N = ReferenceFrame('N') | ||
>>> b = ReferenceFrame('b') | ||
>>> b.set_ang_vel(N, omega * b.x) | ||
>>> P = Point('P') | ||
>>> P.set_vel(N, v * N.x) | ||
>>> I = outer (b.x, b.x) | ||
>>> inertia_tuple = (I, P) | ||
>>> B = RigidBody('B', P, b, M, inertia_tuple) | ||
>>> B.rotational_kinetic_energy(N) | ||
omega**2/2 | ||
|
||
""" | ||
|
||
return (self.frame.ang_vel_in(frame) & (self.central_inertia & | ||
self.frame.ang_vel_in(frame)) / sympify(2)) | ||
ritesh99rakesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def translational_kinetic_energy(self, frame): | ||
"""Translational kinetic energy of the rigid body | ||
|
||
The translational kinetic energy, T, of a rigid body, B, is given by | ||
|
||
'T = 1/2 (m v^2)' | ||
|
||
where m is the mass of rigid body B, v is the velocity of the body's | ||
mass center in the supplied ReferenceFrame. | ||
|
||
Parameters | ||
========== | ||
|
||
frame : ReferenceFrame | ||
The RigidBody's angular velocity and the velocity of it's mass | ||
center are typically defined with respect to an inertial frame but | ||
any relevant frame in which the velocities are known can be supplied. | ||
|
||
Examples | ||
======== | ||
|
||
>>> from sympy.physics.mechanics import Point, ReferenceFrame, outer | ||
>>> from sympy.physics.mechanics import RigidBody | ||
>>> from sympy import symbols | ||
>>> M, v, r, omega = symbols('M v r omega') | ||
>>> N = ReferenceFrame('N') | ||
>>> b = ReferenceFrame('b') | ||
>>> b.set_ang_vel(N, omega * b.x) | ||
>>> P = Point('P') | ||
>>> P.set_vel(N, v * N.x) | ||
>>> I = outer (b.x, b.x) | ||
>>> inertia_tuple = (I, P) | ||
>>> B = RigidBody('B', P, b, M, inertia_tuple) | ||
>>> B.translational_kinetic_energy(N) | ||
M*v**2/2 | ||
|
||
""" | ||
|
||
return (self.mass * (self.masscenter.vel(frame) & | ||
self.masscenter.vel(frame)) / sympify(2)) | ||
ritesh99rakesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def kinetic_energy(self, frame): | ||
"""Kinetic energy of the rigid body | ||
|
||
|
@@ -238,13 +321,7 @@ def kinetic_energy(self, frame): | |
|
||
""" | ||
|
||
rotational_KE = (self.frame.ang_vel_in(frame) & (self.central_inertia & | ||
self.frame.ang_vel_in(frame)) / sympify(2)) | ||
|
||
translational_KE = (self.mass * (self.masscenter.vel(frame) & | ||
self.masscenter.vel(frame)) / sympify(2)) | ||
|
||
return rotational_KE + translational_KE | ||
return self.rotational_kinetic_energy(frame) + self.translational_kinetic_energy(frame) | ||
|
||
@property | ||
def potential_energy(self): | ||
|
@@ -296,3 +373,40 @@ def potential_energy(self, scalar): | |
""" | ||
|
||
self._pe = sympify(scalar) | ||
|
||
def total_energy(self, frame): | ||
"""The total energy of the RigidBody. | ||
|
||
The total energy E, of rigidbody B, is given by | ||
E = K.E. + P.E. | ||
|
||
where P.E. is the potential energy of the rigid body B and | ||
K.E. is kinetic energy of the rigid body B in the supplied ReferenceFrame. | ||
|
||
Parameters | ||
========== | ||
|
||
frame : ReferenceFrame | ||
The RigidBody's angular velocity and the velocity of it's mass | ||
center are typically defined with respect to an inertial frame but | ||
any relevant frame in which the velocities are known can be supplied. | ||
|
||
Examples | ||
======== | ||
|
||
>>> from sympy.physics.mechanics import RigidBody, Point, outer, ReferenceFrame | ||
>>> from sympy import symbols | ||
>>> M, v, r, omega, g, h = symbols('M v r omega g h') | ||
>>> N = ReferenceFrame('N') | ||
>>> b = ReferenceFrame('b') | ||
>>> b.set_ang_vel(N, omega * b.x) | ||
>>> P = Point('P') | ||
>>> P.set_vel(N, v * N.x) | ||
>>> I = outer (b.x, b.x) | ||
>>> Inertia_tuple = (I, P) | ||
>>> B = RigidBody('B', P, b, M, Inertia_tuple) | ||
>>> B.potential_energy = M * g * h | ||
>>> B.total_energy(N) | ||
M*g*h + M*v**2/2 + omega**2/2 | ||
""" | ||
return self.kinetic_energy(frame) + self.potential_energy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should raise an error if potential energy is not defined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should raise an error if potential_energy is not defined.
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.
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?
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.
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.