Ejemplo n.º 1
0
pP2 = pO.locatenew('P2', -q2*N.x + b*N.z)
for p in [pB_star, pP1, pP2]:
    p.set_vel(N, p.pos_from(pO).diff(t, N))

# kinematic differential equations
kde = [u1 - q1d, u2 - q2d]
kde_map = solve(kde, [q1d, q2d])

# contact/distance forces
M = lambda qi, qj: 12*E*I/(L**2) * (L/3 * (qj - qi)/(2*b) - qi/2)
V = lambda qi, qj: 12*E*I/(L**3) * (qi - L/2 * (qj - qi)/(2*b))

forces = [(pP1, V(q1, q2)*N.x),
          (pB_star, -m*g*N.x),
          (pP2, V(q2, q1)*N.x)]
# M2 torque is applied in the opposite direction
torques = [(B, (M(q1, q2) - M(q2, q1))*N.y)]

partials = partial_velocities([pP1, pP2, pB_star, B], [u1, u2], N, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)
V = simplify(potential_energy(Fr, [q1, q2], [u1, u2], kde_map))
print('V = {0}'.format(msprint(V)))
print('Setting C = 0, αi = 0')
V = V.subs(dict(zip(symbols('C α1:3'), [0] * 3)))
print('V = {0}\n'.format(msprint(V)))

assert (expand(V) ==
        expand(6*E*I/L**3 * ((1 + L/2/b + L**2/6/b**2)*(q1**2 + q2**2) -
                             q1*q2*L/b * (1 + L/3/b)) -
               m*g/2 * (q1 + q2)))
Ejemplo n.º 2
0
## --- Expressions for generalized speeds u1, u2, u3, u4, u5 ---
u_expr = map(lambda x: dot(C.ang_vel_in(A), x), B)
u_expr += qd[3:]
kde = [u_i - u_ex for u_i, u_ex in zip(u, u_expr)]
kde_map = solve(kde, qd)
print("using the following kinematic eqs:\n{0}".format(msprint(kde)))

## --- Define forces on each point in the system ---
R_C_hat = Px*A.x + Py*A.y + Pz*A.z
R_Cs = -m*g*A.z
forces = [(pC_hat, R_C_hat), (pCs, R_Cs)]

## --- Calculate generalized active forces ---
partials = partial_velocities([pC_hat, pCs], u, A, kde_map)
F, _ = generalized_active_forces(partials, forces)
print("Generalized active forces:")
for i, f in enumerate(F, 1):
    print("F{0} = {1}".format(i, msprint(simplify(f))))

# Now impose the condition that disk C is rolling without slipping
u_indep = u[:3]
u_dep = u[3:]
vc = map(lambda x: dot(pC_hat.vel(A), x), [A.x, A.y])
vc_map = solve(subs(vc, kde_map), u_dep)

partials_tilde = partial_velocities([pC_hat, pCs], u_indep, A, kde_map, vc_map)
F_tilde, _ = generalized_active_forces(partials_tilde, forces)
print("Nonholonomic generalized active forces:")
for i, f in enumerate(F_tilde, 1):
    print("F{0} = {1}".format(i, msprint(simplify(f))))
Ejemplo n.º 3
0
forces = [(pP1, R1), (pDs, R2)]
system = [Particle('P1', pP1, m1), Particle('P2', pDs, m2)]

# kinematic differential equations
kde = [u1 - dot(pP1.vel(A), E.x), u2 - dot(pP1.vel(A), E.y), u3 - q3d]
kde_map = solve(kde, qd)
# include second derivatives in kde map
for k, v in kde_map.items():
    kde_map[k.diff(t)] = v.diff(t)

# use nonholonomic partial velocities to find the nonholonomic
# generalized active forces
vc = [dot(pDs.vel(B), E.y).subs(kde_map)]
vc_map = solve(vc, [u3])
partials = partial_velocities(points, [u1, u2], A, kde_map, vc_map)
Fr, _ = generalized_active_forces(partials, forces)
Fr_star, _ = generalized_inertia_forces(partials, system, kde_map, vc_map)

