This example shows how to solve a simple surface-mounted permanent magnet (SPM) motor model using 2D finite element method (FEM) from scratch, including element analysis, assembling matrix, modifying right-hand-side terms based on excitations and boundary conditions, solving the matrix, postprocessing field results, and how to create an application (.exe file) using MATLAB GUIDE, which will be replaced by App Designer introduced in 2016a. It can be used as a general tutorial guide for FE programming to solve 2D magnetostatic problems in PM electric machines for undergraduate and graduate students in electrical engineering, as well as electrical engineers.
Main steps are:
- Using MATLAB PDE Toolbox to create the 2D cross-sectional geometry of the motor and generate the mesh. The meshed geometry can be exported into (p,e,t) triple data format.
- Creating an application that can read (p,e,t) data, plotting the geometry, visualizing the mesh, solving the problem, and viewing the field results.
- Deploying the App in standalone mode in computers that do not have MATLAB installed.
Type pdetool in MATLAB command line prompt to open the PDE Toolkit window (available in MATLAB 2017a). Click on File -> Open and select Geometry_V2.m to open the motor cross-sectional geometry. In later versions, the PDE Toolkit has been replaced by PDE Modeler or Partial Differential Equation Toolbox. The [p,e,t] triple data can be obtained by meshToPet. More information about this command line can be found: https://www.mathworks.com/help/pde/ug/pde.femesh.meshtopet.html
Go to the Boundary mode and check "show labels for edges" and "show labels for subdomains". It is shown that Subdomain 1 is for the stator core, Subdomain 2 for rotor core, Subdomain 3 for air and Subdomain 4 for permanent magnet. Edges 31-33 and 73-75 are for flux tangential boundary conditions.
Go to the Mesh mode, and the initial mesh can be generated. We can refine the mesh if needed.
We can also check the mesh quality. The meshed geometry can be exported into (p,e,t) triple data format. The (p,e,t) triple data is saved in three separate data files -- p.mat, e.mat and t.mat.
Type the following command in MATLAB command line prompt to compile .m files into a single application MotorSolve.exe:
mcc -m MotorSolve.m Element_Analysis.m Assemble.m Is_In.m NodeOnEdge.m SameSide.m Calc_B.m
Three additional files will be generated at the same time -- mccExcludedFiles.log, readme.txt, and requiredMCRProducts.txt.
The final application will look like:









