Polyphase variable admittance. The admittance model represents a parallel connection of a resistor and either a capacitor or inductor
in each phase.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableAdmittance "Polyphase variable admittance"
  extends Interfaces.TwoPlug;
  parameter SI.Temperature T_ref[m]=fill(293.15, m)
    "Reference temperatures";
  parameter SI.LinearTemperatureCoefficient alpha_ref[m]=zeros(m)
    "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(final mh=m, T=T_ref);
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  Modelica.ComplexBlocks.Interfaces.ComplexInput Y_ref[m]
    "Variable complex admittances"
  SinglePhase.Basic.VariableAdmittance variableImpedance[m](
    final T_ref=T_ref,
    final alpha_ref=alpha_ref,
    each final useHeatPort=useHeatPort,
    final T=T,
    final frequencyDependent=fill(frequencyDependent, m),
    final f_ref=fill(f_ref, m))
equation
  connect(variableImpedance.pin_p, plugToPins_p.pin_p)
  connect(variableImpedance.pin_n, plugToPins_n.pin_n)
  connect(variableImpedance.heatPort, heatPort)
  connect(Y_ref, variableImpedance.Y_ref)
end VariableAdmittance;


Polyphase variable capacitor. The linear capacitors connect the complex currents i with the complex
voltages v by v*j*ω*C = i,
using m single-phase variable Capacitors.
The capacitances C are given as m input signals.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableCapacitor "Polyphase variable capacitor"
  extends Interfaces.TwoPlug;
  Modelica.Blocks.Interfaces.RealInput C[m](each unit="F")
    "Variable capacitance"
  QuasiStatic.SinglePhase.Basic.VariableCapacitor variableCapacitor[m]
equation
  connect(variableCapacitor.pin_p, plugToPins_p.pin_p)
  connect(variableCapacitor.pin_n, plugToPins_n.pin_n)
  connect(C, variableCapacitor.C)
end VariableCapacitor;


Polyphase variable conductor. The linear resistors connect the complex currents i with the complex
voltages v by v*G = i,
using m single-phase variable Conductors.
The conductances G are given as m input signals.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableConductor "Polyphase variable conductor"
  extends Interfaces.TwoPlug;
  parameter SI.Temperature T_ref[m]=fill(293.15, m)
    "Reference temperatures";
  parameter SI.LinearTemperatureCoefficient alpha_ref[m]=
      zeros(m)
    "Temperature coefficient of resistance (G_actual = G_ref/(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, T=T_ref);
  Modelica.Blocks.Interfaces.RealInput G_ref[m](each unit="S")
    "Variable conductance"
  QuasiStatic.SinglePhase.Basic.VariableConductor variableConductor[m](
    final T_ref=T_ref,
    final alpha_ref=alpha_ref,
    each final useHeatPort=useHeatPort,
    final T=T)
equation
  connect(variableConductor.pin_p, plugToPins_p.pin_p)
  connect(variableConductor.pin_n, plugToPins_n.pin_n)
  connect(variableConductor.heatPort, heatPort)
  connect(G_ref, variableConductor.G_ref)
end VariableConductor;


Polyphase variable impedance. The impedance model represents a series connection of a resistor and either an inductor or capacitor
in each phase.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableImpedance "Polyphase variable impedance"
  extends Interfaces.TwoPlug;
  parameter SI.Temperature T_ref[m]=fill(293.15, m)
    "Reference temperatures";
  parameter SI.LinearTemperatureCoefficient alpha_ref[m]=zeros(m)
    "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(final mh=m, T=T_ref);
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  Modelica.ComplexBlocks.Interfaces.ComplexInput Z_ref[m]
    "Variable complex impedances"
  SinglePhase.Basic.VariableImpedance variableImpedance[m](
    final T_ref=T_ref,
    final alpha_ref=alpha_ref,
    each final useHeatPort=useHeatPort,
    final T=T,
    final frequencyDependent=fill(frequencyDependent, m),
    final f_ref=fill(f_ref, m))
equation
  connect(variableImpedance.pin_p, plugToPins_p.pin_p)
  connect(variableImpedance.pin_n, plugToPins_n.pin_n)
  connect(variableImpedance.heatPort, heatPort)
  connect(variableImpedance.Z_ref, Z_ref)
end VariableImpedance;


Polyphase variable inductor. The linear inductors connect the complex voltages v with the complex
currents i by i*j*ω*L = v,
using m single-phase variable Inductors.
The inductances L are given as m input signals.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableInductor "Polyphase variable inductor"
  extends Interfaces.TwoPlug;
  Modelica.Blocks.Interfaces.RealInput L[m](each unit="H")
    "Variable inductance"
  QuasiStatic.SinglePhase.Basic.VariableInductor variableInductor[m]
equation
  connect(variableInductor.pin_p, plugToPins_p.pin_p)
  connect(variableInductor.pin_n, plugToPins_n.pin_n)
  connect(variableInductor.L, L)
end VariableInductor;


Polyphase variable resistor. The linear resistors connect the complex voltages v with the complex
currents i by i*R = v,
using m single-phase variable Resistors.
The resistances R are given as m input signals.

within Modelica.Electrical.QuasiStatic.Polyphase.Basic;
model VariableResistor "Polyphase variable resistor"
  extends Interfaces.TwoPlug;
  parameter SI.Temperature T_ref[m]=fill(293.15, m)
    "Reference temperatures";
  parameter SI.LinearTemperatureCoefficient alpha_ref[m]=
      zeros(m)
    "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, T=T_ref);
  Modelica.Blocks.Interfaces.RealInput R_ref[m](each unit="Ohm")
    "Variable resistance"
  QuasiStatic.SinglePhase.Basic.VariableResistor variableResistor[m](
    final T_ref=T_ref,
    final alpha_ref=alpha_ref,
    each final useHeatPort=useHeatPort,
    final T=T)
equation

  connect(variableResistor.pin_p, plugToPins_p.pin_p)
  connect(variableResistor.pin_n, plugToPins_n.pin_n)
  connect(variableResistor.heatPort, heatPort)
  connect(R_ref, variableResistor.R_ref)
end VariableResistor;


Conversion: space phasor -> m phase. Transformation of space phasor to m phase values (voltages or currents).

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block FromSpacePhasor "Conversion: space phasor -> m phase"
  extends Modelica.Blocks.Icons.Block;
  import Modelica.ComplexMath.j;
  import Modelica.ComplexMath.exp;
  parameter Integer m(min=1) = 3 "Number of phases"
  Modelica.Blocks.Interfaces.RealInput u[2]
  Modelica.ComplexBlocks.Interfaces.ComplexOutput y[m]
protected
  parameter SI.Angle phi[m]=
      Modelica.Electrical.Polyphase.Functions.symmetricOrientation(
                                                          m);
equation
  y = {Complex(u[1], u[2])*exp(-j*phi[k])/sqrt(2) for k in 1:m};
end FromSpacePhasor;


Creates quasi-static phasors from symmetrical components. Calculates the time phasors from the symmetric components according to Charles L. Fortescue.

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block FromSymmetricalComponents
  "Creates quasi-static phasors from symmetrical components"
  extends Modelica.ComplexBlocks.Interfaces.ComplexMIMOs(final n=m,final useConjugateInput=fill(false,m));
  import Modelica.ComplexMath.abs;
  import Modelica.ComplexMath.arg;
  parameter Integer m=3 "Number of phases"
  output Real abs_u[m] = abs(u) "Absolute of input";
  output SI.Angle arg_u[m](displayUnit="deg") = arg(u)
    "Argument of input";
  output Real abs_y[m] = abs(y) "Absolute of output";
  output SI.Angle arg_y[m](displayUnit="deg") = arg(y)
    "Argument of output";
protected
  final parameter Complex sbTM[m,m]=
    Modelica.Electrical.Polyphase.Functions.symmetricBackTransformationMatrix(m);
equation
  // Symmetrical components (preferred): y = sbTM*u;
  for j in 1:m loop
    y[j] = Complex(sum({sbTM[j,k].re*u[k].re - sbTM[j,k].im*u[k].im for k in 1:m}),
                   sum({sbTM[j,k].re*u[k].im + sbTM[j,k].im*u[k].re for k in 1:m}));
  end for;
end FromSymmetricalComponents;


within Modelica.Electrical.QuasiStatic.Polyphase;
package Blocks "Blocks for quasi-static polyphase systems"
  extends Modelica.Icons.Package;
end Blocks;


Number of phases. This block determines the continuous quasi RMS value of a polyphase system, representing an equivalent RMS vector or phasor.

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block QuasiRMS
  extends Modelica.Blocks.Interfaces.SO;
  parameter Integer m(min=2) = 3 "Number of phases"
  Modelica.ComplexBlocks.Interfaces.ComplexInput u[m]
equation
  y = QuasiStatic.Polyphase.Functions.quasiRMS(u);
end QuasiRMS;


Extends complex phase signal to complex polyphase signals using symmetricOrientation. This function propagates the input phasor to m output phasors with symmetricOrientation.

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block SingleToPolyphase
  "Extends complex phase signal to complex polyphase signals using symmetricOrientation"
  extends Modelica.ComplexBlocks.Interfaces.ComplexSIMO(final nout=m,final useConjugateInput=false);
  parameter Integer m=3 "Number of phases"
equation
  y = u*Modelica.ComplexMath.fromPolar(fill(1, m), -
    Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m));
end SingleToPolyphase;


Creates symmetrical components from signals representing quasi-static phasors. Calculates the symmetric components according to Charles L. Fortescue from the time phasors.

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block SymmetricalComponents
  "Creates symmetrical components from signals representing quasi-static phasors"
  extends Modelica.ComplexBlocks.Interfaces.ComplexMIMOs(final n=m,final useConjugateInput=fill(false,m));
  import Modelica.ComplexMath.abs;
  import Modelica.ComplexMath.arg;
  parameter Integer m=3 "Number of phases"
  output Real abs_u[m] = abs(u) "Absolute of input";
  output SI.Angle arg_u[m](each displayUnit="deg") = arg(u)
    "Argument of input";
  output Real abs_y[m] = abs(y) "Absolute of output";
  output SI.Angle arg_y[m](each displayUnit="deg") = arg(y)
    "Argument of output";
protected
  final parameter Complex sTM[m,m]=
    Modelica.Electrical.Polyphase.Functions.symmetricTransformationMatrix(
                                                                 m);
equation
  // Symmetrical components (preferred): y = sTM*u;
  for j in 1:m loop
    y[j] = Complex(sum({sTM[j,k].re*u[k].re - sTM[j,k].im*u[k].im for k in 1:m}),
                   sum({sTM[j,k].re*u[k].im + sTM[j,k].im*u[k].re for k in 1:m}));
  end for;
end SymmetricalComponents;


Conversion: m phase -> space phasor. Transformation of m phase values (voltages or currents) to space phasor.

within Modelica.Electrical.QuasiStatic.Polyphase.Blocks;
block ToSpacePhasor "Conversion: m phase -> space phasor"
  extends Modelica.Blocks.Icons.Block;
  // import Modelica.ComplexMath.j;
  // import Modelica.ComplexMath.exp;
  // import Modelica.ComplexMath.sum;
  // The import of sum goes along with the original complex equation:
  // c = sqrt(2)/m*sum({u[k]*exp(j*phi[k]) for k in 1:m});
  parameter Integer m(min=1) = 3 "Number of phases"
  Modelica.ComplexBlocks.Interfaces.ComplexInput u[m]
  Modelica.Blocks.Interfaces.RealOutput y[2]
protected
  parameter SI.Angle phi[m]=
      Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m);
  Complex c;
equation
  // c = sqrt(2)/m*sum({u[k]*exp(j*phi[k]) for k in 1:m});
  // Alternative implementation due to https://trac.openmodelica.org/OpenModelica/ticket/4496
  c.re = sqrt(2)/m*sum(u[k].re*cos(phi[k])-u[k].im*sin(phi[k]) for k in 1:m);
  c.im = sqrt(2)/m*sum(u[k].re*sin(phi[k])+u[k].im*cos(phi[k]) for k in 1:m);
  y = {c.re,c.im};
end ToSpacePhasor;


Balancing an unsymmetrical delta-connected load. For the unsymmetrical load (resistor, capacitor and inductor) the parameters inductance L and capacitance C
are chosen such way that the magnitudes of the three-phase currents (see currentSensor12, currentSensor23, currentSensor31) are equal.

