Finite element method in 3D

FEM 3D

fem_3d.main(mesh_file, nelx, nely, nelz, lx, ly, lz, load_matrix, restri_matrix=None, num_el=15, E=210000000000.0, v=0.3, rho=7860, alpha=0.1, beta=1e-07, eta=1e-08, factor=1000000000.0, freq=180, freq_range=[], plot_type='deformed', complete=True, amp=1000000000.0, node_plot=None, timing=False)
Parameters
  • mesh_file (iges) – iges file.

  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • nelz (int) – Number of elements on the Z-axis.

  • lx (float) – X-axis length.

  • ly (float) – Y-axis length.

  • lz (float) – Z-axis length.

  • load_matrix (numpy.array) –

    List of dictionaries. The dictionary can be:

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “x_direc”:force_applied_x, “y_direc”:force_applied_y, “z_direc”:force_applied_z, “force”:force_value}

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “apply_x”:force_applied_x, “apply_y”:force_applied_y, “apply_z”:force_applied_z, “force”:force_value}

  • restri_matrix (numpy.array, optional) –

    List of dictionaries. Defaults to None. The dictionary can be:

    • {“x_coord”:x_coordinate, “y_coord”:y_coordinate, “z_coord”:z_coordinate, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y, “constrain_disp_z”:constrain_disp_z}

    • {“coord”:value_coordinate, “axis”:column_to_compare, “eps”:error_margin, “constrain_disp_x”:constrain_disp_x, “constrain_disp_y”:constrain_disp_y, “constrain_disp_z”:constrain_disp_z}

  • num_el (int, optional) – Number of elements when passing an iges file. Defaults to 15.

  • E (float, optional) – Elastic modulus. Defaults to 210e9.

  • v (float, optional) – Poisson’s ratio. Defaults to 0.3.

  • rho (float, optional) – Density. Defaults to 7860.

  • alpha (float, optional) – Damping coefficient proportional to mass. Defaults to 1e-1.

  • beta (float, optional) – Damping coefficient proportional to stiffness. Defaults to 1e-7.

  • eta (float, optional) – Damping coefficient. Defaults to 1e-8.

  • factor (float, optional) – Factor to deform the mesh. Defaults to 1e9.

  • freq (int, optional) – Optimized frequency. Defaults to 180.

  • freq_range (list, optional) –

    If len is 3, a frequency response graph of the original and optimized structure is generated. Defaults to [].

    • First value is the minimum frequency of the graph.

    • Second value is the maximum frequency of the graph.

    • Third value is the step between each calculation of the objective function.

  • plot_type (str, optional) – The type of the plot. It can be “deformed”, “non_and_deformed”, “colorful” and “animation”. Defaults to “deformed”.

  • complete (bool, optional) – If the arrows and cones will be plotted. Defaults to True.

  • amp (int, optional) – Amplitude to generate deformation animation. Defaults to 1e9.

  • node_plot (numpy.array, optional) –

    The node to plot the frequency response graph. Defaults to first element of load_matrix.

    • The columns are respectively node, x direction, y direction, z direction.

    • It is a 1x4 matrix.

  • timing (bool, optional) – If True shows the process optimization time. Defaults to False.

General functions

functions_3d.apply_U(disp_vector, coord, factor)

Applies displacement to coordinates.

Parameters
  • disp_vector (numpy.array) – Displacement.

  • coord (numpy.array) – mesh coordinates.

  • factor (float) – Factor to deform the mesh.

Returns

Displaced mesh coordinates.

functions_3d.change_U_shape(disp_vector)

Transforms displacement vector in matrix.

Parameters

disp_vector (numpy.array) – Displacement.

Returns

Displacement of each axis.

functions_3d.duplicate_force(load_matrix)

Doubled force value.

Parameters

load_matrix (numpy.array) – Load.

Returns

Load values.

functions_3d.freqresponse(stif_matrix, mass_matrix, load_vector, free_ind, ngl, alpha, beta, eta, freq_range, node_plot)

Frequency response.

Parameters
  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • load_vector (numpy.array) – Load.

  • free_ind (numpy.array) – Free dofs.

  • ngl (int) – Degrees of freedom.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • eta (float) – Damping coefficient.

  • freq_range (list) –

    Frequency range.

    • First value is the minimum frequency.

    • Second value is the maximum frequency.

    • Third value is the step between each calculation of the objective function.

  • node_plot (int) – Node to calculates the displacement.

Returns

Displacement.

functions_3d.get_damp_matrix(mass_matrix, stif_matrix, freq, alpha, beta, eta)

Calculates damping matrix.

