My journey from theory to code

Background

Since my Bachelor's studies in Grenoble, I've been proficient in using Flux, distributed by Cedrat (now Altair). Throughout my PhD, I continued to utilise Flux, enhancing its functionality by developing Python macros. Additionally, I gained experience with Ansys Mechanical. I also explored programming the Finite Element Method using MATLAB, where I computed natural frequencies of stators without relying on additional libraries.

I vividly remember the sense of empowerment that came from mastering computational techniques. After reading the seminal 1993 papers by Zhu, Howe, Bolte, and Ackermann on magnetic field theory in the air-gap, I successfully translated their equations into Python code. This allowed me to achieve similar results and calculate the flux density in the air gap. By incorporating these computations with my natural frequency code, I gained valuable insights into the vibration behavior of electric machines caused by magnetic forces.

Since then, my affinity for simulation and coding has remained strong, as I consider coding an essential tool in my engineering toolbox.

First steps in 2021

Natural frequencies

While I continued to engage in simulations following my PhD, developing simulation tools for electric motors remained outside the scope of my professional activities. However, during the lockdown imposed by the Covid pandemic in 2021, I found myself searching for ways to occupy my evenings. Revisiting a book from my PhD studies sparked an intriguing challenge: to create a simple mesher, solver, and post-processor capable of computing natural frequencies for various stator shapes.

After several weeks of dedicated effort, I succeeded in developing these tools and was pleasantly surprised by their functionality. I decided to make them accessible by hosting them on Google Colab, enabling me to carry this powerful tool with me on my smartphone through a web browser. This experience was transformative, prompting me to explore further possibilities. Why stop at natural frequencies? Why not extend the capabilities to compute magnetic fields as well? Additionally, the idea of creating a phone app to streamline accessibility and usability became increasingly appealing.

Magnetostatics

With access to the EPFL/ETHz library, I immersed myself in literature on electromagnetism finite element programming. After studying several books, I struck gold with a document that featured code snippets in Fortran. Determined to adapt these insights, I learned basic Fortran and translated the code into Python. This enabled me to visualise the flux density of any objects comprising magnets, coils, and steel components, utilising most basic libraries.

The next phase of my exploration involved the development of essential utilities; a generic geometric tool, a 2D triangular mesher, as well as a solver capable of incorporating saturation effects. As these components began to take shape within the Python environment, my aspirations expanded to include the creation of a user-friendly app.

Construction of FErez from 2022

Geometry

Prior to the initial release of Pyleecan in 2018, I began experimenting with the python API of FEMM, achieving notable success in computing torque and flux linkage for parametrized motors. My inspiration was first fueled by my exposure to MotorCAD (now part of Ansys) at various conferences during my PhD. Subsequently, gaining access to FluxMotor (Altair) through work allowed me to explore a synthesis of Pyleecan, MotorCAD, and FluxMotor, but in my own words.

Mesh

In my pursuit of mesh generation tools, I initially explored translating sophisticated Delaunay meshers like Delaunator into my workflow. However, I encountered challenges in constraining the mesh to complex geometries comprising arcs, segments, and holes. Recognizing the need for a constrained conforming Delaunay triangulation approach, I turned to Triangle by Shewchuk, which is utilized by FEMM. Leveraging the original C code, I realised I could adapt it into Swift using a wrapper function. Subsequently, reading books and articles by Shewchuk, I progressivly ported the relevant sections of the code into Swift.

Magnetostatic solver

I quickly encountered limitations in the basic approach outlined in the books I could find on magnetostatic FEA. Despite their simplicities, the solvers I could find proved insufficiently robust in handling nonlinearities, that are inherent in electromagnetic systems. Additionally, I couldn't find enough guidance on creating a sliding band air gap, which, combined with periodic boundary conditions, is essential for achieving fast computation, precision and optimising memory usage.

To address these challenges, I turned to the codebase of FEMM for insights into advanced solver functionalities. Analysing the code, I identified key functionalities that could enhance the robustness and capability of my solver.

Building upon insights from various research papers, I developed the capability to post-process electromagnetic quantities such as torque, losses, and dqz maps. This mostly involved manipulating magnetic vector potential and flux linkages.

App

Invited in Italy for a wedding close to Ivrea, where I discovered the bar Arduino was named after, I engaged in a lengthy conversation with a fellow guest who happened to be a developer. He introduced me to the world of app development for iPhone using Swift Playgrounds, an experience that piqued my interest. Armed with references from developers like Hudson and Sundell, I delved into this new realm with enthusiasm.

Having prior experience with Qt and TKinter, I found myself comfortable with user interfaces and background tasks. SwiftUI, with its intuitive design, further eased my transition into iOS app development. However, I encountered challenges when it came to plotting meshed flux densities and creating 2D maps - There’s no Swift-Matplotlib! Additionally, performing linear algebra operations presented hurdles - There’s no Swift-Scipy neither!

While the abundance of SwiftUI resources and the release of Swift Charts facilitated plotting tasks, finding solutions for linear algebra proved more daunting. Recognising that Scipy leverages low-level LAPACK functions, I explored Swift's LAPACK and BLAS implementations as potential alternatives. Despite their availability, navigating these libraries and applying them to my specific needs required deeper exploration and experimentation. Through perseverance, I overcame these challenges and gained valuable insights into leveraging Swift's native capabilities for app development.


© Guillaume Verez