def test_save_and_rebuild(self): # Build truss from file t2 = truss.Truss(TEST_TRUSS_FILENAME) t2.set_goal(min_fos_buckling=1.5, min_fos_yielding=1.5, max_mass=5.0, max_deflection=6e-3) # Save t2.save_report(os.path.join(os.path.dirname(__file__), 'report_2.txt')) t2.save_truss(os.path.join(os.path.dirname(__file__), 'asdf.trs')) # Rebuild t3 = truss.Truss(os.path.join(os.path.dirname(__file__), 'asdf.trs')) t3.set_goal(min_fos_buckling=1.5, min_fos_yielding=1.5, max_mass=5.0, max_deflection=6e-3) t3.save_report(os.path.join(os.path.dirname(__file__), 'report_3.txt')) # Test for sameness file_are_the_same = filecmp.cmp( os.path.join(os.path.dirname(__file__), 'report_3.txt'), os.path.join(os.path.dirname(__file__), 'report_2.txt')) self.assertTrue(file_are_the_same) # Clean up os.remove(os.path.join(os.path.dirname(__file__), 'report_2.txt')) os.remove(os.path.join(os.path.dirname(__file__), 'report_3.txt')) os.remove(os.path.join(os.path.dirname(__file__), 'asdf.trs'))
def build_triangle_truss(self): # Build truss from scratch # Simple triangular truss t4 = truss.Truss() t4.add_support(np.array([0.0, 0.0, 0.0]), d=2) t4.add_roller(np.array([2.0, 0.0, 0.0]), axis='y', d=2) t4.add_joint(np.array([1.0, 3.0, 0.0]), d=2) t4.add_member(0, 1) t4.add_member(1, 2) t4.add_member(0, 2) t4.joints[2].loads[0] = 0 t4.joints[2].loads[1] = 1 t4.joints[2].loads[2] = 0 for m in t4.members: m.set_shape('arbitrary') m.set_parameters(a=1, I_min=1) m.rho = 1.0 m.elastic_modulus = 1.0 m.Fy = 1.0 m.calc_properties() t4.g = np.array([0.0, -1.0, 0.0]) t4.set_goal(min_fos_buckling=-1, min_fos_yielding=-1, max_mass=-1, max_deflection=-1) t4.save_report(os.path.join(os.path.dirname(__file__), 'report_4.txt')) os.remove(os.path.join(os.path.dirname(__file__), 'report_4.txt')) return t4
def build_single_bar_truss(self): # Build truss from scratch t5 = truss.Truss() t5.add_support(np.array([0.0, 0.0, 0.0]), d=2) t5.add_roller(np.array([0.0, 1.0, 0.0]), axis='x', d=2) t5.add_member(0, 1) t5.joints[1].loads[0] = 0 t5.joints[1].loads[1] = 3 t5.joints[1].loads[2] = 0 for m in t5.members: m.set_shape('arbitrary') m.set_parameters(area=1, I_min=1) m.rho = 1.0 m.elastic_modulus = 1.0 m.Fy = 1.0 m.calc_properties() t5.g = np.array([0.0, -1.0, 0.0]) t5.set_goal(min_fos_buckling=-1, min_fos_yielding=-1, max_mass=-1, max_deflection=-1) t5.print_report()
def test_build_methods(self): # Build truss from scratch t1 = truss.Truss() left_end = t1.add_joint(numpy.array([0.0, 0.0, 0.0]), d=2) left_end.roller(d=2) t1.add_joint(numpy.array([18.0 / 100.0, 0.0, 0.0]), d=2) right_end = t1.add_joint(numpy.array([36.0 / 100.0, 0.0, 0.0]), d=2) right_end.pinned() t1.add_joint(numpy.array([8.0 / 100.0, 6.0 / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([18.0 / 100.0, 9.0 / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([28.0 / 100.0, 6.0 / 100.0, 0.0]), d=2) t1.joints[1].loads[1] = -434 t1.add_member(0, 1) t1.add_member(1, 2) t1.add_member(0, 3) t1.add_member(3, 4) t1.add_member(4, 5) t1.add_member(5, 2) t1.add_member(3, 1) t1.add_member(4, 1) t1.add_member(5, 1) t1.save_report(os.path.join(os.path.dirname(__file__), 'report_1.txt'))
def truss_efficiency(truss_points, logger): joint1 = truss_points[0] joint2 = truss_points[1] joint3 = truss_points[2] joint4 = truss_points[3] joint5 = truss_points[4] load_joint = truss_points[5] # Build truss from scratch t1 = truss.Truss() left_end = t1.add_joint(numpy.array([0.0, 0.0, 0.0]), d=2) left_end.roller(d=2) t1.add_joint(numpy.array([load_joint[0] / 100.0, load_joint[1] / 100, 0.0]), d=2) right_end = t1.add_joint(numpy.array([37.0 / 100.0, 5.14 / 100.0, 0.0]), d=2) right_end.pinned() t1.add_joint(numpy.array([joint1[0] / 100.0, joint1[1] / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([joint2[0] / 100.0, joint2[1] / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([joint3[0] / 100.0, joint3[1] / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([joint4[0] / 100.0, joint4[1] / 100.0, 0.0]), d=2) t1.add_joint(numpy.array([joint5[0] / 100.0, joint5[1] / 100.0, 0.0]), d=2) t1.joints[1].loads[1] = -100 t1.load = -100 t1.add_member(0, 1) t1.add_member(1, 2) t1.add_member(0, 3) t1.add_member(3, 4) t1.add_member(4, 5) t1.add_member(5, 6) t1.add_member(6, 7) t1.add_member(7, 2) t1.add_member(3, 1) t1.add_member(4, 1) t1.add_member(5, 1) t1.add_member(6, 1) t1.add_member(7, 1) t1.calc_mass() try: t1.calc_fos() except LinAlgError: logger.warn('Bridge geometry causes singular matrix, disqualifying: ' + str(truss_points)) return t1, 0.0, 0.0 if t1.result_suspect == True: logger.warn('Results possibly inacurate, disqualifying: ' + str(truss_points)) return t1, 0.0, 0.0 supported_load, efficiency = get_truss_load_and_efficiency(t1, logger) return t1, supported_load, efficiency
def truss_analysis(j1, j2, j3): if j1[0] >= j2[0]: return if j2[0] >= j3[0]: return # print j1, j2, j3 truss_being_tested = truss.Truss() left_end = truss_being_tested.add_joint(numpy.array([0.0, 0.0, 0.0]), d=2) left_end.roller(d=2) truss_being_tested.add_joint(numpy.array([18.0 / 100.0, 2.5 / 100.0, 0.0]), d=2) right_end = truss_being_tested.add_joint(numpy.array( [36.0 / 100.0, 5.0 / 100.0, 0.0]), d=2) right_end.pinned() truss_being_tested.add_joint(numpy.array( [j1[0] / 100.0, j1[1] / 100.0, 0.0]), d=2) truss_being_tested.add_joint(numpy.array( [j2[0] / 100.0, j2[1] / 100.0, 0.0]), d=2) truss_being_tested.add_joint(numpy.array( [j3[0] / 100.0, j3[1] / 100.0, 0.0]), d=2) truss_being_tested.joints[1].loads[1] = -2 truss_being_tested.add_member(0, 1) truss_being_tested.add_member(1, 2) truss_being_tested.add_member(0, 3) truss_being_tested.add_member(3, 4) truss_being_tested.add_member(4, 5) truss_being_tested.add_member(5, 2) truss_being_tested.add_member(3, 1) truss_being_tested.add_member(4, 1) truss_being_tested.add_member(5, 1) truss_being_tested.calc_fos() return truss
def test_build_methods(self): # Build truss from scratch t1 = truss.Truss() t1.add_support(np.array([0.0, 0.0, 0.0]), d=2) t1.add_joint(np.array([1.0, 0.0, 0.0]), d=2) t1.add_joint(np.array([2.0, 0.0, 0.0]), d=2) t1.add_joint(np.array([3.0, 0.0, 0.0]), d=2) t1.add_joint(np.array([4.0, 0.0, 0.0]), d=2) t1.add_support(np.array([5.0, 0.0, 0.0]), d=2) t1.add_joint(np.array([0.5, 1.0, 0.0]), d=2) t1.add_joint(np.array([1.5, 1.0, 0.0]), d=2) t1.add_joint(np.array([2.5, 1.0, 0.0]), d=2) t1.add_joint(np.array([3.5, 1.0, 0.0]), d=2) t1.add_joint(np.array([4.5, 1.0, 0.0]), d=2) t1.joints[7].loads[1] = -20000 t1.joints[8].loads[1] = -20000 t1.joints[9].loads[1] = -20000 t1.add_member(0, 1) t1.add_member(1, 2) t1.add_member(2, 3) t1.add_member(3, 4) t1.add_member(4, 5) t1.add_member(6, 7) t1.add_member(7, 8) t1.add_member(8, 9) t1.add_member(9, 10) t1.add_member(0, 6) t1.add_member(6, 1) t1.add_member(1, 7) t1.add_member(7, 2) t1.add_member(2, 8) t1.add_member(8, 3) t1.add_member(3, 9) t1.add_member(9, 4) t1.add_member(4, 10) t1.add_member(10, 5) t1.set_goal(min_fos_buckling=1.5, min_fos_yielding=1.5, max_mass=5.0, max_deflection=6e-3) # Build truss from file t2 = truss.Truss(TEST_TRUSS_FILENAME) t2.set_goal(min_fos_buckling=1.5, min_fos_yielding=1.5, max_mass=5.0, max_deflection=6e-3) # Save reports t1.save_report(os.path.join(os.path.dirname(__file__), 'report_1.txt')) t2.save_report(os.path.join(os.path.dirname(__file__), 'report_2.txt')) # Test for sameness file_are_the_same = filecmp.cmp( os.path.join(os.path.dirname(__file__), 'report_1.txt'), os.path.join(os.path.dirname(__file__), 'report_2.txt')) self.assertTrue(file_are_the_same) # Clean up os.remove(os.path.join(os.path.dirname(__file__), 'report_1.txt')) os.remove(os.path.join(os.path.dirname(__file__), 'report_2.txt'))
import os import datetime def import_data(): root = tk.Tk() root.withdraw() file_path = tkFileDialog.askopenfilename() return file_path if __name__ == "__main__": file_path = import_data() # Build truss from file t = truss.Truss(file_path) t.set_goal(min_fos_buckling=1.5, min_fos_yielding=1.5, max_mass=5.0, max_deflection=6e-3) # Save report # A C H T U N G: Derzeit wird OHNE Report nichts berechnet, # entsprechend stimmt auch der Plot nicht timestamp = '{:%Y-%m-%d_%H-%M-%S}'.format(datetime.datetime.now()) base_name = os.path.splitext(os.path.basename(file_path))[0] t.print_and_save_report( os.path.join(os.path.dirname(__file__), 'report_' + base_name + '_' + timestamp + '.txt')) # Plot truss t.plot(mlbl=True, jlbl=True, ldlbl=True, legend=True)