Test Case 1, Section 5.1, focuses on the dynamic behavior of the model for the synchronous generator machine and its AVR.

within PowerGrids.Examples.ENTSOE;

model TestCase1 "Test Case 1, Section 5.1, focuses on the dynamic behavior of the model for the synchronous generator machine and its AVR"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = 0, QStart = 0, SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0, UStart = 21000, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.ReferenceBus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VrMax = 4)
  PowerGrids.Electrical.Controls.PowerSystemStabilizers.IEEE_PSS2A PSS(Ks1 = 10, Ks2 = 0.1564, M = 0, N = 0, T1 = 0.25, T2 = 0.03, T3 = 0.15, T4 = 0.015, T7 = 2, T8 = 0.5, T9 = 0.1, Tw1 = 2, Tw2 = 2, Tw3 = 2, Tw4 = 0, VstMax = 0.1, VstMin = -0.1)
  Modelica.Blocks.Sources.RealExpression zero
  Modelica.Blocks.Sources.RealExpression VrefPu(y = if time < 0.1 then 1.005 else 1.055)
  Modelica.Blocks.Sources.RealExpression RefLPu(y = 0)

  Types.PerUnit AA_01_GEN_Upu = GEN.port.VPu "Fig. 5.1, terminal voltage";
  Types.PerUnit AA_02_GEN_efd = GEN.ufPuIn "Fig. 5.2, excitation voltage";

equation
  connect(GEN.PPu, PSS.Vsi2Pu)
  connect(GEN.VPu, AVR.VcPu)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(VrefPu.y, AVR.VrefPu)
  connect(zero.y, AVR.VuelPu)
  connect(GEN.omegaPu, PSS.Vsi1Pu)
  connect(PSS.VstPu, AVR.VsPu)
  connect(AVR.efdPu, GEN.ufPuIn)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.terminal, NTLV.terminal)
end TestCase1;


Test Case 2, Section 5.2, focuses on the dynamic behavior of the model for the synchronous generator and its governor.

within PowerGrids.Examples.ENTSOE;

model TestCase2 "Test Case 2, Section 5.2, focuses on the dynamic behavior of the model for the synchronous generator and its governor"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -3.8e+08, QStart = 0, SNom = 4.75e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0, UStart = 21000, portVariablesPhases = true, raPu = 0, referenceGenerator = true, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.ReferenceBus NGEN(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VrMax = 4)
  Modelica.Blocks.Sources.RealExpression zero
  Modelica.Blocks.Sources.RealExpression VrefPu(y = 1.00943)
  Modelica.Blocks.Sources.RealExpression RefLPu(y = 380 / 475 * 0.05)
  PowerGrids.Electrical.Loads.LoadImpedancePQInputs LOAD(PStart = 3.8e+08, SNom = 4.75e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.Step PLoad(height = 23.75e6, offset = 380e6, startTime = 0.1)
  Modelica.Blocks.Sources.RealExpression zero2

  Types.PerUnit AA_01_GEN_UPu = GEN.port.VPu "Fig. 5-3, terminal voltage";
  Types.PerUnit AA_02_GEN_PPu = GEN.port.PGenPu "Fig. 5-4, active power of the synchronous machine";
  Types.PerUnit AA_03_GEN_PmechPu = GEN.PmPu "Fig. 5-5, mechanical power of the synchronous machine";
  Types.PerUnit AA_04_GEN_omegaPu = GEN.omegaPu "Fig. 5-6, speed";

equation
  connect(GEN.VPu, AVR.VcPu)
  connect(zero2.y, LOAD.QRefIn)
  connect(zero.y, AVR.VuelPu)
  connect(zero.y, AVR.VsPu)
  connect(VrefPu.y, AVR.VrefPu)
  connect(PLoad.y, LOAD.PRefIn)
  connect(NGEN.terminal, LOAD.terminal)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(AVR.efdPu, GEN.ufPuIn)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.terminal, NGEN.terminal)
end TestCase2;


Test Case 3, Section 5.3, focuses on the dynamic behavior of the model for the synchronous machine with its whole control in response to a short-circuit.

within PowerGrids.Examples.ENTSOE;

model TestCase3 "Test Case 3, Section 5.3, focuses on the dynamic behavior of the model for the synchronous machine with its whole control in response to a short-circuit"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08, SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161146, UStart = 21e3 * 0.992, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.BusFault NTHV(R = 0.05, SNom = 5e+08, UNom = 380000, UStart = 1.050 * 380e3, X = 0, portVariablesPhases = true, portVariablesPu = true, startTime = 0.1, stopTime = 0.2)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161146, UPhaseStartB = 0, UStartA = 0.992 * 21e3, UStartB = 1.050 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VrMax = 4)
  PowerGrids.Electrical.Controls.PowerSystemStabilizers.IEEE_PSS2A PSS(Ks1 = 10, Ks2 = 0.1564, M = 0, N = 0, T1 = 0.25, T2 = 0.03, T3 = 0.15, T4 = 0.015, T7 = 2, T8 = 0.5, T9 = 0.1, Tw1 = 2, Tw2 = 2, Tw3 = 2, Tw4 = 0, VstMax = 0.1, VstMin = -0.1)
  Modelica.Blocks.Sources.RealExpression zero
  Modelica.Blocks.Sources.RealExpression VrefPu(y = 1.004552)
  Modelica.Blocks.Sources.RealExpression RefLPu(y = 475 / 500 * 0.05)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRef = 4.75e+08, QRef = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.050 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)

  Types.PerUnit AA_01_GEN_Upu = GEN.port.VPu "Fig. 5.7, terminal voltage";
  Types.PerUnit AA_02_GEN_efd = GEN.ufPuIn "Fig. 5.8, excitation voltage";
  Types.PerUnit AA_03_GEN_Ppu = GEN.port.PGenPu/0.95 "Fig. 5.9, active power of the synchronous machine";
  Types.PerUnit AA_04_GEN_Qpu = GEN.port.QGenPu/0.314583 "Fig. 5.10, reactive power of the synchronous machine";
  Types.PerUnit AA_05_GEN_omegapu = GEN.omegaPu "Fig. 5.11, speed";
  Types.PerUnit AA_06_PSS_out = PSS.VstPu "Fig. 5.12, PSS output signal";
  Types.PerUnit AA_07_GRIDL_Ppu = GRIDL.port.PPu/0.95 "Fig. 5.13, active power of the load";
  Types.PerUnit AA_08_GRIDL_Qpu = GRIDL.port.QPu/0.1519 "Fig. 5.14, reactive power of the load";

equation
  connect(GRID.terminal, NTHV.terminal)
  connect(VrefPu.y, AVR.VrefPu)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(GEN.PPu, PSS.Vsi2Pu)
  connect(GEN.VPu, AVR.VcPu)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(zero.y, AVR.VuelPu)
  connect(GEN.omegaPu, PSS.Vsi1Pu)
  connect(PSS.VstPu, AVR.VsPu)
  connect(AVR.efdPu, GEN.ufPuIn)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(GEN.terminal, NTLV.terminal)
end TestCase3;


Model of controlled generator for the IEEE 14-bus benchmark - synchronous machine with proportional regulations.

within PowerGrids.Examples.IEEE14bus;
model ControlledGeneratorIEEE "Model of controlled generator for the IEEE 14-bus benchmark - synchronous machine with proportional regulations"
  extends Icons.Machine;
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(portVariablesPhases = true)
  PowerGrids.Interfaces.TerminalAC terminal
  Electrical.Controls.ExcitationSystems.VRProportional AVR(Ka = 20, VcPuStart = GEN.UStart / GEN.UNom, VrMax = 5, VrMin = -5)
  Electrical.Controls.TurbineGovernors.GoverProportional GOV(KGover = 5, PMaxPu = 1, PMinPu = 0, PPuStart = -GEN.PStart / GEN.PNom)
  PowerGrids.Controls.FreeOffset PmRefPu(use_u = true)
  Controls.FreeOffset VrefPu(use_u = true)
  Modelica.Blocks.Sources.RealExpression VrefPuDef(y = 1)
  Modelica.Blocks.Sources.RealExpression PmRefPuDef(y = -GEN.PStart / GEN.PNom)
  Modelica.Blocks.Interfaces.RealOutput omega
equation
  connect(GEN.terminal, terminal)
  connect(GOV.omegaPu, GEN.omegaPu)
  connect(AVR.VcPu, GEN.VPu)
  connect(AVR.efdPu, GEN.ufPuIn)
  connect(GOV.PMechPu, GEN.PmPu)
  connect(PmRefPu.y, GOV.PmRefPu)
  connect(VrefPu.y, AVR.VrefPu)
  connect(VrefPuDef.y, VrefPu.u)
  connect(GEN.PPu, GOV.PPu)
  connect(PmRefPuDef.y, PmRefPu.u)
  connect(GEN.omega, omega)
end ControlledGeneratorIEEE;


Simulation of the disconnection of generator 2 at t = 1 s.

within PowerGrids.Examples.IEEE14bus;
model IEEE14busGen2Disconnection "Simulation of the disconnection of generator 2 at t = 1 s"
  extends IEEE14busStaticNetwork(Tgen2(useBreaker = true));
  Modelica.Blocks.Sources.BooleanExpression Gen2BreakerState(y = time < 1)
equation
  connect(Gen2BreakerState.y, Tgen2.breakerStatusIn)
end IEEE14busGen2Disconnection;


Simulation of the opening of line 1 to 5 at t = 1 s.

within PowerGrids.Examples.IEEE14bus;

model IEEE14busLine1to5Opening "Simulation of the opening of line 1 to 5 at t = 1 s"
  extends IEEE14busStaticNetwork(L1to5(useBreakerB = true));
  Modelica.Blocks.Sources.BooleanExpression L1to5BreakerState(y = time < 1)
equation
  connect(L1to5BreakerState.y, L1to5.breakerStatusB)
end IEEE14busLine1to5Opening;


Simulation of a load increase on load 2 at t = 1 s.

within PowerGrids.Examples.IEEE14bus;

model IEEE14busLoad2Variation "Simulation of a load increase on load 2 at t = 1 s"
  extends IEEE14busStaticNetwork(
    Load2(
      PRef = Load2.PRefConst*(if time < 1 then 1 else 2) "Active power consumption at reference voltage",
      QRef = Load2.QRefConst*(if time < 1 then 1 else 2) "Reactive power consumption at reference voltage"
    ));
equation
end IEEE14busLoad2Variation;


