Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Kinetic and potential energy functionality. #1407

Merged
merged 1 commit into from

9 participants

Angadh Nanjangud Don't Add Me To Your Organization a.k.a The Travis Bot Stefan Krastanov Ondřej Čertík Jason K. Moore Aaron Meurer Gilbert Gede Thomas Hisch Bharath M R
Angadh Nanjangud

Also some minor edits to momenta functionality.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 71221bfd into 48f42f8).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY5oMeDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 48f42f8
branch hash: 71221bfdb6df517c8009f4eac196d2269b47f154

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYv-QdDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 48f42f8
branch hash: 71221bfdb6df517c8009f4eac196d2269b47f154

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYopseDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 48f42f8
branch hash: 71221bfdb6df517c8009f4eac196d2269b47f154

Automatic review by SymPy Bot.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged b411038f into 48f42f8).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYqMUdDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 48f42f8
branch hash: e831b7a77f8b07f0fbdb2a330010c57c7453324b

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYo5seDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: e831b7a77f8b07f0fbdb2a330010c57c7453324b

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY27UdDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: e831b7a77f8b07f0fbdb2a330010c57c7453324b

Automatic review by SymPy Bot.

sympy/physics/mechanics/functions.py
@@ -557,3 +561,121 @@ def angularmomentum(bodylist, point, frame):
raise TypeError('Body list must have only Particle'
'or RigidBody')
return angularmomentum_sys
+
+def kinetic_energy(bodylist, frame):
+ """Kinetic energy of a multibody system.
+
+ This function returns the kinetic energy of a system of Particle's and/or
+ RigidBody's. The kinertic energy of such a system is equal to the sum of

kinertic -> kinetic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((52 lines not shown))
+ if not isinstance(bodylist, list):
+ raise TypeError('System elements must be supplied as a list')
+ else:
+ KE_sys = 0
+ for e in bodylist:
+ if isinstance(e, (RigidBody, Particle)):
+ KE_individual = e.kinetic_energy(frame)
+ KE_sys = KE_sys + KE_individual
+ else:
+ raise TypeError('Body list must have only Particle'
+ 'or RigidBody')
+ return KE_sys
+
+def potential_energy(bodylist):
+ """Kinetic energy of a multibody system.
+

different docstring?

Angadh Nanjangud
angadhn added a note

hah! embarrassing! thanks for the catch(es)!

Thomas Hisch
thisch added a note

what about two body potentials (e.g. Coulomb potential) ? Your implementation only supports one body potentials, right ?

Angadh Nanjangud
angadhn added a note

Yes, that is correct. This functionality is primarily geared towards mechanical systems. The idea is to use the energy functions to determine the Lagrangian of any mechanical system and finally use Lagrange's method to derive the equations of motion for said mechanical system.

Thomas Hisch
thisch added a note

Anyway, in the future it would be great to extend the potential implementation to treat two body potentials :)

Angadh Nanjangud
angadhn added a note

well, it can still handle 'coulomb potential' (electric potential due to a point charge). The function doesn't determine the potential energy but accepts a user defined function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
((29 lines not shown))
+ >>> 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.kinetic_energy(N)
+ M*v**2/2 + omega**2/2
+
+ """
+
+ return (((self.frame.ang_vel_in(frame) & (self.inertia[0] &

I guess splitting it as assignments and then rewriting will be better because its too long an expression.

Angadh Nanjangud
angadhn added a note

Noted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 9395da38 into 424160a).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYweQdDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: 9395da384a476c4851c13d1b824b2c80ca121a4e

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY2LIeDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: 9395da384a476c4851c13d1b824b2c80ca121a4e

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYj80dDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: 9395da384a476c4851c13d1b824b2c80ca121a4e

Automatic review by SymPy Bot.

Ondřej Čertík
Owner

What is the status of this pull request? Is it ready to be merged?

Ondřej Čertík
Owner

@angadhn said privately "As for PR 1407, I think it's good to be merged unless anyone has any objections with the docstrings.", so I am running tests on this and if it passes, merge it.

sympy/physics/mechanics/functions.py
@@ -11,7 +11,9 @@
'inertia_of_point_mass',
'partial_velocity',
'linearmomentum',
- 'angularmomentum']
+ 'angularmomentum',
Jason K. Moore Collaborator

all of the other functions use an underscore as PEP8's suggestion. So why not angular_momentum and linear_momentum?

Ondřej Čertík Owner
certik added a note

I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ondřej Čertík
Owner

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed (merged angadhn/dev (f69c4a28850ddc85edef31a92c4e4c1e29a56631) into master (9625918)).

Interpreter 1: :eight_spoked_asterisk: All tests have passed.
Interpreter: /usr/bin/python (2.7.3-final-0)
Architecture: Linux (64-bit)

sympy/physics/mechanics/functions.py
((6 lines not shown))
10*N.x + 500*N.y
"""
+ bodylist = list(bodylist)
if not isinstance(bodylist, list):
Jason K. Moore Collaborator

What's up with this? If you always convert bodylist to a list, then how will your "not and instance" ever checkout?

Angadh Nanjangud
angadhn added a note

If users mistakenly pass a tuple for the bodylist in place of a list then list(bodylist) will change it to a list. If they pass a list, then it won't matter, Any other data type should bring the 'not isinstance' to the fore.

Jason K. Moore Collaborator

but you can turn all kinds of things into lists, like:

>>> list('test')
['t', 'e', 's', 't']

There are all kinds of sequences (lists, tuples, sets, etc) and all will turn into lists. So checking whether something is a list doesn't help that much. Your function shouldn't care whether something is a list. It just needs a group of 1 to N particles and bodies. You can group them in multiple ways. It should check for particles and bodies but not worry too much about how you pass them in.

Aaron Meurer Owner
asmeurer added a note

The not isinstance block will never be run. list either returns a list or raises an exception. It never returns something that is not a list.

Also, why does it need to be a list in the first place? It looks like all you're doing is iterating through the elements. That will work just the same if a tuple is left as a tuple.

Ondřej Čertík Owner
certik added a note

@angadhn, this comment still applies I think.

Angadh Nanjangud
angadhn added a note

