Ideal intermediate switch. The intermediate switch has four switching contact pins p1, p2, n1, and n2.
The switching behaviour is controlled by the input signal control. If control
is true, the pin p1 is connected to pin n2, and the pin p2 is
connected to the pin n2. Otherwise, the pin p1 is connected to n1, and
p2 is connected to n2.

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model IdealIntermediateSwitch "Ideal intermediate 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 p1
  QuasiStatic.SinglePhase.Interfaces.PositivePin p2
  QuasiStatic.SinglePhase.Interfaces.NegativePin n1
  QuasiStatic.SinglePhase.Interfaces.NegativePin n2
  Modelica.Blocks.Interfaces.BooleanInput control "true => p1--n2, p2--n1 connected, otherwise p1--n1, p2--n2  connected"
protected
  Complex s1(re(final unit="1"), im(final unit="1"));
  Complex s2(re(final unit="1"), im(final unit="1"));
  Complex s3(re(final unit="1"), im(final unit="1"));
  Complex s4(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(p1.reference, n1.reference);
  p1.reference.gamma = n1.reference.gamma;
  Connections.branch(p2.reference, n2.reference);
  p2.reference.gamma = n2.reference.gamma;
  Connections.branch(n1.reference, n2.reference);
  n1.reference.gamma = n2.reference.gamma;

  p1.v - n1.v = (s1*unitCurrent)*(if (control) then 1 else Ron);
  p2.v - n2.v = (s2*unitCurrent)*(if (control) then 1 else Ron);
  p1.v - n2.v = (s3*unitCurrent)*(if (control) then Ron else 1);
  p2.v - n1.v = (s4*unitCurrent)*(if (control) then Ron else 1);

  p1.i = if control then s1*unitVoltage*Goff + s3*unitCurrent else s1*
    unitCurrent + s3*unitVoltage*Goff;
  p2.i = if control then s2*unitVoltage*Goff + s4*unitCurrent else s2*
    unitCurrent + s4*unitVoltage*Goff;
  n1.i = if control then -s1*unitVoltage*Goff - s4*unitCurrent else -s1*
    unitCurrent - s4*unitVoltage*Goff;
  n2.i = if control then -s2*unitVoltage*Goff - s3*unitCurrent else -s2*
    unitCurrent - s3*unitVoltage*Goff;

  LossPower = real(p1.v*conj(p1.i)) + real(p2.v*conj(p2.i)) + real(n1.v*
    conj(n1.i)) + real(n2.v*conj(n2.i));
end IdealIntermediateSwitch;


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

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model IdealOpeningSwitch "Ideal electrical opener"
  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 => switch open, false => p--n connected"
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 1 else Ron);
  i = (s*unitVoltage)*(if control then Goff else 1);

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


Ideal transformer. The ideal transformer is a two-port circuit element without magnetization. Voltages and currents are ideally transformed:

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model IdealTransformer "Ideal transformer"
  parameter Real n=1 "Ratio of primary to secondary voltage";
  SI.ComplexVoltage v1=pin_p1.v - pin_n1.v "Voltage drop of side 1";
  SI.ComplexCurrent i1=pin_p1.i "Current into side 1";
  SI.ComplexVoltage v2=pin_p2.v - pin_n2.v "Voltage drop of side 2";
  SI.ComplexCurrent i2=pin_p2.i "Current into side 2";

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

  SI.Voltage abs_v2=Modelica.ComplexMath.abs(v2) "Magnitude of complex voltage v2";
  SI.Angle arg_v2=Modelica.ComplexMath.arg(v2) "Argument of complex voltage v2";
  SI.Current abs_i2=Modelica.ComplexMath.abs(i2) "Magnitude of complex current i2";
  SI.Angle arg_i2=Modelica.ComplexMath.arg(i2) "Argument of complex current i2";
  SI.ActivePower P2=Modelica.ComplexMath.real(v2*
      Modelica.ComplexMath.conj(i2)) "Active power, side 2";
  SI.ReactivePower Q2=Modelica.ComplexMath.imag(v2*
      Modelica.ComplexMath.conj(i2)) "Reactive power, side 2";
  SI.ApparentPower S2=Modelica.ComplexMath.abs(v2*
      Modelica.ComplexMath.conj(i2)) "Magnitude of complex apparent power, side 2";
  Real pf2=cos(Modelica.ComplexMath.arg(Complex(P2, Q2))) "Power factor, side 2";

  QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p1 "Primary positive pin"
  QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p2
    "Secondary positive pin"
  QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n1 "Primary negative pin"
  QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n2
    "Secondary negative pin"