within Modelica.Electrical.QuasiStatic.Polyphase.Examples;
model BalancingDelta "Balancing an unsymmetrical delta-connected load"
  extends Modelica.Icons.Example;
  parameter Integer m=3 "Number of phases"
  parameter SI.Voltage V_LL=100 "Source voltage line-to-line";
  parameter SI.Frequency f=50 "Source frequency";
  parameter SI.Resistance R=10 "Load resistance";
  parameter SI.Inductance L=(R*sqrt(3))/(2*Modelica.Constants.pi*f)
    "Load inductance";
  parameter SI.Capacitance C=1/(R*sqrt(3))/(2*Modelica.Constants.pi*f)
    "Load capacitance";
  output SI.ComplexCurrent i[m]={resistor.i, inductor.i, capacitor.i}
    "Phase currents";
  QuasiStatic.Polyphase.Sources.VoltageSource voltageSource(
    m=m,
    f=f,
    V=fill(V_LL, m),
    phi=-Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m),
    gamma(fixed=true, start=0))
  QuasiStatic.Polyphase.Basic.Star star(m=m)
  QuasiStatic.SinglePhase.Basic.Ground ground
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p1(m=m, k=1)
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p2(k=2, m=m)
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p3(k=3, m=m)
  QuasiStatic.Polyphase.Sensors.PowerSensor powerSensor(m=m)
  QuasiStatic.Polyphase.Sensors.CurrentSensor currentSensor(m=m)
  QuasiStatic.SinglePhase.Basic.Resistor resistor(R_ref=R)
  QuasiStatic.SinglePhase.Basic.Capacitor capacitor(C=C)
  QuasiStatic.SinglePhase.Basic.Inductor inductor(L=L)
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor12
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor23
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor31
  Modelica.ComplexBlocks.ComplexMath.ComplexToPolar complexToPolar[m]
equation
  connect(ground.pin, star.pin_n)
  connect(star.plug_p, voltageSource.plug_n)
  connect(voltageSource.plug_p, powerSensor.currentP)
  connect(powerSensor.currentP, powerSensor.voltageP)
  connect(powerSensor.currentN, currentSensor.plug_p)
  connect(powerSensor.voltageN, star.plug_p)
  connect(currentSensor.plug_n, plugToPin_p2.plug_p)
  connect(currentSensor.plug_n, plugToPin_p1.plug_p)
  connect(currentSensor.plug_n, plugToPin_p3.plug_p)
  connect(currentSensor12.pin_p, plugToPin_p1.pin_p)
  connect(currentSensor12.pin_n, capacitor.pin_p)
  connect(capacitor.pin_n, plugToPin_p2.pin_p)
  connect(plugToPin_p2.pin_p, currentSensor23.pin_p)
  connect(currentSensor23.pin_n, inductor.pin_p)
  connect(inductor.pin_n, plugToPin_p3.pin_p)
  connect(plugToPin_p1.pin_p, resistor.pin_n)
  connect(resistor.pin_p, currentSensor31.pin_n)
  connect(currentSensor31.pin_p, plugToPin_p3.pin_p)
  connect(currentSensor.i, complexToPolar.u)
end BalancingDelta;


Balancing an unsymmetrical star-connected load. For the unsymmetrical load (resistor, capacitor and inductor) the parameters inductance L and capacitance C
are chosen such way that the neutral current (see currentSensor0) is zero.

within Modelica.Electrical.QuasiStatic.Polyphase.Examples;
model BalancingStar "Balancing an unsymmetrical star-connected load"
  extends Modelica.Icons.Example;
  constant Integer m=3 "Number of phases";
  parameter SI.Voltage V=100 "Source Voltage";
  parameter SI.Frequency f=50 "Source frequency";
  parameter SI.Resistance R=10 "Load resistance";
  parameter SI.Inductance L=(R*sqrt(3))/(2*Modelica.Constants.pi*f)
    "Load inductance";
  parameter SI.Capacitance C=1/(R*sqrt(3))/(2*Modelica.Constants.pi*f)
    "Load capacitance";
  output SI.ComplexCurrent i[m]={resistor.i, inductor.i, capacitor.i}
    "Phase currents";
  QuasiStatic.Polyphase.Sources.VoltageSource voltageSource(
    m=m,
    f=f,
    V=fill(V, m),
    phi=-Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m),
    gamma(fixed=true, start=0))
  QuasiStatic.Polyphase.Basic.Star star(m=m)
  QuasiStatic.SinglePhase.Basic.Ground ground
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p1(m=m, k=1)
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p2(k=2, m=m)
  QuasiStatic.Polyphase.Basic.PlugToPin_p plugToPin_p3(k=3, m=m)
  QuasiStatic.Polyphase.Sensors.PowerSensor powerSensor(m=m)
  QuasiStatic.Polyphase.Sensors.CurrentSensor currentSensor(m=m)
  QuasiStatic.SinglePhase.Basic.Resistor resistor(R_ref=R)
  QuasiStatic.SinglePhase.Basic.Capacitor capacitor(C=C)
  QuasiStatic.SinglePhase.Basic.Inductor inductor(L=L)
  QuasiStatic.Polyphase.Basic.Star star2(m=m)
  QuasiStatic.Polyphase.Basic.PlugToPin_n plugToPin_n1(m=m, k=1)
  QuasiStatic.Polyphase.Basic.PlugToPin_n plugToPin_n2(k=2, m=m)
  QuasiStatic.Polyphase.Basic.PlugToPin_n plugToPin_n3(k=3, m=m)
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor0
  Modelica.ComplexBlocks.ComplexMath.ComplexToPolar complexToPolar[m]
equation
  connect(ground.pin, star.pin_n)
  connect(star.plug_p, voltageSource.plug_n)
  connect(voltageSource.plug_p, powerSensor.currentP)
  connect(powerSensor.currentN, currentSensor.plug_p)
  connect(powerSensor.voltageP, powerSensor.currentP)
  connect(powerSensor.voltageN, star.plug_p)
  connect(currentSensor.plug_n, plugToPin_p2.plug_p)
  connect(currentSensor.plug_n, plugToPin_p3.plug_p)
  connect(currentSensor.plug_n, plugToPin_p1.plug_p)
  connect(plugToPin_p1.pin_p, inductor.pin_p)
  connect(plugToPin_p2.pin_p, capacitor.pin_p)
  connect(plugToPin_p3.pin_p, resistor.pin_p)
  connect(inductor.pin_n, plugToPin_n1.pin_n)
  connect(capacitor.pin_n, plugToPin_n2.pin_n)
  connect(resistor.pin_n, plugToPin_n3.pin_n)
  connect(plugToPin_n1.plug_n, star2.plug_p)
  connect(plugToPin_n2.plug_n, star2.plug_p)
  connect(plugToPin_n3.plug_n, star2.plug_p)
  connect(star2.pin_n, currentSensor0.pin_p)
  connect(currentSensor0.pin_n, star.pin_n)
  connect(currentSensor.i, complexToPolar.u)
end BalancingStar;


Test examples

within Modelica.Electrical.QuasiStatic.Polyphase;
package Examples "Test examples"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Number of phases. Test quasi-static polyphase sensors: A sinusoidal source feeds a load consisting of resistor and inductor.

within Modelica.Electrical.QuasiStatic.Polyphase.Examples;
model TestSensors
  extends Modelica.Icons.Example;
  constant Integer m=3 "Number of phases";
  import Modelica.Constants.pi;
  parameter SI.Voltage VRMS=100
    "Nominal RMS voltage per phase";
  parameter SI.Frequency f=50 "Frequency";
  parameter SI.Resistance R=1/sqrt(2) "Load resistance";
  parameter SI.Inductance L=1/sqrt(2)/(2*pi*f) "Load inductance";
  final parameter SI.Impedance Z=sqrt(R^2 + (2*pi*f*L)^2) "Load impedance";
  final parameter SI.Current IRMS=VRMS/Z "Steady state RMS current";
  final parameter SI.ActivePower P=3*R*IRMS^2 "Total active power";
  final parameter SI.ReactivePower Q=3*(2*pi*f*L)*IRMS^2 "Total reactive power";
  final parameter SI.ApparentPower S=3*Z*IRMS^2 "Total apparent power";
  Modelica.Electrical.QuasiStatic.Polyphase.Sources.VoltageSource sineVoltage(
    final m=m,
    f=f,
    V=fill(VRMS, m),
    gamma(fixed=true, start=0))
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.Star star(final m=m)
  Modelica.Electrical.QuasiStatic.SinglePhase.Basic.Ground ground
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.Resistor resistor(m=m, R_ref=fill(R, m))
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.Inductor inductor(m=m, L=fill(L, m))
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.Star starLoad(m=m)
  Modelica.Electrical.QuasiStatic.Polyphase.Sensors.CurrentQuasiRMSSensor
    currentQuasiRMSSensor(m=m)
  Modelica.Blocks.Math.Feedback feedbackI
  Modelica.Blocks.Sources.Constant constI(k=IRMS)

  Modelica.Electrical.QuasiStatic.Polyphase.Sensors.VoltageQuasiRMSSensor voltageQuasiRMSSensor(m=m)
  Modelica.Blocks.Math.Feedback feedbackV
  Modelica.Blocks.Sources.Constant constV(k=VRMS)
  Modelica.Electrical.QuasiStatic.Polyphase.Sensors.PowerSensor powerSensor(m=m)
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal
  Modelica.Blocks.Math.Feedback feedbackP
  Modelica.Blocks.Sources.RealExpression realExpression(y=
    Modelica.Electrical.QuasiStatic.Polyphase.Functions.activePower(
        voltageQuasiRMSSensor.v, currentQuasiRMSSensor.i))
  Modelica.Electrical.QuasiStatic.Polyphase.Sensors.AronSensor aronSensor
  Modelica.Blocks.Math.Feedback feedbackPAron
  Modelica.Electrical.QuasiStatic.Polyphase.Sensors.ReactivePowerSensor
    reactivePowerSensor
  Modelica.Blocks.Math.Feedback feedbackQ
equation

  connect(feedbackV.u1, voltageQuasiRMSSensor.V)
  connect(constV.y, feedbackV.u2)
  connect(realExpression.y, feedbackP.u2)
  connect(voltageQuasiRMSSensor.plug_p, sineVoltage.plug_p)
  connect(voltageQuasiRMSSensor.plug_n, sineVoltage.plug_n)
  connect(powerSensor.currentP, aronSensor.plug_n)
  connect(powerSensor.currentP, powerSensor.voltageP)
  connect(powerSensor.currentN, resistor.plug_p)
  connect(resistor.plug_n, inductor.plug_p)
  connect(inductor.plug_n, starLoad.plug_p)
  connect(starLoad.plug_p, powerSensor.voltageN)
  connect(star.pin_n, ground.pin)
  connect(sineVoltage.plug_n, star.plug_p)
  connect(powerSensor.apparentPower, complexToReal.u)
  connect(complexToReal.re, feedbackP.u1)
  connect(feedbackI.u2, constI.y)
  connect(feedbackI.u1, currentQuasiRMSSensor.I)
  connect(currentQuasiRMSSensor.plug_p, sineVoltage.plug_p)
  connect(reactivePowerSensor.plug_n, aronSensor.plug_p)
  connect(currentQuasiRMSSensor.plug_n, reactivePowerSensor.plug_p)
  connect(reactivePowerSensor.reactivePower, feedbackQ.u1)
  connect(aronSensor.activePower, feedbackPAron.u1)
  connect(complexToReal.re, feedbackPAron.u2)
  connect(complexToReal.im, feedbackQ.u2)
end TestSensors;


Unsymmetrical three-phase load. This example shows an unsymmetrical load, in the upper with neutral connection (the single-phase current sensor measures the neutral current) and in the lower without neutral connection (the single-phase voltage sensor measures the neutral displacement).