same as below. addressed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((6 lines not shown))
10*N.z
"""
+ bodylist = list(bodylist)
Jason K. Moore Collaborator

What is this here for? This doesn't seem like smart error checking. See line 490.

Ondřej Čertík Owner
certik added a note

@angadhn, this comment still applies I think.

Angadh Nanjangud
angadhn added a note

fixed this. I didn't realise this was in the momenta functions too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
@@ -557,3 +561,121 @@ def angularmomentum(bodylist, point, frame):
raise TypeError('Body list must have only Particle'
'or RigidBody')
return angularmomentum_sys
+
+def kinetic_energy(bodylist, frame):
Jason K. Moore Collaborator

why not do this?

def kinetic_energy(frame, *args):

Then the user doesn't have to put anything in a list as an extra step. They call:

ke = kinetic_energy(N, particle1, body2)

And if the user happens to have particles and bodies stored is some sort of sequence they can simply use this notation when calling:

bodies = (particle1, body2)
ke = kinetic_energy(N, *bodies)

This seems like less overhead and simpler and it also avoides having to error check for a list which is problematic because there is nothing wrong with supplying other types of sequences like a tuple.

Angadh Nanjangud
angadhn added a note

When I wrote this, I was looking at how things were setup to derive the equations of motion of a system in Kane. Since the bodylist was anyhow required there, I thought it best to use what the user already prepared for Kane.

Angadh Nanjangud
angadhn added a note

Also in the other comment above , I have addressed how the issue of a tuple can be dealt with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 02547c0b into 9625918).

Ondřej Čertík
Owner

SymPy Bot Summary: :red_circle: There were test failures (merged angadhn/dev (02547c0b7c48c3f90ddf1f96c7b11204a736b588) into master (9625918)).

@angadhn: Please fix the test failures.

Interpreter 1: :red_circle: There were test failures.
Interpreter: /usr/bin/python3 (3.2.3-final-0)
Architecture: Linux (64-bit)

Angadh Nanjangud

oops. fixed it.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 6524040b into 9625918).

sympy/physics/mechanics/functions.py
((67 lines not shown))
+ >>> A = RigidBody('A', Ac, a, 20, (I, Ac))
+ >>> BL = [Pa, A]
+ >>> kinetic_energy(BL, N)
+ 350
+
+ """
+
+ bodylist = list(bodylist)
+ if not isinstance(bodylist, list):
+ raise TypeError('System elements must be supplied as a list')
+ else:
+ KE_sys = 0
+ for e in bodylist:
+ if isinstance(e, (RigidBody, Particle)):
+ KE_individual = e.kinetic_energy(frame)
+ KE_sys = KE_sys + KE_individual
Jason K. Moore Collaborator

all this can be written like:

ke_sys += e.kinetic_energy(frame)

No extra variable needed.

Check PEP8 too, leading caps in variable names is not really recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((76 lines not shown))
+ raise TypeError('System elements must be supplied as a list')
+ else:
+ KE_sys = 0
+ for e in bodylist:
+ if isinstance(e, (RigidBody, Particle)):
+ KE_individual = e.kinetic_energy(frame)
+ KE_sys = KE_sys + KE_individual
+ else:
+ raise TypeError('Body list must have only Particle'
+ 'or RigidBody')
+ return KE_sys
+
+def potential_energy(bodylist):
+ """Potential energy of a multibody system.
+
+ This function returns the kinetic energy of a system of Particle's and/or
Jason K. Moore Collaborator

kinetic -> potential

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jason K. Moore moorepants commented on the diff
sympy/physics/mechanics/functions.py
((111 lines not shown))
+ >>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame
+ >>> from sympy.physics.mechanics import RigidBody, outer, potential_energy
+ >>> from sympy import symbols
+ >>> M, m, g, h = symbols('M m g h')
+ >>> N = ReferenceFrame('N')
+ >>> O = Point('O')
+ >>> O.set_vel(N, 0 * N.x)
+ >>> P = O.locatenew('P', 1 * N.x)
+ >>> Pa = Particle('Pa', P, m)
+ >>> Ac = O.locatenew('Ac', 2 * N.y)
+ >>> a = ReferenceFrame('a')
+ >>> I = outer(N.z, N.z)
+ >>> A = RigidBody('A', Ac, a, M, (I, Ac))
+ >>> BL = [Pa, A]
+ >>> Pa.set_potential_energy(m * g * h)
+ >>> A.set_potential_energy(M * g * h)
Jason K. Moore Collaborator

Would it be more useful to have an optional argument in potential energy or some other way to pass in the potential energy definitions? Seems like if you have to call .set_potential_energy for everything seperately anyways, what is the point of this function? It only takes a short one liner to sum up the potential energies if you've already defined them. Maybe something like:

potential_energy(Pa, A, expressions=(m * g * h, M * g * h))

Then you at least don't have to type .set_potential_energy so many times.

Ondřej Čertík Owner
certik added a note

@angadhn, this comment still applies I think.

Angadh Nanjangud
angadhn added a note

So I have addressed this in one of the comments earlier where Jason discusses the 'decorators'. Let me tag you on that comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((125 lines not shown))
+ >>> Pa.set_potential_energy(m * g * h)
+ >>> A.set_potential_energy(M * g * h)
+ >>> potential_energy(BL)
+ M*g*h + g*h*m
+
+ """
+
+ bodylist = list(bodylist)
+ if not isinstance(bodylist, list):
+ raise TypeError('System elements must be supplied as a list')
+ else:
+ PE_sys = 0
+ for e in bodylist:
+ if isinstance(e, (RigidBody, Particle)):
+ PE_individual = e.potential_energy
+ PE_sys = PE_sys + PE_individual
Jason K. Moore Collaborator

pe_sys += e.potential_energy(frame)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((124 lines not shown))
+ >>> BL = [Pa, A]
+ >>> Pa.set_potential_energy(m * g * h)
+ >>> A.set_potential_energy(M * g * h)
+ >>> potential_energy(BL)
+ M*g*h + g*h*m
+
+ """
+
+ bodylist = list(bodylist)
+ if not isinstance(bodylist, list):
+ raise TypeError('System elements must be supplied as a list')
+ else:
+ PE_sys = 0
+ for e in bodylist:
+ if isinstance(e, (RigidBody, Particle)):
+ PE_individual = e.potential_energy
Jason K. Moore Collaborator

You can get an AttributeError here if the particle or body has no potential_energy defined. You should catch it and give the user a useful message about being sure to define it previously.

Aaron Meurer Owner
asmeurer added a note

Perhaps RigitBody and Particle should define no-op potential_energy that has the error message there.

Angadh Nanjangud
angadhn added a note

Fixed this using 'callable'. It should check if the potential energy has been set or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/particle.py
((12 lines not shown))
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the particle
+
+ The kinetic energy, T, of a particle,P, is given by
+
+ T = 0.5 * m * v**2
+
+ where m is the mass of particle P, and v is the velocity of the
+ particle in the supplied ReferenceFrame.
+
+ Parameters
+ ==========
+
+ frame : ReferenceFrame
+ The Particle's velocity is typically defined with respect to
+ an inertial frame but any relevant frame in which the velcoity is
Jason K. Moore Collaborator

velcoity -> velocity

Make sure to run your spell checker. In vim it is:

:set spell "on

:set nospell "off
Angadh Nanjangud
angadhn added a note

Thanks for both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 9625918
branch hash: 6524040ba1fd37c0675f7e7dfa9131a4768eabb7

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYx6MjDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYkO0iDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY1tUiDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYsN0iDA

Automatic review by SymPy Bot.

sympy/physics/mechanics/particle.py
((56 lines not shown))
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Particle, Point
+ >>> from sympy import symbols
+ >>> m, g, h = symbols('m g h')
+ >>> O = Point('O')
+ >>> P = Particle('P', O, m)
+ >>> P.set_potential_energy(m * g * h)
+
+ """
+ scalar = sympify(scalar)
+ self._pe = scalar
+
+ @property
Jason K. Moore Collaborator

