Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 91 additions & 4 deletions sympy/physics/continuum_mechanics/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
from sympy import lambdify
from sympy.core.compatibility import iterable

matplotlib = import_module('matplotlib', __import__kwargs={'fromlist':['pyplot']})
numpy = import_module('numpy', __import__kwargs={'fromlist':['linspace']})

__doctest_requires__ = {('Beam.plot_loading_results',): ['matplotlib']}


class Beam(object):
"""
A Beam is a structural element that is capable of withstanding load
Expand Down Expand Up @@ -124,6 +120,8 @@ def __init__(self, length, elastic_modulus, second_moment, variable=Symbol('x'),
self._boundary_conditions = {'deflection': [], 'slope': []}
self._load = 0
self._applied_loads = []
self._applied_supports = []
self._support_as_loads = []
self._reaction_loads = {}
self._composite_type = None
self._hinge_position = None
Expand Down Expand Up @@ -366,6 +364,8 @@ def apply_support(self, loc, type="fixed"):
(-4*SingularityFunction(x, 0, 2) + 3*SingularityFunction(x, 10, 2)
+ 120*SingularityFunction(x, 30, 1) + SingularityFunction(x, 30, 2) + 4000/3)/(E*I)
"""
loc = sympify(loc)
self._applied_supports.append((loc, type))
if type == "pin" or type == "roller":
reaction_load = Symbol('R_'+str(loc))
self.apply_load(reaction_load, loc, -1)
Expand All @@ -377,6 +377,9 @@ def apply_support(self, loc, type="fixed"):
self.apply_load(reaction_moment, loc, -2)
self.bc_deflection.append((loc, 0))
self.bc_slope.append((loc, 0))
self._support_as_loads.append((reaction_moment, loc, -2, None))

self._support_as_loads.append((reaction_load, loc, -1, None))

def apply_load(self, value, start, order, end=None):
"""
Expand Down Expand Up @@ -1521,6 +1524,90 @@ def plot_loading_results(self, subs=None):
return PlotGrid(4, 1, ax1, ax2, ax3, ax4)


def draw(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docstring.

x = self.variable
length = self.length
height = 0.08
p = Plot()
backend = p.backend(p)
fig = backend.fig
ax = backend.ax

rect = backend.matplotlib.patches.Rectangle((0, 0), length, height, facecolor="brown")
ax.add_patch(rect)

self._draw_load_arrows(ax, backend)
self._draw_supports(ax, backend)

backend.plt.axis("off") # to turn off axis
ax.set_ylim(-0.5, 0.5)
backend.plt.show()
return ax

def _draw_load_arrows(self, ax, backend):
loads = list(set(self.applied_loads) - set(self._support_as_loads))
height = 0.08
length = self.length

for load in loads:
if load[2] == -1:
if load[0].is_positive:
ax.annotate('', xy=(load[1], height), xytext=(load[1], height*3), arrowprops=dict(width= 1.5, headlength=5, headwidth=5, facecolor='black'))
else:
ax.annotate('', xy=(load[1], 0), xytext=(load[1], height - 4*height), arrowprops=dict(width= 1.5, headlength=5, headwidth=5, facecolor='black'))

elif load[2] == -2:
if load[0].is_negative:
ax.plot([load[1]],[height/2], marker=r'$\circlearrowleft$', markersize=15)
else:
ax.plot([load[1]],[height/2], marker=r'$\circlearrowright$', markersize=15)

elif load[2] == 0:
start = float(load[1])
end = float(load[3])

n = int((end - start)/length/0.06)
x_pos = numpy.linspace(start, end, n)

line = backend.matplotlib.lines.Line2D([x_pos[0], x_pos[-1]], [3*height, 3*height], color="black")
ax.add_line(line)

for i in range(0, n):
ax.annotate('', xy=(x_pos[i], height), xytext=(x_pos[i], 3*height), arrowprops=dict(width= 1.5, headlength=4, headwidth=4, facecolor='black'))

elif load[2] == 1:
start = float(load[1])
end = float(load[3])

n = int((end - start)/length/0.06)
x_pos = numpy.linspace(start, end, n)
y_pos = numpy.linspace(height, height*3, n)

line = backend.matplotlib.lines.Line2D([x_pos[0], x_pos[-1]], [y_pos[0], y_pos[-1]], color="black")
ax.add_line(line)

for i in range(1, n):
ax.annotate('', xy=(x_pos[i], height), xytext=(x_pos[i], y_pos[i]), arrowprops=dict(width= 1.5, headlength=4, headwidth=4, facecolor='black'))


def _draw_supports(self, ax, backend):
height = 0.08

for support in self._applied_supports:
print(support[1])
if support[1] == "pin":
ax.plot([support[0]], [0], marker=6, markersize=10, color="black")

elif support[1] == "roller":
ax.plot(support[0], [-0.018], marker='o', markersize=10, color="black")

elif support[1] == "fixed":
if support[0] == 0:
clamp = backend.matplotlib.patches.Rectangle((0, -0.2), -self.length/30, 0.4 + height, fill=False, hatch='/////')
else:
clamp = backend.matplotlib.patches.Rectangle((self.length, -0.2), self.length/30, 0.4 + height, fill=False, hatch='/////')
ax.add_patch(clamp)

class Beam3D(Beam):
"""
This class handles loads applied in any direction of a 3D space along
Expand Down