equation
  // Current balance
  pin_p1.i + pin_n1.i = Complex(0, 0);
  pin_p2.i + pin_n2.i = Complex(0, 0);
  // Transformation ratios
  v1 = Complex(+n, 0)*v2;
  i2 = Complex(-n, 0)*i1;
  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 IdealTransformer;


Idle branch. This model is a simple idle branch considering the complex current i = 0.

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model Idle "Idle branch"
  extends Interfaces.OnePort;
equation
  i = Complex(0);
end Idle;


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


Short cut branch. This model is a simple short cut branch considering the complex voltage v = 0.

within Modelica.Electrical.QuasiStatic.SinglePhase.Ideal;
model Short "Short cut branch"
  extends Interfaces.OnePort;
equation
  v = Complex(0);
end Short;


Partial potential sensor. The absolute sensor partial model provides a single
positive pin
to measure the complex voltage, frequency, angular frequency. Additionally this model contains
a proper icon and a definition of the angular velocity.

within Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces;
partial model AbsoluteSensor "Partial potential sensor"
  extends Modelica.Icons.RoundSensor;
  SI.AngularVelocity omega;
  PositivePin pin "Positive quasi-static single-phase pin"
equation
  omega = der(pin.reference.gamma);
  pin.i = Complex(0);
end AbsoluteSensor;


Two pins, current through. This partial model is based on TwoPin and
additionally considers the complex current balance of the
positive and the
negative pin.
This model is intended to be used with textual representation of user models.

within Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces;
partial model OnePort "Two pins, current through"
  extends TwoPin;
equation
  pin_p.i + pin_n.i = Complex(0);
end OnePort;


Interfaces for AC single-phase models

within Modelica.Electrical.QuasiStatic.SinglePhase;
package Interfaces "Interfaces for AC single-phase models"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


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

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

equation
  Complex(0,0) = pin_p.i + pin_n.i "Current balance";
end RelativeSensorElementary;


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

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


Two pins. This partial model uses a positive
and negative pin and defines
the complex voltage difference as well as the complex current (into the positive pin).
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.SinglePhase.Interfaces;
partial model TwoPin "Two pins"
  import Modelica.Constants.eps;
  extends Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.TwoPinElementary;

  SI.ComplexVoltage v "Complex voltage";
  SI.Voltage abs_v=Modelica.ComplexMath.abs(v) "Magnitude of complex voltage";
  SI.Angle arg_v=Modelica.ComplexMath.arg(v) "Argument of complex voltage";
  SI.ComplexCurrent i "Complex current";
  SI.Current abs_i=Modelica.ComplexMath.abs(i) "Magnitude of complex current";
  SI.Angle arg_i=Modelica.ComplexMath.arg(i) "Argument of complex current";
  SI.ActivePower P=Modelica.ComplexMath.real(v*
      Modelica.ComplexMath.conj(i)) "Active power";
  SI.ReactivePower Q=Modelica.ComplexMath.imag(v*
      Modelica.ComplexMath.conj(i)) "Reactive power";
  SI.ApparentPower S=Modelica.ComplexMath.abs(v*
      Modelica.ComplexMath.conj(i)) "Magnitude of complex apparent power";
  Real pf=cos(Modelica.ComplexMath.arg(Complex(P, Q))) "Power factor";
  SI.AngularVelocity omega "Angular velocity of reference frame";

equation
  v = pin_p.v - pin_n.v;
  i = pin_p.i;
end TwoPin;