Is the only point of have the @property decorator so that you can write a doc string for the .potential_energy attribute? I'm not sure what the reason for it is? What happens when you try to set the .potential_energy directly?

You could get rid of the set_method and the decorated function. What if it just went like this:

>>> P.potential_energy = m * g * h
>>> P.potential_energy
m*g*h

You can make use of the @property to at least error check whatever folks assign to .potential_energy but you aren't doing that here. I'm curious why you have the extra overhead of the set method and @property decorator?

Angadh Nanjangud
angadhn added a note

Well, right now it looks redundant. But we felt that we can later add more functionality to the 'set' method i.e. having it compute the potential energy due to gravity or a constant force or a spring force, which are pretty standard. SO we felt that it could be useful to have a method to 'set' and then have it as a property.

Jason K. Moore Collaborator

ok

Angadh Nanjangud
angadhn added a note

@certik here is that comment on 'decorators' I was talking about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
@@ -180,3 +180,101 @@ def angularmomentum(self, point, frame):
return ((self.inertia[0] & self.frame.ang_vel_in(frame)) +
(point.vel(frame) ^ -self.masscenter.pos_from(point)) *
self.mass)
+
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the particle
Jason K. Moore Collaborator

particle -> RigidBody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
@@ -180,3 +180,101 @@ def angularmomentum(self, point, frame):
return ((self.inertia[0] & self.frame.ang_vel_in(frame)) +
(point.vel(frame) ^ -self.masscenter.pos_from(point)) *
self.mass)
+
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the particle
+
+ The kinetic energy, T, of a rigid body, B, is given by
+
+ T = (omega . (I* . omega)) + (0.5 * m * v **2)
Jason K. Moore Collaborator

You may want to clarify that . = dot product, I haven't seen this anywhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
((22 lines not shown))
+ any relevant frame in which the velocity is 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)
Jason K. Moore Collaborator

Inertia_tuple -> inertia_tuple (PEP8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
((35 lines not shown))
+ >>> 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.kinetic_energy(N)
+ M*v**2/2 + omega**2/2
+
+ """
+
+ Rotational_KE = (self.frame.ang_vel_in(frame) & (self.inertia[0] &
+ 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)
Jason K. Moore Collaborator

the parentheses are not needed, in fact it may return a tuple...but maybe not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/rigidbody.py
((29 lines not shown))
+ >>> 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.kinetic_energy(N)
+ M*v**2/2 + omega**2/2
+
+ """
+
+ Rotational_KE = (self.frame.ang_vel_in(frame) & (self.inertia[0] &
Jason K. Moore Collaborator

I'd read over PEP8 and adjust many or your variable names. I don't think the leading caps (or caps at all) are preferred. mixedCase is potentially, but these stand out to me. But I'm not completely sure and variable names don't seem to be a super concern in PEP8, but it's worth reading into to it just to get refreshed every once in a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jason K. Moore moorepants commented on the diff
sympy/physics/mechanics/tests/test_functions.py
@@ -4,8 +4,9 @@
kinematic_equations, Vector,
inertia_of_point_mass, partial_velocity,
outer, Particle,
- Point, RigidBody, angularmomentum,
Jason K. Moore Collaborator

Did you remove Point? Isn't that needed below?

Angadh Nanjangud
angadhn added a note

It was an additional 'Point' so I took it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/tests/test_functions.py
((10 lines not shown))
+ m, M, l1 = symbols('m M l1')
+ omega = dynamicsymbols('omega')
+ N = ReferenceFrame('N')
+ O = Point('O')
+ O.set_vel(N, 0 * N.x)
+ Ac = O.locatenew('Ac', l1 * N.x)
+ P = Ac.locatenew('P', l1 * N.x)
+ a = ReferenceFrame('a')
+ a.set_ang_vel(N, omega * N.z)
+ Ac.v2pt_theory(O, N, a)
+ P.v2pt_theory(O, N, a)
+ Pa = Particle('Pa', P, m)
+ I = outer(N.z, N.z)
+ A = RigidBody('A', Ac, a, M, (I, Ac))
+ BL =[Pa, A]
+ assert kinetic_energy(BL, N) == (M*l1**2*omega**2/2 + 2*l1**2*m*omega**2
Jason K. Moore Collaborator

Does this return a tuple? I don't think it should.

Also, is it better to assert that:

assert 0 == kinetic_energy(BL, N) - (M*l1**2*omega**2/2 + 2*l1**2*m*omega**2+ omega**2/2)

I vaguely remember Gilbert asking about this last year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jason K. Moore
Collaborator

I just went through this and picked out some potential issues. Hope it helps.

sympy/physics/mechanics/functions.py
((16 lines not shown))
for e in bodylist:
if isinstance(e, (RigidBody, Particle)):
- lm_individual = e.linearmomentum(frame)
- linearmomentum_sys = linearmomentum_sys + lm_individual
+ lm_individual = e.linear_momentum(frame)
+ linear_momentum_sys = linear_momentum_sys + lm_individual
Aaron Meurer Owner
asmeurer added a note

Just do linear_momentum_sys += e.linear_momentum(frame). There's no need to create the intermediate variable that is not used again.

Ondřej Čertík Owner
certik added a note

@angadhn, this comment still applies I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged ce96f6d5 into 7d92368).

sympy/physics/mechanics/functions.py
((65 lines not shown))
+ >>> a.set_ang_vel(N, 10 * N.z)
+ >>> I = outer(N.z, N.z)
+ >>> A = RigidBody('A', Ac, a, 20, (I, Ac))
+ >>> kinetic_energy(N, Pa, A)
+ 350
+
+ """
+
+ if not isinstance(frame, ReferenceFrame):
+ raise TypeError('Please enter a valid ReferenceFrame')
+ ke_sys = 0
+ for e in body:
+ if isinstance(e, (RigidBody, Particle)):
+ ke_sys += e.kinetic_energy(frame)
+ else:
+ raise TypeError('*bodies must have only Particle or RigidBody')
Jason K. Moore Collaborator

You use the variable body in your source not bodies.

Angadh Nanjangud
angadhn added a note

Fixed it. So do you think this is good to be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 53b6bc2d into 41e968b).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 1627b32
branch hash: 53b6bc2d1f2dd99f6d27a4c154481fa463b0a2ec

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYhpQjDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYuY8iDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYgsYiDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY0qMjDA

Automatic review by SymPy Bot.

Ondřej Čertík
Owner

@angadhn, can you please address all Aaron's and Jason's comments above? E.g. things about the "isinstance" as well as the "+=". Then we can merge it.

Angadh Nanjangud

Hi @certik, I believe I have already addressed the issues.
angadhn@53b6bc2

Ondřej Čertík
Owner

First one note for any PR ---- just keep adding patches to your branch, so that we can quickly see what has changed and one can read the whole PR as a history or "story". If you rebase, then suddenly all the test results stop having any sense.
Only at the very end, when the PR is ready to go in, and the history is really ugly (which actually is rarely the case), then one can do a quick rebase and merge it.

Now I am going to comment to all the comments that you didn't address, so they will show up below. Edit: so they don't appear below, but above.

Ondřej Čertík
Owner

Looks like you rebased again...

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 1ba125ec into bd49e6a).

Angadh Nanjangud

Must've done that again mistakenly. Apologies.

sympy/physics/mechanics/rigidbody.py
((65 lines not shown))
+
+ >>> from sympy.physics.mechanics import Particle, Point, outer
+ >>> from sympy.physics.mechanics import RigidBody, ReferenceFrame
+ >>> from sympy import symbols
+ >>> b = ReferenceFrame('b')
+ >>> M, g, h = symbols('M g h')
+ >>> P = Point('P')
+ >>> I = outer (b.x, b.x)
+ >>> Inertia_tuple = (I, P)
+ >>> B = RigidBody('B', P, b, M, Inertia_tuple)
+ >>> B.set_potential_energy(M * g * h)
+
+ """
+
+ scalar = sympify(scalar)
+ self._pe = scalar
Jason K. Moore Collaborator

Why two lines?

self._pe = sympify(scalar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged caa2aa88 into bd49e6a).

sympy/physics/mechanics/functions.py
((11 lines not shown))
if not isinstance(bodylist, list):
raise TypeError('System elements must be supplied as a list')
else:
- linearmomentum_sys = 0
+ linear_momentum_sys = 0

Would returning S(0) here be better, to get a SymPy object? I've had other difficulties in mechanics with returning integers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/mechanics/functions.py
((11 lines not shown))
if not isinstance(bodylist, list):
raise TypeError('System elements must be supplied as a list')
else:
- angularmomentum_sys = 0
+ angular_momentum_sys = 0

Same comment about S(0)

Angadh Nanjangud
angadhn added a note

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 0d88b25
branch hash: caa2aa8836cadb302a33bf511f9f6264f762e9d5

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYwo8iDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYwt0iDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYnfAhDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYq4wjDA

Automatic review by SymPy Bot.

Angadh Nanjangud

I have also fixed the html doc errors in the latest commit and addressed all issues brought up thus far.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 57f1c042 into 0d88b25).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 2fa49af6 into 0d88b25).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 0d88b25
branch hash: 2fa49af623f5af1f8e4ac9ab5aa9822681ecd550

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYxrYiDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYofAhDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY59UiDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYjsYiDA

Automatic review by SymPy Bot.

Ondřej Čertík
Owner

@angadhn, did you see my comment about rebasing? See also:

https://groups.google.com/d/topic/sympy/T2NfDo17wqc/discussion

Please stop rebasing, just keep pushing new patches in.

You still didn't address the points, that I mentioned:

https://github.com/sympy/sympy/pull/1407/files#r1306927
https://github.com/sympy/sympy/pull/1407/files#r1306929
https://github.com/sympy/sympy/pull/1407/files#r1307067

Can you please do that soon? Just push new patches in, let's do final review and push it in. Thanks!

Angadh Nanjangud

@certik I have stopped rebasing. Sorry about that mess.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 50b2496f into 0d88b25).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 15c2c89
branch hash: 50b2496fba8ef6df10c5032088b1c4965dbf2f7c

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYre0iDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYr4wjDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYo_AhDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY7tUiDA

