Finite Element Analysis Using Python and Feon

Click the above“Mechanical and Electronic Engineering Technology”to follow us1D RodFinite Element Analysis Using Python and Feon

from feon.sa import *
import numpy as np
from feon.tools import pair_wise

if __name__ == "__main__":
    E = 210e6
    P = 18
    X = np.linspace(0,3,6)
    _X = X - 0.3
    A = [0.002 + 0.01 * val / 3. for val in _X[1:]]
    A.reverse()

    nds = [Node(x, 0) for x in X]
    els = []
    count = 0
    for nd in pair_wise(nds):
        els.append(Link1D11(nd, E, A[count]))
        count += 1

    s = System()
    s.add_nodes(nds)
    s.add_elements(els)
    s.add_fixed_sup(0)
    s.add_node_force(nds[-1].ID, Fx=18)
    s.solve()

    import matplotlib.pyplot as plt
    from matplotlib import cm
    stress = np.array([el.sx[0][0] for el in els])
    a = np.zeros((5, 5))
    fig, ax = plt.subplots()

    for i in range(5):
        a[i, :] = stress
    cax = ax.imshow(a, interpolation='nearest', cmap=cm.coolwarm)
    cbar = fig.colorbar(cax, orientation='horizontal')

    plt.show()

Finite Element Analysis Using Python and Feon

2D Rod

Finite Element Analysis Using Python and Feon

from feon.sa import *

if __name__ == "__main__":
    E = 210e6
    A = 0.005
    K = 79e3
    n0 = Node(0, 0)
    n1 = Node(5, 0)
    n2 = Node(10, 0)
    n3 = Node(15, 0)
    n4 = Node(5, 7)
    n5 = Node(10, 7)
    n6 = Node(15, -1)

    e0 = Link2D11((n0, n1), E, A)
    e1 = Link2D11((n1, n2), E, A)
    e2 = Link2D11((n2, n3), E, A)
    e3 = Link2D11((n4, n0), E, A)
    e4 = Link2D11((n4, n1), E, A)
    e5 = Link2D11((n4, n2), E, A)
    e6 = Link2D11((n4, n5), E, A)
    e7 = Link2D11((n5, n2), E, A)
    e8 = Link2D11((n5, n3), E, A)
    e9 = Spring2D11((n3, n6), K)

    s = System()
    s.add_nodes(n0, n1, n2, n3, n4, n5, n6)
    s.add_elements(e0, e1, e2, e3, e4, e5, e6, e7, e8, e9)
    s.add_node_force(4, Fx=30)
    s.add_fixed_sup(0, 6)
    s.solve()

    print(e9.force)
    print(n3.disp)

{‘N’: array([[ 14.],
[-14.]])}

{‘Ux’: 0.00023809523809523858, ‘Uy’: -0.00017721518987341803,
‘Phz’: 0.0}

3D Rod

Finite Element Analysis Using Python and Feon

from feon.sa import *

if __name__ == "__main__":
    E = 200e6
    A1 = 0.001
    A2 = 0.002

    n0 = Node(0, 0, 0)
    n1 = Node(0, -4, -5)
    n2 = Node(-3, 0, -5)
    n3 = Node(0, 4, -5)

    e0 = Link3D11((n0, n1), E, A1)
    e1 = Link3D11((n0, n2), E, A2)
    e2 = Link3D11((n0, n3), E, A1)

    s = System()
    s.add_nodes(n0, n1, n2, n3)
    s.add_elements(e0, e1, e2)
    s.add_node_force(0, Fx=12)
    s.add_fixed_sup(1, 2, 3)
    s.solve()

    from matplotlib.ticker import FuncFormatter
    import matplotlib.pyplot as plt
    import numpy as np

    def stresses(x, pos):
        return "$%1.1fMPa$" % (x * 1e-3)

    x = np.arange(3)
    stress = [abs(el.sx[0][0]) for el in [e0, e1, e2]]
    formatter = FuncFormatter(stresses)

    fig, ax = plt.subplots()
    ax.yaxis.set_major_formatter(formatter)
    plt.bar(x, stress, 0.2, color=["r", "b", "g"])
    ax.set_xticks(x + 0.1)
    ax.set_xticklabels(("$Bar 0$", "$Bar 1$", "$Bar 2$"))
    ax.set_ylabel("$N/kN$")
    ax.set_xlim([-0.5, 3])

    plt.show()