within Modelica.Electrical.QuasiStatic.Polyphase.Examples;
model UnsymmetricalLoad "Unsymmetrical three-phase load"
  extends Modelica.Icons.Example;
  import Modelica.ComplexMath.abs;
  output SI.Current i1_d=symmetricalComponents_1.abs_y[1]
    "With neutral, direct component";
  output SI.Current i1_i=symmetricalComponents_1.abs_y[2]
    "With neutral, inverse component";
  output SI.Current i1_0=symmetricalComponents_1.abs_y[3]
    "With neutral, zero component";
  output SI.Current i1_n=abs(currentSensorN.i)
    "With neutral, neutral current";
  output SI.Current i2_d=symmetricalComponents_2.abs_y[1]
    "Without neutral, direct component";
  output SI.Current i2_i=symmetricalComponents_2.abs_y[2]
    "Without neutral, inverse component";
  output SI.Current i2_0=symmetricalComponents_2.abs_y[3]
    "Without neutral, zero component";
  output SI.Voltage v2_n=abs(voltageSensorN.v)
    "Without neutral, neutral voltage";

  Sources.VoltageSource voltageSource1(
    m=3,
    f=50,
    V=fill(400/sqrt(3), 3),
    gamma(fixed=true, start=0))
  Basic.Star star1_1(m=3)
  SinglePhase.Basic.Ground ground1
  Sources.VoltageSource voltageSource2(
    m=3,
    f=50,
    V=fill(400/sqrt(3), 3),
    gamma(fixed=true, start=0))
  Basic.Star star2_1(m=3)
  SinglePhase.Basic.Ground ground2
  Sensors.CurrentSensor currentSensor1(m=3)
  Blocks.SymmetricalComponents symmetricalComponents_1(m=3)
  Sensors.CurrentSensor currentSensor2(m=3)
  Blocks.SymmetricalComponents symmetricalComponents_2(m=3)
  SinglePhase.Basic.Resistor resistor1_1(R_ref=110)
  SinglePhase.Basic.Resistor resistor1_2(R_ref=100)
  SinglePhase.Basic.Resistor resistor1_3(R_ref=60)
  SinglePhase.Basic.Inductor inductor1_2(L=0.25)
  SinglePhase.Basic.Capacitor capacitor1_3(C=35e-6)
  SinglePhase.Basic.Resistor resistor2_1(R_ref=110)
  SinglePhase.Basic.Resistor resistor2_2(R_ref=100)
  SinglePhase.Basic.Resistor resistor2_3(R_ref=60)
  SinglePhase.Basic.Inductor inductor2_2(L=0.25)
  SinglePhase.Basic.Capacitor capacitor2_3(C=35e-6)
  Basic.PlugToPins_p plugToPins_p_1(m=3)
  Basic.PlugToPins_p plugToPins_p_2(m=3)
  Basic.PlugToPins_n plugToPins_n_1(m=3)
  Basic.PlugToPins_n plugToPins_n_2(m=3)
  Basic.Star star1_2(m=3)
  Basic.Star star2_2(m=3)
  SinglePhase.Sensors.CurrentSensor currentSensorN
  SinglePhase.Sensors.VoltageSensor voltageSensorN
equation
  connect(voltageSource1.plug_n, star1_1.plug_p)
  connect(star1_1.pin_n, ground1.pin)
  connect(voltageSource2.plug_n, star2_1.plug_p)
  connect(star2_1.pin_n, ground2.pin)
  connect(voltageSource1.plug_p, currentSensor1.plug_p)
  connect(voltageSource2.plug_p, currentSensor2.plug_p)
  connect(resistor1_2.pin_n, inductor1_2.pin_p)
  connect(resistor1_3.pin_p, capacitor1_3.pin_p)
  connect(resistor1_3.pin_n, capacitor1_3.pin_n)
  connect(resistor2_2.pin_n, inductor2_2.pin_p)
  connect(resistor2_3.pin_n, capacitor2_3.pin_n)
  connect(resistor2_3.pin_p, capacitor2_3.pin_p)
  connect(currentSensor1.plug_n, plugToPins_p_1.plug_p)
  connect(currentSensor2.plug_n, plugToPins_p_2.plug_p)
  connect(plugToPins_p_1.pin_p[1], resistor1_1.pin_p)
  connect(plugToPins_p_1.pin_p[2], resistor1_2.pin_p)
  connect(plugToPins_p_1.pin_p[3], resistor1_3.pin_p)
  connect(plugToPins_p_2.pin_p[1], resistor2_1.pin_p)
  connect(plugToPins_p_2.pin_p[2], resistor2_2.pin_p)
  connect(plugToPins_p_2.pin_p[3], resistor2_3.pin_p)
  connect(plugToPins_n_1.pin_n[1], resistor1_1.pin_n)
  connect(plugToPins_n_1.pin_n[2], inductor1_2.pin_n)
  connect(plugToPins_n_1.pin_n[3], resistor1_3.pin_n)
  connect(plugToPins_n_2.pin_n[1], resistor2_1.pin_n)
  connect(plugToPins_n_2.pin_n[2], inductor2_2.pin_n)
  connect(plugToPins_n_2.pin_n[3], resistor2_3.pin_n)
  connect(plugToPins_n_1.plug_n, star1_2.plug_p)
  connect(plugToPins_n_2.plug_n, star2_2.plug_p)
  connect(star1_2.pin_n, currentSensorN.pin_p)
  connect(currentSensorN.pin_n, ground1.pin)
  connect(star2_2.pin_n, voltageSensorN.pin_p)
  connect(voltageSensorN.pin_n, ground2.pin)
  connect(currentSensor1.i, symmetricalComponents_1.u)
  connect(currentSensor2.i, symmetricalComponents_2.u)
end UnsymmetricalLoad;


Polyphase ideal closer. Contains m ideal closing switches (Modelica.Electrical.QuasiStatic.SinglePhase.Ideal.IdealClosingSwitch).

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model IdealClosingSwitch "Polyphase ideal closer"
  extends QuasiStatic.Polyphase.Interfaces.TwoPlug;
  parameter SI.Resistance Ron[m](final min=zeros(m), start=
        fill(1e-5, m)) "Closed switch resistance";
  parameter SI.Conductance Goff[m](final min=zeros(m), start=
        fill(1e-5, m)) "Opened switch conductance";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, final T=fill(293.15, m));
  Modelica.Blocks.Interfaces.BooleanInput control[m]
    "true => p--n connected, false => switch open"
  QuasiStatic.SinglePhase.Ideal.IdealClosingSwitch idealClosingSwitch[m](
    final Ron=Ron,
    final Goff=Goff,
    each final useHeatPort=useHeatPort)
equation
  connect(control, idealClosingSwitch.control)
  connect(idealClosingSwitch.heatPort, heatPort)
  connect(idealClosingSwitch.pin_p, plugToPins_p.pin_p)
  connect(idealClosingSwitch.pin_n, plugToPins_n.pin_n)
end IdealClosingSwitch;


Polyphase ideal commuting switch. Contains m single-phase ideal commuting switches (Modelica.Electrical.QuasiStatic.SinglePhase.Ideal.IdealCommutingSwitch).

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model IdealCommutingSwitch "Polyphase ideal commuting switch"
  parameter Integer m(final min=1) = 3 "Number of phases"
  parameter SI.Resistance Ron[m](final min=zeros(m), start=
        fill(1e-5, m)) "Closed switch resistance";
  parameter SI.Conductance Goff[m](final min=zeros(m), start=
        fill(1e-5, m)) "Opened switch conductance";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, final T=fill(293.15, m));
  Modelica.Blocks.Interfaces.BooleanInput control[m]
    "true => p--n2 connected, false => p--n1 connected"
  QuasiStatic.Polyphase.Interfaces.PositivePlug plug_p(final m=m)
  QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n2(final m=m)
  QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n1(final m=m)
  QuasiStatic.SinglePhase.Ideal.IdealCommutingSwitch idealCommutingSwitch[m](
    final Ron=Ron,
    final Goff=Goff,
    each final useHeatPort=useHeatPort)
  QuasiStatic.Polyphase.Basic.PlugToPins_p plugToPins_p(final m=m)
  QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n1(final m=m)
  QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n2(final m=m)
equation
  connect(control, idealCommutingSwitch.control)
  connect(idealCommutingSwitch.heatPort, heatPort)
  connect(plugToPins_n1.plug_n, plug_n1)
  connect(plugToPins_n2.plug_n, plug_n2)
  connect(plugToPins_n2.pin_n, idealCommutingSwitch.n2)
  connect(idealCommutingSwitch.n1, plugToPins_n1.pin_n)
  connect(plugToPins_p.plug_p, plug_p)
  connect(idealCommutingSwitch.p, plugToPins_p.pin_p)
end IdealCommutingSwitch;


Polyphase ideal intermediate switch.

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model IdealIntermediateSwitch "Polyphase ideal intermediate switch"
  parameter Integer m(final min=1) = 3 "Number of phases"
  parameter SI.Resistance Ron[m](final min=zeros(m), start=
        fill(1e-5, m)) "Closed switch resistance";
  parameter SI.Conductance Goff[m](final min=zeros(m), start=
        fill(1e-5, m)) "Opened switch conductance";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, final T=fill(293.15, m));
  Modelica.Blocks.Interfaces.BooleanInput control[m]
    "true => p1--n2, p2--n1 connected, otherwise p1--n1, p2--n2 connected"
  QuasiStatic.Polyphase.Interfaces.PositivePlug plug_p1(final m=m)
  QuasiStatic.Polyphase.Interfaces.PositivePlug plug_p2(final m=m)
  QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n2(final m=m)
  QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n1(final m=m)
  QuasiStatic.SinglePhase.Ideal.IdealIntermediateSwitch idealIntermediateSwitch[m](
    final Ron=Ron,
    final Goff=Goff,
    each final useHeatPort=useHeatPort)
  QuasiStatic.Polyphase.Basic.PlugToPins_p plugToPins_p1(final m=m)
  QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n1(final m=m)
  QuasiStatic.Polyphase.Basic.PlugToPins_p plugToPins_p2(final m=m)
  QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n2(final m=m)
equation
  connect(control, idealIntermediateSwitch.control)
  connect(idealIntermediateSwitch.heatPort, heatPort)
  connect(plug_p1, plugToPins_p1.plug_p)
  connect(plug_p2, plugToPins_p2.plug_p)
  connect(plugToPins_n1.plug_n, plug_n1)
  connect(plugToPins_n2.plug_n, plug_n2)
  connect(idealIntermediateSwitch.p2, plugToPins_p2.pin_p)
  connect(idealIntermediateSwitch.n2, plugToPins_n2.pin_n)
  connect(idealIntermediateSwitch.n1, plugToPins_n1.pin_n)
  connect(idealIntermediateSwitch.p1, plugToPins_p1.pin_p)
end IdealIntermediateSwitch;


Polyphase ideal opener. Contains m ideal opening switches (Modelica.Electrical.QuasiStatic.SinglePhase.Ideal.IdealOpeningSwitch).

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model IdealOpeningSwitch "Polyphase ideal opener"
  extends QuasiStatic.Polyphase.Interfaces.TwoPlug;
  parameter SI.Resistance Ron[m](final min=zeros(m), start=
        fill(1e-5, m)) "Closed switch resistance";
  parameter SI.Conductance Goff[m](final min=zeros(m), start=
        fill(1e-5, m)) "Opened switch conductance";
  extends Modelica.Electrical.Polyphase.Interfaces.ConditionalHeatPort(
      final mh=m, final T=fill(293.15, m));
  Modelica.Blocks.Interfaces.BooleanInput control[m]
    "true => switch open, false => p--n connected"
  QuasiStatic.SinglePhase.Ideal.IdealOpeningSwitch idealOpeningSwitch[m](
    final Ron=Ron,
    final Goff=Goff,
    each final useHeatPort=useHeatPort)
equation
  connect(control, idealOpeningSwitch.control)
  connect(idealOpeningSwitch.heatPort, heatPort)
  connect(idealOpeningSwitch.pin_n, plugToPins_n.pin_n)
  connect(plugToPins_p.pin_p, idealOpeningSwitch.pin_p)
end IdealOpeningSwitch;


Idle branch. This model describes m simple idle branches considering the complex currents i = 0;
it uses m single-phase idle branches.

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model Idle "Idle branch"
  extends Interfaces.TwoPlug;

  QuasiStatic.SinglePhase.Ideal.Idle idle[m]

equation
  connect(plugToPins_p.pin_p, idle.pin_p)
  connect(idle.pin_n, plugToPins_n.pin_n)
end Idle;


within Modelica.Electrical.QuasiStatic.Polyphase;
package Ideal "Ideal components for AC polyphase models"
  extends Modelica.Icons.Package;
end Ideal;


Short cut branch. This model describes m simple short branches considering the complex voltages v = 0;
it uses m single-phase short branches.

within Modelica.Electrical.QuasiStatic.Polyphase.Ideal;
model Short "Short cut branch"
  extends Interfaces.TwoPlug;

  QuasiStatic.SinglePhase.Ideal.Short short[m]

