def test_Sim_ass_3(): #####From assignment 3#### laminate_q1 = Laminate('p10/90/0_2/p50s', materialID = 1) laminate_q1.compute_all() load = numpy.array([450000,-110000,-130000],dtype=float) load = load*10**-6 off_stress_norm = load*10**-3 off_strain = laminate_q1.a.dot(off_stress_norm).reshape((3,1)) on_strain = numpy.empty((14,3)) on_stress = numpy.empty((14,3)) for i in range(14): layer = laminate_q1.layers[i] on_strain[i,:] = transform_strain(off_strain,'off',layer.theta) on_stress[i,:] = laminate_q1.layers[0].Q_on.dot(on_strain[i,:]) ###### ######From new Sim#### ##### my_sim = Sim(layup = 'p10/90/0_2/p50s', materialID = 1) my_sim.apply_N(numpy.array([[0.4500],[-0.1100],[-0.1300]])*ureg.MNperm) my_sim.solve() sim_off_strain = numpy.vstack(my_sim.off_strain) sim_on_strain = numpy.vstack(my_sim.on_strain) sim_on_stress = numpy.vstack(my_sim.on_stress) # sim_off_stress = numpy.vstack(my_sim.off_stress) for row in sim_off_strain: # print row array_assert_error(row,off_strain,tol = 0.001) # for row in sim_on_strain: # array_assert_error(row,on_strain,tol=0.001) array_assert(sim_on_strain[0::2,:],on_strain,precision = 10) array_assert(sim_on_strain[1::2,:],on_strain,precision = 10) array_assert(sim_on_stress[0::2,:],on_stress,precision = 10) array_assert(sim_on_stress[1::2,:],on_stress,precision = 10)
def test_ass5(): sim = Sim(laminate=Laminate( '0_2/p25/0_2s', materialID=5, #5 core_thick=0.01)) P = Q_(1000, 'N') b = Q_(0.11, 'm') L = Q_(0.51, 'm') M1 = -P * L / (4 * b) N1 = 0.5 * P / b M = Q_([M1.magnitude, 0, 0], M1.units) N = Q_([N1.magnitude, 0, 0], N1.units) sim.apply_M(M) sim.apply_N(N) sim.solve() df = sim.return_results() fail = FailureAnalysis(sim) R = fail.compute_all() R_data = fail.make_table() def print_R_analyz(data): the_min_idx = data['Lowest R'].idxmin() lowest_R = data['Lowest R'].iloc[the_min_idx] ply = data['Ply'].iloc[the_min_idx].split(' ')[0] print("Lowest R is %.1f and occurs at top of ply number %s." % (lowest_R, ply)) print "The load vectors R(M) and R(N) which cause failure are:" print "R(M) [N] : " print[round(M1.magnitude * lowest_R, 2), 0, 0] print "R(N) [N/m] : " print[round(N1.magnitude * lowest_R, 2), 0, 0] def find_min(dataframe, columns): lowest_Rs = [] plys = [] modes = [x.split('_')[0] for x in columns] nonzero_dat = dataframe[dataframe != 0] for col in columns: the_data = nonzero_dat[col] min_index = the_data.idxmin() lowest_Rs.append(the_data.iloc[min_index]) plys.append(dataframe['Ply'].iloc[min_index]) return pd.DataFrame({ 'Mode': modes, 'Lowest R': lowest_Rs, 'Ply': plys })[['Mode', 'Lowest R', 'Ply']] max_data = find_min(R_data, 'FT_max,FC_max,MT_max,MC_max,S'.split(',')) print_R_analyz(max_data) quad_data = find_min(R_data, ['(+)']) print_R_analyz(quad_data) print R_data hashin_data = find_min(R_data, 'FT_hash,FC_hash,MT_hash,MC_hash'.split(',')) hashin_data print_R_analyz(hashin_data) fail.find_min
def test_apply_M_k_Sim_p96(): global my_sim_p96 my_sim_p96 = Sim(layup = '0_4/90_4s',materialID = 1) P = -100 * ureg.N L = 0.1 * ureg.meter b = 0.01 * ureg.meter moment = P*L/(4*b) M = Q_([moment.magnitude,0,0],moment.units) k,e = my_sim_p96.apply_M(M,True) assert(e.shape == (my_sim_p96.laminate.num_of_layers(),2,3)) array_assert(k,[-2.34,0.213,0],precision = 2)
def test_apply_M_k_Sim_p96(): global my_sim_p96 my_sim_p96 = Sim(layup='0_4/90_4s', materialID=1) P = -100 * ureg.N L = 0.1 * ureg.meter b = 0.01 * ureg.meter moment = P * L / (4 * b) M = Q_([moment.magnitude, 0, 0], moment.units) k, e = my_sim_p96.apply_M(M, True) assert (e.shape == (my_sim_p96.laminate.num_of_layers(), 2, 3)) array_assert(k, [-2.34, 0.213, 0], precision=2)
def test_Sim_wrong_key_2(): try: Sim(blah='45/90') except KeyError: pass else: raise AssertionError
def test_Sim_wrong_key(): try: Sim(layup='45/90') except KeyError: pass else: raise AssertionError
def test_Sim_not_a_kw(): try: sim = Sim(5) except TypeError: pass else: raise AssertionError
def test_ass5(): sim = Sim(laminate = Laminate('0_2/p25/0_2s', materialID = 5, #5 core_thick = 0.01)) P = Q_(1000,'N'); b = Q_(0.11,'m'); L = Q_(0.51,'m') M1 = -P*L/(4*b); N1 = 0.5*P/b; M = Q_([M1.magnitude,0,0],M1.units) N = Q_([N1.magnitude,0,0],N1.units) sim.apply_M(M) sim.apply_N(N) sim.solve() df = sim.return_results() fail = FailureAnalysis(sim) R = fail.compute_all() R_data = fail.make_table() def print_R_analyz(data): the_min_idx = data['Lowest R'].idxmin() lowest_R = data['Lowest R'].iloc[the_min_idx] ply = data['Ply'].iloc[the_min_idx].split(' ')[0] print ("Lowest R is %.1f and occurs at top of ply number %s." % (lowest_R,ply)) print "The load vectors R(M) and R(N) which cause failure are:" print "R(M) [N] : " print [round(M1.magnitude*lowest_R,2),0,0] print "R(N) [N/m] : " print [round(N1.magnitude*lowest_R,2),0,0] def find_min(dataframe,columns): lowest_Rs = []; plys = []; modes = [x.split('_')[0] for x in columns] nonzero_dat = dataframe[dataframe != 0] for col in columns: the_data = nonzero_dat[col] min_index = the_data.idxmin() lowest_Rs.append(the_data.iloc[min_index]) plys.append(dataframe['Ply'].iloc[min_index]) return pd.DataFrame({'Mode':modes, 'Lowest R':lowest_Rs, 'Ply':plys })[['Mode','Lowest R','Ply']] max_data = find_min(R_data,'FT_max,FC_max,MT_max,MC_max,S'.split(',')) print_R_analyz(max_data) quad_data = find_min(R_data,['(+)']) print_R_analyz(quad_data) print R_data hashin_data = find_min(R_data,'FT_hash,FC_hash,MT_hash,MC_hash'.split(',')) hashin_data print_R_analyz(hashin_data) fail.find_min
def test_apply_units(): sim = Sim(layup='45/90', materialID=2) P = Q_(1000, 'N') b = Q_(0.11, 'm') L = Q_(0.51, 'm') M1 = -P * L / (4 * b) N1 = 0.5 * P / b M = Q_([M1.magnitude, 0, 0], M1.units) N = Q_([N1.magnitude, 0, 0], N1.units) print type(N1) try: sim.apply_M(M) sim.apply_N(N) sim.apply_N(N1) sim.apply_M(M1) except: raise
def test_apply_units(): sim = Sim(layup = '45/90',materialID = 2) P = Q_(1000,'N'); b = Q_(0.11,'m'); L = Q_(0.51,'m') M1 = -P*L/(4*b); N1 = 0.5*P/b; M = Q_([M1.magnitude,0,0],M1.units) N = Q_([N1.magnitude,0,0],N1.units) print type(N1) try: sim.apply_M(M) sim.apply_N(N) sim.apply_N(N1) sim.apply_M(M1) except: raise
def test_solve_M(): sim = Sim(layup='45/90', materialID=2) assert (not sim.solved) try: sim.solve() except sim.WorkflowError: pass else: raise AssertionError("""Did not get a WorkflowError when solving before applying""") assert (not sim.solved) sim.apply_M([500, 500, 500] * ureg.MN) sim.solve() assert (sim.solved)
def test_Sim_ass_3(): #####From assignment 3#### laminate_q1 = Laminate('p10/90/0_2/p50s', materialID=1) laminate_q1.compute_all() load = numpy.array([450000, -110000, -130000], dtype=float) load = load * 10**-6 off_stress_norm = load * 10**-3 off_strain = laminate_q1.a.dot(off_stress_norm).reshape((3, 1)) on_strain = numpy.empty((14, 3)) on_stress = numpy.empty((14, 3)) for i in range(14): layer = laminate_q1.layers[i] on_strain[i, :] = transform_strain(off_strain, 'off', layer.theta) on_stress[i, :] = laminate_q1.layers[0].Q_on.dot(on_strain[i, :]) ###### ######From new Sim#### ##### my_sim = Sim(layup='p10/90/0_2/p50s', materialID=1) my_sim.apply_N(numpy.array([[0.4500], [-0.1100], [-0.1300]]) * ureg.MNperm) my_sim.solve() sim_off_strain = numpy.vstack(my_sim.off_strain) sim_on_strain = numpy.vstack(my_sim.on_strain) sim_on_stress = numpy.vstack(my_sim.on_stress) # sim_off_stress = numpy.vstack(my_sim.off_stress) for row in sim_off_strain: # print row array_assert_error(row, off_strain, tol=0.001) # for row in sim_on_strain: # array_assert_error(row,on_strain,tol=0.001) array_assert(sim_on_strain[0::2, :], on_strain, precision=10) array_assert(sim_on_strain[1::2, :], on_strain, precision=10) array_assert(sim_on_stress[0::2, :], on_stress, precision=10) array_assert(sim_on_stress[1::2, :], on_stress, precision=10)
def test_solve_M(): sim = Sim(layup = '45/90',materialID = 2) assert(not sim.solved) try: sim.solve() except sim.WorkflowError: pass else: raise AssertionError("""Did not get a WorkflowError when solving before applying""") assert(not sim.solved) sim.apply_M([500,500,500]*ureg.MN) sim.solve() assert(sim.solved)
def evaluate_layup(individual, materialID): list_of_str = ['{0:d}'.format(k) for k in individual] layup = '/'.join(list_of_str) + 's' laminate = Laminate(layup, materialID, zc) sim_1 = Sim(laminate=laminate) sim_1.apply_N(N_1) sim_1.apply_M(M_1) sim_1.solve() fail = FailureAnalysis(sim_1) the_mins = fail.find_min() first_min = min([R[0] for R in the_mins.values()]) sim_1.apply_N(N_2) sim_1.apply_M(M_2) fail = FailureAnalysis(sim_1) the_mins = fail.find_min() second_min = min([R[0] for R in the_mins.values()]) return float(min((first_min, second_min))),
def test_Sim_layup_id(): my_lam = Laminate('45/90', 2) sim = Sim(layup='45/90', materialID=2)
def test_Sim_laminate(): my_lam = Laminate('45/90', 2) sim = Sim(laminate=my_lam)