This example illustrates how to use the AC/AC simplified transformer model. This example illustrates the use of the AC/AC transformer model.
The example shows three different configurations:

within Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.Examples;
model ACACTransformer
  "This example illustrates how to use the AC/AC simplified transformer model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformer tra_load(
    Zperc=0.03,
    VABase=4000,
    XoverR=8,
    VHigh=480,
    VLow=120) "Transformer with load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive load(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    pf=0.8,
    V_nominal=120) "Load model"
  Modelica.Blocks.Sources.Ramp ramp(
    duration=0.5,
    startTime=0.3,
    offset=0,
    height=-4000*0.8) "Load power consumption profile"
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformer tra_cc(
    XoverR=8,
    Zperc=0.03,
    VABase=4000,
    VHigh=480,
    VLow=120) "Transformer with short circuit"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Impedance shortCircuit(R=1e-8)
    "Short circuit"
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformer tra_void(
    XoverR=8,
    Zperc=0.03,
    VABase=4000,
    VHigh=480,
    VLow=120) "Transformer with secondary not connected"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou1(
    definiteReference=true,
    f=60,
    V=480) "Voltage source for open and short circuit tests"
equation
  connect(sou.terminal, tra_load.terminal_n)
  connect(tra_load.terminal_p, load.terminal)
  connect(ramp.y, load.Pow)
  connect(tra_cc.terminal_p, shortCircuit.terminal)
  connect(sou1.terminal, tra_cc.terminal_n)
  connect(sou1.terminal, tra_void.terminal_n)
end ACACTransformer;


This example illustrates how to use the AC/AC transformer model. This example illustrates the use of the AC/AC transformer model
that includes losses at the primary and secondary side and magnetization
effects.
The example shows three different configurations:

within Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.Examples;
model ACACTransformerFull
  "This example illustrates how to use the AC/AC transformer model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformerFull tra_load(
    R1=0.0001,
    L1=0.0001,
    R2=0.0001,
    L2=0.0001,
    VABase=4000,
    magEffects=true,
    Rm=10,
    Lm=10,
    VHigh=480,
    VLow=120,
    f=60) "Transformer with load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive load(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    pf=0.8,
    V_nominal=120) "Load"
  Modelica.Blocks.Sources.Ramp ramp(
    duration=0.5,
    startTime=0.3,
    offset=0,
    height=-4000*0.8) "Load power consumption profile"
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformerFull tra_cc(
    VABase=4000,
    R1=0.01,
    L1=0.01,
    R2=0.01,
    L2=0.01,
    magEffects=false,
    Rm=100,
    Lm=100,
    VHigh=480,
    VLow=120,
    f=60) "Transformer with short circuit connection"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Impedance shortCircuit(R=1e-8)
    "Short circuit"
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACACTransformerFull tra_void(
    VABase=4000,
    R1=0.01,
    L1=0.01,
    R2=0.01,
    L2=0.01,
    magEffects=false,
    Rm=100,
    Lm=100,
    VHigh=480,
    VLow=120,
    f=60) "Transformer with open connection"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou1(
    definiteReference=true,
    f=60,
    V=480) "Voltage source for short circuit and open tests"
equation
  connect(sou.terminal, tra_load.terminal_n)
  connect(tra_load.terminal_p, load.terminal)
  connect(ramp.y, load.Pow)
  connect(tra_cc.terminal_p, shortCircuit.terminal)
  connect(sou1.terminal, tra_cc.terminal_n)
  connect(sou1.terminal, tra_void.terminal_n)
end ACACTransformerFull;


This example illustrates how to use the AC/DC converter model. This example illustrates the use of a model that converts AC voltage to DC voltage.
The transformer model assumes a linear loss when transmitting the power.

within Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.Examples;
model ACDCConverter
  "This example illustrates how to use the AC/DC converter model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.DC.Loads.Resistor res(
    R=1,
    V_nominal=120,
    i(each start=0))
    "Resistive load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Conversion.ACDCConverter conversion(
    eta=0.9,
    ground_AC=false,
    ground_DC=true,
    conversionFactor=120/480) "AC/DC transformer"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou(
    definiteReference=true,
    f=60,
    V=480) "Voltage source"
  Buildings.Electrical.DC.Loads.Conductor load(
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input,
    V_nominal=120) "Variable resistive load"
  Modelica.Blocks.Sources.Ramp pow(
    duration=0.5,
    startTime=0.2,
    offset=-200,
    height=5200) "Variable load profile"
equation
  connect(sou.terminal, conversion.terminal_n)
  connect(conversion.terminal_p, res.terminal)
  connect(conversion.terminal_p, load.terminal)
  connect(pow.y, load.Pow)
end ACDCConverter;


Package with example models

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


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Interfaces "Package interfaces for three-phase balanced AC systems"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


within Buildings.Electrical.AC.ThreePhasesBalanced.Interfaces;
connector Terminal_n "AC three-phase balanced terminal ('negative')"
  extends Buildings.Electrical.Interfaces.Terminal(
    redeclare replaceable package PhaseSystem = PhaseSystems.OnePhase);
end Terminal_n;


within Buildings.Electrical.AC.ThreePhasesBalanced.Interfaces;
connector Terminal_p "AC three-phase balanced terminal ('positive')"
  extends Buildings.Electrical.Interfaces.Terminal(
    redeclare replaceable package PhaseSystem = PhaseSystems.OnePhase);
end Terminal_p;


Model of an electrical line. This model represents a cable for three-phase balanced AC systems. The model is based on

Buildings.Electrical.AC.ThreePhasesBalanced.Lines.TwoPortRLC
and provides functionalities to parametrize the values of R, L and C either
using commercial cables or using default values.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model Line "Model of an electrical line"
  extends Buildings.Electrical.AC.OnePhase.Lines.Line(
    redeclare Interfaces.Terminal_n terminal_n,
    redeclare Interfaces.Terminal_p terminal_p,
    V_nominal(start=480),
    redeclare TwoPortRLC line(
     R=R,
     L=L,
     C=C,
     V_nominal=V_nominal));
end Line;


Three phases balanced AC network. This model represents a generalized electrical AC three-phase balanced network.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model Network "Three phases balanced AC network"
  extends Buildings.Electrical.Transmission.BaseClasses.PartialNetwork(
    V_nominal(start = 480),
    redeclare Interfaces.Terminal_p terminal,
    redeclare replaceable Transmission.Grids.TestGrid2Nodes grid,
    redeclare Lines.Line lines(
    redeclare replaceable
        Buildings.Electrical.Transmission.LowVoltageCables.Generic commercialCable=grid.cables));
  Modelica.Units.SI.Voltage VAbs[grid.nNodes] "RMS voltage of the grid nodes";
equation
  for i in 1:grid.nLinks loop
    connect(lines[i].terminal_p, terminal[grid.fromTo[i,1]]);
    connect(lines[i].terminal_n, terminal[grid.fromTo[i,2]]);
  end for;

  for i in 1:grid.nNodes loop
    VAbs[i] = Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal[i].v);
  end for;
end Network;


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Lines "Package with line models for three-phase balanced AC systems"
  extends Modelica.Icons.Package;
end Lines;


Model of an inductance with two electrical ports. Inductance that connects two AC three-phase
balanced interfaces. This model can be used to represent a
cable in a three-phase balanced AC system.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model TwoPortInductance "Model of an inductance with two electrical ports"
  extends Buildings.Electrical.AC.OnePhase.Lines.TwoPortInductance(
    redeclare Interfaces.Terminal_n terminal_n,
    redeclare Interfaces.Terminal_p terminal_p);
end TwoPortInductance;


Model of a resistance with two electrical ports. Resistance that connects two AC three-phase
balanced interfaces. This model can be used to represent a
cable in a three-phase balanced AC system.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model TwoPortResistance "Model of a resistance with two electrical ports"
  extends Buildings.Electrical.AC.OnePhase.Lines.TwoPortResistance(
    redeclare Interfaces.Terminal_n terminal_n,
    redeclare Interfaces.Terminal_p terminal_p);
end TwoPortResistance;


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

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model TwoPortRL
  "Model of a resistive-inductive element with two electrical ports"
  extends Buildings.Electrical.AC.OnePhase.Lines.TwoPortRL(
    redeclare Interfaces.Terminal_n terminal_n,
    redeclare Interfaces.Terminal_p terminal_p);
end TwoPortRL;


Model of a RLC element with two electrical ports. RLC impedance that connects two AC three-phase
balanced interfaces. This model can be used to represent a
cable in a three-phase balanced AC system.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines;
model TwoPortRLC "Model of a RLC element with two electrical ports"
  extends Buildings.Electrical.AC.OnePhase.Lines.TwoPortRLC(
    redeclare Interfaces.Terminal_n terminal_n,
    redeclare Interfaces.Terminal_p terminal_p);
end TwoPortRLC;


