def inertia_torque(rb, frame, kde_map=None, constraint_map=None, uaux=None): # get central inertia # I_S/O = I_S/S* + I_S*/O I = rb.inertia[0] - inertia_of_point_mass( rb.mass, rb.masscenter.pos_from(rb.inertia[1]), rb.frame) alpha = rb.frame.ang_acc_in(frame) omega = rb.frame.ang_vel_in(frame) if not isinstance(alpha, Vector) and alpha == 0: alpha = Vector([]) if not isinstance(omega, Vector) and omega == 0: omega = Vector([]) if uaux is not None: # auxilliary speeds do not change alpha, omega # use doit() to evaluate terms such as # Derivative(0, t) to 0. uaux_zero = dict(zip(uaux, [0] * len(uaux))) alpha = subs(alpha, uaux_zero) omega = subs(omega, uaux_zero) if kde_map is not None: alpha = subs(alpha, kde_map) omega = subs(omega, kde_map) if constraint_map is not None: alpha = subs(alpha, constraint_map) omega = subs(omega, constraint_map) return -dot(alpha, I) - dot(cross(omega, I), omega)
def partial_velocities(system, generalized_speeds, frame, kde_map=None, constraint_map=None, express_frame=None): partials = PartialVelocity(frame, generalized_speeds) if express_frame is None: express_frame = frame for p in system: if p in partials: continue if isinstance(p, Point): v = p.vel(frame) elif isinstance(p, ReferenceFrame): v = p.ang_vel_in(frame) if kde_map is not None: v = subs(v, kde_map) if constraint_map is not None: v = subs(v, constraint_map) v_r_p = {} for u in generalized_speeds: v_r_p[u] = Vector([]) if v == 0 else v.diff(u, express_frame) partials[p] = v_r_p return partials
def test_angular_momentum_and_linear_momentum(): """A rod with length 2l, centroidal inertia I, and mass M along with a particle of mass m fixed to the end of the rod rotate with an angular rate of omega about point O which is fixed to the non-particle end of the rod. The rod's reference frame is A and the inertial frame is N.""" m, M, l, I = symbols('m, M, l, I') omega = dynamicsymbols('omega') N = ReferenceFrame('N') a = ReferenceFrame('a') O = Point('O') Ac = O.locatenew('Ac', l * N.x) P = Ac.locatenew('P', l * N.x) O.set_vel(N, 0 * N.x) 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) A = RigidBody('A', Ac, a, M, (I * outer(N.z, N.z), Ac)) expected = 2 * m * omega * l * N.y + M * l * omega * N.y assert (linear_momentum(N, A, Pa) - expected) == Vector(0) expected = (I + M * l**2 + 4 * m * l**2) * omega * N.z assert (angular_momentum(O, N, A, Pa) - expected).simplify() == Vector(0)
partial_v_P = [P.vel(N).diff(ui, N) for ui in u + ua] partial_v_RO = [RO.vel(N).diff(ui, N) for ui in u + ua] # Set auxiliary generalized speeds to zero in velocity vectors P.set_vel(N, P.vel(N).subs({ua[0]: 0, ua[1]: 0, ua[2]: 0})) O.set_vel(N, O.vel(N).subs({ua[0]: 0, ua[1]: 0, ua[2]: 0})) RO.set_vel(N, RO.vel(N).subs({ua[0]: 0, ua[1]: 0, ua[2]: 0})) # Angular acceleration R.set_ang_acc(N, ud[0] * R.x + ud[1] * R.y + ud[2] * R.z) # Acceleration of mass center RO.set_acc(N, RO.vel(N).diff(t, R) + cross(R.ang_vel_in(N), RO.vel(N))) # Forces and Torques F_P = sum([cf * uv for cf, uv in zip(CF, Y)], Vector(0)) F_RO = m * g * Y.z T_R = -s * R.ang_vel_in(N) # Generalized Active forces gaf_P = [dot(F_P, pv) for pv in partial_v_P] gaf_RO = [dot(F_RO, pv) for pv in partial_v_RO] gaf_R = [dot(T_R, pv) for pv in partial_w] # Generalized Inertia forces # First, compute R^* and T^* for the rigid body R_star = -m * RO.acc(N) T_star = - dot(R.ang_acc_in(N), I)\ - cross(R.ang_vel_in(N), dot(I, R.ang_vel_in(N))) # Isolate the parts that involve only time derivatives of u's
def test_operator_match(): """Test that the output of dot, cross, outer functions match operator behavior. """ A = ReferenceFrame('A') v = A.x + A.y d = v | v zerov = Vector(0) zerod = Dyadic(0) # dot products assert d & d == dot(d, d) assert d & zerod == dot(d, zerod) assert zerod & d == dot(zerod, d) assert d & v == dot(d, v) assert v & d == dot(v, d) assert d & zerov == dot(d, zerov) assert zerov & d == dot(zerov, d) raises(TypeError, lambda: dot(d, S(0))) raises(TypeError, lambda: dot(S(0), d)) raises(TypeError, lambda: dot(d, 0)) raises(TypeError, lambda: dot(0, d)) assert v & v == dot(v, v) assert v & zerov == dot(v, zerov) assert zerov & v == dot(zerov, v) raises(TypeError, lambda: dot(v, S(0))) raises(TypeError, lambda: dot(S(0), v)) raises(TypeError, lambda: dot(v, 0)) raises(TypeError, lambda: dot(0, v)) # cross products raises(TypeError, lambda: cross(d, d)) raises(TypeError, lambda: cross(d, zerod)) raises(TypeError, lambda: cross(zerod, d)) assert d ^ v == cross(d, v) assert v ^ d == cross(v, d) assert d ^ zerov == cross(d, zerov) assert zerov ^ d == cross(zerov, d) assert zerov ^ d == cross(zerov, d) raises(TypeError, lambda: cross(d, S(0))) raises(TypeError, lambda: cross(S(0), d)) raises(TypeError, lambda: cross(d, 0)) raises(TypeError, lambda: cross(0, d)) assert v ^ v == cross(v, v) assert v ^ zerov == cross(v, zerov) assert zerov ^ v == cross(zerov, v) raises(TypeError, lambda: cross(v, S(0))) raises(TypeError, lambda: cross(S(0), v)) raises(TypeError, lambda: cross(v, 0)) raises(TypeError, lambda: cross(0, v)) # outer products raises(TypeError, lambda: outer(d, d)) raises(TypeError, lambda: outer(d, zerod)) raises(TypeError, lambda: outer(zerod, d)) raises(TypeError, lambda: outer(d, v)) raises(TypeError, lambda: outer(v, d)) raises(TypeError, lambda: outer(d, zerov)) raises(TypeError, lambda: outer(zerov, d)) raises(TypeError, lambda: outer(zerov, d)) raises(TypeError, lambda: outer(d, S(0))) raises(TypeError, lambda: outer(S(0), d)) raises(TypeError, lambda: outer(d, 0)) raises(TypeError, lambda: outer(0, d)) assert v | v == outer(v, v) assert v | zerov == outer(v, zerov) assert zerov | v == outer(zerov, v) raises(TypeError, lambda: outer(v, S(0))) raises(TypeError, lambda: outer(S(0), v)) raises(TypeError, lambda: outer(v, 0)) raises(TypeError, lambda: outer(0, v))
def test_output_type(): A = ReferenceFrame('A') v = A.x + A.y d = v | v zerov = Vector(0) zerod = Dyadic(0) # dot products assert isinstance(d & d, Dyadic) assert isinstance(d & zerod, Dyadic) assert isinstance(zerod & d, Dyadic) assert isinstance(d & v, Vector) assert isinstance(v & d, Vector) assert isinstance(d & zerov, Vector) assert isinstance(zerov & d, Vector) raises(TypeError, lambda: d & S(0)) raises(TypeError, lambda: S(0) & d) raises(TypeError, lambda: d & 0) raises(TypeError, lambda: 0 & d) assert not isinstance(v & v, (Vector, Dyadic)) assert not isinstance(v & zerov, (Vector, Dyadic)) assert not isinstance(zerov & v, (Vector, Dyadic)) raises(TypeError, lambda: v & S(0)) raises(TypeError, lambda: S(0) & v) raises(TypeError, lambda: v & 0) raises(TypeError, lambda: 0 & v) # cross products raises(TypeError, lambda: d ^ d) raises(TypeError, lambda: d ^ zerod) raises(TypeError, lambda: zerod ^ d) assert isinstance(d ^ v, Dyadic) assert isinstance(v ^ d, Dyadic) assert isinstance(d ^ zerov, Dyadic) assert isinstance(zerov ^ d, Dyadic) assert isinstance(zerov ^ d, Dyadic) raises(TypeError, lambda: d ^ S(0)) raises(TypeError, lambda: S(0) ^ d) raises(TypeError, lambda: d ^ 0) raises(TypeError, lambda: 0 ^ d) assert isinstance(v ^ v, Vector) assert isinstance(v ^ zerov, Vector) assert isinstance(zerov ^ v, Vector) raises(TypeError, lambda: v ^ S(0)) raises(TypeError, lambda: S(0) ^ v) raises(TypeError, lambda: v ^ 0) raises(TypeError, lambda: 0 ^ v) # outer products raises(TypeError, lambda: d | d) raises(TypeError, lambda: d | zerod) raises(TypeError, lambda: zerod | d) raises(TypeError, lambda: d | v) raises(TypeError, lambda: v | d) raises(TypeError, lambda: d | zerov) raises(TypeError, lambda: zerov | d) raises(TypeError, lambda: zerov | d) raises(TypeError, lambda: d | S(0)) raises(TypeError, lambda: S(0) | d) raises(TypeError, lambda: d | 0) raises(TypeError, lambda: 0 | d) assert isinstance(v | v, Dyadic) assert isinstance(v | zerov, Dyadic) assert isinstance(zerov | v, Dyadic) raises(TypeError, lambda: v | S(0)) raises(TypeError, lambda: S(0) | v) raises(TypeError, lambda: v | 0) raises(TypeError, lambda: 0 | v)