within Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model BaseLoadCtrl
  "Partial model of a three-phase unbalanced load with voltage controllers"
  extends Buildings.Electrical.Interfaces.PartialPluggableUnbalanced;
  parameter Buildings.Electrical.Types.LoadConnection loadConn=
    Buildings.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 Buildings.Electrical.Types.Load mode(
    min=Buildings.Electrical.Types.Load.FixedZ_steady_state,
    max=Buildings.Electrical.Types.Load.VariableZ_y_input)=
    Buildings.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=Buildings.Electrical.Types.InitMode.zero_current
    "Initialization mode for homotopy operator"
  replaceable Buildings.Electrical.Interfaces.Load load1(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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 Buildings.Electrical.Interfaces.Load load2(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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 Buildings.Electrical.Interfaces.Load load3(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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 == Buildings.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow1(unit="W") if plugPhase1 and
    mode == Buildings.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  Modelica.Blocks.Interfaces.RealInput y2 if plugPhase2 and
    mode == Buildings.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow2(unit="W") if plugPhase2 and
    mode == Buildings.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  Modelica.Blocks.Interfaces.RealInput y3 if plugPhase3 and
    mode == Buildings.Electrical.Types.Load.VariableZ_y_input
    "Fraction of the nominal power consumed"
  Modelica.Blocks.Interfaces.RealInput Pow3(unit="W") if plugPhase3 and
    mode == Buildings.Electrical.Types.Load.VariableZ_P_input "Power consumed"
  Buildings.Electrical.Utilities.VoltageControl vCTRL_1(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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"
  Buildings.Electrical.Utilities.VoltageControl vCTRL_2(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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"
  Buildings.Electrical.Utilities.VoltageControl vCTRL_3(
    redeclare package PhaseSystem = Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Buildings.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 == Buildings.Electrical.Types.LoadConnection.wye_to_delta)
    "Wye to delta load connection"
  Interfaces.WyeToWyeGround
    wyeToWyeGround if (loadConn == Buildings.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Wye to wye grounded connection"
protected
  Interfaces.Adapter3to3 adaDel
    if (loadConn == Buildings.Electrical.Types.LoadConnection.wye_to_delta)
    "Adapter"
  Interfaces.Adapter3to3 adaWye
    if (loadConn == Buildings.Electrical.Types.LoadConnection.wye_to_wyeg)
    "Adapter"
equation
  // Connections enabled when the input provided is y (between 0 and 1)
  if mode==Buildings.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==Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model Impedance
  "Partial model of a three-phase unbalanced impedance without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseImpedance;
  Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model Impedance_N
  "Partial model of a three-phase unbalanced impedance with neutral cable"
  extends
    Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model LoadCtrl
  "Partial model of a three-phase load with voltage controller without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseLoadCtrl;
    Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses;
partial model LoadCtrl_N
  "Partial model of a three-phase unbalanced load with voltage controller and neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.BaseClasses.BaseLoadCtrl;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_n terminal
    "Connector for three-phase unbalanced systems with neutral cable"
  Buildings.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 Buildings.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 Buildings.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 Buildings.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=Buildings.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=Buildings.Electrical.Types.CableMode.commercial,
    redeclare Buildings.Electrical.Transmission.LowVoltageCables.Cu10
      commercialCable,
    l=400,
    P_nominal=10000,
    V_nominal=480) "Transmission line to voltage controlled load"
  Resistive_N load(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Load"
  Lines.Line_N line(
    mode=Buildings.Electrical.Types.CableMode.commercial,
    redeclare Buildings.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 Buildings.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=Buildings.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Resistive load"
  Inductive loaRL(mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Inductive load"
  Capacitive loaRC(mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Capacitive load"
  Sensors.GeneralizedSensor sen "Power sensor"
  Sensors.GeneralizedSensor senSingleConn "Power sensor"
  Capacitive loaRC1(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Capacitive load"
  Inductive loaRL1(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    plugPhase2=false,
    plugPhase3=false,
    V_nominal=480) "Inductive load"
  Resistive loaR1(
    mode=Buildings.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 Buildings.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=Buildings.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=480) "Resistive load with neutral cable"
  Inductive_N loaRL_N(mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
      pf=0.9,
    V_nominal=480) "Inductive load with neutral cable"
  Capacitive_N loaRC_N(
    mode=Buildings.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 Buildings.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 Buildings.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, Buildings.Electrical.PhaseSystems.OnePhase.n](
                                          each final quantity="Power",
                                          each final unit="W") "Phase powers"
equation

  for i in 1:3 loop
    V[i]   = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal_n.phase[i].v);
    I[i]   = Buildings.Electrical.PhaseSystems.OnePhase.systemCurrent(terminal_n.phase[i].i);
    S[i,:] = Buildings.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 Buildings.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, Buildings.Electrical.PhaseSystems.OnePhase.n](
                                          each final quantity="Power",
                                          each final unit="W") "Phase powers"
equation

  for i in 1:4 loop
    V[i]   = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal_n.phase[i].v);
    I[i]   = Buildings.Electrical.PhaseSystems.OnePhase.systemCurrent(terminal_n.phase[i].i);
    S[i,:] = Buildings.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 Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeDelta
  "Model of a probe that measures voltage magnitude and angle (Delta configuration)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  Buildings.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] = Buildings.Electrical.PhaseSystems.OnePhase.phase(wyeToDelta.delta.phase[i].v);
      if perUnit then
        V[i] = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToDelta.delta.phase[i].v)/V_nominal;
      else
        V[i] = Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeWye
  "Model of a probe that measures voltage magnitude and angle (Wye configuration)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  Buildings.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] = Buildings.Electrical.PhaseSystems.OnePhase.phase(wyeToWyeGround.wyeg.phase[i].v);
      if perUnit then
        V[i] = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(wyeToWyeGround.wyeg.phase[i].v)/(V_nominal/sqrt(3));
      else
        V[i] = Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors;
model ProbeWye_N
  "Model of a probe that measures voltage magnitude and angle (Wye configuration) witn neutral cable connection"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_n
    term "Electrical connector"
equation

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

  for i in 1:3 loop
      theta[i] = Buildings.Electrical.PhaseSystems.OnePhase.phase(term.phase[i].v - term.phase[4].v);
      if perUnit then
        V[i] = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(term.phase[i].v - term.phase[4].v)/(V_nominal/sqrt(3));
      else
        V[i] = Buildings.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
Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye and

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

within Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors;
package BaseClasses "Package that contains base classes"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


Package with example models

within Buildings.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 Buildings.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=Buildings.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=Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model FixedVoltage "Fixed voltage source"
  extends
    Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model FixedVoltage_N "Fixed voltage source with neutral cable"
  extends
    Buildings.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 Buildings.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";
  Buildings.Electrical.AC.Interfaces.PowerOutput P[3]
    "Power consumed from grid if positive, or fed to grid if negative"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal_p terminal
    "Connector for three-phase unbalanced systems"

  Buildings.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 Buildings.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";
  Buildings.Electrical.AC.Interfaces.PowerOutput P[3]
    "Power consumed from grid if positive, or fed to grid if negative"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Terminal4_p terminal
    "Connector for three-phase unbalanced systems"
  Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced;
package Sources "Package with sources model for three-phase unbalanced AC systems"
  extends Modelica.Icons.SourcesPackage;
end Sources;


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

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model PVsimple "Simple PV source without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.UnbalancedPV(
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase1,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase2,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase3);
  Modelica.Blocks.Interfaces.RealInput G(unit="W/m2")
    "Total solar irradiation per unit area"
equation
  connect(G, G_int)
end PVsimple;


Simple PV source with orientation and without neutral cable. Simple PV model with orientation for three-phase unbalanced systems
without neutral cable connection.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model PVsimpleOriented
  "Simple PV source with orientation and without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.UnbalancedPV(
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase1,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase2,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase3);
  parameter Modelica.Units.SI.Angle til "Surface tilt"
  parameter Modelica.Units.SI.Angle azi "Surface Azimith"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil(
    final til=til,
    final azi=azi) "Diffuse irradiation on tilted surface"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    final til=til,
    final azi=azi) "Direct irradiation on tilted surface"
  Modelica.Blocks.Math.Add G "Total irradiation on tilted surface"
  BoundaryConditions.WeatherData.Bus weaBus "Bus with weather data"
equation
  connect(HDifTil.weaBus,weaBus)
  connect(weaBus,HDirTil. weaBus)
  connect(HDifTil.H, G.u2)
  connect(G.y, G_int)
  connect(HDirTil.H, G.u1)
end PVsimpleOriented;


Simple PV source with orientation and neutral cable. Simple PV model with orientation for three-phase unbalanced systems
with neutral cable connection.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model PVsimpleOriented_N "Simple PV source with orientation and neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.UnbalancedPV_N(
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase1,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase2,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase3);
  parameter Modelica.Units.SI.Angle til "Surface tilt"
  parameter Modelica.Units.SI.Angle azi "Surface Azimith"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil(
    final til=til,
    final azi=azi) "Diffuse irradiation on tilted surface"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    final til=til,
    final azi=azi) "Direct irradiation on tilted surface"
  Modelica.Blocks.Math.Add G "Total irradiation on tilted surface"
  BoundaryConditions.WeatherData.Bus weaBus "Bus with weather data"
equation
  connect(HDifTil.weaBus,weaBus)
  connect(weaBus,HDirTil. weaBus)
  connect(HDifTil.H, G.u2)
  connect(G.y, G_int)
  connect(HDirTil.H, G.u1)
end PVsimpleOriented_N;


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

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model PVsimple_N "Simple PV source with neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.UnbalancedPV_N(
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase1,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase2,
    redeclare Buildings.Electrical.AC.OnePhase.Sources.PVSimple pv_phase3);
  Modelica.Blocks.Interfaces.RealInput G(unit="W/m2")
    "Total solar irradiation per unit area"