Test model for single phase lines that use commercial cables. This example demonstrates how to use a line model to connect
a source to a load that uses commercial cables.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Examples;
model ACLine "Test model for single phase lines that use commercial cables"
  extends Modelica.Icons.Example;
  ThreePhasesBalanced.Sources.FixedVoltage E(definiteReference=true,
    f=60,
    V=480) "Voltage source"
  ThreePhasesBalanced.Loads.Impedance R1(R=10) "Resistive load 1"
  ThreePhasesBalanced.Lines.Line line_1(
    P_nominal=5000,
    l=2000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    V_nominal=480) "Resistive line that connects to load 1"
  ThreePhasesBalanced.Lines.Line line_2a(
    P_nominal=5000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    l=1000,
    V_nominal=480) "Resistive line that connects to load 2"
  ThreePhasesBalanced.Loads.Impedance R2(R=10) "Resistive load 2"
  ThreePhasesBalanced.Lines.Line line_2b(
    P_nominal=5000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    l=1000,
    V_nominal=480) "Resistive line that connects to load 2"
  ThreePhasesBalanced.Lines.Line line_3a(
    P_nominal=5000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    l=4000,
    V_nominal=480) "Resistive line that connects to load 3"
  ThreePhasesBalanced.Lines.Line line_3b(
    P_nominal=5000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    l=4000,
    V_nominal=480) "Resistive line that connects to load 3"
  ThreePhasesBalanced.Loads.Impedance R3(R=10) "Resistive load 3"
  ThreePhasesBalanced.Lines.Line line_sc(
    P_nominal=5000,
    l=2000,
    mode=Types.CableMode.commercial,
    commercialCable=Transmission.LowVoltageCables.Cu50(),
    V_nominal=480) "Line that connects the source and the short circuit"
  ThreePhasesBalanced.Loads.Impedance load_sc(R=0) "Short circuit"
equation
  connect(line_1.terminal_p, R1.terminal)
  connect(E.terminal, line_1.terminal_n)
  connect(E.terminal, line_2a.terminal_n)
  connect(line_2a.terminal_p, line_2b.terminal_n)
  connect(line_2b.terminal_p, R2.terminal)
  connect(line_3a.terminal_p, R3.terminal)
  connect(line_3b.terminal_p, R3.terminal)
  connect(E.terminal, line_3a.terminal_n)
  connect(E.terminal, line_3b.terminal_n)
  connect(line_sc.terminal_p, load_sc.terminal)
  connect(E.terminal, line_sc.terminal_n)
end ACLine;