Elementary two pins with reference connection, without declaration of voltage and current. This partial model uses a positive
and negative pin,
but no complex voltage, current, power, etc. 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.SinglePhase.Interfaces;
partial model TwoPinElementary "Elementary two pins with reference connection, without declaration of voltage and current"
  import Modelica.Constants.eps;
  SI.AngularVelocity omega "Angular velocity of reference frame";

  PositivePin pin_p "Positive quasi-static single-phase pin"
  NegativePin pin_n "Negative quasi-static single-phase pin"
equation
  Connections.branch(pin_p.reference, pin_n.reference);
  pin_p.reference.gamma = pin_n.reference.gamma;
  omega = der(pin_p.reference.gamma);
end TwoPinElementary;


Continuous current RMS sensor for single-phase system. This sensor determines the continuous root mean square (RMS)
value of a single-phase current system.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model CurrentRMSSensor "Continuous current RMS sensor for single-phase system"
  extends Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.RelativeSensorElementary;
  Modelica.Blocks.Interfaces.RealOutput I(unit="A")
    "Continuous average RMS of current"
  SI.ComplexCurrent i "Complex current";
  SI.ComplexVoltage v "Complex voltage";
equation
  I = sqrt(i.re^2 + i.im^2);
  i = pin_p.i;
  v = pin_p.v - pin_n.v;
  v = Complex(0,0);
end CurrentRMSSensor;


Current sensor. This sensor can be used to measure the complex current.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model CurrentSensor "Current sensor"
  extends Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.RelativeSensorElementary;
  Modelica.ComplexBlocks.Interfaces.ComplexOutput i(re(unit = "A"), im(unit = "A")) "Complex current"
  SI.Current abs_i=Modelica.ComplexMath.abs(i) "Magnitude of complex current";
  SI.Angle arg_i=Modelica.ComplexMath.arg(i) "Argument of complex current";
  SI.ComplexVoltage v "Complex voltage";
equation
  i = pin_p.i;
  v = pin_p.v - pin_n.v;
  v = Complex(0,0);
end CurrentSensor;


Frequency sensor. This sensor can be used to measure the frequency of the reference system.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model FrequencySensor "Frequency sensor"
  extends Interfaces.AbsoluteSensor;
  import Modelica.Constants.pi;
  Modelica.Blocks.Interfaces.RealOutput f(unit="Hz") "Frequency"
equation
  2*pi*f = omega;
end FrequencySensor;


Sensor to measure current, voltage and power. This multi sensor measures current, voltage and instantaneous electrical power of a single-phase system and has a separated voltage and current path.
The pins of the voltage path are pv and nv, the pins of the current path are pc and nc.
The internal resistance of the current path is zero, the internal resistance of the voltage path is infinite.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model MultiSensor "Sensor to measure current, voltage and power"
  extends Modelica.Icons.RoundSensor;
  import Modelica.ComplexMath.conj;
  import Modelica.ComplexMath.abs;
  import Modelica.ComplexMath.arg;
  QuasiStatic.SinglePhase.Interfaces.PositivePin pc
    "Positive pin, current path"
  QuasiStatic.SinglePhase.Interfaces.NegativePin nc
    "Negative pin, current path"
  QuasiStatic.SinglePhase.Interfaces.PositivePin pv
    "Positive pin, voltage path"
  QuasiStatic.SinglePhase.Interfaces.NegativePin nv
    "Negative pin, voltage path"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput i(
    redeclare final SI.Current re, redeclare final SI.Current im)
    "Current as complex output signal"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput v(
    redeclare final SI.Voltage re, redeclare final SI.Voltage im)
    "Voltage as complex output signal"
  Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower(
    redeclare final SI.ActivePower re, redeclare final SI.ReactivePower im)
    "Instantaneous apparent power as complex output signal"
  output SI.Current abs_i=abs(i) "Absolute of complex current";
  output SI.Angle arg_i=arg(i) "Argument of complex current";
  output SI.Voltage abs_v=abs(v) "Absolute of complex voltage";
  output SI.Angle arg_v=arg(v) "Argument of complex voltage";
  output SI.ApparentPower abs_apparentPower=abs(apparentPower) "Absolute of complex apparent power";
  output SI.Angle arg_apparentPower=arg(apparentPower) "Argument of 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.i + nc.i = Complex(0);
  pc.v - nc.v = Complex(0);
  pv.i = Complex(0);
  nv.i = Complex(0);
  i = pc.i;
  v = pv.v - nv.v;
  apparentPower = v*conj(i);