Parameters
  • mass_matrix (numpy.array) – Mass matrix.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • freq (int) – Analyzed frequency.

  • alpha (float) – Damping coefficient proportional to mass.

  • beta (float) – Damping coefficient proportional to stiffness.

  • eta (float) – Damping coefficient.

Returns

Damping matrix.

functions_3d.get_displacement(load_vector, free_ind, stif_matrix, mass_matrix, damp_matrix, freq, ngl, timing)

Harmonic solution.

Parameters
  • load_vector (numpy.array) – Load.

  • free_ind (numpy.array) – Free dofs.

  • stif_matrix (numpy.array) – Stiffness matrix.

  • mass_matrix (numpy.array) – Mass matrix.

  • damp_matrix (numpy.array) – Damping matrix.

  • freq (int) – Analyzed frequency.

  • ngl (int) – Degrees of freedom.

  • timing (bool, optional) – If True shows the process optimization time. Defaults to False.

Returns

Displacement vector.

functions_3d.get_dofs(nodes_direct)

Gets DOFs that meet the specified direction.

Parameters

nodes_dir (numpy.array) – [nodes numbers, x_direction, y_direction, z_direction]. x_direction, y_direction and z_direction can be -1, 0 or 1.

Returns

DOFs of each node in array nodes.

functions_3d.get_load_vector(ngl, load_matrix)

Creates the load vector.

Parameters
  • ngl (int) – Degrees of freedom.

  • load_matrix (numpy.array) – Load.

Returns

Loading vector.

functions_3d.get_matrices(matrix, coord, force)

Gets the force matrix or the contraint matrix.

Parameters
  • matrix (list) – List passed by the user.

  • coord (numpy.array) – Coordinates of the element.

  • force (bool) – True if encountering force matrix.

Returns

force_matrix or restri_matrix.

functions_3d.get_matrix(nodes_coord, nodes_col, np_matrix, index_by_coord, index_by_col, ind1, ind2, total_cols)

Creates the node matrix.

Parameters
  • nodes_coord (list) – Nodes passed by coordinate.

  • nodes_col (list) – Nodes passed by column.

  • coord (numpy.array) – Coordinates of the element.

  • matrix (numpy.array) – List passed to an array.

  • index_by_coord (list) – indices of elements passed by coordinates.

  • index_by_col (list) – indices of elements passed by columns.

  • ind1 (int) – Indices of matrix with nodes.

  • ind2 (int) – Indices of matrix passed by user.

  • total_cols (int) – Number of columns desired for the matrix.

Returns

matrix with nodes.

functions_3d.get_max_min_freq(freq_range, delta, disp_vector)

Gets the frequency with the minimum and maximum displacement, respectively.

Parameters
  • freq_range (list) – The initial and final frequency.

  • delta (int) – step between each calculation of the displacement.

  • disp_vector (numpy.array) – Displacement.

Returns

A tuple with the minimum and maximum frequency.

functions_3d.get_nodes(coord, np_matrix, index_by_coord, index_by_col)

Gets nodes by a coordinate or a column.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • np_matrix (numpy.array) – List passed to an array.

  • index_by_coord (list) – indices of elements passed by coordinates.

  • index_by_col (list) – indices of elements passed by columns.

  • ind (int) – The column that has the margin of error.

Returns

Nodes.

functions_3d.get_nodes1d(coord, coord_user, eps, column)

Gets node numbers that are equal to coord.

Parameters
  • coord (numpy.array) – mesh coordinates.

  • coord_user (numpy.array) – coordinates in one direction (x, y or z).

  • eps (float) – Acceptable margin of difference.

  • column (int) – Direction to compare (x, y or z).

Returns

Nodes.

functions_3d.get_nodes_by_coord(coord, coord_user)

Gets node numbers by coordinate.

Parameters
  • coord (numpy.array) – mesh coordinates.

  • coord_user (numpy.array) – user coordinates.

Returns

Nodes of the coordinates provided.

functions_3d.matricesH8(ee, coord, connect, E, v, rho)

H8 stiffness and mass matrices.

Parameters
  • ee (int) – Element.

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

Returns

Tuple with stiffness and mass matrices.

functions_3d.regularmeshH8(nelx, nely, nelz, lx, ly, lz)

Creates a regular H8 mesh.

Parameters
  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • nelz (int) – Number of elements on the Z-axis.

  • lx (float) – X-axis length.

  • ly (float) – Y-axis length.

  • lz (float) – Z-axis length.

Returns

Tuple with the coordinate matrix, connectivity, and the indexes of each node.

functions_3d.remove_dofs(nelx, nely, nelz, del_dofs)

Deletes specific DOFs from all DOFs.

Parameters
  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • nelz (int) – Number of elements on the Z-axis.

  • del_dofs (numpy.array) – Array with DOFs to be removed.