equation
  connect(G, G_int)
end PVsimple_N;


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

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model WindTurbine "Simple wind turbine source without neutral cable"
  extends BaseClasses.UnbalancedWindTurbine(
  redeclare Buildings.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase1,
  redeclare Buildings.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase2,
  redeclare Buildings.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 Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources;
model WindTurbine_N "Simple wind turbine source with neutral cable"
  extends BaseClasses.UnbalancedWindTurbine_N(
  redeclare Buildings.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase1,
  redeclare Buildings.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase2,
  redeclare Buildings.Electrical.AC.OnePhase.Sources.WindTurbine wt_phase3);
end WindTurbine_N;


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

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
partial model BaseUnbalancedPV "Partial model for an unbalanced PV source"
  extends Buildings.Electrical.Interfaces.PartialPluggableUnbalanced;
  extends Buildings.Electrical.Interfaces.PartialPvBase;
  extends Buildings.Electrical.Interfaces.PartialAcDcParameters;
  parameter Modelica.Units.SI.Voltage V_nominal(min=0, start=480)
    "Nominal voltage (V_nominal >= 0)"
  parameter Real areaFraction[3](each min=0, each max=1.0) = ones(3)/3
    "Fraction of area occupied by the PVs of each phase";
  replaceable OnePhase.Sources.PVSimple pv_phase2(
    pf=pf,
    eta_DCAC=eta_DCAC,
    A=A*areaFraction[2],
    fAct=fAct,
    eta=eta,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase2 "PV phase 2"
  replaceable OnePhase.Sources.PVSimple pv_phase3(
    pf=pf,
    eta_DCAC=eta_DCAC,
    A=A*areaFraction[3],
    fAct=fAct,
    eta=eta,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase3 "PV phase 3"
  replaceable OnePhase.Sources.PVSimple pv_phase1(
    pf=pf,
    eta_DCAC=eta_DCAC,
    A=A*areaFraction[1],
    fAct=fAct,
    eta=eta,
    V_nominal=V_nominal/sqrt(3))
    if plugPhase1 "PV phase 1"
  Modelica.Blocks.Math.Add3 sumBlock "Sum of the generated power on each phase"
protected
  Modelica.Blocks.Interfaces.RealOutput G_int
    "Total solar irradiation per unit area"
equation
  assert(abs(sum(areaFraction)-1) < Modelica.Constants.eps,
  "Model that extends Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedPV,
  has an invalid value for the vector areaFraction[:]. The sum of the
  elements has to be equal to 1.0.",
  level=AssertionLevel.error);

  if plugPhase1 then
    connect(pv_phase1.G, G_int)
  end if;

  if plugPhase2 then
    connect(G_int, pv_phase2.G)
  end if;

  if plugPhase3 then
    connect(G_int, pv_phase3.G)
  end if;

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

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

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

  connect(sumBlock.y, P)
end BaseUnbalancedPV;


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

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
partial model BaseUnbalancedWindTurbine
  "Partial model for an unbalanced wind power source"
  extends Buildings.Electrical.Interfaces.PartialPluggableUnbalanced;
  extends Buildings.Electrical.Interfaces.PartialAcDcParameters;
  extends Buildings.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 Buildings.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 Buildings.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 Buildings.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 Buildings.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;


Base model for an unbalanced PV source without neutral cable. This model is a class extended by three-phase unbalanced
PV power sources without neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
model UnbalancedPV
  "Base model for an unbalanced PV source without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedPV;
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.PartialSource;
protected
  Interfaces.Adapter3to3 ada "Adapter"
equation

  if plugPhase1 then
  connect(pv_phase1.terminal, ada.terminals[1])
  end if;

  if plugPhase2 then
  connect(pv_phase2.terminal, ada.terminals[2])
  end if;

  if plugPhase3 then
   connect(pv_phase3.terminal, ada.terminals[3])
  end if;

  connect(ada.terminal, connection3to4.terminal4)
end UnbalancedPV;


Base model for an unbalanced PV source with neutral cable. This model is a class extended by three-phase unbalanced
PV power sources with neutral cable connection.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
model UnbalancedPV_N
  "Base model for an unbalanced PV source with neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedPV;
  Interfaces.Terminal4_p terminal
    "Connector for three-phase unbalanced systems with neutral cable"
  Interfaces.Connection3to4_p conn3to4 "Connection between 3 to 4 wire"
protected
  Interfaces.Adapter3to3 ada "Adapter"
equation

  if plugPhase1 then
    connect(pv_phase1.terminal, ada.terminals[1])
  end if;

  if plugPhase2 then
    connect(pv_phase2.terminal, ada.terminals[2])
  end if;

  if plugPhase3 then
    connect(pv_phase3.terminal, ada.terminals[3])
  end if;

  connect(conn3to4.terminal4, terminal)

  connect(ada.terminal, conn3to4.terminal3)
end UnbalancedPV_N;


Base model for an unbalanced wind power source without neutral cable. This model is a class extended by three-phase unbalanced
wind turbine power sources without neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
model UnbalancedWindTurbine
  "Base model for an unbalanced wind power source without neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedWindTurbine;
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.PartialSource;
protected
  Interfaces.Adapter3to3 ada "Adapter"
equation
  if plugPhase1 then
    connect(wt_phase1.terminal, ada.terminals[1])  end if;

  if plugPhase2 then
    connect(wt_phase2.terminal, ada.terminals[2])
   end if;

  if plugPhase3 then
   connect(wt_phase3.terminal, ada.terminals[3])
  end if;
  connect(ada.terminal, connection3to4.terminal4)
end UnbalancedWindTurbine;


Base model for an unbalanced wind power source with neutral cable. This model is a class extended by three-phase unbalanced
wind turbine power sources with neutral cable connection.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses;
model UnbalancedWindTurbine_N
  "Base model for an unbalanced wind power source with neutral cable"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.BaseClasses.BaseUnbalancedWindTurbine;
  Interfaces.Terminal4_p terminal
    "Connector for three-phase unbalanced systems with neutral cable"
  Interfaces.Connection3to4_p conn3to4 "Connection between 3 to 4 wire"
protected
  Interfaces.Adapter3to3 ada "Adapter"
equation

  if plugPhase1 then
    connect(wt_phase1.terminal, ada.terminals[1])
  end if;

  if plugPhase2 then
    connect(wt_phase2.terminal, ada.terminals[2])
  end if;

  if plugPhase3 then
    connect(wt_phase3.terminal, ada.terminals[3])
  end if;

  connect(conn3to4.terminal4, terminal)
  connect(ada.terminal, conn3to4.terminal3)
end UnbalancedWindTurbine_N;


This example illustrates how using a fixed voltage source. This example shows how to use a fixed voltage generator model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.Examples;
model FixedVoltageSource
  "This example illustrates how using a fixed voltage source"
  extends Modelica.Icons.Example;
  FixedVoltage                             grid(
    f=60,
    V=480,
    definiteReference=true,
    phiSou=0.17453292519943) "AC one phase electrical grid"
  Sensors.ProbeWye                  sen(V_nominal=480)
    "Probe that measures the voltage at the load"
  Loads.Inductive loa(P_nominal=-2000, V_nominal=480) "Inductive load"
  FixedVoltage_N grid_N(
    f=60,
    V=480,
    definiteReference=true,
    phiSou=0.17453292519943) "AC one phase electrical grid"
  Sensors.ProbeWye_N sen_N(V_nominal=480)
    "Probe that measures the voltage at the load"
  Loads.Inductive_N loa_N(P_nominal=-2000, V_nominal=480) "Inductive load"
equation
  connect(grid.terminal, loa.terminal)
  connect(grid.terminal, sen.term)
  connect(grid_N.terminal, loa_N.terminal)
  connect(grid_N.terminal, sen_N.term)
end FixedVoltageSource;


Package with example models

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


This example illustrates how to use PV panel models. This example shows how to use a simple PV model without orientation
as well as a PV model with orientation. The power produced by the PV is
partially consumed by the load, and the remaining part is fed into
the grid.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.Examples;
model PVPanels "This example illustrates how to use PV panel models"
  extends Modelica.Icons.Example;
  ThreePhasesUnbalanced.Loads.Inductive RL(
    mode=Types.Load.VariableZ_y_input,
    P_nominal=-2000,
    V_nominal=480,
    plugPhase3=false) "Load taht consumes the power generted by the PVs"
  ThreePhasesUnbalanced.Sources.Grid grid(f=60, V=480) "Electrical grid model"
  Modelica.Blocks.Sources.Constant  load(k=0.5) "Load consumption"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil(til=0.34906585039887,
      azi=-0.78539816339745)
                           "Diffuse irradiation on tilted surface"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(til=0.34906585039887,
      azi=-0.78539816339745)
                           "Direct irradiation on tilted surface"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
      computeWetBulbTemperature=false,
      filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
  Modelica.Blocks.Math.Add G "Total irradiation on tilted surface"
  PVsimple pvSimple(
    V_nominal=480,
    A=100,
    areaFraction={0.5,0.3,0.2}) "PV array simplified"
  PVsimpleOriented pvOriented(
    V_nominal=480,
    A=100,
    til=0.34906585039887,
    azi=-0.78539816339745,
    areaFraction={0.5,0.3,0.2}) "PV array oriented"
equation
  connect(weaDat.weaBus,HDifTil. weaBus)
  connect(weaDat.weaBus,HDirTil. weaBus)
  connect(HDifTil.H,G. u1)
  connect(HDirTil.H,G. u2)
  connect(G.y,pvSimple. G)
  connect(weaDat.weaBus, pvOriented.weaBus)
  connect(load.y, RL.y2)
  connect(load.y, RL.y1)
  connect(grid.terminal, RL.terminal)
  connect(grid.terminal, pvOriented.terminal)
  connect(grid.terminal, pvSimple.terminal)
end PVPanels;


This example illustrates how to use PV panel models with neutral cable. This example shows how to use a simple PV model with neutral cable connection and without orientation
as well as a PV model with orientation. The power produced by the PV is
partially consumed by the load, and the remaining part is fed into
the grid.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.Examples;
model PVPanels_N
  "This example illustrates how to use PV panel models with neutral cable"
  extends Modelica.Icons.Example;
  ThreePhasesUnbalanced.Loads.Inductive_N                                             RL(
    mode=Types.Load.VariableZ_y_input,
    P_nominal=-2000,
    V_nominal=480,
    plugPhase3=false) "Load taht consumes the power generted by the PVs"
  ThreePhasesUnbalanced.Sources.Grid_N grid(f=60, V=480)
    "Electrical grid model"
  Modelica.Blocks.Sources.Constant  load(k=0.5) "Load consumption"
  BoundaryConditions.SolarIrradiation.DiffusePerez HDifTil(
    til=0.34906585039887,
    azi=-0.78539816339745) "Diffuse irradiation on tilted surface"
  BoundaryConditions.SolarIrradiation.DirectTiltedSurface HDirTil(
    til=0.34906585039887,
    azi=-0.78539816339745) "Direct irradiation on tilted surface"
  BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
      computeWetBulbTemperature=false,
      filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
  Modelica.Blocks.Math.Add G "Total irradiation on tilted surface"
  PVsimple_N                               pvSimple(      V_nominal=480,
    A=100,
    plugPhase2=false,
    areaFraction={0.4,0.0,0.6}) "PV array simplified"
  PVsimpleOriented_N                               pvOriented(
    V_nominal=480,
    A=100,
    plugPhase2=false,
    til=0.34906585039887,
    azi=-0.78539816339745,
    areaFraction={0.4,0.0,0.6}) "PV array oriented"
equation
  connect(weaDat.weaBus,HDifTil. weaBus)
  connect(weaDat.weaBus,HDirTil. weaBus)
  connect(HDifTil.H,G. u1)
  connect(HDirTil.H,G. u2)
  connect(G.y,pvSimple. G)
  connect(weaDat.weaBus, pvOriented.weaBus)
  connect(load.y, RL.y2)
  connect(load.y, RL.y1)
  connect(grid.terminal, RL.terminal)
  connect(grid.terminal, pvOriented.terminal)
  connect(grid.terminal, pvSimple.terminal)
end PVPanels_N;


Example for the WindTurbine AC model. This model illustrates the use of the wind turbine model,
which is connected to a AC voltage source and a resistive load.
This voltage source can represent the grid to which the
circuit is connected.
Wind data for San Francisco, CA, are used.
The turbine cut-in wind speed is <i>3.5</i> m/s,
and hence it is off in the first day when the wind speed is low.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.Examples;
model WindTurbine "Example for the WindTurbine AC model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.WindTurbine tur(
    table=[3.5, 0;
           5.5,   100;
           12, 900;
           14, 1000;
           25, 1000], h=10,
    scale=10,
    V_nominal=480,
    scaleFraction={0.5,0.25,0.25}) "Wind turbine"
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
      computeWetBulbTemperature=false,
      filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus "Weather bus";
  Loads.Resistive                           res(P_nominal=-500, V_nominal=480)
    "Resistive line"
  Grid                                                     sou(f=60, V=480)
    "Voltage source"
  Sensors.GeneralizedSensor                         sen "Generalized sensor"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.Line line(
    l=200,
    P_nominal=5000,
    V_nominal=480)
equation
  connect(weaDat.weaBus,weaBus)
  connect(weaBus.winSpe,tur. vWin)
  connect(sou.terminal, res.terminal)
  connect(sen.terminal_p, tur.terminal)
  connect(sou.terminal, line.terminal_n)
  connect(line.terminal_p, sen.terminal_n)
end WindTurbine;


Example for the WindTurbine AC model with neutral cable. This model illustrates the use of the wind turbine model with neutral cable,
which is connected to a AC voltage source and a resistive load.
This voltage source can represent the grid to which the
circuit is connected.
Wind data for San Francisco, CA, are used.
The turbine cut-in wind speed is <i>3.5</i> m/s,
and hence it is off in the first day when the wind speed is low.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.Examples;
model WindTurbine_N "Example for the WindTurbine AC model with neutral cable"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.WindTurbine_N tur(
    table=[3.5, 0;
           5.5,   100;
           12, 900;
           14, 1000;
           25, 1000], h=10,
    scale=10,
    V_nominal=480,
    plugPhase2=false,
    scaleFraction={0.4,0.0,0.6}) "Wind turbine"
  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weaDat(
      computeWetBulbTemperature=false,
      filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
    "Weather data"
  Buildings.BoundaryConditions.WeatherData.Bus weaBus "Weather bus";
  Loads.Resistive_N                          res(P_nominal=-500, V_nominal=480)
    "Resistive line"
  Grid_N                                                     sou(f=60, V=480)
    "Voltage source"
  Sensors.GeneralizedSensor_N                         sen "Generalized sensor"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.Line_N line(
    l=200,
    P_nominal=5000,
    V_nominal=480)
equation
  connect(weaDat.weaBus,weaBus)
  connect(weaBus.winSpe,tur. vWin)
  connect(tur.terminal, sen.terminal_p)
  connect(sen.terminal_n, line.terminal_p)
  connect(line.terminal_n, sou.terminal)
  connect(res.terminal, sou.terminal)
end WindTurbine_N;


within Buildings.Electrical.AC.ThreePhasesUnbalanced;
package Validation "Package with validation examples and tests for the AC three-phase unbalanced models"
  extends Modelica.Icons.ExamplesPackage;
end Validation;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation;
package IEEETests "This package contains models of the IEEE tests for feeders"
extends Modelica.Icons.ExamplesPackage;
end IEEETests;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests;
package Test4NodesFeeder "This package contains models for the IEEE 4 nodes test feeder"
extends Modelica.Icons.ExamplesPackage;
end Test4NodesFeeder;


IEEE 4 node test feeder model with balanced load and D - D connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepDown;
model DD
  "IEEE 4 node test feeder model with balanced load and D - D connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={12339,12349,12321},
    final V3_ref={3911,3914,3905},
    final V4_ref={3442,3497,3384},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.7,-90.4,149.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{26.5,-93.6,146.4},
    final Theta4_ref=Modelica.Constants.pi/180.0*{22.3,-99.4,140.7},
    loadRL(use_pf_in=false, loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DD;


IEEE 4 node test feeder model with balanced load and D - Y connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepDown;
model DY
  "IEEE 4 node test feeder model with balanced load and D - Y connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={12340,12349,12318},
    final V3_ref={2249,2263,2259},
    final V4_ref={1920,2054,1986},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.7,-90.4,149.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-33.7,-153.4,86.4},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-39.1,-158.3,80.9},
    loadRL(use_pf_in=false,
    load1(v(start={1500, 1200}))));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownDY
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DY;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder;
package BalancedStepDown "Package that contains the examples for balanced loads and step down transformer"
  extends Modelica.Icons.ExamplesPackage;
end BalancedStepDown;


IEEE 4 node test feeder model with balanced load and Y - D connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepDown;
model YD
  "IEEE 4 node test feeder model with balanced load and Y - D connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={7113,7132,7123},
    final V3_ref={3906,3915,3909},
    final V4_ref={3437,3497,3388},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.3,-120.3,119.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-3.5,-123.6,116.3},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-7.8,-129.3,110.6},
    loadRL(use_pf_in=false, loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownYD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase,
    conv1(
      terminal_p(i(start={-477, 327})),
      V1(start={7000, -400})))
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YD;