Test model for a single phase line that uses medium voltage commercial cable information . This example demonstrates how to use a line model to connect
a source to a load that uses medium voltage commercial cable information.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Examples;
model ACLineMedium
  "Test model for a single phase line that uses medium voltage commercial cable information "
  extends Modelica.Icons.Example;
  ThreePhasesBalanced.Sources.FixedVoltage E(definiteReference=true, V=15000,
    f=60) "Voltage source"
  ThreePhasesBalanced.Loads.Impedance R1(R=10) "Resistive load 1"
  ThreePhasesBalanced.Lines.Line line_1(
    P_nominal=5000,
    l=2000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Resistive line that connects to load 1"
  ThreePhasesBalanced.Lines.Line line_2a(
    P_nominal=5000,
    l=1000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Resistive line that connects to load 2"
  ThreePhasesBalanced.Loads.Impedance R2(R=10) "Resistive load 2"
  ThreePhasesBalanced.Lines.Line line_2b(
    P_nominal=5000,
    l=1000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Resistive line that connects to load 2"
  ThreePhasesBalanced.Lines.Line line_3a(
    P_nominal=5000,
    l=4000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Resistive line that connects to load 3"
  ThreePhasesBalanced.Lines.Line line_3b(
    P_nominal=5000,
    l=4000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Resistive line that connects to load 3"
  ThreePhasesBalanced.Loads.Impedance R3(R=10) "Resistive load 3"
  ThreePhasesBalanced.Lines.Line line_sc(
    P_nominal=5000,
    l=2000,
    redeclare Buildings.Electrical.Transmission.MediumVoltageCables.Generic
          commercialCable = Buildings.Electrical.Transmission.MediumVoltageCables.Annealed_Al_10(),
    V_nominal=15000) "Line that connects the source and the short circuit"
  ThreePhasesBalanced.Loads.Impedance load_sc(R=0) "Short circuit"
equation
  connect(line_1.terminal_p, R1.terminal)
  connect(E.terminal, line_1.terminal_n)
  connect(E.terminal, line_2a.terminal_n)
  connect(line_2a.terminal_p, line_2b.terminal_n)
  connect(line_2b.terminal_p, R2.terminal)
  connect(line_3a.terminal_p, R3.terminal)
  connect(line_3b.terminal_p, R3.terminal)
  connect(E.terminal, line_3a.terminal_n)
  connect(E.terminal, line_3b.terminal_n)
  connect(line_sc.terminal_p, load_sc.terminal)
  connect(E.terminal, line_sc.terminal_n)
end ACLineMedium;


Test model for single phase inductive lines. This example demonstrates how to use a purely inductive line model to connect
a source to a load.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Examples;
model ACLine_L "Test model for single phase inductive lines"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Inductance Lbase=10/2/Modelica.Constants.pi/60
    "Base value for the line inductances";
  ThreePhasesBalanced.Sources.FixedVoltage E(definiteReference=true,
    f=60,
    V=480) "Voltage source"
  ThreePhasesBalanced.Loads.Impedance R1(R=10) "Resistive load 1"
  ThreePhasesBalanced.Loads.Impedance R2(R=10) "Resistive load 2"
  ThreePhasesBalanced.Loads.Impedance R3(R=10) "Resistive load 3"
  ThreePhasesBalanced.Loads.Impedance load_sc(R=0) "Short circuit"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_sc(L=Lbase)
    "Inductive line connected to the short circuit"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_1(L=Lbase)
    "Inductive line connected to load 1"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_2a(L=0.5*Lbase)
    "Inductive line connected to load 2"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_2b(L=0.5*Lbase)
    "Inductive line connected to load 2"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_3(L=2*Lbase)
    "Inductive line connected to load 3"
  ThreePhasesBalanced.Lines.TwoPortInductance Lline_3b(L=2*Lbase)
    "Inductive line connected to load 3"
equation
  connect(E.terminal, Lline_sc.terminal_n)
  connect(Lline_sc.terminal_p, load_sc.terminal)
  connect(E.terminal, Lline_1.terminal_n)
  connect(Lline_1.terminal_p, R1.terminal)
  connect(E.terminal, Lline_2a.terminal_n)
  connect(Lline_2a.terminal_p, Lline_2b.terminal_n)
  connect(Lline_2b.terminal_p, R2.terminal)
  connect(E.terminal, Lline_3.terminal_n)
  connect(E.terminal, Lline_3b.terminal_n)
  connect(Lline_3.terminal_p, R3.terminal)
  connect(Lline_3b.terminal_p, R3.terminal)
end ACLine_L;


Test model for single phase resistive lines. This example demonstrates how to use a resistive line model to connect
a source to a load.

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


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

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


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

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Examples;
model ACSimpleGrid "Test model for a network model"
  extends Modelica.Icons.Example;
  ThreePhasesBalanced.Lines.Network network(
    redeclare Buildings.Electrical.Transmission.Grids.TestGrid2Nodes grid,
      V_nominal=480)
    "Network model that represents the connection between the source and the load"
  ThreePhasesBalanced.Loads.Inductive load(
    P_nominal=2500,
    mode=Types.Load.VariableZ_P_input,
    V_nominal=480) "Load connected to the network"
  ThreePhasesBalanced.Sources.FixedVoltage E(f=60, V=480) "Voltage source"
  Modelica.Blocks.Sources.Ramp load_inputs(
    height=5000,
    duration=2,
    offset=-2000,
    startTime=0.5) "Input signal for the power consumption of the loads"
equation
  connect(load.terminal, network.terminal[2])
  connect(E.terminal, network.terminal[1])
  connect(load_inputs.y, load.Pow)
end ACSimpleGrid;


Test model for a network model with medium voltage. This example demonstrates how to use a network model to connect
a source to a load (using a medium voltage cable). In this simple case the network has two nodes
that are connected by a commercial line cable.

within Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Examples;
model ACSimpleGridMedium "Test model for a network model with medium voltage"
  extends Modelica.Icons.Example;
  ThreePhasesBalanced.Lines.Network network(
      redeclare Buildings.Electrical.Transmission.Grids.TestGrid2NodesMedium grid,
      lines(redeclare
        Buildings.Electrical.Transmission.MediumVoltageCables.Generic
        commercialCable = network.grid.cables,
        each V_nominal = network.V_nominal),
    V_nominal=15000)
    "Network model that represents the connection between the source and the load"
  ThreePhasesBalanced.Loads.Inductive load(mode=Types.Load.VariableZ_P_input,
    P_nominal=250000,
    V_nominal=15000) "Load connected to the network"
  ThreePhasesBalanced.Sources.FixedVoltage E(V=15000, f=60) "Voltage source"
  Modelica.Blocks.Sources.Ramp load_inputs(
    height=5000,
    duration=2,
    offset=-2000,
    startTime=0.5) "Input signal for the power consumption of the loads"
equation
  connect(load.terminal, network.terminal[2])
  connect(E.terminal, network.terminal[1])
  connect(load_inputs.y, load.Pow)
end ACSimpleGridMedium;


Package with example models

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


Model of a capacitive and resistive load. Model of a capacitive load. See

Buildings.Electrical.AC.OnePhase.Loads.Capacitive for more information.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads;
model Capacitive "Model of a capacitive and resistive load"
  extends Buildings.Electrical.AC.OnePhase.Loads.Capacitive(
    redeclare Interfaces.Terminal_n terminal,
    V_nominal(start=480));
end Capacitive;


Model of a resistive load

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads;
model Impedance "Model of a resistive load"
  extends Buildings.Electrical.Interfaces.Impedance(
    redeclare package PhaseSystem = PhaseSystems.OnePhase,
    redeclare Interfaces.Terminal_n terminal);

  parameter Boolean star = true
    "Type of load connection: true = star, false = triangle"

protected
  Modelica.Units.SI.Angle theRef "Absolute angle of rotating reference system";
  Modelica.Units.SI.AngularVelocity omega
    "Frequency of the quasi-stationary sine waves";
  Modelica.Units.SI.Reactance X(start=1) "Complex component of the impedance";

equation
  theRef = PhaseSystem.thetaRef(terminal.theta);
  omega = der(theRef);

  // Inductance of each line
  if inductive then
    X = omega*L_internal;
  else
    X = -1/(omega*C_internal);
  end if;

  // Ohm's law
  if star then
    terminal.v = {{R_internal,-X}*terminal.i, {X,R_internal}*terminal.i};
  else
    terminal.v = {{R_internal/3,-X/3}*terminal.i, {X/3,R_internal/3}*terminal.i};
  end if;
end Impedance;


Model of an inductive and resistive load. Model of an inductive load. See

Buildings.Electrical.AC.OnePhase.Loads.Inductive for more information.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads;
model Inductive "Model of an inductive and resistive load"
  extends Buildings.Electrical.AC.OnePhase.Loads.Inductive(
    redeclare Interfaces.Terminal_n terminal,
    V_nominal(start=480));
end Inductive;


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Loads "Package with load models for three-phase balanced AC systems"
  extends Modelica.Icons.VariantsPackage;
end Loads;


Model of a resistive load. Model of a resistive load. See

Buildings.Electrical.AC.OnePhase.Loads.Resistive for more information.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads;
model Resistive "Model of a resistive load"
  extends Buildings.Electrical.AC.OnePhase.Loads.Resistive(
    redeclare Interfaces.Terminal_n terminal,
    V_nominal(start=480));
end Resistive;


Example that illustrates the use of the impedance models. This model illustrates the use of the impedance models.
The impedances have unitary values such that the RMS value of the voltage and of the current are the same.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Examples;
model Impedances "Example that illustrates the use of the impedance models"
   extends Modelica.Icons.Example;
  Sources.FixedVoltage sou(f=60, V=480) "Voltage source"
  Impedance Z1(R=0,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60),
    star=true) "Impedance purely inductive"
  Impedance Z2(R=1, star=true) "Impedance purely resistive"
  Impedance Z3(R=0,
    inductive=false,
    C=1/(2*Modelica.Constants.pi*60),
    star=true) "Impedance purely capacitive"
  Impedance Z4(
    inductive=false,
    R=1,
    C=1/(2*Modelica.Constants.pi*60),
    star=true) "Impedance capacitive"
  Impedance Z5(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60),
    star=true) "Impedance inductive"
equation
  connect(sou.terminal, Z1.terminal)
  connect(sou.terminal, Z2.terminal)
  connect(sou.terminal, Z3.terminal)
  connect(sou.terminal, Z4.terminal)
  connect(sou.terminal, Z5.terminal)
end Impedances;


Package with example models

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


Example that illustrates the use of the load models. This model illustrates the use of the three-phase unbalanced load models.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Examples;
model ParallelLoads "Example that illustrates the use of the load models"
  extends Modelica.Icons.Example;
  Sources.FixedVoltage E(f=60, V=480) "Voltage source"
  Resistive R(P_nominal=-2000, V_nominal=480) "Resistive load"
  Inductive RL_pf(
    pf=0.8,
    P_nominal=-2000,
    use_pf_in=true,
    V_nominal=480) "Inductive load with variable power factor"
  Modelica.Blocks.Sources.Ramp load(              startTime=0.2, duration=0.3)
    "Power signal profile"
  Inductive varRL_y(                                   P_nominal=-2000,
    V_nominal=480,
    mode=Buildings.Electrical.Types.Load.VariableZ_y_input)
    "Inductive load with y as input"
  Capacitive varRC_y(                                   P_nominal=-2000,
    V_nominal=480,
    mode=Buildings.Electrical.Types.Load.VariableZ_y_input)
    "Capacitive load with y as input"
  Inductive varRL_P(pf=0.8,
    V_nominal=480,
    mode=Buildings.Electrical.Types.Load.VariableZ_P_input)
    "Inductive load with P as input"
  Modelica.Blocks.Sources.Ramp pow(
    startTime=0.2,
    duration=0.3,
    height=4000,
    offset=-2000) "Power consumption profile"
  Modelica.Blocks.Sources.Ramp pf(
    height=0.2,
    duration=0.2,
    offset=0.8,
    startTime=0.7) "Power factor profile"
equation
  connect(E.terminal, R.terminal)
  connect(E.terminal, RL_pf.terminal)
  connect(E.terminal, varRL_y.terminal)
  connect(E.terminal, varRC_y.terminal)
  connect(load.y, varRL_y.y)

  connect(load.y, varRC_y.y)
  connect(E.terminal, varRL_P.terminal)
  connect(pow.y, varRL_P.Pow)
  connect(pf.y, RL_pf.pf_in)
end ParallelLoads;


Example that provides a comparison between AC one phase and three-phase balanced. This model illustrates the use of the impedance models and how the three-phase balanced model
can reproduce the same results obtained using three separate one phase circuits.

within Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Examples;
model ThreePhases
  "Example that provides a comparison between AC one phase and three-phase balanced"
  extends Modelica.Icons.Example;
  Modelica.Units.SI.Power errorY=sqrt((sen_Y.S[1] - (sen_a.S[1] + sen_b.S[1] +
      sen_c.S[1]))^2 + (sen_Y.S[2] - (sen_a.S[2] + sen_b.S[2] + sen_c.S[2]))^2)
    "Difference of the power consumption in the star (Y) connection";
  Modelica.Units.SI.Power errorD=sqrt((sen_D.S[1] - (sen_ab.S[1] + sen_bc.S[1]
       + sen_ca.S[1]))^2 + (sen_D.S[2] - (sen_ab.S[2] + sen_bc.S[2] + sen_ca.S[
      2]))^2)
    "Difference of the power consumption in the triangle (D) connection";
  Sources.FixedVoltage sou(definiteReference=true,
    f=60,
    V=480) "Three phases balanced voltage source"
  Impedance RL_star(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance with Y connection"
  OnePhase.Sources.FixedVoltage sou_a(V=480/sqrt(3), definiteReference=true,
    f=60) "Voltage source phase a"
  OnePhase.Sources.FixedVoltage sou_b(
    V=480/sqrt(3),
    definiteReference=true,
    phiSou=2.0943951023932,
    f=60) "Voltage source phase b"
  OnePhase.Sources.FixedVoltage sou_c(
    V=480/sqrt(3),
    definiteReference=true,
    phiSou=-2.0943951023932,
    f=60) "Voltage source phase c"
  OnePhase.Loads.Impedance RL_a(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on phase A"
  OnePhase.Loads.Impedance RL_b(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on phase B"
  OnePhase.Loads.Impedance RL_c(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on phase C"
  Impedance RL_tri(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60),
    star=false) "Impedance with D connection"
  OnePhase.Sources.FixedVoltage sou_ab(
    V=480,
    phiSou=-0.5235987755983,
    definiteReference=true,
    f=60) "Voltage source line ab"
  OnePhase.Sources.FixedVoltage sou_bc(
    phiSou=1.5707963267949,
    V=480,
    definiteReference=true,
    f=60) "Voltage source line bc"
  OnePhase.Sources.FixedVoltage sou_ca(
    phiSou=-3.6651914291881,
    V=480,
    definiteReference=true,
    f=60) "Voltage source line ca"
  OnePhase.Loads.Impedance RL_ab(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on line AB"
  OnePhase.Loads.Impedance RL_bc(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on line BC"
  OnePhase.Loads.Impedance RL_c1(
    R=1,
    inductive=true,
    L=1/(2*Modelica.Constants.pi*60)) "Impedance on linease CA"
  OnePhase.Sensors.GeneralizedSensor sen_a
    "Sensor located on phase A (Y connection)"
  OnePhase.Sensors.GeneralizedSensor sen_ab
    "Sensor located on line AB (D connection)"
  Sensors.GeneralizedSensor sen_Y "Sensor for Y connection (balanced case)"
  Sensors.GeneralizedSensor sen_D "Sensor for D connection (balanced case)"
  OnePhase.Sensors.GeneralizedSensor sen_b
    "Sensor located on phase B (Y connection)"
  OnePhase.Sensors.GeneralizedSensor sen_c
    "Sensor located on phase C (Y connection)"
  OnePhase.Sensors.GeneralizedSensor sen_bc
    "Sensor located on line BC (D connection)"
  OnePhase.Sensors.GeneralizedSensor sen_ca
    "Sensor located on line CA (D connection)"
equation
  connect(sou_a.terminal, sen_a.terminal_n)
  connect(sen_a.terminal_p, RL_a.terminal)
  connect(sou_ab.terminal, sen_ab.terminal_n)
  connect(sen_ab.terminal_p, RL_ab.terminal)
  connect(sou.terminal, sen_Y.terminal_n)
  connect(sen_Y.terminal_p, RL_star.terminal)
  connect(sou.terminal, sen_D.terminal_n)
  connect(sen_D.terminal_p, RL_tri.terminal)
  connect(sou_b.terminal, sen_b.terminal_n)
  connect(sen_b.terminal_p, RL_b.terminal)
  connect(sou_c.terminal, sen_c.terminal_n)
  connect(sen_c.terminal_p, RL_c.terminal)
  connect(sou_bc.terminal, sen_bc.terminal_n)
  connect(sen_bc.terminal_p, RL_bc.terminal)
  connect(sou_ca.terminal, sen_ca.terminal_n)
  connect(sen_ca.terminal_p, RL_c1.terminal)
end ThreePhases;


Sensor for power, voltage and current

within Buildings.Electrical.AC.ThreePhasesBalanced.Sensors;
model GeneralizedSensor "Sensor for power, voltage and current"
  extends Buildings.Electrical.Icons.GeneralizedSensor;
  extends Buildings.Electrical.Interfaces.PartialTwoPort(
    redeclare package PhaseSystem_p = PhaseSystems.OnePhase,
    redeclare package PhaseSystem_n = PhaseSystems.OnePhase,
    redeclare Interfaces.Terminal_n terminal_n(redeclare package PhaseSystem =
          PhaseSystem_n),
    redeclare Interfaces.Terminal_p terminal_p(redeclare package PhaseSystem =
          PhaseSystem_p));
  Modelica.Blocks.Interfaces.RealOutput V(
    final quantity="ElectricPotential",
    final unit="V")=
      Buildings.Electrical.PhaseSystems.OnePhase.systemVoltage(terminal_n.v)
    "Voltage"
  Modelica.Blocks.Interfaces.RealOutput I(
    final quantity="ElectricCurrent",
    final unit="A")=
      Buildings.Electrical.PhaseSystems.OnePhase.systemCurrent(terminal_n.i)
    "Current"
  Modelica.Blocks.Interfaces.RealOutput S[PhaseSystems.OnePhase.n](
    each final quantity="Power",
    each final unit="W")=
      Buildings.Electrical.PhaseSystems.OnePhase.phasePowers_vi(v=terminal_n.v, i=terminal_n.i)
    "Phase powers"
equation
  connect(terminal_n, terminal_p)
end GeneralizedSensor;


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Sensors "Package with sensors models for three-phase balanced AC systems"
extends Modelica.Icons.SensorsPackage;
end Sensors;


Model of a probe that measures RMS voltage and angle. This model represents a probe that measures the RMS voltage and the angle
of the voltage phasor at a given point.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sensors;
model Probe "Model of a probe that measures RMS voltage and angle"
  extends OnePhase.Sensors.Probe(
  redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Interfaces.Terminal_n term,
  V_nominal(start=480));
end Probe;


Example model for generalized sensor. This example illustrates the use of the generalized sensor.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.Examples;
model GeneralizedSensor "Example model for generalized sensor"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.GeneralizedSensor
    sen "Sensor model"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Capacitive loa(
                   V_nominal=480, P_nominal=-100) "Constant load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage
    sou(f=60, V=480) "Voltage source"
equation
  connect(sen.terminal_p, loa.terminal)
  connect(sen.terminal_n, sou.terminal)
end GeneralizedSensor;


Package with example models

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


This example illustrates how to use the probe model. This example illustrates the use of the probe model.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.Examples;
model Probe "This example illustrates how to use the probe model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Capacitive loaRC(
    mode=Buildings.Electrical.Types.Load.FixedZ_steady_state,
    P_nominal=-10000,
    V_nominal=480) "Constant load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou(f=60, V=
        480) "Voltage source"
  Buildings.Electrical.AC.ThreePhasesBalanced.Lines.TwoPortResistance res1(R=0.1)
    "First line resistance"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.Probe probe_source(V_nominal=
       480) "Probe that measures at the voltage source"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.Probe probe_loadRC(V_nominal=
       480) "Probe that measures at the RC load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Lines.TwoPortResistance res2(R=0.1)
    "Second line resistance"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive loaRL(
    mode=Buildings.Electrical.Types.Load.FixedZ_steady_state,
    P_nominal=-10000,
    V_nominal=480) "Constant load"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.Probe probe_loadRL(V_nominal=
       480) "Probe that measures at the RL load"
equation
  connect(sou.terminal, res1.terminal_n)
  connect(res1.terminal_p, loaRC.terminal)
  connect(sou.terminal, probe_source.term)
  connect(loaRC.terminal, probe_loadRC.term)
  connect(sou.terminal, res2.terminal_n)
  connect(res2.terminal_p, loaRL.terminal)
  connect(loaRL.terminal, probe_loadRL.term)
end Probe;


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

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model FixedVoltage "Fixed three-phase balanced AC voltage source"
  extends Buildings.Electrical.AC.OnePhase.Sources.FixedVoltage(
    redeclare Interfaces.Terminal_p terminal,
    f(start=60),
    V(start=480));
end FixedVoltage;


Model of a generator. Model of an inductive generator.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model Generator "Model of a generator"
  extends Buildings.Electrical.AC.OnePhase.Sources.Generator(
    redeclare Interfaces.Terminal_p terminal,
    f(start=60));
end Generator;


Electrical grid. Model that can be used to represent the electrical grid supply.
See
Buildings.Electrical.AC.OnePhase.Sources.Grid for
more information.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model Grid "Electrical grid"
  extends Buildings.Electrical.AC.OnePhase.Sources.Grid(
    redeclare Interfaces.Terminal_p terminal,
    f(start=60),
    V(start=480),
    redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Sources.FixedVoltage sou);
end Grid;


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Sources "Package with source models for three-phase balanced AC systems"
  extends Modelica.Icons.SourcesPackage;
end Sources;


Model of a simple PV panel. Model of a simple photovoltaic array.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model PVSimple "Model of a simple PV panel"
  extends Buildings.Electrical.AC.OnePhase.Sources.PVSimple(
    redeclare Interfaces.Terminal_p terminal,
    redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Capacitive load,
    V_nominal(start=480));
end PVSimple;


Model of a simple PV panel with orientation. Model of a simple photovoltaic array.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model PVSimpleOriented "Model of a simple PV panel with orientation"
  extends Buildings.Electrical.AC.OnePhase.Sources.PVSimpleOriented(
    redeclare Interfaces.Terminal_p terminal,
    redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Sources.PVSimple
    panel(V_nominal = V_nominal),
    V_nominal(start=480));
end PVSimpleOriented;


Model of a simple wind turbine generator. Model of a wind turbine whose power is computed as a function of wind-speed as defined in a table.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources;
model WindTurbine "Model of a simple wind turbine generator"
  extends Buildings.Electrical.AC.OnePhase.Sources.WindTurbine(
    redeclare Interfaces.Terminal_p terminal,
    redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Capacitive load,
    V_nominal(start=480));
end WindTurbine;


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

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Examples;
model FixedVoltageSource
  "This example illustrates how using a fixed voltage source"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive RL(
      P_nominal=-300, mode=Buildings.Electrical.Types.Load.FixedZ_steady_state,
    V_nominal=480) "Load model"
  ThreePhasesBalanced.Sources.FixedVoltage grid(
    f=60,
    V=480,
    phiSou=0.34906585039887) "AC one phase electrical grid"
  ThreePhasesBalanced.Sensors.Probe sen(V_nominal=480)
    "Probe that measures the voltage at the load"
equation
  connect(grid.terminal, RL.terminal)
  connect(grid.terminal, sen.term)
end FixedVoltageSource;


Package with example models

within Buildings.Electrical.AC.ThreePhasesBalanced.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.ThreePhasesBalanced.Sources.Examples;
model PVPanels "This example illustrates how to use PV panel models"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive RL(
    mode=Types.Load.VariableZ_y_input,
    P_nominal=-2000,
    V_nominal=480) "Load taht consumes the power generted by the PVs"
  Buildings.Electrical.AC.ThreePhasesBalanced.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"
  ThreePhasesBalanced.Sources.PVSimple pvSimple(A=10, V_nominal=480)
    "PV array simplified"
  ThreePhasesBalanced.Sources.PVSimpleOriented pvOriented(
    A=10,
    V_nominal=480,
    til=0.34906585039887,
    azi=-0.78539816339745) "PV array oriented"
equation
  connect(grid.terminal, RL.terminal)
  connect(load.y, RL.y)
  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(pvSimple.terminal, RL.terminal)
  connect(weaDat.weaBus, pvOriented.weaBus)
  connect(pvOriented.terminal, RL.terminal)
end PVPanels;


This example illustrates how using a variable power source. This example shows how to use a variable generator model. The generator model has to be used
together with a voltage source generator, which is in this example the
grid model.

within Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Examples;
model VariablePowerSource
  "This example illustrates how using a variable power source"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Generator generator(f=60,
      phiGen=0.26179938779915) "AC generator model"
  Modelica.Blocks.Sources.Sine generation(
    offset=200,
    startTime=1,
    amplitude=100,
    f=0.05) "Generated power"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Inductive RL(mode=Types.Load.VariableZ_y_input,
      P_nominal=-300,
    V_nominal=480) "Load model"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid grid(f=60, V=480)
    "AC one phase electrical grid"
  Modelica.Blocks.Sources.Trapezoid load(
    rising=2,
    width=3,
    falling=3,
    period=10,
    startTime=1,
    amplitude=0.8,
    offset=0.2) "Power consumption profile"
equation
  connect(generation.y, generator.P)
  connect(generator.terminal, RL.terminal)
  connect(grid.terminal, RL.terminal)
  connect(load.y, RL.y)
end VariablePowerSource;


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.ThreePhasesBalanced.Sources.Examples;
model WindTurbine "Example for the WindTurbine AC model"
  extends Modelica.Icons.Example;
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.WindTurbine tur(
    table=[3.5, 0;
           5.5,   100;
           12, 900;
           14, 1000;
           25, 1000], h=10,
    scale=10,
    V_nominal=480) "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"
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Resistive res(
    P_nominal=-500,
    V_nominal=480)
    "Resistive line"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid sou(
    f=60,
    V=480)
    "Voltage source"
  Buildings.Electrical.AC.ThreePhasesBalanced.Lines.TwoPortResistance lin(
    R=0.1)
    "Transmission line"
  Buildings.Electrical.AC.ThreePhasesBalanced.Sensors.GeneralizedSensor sen
    "Generalized sensor"
equation
  connect(weaDat.weaBus,weaBus)
  connect(weaBus.winSpe,tur. vWin)
  connect(sou.terminal, lin.terminal_n)
  connect(sou.terminal, res.terminal)
  connect(lin.terminal_p, sen.terminal_n)
  connect(sen.terminal_p, tur.terminal)
end WindTurbine;


Simple model of a battery. Simple model of a battery.

within Buildings.Electrical.AC.ThreePhasesBalanced.Storage;
model Battery "Simple model of a battery"
  extends Buildings.Electrical.AC.OnePhase.Storage.Battery(redeclare
      Interfaces.Terminal_p terminal,
      V_nominal(start=480),
      redeclare Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Resistive bat);
end Battery;


within Buildings.Electrical.AC.ThreePhasesBalanced;
package Storage "Package with models for electrical storage with a AC three-phase balanced connector"
  extends Modelica.Icons.Package;
end Storage;


This example shows how to use the AC battery model. This example shows how to use an AC battery model.

within Buildings.Electrical.AC.ThreePhasesBalanced.Storage.Examples;
model AcBattery "This example shows how to use the AC battery model"
  extends Modelica.Icons.Example;
  ThreePhasesBalanced.Storage.Battery bat_ideal(
    eta_DCAC=1,
    etaCha=1,
    etaDis=1,
    SOC_start=0.5,
    EMax=749999.88,
    V_nominal=480) "Ideal battery without losses"
  ThreePhasesBalanced.Sources.FixedVoltage fixVol(f=60, V=480)
  Modelica.Blocks.Sources.Pulse pow(
    offset=-500,
    amplitude=1000,
    width=50,
    period=1200)
    "Signal that indicates how much power should be stored in the battery"
  ThreePhasesBalanced.Storage.Battery bat_loss_acdc(
    etaCha=1,
    etaDis=1,
    SOC_start=0.5,
    eta_DCAC=0.95,
    EMax=749999.88,
    V_nominal=480) "Battery with losses for AC/DC conversion"
  ThreePhasesBalanced.Storage.Battery bat(
    SOC_start=0.5,
    eta_DCAC=0.95,
    EMax=749999.88,
    V_nominal=480)
    "Battery with losses for AC/DC conversion and charge/discharge"
equation
  connect(fixVol.terminal, bat_ideal.terminal)
  connect(pow.y, bat_ideal.P)
  connect(fixVol.terminal, bat_loss_acdc.terminal)
  connect(fixVol.terminal, bat.terminal)
  connect(pow.y, bat_loss_acdc.P)
  connect(pow.y, bat.P)
end AcBattery;


Package with example models

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


Three phases unbalanced AC systems

within Buildings.Electrical.AC;
package ThreePhasesUnbalanced "Three phases unbalanced AC systems"
  extends Modelica.Icons.VariantsPackage;
end ThreePhasesUnbalanced;


AC AC converter single phase systems (YY). This is an AC AC converter, based on a power balance between both circuit sides.
The parameter <i>conversionFactor</i> defines the ratio between the RMS voltages

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACConverter "AC AC converter single phase systems (YY)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterYY(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACConverter conv1(
      conversionFactor=conversionFactor,
      eta=eta,
      ground_1=ground_1,
      ground_2=ground_2),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACConverter conv2(
      conversionFactor=conversionFactor,
      eta=eta,
      ground_1=ground_1,
      ground_2=ground_2),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACConverter conv3(
      conversionFactor=conversionFactor,
      eta=eta,
      ground_1=ground_1,
      ground_2=ground_2));
  parameter Real conversionFactor
    "Ratio of QS rms voltage on side 2 / QS rms voltage on side 1";
  parameter Modelica.Units.SI.Efficiency eta(max=1)
    "Converter efficiency, pLoss = (1-eta) * Ptr";
  parameter Boolean ground_1 = false "Connect side 1 of converter to ground"
  parameter Boolean ground_2 = true "Connect side 2 of converter to ground"
end ACACConverter;


AC AC transformer simplified equivalent circuit (YY). This is a simplified equivalent transformer model.
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent both the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformer "AC AC transformer simplified equivalent circuit (YY)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterYY(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      phi_1=0),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      phi_1=-2.0943951023932),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      phi_1=2.0943951023932));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformer;


AC AC transformer simplified equivalent circuit (DD). This is a simplified equivalent transformer model with Delta-Delta connection.
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerDD "AC AC transformer simplified equivalent circuit (DD)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterDD(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VHigh=VHigh,
      VLow=VLow,
      phi_1=0.5235987755983),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VHigh=VHigh,
      VLow=VLow,
      phi_1=-1.5707963267949),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VHigh=VHigh,
      VLow=VLow,
      phi_1=2.6179938779915));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformerDD;


