This project was created to help students develop their first finite element (FE) code for elasticity problems applying object-oriented programming principles.
- Change the folder name from
PyFET-StudentstoPyFET. - Install all required libraries (see Required Libraries section).
- Create an empty Python script at the same level as the
PyFETdirectory (see Folder Structure section). - Fill the empty script with the following Python code:
from PyFET.Node import *
n1 = Node([1,0])
print(f"node n1 = \n{n1}")
print("PyFET is working properly!")If the message PyFET is working properly! appears, the installation is successful.
To install Python, follow these steps:
- Go to the official Python website: python.org.
- Click on the "Downloads" tab.
- Select the appropriate version for your operating system (Windows, macOS, or Linux).
- Download the installer and run it.
- Follow the installation instructions. Make sure to check the box that says "Add Python to PATH" during the installation process.
After installing Python, you can verify the installation by opening a terminal or command prompt and typing:
python --versionThis should display the version of Python that you installed.
To use PyFET, you need to have the following libraries installed:
- Python: PyFET is written in Python, so you need Python installed on your system.
- gmsh: A 3D finite element grid generator required for mesh generation.
- numpy: A fundamental package for scientific computing with Python.
- scipy: A Python library used for scientific and technical computing.
You can install these libraries using pip:
python -m pip install gmsh numpy scipyMake sure the Python version you are using is the same as the one you installed the libraries. It is not uncommon for an environment to have more than one Python version installed.
To use PyFET in your project, you need to import it into your Python script. Ensure that the PyFET directory is in the same directory as your script or in your Python path.
Here is an example of how to import and use PyFET:
from PyFET.Bar2Node import *
# Your code to use PyFETThis will import all the functions related to the Bar2Node class that implements a 2-noded bar element.
Your folder structure should look something like this:
/your_project_directory
/PyFET
# All PyFET files
your_script.py
PyFET is designed to generate outputs in VTK format, which can be visualized using ParaView. Throughout the course, two functions will be implemented: one to simply visualize the domain and mesh, and another to visualize the solution fields after running. For the mesh/domain:
# Printing mesh in vtk format
mesh.generateGeometryVTK("filename.vtk")And to visualize the solution fields:
vecnames = ["displacement"] # vector solution fields
scalnames = ["normal", "strain", "stress"] # scalar solution fields
analysis.generateSolutionVTK(filename="filename.vtk",vecnames=vecnames,scalnames=scalnames)To visualize the VTK output file, you can use ParaView:
- Download ParaView from the official website: paraview.org.
- Open ParaView.
- Go to
File>Openand select thefilename.vtkfile. - Click
Applyto load the data. - Use the visualization tools in ParaView to explore your results.
With these steps, you should be able to set up and use PyFET for your finite element analysis projects.