IEEE 4 node test feeder model with balanced load and Y - Y connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepDown;
model YY
  "IEEE 4 node test feeder model with balanced load and Y - Y connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={7107,7140,7121},
    final V3_ref={2247,2269,2256},
    final V4_ref={1918,2061,1981},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.3,-120.3,119.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-3.7,-123.5,116.4},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-9.1,-128.3,110.9},
    loadRL(use_pf_in=false));

  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformer
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YY;


IEEE 4 node test feeder model with balanced load and D - D connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepUp;
model DD
  "IEEE 4 node test feeder model with balanced load and D - D connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={12361,12372,12348},
    final V3_ref={23723,23746,23698},
    final V4_ref={23657,23688,23625},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.7,-90.4,149.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{26.7,-93.4,146.6},
    final Theta4_ref=Modelica.Constants.pi/180.0*{26.6,-93.6,146.5},
    loadRL(use_pf_in=false, loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DD;


IEEE 4 node test feeder model with balanced load and D - Y connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepUp;
model DY
  "IEEE 4 node test feeder model with balanced load and D - Y connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={12361,12372,12348},
    final V3_ref={13697,13710,13681},
    final V4_ref={13653,13678,13644},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.7,-90.4,149.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{26.7,-93.4,146.6},
    final Theta4_ref=Modelica.Constants.pi/180.0*{26.6,-93.5,146.5},
    loadRL(use_pf_in=false));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpDY
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase,
    conv1(V1(start={11E3, 6E3})),
    conv2(V1(start={-700, -11E3})))
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DY;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder;
package BalancedStepUp "Package that contains the examples for balanced loads and step up transformer"
  extends Modelica.Icons.ExamplesPackage;