AC AC transformer detailed equivalent circuit (YY). This is a detailed transformer model that takes into accounts the winding Joule losses,
and the leakage reactances on the primary and secondary side. The model also takes into account
the core or iron losses and the losses due to magnetization effects.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerFull "AC AC transformer detailed equivalent circuit (YY)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterYY(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformerFull conv1(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      f = f,
      VABase=VABase,
      R1=R1,L1=L1,R2=R2,L2=L2,
      magEffects=magEffects,
      Rm=Rm,Lm=Lm,
      ground_1=ground_1,
      ground_2=ground_2),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformerFull conv2(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      f = f,
      VABase=VABase,
      R1=R1,L1=L1,R2=R2,L2=L2,
      magEffects=magEffects,
      Rm=Rm,Lm=Lm,
      ground_1=ground_1,
      ground_2=ground_2),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformerFull conv3(
      VHigh=VHigh/sqrt(3),
      VLow=VLow/sqrt(3),
      f = f,
      VABase=VABase,
      R1=R1,L1=L1,R2=R2,L2=L2,
      magEffects=magEffects,
      Rm=Rm,Lm=Lm,
      ground_1=ground_1,
      ground_2=ground_2));

  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Modelica.Units.SI.Frequency f(start=60) "Nominal frequency";
  parameter Buildings.Electrical.Types.PerUnit R1(min=0)
    "Resistance on side 1 of the transformer (pu)";
  parameter Buildings.Electrical.Types.PerUnit L1(min=0)
    "Inductance on side 1 of the transformer (pu)";
  parameter Buildings.Electrical.Types.PerUnit R2(min=0)
    "Resistance on side 2 of the transformer (pu)";
  parameter Buildings.Electrical.Types.PerUnit L2(min=0)
    "Inductance on side 2 of the transformer (pu)";
  parameter Boolean magEffects = false
    "If =true introduce magnetization effects"
  parameter Buildings.Electrical.Types.PerUnit Rm(min=0,start=0)
    "Magnetization resistance (pu)"
  parameter Buildings.Electrical.Types.PerUnit Lm(min=0,start=0)
    "Magnetization inductance (pu)"
  parameter Boolean ground_1 = false "Connect side 1 of converter to ground"
  parameter Boolean ground_2 = true "Connect side 2 of converter to ground"