end MultiSensor;


AC single-phase sensors

within Modelica.Electrical.QuasiStatic.SinglePhase;
package Sensors "AC single-phase sensors"
  extends Modelica.Icons.SensorsPackage;
end Sensors;


Potential sensor. This sensor can be used to measure the complex potential.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model PotentialSensor "Potential sensor"
  extends Interfaces.AbsoluteSensor;
  Modelica.ComplexBlocks.Interfaces.ComplexOutput v "Complex potential"
  SI.Voltage abs_v=Modelica.ComplexMath.abs(v) "Magnitude of complex potential";
  SI.Angle arg_v=Modelica.ComplexMath.arg(v) "Argument of complex potential";
equation
  v = pin.v;
end PotentialSensor;


Power sensor. This sensor can be used to measure the complex apparent power.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model PowerSensor "Power sensor"
  import Modelica.ComplexMath.conj;
  extends Modelica.Icons.RoundSensor;
  Interfaces.PositivePin currentP
  Interfaces.NegativePin currentN
  Interfaces.PositivePin voltageP
  Interfaces.NegativePin voltageN
  output SI.ComplexCurrent i;
  output SI.ComplexVoltage v;
  Modelica.ComplexBlocks.Interfaces.ComplexOutput apparentPower(re(unit="W"), im(unit="var")) "Complex apparent power = active power + j * reactive power"
  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
  Connections.branch(currentP.reference, currentN.reference);
  currentP.reference.gamma = currentN.reference.gamma;
  Connections.branch(voltageP.reference, voltageN.reference);
  voltageP.reference.gamma = voltageN.reference.gamma;
  Connections.branch(currentP.reference, voltageP.reference);
  currentP.reference.gamma = voltageP.reference.gamma;
  currentP.i + currentN.i = Complex(0);
  currentP.v - currentN.v = Complex(0);
  i = currentP.i;
  voltageP.i + voltageN.i = Complex(0);
  voltageP.i = Complex(0);
  v = voltageP.v - voltageN.v;
  //P + j*Q = v * conj(i);
  apparentPower = v*conj(i);
end PowerSensor;


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

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model ReferenceSensor "Sensor of reference angle gamma"
  extends QuasiStatic.SinglePhase.Interfaces.AbsoluteSensor;
  Modelica.Blocks.Interfaces.RealOutput gamma(unit="rad") "Reference angle"
equation
  gamma = pin.reference.gamma;
end ReferenceSensor;


Continuous voltage RMS sensor for single-phase system. This sensor determines the continuous root mean square (RMS)
value of a single-phase voltage system.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model VoltageRMSSensor "Continuous voltage RMS sensor for single-phase system"
  extends Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.RelativeSensorElementary;
  Modelica.Blocks.Interfaces.RealOutput V(unit="V")
    "Continuous average RMS of voltage"
  SI.ComplexVoltage v "Complex voltage";
  SI.ComplexCurrent i "Complex current";
equation
  V = sqrt(v.re^2 + v.im^2);
  v = pin_p.v - pin_n.v;
  i = pin_p.i;
  i = Complex(0,0);
end VoltageRMSSensor;


Voltage sensor. This sensor can be used to measure the complex voltage.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sensors;
model VoltageSensor "Voltage sensor"
  extends Modelica.Electrical.QuasiStatic.SinglePhase.Interfaces.RelativeSensorElementary;
  Modelica.ComplexBlocks.Interfaces.ComplexOutput v(re(unit = "V"), im(unit = "V")) "Complex voltage"
  SI.Voltage abs_v=Modelica.ComplexMath.abs(v) "Magnitude of complex voltage";
  SI.Angle arg_v=Modelica.ComplexMath.arg(v) "Argument of complex voltage";
  SI.ComplexCurrent i "Complex current";