Finite Element Analysis Using Python and Feon

Truss

Finite Element Analysis Using Python and Feon

from feon.sa import *
from feon.tools import pair_wise
from feon.sa.draw2d import *
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

if __name__ == "__main__":
    E = 210e6
    A1 = 31.2e-2
    A2 = 8.16e-2
    nds1 = []
    nds2 = []

    for i in range(13):
        nds1.append(Node(i, 0))
    for i in range(11):
        nds2.append(Node(i + 1, -1))

    el = []
    for e in pair_wise(nds1):
        el.append(Link2D11((e[0], e[1]), E, A1))
    for e in pair_wise(nds2):
        el.append(Link2D11((e[0], e[1]), E, A1))

    for i in range(6):
        el.append(Link2D11((nds1[i], nds2[i]), E, A2))
    for i in range(6):
        el.append(Link2D11((nds2[i + 5], nds1[i + 7]), E, A2))
    for i in range(11):
        el.append(Link2D11((nds1[i + 1], nds2[i]), E, A2))

    s = System()
    s.add_nodes(nds1, nds2)
    s.add_elements(el)
    s.add_node_force(nds1[0].ID, Fy=-1000)
    s.add_node_force(nds1[-1].ID, Fy=-1000)
    for i in range(1, 12):
        s.add_node_force(nds1[i].ID, Fy=-1900)
    s.add_fixed_sup(nds1[0].ID)
    s.add_rolled_sup(nds1[-1].ID, "y")
    s.solve()

    disp = [np.sqrt(nd.disp["Ux"]**2 + nd.disp["Uy"]**2) for nd in s.get_nodes()]
    eforce = [el.force["N"][0][0] for el in s.get_elements()]

    fig = plt.figure()
    ax = fig.add_subplot(211)
    ax.yaxis.get_major_formatter().set_powerlimits((0, 1))
    ax2 = fig.add_subplot(212)
    ax2.yaxis.get_major_formatter().set_powerlimits((0, 1))
    ax.set_xlabel(r"$Node ID$")
    ax.set_ylabel(r"$Disp/m$")
    ax.set_ylim([-4e-2, 4e-2])
    ax.set_xlim([-1, 27])
    ax.xaxis.set_minor_locator(MultipleLocator(1))
    ax.plot(range(len(disp)), disp, "r*-")
    ax2.set_xlabel(r"$Element ID$")
    ax2.set_xlim([-1, 46])
    ax2.set_ylabel(r"$N/kN$")
    ax2.set_ylim(-40000, 40000)
    ax2.xaxis.set_minor_locator(MultipleLocator(1))
    for i in range(len(eforce)):
        ax2.plot([i - 0.5, i + 0.5], [eforce[i], eforce[i]], "ks-", ms=3)

    plt.show()

Finite Element Analysis Using Python and Feon

1D Beam

Finite Element Analysis Using Python and Feon

from feon.sa import *

if __name__ == "__main__":
    E = 210e6
    A = 0.005
    I = 5e-5

    n0 = Node(0, 0)
    n1 = Node(2, 0)
    n2 = Node(4, 0)
    n3 = Node(8, 0)
    n4 = Node(10, 0)

    e0 = Beam1D11((n0, n1), E, A, I)
    e1 = Beam1D11((n1, n2), E, A, I)
    e2 = Beam1D11((n2, n3), E, A, I)
    e3 = Beam1D11((n3, n4), E, A, I)

    s = System()
    s.add_nodes(n0, n1, n2, n3, n4)
    s.add_elements(e0, e1, e2, e3)

    for nd in [n0, n2, n3]:
        s.add_rolled_sup(nd.ID, "y")
    s.add_fixed_sup(4)
    s.add_element_load(2, "Q", -7)
    s.add_node_force(1, Fy=-10)
    s.solve()

    from feon.sa.draw2d import *
    for el in [e0, e1, e2]:
        draw_bar_info(el)

Finite Element Analysis Using Python and Feon

Finite Element Analysis Using Python and Feon

Finite Element Analysis Using Python and Feon

Finite Element Analysis Using Python and Feon

Want to know more?

Quickly scan the code to follow us

Leave a Comment