end ACACTransformerFull;


AC AC transformer simplified equivalent circuit (DY step down). This is a simplified equivalent transformer model with Y-Delta connection
(voltage step down).
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerStepDownDY
  "AC AC transformer simplified equivalent circuit (DY step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterStepDownDY(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow/sqrt(3),
      phi_1=2.6179938779915),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow/sqrt(3),
      phi_1=0.5235987755983),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow/sqrt(3),
      phi_1=-1.5707963267949));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformerStepDownDY;


AC AC transformer simplified equivalent circuit (YD step down). This is a simplified equivalent transformer model with Y-Delta connection
(voltage step down).
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerStepDownYD
  "AC AC transformer simplified equivalent circuit (YD step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterStepDownYD(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow,
      phi_1=0),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow,
      phi_1=-2.0943951023932),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow,
      phi_1=2.0943951023932));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformerStepDownYD;


AC AC transformer simplified equivalent circuit (DY step up). This is a simplified equivalent transformer model with Delta-Y connection
(voltage step up).
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerStepUpDY
  "AC AC transformer simplified equivalent circuit (DY step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterStepUpDY(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow/sqrt(3),
      phi_1=0.5235987755983),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow/sqrt(3),
      phi_1=-1.5707963267949),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      VHigh=VHigh,
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=VLow/sqrt(3),
      phi_1=2.6179938779915));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformerStepUpDY;