end BalancedStepUp;


IEEE 4 node test feeder model with balanced load and Y - D connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepUp;
model YD
  "IEEE 4 node test feeder model with balanced load and Y - D connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={7128,7145,7137},
    final V3_ref={23746,23722,23698},
    final V4_ref={23680,23663,23625},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.3,-120.3,119.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{56.7,-63.4,176.7},
    final Theta4_ref=Modelica.Constants.pi/180.0*{56.6,-63.6,176.5},
    loadRL(use_pf_in=false,
           loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta,
           load1(v(start = {13000, 20000}))));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpYD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YD;


IEEE 4 node test feeder model with balanced load and Y - Y connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BalancedStepUp;
model YY
  "IEEE 4 node test feeder model with balanced load and Y - Y connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={7126,7145,7137},
    final V3_ref={13675,13715,13698},
    final V4_ref={13631,13682,13661},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.3,-120.4,119.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-3.3,-123.4,116.6},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-3.5,-123.5,116.5},
    loadRL(use_pf_in=false));
  Modelica.Blocks.Sources.Constant load(k=-1800e3)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformer
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load.y, loadRL.Pow1)
  connect(load.y, loadRL.Pow2)
  connect(load.y, loadRL.Pow3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, source.terminal)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YY;


Base model of the IEEE 4 nodes test feeder. This is a partial model that is extended by all the other validation test cases.
This model defined replaceable probes and transformer so they can be
easily changed when implementing the different tests.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses;
partial model IEEE4 "Base model of the IEEE 4 nodes test feeder"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Voltage VLL_side1=12.47e3
    "Voltage line to line side 1";
  parameter Modelica.Units.SI.Voltage VLL_side2=4.16e3
    "Voltage line to line side 2";

  parameter Modelica.Units.SI.ApparentPower VARbase=6000e3
    "Base VA power of the transformer";

  parameter Boolean line1_use_Z_y = true
    "Choose between Zy or Zd impedance matrix for line 1";
  parameter Boolean line2_use_Z_y = true
    "Choose between Zy or Zd impedance matrix for line 2";

  parameter Modelica.Units.SI.Voltage V2_ref[3]={7107,7140,7121}
    "Reference RMS voltage node 2 - IEEE results";
  parameter Modelica.Units.SI.Voltage V3_ref[3]={2247,2269,2256}
    "Reference RMS voltage node 3 - IEEE results";
  parameter Modelica.Units.SI.Voltage V4_ref[3]={1918,2061,1981}
    "Reference RMS voltage node 4 - IEEE results";
  parameter Modelica.Units.SI.Angle Theta2_ref[3](each displayUnit="deg") = {-0.3,
    -120.3,119.6} "Reference voltage phase angle node 2 - IEEE results";
  parameter Modelica.Units.SI.Angle Theta3_ref[3](each displayUnit="deg") = {-3.7,
    -123.5,116.4} "Reference voltage phase angle node 3 - IEEE results";
  parameter Modelica.Units.SI.Angle Theta4_ref[3](each displayUnit="deg") = {-9.1,
    -128.3,110.9} "Reference voltage phase angle node 4 - IEEE results";
  Modelica.Units.SI.Voltage err_V2[3]=node2.V - V2_ref
    "Error on voltage at node 2";
  Modelica.Units.SI.Voltage err_V3[3]=node3.V - V3_ref
    "Error on voltage at node 3";
  Modelica.Units.SI.Voltage err_V4[3]=node4.V - V4_ref
    "Error on voltage at node 4";
  Modelica.Units.SI.Angle err_Theta2[3](each displayUnit="deg") = node2.theta
     - Theta2_ref "Error on voltage at node 2";
  Modelica.Units.SI.Angle err_Theta3[3](each displayUnit="deg") = node3.theta
     - Theta3_ref "Error on voltage at node 3";
  Modelica.Units.SI.Angle err_Theta4[3](each displayUnit="deg") = node4.theta
     - Theta4_ref "Error on voltage at node 4";
  Real err_V2_percent[3] = 100*{err_V2[i]/V2_ref[i] for i in 1:3}
    "Error in RMS voltage at node 2 -- percent";
  Real err_V3_percent[3] = 100*{err_V3[i]/V3_ref[i] for i in 1:3}
    "Error in RMS voltage at node 3 -- percent";
  Real err_V4_percent[3] = 100*{err_V4[i]/V4_ref[i] for i in 1:3}
    "Error in RMS voltage at node 4 -- percent";
  Real err_Theta2_percent[3] = 100*{err_Theta2[i]/Theta2_ref[i] for i in 1:3}
    "Error in voltage phase angle at node 2 -- percent";
  Real err_Theta3_percent[3] = 100*{err_Theta3[i]/Theta3_ref[i] for i in 1:3}
    "Error in voltage phase angle at node 3 -- percent";
  Real err_Theta4_percent[3] = 100*{err_Theta4[i]/Theta4_ref[i] for i in 1:3}
    "Error in voltage phase angle at node 4 -- percent";
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.FixedVoltage source(
    f=60,
    V=VLL_side1) "Voltage source"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.TwoPortMatrixRL line1(
    Z11=L1*(if line1_use_Z_y then Z11_y else Z11_d),
    Z12=L1*(if line1_use_Z_y then Z12_y else Z12_d),
    Z13=L1*(if line1_use_Z_y then Z13_y else Z13_d),
    Z22=L1*(if line1_use_Z_y then Z22_y else Z22_d),
    Z23=L1*(if line1_use_Z_y then Z23_y else Z23_d),
    Z33=L1*(if line1_use_Z_y then Z33_y else Z33_d),
    V_nominal=VLL_side1) "Line at primary side"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.TwoPortMatrixRL line2(
    Z11=L2*(if line2_use_Z_y then Z11_y else Z11_d),
    Z12=L2*(if line2_use_Z_y then Z12_y else Z12_d),
    Z13=L2*(if line2_use_Z_y then Z13_y else Z13_d),
    Z22=L2*(if line2_use_Z_y then Z22_y else Z22_d),
    Z23=L2*(if line2_use_Z_y then Z23_y else Z23_d),
    Z33=L2*(if line2_use_Z_y then Z33_y else Z33_d),
    V_nominal=VLL_side2) "Line at secondary side"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Loads.Inductive loadRL(
    pf=0.9,
    V_nominal=VLL_side2,
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    use_pf_in=true) "Load"
  replaceable
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe
    node1(perUnit=false, V_nominal=VLL_side1) "Probe at source"
  replaceable
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe
    node2(perUnit=false, V_nominal=VLL_side1)
    "Probe at the primary side of the transformer"
  replaceable
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe
    node3(perUnit=false, V_nominal=VLL_side2)
    "Probe at the secondary side of the transformer"
  replaceable
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.BaseClasses.GeneralizedProbe
    node4(perUnit=false, V_nominal=VLL_side2) "Probe at the load"

