Kinetic and potential energy functionality. #1407

Merged
merged 1 commit into from Aug 10, 2012
View
12 doc/src/modules/physics/mechanics/api/part_bod.rst
@@ -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
View
176 sympy/physics/mechanics/functions.py
@@ -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)
@moorepants
moorepants Aug 4, 2012

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.

@certik
certik Aug 8, 2012

@angadhn, this comment still applies I think.

@angadhn
angadhn Aug 8, 2012

So I have addressed this in one of the comments earlier where Jason discusses the 'decorators'. Let me tag you on that 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
View
91 sympy/physics/mechanics/particle.py
@@ -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')
View
108 sympy/physics/mechanics/rigidbody.py
@@ -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,11 +172,111 @@ 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
"""
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')
View
54 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,
@moorepants
moorepants Aug 4, 2012

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

@angadhn
angadhn Aug 4, 2012

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

- 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
View
21 sympy/physics/mechanics/tests/test_particle.py
@@ -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
View
11 sympy/physics/mechanics/tests/test_rigidbody.py
@@ -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