AC AC transformer simplified equivalent circuit (YD step up). This is a simplified equivalent transformer model with Y-Delta connection
(voltage step up).
The model accounts for winding Joule losses and leakage reactances
that are represented by a series of a resistance R and an
inductance L. The resistance and the inductance represent the
effects of the secondary and primary side of the transformer.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion;
model ACACTransformerStepUpYD
  "AC AC transformer simplified equivalent circuit (YD step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverterStepUpYD(
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv1(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow,
      phi_1=0),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv2(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow,
      phi_1=-2.0943951023932),
    redeclare Buildings.Electrical.AC.OnePhase.Conversion.ACACTransformer conv3(
      VHigh=VHigh/sqrt(3),
      XoverR=XoverR,
      Zperc=Zperc,
      ground_1=ground_1,
      ground_2=ground_2,
      VABase=VABase/3,
      VLow=-VLow,
      phi_1=2.0943951023932));
  parameter Modelica.Units.SI.Voltage VHigh
    "Rms voltage on side 1 of the transformer (primary side)";
  parameter Modelica.Units.SI.Voltage VLow
    "Rms voltage on side 2 of the transformer (secondary side)";
  parameter Modelica.Units.SI.ApparentPower VABase
    "Nominal power of the transformer";
  parameter Real XoverR
    "Ratio between the complex and real components of the impedance (XL/R)";
  parameter Real Zperc "Short circuit impedance";
  parameter Boolean ground_1 = false "Connect side 1 of transformer to ground"
  parameter Boolean ground_2 = true "Connect side 2 of transformer to ground"
equation
end ACACTransformerStepUpYD;


within Buildings.Electrical.AC.ThreePhasesUnbalanced;
package Conversion "Package with converter and transformer models for three-phase
  unbalanced AC systems"
  extends Modelica.Icons.Package;
end Conversion;


Package with base class models

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


Partial model of a transformer

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverter "Partial model of a transformer"
  extends Buildings.Electrical.Icons.RefAngleConversion;
  replaceable Buildings.Electrical.Interfaces.PartialConversion
    conv1 constrainedby Buildings.Electrical.Interfaces.PartialConversion(
    redeclare package PhaseSystem_p =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare package PhaseSystem_n =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_n terminal_n,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_p terminal_p)
    "Transformer phase 1"
  replaceable Buildings.Electrical.Interfaces.PartialConversion
    conv2 constrainedby Buildings.Electrical.Interfaces.PartialConversion(
    redeclare package PhaseSystem_p =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare package PhaseSystem_n =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_n terminal_n,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_p terminal_p)
    "Transformer phase 2"
  replaceable Buildings.Electrical.Interfaces.PartialConversion
    conv3 constrainedby Buildings.Electrical.Interfaces.PartialConversion(
    redeclare package PhaseSystem_p =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare package PhaseSystem_n =
        Buildings.Electrical.PhaseSystems.OnePhase,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_n terminal_n,
    redeclare Electrical.AC.OnePhase.Interfaces.Terminal_p terminal_p)
    "Transformer phase 3"
  Interfaces.Terminal_n terminal_n "Electrical connector side N"
  Interfaces.Terminal_p terminal_p "Electrical connector side P"
end PartialConverter;


Model of a transformer with D connection primary side and D
  connection secondary side. Partial model that represents a three-phase unbalanced
transformer with delta connection on both primary and secondary side.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterDD "Model of a transformer with D connection primary side and D
  connection secondary side"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta wye_to_delta
    "Delta to wye connection"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta delta_to_wye
    "Delta to wye connection"
protected
  Interfaces.Adapter3to3 ada_n "Adapter"
  Interfaces.Adapter3to3 ada_p "Adapter"
equation

  connect(delta_to_wye.wye, terminal_n)
  connect(wye_to_delta.wye, terminal_p)

  connect(delta_to_wye.delta, ada_n.terminal)
  connect(wye_to_delta.delta, ada_p.terminal)
  connect(conv1.terminal_n, ada_n.terminals[1])
  connect(conv2.terminal_n, ada_n.terminals[2])
  connect(conv3.terminal_n, ada_n.terminals[3])
  connect(conv1.terminal_p, ada_p.terminals[1])
  connect(conv2.terminal_p, ada_p.terminals[2])
  connect(conv3.terminal_p, ada_p.terminals[3])
end PartialConverterDD;


Model of a transformer with D connection primary side and
  Y connection secondary side (Voltage step down). Partial model that represents a three-phase unbalanced