protected
  parameter Real L1 = 2000*(1.0/5280.0) "Length line 1 in miles";
  parameter Real L2 = 2500*(1.0/5280.0) "Length line 2 in miles";

  parameter Modelica.Units.SI.Impedance Z11_d[2]={0.4013,1.4133}
    "Element [1,1] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z12_d[2]={0.0953,0.8515}
    "Element [1,2] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z13_d[2]={0.0953,0.7266}
    "Element [1,3] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z22_d[2]={0.4013,1.4133}
    "Element [2,2] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z23_d[2]={0.0953,0.7802}
    "Element [2,3] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z33_d[2]={0.4013,1.4133}
    "Element [3,3] of impedance matrix";

  parameter Modelica.Units.SI.Impedance Z11_y[2]={0.4576,1.078}
    "Element [1,1] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z12_y[2]={0.1559,0.5017}
    "Element [1,2] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z13_y[2]={0.1535,0.3849}
    "Element [1,3] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z22_y[2]={0.4666,1.0482}
    "Element [2,2] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z23_y[2]={0.158,0.4236}
    "Element [2,3] of impedance matrix";
  parameter Modelica.Units.SI.Impedance Z33_y[2]={0.4615,1.0651}
    "Element [3,3] of impedance matrix";
equation
  connect(source.terminal, line1.terminal_n)
  connect(line2.terminal_p, loadRL.terminal)
