#049 - Pynite 01: Introduction to Finite Element Modeling in Python
Pynite is a powerful Python library designed for finite element analysis (FEA).
This article is a high-level introduction to Pynite and its capabilities. It is the first in a series on Pynite intended to capture its flexibility and practicality.
Pynite is one of my favourite structural tools. It is particularly suitable for engineers who are already familiar with Python or those looking to incorporate Finite Element Analysis into their existing Python workflows.
Advantages:
Cost: Pynite is free to use as an open-source tool, making it accessible to a wide range of users. No more fighting for license seats or dealing with license expirations/issues.
Ease of Use: Pynite offers an intuitive API that simplifies the process of creating, analyzing, and visualizing FEA models. It is organized in a way that makes sense, using intuitive positional arguments for many of its methods. The clear and concise documentation is a big help too. (Pynite Docs).
Integration with Python: Pynite integrates with many Python libraries for data processing, visualization, and automation, allowing engineers to leverage the full power of Python in their structural analyses.
Special shout out to Connor Ferster’s new visualization library for Pynite: pynite-plotly. You can check out our conversation about Engineering Automation here.
Community Support: As an open-source project, Pynite benefits from contributions and support from the engineering community. This helps with continuous improvement and the addition of new features. You can talk to such folks at the Pynite GitHub Repo or the Flocode Community.
Disadvantages:
Feature Set: While Pynite offers a robust set of features for many common FEA tasks, it lacks some of the advanced capabilities in high-end commercial software.
Performance: For extremely large or complex models, commercial tools with optimized solvers might offer better performance. However, Pynite's use of sparse matrix solvers and ongoing performance optimizations help mitigate this gap.
Pynite provides an excellent alternative to both high-cost commercial software and other open-source tools. I love that it’s simple, fast and flexible.
It’s one of the first practical tools I started using with Python. It is a lightweight yet robust structural analysis suite, and I highly recommend it to all structural engineers.
To accompany today’s article, I have also included a GitHub repo for a simple beam example so you can dig into the code a little more and understand what’s happening. I’ve added plenty of context so you can see what’s happening throughout the example, step by step, and understand the methods and order of operations.
Pynite Features
Pynite provides a user-friendly interface for creating, analyzing, and visualizing 3D finite element models directly within the Python programming environment.
The library offers a wide range of capabilities, including:
Modelling of various structural elements such as beams, columns, trusses, plates, and shells
Support for different material properties and cross-sections
Application of loads, boundary conditions, and member end releases
Linear and non-linear analysis options, including P-Delta and P-delta effects
Visualization of deformed shapes, stress contours, and load distributions
Generation of detailed PDF reports for sharing results and documentation
How Does Pynite Compare to Other FEA Tools?
While Pynite offers a powerful and flexible platform for finite element analysis (FEA), it's beneficial to understand how it compares with other tools in the market, both commercial and open-source.
Commercial Software
SAP2000, ETABS, ANSYS, RISA, Tekla and many more: These are some of the most widely used commercial FEA tools, known for their advanced capabilities and extensive support. They offer a comprehensive suite of features for complex simulations, including multi-physics, non-linear material models, and highly detailed mesh generation. However, these tools come at a high cost, making them less accessible for smaller firms or individual engineers.
Advantages:
Extensive feature set with advanced capabilities.
Robust support and regular updates.
Wide acceptance and usage in the industry.
Disadvantages:
High licensing costs.
Steeper learning curve due to the complexity of features.
Less flexibility for customization compared to open-source solutions.
For those interested, you can check out the status of my current global engineering software survey here.
Other Open-Source Tools
OpenSees: OpenSees (Open System for Earthquake Engineering Simulation) is another popular open-source FEA tool primarily used for simulating the seismic response of structural and geotechnical systems. It is highly customizable and supports a wide range of material models and analysis types.
Advantages:
Highly customizable and extensible.
Strong focus on seismic and geotechnical applications.
Active community and extensive documentation.
Disadvantages:
Steeper learning curve compared to Pynite.
Less user-friendly interface.
Limited integration with other Python libraries.
For more information on OpenSees, check out the excellent resources at Dr. Sean Carroll’s Engineering Skills.
There are plenty of other structural tools for Python, you can check them out here.
#023 - Python Libraries for Civil/Structural Engineering
Who Created Pynite?
Craig Brink (LinkedIn), a structural engineer based in Utah, USA wrote this entire library. I think this is incredible. He’s expanded and improved upon this library for years, with suggestions and help from the open-source community.
I can’t emphasize how impactful this kind of professional generosity is. This is a massive contribution to our field and I can’t believe more people don’t know about it. He has my deepest gratitude and appreciation for such a worthwhile and impressive creation. I only wish I could come up with something so useful.
Craig and I speak at at length about Pynite in a past podcast episode here:
You can check out the Pynite repository here and see how his project has grown over the years. He has written clear, concise documentation and includes many examples to demonstrate how to use various aspects of the library.
A huge shout out to Craig, thank you for this amazing engineering tool. I look forward to seeing it continue to grow and develop as more and more engineers around the world realize how useful it is.
Installation and Setup
You have a few options.
Visit the official Pynite Github repo and follow the instructions in the README.md
Follow the Pynite documentation.
Clone my Pynite example repo and follow the instruction:
To start using Pynite, you'll first need to install the library and its dependencies. Pynite can be easily installed using pip, Python's default package installer. Open a terminal or command prompt and run the following command:
pip install PyniteFEA
Note: You should install PyniteFEA
rather than Pynite
, as the latter is an API stat tracker for Fortnite, which my nephews play (I prefer Elden Ring, Nioh etc.) and is somewhat unrelated to finite element analysis. I fell into this trap despite the documentation clearly telling me not to.
Pynite has a few dependencies that are automatically installed when you install the library:
NumPy: Used for efficient array operations and linear algebra
SciPy (optional): Required for using the sparse matrix solver, which is recommended for large models
Matplotlib (optional): Used for plotting member diagrams and results
VTK (optional): Enables advanced visualization capabilities
The Finite Element Solvers
Pynite offers three primary solvers to address various structural analysis needs: analyze_linear
, analyze
, and analyze_PDelta
. These solvers allow us to perform first-order, non-linear, and second-order analyses efficiently.
Linear Analysis (
analyze_linear
): Theanalyze_linear
solver performs a first-order static analysis, ideal for models without non-linear behaviors. It assembles the global stiffness matrix once, providing a quick solution for simple structures. This solver is appropriate when the structural response is expected to be linear, and no large displacements or rotations are involved.
my_model.analyze_linear(log=True)
Non-Linear Analysis (
analyze
): Theanalyze
solver extends the capabilities to include non-linear analysis, accommodating tension/compression-only members and iterative solutions. It iterates to ensure equilibrium, suitable for models where non-linear behaviors are present, such as structures with tension-only or compression-only elements.
my_model.analyze(check_statics=True)
Second-Order Analysis (
analyze_PDelta
): Theanalyze_PDelta
solver performs second-order (P-Delta) analysis, capturing the effects of large displacements and rotations. This type of analysis is crucial for slender structures and those with significant axial forces, where P-Delta effects can influence the overall stability and response of the structure.
my_model.analyze_PDelta(log=True)
Sparse vs. Dense Matrices
The solvers in Pynite utilize stiffness matrices to represent the structural system's response to loads. These matrices can be either sparse or dense:
Sparse Matrices: Finite element models often have large stiffness matrices with many zero elements. Sparse matrices store only the non-zero elements, significantly reducing memory usage. Operations on sparse matrices can be significantly faster due to the reduced number of elements to process. This is crucial for large-scale models or if you suffer from the undeniable urge to use a high mesh density in your model.
# Creating a sparse matrix (Compressed Sparse Row)
sparse_matrix = csr_matrix([[1, 0, 0], [0, 5, 0], [0, 0, 9]])
# Creating a dense matrix
dense_matrix = np.array([[1, 0, 0], [0, 5, 0], [0, 0, 9]])
Dense Matrices: Dense matrices store all elements, including zeros. While they can be simpler to work with for small models, they are less efficient for large systems due to higher memory and computation requirements.
Choosing between sparse and dense matrices depends on the model's size and complexity. Sparse matrices are generally preferred for large-scale models to enhance performance and reduce resource consumption. Generally speaking, I use the default sparse solver and have never felt like I needed a faster run-time on my analyses, since my models are typically pretty simple, 3D or 2D, frames or plates. Your mileage may vary.
As much as I’d like to dig into this in more detail, I will save it for a future discussion.
Example: Simple Beam in Pynite
I have a detailed walkthrough of how to analyze a simple beam using Pynite here:
https://github.com/joreilly86/Flocode-Pynite-01
I discuss a few of the methods and functions that are required to build FE models using simple arguments, as per the Pynite documentation. I highly recommend taking 10 mins to walk yourself through the code and you will begin to understand how Pynite works.
This example is just scratching the surface. There are many more, including large 3D shell models, that can provide you with a lot of analysis firepower in a convenient, lean package.
Community and Support
The strength of an open-source project like Pynite lies in its community. Here are some ways to get involved and contribute:
GitHub Issues: The Pynite GitHub Issues page is the primary platform for reporting bugs, requesting new features, and seeking help. Users can browse existing issues to find solutions to common problems or raise new ones if they encounter unique challenges.
Community Forums and Groups: Part of the Flocode Community goal is to provide a space for Pynite collaborators but GitHub Discussions are the official place to discuss Pynite development.
Contributing to Pynite: Engineers and developers can contribute to Pynite by submitting pull requests on GitHub. This could involve fixing bugs, adding new features, or improving documentation. Contributions are not limited to code; sharing detailed use cases, writing tutorials, and creating example projects can significantly benefit the community.
Documentation and Examples: Pynite’s official documentation is comprehensive and regularly updated. Users are encouraged to read through the documentation for detailed usage instructions and examples. Additionally, contributing to the documentation by clarifying instructions or adding new examples is a valuable way to support Craig and the community.
Visualization Tools
Visualization is a critical aspect of finite element analysis, allowing engineers to interpret results effectively. Pynite offers built-in visualization tools, and its compatibility with other Python visualization libraries enhances its capabilities:
Built-In Visualization: Pynite provides visualization tools (via PyVista and VTK) to plot deformed shapes, stress contours, and load distributions. These tools are useful for quickly visualizing the results of your analyses directly within the Python environment.
Integration with Matplotlib: Pynite can leverage Matplotlib, a widely-used Python plotting library, for more advanced visualizations. Engineers can create custom plots of member diagrams, shear and moment diagrams, and deflection shapes, allowing for detailed inspection of structural responses.
Advanced Visualization with Plotly: For interactive and detailed visualizations, Pynite can be integrated with Plotly. Plotly offers powerful capabilities for creating interactive plots that can be manipulated in real-time. This is particularly useful for exploring complex 3D models and sharing results with stakeholders.
VTK for 3D Visualizations: The Visualization Toolkit (VTK) can be used for advanced 3D visualizations, enabling you to create high-quality renderings of finite element models. This includes the ability to visualize detailed stress and strain distributions.
The great thing about Pynite is that you can choose your own visualization libraries to illustrate your results. I often use Seaborn, I really like the minimal style of the plots and the nice colour palette!
Closing
Understanding the fundamentals of finite element analysis (FEA) is crucial for any structural engineer. Pynite gives you a powerful, flexible, and free tool to apply these principles effectively. Its integration with Python's broader ecosystem allows for extensive data processing, visualization, and automation.
It has clear documentation and an intuitive API and I think it’s an excellent tool for both beginners and experienced engineers. Pynite can extend your analytical capabilities. You can do a lot, quickly and accurately and at no cost.
I plan to continue expanding on this simple introductory example with more practical use cases in the future.
Check out the first example project on GitHub to get started.
Keep innovating and I’ll see you in the next one.
James 🌊