Model of a resistance with two electrical ports and neutral cable. Resistive model that connects two AC three-phase
unbalanced interfaces with neutral line. This model can be used to represent a
cable in a three-phase unbalanced AC system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
model TwoPortResistance_N
  "Model of a resistance with two electrical ports and neutral cable"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort_N;
  parameter Modelica.Units.SI.Temperature T_ref=298.15 "Reference temperature"
  parameter Modelica.Units.SI.Temperature M=507.65
    "Temperature constant (R_actual = R*(M + T_heatPort)/(M + T_ref))"
  parameter Modelica.Units.SI.Resistance R "Resistance at temperature T_ref";
  parameter Modelica.Units.SI.Resistance Rn
    "Resistance of neutral cable at temperature T_ref";
  OnePhase.Lines.TwoPortResistance  phase1(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final useHeatPort=useHeatPort) "Resistance line 1"
  OnePhase.Lines.TwoPortResistance phase2(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final useHeatPort=useHeatPort) "Resistance line 2"
  OnePhase.Lines.TwoPortResistance phase3(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final useHeatPort=useHeatPort) "Resistance line 3"
  OnePhase.Lines.TwoPortResistance neutral(
    final T_ref=T_ref,
    final M=M,
    final useHeatPort=useHeatPort,
    final R=Rn) "Resistance neutral cable"
equation
  // Joule Losses
  LossPower = phase1.LossPower + phase2.LossPower + phase3.LossPower + neutral.LossPower;
  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])

  connect(phase1.heatPort, heatPort)
  connect(phase3.heatPort, heatPort)
  connect(phase2.heatPort, heatPort)
  connect(neutral.heatPort, heatPort)
  connect(neutral.terminal_p, terminal_p.phase[4])
  connect(neutral.terminal_n, terminal_n.phase[4])
end TwoPortResistance_N;


Model of a resistive-inductive element with two electrical ports. Resistive-inductive model that connects two AC three-phase
unbalanced interfaces. This model can be used to represent a
cable in a three-phase unbalanced AC system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
model TwoPortRL
  "Model of a resistive-inductive element with two electrical ports"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort;
  parameter Modelica.Units.SI.Resistance R "Resistance at temperature T_ref"
  parameter Modelica.Units.SI.Temperature T_ref=298.15 "Reference temperature"
  parameter Modelica.Units.SI.Temperature M=507.65
    "Temperature constant (R_actual = R*(M + T_heatPort)/(M + T_ref))"
  parameter Modelica.Units.SI.Inductance L "Inductance";
  parameter Modelica.Units.SI.Current i1_start[2]={0,0}
    "Initial current phasor of phase 1 (positive if entering from terminal p)"
  parameter Modelica.Units.SI.Current i2_start[2]={0,0}
    "Initial current phasor of phase 2 (positive if entering from terminal p)"
  parameter Modelica.Units.SI.Current i3_start[2]={0,0}
    "Initial current phasor of phase 3 (positive if entering from terminal p)"
  parameter AixLib.Electrical.Types.Load mode(
    min=AixLib.Electrical.Types.Load.FixedZ_steady_state,
    max=AixLib.Electrical.Types.Load.FixedZ_dynamic) = AixLib.Electrical.Types.Load.FixedZ_steady_state
    "Type of model (e.g., steady state, dynamic, prescribed power consumption, etc.)"
  OnePhase.Lines.TwoPortRL phase1(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i1_start) "Impedance line 1"
  OnePhase.Lines.TwoPortRL phase2(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i2_start) "Impedance line 2"
  OnePhase.Lines.TwoPortRL phase3(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i3_start) "Impedance line 3"
equation
  // Joule Losses
  LossPower = phase1.LossPower + phase2.LossPower + phase3.LossPower;

  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])

  connect(phase1.heatPort, heatPort)
  connect(phase3.heatPort, heatPort)
  connect(phase2.heatPort, heatPort)
end TwoPortRL;


Model of an RLC element with two electrical ports. RLC line model (T-model) that connects two AC three-phase
unbalanced interfaces. This model can be used to represent a
cable in a three-phase unbalanced AC system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
model TwoPortRLC "Model of an RLC element with two electrical ports"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort(
    terminal_p(phase(v(each nominal = V_nominal))),
    terminal_n(phase(v(each nominal = V_nominal))));

  parameter Modelica.Units.SI.Resistance R "Resistance at temperature T_ref";
  parameter Modelica.Units.SI.Capacitance C "Capacity";
  parameter Modelica.Units.SI.Inductance L "Inductance";
  parameter Modelica.Units.SI.Temperature T_ref=298.15 "Reference temperature"
  parameter Modelica.Units.SI.Temperature M=507.65
    "Temperature constant (R_actual = R*(M + T_heatPort)/(M + T_ref))"
  parameter Modelica.Units.SI.Voltage Vc1_start[2]=V_nominal/sqrt(3)*{1,0}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter Modelica.Units.SI.Voltage Vc2_start[2]=V_nominal/sqrt(3)*{-1/2,-
      sqrt(3)/2}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter Modelica.Units.SI.Voltage Vc3_start[2]=V_nominal/sqrt(3)*{-1/2,+
      sqrt(3)/2}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter AixLib.Electrical.Types.Load mode(
    min=AixLib.Electrical.Types.Load.FixedZ_steady_state,
    max=AixLib.Electrical.Types.Load.FixedZ_dynamic)=
    AixLib.Electrical.Types.Load.FixedZ_steady_state
    "Type of model (e.g., steady state, dynamic, prescribed power consumption, etc.)"
  parameter Modelica.Units.SI.Voltage V_nominal(min=0, start=480)
    "Nominal voltage (V_nominal >= 0)"
  OnePhase.Lines.TwoPortRLC phase1(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc1_start) "Impedance line 1"
  OnePhase.Lines.TwoPortRLC phase2(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc2_start) "Impedance line 2"
  OnePhase.Lines.TwoPortRLC phase3(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc3_start) "Impedance line 3"
equation
  // Joule Losses
  LossPower = phase1.LossPower + phase2.LossPower + phase3.LossPower;

  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])

  connect(phase1.heatPort, heatPort)
  connect(phase3.heatPort, heatPort)
  connect(phase2.heatPort, heatPort)
end TwoPortRLC;


Model of an RLC element with two electrical ports and neutral line cable. RLC line model (T-model) that connects two AC three-phase
unbalanced interfaces with neutral line. This model can be used to represent a
cable in a three-phase unbalanced AC system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
model TwoPortRLC_N
  "Model of an RLC element with two electrical ports and neutral line cable"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort_N(
    terminal_p(phase(v(each nominal = V_nominal))),
    terminal_n(phase(v(each nominal = V_nominal))));

  parameter Modelica.Units.SI.Resistance R "Resistance at temperature T_ref";
  parameter Modelica.Units.SI.Resistance Rn
    "Resistance of neutral cable at temperature T_ref";
  parameter Modelica.Units.SI.Capacitance C "Capacity";
  parameter Modelica.Units.SI.Capacitance Cn "Capacityof neutral cable";
  parameter Modelica.Units.SI.Inductance L "Inductance";
  parameter Modelica.Units.SI.Inductance Ln "Inductance of neutral cable";
  parameter Modelica.Units.SI.Temperature T_ref=298.15 "Reference temperature"
  parameter Modelica.Units.SI.Temperature M=507.65
    "Temperature constant (R_actual = R*(M + T_heatPort)/(M + T_ref))"
  parameter Modelica.Units.SI.Voltage Vc1_start[2]=V_nominal/sqrt(3)*{1,0}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter Modelica.Units.SI.Voltage Vc2_start[2]=V_nominal/sqrt(3)*{-1/2,-
      sqrt(3)/2}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter Modelica.Units.SI.Voltage Vc3_start[2]=V_nominal/sqrt(3)*{-1/2,+
      sqrt(3)/2}
    "Initial voltage phasor of the capacitance located in the middle of phase 1"
  parameter AixLib.Electrical.Types.Load mode(
    min=AixLib.Electrical.Types.Load.FixedZ_steady_state,
    max=AixLib.Electrical.Types.Load.FixedZ_dynamic)=
    AixLib.Electrical.Types.Load.FixedZ_steady_state
    "Type of model (e.g., steady state, dynamic, prescribed power consumption, etc.)"
  parameter Modelica.Units.SI.Voltage V_nominal(min=0, start=480)
    "Nominal voltage (V_nominal >= 0)"
  OnePhase.Lines.TwoPortRLC phase1(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc1_start) "Impedance line 1"
  OnePhase.Lines.TwoPortRLC phase2(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc2_start) "Impedance line 2"
  OnePhase.Lines.TwoPortRLC phase3(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final C=C/3,
    final mode=mode,
    final V_nominal = V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    Vc_start=Vc3_start) "Impedance line 3"
  OnePhase.Lines.TwoPortRLC neutral(
    final T_ref=T_ref,
    final M=M,
    final mode=mode,
    final V_nominal=V_nominal/sqrt(3),
    final useHeatPort=useHeatPort,
    final R=Rn,
    final C=Cn,
    final L=Ln,
    Vc_start=-Vc1_start - Vc2_start - Vc3_start) "Neutral line RLC model"
equation
  // Joule Losses
  LossPower = phase1.LossPower + phase2.LossPower + phase3.LossPower + neutral.LossPower;

  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])

  connect(phase1.heatPort, heatPort)
  connect(phase3.heatPort, heatPort)
  connect(phase2.heatPort, heatPort)
  connect(neutral.terminal_p, terminal_p.phase[4])
  connect(neutral.terminal_n, terminal_n.phase[4])
  connect(neutral.heatPort, heatPort)
end TwoPortRLC_N;


Model of a resistive-inductive element with two electrical ports and neutral line cable. Resistive-inductive model that connects two AC three-phase
unbalanced interfaces with neutral line. This model can be used to represent a
cable in a three-phase unbalanced AC system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
model TwoPortRL_N
  "Model of a resistive-inductive element with two electrical ports and neutral line cable"
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort;
  extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort_N;
  parameter Modelica.Units.SI.Resistance R "Resistance at temperature T_ref";
  parameter Modelica.Units.SI.Resistance Rn
    "Resistance of neutral cable at temperature T_ref";
  parameter Modelica.Units.SI.Temperature T_ref=298.15 "Reference temperature"
  parameter Modelica.Units.SI.Temperature M=507.65
    "Temperature constant (R_actual = R*(M + T_heatPort)/(M + T_ref))"
  parameter Modelica.Units.SI.Inductance L "Inductance";
  parameter Modelica.Units.SI.Inductance Ln "Inductance of neutral cable";
  parameter Modelica.Units.SI.Current i1_start[2]={0,0}
    "Initial current phasor of phase 1 (positive if entering from terminal p)"
  parameter Modelica.Units.SI.Current i2_start[2]={0,0}
    "Initial current phasor of phase 2 (positive if entering from terminal p)"
  parameter Modelica.Units.SI.Current i3_start[2]={0,0}
    "Initial current phasor of phase 3 (positive if entering from terminal p)"
  parameter AixLib.Electrical.Types.Load mode(
    min=AixLib.Electrical.Types.Load.FixedZ_steady_state,
    max=AixLib.Electrical.Types.Load.FixedZ_dynamic) = AixLib.Electrical.Types.Load.FixedZ_steady_state
    "Type of model (e.g., steady state, dynamic, prescribed power consumption, etc.)"
  OnePhase.Lines.TwoPortRL  phase1(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i1_start) "Impedance line 1"
  OnePhase.Lines.TwoPortRL phase2(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i2_start) "Impedance line 2"
  OnePhase.Lines.TwoPortRL phase3(
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=mode,
    final useHeatPort=useHeatPort,
    i_start=i3_start) "Impedance line 3"
  OnePhase.Lines.TwoPortRL neutral(
    final T_ref=T_ref,
    final M=M,
    final mode=mode,
    final useHeatPort=useHeatPort,
    final R=Rn,
    final L=Ln,
    i_start=-i1_start - i2_start - i3_start) "neutral cable RL model"
