main.cpp.save 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // This code shows how to perfom a magnetostatic analysis on a 2D cross-section of a
  2. // rotating PMSM (permanent magnet synchronous) electric motor. The motor torque is
  3. // calculated based on the virtual work principle for an increasing mechanical angle.
  4. //
  5. // Antiperiodicity is used to reduce the computational domain to only 45 degrees of
  6. // the total geometry (the motor has 4 pairs of poles). In order to link the rotor and
  7. // stator domains at their interface a general mortar-based continuity condition is used.
  8. // This allows to work with the non-matching mesh at the interface when the rotor moves.
  9. #include "sparselizardbase.h"
  10. using namespace mathop;
  11. // Input is rotor angular position in degrees. Output is torque in Nm.
  12. double sparselizard(double alpha)
  13. {
  14. // Give names to the physical region numbers :
  15. int rotmagmat = 1, magnet = 2, magnetgap = 3, gaprot = 4, gapstat = 5, statmagmat = 6, windslot = 7, winda = 8, windb = 9, windc = 10;
  16. int gammarot = 11, gammastat = 12, gamma1rot = 13, gamma2rot = 14, gamma1stat = 15, gamma2stat = 16, inarc = 17, outarc = 18;
  17. // Load the rotor and stator mesh without merging the interface. Set verbosity to 0.
  18. mesh mymesh(false, {"rotor.msh", "stator.msh"}, 0);
  19. // Define new physical regions for convenience:
  20. int rotor = regionunion({rotmagmat, magnet, magnetgap, gaprot});
  21. int windings = regionunion({winda, windb, windc});
  22. int stator = regionunion({gapstat, windslot, statmagmat, windings});
  23. int nonmag = regionunion({magnet, magnetgap, gaprot, gapstat, windslot, windings});
  24. int gamma1 = regionunion({gamma1rot,gamma1stat});
  25. int gamma2 = regionunion({gamma2rot,gamma2stat});
  26. int all = regionunion({rotor,stator});
  27. mymesh.rotate(rotor, 0,0,alpha);
  28. // Peak winding current [A] times number of turns:
  29. double Imax = 300;
  30. // Calculate the area of a winding:
  31. double windarea = expression(1).integrate(winda, 5);
  32. // Nodal shape functions 'h1' for the z component of the vector potential.
  33. field az("h1"), x("x"), y("y"), z("z");
  34. // In 2D the vector potential only has a z component:
  35. expression a = array3x1(0,0,az);
  36. // Use interpolation order 2:
  37. az.setorder(all, 2);
  38. // Put a magnetic wall at the inner rotor and outer stator boundaries:
  39. az.setconstraint(inarc);
  40. az.setconstraint(outarc);
  41. // The remanent induction field in the magnet is 0.5 Tesla perpendicular to the magnet:
  42. expression normedradialdirection = array3x1(x,y,0)/sqrt(x*x+y*y);
  43. expression bremanent = 0.5 * normedradialdirection;
  44. // Vacuum magnetic permeability [H/m]:
  45. double mu0 = 4.0*getpi()*1e-7;
  46. // Define the permeability in all regions.
  47. //
  48. // Taking into account saturation and measured B-H curves can be easily done
  49. // by defining an expression based on a 'spline' object (see documentation).
  50. //
  51. parameter mu;
  52. mu|all = 2000.0*mu0;
  53. // Overwrite on non-magnetic regions:
  54. mu|nonmag = mu0;
  55. formulation magnetostatics;
  56. // The strong form of the magnetostatic formulation is curl( 1/mu * curl(a) ) = j, with b = curl(a):
  57. magnetostatics += integral(all, 1/mu* curl(dof(a)) * curl(tf(a)) );
  58. // Add the remanent magnetization of the rotor magnet:
  59. magnetostatics += integral(magnet, -1/mu* bremanent * curl(tf(a)));
  60. // Add the current density source js [A/m2] in the z direction in the stator windings.
  61. // A three-phased actuation is used. The currents are dephased by the mechanical angle
  62. // times the number of pole pairs. This gives a stator field rotating at synchronous speed.
  63. // Change the phase (degrees) to tune the electric angle:
  64. double phase = 0;
  65. parameter jsz;
  66. jsz|winda = Imax/windarea * sin( (phase + 4.0*alpha - 0.0) * getpi()/180.0);
  67. jsz|windb = Imax/windarea * sin( (phase + 4.0*alpha - 60.0) * getpi()/180.0);
  68. jsz|windc = Imax/windarea * sin( (phase + 4.0*alpha - 120.0) * getpi()/180.0);
  69. magnetostatics += integral(windings, -array3x1(0,0,jsz) * tf(a));
  70. // Rotor-stator continuity condition (including antiperiodicity settings with factor '-1'):
  71. magnetostatics += continuitycondition(gammastat, gammarot, az, az, {0,0,0}, alpha, 45.0, -1.0);
  72. // Rotor and stator antiperiodicity condition:
  73. magnetostatics += periodicitycondition(gamma1, gamma2, az, {0,0,0}, {0,0,45.0}, -1.0);
  74. solve(magnetostatics);
  75. az.write(all, "a"+std::to_string((int)alpha)+".vtu", 2);
  76. curl(a).write(all, "b"+std::to_string((int)alpha)+".vtu", 2);
  77. // The magnetostatic force acting on the motor is computed below.
  78. // This field will hold the x and y component of the magnetic forces:
  79. field magforce("h1xy");
  80. // The magnetic force is projected on field 'magforce' on the solid stator region.
  81. // This is done with a formulation of the type dof*tf - force calculation = 0.
  82. formulation forceprojection;
  83. forceprojection += integral(statmagmat, dof(magforce)*tf(magforce));
  84. forceprojection += integral(stator, - predefinedmagnetostaticforce(tf(magforce, statmagmat), 1/mu*curl(a), mu));
  85. solve(forceprojection);
  86. // Calculate the torque:
  87. expression leverarm = array3x1(x,y,0);
  88. double torque = compz(crossproduct(leverarm, magforce)).integrate(statmagmat, 5);
  89. // The torque has to be scaled to the actual motor z length (50 mm) and multiplied
  90. // by 8 to take into account the full 360 degrees of the motor.
  91. // A minus sign gives the torque on the rotor (opposite sign than the stator torque).
  92. torque = - torque * 8.0 * 0.05;
  93. return torque;
  94. }
  95. int main(void)
  96. {
  97. SlepcInitialize(0,{},0,0);
  98. wallclock clk;
  99. double torque;
  100. std::cout << "Mechanical angle [degrees] and torque [Nm]:" << std::endl;
  101. for (double alpha = 0.0; alpha <= 45.0; alpha += 1.0)
  102. {
  103. torque = sparselizard(alpha);
  104. std::cout << alpha << " " << torque << std::endl;
  105. }
  106. clk.print("Total run time:");
  107. SlepcFinalize();
  108. // Code validation line. Can be removed:
  109. std::cout << (torque < 3.58709 && torque > 3.58707);
  110. return 0;
  111. }