PermanentMagnet

model PermanentMagnet "Permanent magnet model without intrinsic reluctance, represented by magnetic potential difference"
    extends FundamentalWave.Losses.PermanentMagnetLosses;
    extends Modelica.Magnetic.QuasiStatic.FundamentalWave.Interfaces.PartialTwoPort;

    parameter Modelica.SIunits.ComplexMagneticPotentialDifference V_m = Complex(re = 1, im = 0) "Complex magnetic potential difference w.r.t. the rotor fixed reference frame";
    Modelica.SIunits.MagneticPotentialDifference abs_V_m = Modelica.ComplexMath.'abs'(V_m) "Magnitude of complex magnetic potential difference";
    Modelica.SIunits.Angle arg_V_m = Modelica.ComplexMath.arg(V_m) "Argument of complex magnetic potential difference w.r.t. reference frame";
    Modelica.SIunits.Angle gamma "Angle of V_m fixed reference frame";
    Modelica.SIunits.ComplexMagneticFlux Phi "Complex magnetic flux";
    Modelica.SIunits.MagneticPotentialDifference abs_Phi = Modelica.ComplexMath.'abs'(Phi) "Magnitude of complex magnetic flux";
    Modelica.SIunits.Angle arg_Phi = Modelica.ComplexMath.arg(Phi) "Argument of complex magnetic flux";
    Modelica.SIunits.ComplexMagneticPotentialDifference V_mGamma = V_m * Modelica.ComplexMath.fromPolar(1, -gamma) "Magnetic potential difference w.r.t. the reference frame";
equation
    port_p.Phi + port_n.Phi = Complex(0, 0);
    gamma = port_p.reference.gamma;
    port_p.Phi = Phi;
    port_p.V_m - port_n.V_m = V_mGamma;

    annotation (
        defaultComponentName = "magnet",
        Documentation(info = "<html>\n<p>Permanent magnet model with magnetic, mechanical and thermal connector including losses. The PM model is source  of constant magnetic potential difference. The PM loss is calculated by\n<a href=\"modelica://Modelica.Magnetic.QuasiStatic.FundamentalWave.Losses.PermanentMagnetLosses\">PermanentMagnetLosses</a>.\n</p>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = false,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-100, 0}, 
                        {100, 0}},
                    color = {255, 170, 85}), 
                Ellipse(
                    extent = {
                        {-50, 50}, 
                        {50, -50}},
                    lineColor = {255, 170, 85})}));
end PermanentMagnet;