equation
  connect(plugToPins_p.pin_p, short.pin_p)
  connect(short.pin_n, plugToPins_n.pin_n)
end Short;


Partial potential sensor. The absolute sensor partial model relies on the a
positive plug
to measure the complex potential, frequency, angular frequency. Additionally this model contains
a proper icon and a definition of the angular velocity.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model AbsoluteSensor "Partial potential sensor"
  extends Modelica.Icons.RoundSensor;
  parameter Integer m(min=1) = 3 "Number of phases"
  SI.AngularVelocity omega;
  PositivePlug plug_p(final m=m)
    "Positive quasi-static polyphase plug"
equation
  omega = der(plug_p.reference.gamma);
end AbsoluteSensor;


Two plugs, reference connection and declaration of voltage and current. This partial model uses a positive
and negative plug and defines
the complex voltage differences as well as the complex currents (into the positive plug).
A positive and
a negative adapter
are used to give easy access to the single pins of both plugs. Additionally, the angular velocity of the
quasi-static system is explicitly defined as variable. This model is mainly intended to be used with textual representation of user models.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model OnePort "Two plugs, reference connection and declaration of voltage and current"
  parameter Integer m(min=1) = 3 "Number of phases"
  SI.ComplexVoltage v[m] "Complex voltage";
  SI.Voltage abs_v[m]=Modelica.ComplexMath.abs(v)
    "Magnitude of complex voltage";
  SI.Angle arg_v[m]=Modelica.ComplexMath.arg(v)
    "Argument of complex voltage";
  SI.ComplexCurrent i[m] "Complex current";
  SI.Current abs_i[m]=Modelica.ComplexMath.abs(i)
    "Magnitude of complex current";
  SI.Angle arg_i[m]=Modelica.ComplexMath.arg(i)
    "Argument of complex current";
  SI.ActivePower P[m]={Modelica.ComplexMath.real(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m} "Active power";
  SI.ActivePower P_total=sum(P) "Total active power";
  SI.ReactivePower Q[m]={Modelica.ComplexMath.imag(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m} "Reactive power";
  SI.ReactivePower Q_total=sum(Q) "Total reactive power";
  SI.ApparentPower S[m]={Modelica.ComplexMath.abs(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m}
    "Magnitude of complex apparent power";
  SI.ApparentPower S_total=sqrt(P_total^2 + Q_total^2)
    "Magnitude of total complex apparent power";
  Real pf[m]={cos(Modelica.ComplexMath.arg(Complex(P[k], Q[k]))) for k in 1
      :m} "Power factor";
  /*
  Real pf_total = cos(Modelica.ComplexMath.arg(Complex(P_total,Q_total)))
    "Total power factor";
  */
  SI.AngularVelocity omega
    "Angular velocity of reference frame";

  PositivePlug plug_p(final m=m)
    "Positive quasi-static polyphase plug"
  NegativePlug plug_n(final m=m)
    "Negative quasi-static polyphase plug"
equation
  Connections.branch(plug_p.reference, plug_n.reference);
  plug_p.reference.gamma = plug_n.reference.gamma;
  omega = der(plug_p.reference.gamma);
  v = plug_p.pin.v - plug_n.pin.v;
  i = plug_p.pin.i;
  plug_p.pin.i + plug_n.pin.i = fill(Complex(0), m);
end OnePort;


Interfaces for AC polyphase models

within Modelica.Electrical.QuasiStatic.Polyphase;
package Interfaces "Interfaces for AC polyphase models"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Partial of voltage or current source with reference input. The source partial model relies on the
TwoPlug and contains a proper icon.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model ReferenceSource
  "Partial of voltage or current source with reference input"
  extends QuasiStatic.Polyphase.Interfaces.OnePort;
  import Modelica.Constants.pi;
equation
  Connections.root(plug_p.reference);
end ReferenceSource;


Elementary partial voltage / current sensor. The relative sensor partial model relies on the
TwoPlug to measure the complex voltages, currents or power. Additionally this model contains a proper icon and a definition of the angular velocity.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model RelativeSensorElementary "Elementary partial voltage / current sensor"
  extends Modelica.Icons.RoundSensor;
  extends TwoPlugElementary;

end RelativeSensorElementary;


Partial voltage / current source. The source partial model relies on the
TwoPlug and contains a proper icon.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model Source "Partial voltage / current source"
  extends OnePort;
  constant SI.Angle pi=Modelica.Constants.pi;
  SI.Angle gamma(start=0) = plug_p.reference.gamma;
equation
  Connections.root(plug_p.reference);
end Source;


Two plugs with pin-adapter, reference connection and declaration of voltage and current. This partial model uses a positive
and negative plug,
but no complex voltage and complex current.
A positive and
a negative adapter
are used to give easy access to the single pins of both plugs. Additionally, the angular velocity of the
quasi-static system is explicitly defined as variable. This model is mainly intended to be used with graphical representation of user models.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model TwoPlug "Two plugs with pin-adapter, reference connection and declaration of voltage and current"
  extends Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.TwoPlugElementary;

  SI.ComplexVoltage v[m] "Complex voltage";
  SI.Voltage abs_v[m]=Modelica.ComplexMath.abs(v)
    "Magnitude of complex voltage";
  SI.Angle arg_v[m]=Modelica.ComplexMath.arg(v)
    "Argument of complex voltage";
  SI.ComplexCurrent i[m] "Complex current";
  SI.Current abs_i[m]=Modelica.ComplexMath.abs(i)
    "Magnitude of complex current";
  SI.Angle arg_i[m]=Modelica.ComplexMath.arg(i)
    "Argument of complex current";
  SI.ActivePower P[m]={Modelica.ComplexMath.real(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m} "Active power";
  SI.ActivePower P_total=sum(P) "Total active power";
  SI.ReactivePower Q[m]={Modelica.ComplexMath.imag(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m} "Reactive power";
  SI.ReactivePower Q_total=sum(Q) "Total reactive power";
  SI.ApparentPower S[m]={Modelica.ComplexMath.abs(v[k]*
      Modelica.ComplexMath.conj(i[k])) for k in 1:m}
    "Magnitude of complex apparent power";
  SI.ApparentPower S_total=sqrt(P_total^2 + Q_total^2)
    "Magnitude of total complex apparent power";
  Real pf[m]={cos(Modelica.ComplexMath.arg(Complex(P[k], Q[k]))) for k in 1
      :m} "Power factor";
  /*
  Real pf_total = cos(Modelica.ComplexMath.arg(Complex(P_total,Q_total)))
   "Total power factor";
  */
equation
  v = plug_p.pin.v - plug_n.pin.v;
  i = plug_p.pin.i;
end TwoPlug;


Two plugs with pin-adapter and reference connection, without declaration of voltage and current. This partial model uses a positive
and negative plug
but no complex voltage, current, power, etc.
A positive and
a negative adapter
are used to give easy access to the single pins of both plugs. Additionally, the angular velocity of the
quasi-static system is explicitly defined as variable. This model is mainly intended to be used with graphical representation of user models.

within Modelica.Electrical.QuasiStatic.Polyphase.Interfaces;
partial model TwoPlugElementary "Two plugs with pin-adapter and reference connection, without declaration of voltage and current"
  parameter Integer m(min=1) = 3 "Number of phases"
  SI.AngularVelocity omega "Angular velocity of reference frame";

  PositivePlug plug_p(final m=m)
    "Positive quasi-static polyphase plug"
  NegativePlug plug_n(final m=m)
    "Negative quasi-static polyphase plug"
  Basic.PlugToPins_p plugToPins_p(final m=m)
  Basic.PlugToPins_n plugToPins_n(final m=m)
equation
  omega = der(plug_p.reference.gamma);
  connect(plug_p, plugToPins_p.plug_p)
  connect(plugToPins_n.plug_n, plug_n)
end TwoPlugElementary;


Three-phase Aron sensor for active power. Contains two power meters to measure total active power in a three-phase system.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model AronSensor "Three-phase Aron sensor for active power"
  extends Modelica.Icons.RoundSensor;
  final parameter Integer m(final min=1) = 3 "Number of phases"
  Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.PositivePlug plug_p(final m=m)
  Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n(final m=m)
  Modelica.Blocks.Interfaces.RealOutput activePower(unit="W") "Active power"
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.PlugToPins_p plugToPins_p(final m=m)
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n(final m=m)
  Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor1
  Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor3
  Modelica.Blocks.Math.Add add
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal1(final
      useConjugateInput=false)
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal3(final
      useConjugateInput=false)
equation
  connect(add.y, activePower)
  connect(plug_p, plugToPins_p.plug_p)
  connect(plugToPins_n.plug_n, plug_n)
  connect(plugToPins_p.pin_p[1], powerSensor1.currentP)
  connect(powerSensor1.currentP, powerSensor1.voltageP)
  connect(powerSensor1.currentN, plugToPins_n.pin_n[1])
  connect(plugToPins_p.pin_p[2], plugToPins_n.pin_n[2])
  connect(plugToPins_p.pin_p[3], powerSensor3.currentP)
  connect(powerSensor3.currentP, powerSensor3.voltageP)
  connect(powerSensor3.currentN, plugToPins_n.pin_n[3])
  connect(complexToReal3.re, add.u1)
  connect(complexToReal1.re, add.u2)
  connect(powerSensor3.apparentPower, complexToReal3.u)
  connect(powerSensor1.apparentPower, complexToReal1.u)
  connect(plugToPins_p.pin_p[2], powerSensor1.voltageN)
  connect(plugToPins_p.pin_p[2], powerSensor3.voltageN)
end AronSensor;


Continuous quasi current RMS sensor for polyphase system. This sensor determines the continuous quasi RMS
value of a polyphase current system, by averaging the phase RMS current phasors i.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model CurrentQuasiRMSSensor
  "Continuous quasi current RMS sensor for polyphase system"
  extends Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.RelativeSensorElementary;

  parameter Integer m(min=1) = 3 "Number of phases"
  Modelica.Blocks.Interfaces.RealOutput I(unit="A")
    "Continuous quasi average RMS of current"
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor[m]
  QuasiStatic.Polyphase.Blocks.QuasiRMS quasiRMS(final m=m)
  SI.ComplexVoltage v[m] = plug_p.pin.v - plug_n.pin.v "Complex voltage";
  SI.ComplexCurrent i[m] = plug_p.pin.i "Complex current";
equation
  connect(quasiRMS.y, I)
  connect(plugToPins_p.pin_p, currentSensor.pin_p)
  connect(currentSensor.pin_n, plugToPins_n.pin_n)
  connect(currentSensor.i, quasiRMS.u)
end CurrentQuasiRMSSensor;


Current Sensor. This sensor can be used to measure m complex currents, using m
single-phase CurrentSensors.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model CurrentSensor "Current Sensor"
  extends Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.RelativeSensorElementary;

  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor[m]
  SI.Current abs_i[m]=Modelica.ComplexMath.abs(i)
    "Magnitude of complex current";
  SI.Angle arg_i[m]=Modelica.ComplexMath.arg(i)
    "Argument of complex current";
  ComplexBlocks.Interfaces.ComplexOutput i[m](redeclare each final SI.Current re, redeclare each final SI.Current im) "Current as complex output signal"
equation
  connect(plugToPins_p.pin_p, currentSensor.pin_p)
  connect(currentSensor.pin_n, plugToPins_n.pin_n)
  connect(currentSensor.i,i)
end CurrentSensor;


Frequency sensor. This sensor can be used to measure the frequency of the reference system, using one
single-phase FrequencySensor.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model FrequencySensor "Frequency sensor"
  extends Interfaces.AbsoluteSensor;
  SinglePhase.Sensors.FrequencySensor frequencySensor
  Basic.PlugToPin_p plugToPin_p(final m=m, final k=1)
  Modelica.Blocks.Interfaces.RealOutput f(unit="Hz")
equation

  connect(plug_p, plugToPin_p.plug_p)
  connect(plugToPin_p.pin_p, frequencySensor.pin)
  connect(frequencySensor.f,f)
end FrequencySensor;


Polyphase sensor to measure current, voltage and power. This multi sensor measures currents, voltages and instantaneous electrical power of a polyphase system and has separated voltage and current paths.
The plugs of the voltage paths are pv and nv, the plugs of the current paths are pc and nc.
The internal resistance of each current path is zero, the internal resistance of each voltage path is infinite.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model MultiSensor "Polyphase sensor to measure current, voltage and power"
  extends Modelica.Icons.RoundSensor;
  import Modelica.ComplexMath.conj;
  import Modelica.ComplexMath.abs;
  import Modelica.ComplexMath.arg;
  parameter Integer m(min=1) = 3 "Number of phases"
  QuasiStatic.Polyphase.Interfaces.PositivePlug pc(final m=m)
    "Positive plug, current path"
  QuasiStatic.Polyphase.Interfaces.NegativePlug nc(final m=m)
    "Negative plug, current path"
  QuasiStatic.Polyphase.Interfaces.PositivePlug pv(final m=m)
    "Positive plug, voltage path"
  QuasiStatic.Polyphase.Interfaces.NegativePlug nv(final m=m)
    "Negative plug, voltage path"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput i[m](
    redeclare each final SI.Current re, redeclare each final SI.Current im)
    "Current as complex output signal"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput v[m](
    redeclare each final SI.Voltage re, redeclare each final SI.Voltage im)
    "Voltage as complex output signal"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower[m](
    redeclare each final SI.ActivePower re, redeclare each final SI.ReactivePower im)
    "Instantaneous apparent power as complex output signal"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPowerTotal(
    redeclare final SI.ActivePower re, redeclare final SI.ReactivePower im)
    "Sum of instantaneous apparent power as complex output signal"
  output SI.Current abs_i[m]=abs(i) "Absolute of complex currents";
  output SI.Angle arg_i[m]=arg(i) "Argument of complex currents";
  output SI.Voltage abs_v[m]=abs(v) "Absolute of complex voltages";
  output SI.Angle arg_v[m]=arg(v) "Argument of complex voltages";
  output SI.ApparentPower abs_apparentPower[m]=abs(apparentPower) "Absolute of complex apparent power signals";
  output SI.Angle arg_apparentPower[m]=arg(apparentPower) "Argument of complex apparent power signals";
  output SI.ApparentPower abs_apparentPowerTotal=abs(apparentPowerTotal) "Absolute of sum complex apparent power";
  output SI.Angle arg_apparentPowerTotal=arg(apparentPowerTotal) "Argument of sum complex apparent power";
equation
  Connections.branch(pc.reference, nc.reference);
  pc.reference.gamma = nc.reference.gamma;
  Connections.branch(pv.reference, nv.reference);
  pv.reference.gamma = nv.reference.gamma;
  Connections.branch(pc.reference, pv.reference);
  pc.reference.gamma = pv.reference.gamma;
  pc.pin.i + nc.pin.i = fill(Complex(0), m);
  pc.pin.v - nc.pin.v = fill(Complex(0), m);
  pv.pin.i = fill(Complex(0), m);
  nv.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));
end MultiSensor;


AC polyphase sensors

within Modelica.Electrical.QuasiStatic.Polyphase;
package Sensors "AC polyphase sensors"
  extends Modelica.Icons.SensorsPackage;
end Sensors;


Potential sensor. This sensor can be used to measure m complex potentials, using m
single-phase PotentialSensors.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model PotentialSensor "Potential sensor"
  extends Interfaces.AbsoluteSensor;
  QuasiStatic.SinglePhase.Sensors.PotentialSensor potentialSensor[m]
  Basic.PlugToPins_p plugToPins_p(final m=m)
  Modelica.ComplexBlocks.Interfaces.ComplexOutput v[m] "Potential as complex output signal"
  SI.Voltage abs_v[m]=Modelica.ComplexMath.abs(v)
    "Magnitude of complex potential";
  SI.Angle arg_v[m]=Modelica.ComplexMath.arg(v)
    "Argument of complex potential";

equation
  connect(potentialSensor.v,v)
  connect(plug_p, plugToPins_p.plug_p)
  connect(plugToPins_p.pin_p, potentialSensor.pin)
end PotentialSensor;


Power sensor. This sensor can be used to measure m complex apparent power values, using m
single-phase PowerSensors.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model PowerSensor "Power sensor"
  extends Modelica.Icons.RoundSensor;
  parameter Integer m(min=1) = 3 "Number of phases"
  SI.AngularVelocity omega=der(currentP.reference.gamma);
  Interfaces.PositivePlug currentP(final m=m)
  Interfaces.NegativePlug currentN(final m=m)
  Interfaces.PositivePlug voltageP(final m=m)
  Interfaces.NegativePlug voltageN(final m=m)
  Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower "Total apparent power as complex output signal"
  Basic.PlugToPins_p plugToPinsCurrentP(final m=m)
  Basic.PlugToPins_p plugToPinsVoltageP(final m=m)
  Basic.PlugToPins_n plugToPinsCurrentN(final m=m)
  Basic.PlugToPins_n plugToPinsVoltageN(final m=m)
  QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor[m]
  Modelica.ComplexBlocks.ComplexMath.Sum sum(final nin=m)

  SI.ApparentPower abs_apparentPower=Modelica.ComplexMath.abs(apparentPower) "Magnitude of complex apparent power";
  SI.Angle arg_apparentPower=Modelica.ComplexMath.arg(apparentPower) "Argument of complex apparent power";

equation
  connect(plugToPinsCurrentP.plug_p, currentP)
  connect(currentN, plugToPinsCurrentN.plug_n)
  connect(voltageP, plugToPinsVoltageP.plug_p)
  connect(plugToPinsVoltageN.plug_n, voltageN)
  connect(plugToPinsCurrentP.pin_p, powerSensor.currentP)
  connect(powerSensor.currentN, plugToPinsCurrentN.pin_n)
  connect(powerSensor.voltageP, plugToPinsVoltageP.pin_p)
  connect(powerSensor.voltageN, plugToPinsVoltageN.pin_n)
  connect(powerSensor.apparentPower, sum.u)
  connect(sum.y, apparentPower)
end PowerSensor;


Three-phase sensor for reactive power. Contains 3 power meters (Modelica.Electrical.Analog.Sensors.PowerSensor) to measure total reactive power in a three-phase system.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model ReactivePowerSensor "Three-phase sensor for reactive power"
  extends Modelica.Icons.RoundSensor;
  final parameter Integer m(final min=1) = 3 "Number of phases"
  Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.PositivePlug plug_p(final m=m)
  Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.NegativePlug plug_n(final m=m)
  Modelica.Blocks.Interfaces.RealOutput reactivePower "Reactive power"
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.PlugToPins_p plugToPins_p(final m=m)
  Modelica.Electrical.QuasiStatic.Polyphase.Basic.PlugToPins_n plugToPins_n(final m=m)
  Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor1
  Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor2
  Modelica.Blocks.Math.Add3 add(
    final k1=1/sqrt(3),
    final k2=1/sqrt(3),
    final k3=1/sqrt(3))
  Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor3
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal1(final
      useConjugateInput=false)
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal2(final
      useConjugateInput=false)
  Modelica.ComplexBlocks.ComplexMath.ComplexToReal complexToReal3(final
      useConjugateInput=false)
equation
  connect(add.y, reactivePower)
  connect(plug_p, plugToPins_p.plug_p)
  connect(plugToPins_n.plug_n, plug_n)
  connect(plugToPins_p.pin_p[1], powerSensor1.currentP)
  connect(plugToPins_p.pin_p[2], powerSensor1.voltageP)
  connect(powerSensor1.currentN, plugToPins_n.pin_n[1])
  connect(plugToPins_p.pin_p[3], powerSensor1.voltageN)
  connect(plugToPins_p.pin_p[2], powerSensor2.currentP)
  connect(powerSensor2.currentN, plugToPins_n.pin_n[2])
  connect(plugToPins_p.pin_p[3], powerSensor2.voltageP)
  connect(powerSensor1.currentN, powerSensor2.voltageN)
  connect(plugToPins_p.pin_p[3], powerSensor3.currentP)
  connect(powerSensor3.currentN, plugToPins_n.pin_n[3])
  connect(powerSensor1.currentN, powerSensor3.voltageP)
  connect(powerSensor3.voltageN, plugToPins_n.pin_n[2])
  connect(powerSensor1.apparentPower, complexToReal1.u)
  connect(complexToReal2.u, powerSensor2.apparentPower)
  connect(powerSensor3.apparentPower, complexToReal3.u)
  connect(complexToReal1.re, add.u1)
  connect(complexToReal2.re, add.u2)
  connect(complexToReal3.re, add.u3)
end ReactivePowerSensor;


Sensor of reference angle gamma. This sensor can be used to measure the reference angle.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model ReferenceSensor "Sensor of reference angle gamma"
  extends QuasiStatic.Polyphase.Interfaces.AbsoluteSensor;
  Modelica.Blocks.Interfaces.RealOutput gamma "Reference angle"
equation
  gamma = plug_p.reference.gamma;
  plug_p.pin.i = fill(Complex(0), m);
end ReferenceSensor;


Continuous quasi voltage RMS sensor for polyphase system. This sensor determines the continuous quasi RMS
value of a polyphase voltage system, by averaging the phase RMS voltage phasors v.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model VoltageQuasiRMSSensor
  "Continuous quasi voltage RMS sensor for polyphase system"
  extends Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.RelativeSensorElementary;

  parameter Integer m(min=1) = 3 "Number of phases"
  Modelica.Blocks.Interfaces.RealOutput V
    "Continuous quasi average RMS of current"
  SinglePhase.Sensors.VoltageSensor voltageSensor[m]
  QuasiStatic.Polyphase.Blocks.QuasiRMS quasiRMS(final m=m)
  SI.ComplexVoltage v[m] = plug_p.pin.v - plug_n.pin.v "Complex voltage";
  SI.ComplexCurrent i[m] = plug_p.pin.i "Complex current";
equation
  connect(quasiRMS.y, V)
  connect(plugToPins_p.pin_p, voltageSensor.pin_p)
  connect(voltageSensor.pin_n, plugToPins_n.pin_n)
  connect(voltageSensor.v, quasiRMS.u)
end VoltageQuasiRMSSensor;


Voltage sensor. This sensor can be used to measure m complex voltages, using m
single-phase VoltageSensors.

within Modelica.Electrical.QuasiStatic.Polyphase.Sensors;
model VoltageSensor "Voltage sensor"
  extends Modelica.Electrical.QuasiStatic.Polyphase.Interfaces.RelativeSensorElementary;

  QuasiStatic.SinglePhase.Sensors.VoltageSensor voltageSensor[m]
  SI.Voltage abs_v[m]=Modelica.ComplexMath.abs(v)
    "Magnitude of complex voltage";
  SI.Angle arg_v[m]=Modelica.ComplexMath.arg(v)
    "Argument of complex voltage";
  ComplexBlocks.Interfaces.ComplexOutput v[m](redeclare each final SI.Voltage re, redeclare each final SI.Voltage im) "Voltage as complex output signal"
equation
  connect(plugToPins_p.pin_p, voltageSensor.pin_p)
  connect(voltageSensor.pin_n, plugToPins_n.pin_n)
  connect(voltageSensor.v,v)
end VoltageSensor;


Constant polyphase AC current. This model describes m constant current sources, specifying the complex currents by the RMS currents and the phase shifts
(defaults are
-symmetricOrientation).
m single-phase CurrentSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model CurrentSource "Constant polyphase AC current"
  extends Interfaces.Source;
  import Modelica.ComplexMath.j;
  import Modelica.ComplexMath.exp;
  parameter SI.Frequency f(start=1) "Frequency of the source";
  parameter SI.Current I[m](start=fill(1, m))
    "RMS current of the source";
  parameter SI.Angle phi[m]=-
      Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m)
    "Phase shift of the source";
equation
  omega = 2*Modelica.Constants.pi*f;
  i = {I[k]*exp(j*phi[k]) for k in 1:m};
end CurrentSource;


Current source with integrated frequency sweep. This source provides polyphase constant RMS phase currents I and phase angles phi,
whereas the frequency sweeps from
fStart to fStop with duration. The frequency sweeps such
way that on a logarithmic frequency scale, the frequency curve appears linear.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model FrequencySweepCurrentSource "Current source with integrated frequency sweep"
  extends Interfaces.TwoPlug;
  import Modelica.Constants.eps;
  SI.Angle gamma(start=0) = plug_p.reference.gamma;
  parameter SI.Frequency fStart(final min=eps, start=1) "Start sweep frequency";
  parameter SI.Frequency fStop(final min=eps, start=1) "Stop sweep frequency";
  parameter SI.Time startTime=0 "Start time of frequency sweep";
  parameter SI.Time duration(start=1) "Duration of frequency sweep";
  parameter SI.Current I[m](start=fill(1,m)) "RMS current of the source";
  parameter SI.Angle phi[m]=-Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m) "Phase shift of the source";
  SI.Frequency f=currentSource.f   "Actual frequency";
  VariableCurrentSource currentSource(final m=m)
  Modelica.Blocks.Sources.LogFrequencySweep logFrequencySweep(
    final wMin=fStart,
    final wMax=fStop,
    final startTime=startTime,
    final duration=duration)
  Modelica.ComplexBlocks.Sources.ComplexConstant const[m](final k=
        Modelica.ComplexMath.fromPolar(len=I, phi=phi))
equation
  connect(logFrequencySweep.y,currentSource. f)
  connect(plug_p,currentSource. plug_p)
  connect(currentSource.plug_n, plug_n)
  connect(currentSource.I, const.y)
end FrequencySweepCurrentSource;


Voltage source with integrated frequency sweep. This source provides polyphase constant RMS phase voltages V and phase angles phi,
whereas the frequency sweeps from
fStart to fStop with duration. The frequency sweeps such
way that on a logarithmic frequency scale, the frequency curve appears linear.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model FrequencySweepVoltageSource "Voltage source with integrated frequency sweep"
  extends Interfaces.TwoPlug;
  import Modelica.Constants.eps;
  SI.Angle gamma(start=0) = plug_p.reference.gamma;
  parameter SI.Frequency fStart(final min=eps, start=1) "Start sweep frequency";
  parameter SI.Frequency fStop(final min=eps, start=1) "Stop sweep frequency";
  parameter SI.Time startTime=0 "Start time of frequency sweep";
  parameter SI.Time duration(start=1) "Duration of frequency sweep";
  parameter SI.Voltage V[m](start=fill(1,m)) "RMS voltage of the source";
  parameter SI.Angle phi[m]=-Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m) "Phase shift of the source";
  SI.Frequency f = voltageSource.f "Actual frequency";
  VariableVoltageSource voltageSource(final m=m)
  Modelica.Blocks.Sources.LogFrequencySweep logFrequencySweep(
    final wMin=fStart,
    final wMax=fStop,
    final startTime=startTime,
    final duration=duration)
  Modelica.ComplexBlocks.Sources.ComplexConstant const[m](final k=
        Modelica.ComplexMath.fromPolar(len=V, phi=phi))
