MultiSensor

model MultiSensor "Multiphase sensor to measure current, voltage and power"
    import Modelica.ComplexMath.conj;
    import Modelica.ComplexMath.'sum';
    import Modelica.ComplexMath.'abs';
    import Modelica.ComplexMath.arg;

    extends Modelica.Icons.RotationalSensor;

    parameter Integer m(min = 1) = 3 "Number of phases";
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug pc(final m = m) "Positive plug, current path"
        annotation (Placement(transformation(extent = {
            {-90, -10}, 
            {-110, 10}})));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.NegativePlug nc(final m = m) "Negative plug, current path"
        annotation (Placement(transformation(extent = {
            {110, -10}, 
            {90, 10}})));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug pv(final m = m) "Positive plug, voltage path"
        annotation (Placement(transformation(extent = {
            {-10, 110}, 
            {10, 90}})));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.NegativePlug nv(final m = m) "Negative plug, voltage path"
        annotation (Placement(transformation(extent = {
            {10, -110}, 
            {-10, -90}})));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput i[m](redeclare each final Modelica.SIunits.Current re, redeclare each final Modelica.SIunits.Current im) "Current as complex output signal"
        annotation (Placement(transformation(
            origin = {-60, -110},
            extent = {
                {10, 10}, 
                {-10, -10}},
            rotation = 90)));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput v[m](redeclare each final Modelica.SIunits.Voltage re, redeclare each final Modelica.SIunits.Voltage im) "Voltage as complex output signal"
        annotation (Placement(transformation(
            origin = {60, -110},
            extent = {
                {10, 10}, 
                {-10, -10}},
            rotation = 90)));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower[m](redeclare each final Modelica.SIunits.ActivePower re, redeclare each final Modelica.SIunits.ReactivePower im) "Instantaneous apparent power as complex output signal"
        annotation (Placement(transformation(
            origin = {-110, -60},
            extent = {
                {-10, 10}, 
                {10, -10}},
            rotation = 180)));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPowerTotal(redeclare final Modelica.SIunits.ActivePower re, redeclare final Modelica.SIunits.ReactivePower im) "Sum of instantaneous apparent power as complex output signal"
        annotation (Placement(transformation(
            origin = {110, -60},
            extent = {
                {10, 10}, 
                {-10, -10}},
            rotation = 180)));
    output Modelica.SIunits.Current abs_i[m] = 'abs'(i) "Absolute of complex currents";
    output Modelica.SIunits.Angle arg_i[m] = arg(i) "Argument of complex currents";
    output Modelica.SIunits.Voltage abs_v[m] = 'abs'(v) "Absolute of complex voltages";
    output Modelica.SIunits.Angle arg_v[m] = arg(v) "Argument of complex voltages";
    output Modelica.SIunits.ApparentPower abs_apparentPower[m] = 'abs'(apparentPower) "Absolute of complex apparent power signals";
    output Modelica.SIunits.Angle arg_apparentPower[m] = arg(apparentPower) "Argument of complex apparent power signals";
    output Modelica.SIunits.ApparentPower abs_apparentPowerTotal = 'abs'(apparentPowerTotal) "Absolute of sum complex apparent power";
    output Modelica.SIunits.Angle arg_apparentPowerTotal = arg(apparentPowerTotal) "Argument of sum complex apparent power";
equation
    Connections.branch(pc.reference, nc.reference);
    Connections.branch(pc.reference, pv.reference);
    Connections.branch(pv.reference, nv.reference);
    pc.pin.i + nc.pin.i = fill(Complex(0), m);
    i = pc.pin.i;
    v = pv.pin.v - nv.pin.v;
    apparentPower = v .* conj(i);
    apparentPowerTotal = Complex(sum(apparentPower.re), sum(apparentPower.im));
    nv.pin.i = fill(Complex(0), m);
    pc.reference.gamma = nc.reference.gamma;
    pc.reference.gamma = pv.reference.gamma;
    pv.pin.i = fill(Complex(0), m);
    pv.reference.gamma = nv.reference.gamma;
    pc.pin.v - nc.pin.v = fill(Complex(0), m);

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {0, 100}, 
                        {0, 70}},
                    color = {85, 170, 255}), 
                Line(
                    points = {
                        {0, -70}, 
                        {0, -100}},
                    color = {85, 170, 255}), 
                Line(
                    points = {
                        {-100, 0}, 
                        {100, 0}},
                    color = {85, 170, 255}), 
                Line(points = {
                    {0, 70}, 
                    {0, 40}}), 
                Line(
                    points = {
                        {-100, -60}, 
                        {-80, -60}, 
                        {-56, -42}},
                    color = {85, 170, 255}), 
                Line(
                    points = {
                        {-60, -100}, 
                        {-60, -80}, 
                        {-42, -56}},
                    color = {85, 170, 255}), 
                Line(
                    points = {
                        {60, -100}, 
                        {60, -80}, 
                        {42, -56}},
                    color = {85, 170, 255}), 
                Text(
                    extent = {
                        {-100, -40}, 
                        {-60, -80}},
                    textString = "s"), 
                Text(
                    extent = {
                        {-80, -60}, 
                        {-40, -100}},
                    textString = "i"), 
                Text(
                    extent = {
                        {40, -60}, 
                        {80, -100}},
                    textString = "v"), 
                Line(
                    points = {
                        {100, -60}, 
                        {80, -60}, 
                        {56, -42}},
                    color = {85, 170, 255}), 
                Text(
                    extent = {
                        {-150, 110}, 
                        {150, 150}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}),
        Documentation(
            info = "<html>\n<p>This multi sensor measures currents, voltages and instantaneous electrical power of a multiphase system and has separated voltage and current paths.\nThe plugs of the voltage paths are pv and nv, the plugs of the current paths are pc and nc.\nThe internal resistance of each current path is zero, the internal resistance of each voltage path is infinite.</p>\n\n<h4>See also</h4>\n\n<p>\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.MultiSensor\">SinglePhase.Sensors.MultiSensor</a>\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.ReferenceSensor\">ReferenceSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.FrequencySensor\">FrequencySensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.PotentialSensor\">PotentialSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.VoltageSensor\">VoltageSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.VoltageQuasiRMSSensor\">VoltageQuasiRMSSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.CurrentSensor\">CurrentSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.CurrentQuasiRMSSensor\">CurrentQuasiRMSSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.MultiPhase.Sensors.PowerSensor\">PowerSensor</a>\n</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em>20170306</em> first implementation by Anton Haumer</li>\n</ul>\n</html>"));
end MultiSensor;