SM_PermanentMagnet

model SM_PermanentMagnet "Permanent magnet synchronous machine with optional damper cage"
    extends Modelica.Magnetic.FundamentalWave.Interfaces.PartialBasicInductionMachine(is(start = zeros(m)), Rs(start = 0.03), Lssigma(start = 0.1 / (2 * pi * fsNominal)), final L0(d = 2 * Lmd / m / effectiveStatorTurns ^ 2, q = 2 * Lmq / m / effectiveStatorTurns ^ 2), redeclare final Modelica.Electrical.Machines.Thermal.SynchronousInductionMachines.ThermalAmbientSMPM thermalAmbient(final useDamperCage = useDamperCage, final Tr = TrOperational, final Tpm = TpmOperational), redeclare final Modelica.Electrical.Machines.Interfaces.InductionMachines.ThermalPortSMPM thermalPort(final useDamperCage = useDamperCage), redeclare final Modelica.Electrical.Machines.Interfaces.InductionMachines.ThermalPortSMPM internalThermalPort(final useDamperCage = useDamperCage), redeclare final Modelica.Electrical.Machines.Interfaces.InductionMachines.PowerBalanceSMPM powerBalance(final lossPowerRotorWinding = damperCageLossPower, final lossPowerRotorCore = 0, final lossPowerPermanentMagnet = permanentMagnet.lossPower));

    parameter Modelica.SIunits.Inductance Lmd(start = 0.3 / (2 * pi * fsNominal)) "Stator main field inductance, d-axis"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            groupImage = "modelica://Modelica/Resources/Images/Electrical/Machines/SMPM.png"));
    parameter Modelica.SIunits.Inductance Lmq(start = 0.3 / (2 * pi * fsNominal)) "Stator main field inductance, q-axis"
        annotation (Dialog(tab = "Nominal resistances and inductances"));
    parameter Boolean useDamperCage(start = true) "Enable/disable damper cage"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage"));
    parameter Modelica.SIunits.Inductance Lrsigmad(start = 0.05 / (2 * pi * fsNominal)) "Rotor leakage inductance, d-axis, w.r.t. stator side"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    parameter Modelica.SIunits.Inductance Lrsigmaq = Lrsigmad "Rotor leakage inductance, q-axis, w.r.t. stator side"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    parameter Modelica.SIunits.Resistance Rrd(start = 0.04) "Rotor resistance, d-axis, w.r.t. stator side"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    parameter Modelica.SIunits.Resistance Rrq = Rrd "Rotor resistance , q-axis, w.r.t. stator side"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    parameter Modelica.SIunits.Temperature TrRef(start = 293.15) "Reference temperature of damper resistances in d- and q-axis"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    parameter Modelica.Electrical.Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start = 0) "Temperature coefficient of damper resistances in d- and q-axis"
        annotation (Dialog(
            tab = "Nominal resistances and inductances",
            group = "Damper cage",
            enable = useDamperCage));
    final parameter Modelica.SIunits.Temperature TpmOperational = 293.15 "Operational temperature of permanent magnet"
        annotation (Dialog(group = "Operational temperatures"));
    parameter Modelica.SIunits.Temperature TrOperational(start = 293.15) "Operational temperature of (optional) damper cage"
        annotation (Dialog(
            group = "Operational temperatures",
            enable = not useThermalPort and useDamperCage));
    parameter Modelica.SIunits.Voltage VsOpenCircuit(start = 112.3) "Open circuit RMS voltage per phase @ fsNominal";
    parameter Modelica.Electrical.Machines.Losses.PermanentMagnetLossParameters permanentMagnetLossParameters(IRef(start = 100), wRef(start = 2 * pi * fsNominal / p)) "Permanent magnet loss parameter record"
        annotation (Dialog(tab = "Losses"));
    Modelica.Blocks.Interfaces.RealOutput ir[2](start = zeros(2), each final quantity = "ElectricCurrent", each final unit = "A") if useDamperCage "Damper cage currents"
        annotation (
            Placement(visible = false),
            Dialog(showStartAttribute = true));
    Modelica.Magnetic.FundamentalWave.Components.Short short if not useDamperCage "Magnetic connection in case the damper cage is not present"
        annotation (Placement(transformation(
            origin = {10, -40},
            extent = {
                {10, 10}, 
                {-10, -10}},
            rotation = 270)));
    Modelica.Magnetic.FundamentalWave.BasicMachines.Components.SaliencyCageWinding rotorCage(final RRef(d = Rrd, q = Rrq), final Lsigma(d = Lrsigmad, q = Lrsigmaq), final effectiveTurns = sqrt(1.5) * effectiveStatorTurns, final useHeatPort = true, final TRef = TrRef, final alpha20 = alpha20r, final TOperational = TrOperational) if useDamperCage "Symmetric rotor cage winding including resistances and stray inductances"
        annotation (Placement(transformation(
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 90,
            origin = {30, -40})));
    Components.PermanentMagnet permanentMagnet(final V_m = Complex(V_mPM, 0), final m = m, final permanentMagnetLossParameters = permanentMagnetLossParameters, final useHeatPort = true, final is = is) "Magnetic potential difference of permanent magnet"
        annotation (Placement(transformation(
            origin = {-10, -40},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 270)));
