FEM Tutorial Python

Introduction
This tutorial is meant to show how a simple Finite Element Analysis (FEA) in FreeCAD's FEM Workbench is done using python. The model from the FEM CalculiX Cantilever 3D tutorial will be used for this example.



Requirements
FEM Workbench it is recommended to use the latest development snapshot of FreeCAD for python scripted FEM analyses.
 * The compatible version of FreeCAD as designated in the tutorial overview
 * Use the to see the version of FreeCAD that is installed.
 * Note: Due to the continuous development of the [[Image:Workbench_FEM.svg|24px]]
 * A working FEM workbench. Run the FEM CalculiX Cantilever 3D analysis to ascertain this.

FEM mesh
see Additional informations for how to script mesh generation with GMSH or Netgen mesh object.

Some informations
To run the analysis by Python an instance of the ccxtools module needs to be created. With this instance all processes could be done at once or step by step. If there is only one analysis in the document and only one solver in the analysis, no objects need to be passed on fea init. The init method of the fea class will activate the analysis if the gui is up. As an aditional information, activating an analysis by Python works a follows.

Scripting FEM mesh objects
Scripting the Netgen mesh object was tried here: http://forum.freecadweb.org/viewtopic.php?f=18&t=16944#p134519, but has some limitations. On the contrary the GMSH mesh object fully supports python scripting. See forum post https://forum.freecadweb.org/viewtopic.php?f=22&t=42922#p365042 and forum topic http://forum.freecadweb.org/viewtopic.php?f=18&t=20087.

Scripting multiple analysis
See forum post: http://forum.freecadweb.org/viewtopic.php?f=18&t=19549#p151385

Scripting results
See forum posts:
 * https://forum.freecadweb.org/viewtopic.php?f=18&t=34048&p=289519#p289519 → scale factor in standard result object
 * http://forum.freecadweb.org/viewtopic.php?f=18&t=4677&start=20#p148982
 * http://forum.freecadweb.org/viewtopic.php?f=18&t=4677&start=30#p149043
 * http://forum.freecadweb.org/viewtopic.php?t=18415#p144028
 * https://forum.freecadweb.org/viewtopic.php?f=18&t=31123&p=258761#p258761 → coloring just one element
 * https://forum.freecadweb.org/viewtopic.php?f=18&t=41951&p=357687#p357685 → reset all result mesh, show colored displacement magnitude

Console mode
Writing the input file in FreeCAD console mode (no Gui) could be done in test mode. See forum post in this regard: https://forum.freecadweb.org/viewtopic.php?f=22&t=25852&p=208897#p208897

Appendix
Have Fun!