# dynamical equations
dyn_eq = [x + y for x, y in zip(Fr, Fr_star)]
u1d, u2d = ud = [x.diff(t) for x in [u1, u2]]
dyn_eq_map = solve(dyn_eq, ud)

for x in ud:
    print('{0} = {1}'.format(msprint(x), msprint(trigsimp(dyn_eq_map[x]))))

u1d_expected = (-g * sin(q3) + omega**2 * q1 * cos(q3) +
                (m2 * L * omega**2 * cos(q3)**2 - m1 * u2**2 / L) / (m1 + m2))
u2d_expected = -g * cos(q3) - omega**2 * q1 * sin(q3) + u1 * u2 / L
assert expand(trigsimp(dyn_eq_map[u1d] - u1d_expected)) == 0
assert expand(trigsimp(dyn_eq_map[u2d] - u2d_expected)) == 0
Ejemplo n.º 4
0
pC_hat.v2pt_theory(pCs, A, C)

## --- Expressions for generalized speeds u1, u2, u3, u4, u5 ---
u_expr = map(lambda x: dot(C.ang_vel_in(A), x), B)
u_expr += qd[3:]
kde = [u_i - u_ex for u_i, u_ex in zip(u, u_expr)]
kde_map = solve(kde, qd)

## --- Define forces on each point in the system ---
R_C_hat = Px*A.x + Py*A.y + Pz*A.z
R_Cs = -m*g*A.z
forces = [(pC_hat, R_C_hat), (pCs, R_Cs)]