equation
  connect(logFrequencySweep.y, voltageSource.f)
  connect(plug_p, voltageSource.plug_p)
  connect(voltageSource.plug_n, plug_n)
  connect(const.y, voltageSource.V)
end FrequencySweepVoltageSource;


AC polyphase sources

within Modelica.Electrical.QuasiStatic.Polyphase;
package Sources "AC polyphase sources"
  extends Modelica.Icons.SourcesPackage;
end Sources;


Variable polyphase AC current with reference angle input. This model describes m variable current sources, with m complex signal inputs,
specifying the complex current by the complex RMS voltage components.
Additionally, the frequency of the current source is defined by a real signal input.
m single-phase VariableCurrentSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model ReferenceCurrentSource
  "Variable polyphase AC current with reference angle input"
  extends Interfaces.ReferenceSource;
  import Modelica.Constants.pi;
  Modelica.Blocks.Interfaces.RealInput gamma
    "Reference angle of current source"
  Modelica.ComplexBlocks.Interfaces.ComplexInput I[m]
equation
  plug_p.reference.gamma = gamma;
  i = I;
end ReferenceCurrentSource;


Variable polyphase AC voltage with reference angle input. This model describes m variable current sources, with m complex signal inputs,
specifying the complex current by the complex RMS voltage components.
Additionally, the frequency of the current source is defined by a real signal input.
m single-phase VariableCurrentSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model ReferenceVoltageSource
  "Variable polyphase AC voltage with reference angle input"
  extends Interfaces.ReferenceSource;
  import Modelica.Constants.pi;
  Modelica.Blocks.Interfaces.RealInput gamma
    "Reference angle of voltage source"
  Modelica.ComplexBlocks.Interfaces.ComplexInput V[m]
