def test_smart_vs_dumb(): my_dumb = Laminate('90_2/p40/p20/0s', 2) my_dumb.compute_all(method='dumb') my_smart = Laminate('90_2/p40/p20/0s', 2) my_smart.compute_all(method='smart') print len(my_smart.layers) for i in range(len(my_smart.layers)): for j in parse_request('QS'): smart = getattr(my_smart.layers[i], j) dumb = getattr(my_dumb.layers[i], j) array_assert(smart, dumb)
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_smart_q_s_on_uniform(): my_smart = Laminate('90_2/p40/p20/0s', 2) my_smart.compute_all(method='smart') Q_on_0 = my_smart.layers[0].Q_on S_on_0 = my_smart.layers[0].S_on for layer in my_smart.layers: array_assert(layer.Q_on, Q_on_0) array_assert(layer.S_on, S_on_0)
def test_quasi_isotropic(): import numpy my_lam = Laminate('0/p60s', 1) my_lam.compute_all() A = my_lam.A_vec array_assert(A[0], A[1]) array_assert(A[-1], 0.0) array_assert(A[-2], 0.0) array_assert((A[0] - A[2]) / 2, A[3])
def test_z_w_core(): my_laminate = Laminate('90_2/p40/p20/0s', 2, core_thick=1) # print "%.9f" % (my_laminate.layers[0].z_bot) print "%.9f" % (my_laminate.layers[13].z_top) array_assert(my_laminate.layers[0].z_bot, float(-0.500875)) array_assert(my_laminate.layers[13].z_top, float(0.500875000)) print -my_laminate.layers[6].z_top print my_laminate.layers[7].z_bot array_assert(float(my_laminate.layers[6].z_top), -1.0 * float(my_laminate.layers[7].z_bot))
def test_angle_ply(): import numpy my_lam = Laminate('p45s', 2) my_lam.compute_all() should_be_zero = numpy.absolute( numpy.array([my_lam.A_vec[-2:], my_lam.a_vec[-2:]]).reshape(4, )) zeros = [0] * 4 print should_be_zero print zeros array_assert(should_be_zero, zeros)
def test_values_p56_30degrees(): import numpy my_lam = Laminate('p30', 1) my_lam.compute_all() A = numpy.array(my_lam.A_vec) / my_lam.total_thickness A_desired = [109.3, 23.6, 32.46, 36.73, 0, 0] a = numpy.array(my_lam.a_vec) * my_lam.total_thickness * 1000 a_desired = [15.42, 71.36, -21.18, 27.22, 0, 0] array_assert(A, A_desired, precision=1) array_assert(a, a_desired, precision=1)
def test_d_cross_m_4(): import numpy layup = '0_4/90_4s' my_cross = Laminate(layup, 1) my_cross.compute_all() D_desired = numpy.array([[106.9, 1.93, 0.0], [1.93, 21.18, 0.0], [0.0, 0.0, 4.78]]) d_desired = numpy.array([[9.36, -0.85, 0], [-0.85, 47.27, 0], [0.0, 0.0, 209.2]]) array_assert(my_cross.D * 10**9, D_desired, precision=1) array_assert(my_cross.d * 10**-6, d_desired, precision=1)
def test_values_p56_75degrees(): import numpy my_lam = Laminate('m75', 1) my_lam.compute_all() print my_lam.layup print my_lam.A_vec A = numpy.array(my_lam.A_vec) / my_lam.total_thickness A_desired = [11.9, 160.4, 12.75, 17.02, 0, 0] a = numpy.array(my_lam.a_vec) * my_lam.total_thickness * 1000 a_desired = [91.21, 6.80, -7.24, 58.73, 0, 0] array_assert(A, A_desired, precision=1) array_assert(a, a_desired, precision=1)
def print_shit(a_layup): print "Layup : %s " % a_layup lam = Laminate(a_layup, 1, compute='smart') print "V*'s for A: %r" % lam.Vstar_for_A print "A* [GPa]:" print lam.A / lam.total_ply_thickness print "a* [1/TPa]:" print lam.a * lam.total_ply_thickness * 1000 print "V*'s for D: %r" % lam.Vstar_for_D print "D* : [GPa]:" Dstar = lam.D / (lam.total_thickness**3 / 12.0 * (1 - lam.zc)) print Dstar print "d* : [GPa]:" print scipy.linalg.inv(Dstar) * 1000 print '\n'
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_laminate(): my_lam = Laminate('45/90', 2) sim = Sim(laminate=my_lam)
def test_core_thickness(): my_laminate = Laminate('90_2/p40/p20/0s', 2, core_thick=0.01) assert (my_laminate.total_ply_thickness == 0.125 * 14 / 1000) assert (my_laminate.total_thickness == 0.125 * 14 / 1000 + 0.01) assert (my_laminate.has_core)
def test_A_core(): no_core_lam = Laminate('90_2/p40/p20/0s', 2, 0.0, True) w_core_lam = Laminate('90_2/p40/p20/0s', 2, 0.3, True) array_assert(no_core_lam.A, w_core_lam.A) array_assert(no_core_lam.a, w_core_lam.a)
def test_computed(): layup = '0_4/90_4s' my_lam = Laminate(layup, 1) assert (my_lam.computed == False) assert (my_lam.compute_all() == True) assert (my_lam.compute_all() == False)
def test_Sim_layup_id(): my_lam = Laminate('45/90', 2) sim = Sim(layup='45/90', materialID=2)
def setup(): global my_laminate my_laminate = Laminate('90_2/p40/p20/0s', 2)
def test_mass(): lam_naked = Laminate('90/90',2) lam_core = Laminate('90/90',2,0.5) assert(lam_naked.get_mass(1,2) == 1.0*2.0*0.125/1000*2*1.6) assert(lam_naked.get_mass(1,2) == lam_core.get_mass(1,2))