MultiSensor

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

    extends Modelica.Icons.RotationalSensor;

    Modelica.Electrical.QuasiStationary.SinglePhase.Interfaces.PositivePin pc "Positive pin, current path"
        annotation (Placement(transformation(extent = {
            {-90, -10}, 
            {-110, 10}})));
    Modelica.Electrical.QuasiStationary.SinglePhase.Interfaces.NegativePin nc "Negative pin, current path"
        annotation (Placement(transformation(extent = {
            {110, -10}, 
            {90, 10}})));
    Modelica.Electrical.QuasiStationary.SinglePhase.Interfaces.PositivePin pv "Positive pin, voltage path"
        annotation (Placement(transformation(extent = {
            {-10, 110}, 
            {10, 90}})));
    Modelica.Electrical.QuasiStationary.SinglePhase.Interfaces.NegativePin nv "Negative pin, voltage path"
        annotation (Placement(transformation(extent = {
            {10, -110}, 
            {-10, -90}})));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput i(redeclare final Modelica.SIunits.Current re, redeclare final Modelica.SIunits.Current im) "Current as complex output signal"
        annotation (Placement(
            transformation(
                origin = {-60, -110},
                extent = {
                    {10, 10}, 
                    {-10, -10}},
                rotation = 90),
            iconTransformation(
                extent = {
                    {10, 10}, 
                    {-10, -10}},
                rotation = 90,
                origin = {-60, -110})));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput v(redeclare final Modelica.SIunits.Voltage re, redeclare final Modelica.SIunits.Voltage im) "Voltage as complex output signal"
        annotation (Placement(
            transformation(
                origin = {60, -110},
                extent = {
                    {10, 10}, 
                    {-10, -10}},
                rotation = 90),
            iconTransformation(
                extent = {
                    {10, 10}, 
                    {-10, -10}},
                rotation = 90,
                origin = {60, -110})));
    Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower(redeclare final Modelica.SIunits.ActivePower re, redeclare 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),
            iconTransformation(
                extent = {
                    {-10, 10}, 
                    {10, -10}},
                rotation = 180,
                origin = {-110, -60})));
    output Modelica.SIunits.Current abs_i = 'abs'(i) "Absolute of complex current";
    output Modelica.SIunits.Angle arg_i = arg(i) "Argument of complex current";
    output Modelica.SIunits.Voltage abs_v = 'abs'(v) "Absolute of complex voltage";
    output Modelica.SIunits.Angle arg_v = arg(v) "Argument of complex voltage";
    output Modelica.SIunits.ApparentPower abs_apparentPower = 'abs'(apparentPower) "Absolute of complex apparent power";
    output Modelica.SIunits.Angle arg_apparentPower = arg(apparentPower) "Argument of complex apparent power";
equation
    Connections.branch(pc.reference, nc.reference);
    Connections.branch(pc.reference, pv.reference);
    Connections.branch(pv.reference, nv.reference);
    pc.i + nc.i = Complex(0);
    i = pc.i;
    v = pv.v - nv.v;
    apparentPower = v * conj(i);
    nv.i = Complex(0);
    pv.i = Complex(0);
    pc.reference.gamma = nc.reference.gamma;
    pc.reference.gamma = pv.reference.gamma;
    pv.reference.gamma = nv.reference.gamma;
    pc.v - nc.v = Complex(0);

    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}}), 
                Text(
                    extent = {
                        {-150, 110}, 
                        {150, 150}},
                    textString = "%name",
                    lineColor = {0, 0, 255}), 
                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")}),
        Documentation(
            info = "<html>\n<p>This multi sensor measures current, voltage and instantaneous electrical power of a singlephase system and has a separated voltage and current path.\nThe pins of the voltage path are pv and nv, the pins of the current path are pc and nc.\nThe internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.</p>\n\n<h4>See also</h4>\n\n<p>\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.ReferenceSensor\">ReferenceSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.FrequencySensor\">FrequencySensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.PotentialSensor\">PotentialSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.VoltageSensor\">VoltageSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.Sensors.CurrentSensor\">CurrentSensor</a>,\n<a href=\"modelica://Modelica.Electrical.QuasiStationary.SinglePhase.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;