end IEEE4;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder;
package BaseClasses "This package contains the base classes used by the IEEE 4 nodes test feeder"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


IEEE 4 node test feeder model with unbalanced load and D - D connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepDown;
model DD
  "IEEE 4 node test feeder model with unbalanced load and D - D connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={12341,12370,12302},
    final V3_ref={3902,3972,3871},
    final V4_ref={3431,3647,3294},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.8,-90.5,149.5},
    final Theta3_ref=Modelica.Constants.pi/180.0*{27.2,-93.9,145.7},
    final Theta4_ref=Modelica.Constants.pi/180.0*{24.3,-100.4,138.6},
    loadRL(loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta,
        use_pf_in=true));
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
equation
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(load1.y, loadRL.Pow1)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DD;


IEEE 4 node test feeder model with unbalanced load and D - Y connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepDown;
model DY
  "IEEE 4 node test feeder model with unbalanced load and D - Y connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={12350,12314,12333},
    final V3_ref={2290,2261,2214},
    final V4_ref={2157,1936,1849},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.6,-90.4,149.8},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-32.4,-153.8,85.2},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-34.2,-157.0,73.4},
    loadRL(use_pf_in=true),
    line2(terminal_p(phase(v(each start=-1)))));
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownDY
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
equation
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(load1.y, loadRL.Pow1)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DY;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder;
package UnbalancedStepDown "Package that contains the examples for unbalanced loads and step down transformer"
  extends Modelica.Icons.ExamplesPackage;