equation
  // Joule Losses
  LossPower = phase1.LossPower + phase2.LossPower + phase3.LossPower + neutral.LossPower;

  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])

  connect(phase1.heatPort, heatPort)
  connect(phase3.heatPort, heatPort)
  connect(phase2.heatPort, heatPort)
  connect(neutral.heatPort, heatPort)
  connect(neutral.terminal_p, terminal_p.phase[4])
  connect(neutral.terminal_n, terminal_n.phase[4])
end TwoPortRL_N;


Test model for a three-phase unbalanced commercial cable without neutral. This example demonstrates how to use a cable model without neutral line
to connect a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine
  "Test model for a three-phase unbalanced commercial cable without neutral"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance R1(R=10) "Resistive load 1"
  Loads.Impedance R2(R=10) "Resistive load 2"
  Loads.Impedance R3(R=10) "Resistive load 3"
  Line line_1(
    l=1000,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 1"
  Line line_2a(
    l=500,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 2"
  Line line_2b(
    l=500,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 2"
  Line line_3a(
    l=2000,
    P_nominal=1000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 3"
  Line line_3b(
    l=2000,
    P_nominal=1000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 3"
equation
  connect(E.terminal, line_1.terminal_n)
  connect(line_1.terminal_p, R1.terminal)
  connect(E.terminal, line_2a.terminal_n)
  connect(line_2a.terminal_p, line_2b.terminal_n)
  connect(line_2b.terminal_p, R2.terminal)
  connect(E.terminal, line_3a.terminal_n)
  connect(E.terminal, line_3b.terminal_n)
  connect(line_3a.terminal_p, R3.terminal)
  connect(line_3b.terminal_p, R3.terminal)
end ACLine;


Test model for a three-phase unbalanced inductive-resistive line specified by a Z matrix. This example demonstrates how to use an inductive resistive line model to connect
a source to a load. The model is parameterized using the impedance matrix <i>Z</i>.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLineMatrix_RL
  "Test model for a three-phase unbalanced inductive-resistive line specified by a Z matrix"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance sc_load1(R=0, L=0) "Short circuit load"
  Loads.Impedance sc_load2(R=0, L=0) "Short circuit load"
  Loads.Impedance sc_load3(R=0, L=0) "Short circuit load"
  Lines.TwoPortMatrixRL Rline_1(
    Z11={10,10},
    Z12={0,0},
    Z13={0,0},
    Z22={10,10},
    Z23={0,0},
    Z33={10,10},
    V_nominal=100*sqrt(3)) "RL line that connects to load 1"
  Lines.TwoPortMatrixRL Rline_2a(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=0.5*{10,10},
    Z22=0.5*{10,10},
    Z33=0.5*{10,10},
    V_nominal=100*sqrt(3)) "RL line that connects to load 2"
  Lines.TwoPortMatrixRL Rline_2b(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=0.5*{10,10},
    Z22=0.5*{10,10},
    Z33=0.5*{10,10},
    V_nominal=100*sqrt(3)) "RL line that connects to load 2"
  Lines.TwoPortMatrixRL Rline_3a(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=2*{10,10},
    Z22=2*{10,10},
    Z33=2*{10,10},
    V_nominal=100*sqrt(3)) "RL line that connects to load 3"
  Lines.TwoPortMatrixRL Rline_3b(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=2*{10,10},
    Z22=2*{10,10},
    Z33=2*{10,10},
    V_nominal=100*sqrt(3)) "RL line that connects to load 3"
equation
  connect(E.terminal, Rline_1.terminal_n)
  connect(Rline_1.terminal_p, sc_load1.terminal)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
  connect(Rline_2b.terminal_p, sc_load2.terminal)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
  connect(Rline_3a.terminal_p, sc_load3.terminal)
  connect(Rline_3b.terminal_p, sc_load3.terminal)
end ACLineMatrix_RL;


Test model for a three-phase unbalanced RLC line specified by Z and B matrices. This example demonstrates how to use a RLC line model to connect
a source to a load. The model is parameterized using the impedance matrix Z
and the admittance matrix B.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLineMatrix_RLC
  "Test model for a three-phase unbalanced RLC line specified by Z and B matrices"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance sc_load1(R=0, L=0) "Short circuit load"
  Lines.TwoPortMatrixRLC Rline_1(
    Z11={10,10},
    Z12={0,0},
    Z13={0,0},
    Z22={10,10},
    Z23={0,0},
    Z33={10,10},
    V_nominal=100*sqrt(3),
    B12=0,
    B13=0,
    B23=0,
    B11=10,
    B22=10,
    B33=10) "RL line that connects to load 1"
  Lines.TwoPortMatrixRLC Rline_2(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    V_nominal=100*sqrt(3),
    B12=0,
    B13=0,
    B23=0,
    Z11={0,0},
    Z22={0,0},
    Z33={0,0},
    B11=0.1,
    B22=0.1,
    B33=0.1) "RL line that connects to load 2"
equation
  connect(E.terminal, Rline_1.terminal_n)
  connect(Rline_1.terminal_p, sc_load1.terminal)
  connect(E.terminal, Rline_2.terminal_n)
end ACLineMatrix_RLC;


Test model for a three-phase unbalanced RLC line with neutral cable specified by Z and B matrices. This example demonstrates how to use a RLC line model with neutral line to connect
a source to a load. The model is parameterized using the impedance matrix Z
and the admittance matrix B.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLineMatrix_RLC_N
  "Test model for a three-phase unbalanced RLC line with neutral cable specified by Z and B matrices"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance_N sc_load1(R=0, L=0) "Short circuit load"
  Lines.TwoPortMatrixRLC_N Rline_1(
    Z11={10,10},
    Z12={0,0},
    Z13={0,0},
    Z22={10,10},
    Z23={0,0},
    Z33={10,10},
    V_nominal=100*sqrt(3),
    B12=0,
    B13=0,
    B23=0,
    B11=10,
    B22=10,
    B33=10,
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44={10,10},
    B14=0,
    B24=0,
    B34=0,
    B44=10) "RL line that connects to load 1"
  Lines.TwoPortMatrixRLC_N Rline_2(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    V_nominal=100*sqrt(3),
    B12=0,
    B13=0,
    B23=0,
    Z11={0,0},
    Z22={0,0},
    Z33={0,0},
    B11=0.1,
    B22=0.1,
    B33=0.1,
    Z14={0,0},
    Z24={0,0},
    B14=0,
    B24=0,
    B34=0,
    B44=0.1,
    Z34={0,0},
    Z44={0,0}) "RL line that connects to load 2"
equation
  connect(E.terminal, Rline_1.terminal_n)
  connect(E.terminal, Rline_2.terminal_n)
  connect(Rline_1.terminal_p, sc_load1.terminal)
end ACLineMatrix_RLC_N;


Test model for a three-phase unbalanced inductive-resistive line with neutral cable specified by a Z matrix. This example demonstrates how to use an inductive resistive line model with neutral line to connect
a source to a load. The model is parameterized using the impedance matrix <i>Z</i>.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLineMatrix_RL_N
  "Test model for a three-phase unbalanced inductive-resistive line with neutral cable specified by a Z matrix"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance_N sc_load1(R=0, L=0) "Short circuit load"
  Loads.Impedance_N sc_load2(R=0, L=0) "Short circuit load"
  Loads.Impedance_N sc_load3(R=0, L=0) "Short circuit load"
  Lines.TwoPortMatrixRL_N Rline_1(
    Z11={10,10},
    Z12={0,0},
    Z13={0,0},
    Z22={10,10},
    Z23={0,0},
    Z33={10,10},
    V_nominal=100*sqrt(3),
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44={10,10}) "RL line that connects to load 1"
  Lines.TwoPortMatrixRL_N Rline_2a(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=0.5*{10,10},
    Z22=0.5*{10,10},
    Z33=0.5*{10,10},
    V_nominal=100*sqrt(3),
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44=0.5*{10,10}) "RL line that connects to load 2"
  Lines.TwoPortMatrixRL_N Rline_2b(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=0.5*{10,10},
    Z22=0.5*{10,10},
    Z33=0.5*{10,10},
    V_nominal=100*sqrt(3),
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44=0.5*{10,10}) "RL line that connects to load 2"
  Lines.TwoPortMatrixRL_N Rline_3a(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=2*{10,10},
    Z22=2*{10,10},
    Z33=2*{10,10},
    V_nominal=100*sqrt(3),
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44=2*{10,10}) "RL line that connects to load 3"
  Lines.TwoPortMatrixRL_N Rline_3b(
    Z12={0,0},
    Z13={0,0},
    Z23={0,0},
    Z11=2*{10,10},
    Z22=2*{10,10},
    Z33=2*{10,10},
    V_nominal=100*sqrt(3),
    Z14={0,0},
    Z24={0,0},
    Z34={0,0},
    Z44=2*{10,10}) "RL line that connects to load 3"
equation
  connect(E.terminal, Rline_1.terminal_n)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
  connect(Rline_3b.terminal_p, sc_load3.terminal)
  connect(Rline_3a.terminal_p, sc_load3.terminal)
  connect(Rline_2b.terminal_p, sc_load2.terminal)
  connect(Rline_1.terminal_p, sc_load1.terminal)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
end ACLineMatrix_RL_N;


Test model for a three-phase unbalanced inductive line. This example demonstrates how to use a purely inductive line model to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_L "Test model for a three-phase unbalanced inductive line"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Inductance Lbase=10/2/Modelica.Constants.pi/60
    "Base value for the line inductances";
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance L1(R=0, L=Lbase) "Inductive load 1"
  Loads.Impedance L2(R=0, L=Lbase) "Inductive load 2"
  Loads.Impedance L3(R=0, L=Lbase) "Inductive load 3"
  Loads.Impedance sc_load(R=0) "Short circuit load"
  Lines.TwoPortInductance Lline_sc(L=6*Lbase)
    "Inductive line that connects to the short circuit"
  Lines.TwoPortInductance Rline_1(L=3*Lbase)
    "Inductive line that connects to load 1"
  Lines.TwoPortInductance Rline_2a(L=3*Lbase/2)
    "Inductive line that connects to load 2"
  Lines.TwoPortInductance Rline_2b(L=3*Lbase/2)
    "Inductive line that connects to load 2"
  Lines.TwoPortInductance Rline_3a(L=6*Lbase)
    "Inductive line that connects to load 3"
  Lines.TwoPortInductance Rline_3b(L=6*Lbase)
    "Inductive line that connects to load 3"
equation
  connect(E.terminal,Lline_sc. terminal_n)
  connect(Lline_sc.terminal_p, sc_load.terminal)
  connect(E.terminal, Rline_1.terminal_n)
  connect(Rline_1.terminal_p,L1. terminal)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
  connect(Rline_2b.terminal_p,L2. terminal)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
  connect(Rline_3a.terminal_p,L3. terminal)
  connect(Rline_3b.terminal_p,L3. terminal)
end ACLine_L;


Test model for a three-phase unbalanced inductive line with neutral cable. This example demonstrates how to use a purely inductive line model with neutral cable to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_L_N
  "Test model for a three-phase unbalanced inductive line with neutral cable"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Inductance Lbase=10/2/Modelica.Constants.pi/60
    "Base value for the line inductances";
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance_N L1(R=0, L=Lbase) "Inductive load 1"
  Loads.Impedance_N L2(R=0, L=Lbase) "Inductive load 2"
  Loads.Impedance_N L3(R=0, L=Lbase) "Inductive load 3"
  Loads.Impedance_N sc_load(R=0) "Short circuit load"
  Lines.TwoPortInductance_N Lline_sc(L=6*Lbase, Ln=Lbase)
    "Inductive line that connects to the short circuit"
  Lines.TwoPortInductance_N Rline_1(L=3*Lbase, Ln=0.5*Lbase)
    "Inductive line that connects to load 1"
  Lines.TwoPortInductance_N Rline_2a(L=3*Lbase/2, Ln=0.5*Lbase/2)
    "Inductive line that connects to load 2"
  Lines.TwoPortInductance_N Rline_2b(L=3*Lbase/2, Ln=0.5*Lbase/2)
    "Inductive line that connects to load 2"
  Lines.TwoPortInductance_N Rline_3a(L=6*Lbase, Ln=Lbase)
    "Inductive line that connects to load 3"
  Lines.TwoPortInductance_N Rline_3b(L=6*Lbase, Ln=Lbase)
    "Inductive line that connects to load 3"
equation
  connect(E.terminal, Lline_sc.terminal_n)
  connect(E.terminal, Rline_1.terminal_n)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
  connect(Rline_3b.terminal_p, L3.terminal)
  connect(Rline_3a.terminal_p, L3.terminal)
  connect(Rline_2b.terminal_p, L2.terminal)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
  connect(Rline_1.terminal_p, L1.terminal)
  connect(Lline_sc.terminal_p, sc_load.terminal)
end ACLine_L_N;


Test model for a three-phase unbalanced commercial cable with neutral. This example demonstrates how to use a cable line model with
neutral to connect a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_N
  "Test model for a three-phase unbalanced commercial cable with neutral"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance_N R1(R=10) "Resistive load 1"
  Loads.Impedance_N R2(R=10) "Resistive load 2"
  Loads.Impedance_N R3(R=10) "Resistive load 3"
  Line_N line_1(
    l=1000,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 1"
  Line_N line_2a(
    l=500,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 2"
  Line_N line_2b(
    l=500,
    P_nominal=2000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 2"
  Line_N line_3a(
    l=2000,
    P_nominal=1000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 3"
  Line_N line_3b(
    l=2000,
    P_nominal=1000,
    V_nominal=480,
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu35
      commercialCable) "Cable that connects to load 3"
equation
  connect(E.terminal, line_2a.terminal_n)
  connect(E.terminal, line_1.terminal_n)
  connect(line_1.terminal_p, R1.terminal)
  connect(E.terminal, line_3a.terminal_n)
  connect(E.terminal, line_3b.terminal_n)
  connect(line_2a.terminal_p, line_2b.terminal_n)
  connect(line_3a.terminal_p, R3.terminal)
  connect(line_3b.terminal_p, R3.terminal)
  connect(line_2b.terminal_p, R2.terminal)
end ACLine_N;


Test model for a three-phase unbalanced resistive line. This example demonstrates how to use a resistive line model to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_R "Test model for a three-phase unbalanced resistive line"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance R1(R=10) "Resistive load 1"
  Loads.Impedance R2(R=10) "Resistive load 2"
  Loads.Impedance R3(R=10) "Resistive load 3"
  Loads.Impedance sc_load(R=0) "Short circuit load"
  Lines.TwoPortResistance Rline_sc(      useHeatPort=false, R=60)
    "Resistive line that connects to the short circuit"
  Lines.TwoPortResistance Rline_1(R=30)
    "Resistive line that connects to load 1"
  Lines.TwoPortResistance Rline_2a(R=15)
    "Resistive line that connects to load 2"
  Lines.TwoPortResistance Rline_2b(R=15)
    "Resistive line that connects to load 2"
  Lines.TwoPortResistance Rline_3a(R=60)
    "Resistive line that connects to load 3"
  Lines.TwoPortResistance Rline_3b(R=60)
    "Resistive line that connects to load 3"
equation
  connect(E.terminal, Rline_sc.terminal_n)
  connect(Rline_sc.terminal_p, sc_load.terminal)
  connect(E.terminal, Rline_1.terminal_n)
  connect(Rline_1.terminal_p, R1.terminal)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
  connect(Rline_2b.terminal_p, R2.terminal)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
  connect(Rline_3a.terminal_p, R3.terminal)
  connect(Rline_3b.terminal_p, R3.terminal)
end ACLine_R;


Test model for a three-phase unbalanced inductive-resistive line. This example demonstrates how to use a resistive-inductive line model to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_RL
  "Test model for a three-phase unbalanced inductive-resistive line"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Resistance Rbase=3*10
    "Base value for the line resistance";
  parameter Modelica.Units.SI.Inductance Lbase=Rbase/2/Modelica.Constants.pi/60
    "Base value for the line inductance";
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance load_sc_1(R=0) "Short circuit 1"
  Loads.Impedance load_sc_2(R=0) "Short circuit 2"
  Lines.TwoPortRL RL_2(
    R=Rbase,
    L=Lbase) "Resistive-Inductive line connected to short circuit 2"
  Lines.TwoPortResistance R_1(R=Rbase)
    "Resistance line connected to short circuit 1"
  Lines.TwoPortInductance L_1(L=Lbase)
    "Inductance line connected to short circuit 1"
  Lines.TwoPortRL RL_3(
    R=Rbase,
    L=Lbase,
    mode=AixLib.Electrical.Types.Load.FixedZ_dynamic)
    "Dynamic resistive-inductive line connected to short circuit 3"
  Loads.Impedance load_sc_3(R=0) "Short circuit 3"
equation
  connect(E.terminal, R_1.terminal_n)
  connect(R_1.terminal_p, L_1.terminal_n)
  connect(L_1.terminal_p, load_sc_1.terminal)
  connect(E.terminal, RL_2.terminal_n)
  connect(RL_2.terminal_p, load_sc_2.terminal)
  connect(E.terminal, RL_3.terminal_n)
  connect(RL_3.terminal_p, load_sc_3.terminal)
end ACLine_RL;


Test model for a three-phase unbalanced RLC line. This example demonstrates how to use an RLC line model to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_RLC "Test model for a three-phase unbalanced RLC line"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Resistance RBase=3*10
    "Base value for the line resistance";
  parameter Modelica.Units.SI.Inductance LBase=RBase/(2*Modelica.Constants.pi*
      60) "Base value for the line inductances";
  parameter Modelica.Units.SI.Capacitance CBase=3*0.1/(2*Modelica.Constants.pi*
      60) "Base value for the line inductances";
  Sources.FixedVoltage E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance sc_load1(R=0, L=0) "Short circuit load"
  Loads.Impedance sc_load2(R=0, L=0) "Short circuit load"
  Loads.Impedance sc_load3(R=0, L=0) "Short circuit load"
  Loads.Impedance sc_load(R=0, L=0) "Short circuit load"
  Lines.TwoPortRLC RLCLine_sc(
    R=RBase,
    C=CBase,
    L=LBase,
    mode=AixLib.Electrical.Types.Load.FixedZ_dynamic,
    V_nominal=480) "RLC line that connects to the short circuit"
  Lines.TwoPortRLC RLCLine_1(
    R=RBase,
    C=CBase,
    L=LBase,
    V_nominal=480) "RLC line that connects to load 1"
  Lines.TwoPortRLC RLCLine_2a(
    V_nominal=480,
    R=RBase/2,
    L=LBase/2,
    C=CBase/2) "RLC line that connects to load 2"
  Lines.TwoPortRLC RLCLine_2b(
    V_nominal=480,
    R=RBase/2,
    L=LBase/2,
    C=CBase/2) "RLC line that connects to load 2"
  Lines.TwoPortRLC RLCLine_3a(
    R=2*RBase,
    L=2*LBase,
    V_nominal=480,
    C=CBase/2) "RLC line that connects to load 3"
  Lines.TwoPortRLC RLCLine_3b(
    R=2*RBase,
    L=2*LBase,
    V_nominal=480,
    C=CBase/2) "RLC line that connects to load 3"
equation
  connect(E.terminal, RLCLine_sc.terminal_n)
  connect(RLCLine_sc.terminal_p, sc_load.terminal)
  connect(E.terminal, RLCLine_1.terminal_n)
  connect(RLCLine_1.terminal_p, sc_load1.terminal)
  connect(E.terminal, RLCLine_2a.terminal_n)
  connect(RLCLine_2a.terminal_p, RLCLine_2b.terminal_n)
  connect(RLCLine_2b.terminal_p, sc_load2.terminal)
  connect(E.terminal, RLCLine_3a.terminal_n)
  connect(E.terminal, RLCLine_3b.terminal_n)
  connect(RLCLine_3a.terminal_p, sc_load3.terminal)
  connect(RLCLine_3b.terminal_p, sc_load3.terminal)
end ACLine_RLC;


Test model for a three-phase unbalanced RLC line with neutral cable. This example demonstrates how to use an RLC line model with neutral cable to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_RLC_N
  "Test model for a three-phase unbalanced RLC line with neutral cable"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Resistance RBase=3*10
    "Base value for the line resistance";
  parameter Modelica.Units.SI.Inductance LBase=RBase/(2*Modelica.Constants.pi*
      60) "Base value for the line inductances";
  parameter Modelica.Units.SI.Capacitance CBase=3*0.1/(2*Modelica.Constants.pi*
      60) "Base value for the line inductances";
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance_N sc_load1(R=0, L=0) "Short circuit load"
  Loads.Impedance_N sc_load2(R=0, L=0) "Short circuit load"
  Loads.Impedance_N sc_load3(R=0, L=0) "Short circuit load"
  Loads.Impedance_N sc_load(R=0, L=0) "Short circuit load"
  Lines.TwoPortRLC_N RLCLine_sc(
    R=RBase,
    C=CBase,
    L=LBase,
    mode=AixLib.Electrical.Types.Load.FixedZ_dynamic,
    V_nominal=480,
    Rn=RBase,
    Cn=CBase,
    Ln=LBase) "RLC line that connects to the short circuit"
  Lines.TwoPortRLC_N RLCLine_1(
    R=RBase,
    C=CBase,
    L=LBase,
    V_nominal=480,
    Rn=RBase,
    Cn=CBase,
    Ln=LBase) "RLC line that connects to load 1"
  Lines.TwoPortRLC_N RLCLine_2a(
    V_nominal=480,
    R=RBase/2,
    L=LBase/2,
    C=CBase/2,
    Rn=RBase/2,
    Cn=CBase/2,
    Ln=LBase/2) "RLC line that connects to load 2"
  Lines.TwoPortRLC_N RLCLine_2b(
    V_nominal=480,
    R=RBase/2,
    L=LBase/2,
    C=CBase/2,
    Rn=RBase/2,
    Cn=CBase/2,
    Ln=LBase/2) "RLC line that connects to load 2"
  Lines.TwoPortRLC_N RLCLine_3a(
    R=2*RBase,
    L=2*LBase,
    V_nominal=480,
    C=CBase/2,
    Rn=2*RBase,
    Cn=CBase/2,
    Ln=2*LBase) "RLC line that connects to load 3"
  Lines.TwoPortRLC_N RLCLine_3b(
    R=2*RBase,
    L=2*LBase,
    V_nominal=480,
    C=CBase/2,
    Rn=2*RBase,
    Cn=CBase/2,
    Ln=2*LBase) "RLC line that connects to load 3"
equation
  connect(RLCLine_2a.terminal_p, RLCLine_2b.terminal_n)
  connect(RLCLine_2b.terminal_p, sc_load2.terminal)
  connect(RLCLine_3a.terminal_p, sc_load3.terminal)
  connect(RLCLine_3b.terminal_p, sc_load3.terminal)
  connect(RLCLine_1.terminal_p, sc_load1.terminal)
  connect(RLCLine_sc.terminal_p, sc_load.terminal)
  connect(E.terminal, RLCLine_sc.terminal_n)
  connect(E.terminal, RLCLine_1.terminal_n)
  connect(E.terminal, RLCLine_2a.terminal_n)
  connect(E.terminal, RLCLine_3a.terminal_n)
  connect(E.terminal, RLCLine_3b.terminal_n)
end ACLine_RLC_N;


Test model for a three-phase unbalanced inductive-resistive line with neutral cable. This example demonstrates how to use a resistive-inductive line model with neutral cable to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_RL_N
  "Test model for a three-phase unbalanced inductive-resistive line with neutral cable"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Resistance Rbase=3*10
    "Base value for the line resistance";
  parameter Modelica.Units.SI.Inductance Lbase=Rbase/2/Modelica.Constants.pi/60
    "Base value for the line inductance";
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=100*sqrt(3)) "Voltage source"
  Loads.Impedance_N load_sc_1(R=0) "Short circuit 1"
  Loads.Impedance_N load_sc_2(R=0) "Short circuit 2"
  Lines.TwoPortRL_N RL_2(
    R=Rbase,
    L=Lbase,
    Rn=0.5*Rbase,
    Ln=0.5*Lbase) "Resistive-Inductive line connected to short circuit 2"
  Lines.TwoPortResistance_N R_1(R=Rbase, Rn=0.5*Rbase)
    "Resistance line connected to short circuit 1"
  Lines.TwoPortInductance_N L_1(L=Lbase, Ln=0.5*Lbase)
    "Inductance line connected to short circuit 1"
equation
  connect(RL_2.terminal_p, load_sc_2.terminal)
  connect(L_1.terminal_p, load_sc_1.terminal)
  connect(L_1.terminal_n, R_1.terminal_p)
  connect(R_1.terminal_n, E.terminal)
  connect(E.terminal, RL_2.terminal_n)
end ACLine_RL_N;


Test model for a three-phase unbalanced resistive line with neutral cable. This example demonstrates how to use a resistive line model with neutral cable to connect
a source to a load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACLine_R_N
  "Test model for a three-phase unbalanced resistive line with neutral cable"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N E(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Loads.Impedance_N R1(R=10) "Resistive load 1"
  Loads.Impedance_N R2(R=10) "Resistive load 2"
  Loads.Impedance_N R3(R=10) "Resistive load 3"
  Loads.Impedance_N sc_load(R=0) "Short circuit load"
  Lines.TwoPortResistance_N Rline_sc(      useHeatPort=false, R=60,
    Rn=20) "Resistive line that connects to the short circuit"
  Lines.TwoPortResistance_N Rline_1(R=30, Rn=10)
    "Resistive line that connects to load 1"
  Lines.TwoPortResistance_N Rline_2a(R=15, Rn=5)
    "Resistive line that connects to load 2"
  Lines.TwoPortResistance_N Rline_2b(R=15, Rn=5)
    "Resistive line that connects to load 2"
  Lines.TwoPortResistance_N Rline_3a(R=60, Rn=20)
    "Resistive line that connects to load 3"
  Lines.TwoPortResistance_N Rline_3b(R=60, Rn=20)
    "Resistive line that connects to load 3"
equation
  connect(Rline_sc.terminal_p, sc_load.terminal)
  connect(Rline_1.terminal_p, R1.terminal)
  connect(Rline_2b.terminal_p, R2.terminal)
  connect(Rline_2a.terminal_p, Rline_2b.terminal_n)
  connect(Rline_3b.terminal_p, R3.terminal)
  connect(Rline_3a.terminal_p, R3.terminal)
  connect(E.terminal, Rline_sc.terminal_n)
  connect(E.terminal, Rline_1.terminal_n)
  connect(E.terminal, Rline_2a.terminal_n)
  connect(E.terminal, Rline_3a.terminal_n)
  connect(E.terminal, Rline_3b.terminal_n)
end ACLine_R_N;


Test model for a network model for three-phase unbalanced systems without neutral cable. This example demonstrates how to use a network model to connect
a source to a load. In this simple case the network has two nodes
that are connected by a commercial cable without a neutral line.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACSimpleGrid
  "Test model for a network model for three-phase unbalanced systems without neutral cable"
  extends Modelica.Icons.Example;
  Network network(
    redeclare AixLib.Electrical.Transmission.Grids.TestGrid2Nodes grid,
    V_nominal=480)
    "Network model that represents the connection between the source and the load"
  Loads.Inductive load(
    V_nominal=480,
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase3=false) "Load connected to the network"
  Sources.FixedVoltage E(f=60, V=480,
    definiteReference=true) "Voltage source"
  Modelica.Blocks.Sources.Ramp load_inputs(
    height=5000,
    offset=-2000,
    duration=0.5,
    startTime=0.25) "Input signal for the power consumption of the loads"
equation
  connect(E.terminal, network.terminal[1])
  connect(load.terminal, network.terminal[2])
  connect(load_inputs.y, load.Pow1)
  connect(load_inputs.y, load.Pow2)
end ACSimpleGrid;


Test model for a network model for three-phase unbalanced systems with neutral cable. This example demonstrates how to use a network model to connect
a source to a load. In this simple case the network has two nodes
that are connected by a commercial cable with neutral line.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines.Examples;
model ACSimpleGrid_N
  "Test model for a network model for three-phase unbalanced systems with neutral cable"
  extends Modelica.Icons.Example;
  Network_N network(
    redeclare AixLib.Electrical.Transmission.Grids.TestGrid2Nodes grid,
    V_nominal=480)
    "Network model that represents the connection between the source and the load"
  Loads.Inductive_N load(
    V_nominal=480,
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase3=false) "Load connected to the network"
  Sources.FixedVoltage_N E(
    f=60,
    V=480,
    definiteReference=true) "Voltage source"
  Modelica.Blocks.Sources.Ramp load_inputs(
    height=5000,
    offset=-2000,
    duration=0.5,
    startTime=0.25) "Input signal for the power consumption of the loads"
equation
  connect(E.terminal, network.terminal[1])
  connect(load.terminal, network.terminal[2])
  connect(load_inputs.y, load.Pow1)
  connect(load_inputs.y, load.Pow2)
end ACSimpleGrid_N;


Package with example models

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Lines;
package Examples "Package with example models"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Model of a three-phase unbalanced capacitive load without neutral cable. This model represents a three-phase unbalanced capacitive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Capacitive
  "Model of a three-phase unbalanced capacitive load without neutral cable"
  extends BaseClasses.LoadCtrl(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load1(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load2(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load3(pf=pf,
        use_pf_in=use_pf_in));
  parameter Boolean use_pf_in = false
    "If true, the power factor is defined by an input"
  parameter Real pf(min=0, max=1) = 0.8 "Power factor"
  Modelica.Blocks.Interfaces.RealInput pf_in_1(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase1) "Power factor of load on phase 1"
  Modelica.Blocks.Interfaces.RealInput pf_in_2(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase2) "Power factor of load on phase 2"
  Modelica.Blocks.Interfaces.RealInput pf_in_3(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase3) "Power factor of load on phase 3"
equation
  connect(pf_in_1, load1.pf_in)
  connect(pf_in_2, load2.pf_in)
  connect(pf_in_3, load3.pf_in)
end Capacitive;


Model of a three-phase unbalanced capacitive load with neutral cable. This model represents a three-phase unbalanced capacitive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl_N
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Capacitive_N
  "Model of a three-phase unbalanced capacitive load with neutral cable"
  extends BaseClasses.LoadCtrl_N(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load1(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load2(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Capacitive load3(pf=pf,
        use_pf_in=use_pf_in));
  parameter Boolean use_pf_in = false
    "If true, the power factor is defined by an input"
  parameter Real pf(min=0, max=1) = 0.8 "Power factor"
  Modelica.Blocks.Interfaces.RealInput pf_in_1(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase1) "Power factor of load on phase 1"
  Modelica.Blocks.Interfaces.RealInput pf_in_2(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase2) "Power factor of load on phase 2"
  Modelica.Blocks.Interfaces.RealInput pf_in_3(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase3) "Power factor of load on phase 3"
equation
  connect(pf_in_1, load1.pf_in)
  connect(pf_in_2, load2.pf_in)
  connect(pf_in_3, load3.pf_in)
end Capacitive_N;


Model of a three-phase unbalanced impedance without neutral cable. This model represents a three-phase unbalanced impedance without neutral cable.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.Impedance
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.Impedance.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Impedance
  "Model of a three-phase unbalanced impedance without neutral cable"
  extends BaseClasses.Impedance(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load1,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load2,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load3);
equation
end Impedance;


Model of a three-phase unbalanced impedance with neutral cable. This model represents a three-phase unbalanced impedance with neutral cable.
The current in the neutral cable is computed as the algebraic sum of the currents
of the loads.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.Impedance_N
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.Impedance.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Impedance_N
  "Model of a three-phase unbalanced impedance with neutral cable"
  extends BaseClasses.Impedance_N(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load1,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load2,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Impedance load3);
equation
end Impedance_N;


Model of a three-phase unbalanced inductive load without neutral cable. This model represents a three-phase unbalanced inductive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Inductive
  "Model of a three-phase unbalanced inductive load without neutral cable"
  extends BaseClasses.LoadCtrl(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load1(
      pf=pf,
      use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load2(
      pf=pf,
      use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load3(
      pf=pf,
      use_pf_in=use_pf_in));
  parameter Boolean use_pf_in = false
    "If true, the power factor is defined by an input"
  parameter Real pf(min=0, max=1) = 0.8 "Power factor"
  Modelica.Blocks.Interfaces.RealInput pf_in_1(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase1) "Power factor of load on phase 1"
  Modelica.Blocks.Interfaces.RealInput pf_in_2(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase2) "Power factor of load on phase 2"
  Modelica.Blocks.Interfaces.RealInput pf_in_3(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase3) "Power factor of load on phase 3"

equation
  connect(pf_in_1, load1.pf_in)
  connect(pf_in_2, load2.pf_in)
  connect(pf_in_3, load3.pf_in)
end Inductive;


Model of a three-phase unbalanced inductive load with neutral cable. This model represents a three-phase unbalanced inductive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl_N
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Inductive_N
  "Model of a three-phase unbalanced inductive load with neutral cable"
  extends BaseClasses.LoadCtrl_N(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load1(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load2(pf=pf,
        use_pf_in=use_pf_in),
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Inductive load3(pf=pf,
        use_pf_in=use_pf_in));
  parameter Boolean use_pf_in = false
    "If true, the power factor is defined by an input"
  parameter Real pf(min=0, max=1) = 0.8 "Power factor"
  Modelica.Blocks.Interfaces.RealInput pf_in_1(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase1) "Power factor of load on phase 1"
  Modelica.Blocks.Interfaces.RealInput pf_in_2(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase2) "Power factor of load on phase 2"
  Modelica.Blocks.Interfaces.RealInput pf_in_3(
    min=0,
    max=1,
    unit="1") if (use_pf_in and plugPhase3) "Power factor of load on phase 3"
equation
  connect(pf_in_1, load1.pf_in)
  connect(pf_in_2, load2.pf_in)
  connect(pf_in_3, load3.pf_in)
end Inductive_N;


within AixLib.Electrical.AC.ThreePhasesUnbalanced;
package Loads "Package with load models for three-phase unbalanced AC systems"
  extends Modelica.Icons.VariantsPackage;
end Loads;


Model of a three-phase unbalanced resistive load without neutral cable. This model represents a three-phase unbalanced resistive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Resistive
  "Model of a three-phase unbalanced resistive load without neutral cable"
  extends BaseClasses.LoadCtrl(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load1,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load2,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load3);
equation
end Resistive;


Model of a three-phase unbalanced resistive load with neutral cable. This model represents a three-phase unbalanced resistive load.
The model extends from

AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.LoadCtrl_N
and uses the load model from the package

AixLib.Electrical.AC.OnePhase.Loads.
The model computes the voltages, currents and powers on each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
model Resistive_N
  "Model of a three-phase unbalanced resistive load with neutral cable"
  extends BaseClasses.LoadCtrl_N(
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load1,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load2,
    redeclare AixLib.Electrical.AC.OnePhase.Loads.Resistive load3);
equation
end Resistive_N;


Partial model of a three-phase unbalanced impedance. This model represents a partial interface for a three-phase AC
unbalanced impedance.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model BaseImpedance
  "Partial model of a three-phase unbalanced impedance"
  extends AixLib.Electrical.Interfaces.PartialPluggableUnbalanced;
  replaceable AixLib.Electrical.AC.OnePhase.Loads.Impedance
    load1(
    inductive=inductive,
    R=R,
    L=L,
    C=C,
    use_R_in=use_R_in,
    RMin=RMin,
    RMax=RMax,
    use_C_in=use_C_in,
    CMin=CMin,
    CMax=CMax,
    use_L_in=use_L_in,
    LMin=LMin,
    LMax=LMax)
    if plugPhase1 "Load 1"
  replaceable AixLib.Electrical.AC.OnePhase.Loads.Impedance
    load2(
    inductive=inductive,
    R=R,
    L=L,
    C=C,
    use_R_in=use_R_in,
    RMin=RMin,
    RMax=RMax,
    use_C_in=use_C_in,
    CMin=CMin,
    CMax=CMax,
    use_L_in=use_L_in,
    LMin=LMin,
    LMax=LMax)
    if plugPhase2 "Load 2"
  replaceable AixLib.Electrical.AC.OnePhase.Loads.Impedance
    load3(
    inductive=inductive,
    R=R,
    L=L,
    C=C,
    use_R_in=use_R_in,
    RMin=RMin,
    RMax=RMax,
    use_C_in=use_C_in,
    CMin=CMin,
    CMax=CMax,
    use_L_in=use_L_in,
    LMin=LMin,
    LMax=LMax)
    if plugPhase3 "Load 3"
  parameter AixLib.Electrical.Types.LoadConnection loadConn=
    AixLib.Electrical.Types.LoadConnection.wye_to_wyeg
    "Type of load connection (Yg or D)";
  parameter Boolean inductive=true
    "If =true the load is inductive, otherwise it is capacitive"
  parameter Modelica.Units.SI.Resistance R(
    start=1,
    min=0) = 1 "Resistance"
  parameter Modelica.Units.SI.Inductance L(
    start=0,
    min=0) = 0 "Inductance"
  parameter Modelica.Units.SI.Capacitance C(
    start=0,
    min=0) = 0 "Capacitance"
  parameter Boolean use_R_in = false "if true, R is specified by an input"
  parameter Modelica.Units.SI.Resistance RMin(
    start=R,
    min=Modelica.Constants.eps) = 1e-4 "Minimum value of the resistance"
  parameter Modelica.Units.SI.Resistance RMax(
    start=R,
    min=Modelica.Constants.eps) = 1e2 "Maximum value of the resistance"
  parameter Boolean use_C_in = false "if true, C is specified by an input"
  parameter Modelica.Units.SI.Capacitance CMin(
    start=C,
    min=Modelica.Constants.eps) = 1e-4 "Minimum value of the capacitance"
  parameter Modelica.Units.SI.Capacitance CMax(
    start=C,
    min=Modelica.Constants.eps) = 1e2 "Maximum value of the capacitance"
  parameter Boolean use_L_in = false "if true, L is specified by an input"
  parameter Modelica.Units.SI.Inductance LMin(
    start=L,
    min=Modelica.Constants.eps) = 1e-4 "Minimum value of the inductance"
  parameter Modelica.Units.SI.Inductance LMax(
    start=L,
    min=Modelica.Constants.eps) = 1e2 "Maximum value of the inductance"
  Modelica.Blocks.Interfaces.RealInput y_R(min=0, max=1) if use_R_in
    "Input that sepecifies variable R"
  Modelica.Blocks.Interfaces.RealInput y_C(min=0, max=1) if use_C_in
    "Input that sepecifies variable C"
  Modelica.Blocks.Interfaces.RealInput y_L(min=0, max=1) if use_L_in
    "Input that sepecifies variable L"

  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta
    wyeToDelta if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_delta)
    "Wye to delta load connection"
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToWyeGround
    wyeToWyeGround if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Wye to grounded wye connection"
protected
  Interfaces.Adapter3to3 adaDel
    if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_delta)
    "Adapter"
  Interfaces.Adapter3to3 adaWye
    if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Adapter"
equation

  // Conditional connections to load 1
  if plugPhase1 then
    if use_R_in then
      connect(y_R, load1.y_R)
    end if;
    if use_C_in then
      connect(y_C, load1.y_C)
    end if;
    if use_L_in then
      connect(y_L, load1.y_L)
    end if;
  end if;
  // Conditional connections to load 2
  if plugPhase2 then
    if use_R_in then
      connect(y_R, load2.y_R)
    end if;
    if use_L_in then
      connect(y_L, load2.y_L)
    end if;
    if use_C_in then
      connect(y_C, load2.y_C)
    end if;
  end if;

  // Conditional connections to load 3
  if plugPhase3 then
    if use_R_in then
      connect(y_R, load3.y_R)
    end if;
    if use_C_in then
      connect(y_C, load3.y_C)
    end if;
    if use_L_in then
      connect(y_L, load3.y_L)
    end if;
  end if;

  // Connection of the single loads to the 3phases connector
  if plugPhase1 then
    connect(load1.terminal, adaDel.terminals[1])
    connect(load1.terminal, adaWye.terminals[1])
  end if;

  if plugPhase2 then
    connect(load2.terminal, adaDel.terminals[2])
    connect(load2.terminal, adaWye.terminals[2])
  end if;
  if plugPhase3 then
    connect(load3.terminal, adaDel.terminals[3])
    connect(load3.terminal, adaWye.terminals[3])
  end if;

  connect(adaDel.terminal, wyeToDelta.delta)
  connect(adaWye.terminal, wyeToWyeGround.wyeg)
end BaseImpedance;


within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model BaseLoadCtrl
  "Partial model of a three-phase unbalanced load with voltage controllers"
  extends AixLib.Electrical.Interfaces.PartialPluggableUnbalanced;
  parameter AixLib.Electrical.Types.LoadConnection loadConn=
    AixLib.Electrical.Types.LoadConnection.wye_to_wyeg
    "Type of load connection (Yg or D)";
  parameter Boolean linearized = false
    "If =true introduce a linearization in the load"
  parameter AixLib.Electrical.Types.Load mode(
    min=AixLib.Electrical.Types.Load.FixedZ_steady_state,
    max=AixLib.Electrical.Types.Load.VariableZ_y_input)=
    AixLib.Electrical.Types.Load.FixedZ_steady_state "Parameters that specifies the mode of the load (e.g., steady state,
    dynamic, prescribed power consumption, etc.)"

  parameter Modelica.Units.SI.Power P_nominal=0
    "Nominal power (negative if consumed, positive if generated)"

  parameter Modelica.Units.SI.Voltage V_nominal(min=0, start=480)
    "Nominal voltage (V_nominal >= 0)"
  parameter Boolean voltageCtrl = false "This flag enables the voltage control"
  parameter Real vThresh(min=0.0, max=1.0) = 0.1
    "Threshold that activates voltage ctrl (ratio of nominal voltage)"
  parameter Modelica.Units.SI.Time tDelay=300
    "Time to wait before plugging the load again after disconnection"
  parameter Types.InitMode initMode=AixLib.Electrical.Types.InitMode.zero_current
    "Initialization mode for homotopy operator"
  replaceable AixLib.Electrical.Interfaces.Load load1(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    final linearized=linearized,
    final mode=mode,
    final P_nominal = P_nominal,
    final V_nominal=V_nominal/sqrt(3),
    final initMode=initMode)
    if plugPhase1 "Load 1"
  replaceable AixLib.Electrical.Interfaces.Load load2(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    final linearized=linearized,
    final mode=mode,
    final P_nominal = P_nominal,
    final V_nominal=V_nominal/sqrt(3),
    final initMode=initMode)
    if plugPhase2 "Load 2"
  replaceable AixLib.Electrical.Interfaces.Load load3(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    final linearized=linearized,
    final mode=mode,
    final P_nominal = P_nominal,
    final V_nominal=V_nominal/sqrt(3),
    final initMode=initMode)
    if plugPhase3 "Load 3"
  Modelica.Blocks.Interfaces.RealInput y1  if plugPhase1 and
    mode == AixLib.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow1(unit="W") if plugPhase1 and
    mode == AixLib.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  Modelica.Blocks.Interfaces.RealInput y2 if plugPhase2 and
    mode == AixLib.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow2(unit="W") if plugPhase2 and
    mode == AixLib.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  Modelica.Blocks.Interfaces.RealInput y3 if plugPhase3 and
    mode == AixLib.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow3(unit="W") if plugPhase3 and
    mode == AixLib.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  AixLib.Electrical.Utilities.VoltageControl vCTRL_1(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    vThresh=vThresh,
    tDelay=tDelay,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase1 and voltageCtrl "Voltage controller for load 1"
  Modelica.Blocks.Math.Product cmd1 if plugPhase1 and voltageCtrl
    "Block that impose voltage ctrl"
  AixLib.Electrical.Utilities.VoltageControl vCTRL_2(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    vThresh=vThresh,
    tDelay=tDelay,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase2 and voltageCtrl "Voltage controller for load 2"
  Modelica.Blocks.Math.Product cmd2 if plugPhase2 and voltageCtrl
    "Block that impose voltage ctrl"
  AixLib.Electrical.Utilities.VoltageControl vCTRL_3(
    redeclare package PhaseSystem = AixLib.Electrical.PhaseSystems.OnePhase,
    redeclare AixLib.Electrical.AC.OnePhase.Interfaces.Terminal_n terminal,
    vThresh=vThresh,
    tDelay=tDelay,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase3 and voltageCtrl "Voltage controller for load 3"
  Modelica.Blocks.Math.Product cmd3 if plugPhase3 and voltageCtrl
    "Block that impose voltage ctrl"
  Interfaces.WyeToDelta
    wyeToDelta if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_delta)
    "Wye to delta load connection"
  Interfaces.WyeToWyeGround
    wyeToWyeGround if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Wye to wye grounded connection"
protected
  Interfaces.Adapter3to3 adaDel
    if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_delta)
    "Adapter"
  Interfaces.Adapter3to3 adaWye
    if (loadConn == AixLib.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Adapter"
equation
  // Connections enabled when the input provided is y (between 0 and 1)
  if mode==AixLib.Electrical.Types.Load.VariableZ_y_input then
    if plugPhase1 and voltageCtrl then
      connect(cmd1.y, load1.y)
      connect(cmd1.u2, y1)
    end if;
    if plugPhase1 and not voltageCtrl then
      connect(y1, load1.y)
    end if;

    if plugPhase2 and voltageCtrl then
      connect(cmd2.y, load2.y)
      connect(cmd2.u2, y2)
    end if;
    if plugPhase2 and not voltageCtrl then
      connect(y2, load2.y)
    end if;

    if plugPhase3 and voltageCtrl then
      connect(cmd3.y, load3.y)
      connect(cmd3.u2, y3)
    end if;
    if plugPhase3 and not voltageCtrl then
      connect(y3, load3.y)
    end if;
  end if;

  // Connections enabled when the input provided is the power
  if mode==AixLib.Electrical.Types.Load.VariableZ_P_input then
    if plugPhase1 and voltageCtrl then
      connect(cmd1.y, load1.Pow)
      connect(cmd1.u2, Pow1)
    end if;
    if plugPhase1 and not voltageCtrl then
      connect(Pow1, load1.Pow)
    end if;

    if plugPhase2 and voltageCtrl then
      connect(cmd2.y, load2.Pow)
      connect(cmd2.u2, Pow2)
    end if;
    if plugPhase2 and not voltageCtrl then
      connect(Pow2, load2.Pow)
    end if;

    if plugPhase3 and voltageCtrl then
      connect(cmd3.y, load3.Pow)
      connect(cmd3.u2, Pow3)
    end if;
    if plugPhase3 and not voltageCtrl then
      connect(Pow3, load3.Pow)
    end if;
  end if;

  // Connections enabled when phase 1 is plugged and voltage ctrl activated
  if plugPhase1 and voltageCtrl then
    connect(load1.terminal, vCTRL_1.terminal)
    connect(vCTRL_1.y, cmd1.u1)
  end if;

  if plugPhase2 and voltageCtrl then
    connect(load2.terminal, vCTRL_2.terminal)
    connect(vCTRL_2.y, cmd2.u1)
  end if;

  if plugPhase3 and voltageCtrl then
    connect(load3.terminal, vCTRL_3.terminal)
    connect(vCTRL_3.y, cmd3.u1)
  end if;

  // Connection of the single loads to the 3phases connector
  if plugPhase1 then
    connect(load1.terminal, adaDel.terminals[1])
    connect(load1.terminal, adaWye.terminals[1])
  end if;

  if plugPhase2 then
    connect(load2.terminal, adaDel.terminals[2])
    connect(load2.terminal, adaWye.terminals[2])
  end if;
  if plugPhase3 then
    connect(load3.terminal, adaDel.terminals[3])
    connect(load3.terminal, adaWye.terminals[3])
  end if;

  connect(adaDel.terminal, wyeToDelta.delta)
  connect(adaWye.terminal, wyeToWyeGround.wyeg)
end BaseLoadCtrl;


Partial model of a three-phase unbalanced impedance without neutral cable. This model represents a partial interface for a three-phase AC
unbalanced impedance without neutral cable.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model Impedance
  "Partial model of a three-phase unbalanced impedance without neutral cable"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseImpedance;
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_n terminal
    "Electrical connector"

equation
  connect(terminal, wyeToDelta.wye)
  connect(terminal, wyeToWyeGround.wye)
end Impedance;


Partial model of a three-phase unbalanced impedance with neutral cable. This model represents a partial interface for a three-phase AC
unbalanced impedance with a neutral cable. The current in the neutral
cable is computed as the algebraic sum of the currents in the loads.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model Impedance_N
  "Partial model of a three-phase unbalanced impedance with neutral cable"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseImpedance;
  Interfaces.Terminal4_n terminal "Electrical connector"
  Interfaces.Connection3to4_n connection3to4
    "Connection from three-phase and neutral to three-phase"
equation

  connect(connection3to4.terminal3, wyeToDelta.wye)
  connect(connection3to4.terminal3, wyeToWyeGround.wye)
  connect(connection3to4.terminal4, terminal)
end Impedance_N;


Partial model of a three-phase load with voltage controller without neutral cable. This model represents a partial interface for a three-phase AC unbalanced
load without neutral cable.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model LoadCtrl
  "Partial model of a three-phase load with voltage controller without neutral cable"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseLoadCtrl;
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_n terminal
    "Connector for three-phase unbalanced systems without neutral cable"
equation

  connect(terminal, wyeToDelta.wye)
  connect(terminal, wyeToWyeGround.wye)
end LoadCtrl;


Partial model of a three-phase unbalanced load with voltage controller and neutral cable. This model represents a partial interface for a three-phase AC unbalanced
load with neutral cable. The current in the neutral cable is computed as the
algebraic sum of the currents in the loads.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model LoadCtrl_N
  "Partial model of a three-phase unbalanced load with voltage controller and neutral cable"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseLoadCtrl;
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_n terminal
    "Connector for three-phase unbalanced systems with neutral cable"
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Connection3to4_n
    connection3to4 "Connection from three-phase and neutral to three-phase"
equation

  connect(connection3to4.terminal3, wyeToDelta.wye)
  connect(connection3to4.terminal3, wyeToWyeGround.wye)
  connect(connection3to4.terminal4, terminal)
end LoadCtrl_N;


Package with base class models

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
package BaseClasses "Package with base class models"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


This model tests three-phase unbalanced impedances with and without neutral cable. This example model shows how to use three-phase unbalanced impedances with and without neutral cable.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.Examples;
model Impedances
  "This model tests three-phase unbalanced impedances with and without neutral cable"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N sou_N(definiteReference=true,
    f=60,
    V=480) "Voltage source with neutral cable"
  Sensors.GeneralizedSensor_N sen_N "Power sensor with neutral cable"
  Impedance_N imp_N(
    plugPhase2=false,
    use_R_in=true,
    RMin=1,
    RMax=10,
    use_L_in=true,
    LMin=0.1,
    LMax=1) "Impedance with neutral cable"
  Sources.FixedVoltage sou(definiteReference=true,
    f=60,
    V=480) "Voltage source without neutral cable"
  Sensors.GeneralizedSensor sen "Power sensor without neutral cable"
  Impedance imp(
    plugPhase2=false,
    use_R_in=true,
    RMin=1,
    RMax=10,
    use_L_in=true,
    LMin=0.1,
    LMax=1) "Impedance without neutral cable"
  Modelica.Blocks.Sources.Ramp var_RL(
    duration=0.5,
    startTime=0.25,
    height=1,
    offset=0) "Power signal for loads on phase 1"
equation

  connect(sou.terminal, sen.terminal_n)
  connect(sen.terminal_p, imp.terminal)
  connect(var_RL.y, imp.y_R)
  connect(var_RL.y, imp.y_L)
  connect(var_RL.y, imp_N.y_R)
  connect(var_RL.y, imp_N.y_L)
  connect(sou_N.terminal, sen_N.terminal_n)
  connect(sen_N.terminal_p, imp_N.terminal)
end Impedances;


Voltage source. This example model shows how the voltage controller can act on a three-phase unbalanced load.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.Examples;
model LoadCtrl
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N sou(f=60, V=480) "Voltage source"
  Modelica.Blocks.Sources.Sine pow_1(
    f=0.1,
    amplitude=4500,
    offset=6000) "Power on phase 1"
  Resistive_N load_ctrl(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    vThresh=0.05,
    tDelay=2,
    voltageCtrl=true,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Voltage controlled load"
  Lines.Line_N line1(
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu10
      commercialCable,
    l=400,
    P_nominal=10000,
    V_nominal=480) "Transmission line to voltage controlled load"
  Resistive_N load(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Load"
  Lines.Line_N line(
    mode=AixLib.Electrical.Types.CableMode.commercial,
    redeclare AixLib.Electrical.Transmission.LowVoltageCables.Cu10
      commercialCable,
    l=400,
    P_nominal=10000,
    V_nominal=480)
equation
  connect(pow_1.y, load_ctrl.Pow1)
  connect(pow_1.y, load.Pow1)
  connect(sou.terminal, line1.terminal_n)
  connect(sou.terminal, line.terminal_n)
  connect(line.terminal_p, load.terminal)
  connect(line1.terminal_p, load_ctrl.terminal)
end LoadCtrl;


This model tests the load models without neutral cable connection. This example model shows how three-phase unbalanced loads can be used.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.Examples;
model Loads "This model tests the load models without neutral cable connection"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage sou(definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Modelica.Blocks.Sources.Sine ph_1(
    amplitude=2000,
    f=10,
    offset=-2500) "Power signal for loads on phase 1"
  Modelica.Blocks.Sources.Constant ph_23(k=0)
    "Power signal for loads on phase 2 and 3"
  Resistive loaR(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Resistive load"
  Inductive loaRL(mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Inductive load"
  Capacitive loaRC(mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Capacitive load"
  Sensors.GeneralizedSensor sen "Power sensor"
  Sensors.GeneralizedSensor senSingleConn "Power sensor"
  Capacitive loaRC1(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Capacitive load"
  Inductive loaRL1(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Inductive load"
  Resistive loaR1(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Resistive load"
equation
  connect(ph_1.y, loaR.Pow1)
  connect(ph_23.y, loaR.Pow3)
  connect(ph_23.y, loaR.Pow2)
  connect(ph_1.y, loaRL.Pow1)
  connect(ph_1.y, loaRC.Pow1)
  connect(ph_23.y, loaRL.Pow2)
  connect(ph_23.y, loaRL.Pow3)
  connect(ph_23.y, loaRC.Pow2)
  connect(ph_23.y, loaRC.Pow3)
  connect(sou.terminal, sen.terminal_n)

  connect(sen.terminal_p, loaR.terminal)
  connect(sen.terminal_p, loaRL.terminal)
  connect(sen.terminal_p, loaRC.terminal)
  connect(senSingleConn.terminal_p, loaR1.terminal)
  connect(senSingleConn.terminal_p, loaRL1.terminal)
  connect(senSingleConn.terminal_p, loaRC1.terminal)
  connect(ph_1.y, loaRC1.Pow1)
  connect(ph_1.y, loaRL1.Pow1)
  connect(ph_1.y, loaR1.Pow1)
  connect(sou.terminal, senSingleConn.terminal_n)
end Loads;


This model tests unbalanced load models with neutral cable connection. This example model shows how three-phase unbalanced loads with the neutral cable can be used.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads.Examples;
model Loads_N
  "This model tests unbalanced load models with neutral cable connection"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage_N
                       sou(definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Modelica.Blocks.Sources.Ramp ph_1(
    offset=-1000,
    duration=0.5,
    startTime=0.25,
    height=-500) "Power signal for loads on phase 1"
  Modelica.Blocks.Sources.Constant ph_23(k=-1000)
    "Power signal for loads on phase 2 and 3"
  Resistive_N loaR_N(mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Resistive load with neutral cable"
  Inductive_N loaRL_N(mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
      pf=0.9,
    V_nominal=480) "Inductive load with neutral cable"
  Capacitive_N loaRC_N(
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input,
    pf=0.7,
    V_nominal=480) "Capacitive load with neutral cable"
  Sensors.GeneralizedSensor_N
                            sen "Power sensor with neutral cable"
equation
  connect(ph_1.y, loaR_N.Pow1)
  connect(ph_23.y, loaR_N.Pow3)
  connect(ph_23.y, loaR_N.Pow2)

  connect(ph_1.y, loaRL_N.Pow1)
  connect(ph_1.y, loaRC_N.Pow1)
  connect(ph_23.y, loaRL_N.Pow2)
  connect(ph_23.y, loaRL_N.Pow3)
  connect(ph_23.y, loaRC_N.Pow2)
  connect(ph_23.y, loaRC_N.Pow3)

  connect(sou.terminal, sen.terminal_n)
  connect(sen.terminal_p, loaR_N.terminal)
  connect(sen.terminal_p, loaRL_N.terminal)
  connect(sen.terminal_p, loaRC_N.terminal)
end Loads_N;


Package with example models

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Loads;
package Examples "Package with example models"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Sensor for power, voltage and current (3 wire system, no neutral cable). Ideal sensor that measures power, voltage and current in a three-phase unbalanced system
without a neutral cable.
The two components of the power <i>S</i> are the active and reactive power for each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model GeneralizedSensor
  "Sensor for power, voltage and current (3 wire system, no neutral cable)"

  Interfaces.Terminal_n terminal_n "Electrical connector side N"
  Interfaces.Terminal_p terminal_p "Electrical connector side P"
  Modelica.Blocks.Interfaces.RealOutput V[3](each final quantity="ElectricPotential",
                                          each final unit="V") "Voltage"
  Modelica.Blocks.Interfaces.RealOutput I[3](each final quantity="ElectricCurrent",
                                          each final unit="A") "Current"
  Modelica.Blocks.Interfaces.RealOutput S[3, AixLib.Electrical.PhaseSystems.OnePhase.n](
                                          each final quantity="Power",
                                          each final unit="W") "Phase powers"
equation

  for i in 1:3 loop
    V[i]   = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal_n.phase[i].v);
    I[i]   = AixLib.Electrical.PhaseSystems.OnePhase.systemCurrent(terminal_n.phase[i].i);
    S[i,:] = AixLib.Electrical.PhaseSystems.OnePhase.phasePowers_vi(v=terminal_n.phase[i].v, i=terminal_n.phase[i].i);
  end for;

  connect(terminal_n, terminal_p)
end GeneralizedSensor;


Sensor for power, voltage and current (4 wire system, with neutral cable). Ideal sensor that measures power, voltage and current in a three-phase unbalanced system
with neutral cable.
The two components of the power <i>S</i> are the active and reactive power for each phase.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model GeneralizedSensor_N
  "Sensor for power, voltage and current (4 wire system, with neutral cable)"

  Interfaces.Terminal4_n terminal_n "Electrical connector side N"
  Interfaces.Terminal4_p terminal_p "Electrical connector side P"
  Modelica.Blocks.Interfaces.RealOutput V[4](each final quantity="ElectricPotential",
                                          each final unit="V") "Voltage"
  Modelica.Blocks.Interfaces.RealOutput I[4](each final quantity="ElectricCurrent",
                                          each final unit="A") "Current"
  Modelica.Blocks.Interfaces.RealOutput S[4, AixLib.Electrical.PhaseSystems.OnePhase.n](
                                          each final quantity="Power",
                                          each final unit="W") "Phase powers"
equation

  for i in 1:4 loop
    V[i]   = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal_n.phase[i].v);
    I[i]   = AixLib.Electrical.PhaseSystems.OnePhase.systemCurrent(terminal_n.phase[i].i);
    S[i,:] = AixLib.Electrical.PhaseSystems.OnePhase.phasePowers_vi(v=terminal_n.phase[i].v, i=terminal_n.phase[i].i);
  end for;

  connect(terminal_n, terminal_p)
end GeneralizedSensor_N;


within AixLib.Electrical.AC.ThreePhasesUnbalanced;
package Sensors "Package with sensor models for three-phase unbalanced AC systems"
  extends Modelica.Icons.SensorsPackage;
end Sensors;


Model of a probe that measures voltage magnitude and angle (Delta configuration). This model represents a probe that measures the RMS voltage and the angle
of the voltage phasors at a given point. The probes are connected
in the Wye (Y) grounded configuration.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeDelta
  "Model of a probe that measures voltage magnitude and angle (Delta configuration)"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_n
  term "Electrical connector"
  Interfaces.WyeToDelta wyeToDelta "Y to D transformation"
equation
  for i in 1:3 loop
      theta[i] = AixLib.Electrical.PhaseSystems.OnePhase.phase(wyeToDelta.delta.phase[i].v);
      if perUnit then
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToDelta.delta.phase[i].v)/V_nominal;
      else
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToDelta.delta.phase[i].v);
      end if;
  end for;

  connect(term, wyeToDelta.wye)
end ProbeDelta;


Model of a probe that measures voltage magnitude and angle (Wye configuration). This model represents a probe that measures the RMS voltage and the angle
of the voltage phasors at a given point. The probes are connected
in the Wye (Y) grounded configuration.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeWye
  "Model of a probe that measures voltage magnitude and angle (Wye configuration)"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_n
    term "Electrical connector"
  Interfaces.WyeToWyeGround wyeToWyeGround "Y to Y grounded transformation"
equation
  for i in 1:3 loop
      theta[i] = AixLib.Electrical.PhaseSystems.OnePhase.phase(wyeToWyeGround.wyeg.phase[i].v);
      if perUnit then
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToWyeGround.wyeg.phase[i].v)/(V_nominal/sqrt(3));
      else
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToWyeGround.wyeg.phase[i].v);
      end if;
  end for;

  connect(term, wyeToWyeGround.wye)
end ProbeWye;


Model of a probe that measures voltage magnitude and angle (Wye configuration) witn neutral cable connection. This model represents a probe that measures the RMS voltage and the angle
of the voltage phasors at a given point. The probes are connected
in the Wye (Y) grounded configuration.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeWye_N
  "Model of a probe that measures voltage magnitude and angle (Wye configuration) witn neutral cable connection"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_n
    term "Electrical connector"
equation

  for i in 1:4 loop
    term.phase[i].i = zeros(AixLib.Electrical.PhaseSystems.OnePhase.n);
  end for;

  for i in 1:3 loop
      theta[i] = AixLib.Electrical.PhaseSystems.OnePhase.phase(term.phase[i].v - term.phase[4].v);
      if perUnit then
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(term.phase[i].v - term.phase[4].v)/(V_nominal/sqrt(3));
      else
        V[i] = AixLib.Electrical.PhaseSystems.OnePhase.systemVoltage(term.phase[i].v - term.phase[4].v);
      end if;
  end for;
end ProbeWye_N;


Partial model of a generalized three-phase probe. This model contains the parameters and connectors that are used by
probe models such as
AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye and

AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta.
The output connectors are for the RMS voltage and the angle of the voltage phasors.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses;
partial model GeneralizedProbe
  "Partial model of a generalized three-phase probe"
  extends Icons.GeneralizedProbe;
  parameter Modelica.Units.SI.Voltage V_nominal(min=0, start=480)
    "RMS Nominal voltage (V_nominal >= 0)";
  parameter Boolean perUnit = true "This flag display voltage in p.u.";
  Modelica.Blocks.Interfaces.RealOutput V[3](each unit="1")
    "Voltage in per unit"
  Modelica.Blocks.Interfaces.RealOutput theta[3](each unit="rad", each displayUnit="deg") "Angle"
end GeneralizedProbe;


Package that contains base classes

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
package BaseClasses "Package that contains base classes"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


Package with example models

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors;
package Examples "Package with example models"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Test models for sensors and probes. This example shows how different types of sensors and probes can be used
to measure the voltages, currents and powers in a three-phase
unbalanced system.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sensors.Examples;
model Sensors "Test models for sensors and probes"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage source(
    f=60,
    V=480)
    "Voltage source without neutral cable"
  Loads.Resistive load(
    V_nominal=480,
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input)
    "Load model"
  ProbeWye probeWye(V_nominal=480) "Probe that measures the phase voltages"
  ProbeDelta probeDelta(V_nominal=480) "Probe that measures the line voltages"
  Sources.FixedVoltage_N source_N(
    f=60,
    V=480)
    "Voltage source with neutral cable"
  Loads.Resistive_N load_N(
    V_nominal=480,
    mode=AixLib.Electrical.Types.Load.VariableZ_P_input)
    "Load model"
  ProbeWye_N probeWye_N(V_nominal=480)
  GeneralizedSensor sen "Generalized sensor withour neutral cable"
  GeneralizedSensor_N sen_N "Generalized sensor with neutral cable"
  Modelica.Blocks.Sources.Ramp ramp(
    height=2e4,
    duration=0.5,
    offset=-1e4,
    startTime=0.25)
equation
  connect(probeWye.term, source.terminal)
  connect(probeDelta.term, source.terminal)
  connect(source_N.terminal, probeWye_N.term)
  connect(source_N.terminal, sen_N.terminal_n)
  connect(sen_N.terminal_p, load_N.terminal)
  connect(sen.terminal_p, load.terminal)
  connect(sen.terminal_n, source.terminal)
  connect(ramp.y, load.Pow1)
  connect(ramp.y, load.Pow2)
  connect(ramp.y, load.Pow3)
  connect(ramp.y, load_N.Pow1)
  connect(ramp.y, load_N.Pow2)
  connect(ramp.y, load_N.Pow3)
end Sensors;


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

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model FixedVoltage "Fixed voltage source"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.PartialSource;
  parameter Modelica.Units.SI.Frequency f(start=60) "Frequency of the source";
  parameter Modelica.Units.SI.Voltage V(start=480) "RMS voltage of the source";
  parameter Modelica.Units.SI.Angle phiSou=0 "Phase shift of the source";
  parameter Boolean potentialReference = true
    "Serve as potential root for the reference angle theta"
  parameter Boolean definiteReference = false
    "Serve as definite root for the reference angle theta"
  constant Modelica.Units.SI.Angle angle120=2*Modelica.Constants.pi/3
    "Phase shift between the phase voltages";
  OnePhase.Sources.FixedVoltage vPhase[3](
    each f=f,
    potentialReference={potentialReference, potentialReference, potentialReference},
    definiteReference={definiteReference, false, false},
    phiSou={phiSou,phiSou - angle120,phiSou + angle120},
    each V=V/sqrt(3)) "Voltage sources on the three-phase"
protected
  Interfaces.Adapter3to3 ada "Adapter between the different connectors"
equation

  connect(vPhase.terminal, ada.terminals)
  connect(ada.terminal, connection3to4.terminal4)
end FixedVoltage;


Fixed voltage source with neutral cable. This is a constant voltage source, specifying the complex
voltage by the RMS voltage and the phase shift. The model has also
the neutral cable, connected to a ground reference by default.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model FixedVoltage_N "Fixed voltage source with neutral cable"
  extends
    AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.PartialSource_N;
  parameter Modelica.Units.SI.Frequency f(start=60) "Frequency of the source";
  parameter Modelica.Units.SI.Voltage V(start=480) "RMS voltage of the source";
  parameter Modelica.Units.SI.Angle phiSou=0 "Phase shift of the source";
  parameter Boolean potentialReference = true
    "Serve as potential root for the reference angle theta"
  parameter Boolean definiteReference = false
    "Serve as definite root for the reference angle theta"
  constant Modelica.Units.SI.Angle angle120=2*Modelica.Constants.pi/3
    "Phase shift between the phase voltages";
  OnePhase.Sources.FixedVoltage vPhase[3](
    each f=f,
    phiSou={phiSou, phiSou + angle120, phiSou + 2*angle120},
    potentialReference={potentialReference, potentialReference, potentialReference},
    definiteReference={definiteReference, false, false},
    each V=V/sqrt(3)) "Voltage sources on the three-phase"
equation

  connect(vPhase[1].terminal, terminal.phase[1])
  connect(vPhase[2].terminal, terminal.phase[2])
  connect(vPhase[3].terminal, terminal.phase[3])
end FixedVoltage_N;


Electrical grid. Model that can be used to represent the electrical grid supply.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model Grid "Electrical grid"
  parameter Modelica.Units.SI.Frequency f(start=60) "Frequency of the source";
  parameter Modelica.Units.SI.Voltage V(start=480) "RMS voltage of the source";
  parameter Modelica.Units.SI.Angle phiSou=0 "Phase shift of the source";
  AixLib.Electrical.AC.Interfaces.PowerOutput P[3]
    "Power consumed from grid if positive, or fed to grid if negative"
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_p terminal
    "Connector for three-phase unbalanced systems"

  AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.FixedVoltage sou(
    potentialReference=true,
    definiteReference=true,
    f=f,
    V=V,
    phiSou=phiSou) "Voltage source"
equation
  for i in 1:3 loop
    P[i].real = -sou.vPhase[i].S[1];
    P[i].apparent = sqrt(sou.vPhase[i].S[2]^2 + sou.vPhase[i].S[1]^2);
    P[i].phi = sou.vPhase[i].phi;
    P[i].cosPhi = cos(sou.vPhase[i].phi);
  end for;
  connect(sou.terminal, terminal)
end Grid;


Electrical grid with neutral cable. Model that can be used to represent the electrical grid supply with a neutral cable connection.
The neutral cable is connected to the ground.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model Grid_N "Electrical grid with neutral cable"
  parameter Modelica.Units.SI.Frequency f(start=60) "Frequency of the source";
  parameter Modelica.Units.SI.Voltage V(start=480) "RMS voltage of the source";
  parameter Modelica.Units.SI.Angle phiSou=0 "Phase shift of the source";
  AixLib.Electrical.AC.Interfaces.PowerOutput P[3]
    "Power consumed from grid if positive, or fed to grid if negative"
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_p terminal
    "Connector for three-phase unbalanced systems"
  AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.FixedVoltage_N sou(
    potentialReference=true,
    definiteReference=true,
    f=f,
    V=V,
    phiSou=phiSou) "Voltage source"
equation
  for i in 1:3 loop
    P[i].real = -sou.vPhase[i].S[1];
    P[i].apparent = sqrt(sou.vPhase[i].S[2]^2 + sou.vPhase[i].S[1]^2);
    P[i].phi = sou.vPhase[i].phi;
    P[i].cosPhi = cos(sou.vPhase[i].phi);
  end for;
  connect(sou.terminal, terminal)
end Grid_N;


within AixLib.Electrical.AC.ThreePhasesUnbalanced;
package Sources "Package with sources model for three-phase unbalanced AC systems"
  extends Modelica.Icons.SourcesPackage;
end Sources;


Simple wind turbine source without neutral cable. Simple wind turbine model for three-phase unbalanced systems
without neutral cable connection.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model WindTurbine "Simple wind turbine source without neutral cable"
  extends BaseClasses.UnbalancedWindTurbine(
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase1,
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase2,
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase3);
end WindTurbine;


Simple wind turbine source with neutral cable. Simple wind turbine model for three-phase unbalanced systems
with neutral cable connection.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
model WindTurbine_N "Simple wind turbine source with neutral cable"
  extends BaseClasses.UnbalancedWindTurbine_N(
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase1,
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase2,
  redeclare AixLib.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase3);
end WindTurbine_N;


Partial model for an unbalanced wind power source. This model is a partial class extended by three-phase unbalanced
wind turbine power sources.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
partial model BaseUnbalancedWindTurbine
  "Partial model for an unbalanced wind power source"
  extends AixLib.Electrical.Interfaces.PartialPluggableUnbalanced;
  extends AixLib.Electrical.Interfaces.PartialAcDcParameters;
  extends AixLib.Electrical.BaseClasses.WindTurbine.PartialWindTurbineBase(
    V_nominal(start = 480));
  parameter Real scaleFraction[3](each min=0, each max=1.0) = ones(3)/3
    "Fraction of power allocated to the wind turbines of each phase";
  replaceable OnePhase.Sources.WindTurbine wt_phase2(
    pf=pf,
    eta_DCAC=eta_DCAC,
    scale=scale*scaleFraction[2],
    h=h,
    hRef=hRef,
    nWin=nWin,
    tableOnFile=tableOnFile,
    table=table,
    tableName=tableName,
    fileName=fileName,
    V_nominal=V_nominal/sqrt(3))
      if plugPhase2 "Wind turbine phase 2"

  replaceable OnePhase.Sources.WindTurbine wt_phase3(
    pf=pf,
    eta_DCAC=eta_DCAC,
    scale=scale*scaleFraction[3],
    h=h,
    hRef=hRef,
    nWin=nWin,
    tableOnFile=tableOnFile,
    table=table,
    tableName=tableName,
    fileName=fileName,
    V_nominal=V_nominal/sqrt(3))
      if plugPhase3 "Wind turbine phase 3"

  replaceable OnePhase.Sources.WindTurbine wt_phase1(
    pf=pf,
    eta_DCAC=eta_DCAC,
    scale=scale*scaleFraction[1],
    h=h,
    hRef=hRef,
    nWin=nWin,
    tableOnFile=tableOnFile,
    table=table,
    tableName=tableName,
    fileName=fileName,
    V_nominal=V_nominal/sqrt(3))
      if plugPhase1 "Wind turbine phase 1"
  Modelica.Blocks.Math.Add3 sumBlock "Sum of th epower generated on each phase"
equation

  assert(abs(sum(scaleFraction)-1) < Modelica.Constants.eps,
  "Model that extends AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedWindTurbine,
  has an invalid value for the vector scaleFraction[:]. The sum of the
  elements has to be equal to 1.0.",
  level=AssertionLevel.error);

  if plugPhase1 then
    connect(wt_phase1.P, sumBlock.u1)
  else
    sumBlock.u1 = 0;
  end if;

  if plugPhase2 then
    connect(wt_phase2.P, sumBlock.u2)
  else
    sumBlock.u2 = 0;
  end if;

  if plugPhase3 then
    connect(wt_phase3.P, sumBlock.u3)
  else
    sumBlock.u3 = 0;
  end if;

  connect(sumBlock.y, P)

  connect(vWin, wt_phase1.vWin)
  connect(vWin, wt_phase2.vWin)
  connect(vWin, wt_phase3.vWin)
end BaseUnbalancedWindTurbine;


Package with base class models

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources;
package BaseClasses "Package with base class models"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Partial model for a three-phase AC unbalanced voltage source without neutral cable. This model is a partial class extended by three-phase unbalanced
voltage sources without neutral cable connection.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
partial model PartialSource
  "Partial model for a three-phase AC unbalanced voltage source without neutral cable"

  Interfaces.Connection3to3Ground_p connection3to4
    "Connection between three to four AC connectors with ground connection"
  OnePhase.Basics.Ground ground "Ground reference"
  Interfaces.Terminal_p terminal "Connector for three-phase unbalanced systems"
equation

  connect(connection3to4.terminal3,terminal)
  connect(ground.terminal, connection3to4.ground4)
end PartialSource;


Partial model for a three-phase AC unbalanced voltage source
  with neutral cable. This model is a partial class extended by three-phase unbalanced
voltage sources that have a neutral cable.

within AixLib.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
partial model PartialSource_N "Partial model for a three-phase AC unbalanced voltage source
  with neutral cable"

  OnePhase.Basics.Ground ground "Ground reference"
  Interfaces.Terminal4_p terminal
    "Connector for three-phase unbalanced systems with neutral cable"
equation

  connect(ground.terminal, terminal.phase[4])
end PartialSource_N;