I am done

This commit is contained in:
2024-10-30 22:14:35 +01:00
parent 720dc28c09
commit 40e2a747cf
36901 changed files with 5011519 additions and 0 deletions

View File

@ -0,0 +1,6 @@
__all__ = ['Beam',
'Truss', 'Cable']
from .beam import Beam
from .truss import Truss
from .cable import Cable

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,587 @@
"""
This module can be used to solve problems related
to 2D Cables.
"""
from sympy.core.sympify import sympify
from sympy.core.symbol import Symbol
from sympy import sin, cos, pi, atan, diff
from sympy.functions.elementary.miscellaneous import sqrt
from sympy.solvers.solveset import linsolve
from sympy.matrices import Matrix
class Cable:
"""
Cables are structures in engineering that support
the applied transverse loads through the tensile
resistance developed in its members.
Cables are widely used in suspension bridges, tension
leg offshore platforms, transmission lines, and find
use in several other engineering applications.
Examples
========
A cable is supported at (0, 10) and (10, 10). Two point loads
acting vertically downwards act on the cable, one with magnitude 3 kN
and acting 2 meters from the left support and 3 meters below it, while
the other with magnitude 2 kN is 6 meters from the left support and
6 meters below it.
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.apply_load(-1, ('P', 2, 7, 3, 270))
>>> c.apply_load(-1, ('Q', 6, 4, 2, 270))
>>> c.loads
{'distributed': {}, 'point_load': {'P': [3, 270], 'Q': [2, 270]}}
>>> c.loads_position
{'P': [2, 7], 'Q': [6, 4]}
"""
def __init__(self, support_1, support_2):
"""
Initializes the class.
Parameters
==========
support_1 and support_2 are tuples of the form
(label, x, y), where
label : String or symbol
The label of the support
x : Sympifyable
The x coordinate of the position of the support
y : Sympifyable
The y coordinate of the position of the support
"""
self._left_support = []
self._right_support = []
self._supports = {}
self._support_labels = []
self._loads = {"distributed": {}, "point_load": {}}
self._loads_position = {}
self._length = 0
self._reaction_loads = {}
self._tension = {}
self._lowest_x_global = sympify(0)
if support_1[0] == support_2[0]:
raise ValueError("Supports can not have the same label")
elif support_1[1] == support_2[1]:
raise ValueError("Supports can not be at the same location")
x1 = sympify(support_1[1])
y1 = sympify(support_1[2])
self._supports[support_1[0]] = [x1, y1]
x2 = sympify(support_2[1])
y2 = sympify(support_2[2])
self._supports[support_2[0]] = [x2, y2]
if support_1[1] < support_2[1]:
self._left_support.append(x1)
self._left_support.append(y1)
self._right_support.append(x2)
self._right_support.append(y2)
self._support_labels.append(support_1[0])
self._support_labels.append(support_2[0])
else:
self._left_support.append(x2)
self._left_support.append(y2)
self._right_support.append(x1)
self._right_support.append(y1)
self._support_labels.append(support_2[0])
self._support_labels.append(support_1[0])
for i in self._support_labels:
self._reaction_loads[Symbol("R_"+ i +"_x")] = 0
self._reaction_loads[Symbol("R_"+ i +"_y")] = 0
@property
def supports(self):
"""
Returns the supports of the cable along with their
positions.
"""
return self._supports
@property
def left_support(self):
"""
Returns the position of the left support.
"""
return self._left_support
@property
def right_support(self):
"""
Returns the position of the right support.
"""
return self._right_support
@property
def loads(self):
"""
Returns the magnitude and direction of the loads
acting on the cable.
"""
return self._loads
@property
def loads_position(self):
"""
Returns the position of the point loads acting on the
cable.
"""
return self._loads_position
@property
def length(self):
"""
Returns the length of the cable.
"""
return self._length
@property
def reaction_loads(self):
"""
Returns the reaction forces at the supports, which are
initialized to 0.
"""
return self._reaction_loads
@property
def tension(self):
"""
Returns the tension developed in the cable due to the loads
applied.
"""
return self._tension
def tension_at(self, x):
"""
Returns the tension at a given value of x developed due to
distributed load.
"""
if 'distributed' not in self._tension.keys():
raise ValueError("No distributed load added or solve method not called")
if x > self._right_support[0] or x < self._left_support[0]:
raise ValueError("The value of x should be between the two supports")
A = self._tension['distributed']
X = Symbol('X')
return A.subs({X:(x-self._lowest_x_global)})
def apply_length(self, length):
"""
This method specifies the length of the cable
Parameters
==========
length : Sympifyable
The length of the cable
Examples
========
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.apply_length(20)
>>> c.length
20
"""
dist = ((self._left_support[0] - self._right_support[0])**2
- (self._left_support[1] - self._right_support[1])**2)**(1/2)
if length < dist:
raise ValueError("length should not be less than the distance between the supports")
self._length = length
def change_support(self, label, new_support):
"""
This method changes the mentioned support with a new support.
Parameters
==========
label: String or symbol
The label of the support to be changed
new_support: Tuple of the form (new_label, x, y)
new_label: String or symbol
The label of the new support
x: Sympifyable
The x-coordinate of the position of the new support.
y: Sympifyable
The y-coordinate of the position of the new support.
Examples
========
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.supports
{'A': [0, 10], 'B': [10, 10]}
>>> c.change_support('B', ('C', 5, 6))
>>> c.supports
{'A': [0, 10], 'C': [5, 6]}
"""
if label not in self._supports:
raise ValueError("No support exists with the given label")
i = self._support_labels.index(label)
rem_label = self._support_labels[(i+1)%2]
x1 = self._supports[rem_label][0]
y1 = self._supports[rem_label][1]
x = sympify(new_support[1])
y = sympify(new_support[2])
for l in self._loads_position:
if l[0] >= max(x, x1) or l[0] <= min(x, x1):
raise ValueError("The change in support will throw an existing load out of range")
self._supports.pop(label)
self._left_support.clear()
self._right_support.clear()
self._reaction_loads.clear()
self._support_labels.remove(label)
self._supports[new_support[0]] = [x, y]
if x1 < x:
self._left_support.append(x1)
self._left_support.append(y1)
self._right_support.append(x)
self._right_support.append(y)
self._support_labels.append(new_support[0])
else:
self._left_support.append(x)
self._left_support.append(y)
self._right_support.append(x1)
self._right_support.append(y1)
self._support_labels.insert(0, new_support[0])
for i in self._support_labels:
self._reaction_loads[Symbol("R_"+ i +"_x")] = 0
self._reaction_loads[Symbol("R_"+ i +"_y")] = 0
def apply_load(self, order, load):
"""
This method adds load to the cable.
Parameters
==========
order : Integer
The order of the applied load.
- For point loads, order = -1
- For distributed load, order = 0
load : tuple
* For point loads, load is of the form (label, x, y, magnitude, direction), where:
label : String or symbol
The label of the load
x : Sympifyable
The x coordinate of the position of the load
y : Sympifyable
The y coordinate of the position of the load
magnitude : Sympifyable
The magnitude of the load. It must always be positive
direction : Sympifyable
The angle, in degrees, that the load vector makes with the horizontal
in the counter-clockwise direction. It takes the values 0 to 360,
inclusive.
* For uniformly distributed load, load is of the form (label, magnitude)
label : String or symbol
The label of the load
magnitude : Sympifyable
The magnitude of the load. It must always be positive
Examples
========
For a point load of magnitude 12 units inclined at 30 degrees with the horizontal:
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.apply_load(-1, ('Z', 5, 5, 12, 30))
>>> c.loads
{'distributed': {}, 'point_load': {'Z': [12, 30]}}
>>> c.loads_position
{'Z': [5, 5]}
For a uniformly distributed load of magnitude 9 units:
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.apply_load(0, ('X', 9))
>>> c.loads
{'distributed': {'X': 9}, 'point_load': {}}
"""
if order == -1:
if len(self._loads["distributed"]) != 0:
raise ValueError("Distributed load already exists")
label = load[0]
if label in self._loads["point_load"]:
raise ValueError("Label already exists")
x = sympify(load[1])
y = sympify(load[2])
if x > self._right_support[0] or x < self._left_support[0]:
raise ValueError("The load should be positioned between the supports")
magnitude = sympify(load[3])
direction = sympify(load[4])
self._loads["point_load"][label] = [magnitude, direction]
self._loads_position[label] = [x, y]
elif order == 0:
if len(self._loads_position) != 0:
raise ValueError("Point load(s) already exist")
label = load[0]
if label in self._loads["distributed"]:
raise ValueError("Label already exists")
magnitude = sympify(load[1])
self._loads["distributed"][label] = magnitude
else:
raise ValueError("Order should be either -1 or 0")
def remove_loads(self, *args):
"""
This methods removes the specified loads.
Parameters
==========
This input takes multiple label(s) as input
label(s): String or symbol
The label(s) of the loads to be removed.
Examples
========
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(('A', 0, 10), ('B', 10, 10))
>>> c.apply_load(-1, ('Z', 5, 5, 12, 30))
>>> c.loads
{'distributed': {}, 'point_load': {'Z': [12, 30]}}
>>> c.remove_loads('Z')
>>> c.loads
{'distributed': {}, 'point_load': {}}
"""
for i in args:
if len(self._loads_position) == 0:
if i not in self._loads['distributed']:
raise ValueError("Error removing load " + i + ": no such load exists")
else:
self._loads['disrtibuted'].pop(i)
else:
if i not in self._loads['point_load']:
raise ValueError("Error removing load " + i + ": no such load exists")
else:
self._loads['point_load'].pop(i)
self._loads_position.pop(i)
def solve(self, *args):
"""
This method solves for the reaction forces at the supports, the tension developed in
the cable, and updates the length of the cable.
Parameters
==========
This method requires no input when solving for point loads
For distributed load, the x and y coordinates of the lowest point of the cable are
required as
x: Sympifyable
The x coordinate of the lowest point
y: Sympifyable
The y coordinate of the lowest point
Examples
========
For point loads,
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c = Cable(("A", 0, 10), ("B", 10, 10))
>>> c.apply_load(-1, ('Z', 2, 7.26, 3, 270))
>>> c.apply_load(-1, ('X', 4, 6, 8, 270))
>>> c.solve()
>>> c.tension
{A_Z: 8.91403453669861, X_B: 19*sqrt(13)/10, Z_X: 4.79150773600774}
>>> c.reaction_loads
{R_A_x: -5.25547445255474, R_A_y: 7.2, R_B_x: 5.25547445255474, R_B_y: 3.8}
>>> c.length
5.7560958484519 + 2*sqrt(13)
For distributed load,
>>> from sympy.physics.continuum_mechanics.cable import Cable
>>> c=Cable(("A", 0, 40),("B", 100, 20))
>>> c.apply_load(0, ("X", 850))
>>> c.solve(58.58, 0)
>>> c.tension
{'distributed': 36456.8485*sqrt(0.000543529004799705*(X + 0.00135624381275735)**2 + 1)}
>>> c.tension_at(0)
61709.0363315913
>>> c.reaction_loads
{R_A_x: 36456.8485, R_A_y: -49788.5866682485, R_B_x: 44389.8401587246, R_B_y: 42866.621696333}
"""
if len(self._loads_position) != 0:
sorted_position = sorted(self._loads_position.items(), key = lambda item : item[1][0])
sorted_position.append(self._support_labels[1])
sorted_position.insert(0, self._support_labels[0])
self._tension.clear()
moment_sum_from_left_support = 0
moment_sum_from_right_support = 0
F_x = 0
F_y = 0
self._length = 0
for i in range(1, len(sorted_position)-1):
if i == 1:
self._length+=sqrt((self._left_support[0] - self._loads_position[sorted_position[i][0]][0])**2 + (self._left_support[1] - self._loads_position[sorted_position[i][0]][1])**2)
else:
self._length+=sqrt((self._loads_position[sorted_position[i-1][0]][0] - self._loads_position[sorted_position[i][0]][0])**2 + (self._loads_position[sorted_position[i-1][0]][1] - self._loads_position[sorted_position[i][0]][1])**2)
if i == len(sorted_position)-2:
self._length+=sqrt((self._right_support[0] - self._loads_position[sorted_position[i][0]][0])**2 + (self._right_support[1] - self._loads_position[sorted_position[i][0]][1])**2)
moment_sum_from_left_support += self._loads['point_load'][sorted_position[i][0]][0] * cos(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180) * abs(self._left_support[1] - self._loads_position[sorted_position[i][0]][1])
moment_sum_from_left_support += self._loads['point_load'][sorted_position[i][0]][0] * sin(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180) * abs(self._left_support[0] - self._loads_position[sorted_position[i][0]][0])
F_x += self._loads['point_load'][sorted_position[i][0]][0] * cos(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180)
F_y += self._loads['point_load'][sorted_position[i][0]][0] * sin(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180)
label = Symbol(sorted_position[i][0]+"_"+sorted_position[i+1][0])
y2 = self._loads_position[sorted_position[i][0]][1]
x2 = self._loads_position[sorted_position[i][0]][0]
y1 = 0
x1 = 0
if i == len(sorted_position)-2:
x1 = self._right_support[0]
y1 = self._right_support[1]
else:
x1 = self._loads_position[sorted_position[i+1][0]][0]
y1 = self._loads_position[sorted_position[i+1][0]][1]
angle_with_horizontal = atan((y1 - y2)/(x1 - x2))
tension = -(moment_sum_from_left_support)/(abs(self._left_support[1] - self._loads_position[sorted_position[i][0]][1])*cos(angle_with_horizontal) + abs(self._left_support[0] - self._loads_position[sorted_position[i][0]][0])*sin(angle_with_horizontal))
self._tension[label] = tension
moment_sum_from_right_support += self._loads['point_load'][sorted_position[i][0]][0] * cos(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180) * abs(self._right_support[1] - self._loads_position[sorted_position[i][0]][1])
moment_sum_from_right_support += self._loads['point_load'][sorted_position[i][0]][0] * sin(pi * self._loads['point_load'][sorted_position[i][0]][1] / 180) * abs(self._right_support[0] - self._loads_position[sorted_position[i][0]][0])
label = Symbol(sorted_position[0][0]+"_"+sorted_position[1][0])
y2 = self._loads_position[sorted_position[1][0]][1]
x2 = self._loads_position[sorted_position[1][0]][0]
x1 = self._left_support[0]
y1 = self._left_support[1]
angle_with_horizontal = -atan((y2 - y1)/(x2 - x1))
tension = -(moment_sum_from_right_support)/(abs(self._right_support[1] - self._loads_position[sorted_position[1][0]][1])*cos(angle_with_horizontal) + abs(self._right_support[0] - self._loads_position[sorted_position[1][0]][0])*sin(angle_with_horizontal))
self._tension[label] = tension
angle_with_horizontal = pi/2 - angle_with_horizontal
label = self._support_labels[0]
self._reaction_loads[Symbol("R_"+label+"_x")] = -sin(angle_with_horizontal) * tension
F_x += -sin(angle_with_horizontal) * tension
self._reaction_loads[Symbol("R_"+label+"_y")] = cos(angle_with_horizontal) * tension
F_y += cos(angle_with_horizontal) * tension
label = self._support_labels[1]
self._reaction_loads[Symbol("R_"+label+"_x")] = -F_x
self._reaction_loads[Symbol("R_"+label+"_y")] = -F_y
elif len(self._loads['distributed']) != 0 :
if len(args) == 0:
raise ValueError("Provide the lowest point of the cable")
lowest_x = sympify(args[0])
lowest_y = sympify(args[1])
self._lowest_x_global = lowest_x
a = Symbol('a')
b = Symbol('b')
c = Symbol('c')
# augmented matrix form of linsolve
M = Matrix(
[[self._left_support[0]**2, self._left_support[0], 1, self._left_support[1]],
[self._right_support[0]**2, self._right_support[0], 1, self._right_support[1]],
[lowest_x**2, lowest_x, 1, lowest_y] ]
)
coefficient_solution = list(linsolve(M, (a, b, c)))
if len(coefficient_solution) == 0:
raise ValueError("The lowest point is inconsistent with the supports")
A = coefficient_solution[0][0]
B = coefficient_solution[0][1]
C = coefficient_solution[0][2]
# y = A*x**2 + B*x + C
# shifting origin to lowest point
X = Symbol('X')
Y = Symbol('Y')
Y = A*(X + lowest_x)**2 + B*(X + lowest_x) + C - lowest_y
temp_list = list(self._loads['distributed'].values())
applied_force = temp_list[0]
horizontal_force_constant = (applied_force * (self._right_support[0] - lowest_x)**2) / (2 * (self._right_support[1] - lowest_y))
self._tension.clear()
tangent_slope_to_curve = diff(Y, X)
self._tension['distributed'] = horizontal_force_constant / (cos(atan(tangent_slope_to_curve)))
label = self._support_labels[0]
self._reaction_loads[Symbol("R_"+label+"_x")] = self.tension_at(self._left_support[0]) * cos(atan(tangent_slope_to_curve.subs(X, self._left_support[0] - lowest_x)))
self._reaction_loads[Symbol("R_"+label+"_y")] = self.tension_at(self._left_support[0]) * sin(atan(tangent_slope_to_curve.subs(X, self._left_support[0] - lowest_x)))
label = self._support_labels[1]
self._reaction_loads[Symbol("R_"+label+"_x")] = self.tension_at(self._left_support[0]) * cos(atan(tangent_slope_to_curve.subs(X, self._right_support[0] - lowest_x)))
self._reaction_loads[Symbol("R_"+label+"_y")] = self.tension_at(self._left_support[0]) * sin(atan(tangent_slope_to_curve.subs(X, self._right_support[0] - lowest_x)))

