Pycalculix is a tool I wrote which lets users build, solve, and query mechanical engineering models of parts. The tool is a Python3 library, which uses the Calculix program to run and solve finite element analysis models. With it you can see and understand part stresses, strains, displacements, and reaction forces.
Pycalculix Strengths:
It is great for design studies. You could run many versions of your part where you change a fillet, or wall thickness, and record the stress impact. It is also good for calculating stress concentration factors. In the example below, Pycalculix was used to re-create the tension hole in a plate Kt graph, and it was accurate to Peterson’s answer to within 1.5%. Because simplicity is minimized, Pycalculix is a good educational introduction to FEA.
Pycalculix Technical Capabilities:
- Model Type: structural
- Element Types: plane stress, plane strain, axisymmetric
- Element Shapes: triangles, and quadrilaterals
- Element Order: 1 (corner nodes only) and 2 (corner nodes and midside nodes)
- Geometry: build part geometry, including straight lines, arcs, and fillets/blends
- Loads: apply pressures, gravity, rotational speed, water pressure, forces
- Constraints: apply displacements
- Contact: define linear contact between multiple parts.
- Time Steps: multiple steady state time steps supported
- Meshing: Calculix CGX or GMSH are run in the background to mesh your part, you don’t need t know how to use them
- Solving: Calculix CCX is used to solve the model in the background
- Results Viewing/Querying: FRD results file is read in and all results are accessible in python
- Can query nodal max and min
- Can select elements connected to points, lines, areas, parts
- Can plot nodal and element results
- Cost: Free (GPL license)
- Pycalculix Release Date: December 23, 2014, written by Justin Black
Example Problems:
- 2D plane stress example: hole-in-plate-quarter.py
- 2D plane strain example: dam.py
- Axisymmetric rotating part: compr-rotor.py
- Design study example: hole-kt-study.py
- Multiple time step example: dam-times.py
- Multi-body contact: pipe-crush-elastic.py
Gallery Images:
Pycalculix Documentation + Links :
Installation:
Walk-through, Building and Solving a Model:
In this pdf, we’ll walk through all the normal steps. We’ll build our model geometry, apply loads, mesh the model, solve it, then view and query the results.
Related Links:
- Calculix(Free GPL FEA solver that pycalculix uses)
- Gmsh (Free GPL mesher that pycalculix uses)
- Anaconda (distribution which includes Python, Numpy, Matplotlib, and many other Python libraries)
- Python (what pycalculix was written in)
- Numpy (Python library focused on matrices)
- Matplotlib (Python graphing library)
- Agros2D (Free GPL 2D FEA that has a GUI, Python interface, multiphysics, and supports mesh refinement)
- Sfepy (Python fea, applied but verbose)
- Fipy (Python fea, very academic)
- Freecad (great free modeling/cad program, has python interface and integrates Calculix)
- Salome-Meca (very full featured free FEA program with python interface, some steps in French)
- Elmer (very full featured FEA program, user friendly for one part 3D model)
Hi Justin,
I’ve found you project pyCalculix. This is a realy good idea to create python api and pre/post processor for calculix. Do you have any plan to extend you project on 3D models?
I agree that developing a python interface in 3d would be a good next step. I don’t plan on taking it right now. If I did, I’d probably want to use openscad, pyopengl, gmsh 3d internals, or pythonocc http://www.pythonocc.org
(pythonocc looks like the best option)
Installed Anaconda and then py calculix. But do not know how to run your example. Can you kindly describe how to run a simple example. Youtube video would be very useful. Put your work details in yahoo calculix forum
Justin,
I conduct research in structural design optimization (under uncertainty). Your pyCalculix is exactly what I have been looking for the optimization of small problems and for my students to get started easily.
I have a couple questions for you:
-Why did you decide to use Python 3 and not Python 2? I wrote my optimization and uncertainty analysis tool using Python 2 and was curious on the advantages of version 3. Do you know if it is possible to “mix” 2 and 3, i.e. optimization tool with 2 and structural-mechanical analysis in 3.
-What are your plans for the tool? Do you plan on moving to three-dimensional analysis?
Greetings from Munich
Erich
Erich,
I’m glad pycalculix will help you. To answer your questions:
1) I decided to use Python 3 because it’s the current and future version of the language and it’s been around for 7 years now. All the required libraries I need are available in Python 3. If you want you can read the below arguments for a switch to 3:
https://wiki.python.org/moin/Python2orPython3
http://blog.teamtreehouse.com/python-2-vs-python-3
You have a three options.
-Port your tool into Python 3 (this isn’t very hard, not much has changed)
-Run a dual installation with python2 and python3 separately installed and call them as python2 script.py python3 script.py [Ubuntu has this by default]
-Use virtual environments to separate each python installation, http://www.circuidipity.com/python2-and-python3.html
2) My plans for the tool are to keep the domain in 2D right now, and make it more functional. My main goal is to have the ability to import and export parts from the tool, and have the ability to run thermal, structural, and thermal-structural analysis, and autodetect and include contact between parts. I don’t intend to move it into 3D at this point. If that is something that you need, I would suggest looking at:
Elmer: https://www.csc.fi/web/elmer/documentation (look at Elmergrid and the non-gui examples for how you would automate it)
Sfepy: http://sfepy.org/doc-devel/index.html
Fipy: http://www.ctcms.nist.gov/fipy/
FreeCAD with Calculix: http://www.freecadweb.org/ (great geometry generation)
Code-Aster: http://www.code-aster.org/V2/spip.php?article303
PythonOCC: http://www.pythonocc.org/category/quick-examples/ (great geometry generation, one would have to hook it into Calculix or another solver, but I think it has meshing in it already)
Say, given that you all are familiar with calculix…can I ask a question? I am trying to find out if I can do 2D thermal analysis with Calculix and I am having a very hard time finding any information about it.
thanks
Yes, Calculix supports 2D thermal analysis. I haven’t added the functionality in pycalculix yet, but I’ll add it in the next release.
In the Calculix manual, look up *HEAT TRANSFER, Calculix comes with a number of example files. For me they are at: C:\Program Files\Calculix27\ccx_2.7.1_tests
In those files look at the examples: beamhtcr.inp, oneel20fi.inp, oneel20rs.inp
Hi Justin
Good work. We wonder is it possible for you to show us a demo (a short video on youtube) of how to run an example in powershell.
We find it very easy to install via anaconda but we don’t know hoe execute your examples.
Linda, I’ll have some examples up soon. I’m working on getting the Linux version working out of the box, and then I’ll post tutorial videos. To execute the examples you need to run them using python.
Windows:
Make sure .py files are associated with python, then
Double click the example.py file to run it
Linux:
cd to the directory with the example file in it, then run
python3 example.py
Hi. This is very nice.
I have a question. Well, I want to use CalculiX instead of Abaqus. Abaqus write and read A LOT in disk, and I have to run some code like 20000 times at least. You think in create something to read a inp file and than you have your model without have to code?
I don’t understand your question. You could be asking can I use your library without coding? Nope, it’s purely a programming library. But if you have to do analysis 2000 times, automating it with a script is the easiest way to do it. If you look at the pycalculix examples, I think that you’ll find them easy to understand. Good luck.
Hi when I do pip install pycalculix in the command prompt window I get the message ‘No Distributions at all found for pycalculix’. I am using Python 3.4.3. Does pycalculix work only till python Python 3.4.2?
Pypi was having indexing issues and was not pointing to their hosted libraries correctly. Pypi download should work right now. Or you can download the github repository and install from there.
Hi Justin
thanks for sharing, great stuff.
There is a slight issue with installing 0.9.3 from github, fix below worked for me
svn co https://github.com/spacether/pycalculix.git
cd pycalculix.git/trunk
##this is the fix
sudo rm `find ./ -name *pyc`
sudo setup.py install
Great goods from you, man. I’ve understand your
stuff previous to and you’re just extremely fantastic.
I really like what you have acquired here, really like what you are saying and the
way in which you say it. You make it entertaining and you still take
care of to keep it wise. I cant wait to read far more from you.
This is really a terrific web site.
Python 3 highest Version is today 3.5.2.
Is 3.5.2 icompatible to version 0.9.3 or is python 3.4.5 better ?
Next Version with Heat transfer solution. I see some thermal things in the code.
Much work to do last parts, time plan about it?
hi again,
an update to calculix 2.10 in win (available by beconverged) and gmsh 2.13 (64bit win available) could also improve future possibilities
great work this pycalculix
and hope for more
Hi, Justin!
Please, what libraries did you used to make the 2D images in python?
I want to make a similar software in python with 3D visualization…
Can you help me?
I used matplotlib to plot images. Please look in to it, there are many great 2d and 3d examples there.
Ok, thank you very much!
Hi, Justin
What library did you used to make the color gradient?
Matplotlib
Hi Justin,
Great work on this Python3 library, I’m not familiar with CalculiX and I was up and running within a few hours. I followed your quarter plate with a hole example because I have to do a FEA demo for a group of other graduate students and the professor is very familiar with CalculiX but I’m familiar with another commercially available option – I compared the same model with very similar mesh densities and the results are very close (thanks!).
Are you planning to add more documentation about the different modules (Mesh, Part, Geometry, etc.)? Most of my struggle was meshing the part and also re-drawing the geometry (from a vertical plate to a horizontal one).
Great work man! Keep the project moving – this is great work!
Good Morning,
I am a student at the State University of Ceará – Brazil. I wonder if Pycalculix can be used to solve problems involving heat transfer in batch reactors?
Hello Pedro. Pycalculix only supports structural analysis at this time, so no. The solver Calculix does support 2d and 3d heat transfer analysis though.