Exemple #1
0
def solids_GUI(compute_strains=False, plot_contours=True):
    """
    Run a complete workflow for a Finite Element Analysis
    
    Parameters
    ----------
    compute_strains : Bool (optional)
      Boolean variable to compute Strains and Stresses at nodes.
      By default it is False.
    plot_contours : Bool (optional)
      Boolean variable to plot contours of the computed variables.
      By default it is True.

    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.

    """    
    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
Exemple #2
0
def test_2_elements():
    """2x1 mesh cantilever beam"""
    nodes = np.array([[0, 0, 0], [1, 1, 0], [2, 2, 0], [3, 0, 1], [4, 1, 1],
                      [5, 2, 1]])
    cons = np.array([[-1, -1], [0, 0], [0, 0], [-1, -1], [0, 0], [0, 0]])
    eles = np.array([[0, 1, 0, 0, 1, 4, 3], [1, 1, 0, 1, 2, 5, 4]])
    loads = np.array([[2, 0, -0.5], [5, 0, -0.5]])
    mater = np.array([[1.0, 0.3]])
    assem_op, bc_array, neq = ass.DME(cons, eles)
    stiff, _ = ass.assembler(eles, mater, nodes, neq, assem_op)
    load_vec = ass.loadasem(loads, bc_array, neq)
    disp = sol.static_sol(stiff, load_vec)
    disp_complete = pos.complete_disp(bc_array, nodes, disp)
    disp_analytic = 1 / 45 * np.array([[0, 0], [-273, -390], [-364, -1144],
                                       [0, 0], [273, -390], [364, -1144]])

    assert np.allclose(disp_complete, disp_analytic)
Exemple #3
0
def test_4_elements():
    """2×2 mesh with uniaxial load"""
    nodes = np.array([[0, 0, 0], [1, 2, 0], [2, 2, 2], [3, 0, 2], [4, 1, 0],
                      [5, 2, 1], [6, 1, 2], [7, 0, 1], [8, 1, 1]])
    cons = np.array([[0, -1], [0, -1], [0, 0], [0, 0], [-1, -1], [0, 0],
                     [0, 0], [0, 0], [0, 0]])
    eles = np.array([[0, 1, 0, 0, 4, 8, 7], [1, 1, 0, 4, 1, 5, 8],
                     [2, 1, 0, 7, 8, 6, 3], [3, 1, 0, 8, 5, 2, 6]])
    loads = np.array([[3, 0, 1], [6, 0, 2], [2, 0, 1]])
    mater = np.array([[1.0, 0.3]])
    assem_op, bc_array, neq = ass.DME(cons, eles)
    stiff, _ = ass.assembler(eles, mater, nodes, neq, assem_op)
    load_vec = ass.loadasem(loads, bc_array, neq)
    disp = sol.static_sol(stiff, load_vec)
    disp_complete = pos.complete_disp(bc_array, nodes, disp)
    disp_analytic = np.array([[0.6, 0.0], [-0.6, 0.0], [-0.6, 4.0], [0.6, 4.0],
                              [0.0, 0.0], [-0.6, 2.0], [0.0, 4.0], [0.6, 2.0],
                              [0.0, 2.0]])
    assert np.allclose(disp_complete, disp_analytic)
Exemple #4
0
import solidspy.solutil as sol


start_time = datetime.now()

#%% PRE-PROCESSING
nodes, mats, elements, loads = pre.readin()
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, sparse=False)
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)
pos.fields_plot(elements, nodes, UC)
end_time = datetime.now()
print('Duration for post processing: {}'.format(end_time - start_time))
print('Analysis terminated successfully!')
Exemple #5
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
Exemple #6
0
# System solution

t1=time.time()
UG = sol.static_sol(KG, RHSG)  #   nodes added by me
if not (np.allclose(KG.dot(UG) / KG.max(), RHSG / KG.max())):
    print("The system is not in equilibrium!")

t2=time.time()
print("system solution ", t2-t1)

end_time = dt.now()
#print('Duration for system solution: {}'.format(end_time - start_time))

# Post-processing
start_time = dt.now()
UC = pos.complete_disp(IBC, nodes, UG)  # uc are x and y displacements
#UC2 = pos.complete_disp(IBC, nodes, UG2)  # uc are x and y displacements


E_nodes, S_nodes = None, None
if compute_strains:
    E_nodes, S_nodes = pos.strain_nodes(nodes, elements, mats, UC)
    #E_nodes2,S_nodes2=pos.strain_nodes(nodes, elements, mats, UC2)
if plot_contours:
    pos.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes) # some matplotlib internal function to make it look smoother
end_time = dt.now()



# calculation of principal stresses
## are signes importnatn here???
Exemple #7
0
def solids_auto(data, plot_contours=True, compute_strains=False):
    """
    Run a complete workflow for a Finite Element Analysis

    Parameters
    ----------
    data : dict
        Simulation data composed of nodes, constrains, elements,
        materials and loads.
    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.

    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.

    """
    # Retrieving data
    nodes = data["nodes"]
    cons = data["cons"]
    elements = data["elements"]
    mats = data["mats"]
    loads = data["loads"]

    # Pre-processing
    assem_op, bc_array, neq = ass.DME(cons, 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
    stiff_mat, _ = ass.assembler(elements, mats, nodes, neq, assem_op)
    rhs_vec = ass.loadasem(loads, bc_array, neq)

    # System solution
    start_time = datetime.now()
    disp = sol.static_sol(stiff_mat, rhs_vec)
    if not np.allclose(
            stiff_mat.dot(disp) / stiff_mat.max(), rhs_vec / stiff_mat.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()
    disp_complete = pos.complete_disp(bc_array, nodes, disp)
    strain_nodes, stress_nodes = None, None
    if compute_strains:
        strain_nodes, stress_nodes = pos.strain_nodes(nodes, elements, mats,
                                                      disp_complete)
    if plot_contours:
        pos.fields_plot(elements,
                        nodes,
                        disp_complete,
                        E_nodes=strain_nodes,
                        S_nodes=stress_nodes)
    end_time = datetime.now()
    print('Duration for post processing: {}'.format(end_time - start_time))
    print('Analysis terminated successfully!')
    if compute_strains:
        return (disp_complete, strain_nodes, stress_nodes)
    else:
        return disp_complete
Exemple #8
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)
    assem_op, bc_array, neq = ass.DME(nodes[:, -2:], 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
    stiff_mat, _ = ass.assembler(elements, mats, nodes[:, :3], neq, assem_op)
    rhs_vec = ass.loadasem(loads, bc_array, neq)

    # System solution
    disp = sol.static_sol(stiff_mat, rhs_vec)
    if not np.allclose(
            stiff_mat.dot(disp) / stiff_mat.max(), rhs_vec / stiff_mat.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()
    disp_complete = pos.complete_disp(bc_array, nodes, disp)
    strain_nodes, stress_nodes = None, None
    if compute_strains:
        strain_nodes, stress_nodes = pos.strain_nodes(nodes, elements, mats,
                                                      disp_complete)
    if plot_contours:
        pos.fields_plot(elements,
                        nodes,
                        disp_complete,
                        E_nodes=strain_nodes,
                        S_nodes=stress_nodes)
    end_time = datetime.now()
    print('Duration for post processing: {}'.format(end_time - start_time))
    print('Analysis terminated successfully!')
    if compute_strains:
        return (disp_complete, strain_nodes, stress_nodes)
    else:
        return disp_complete