View File

@ -0,0 +1,802 @@
from sympy.core.function import expand
from sympy.core.numbers import (Rational, pi)
from sympy.core.singleton import S
from sympy.core.symbol import (Symbol, symbols)
from sympy.sets.sets import Interval
from sympy.simplify.simplify import simplify
from sympy.physics.continuum_mechanics.beam import Beam
from sympy.functions import SingularityFunction, Piecewise, meijerg, Abs, log
from sympy.testing.pytest import raises
from sympy.physics.units import meter, newton, kilo, giga, milli
from sympy.physics.continuum_mechanics.beam import Beam3D
from sympy.geometry import Circle, Polygon, Point2D, Triangle
from sympy.core.sympify import sympify
x = Symbol('x')
y = Symbol('y')
R1, R2 = symbols('R1, R2')
def test_Beam():
E = Symbol('E')
E_1 = Symbol('E_1')
I = Symbol('I')
I_1 = Symbol('I_1')
A = Symbol('A')
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 shear stress distribution function
p = b1.shear_stress()
q = (8*SingularityFunction(x, 0, 0) - 6*SingularityFunction(x, 10, 0) \
- 120*SingularityFunction(x, 30, -1) \
- 2*SingularityFunction(x, 30, 0))/A
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) \
+ Rational(4000, 3)
assert p == q/(E*I)
# Test for deflection distribution function
p = b1.deflection()
q = 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
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 shear stress distribution function
p = b2.shear_stress()
q = (-w0*SingularityFunction(x, a1, 2)/2 \
- w2*SingularityFunction(x, c1, 0))/A
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 expand(p) == expand(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 simplify(p - q) == 0
b3 = Beam(9, E, I, 2)
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.shear_force()
q = 2*SingularityFunction(x, 2, 3)/3 - 2*SingularityFunction(x, 3, 1) \
- 2*SingularityFunction(x, 3, 2) - 2*SingularityFunction(x, 3, 3)/3
assert p == q
p = b3.shear_stress()
q = SingularityFunction(x, 2, 3)/3 - 1*SingularityFunction(x, 3, 1) \
- 1*SingularityFunction(x, 3, 2) - 1*SingularityFunction(x, 3, 3)/3
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, 3)
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.shear_force()
q = 3*SingularityFunction(x, 0, 1) \
- 3*SingularityFunction(x, 3, 1)
assert p == q
p = b4.shear_stress()
q = SingularityFunction(x, 0, 1) - SingularityFunction(x, 3, 1)
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_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)
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_beam_units():
E = Symbol('E')
I = Symbol('I')
R1, R2 = symbols('R1, R2')
kN = kilo*newton
gN = giga*newton
b = Beam(8*meter, 200*gN/meter**2, 400*1000000*(milli*meter)**4)
b.apply_load(5*kN, 2*meter, -1)
b.apply_load(R1, 0*meter, -1)
b.apply_load(R2, 8*meter, -1)
b.apply_load(10*kN/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*kN, 1*meter, -1)
b.apply_load(R1, 0*meter, -1)
b.apply_load(R2, 3*meter, -1)
b.apply_load(12*kN*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: newton*Rational(-28000, 3), R2: newton*Rational(4000, 3)}
assert b.deflection().subs(x, 1*meter) == 62000*meter/(9*E*I)
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), (x**2*meijerg(((-1, 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_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: P*Rational(-5, 4), M1: -P*l/4, R1: P*Rational(3, 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_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() == [Rational(10, 3)]
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_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 simplify(b.slope()) == simplify((80*SingularityFunction(x, 0, 1) - 10*SingularityFunction(x, 0, 2)
+ 10*SingularityFunction(x, 4, 2))/(E*I))
assert simplify(b.deflection()) == simplify((40*SingularityFunction(x, 0, 2) - 10*SingularityFunction(x, 0, 3)/3
+ 10*SingularityFunction(x, 4, 3)/3)/(E*I))
b = Beam(30, E, I)
p0 = b.apply_support(10, "pin")
p1 = b.apply_support(30, "roller")
b.apply_load(-8, 0, -1)
b.apply_load(120, 30, -2)
b.solve_for_reaction_loads(p0, p1)
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)
R_10 = Symbol('R_10')
R_30 = Symbol('R_30')
assert p0 == R_10
assert b.reaction_loads == {R_10: 6, R_30: 2}
assert b.reaction_loads[p0] == 6
b = Beam(8, E, I)
p0, m0 = b.apply_support(0, "fixed")
p1 = b.apply_support(8, "roller")
b.apply_load(-5, 0, 0, 8)
b.solve_for_reaction_loads(p0, m0, p1)
R_0 = Symbol('R_0')
M_0 = Symbol('M_0')
R_8 = Symbol('R_8')
assert p0 == R_0
assert m0 == M_0
assert p1 == R_8
assert b.reaction_loads == {R_0: 25, M_0: -40, R_8: 15}
assert b.reaction_loads[m0] == -40
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_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)
max_shear = b.max_shear_force()
assert max_shear[0] == 0
assert simplify(max_shear[1] - (l*Abs(P)/2)) == 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 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_Beam3D():
l, E, G, I, A = symbols('l, E, G, I, A')
R1, R2, R3, R4 = symbols('R1, R2, R3, R4')
b = Beam3D(l, E, G, I, A)
m, q = symbols('m, q')
b.apply_load(q, 0, 0, dir="y")
b.apply_moment_load(m, 0, 0, dir="z")
b.bc_slope = [(0, [0, 0, 0]), (l, [0, 0, 0])]
b.bc_deflection = [(0, [0, 0, 0]), (l, [0, 0, 0])]
b.solve_slope_deflection()
assert b.polar_moment() == 2*I
assert b.shear_force() == [0, -q*x, 0]
assert b.shear_stress() == [0, -q*x/A, 0]
assert b.axial_stress() == 0
assert b.bending_moment() == [0, 0, -m*x + q*x**2/2]
expected_deflection = (x*(A*G*q*x**3/4 + A*G*x**2*(-l*(A*G*l*(l*q - 2*m) +
12*E*I*q)/(A*G*l**2 + 12*E*I)/2 - m) + 3*E*I*l*(A*G*l*(l*q - 2*m) +
12*E*I*q)/(A*G*l**2 + 12*E*I) + x*(-A*G*l**2*q/2 +
3*A*G*l**2*(A*G*l*(l*q - 2*m) + 12*E*I*q)/(A*G*l**2 + 12*E*I)/4 +
A*G*l*m*Rational(3, 2) - 3*E*I*q))/(6*A*E*G*I))
dx, dy, dz = b.deflection()
assert dx == dz == 0
assert simplify(dy - expected_deflection) == 0
b2 = Beam3D(30, E, G, I, A, x)
b2.apply_load(50, start=0, order=0, dir="y")
b2.bc_deflection = [(0, [0, 0, 0]), (30, [0, 0, 0])]
b2.apply_load(R1, start=0, order=-1, dir="y")
b2.apply_load(R2, start=30, order=-1, dir="y")
b2.solve_for_reaction_loads(R1, R2)
assert b2.reaction_loads == {R1: -750, R2: -750}
b2.solve_slope_deflection()
assert b2.slope() == [0, 0, 25*x**3/(3*E*I) - 375*x**2/(E*I) + 3750*x/(E*I)]
expected_deflection = 25*x**4/(12*E*I) - 125*x**3/(E*I) + 1875*x**2/(E*I) - \
25*x**2/(A*G) + 750*x/(A*G)
dx, dy, dz = b2.deflection()
assert dx == dz == 0
assert dy == expected_deflection
# Test for solve_for_reaction_loads
b3 = Beam3D(30, E, G, I, A, x)
b3.apply_load(8, start=0, order=0, dir="y")
b3.apply_load(9*x, start=0, order=0, dir="z")
b3.apply_load(R1, start=0, order=-1, dir="y")
b3.apply_load(R2, start=30, order=-1, dir="y")
b3.apply_load(R3, start=0, order=-1, dir="z")
b3.apply_load(R4, start=30, order=-1, dir="z")
b3.solve_for_reaction_loads(R1, R2, R3, R4)
assert b3.reaction_loads == {R1: -120, R2: -120, R3: -1350, R4: -2700}
def test_polar_moment_Beam3D():
l, E, G, A, I1, I2 = symbols('l, E, G, A, I1, I2')
I = [I1, I2]
b = Beam3D(l, E, G, I, A)
assert b.polar_moment() == I1 + I2
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_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)
def test_max_shear_force_Beam3D():
x = symbols('x')
b = Beam3D(20, 40, 21, 100, 25)
b.apply_load(15, start=0, order=0, dir="z")
b.apply_load(12*x, start=0, order=0, dir="y")
b.bc_deflection = [(0, [0, 0, 0]), (20, [0, 0, 0])]
assert b.max_shear_force() == [(0, 0), (20, 2400), (20, 300)]
def test_max_bending_moment_Beam3D():
x = symbols('x')
b = Beam3D(20, 40, 21, 100, 25)
b.apply_load(15, start=0, order=0, dir="z")
b.apply_load(12*x, start=0, order=0, dir="y")
b.bc_deflection = [(0, [0, 0, 0]), (20, [0, 0, 0])]
assert b.max_bmoment() == [(0, 0), (20, 3000), (20, 16000)]
def test_max_deflection_Beam3D():
x = symbols('x')
b = Beam3D(20, 40, 21, 100, 25)
b.apply_load(15, start=0, order=0, dir="z")
b.apply_load(12*x, start=0, order=0, dir="y")
b.bc_deflection = [(0, [0, 0, 0]), (20, [0, 0, 0])]
b.solve_slope_deflection()
c = sympify("495/14")
p = sympify("-10 + 10*sqrt(10793)/43")
q = sympify("(10 - 10*sqrt(10793)/43)**3/160 - 20/7 + (10 - 10*sqrt(10793)/43)**4/6400 + 20*sqrt(10793)/301 + 27*(10 - 10*sqrt(10793)/43)**2/560")
assert b.max_deflection() == [(0, 0), (10, c), (p, q)]
def test_torsion_Beam3D():
x = symbols('x')
b = Beam3D(20, 40, 21, 100, 25)
b.apply_moment_load(15, 5, -2, dir='x')
b.apply_moment_load(25, 10, -2, dir='x')
b.apply_moment_load(-5, 20, -2, dir='x')
b.solve_for_torsion()
assert b.angular_deflection().subs(x, 3) == sympify("1/40")
assert b.angular_deflection().subs(x, 9) == sympify("17/280")
assert b.angular_deflection().subs(x, 12) == sympify("53/840")
assert b.angular_deflection().subs(x, 17) == sympify("2/35")
assert b.angular_deflection().subs(x, 20) == sympify("3/56")

View File

@ -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) - 61709.0363315913) < 10e-11
assert abs(c.tension_at(40) - 39729.7316969361) < 10e-11
assert abs(c.reaction_loads[Symbol("R_A_x")] - 36456.8485000000) < 10e-11
assert abs(c.reaction_loads[Symbol("R_A_y")] + 49788.5866682486) < 10e-11
assert abs(c.reaction_loads[Symbol("R_B_x")] - 44389.8401587246) < 10e-11
assert abs(c.reaction_loads[Symbol("R_B_y")] - 42866.6216963330) < 10e-11

View File

@ -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

File diff suppressed because it is too large Load Diff