equation
  v = pin_p.v - pin_n.v;
  i = pin_p.i;
  i = Complex(0,0);
end VoltageSensor;


Constant AC current. This is a constant current source, specifying the complex current by the RMS current and the phase shift.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sources;
model CurrentSource "Constant AC current"
  extends Interfaces.Source;
  parameter SI.Frequency f(start=1) "Frequency of the source";
  parameter SI.Current I(start=1) "RMS current of the source";
  parameter SI.Angle phi(start=0) "Phase shift of the source";
equation
  omega = 2*Modelica.Constants.pi*f;
  i = Complex(I*cos(phi), I*sin(phi));
end CurrentSource;


Current source with integrated frequency sweep. This source provides a constant RMS phase current I and phase angle 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.SinglePhase.Sources;
model FrequencySweepCurrentSource "Current source with integrated frequency sweep"
  extends Interfaces.TwoPin;
  import Modelica.Constants.eps;
  SI.Angle gamma(start=0) = pin_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(start=1) "RMS current of the source";
  parameter SI.Angle phi=0 "Phase shift of the source";
  SI.Frequency f = currentSource.f "Actual frequency";
  Modelica.Blocks.Sources.LogFrequencySweep logFrequencySweep(
    final wMin=fStart,
    final wMax=fStop,
    final startTime=startTime,
    final duration=duration)
  VariableCurrentSource currentSource
  Modelica.ComplexBlocks.Sources.ComplexConstant const(final k=
        Modelica.ComplexMath.fromPolar(len=I, phi=phi))
equation

  connect(logFrequencySweep.y,currentSource. f)
  connect(pin_p,currentSource. pin_p)
  connect(currentSource.pin_n, pin_n)
  connect(const.y, currentSource.I)
end FrequencySweepCurrentSource;


Voltage source with integrated frequency sweep. This source provides a constant RMS phase voltage V and phase angle 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.SinglePhase.Sources;
model FrequencySweepVoltageSource "Voltage source with integrated frequency sweep"
  extends Interfaces.TwoPin;
  import Modelica.Constants.eps;
  SI.Angle gamma(start=0) = pin_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(start=1) "RMS voltage of the source";
  parameter SI.Angle phi=0 "Phase shift of the source";
  SI.Frequency f = voltageSource.f "Actual frequency";
  Modelica.Blocks.Sources.LogFrequencySweep logFrequencySweep(
    final wMin=fStart,
    final wMax=fStop,
    final startTime=startTime,
    final duration=duration)
  VariableVoltageSource voltageSource
  Modelica.ComplexBlocks.Sources.ComplexConstant const(final k=
        Modelica.ComplexMath.fromPolar(len=V, phi=phi))
equation

  connect(logFrequencySweep.y, voltageSource.f)
  connect(const.y, voltageSource.V)
  connect(pin_p, voltageSource.pin_p)
  connect(voltageSource.pin_n, pin_n)
end FrequencySweepVoltageSource;


AC single-phase sources

within Modelica.Electrical.QuasiStatic.SinglePhase;
package Sources "AC single-phase sources"
  extends Modelica.Icons.SourcesPackage;
end Sources;


Variable AC current. This is a current source with a complex signal input, specifying the complex current by the complex RMS current components.
Additionally, the frequency of the voltage source is defined by a real signal input.

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


Variable AC voltage. This is a voltage source with a complex signal input, specifying the complex voltage by the complex RMS voltage components.
Additionally, the frequency of the voltage source is defined by a real signal input.

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


Constant AC voltage. This is a constant voltage source, specifying the complex voltage by the RMS voltage and the phase shift.

within Modelica.Electrical.QuasiStatic.SinglePhase.Sources;
model VoltageSource "Constant AC voltage"
  extends Interfaces.Source;
  parameter SI.Frequency f(start=1) "Frequency of the source";
  parameter SI.Voltage V(start=1) "RMS voltage of the source";
  parameter SI.Angle phi(start=0) "Phase shift of the source";