protected
    final parameter Modelica.SIunits.MagneticPotentialDifference V_mPM = 2 / pi * sqrt(2) * (0.5 * m) * VsOpenCircuit / effectiveStatorTurns / (Lmd / effectiveStatorTurns ^ 2 * 2 * pi * fsNominal) "Equivalent excitation magnetic potential difference";
    Modelica.Blocks.Interfaces.RealOutput damperCageLossPower(final quantity = "Power", final unit = "W") "Damper losses";
equation
    connect(ir,rotorCage.i);
    connect(damperCageLossPower,rotorCage.lossPower);
    if not useDamperCage then 
        damperCageLossPower = 0;
    end if;
    connect(airGap.port_rp,rotorCage.port_n) annotation (Line(
        points = {
            {10, -10}, 
            {10, -30}, 
            {30, -30}},
        color = {255, 128, 0}));
    connect(rotorCage.port_p,permanentMagnet.port_n) annotation (Line(
        points = {
            {30, -50}, 
            {-10, -50}},
        color = {255, 128, 0}));
    connect(rotorCage.heatPortWinding,internalThermalPort.heatPortRotorWinding) annotation (Line(
        points = {
            {40, -40}, 
            {40, -80}, 
            {-40, -80}, 
            {-40, -90}},
        color = {191, 0, 0}));
    connect(short.port_n,airGap.port_rp) annotation (Line(
        points = {
            {10, -30}, 
            {10, -10}},
        color = {255, 128, 0}));
    connect(short.port_p,permanentMagnet.port_n) annotation (Line(
        points = {
            {10, -50}, 
            {-10, -50}},
        color = {255, 128, 0}));
    connect(permanentMagnet.flange,inertiaRotor.flange_b) annotation (Line(points = {
        {0, -40}, 
        {0, -20}, 
        {90, -20}, 
        {90, 0}}));
    connect(permanentMagnet.heatPort,internalThermalPort.heatPortPermanentMagnet) annotation (Line(
        points = {
            {-20, -30}, 
            {-40, -30}, 
            {-40, -90}},
        color = {191, 0, 0}));
    connect(permanentMagnet.port_p,airGap.port_rn) annotation (Line(
        points = {
            {-10, -30}, 
            {-10, -10}},
        color = {255, 128, 0}));
    connect(permanentMagnet.support,airGap.support) annotation (Line(points = {
        {-20, -40}, 
        {-50, -40}, 
        {-50, 0}, 
        {-10, 0}}));

    annotation (
        defaultComponentName = "smpm",
        Icon(graphics = {
            Rectangle(
                extent = {
                    {-130, 10}, 
                    {-100, -10}},
                fillColor = {0, 255, 0},
                fillPattern = FillPattern.Solid), 
            Rectangle(
                extent = {
                    {-100, 10}, 
                    {-70, -10}},
                fillColor = {255, 0, 0},
                fillPattern = FillPattern.Solid), 
            Ellipse(
                extent = {
                    {-134, 34}, 
                    {-66, -34}},
                lineColor = {0, 0, 255})}),
        Documentation(info = "<html>\n<p>\nResistances and stray inductances of the machine refer to an <code>m</code> phase stator. The symmetry of the stator is assumed. For rotor asymmetries can be taken into account by different resistances and stray inductances in the d- and q-axis. The machine models take the following loss effects into account:\n</p>\n\n<ul>\n<li>heat losses in the temperature dependent stator winding resistances</li>\n<li>optional, when enabled: heat losses in the temperature dependent damper cage resistances</li>\n<li>friction losses</li>\n<li>core losses (only eddy current losses, no hysteresis losses)</li>\n<li>stray load losses</li>\n<li>permanent magnet losses</li>\n</ul>\n\n<h4>See also</h4>\n<p>\n<a href=\"modelica://Modelica.Magnetic.FundamentalWave.BasicMachines.SynchronousInductionMachines.SM_ElectricalExcited\">SM_ElectricalExcited</a>,\n<a href=\"modelica://Modelica.Magnetic.FundamentalWave.BasicMachines.SynchronousInductionMachines.SM_ReluctanceRotor\">SM_ReluctanceRotor</a>,\n</p>\n</html>"));
end SM_PermanentMagnet;