Power flow model of the IEEE 14-bus benchmark.

within PowerGrids.Examples.IEEE14bus;

model IEEE14busPowerFlow "Power flow model of the IEEE 14-bus benchmark"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids

  // Buses
  PowerGrids.Electrical.PowerFlow.SlackBus bus1(
    SNom = 100e6,
    U = 69e3*1.0598,
    UNom = 69000
  )
  PowerGrids.Electrical.Buses.Bus bus2(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus3(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus4(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus5(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus6(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus7(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus8(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus9(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus10(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus11(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus12(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus13(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus14(
    SNom = 100e6,
    UNom = 13.8e3
  )

  // Lines
  PowerGrids.Electrical.Branches.LineConstantImpedance L1to2(
    portVariablesPhases = true,
    R = 0.922682,
    X = 2.81708,
    G = 0,
    B = 0.00110901,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedanceWithBreakers L1to5(
    portVariablesPhases = true,
    R = 2.57237,
    X = 10.6189,
    B = 0.0010334,
    G = 0,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to3(
    portVariablesPhases = true,
    R = 2.23719,
    X = 9.42535,
    G = 0,
    B = 0.000919975,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to4(
    portVariablesPhases = true,
    R = 2.76662,
    X = 8.3946,
    G = 0,
    B = 0.000714136,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to5(
    portVariablesPhases = true,
    R = 2.71139,
    X = 8.27843,
    G = 0,
    B = 0.000726738,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L3to4(
    portVariablesPhases = true,
    R = 3.19035,
    X = 8.14274,
    G = 0,
    B = 0.000268851,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L4to5(
    portVariablesPhases = true,
    R = 0.635593,
    X = 2.00486,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to11(
    portVariablesPhases = true,
    R = 0.18088,
    X = 0.378785,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to12(
    portVariablesPhases = true,
    R = 0.23407,
    X = 0.487165,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to13(
    portVariablesPhases = true,
    R = 0.125976,
    X = 0.248086,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L7to8(
    portVariablesPhases = true,
    R = 0,
    X = 0.33546,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L7to9(
    portVariablesPhases = true,
    R = 0,
    X = 0.209503,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L9to10(
    portVariablesPhases = true,
    R = 0.060579,
    X = 0.160922,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L9to14(
    portVariablesPhases = true,
    R = 0.242068,
    X = 0.514912,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L10to11(
    portVariablesPhases = true,
    R = 0.156256,
    X = 0.365778,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L12to13(
    portVariablesPhases = true,
    R = 0.42072,
    X = 0.380651,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L13to14(
    portVariablesPhases = true,
    R = 0.325519,
    X = 0.662763,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )

  // LOADS
  PowerGrids.Electrical.PowerFlow.PQBus Load2(
    portVariablesPhases = true,
    P = 21.7e6,
    Q = 12.7e6,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load3(
    portVariablesPhases = true,
    P = 94.2e6,
    Q = 19.1e6,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load4(
    portVariablesPhases = true,
    P = 47.8e6,
    Q = -3.9e6,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load5(
    portVariablesPhases = true,
    P = 7.6e6,
    Q = 1.6e6,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load6(
    portVariablesPhases = true,
    P = 11.2e6,
    Q = 7.5e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load9(
    portVariablesPhases = true,
    P = 29.5e6,
    Q = 16.6e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load10(
    portVariablesPhases = true,
    P = 9e6,
    Q = 5.8e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load11(
    portVariablesPhases = true,
    P = 3.5e6,
    Q = 1.8e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load12(
    portVariablesPhases = true,
    P = 6.1e6,
    Q = 1.6e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load13(
    portVariablesPhases = true,
    P = 13.8e6,
    Q = 5.8e6,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.PowerFlow.PQBus Load14(
    portVariablesPhases = true,
    P = 14.9e6,
    Q = 5e6,
    SNom = 100e6,
    UNom = 13.8e3
  )

  // Capacitor bank
  PowerGrids.Electrical.Banks.CapacitorBankFixed Cbank9(
    portVariablesPhases = true,
    B = 0.099769,
    SNom = 100e6,
    UNom = 13.8e3
  )

  // Transformers
  PowerGrids.Electrical.Branches.TransformerFixedRatio T4to7(
    portVariablesPhases = true,
    R = 0,
    X = 0.398248,
    B = 0,
    G = 0,
    rFixed = 0.204082,
    SNom = 100e6,
    UNomA = 69e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio T4to9(
    portVariablesPhases = true,
    R = 0,
    X = 1.05919,
    B = 0,
    G = 0,
    rFixed = 0.208333,
    SNom = 100e6,
    UNomA = 69.0e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio T5to6(
    portVariablesPhases = true,
    R = 0,
    X = 0.479948,
    B = 0,
    G = 0,
    rFixed = 0.212766,
    SNom = 100e6,
    UNomA = 69e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen1(
    portVariablesPhases = true,
    R = 0,
    X = 0.393146,
    B = 0,
    G = 0,
    rFixed = 2.875,
    SNom = 1211e6,
    UNomA = 24e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatioWithBreaker Tgen2(
    portVariablesPhases = true,
    R = 0,
    X = 0.425089,
    B = 0,
    G = 0,
    rFixed = 2.875,
    SNom = 1120e6,
    UNomA = 24e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen3(
    portVariablesPhases = true,
    R = 0,
    X = 0.288545,
    B = 0,
    G = 0,
    rFixed = 3.45,
    SNom = 1650e6,
    UNomA = 20e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen8(
    portVariablesPhases = true,
    R = 0,
    X = 0.076176,
    B = 0,
    G = 0,
    rFixed = 0.766667,
    SNom = 250e6,
    UNomA = 18e3,
    UNomB = 13.8e3
  )

  // Generators
  PowerGrids.Electrical.PowerFlow.PVBus GEN1(
    portVariablesPhases = true,
    SNom = 1211e6,
    UNom = 24e3,
    P = -232.36955e6,
    U = 25.4068e3
  )
  PowerGrids.Electrical.PowerFlow.PVBus GEN2(
    portVariablesPhases = true,
    SNom = 1120e6,
    UNom = 24e3,
    U = 25.1608e3,
    P = -40e6
  )
  PowerGrids.Electrical.PowerFlow.PVBus GEN3(
    portVariablesPhases = true,
    SNom = 1650e6,
    UNom = 20e3,
    U = 20.229e3,
    P = 0.0
  )
  PowerGrids.Electrical.PowerFlow.PVBus GEN6(
    portVariablesPhases = true,
    SNom = 80.0e6,
    UNom = 13.8e3,
    U = 14.7347e3,
    P = 0
  )
  PowerGrids.Electrical.PowerFlow.PVBus GEN8(
    portVariablesPhases = true,
    SNom = 250e6,
    UNom = 18e3,
    U = 19.6461e3,
    P = 0
  )

equation
  connect(bus12.terminal, L6to12.terminalB)
  connect(L12to13.terminalA, bus12.terminal)
  connect(L12to13.terminalB, bus13.terminal)
  connect(L6to12.terminalA, bus6.terminal)
  connect(L6to13.terminalA, bus6.terminal)
  connect(L6to13.terminalB, bus13.terminal)
  connect(bus13.terminal, L6to13.terminalB)
  connect(L6to11.terminalA, bus6.terminal)
  connect(L6to11.terminalB, bus11.terminal)
  connect(L13to14.terminalA, bus13.terminal)
  connect(L13to14.terminalB, bus14.terminal)
  connect(L9to14.terminalB, bus14.terminal)
  connect(L9to14.terminalA, bus9.terminal)
  connect(L10to11.terminalB, bus11.terminal)
  connect(L10to11.terminalA, bus10.terminal)
  connect(L9to10.terminalB, bus10.terminal)
  connect(L9to10.terminalA, bus9.terminal)
  connect(L7to8.terminalA, bus7.terminal)
  connect(L7to9.terminalA, bus7.terminal)
  connect(L7to9.terminalB, bus9.terminal)
  connect(L7to8.terminalB, bus8.terminal)
  connect(T4to9.terminalA, bus4.terminal)
  connect(T4to9.terminalB, bus9.terminal)
  connect(T5to6.terminalB, bus6.terminal)
  connect(T5to6.terminalA, bus5.terminal)
  connect(L1to2.terminalA, bus1.terminal)
  connect(L1to2.terminalB, bus2.terminal)
  connect(L1to5.terminalA, bus1.terminal)
  connect(L1to5.terminalB, bus5.terminal)
  connect(L2to5.terminalB, bus5.terminal)
  connect(L4to5.terminalB, bus5.terminal)
  connect(L2to5.terminalA, bus2.terminal)
  connect(L2to4.terminalA, bus2.terminal)
  connect(L3to4.terminalB, bus4.terminal)
  connect(L3to4.terminalA, bus3.terminal)
  connect(L2to4.terminalB, bus4.terminal)
  connect(L4to5.terminalA, bus4.terminal)
  connect(L2to3.terminalB, bus3.terminal)
  connect(Tgen8.terminalB, bus8.terminal)
  connect(Tgen3.terminalB, bus3.terminal)
  connect(Tgen2.terminalB, bus2.terminal)
  connect(Tgen1.terminalB, bus1.terminal)
  connect(Load12.terminal, bus12.terminal)
  connect(bus13.terminal, Load13.terminal)
  connect(Load14.terminal, bus14.terminal)
  connect(Load11.terminal, bus11.terminal)
  connect(Load10.terminal, bus10.terminal)
  connect(Cbank9.terminal, bus9.terminal)
  connect(Load9.terminal, bus9.terminal)
  connect(Load6.terminal, bus6.terminal)
  connect(Load5.terminal, bus5.terminal)
  connect(Load3.terminal, bus3.terminal)
  connect(Load2.terminal, bus2.terminal)
  connect(L2to3.terminalA, bus2.terminal)
  connect(Tgen1.terminalA, GEN1.terminal)
  connect(GEN2.terminal, Tgen2.terminalA)
  connect(Tgen3.terminalA, GEN3.terminal)
  connect(GEN8.terminal, Tgen8.terminalA)
  connect(Load4.terminal, bus4.terminal)
  connect(GEN6.terminal, bus6.terminal)
  connect(T4to7.terminalA, bus4.terminal)
  connect(T4to7.terminalB, bus7.terminal)
end IEEE14busPowerFlow;


Dynamic model of the IEEE 14-bus system, operating in steady-state.

within PowerGrids.Examples.IEEE14bus;
model IEEE14busStaticNetwork "Dynamic model of the IEEE 14-bus system, operating in steady-state"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids(initOpt = PowerGrids.Types.Choices.InitializationOption.globalSteadyStateFixedPowerFlow, referenceFrequency = PowerGrids.Types.Choices.ReferenceFrequency.fixedReferenceGenerator)

// Buses
  PowerGrids.Electrical.Buses.ReferenceBus bus1(
    SNom = 100e6,
    UNom = 69e3,
    UStart = 69e3*1.0598
  )
  PowerGrids.Electrical.Buses.Bus bus2(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus3(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus4(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus5(
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Buses.Bus bus6(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus7(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus8(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus9(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus10(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus11(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus12(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus13(
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Buses.Bus bus14(
    SNom = 100e6,
    UNom = 13.8e3
  )

// Lines
  PowerGrids.Electrical.Branches.LineConstantImpedance L1to2(
    portVariablesPhases = true,
    R = 0.922682,
    X = 2.81708,
    G = 0,
    B = 0.00110901,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedanceWithBreakers L1to5(
    portVariablesPhases = true,
    R = 2.57237,
    X = 10.6189,
    G = 0,
    B = 0.0010334,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to3(
    portVariablesPhases = true,
    R = 2.23719,
    X = 9.42535,
    G = 0,
    B = 0.000919975,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to4(
    portVariablesPhases = true,
    R = 2.76662,
    X = 8.3946,
    G = 0,
    B = 0.000714136,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L2to5(
    portVariablesPhases = true,
    R = 2.71139,
    X = 8.27843,
    G = 0,
    B = 0.000726738,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L3to4(
    portVariablesPhases = true,
    R = 3.19035,
    X = 8.14274,
    G = 0,
    B = 0.000268851,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L4to5(
    portVariablesPhases = true,
    R = 0.635593,
    X = 2.00486,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 69e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to11(
    portVariablesPhases = true,
    R = 0.18088,
    X = 0.378785,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to12(
    R = 0.23407,
    portVariablesPhases = true,
    X = 0.487165,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L6to13(
    portVariablesPhases = true,
    R = 0.125976,
    X = 0.248086,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L7to8(
    portVariablesPhases = true,
    R = 0,
    X = 0.33546,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L7to9(
    portVariablesPhases = true,
    R = 0,
    X = 0.209503,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L9to10(
    portVariablesPhases = true,
    R = 0.060579,
    X = 0.160922,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L9to14(
    portVariablesPhases = true,
    R = 0.242068,
    X = 0.514912,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L10to11(
    portVariablesPhases = true,
    R = 0.156256,
    X = 0.365778,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L12to13(
    portVariablesPhases = true,
    R = 0.42072,
    X = 0.380651,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )
  PowerGrids.Electrical.Branches.LineConstantImpedance L13to14(
    portVariablesPhases = true,
    R = 0.325519,
    X = 0.662763,
    G = 0,
    B = 0,
    SNom = 100e6,
    UNom = 13.8e3
  )

// Loads
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load2(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 21.7e6,
    QRefConst = 12.7e6,
    SNom = 100e6,
    UNom = 69e3,
    URef = 72.105e3,
    UStart = 72.0866e3,
    UPhaseStart = -0.087
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load3(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 94.2e6,
    QRefConst = 19.1e6,
    SNom = 100e6,
    UNom = 69e3,
    URef = 69.69e3,
    UStart = 69.685e3,
    UPhaseStart = -0.22231
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load4(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 47.8e6,
    QRefConst = -3.9e6,
    SNom = 100e6,
    UNom = 69e3,
    URef = 70.2756e3,
    UStart = 70.2049e3,
    UPhaseStart = -0.180223
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load5(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 7.6e6,
    QRefConst = 1.6e6,
    SNom = 100e6,
    UNom = 69e3,
    URef = 70.4552e3,
    UStart = 70.3898e3,
    UPhaseStart = -0.153511
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load6(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 11.2e6,
    QRefConst = 7.5e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.766e3,
    UStart = 14.7347e3,
    UPhaseStart = -0.249364
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load9(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 29.5e6,
    QRefConst = 16.6e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.5966e3,
    UStart = 14.5624e3,
    UPhaseStart = -0.261599
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load10(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 9e6,
    QRefConst = 5.8e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.5241e3,
    UStart = 14.4903e3,
    UPhaseStart = -0.264445
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load11(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 3.5e6,
    QRefConst = 1.8e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.5959e3,
    UStart = 14.5633e3,
    UPhaseStart = -0.259223
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load12(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 6.1e6,
    QRefConst = 1.6e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.499e3,
    UStart = 14.5308e3,
    UPhaseStart = -0.264428
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load13(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 13.8e6,
    QRefConst = 5.8e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.5634e3,
    UStart = 14.4648e3,
    UPhaseStart = -0.265952
  )
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence Load14(
    alpha = 1.5,
    beta = 2.5,
    PRefConst = 14.9e6,
    QRefConst = 5e6,
    SNom = 100e6,
    UNom = 13.8e3,
    URef = 14.3062e3,
    UStart = 14.2714e3,
    UPhaseStart = -0.281002
  )

// Capacitor Bank
  PowerGrids.Electrical.Banks.CapacitorBankFixed Cbank9(
    B = 0.099769,
    SNom = 100e6,
    UNom = 13.8e3
  )

// Transformers
  PowerGrids.Electrical.Branches.TransformerFixedRatio T4to7(
    R = 0,
    X = 0.398248,
    B = 0,
    G = 0,
    rFixed = 0.204082,
    SNom = 100e6,
    UNomA = 69e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio T4to9(
    R = 0,
    X = 1.05919,
    B = 0,
    G = 0,
    rFixed = 0.208333,
    SNom = 100e6,
    UNomA = 69.0e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio T5to6(
    R = 0,
    X = 0.479948,
    B = 0,
    G = 0,
    rFixed = 0.212766,
    SNom = 100e6,
    UNomA = 69e3,
    UNomB = 13.8e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen1(
    portVariablesPhases = true,
    R = 0,
    X = 0.393146,
    B = 0,
    G = 0,
    rFixed = 2.875,
    SNom = 1211e6,
    UNomA = 24e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatioWithBreaker Tgen2(
    portVariablesPhases = true,
    R = 0,
    X = 0.425089,
    B = 0,
    G = 0,
    rFixed = 2.875,
    SNom = 1120e6,
    UNomA = 24e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen3(
    portVariablesPhases = true,
    R = 0,
    X = 0.288545,
    B = 0,
    G = 0,
    rFixed = 3.45,
    SNom = 1650e6,
    UNomA = 20e3,
    UNomB = 69e3
  )
  PowerGrids.Electrical.Branches.TransformerFixedRatio Tgen8(
    portVariablesPhases = true,
    R = 0,
    X = 0.076176,
    B = 0,
    G = 0,
    rFixed = 0.766667,
    SNom = 250e6,
    UNomA = 18e3,
    UNomB = 13.8e3
  )

// Generators
  PowerGrids.Examples.IEEE14bus.ControlledGeneratorIEEE GEN1(
    GEN(
      DPu = 0.0,
      H = 5.4,
      Tppd0 = 0.08,
      xpdPu = 0.384,
      Tpd0 = 8.094,
      raPu = 0.002796,
      xpqPu = 0.393,
      Tppq0 = 0.084,
      Tpq0 = 1.572,
      xppdPu = 0.264,
      xdPu = 2.22,
      xlPu = 0.202,
      xppqPu = 0.262,
      xqPu = 2.22,
      PNom = 1090e6,
      SNom = 1211e6,
      UNom = 24e3,
      PStart = -232.37e6,
      QStart = 15.7473e6,
      UStart = 25.4068e3,
      UPhaseStart = 0.0171006
    )
  )
  PowerGrids.Examples.IEEE14bus.ControlledGeneratorIEEE GEN2(
    GEN(
      DPu = 0.0,
      H = 5.4,
      Tppd0 = 0.058,
      xpdPu = 0.407,
      Tpd0 = 9.651,
      raPu = 0.00357,
      xpqPu = 0.454,
      Tppq0 = 0.06,
      Tpq0 = 1.009,
      xppdPu = 0.3,
      xdPu = 2.57,
      xlPu = 0.219,
      xppqPu = 0.301,
      xqPu = 2.57,
      PNom = 1008e6,
      SNom = 1120e6,
      UNom = 24e3,
      PStart = -40e6,
      QStart = -42.7306e6,
      UStart = 25.1608e3,
      UPhaseStart = -0.0837392
    )
  )
  PowerGrids.Examples.IEEE14bus.SynchronousCondenser GEN3(
    GEN(
      DPu = 0.0,
      H = 5.625,
      Tppd0 = 0.065,
      xpdPu = 0.509,
      Tpd0 = 10.041,
      raPu = 0.00316,
      xpqPu = 0.601,
      Tppq0 = 0.094,
      Tpq0 = 1.22,
      xppdPu = 0.354,
      xdPu = 2.81,
      xlPu = 0.256,
      xppqPu = 0.377,
      xqPu = 2.62,
      PNom = 1485e6,
      SNom = 1650e6,
      UNom = 20e3,
      PStart = 0.0,
      QStart = -25.3998e6,
      UStart = 20.229e3,
      UPhaseStart = -0.22231
    )
  )
  PowerGrids.Examples.IEEE14bus.SynchronousCondenser GEN6(
    GEN(
      xpqPu = 0.225,
      Tpq0 = 3.0,
      DPu = 0.0,
      H = 4.975,
      Tppd0 = 0.04,
      xpdPu = 0.225,
      Tpd0 = 3.0,
      raPu = 0.004,
      Tppq0 = 0.06,
      xppdPu = 0.154,
      xdPu = 0.75,
      xlPu = 0.102,
      xppqPu = 0.154,
      xqPu = 0.45,
      PNom = 71.8e6,
      SNom = 80.0e6,
      UNom = 13.8e3,
      PStart = 0,
      QStart = -15.0186e6,
      UStart = 14.7347e3,
      UPhaseStart = -0.249364
    )
  )
  PowerGrids.Examples.IEEE14bus.SynchronousCondenser GEN8(
    GEN(
      xpqPu = 0.31,
      Tpq0 = 8.4,
      DPu = 0.0,
      H = 2.748,
      Tppd0 = 0.096,
      xpdPu = 0.31,
      Tpd0 = 8.4,
      raPu = 0.004,
      Tppq0 = 0.1,
      xppdPu = 0.275,
      xdPu = 1.53,
      xlPu = 0.11,
      xppqPu = 0.346,
      xqPu = 0.99,
      PNom = 242e6,
      SNom = 250e6,
      UNom = 18e3,
      PStart = 0,
      QStart = -16.2253e6,
      UStart = 19.6461e3,
      UPhaseStart = -0.233851
    )
  )

equation
  connect(bus12.terminal, L6to12.terminalB)
  connect(L12to13.terminalA, bus12.terminal)
  connect(L12to13.terminalB, bus13.terminal)
  connect(L6to12.terminalA, bus6.terminal)
  connect(L6to13.terminalA, bus6.terminal)
  connect(L6to13.terminalB, bus13.terminal)
  connect(bus13.terminal, L6to13.terminalB)
  connect(L6to11.terminalA, bus6.terminal)
  connect(L6to11.terminalB, bus11.terminal)
  connect(L13to14.terminalA, bus13.terminal)
  connect(L13to14.terminalB, bus14.terminal)
  connect(L9to14.terminalB, bus14.terminal)
  connect(L9to14.terminalA, bus9.terminal)
  connect(L10to11.terminalB, bus11.terminal)
  connect(L10to11.terminalA, bus10.terminal)
  connect(L9to10.terminalB, bus10.terminal)
  connect(L9to10.terminalA, bus9.terminal)
  connect(L7to8.terminalA, bus7.terminal)
  connect(L7to9.terminalA, bus7.terminal)
  connect(L7to9.terminalB, bus9.terminal)
  connect(L7to8.terminalB, bus8.terminal)
  connect(T4to9.terminalA, bus4.terminal)
  connect(T4to9.terminalB, bus9.terminal)
  connect(T5to6.terminalB, bus6.terminal)
  connect(T5to6.terminalA, bus5.terminal)
  connect(L1to2.terminalA, bus1.terminal)
  connect(L1to2.terminalB, bus2.terminal)
  connect(L1to5.terminalA, bus1.terminal)
  connect(L1to5.terminalB, bus5.terminal)
  connect(L2to5.terminalB, bus5.terminal)
  connect(L4to5.terminalB, bus5.terminal)
  connect(L2to5.terminalA, bus2.terminal)
  connect(L2to4.terminalA, bus2.terminal)
  connect(L3to4.terminalB, bus4.terminal)
  connect(L3to4.terminalA, bus3.terminal)
  connect(L2to4.terminalB, bus4.terminal)
  connect(L4to5.terminalA, bus4.terminal)
  connect(L2to3.terminalB, bus3.terminal)
  connect(Tgen8.terminalB, bus8.terminal)
  connect(Tgen3.terminalB, bus3.terminal)
  connect(Tgen2.terminalB, bus2.terminal)
  connect(Tgen1.terminalB, bus1.terminal)
  connect(Load12.terminal, bus12.terminal)
  connect(bus13.terminal, Load13.terminal)
  connect(Load14.terminal, bus14.terminal)
  connect(Load11.terminal, bus11.terminal)
  connect(Load10.terminal, bus10.terminal)
  connect(Cbank9.terminal, bus9.terminal)
  connect(Load9.terminal, bus9.terminal)
  connect(Load6.terminal, bus6.terminal)
  connect(Load5.terminal, bus5.terminal)
  connect(Load3.terminal, bus3.terminal)
  connect(Load2.terminal, bus2.terminal)
  connect(L2to3.terminalA, bus2.terminal)
  connect(Tgen1.terminalA, GEN1.terminal)
  connect(GEN2.terminal, Tgen2.terminalA)
  connect(Tgen3.terminalA, GEN3.terminal)
  connect(GEN8.terminal, Tgen8.terminalA)
  connect(Load4.terminal, bus4.terminal)
  connect(GEN6.terminal, bus6.terminal)
  connect(T4to7.terminalA, bus4.terminal)
  connect(T4to7.terminalB, bus7.terminal)
  connect(GEN1.omega, systemPowerGrids.omegaRefIn)
end IEEE14busStaticNetwork;


Information

within PowerGrids.Examples.IEEE14bus;

package Info "Information"
  extends Modelica.Icons.Information;
end Info;


Classical IEEE14 bus network

within PowerGrids.Examples;
package IEEE14bus "Classical IEEE14 bus network"
  extends Modelica.Icons.ExamplesPackage;
end IEEE14bus;


Model of a synchronous condenser for the IEEE-14 bus system.

within PowerGrids.Examples.IEEE14bus;

model SynchronousCondenser "Model of a synchronous condenser for the IEEE-14 bus system"
  extends Icons.Machine;
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(portVariablesPhases = true)
  PowerGrids.Interfaces.TerminalAC terminal
  Electrical.Controls.ExcitationSystems.VRProportional AVR(Ka = 20, VcPuStart = GEN.UStart / GEN.UNom, VrMax = 5, VrMin = -5)
  Controls.FreeOffset VrefPu(use_u = true)
  Modelica.Blocks.Sources.RealExpression VrefPuDef(y = 1)
  Modelica.Blocks.Sources.RealExpression PmPu(y = 0)
  Modelica.Blocks.Interfaces.RealOutput omega
equation
  connect(GEN.terminal, terminal)
  connect(AVR.VcPu, GEN.VPu)
  connect(AVR.efdPu, GEN.ufPuIn)
  connect(VrefPu.y, AVR.VrefPu)
  connect(VrefPuDef.y, VrefPu.u)
  connect(GEN.omega, omega)
  connect(PmPu.y, GEN.PmPu)
end SynchronousCondenser;


within PowerGrids.Examples;

package Tutorial "Tutorial examples of increasing complexity"
  extends Modelica.Icons.ExamplesPackage;
end Tutorial;


Examples of grid-connected systems

within PowerGrids.Examples.Tutorial;
package GridOperation "Examples of grid-connected systems"
  extends Modelica.Icons.ExamplesPackage;
end GridOperation;


Model of a synchronous generator with governor, AVR, and PSS.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGenerator "Model of a synchronous generator with governor, AVR, and PSS"
  extends Icons.Machine;
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(PMechPuStart = -GEN.PStart / GEN.SNom,R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VcPuStart = GEN.UStart / GEN.UNom, VrMax = 4)
  Modelica.Blocks.Sources.RealExpression zero
  PowerGrids.Electrical.Controls.PowerSystemStabilizers.IEEE_PSS2A PSS(Ks1 = 10, Ks2 = 0.1564, M = 0, N = 0, T1 = 0.25, T2 = 0.03, T3 = 0.15, T4 = 0.015, T7 = 2, T8 = 0.5, T9 = 0.1, Tw1 = 2, Tw2 = 2, Tw3 = 2, Tw4 = 0, VstMax = 0.1, VstMin = -0.1)
  PowerGrids.Interfaces.TerminalAC terminal
  PowerGrids.Controls.FreeOffset RefLPu
  PowerGrids.Controls.FreeOffset VrefPu
  Modelica.Blocks.Interfaces.RealOutput omega "Angular frequency / (rad/s)"
equation
  connect(GEN.ufPuIn, AVR.efdPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.VPu, AVR.VcPu)
  connect(PSS.VstPu, AVR.VsPu)
  connect(PSS.Vsi2Pu, GEN.PPu)
  connect(GEN.terminal, terminal)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(VrefPu.y, AVR.VrefPu)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(AVR.VuelPu, zero.y)
  connect(GEN.omegaPu, PSS.Vsi1Pu)
  connect(GEN.omega, omega)
end ControlledGenerator;


Variant of ControlledGridWithPSS.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridParametersChange "Variant of ControlledGridWithPSS"
  extends Modelica.Icons.Example;
  extends Examples.Tutorial.GridOperation.Controlled.ControlledGridWithPSS(
    TGOV(T1 = 0.4 "Governor new time constant"),
    AVR(Ka = 210 "Overall new equivalent gain")
    );
end ControlledGridParametersChange;


System under automatic control with high-level controlled generator component.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridWithControlledGen "System under automatic control with high-level controlled generator component"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids(initOpt = PowerGrids.Types.Choices.InitializationOption.globalSteadyStateFixedPowerFlow)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.BusFault NTHV(R = 0.05,SNom = 5e+08, UNom = 380000, UPhaseStart = 0, UStart = 1.050 * 380e3,portVariablesPhases = true, portVariablesPu = true, startTime = 2, stopTime = 2.1)
  PowerGrids.Examples.Tutorial.GridOperation.Controlled.ControlledGenerator ctrlGEN(AVR(Ka = 150))
equation
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(ctrlGEN.terminal, NTLV.terminal)

end ControlledGridWithControlledGen;


System under automatic control without PSS.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridWithoutPSS "System under automatic control without PSS"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VrMax = 4)
  Modelica.Blocks.Sources.RealExpression zero
  Modelica.Blocks.Sources.RealExpression VrefPu(y = 1.004552)
  Modelica.Blocks.Sources.RealExpression RefLPu(y = 475 / 500 * 0.05)
  PowerGrids.Electrical.Buses.BusFault NTHV(R = 0.05,SNom = 5e+08, UNom = 380000, UPhaseStart = 0, UStart = 1.050 * 380e3,portVariablesPhases = true, portVariablesPu = true, startTime = 2, stopTime = 2.1)
equation
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(AVR.VrefPu, VrefPu.y)
  connect(AVR.VsPu, zero.y)
  connect(AVR.VuelPu, zero.y)
  connect(GEN.ufPuIn, AVR.efdPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.VPu, AVR.VcPu)
  connect(GEN.omegaPu, TGOV.omegaPu)
end ControlledGridWithoutPSS;


System under automatic control including PSS.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridWithPSS "System under automatic control including PSS"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VrMax = 4)
  Modelica.Blocks.Sources.RealExpression zero
  Modelica.Blocks.Sources.RealExpression VrefPu(y = 1.004552)
  Modelica.Blocks.Sources.RealExpression RefLPu(y = 475 / 500 * 0.05)
  PowerGrids.Electrical.Buses.BusFault NTHV(R = 0.05,SNom = 5e+08, UNom = 380000, UPhaseStart = 0, UStart = 1.050 * 380e3,portVariablesPhases = true, portVariablesPu = true, startTime = 2, stopTime = 2.1)
  PowerGrids.Electrical.Controls.PowerSystemStabilizers.IEEE_PSS2A PSS(Ks1 = 10, Ks2 = 0.1564, M = 0, N = 0, T1 = 0.25, T2 = 0.03, T3 = 0.15, T4 = 0.015, T7 = 2, T8 = 0.5, T9 = 0.1, Tw1 = 2, Tw2 = 2, Tw3 = 2, Tw4 = 0, VstMax = 0.1, VstMin = -0.1)
equation
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(AVR.VrefPu, VrefPu.y)
  connect(AVR.VuelPu, zero.y)
  connect(GEN.ufPuIn, AVR.efdPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.VPu, AVR.VcPu)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(PSS.VstPu, AVR.VsPu)
  connect(PSS.Vsi1Pu, GEN.omegaPu)
  connect(PSS.Vsi2Pu, GEN.PPu)

end ControlledGridWithPSS;


System under automatic control with automatic computation of set point offsets.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridWithReferenceCalculation "System under automatic control with automatic computation of set point offsets"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids(initOpt = PowerGrids.Types.Choices.InitializationOption.globalSteadyStateFixedPowerFlow)
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.TurbineGovernors.IEEE_TGOV1 TGOV(PMechPuStart = -GEN.PStart / GEN.SNom,R = 0.05, T1 = 0.5, T2 = 3, T3 = 10, VMax = 1)
  PowerGrids.Electrical.Controls.ExcitationSystems.IEEE_AC4A AVR(Ka = 200, Ta = 0.05, Tb = 10, Tc = 3, VcPuStart = GEN.UStart/GEN.UNom, VrMax = 4)
  Modelica.Blocks.Sources.RealExpression zero
  PowerGrids.Electrical.Buses.Bus NTHV(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Controls.PowerSystemStabilizers.IEEE_PSS2A PSS(Ks1 = 10, Ks2 = 0.1564, M = 0, N = 0, T1 = 0.25, T2 = 0.03, T3 = 0.15, T4 = 0.015, T7 = 2, T8 = 0.5, T9 = 0.1, Tw1 = 2, Tw2 = 2, Tw3 = 2, Tw4 = 0, VstMax = 0.1, VstMin = -0.1)
  PowerGrids.Controls.FreeOffset RefLPu
  PowerGrids.Controls.FreeOffset VrefPu(use_u = true)
  Modelica.Blocks.Sources.RealExpression deltaVrefPu(y=if time >= 2 then 3e3*sin(2*Modelica.Constants.pi * 0.05 *(time-2))/GEN.UNom else 0)

  Real VrefPuTot = deltaVrefPu.y + GEN.VStartPu;

equation
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(AVR.VuelPu, zero.y)
  connect(GEN.ufPuIn, AVR.efdPu)
  connect(TGOV.PMechPu, GEN.PmPu)
  connect(GEN.VPu, AVR.VcPu)
  connect(GEN.omegaPu, TGOV.omegaPu)
  connect(PSS.VstPu, AVR.VsPu)
  connect(PSS.Vsi1Pu, GEN.omegaPu)
  connect(PSS.Vsi2Pu, GEN.PPu)
  connect(VrefPu.y, AVR.VrefPu)
  connect(RefLPu.y, TGOV.RefLPu)
  connect(deltaVrefPu.y, VrefPu.u)
end ControlledGridWithReferenceCalculation;


System under automatic control with automatic computation of set point offsets - saturation case.

within PowerGrids.Examples.Tutorial.GridOperation.Controlled;
model ControlledGridWithReferenceCalculationSat "System under automatic control with automatic computation of set point offsets - saturation case"
  extends ControlledGridWithReferenceCalculation(AVR.VrMax = 0.5);
end ControlledGridWithReferenceCalculationSat;


within PowerGrids.Examples.Tutorial.GridOperation;
package Controlled "Models of grid-connected systems with generator controllers"
  extends Modelica.Icons.ExamplesPackage;
end Controlled;


Load step response specified by input signals.

within PowerGrids.Examples.Tutorial.GridOperation.LoadChange;
model LoadChangeByInputSignals "Load step response specified by input signals"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.BusFault NTHV(R = 0.05,SNom = 5e+08, UNom = 380000, UPhaseStart = 0, UStart = 1.050 * 380e3,portVariablesPhases = true, portVariablesPu = true, startTime = 1e10, stopTime = 1e10)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQInputs GRIDL(SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu(y = -GEN.PStart / GEN.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn(y = GEN.ufPuInStart)
  Modelica.Blocks.Sources.Step PRef(height = 475e6 * 0.05, offset = 475e6, startTime = 2)
  Modelica.Blocks.Sources.Step QRef(height = 76e6 * 0.04, offset = 76e6, startTime = 2)
equation
  connect(PmPu.y, GEN.PmPu)
  connect(ufPuIn.y, GEN.ufPuIn)
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(NTHV.terminal, GRIDL.terminal)
  connect(PRef.y, GRIDL.PRefIn)
  connect(QRef.y, GRIDL.QRefIn)
end LoadChangeByInputSignals;


Load step response specified by modifiers on a copy of the static system.

within PowerGrids.Examples.Tutorial.GridOperation.LoadChange;
model LoadChangeByModifier "Load step response specified by modifiers on a copy of the static system"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(
      PRef = 4.75e+08*(if time < 2 then 1 else 1.05) "Active power consumption at reference voltage",
      QRef = 7.6e+07*(if time < 2 then 1 else 1.04) "Reactive power consumption at reference voltage",
      SNom = 5e+08,
      UNom = 380000,
      URef = 1.05 * 380e3,
      portVariablesPhases = true,
      portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu(y = -GEN.PStart / GEN.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn(y = GEN.ufPuInStart)

equation
  connect(PmPu.y, GEN.PmPu)
  connect(ufPuIn.y, GEN.ufPuIn)
  connect(GRIDL.terminal, NTHV.terminal)
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
end LoadChangeByModifier;


Load step response specified by modifiers by inheritance from the static system.

within PowerGrids.Examples.Tutorial.GridOperation.LoadChange;
model LoadChangeByModifierUsingExtends "Load step response specified by modifiers by inheritance from the static system"
  extends Examples.Tutorial.GridOperation.Static.StaticGridComputedParameters(
    GRIDL(
      PRef = GRIDL.PRefConst*(if time < 2 then 1 else 1.05) "Active power consumption at reference voltage",
      QRef = GRIDL.QRefConst*(if time < 2 then 1 else 1.04) "Reactive power consumption at reference voltage"));
end LoadChangeByModifierUsingExtends;


within PowerGrids.Examples.Tutorial.GridOperation;
package LoadChange "Models of grid-connected systems subject to open-loop load changes"
  extends Modelica.Icons.ExamplesPackage;
end LoadChange;


within PowerGrids.Examples.Tutorial.GridOperation;
package Static "Models of grid-connected systems operating in steady-state"
  extends Modelica.Icons.ExamplesPackage;
end Static;


Power flow for the basic grid used in the tutorial.

within PowerGrids.Examples.Tutorial.GridOperation.Static;
model PowerFlow "Power flow for the basic grid used in the tutorial"
  extends Modelica.Icons.Example;
  PowerGrids.Electrical.PowerFlow.PVBus GEN(P = -4.75e+8, SNom = 5e+8, U = 20825.8, UNom = 21000, generatorConvention = false, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+8, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+8, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.Bus NTHV(SNom = 5e+8, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.PowerFlow.PQBus GRIDL(P = 4.75e+8, Q = 7.6e+7, SNom = 5e+8, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.PowerFlow.SlackBus GRID(SNom = 5e+8, U = 399000, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
equation
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
  connect(GRIDL.terminal, NTHV.terminal)
end PowerFlow;


System operating in steady-state with given inputs.

within PowerGrids.Examples.Tutorial.GridOperation.Static;
model StaticGrid "System operating in steady-state with given inputs"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, UPhaseStart = 0, URef = 1.05 * 380e3, UStart = 399000, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu(y = 0.95)
  Modelica.Blocks.Sources.RealExpression ufPuIn(y = 2.50826)
equation
  connect(PmPu.y, GEN.PmPu)
  connect(ufPuIn.y, GEN.ufPuIn)
  connect(GRIDL.terminal, NTHV.terminal)
  connect(GEN.terminal, NTLV.terminal)
  connect(NTLV.terminal, TGEN.terminalA)
  connect(TGEN.terminalB, NTHV.terminal)
  connect(NTHV.terminal, GRID.terminal)
end StaticGrid;


System operating in steady-state with computed inputs.

within PowerGrids.Examples.Tutorial.GridOperation.Static;
model StaticGridComputedParameters "System operating in steady-state with computed inputs"
  extends StaticGrid(
    PmPu(y = -GEN.PStart / GEN.SNom),
    ufPuIn(y = GEN.ufPuInStart));
end StaticGridComputedParameters;


Systems operating in steady-state with different generator parameterss.

within PowerGrids.Examples.Tutorial.GridOperation.Static;
model StaticGridDifferentGeneratorParam "Systems operating in steady-state with different generator parameterss"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids

// First Grid
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN_1(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV_1(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_1(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_1(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_1(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_1(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_1(y = -GEN_1.PStart / GEN_1.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn_1(y = GEN_1.ufPuInStart)
  // Second Grid - Transformer nominal voltage changed
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN_2(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, excitationPuType = PowerGrids.Types.Choices.ExcitationPuType.Kundur, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV_2(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_2(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_2(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_2(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_2(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_2(y = -GEN_2.PStart / GEN_2.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn_2(y = GEN_2.ufPuInStart)

// Third Grid - Generator Nominal Voltage changed
  PowerGrids.Electrical.Machines.SynchronousMachine4WindingsInternalParameters GEN_3(H = 4, LDPu = 0.2, LQ1Pu = 0.444231, LQ2Pu = 0.2625, LdPu = 0.15, LfPu = 0.224242, LqPu = 0.15, MdPu = 1.85, MqPu = 1.65, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, mrcPu = 0, portVariablesPhases = true, rDPu = 0.0303152, rQ1Pu = 0.00308618, rQ2Pu = 0.0234897, raPu = 0, rfPu = 0.00128379)
  PowerGrids.Electrical.Buses.Bus NTLV_3(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_3(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_3(PStartA = 4.75e+08, PStartB = -4.75e+08, QStartA = 1.56e+08, QStartB = -7.6e+07, R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, UPhaseStartA = 0.161156, UPhaseStartB = 0, UStartA = 0.9917 * 21e3, UStartB = 0.95227 * 380e3, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_3(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_3(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_3(y = 0.95)
  Modelica.Blocks.Sources.RealExpression ufPuIn_3(y = 2.50826)
equation
  connect(PmPu_1.y, GEN_1.PmPu)
  connect(ufPuIn_1.y, GEN_1.ufPuIn)
  connect(PmPu_2.y, GEN_2.PmPu)
  connect(ufPuIn_2.y, GEN_2.ufPuIn)
  connect(PmPu_3.y, GEN_3.PmPu)
  connect(ufPuIn_3.y, GEN_3.ufPuIn)
  connect(GEN_1.terminal, NTLV_1.terminal)
  connect(NTLV_1.terminal, TGEN_1.terminalA)
  connect(TGEN_1.terminalB, NTHV_1.terminal)
  connect(NTHV_1.terminal, GRID_1.terminal)
  connect(NTHV_1.terminal, GRIDL_1.terminal)
  connect(GEN_2.terminal, NTLV_2.terminal)
  connect(NTLV_2.terminal, TGEN_2.terminalA)
  connect(TGEN_2.terminalB, NTHV_2.terminal)
  connect(NTHV_2.terminal, GRID_2.terminal)
  connect(GEN_3.terminal, NTLV_3.terminal)
  connect(NTLV_3.terminal, TGEN_3.terminalA)
  connect(TGEN_3.terminalB, NTHV_3.terminal)
  connect(NTHV_3.terminal, GRID_3.terminal)
  connect(GRIDL_2.terminal, NTHV_2.terminal)
  connect(GRIDL_3.terminal, NTHV_3.terminal)
end StaticGridDifferentGeneratorParam;


Systems operating in steady-state with different nominal values.

within PowerGrids.Examples.Tutorial.GridOperation.Static;
model StaticGridDifferentNominals "Systems operating in steady-state with different nominal values"
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids

// First System
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN_1(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV_1(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_1(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_1( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_1(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_1(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, UPhaseStart = 0, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_1(y = -GEN_1.PStart / GEN_1.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn_1(y = GEN_1.ufPuInStart)
  // Second System - Transformer nominal voltage changed
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN_2(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 21000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV_2(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_2(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_2( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 100000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_2(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_2(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, UPhaseStart = 0, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_2(y = -GEN_2.PStart / GEN_2.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn_2(y = GEN_2.ufPuInStart)

// Third System - Generator Nominal Voltage changed
  PowerGrids.Electrical.Machines.SynchronousMachine4Windings GEN_3(H = 4, PStart = -4.75e+08, QStart = -1.56e+08,SNom = 5e+08, Tpd0 = 5.143, Tppd0 = 0.042, Tppq0 = 0.083, Tpq0 = 2.16, UNom = 10000, UPhaseStart = 0.161156, UStart = 21e3 * 0.9917, portVariablesPhases = true, raPu = 0, xdPu = 2, xlPu = 0.15, xpdPu = 0.35, xppdPu = 0.25, xppqPu = 0.3, xpqPu = 0.5, xqPu = 1.8)
  PowerGrids.Electrical.Buses.Bus NTLV_3(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV_3(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN_3( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Buses.EquivalentGrid GRID_3(R_X = 1 / 10, SNom = 5e+08, SSC = 2.5e+09, UNom = 380000, URef = 1.05 * 380e3, c = 1.1, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL_3(PRefConst = 4.75e+08, QRefConst = 7.6e+07, SNom = 5e+08, UNom = 380000, UPhaseStart = 0, URef = 1.05 * 380e3, portVariablesPhases = true, portVariablesPu = true)
  Modelica.Blocks.Sources.RealExpression PmPu_3(y = -GEN_3.PStart / GEN_3.SNom)
  Modelica.Blocks.Sources.RealExpression ufPuIn_3(y = GEN_3.ufPuInStart)
equation
  connect(PmPu_1.y, GEN_1.PmPu)
  connect(ufPuIn_1.y, GEN_1.ufPuIn)
  connect(PmPu_2.y, GEN_2.PmPu)
  connect(PmPu_3.y, GEN_3.PmPu)
  connect(GEN_1.terminal, NTLV_1.terminal)
  connect(NTLV_1.terminal, TGEN_1.terminalA)
  connect(TGEN_1.terminalB, NTHV_1.terminal)
  connect(NTHV_1.terminal, GRID_1.terminal)
  connect(NTHV_1.terminal, GRIDL_1.terminal)
  connect(GEN_2.terminal, NTLV_2.terminal)
  connect(NTLV_2.terminal, TGEN_2.terminalA)
  connect(TGEN_2.terminalB, NTHV_2.terminal)
  connect(NTHV_2.terminal, GRID_2.terminal)
  connect(NTHV_2.terminal, GRIDL_2.terminal)
  connect(GEN_3.terminal, NTLV_3.terminal)
  connect(NTLV_3.terminal, TGEN_3.terminalA)
  connect(TGEN_3.terminalB, NTHV_3.terminal)
  connect(NTHV_3.terminal, GRID_3.terminal)
  connect(NTHV_3.terminal, GRIDL_3.terminal)
  connect(GEN_2.ufPuIn, ufPuIn_2.y)
  connect(GEN_3.ufPuIn, ufPuIn_3.y)
end StaticGridDifferentNominals;


Examples of islanded systems

within PowerGrids.Examples.Tutorial;
package IslandOperation "Examples of islanded systems"
  extends Modelica.Icons.ExamplesPackage;
end IslandOperation;


within PowerGrids.Examples.Tutorial.IslandOperation;

model PowerFlow
  extends Modelica.Icons.Example;
  PowerGrids.Electrical.PowerFlow.PVBus GEN1(P = -4.5088e+08, SNom = 5e+08, U = 20825, UNom = 21000)
  PowerGrids.Electrical.PowerFlow.PVBus GEN2(P = -4.5088e+08, SNom = 5e+08, U = 20825, UNom = 21000)
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence GRIDL1(PRefConst = 4.5e+08, QRefConst = 200e6, SNom = 5e+08, UNom = 380000, portVariablesPhases = true)
  PowerGrids.Electrical.Loads.LoadImpedancePQ GRIDL2(PRefConst = 4.5e+08, QRefConst = 200e6, SNom = 5e+08, UNom = 380000, portVariablesPhases = true)
  PowerGrids.Electrical.Buses.Bus NTLV1(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN1(R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.PowerFlow.SlackBus NTHV1(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.LineConstantImpedance LINE(R = 10, SNom = 5e+8, UNom = 380000, X = 100, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.Bus NTHV2(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN2(R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  inner Electrical.System systemPowerGrids
equation
  connect(NTLV1.terminal, TGEN1.terminalA)
  connect(TGEN1.terminalB, NTHV1.terminal)
  connect(NTHV1.terminal, GRIDL1.terminal)
  connect(GEN1.terminal, NTLV1.terminal)
  connect(LINE.terminalA, NTHV1.terminal)
  connect(LINE.terminalB, NTHV2.terminal)
  connect(NTHV2.terminal, GRIDL2.terminal)
  connect(NTHV2.terminal, TGEN2.terminalB)
  connect(TGEN2.terminalA, GEN2.terminal)
end PowerFlow;


--tearingMethod=minimalTearing.

within PowerGrids.Examples.Tutorial.IslandOperation;

model TwoGeneratorsFixedFrequencyReference
  extends TwoGeneratorsOneReferenceGenerator(systemPowerGrids.referenceFrequency = PowerGrids.Types.Choices.ReferenceFrequency.nominalFrequency);
end TwoGeneratorsFixedFrequencyReference;


--tearingMethod=minimalTearing.

within PowerGrids.Examples.Tutorial.IslandOperation;

model TwoGeneratorsLocalInitialization
  extends PowerGrids.Examples.Tutorial.IslandOperation.TwoGeneratorsOneReferenceGenerator(systemPowerGrids.initOpt = PowerGrids.Types.Choices.InitializationOption.localSteadyStateFixedPowerFlow);
equation
end TwoGeneratorsLocalInitialization;


--tearingMethod=minimalTearing.

within PowerGrids.Examples.Tutorial.IslandOperation;

model TwoGeneratorsOneReferenceGenerator
  extends Modelica.Icons.Example;
  inner PowerGrids.Electrical.System systemPowerGrids(initOpt = PowerGrids.Types.Choices.InitializationOption.globalSteadyStateFixedPowerFlow, referenceFrequency = PowerGrids.Types.Choices.ReferenceFrequency.fixedReferenceGenerator)
  PowerGrids.Electrical.Buses.Bus NTLV1(SNom = 5e+08, UNom = 21000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Buses.ReferenceBus NTHV1(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN1(R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Electrical.Branches.TransformerFixedRatio TGEN2( R = 0.15e-2 * 419 ^ 2 / 500, SNom = 5e+08, UNomA = 21000, UNomB = 419000, X = 16e-2 * 419 ^ 2 / 500, portVariablesPhases = true, portVariablesPu = true, rFixed = 419 / 21)
  PowerGrids.Examples.Tutorial.GridOperation.Controlled.ControlledGenerator GEN1(GEN(UNom = 21e3, SNom = 500e6, UStart = 20.825e3, UPhaseStart = 9.1746/180*3.14159, PStart = -450.88e6, QStart = -294.351e6), TGOV(R = 0.05))
  PowerGrids.Electrical.Branches.LineConstantImpedance LINE( R = 10, SNom = 5e+8, UNom = 380000, UPhaseStartA = 0, X = 100, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Examples.Tutorial.GridOperation.Controlled.ControlledGenerator GEN2(GEN(UNom = 21e3, SNom = 500e6, UStart = 20.825e3, UPhaseStart = 9.1746/180*3.14159, PStart = -450.88e6, QStart = -294.351e6), TGOV(R = 0.05))
  PowerGrids.Electrical.Buses.Bus NTHV2(SNom = 5e+08, UNom = 380000, portVariablesPhases = true, portVariablesPu = true)
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence GRIDL1(PRef = 450e6 + (if time < 1 then 0 else -100e6), PRefConst = 4.5e+08, QRefConst = 200e6, SNom = 500e6, UNom = 380000, portVariablesPhases = true)
  PowerGrids.Electrical.Loads.LoadPQVoltageDependence GRIDL2(PRefConst = 4.5e+08, QRefConst = 200e6, SNom = 500e6, UNom = 380000, portVariablesPhases = true)
equation
  connect(NTLV1.terminal, TGEN1.terminalA)
  connect(TGEN1.terminalB, NTHV1.terminal)
  connect(NTHV1.terminal, GRIDL1.terminal)
  connect(GEN1.terminal, NTLV1.terminal)
  connect(LINE.terminalA, NTHV1.terminal)
  connect(LINE.terminalB, NTHV2.terminal)
  connect(NTHV2.terminal, GRIDL2.terminal)
  connect(NTHV2.terminal, TGEN2.terminalB)
  connect(TGEN2.terminalA, GEN2.terminal)
  connect(GEN2.omega, systemPowerGrids.omegaRefIn)
end TwoGeneratorsOneReferenceGenerator;


Custom functions

within PowerGrids;

package Functions "Custom functions"
  extends Modelica.Icons.UtilitiesPackage;
end Functions;


Computes the time constants of 1 + 8s + 15 = (1+3s)(1+5s)

within PowerGrids.Functions;

package Test
  extends Modelica.Icons.ExamplesPackage;

  model TestTimeConstants
    extends Modelica.Icons.Example;
    Real T1 = largerTimeConstant(8, 15);
    Real T2 = smallerTimeConstant(8, 15);
  end TestTimeConstants;

end Test;


Interfaces package

within PowerGrids;

package Interfaces "Interfaces package"
  extends Modelica.Icons.InterfacesPackage;

  connector TerminalAC "Terminal for phasor-based AC connections"
    Types.ComplexVoltage v "Phase-to-ground voltage phasor";
    flow Types.ComplexCurrent i "Line current phasor";
  end TerminalAC;

end Interfaces;


Breakers

within PowerSystems.AC1ph_DC;
package Breakers "Breakers "
  extends Modelica.Icons.VariantsPackage;

  model ForcedSwitch "Forced switch, 1-phase"
    extends Partials.SwitchBase;

    parameter SI.Time t_relax=10e-3 "switch relaxation time";
    parameter Integer p_relax(min=2)=4 "power of relaxation exponent";
  protected
    SI.Time t0(start=-Modelica.Constants.inf, fixed=true);
    Real[2] r(start={0,1});
    Real s;
  /*
  Boolean open(start=not control)=not control;
  Boolean closed(start=control)=control;

  Start values not correct, since no parameter expressions.
  Removed start values and initalized the pre(..) values in the
  initial equation section.
*/
    Boolean open = not control;
    Boolean closed = control;

    function relaxation=Utilities.Math.relaxation;

  initial equation
    pre(open) = not control;
    pre(closed) = control;
  equation
    when edge(open) or edge(closed) then
      t0 = time;
    end when;
    r = relaxation(time - t0, t_relax, p_relax);
    {v,i} = if closed then {(r[1]+r[2]*epsR)*s,(r[1]*epsG+r[2])*s} else {(r[1]*epsR+r[2])*s,(r[1]+r[2]*epsG)*s};
  end ForcedSwitch;

  model ForcedCommSwitch "Forced commuting switch, 1-phase"
    extends Common.Nominal.NominalVI;
    extends Ports.PortBase;

    parameter Real[2] eps(final min={0,0}, each unit="1")={1e-4,1e-4}
      "{resistance 'closed', conductance 'open'}";
    parameter SI.Time t_relax=10e-3 "switch relaxation time";
    parameter Integer p_relax(min=2)=4 "power of relaxation exponent";
    PS.Voltage[2] v_t;
    PS.Voltage[2] v_f;
    PS.Current[2] i_t;
    PS.Current[2] i_f;

    Ports.TwoPin_p term_p "positive terminal"
    Ports.TwoPin_n term_nt "negative terminal"
    Ports.TwoPin_n term_nf "negative terminal"
    Modelica.Blocks.Interfaces.BooleanInput control
      "true: p - nt closed, false: p - nf closed"
  protected
    final parameter SI.Resistance epsR=eps[1]*V_nom/I_nom;
    final parameter SI.Conductance epsG=eps[2]*I_nom/V_nom;
    SI.Time t0(start=-Modelica.Constants.inf, fixed=true);
    Real[2] r(start={0,1});
    Real[2] s_t;
    Real[2] s_f;
  /*
  Boolean open_t(start=not control)=not control;
  Boolean closed_t(start=control)=control;

  Start values not correct, since no parameter expressions.
  Removed start values and initalized the pre(..) values in the
  initial equation section.
*/
    Boolean open_t = not control;
    Boolean closed_t = control;

    function relaxation=Utilities.Math.relaxation;

  initial equation
    pre(open_t) = not control;
    pre(closed_t) = control;
  equation
    v_t = term_p.v - term_nt.v;
    v_f = term_p.v - term_nf.v;
    term_nt.i = - i_t;
    term_nf.i = - i_f;
    term_p.i + term_nt.i + term_nf.i = zeros(2);

    when edge(open_t) or edge(closed_t) then
      t0 = time;
    end when;
    r = relaxation(time - t0, t_relax, p_relax);
    {v_t,i_t} = if closed_t then {(r[1]+r[2]*epsR)*s_t,(r[1]*epsG+r[2])*s_t} else {(r[1]*epsR+r[2])*s_t,(r[1]+r[2]*epsG)*s_t};
    {v_f,i_f} = if open_t then {(r[1]+r[2]*epsR)*s_f,(r[1]*epsG+r[2])*s_f} else {(r[1]*epsR+r[2])*s_f,(r[1]+r[2]*epsG)*s_f};
  end ForcedCommSwitch;

  model Switch "Ideal switch, 1-phase"
    extends Partials.SwitchBase;

  protected
    Common.Switching.Switch switch_1(
      epsR=epsR,
      epsG=epsG)

  equation
    switch_1.v = v;
    switch_1.i = i;
    connect(control, switch_1.closed)
  end Switch;

  model Breaker "Breaker, 1-phase"
    extends Partials.SwitchBase;

    replaceable parameter Parameters.BreakerArc par "breaker parameter"
  protected
    Common.Switching.Breaker breaker_1(
      D=par.D,
      t_opening=par.t_opening,
      Earc=par.Earc,
      R0=par.R0,
      epsR=epsR,
      epsG=epsG)

  equation
    breaker_1.v = v;
    breaker_1.i = i;
    connect(control, breaker_1.closed)
  end Breaker;

  model ForcedDoubleSwitch "Forced double switch, 1-phase"
    extends Partials.DoubleSwitchBase;

    parameter SI.Time t_relax=10e-3 "switch relaxation time";
    parameter Integer p_relax(min=2)=4 "power of relaxation exponent";
  protected
    SI.Time[2] t0(start=-{Modelica.Constants.inf,Modelica.Constants.inf}, fixed=true);
    Real[2] r_1(start={0,1});
    Real[2] r_2(start={0,1});
    Real[2] s;
  /*
  Boolean[2] open(start={not control[1],not control[2]})={not control[1],not control[2]};
  Boolean[2] closed(start={control[1],control[2]})={control[1],control[2]};

  Start values not correct, since no parameter expressions.
  Removed start values and initalized the pre(..) values in the
  initial equation section.
*/
    Boolean[2] open = {not control[1],not control[2]};
    Boolean[2] closed = {control[1],control[2]};

    function relaxation=Utilities.Math.relaxation;

  initial equation
    pre(open) = {not control[1],not control[2]};
    pre(closed) = {control[1],control[2]};
  equation
    when edge(open[1]) or edge(closed[1]) then
      t0[1] = time;
    end when;
    when edge(open[2]) or edge(closed[2]) then
      t0[2] = time;
    end when;
    r_1 = relaxation(time - t0[1], t_relax, p_relax);
    r_2 = relaxation(time - t0[2], t_relax, p_relax);
    {v[1],i[1]} = if closed[1] then {(r_1[1]+r_1[2]*epsR)*s[1],(r_1[1]*epsG+r_1[2])*s[1]} else {(r_1[1]*epsR+r_1[2])*s[1],(r_1[1]+r_1[2]*epsG)*s[1]};
    {v[2],i[2]} = if closed[2] then {(r_2[1]+r_2[2]*epsR)*s[2],(r_2[1]*epsG+r_2[2])*s[2]} else {(r_2[1]*epsR+r_2[2])*s[2],(r_2[1]+r_2[2]*epsG)*s[2]};
  end ForcedDoubleSwitch;

  model DoubleSwitch "Double switch, 1-phase"
    extends Partials.DoubleSwitchBase;

  protected
    Common.Switching.Switch switch_1(
      epsR=epsR,
      epsG=epsG)
    Common.Switching.Switch switch_2(
      epsR=epsR,
      epsG=epsG)

  equation
    switch_1.v = v[1];
    switch_1.i = i[1];
    switch_2.v = v[2];
    switch_2.i = i[2];
    connect(control[1], switch_1.closed)
    connect(control[2], switch_2.closed)
  end DoubleSwitch;

  model DoubleBreaker "Double breaker, 1-phase"
    extends Partials.DoubleSwitchBase;

    replaceable parameter Parameters.BreakerArc par "breaker parameter"
  protected
    replaceable Common.Switching.Breaker breaker_1(
      D=par.D,
      t_opening=par.t_opening,
      Earc=par.Earc,
      R0=par.R0,
      epsR=epsR,
      epsG=epsG)
    replaceable Common.Switching.Breaker breaker_2(
      D=par.D,
      t_opening=par.t_opening,
      Earc=par.Earc,
      R0=par.R0,
      epsR=epsR,
      epsG=epsG)

  equation
    breaker_1.v = v[1];
    breaker_1.i = i[1];
    breaker_2.v = v[2];
    breaker_2.i = i[2];
    connect(control[1], breaker_1.closed)
    connect(control[2], breaker_2.closed)
  end DoubleBreaker;

  package Partials "Partial models"
    extends Modelica.Icons.BasesPackage;

     partial model SwitchBase0 "Switch base, 1-phase"
       extends Ports.Port_pn;
       extends Common.Nominal.NominalVI;

       parameter Real[2] eps(final min={0,0}, each unit="1")={1e-4,1e-4}
        "{resistance 'closed', conductance 'open'}";
    protected
       final parameter SI.Resistance epsR=eps[1]*V_nom/I_nom;
       final parameter SI.Conductance epsG=eps[2]*I_nom/V_nom;
     end SwitchBase0;

    partial model SwitchBase "Switch base, 1-phase"
      extends SwitchBase0;

      PS.Voltage v;
      PS.Current i;
      Modelica.Blocks.Interfaces.BooleanInput control "true:closed, false:open"

    equation
      v = term_p.v[1] - term_n.v[1];
      i = term_p.i[1];
      term_p.v[2] = term_n.v[2];
    end SwitchBase;

    partial model DoubleSwitchBase "Double switch base, 1-phase"
      extends SwitchBase0;

      PS.Voltage[2] v;
      PS.Current[2] i;
      Modelica.Blocks.Interfaces.BooleanInput[2] control
        "true:closed, false:open"

    equation
      v = term_p.v - term_n.v;
      i = term_p.i;
    end DoubleSwitchBase;

  end Partials;

package Parameters "Parameter data for interactive use"
  extends Modelica.Icons.MaterialPropertiesPackage;

record BreakerArc "Breaker parameters, 3-phase"
  extends Modelica.Icons.Record;

  SI.Distance D=50e-3 "contact distance open"
  SI.Time t_opening=30e-3 "opening duration"
  SI.ElectricFieldStrength Earc=50e3 "electric field arc"
  Real R0=1 "small signal resistance arc"
end BreakerArc;
end Parameters;
end Breakers;


DC-drives

within PowerSystems.AC1ph_DC;
package Drives "DC-drives"
  extends Modelica.Icons.VariantsPackage;

  model DCMser "DC machine, series connected"
    extends Partials.DriveBase(heat(final m=2));

    replaceable model Motor = PowerSystems.AC1ph_DC.Machines.DCser
      "DC motor series"
    Motor motor "DC motor series"

  equation
    connect(motor.heat, heat)
    connect(motor.airgap, rotor.rotor)
    connect(term, motor.term)
  end DCMser;

  model DCMpar "DC machine, parallel connected"
    extends Partials.DriveBase(heat(final m=2));

    replaceable model Motor = PowerSystems.AC1ph_DC.Machines.DCpar
      "DC motor parallel"
    Motor motor "DC motor parallel"
    AC1ph_DC.Ports.TwoPin_p field

  equation
    connect(motor.heat, heat)
    connect(motor.airgap, rotor.rotor)
    connect(term, motor.term)
    connect(field, motor.field)
  end DCMpar;

  model DCMpm "DC machine, permanent magnet"
    extends Partials.DriveBase(heat(final m=2));

    replaceable model Motor = PowerSystems.AC1ph_DC.Machines.DCpm
      "DC motor magnet"
    Motor motor "DC motor magnet"

  equation
    connect(motor.heat, heat)
    connect(motor.airgap, rotor.rotor)
    connect(term, motor.term)
  end DCMpm;

  model BLDC "BLDC machine"
    extends Partials.DriveBase(heat(final m=sum(heat_adapt.m)));

    replaceable model Inverter = PowerSystems.AC3ph.Inverters.InverterAverage (
      modulation=3) constrainedby
      PowerSystems.AC3ph.Inverters.Partials.AC_DC_base
      "inverter (average or modulated)"
    Inverter inverter "inverter (average or modulated)"
    replaceable model Motor =
      PowerSystems.AC1ph_DC.Drives.Partials.Synchron3rd_bldc
      "BLDC motor (syn pm machine)"
    Motor motor "BLDC motor (syn pm machine)"
    Common.Thermal.HeatV_a_b_ab heat_adapt(final m={2,inverter.heat.m})

  equation
    connect(motor.heat, heat_adapt.port_a)
    connect(inverter.heat, heat_adapt.port_b)
    connect(heat_adapt.port_ab, heat)
    connect(motor.airgap, rotor.rotor)
    connect(term, inverter.DC)
    connect(inverter.AC, motor.term)
    connect(motor.rotorAngle, inverter.theta)
    connect(motor.vPhasor,inverter.vPhasor)
  end BLDC;

  package Partials "Partial models"
    extends Modelica.Icons.BasesPackage;

  partial model DriveBase "DC drives base"

    parameter SI.AngularVelocity  w_start = 0
        "initial rpm (start-value if steady init)"
    AC1ph_DC.Ports.TwoPin_p term "electric terminal"
    Interfaces.Rotation_n flange "mechanical flange"
    replaceable model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor
        "machine rotor"
    Rotor rotor(w(start=w_start)) "machine rotor"
    replaceable model Gear = PowerSystems.Mechanics.Rotational.NoGear
        "type of gear"
    Gear gear "type of gear"
    Interfaces.ThermalV_n heat(     m=2) "heat source port {stator, rotor}"
    protected
    outer System system;

  equation
    connect(rotor.flange_b,gear.flange_a)
    connect(gear.flange_b, flange)
  end DriveBase;

  model Synchron3rd_bldc
      "Synchronous machine, torque-control, 3rd order model, 3-phase dq0"
    extends AC3ph.Machines.Synchron3rd_pm(i_s(start={0,1,0}));

    Modelica.Blocks.Interfaces.RealOutput rotorAngle=
                      phi_el "rotor angle el"
    Modelica.Blocks.Interfaces.RealOutput[2] vPhasor
        "desired {abs(u), phase(u)}"

  equation
    vPhasor[1] = 1; //not used if no PWM
    vPhasor[2] = atan2(c.R_s*i_s[2] + w_el*psi_e, -w_el*c.L_s[2]*i_s[2]);
  v_sq = 1;
  vPhasor[1] = sqrt(v_sd*v_sd + v_sq*v_sq);
  vPhasor[2] = atan2(v_sq, v_sd);

For reluctance (<tt>excite=3</tt>) machines psi_e is replaced by a desired magnetising current in d-axis <tt>i_sd</tt>.

  vPhasor[2] = atan2(c.R_s*i_s[2] + w_el*c.L_s[1]*i_sd, c.R_s*i_sd - w_el*c.L_s[2]*i_s[2]);

Using a pu-current <tt>i_sd_pu</tt> we obtain

  vPhasor[2] = atan2(c.R_s*i_s[2] + w_el*c.L_s[1]*i_sd, (par.V_nom/(c.omega_nom*c.L_s[1]))*i_sd_pu - w_el*c.L_s[2]*i_s[2]);

More information see Partials.Synchron3rdBase.

"), Icon(graphics={Rectangle(
              extent={{-90,112},{90,88}},
              lineColor={0,0,127},
              fillColor={170,213,255},
              fillPattern=FillPattern.Solid)}));
  end Synchron3rd_bldc;

  end Partials;
end Drives;


Line-faults

within PowerSystems.AC1ph_DC;
package Faults "Line-faults "
  extends Modelica.Icons.VariantsPackage;

  model Short_ABC "a, b, c to ground short, 3-phase abc"
    extends Partials.FaultBase;

    Real[2] s;

  equation
    {v,i} = if on then {epsR*s,s} else {s,epsG*s};
  end Short_ABC;

  model Fault_ab "a to b fault, 1-phase"
    extends Partials.Fault_pp;
  end Fault_ab;

  model Fault_A "a to ground fault, 1-phase"
    extends Partials.Fault_pg(final n_ph=1);
  end Fault_A;

  model Fault_B "b to ground fault, 1-phase"
    extends Partials.Fault_pg(final n_ph=2);
  end Fault_B;

  model Fault_Ab "b to a to ground fault, 1-phase"
    extends Partials.Fault_ppg(final n_ph=1);
  end Fault_Ab;

  model Fault_aB "a to b to ground fault, 1-phase"
    extends Partials.Fault_ppg(final n_ph=2);
  end Fault_aB;

  package Partials "Partial models"
    extends Modelica.Icons.BasesPackage;

    partial model FaultBase "Line fault base, 1-phase"
      extends Ports.Port_f;

      parameter SI.Frequency f=system.f_nom "frequency (when fault occurs)";
      parameter SI.Time t_on=0.1 "approx time fault on";
      parameter SI.Angle phi_on(min=0)=0 "voltage phase angle fault on";
      parameter SI.Resistance epsR=1e-4 "resistance 'fault'";
      parameter SI.Conductance epsG=1e-4 "conductance 'no fault'";
      PS.Voltage[2] v;
      PS.Current[2] i;
      Boolean on(final start=false, fixed=true);
    protected
      outer System system;
      constant Integer[2] pair={2, 1};
      discrete SI.Time t_zero(start=Modelica.Constants.inf, fixed=true);
      Boolean v_pos(start=true, fixed=true);
      Boolean first(start=true, fixed=true);

    equation
      v = term.v;
      term.i = i;

      v_pos = v[1] - v[2] > 0;
      when time > t_on and edge(v_pos) and pre(first) then
        t_zero = time;
        first = false;
      end when;
      on = time > pre(t_zero) + phi_on/(2*pi*f);
    end FaultBase;

    partial model Fault_pp "Conductor to conductor fault, 1-phase"
      extends FaultBase;

      replaceable Common.Switching.Short fault_pp(
        final on=on,
        final epsR=epsR,
        final epsG=epsG) "fault model"
    //  extends Common.Switching.Partials.FaultBase

    equation
      fault_pp.v = v[1] - v[2];
      fault_pp.i = i[1];
      sum(i) = epsG*sum(v);
    end Fault_pp;

    partial model Fault_pg "Conductor to ground fault, 1-phase"
      extends FaultBase;

      parameter Integer n_ph(min=1,max=2)=1 "faulted phase"
      replaceable Common.Switching.Short fault_pg(
        final on=on,
        final epsR=epsR,
        final epsG=epsG) "fault model"
    //  extends Common.Switching.Partials.FaultBase

    protected
      final parameter Integer m_ph=pair[n_ph];

    equation
      fault_pg.v=v[n_ph];
      fault_pg.i=i[n_ph];
      i[m_ph] = epsG*v[m_ph];
    end Fault_pg;

    partial model Fault_ppg "Conductor to conductor to ground fault, 1-phase"
      extends FaultBase;

      parameter Integer n_ph(min=1,max=2)=1 "which phase to ground"
      replaceable Common.Switching.Short fault_pp(
        final on=on,
        final epsR=epsR,
        final epsG=epsG) "fault model"
    //  extends Common.Switching.Partials.FaultBase
      replaceable Common.Switching.Short fault_pg(
        final on=on,
        final epsR=epsR,
        final epsG=epsG) "fault model"
    //  extends Common.Switching.Partials.FaultBase
    protected
      final parameter Integer m_ph=pair[n_ph];
    equation
      fault_pp.v=v[m_ph] - v[n_ph];
      fault_pp.i=i[m_ph];
      fault_pg.v=v[n_ph];
      fault_pg.i=sum(i);
    end Fault_ppg;

  end Partials;
end Faults;