Designing a 2D Transformer Core: FreeCAD to ElmerFEM Integration (Part 1)
For an electrical machine designer, Finite Element Analysis (FEA) is an indispensable tool. Although a draft project usually begins with a base analytical design, high-performance machines demand flux path optimization, geometry tweaks, and deep material probing.
One of the best ways to achieve this is by creating a parametric drawing and coordinating it using a scripting language. For this, FreeCAD is my go-to choice. Its native Python API allows for complete automation and control over the design variables.
However, before diving into scripting, it is crucial to understand how to structure your first design properly. This post will guide you through that process. While the geometry may seem extremely simple, a few specific tricks will save you hours of rework and frustration.
We are starting with a standard 2D EI transformer core, inspired by the classic FEMM tutorials. Please note that I am using the latest FreeCAD version (v1.1) for this guide.
Parameters
This step is not mandatory, and you can play with constraints for the parametric design as you wish. However, establishing parameters is a fundamental habit for me. I will draw an E-core with a center length of 70mm and lateral legs of 35mm. In total, the height is 140mm, and the coils are fully fitted within a 35mm window.
- Create a new document.
- Switch to the Spreadsheet workbench.
- Create a New Spreadsheet. You can rename it (by pressing
F2) as you like. Mine is namedvars.

After filling out the spreadsheet, you should add aliases to the cells. This creates a global variable that is easy to access during the drawing phase. Just right-click on the value cell » Properties » Alias tab, and type the variable name.
The Sketch
- Switch to the Part Design (or Sketcher) workbench.
- Create a New Sketch.
- Select any plane you prefer. You will likely see a window similar to the one below.

After that, draw the model, apply the geometric constraints, and link your spreadsheet variables by clicking the small f(x) icon in the dimension input boxes or just type =.

Generating the Faces (Surface)
With the 2D geometry ready, it’s time to route it to Gmsh. Inside FreeCAD’s FEM workbench, meshing works reliably on solid bodies or faces, not directly on 2D wireframe sketches. Therefore, we must convert our sketch into 2D faces.

- Select your sketch and use tools to generate flat faces. You will need distinct faces for the Air, the Core, and the Coils.

- If you end up with overlapping faces, they must be broken into their own specific, non-overlapping domains.

- This part can be tricky: using the Part workbench, you must select the surfaces (from the outermost to the innermost) and use the Slice Apart (or Boolean Fragments) tool.
Once properly sliced, use the Connect tool to ensure all adjacent faces share the same boundary edges.

Meshing with Gmsh
Now it’s time to mesh the model.
- Switch to the FEM workbench.
- Select your
Connect(orFragment) group in the tree view and click FEM mesh from shape by Gmsh.

In the configuration panel, you can choose the element dimension as From Shape or 2D, select 2nd order elements, and define the maximum and minimum mesh sizes based on your design requirements.

If you need to improve the mesh density in specific areas, use the Mesh Refinement tool, select the target surface, and adjust as needed. To apply the changes, double-click the Gmsh object in the tree and hit apply to re-mesh.

Materials and Boundaries (The Mesh Groups Trick)
FreeCAD’s visual material tools do not export properly to Elmer when generating .unv files. Instead, materials and boundaries are treated as Physical Groups.
To define them:
- Click on FEM mesh region (Mesh Group).
- Select the specific surface (e.g., the steel core) and assign a Label name (e.g.,
Core). The exact same logic applies to the boundaries (edges), which will later be defined as Magnetic Potentials inside Elmer.
Crucial Tip: Always ensure you are selecting the edges/faces of your final Connect/Face object, not the original Sketch!

The final result is presented bellow.

Exporting to Elmer
The model must now be exported for Elmer to understand. Select your Gmsh mesh object in the tree, go to File » Export…, and save it as an I-DEAS Universal (.unv) file.
Open ElmerGUI, go to File » Open, select your .unv file, and check the final imported mesh. You should see your named physical groups translated perfectly into Body Properties and Boundary Properties.

Now it’s time to assign the electromagnetic equations, materials, and start the Elmer simulation— but that is a topic for the next post.
