def test_dof_index(self): s = System() j1 = FreeJoint('j1') j2 = FreeJoint('j2') s.add_leaf(j1) j1.add_leaf(j2) s.setup() # Prescribe some of the strains: # _____j1____ _____j2____ # Strain: 0 1 2 3 4 5 0 1 2 3 4 5 # Prescr: * * * # Dofs: 0 1 2 3 4 5 6 7 8 s.prescribe(j1, 0, part=[1, 4]) s.prescribe(j2, 0, part=[3]) self.assertEqual(s.dof_index('j1', 0), 0) self.assertEqual(s.dof_index('j1', 2), 1) self.assertEqual(s.dof_index('j1', 5), 3) self.assertEqual(s.dof_index('j2', 5), 8) # Strain index out of range should give IndexError with self.assertRaises(IndexError): s.dof_index('j1', 6) # Asking for index of prescribed strain should give ValueError with self.assertRaises(ValueError): s.dof_index('j1', 1)
def test_solve_accelerations_coupling(self): # Further to test above, check that coupling between prescribed # accelerations and other dofs is correct. For example, if there # is a rigid body vertically offset from the joint, then a # prescribed horizontal acceleration should cause an angular # acceleration as well as the translational acceleration. s = System() j = FreeJoint('joint') c = RigidConnection('conn', [0, 0, 1.7]) b = RigidBody('body', mass=23.54, inertia=74.1 * np.eye(3)) s.add_leaf(j) j.add_leaf(c) c.add_leaf(b) s.setup() # Prescribe horizontal acceleration, solve other accelerations s.prescribe(j, 2.3, part=[0]) # x acceleration s.update_kinematics() # update system to show prescribed acc s.solve_accelerations() # solve free accelerations s.update_kinematics() # update system to show solution # Ground shouldn't move assert_aae(j.ap, 0) # Need angular acceleration = (m a_x L) / I0 I0 = 74.1 + (23.54 * 1.7**2) expected_angular_acc = -(23.54 * 2.3 * 1.7) / I0 assert_aae(j.ad, [2.3, 0, 0, 0, expected_angular_acc, 0]) assert_aae(j.astrain, j.ad) # not always true, but works for FreeJoint
def test_solve_accelerations(self): # solve_accelerations() should find: # (a) response of system to forces (here, gravity) # (b) include any prescribed accelerations in qdd vector g = 9.81 s = System(gravity=g) j = FreeJoint('joint') b = RigidBody('body', mass=23.54, inertia=52.1 * np.eye(3)) s.add_leaf(j) j.add_leaf(b) s.setup() # Prescribe horizontal acceleration. Vertical acceleration # should result from gravity. s.prescribe(j, 2.3, part=[0]) # x acceleration # Initially accelerations are zero assert_aae(j.ap, 0) assert_aae(j.ad, 0) assert_aae(j.astrain, 0) # Solve accelerations & check s.solve_accelerations() s.update_kinematics() assert_aae(j.ap, 0) # ground assert_aae(j.ad, [2.3, 0, -g, 0, 0, 0]) assert_aae(j.astrain, j.ad) # not always true, but works for FreeJoint
def test_single_rigid_body(self): mass = 36.2 inertia = np.diag([75.4, 653, 234]) s = System() j = FreeJoint('joint') b = RigidBody('body', mass, inertia) s.add_leaf(j) j.add_leaf(b) s.setup() # Calculate reduced system to get rigid body matrices rsys = ReducedSystem(s) self.assertEqual(rsys.M.shape, (6, 6)) self.assertEqual(rsys.Q.shape, (6, )) assert_aae(rsys.M[:3, :3], mass * np.eye(3)) assert_aae(rsys.M[3:, 3:], inertia) assert_aae(rsys.M[3:, :3], 0) assert_aae(rsys.M[:3, 3:], 0) assert_aae(rsys.Q, 0) # Now if some freedoms are prescribed, don't appear in reduced system s.prescribe(j, part=[1, 2, 3, 4, 5]) # only x-translation is free now rsys = ReducedSystem(s) self.assertEqual(rsys.M.shape, (1, 1)) self.assertEqual(rsys.Q.shape, (1, )) assert_aae(rsys.M[0, 0], mass) assert_aae(rsys.Q, 0)
def test_single_rigid_body(self): mass = 36.2 inertia = np.diag([75.4, 653, 234]) s = System() j = FreeJoint('joint') b = RigidBody('body', mass, inertia) s.add_leaf(j) j.add_leaf(b) s.setup() # Calculate reduced system to get rigid body matrices rsys = ReducedSystem(s) self.assertEqual(rsys.M.shape, (6, 6)) self.assertEqual(rsys.Q.shape, (6,)) assert_aae(rsys.M[:3, :3], mass * np.eye(3)) assert_aae(rsys.M[3:, 3:], inertia) assert_aae(rsys.M[3:, :3], 0) assert_aae(rsys.M[:3, 3:], 0) assert_aae(rsys.Q, 0) # Now if some freedoms are prescribed, don't appear in reduced system s.prescribe(j, part=[1, 2, 3, 4, 5]) # only x-translation is free now rsys = ReducedSystem(s) self.assertEqual(rsys.M.shape, (1, 1)) self.assertEqual(rsys.Q.shape, (1,)) assert_aae(rsys.M[0, 0], mass) assert_aae(rsys.Q, 0)
def test_print_functions(self): # Not very good tests, but at least check they run without errors joint = FreeJoint('joint') body = RigidBody('body', mass=1.235) s = System() s.add_leaf(joint) joint.add_leaf(body) s.setup() s.print_states() s.print_info()