transformer with delta connection on the primary and Y connection on
the secondary side. The configuration is for voltage step down.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterStepDownDY "Model of a transformer with D connection primary side and
  Y connection secondary side (Voltage step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToWyeGround wye_to_wyeg
    "Wye to wye grounded connection"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta delta_to_wye
    "Delta to wye connection"
protected
  Interfaces.Adapter3to3 ada3to3_n "Adapter for connections"
  Interfaces.Adapter3to3 ada3to3_p "Adapter for connections"
equation

  connect(delta_to_wye.wye, terminal_n)
  connect(wye_to_wyeg.wye, terminal_p)

  connect(conv1.terminal_n, ada3to3_n.terminals[3])
  connect(conv2.terminal_n, ada3to3_n.terminals[1])
  connect(conv3.terminal_n, ada3to3_n.terminals[2])
  connect(delta_to_wye.delta, ada3to3_n.terminal)
  connect(conv1.terminal_p, ada3to3_p.terminals[1])
  connect(conv2.terminal_p, ada3to3_p.terminals[2])
  connect(conv3.terminal_p, ada3to3_p.terminals[3])
  connect(ada3to3_p.terminal, wye_to_wyeg.wyeg)
end PartialConverterStepDownDY;


Model of a transformer with Y connection primary side and D
connection secondary side (Voltage step down). Partial model that represents a three-phase unbalanced
transformer with Y connection on primary and delta connection on
the secondary one. The configuration is for voltage step down.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterStepDownYD "Model of a transformer with Y connection primary side and D
connection secondary side (Voltage step down)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToWyeGround wye_to_wyeg
    "Wye to wye grounded connection"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta delta_to_wye
    "Delta to wye connection "
protected
  Interfaces.Adapter3to3 ada3to3_n "Adapter for connections"
  Interfaces.Adapter3to3 ada3to3_p "Adapter for connections"
equation

  connect(delta_to_wye.wye, terminal_p)
  connect(wye_to_wyeg.wye, terminal_n)

  connect(conv1.terminal_n, ada3to3_n.terminals[1])
  connect(conv2.terminal_n, ada3to3_n.terminals[2])
  connect(conv3.terminal_n, ada3to3_n.terminals[3])
  connect(conv1.terminal_p, ada3to3_p.terminals[1])
  connect(conv2.terminal_p, ada3to3_p.terminals[2])
  connect(conv3.terminal_p, ada3to3_p.terminals[3])
  connect(ada3to3_p.terminal, delta_to_wye.delta)
  connect(wye_to_wyeg.wyeg, ada3to3_n.terminal)
end PartialConverterStepDownYD;


Model of a transformer with D connection primary side and Y connection
  secondary side (Voltage step up). Partial model that represents a three-phase unbalanced
transformer with delta connection on the primary and Y connection on
the secondary side. The configuration is for voltage step up.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterStepUpDY "Model of a transformer with D connection primary side and Y connection
  secondary side (Voltage step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToWyeGround wye_to_wyeg
    "Wye to wye grounded connection"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta delta_to_wye
    "Delta to wye connection"
protected
  Interfaces.Adapter3to3 ada3to3_n "Adapter for connections"
  Interfaces.Adapter3to3 ada3to3_p "Adapter for connections"
equation

  connect(delta_to_wye.wye, terminal_n)
  connect(wye_to_wyeg.wye, terminal_p)

  connect(conv1.terminal_n,ada3to3_n. terminals[1])
  connect(conv2.terminal_n,ada3to3_n. terminals[2])
  connect(conv3.terminal_n,ada3to3_n. terminals[3])
  connect(conv1.terminal_p,ada3to3_p. terminals[1])
  connect(conv2.terminal_p,ada3to3_p. terminals[2])
  connect(conv3.terminal_p,ada3to3_p. terminals[3])
  connect(ada3to3_p.terminal, wye_to_wyeg.wyeg)
  connect(delta_to_wye.delta, ada3to3_n.terminal)
end PartialConverterStepUpDY;


Model of a transformer with Y connection primary side and D connection
  secondary side (Voltage step up). Partial model that represents a three-phase unbalanced
transformer with Y connection on the primary and delta connection on
the secondary side. The configuration is for voltage step up.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterStepUpYD "Model of a transformer with Y connection primary side and D connection
  secondary side (Voltage step up)"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToWyeGround wye_to_wyeg
    "Wye to wye grounded connection"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta delta_to_wye
    "Delta to wye connection"
protected
  Interfaces.Adapter3to3 ada3to3_n "Adapter for connections"
  Interfaces.Adapter3to3 ada3to3_p "Adapter for connections"
equation

  connect(delta_to_wye.wye, terminal_p)
  connect(wye_to_wyeg.wye, terminal_n)

  connect(conv1.terminal_n,ada3to3_n. terminals[1])
  connect(conv2.terminal_n,ada3to3_n. terminals[2])
  connect(conv3.terminal_n,ada3to3_n. terminals[3])
  connect(wye_to_wyeg.wyeg, ada3to3_n.terminal)
  connect(conv1.terminal_p, ada3to3_p.terminals[3])
  connect(conv2.terminal_p, ada3to3_p.terminals[1])
  connect(conv3.terminal_p, ada3to3_p.terminals[2])
  connect(ada3to3_p.terminal, delta_to_wye.delta)
end PartialConverterStepUpYD;


Model of a transformer with Y connection primary side and Y
  connection secondary side. Partial model that represents a three-phase unbalanced
transformer with Y connection on both primary and secondary side.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses;
partial model PartialConverterYY "Model of a transformer with Y connection primary side and Y
  connection secondary side"
  extends
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter;
  Interfaces.Connection3to3Ground_n connection3to4_n
    "Conversion between 3 to 4 connectors"
  Interfaces.Connection3to3Ground_p connection3to4_p
    "Conversion between 3 to 4 connectors"
  OnePhase.Basics.Ground ground_n "Ground reference"
  OnePhase.Basics.Ground ground_p "Ground reference"
protected
  Interfaces.Adapter3to3 ada3to3_n "Adapter for connections"
  Interfaces.Adapter3to3 ada3to3_p "Adapter for connections"
equation

  connect(terminal_p, connection3to4_p.terminal3)
  connect(terminal_n, connection3to4_n.terminal3)
  connect(connection3to4_p.ground4, ground_p.terminal)
  connect(ground_n.terminal, connection3to4_n.ground4)
  connect(connection3to4_n.terminal4, ada3to3_n.terminal)
  connect(ada3to3_n.terminals[1], conv1.terminal_n)
  connect(ada3to3_n.terminals[2], conv2.terminal_n)
  connect(ada3to3_n.terminals[3], conv3.terminal_n)
  connect(conv1.terminal_p, ada3to3_p.terminals[1])
  connect(conv2.terminal_p, ada3to3_p.terminals[2])
  connect(conv3.terminal_p, ada3to3_p.terminals[3])
  connect(ada3to3_p.terminal, connection3to4_p.terminal4)
end PartialConverterYY;


Test for the AC/AC converter model. This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACConverter model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model Converter "Test for the AC/AC converter model"
  extends BaseClasses.TransformerExample(
  V_primary = 480,
  V_secondary = 240,
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACConverter
  tra(conversionFactor=0.5,eta=0.9));

equation
  connect(probe_2.term, tra.terminal_p)
end Converter;


Package with example models

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


Test for the AC/AC transformer model. This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformer model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model Transformer "Test for the AC/AC transformer model"
  extends BaseClasses.TransformerExample(
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformer
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end Transformer;


Test for the AC/AC transformer model with Delta-Delta configuration. This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerDD
  "Test for the AC/AC transformer model with Delta-Delta configuration"
  extends BaseClasses.TransformerExample(
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerDD
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end TransformerDD;


Test for the AC/AC transformer full model. This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerFull model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerFull "Test for the AC/AC transformer full model"
  extends BaseClasses.TransformerExample(
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerFull
  tra(VHigh=V_primary,
      VLow=V_secondary,
      VABase=6000000,
      f=60,
      R1=0.005,
      L1=0.005*6,
      R2=0.005,
      L2=0.005*6,
      magEffects=true,
      Rm=10,
      Lm=10),
      load(initMode=Buildings.Electrical.Types.InitMode.linearized));

equation
  connect(probe_2.term, load.terminal)
end TransformerFull;


Test for the AC/AC transformer model with Delta-Wye configuration (step-down voltage). This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownDY model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerStepDownDY
  "Test for the AC/AC transformer model with Delta-Wye configuration (step-down voltage)"
  extends BaseClasses.TransformerExample(
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownDY
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end TransformerStepDownDY;


Test for the AC/AC transformer model with Wye-Delta configuration (step-down voltage). This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownYD model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerStepDownYD
  "Test for the AC/AC transformer model with Wye-Delta configuration (step-down voltage)"
  extends BaseClasses.TransformerExample(
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepDownYD
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end TransformerStepDownYD;


Test for the AC/AC transformer model with Delta-Wye configuration (step-up voltage). This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpDY model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerStepUpDY
  "Test for the AC/AC transformer model with Delta-Wye configuration (step-up voltage)"
  extends BaseClasses.TransformerExample(
  V_primary = 4160,
  V_secondary = 12470,
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpDY
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end TransformerStepUpDY;


Test for the AC/AC transformer model with Wye-Delta configuration (step-up voltage). This example model tests the

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpYD model.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
model TransformerStepUpYD
  "Test for the AC/AC transformer model with Wye-Delta configuration (step-up voltage)"
  extends BaseClasses.TransformerExample(
  V_primary = 4160,
  V_secondary = 12470,
  redeclare Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeDelta probe_2,
  redeclare
      Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.ACACTransformerStepUpYD
  tra(VHigh=V_primary,
      VLow=V_secondary,
      XoverR=6,
      Zperc=sqrt(0.01^2 + 0.06^2),
      VABase=6000000));

equation
  connect(probe_2.term, load.terminal)
end TransformerStepUpYD;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples;
package BaseClasses "This package contains base classes inherited by the examples"
extends Modelica.Icons.BasesPackage;
end BaseClasses;


This example represents the basic test for a transformer model. This model is the base classes used by the examples that are part of the package

Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.Examples.BaseClasses;
model TransformerExample
  "This example represents the basic test for a transformer model"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Voltage V_primary=12470
    "RMS Voltage on the primary side of the transformer";
  parameter Modelica.Units.SI.Voltage V_secondary=4160
    "RMS Voltage on the secondary side of the transformer";
  Sources.FixedVoltage sou(
    f=60,
    V=V_primary) "Voltage source"
  replaceable
    Buildings.Electrical.AC.ThreePhasesUnbalanced.Conversion.BaseClasses.PartialConverter
    tra "Transformer model"
  Loads.Resistive load(
    loadConn=Buildings.Electrical.Types.LoadConnection.wye_to_wyeg,
    P_nominal=-1800e3,
    V_nominal=V_secondary,
    linearized=true)       "Load model"
  Sensors.ProbeWye probe_Y_1(perUnit=false, V_nominal = V_primary)
    "Probe that measures the voltage in Y configuration, primary side"
  Sensors.ProbeDelta probe_D_1(perUnit=false, V_nominal = V_primary)
    "Probe that measures the voltage in D configuration, primary side"
  replaceable Sensors.BaseClasses.GeneralizedProbe probe_2 constrainedby
    Sensors.BaseClasses.GeneralizedProbe(perUnit=false,
    V_nominal=V_secondary)
    "Probe that measures the voltage at the secondary side"

equation
  connect(sou.terminal, tra.terminal_n)
  connect(probe_Y_1.term, tra.terminal_n)
  connect(probe_D_1.term, tra.terminal_n)
  connect(tra.terminal_p, load.terminal)
end TransformerExample;


within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model Adapter3to3
  "Adapter from 3 single phase connectors to a connector with 3 phases"
  extends Modelica.Blocks.Icons.Block;

  Buildings.Electrical.Interfaces.Terminal terminals[3](
    redeclare final package PhaseSystem = PhaseSystems.OnePhase)
    "Generalized terminal"

  Interfaces.Terminal_p terminal "Connector with 3 lines"
equation
  for i in 1:3 loop
    terminal.phase[i].v     = terminals[i].v;
    terminal.phase[i].i     = -terminals[i].i;
    Connections.branch(terminal.phase[i].theta, terminals[i].theta);
    terminal.phase[i].theta = terminals[i].theta;
  end for;
end Adapter3to3;


Adapter between Terminal4 (3 phases and ground) and Terminal3 N. Adapter between electric connectors type n for AC three-phase unbalanced systems.
This adapter connects a connector without neutral cable to a connector without
neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model Connection3to3Ground_n
  "Adapter between Terminal4 (3 phases and ground) and Terminal3 N"

  Terminal_n terminal4 "Connector for side with neutral"
  Buildings.Electrical.AC.OnePhase.Interfaces.Terminal_n ground4
    "Connector for neutral"
  Terminal_n terminal3 "Connector without neutral"
equation

  // Connection branches required to propagate the reference angle
  Connections.branch(terminal4.phase[1].theta, ground4.theta);
  terminal4.phase[1].theta = ground4.theta;
  for i in 1:3 loop
    Connections.branch(terminal3.phase[i].theta, terminal4.phase[i].theta);
    terminal3.phase[i].theta = terminal4.phase[i].theta;
  end for;

  // KVL and KCL
  terminal3.phase[1].v[:] = terminal4.phase[1].v[:] - ground4.v[:];
  terminal3.phase[2].v[:] = terminal4.phase[2].v[:] - ground4.v[:];
  terminal3.phase[3].v[:] = terminal4.phase[3].v[:] - ground4.v[:];

  terminal4.phase[1].i[:] + terminal4.phase[2].i[:] = -terminal4.phase[3].i[:] - ground4.i[:];
  terminal4.phase[1].i[:] = - terminal3.phase[1].i[:];
  terminal4.phase[2].i[:] = - terminal3.phase[2].i[:];
  terminal4.phase[3].i[:] = - terminal3.phase[3].i[:];
end Connection3to3Ground_n;


Adapter between Terminal4 (3 phases and ground) and Terminal3 P. Adapter between electric connectors type p for AC three-phase unbalanced systems.
This adapter connects a connector without neutral cable to a connector without
neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model Connection3to3Ground_p
  "Adapter between Terminal4 (3 phases and ground) and Terminal3 P"

  Terminal_p terminal4 "Connector with neutral"
  Buildings.Electrical.AC.OnePhase.Interfaces.Terminal_p ground4
    "Connector for neutral"
  Terminal_p terminal3 "Connector without neutral"
equation

  // Connection branches required to propagate the reference angle
  Connections.branch(terminal4.phase[1].theta, ground4.theta);
  terminal4.phase[1].theta = ground4.theta;
  for i in 1:3 loop
    Connections.branch(terminal3.phase[i].theta, terminal4.phase[i].theta);
    terminal3.phase[i].theta = terminal4.phase[i].theta;
  end for;

  // KVL and KCL
  terminal3.phase[1].v[:] = terminal4.phase[1].v[:] - ground4.v[:];
  terminal3.phase[2].v[:] = terminal4.phase[2].v[:] - ground4.v[:];
  terminal3.phase[3].v[:] = terminal4.phase[3].v[:] - ground4.v[:];

  terminal4.phase[1].i[:] + terminal4.phase[2].i[:] = -terminal4.phase[3].i[:] - ground4.i[:];
  terminal4.phase[1].i[:] = - terminal3.phase[1].i[:];
  terminal4.phase[2].i[:] = - terminal3.phase[2].i[:];
  terminal4.phase[3].i[:] = - terminal3.phase[3].i[:];
end Connection3to3Ground_p;


Adapter between Terminal4 and Terminal3 N. Adapter between electric connectors type n for AC three-phase unbalanced systems.
This adapter connects a connector without neutral cable with a one that has it

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model Connection3to4_n "Adapter between Terminal4 and Terminal3 N"

  Terminal4_n terminal4 "Connector with neutral"
  Terminal_n terminal3 "Connector without neutral"
equation

  // Connection branches required to propagate the reference angle
  Connections.branch(terminal4.phase[1].theta, terminal4.phase[4].theta);
  terminal4.phase[1].theta = terminal4.phase[4].theta;
  for i in 1:3 loop
    Connections.branch(terminal3.phase[i].theta, terminal4.phase[i].theta);
    terminal3.phase[i].theta = terminal4.phase[i].theta;
  end for;

  // KVL and KCL
  terminal3.phase[1].v[:] = terminal4.phase[1].v[:] - terminal4.phase[4].v[:];
  terminal3.phase[2].v[:] = terminal4.phase[2].v[:] - terminal4.phase[4].v[:];
  terminal3.phase[3].v[:] = terminal4.phase[3].v[:] - terminal4.phase[4].v[:];

  terminal4.phase[1].i[:] + terminal4.phase[2].i[:] = -terminal4.phase[3].i[:] - terminal4.phase[4].i[:];
  terminal4.phase[1].i[:] = - terminal3.phase[1].i[:];
  terminal4.phase[2].i[:] = - terminal3.phase[2].i[:];
  terminal4.phase[3].i[:] = - terminal3.phase[3].i[:];
end Connection3to4_n;


Adapter between Terminal4 and Terminal3 P. Adapter between electric connectors type p for AC three-phase unbalanced systems.
This adapter connects two connectors without and without a neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model Connection3to4_p "Adapter between Terminal4 and Terminal3 P"

  Terminal4_p terminal4 "Connector with neutral"
  Terminal_p terminal3 "Connector without neutral"
equation

  // Connection branches required to propagate the reference angle
  Connections.branch(terminal4.phase[1].theta, terminal4.phase[4].theta);
  terminal4.phase[1].theta = terminal4.phase[4].theta;
  for i in 1:3 loop
    Connections.branch(terminal3.phase[i].theta, terminal4.phase[i].theta);
    terminal3.phase[i].theta = terminal4.phase[i].theta;
  end for;

  // KVL and KCL
  terminal3.phase[1].v[:] = terminal4.phase[1].v[:] - terminal4.phase[4].v[:];
  terminal3.phase[2].v[:] = terminal4.phase[2].v[:] - terminal4.phase[4].v[:];
  terminal3.phase[3].v[:] = terminal4.phase[3].v[:] - terminal4.phase[4].v[:];

  terminal4.phase[1].i[:] + terminal4.phase[2].i[:] = -terminal4.phase[3].i[:] - terminal4.phase[4].i[:];
  terminal4.phase[1].i[:] = - terminal3.phase[1].i[:];
  terminal4.phase[2].i[:] = - terminal3.phase[2].i[:];
  terminal4.phase[3].i[:] = - terminal3.phase[3].i[:];
end Connection3to4_p;


within Buildings.Electrical.AC.ThreePhasesUnbalanced;
package Interfaces "Package with interfaces for three-phase unbalanced AC models"
  extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Partial model interface for a two port component without neutral cable. Interface model for an AC three-phase unbalanced component with two ports
and without neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
partial model TwoPort
  "Partial model interface for a two port component without neutral cable"

  Terminal_p terminal_p "Electric terminal side p"
  Terminal_n terminal_n "Electric terminal side n"
end TwoPort;


Partial model interface for a two port component with neutral cable. Interface model for an AC three-phase unbalanced component with two ports
and with neutral cable.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
partial model TwoPort_N
  "Partial model interface for a two port component with neutral cable"

  Terminal4_p terminal_p "Electric terminal side p"
  Terminal4_n terminal_n "Electric terminal side n"
end TwoPort_N;


This model represent a connection between wye to delta. Adapter from Wye (Y) to Delta (D) connector.
A three-phase unbalanced connector has three AC single phase
connectors. Each AC single phase connector contains the phase voltage,
which is measured between the phase and the neutral.
This model converts the phase voltage to the line voltage, measured between
the phases.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model WyeToDelta "This model represent a connection between wye to delta"

  Terminal_n wye "Terminal Y"
  Terminal_n delta "Terminal D"
equation

  for i in 1:3 loop
    Connections.branch(wye.phase[i].theta, delta.phase[i].theta);
    wye.phase[i].theta = delta.phase[i].theta;
  end for;

  delta.phase[1].v[:] = wye.phase[1].v[:] - wye.phase[2].v[:];
  delta.phase[2].v[:] = wye.phase[2].v[:] - wye.phase[3].v[:];
  delta.phase[3].v[:] = wye.phase[3].v[:] - wye.phase[1].v[:];

  -wye.phase[1].i[:] + delta.phase[3].i[:] = delta.phase[1].i[:];
  -wye.phase[2].i[:] + delta.phase[1].i[:] = delta.phase[2].i[:];
  -wye.phase[3].i[:] + delta.phase[2].i[:] = delta.phase[3].i[:];
end WyeToDelta;


This model represent a connection between wye to wye grounded. Adapter from wye (Y) to wye grounded (Yg) connector.
A three-phase unbalanced connector has three AC single phase
connectors. Each AC single phase connector contains a the phase voltage,
which is measured
between the phase and the neutral. This model assures that the voltage of the neutral
cable is equal to zero.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces;
model WyeToWyeGround
  "This model represent a connection between wye to wye grounded"

  Terminal_n wye "Terminal Y"
  Terminal_n wyeg "Terminal Y with ground connection"
  Connection3to3Ground_n connection3to4
    "Adapter between Termina3 and Terminal4"
  Buildings.Electrical.AC.OnePhase.Basics.Ground ground "Ground reference"
equation
  connect(wye, connection3to4.terminal3)
  connect(connection3to4.terminal4, wyeg)
  connect(connection3to4.ground4, ground.terminal)
end WyeToWyeGround;


Package with example models

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


Test for Y to D connection. This simple example shows how to use a Y to D adapter.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.Examples;
model WyeToDelta "Test for Y to D connection"
  extends Modelica.Icons.Example;

  Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.WyeToDelta wyeToDelta
    "Conversion of the voltages from Y to D"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sources.FixedVoltage V1(f=60, V=
        480) "Voltage source"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probe_Y(perUnit=
       false, V_nominal=480)
    "Probe that measures the voltage and the angles on each phase"
  Buildings.Electrical.AC.ThreePhasesUnbalanced.Sensors.ProbeWye probeD(perUnit=
        false, V_nominal=480)
    "Probe that measures the voltage and the angles on each phase"
equation
  connect(V1.terminal, wyeToDelta.wye)
  connect(probe_Y.term, wyeToDelta.wye)
  connect(probeD.term, wyeToDelta.delta)
end WyeToDelta;


Model of an electrical line without neutral cable. This model represents an AC three-phase unbalanced cable without
neutral connection. The model is based on

Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines.TwoPortRLC
and provides functionalities to parametrize the values of R, L and C
using either commercial cables or default values.

within Buildings.Electrical.AC.ThreePhasesUnbalanced.Lines;
model Line "Model of an electrical line without neutral cable"
  extends Buildings.Electrical.AC.ThreePhasesUnbalanced.Interfaces.TwoPort(
    terminal_p(phase(v(each nominal = V_nominal))),
    terminal_n(phase(v(each nominal = V_nominal))));
  extends Buildings.Electrical.Transmission.BaseClasses.PartialBaseLine(
  V_nominal(start = 480),
  commercialCable = Buildings.Electrical.Transmission.Functions.selectCable_low(P_nominal, V_nominal));
  OnePhase.Lines.TwoPortRL phase1(
    final useHeatPort=true,
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=modelMode) "Impedance line 1"
  OnePhase.Lines.TwoPortRL phase2(
    final useHeatPort=true,
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=modelMode) "Impedance line 2"
  OnePhase.Lines.TwoPortRL phase3(
    final useHeatPort=true,
    final T_ref=T_ref,
    final M=M,
    final R=R/3,
    final L=L/3,
    final mode=modelMode) "Impedance line 3"
equation

  connect(cableTemp.port, phase1.heatPort)
  connect(cableTemp.port, phase2.heatPort)
  connect(cableTemp.port, phase3.heatPort)
  connect(terminal_n.phase[1], phase1.terminal_n)
  connect(terminal_n.phase[2], phase2.terminal_n)
  connect(terminal_n.phase[3], phase3.terminal_n)
  connect(phase1.terminal_p, terminal_p.phase[1])
  connect(phase2.terminal_p, terminal_p.phase[2])
  connect(phase3.terminal_p, terminal_p.phase[3])
end Line;