equation
  omega = 2*Modelica.Constants.pi*f;
  v = Complex(V*cos(phi), V*sin(phi));
end VoltageSource;


Graetz rectifier bridge. This is a so called Graetz-bridge, a single-phase rectifier built from 4 diodes.

within Modelica.Electrical.QuasiStatic.SinglePhase.Utilities;
model GraetzRectifier "Graetz rectifier bridge"
  SI.Voltage vAC=pin_pAC.v - pin_nAC.v "AC voltage";
  SI.Current iAC=pin_pAC.i "AC current";
  SI.ActivePower pAC=vAC*iAC "AC power";
  SI.Voltage vDC=pin_pDC.v - pin_nDC.v "DC voltage";
  SI.Current iDC=pin_pDC.i "DC current";
  SI.Power pDC=vDC*iDC "DC power";
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_pAC
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_nAC
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_pDC
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_nDC
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode1(Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode2(Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode3(Vknee=0)
  Modelica.Electrical.Analog.Ideal.IdealDiode idealDiode4(Vknee=0)
equation
  connect(idealDiode1.p, idealDiode3.n)
  connect(idealDiode2.p, idealDiode4.n)
  connect(idealDiode3.p, idealDiode4.p)
  connect(idealDiode1.n, idealDiode2.n)
  connect(pin_pAC, idealDiode1.p)
  connect(pin_nAC, idealDiode4.n)
  connect(idealDiode2.n, pin_pDC)
  connect(idealDiode4.p, pin_nDC)
end GraetzRectifier;


Ideal AC DC converter. This is an ideal AC DC converter, based on a power balance between QS circuit and DC side.
The parameter conversionFactor defines the ratio between averaged DC voltage and QS rms voltage.
Furthermore, reactive power at the QS side is set to 0.

within Modelica.Electrical.QuasiStatic.SinglePhase.Utilities;
model IdealACDCConverter "Ideal AC DC converter"
  parameter Real conversionFactor "Ratio of DC voltage / QS rms voltage";
  import Modelica.ComplexMath.real;
  import Modelica.ComplexMath.imag;
  import Modelica.ComplexMath.conj;
  import Modelica.ComplexMath.abs;
  import Modelica.ComplexMath.arg;
  SI.ComplexVoltage vQS=pin_pQS.v - pin_nQS.v "AC QS voltage";
  SI.ComplexCurrent iQS=pin_pQS.i "AC QS current";
  output SI.Voltage vQSabs=abs(vQS) "Abs(AC QS voltage)";
  output SI.Current iQSabs=abs(iQS) "Abs(AC QS current)";
  SI.ComplexPower sQS=vQS*conj(iQS) "AC QS apparent power";
  SI.ActivePower pQS=real(sQS) "AC QS active power";
  SI.ReactivePower qQS=imag(sQS) "AC QS reactive power";
  SI.Voltage vDC=pin_pDC.v - pin_nDC.v "DC voltage";
  SI.Current iDC=pin_pDC.i "DC current";
  SI.Power pDC=vDC*iDC "DC power";
  Interfaces.PositivePin pin_pQS
  Interfaces.NegativePin pin_nQS
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_pDC
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_nDC
equation
  //QS balances
  Connections.branch(pin_pQS.reference, pin_nQS.reference);
  pin_pQS.reference.gamma = pin_nQS.reference.gamma;
  pin_pQS.i + pin_nQS.i = Complex(0);
  //DC current balance
  pin_pDC.i + pin_nDC.i = 0;
  //voltage relation
  vDC = abs(vQS)*conversionFactor;
  //power balance
  pQS + pDC = 0;
  //define reactive power
  qQS = 0;
end IdealACDCConverter;


within Modelica.Electrical.QuasiStatic.SinglePhase;
package Utilities "Library with auxiliary models for testing"
  extends Modelica.Icons.UtilitiesPackage;
end Utilities;


within Modelica.Electrical.QuasiStatic;
package Types "Definition of types for quasi-static AC models"
  extends Modelica.Icons.TypesPackage;
end Types;