## --- Calculate generalized active forces ---
partials = partial_velocities([pC_hat, pCs], u, A, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

# Impose the condition that disk C is rolling without slipping
u_indep = u[:3]
u_dep = u[3:]
vc = map(lambda x: dot(pC_hat.vel(A), x), [A.x, A.y])
vc_map = solve(subs(vc, kde_map), u_dep)

partials_tilde = partial_velocities([pC_hat, pCs], u_indep, A, kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials_tilde, forces)
Fr_tilde = map(expand, Fr_tilde)

# solve for ∂V/∂qs using 5.1.9
V_gamma = m * g * R * cos(q[1])
print(('\nVerify V_γ = {0} is a potential energy '.format(V_gamma) +
       'contribution of γ for C.'))
Ejemplo n.º 5
0
B = A.orientnew('B', 'body', [q1, q2, q3], 'xyz')

# define points
pO = Point('O')
pP = pO.locatenew('P', q1 * A.x + q2 * A.y + q3 * A.z)
pP.set_vel(A, pP.pos_from(pO).dt(A))

# kinematic differential equations
kde_map = dict(zip(map(lambda x: x.diff(), q), u))

# forces
forces = [(pP, -beta * pP.vel(A))]
torques = [(B, -alpha * B.ang_vel_in(A))]

partials_c = partial_velocities(zip(*forces + torques)[0], u, A, kde_map)
Fr_c, _ = generalized_active_forces(partials_c, forces + torques)

dissipation_function = function_from_partials(map(
    lambda x: 0 if x == 0 else -x.subs(kde_map), Fr_c),
                                              u,
                                              zero_constants=True)
from sympy import simplify, trigsimp
dissipation_function = trigsimp(dissipation_function)
#print('ℱ = {0}'.format(msprint(dissipation_function)))

omega2 = trigsimp(dot(B.ang_vel_in(A), B.ang_vel_in(A)).subs(kde_map))
v2 = trigsimp(dot(pP.vel(A), pP.vel(A)).subs(kde_map))
sym_map = dict(zip([omega2, v2], map(lambda x: x**2, symbols('ω v'))))
#print('ω**2 = {0}'.format(msprint(omega2)))
#print('v**2 = {0}'.format(msprint(v2)))
print('ℱ = {0}'.format(msprint(dissipation_function.subs(sym_map))))
Ejemplo n.º 6
0
pC_hat.v2pt_theory(pCs, A, C)

## --- Expressions for generalized speeds u1, u2, u3, u4, u5 ---
u_expr = map(lambda x: dot(C.ang_vel_in(A), x), B)
u_expr += qd[3:]
kde = [u_i - u_ex for u_i, u_ex in zip(u, u_expr)]
kde_map = solve(kde, qd)

## --- Define forces on each point in the system ---
R_C_hat = Px * A.x + Py * A.y + Pz * A.z
R_Cs = -m * g * A.z
forces = [(pC_hat, R_C_hat), (pCs, R_Cs)]

## --- Calculate generalized active forces ---
partials = partial_velocities([pC_hat, pCs], u, A, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

# Impose the condition that disk C is rolling without slipping
u_indep = u[:3]
u_dep = u[3:]
vc = map(lambda x: dot(pC_hat.vel(A), x), [A.x, A.y])
vc_map = solve(subs(vc, kde_map), u_dep)

partials_tilde = partial_velocities([pC_hat, pCs], u_indep, A, kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials_tilde, forces)
Fr_tilde = map(expand, Fr_tilde)

# solve for ∂V/∂qs using 5.1.9
V_gamma = m * g * R * cos(q[1])
print(('\nVerify V_γ = {0} is a potential energy '.format(V_gamma) +
       'contribution of γ for C.'))
Ejemplo n.º 7
0
resultants = [R1, R2]
forces = [(pP1, R1), (pDs, R2)]
point_masses = [Particle('P1', pP1, m1), Particle('P2', pDs, m2)]
points = [f[0] for f in forces]

# define generalized speeds
kde = [u_i - u_ex for u_i, u_ex in zip(ulist, u_expr)]
kde_map = solve(kde, [q1d, q2d, q3d])

# include second derivatives in kde map
for k, v in kde_map.items():
    kde_map[k.diff(t)] = v.diff(t)

# calculate partials, generalized forces
partials = partial_velocities(points, [u1, u2, u3], A, kde_map)
Fr, _ = generalized_active_forces(partials, forces)
Fr_star, _ = generalized_inertia_forces(partials, point_masses, kde_map)

# use nonholonomic partial velocities to find the nonholonomic
# generalized active forces
vc = [dot(pDs.vel(B), E.y)]
vc_map = solve(subs(vc, kde_map), [u3])
partials_tilde = partial_velocities(points, [u1, u2], A, kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials_tilde, forces)
Fr_tilde_star, _ = generalized_inertia_forces(partials_tilde, point_masses,
                                              kde_map, vc_map)

print("\nFor generalized speeds\n[u1, u2, u3] = {0}".format(msprint(u_expr)))
print("\nGeneralized active forces:")
for i, f in enumerate(Fr, 1):
    print("F{0} = {1}".format(i, msprint(simplify(f))))
Ejemplo n.º 8
0
pD.set_vel(F, u2 * A.y)

pS_star = pD.locatenew('S*', e * A.y)
pQ = pD.locatenew('Q', f * A.y - R * A.x)
for p in [pS_star, pQ]:
    p.set_vel(A, 0)
    p.v2pt_theory(pD, F, A)

## --- define partial velocities ---
partials = partial_velocities([pD, pS_star, pQ], [u1, u2, u3],
                              F,
                              express_frame=A)

forces = [(pS_star, -M * g * F.x), (pQ, Q1 * A.x + Q2 * A.y + Q3 * A.z)]
torques = []
Fr, _ = generalized_active_forces(partials, forces + torques, uaux=[u3])
print("Generalized active forces:")
for i, f in enumerate(Fr, 1):
    print("F{0} = {1}".format(i, msprint(f)))

friction = -u_prime * Q1 * (pQ.vel(F).normalize().express(A)).subs(u3, 0)
Q_map = dict(zip([Q2, Q3], [dot(friction, x) for x in [A.y, A.z]]))
Q_map[Q1] = trigsimp(solve(F3 - Fr[-1].subs(Q_map), Q1)[0])
print('')
for x in [Q1, Q2, Q3]:
    print('{0} = {1}'.format(x, msprint(Q_map[x])))

print("\nEx8.17")
### --- define new symbols ---
a, b, mA, mB, IA, J, K, t = symbols('a b mA mB IA J K t')
IA22, IA23, IA33 = symbols('IA22 IA23 IA33')
Ejemplo n.º 9
0
## --- define points P, P' ---
# point on C
pP = pC_star.locatenew('P', x * B.x + y * B.y + z * B.z)
pP.set_vel(C, 0)
pP.v2pt_theory(pC_star, B, C)
pP.v2pt_theory(pC_star, A, C)
# point on B
pP_prime = pP.locatenew("P'", 0)
pP_prime.set_vel(B, 0)
pP_prime.v1pt_theory(pC_star, A, B)

## --- Define forces ---
cart_sph_map = dict([(z, r*sin(phi)),
                      (y, r*cos(phi)*sin(theta)),
                      (x, r*cos(phi)*cos(theta))])
J = Matrix([cart_sph_map.values()]).jacobian([r, phi, theta])
dJ = simplify(J.det())

dtheta = -c * pP.vel(B) * dJ
integral = lambda i: integrate(integrate(i.subs(cart_sph_map),
                                         (theta, 0, 2*pi)),
                               (phi, -pi/2, pi/2)).subs(r, R)

forces = [(pP, dtheta, integral), (pP_prime, -dtheta, integral)]
partials = partial_velocities([pP, pP_prime], [u2, u4], A, express_frame=B)
Flist, _ = generalized_active_forces(partials, forces)

print("Generalized active forces:")
for f, i in zip(Flist, [2, 4]):
    print("F{0} = {1}".format(i, msprint(simplify(f)))) 
Ejemplo n.º 10
0
pC_hat.v2pt_theory(pCs, A, C)

## --- Expressions for generalized speeds u1, u2, u3, u4, u5 ---
u_expr = map(lambda x: dot(C.ang_vel_in(A), x), B)
u_expr += qd[3:]
kde = [u_i - u_ex for u_i, u_ex in zip(u, u_expr)]
kde_map = solve(kde, qd)

## --- Define forces on each point in the system ---
R_C_hat = Px * A.x + Py * A.y + Pz * A.z
R_Cs = -m * g * A.z
forces = [(pC_hat, R_C_hat), (pCs, R_Cs)]

## --- Calculate generalized active forces ---
partials = partial_velocities([pC_hat, pCs], u, A, kde_map)
Fr, _ = generalized_active_forces(partials, forces)

# Impose the condition that disk C is rolling without slipping
u_indep = u[:3]
u_dep = u[3:]
vc = map(lambda x: dot(pC_hat.vel(A), x), [A.x, A.y])
vc_map = solve(subs(vc, kde_map), u_dep)

partials_tilde = partial_velocities([pC_hat, pCs], u_indep, A, kde_map, vc_map)
Fr_tilde, _ = generalized_active_forces(partials_tilde, forces)
Fr_tilde = map(expand, Fr_tilde)

# solve for ∂V/∂qs using 5.1.9
V_gamma = m * g * R * cos(q[1])
print(("\nVerify V_γ = {0} is a potential energy ".format(V_gamma) + "contribution of γ for C."))
V_gamma_dot = -sum(fr * ur for fr, ur in zip(*generalized_active_forces(partials_tilde, forces[1:])))
Ejemplo n.º 11
0
Archivo: Ex8.9.py Proyecto: nouiz/pydy
def print_fr(forces, ulist):
    print("Generalized active forces:")
    partials = partial_velocities(zip(*forces + torques)[0], ulist, N, kde_map)
    Fr, _ = generalized_active_forces(partials, forces + torques)
    for i, f in enumerate(Fr, 1):
        print("F{0} = {1}".format(i, msprint(trigsimp(f))))
Ejemplo n.º 12
0
pB1 = pO.locatenew('B1', (L1 + q1)*N.x) # treat block 1 as a point mass
pB2 = pB1.locatenew('B2', (L2 + q2)*N.x) # treat block 2 as a point mass
pB1.set_vel(N, pB1.pos_from(pO).dt(N))
pB2.set_vel(N, pB2.pos_from(pO).dt(N))

# kinematic differential equations
kde_map = dict(zip(map(lambda x: x.diff(), q), u))

# forces
#spring_forces = [(pB1, -k1 * q1 * N.x),
#                 (pB1, k2 * q2 * N.x),
#                 (pB2, -k2 * q2 * N.x)]
dashpot_forces = [(pB1, beta * q2d * N.x),
                 (pB2, -beta * q2d * N.x),
                 (pB2, -alpha * (q1d + q2d) * N.x)]
#forces = spring_forces + dashpot_forces

partials_c = partial_velocities(zip(*dashpot_forces)[0], u, N, kde_map)
Fr_c, _ = generalized_active_forces(partials_c, dashpot_forces)
#print('generalized active forces due to dashpot forces')
#for i, fr in enumerate(Fr_c, 1):
#    print('(F{0})c = {1} = -∂ℱ/∂u{0}'.format(i, msprint(fr)))

dissipation_function = function_from_partials(
        map(lambda x: -x.subs(kde_map), Fr_c), u, zero_constants=True)
print('ℱ = {0}'.format(msprint(dissipation_function)))

dissipation_function_expected = (alpha*u1**2 + 2*alpha*u1*u2 +
                                 (alpha + beta)*u2**2)/2
assert expand(dissipation_function - dissipation_function_expected) == 0
Ejemplo n.º 13
0
def print_fr(forces, ulist):
    print("Generalized active forces:")
    partials = partial_velocities(zip(*forces + torques)[0], ulist, N, kde_map)
    Fr, _ = generalized_active_forces(partials, forces + torques)
    for i, f in enumerate(Fr, 1):
        print("F{0} = {1}".format(i, msprint(trigsimp(f))))
Ejemplo n.º 14
0
pB_star.set_vel(B, 0)
pB_star.set_vel(A, pB_star.pos_from(pP).dt(A))

# kinematic differential equations
kde = [x - y for x, y in zip([u1, u2, u3], map(B.ang_vel_in(A).dot, B))]
kde_map = solve(kde, [q1d, q2d, q3d])

I = inertia(B, I1, I2, I3) # central inertia dyadic of B

# forces, torques due to set of gravitational forces γ
forces = [(pB_star, -G * m * M / R**2 * A.x)]
torques = [(B, cross(3 * G * m / R**3 * A.x, dot(I, A.x)))]

partials = partial_velocities(zip(*forces + torques)[0], [u1, u2, u3],
                              A, kde_map)
Fr, _ = generalized_active_forces(partials, forces + torques)

print('part a')
V_gamma = potential_energy(Fr, [q1, q2, q3], [u1, u2, u3], kde_map)
print('V_γ = {0}'.format(msprint(V_gamma)))
print('Setting C = 0, α1, α2, α3 = 0')
V_gamma = V_gamma.subs(dict(zip(symbols('C α1 α2 α3'), [0] * 4)))
print('V_γ= {0}'.format(msprint(V_gamma)))

V_gamma_expected = (-3*G*m/2/R**3 * ((I1 - I3)*sin(q2)**2 +
                                     (I1 - I2)*cos(q2)**2*sin(q3)**2))
assert expand(V_gamma) == expand(V_gamma_expected)

print('\npart b')
kde_b = [x - y for x, y in zip([u1, u2, u3], [q1d, q2d, q3d])]
kde_map_b = solve(kde_b, [q1d, q2d, q3d])