A moving meshing algorithm with mesh adaptive size function was proposed in this paper with regard to the modeling speed and solution accuracy of electromagnetic equipment in the optimization design process. In the proposed method, a mesh size function that considers curvature, feature size, and distance gradient restrictions is constructed, which can obtain high quality meshes and avoid excessive iteration; when the finite element mesh domain is deformed, only the mesh nodes close to the moving boundary are allowed to move, and the theory of force-balance is used combined with the second-order boundary projection algorithm to perform iterative optimization of the mesh node positions. The proposed method has the advantages of keeping the original mesh structure and minimum mesh deformation as well as speed up the convergence, save time in the finite element meshing, and ensure the quality of the generated mesh. Then, the proposed method was applied to a 37 kw motor for electromagnetic analysis, and the results obtained proved the accuracy of the algorithm; finally, the effectiveness of the mesh movement algorithm in three-dimensional space was tested by moving the sphere inside the cylinder.