equation
  plug_p.reference.gamma = gamma;
  v = V;
end ReferenceVoltageSource;


Variable polyphase AC current. This model describes m variable current sources, with m complex signal inputs,
specifying the complex current by the complex RMS voltage components.
Additionally, the frequency of the current source is defined by a real signal input.
m single-phase VariableCurrentSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model VariableCurrentSource "Variable polyphase AC current"
  extends Interfaces.Source;
  Modelica.Blocks.Interfaces.RealInput f(unit="Hz")
  Modelica.ComplexBlocks.Interfaces.ComplexInput I[m]
equation
  omega = 2*Modelica.Constants.pi*f;
  i = I;
end VariableCurrentSource;


Variable polyphase AC voltage. This model describes m variable voltage sources, with m complex signal inputs,
specifying the complex voltages by the complex RMS voltage components.
Additionally, the frequency of the voltage source is defined by a real signal input.
m single-phase VariableVoltageSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model VariableVoltageSource "Variable polyphase AC voltage"
  extends Interfaces.Source;
  Modelica.Blocks.Interfaces.RealInput f(unit="Hz")
  Modelica.ComplexBlocks.Interfaces.ComplexInput V[m]
equation
  omega = 2*Modelica.Constants.pi*f;
  v = V;
end VariableVoltageSource;


Constant polyphase AC voltage. This model describes m constant voltage sources, specifying the complex voltages by the RMS voltages and the phase shifts
(defaults are
-symmetricOrientation).
m single-phase VoltageSources are used.

within Modelica.Electrical.QuasiStatic.Polyphase.Sources;
model VoltageSource "Constant polyphase AC voltage"
  extends Interfaces.Source;
  import Modelica.ComplexMath.j;
  import Modelica.ComplexMath.exp;
  parameter SI.Frequency f(start=1) "Frequency of the source";
  parameter SI.Voltage V[m](start=fill(1, m))
    "RMS voltage of the source";
  parameter SI.Angle phi[m]=-
      Modelica.Electrical.Polyphase.Functions.symmetricOrientation(m)
    "Phase shift of the source";
equation
  omega = 2*Modelica.Constants.pi*f;
  v = {V[k]*exp(j*phi[k]) for k in 1:m};
end VoltageSource;


Single-phase AC components

within Modelica.Electrical.QuasiStatic;
package SinglePhase "Single-phase AC components"
  extends Modelica.Icons.Package;
end SinglePhase;


Single-phase linear admittance. The admittance model represents a parallel connection of a conductor and either a capacitor or inductor.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Admittance "Single-phase linear admittance"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.imag;
  import Modelica.ComplexMath.conj;
  parameter SI.ComplexAdmittance Y_ref(re(start=1),im(start=0)) "Complex admittance G_ref + j*B_ref";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  SI.Conductance G_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  SI.Susceptance B_actual "Susceptance considering possible frequency dependency";
  final parameter SI.Conductance G_ref=real(Y_ref) "Resistive component of conductance";
  final parameter SI.Susceptance B_ref=imag(Y_ref) "Reactive component of susceptance";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G_ref/(1 + alpha_ref*(T_heatPort - T_ref));
  B_actual = B_ref * (if not frequencyDependent then 1 else
    (if B_ref>=0 then omega/(2*Modelica.Constants.pi*f_ref) else 2*Modelica.Constants.pi*f_ref/omega));
  i = Complex(G_actual, B_actual) * v;
  LossPower = real(v*conj(i));
end Admittance;


Single-phase linear capacitor. The linear capacitor connects the voltage v with the
current i by i = j*ω*C*v.
The capacitance C is allowed to be positive, zero, or negative.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Capacitor "Single-phase linear capacitor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  parameter SI.Capacitance C(start=1) "Capacitance";
equation
  i = j*omega*C*v;
end Capacitor;


Single-phase linear conductor. The linear conductor connects the voltage v with the
current i by i = v*G.
The conductance G is allowed to be positive, zero, or negative.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Conductor "Single-phase linear conductor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  parameter SI.Conductance G_ref(start=1) "Reference conductance at T_ref";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of conductance (G_actual = G_ref/(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Conductance G_actual "Conductance = G_ref/(1 + alpha_ref*(heatPort.T - T_ref))";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G_ref/(1 + alpha_ref*(T_heatPort - T_ref));
  i = G_actual*v;
  LossPower = real(v*conj(i));
end Conductor;


Electrical ground. Ground of a single-phase circuit. The potential at the ground node is zero.
Every electrical circuit, e.g., a series resonance

          example, has to contain at least one ground object.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Ground "Electrical ground"

  Interfaces.PositivePin pin
equation
  Connections.potentialRoot(pin.reference, 256);
  if Connections.isRoot(pin.reference) then
    pin.reference.gamma = 0;
  end if;
  pin.v = Complex(0);
end Ground;


Single-phase linear impedance. The impedance model represents a series connection of a resistor and either an inductor or capacitor.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Impedance "Single-phase linear impedance"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.imag;
  import Modelica.ComplexMath.conj;
  parameter SI.ComplexImpedance Z_ref(re(start=1),im(start=0)) "Complex impedance R_ref + j*X_ref";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  SI.Resistance R_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  SI.Reactance X_actual "Reactance considering possible frequency dependency";
  final parameter SI.Resistance R_ref=real(Z_ref) "Resistive component of impedance, resistance";
  final parameter SI.Reactance X_ref=imag(Z_ref) "Reactive component of impedance, reactance";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R_ref*(1 + alpha_ref*(T_heatPort - T_ref));
  X_actual = X_ref * (if not frequencyDependent then 1 else
    (if X_ref>=0 then omega/(2*Modelica.Constants.pi*f_ref) else 2*Modelica.Constants.pi*f_ref/omega));
  v = Complex(R_actual, X_actual) * i;
  LossPower = real(v*conj(i));
end Impedance;


Single-phase linear inductor. The linear inductor connects the voltage v with the
current i by  v = j*ω*L*i.
The Inductance L is allowed to be positive, zero, or negative.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Inductor "Single-phase linear inductor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  parameter SI.Inductance L(start=1) "Inductance";
equation
  v = j*omega*L*i;
end Inductor;


within Modelica.Electrical.QuasiStatic.SinglePhase;
package Basic "Basic components for AC single-phase models"
  extends Modelica.Icons.Package;
end Basic;


Single-phase linear resistor. The linear resistor connects the complex voltage v with the complex
current i by i*R = v.
The resistance R is allowed to be positive, zero, or negative.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Resistor "Single-phase linear resistor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  parameter SI.Resistance R_ref(start=1) "Reference resistance at T_ref";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance R_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R_ref*(1 + alpha_ref*(T_heatPort - T_ref));
  v = R_actual*i;
  LossPower = real(v*conj(i));
end Resistor;


Transformer with two ports. The transformer is a two port. The left port voltage v1, left port current i1, right port voltage v2 and right port current i2 are connected by the following relation:

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model Transformer "Transformer with two ports"
  import Modelica.ComplexMath.j;
  parameter Modelica.Units.SI.Inductance L1(start=1) "Primary inductance";
  parameter Modelica.Units.SI.Inductance L2(start=1) "Secondary inductance";
  parameter Modelica.Units.SI.Inductance M(start=1) "Coupling inductance";

  Modelica.Units.SI.AngularVelocity omega=der(pin_p1.reference.gamma)
    "Angular velocity of reference frame";
  Modelica.Units.SI.ComplexVoltage v1=pin_p1.v - pin_n1.v
    "Voltage drop of side 1";
  Modelica.Units.SI.ComplexCurrent i1=pin_p1.i "Current into side 1";
  Modelica.Units.SI.ComplexVoltage v2=pin_p2.v - pin_n2.v
    "Voltage drop of side 2";
  Modelica.Units.SI.ComplexCurrent i2=pin_p2.i "Current into side 2";

  Modelica.Units.SI.Voltage abs_v1=Modelica.ComplexMath.abs(v1)
    "Magnitude of complex voltage v1";
  Modelica.Units.SI.Angle arg_v1=Modelica.ComplexMath.arg(v1)
    "Argument of complex voltage v1";
  Modelica.Units.SI.Current abs_i1=Modelica.ComplexMath.abs(i1)
    "Magnitude of complex current i1";
  Modelica.Units.SI.Angle arg_i1=Modelica.ComplexMath.arg(i1)
    "Argument of complex current i1";
  Modelica.Units.SI.ActivePower P1=Modelica.ComplexMath.real(v1*
      Modelica.ComplexMath.conj(i1)) "Active power, side 1";
  Modelica.Units.SI.ReactivePower Q1=Modelica.ComplexMath.imag(v1*
      Modelica.ComplexMath.conj(i1)) "Reactive power, side 1";
  Modelica.Units.SI.ApparentPower S1=Modelica.ComplexMath.abs(v1*
      Modelica.ComplexMath.conj(i1))
    "Magnitude of complex apparent power, side 1";

  Modelica.Units.SI.Voltage abs_v2=Modelica.ComplexMath.abs(v2)
    "Magnitude of complex voltage v2";
  Modelica.Units.SI.Angle arg_v2=Modelica.ComplexMath.arg(v2)
    "Argument of complex voltage v2";
  Modelica.Units.SI.Current abs_i2=Modelica.ComplexMath.abs(i2)
    "Magnitude of complex current i2";
  Modelica.Units.SI.Angle arg_i2=Modelica.ComplexMath.arg(i2)
    "Argument of complex current i2";
  Modelica.Units.SI.ActivePower P2=Modelica.ComplexMath.real(v2*
      Modelica.ComplexMath.conj(i2)) "Active power, side 2";
  Modelica.Units.SI.ReactivePower Q2=Modelica.ComplexMath.imag(v2*
      Modelica.ComplexMath.conj(i2)) "Reactive power, side 2";
  Modelica.Units.SI.ApparentPower S2=Modelica.ComplexMath.abs(v2*
      Modelica.ComplexMath.conj(i2))
    "Magnitude of complex apparent power, side 2";
  Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p1
    "Primary positive pin"
  Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p2
    "Secondary positive pin"
  Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n1
    "Primary negative pin"
  Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n2
    "Secondary negative pin"