Automatic review by SymPy Bot.

Angadh Nanjangud

I think this error may be due to the whole rebasing issue. I have fixed this in my last commit. Sorry for the confusion.

Angadh Nanjangud

@certik I am uncertain of how to interpret the docstring error but I have corrected what I believe was causing the error. I believe I have addressed all the concerns.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 5492ef80 into 15c2c89).

Ondřej Čertík
Owner

Thanks. This PR is +1 from me. I am just waiting for one last pass of Stefan's bot to make sure the "make html" passes as well, and then I'll merge it.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@angadhn: Please fix the test failures.

Test command: setup.py test
master hash: 15c2c89
branch hash: 5492ef80cfd9b63b0e65fb6432948ff6df012dd1

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYzY8iDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYyN0iDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY5KMjDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYr-0iDA

Automatic review by SymPy Bot.

Ondřej Čertík
Owner

Ok, so the "make html" has to be fixed. @angadhn, are you able to reproduce the warning? Just do "make html", try to build the docs and see if you can see the warning.

sympy/physics/mechanics/particle.py
((6 lines not shown))
m*r*v*N.z
"""
return self.point.pos_from(point) ^ (self.mass * self.point.vel(frame))
+
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the particle
+
+ The kinetic energy, T, of a particle,P, is given by
+
+ T = 0.5 * m * v**2
Ondřej Čertík Owner
certik added a note

I think that the "make html" failure is caused by this line. Do we have some way to specify math in sympy? If not, just write it as:

T = 1/2 * m * v^2

That should be clear. Also, while you are at it ---- put one space before "P" in "of a particle,P, is".

Aaron Meurer Owner
asmeurer added a note

Yes, use single backticks, like `T = 1/2 m v^2`. Note that you need to use LaTeX notation here.

Angadh Nanjangud
angadhn added a note

Thanks for all the help. It passed the doctest now. Hopefully it goes smoothly from hereon. Thanks a bunch again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ondřej Čertík
Owner

@angadhn, there are several warnings, see my log here: https://gist.github.com/3305562, and no warnings in master.
Do:

cd doc
make html

and let me know if you can reproduce my log. Then the next step will be to fix the warnings.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged e16691a into dd8352a).

Aaron Meurer
Owner

SymPy Bot Summary: :red_circle: There were test failures (merged angadhn/dev (e16691a) into master (dd8352a)).
@angadhn: Please fix the test failures.
Build HTML Docs: :red_circle: There were test failures: 1.1.3

Angadh Nanjangud

I'm unable to recreate these errors with 'make html'. Just checked again to make sure I did run things on the right branch.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test command: setup.py test
master hash: dd8352a
branch hash: e16691a

Interpreter 1: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYqPAhDA

Interpreter 2: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYlcYiDA

Interpreter 3: :eight_spoked_asterisk: All tests have passed.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYzKsjDA

Build HTML Docs: :eight_spoked_asterisk: All tests have passed.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY07YiDA

Automatic review by SymPy Bot.

Aaron Meurer
Owner

@angadhn try make clean; make html.

Angadh Nanjangud

still nothing. but it looks like the tests passed.

Aaron Meurer
Owner

SymPy Bot Summary: :red_circle: There were test failures (merged angadhn/dev (e16691a) into master (dd8352a)).
@angadhn: Please fix the test failures.
Build HTML Docs: :red_circle: There were test failures: 1.1.3

Aaron Meurer
Owner

I also can't reproduce it outside of sympy-bot. So I don't know what's going on. Sphinx seems to be quite buggy.

Aaron Meurer
Owner

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed (merged angadhn/dev (e16691a) into master (dd8352a)).
Build HTML Docs: :eight_spoked_asterisk: All tests have passed: 1.1.3
Docs build command: make clean; make html

Ondřej Čertík
Owner

@angadhn, you seem to have rebased yet again... Since I asked you three times and you didn't manage not to rebase a single time, there must be some technical difficulties. Are you doing "git rebase master"? Or are you doing "git commit --amend"? Please don't do any of these once your branch us up there. You can notice that when you push, git will refuse to push and you have to force it (typically with "+"). This is a sign that you have rebased. (If that happens, you can just rebase on top of the commit that is out here --- feel free to ask on the mailinglist if you have any problems with git.)

Anyway, this patch is +1 from me. Well, you did not address my comment about adding a space before "P"... But let's just get this merged, I don't want to delay this anymore.

Ondřej Čertík certik merged commit 85a4a4e into from
Angadh Nanjangud

I haven't been rebasing but I have been amending and the forcing it, like you said. I will keep your advice in mind from here on. Sorry about this, again.

Gilbert Gede

Thanks everyone for getting this in.

Ondřej Čertík
Owner

No problem. Let's get the other PRs in as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
12 doc/src/modules/physics/mechanics/api/part_bod.rst
View
@@ -28,13 +28,13 @@ inertia_of_point_mass
.. autofunction:: sympy.physics.mechanics.functions.inertia_of_point_mass
-linearmomentum
-==============
+linear_momentum
+===============
-.. autofunction:: sympy.physics.mechanics.functions.linearmomentum
+.. autofunction:: sympy.physics.mechanics.functions.linear_momentum
-angularmomentum
-===============
+angular_momentum
+================
-.. autofunction:: sympy.physics.mechanics.functions.angularmomentum
+.. autofunction:: sympy.physics.mechanics.functions.angular_momentum
176 sympy/physics/mechanics/functions.py
View
@@ -10,8 +10,10 @@
'kinematic_equations',
'inertia_of_point_mass',
'partial_velocity',
- 'linearmomentum',
- 'angularmomentum']
+ 'linear_momentum',
+ 'angular_momentum',
+ 'kinetic_energy',
+ 'potential_energy']
from sympy.physics.mechanics.essential import (Vector, Dyadic, ReferenceFrame,
MechanicsStrPrinter,
@@ -20,7 +22,9 @@
dynamicsymbols)
from sympy.physics.mechanics.particle import Particle
from sympy.physics.mechanics.rigidbody import RigidBody
+from sympy.physics.mechanics.point import Point
from sympy import sympify, diff, sin, cos, Matrix
+from sympy.core.basic import S
def cross(vec1, vec2):
"""Cross product convenience wrapper for Vector.cross(): \n"""
@@ -448,7 +452,7 @@ def partial_velocity(vel_list, u_ind_list):
i = i + 1
return list_of_pvlists
-def linearmomentum(bodylist, frame):
+def linear_momentum(frame, *body):
"""Linear momentum of the system.
This function returns the linear momentum of a system of Particle's and/or
@@ -460,17 +464,18 @@ def linearmomentum(bodylist, frame):
L = L1 + L2
- bodylist : list
- A list of all RigidBody's and Particle's in the system.
-
frame : ReferenceFrame
The frame in which linear momentum is desired.
+ body1, body2, body3... : Particle and/or RigidBody
+ The body (or bodies) whose kinetic energy is required.
+
+
Examples
========
>>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame
- >>> from sympy.physics.mechanics import RigidBody, outer, linearmomentum
+ >>> from sympy.physics.mechanics import RigidBody, outer, linear_momentum
>>> N = ReferenceFrame('N')
>>> P = Point('P')
>>> P.set_vel(N, 10 * N.x)
@@ -479,26 +484,23 @@ def linearmomentum(bodylist, frame):
>>> Ac.set_vel(N, 25 * N.y)
>>> I = outer(N.x, N.x)
>>> A = RigidBody('A', Ac, N, 20, (I, Ac))
- >>> BL = [Pa, A]
- >>> print linearmomentum(BL, N)
+ >>> linear_momentum(N, A, Pa)
10*N.x + 500*N.y
"""
- if not isinstance(bodylist, list):
- raise TypeError('System elements must be supplied as a list')
+ if not isinstance(frame, ReferenceFrame):
+ raise TypeError('Please specify a valid ReferenceFrame')
else:
- linearmomentum_sys = 0
- for e in bodylist:
+ linear_momentum_sys = S(0)
+ for e in body:
if isinstance(e, (RigidBody, Particle)):
- lm_individual = e.linearmomentum(frame)
- linearmomentum_sys = linearmomentum_sys + lm_individual
+ linear_momentum_sys += e.linear_momentum(frame)
else:
- raise TypeError('Body list must have only Particle'
- 'or RigidBody')
- return linearmomentum_sys
+ raise TypeError('*body must have only Particle or RigidBody')
+ return linear_momentum_sys
-def angularmomentum(bodylist, point, frame):
+def angular_momentum(point, frame, *body):
"""Angular momentum of a system
This function returns the angular momentum of a system of Particle's and/or
@@ -513,20 +515,20 @@ def angularmomentum(bodylist, point, frame):
Parameters
==========
- bodylist : list
- A list of all RigidBody's and Particle's in the system.
-
point : Point
The point about which angular momentum of the system is desired.
frame : ReferenceFrame
The frame in which angular momentum is desired.
+ body1, body2, body3... : Particle and/or RigidBody
+ The body (or bodies) whose kinetic energy is required.
+
Examples
========
>>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame
- >>> from sympy.physics.mechanics import RigidBody, outer, angularmomentum
+ >>> from sympy.physics.mechanics import RigidBody, outer, angular_momentum
>>> N = ReferenceFrame('N')
>>> O = Point('O')
>>> O.set_vel(N, 0 * N.x)
@@ -539,21 +541,127 @@ def angularmomentum(bodylist, point, frame):
>>> a.set_ang_vel(N, 10 * N.z)
>>> I = outer(N.z, N.z)
>>> A = RigidBody('A', Ac, a, 20, (I, Ac))
- >>> BL = [Pa, A]
- >>> print angularmomentum(BL, O, N)
+ >>> angular_momentum(O, N, Pa, A)
10*N.z
"""
- if not isinstance(bodylist, list):
- raise TypeError('System elements must be supplied as a list')
+ if not isinstance(frame, ReferenceFrame):
+ raise TypeError('Please enter a valid ReferenceFrame')
+ if not isinstance(point, Point):
+ raise TypeError('Please specify a valid Point')
else:
- angularmomentum_sys = 0
- for e in bodylist:
+ angular_momentum_sys = S(0)
+ for e in body:
if isinstance(e, (RigidBody, Particle)):
- angmom_individual = e.angularmomentum(point, frame)
- angularmomentum_sys = angularmomentum_sys + angmom_individual
+ angular_momentum_sys += e.angular_momentum(point, frame)
else:
- raise TypeError('Body list must have only Particle'
- 'or RigidBody')
- return angularmomentum_sys
+ raise TypeError('*body must have only Particle or RigidBody')
+ return angular_momentum_sys
+
+def kinetic_energy(frame, *body):
+ """Kinetic energy of a multibody system.
+
+ This function returns the kinetic energy of a system of Particle's and/or
+ RigidBody's. The kinetic energy of such a system is equal to the sum of
+ the kinetic energies of its constituents. Consider a system, S, comprising
+ a rigid body, A, and a particle, P. The kinetic energy of the system, T,
+ is equal to the vector sum of the kinetic energy of the particle, T1, and
+ the kinetic energy of the rigid body, T2, i.e.
+
+ T = T1 + T2
+
+ Kinetic energy is a scalar.
+
+ Parameters
+ ==========
+
+ frame : ReferenceFrame
+ The frame in which angular momentum is desired.
+
+ body1, body2, body3... : Particle and/or RigidBody
+ The body (or bodies) whose kinetic energy is required.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame
+ >>> from sympy.physics.mechanics import RigidBody, outer, kinetic_energy
+ >>> N = ReferenceFrame('N')
+ >>> O = Point('O')
+ >>> O.set_vel(N, 0 * N.x)
+ >>> P = O.locatenew('P', 1 * N.x)
+ >>> P.set_vel(N, 10 * N.x)
+ >>> Pa = Particle('Pa', P, 1)
+ >>> Ac = O.locatenew('Ac', 2 * N.y)
+ >>> Ac.set_vel(N, 5 * N.y)
+ >>> a = ReferenceFrame('a')
+ >>> a.set_ang_vel(N, 10 * N.z)
+ >>> I = outer(N.z, N.z)
+ >>> A = RigidBody('A', Ac, a, 20, (I, Ac))
+ >>> kinetic_energy(N, Pa, A)
+ 350
+
+ """
+
+ if not isinstance(frame, ReferenceFrame):
+ raise TypeError('Please enter a valid ReferenceFrame')
+ ke_sys = S(0)
+ for e in body:
+ if isinstance(e, (RigidBody, Particle)):
+ ke_sys += e.kinetic_energy(frame)
+ else:
+ raise TypeError('*body must have only Particle or RigidBody')
+ return ke_sys
+
+def potential_energy(*body):
+ """Potential energy of a multibody system.
+
+ This function returns the potential energy of a system of Particle's and/or
+ RigidBody's. The potential energy of such a system is equal to the sum of
+ the potential energy of its constituents. Consider a system, S, comprising
+ a rigid body, A, and a particle, P. The potential energy of the system, V,
+ is equal to the vector sum of the potential energy of the particle, V1, and
+ the potential energy of the rigid body, V2, i.e.
+
+ V = V1 + V2
+
+ Potential energy is a scalar.
+
+ Parameters
+ ==========
+
+ body1, body2, body3... : Particle and/or RigidBody
+ The body (or bodies) whose potential energy is required.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame
+ >>> from sympy.physics.mechanics import RigidBody, outer, potential_energy
+ >>> from sympy import symbols
+ >>> M, m, g, h = symbols('M m g h')
+ >>> N = ReferenceFrame('N')
+ >>> O = Point('O')
+ >>> O.set_vel(N, 0 * N.x)
+ >>> P = O.locatenew('P', 1 * N.x)
+ >>> Pa = Particle('Pa', P, m)
+ >>> Ac = O.locatenew('Ac', 2 * N.y)
+ >>> a = ReferenceFrame('a')
+ >>> I = outer(N.z, N.z)
+ >>> A = RigidBody('A', Ac, a, M, (I, Ac))
+ >>> BL = [Pa, A]
+ >>> Pa.set_potential_energy(m * g * h)
+ >>> A.set_potential_energy(M * g * h)
Jason K. Moore Collaborator

