def test_composite_beam(): E = Symbol('E') I = Symbol('I') b1 = Beam(2, E, 1.5*I) b2 = Beam(2, E, I) b = b1.join(b2, "fixed") b.apply_load(-20, 0, -1) b.apply_load(80, 0, -2) b.apply_load(20, 4, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0)] assert b.length == 4 assert b.second_moment == Piecewise((1.5*I, x <= 2), (I, x <= 4)) assert b.slope().subs(x, 4) == 120.0/(E*I) assert b.slope().subs(x, 2) == 80.0/(E*I) assert int(b.deflection().subs(x, 4).args[0]) == 302 # Coefficient of 1/(E*I) l = symbols('l', positive=True) R1, M1, R2, R3, P = symbols('R1 M1 R2 R3 P') b1 = Beam(2*l, E, I) b2 = Beam(2*l, E, I) b = b1.join(b2,"hinge") b.apply_load(M1, 0, -2) b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(R3, 4*l, -1) b.apply_load(P, 3*l, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0), (l, 0), (4*l, 0)] b.solve_for_reaction_loads(M1, R1, R2, R3) assert b.reaction_loads == {R3: -P/2, R2: -5*P/4, M1: -P*l/4, R1: 3*P/4} assert b.slope().subs(x, 3*l) == -7*P*l**2/(48*E*I) assert b.deflection().subs(x, 2*l) == 7*P*l**3/(24*E*I) assert b.deflection().subs(x, 3*l) == 5*P*l**3/(16*E*I)
def test_point_cflexure(): E = Symbol('E') I = Symbol('I') b = Beam(10, E, I) b.apply_load(-4, 0, -1) b.apply_load(-46, 6, -1) b.apply_load(10, 2, -1) b.apply_load(20, 4, -1) b.apply_load(3, 6, 0) assert b.point_cflexure() == [S(10)/3]
def set_E_I_Len(self, instance): #print(self.E_text.text, "\n", self.I_text.text, "\n",self.len_text.text) self.E = self.E_text.text self.I = self.I_text.text self.Len = self.len_text.text self.BEAM = Beam(self.Len, self.E, self.I) self.popup.dismiss()
def popup_newbeam(self, instance): del self.BEAM self.E = "210E9" self.I = "1.71E-6" self.Len = '10' self.reaction_vars = [] self.i = 0 self.BEAM = Beam(self.Len, self.E, self.I) layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "ANALYSE A NEW BEAM NOW!!!")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "!!NEW!!",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open()
def menu(): print("Welcome to the Macaulay notation plotter.") print("How long is the beam?") xend = int(input("")) b = Beam(xend, E, I) print("How many forces are acting upon the beam?") num_forces = int(input("")) for x in range(num_forces): print("\nForce number " + str(x+1) + ":") print("What's the magnitude of the force? (Convention is upwards being positive.)") mag = int(input("")) print("How far along the beam is the force?") dist = int(input("")) print("What's the power?") power = int(input("")) b.apply_load(mag, dist, power-1) print("The Macaulay equation for the beam is:") pprint(b.shear_force()) graph_choice(b)
def test_composite_beam(): E = Symbol('E') I = Symbol('I') b1 = Beam(2, E, 1.5*I) b2 = Beam(2, E, I) b = b1.join(b2, "fixed") b.apply_load(-20, 0, -1) b.apply_load(80, 0, -2) b.apply_load(20, 4, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0)] assert b.length == 4 assert b.second_moment == Piecewise((1.5*I, x <= 2), (I, x <= 4)) assert b.slope().subs(x, 4) == 120.0/(E*I) assert b.slope().subs(x, 2) == 80.0/(E*I) assert int(b.deflection().subs(x, 4).args[0]) == 302 # Coefficient of 1/(E*I) l = symbols('l', positive=True) R1, M1, R2, R3, P = symbols('R1 M1 R2 R3 P') b1 = Beam(2*l, E, I) b2 = Beam(2*l, E, I) b = b1.join(b2,"hinge") b.apply_load(M1, 0, -2) b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(R3, 4*l, -1) b.apply_load(P, 3*l, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0), (l, 0), (4*l, 0)] b.solve_for_reaction_loads(M1, R1, R2, R3) assert b.reaction_loads == {R3: -P/2, R2: -5*P/4, M1: -P*l/4, R1: 3*P/4} assert b.slope().subs(x, 3*l) == -7*P*l**2/(48*E*I) assert b.deflection().subs(x, 2*l) == 7*P*l**3/(24*E*I) assert b.deflection().subs(x, 3*l) == 5*P*l**3/(16*E*I) # When beams having same second moment are joined. b1 = Beam(2, 500, 10) b2 = Beam(2, 500, 10) b = b1.join(b2, "fixed") b.apply_load(M1, 0, -2) b.apply_load(R1, 0, -1) b.apply_load(R2, 1, -1) b.apply_load(R3, 4, -1) b.apply_load(10, 3, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0), (1, 0), (4, 0)] b.solve_for_reaction_loads(M1, R1, R2, R3) assert b.slope() == -2*SingularityFunction(x, 0, 1)/5625 + SingularityFunction(x, 0, 2)/1875\ - 133*SingularityFunction(x, 1, 2)/135000 + SingularityFunction(x, 3, 2)/1000\ - 37*SingularityFunction(x, 4, 2)/67500 assert b.deflection() == -SingularityFunction(x, 0, 2)/5625 + SingularityFunction(x, 0, 3)/5625\ - 133*SingularityFunction(x, 1, 3)/405000 + SingularityFunction(x, 3, 3)/3000\ - 37*SingularityFunction(x, 4, 3)/202500
def test_variable_moment(): E = Symbol('E') I = Symbol('I') b = Beam(4, E, 2*(4 - x)) b.apply_load(20, 4, -1) R, M = symbols('R, M') b.apply_load(R, 0, -1) b.apply_load(M, 0, -2) b.bc_deflection = [(0, 0)] b.bc_slope = [(0, 0)] b.solve_for_reaction_loads(R, M) assert b.slope().expand() == ((10*x*SingularityFunction(x, 0, 0) - 10*(x - 4)*SingularityFunction(x, 4, 0))/E).expand() assert b.deflection().expand() == ((5*x**2*SingularityFunction(x, 0, 0) - 10*Piecewise((0, Abs(x)/4 < 1), (16*meijerg(((3, 1), ()), ((), (2, 0)), x/4), True)) + 40*SingularityFunction(x, 4, 1))/E).expand() b = Beam(4, E - x, I) b.apply_load(20, 4, -1) R, M = symbols('R, M') b.apply_load(R, 0, -1) b.apply_load(M, 0, -2) b.bc_deflection = [(0, 0)] b.bc_slope = [(0, 0)] b.solve_for_reaction_loads(R, M) assert b.slope().expand() == ((-80*(-log(-E) + log(-E + x))*SingularityFunction(x, 0, 0) + 80*(-log(-E + 4) + log(-E + x))*SingularityFunction(x, 4, 0) + 20*(-E*log(-E) + E*log(-E + x) + x)*SingularityFunction(x, 0, 0) - 20*(-E*log(-E + 4) + E*log(-E + x) + x - 4)*SingularityFunction(x, 4, 0))/I).expand()
def test_insufficient_bconditions(): # Test cases when required number of boundary conditions # are not provided to solve the integration constants. L = symbols('L', positive=True) E, I, P, a3, a4 = symbols('E I P a3 a4') b = Beam(L, E, I, base_char='a') b.apply_load(R2, L, -1) b.apply_load(R1, 0, -1) b.apply_load(-P, L/2, -1) b.solve_for_reaction_loads(R1, R2) p = b.slope() q = P*SingularityFunction(x, 0, 2)/4 - P*SingularityFunction(x, L/2, 2)/2 + P*SingularityFunction(x, L, 2)/4 assert p == q/(E*I) + a3 p = b.deflection() q = P*SingularityFunction(x, 0, 3)/12 - P*SingularityFunction(x, L/2, 3)/6 + P*SingularityFunction(x, L, 3)/12 assert p == q/(E*I) + a3*x + a4 b.bc_deflection = [(0, 0)] p = b.deflection() q = a3*x + P*SingularityFunction(x, 0, 3)/12 - P*SingularityFunction(x, L/2, 3)/6 + P*SingularityFunction(x, L, 3)/12 assert p == q/(E*I) b.bc_deflection = [(0, 0), (L, 0)] p = b.deflection() q = -L**2*P*x/16 + P*SingularityFunction(x, 0, 3)/12 - P*SingularityFunction(x, L/2, 3)/6 + P*SingularityFunction(x, L, 3)/12 assert p == q/(E*I)
from sympy.physics.continuum_mechanics.beam import Beam from sympy import symbols R1, R2 = symbols('R1, R2') b = Beam(8, 200*(10**9), 400*(10**-6)) b.apply_load(5000, 2, -1) b.apply_load(R1, 0, -1) b.apply_load(R2, 8, -1) b.apply_load(10000, 4, 0, end=8) b.bc_deflection = [(0, 0), (8, 0)] b.solve_for_reaction_loads(R1, R2) b.plot_deflection() # Plot object containing: # [0]: cartesian line: 0.00138541666666667*x - 2.86458333333333e-5*SingularityFunction(x, 0, 3) # + 1.04166666666667e-5*SingularityFunction(x, 2, 3) + 5.20833333333333e-6*SingularityFunction(x, 4, 4) # - 6.51041666666667e-5*SingularityFunction(x, 8, 3) - 5.20833333333333e-6*SingularityFunction(x, 8, 4) # for x over (0.0, 8.0)
def Test(): x, y, z = symbols('x y z') init_printing(use_unicode=True, wrap_line=False) E, I = symbols('E, I') b = Beam(9, E, I) #Apply loads # -point load of 12 kN downward at x = 9 and of the -1 order or, -12<x-9>^-1 b.apply_load(-12, 9, -1) # -Moment applied at x = 5 or, 5<x-5>^-2 b.apply_load(50, 5, -2) # -Distributed load from x= 0 to x=5 and of -8, or -8<x-0>^0 8<x-5>^0 b.apply_load(-8, 0, 0, end=5) #Boundary conditions # -At 0,0 the deflection will be 0 b.bc_deflection.append((0, 0)) # -At 0, 0 the slope will be 0 b.bc_slope.append((0, 0)) R, M = symbols('R, M') b.apply_load(R, 0, -1) b.apply_load(M, 0, -2) b.solve_for_reaction_loads(R, M)
def test_cross_section(): I = Symbol('I') l = Symbol('l') E = Symbol('E') C3, C4 = symbols('C3, C4') a, c, g, h, r, n = symbols('a, c, g, h, r, n') # test for second_moment and cross_section setter b0 = Beam(l, E, I) assert b0.second_moment == I assert b0.cross_section == None b0.cross_section = Circle((0, 0), 5) assert b0.second_moment == pi*Rational(625, 4) assert b0.cross_section == Circle((0, 0), 5) b0.second_moment = 2*n - 6 assert b0.second_moment == 2*n-6 assert b0.cross_section == None with raises(ValueError): b0.second_moment = Circle((0, 0), 5) # beam with a circular cross-section b1 = Beam(50, E, Circle((0, 0), r)) assert b1.cross_section == Circle((0, 0), r) assert b1.second_moment == pi*r*Abs(r)**3/4 b1.apply_load(-10, 0, -1) b1.apply_load(R1, 5, -1) b1.apply_load(R2, 50, -1) b1.apply_load(90, 45, -2) b1.solve_for_reaction_loads(R1, R2) assert b1.load == (-10*SingularityFunction(x, 0, -1) + 82*SingularityFunction(x, 5, -1)/S(9) + 90*SingularityFunction(x, 45, -2) + 8*SingularityFunction(x, 50, -1)/9) assert b1.bending_moment() == (-10*SingularityFunction(x, 0, 1) + 82*SingularityFunction(x, 5, 1)/9 + 90*SingularityFunction(x, 45, 0) + 8*SingularityFunction(x, 50, 1)/9) q = (-5*SingularityFunction(x, 0, 2) + 41*SingularityFunction(x, 5, 2)/S(9) + 90*SingularityFunction(x, 45, 1) + 4*SingularityFunction(x, 50, 2)/S(9))/(pi*E*r*Abs(r)**3) assert b1.slope() == C3 + 4*q q = (-5*SingularityFunction(x, 0, 3)/3 + 41*SingularityFunction(x, 5, 3)/27 + 45*SingularityFunction(x, 45, 2) + 4*SingularityFunction(x, 50, 3)/27)/(pi*E*r*Abs(r)**3) assert b1.deflection() == C3*x + C4 + 4*q # beam with a recatangular cross-section b2 = Beam(20, E, Polygon((0, 0), (a, 0), (a, c), (0, c))) assert b2.cross_section == Polygon((0, 0), (a, 0), (a, c), (0, c)) assert b2.second_moment == a*c**3/12 # beam with a triangular cross-section b3 = Beam(15, E, Triangle((0, 0), (g, 0), (g/2, h))) assert b3.cross_section == Triangle(Point2D(0, 0), Point2D(g, 0), Point2D(g/2, h)) assert b3.second_moment == g*h**3/36 # composite beam b = b2.join(b3, "fixed") b.apply_load(-30, 0, -1) b.apply_load(65, 0, -2) b.apply_load(40, 0, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0)] assert b.second_moment == Piecewise((a*c**3/12, x <= 20), (g*h**3/36, x <= 35)) assert b.cross_section == None assert b.length == 35 assert b.slope().subs(x, 7) == 8400/(E*a*c**3) assert b.slope().subs(x, 25) == 52200/(E*g*h**3) + 39600/(E*a*c**3) assert b.deflection().subs(x, 30) == 537000/(E*g*h**3) + 712000/(E*a*c**3)
from sympy import symbols from sympy.physics.continuum_mechanics.beam import Beam E, I = symbols('E, I') R_0, R_8 = symbols('R_0, R_8') b = Beam(12, E, I) b.apply_support(0, 'roller') b.apply_support(8, 'roller') b.solve_for_ild_reactions(1, R_0, R_8) b.solve_for_ild_shear(4, 1, R_0, R_8) b.ild_shear # Piecewise((x/8, x < 4), (x/8 - 1, x > 4)) b.plot_ild_shear() # Plot object containing: # [0]: cartesian line: Piecewise((x/8, x < 4), (x/8 - 1, x > 4)) for x over (0.0, 12.0)
from sympy.physics.continuum_mechanics.beam import Beam E, I = symbols('E, I') b = Beam(9, E, I)
def test_parabolic_loads(): E, I, L = symbols('E, I, L', positive=True, real=True) R, M, P = symbols('R, M, P', real=True) # cantilever beam fixed at x=0 and parabolic distributed loading across # length of beam beam = Beam(L, E, I) beam.bc_deflection.append((0, 0)) beam.bc_slope.append((0, 0)) beam.apply_load(R, 0, -1) beam.apply_load(M, 0, -2) # parabolic load beam.apply_load(1, 0, 2) beam.solve_for_reaction_loads(R, M) assert beam.reaction_loads[R] == -L**3 / 3 # cantilever beam fixed at x=0 and parabolic distributed loading across # first half of beam beam = Beam(2 * L, E, I) beam.bc_deflection.append((0, 0)) beam.bc_slope.append((0, 0)) beam.apply_load(R, 0, -1) beam.apply_load(M, 0, -2) # parabolic load from x=0 to x=L beam.apply_load(1, 0, 2, end=L) beam.solve_for_reaction_loads(R, M) # result should be the same as the prior example assert beam.reaction_loads[R] == -L**3 / 3 # check constant load beam = Beam(2 * L, E, I) beam.apply_load(P, 0, 0, end=L) loading = beam.load.xreplace({L: 10, E: 20, I: 30, P: 40}) assert loading.xreplace({x: 5}) == 40 assert loading.xreplace({x: 15}) == 0 # check ramp load beam = Beam(2 * L, E, I) beam.apply_load(P, 0, 1, end=L) assert beam.load == (P*SingularityFunction(x, 0, 1) - P*SingularityFunction(x, L, 1) - P*L*SingularityFunction(x, L, 0)) # check higher order load: x**8 load from x=0 to x=L beam = Beam(2 * L, E, I) beam.apply_load(P, 0, 8, end=L) loading = beam.load.xreplace({L: 10, E: 20, I: 30, P: 40}) assert loading.xreplace({x: 5}) == 40 * 5**8 assert loading.xreplace({x: 15}) == 0
def test_max_bmoment(): E = Symbol('E') I = Symbol('I') l, P = symbols('l, P', positive=True) b = Beam(l, E, I) R1, R2 = symbols('R1, R2') b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(P, l/2, -1) b.solve_for_reaction_loads(R1, R2) b.reaction_loads assert b.max_bmoment() == (l/2, P*l/4) b = Beam(l, E, I) R1, R2 = symbols('R1, R2') b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(P, 0, 0, end=l) b.solve_for_reaction_loads(R1, R2) assert b.max_bmoment() == (l/2, P*l**2/8)
def max_shear_force(self): E = Symbol('E') I = Symbol('I') b = Beam(3, E, I) R, M = symbols('R, M') b.apply_load(R, 0, -1) b.apply_load(M, 0, -2) b.apply_load(2, 3, -1) b.apply_load(4, 2, -1) b.apply_load(2, 2, 0, end=3) b.solve_for_reaction_loads(R, M) assert b.max_shear_force() == (Interval(0, 2), 8) l = symbols('l', positive=True) P = Symbol('P') b = Beam(l, E, I) R1, R2 = symbols('R1, R2') b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(P, 0, 0, end=l) b.solve_for_reaction_loads(R1, R2) assert b.max_shear_force() == (0, l*Abs(P)/2)
def test_apply_support(): E = Symbol('E') I = Symbol('I') b = Beam(4, E, I) b.apply_support(0, "cantilever") b.apply_load(20, 4, -1) M_0, R_0 = symbols('M_0, R_0') b.solve_for_reaction_loads(R_0, M_0) assert b.slope() == (80*SingularityFunction(x, 0, 1) - 10*SingularityFunction(x, 0, 2) + 10*SingularityFunction(x, 4, 2))/(E*I) assert b.deflection() == (40*SingularityFunction(x, 0, 2) - 10*SingularityFunction(x, 0, 3)/3 + 10*SingularityFunction(x, 4, 3)/3)/(E*I) b = Beam(30, E, I) b.apply_support(10, "pin") b.apply_support(30, "roller") b.apply_load(-8, 0, -1) b.apply_load(120, 30, -2) R_10, R_30 = symbols('R_10, R_30') b.solve_for_reaction_loads(R_10, R_30) assert b.slope() == (-4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2) + 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + S(4000)/3)/(E*I) assert b.deflection() == (4000*x/3 - 4*SingularityFunction(x, 0, 3)/3 + SingularityFunction(x, 10, 3) + 60*SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3)/3 - 12000)/(E*I) P = Symbol('P', positive=True) L = Symbol('L', positive=True) b = Beam(L, E, I) b.apply_support(0, type='fixed') b.apply_support(L, type='fixed') b.apply_load(-P, L/2, -1) R_0, R_L, M_0, M_L = symbols('R_0, R_L, M_0, M_L') b.solve_for_reaction_loads(R_0, R_L, M_0, M_L) assert b.reaction_loads == {R_0: P/2, R_L: P/2, M_0: -L*P/8, M_L: L*P/8}
def test_statically_indeterminate(): E = Symbol('E') I = Symbol('I') M1, M2 = symbols('M1, M2') F = Symbol('F') l = Symbol('l', positive=True) b5 = Beam(l, E, I) b5.bc_deflection = [(0, 0),(l, 0)] b5.bc_slope = [(0, 0),(l, 0)] b5.apply_load(R1, 0, -1) b5.apply_load(M1, 0, -2) b5.apply_load(R2, l, -1) b5.apply_load(M2, l, -2) b5.apply_load(-F, l/2, -1) b5.solve_for_reaction_loads(R1, R2, M1, M2) p = b5.reaction_loads q = {R1: F/2, R2: F/2, M1: -F*l/8, M2: F*l/8} assert p == q
def test_max_deflection(): E, I, l, F = symbols('E, I, l, F', positive=True) b = Beam(l, E, I) b.bc_deflection = [(0, 0),(l, 0)] b.bc_slope = [(0, 0),(l, 0)] b.apply_load(F/2, 0, -1) b.apply_load(-F*l/8, 0, -2) b.apply_load(F/2, l, -1) b.apply_load(F*l/8, l, -2) b.apply_load(-F, l/2, -1) assert b.max_deflection() == (l/2, F*l**3/(192*E*I))
def test_apply_support(): E = Symbol('E') I = Symbol('I') b = Beam(4, E, I) b.apply_support(0, "cantilever") b.apply_load(20, 4, -1) M_0, R_0 = symbols('M_0, R_0') b.solve_for_reaction_loads(R_0, M_0) assert b.slope() == (80*SingularityFunction(x, 0, 1) - 10*SingularityFunction(x, 0, 2) + 10*SingularityFunction(x, 4, 2))/(E*I) assert b.deflection() == (40*SingularityFunction(x, 0, 2) - 10*SingularityFunction(x, 0, 3)/3 + 10*SingularityFunction(x, 4, 3)/3)/(E*I) b = Beam(30, E, I) b.apply_support(10, "pin") b.apply_support(30, "roller") b.apply_load(-8, 0, -1) b.apply_load(120, 30, -2) R_10, R_30 = symbols('R_10, R_30') b.solve_for_reaction_loads(R_10, R_30) assert b.slope() == (-4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2) + 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + 4000/3)/(E*I) assert b.deflection() == (4000*x/3 - 4*SingularityFunction(x, 0, 3)/3 + SingularityFunction(x, 10, 3) + 60*SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3)/3 - 12000)/(E*I)
def calc_sympy(self): self.cal_flag = 'CALCULATE BY SYMPY' # change flag to CALCULATE BY SYMPY if (self.tie_release == 1): self.listAnchor = self.alt_release_tie(self.listAnchor0) else: self.listAnchor = self.listAnchor0 # total deflection by external load moment = self.topLoad[0] force_horizontal = self.topLoad[1] force_verticle = self.topLoad[2] E, I = symbols('E, I') # create tuple for constrain: base translation constrain, base rotation constrain, constrain of anchorage[1,2,3,...] # R1: assign force reaction at foundation, M1: assign moment reaction at foundation R1, M1 = symbols('R1,M1') # Assign anchorage force sysbols programically listAnchorSym = [] for countA in range(0, len(self.listAnchor)): listAnchorSym.append(symbols('A' + str(countA + 1))) beam = Beam(float(self.mastHeight), E, I) beam.apply_load(R1, 0, -1) # apply reaction force at height=0 beam.apply_load(M1, 0, -2) # apply reaction moment at height=0 beam.bc_slope.append( (self.windForceRegion[0], 0)) # boundary condition at h=0, slope=0 beam.bc_deflection.append( (self.windForceRegion[0], 0)) # boundary condition at h=0, deflection=0 for countAA in range(1, len(self.listAnchor) + 1): # apply reaction force at each anchorage beam.apply_load(listAnchorSym[countAA - 1], self.listAnchor[countAA - 1], -1) # apply boundary condition at each anchorage, deflection=0 beam.bc_deflection.append((self.listAnchor[countAA - 1], 0)) # apply external loads beam.apply_load(moment, float(self.mastHeight), -2) # apply moment beam.apply_load(force_horizontal, float(self.topWindHeight), -1) # apply horizontal force windRegn = self.windForceRegion[:] windRegn.append(self.mastHeight) # print(windRegn) nc = 0 # apply wind pressure for f_w in self.windForce: # print('1st: '+str(windRegn[nc])) # print('2nd: '+str(windRegn[nc+1])) # print('Force: '+str(f_w)) exStr = 'beam.apply_load(f_w,' + str( windRegn[nc]) + ',0,end=' + str(windRegn[nc + 1]) + ')' print(exStr) exec(exStr) # beam.apply_load(f_w,windRegn[nc],0,end=windRegn[nc+1]) nc += 1 # solve for reaction # l_anc=[R1,M1]+list(dict_anc.values()) # get value in dict_anc to list ### beam.solve_for_reaction_loads(tup) strOfAncSym = '' for countAB in range(0, len(self.listAnchor)): strOfAncSym += ', listAnchorSym[{}]'.format(str(countAB)) exec('beam.solve_for_reaction_loads(R1, M1{})'.format(strOfAncSym)) print(beam._reaction_loads) self.tab_fa = list( zip(self.listAnchor, list(beam._reaction_loads.values())[2:]))
def test_Beam(): E = Symbol("E") E_1 = Symbol("E_1") I = Symbol("I") I_1 = Symbol("I_1") b = Beam(1, E, I) assert b.length == 1 assert b.elastic_modulus == E assert b.second_moment == I assert b.variable == x # Test the length setter b.length = 4 assert b.length == 4 # Test the E setter b.elastic_modulus = E_1 assert b.elastic_modulus == E_1 # Test the I setter b.second_moment = I_1 assert b.second_moment is I_1 # Test the variable setter b.variable = y assert b.variable is y # Test for all boundary conditions. b.bc_deflection = [(0, 2)] b.bc_slope = [(0, 1)] assert b.boundary_conditions == {"deflection": [(0, 2)], "slope": [(0, 1)]} # Test for slope boundary condition method b.bc_slope.extend([(4, 3), (5, 0)]) s_bcs = b.bc_slope assert s_bcs == [(0, 1), (4, 3), (5, 0)] # Test for deflection boundary condition method b.bc_deflection.extend([(4, 3), (5, 0)]) d_bcs = b.bc_deflection assert d_bcs == [(0, 2), (4, 3), (5, 0)] # Test for updated boundary conditions bcs_new = b.boundary_conditions assert bcs_new == {"deflection": [(0, 2), (4, 3), (5, 0)], "slope": [(0, 1), (4, 3), (5, 0)]} b1 = Beam(30, E, I) b1.apply_load(-8, 0, -1) b1.apply_load(R1, 10, -1) b1.apply_load(R2, 30, -1) b1.apply_load(120, 30, -2) b1.bc_deflection = [(10, 0), (30, 0)] b1.solve_for_reaction_loads(R1, R2) # Test for finding reaction forces p = b1.reaction_loads q = {R1: 6, R2: 2} assert p == q # Test for load distribution function. p = b1.load q = ( -8 * SingularityFunction(x, 0, -1) + 6 * SingularityFunction(x, 10, -1) + 120 * SingularityFunction(x, 30, -2) + 2 * SingularityFunction(x, 30, -1) ) assert p == q # Test for shear force distribution function p = b1.shear_force() q = ( -8 * SingularityFunction(x, 0, 0) + 6 * SingularityFunction(x, 10, 0) + 120 * SingularityFunction(x, 30, -1) + 2 * SingularityFunction(x, 30, 0) ) assert p == q # Test for bending moment distribution function p = b1.bending_moment() q = ( -8 * SingularityFunction(x, 0, 1) + 6 * SingularityFunction(x, 10, 1) + 120 * SingularityFunction(x, 30, 0) + 2 * SingularityFunction(x, 30, 1) ) assert p == q # Test for slope distribution function p = b1.slope() q = ( -4 * SingularityFunction(x, 0, 2) + 3 * SingularityFunction(x, 10, 2) + 120 * SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + 4000 / 3 ) assert p == q / (E * I) # Test for deflection distribution function p = b1.deflection() q = ( 4000 * x / 3 - 4 * SingularityFunction(x, 0, 3) / 3 + SingularityFunction(x, 10, 3) + 60 * SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3) / 3 - 12000 ) assert p == q / (E * I) # Test using symbols l = Symbol("l") w0 = Symbol("w0") w2 = Symbol("w2") a1 = Symbol("a1") c = Symbol("c") c1 = Symbol("c1") d = Symbol("d") e = Symbol("e") f = Symbol("f") b2 = Beam(l, E, I) b2.apply_load(w0, a1, 1) b2.apply_load(w2, c1, -1) b2.bc_deflection = [(c, d)] b2.bc_slope = [(e, f)] # Test for load distribution function. p = b2.load q = w0 * SingularityFunction(x, a1, 1) + w2 * SingularityFunction(x, c1, -1) assert p == q # Test for shear force distribution function p = b2.shear_force() q = w0 * SingularityFunction(x, a1, 2) / 2 + w2 * SingularityFunction(x, c1, 0) assert p == q # Test for bending moment distribution function p = b2.bending_moment() q = w0 * SingularityFunction(x, a1, 3) / 6 + w2 * SingularityFunction(x, c1, 1) assert p == q # Test for slope distribution function p = b2.slope() q = ( f - w0 * SingularityFunction(e, a1, 4) / 24 + w0 * SingularityFunction(x, a1, 4) / 24 - w2 * SingularityFunction(e, c1, 2) / 2 + w2 * SingularityFunction(x, c1, 2) / 2 ) assert p == q / (E * I) # Test for deflection distribution function p = b2.deflection() q = ( -c * f + c * w0 * SingularityFunction(e, a1, 4) / 24 + c * w2 * SingularityFunction(e, c1, 2) / 2 + d + f * x - w0 * x * SingularityFunction(e, a1, 4) / 24 - w0 * SingularityFunction(c, a1, 5) / 120 + w0 * SingularityFunction(x, a1, 5) / 120 - w2 * x * SingularityFunction(e, c1, 2) / 2 - w2 * SingularityFunction(c, c1, 3) / 6 + w2 * SingularityFunction(x, c1, 3) / 6 ) assert p == q / (E * I) b3 = Beam(9, E, I) b3.apply_load(value=-2, start=2, order=2, end=3) b3.bc_slope.append((0, 2)) p = b3.load q = -2 * SingularityFunction(x, 2, 2) + 2 * SingularityFunction(x, 3, 0) + 2 * SingularityFunction(x, 3, 2) assert p == q p = b3.slope() q = -SingularityFunction(x, 2, 5) / 30 + SingularityFunction(x, 3, 3) / 3 + SingularityFunction(x, 3, 5) / 30 + 2 assert p == q / (E * I) p = b3.deflection() q = ( 2 * x - SingularityFunction(x, 2, 6) / 180 + SingularityFunction(x, 3, 4) / 12 + SingularityFunction(x, 3, 6) / 180 ) assert p == q / (E * I) b4 = Beam(4, E, I) b4.apply_load(-3, 0, 0, end=3) p = b4.load q = -3 * SingularityFunction(x, 0, 0) + 3 * SingularityFunction(x, 3, 0) assert p == q p = b4.slope() q = -3 * SingularityFunction(x, 0, 3) / 6 + 3 * SingularityFunction(x, 3, 3) / 6 assert p == q / (E * I) p = b4.deflection() q = -3 * SingularityFunction(x, 0, 4) / 24 + 3 * SingularityFunction(x, 3, 4) / 24 assert p == q / (E * I) raises(ValueError, lambda: b4.apply_load(-3, 0, -1, end=3)) with raises(TypeError): b4.variable = 1
def test_Beam(): E = Symbol('E') E_1 = Symbol('E_1') I = Symbol('I') I_1 = Symbol('I_1') b = Beam(1, E, I) assert b.length == 1 assert b.elastic_modulus == E assert b.second_moment == I assert b.variable == x # Test the length setter b.length = 4 assert b.length == 4 # Test the E setter b.elastic_modulus = E_1 assert b.elastic_modulus == E_1 # Test the I setter b.second_moment = I_1 assert b.second_moment is I_1 # Test the variable setter b.variable = y assert b.variable is y # Test for all boundary conditions. b.bc_deflection = [(0, 2)] b.bc_slope = [(0, 1)] assert b.boundary_conditions == {'deflection': [(0, 2)], 'slope': [(0, 1)]} # Test for slope boundary condition method b.bc_slope.extend([(4, 3), (5, 0)]) s_bcs = b.bc_slope assert s_bcs == [(0, 1), (4, 3), (5, 0)] # Test for deflection boundary condition method b.bc_deflection.extend([(4, 3), (5, 0)]) d_bcs = b.bc_deflection assert d_bcs == [(0, 2), (4, 3), (5, 0)] # Test for updated boundary conditions bcs_new = b.boundary_conditions assert bcs_new == { 'deflection': [(0, 2), (4, 3), (5, 0)], 'slope': [(0, 1), (4, 3), (5, 0)]} b1 = Beam(30, E, I) b1.apply_load(-8, 0, -1) b1.apply_load(R1, 10, -1) b1.apply_load(R2, 30, -1) b1.apply_load(120, 30, -2) b1.bc_deflection = [(10, 0), (30, 0)] b1.solve_for_reaction_loads(R1, R2) # Test for finding reaction forces p = b1.reaction_loads q = {R1: 6, R2: 2} assert p == q # Test for load distribution function. p = b1.load q = -8*SingularityFunction(x, 0, -1) + 6*SingularityFunction(x, 10, -1) + 120*SingularityFunction(x, 30, -2) + 2*SingularityFunction(x, 30, -1) assert p == q # Test for shear force distribution function p = b1.shear_force() q = -8*SingularityFunction(x, 0, 0) + 6*SingularityFunction(x, 10, 0) + 120*SingularityFunction(x, 30, -1) + 2*SingularityFunction(x, 30, 0) assert p == q # Test for bending moment distribution function p = b1.bending_moment() q = -8*SingularityFunction(x, 0, 1) + 6*SingularityFunction(x, 10, 1) + 120*SingularityFunction(x, 30, 0) + 2*SingularityFunction(x, 30, 1) assert p == q # Test for slope distribution function p = b1.slope() q = -4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2) + 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + S(4000)/3 assert p == q/(E*I) # Test for deflection distribution function p = b1.deflection() q = 4000*x/3 - 4*SingularityFunction(x, 0, 3)/3 + SingularityFunction(x, 10, 3) + 60*SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3)/3 - 12000 assert p == q/(E*I) # Test using symbols l = Symbol('l') w0 = Symbol('w0') w2 = Symbol('w2') a1 = Symbol('a1') c = Symbol('c') c1 = Symbol('c1') d = Symbol('d') e = Symbol('e') f = Symbol('f') b2 = Beam(l, E, I) b2.apply_load(w0, a1, 1) b2.apply_load(w2, c1, -1) b2.bc_deflection = [(c, d)] b2.bc_slope = [(e, f)] # Test for load distribution function. p = b2.load q = w0*SingularityFunction(x, a1, 1) + w2*SingularityFunction(x, c1, -1) assert p == q # Test for shear force distribution function p = b2.shear_force() q = w0*SingularityFunction(x, a1, 2)/2 + w2*SingularityFunction(x, c1, 0) assert p == q # Test for bending moment distribution function p = b2.bending_moment() q = w0*SingularityFunction(x, a1, 3)/6 + w2*SingularityFunction(x, c1, 1) assert p == q # Test for slope distribution function p = b2.slope() q = (w0*SingularityFunction(x, a1, 4)/24 + w2*SingularityFunction(x, c1, 2)/2)/(E*I) + (E*I*f - w0*SingularityFunction(e, a1, 4)/24 - w2*SingularityFunction(e, c1, 2)/2)/(E*I) assert p == q # Test for deflection distribution function p = b2.deflection() q = x*(E*I*f - w0*SingularityFunction(e, a1, 4)/24 - w2*SingularityFunction(e, c1, 2)/2)/(E*I) + (w0*SingularityFunction(x, a1, 5)/120 + w2*SingularityFunction(x, c1, 3)/6)/(E*I) + (E*I*(-c*f + d) + c*w0*SingularityFunction(e, a1, 4)/24 + c*w2*SingularityFunction(e, c1, 2)/2 - w0*SingularityFunction(c, a1, 5)/120 - w2*SingularityFunction(c, c1, 3)/6)/(E*I) assert p == q b3 = Beam(9, E, I) b3.apply_load(value=-2, start=2, order=2, end=3) b3.bc_slope.append((0, 2)) C3 = symbols('C3') C4 = symbols('C4') p = b3.load q = -2*SingularityFunction(x, 2, 2) + 2*SingularityFunction(x, 3, 0) + 4*SingularityFunction(x, 3, 1) + 2*SingularityFunction(x, 3, 2) assert p == q p = b3.slope() q = 2 + (-SingularityFunction(x, 2, 5)/30 + SingularityFunction(x, 3, 3)/3 + SingularityFunction(x, 3, 4)/6 + SingularityFunction(x, 3, 5)/30)/(E*I) assert p == q p = b3.deflection() q = 2*x + (-SingularityFunction(x, 2, 6)/180 + SingularityFunction(x, 3, 4)/12 + SingularityFunction(x, 3, 5)/30 + SingularityFunction(x, 3, 6)/180)/(E*I) assert p == q + C4 b4 = Beam(4, E, I) b4.apply_load(-3, 0, 0, end=3) p = b4.load q = -3*SingularityFunction(x, 0, 0) + 3*SingularityFunction(x, 3, 0) assert p == q p = b4.slope() q = -3*SingularityFunction(x, 0, 3)/6 + 3*SingularityFunction(x, 3, 3)/6 assert p == q/(E*I) + C3 p = b4.deflection() q = -3*SingularityFunction(x, 0, 4)/24 + 3*SingularityFunction(x, 3, 4)/24 assert p == q/(E*I) + C3*x + C4 # can't use end with point loads raises(ValueError, lambda: b4.apply_load(-3, 0, -1, end=3)) with raises(TypeError): b4.variable = 1
def test_apply_support(): E = Symbol('E') I = Symbol('I') b = Beam(4, E, I) b.apply_support(0, "cantilever") b.apply_load(20, 4, -1) M_0, R_0 = symbols('M_0, R_0') b.solve_for_reaction_loads(R_0, M_0) assert b.slope() == (80*SingularityFunction(x, 0, 1) - 10*SingularityFunction(x, 0, 2) + 10*SingularityFunction(x, 4, 2))/(E*I) assert b.deflection() == (40*SingularityFunction(x, 0, 2) - 10*SingularityFunction(x, 0, 3)/3 + 10*SingularityFunction(x, 4, 3)/3)/(E*I) b = Beam(30, E, I) b.apply_support(10, "pin") b.apply_support(30, "roller") b.apply_load(-8, 0, -1) b.apply_load(120, 30, -2) R_10, R_30 = symbols('R_10, R_30') b.solve_for_reaction_loads(R_10, R_30) assert b.slope() == (-4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2) + 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + Rational(4000, 3))/(E*I) assert b.deflection() == (x*Rational(4000, 3) - 4*SingularityFunction(x, 0, 3)/3 + SingularityFunction(x, 10, 3) + 60*SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3)/3 - 12000)/(E*I) P = Symbol('P', positive=True) L = Symbol('L', positive=True) b = Beam(L, E, I) b.apply_support(0, type='fixed') b.apply_support(L, type='fixed') b.apply_load(-P, L/2, -1) R_0, R_L, M_0, M_L = symbols('R_0, R_L, M_0, M_L') b.solve_for_reaction_loads(R_0, R_L, M_0, M_L) assert b.reaction_loads == {R_0: P/2, R_L: P/2, M_0: -L*P/8, M_L: L*P/8}
def test_beam_units(): E = Symbol('E') I = Symbol('I') R1, R2 = symbols('R1, R2') b = Beam(8*meter, 200*giga*newton/meter**2, 400*1000000*(milli*meter)**4) b.apply_load(5*kilo*newton, 2*meter, -1) b.apply_load(R1, 0*meter, -1) b.apply_load(R2, 8*meter, -1) b.apply_load(10*kilo*newton/meter, 4*meter, 0, end=8*meter) b.bc_deflection = [(0*meter, 0*meter), (8*meter, 0*meter)] b.solve_for_reaction_loads(R1, R2) assert b.reaction_loads == {R1: -13750*newton, R2: -31250*newton} b = Beam(3*meter, E*newton/meter**2, I*meter**4) b.apply_load(8*kilo*newton, 1*meter, -1) b.apply_load(R1, 0*meter, -1) b.apply_load(R2, 3*meter, -1) b.apply_load(12*kilo*newton*meter, 2*meter, -2) b.bc_deflection = [(0*meter, 0*meter), (3*meter, 0*meter)] b.solve_for_reaction_loads(R1, R2) assert b.reaction_loads == {R1: -28000*newton/3, R2: 4000*newton/3} assert b.deflection().subs(x, 1*meter) == 62000*meter/(9*E*I)
def test_composite_beam(): E = Symbol('E') I = Symbol('I') b1 = Beam(2, E, 1.5 * I) b2 = Beam(2, E, I) b = b1.join(b2, "fixed") b.apply_load(-20, 0, -1) b.apply_load(80, 0, -2) b.apply_load(20, 4, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0)] assert b.length == 4 assert b.second_moment == Piecewise((1.5 * I, x <= 2), (I, x <= 4)) assert b.slope().subs(x, 4) == 120.0 / (E * I) assert b.slope().subs(x, 2) == 80.0 / (E * I) assert int(b.deflection().subs(x, 4).args[0]) == 302 # Coefficient of 1/(E*I) l = symbols('l', positive=True) R1, M1, R2, R3, P = symbols('R1 M1 R2 R3 P') b1 = Beam(2 * l, E, I) b2 = Beam(2 * l, E, I) b = b1.join(b2, "hinge") b.apply_load(M1, 0, -2) b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(R3, 4 * l, -1) b.apply_load(P, 3 * l, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0), (l, 0), (4 * l, 0)] b.solve_for_reaction_loads(M1, R1, R2, R3) assert b.reaction_loads == { R3: -P / 2, R2: -5 * P / 4, M1: -P * l / 4, R1: 3 * P / 4 } assert b.slope().subs(x, 3 * l) == -7 * P * l**2 / (48 * E * I) assert b.deflection().subs(x, 2 * l) == 7 * P * l**3 / (24 * E * I) assert b.deflection().subs(x, 3 * l) == 5 * P * l**3 / (16 * E * I) # When beams having same second moment are joined. b1 = Beam(2, 500, 10) b2 = Beam(2, 500, 10) b = b1.join(b2, "fixed") b.apply_load(M1, 0, -2) b.apply_load(R1, 0, -1) b.apply_load(R2, 1, -1) b.apply_load(R3, 4, -1) b.apply_load(10, 3, -1) b.bc_slope = [(0, 0)] b.bc_deflection = [(0, 0), (1, 0), (4, 0)] b.solve_for_reaction_loads(M1, R1, R2, R3) assert b.slope() == -2*SingularityFunction(x, 0, 1)/5625 + SingularityFunction(x, 0, 2)/1875\ - 133*SingularityFunction(x, 1, 2)/135000 + SingularityFunction(x, 3, 2)/1000\ - 37*SingularityFunction(x, 4, 2)/67500 assert b.deflection() == -SingularityFunction(x, 0, 2)/5625 + SingularityFunction(x, 0, 3)/5625\ - 133*SingularityFunction(x, 1, 3)/405000 + SingularityFunction(x, 3, 3)/3000\ - 37*SingularityFunction(x, 4, 3)/202500
from sympy.physics.continuum_mechanics.beam import Beam from sympy import symbols, plot, S E, I = symbols('E, I') R1, R2 = symbols('R1, R2') b = Beam(6, E, I) b.apply_load(R1, 0, -1) b.apply_load(-S(3) / 2, 3, -2) b.apply_load(3, 3, 0) b.apply_load(1, 3, 1) b.apply_load(R2, 6, -1) b.bc_deflection.append((0, 0)) b.bc_deflection.append((6, 0)) b.solve_for_reaction_loads(R1, R2) b.reaction_loads # {R₁: -11/4, R₂: -43/4} b.load # -1 -2 -1 # 11⋅<x> 3⋅<x - 3> 0 1 43⋅<x - 6> # - ──────── - ─────────── + 3⋅<x - 3> + <x - 3> - ──────────── # 4 2 4
def Problem4_7(): x, y, z = symbols('x y z') A = lambda d: np.pi/4*d**2 I1 = MomentOfArea.MomentOfArea2("circle", 1, 1).momentEnglish I2 = MomentOfArea.MomentOfArea2("circle", 1, 1.5).momentEnglish I3 = MomentOfArea.MomentOfArea2("circle", 1, 1.75).momentEnglish gamma = 0.282 g = 32.2 * 12 L1 = 0.5 L2 = 8.0 L3 = 11.0 L4 = 0.5 A1 = A(1) A2 = A(1.5) A3 = A(1.75) A4 = A(1) # E, I = symbols('E, I') E = 30E6 init_printing(use_latex=True, wrap_line=False) b1 = Beam(L1, E, I1) b2 = Beam(L2, E, I2) b3 = Beam(L3, E, I3) b4 = Beam(L4, E, I1) ba = b1.join(b2, "fixed") bb = b2.join(ba, "fixed") bc = b3.join(bb, "fixed") b = b4.join(bc, "fixed") #Apply loads # -point load of 12 kN downward at x = 9 and of the -1 order or, -12<x-9>^-1 R1, R2 = symbols('R1, R2') # b.apply_load(R1, 0, -1) b.apply_load(-600, 8.5, -1) # -Moment # -Distributed load #Boundary conditions # -At 0,0 the deflection will be 0 b.bc_deflection.append((0, 0)) b.bc_deflection.append((0.5, 0)) # print(b.load) # -At 0, 0 the slope will be 0 # b.bc_slope.append((0, 0)) # R, M = symbols('R, M') b.apply_load(R1, 0, -1) b.apply_load(R2, 20, -1) # b.apply_load(R, 0, -1) # b.apply_load(M, 0, -2) b.solve_for_reaction_loads(R1, R2) # b.plot_shear_force() # b.plot_bending_moment() # Y = lambdify(x, b.plot_deflection(subs={E: 30E6}), "sympy") expr = b.deflection() # print(expr) m = b.max_deflection() f = lambdify(x, expr, "sympy") ans = f(5) L1c = L1/2 L2c = L1 + L2/2 L3c = L1 + L2 + L3/2 L4c = L1 + L2 + L3 + L4/2 w1 = gamma*g*L1*A1 w2 = gamma*g*L2*A2 w3 = gamma*g*L3*A3 w4 = gamma*g*L4*A4 omega = Fatigue.RayleighsLumpedMasses([w1, w2, w3, w4], [f(L1c), f(L2c), f(L3c), f(L4c)]) print(omega)
def test_remove_load(): E = Symbol('E') I = Symbol('I') b = Beam(4, E, I) try: b.remove_load(2, 1, -1) # As no load is applied on beam, ValueError should be returned. except ValueError: assert True else: assert False b.apply_load(-3, 0, -2) b.apply_load(4, 2, -1) b.apply_load(-2, 2, 2, end = 3) b.remove_load(-2, 2, 2, end = 3) assert b.load == -3*SingularityFunction(x, 0, -2) + 4*SingularityFunction(x, 2, -1) assert b.applied_loads == [(-3, 0, -2, None), (4, 2, -1, None)] try: b.remove_load(1, 2, -1) # As load of this magnitude was never applied at # this position, method should return a ValueError. except ValueError: assert True else: assert False b.remove_load(-3, 0, -2) b.remove_load(4, 2, -1) assert b.load == 0 assert b.applied_loads == []
def test_Beam(): E = Symbol('E') E_1 = Symbol('E_1') I = Symbol('I') I_1 = Symbol('I_1') b = Beam(1, E, I) assert b.length == 1 assert b.elastic_modulus == E assert b.second_moment == I assert b.variable == x # Test the length setter b.length = 4 assert b.length == 4 # Test the E setter b.elastic_modulus = E_1 assert b.elastic_modulus == E_1 # Test the I setter b.second_moment = I_1 assert b.second_moment is I_1 # Test the variable setter b.variable = y assert b.variable is y # Test for all boundary conditions. b.bc_deflection = [(0, 2)] b.bc_slope = [(0, 1)] assert b.boundary_conditions == {'deflection': [(0, 2)], 'slope': [(0, 1)]} # Test for slope boundary condition method b.bc_slope.extend([(4, 3), (5, 0)]) s_bcs = b.bc_slope assert s_bcs == [(0, 1), (4, 3), (5, 0)] # Test for deflection boundary condition method b.bc_deflection.extend([(4, 3), (5, 0)]) d_bcs = b.bc_deflection assert d_bcs == [(0, 2), (4, 3), (5, 0)] # Test for updated boundary conditions bcs_new = b.boundary_conditions assert bcs_new == { 'deflection': [(0, 2), (4, 3), (5, 0)], 'slope': [(0, 1), (4, 3), (5, 0)]} b1 = Beam(30, E, I) b1.apply_load(-8, 0, -1) b1.apply_load(R1, 10, -1) b1.apply_load(R2, 30, -1) b1.apply_load(120, 30, -2) b1.bc_deflection = [(10, 0), (30, 0)] b1.solve_for_reaction_loads(R1, R2) # Test for finding reaction forces p = b1.reaction_loads q = {R1: 6, R2: 2} assert p == q # Test for load distribution function. p = b1.load q = -8*SingularityFunction(x, 0, -1) + 6*SingularityFunction(x, 10, -1) + 120*SingularityFunction(x, 30, -2) + 2*SingularityFunction(x, 30, -1) assert p == q # Test for shear force distribution function p = b1.shear_force() q = -8*SingularityFunction(x, 0, 0) + 6*SingularityFunction(x, 10, 0) + 120*SingularityFunction(x, 30, -1) + 2*SingularityFunction(x, 30, 0) assert p == q # Test for bending moment distribution function p = b1.bending_moment() q = -8*SingularityFunction(x, 0, 1) + 6*SingularityFunction(x, 10, 1) + 120*SingularityFunction(x, 30, 0) + 2*SingularityFunction(x, 30, 1) assert p == q # Test for slope distribution function p = b1.slope() q = -4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2) + 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + 4000/3 assert p == q/(E*I) # Test for deflection distribution function p = b1.deflection() q = 4000*x/3 - 4*SingularityFunction(x, 0, 3)/3 + SingularityFunction(x, 10, 3) + 60*SingularityFunction(x, 30, 2) + SingularityFunction(x, 30, 3)/3 - 12000 assert p == q/(E*I) # Test using symbols l = Symbol('l') w0 = Symbol('w0') w2 = Symbol('w2') a1 = Symbol('a1') c = Symbol('c') c1 = Symbol('c1') d = Symbol('d') e = Symbol('e') f = Symbol('f') b2 = Beam(l, E, I) b2.apply_load(w0, a1, 1) b2.apply_load(w2, c1, -1) b2.bc_deflection = [(c, d)] b2.bc_slope = [(e, f)] # Test for load distribution function. p = b2.load q = w0*SingularityFunction(x, a1, 1) + w2*SingularityFunction(x, c1, -1) assert p == q # Test for shear force distribution function p = b2.shear_force() q = w0*SingularityFunction(x, a1, 2)/2 + w2*SingularityFunction(x, c1, 0) assert p == q # Test for bending moment distribution function p = b2.bending_moment() q = w0*SingularityFunction(x, a1, 3)/6 + w2*SingularityFunction(x, c1, 1) assert p == q # Test for slope distribution function p = b2.slope() q = (w0*SingularityFunction(x, a1, 4)/24 + w2*SingularityFunction(x, c1, 2)/2)/(E*I) + (E*I*f - w0*SingularityFunction(e, a1, 4)/24 - w2*SingularityFunction(e, c1, 2)/2)/(E*I) assert p == q # Test for deflection distribution function p = b2.deflection() q = x*(E*I*f - w0*SingularityFunction(e, a1, 4)/24 - w2*SingularityFunction(e, c1, 2)/2)/(E*I) + (w0*SingularityFunction(x, a1, 5)/120 + w2*SingularityFunction(x, c1, 3)/6)/(E*I) + (E*I*(-c*f + d) + c*w0*SingularityFunction(e, a1, 4)/24 + c*w2*SingularityFunction(e, c1, 2)/2 - w0*SingularityFunction(c, a1, 5)/120 - w2*SingularityFunction(c, c1, 3)/6)/(E*I) assert p == q b3 = Beam(9, E, I) b3.apply_load(value=-2, start=2, order=2, end=3) b3.bc_slope.append((0, 2)) C3 = symbols('C3') C4 = symbols('C4') p = b3.load q = -2*SingularityFunction(x, 2, 2) + 2*SingularityFunction(x, 3, 0) + 4*SingularityFunction(x, 3, 1) + 2*SingularityFunction(x, 3, 2) assert p == q p = b3.slope() q = 2 + (-SingularityFunction(x, 2, 5)/30 + SingularityFunction(x, 3, 3)/3 + SingularityFunction(x, 3, 4)/6 + SingularityFunction(x, 3, 5)/30)/(E*I) assert p == q p = b3.deflection() q = 2*x + (-SingularityFunction(x, 2, 6)/180 + SingularityFunction(x, 3, 4)/12 + SingularityFunction(x, 3, 5)/30 + SingularityFunction(x, 3, 6)/180)/(E*I) assert p == q + C4 b4 = Beam(4, E, I) b4.apply_load(-3, 0, 0, end=3) p = b4.load q = -3*SingularityFunction(x, 0, 0) + 3*SingularityFunction(x, 3, 0) assert p == q p = b4.slope() q = -3*SingularityFunction(x, 0, 3)/6 + 3*SingularityFunction(x, 3, 3)/6 assert p == q/(E*I) + C3 p = b4.deflection() q = -3*SingularityFunction(x, 0, 4)/24 + 3*SingularityFunction(x, 3, 4)/24 assert p == q/(E*I) + C3*x + C4 # can't use end with point loads raises(ValueError, lambda: b4.apply_load(-3, 0, -1, end=3)) with raises(TypeError): b4.variable = 1
class Panel(FloatLayout): def __init__(self, **kwargs): super(Panel, self).__init__(**kwargs) self.E = "210E9" self.I = "1.71E-6" self.Len = '10' self.reaction_vars = [] self.BEAM = Beam(self.Len, self.E, self.I) self.i = 0 self.add_widget(Label(text = 'MAKE BEAM', size_hint = (.25, 0.1), pos_hint = {'x' : 0, 'y' : 0.9})) layout = GridLayout(cols=1, spacing=10, size_hint_y=None, size_hint_x = 1) layout.bind(minimum_height = layout.setter('height')) default_val = Button(text = 'SET E, I, L', size_hint_y=None, height=40) layout.add_widget(default_val) default_val.bind(on_press = self.popup_default_value) layout.add_widget(Label(text = 'SUPPORTS', size_hint_y=None, height=40)) Fix = Button(text = 'FIX', size_hint_y=None, height=40) layout.add_widget(Fix) Fix.bind(on_press = self.popup_fix) Roller = Button(text = 'ROLLER', size_hint_y=None, height=40) layout.add_widget(Roller) Roller.bind(on_press = self.popup_roller) Pin = Button(text = 'PIN', size_hint_y=None, height=40) layout.add_widget(Pin) Pin.bind(on_press = self.popup_pin) layout.add_widget(Label(text = 'LOADS', size_hint_y=None, height=40)) layout.add_widget(Label(text = 'CONCENTRATED', size_hint_y=None, height=40)) Vertical = Button(text = 'VERTICAL', size_hint_y=None, height=40) layout.add_widget(Vertical) Vertical.bind(on_press = self.popup_vertical) Moment = Button(text = 'MOMENT', size_hint_y=None, height=40) layout.add_widget(Moment) Moment.bind(on_press = self.popup_moment) layout.add_widget(Label(text = 'DISTRIBUTED', size_hint_y=None, height=40)) Linear = Button(text = 'LINEAR', size_hint_y=None, height=40) layout.add_widget(Linear) Linear.bind(on_press = self.popup_linear) NewBeam = Button(text = 'NEW BEAM', size_hint_y=None, height=40) layout.add_widget(NewBeam) NewBeam.bind(on_press = self.popup_newbeam) MakeBeam = ScrollView(size_hint=(.25, .9)) MakeBeam.add_widget(layout) self.add_widget(MakeBeam) self.add_widget(Label(text = 'ANALYSE BEAM', size_hint = (.75, .1), pos_hint = {'x' : .25, 'y' : .9})) layout_analysis = GridLayout(cols=2, spacing=10, size_hint = (.75, .3), pos_hint = {'x' : .25, 'y' : .6}) Shear = Button(text = 'SHEAR FORCE DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Shear) Shear.bind(on_press = self.popup_shear) Bending = Button(text = 'BENDING MOMENT DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Bending) Bending.bind(on_press = self.popup_bending) Slope = Button(text = 'SLOPE DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Slope) Slope.bind(on_press = self.popup_slope) Deflection = Button(text = 'DEFLECTION DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Deflection) Deflection.bind(on_press = self.popup_deflection) PlotAll = Button(text = 'PLOT ALL 4', size_hint_y=None, height=20) layout_analysis.add_widget(PlotAll) PlotAll.bind(on_press = self.popup_plotall) Reaction = Button(text = 'REACTION LOADS', size_hint_y=None, height=15) layout_analysis.add_widget(Reaction) Reaction.bind(on_press = self.popup_reaction) self.add_widget(layout_analysis) def popup_default_value(self, instance): #layout = BoxLayout(orientation = 'vertical') #layout1 is our child wiget of layout and is GridLayout with coloumn = 2 layout1 = GridLayout(cols = 2) #layout1's child widget Label layout1.add_widget(Label(text = 'E () = ')) #layout1's child widget having value of E self.E_text = TextInput(text = self.E,multiline = False) layout1.add_widget(self.E_text) #layout1's child widget Label layout1.add_widget(Label(text = 'I () = ')) #layout1's another child widget having value of E self.I_text = TextInput(text = self.I,multiline = False) layout1.add_widget(self.I_text) #layout1's child widget Label layout1.add_widget(Label(text = 'LENGTH (m) = ')) #layout1's another child widget having value of length of beam self.len_text = TextInput(text = self.Len,multiline = False) layout1.add_widget(self.len_text) #Button to save the changes done btn = Button(text = 'SAVE') layout1.add_widget(btn) btn.bind(on_press = self.set_E_I_Len) #Button to accept the default values and close the popup btn2 = Button(text = 'CLOSE') layout1.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) #layout.add_widget(layout1) #Instantiating the Popup self.popup = Popup(title = 'SET E, I AND LENGTH FOR BEAM', content = layout1, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_fix(self, instance): layout = GridLayout(cols = 2) layout.add_widget(Label(text = 'X (m) = ')) self.fix_text = TextInput(multiline = False) layout.add_widget(self.fix_text) btn = Button(text = 'SAVE') layout.add_widget(btn) btn.bind(on_press = self.add_fix) btn2 = Button(text = 'CLOSE') layout.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) self.popup = Popup(title = 'FIX SUPPPORT (m)', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_roller(self, instance): layout = GridLayout(cols = 2) layout.add_widget(Label(text = 'X (m) = ')) self.roller_text = TextInput(multiline = False) layout.add_widget(self.roller_text) btn = Button(text = 'SAVE') layout.add_widget(btn) btn.bind(on_press = self.add_roller) btn2 = Button(text = 'CLOSE') layout.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) self.popup = Popup(title = 'ROLLER SUPPORT (m)', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_pin(self, instance): layout = GridLayout(cols = 2) layout.add_widget(Label(text = 'X (m) = ')) self.pin_text = TextInput(multiline = False) layout.add_widget(self.pin_text) btn = Button(text = 'SAVE') layout.add_widget(btn) btn.bind(on_press = self.add_pin) btn2 = Button(text = 'CLOSE') layout.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) self.popup = Popup(title = 'PIN SUPPORT ', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_vertical(self, instance): layout = BoxLayout(orientation = 'vertical') layout1 = GridLayout(cols = 2) layout1.add_widget(Label(text = 'X(m) = ')) self.vertical_load_pos_text = TextInput(multiline = False) layout1.add_widget(self.vertical_load_pos_text) layout1.add_widget(Label(text = 'LOAD(kN) = ')) self.vertical_load_mag_text = TextInput(multiline = False) layout1.add_widget(self.vertical_load_mag_text) layout.add_widget(layout1) self.load_dir = Toggle_btn() layout.add_widget(self.load_dir) layout2 = GridLayout(cols = 2) btn = Button(text = 'SAVE') layout2.add_widget(btn) btn.bind(on_press = self.add_vertical_load) btn2 = Button(text = 'CLOSE') layout2.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) layout.add_widget(layout2) self.popup = Popup(title = 'POINT LOAD ', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_moment(self, instance): layout = BoxLayout(orientation = 'vertical') layout1 = GridLayout(cols = 2) layout1.add_widget(Label(text = 'X(m) = ')) self.moment_pos_text = TextInput(multiline = False) layout1.add_widget(self.moment_pos_text) layout1.add_widget(Label(text = 'MOMENT (kN * m)= ')) self.moment_mag_text = TextInput(multiline = False) layout1.add_widget(self.moment_mag_text) layout.add_widget(layout1) self.moment_dir = Toggle_btn_moment() layout.add_widget(self.moment_dir) layout2 = GridLayout(cols = 2) btn = Button(text = 'SAVE') layout2.add_widget(btn) btn.bind(on_press = self.add_moment) btn2 = Button(text = 'CLOSE') layout2.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) layout.add_widget(layout2) self.popup = Popup(title = 'MOMENT MAG. ', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_linear(self, instance): layout = BoxLayout(orientation = 'vertical') layout1 = GridLayout(cols = 2) layout1.add_widget(Label(text = 'X1 (m) = ')) self.starting_pos_text = TextInput(multiline = False) layout1.add_widget(self.starting_pos_text) layout1.add_widget(Label(text = 'X2 (m) = ')) self.ending_pos_text = TextInput(multiline = False) layout1.add_widget(self.ending_pos_text) layout1.add_widget(Label(text = 'LOAD(kN) = ')) self.load_per_m_text = TextInput(multiline = False) layout1.add_widget(self.load_per_m_text) layout.add_widget(layout1) self.load_dir_linear = Toggle_btn() layout.add_widget(self.load_dir_linear) layout2 = GridLayout(cols = 2) btn = Button(text = 'SAVE') layout2.add_widget(btn) btn.bind(on_press = self.add_linear_load) btn2 = Button(text = 'CLOSE') layout2.add_widget(btn2) btn2.bind(on_press = self.popup_dismiss) layout.add_widget(layout2) self.popup = Popup(title = 'DISTRIBUTED LINEAR LOAD ', content = layout, size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup.open() def popup_shear(self, instance): pass def popup_bending(self, instance): pass def popup_slope(self, instance): pass def popup_deflection(self, instance): pass def popup_plotall(self, instance): self.BEAM.solve_for_reaction_loads(*self.reaction_vars) d = self.BEAM.reaction_loads for i, j in d.items(): print(j) pass def popup_reaction(self, instance): if self.i > 0: layout_react = BoxLayout(orientation = 'vertical') for i, j in self.d.items(): alphabet, distance = str(i).split('_') if alphabet == 'R': text1 = 'Reaction Force at x = {} m is {} N'.format(distance, j) elif alphabet == 'M': text1 = 'Reaction Moment at x = {} m is {} N*m'.format(distance, j) layout_react.add_widget(Label(text = text1)) btn = Button(text = 'CLOSE') layout_react.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "SUPPPORT REACTIONS",content = layout_react , size_hint = (.8, .8), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() else: self.i += 1 try: self.BEAM.solve_for_reaction_loads(*self.reaction_vars) except: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "INSUFFICIENT DATA GIVEN!!")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "BEAM UNSTABLE!",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() else: layout_react = BoxLayout(orientation = 'vertical') #self.BEAM.solve_for_reaction_loads(*self.reaction_vars) self.d = self.BEAM.reaction_loads #react_name = list(d.keys()) #react_value = list(d.values()) #print(self.BEAM.reaction_loads, d, react_name, react_value) #more_than_once_call: for i, j in self.d.items(): alphabet, distance = str(i).split('_') if alphabet == 'R': text1 = 'Reaction Force at x = {} m is {} N'.format(distance, j) elif alphabet == 'M': text1 = 'Reaction Moment at x = {} m is {} N*m'.format(distance, j) layout_react.add_widget(Label(text = text1)) btn = Button(text = 'CLOSE') layout_react.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "SUPPPORT REACTIONS",content = layout_react , size_hint = (.8, .8), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def popup_cflexure(self, instance): pass def popup_newbeam(self, instance): del self.BEAM self.E = "210E9" self.I = "1.71E-6" self.Len = '10' self.reaction_vars = [] self.i = 0 self.BEAM = Beam(self.Len, self.E, self.I) layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "ANALYSE A NEW BEAM NOW!!!")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "!!NEW!!",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() """def len_of_beam(self, instance): self.BEAM = Beam(self.len_text.text, self.E, self.I) self.popup.dismiss() print(type(self.len_text.text)) print(self.E) print(self.I) """ def set_E_I_Len(self, instance): #print(self.E_text.text, "\n", self.I_text.text, "\n",self.len_text.text) self.E = self.E_text.text self.I = self.I_text.text self.Len = self.len_text.text self.BEAM = Beam(self.Len, self.E, self.I) self.popup.dismiss() def add_fix(self, instance): if self.fix_text.text: self.reaction_vars.append(symbols('R_{}'.format(self.fix_text.text))) self.reaction_vars.append(symbols('M_{}'.format(self.fix_text.text))) self.BEAM.apply_support(self.fix_text.text, 'fixed') self.BEAM.bc_deflection.append((self.fix_text.text, 0)) self.BEAM.bc_slope.append((self.fix_text.text, 0)) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU HAVEN'T ENTERED POSITION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "NOTHING TO SAVE",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def add_roller(self, instance): if self.roller_text.text: self.reaction_vars.append(symbols('R_{}'.format(self.roller_text.text))) self.BEAM.apply_support(self.roller_text.text, 'roller') self.BEAM.bc_deflection.append((self.roller_text.text, 0)) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU HAVEN'T ENTERED POSITION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "NOTHING TO SAVE",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def add_pin(self, instance): if self.pin_text.text: self.reaction_vars.append(symbols('R_{}'.format(self.pin_text.text))) self.BEAM.apply_support(self.pin_text.text, 'pin') self.BEAM.bc_deflection.append((self.pin_text.text, 0)) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU HAVEN'T ENTERED POSITION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "NOTHING TO SAVE",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def add_vertical_load(self, instance): if self.vertical_load_mag_text.text != '' and self.vertical_load_pos_text.text != '': states = self.load_dir.get_state() print(states) if (states[0] == 'normal' and states[1] == 'down') or (states[0] == 'down' and states[1] == 'normal'): if states[0] == 'normal' and states[1] == 'down': self.BEAM.apply_load(self.vertical_load_mag_text.text, self.vertical_load_pos_text.text, -1) self.popup.dismiss() else: self.BEAM.apply_load('-' + self.vertical_load_mag_text.text, self.vertical_load_pos_text.text, -1) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU MUST CHOOSE ONE DIRECTION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "IN WHICH DIR. DO I APPLY LOAD ?",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "ENTER BOTH LOAD MAG. AND POS.")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "INSUFFICIENT INFO !",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def add_moment(self, instance): if self.moment_pos_text.text != '' and self.moment_mag_text.text != '': states = self.moment_dir.get_state() print(states) if (states[0] == 'normal' and states[1] == 'down') or (states[0] == 'down' and states[1] == 'normal'): if states[0] == 'normal' and states[1] == 'down': self.BEAM.apply_load(self.moment_mag_text.text, self.moment_pos_text.text, -2) self.popup.dismiss() else: self.BEAM.apply_load('-' + self.moment_mag_text.text, self.moment_pos_text.text, -2) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU MUST CHOOSE ONE DIRECTION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "IN WHICH DIR. DO I APPLY MOMENT ?",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "ENTER BOTH MOMENT MAG. AND POS.")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "INSUFFICIENT INFO !",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def add_linear_load(self, instance): if self.starting_pos_text.text != '' and self.ending_pos_text.text != '' and self.load_per_m_text.text != '': states = self.load_dir_linear.get_state() print(states) if (states[0] == 'normal' and states[1] == 'down') or (states[0] == 'down' and states[1] == 'normal'): if states[0] == 'normal' and states[1] == 'down': self.BEAM.apply_load(self.load_per_m_text.text, self.starting_pos_text.text, 0, self.ending_pos_text.text) self.popup.dismiss() else: self.BEAM.apply_load('-' + self.load_per_m_text.text, self.starting_pos_text.text, 0, int(self.ending_pos_text.text)) self.popup.dismiss() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "YOU MUST CHOOSE ONE DIRECTION")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "IN WHICH DIR. DO I APPLY THE LOAD ?",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() else: layout = BoxLayout(orientation = 'vertical') layout.add_widget(Label(text = "ENTER ALL START, END AND LOAD")) btn = Button(text = 'CLOSE') layout.add_widget(btn) btn.bind(on_press = self.popup_in_popup_dismiss) self.popup_in_popup = Popup(title = "INSUFFICIENT INFO !",content = layout , size_hint = (.4, .4), pos_hint = {'center_x' : .5, 'center_y' : .5}) self.popup_in_popup.open() def popup_dismiss(self, instance): self.popup.dismiss() def popup_in_popup_dismiss(self, instance): self.popup_in_popup.dismiss()
def __init__(self, **kwargs): super(Panel, self).__init__(**kwargs) self.E = "210E9" self.I = "1.71E-6" self.Len = '10' self.reaction_vars = [] self.BEAM = Beam(self.Len, self.E, self.I) self.i = 0 self.add_widget(Label(text = 'MAKE BEAM', size_hint = (.25, 0.1), pos_hint = {'x' : 0, 'y' : 0.9})) layout = GridLayout(cols=1, spacing=10, size_hint_y=None, size_hint_x = 1) layout.bind(minimum_height = layout.setter('height')) default_val = Button(text = 'SET E, I, L', size_hint_y=None, height=40) layout.add_widget(default_val) default_val.bind(on_press = self.popup_default_value) layout.add_widget(Label(text = 'SUPPORTS', size_hint_y=None, height=40)) Fix = Button(text = 'FIX', size_hint_y=None, height=40) layout.add_widget(Fix) Fix.bind(on_press = self.popup_fix) Roller = Button(text = 'ROLLER', size_hint_y=None, height=40) layout.add_widget(Roller) Roller.bind(on_press = self.popup_roller) Pin = Button(text = 'PIN', size_hint_y=None, height=40) layout.add_widget(Pin) Pin.bind(on_press = self.popup_pin) layout.add_widget(Label(text = 'LOADS', size_hint_y=None, height=40)) layout.add_widget(Label(text = 'CONCENTRATED', size_hint_y=None, height=40)) Vertical = Button(text = 'VERTICAL', size_hint_y=None, height=40) layout.add_widget(Vertical) Vertical.bind(on_press = self.popup_vertical) Moment = Button(text = 'MOMENT', size_hint_y=None, height=40) layout.add_widget(Moment) Moment.bind(on_press = self.popup_moment) layout.add_widget(Label(text = 'DISTRIBUTED', size_hint_y=None, height=40)) Linear = Button(text = 'LINEAR', size_hint_y=None, height=40) layout.add_widget(Linear) Linear.bind(on_press = self.popup_linear) NewBeam = Button(text = 'NEW BEAM', size_hint_y=None, height=40) layout.add_widget(NewBeam) NewBeam.bind(on_press = self.popup_newbeam) MakeBeam = ScrollView(size_hint=(.25, .9)) MakeBeam.add_widget(layout) self.add_widget(MakeBeam) self.add_widget(Label(text = 'ANALYSE BEAM', size_hint = (.75, .1), pos_hint = {'x' : .25, 'y' : .9})) layout_analysis = GridLayout(cols=2, spacing=10, size_hint = (.75, .3), pos_hint = {'x' : .25, 'y' : .6}) Shear = Button(text = 'SHEAR FORCE DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Shear) Shear.bind(on_press = self.popup_shear) Bending = Button(text = 'BENDING MOMENT DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Bending) Bending.bind(on_press = self.popup_bending) Slope = Button(text = 'SLOPE DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Slope) Slope.bind(on_press = self.popup_slope) Deflection = Button(text = 'DEFLECTION DIAGRAM', size_hint_y=None, height=20) layout_analysis.add_widget(Deflection) Deflection.bind(on_press = self.popup_deflection) PlotAll = Button(text = 'PLOT ALL 4', size_hint_y=None, height=20) layout_analysis.add_widget(PlotAll) PlotAll.bind(on_press = self.popup_plotall) Reaction = Button(text = 'REACTION LOADS', size_hint_y=None, height=15) layout_analysis.add_widget(Reaction) Reaction.bind(on_press = self.popup_reaction) self.add_widget(layout_analysis)
from sympy.physics.continuum_mechanics.beam import Beam from sympy import symbols R1, R2 = symbols('R1, R2') E, I = symbols('E, I') b = Beam(50, 20, 30) b.apply_load(10, 2, -1) b.apply_load(R1, 10, -1) b.apply_load(R2, 30, -1) b.apply_load(90, 5, 0, 23) b.apply_load(10, 30, 1, 50) b.apply_support(50, "pin") b.apply_support(0, "fixed") b.apply_support(20, "roller") p = b.draw() p # Plot object containing: # [0]: cartesian line: 25*SingularityFunction(x, 5, 0) - 25*SingularityFunction(x, 23, 0) # + SingularityFunction(x, 30, 1) - 20*SingularityFunction(x, 50, 0) # - SingularityFunction(x, 50, 1) + 5 for x over (0.0, 50.0) # [1]: cartesian line: 5 for x over (0.0, 50.0) p.show()
def test_max_shear_force(): E = Symbol("E") I = Symbol("I") b = Beam(3, E, I) R, M = symbols("R, M") b.apply_load(R, 0, -1) b.apply_load(M, 0, -2) b.apply_load(2, 3, -1) b.apply_load(4, 2, -1) b.apply_load(2, 2, 0, end=3) b.solve_for_reaction_loads(R, M) assert b.max_shear_force() == (Interval(0, 2), 8) l = symbols("l", positive=True) P = Symbol("P") b = Beam(l, E, I) R1, R2 = symbols("R1, R2") b.apply_load(R1, 0, -1) b.apply_load(R2, l, -1) b.apply_load(P, 0, 0, end=l) b.solve_for_reaction_loads(R1, R2) assert b.max_shear_force() == (0, l * Abs(P) / 2)