Returns

Array without the DOFs removed.

functions_3d.shapeH8(rrx, ssx, ttx)

Linear Shape Functions and Derivatives.

Parameters
  • rrx (float) – Local coordinate of the element on the Z-axis.

  • ssx (float) – Local coordinate of the element on the X-axis.

  • ttx (float) – Local coordinate of the element on the Y-axis.

Returns

Tuple with the shape function and its derivative.

functions_3d.stif_mass_matrices(nelx, nely, nelz, coord, connect, ind_rows, ind_cols, E, v, rho, timing)

Calculates global matrices.

Parameters
  • nelx (int) – Number of elements on the X-axis.

  • nely (int) – Number of elements on the Y-axis.

  • nelz (int) – Number of elements on the Z-axis.

  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • ind_rows (numpy.array) – Node indexes to make the assembly.

  • ind_cols (numpy.array) – Node indexes to make the assembly.

  • E (float) – Elastic modulus.

  • v (float) – Poisson’s ratio.

  • rho (float) – Density.

  • timing (bool, optional) – If True shows the process optimization time. Defaults to False.

Returns

Global matrices

functions_3d.turn_into_np(dicti_matrix, force)

Transforms dictionaries into numpy array.

Parameters
  • dicti_matrix (list) – List of dictionaries passed by the user.

  • force (bool) – True if encountering force matrix.

Returns

numpy array.

Plot

plots_3d.all_faces(coord, connect)

Gets vertices of all faces of the mesh.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

Returns

Corresponding nodes.

plots_3d.animation(coord, connect, amp, disp_vector)

Plot deformed mesh animation.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

  • amp (int) – Amplitude.

  • disp_vector (numpy.array) – Displacement.

plots_3d.build_arrows(load_matrix, normal_coord, timing=False)

Builds load arrows.

Parameters
  • load_matrix (numpy.array) – The columns are respectively node, x direction, y direction, force value.

  • normal_coord (numpy.array) – mesh coordinates.

  • timing (bool, optional) – If True shows the time to build the load arrows. Defaults to False.

Returns

List with the load arrows.

plots_3d.build_cones(restri_nodes, normal_coord, timing=False)

Builds cones to indicate constrain nodes.

Parameters
  • restri_nodes (numpy.array) – Constrain nodes.

  • normal_coord (numpy.array) – mesh coordinates.

  • timing (bool, optional) – If True shows the time to build the load arrows. Defaults to False.

Returns

List with the cones.

plots_3d.build_mesh(verts, ind_faces, scalars=None, timing=False)

Builds the polygonal Mesh.

Parameters
  • verts (numpy.array) – Vertices of the elements.

  • ind_faces (numpy.array) – Connectivity of the faces of the elements.

  • scalars (int, optional) – Values to add the scalar bar. Defaults to None.

  • timing (bool, optional) – If True shows the time to build the mesh. Defaults to False.

Returns

Build an instance of the Mesh object from the Vedo library.

plots_3d.free_faces(coord, connect)

Gets vertices of external faces of the mesh.

Parameters
  • coord (numpy.array) – Coordinates of the element.

  • connect (numpy.array) – Element connectivity.

Returns

Corresponding nodes.

plots_3d.get_normalized_coord(nodes, normal_coord)

Normalizes coordinates.

Parameters
  • nodes (numpy.array) – External face nodes.

  • normal_coord (numpy.array) – Normalized coordinate.

Returns

Normalized coordinate of the external face nodes.

plots_3d.plot_freqresponse(freq_range, disp_vector)

Plot the frequency response.

Parameters
  • freq_range (list) –

    Range of frequencies analyzed.

    • First value is the minimum frequency.

    • Second value is the maximum frequency.

    • Third value is the step between each calculation of the function.

  • disp_vector (numpy.array) – Displacement.

Returns

Window with the graph.

plots_3d.plot_mesh(mesh, arrows, cones, complete=True, mesh2=None)

Plot mesh.

Parameters
  • mesh (vedo.pointcloud.Points) – Mesh object.

  • arrows (vedo.shapes.Arrows) – Load arrows.

  • cones (vedo.shapes.Cones) – Cones to represent constrain nodes.

  • complete (bool, optional) – If true plot mesh with loads and constrain nodes. Defaults to True.

  • mesh2 (vedo.pointcloud.Points, optional) – Mesh without faces. Defaults to None.

plots_3d.select_nodes(coord, connect, nodes)

Selects unique nodes to build the mesh.

Parameters
  • coord (numpy.array) – mesh coordinates.

  • connect (numpy.array) – Element connectivity.

  • nodes (numpy.array) – Nodes to select.

Returns

A tuple with coordinates and connectivity for the selected nodes.