Would it be more useful to have an optional argument in potential energy or some other way to pass in the potential energy definitions? Seems like if you have to call .set_potential_energy for everything seperately anyways, what is the point of this function? It only takes a short one liner to sum up the potential energies if you've already defined them. Maybe something like:

potential_energy(Pa, A, expressions=(m * g * h, M * g * h))

Then you at least don't have to type .set_potential_energy so many times.

Ondřej Čertík Owner
certik added a note

@angadhn, this comment still applies I think.

Angadh Nanjangud
angadhn added a note

So I have addressed this in one of the comments earlier where Jason discusses the 'decorators'. Let me tag you on that comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ >>> potential_energy(Pa, A)
+ M*g*h + g*h*m
+
+ """
+
+ pe_sys = S(0)
+ for e in body:
+ if isinstance(e, (RigidBody, Particle)):
+ pe_sys += e.potential_energy
+ else:
+ raise TypeError('*body must have only Particle or RigidBody')
+ return pe_sys
91 sympy/physics/mechanics/particle.py
View
@@ -41,6 +41,7 @@ def __init__(self, name, point, mass):
self._name = name
self.set_mass(mass)
self.set_point(point)
+ self._pe = None
def __str__(self):
return self._name
@@ -67,7 +68,7 @@ def set_point(self, p):
point = property(get_point, set_point)
- def linearmomentum(self, frame):
+ def linear_momentum(self, frame):
"""Linear momentum of the particle.
The linear momentum L, of a particle P, with respect to frame N is
@@ -94,14 +95,14 @@ def linearmomentum(self, frame):
>>> P = Point('P')
>>> A = Particle('A', P, m)
>>> P.set_vel(N, v * N.x)
- >>> print A.linearmomentum(N)
+ >>> A.linear_momentum(N)
m*v*N.x
"""
return self.mass * self.point.vel(frame)
- def angularmomentum(self, point, frame):
+ def angular_momentum(self, point, frame):
"""Angular momentum of the particle about the point.
The angular momentum H, about some point O of a particle, P, is given
@@ -133,9 +134,91 @@ def angularmomentum(self, point, frame):
>>> A = O.locatenew('A', r * N.x)
>>> P = Particle('P', A, m)
>>> P.point.set_vel(N, v * N.y)
- >>> print P.angularmomentum(O, N)
+ >>> P.angular_momentum(O, N)
m*r*v*N.z
"""
return self.point.pos_from(point) ^ (self.mass * self.point.vel(frame))
+
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the particle
+
+ The kinetic energy, T, of a particle,P, is given by
+
+ 'T = 1/2 m v^2'
+
+ where m is the mass of particle P, and v is the velocity of the
+ particle in the supplied ReferenceFrame.
+
+ Parameters
+ ==========
+
+ frame : ReferenceFrame
+ The Particle's velocity is typically defined with respect to
+ an inertial frame but any relevant frame in which the velocity is
+ known can be supplied.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Particle, Point, ReferenceFrame
+ >>> from sympy import symbols
+ >>> m, v, r = symbols('m v r')
+ >>> N = ReferenceFrame('N')
+ >>> O = Point('O')
+ >>> P = Particle('P', O, m)
+ >>> P.point.set_vel(N, v * N.y)
+ >>> P.kinetic_energy(N)
+ m*v**2/2
+
+ """
+
+ return (self.mass / sympify(2) * self.point.vel(frame) &
+ self.point.vel(frame))
+
+ def set_potential_energy(self, scalar):
+ """Used to set the potential energy of the Particle.
+
+ Parameters
+ ==========
+
+ scalar : Sympifyable
+ The potential energy (a scalar) of the Particle.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Particle, Point
+ >>> from sympy import symbols
+ >>> m, g, h = symbols('m g h')
+ >>> O = Point('O')
+ >>> P = Particle('P', O, m)
+ >>> P.set_potential_energy(m * g * h)
+
+ """
+
+ self._pe = sympify(scalar)
+
+ @property
+ def potential_energy(self):
+ """The potential energy of the Particle.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Particle, Point
+ >>> from sympy import symbols
+ >>> m, g, h = symbols('m g h')
+ >>> O = Point('O')
+ >>> P = Particle('P', O, m)
+ >>> P.set_potential_energy(m * g * h)
+ >>> P.potential_energy
+ g*h*m
+
+ """
+
+ if callable(self._pe) == True:
+ return self._pe
+ else:
+ raise ValueError('Please set the potential energy of the Particle')
108 sympy/physics/mechanics/rigidbody.py
View
@@ -100,7 +100,7 @@ def set_inertia(self, I):
inertia = property(get_inertia, set_inertia)
- def linearmomentum(self, frame):
+ def linear_momentum(self, frame):
""" Linear momentum of the rigid body.
The linear momentum L, of a rigid body B, with respect to frame N is
@@ -129,14 +129,14 @@ def linearmomentum(self, frame):
>>> I = outer (N.x, N.x)
>>> Inertia_tuple = (I, P)
>>> B = RigidBody('B', P, N, M, Inertia_tuple)
- >>> B.linearmomentum(N)
+ >>> B.linear_momentum(N)
M*v*N.x
"""
return self.mass * self.masscenter.vel(frame)
- def angularmomentum(self, point, frame):
+ def angular_momentum(self, point, frame):
""" Angular momentum of the rigid body.
The angular momentum H, about some point O, of a rigid body B, in a
@@ -172,7 +172,7 @@ def angularmomentum(self, point, frame):
>>> I = outer (b.x, b.x)
>>> Inertia_tuple = (I, P)
>>> B = RigidBody('B', P, b, M, Inertia_tuple)
- >>> B.angularmomentum(P, N)
+ >>> B.angular_momentum(P, N)
omega*b.x
"""
@@ -180,3 +180,103 @@ def angularmomentum(self, point, frame):
return ((self.inertia[0] & self.frame.ang_vel_in(frame)) +
(point.vel(frame) ^ -self.masscenter.pos_from(point)) *
self.mass)
+
+ def kinetic_energy(self, frame):
+ """Kinetic energy of the rigid body
+
+ The kinetic energy, T, of a rigid body, B, is given by
+
+ 'T = 1/2 (I omega^2 + m v^2)'
+
+ where I and m are the central inertia dyadic and mass of rigid body B,
+ respectively, omega is the body's angular velocity and 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 is typically defined with respect to an inertial frame but
+ any relevant frame in which the velocity is 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.kinetic_energy(N)
+ M*v**2/2 + omega**2/2
+
+ """
+
+ rotational_KE = (self.frame.ang_vel_in(frame) & (self.inertia[0] &
+ 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
+
+ def set_potential_energy(self, scalar):
+ """Used to set the potential energy of this RigidBody.
+
+ Parameters
+ ==========
+
+ scalar: Sympifyable
+ The potential energy (a scalar) of the RigidBody.
+
+ Examples
+ ========
+
+ >>> from sympy.physics.mechanics import Particle, Point, outer
+ >>> from sympy.physics.mechanics import RigidBody, ReferenceFrame
+ >>> from sympy import symbols
+ >>> b = ReferenceFrame('b')
+ >>> M, g, h = symbols('M g h')
+ >>> P = Point('P')
+ >>> I = outer (b.x, b.x)
+ >>> Inertia_tuple = (I, P)
+ >>> B = RigidBody('B', P, b, M, Inertia_tuple)
+ >>> B.set_potential_energy(M * g * h)
+
+ """
+
+ self._pe = sympify(scalar)
+
+ @property
+ def potential_energy(self):
+ """The potential energy of the RigidBody.
+
+ Examples
+ ========
+
+ >>> 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.set_potential_energy(M * g * h)
+ >>> B.potential_energy
+ M*g*h
+
+ """
+
+ if callable(self._pe) == True:
+ return self._pe
+ else:
+ raise ValueError('Please set the potential energy of the RigidBody')
54 sympy/physics/mechanics/tests/test_functions.py
View
@@ -4,8 +4,9 @@
kinematic_equations, Vector,
inertia_of_point_mass, partial_velocity,
outer, Particle,
- Point, RigidBody, angularmomentum,
Jason K. Moore Collaborator

Did you remove Point? Isn't that needed below?

Angadh Nanjangud
angadhn added a note

It was an additional 'Point' so I took it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- linearmomentum)
+ RigidBody, angular_momentum,
+ linear_momentum, kinetic_energy,
+ potential_energy)
Vector.simp = True
q1, q2, q3, q4, q5 = symbols('q1 q2 q3 q4 q5')
@@ -304,7 +305,7 @@ def test_partial_velocity():
[r*L.x, 0, L.y], [0, 0, L.z], [L.x, L.x, 0],
[cos(q2)*L.y - sin(q2)*L.z, cos(q2)*L.y - sin(q2)*L.z, 0]])
-def test_linearmomentum():
+def test_linear_momentum():
N = ReferenceFrame('N')
Ac = Point('Ac')
Ac.set_vel(N, 25 * N.y)
@@ -313,10 +314,9 @@ def test_linearmomentum():
P = Point('P')
Pa = Particle('Pa', P, 1)
Pa.point.set_vel(N, 10 * N.x)
- BL = [A, Pa]
- assert linearmomentum(BL, N) == 10 * N.x + 500 * N.y
+ assert linear_momentum(N, A, Pa) == 10 * N.x + 500 * N.y
-def test_angularmomentum_and_linearmomentum():
+def test_angular_momentum_and_linear_momentum():
m, M, l1 = symbols('m M l1')
q1d = dynamicsymbols('q1d')
N = ReferenceFrame('N')
@@ -331,6 +331,42 @@ def test_angularmomentum_and_linearmomentum():
Pa = Particle('Pa', P, m)
I = outer(N.z, N.z)
A = RigidBody('A', Ac, a, M, (I, Ac))
- BL =[Pa, A]
- assert linearmomentum(BL, N) == 2 * m * q1d* l1 * N.y + M * l1 * q1d * N.y
- assert angularmomentum(BL, O, N) == 4 * m * q1d * l1**2 * N.z + q1d * N.z
+ assert linear_momentum(N, A, Pa) == 2 * m * q1d* l1 * N.y + M * l1 * q1d * N.y
+ assert angular_momentum(O, N, A, Pa) == 4 * m * q1d * l1**2 * N.z + q1d * N.z
+
+def test_kinetic_energy():
+ m, M, l1 = symbols('m M l1')
+ omega = dynamicsymbols('omega')
+ N = ReferenceFrame('N')
+ O = Point('O')
+ O.set_vel(N, 0 * N.x)
+ Ac = O.locatenew('Ac', l1 * N.x)
+ P = Ac.locatenew('P', l1 * N.x)
+ a = ReferenceFrame('a')
+ a.set_ang_vel(N, omega * N.z)
+ Ac.v2pt_theory(O, N, a)
+ P.v2pt_theory(O, N, a)
+ Pa = Particle('Pa', P, m)
+ I = outer(N.z, N.z)
+ A = RigidBody('A', Ac, a, M, (I, Ac))
+ assert 0 == kinetic_energy(N, Pa, A) - (M*l1**2*omega**2/2
+ + 2*l1**2*m*omega**2 + omega**2/2)
+
+def test_potential_energy():
+ m, M, l1, g, h, H = symbols('m M l1 g h H')
+ omega = dynamicsymbols('omega')
+ N = ReferenceFrame('N')
+ O = Point('O')
+ O.set_vel(N, 0 * N.x)
+ Ac = O.locatenew('Ac', l1 * N.x)
+ P = Ac.locatenew('P', l1 * N.x)
+ a = ReferenceFrame('a')
+ a.set_ang_vel(N, omega * N.z)
+ Ac.v2pt_theory(O, N, a)
+ P.v2pt_theory(O, N, a)
+ Pa = Particle('Pa', P, m)
+ I = outer(N.z, N.z)
+ A = RigidBody('A', Ac, a, M, (I, Ac))
+ Pa.set_potential_energy(m * g * h)
+ A.set_potential_energy(M * g * H)
+ assert potential_energy(A, Pa) == m * g * h + M * g * H
21 sympy/physics/mechanics/tests/test_particle.py
View
@@ -2,7 +2,7 @@
from sympy.physics.mechanics import Point, Particle, ReferenceFrame
def test_particle():
- m, m2, v1, v2, v3, r = symbols('m m2 v1 v2 v3 r')
+ m, m2, v1, v2, v3, r, g, h = symbols('m m2 v1 v2 v3 r g h')
P = Point('P')
P2 = Point('P2')
p = Particle('pa', P, m)
@@ -19,14 +19,17 @@ def test_particle():
O = Point('O')
P2.set_pos(O, r * N.y)
P2.set_vel(N, v1 * N.x)
- assert p.linearmomentum(N) == m2 * v1 * N.x
- assert p.angularmomentum(O, N) == -m2 * r *v1 * N.z
+ assert p.linear_momentum(N) == m2 * v1 * N.x
+ assert p.angular_momentum(O, N) == -m2 * r *v1 * N.z
P2.set_vel(N, v2 * N.y)
- assert p.linearmomentum(N) == m2 * v2 * N.y
- assert p.angularmomentum(O, N) == 0
+ assert p.linear_momentum(N) == m2 * v2 * N.y
+ assert p.angular_momentum(O, N) == 0
P2.set_vel(N, v3 * N.z)
- assert p.linearmomentum(N) == m2 * v3 * N.z
- assert p.angularmomentum(O, N) == m2 * r * v3 * N.x
+ assert p.linear_momentum(N) == m2 * v3 * N.z
+ assert p.angular_momentum(O, N) == m2 * r * v3 * N.x
P2.set_vel(N, v1 * N.x + v2 * N.y + v3 * N.z)
- assert p.linearmomentum(N) == m2 * (v1 * N.x + v2 * N.y + v3 * N.z)
- assert p.angularmomentum(O, N) == m2 * r * (v3 * N.x - v1 * N.z)
+ assert p.linear_momentum(N) == m2 * (v1 * N.x + v2 * N.y + v3 * N.z)
+ assert p.angular_momentum(O, N) == m2 * r * (v3 * N.x - v1 * N.z)
+ p.set_potential_energy(m * g * h)
+ assert p.potential_energy == m * g * h
+ assert p.kinetic_energy(N) == m2 * v1**2 / 2 + m2 * v2**2 / 2+ m2 * v3**2 / 2
11 sympy/physics/mechanics/tests/test_rigidbody.py
View
@@ -30,10 +30,10 @@ def test_rigidbody():
# Testing linear momentum function assuming A2 is the inertial frame
N = ReferenceFrame('N')
P2.set_vel(N, v1 * N.x + v2 * N.y + v3 * N.z)
- assert B.linearmomentum(N) == m2 * (v1 * N.x + v2 * N.y + v3 * N.z)
+ assert B.linear_momentum(N) == m2 * (v1 * N.x + v2 * N.y + v3 * N.z)
def test_rigidbody2():
- M, v, r, omega = dynamicsymbols('M v r omega')
+ M, v, r, omega, g, h = dynamicsymbols('M v r omega g h')
N = ReferenceFrame('N')
b = ReferenceFrame('b')
b.set_ang_vel(N, omega * b.x)
@@ -42,8 +42,11 @@ def test_rigidbody2():
Inertia_tuple = (I, P)
B = RigidBody('B', P, b, M, Inertia_tuple)
P.set_vel(N, v * b.x)
- assert B.angularmomentum(P, N) == omega * b.x
+ assert B.angular_momentum(P, N) == omega * b.x
O = Point('O')
O.set_vel(N, v * b.x)
P.set_pos(O, r * b.y)
- assert B.angularmomentum(O, N) == omega * b.x - M*v*r*b.z
+ assert B.angular_momentum(O, N) == omega * b.x - M*v*r*b.z
+ B.set_potential_energy(M * g * h)
+ assert B.potential_energy == M * g * h
+ assert B.kinetic_energy(N) == (omega**2 + M * v**2) / 2
Something went wrong with that request. Please try again.