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_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_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_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_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_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)