end UnbalancedStepDown;


IEEE 4 node test feeder model with unbalanced load and Y - D connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepDown;
model YD
  "IEEE 4 node test feeder model with unbalanced load and Y - D connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={7113,7144,7111},
    final V3_ref={3896,3972,3875},
    final V4_ref={3425,3646,3298},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.2,-120.4,119.5},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-2.8,-123.8,115.7},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-5.8,-130.3,108.6},
    loadRL(loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta,
           use_pf_in=true,
           load1(v(each start = 3000))),
    line1(i1(each start=200)));
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownYD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
equation
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(load1.y, loadRL.Pow1)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YD;


IEEE 4 node test feeder model with unbalanced load and Y - Y connection (step down). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepDown;
model YY
  "IEEE 4 node test feeder model with unbalanced load and Y - Y connection (step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=true,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=4.16e3,
    final VARbase=6000e3,
    final V2_ref={7164,7110,7082},
    final V3_ref={2305,2255,2203},
    final V4_ref={2175,1930,1833},
    final Theta2_ref=Modelica.Constants.pi/180.0*{-0.1,-120.2,119.3},
    final Theta3_ref=Modelica.Constants.pi/180.0*{-2.3,-123.6,114.8},
    final Theta4_ref=Modelica.Constants.pi/180.0*{-4.1,-126.8,102.8},
    loadRL(use_pf_in=true),
    line1(i1(start={180, -130}),
          i2(start={-300, -160}),
          i3(start={40, 450})),
    line2(i2(start={-900, -480}),
          i3(start={130, 1400})));

  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformer
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
equation
  connect(load1.y, loadRL.Pow1)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end YY;


