Пример #1
0
def solids_GUI(plot_contours=True, compute_strains=False, folder=None):
    """
    Run a complete workflow for a Finite Element Analysis

    Parameters
    ----------
    plot_contours : Bool (optional)
        Boolean variable to plot contours of the computed variables.
        By default it is True.
    compute_strains : Bool (optional)
        Boolean variable to compute Strains and Stresses at nodes.
        By default it is False.
    folder : string (optional)
        String with the path to the input files. If not provided
        it would ask for it in a pop-up window.

    Returns
    -------
    UC : ndarray (nnodes, 2)
        Displacements at nodes.
    E_nodes : ndarray (nnodes, 3), optional
        Strains at nodes. It is returned when `compute_strains` is True.
    S_nodes : ndarray (nnodes, 3), optional
        Stresses at nodes. It is returned when `compute_strains` is True.

    """
    if folder is None:
        folder = pre.initial_params()
    start_time = datetime.now()
    echo = False

    #%% PRE-PROCESSING
    nodes, mats, elements, loads = pre.readin(folder=folder)
    if echo:
        pre.echomod(nodes, mats, elements, loads, folder=folder)
    DME, IBC, neq = ass.DME(nodes, elements)
    print("Number of nodes: {}".format(nodes.shape[0]))
    print("Number of elements: {}".format(elements.shape[0]))
    print("Number of equations: {}".format(neq))

    #%% SYSTEM ASSEMBLY
    KG = ass.assembler(elements, mats, nodes, neq, DME)
    RHSG = ass.loadasem(loads, IBC, neq)

    #%% SYSTEM SOLUTION
    UG = sol.static_sol(KG, RHSG)
    if not (np.allclose(KG.dot(UG) / KG.max(), RHSG / KG.max())):
        print("The system is not in equilibrium!")
    end_time = datetime.now()
    print('Duration for system solution: {}'.format(end_time - start_time))

    #%% POST-PROCESSING
    start_time = datetime.now()
    UC = pos.complete_disp(IBC, nodes, UG)
    E_nodes, S_nodes = None, None
    if compute_strains:
        E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC)
    if plot_contours:
        pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes)
    end_time = datetime.now()
    print('Duration for post processing: {}'.format(end_time - start_time))
    print('Analysis terminated successfully!')
    return (UC, E_nodes, S_nodes) if compute_strains else UC
Пример #2
0
print("Number of equations: {}".format(neq))

#%% SYSTEM ASSEMBLY
KG = ass.assembler(elements, mats, nodes, neq, DME)
RHSG = ass.loadasem(loads, IBC, neq)

#%% SYSTEM SOLUTION
UG = sol.static_sol(KG, RHSG)
if not (np.allclose(KG.dot(UG), RHSG)):
    print("The system is not in equilibrium!")
end_time = datetime.now()
print('Duration for system solution: {}'.format(end_time - start_time))

#%% POST-PROCESSING
start_time = datetime.now()
UC = pos.complete_disp(IBC, nodes, UG)
E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC, DME)
#pos.fields_plot(elements, nodes, UC)
umag = np.linalg.norm(UC, axis=1)
mises = np.sqrt(S_nodes[:, 0]**2 - S_nodes[:, 0] * S_nodes[:, 1] +
                S_nodes[:, 1]**2 + 3 * S_nodes[:, 2]**2)
tri = pos.mesh2tri(nodes, elements)
plt.figure(figsize=(10, 5))
plt.subplot(121)
pos.tri_plot(tri, umag, title=r"$\Vert \mathbf{u}\Vert$ (mm)", levels=12)
plt.subplot(122)
pos.tri_plot(tri, mises, title=r"von Mises Stress (MPa)", levels=12)
plt.savefig("wrench.png", dpi=300)
print('Duration for post processing: {}'.format(end_time - start_time))
print('Analysis terminated successfully!')
plt.show()
Пример #3
0
#%%
#   SYSTEM SOLUTION
#
# Solves the system
UG = np.linalg.solve(KG, RHSG)
if not(np.allclose(np.dot(KG, UG), RHSG)):
    print("The system is not in equilibrium!")
end_time = datetime.now()
print('Duration for system solution: {}'.format(end_time - start_time))

#%%
#   POST-PROCCESSING
#
start_time = datetime.now()
UC = pos.complete_disp(IBC, nodes, UG)
pos.plot_disp(UC, nodes, elements)

# Scatter displacements over the elements
UU = pos.scatter(DME, UG, ne, neq, elements)
pos.gmeshpost(IBC, nn, UG, folder=folder)
# Generates points inside the elements and computes strain solution
E_nodes, S_nodes = pos.strain_nodes(IELCON, UU, ne, COORD, elements, mats)
pos.plot_strain(E_nodes, nodes, elements)
pos.plot_stress(S_nodes, nodes, elements, plt_type="pcolor")
eigs1, eigs2, vecs1, vecs2 = pos.principal_dirs(S_nodes)
tri = pos.mesh2tri(nodes, elements)
pos.tri_plot(tri, eigs1, title=r"Maximum stress: $\sigma_1$")
plt.quiver(nodes[:, 1], nodes[:, 2], vecs1[:,0], vecs1[:,1], pivot="middle",
           headwidth=1.5, headlength=2.5)
end_time = datetime.now()