An algorithm with parameterized mesh generation, refinement and morphing is presented for the optimal design of electromagnetic (EM) devices. The method can do without mesh regeneration when changing design parameters, hence a lot of computation time can be saved in finite element (FE) parameter sweeping analysis. When the design parameters change, a new mesh can be obtained immediately with this proposed technique by simply resetting the coordinates of the nodes in the parameterized mesh. For nonlinear problems, a good initial value can be obtained from the solution on the former mesh to facilitate fast convergence of the nonlinear iterations for subsequent computation. An efficient memory procedure dealing with the design parameters and a practical technique allowing for large shape variation are also presented in the proposed method. Based on the objective function values by post-processing the FE results when sweeping certain sampling points in the design space, an optimization problem can be reconstructed using the response surface methodology. The differential evolution method is used as an optimization solver to search for the optimal solution efficiently. The TEAM Workshop Problem 25 is used as an example to showcase the efficiency and effectiveness of the proposed method.