IEEE 4 node test feeder model with unbalanced load and D - D connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepUp;
model DD
  "IEEE 4 node test feeder model with unbalanced load and D - D connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=false,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={12362,12392,12334},
    final V3_ref={23675,24060,23573},
    final V4_ref={23610,24015,23492},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.8,-90.4,149.5},
    final Theta3_ref=Modelica.Constants.pi/180.0*{27.2,-93.6,146.0},
    final Theta4_ref=Modelica.Constants.pi/180.0*{27.2,-93.7,145.9},
    loadRL(loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_delta,
        use_pf_in=true));
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase)
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
equation
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(load1.y, loadRL.Pow1)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(node1.term, source.terminal)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DD;


IEEE 4 node test feeder model with unbalanced load and D - Y connection (step up). IEEE 4 nodes validation test case with the following characteristics

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.UnbalancedStepUp;
model DY
  "IEEE 4 node test feeder model with unbalanced load and D - Y connection (step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder.BaseClasses.IEEE4(
    final line1_use_Z_y=false,
    final line2_use_Z_y=true,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node1,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta
      node2,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node3,
    redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye
      node4,
    final VLL_side1=12.47e3,
    final VLL_side2=24.9e3,
    final VARbase=6000e3,
    final V2_ref={12364,12391,12333},
    final V3_ref={13792,13733,13641},
    final V4_ref={13768,13684,13600},
    final Theta2_ref=Modelica.Constants.pi/180.0*{29.8,-90.5,149.6},
    final Theta3_ref=Modelica.Constants.pi/180.0*{27.7,-93.5,145.4},
    final Theta4_ref=Modelica.Constants.pi/180.0*{27.7,-93.6,145.2},
    loadRL(use_pf_in=true));
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpDY
    transformer(
    VHigh=VLL_side1,
    VLow=VLL_side2,
    XoverR=6,
    Zperc=sqrt(0.01^2 + 0.06^2),
    VABase=VARbase,
    conv1(V1(start={10E3, 5.5E3})))
  Modelica.Blocks.Sources.Constant load3(k=-2375e3)
  Modelica.Blocks.Sources.Constant load2(k=-1800e3)
  Modelica.Blocks.Sources.Constant pf1(k=0.85)
  Modelica.Blocks.Sources.Constant pf2(k=0.9)
  Modelica.Blocks.Sources.Constant pf3(k=0.95)
  Modelica.Blocks.Sources.Constant load1(k=-1275e3)
equation
  connect(line1.terminal_p, transformer.terminal_n)
  connect(transformer.terminal_p, line2.terminal_n)
  connect(pf1.y, loadRL.pf_in_1)
  connect(pf2.y, loadRL.pf_in_2)
  connect(pf3.y, loadRL.pf_in_3)
  connect(load2.y, loadRL.Pow2)
  connect(load3.y, loadRL.Pow3)
  connect(load1.y, loadRL.Pow1)
  connect(node1.term, line1.terminal_n)
  connect(node2.term, transformer.terminal_n)
  connect(node3.term, line2.terminal_n)
  connect(node4.term, loadRL.terminal)
end DY;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Validation.IEEETests.Test4NodesFeeder;
package UnbalancedStepUp "Package that contains the examples for unbalanced loads and step up transformer"
  extends Modelica.Icons.ExamplesPackage;
end UnbalancedStepUp;