equation
  v1 = j*omega*L1*i1 + j*omega*M*i2;
  v2 = j*omega*L2*i2 + j*omega*M*i1;
  pin_p1.i + pin_n1.i = Complex(0, 0);
  pin_p2.i + pin_n2.i = Complex(0, 0);
  Connections.branch(pin_p1.reference, pin_n1.reference);
  pin_p1.reference.gamma = pin_n1.reference.gamma;
  Connections.branch(pin_n1.reference, pin_n2.reference);
  pin_p2.reference.gamma = pin_n2.reference.gamma;
  Connections.branch(pin_p1.reference, pin_p2.reference);
  pin_p1.reference.gamma = pin_p2.reference.gamma;
end Transformer;


Single-phase variable admittance. The admittance model represents a parallel connection of a conductor and either a capacitor or inductor.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableAdmittance "Single-phase variable admittance"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.imag;
  import Modelica.ComplexMath.conj;
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  Modelica.ComplexBlocks.Interfaces.ComplexInput Y_ref "Variable complex admittance"
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  SI.Conductance G_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  SI.Susceptance B_actual "Susceptance considering possible frequency dependency";
  SI.Conductance G_ref=real(Y_ref) "Resistive component of conductance";
  SI.Susceptance B_ref=imag(Y_ref) "Reactive component of susceptance";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G_ref/(1 + alpha_ref*(T_heatPort - T_ref));
  B_actual = B_ref * (if not frequencyDependent then 1 else
    (if B_ref>=0 then omega/(2*Modelica.Constants.pi*f_ref) else 2*Modelica.Constants.pi*f_ref/omega));
  i = Complex(G_actual, B_actual) * v;
  LossPower = real(v*conj(i));
end VariableAdmittance;


Single-phase variable capacitor. The linear capacitor connects the voltage v with the
current i by i = j*ω*C*v.
The capacitance C is given as input signal.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableCapacitor "Single-phase variable capacitor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  Modelica.Blocks.Interfaces.RealInput C(unit="F") "Variable capacitances"
equation
  i = j*omega*C*v;
end VariableCapacitor;


Single-phase variable conductor. The linear conductor connects the voltage v with the
current i by i = G*v.
The conductance G is given as input signal.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableConductor "Single-phase variable conductor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of conductance (G_actual = G_ref/(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Conductance G_actual "Conductance = G_ref/(1 + alpha_ref*(heatPort.T - T_ref))";
  Modelica.Blocks.Interfaces.RealInput G_ref(unit="S") "Variable conductance"
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  G_actual = G_ref/(1 + alpha_ref*(T_heatPort - T_ref));
  i = G_actual*v;
  LossPower = real(v*conj(i));
end VariableConductor;


Single-phase variable impedance. The impedance model represents a series connection of a resistor and either an inductor or capacitor.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableImpedance "Single-phase variable impedance"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.imag;
  import Modelica.ComplexMath.conj;
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  Modelica.ComplexBlocks.Interfaces.ComplexInput Z_ref "Variable complex impedance"
  parameter Boolean frequencyDependent = false "Consider frequency dependency, if true"
  parameter SI.Frequency f_ref = 1 "Reference frequency, if frequency dependency is considered"
  SI.Resistance R_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  SI.Reactance X_actual "Reactance considering possible frequency dependency";
  SI.Resistance R_ref=real(Z_ref) "Resistive component of impedance, resistance";
  SI.Reactance X_ref=imag(Z_ref) "Reactive component of impedance, reactance";
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R_ref*(1 + alpha_ref*(T_heatPort - T_ref));
  X_actual = X_ref * (if not frequencyDependent then 1 else
    (if X_ref>=0 then omega/(2*Modelica.Constants.pi*f_ref) else 2*Modelica.Constants.pi*f_ref/omega));
  v = Complex(R_actual, X_actual) * i;
  LossPower = real(v*conj(i));
end VariableImpedance;


Single-phase variable inductor. The linear inductor connects the branch voltage v with the
branch current i by v = j*ω*L*i. The inductance L is given as input signal.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableInductor "Single-phase variable inductor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.j;
  Modelica.Blocks.Interfaces.RealInput L(unit="H") "Variable inductances"
equation
  v = j*omega*L*i;
end VariableInductor;


Single-phase variable resistor. The linear resistor connects the voltage v with the
current i by i*R = v.
The resistance R is given as input signal.

within Modelica.Electrical.QuasiStatic.SinglePhase.Basic;
model VariableResistor "Single-phase variable resistor"
  extends Interfaces.OnePort;
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha_ref=0 "Temperature coefficient of resistance (R_actual = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance R_actual "Resistance = R_ref*(1 + alpha_ref*(heatPort.T - T_ref))";
  Modelica.Blocks.Interfaces.RealInput R_ref(unit="Ohm") "Variable resistance"
