Optimum design of ring-shaped rare earth magnets for an ECR ion source