Initial import: grid-bot — grid trading bot for BTC-USDT on Cifra Markets
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
from sympy.physics.continuum_mechanics.arch import Arch
|
||||
from sympy import Symbol, simplify
|
||||
|
||||
x = Symbol('x')
|
||||
t = Symbol('t')
|
||||
|
||||
def test_arch_init():
|
||||
a = Arch((0,0),(10,0),crown_x=5,crown_y=5)
|
||||
assert a.get_loads == {'distributed': {}, 'concentrated': {}}
|
||||
assert a.reaction_force == {Symbol('R_A_x'):0, Symbol('R_A_y'):0, Symbol('R_B_x'):0, Symbol('R_B_y'):0}
|
||||
assert a.supports == {'left':'hinge', 'right':'hinge'}
|
||||
assert a.left_support == (0,0)
|
||||
assert a.right_support == (10,0)
|
||||
assert a.get_shape_eqn == 5 - ((x-5)**2)/5
|
||||
|
||||
a = Arch((0,0),(10,1),crown_x=6)
|
||||
a.change_support_type(left_support='roller')
|
||||
a.add_member(0.5)
|
||||
assert a.supports == {'left':'roller', 'right':'hinge'}
|
||||
assert simplify(a.get_shape_eqn) == simplify(9/5 - (x - 6)**2/20)
|
||||
|
||||
def test_arch_support():
|
||||
a = Arch((0,0),(40,0),crown_x=20,crown_y=12)
|
||||
a.apply_load(-1,'C',8,150,angle=270)
|
||||
a.apply_load(0,'D',start=20,end=40,mag=-4)
|
||||
a.solve()
|
||||
assert abs(a.reaction_force[Symbol("R_A_x")] - 83.33333333333333) < 10e-12
|
||||
assert abs(a.reaction_force[Symbol("R_B_y")] - 90.00000000000000) < 10e-12
|
||||
assert abs(a.reaction_force[Symbol("R_B_x")] + 83.33333333333333) < 10e-12
|
||||
assert abs(a.reaction_force[Symbol("R_A_y")] - 140.00000000000000) < 10e-12
|
||||
|
||||
def test_arch_member():
|
||||
a = Arch((0,0),(40,0),crown_x=20,crown_y=15)
|
||||
a.change_support_type(right_support='roller')
|
||||
a.add_member(0)
|
||||
a.apply_load(-1,'D',start=12,mag=3,angle=270)
|
||||
a.apply_load(-1,'E',start=6,mag=4,angle=270)
|
||||
a.apply_load(-1,'C',start=30,mag=5,angle=270)
|
||||
a.solve()
|
||||
assert a.reaction_force[Symbol("R_A_x")] == 0
|
||||
assert abs(a.reaction_force[Symbol("R_A_y")] - 6.750000000000000) < 10e-12
|
||||
assert a.reaction_force[Symbol("R_B_x")] == 0
|
||||
assert abs(a.reaction_force[Symbol("R_B_y")] - 5.250000000000000) < 10e-12
|
||||
|
||||
def test_symbol_magnitude():
|
||||
a = Arch((0,0),(16,0),crown_x=8,crown_y=5)
|
||||
a.apply_load(0,'C',start=3,end=5,mag=t)
|
||||
a.solve()
|
||||
assert a.reaction_force[Symbol("R_A_x")] == -(4*t)/5
|
||||
assert a.reaction_force[Symbol("R_A_y")] == -(3*t)/2
|
||||
assert a.reaction_force[Symbol("R_B_x")] == (4*t)/5
|
||||
assert a.reaction_force[Symbol("R_B_y")] == -t/2
|
||||
assert a.bending_moment_at(4) == -5*t/2
|
||||
|
||||
def test_forces():
|
||||
a = Arch((0,0),(40,0),crown_x=20,crown_y=12)
|
||||
a.apply_load(-1,'C',8,150,angle=270)
|
||||
a.apply_load(0,'D',start=20,end=40,mag=-4)
|
||||
a.solve()
|
||||
assert abs(a.axial_force_at(7.999999999999999)-149.430523405935) < 1e-12
|
||||
assert abs(a.shear_force_at(7.999999999999999)-64.9227473161196) < 1e-12
|
||||
+1118
File diff suppressed because it is too large
Load Diff
+83
@@ -0,0 +1,83 @@
|
||||
from sympy.physics.continuum_mechanics.cable import Cable
|
||||
from sympy.core.symbol import Symbol
|
||||
|
||||
|
||||
def test_cable():
|
||||
c = Cable(('A', 0, 10), ('B', 10, 10))
|
||||
assert c.supports == {'A': [0, 10], 'B': [10, 10]}
|
||||
assert c.left_support == [0, 10]
|
||||
assert c.right_support == [10, 10]
|
||||
assert c.loads == {'distributed': {}, 'point_load': {}}
|
||||
assert c.loads_position == {}
|
||||
assert c.length == 0
|
||||
assert c.reaction_loads == {Symbol("R_A_x"): 0, Symbol("R_A_y"): 0, Symbol("R_B_x"): 0, Symbol("R_B_y"): 0}
|
||||
|
||||
# tests for change_support method
|
||||
c.change_support('A', ('C', 12, 3))
|
||||
assert c.supports == {'B': [10, 10], 'C': [12, 3]}
|
||||
assert c.left_support == [10, 10]
|
||||
assert c.right_support == [12, 3]
|
||||
assert c.reaction_loads == {Symbol("R_B_x"): 0, Symbol("R_B_y"): 0, Symbol("R_C_x"): 0, Symbol("R_C_y"): 0}
|
||||
|
||||
c.change_support('C', ('A', 0, 10))
|
||||
|
||||
# tests for apply_load method for point loads
|
||||
c.apply_load(-1, ('X', 2, 5, 3, 30))
|
||||
c.apply_load(-1, ('Y', 5, 8, 5, 60))
|
||||
assert c.loads == {'distributed': {}, 'point_load': {'X': [3, 30], 'Y': [5, 60]}}
|
||||
assert c.loads_position == {'X': [2, 5], 'Y': [5, 8]}
|
||||
assert c.length == 0
|
||||
assert c.reaction_loads == {Symbol("R_A_x"): 0, Symbol("R_A_y"): 0, Symbol("R_B_x"): 0, Symbol("R_B_y"): 0}
|
||||
|
||||
# tests for remove_loads method
|
||||
c.remove_loads('X')
|
||||
assert c.loads == {'distributed': {}, 'point_load': {'Y': [5, 60]}}
|
||||
assert c.loads_position == {'Y': [5, 8]}
|
||||
assert c.length == 0
|
||||
assert c.reaction_loads == {Symbol("R_A_x"): 0, Symbol("R_A_y"): 0, Symbol("R_B_x"): 0, Symbol("R_B_y"): 0}
|
||||
|
||||
c.remove_loads('Y')
|
||||
|
||||
#tests for apply_load method for distributed load
|
||||
c.apply_load(0, ('Z', 9))
|
||||
assert c.loads == {'distributed': {'Z': 9}, 'point_load': {}}
|
||||
assert c.loads_position == {}
|
||||
assert c.length == 0
|
||||
assert c.reaction_loads == {Symbol("R_A_x"): 0, Symbol("R_A_y"): 0, Symbol("R_B_x"): 0, Symbol("R_B_y"): 0}
|
||||
|
||||
# tests for apply_length method
|
||||
c.apply_length(20)
|
||||
assert c.length == 20
|
||||
|
||||
del c
|
||||
# tests for solve method
|
||||
# for point loads
|
||||
c = Cable(("A", 0, 10), ("B", 5.5, 8))
|
||||
c.apply_load(-1, ('Z', 2, 7.26, 3, 270))
|
||||
c.apply_load(-1, ('X', 4, 6, 8, 270))
|
||||
c.solve()
|
||||
#assert c.tension == {Symbol("Z_X"): 4.79150773600774, Symbol("X_B"): 6.78571428571429, Symbol("A_Z"): 6.89488895397307}
|
||||
assert abs(c.tension[Symbol("A_Z")] - 6.89488895397307) < 10e-12
|
||||
assert abs(c.tension[Symbol("Z_X")] - 4.79150773600774) < 10e-12
|
||||
assert abs(c.tension[Symbol("X_B")] - 6.78571428571429) < 10e-12
|
||||
#assert c.reaction_loads == {Symbol("R_A_x"): -4.06504065040650, Symbol("R_A_y"): 5.56910569105691, Symbol("R_B_x"): 4.06504065040650, Symbol("R_B_y"): 5.43089430894309}
|
||||
assert abs(c.reaction_loads[Symbol("R_A_x")] + 4.06504065040650) < 10e-12
|
||||
assert abs(c.reaction_loads[Symbol("R_A_y")] - 5.56910569105691) < 10e-12
|
||||
assert abs(c.reaction_loads[Symbol("R_B_x")] - 4.06504065040650) < 10e-12
|
||||
assert abs(c.reaction_loads[Symbol("R_B_y")] - 5.43089430894309) < 10e-12
|
||||
assert abs(c.length - 8.25609584845190) < 10e-12
|
||||
|
||||
del c
|
||||
# tests for solve method
|
||||
# for distributed loads
|
||||
c=Cable(("A", 0, 40),("B", 100, 20))
|
||||
c.apply_load(0, ("X", 850))
|
||||
c.solve(58.58, 0)
|
||||
|
||||
# assert c.tension['distributed'] == 36456.8485*sqrt(0.000543529004799705*(X + 0.00135624381275735)**2 + 1)
|
||||
assert abs(c.tension_at(0) - 61717.4130533677) < 10e-11
|
||||
assert abs(c.tension_at(40) - 39738.0809048449) < 10e-11
|
||||
assert abs(c.reaction_loads[Symbol("R_A_x")] - 36465.0000000000) < 10e-11
|
||||
assert abs(c.reaction_loads[Symbol("R_A_y")] + 49793.0000000000) < 10e-11
|
||||
assert abs(c.reaction_loads[Symbol("R_B_x")] - 44399.9537590861) < 10e-11
|
||||
assert abs(c.reaction_loads[Symbol("R_B_y")] - 42868.2071025955 ) < 10e-11
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
from sympy.core.symbol import Symbol, symbols
|
||||
from sympy.physics.continuum_mechanics.truss import Truss
|
||||
from sympy import sqrt
|
||||
|
||||
|
||||
def test_truss():
|
||||
A = Symbol('A')
|
||||
B = Symbol('B')
|
||||
C = Symbol('C')
|
||||
AB, BC, AC = symbols('AB, BC, AC')
|
||||
P = Symbol('P')
|
||||
|
||||
t = Truss()
|
||||
assert t.nodes == []
|
||||
assert t.node_labels == []
|
||||
assert t.node_positions == []
|
||||
assert t.members == {}
|
||||
assert t.loads == {}
|
||||
assert t.supports == {}
|
||||
assert t.reaction_loads == {}
|
||||
assert t.internal_forces == {}
|
||||
|
||||
# testing the add_node method
|
||||
t.add_node((A, 0, 0), (B, 2, 2), (C, 3, 0))
|
||||
assert t.nodes == [(A, 0, 0), (B, 2, 2), (C, 3, 0)]
|
||||
assert t.node_labels == [A, B, C]
|
||||
assert t.node_positions == [(0, 0), (2, 2), (3, 0)]
|
||||
assert t.loads == {}
|
||||
assert t.supports == {}
|
||||
assert t.reaction_loads == {}
|
||||
|
||||
# testing the remove_node method
|
||||
t.remove_node(C)
|
||||
assert t.nodes == [(A, 0, 0), (B, 2, 2)]
|
||||
assert t.node_labels == [A, B]
|
||||
assert t.node_positions == [(0, 0), (2, 2)]
|
||||
assert t.loads == {}
|
||||
assert t.supports == {}
|
||||
|
||||
t.add_node((C, 3, 0))
|
||||
|
||||
# testing the add_member method
|
||||
t.add_member((AB, A, B), (BC, B, C), (AC, A, C))
|
||||
assert t.members == {AB: [A, B], BC: [B, C], AC: [A, C]}
|
||||
assert t.internal_forces == {AB: 0, BC: 0, AC: 0}
|
||||
|
||||
# testing the remove_member method
|
||||
t.remove_member(BC)
|
||||
assert t.members == {AB: [A, B], AC: [A, C]}
|
||||
assert t.internal_forces == {AB: 0, AC: 0}
|
||||
|
||||
t.add_member((BC, B, C))
|
||||
|
||||
D, CD = symbols('D, CD')
|
||||
|
||||
# testing the change_label methods
|
||||
t.change_node_label((B, D))
|
||||
assert t.nodes == [(A, 0, 0), (D, 2, 2), (C, 3, 0)]
|
||||
assert t.node_labels == [A, D, C]
|
||||
assert t.loads == {}
|
||||
assert t.supports == {}
|
||||
assert t.members == {AB: [A, D], BC: [D, C], AC: [A, C]}
|
||||
|
||||
t.change_member_label((BC, CD))
|
||||
assert t.members == {AB: [A, D], CD: [D, C], AC: [A, C]}
|
||||
assert t.internal_forces == {AB: 0, CD: 0, AC: 0}
|
||||
|
||||
|
||||
# testing the apply_load method
|
||||
t.apply_load((A, P, 90), (A, P/4, 90), (A, 2*P,45), (D, P/2, 90))
|
||||
assert t.loads == {A: [[P, 90], [P/4, 90], [2*P, 45]], D: [[P/2, 90]]}
|
||||
assert t.loads[A] == [[P, 90], [P/4, 90], [2*P, 45]]
|
||||
|
||||
# testing the remove_load method
|
||||
t.remove_load((A, P/4, 90))
|
||||
assert t.loads == {A: [[P, 90], [2*P, 45]], D: [[P/2, 90]]}
|
||||
assert t.loads[A] == [[P, 90], [2*P, 45]]
|
||||
|
||||
# testing the apply_support method
|
||||
t.apply_support((A, "pinned"), (D, "roller"))
|
||||
assert t.supports == {A: 'pinned', D: 'roller'}
|
||||
assert t.reaction_loads == {}
|
||||
assert t.loads == {A: [[P, 90], [2*P, 45], [Symbol('R_A_x'), 0], [Symbol('R_A_y'), 90]], D: [[P/2, 90], [Symbol('R_D_y'), 90]]}
|
||||
|
||||
# testing the remove_support method
|
||||
t.remove_support(A)
|
||||
assert t.supports == {D: 'roller'}
|
||||
assert t.reaction_loads == {}
|
||||
assert t.loads == {A: [[P, 90], [2*P, 45]], D: [[P/2, 90], [Symbol('R_D_y'), 90]]}
|
||||
|
||||
t.apply_support((A, "pinned"))
|
||||
|
||||
# testing the solve method
|
||||
t.solve()
|
||||
assert t.reaction_loads['R_A_x'] == -sqrt(2)*P
|
||||
assert t.reaction_loads['R_A_y'] == -sqrt(2)*P - P
|
||||
assert t.reaction_loads['R_D_y'] == -P/2
|
||||
assert t.internal_forces[AB]/P == 0
|
||||
assert t.internal_forces[CD] == 0
|
||||
assert t.internal_forces[AC] == 0
|
||||
Reference in New Issue
Block a user