equation
  assert((1 + alpha_ref*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  R_actual = R_ref*(1 + alpha_ref*(T_heatPort - T_ref));
  v = R_actual*i;
  LossPower = real(v*conj(i));
end VariableResistor;


Demonstrates series and parallel resonance using a transformer. The series resonance load circuit is fed by a voltage source with inner impedance.
By using a transformer between source and load, we achieve multiple resonance by varying the source frequency:

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model MultipleResonance
  "Demonstrates series and parallel resonance using a transformer"
  extends Icons.Example;
  import Modelica.Constants.small;
  parameter Modelica.Units.SI.Voltage V=0.5 "Source rms voltage";
  parameter Modelica.Units.SI.Frequency fLo=5.e6 "Lower source frequency";
  parameter Modelica.Units.SI.Frequency fUp=15e6 "Upper source frequency";
  parameter Modelica.Units.SI.ComplexImpedance Zi=Modelica.Units.SI.ComplexImpedance(100) "Source inner impedance";
  parameter Modelica.Units.SI.Inductance L1=30e-6 "Transformer primary inductance";
  parameter Modelica.Units.SI.Inductance L2=1.e-6 "Transformer secondary inductance";
  parameter Real k(min=small, max=1)=0.95 "Transformer coupling factor";
  parameter Modelica.Units.SI.Inductance M=k*sqrt(L1*L2) "Transformer mutual inductance"
  parameter Modelica.Units.SI.Resistance R=5 "Load resistance";
  parameter Modelica.Units.SI.Inductance L=5e-6 "Load inductance";
  parameter Modelica.Units.SI.Capacitance C=50e-12 "Load capacitance";
  Sources.VariableVoltageSource voltageSource(
    gamma(fixed=true))
  Basic.Impedance zi(Z_ref=Zi)
  Basic.Transformer transformer(
    L1=L1,
    L2=L2,
    M=M)
  Basic.Ground ground1
  Basic.Ground ground2
  Basic.Resistor loadResistor(R_ref=R)
  Basic.Inductor loadInductor(L=L)
  Basic.Capacitor loadCapacitor(C=C)
  ComplexBlocks.Sources.ComplexConstant complexConst(k(re=V, im=0))
  Blocks.Sources.LogFrequencySweep frequencySweep(
    duration=1,
    wMin=fLo,
    wMax=fUp)
  Sensors.CurrentSensor currentSensor
equation
  connect(voltageSource.pin_n, ground1.pin)
  connect(ground1.pin, transformer.pin_n1)
  connect(transformer.pin_n2, ground2.pin)
  connect(ground2.pin, loadCapacitor.pin_n)
  connect(loadCapacitor.pin_p, loadInductor.pin_n)
  connect(loadInductor.pin_p, loadResistor.pin_n)
  connect(complexConst.y, voltageSource.V)
  connect(transformer.pin_p2, loadResistor.pin_p)
  connect(voltageSource.pin_p, zi.pin_p)
  connect(frequencySweep.y, voltageSource.f)
  connect(zi.pin_n, currentSensor.pin_p)
  connect(currentSensor.pin_n, transformer.pin_p1)
end MultipleResonance;


Test examples

within Modelica.Electrical.QuasiStatic.SinglePhase;
package Examples "Test examples"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Parallel resonance circuit. The frequency of the current source is varied by a ramp.
Plot length and angle of the voltage phasor, i.e., complexToPolar.len and .phi, versus time resp. frequency.

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model ParallelResonance "Parallel resonance circuit"
  extends Modelica.Icons.Example;
  output SI.Voltage V_abs=complexToPolar.len "Voltage";
  output SI.Angle V_arg=complexToPolar.phi "Voltage phase";
  Modelica.Blocks.Sources.Constant I(k=1)
  Modelica.Blocks.Sources.Constant phi(k=0)
  Modelica.Blocks.Sources.Ramp f(
    height=2,
    duration=1,
    offset=1e-6)
  QuasiStatic.SinglePhase.Sources.VariableCurrentSource currentSource(gamma(
        fixed=true, start=0))
  QuasiStatic.SinglePhase.Basic.Ground ground
  QuasiStatic.SinglePhase.Basic.Resistor resistor(R_ref=10)
  QuasiStatic.SinglePhase.Basic.Inductor inductor(L=1/(2*Modelica.Constants.pi))
  QuasiStatic.SinglePhase.Basic.Capacitor capacitor(C=1/(2*Modelica.Constants.pi))
  QuasiStatic.SinglePhase.Sensors.VoltageSensor voltageSensor
  Modelica.ComplexBlocks.ComplexMath.PolarToComplex polarToComplex
  Modelica.ComplexBlocks.ComplexMath.ComplexToPolar complexToPolar
equation
  connect(currentSource.pin_n, resistor.pin_p)
  connect(currentSource.pin_n, inductor.pin_p)
  connect(currentSource.pin_n, capacitor.pin_p)
  connect(currentSource.pin_n, voltageSensor.pin_p)
  connect(currentSource.pin_p, ground.pin)
  connect(resistor.pin_n, ground.pin)
  connect(inductor.pin_n, ground.pin)
  connect(capacitor.pin_n, ground.pin)
  connect(voltageSensor.pin_n, ground.pin)
  connect(f.y, currentSource.f)
  connect(polarToComplex.y, currentSource.I)
  connect(phi.y, polarToComplex.phi)
  connect(I.y, polarToComplex.len)
  connect(voltageSensor.v, complexToPolar.u)
end ParallelResonance;


Rectifier example. This example demonstrates coupling a quasi-static circuit with a DC circuit.
The QS voltage is rectified (using an

ideal AC DC converter), loaded by a variable load conductor.
The conversionFactor = DC voltage / AC rms voltage in this case is the root mean square of a rectified sine, i.e., 1.
You may compare the quasi-static results with that of a fully transient model (using a

Graetz rectifier), plotting:

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model Rectifier "Rectifier example"
  extends Modelica.Icons.Example;
  import Modelica.Constants.pi;
  parameter SI.Voltage VAC=100 "AC rms voltage";
  parameter Real conversionFactor=1 "Ratio of DC voltage / AC rms voltage";
  output SI.Current Itr=iAC.y_rms "Transient current";
  output SI.Current Iqs=iQS.len "QS current";
  Sources.VoltageSource voltageQS(
    f=50,
    V=VAC,
    phi=0,
    i(re(start=0), im(start=0)),
    gamma(fixed=true, start=0))
  Basic.Resistor resistorQS(R_ref=50E-3)
  Sensors.CurrentSensor currentSensorQS
  Modelica.ComplexBlocks.ComplexMath.ComplexToPolar iQS
  Basic.Ground groundQS
  Utilities.IdealACDCConverter rectifierQS(conversionFactor=
        conversionFactor)
  Modelica.Electrical.Analog.Basic.Ground groundDC1
  Modelica.Electrical.Analog.Sensors.CurrentSensor iDC1
  Modelica.Electrical.Analog.Basic.VariableConductor load1
  Modelica.Electrical.Analog.Sources.SineVoltage voltageAC(
    V=sqrt(2)*VAC,
    f=50,
    phase=pi/2)
  Modelica.Electrical.Analog.Basic.Resistor resistorAC(R=50E-3)
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensorAC
  Modelica.Blocks.Math.Harmonic iAC(f=50, k=1)
  Modelica.Electrical.Analog.Basic.Ground groundAC
  Utilities.GraetzRectifier rectifierAC
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensorDC2
  Modelica.Blocks.Math.RootMeanSquare iDC2(f=50)
  Modelica.Electrical.Analog.Basic.VariableConductor load2
  Modelica.Blocks.Sources.Ramp ramp(
    height=1,
    duration=0.8,
    startTime=0.1)
equation
  connect(voltageQS.pin_p, resistorQS.pin_p)
  connect(voltageQS.pin_n, rectifierQS.pin_nQS)
  connect(rectifierQS.pin_nQS, groundQS.pin)
  connect(rectifierQS.pin_nDC, groundDC1.p)
  connect(load1.n, rectifierQS.pin_nDC)
  connect(voltageAC.p, resistorAC.p)
  connect(voltageAC.n, rectifierAC.pin_nAC)
  connect(rectifierAC.pin_nAC, groundAC.p)
  connect(rectifierAC.pin_nDC, load2.n)
  connect(ramp.y, load1.G)
  connect(ramp.y, load2.G)
  connect(resistorQS.pin_n, currentSensorQS.pin_p)
  connect(currentSensorQS.pin_n, rectifierQS.pin_pQS)
  connect(currentSensorQS.i, iQS.u)
  connect(rectifierQS.pin_pDC, iDC1.p)
  connect(iDC1.n, load1.p)
  connect(resistorAC.n, currentSensorAC.p)
  connect(currentSensorAC.n, rectifierAC.pin_pAC)
  connect(currentSensorAC.i, iAC.u)
  connect(currentSensorDC2.i, iDC2.u)
  connect(currentSensorDC2.p, rectifierAC.pin_pDC)
  connect(currentSensorDC2.n, load2.p)
end Rectifier;


Series circuit with Bode analysis. The frequency of the voltage source is varied by a logarithmic ramp, the supply voltage magnitude is constant.

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model SeriesBode "Series circuit with Bode analysis"
  extends Modelica.Icons.Example;
  output Real abs_y = bode.abs_y "Magnitude of voltage ratio";
  output SI.AmplitudeLevelDifference dB_y = bode.dB_y "Log10 of magnitude of voltage ratio";
  output SI.Angle arg_y = bode.arg_y "Angle of voltage ratio";
  Modelica.Blocks.Sources.LogFrequencySweep frequencySweep(
    duration=1,
    wMin=0.01,
    wMax=100)
  QuasiStatic.SinglePhase.Sources.VariableVoltageSource voltageSource(gamma(
        fixed=true, start=0))
  QuasiStatic.SinglePhase.Basic.Ground ground
  QuasiStatic.SinglePhase.Basic.Resistor resistor(R_ref=1)
  QuasiStatic.SinglePhase.Basic.Inductor inductor(L=1/(2*Modelica.Constants.pi))
  Modelica.ComplexBlocks.Sources.ComplexConstant complexConst(k=Complex(1, 0))
  Sensors.CurrentSensor currentSensor
  Sensors.VoltageSensor voltageSensor
  Modelica.ComplexBlocks.ComplexMath.Bode bode
equation
  connect(frequencySweep.y, voltageSource.f)
  connect(ground.pin, voltageSource.pin_n)
  connect(resistor.pin_n, inductor.pin_p)
  connect(complexConst.y, voltageSource.V)
  connect(voltageSensor.pin_p, resistor.pin_p)
  connect(voltageSensor.pin_n, inductor.pin_p)
  connect(ground.pin, inductor.pin_n)
  connect(bode.divisor, complexConst.y)
  connect(bode.u,voltageSensor.v)
  connect(currentSensor.pin_p, voltageSource.pin_p)
  connect(currentSensor.pin_n, resistor.pin_p)
end SeriesBode;


Series resonance circuit. The frequency of the voltage source is varied by a ramp.
Plot length and angle of the current phasor, i.e., complexToPolar.len and .phi, versus time resp. frequency.

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model SeriesResonance "Series resonance circuit"
  extends Modelica.Icons.Example;
  output SI.Current I_abs=complexToPolar.len "Current";
  output SI.Angle I_arg=complexToPolar.phi "Current phase";
  Modelica.Blocks.Sources.Constant V(k=1)
  Modelica.Blocks.Sources.Constant phi(k=0)
  Modelica.Blocks.Sources.Ramp f(
    height=2,
    duration=1,
    offset=1e-6)
  QuasiStatic.SinglePhase.Sources.VariableVoltageSource voltageSource(gamma(
        fixed=true, start=0))
  QuasiStatic.SinglePhase.Basic.Ground ground
  QuasiStatic.SinglePhase.Basic.Resistor resistor(R_ref=0.1)
  QuasiStatic.SinglePhase.Basic.Inductor inductor(L=1/(2*Modelica.Constants.pi))
  QuasiStatic.SinglePhase.Basic.Capacitor capacitor(C=1/(2*Modelica.Constants.pi))
  QuasiStatic.SinglePhase.Sensors.CurrentSensor currentSensor
  Modelica.ComplexBlocks.ComplexMath.PolarToComplex polarToComplex
  Modelica.ComplexBlocks.ComplexMath.ComplexToPolar complexToPolar
equation
  connect(f.y, voltageSource.f)
  connect(polarToComplex.y, voltageSource.V)
  connect(ground.pin, voltageSource.pin_n)
  connect(voltageSource.pin_p, currentSensor.pin_p)
  connect(currentSensor.pin_n, resistor.pin_p)
  connect(resistor.pin_n, inductor.pin_p)
  connect(inductor.pin_n, capacitor.pin_p)
  connect(capacitor.pin_n, ground.pin)
  connect(phi.y, polarToComplex.phi)
  connect(V.y, polarToComplex.len)
  connect(currentSensor.i, complexToPolar.u)
end SeriesResonance;


Example of transformer with short circuit impedance, transmission resistances and load. This examples shows the operational behavior of transformer with short circuit impedance. The transformer is loaded with constant current magnitude of 250A but variable phase angle. The angle varies from 0 to 360 degrees within one second of simulation time.

within Modelica.Electrical.QuasiStatic.SinglePhase.Examples;
model Transformer "Example of transformer with short circuit impedance, transmission resistances and load"
  extends Modelica.Icons.Example;
  Sources.VoltageSource voltageSource(
    f=50,
    V=1000,
    phi=0,
    gamma(fixed=true, start=0))
  Ideal.IdealTransformer idealTransformer(n=5)
  Sensors.PowerSensor sensor0
  Basic.Impedance zk(Z_ref(re=0.72, im=0.96))
  Sources.VariableCurrentSource load(gamma(fixed=true, start=0))
  Sensors.PowerSensor sensorL
  Basic.Ground ground1
  Basic.Ground ground2
  Sensors.VoltageSensor v2
  Modelica.ComplexBlocks.ComplexMath.PolarToComplex polarToComplex
  Modelica.Blocks.Sources.Constant const(k=250)
  Modelica.Blocks.Sources.Ramp ramp(
    duration=1,
    offset=0,
    startTime=0,
    height=2*Modelica.Constants.pi)
  Modelica.Blocks.Sources.Constant constFrequency(k=50)
  Sensors.CurrentSensor i2
  Sensors.CurrentSensor i1
equation
  connect(voltageSource.pin_p, sensor0.currentP)
  connect(zk.pin_n, idealTransformer.pin_p1)
  connect(sensorL.voltageP, sensorL.currentP)
  connect(voltageSource.pin_n, ground1.pin)
  connect(ground1.pin, idealTransformer.pin_n1)
  connect(sensor0.currentP, sensor0.voltageP)
  connect(sensor0.voltageN, ground1.pin)
  connect(v2.pin_n, ground2.pin)
  connect(const.y, polarToComplex.len)
  connect(ramp.y, polarToComplex.phi)
  connect(load.pin_p, sensorL.currentN)
  connect(sensorL.voltageN, ground2.pin)
  connect(load.pin_n, ground2.pin)
  connect(ground2.pin, idealTransformer.pin_n2)
  connect(load.I, polarToComplex.y)
  connect(load.f, constFrequency.y)
  connect(sensorL.currentP, v2.pin_p)
  connect(i2.pin_n, sensorL.currentP)
  connect(sensor0.currentN, i1.pin_p)
  connect(i1.pin_n, zk.pin_p)
  connect(idealTransformer.pin_p2, i2.pin_p)
end Transformer;


Ideal electrical closer. The ideal closing switch has a positive pin p and a negative pin n.
The switching behaviour is controlled by input signal control.
If control is true, pin p is connected
with negative pin n. Otherwise, pin p is not connected
with negative pin n.

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model IdealClosingSwitch "Ideal electrical closer"
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  extends QuasiStatic.SinglePhase.Interfaces.OnePort;
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5 "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=293.15);
  Modelica.Blocks.Interfaces.BooleanInput control "true => p--n connected, false => switch open"
protected
  Complex s(re(final unit="1"), im(final unit="1")) "Auxiliary variable";
  constant SI.ComplexVoltage unitVoltage=Complex(1, 0)
  constant SI.ComplexCurrent unitCurrent=Complex(1, 0)
equation
  v = (s*unitCurrent)*(if control then Ron else 1);
  i = (s*unitVoltage)*(if control then 1 else Goff);

  LossPower = real(v*conj(i));
end IdealClosingSwitch;


Ideal commuting switch. The commuting switch has a positive pin p and two negative pins n1 and n2.
The switching behaviour is controlled
by the input signal control. If control is true, the pin p is connected
with the negative pin n2. Otherwise, the pin p is connected to the negative pin n1.

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model IdealCommutingSwitch "Ideal commuting switch"
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.conj;
  parameter SI.Resistance Ron(final min=0) = 1e-5 "Closed switch resistance";
  parameter SI.Conductance Goff(final min=0) = 1e-5 "Opened switch conductance";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(final T=
       293.15);
  QuasiStatic.SinglePhase.Interfaces.PositivePin p
  QuasiStatic.SinglePhase.Interfaces.NegativePin n2
  QuasiStatic.SinglePhase.Interfaces.NegativePin n1
  Modelica.Blocks.Interfaces.BooleanInput control "true => p--n2 connected, false => p--n1 connected"
protected
  Complex s1(re(final unit="1"), im(final unit="1"));
  Complex s2(re(final unit="1"), im(final unit="1")) "Auxiliary variables";
  constant SI.ComplexVoltage unitVoltage=Complex(1, 0)
  constant SI.ComplexCurrent unitCurrent=Complex(1, 0)
equation
  Connections.branch(p.reference, n1.reference);
  p.reference.gamma = n1.reference.gamma;
  Connections.branch(p.reference, n2.reference);
  p.reference.gamma = n2.reference.gamma;
  p.i + n2.i + n1.i = Complex(0, 0);
  p.v - n1.v = (s1*unitCurrent)*(if (control) then 1 else Ron);
  n1.i = -(s1*unitVoltage)*(if (control) then Goff else 1);
  p.v - n2.v = (s2*unitCurrent)*(if (control) then Ron else 1);
  n2.i = -(s2*unitVoltage)*(if (control) then 1 else Goff);
  LossPower = real(p.v*conj(p.i)) + real(n1.v*conj(n1.i)) + real(n2.v*conj(
    n2.i));
end IdealCommutingSwitch;