Finite Element Scratch is a functioning finite element method (FEM) analysis tool built entirely from scratch, using only numpy and sympy for computation and matplotlib for visualization. This project demonstrates the fundamental steps in FEM, including the creation of stiffness matrices, solving global equations, and visualizing results for different cases.
Note: All units used in this project are SI units
- Stiffness Matrix Construction:
- Local matrices are derived and integrated using interpolation functions.
- Lagrange functions are used for axial displacement.
- Hermitic functions are used for bending displacement.
- Global Matrix Assembly:
- Connectivity of elements is taken into account to construct the global matrix.
- Solution for Displacements and Forces:
- Compute the displacements of all nodes.
- Calculate the forces exerted on each node.
- Visualization:
- Use
matplotlibto visualize the results.
- Use
This repository includes two example cases:
- Truss Bridge Analysis:
FEM_truss_bridge.py - Fixed-Fixed Beam Analysis:
FEM_fixed_fixed_beam.py
Ensure you have Python installed along with the following libraries:
numpysympymatplotlib
You can install the required libraries using pip:
pip install numpy sympy matplotlib- Clone the repository:
git clone https://github.com/gabotuzl/finite_element_scratch.git
cd finite_element_scratch- Run one of the example cases:
python FEM_truss_bridge.pyor
python FEM_fixed_fixed_beam.py- Customize your analysis by modifying specific fields as described below.
To define your custom FEM analysis, update the following fields in your script:
-
node_positions(np.array): An array containing the global coordinates of each node. The position in the array corresponds to the node number.Example:
node_positions = np.array([[0, 0], [1, 0], [2, 0]])
-
connectivity(np.array): An array defining the connections between nodes. For example, if node 1 connects to node 2, the element is[1, 2]. Nodes are numbered from 1 to N.Example:
connectivity = np.array([[1, 2], [2, 3]])
-
fixed_nodes(np.array): An array specifying boundary conditions. A1at a position indicates the corresponding node is fixed.Example:
fixed_nodes = np.array([1, 0, 1]) # Node 1 and Node 3 are fixed
-
global_forces(np.array): An array containing applied forces. Use the same format as shown in the examples to ensure correct application of point loads.Example:
global_forces = np.zeros(total_dof) loaded_node_1 = 3 loaded_node_2 = 7 global_forces[(loaded_node_1 - 1) * node_dof + 1] = -500000 global_forces[(loaded_node_2 - 1) * node_dof + 1] = -500000
Contributions are welcome! If you have suggestions, improvements, or new features to add, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.