AC power generation, dq0

within PowerSystems.Examples.AC3ph;
package Generation "AC power generation, dq0"
  extends Modelica.Icons.ExamplesPackage;

model Vsource "Power transfer from voltage source to slack bus"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Sources.VsourceRX Vsource(
    V_nom=20e3,
    v_start=1.02,
    S_nom=500e6,
    pq_start={1,0.428},
      alpha_start=0.037545522868902)
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Lines.RXline line(
    len=40e3, redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (V_nom=20e3, S_nom=500e6))
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd2

equation
  connect(Vsource.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
  connect(line.term_n, infBus.term)
  connect(grd1.term, Vsource.neutral)
  connect(infBus.neutral, grd2.term)
end Vsource;

model PVsource "Power transfer from power-voltage source to slack bus"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Sources.PVsource PVsource(
    V_nom=20e3,
    S_nom=500e6,
    v0=1.02,
    p0=1)
  PowerSystems.AC3ph.Lines.RXline line(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=20e3,
    S_nom=500e6),
    len=40e3)
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd2

equation
  connect(PVsource.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
  connect(line.term_n, infBus.term)
  connect(grd1.term, PVsource.neutral)
  connect(infBus.neutral, grd2.term)
end PVsource;

model PQsource "Power transfer from power source to slack bus"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Sources.PQsource PQsource(
    S_nom=500e6,
    V_nom=20e3,
    pq0={1,0.428})
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Lines.RXline line(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=20e3,
    S_nom=500e6),
    len=40e3)
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd2

equation
  connect(PQsource.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
  connect(line.term_n, infBus.term)
  connect(grd1.term, PQsource.neutral)
  connect(infBus.neutral, grd2.term)
end PQsource;

  model PowerAngle "Generator at fixed power angle"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Machines.Control.PowerAngle powerAngle(delta=
          0.78539816339745)
    PowerSystems.Control.Exciters.ExciterSimple exciter(v_f=2.258)
    PowerSystems.AC3ph.Machines.Control.Excitation excitation(V_nom=20e3, Vf_nom=20e3)
    PowerSystems.AC3ph.Machines.Synchron3rd_ee generator(redeclare replaceable
        record Data =
          PowerSystems.Examples.Data.Machines.SynchronIso20kV_500MVA)

    PowerSystems.AC3ph.Sensors.Psensor sensor
    PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
    PowerSystems.AC3ph.Sources.Voltage Vgen1(
      V_nom=20e3,
      v0=2.258,
      alpha0=0.78539816339745)
    PowerSystems.AC3ph.Impedances.Inductor RLgen1(
      V_nom=20e3,
      S_nom=500e6,
      r=0.01,
      x_m=-0.5,
      x_s=1.1)
    PowerSystems.AC3ph.Sensors.Psensor sensor1
    PowerSystems.AC3ph.Sources.Voltage Vbus1(V_nom=20e3)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.AC3ph.Nodes.GroundOne grd3
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(Vgen1.term, RLgen1.term_p)
    connect(RLgen1.term_n, sensor1.term_p)
    connect(sensor1.term_n, Vbus1.term)
    connect(exciter.fieldVoltage, excitation.fieldVoltage)
    connect(excitation.termVoltage, exciter.termVoltage)
    connect(generator.term, excitation.term)
    connect(excitation.field, generator.field)
    connect(generator.term, powerAngle.term)
    connect(powerAngle.airgap, generator.airgap)
    connect(generator.term, sensor.term_p)
    connect(sensor.term_n, infBus.term)
    connect(grd1.term, Vgen1.neutral)
    connect(Vbus1.neutral, grd2.term)
    connect(infBus.neutral, grd3.term)
    connect(generator.heat, bdCond.heat)
  end PowerAngle;

  model TurbineGenerator "Turbine with generator"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    parameter SI.AngularVelocity w_start=2*pi*generator.par.f_nom/generator.par.pp
      "initial angular velocity (start-value if ini='st')";
    PowerSystems.Mechanics.TurboGroups.SingleMassTG turboGrp(
      w_start=w_start,
      H=20,
      w_nom=2*pi*generator.par.f_nom/generator.par.pp,
      P_nom=generator.par.S_nom)
    PowerSystems.AC3ph.Machines.Synchron3rd_ee generator(redeclare replaceable
        record Data =
          PowerSystems.Examples.Data.Machines.SynchronIso20kV_500MVA)

    PowerSystems.Control.Governors.GovernorSimple governor(p=1.0116)
    PowerSystems.Control.Exciters.ExciterSimple exciter(v_f=2.258)
    PowerSystems.AC3ph.Machines.Control.Excitation excitation(V_nom=20e3, Vf_nom=20e3)
    PowerSystems.AC3ph.Sensors.Psensor sensor
    PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
    PowerSystems.AC3ph.Sources.Voltage Vgen1(
      V_nom=20e3,
      v0=2.258,
      alpha0=0.78539816339745)
    PowerSystems.AC3ph.Impedances.Inductor RLgen1(
      V_nom=20e3,
      S_nom=500e6,
      x_s=1.1,
      x_m=-0.5,
      r=0.01)
    PowerSystems.AC3ph.Sensors.Psensor sensor1
    PowerSystems.AC3ph.Sources.Voltage VBus1(V_nom=20e3)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.AC3ph.Nodes.GroundOne grd3
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(Vgen1.term, RLgen1.term_p)
    connect(RLgen1.term_n, sensor1.term_p)
    connect(sensor1.term_n, VBus1.term)
    connect(exciter.fieldVoltage, excitation.fieldVoltage)
    connect(excitation.termVoltage, exciter.termVoltage)
    connect(turboGrp.airgap, generator.airgap)
    connect(generator.term, excitation.term)
    connect(excitation.field, generator.field)
    connect(generator.term, sensor.term_p)
    connect(sensor.term_n, infBus.term)
    connect(turboGrp.speed, governor.speed)
    connect(governor.power, turboGrp.power)
    connect(grd1.term, Vgen1.neutral)
    connect(VBus1.neutral, grd2.term)
    connect(infBus.neutral, grd3.term)
    connect(generator.heat, bdCond.heat)
  end TurbineGenerator;

  model TurbineGeneratorLine "Turbine with generator and line"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    parameter SI.AngularVelocity w_start=2*pi*generator.par.f_nom/generator.par.pp
      "initial angular velocity (start-value if ini='st')";
    PowerSystems.Mechanics.TurboGroups.SingleMassTG turboGrp(
      final w_start=w_start,
      H=20,
      w_nom=2*pi*generator.par.f_nom/generator.par.pp,
      P_nom=generator.par.S_nom)
    PowerSystems.AC3ph.Machines.Synchron3rd_ee generator(redeclare replaceable
        record Data =
          PowerSystems.Examples.Data.Machines.SynchronIso20kV_500MVA)

    PowerSystems.Control.Governors.GovernorSimple governor(p=1.0094)
    PowerSystems.Control.Exciters.ExciterSimple exciter(v_f=2.245)
    PowerSystems.AC3ph.Machines.Control.Excitation excitation(V_nom=20e3, Vf_nom=20e3)
    PowerSystems.AC3ph.Nodes.BusBar busbar
    PowerSystems.AC3ph.Sensors.Psensor sensor
    PowerSystems.AC3ph.Lines.RXline line(
      redeclare record Data = PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=20e3,
        r=0.02e-3,
        x=0.2e-3),
      dynType=PowerSystems.Types.Dynamics.FreeInitial,
      len=400e3)
    PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
    PowerSystems.AC3ph.Sources.Voltage Vgen1(
      V_nom=20e3,
      v0=2.245,
      alpha0=1.0285225282003)
    PowerSystems.AC3ph.Impedances.Inductor RLgen1(
      V_nom=20e3,
      S_nom=500e6,
      x_s=1.1,
      x_m=-0.5,
      r=0.01)
    PowerSystems.AC3ph.Nodes.BusBar busbar1
    PowerSystems.AC3ph.Sensors.Psensor sensor1
    PowerSystems.AC3ph.Lines.RXline line1(
      redeclare record Data = PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=20e3,
        r=0.02e-3,
        x=0.2e-3),
      dynType=PowerSystems.Types.Dynamics.FreeInitial,
      len=400e3)
    PowerSystems.AC3ph.Sources.Voltage VBus1(V_nom=20e3)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.AC3ph.Nodes.GroundOne grd3
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(Vgen1.term, RLgen1.term_p)
    connect(RLgen1.term_n, busbar1.term)
    connect(busbar1.term, sensor1.term_p)
    connect(sensor1.term_n, line1.term_p)
    connect(line1.term_n, VBus1.term)
    connect(exciter.fieldVoltage, excitation.fieldVoltage)
    connect(excitation.termVoltage, exciter.termVoltage)
    connect(turboGrp.airgap, generator.airgap)
    connect(generator.term, excitation.term)
    connect(excitation.field, generator.field)
    connect(generator.term, busbar.term)
    connect(busbar.term, sensor.term_p)
    connect(sensor.term_n, line.term_p)
    connect(line.term_n, infBus.term)
    connect(turboGrp.speed, governor.speed)
    connect(governor.power, turboGrp.power)
    connect(grd1.term, Vgen1.neutral)
    connect(VBus1.neutral, grd2.term)
    connect(infBus.neutral, grd3.term)
    connect(generator.heat, bdCond.heat)
  end TurbineGeneratorLine;

model TurboGeneratorLine "Turbo-generator with line to infinite bus"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Generation.TurboGenerator turboGen(
    H=20,
      redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron3rd_ee (
        redeclare replaceable record Data =
          PowerSystems.Examples.Data.Machines.SynchronIso20kV_500MVA),
      v_start=1.12762,
      p_start=1,
      q_start=0.42729,
      alpha_start=0.346481,
      redeclare model Exciter = PowerSystems.Control.Exciters.ExciterConst
        "constant")
  PowerSystems.AC3ph.Nodes.BusBar busbar
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Lines.RXline line(
    redeclare record Data = PowerSystems.AC3ph.Lines.Parameters.RXline (
      V_nom=20e3,
      r=0.02e-3,
      x=0.2e-3),
      dynType=PowerSystems.Types.Dynamics.FreeInitial,
      len=400e3)
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
  PowerSystems.Control.Setpoints.Set_w_p_v setpts
  PowerSystems.AC3ph.Sources.Voltage Vgen1(
    V_nom=20e3,
    v0=2.245,
      alpha0=1.0285225282003)
  PowerSystems.AC3ph.Impedances.Inductor RLgen1(
    V_nom=20e3,
    S_nom=500e6,
    x_s=1.1,
    x_m=-0.5,
    r=0.01)
  PowerSystems.AC3ph.Nodes.BusBar busbar1
  PowerSystems.AC3ph.Sensors.Psensor sensor1
  PowerSystems.AC3ph.Lines.RXline line1(
    redeclare record Data = PowerSystems.AC3ph.Lines.Parameters.RXline (
      V_nom=20e3,
      r=0.02e-3,
      x=0.2e-3),
      dynType=PowerSystems.Types.Dynamics.FreeInitial,
      len=400e3)
  PowerSystems.AC3ph.Sources.Voltage VBus1(V_nom=20e3)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd2
  PowerSystems.AC3ph.Nodes.GroundOne grd
  PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

equation
  connect(setpts.setpts, turboGen.setpts)
  connect(Vgen1.term, RLgen1.term_p)
  connect(RLgen1.term_n, busbar1.term)
  connect(busbar1.term, sensor1.term_p)
  connect(sensor1.term_n, line1.term_p)
  connect(line1.term_n, VBus1.term)
  connect(turboGen.term, busbar.term)
  connect(busbar.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
  connect(line.term_n, infBus.term)
  connect(grd1.term, Vgen1.neutral)
  connect(VBus1.neutral, grd2.term)
  connect(infBus.neutral, grd.term)
  connect(turboGen.heat, bdCond.heat)
end TurboGeneratorLine;

model GenOrder3and7 "Generator-models of different order"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system(f_nom=60)
  PowerSystems.AC3ph.Generation.TurboGenerator turboGen1(
    dispPA=true,
    v_start=1.03,
    p_start=0.97,
    H=20,
    redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
    redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron3rd_ee (
      redeclare record Data =
        PowerSystems.Examples.Data.Machines.Synchron3rd_ee60Hz_26kV_720MVA)
        "3rd order",
      alpha_start=0.5235987755983)
  PowerSystems.AC3ph.Breakers.Switch switchGrd1(V_nom=26e3,I_nom=30e6)
  PowerSystems.AC3ph.Nodes.Ground grd1f
  PowerSystems.AC3ph.Lines.RXline line1(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=26e3,
    f_nom=60,
    r=0.02e-3,
    x=0.3e-3), len=250e3)
  PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=26e3)
  PowerSystems.AC3ph.Generation.TurboGenerator turboGen2(
    dispPA=true,
    v_start=1.03,
    p_start=0.97,
    H=20,
    redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
    redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
      redeclare record Data =
        PowerSystems.Examples.Data.Machines.Synchron_ee60Hz_26kV_720MVA)
        "nth order",
      alpha_start=0.5235987755983)
  PowerSystems.AC3ph.Breakers.Switch switchGrd2(V_nom=26e3,I_nom=30e6)
  PowerSystems.AC3ph.Nodes.Ground grd2f
  PowerSystems.AC3ph.Lines.RXline line2(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=26e3,
    f_nom=60,
    r=0.02e-3,
    x=0.3e-3), len=250e3)
  PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=26e3)
  PowerSystems.Control.Relays.SwitchRelay relayGrd(
    ini_state=false,
    t_switch={0.1,0.3})
  PowerSystems.Control.Setpoints.Set_w_p_v setpts1
  PowerSystems.Control.Setpoints.Set_w_p_v setpts2
  PowerSystems.AC3ph.Nodes.GroundOne grd2
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.Common.Thermal.BdCondV bdCond1(m=2)
  PowerSystems.Common.Thermal.BdCondV bdCond2(m=2)

equation
  connect(setpts1.setpts, turboGen1.setpts)
  connect(setpts2.setpts, turboGen2.setpts)
  connect(relayGrd.y, switchGrd1.control)
  connect(relayGrd.y, switchGrd2.control)
  connect(turboGen1.term, line1.term_p)
  connect(line1.term_n, infBus1.term)
  connect(turboGen1.term, switchGrd1.term_p)
  connect(switchGrd1.term_n, grd1f.term)
  connect(turboGen2.term, line2.term_p)
  connect(line2.term_n, infBus2.term)
  connect(turboGen2.term, switchGrd2.term_p)
  connect(switchGrd2.term_n, grd2f.term)
  connect(infBus1.neutral, grd1.term)
  connect(infBus2.neutral, grd2.term)
  connect(turboGen1.heat, bdCond1.heat)
  connect(turboGen2.heat, bdCond2.heat)
end GenOrder3and7;

model TurboGroupGenerator
    "Turbogroup with generator, electro-mechanical interaction"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.Control.Setpoints.Set_w_p_v setpts
  PowerSystems.AC3ph.Generation.TurboGrpGenerator turboGrpGen(
    v_start=1.0156,
    redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
    redeclare model TurboGroup =
      PowerSystems.Mechanics.TurboGroups.SteamTurboGroup (
        redeclare record Data =
          PowerSystems.Examples.Data.Turbines.SteamTurboGroup1200MW),
    redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
      redeclare record Data =
        PowerSystems.Examples.Data.Machines.Synchron_ee20kV_1200MVA)
        "nth order")
  PowerSystems.AC3ph.Lines.RXline line(
    len=40e3, redeclare record Data =
          PowerSystems.AC3ph.Lines.Parameters.RXline (
      V_nom=20e3,
      r=0.02e-3,
      x=0.2e-3))
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=20e3)
  PowerSystems.AC3ph.Breakers.ForcedSwitch switchGrd(V_nom=20e3,I_nom=60e3)
  PowerSystems.AC3ph.Nodes.Ground grdf
  PowerSystems.Control.Relays.SwitchRelay relayGrd(
    ini_state=false,
    t_switch={0.1,0.3},
    n=1)
  PowerSystems.AC3ph.Nodes.GroundOne grd
  PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

equation
  connect(setpts.setpts, turboGrpGen.setpts)
  connect(relayGrd.y[1], switchGrd.control[1])
  connect(turboGrpGen.term, line.term_p)
  connect(line.term_n, infBus.term)
  connect(turboGrpGen.term, switchGrd.term_p)
  connect(switchGrd.term_n, grdf.term)
  connect(infBus.neutral, grd.term)
  connect(turboGrpGen.heat, bdCond.heat)
end TurboGroupGenerator;

model TieLine "Generators and power-oscillations"
  extends Modelica.Icons.Example;

    inner PowerSystems.System system(
      f_nom=60,
      f_lim={55,65},
      fType=PowerSystems.Types.SystemFrequency.Average)
    PowerSystems.AC3ph.Generation.TurboGenerator turboGen1(
      dispPA=true,
      alpha_start=0.316177 + system.alpha0,
      v_start=1.05,
      H=20,
      redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron_ee60Hz_26kV_720MVA)
        "nth order",
      redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
      redeclare model Governor = PowerSystems.Control.Governors.Governor1st
        "1st order",
      p_start=0.9,
      q_start=0.24022361,
      initType=PowerSystems.Types.Init.p_q)
  PowerSystems.AC3ph.Nodes.BusBar bus1
  PowerSystems.AC3ph.Sensors.Psensor sensor1(term_p(v(start={20e3,0,0})))
  PowerSystems.AC3ph.Lines.RXline line1(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=26e3,
    f_nom=60,
    r=0.02e-3,
    x=0.3e-3), len=200e3,
    dynType=PowerSystems.Types.Dynamics.FreeInitial)
    PowerSystems.AC3ph.Generation.TurboGenerator turboGen2(
      dispPA=true,
      alpha_start=0.0144536 + system.alpha0,
      v_start=1.04,
      H=20,
      redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
      redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron_ee60Hz_26kV_720MVA)
        "nth order",
      redeclare model Governor = PowerSystems.Control.Governors.Governor1st
        "1st order",
      p_start=0.9,
      q_start=0.5092972,
      initType=PowerSystems.Types.Init.p_q)
  PowerSystems.AC3ph.Nodes.BusBar bus2
  PowerSystems.AC3ph.Sensors.Psensor sensor2(term_p(v(start={20e3,0,0})))
  PowerSystems.AC3ph.Lines.RXline line2(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=26e3,
    f_nom=60,
    r=0.02e-3,
    x=0.3e-3), len=40e3,
    dynType=PowerSystems.Types.Dynamics.FreeInitial)
  PowerSystems.AC3ph.Generation.TurboGenerator turboGen3(
    dispPA=true,
    v_start=1.03,
    H=20,
    redeclare model Exciter = PowerSystems.Control.Exciters.Exciter1st
        "1st order",
    redeclare model Governor = PowerSystems.Control.Governors.Governor1st
        "1st order",
    redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron_ee60Hz_26kV_720MVA,
        dynType=PowerSystems.Types.Dynamics.FreeInitial) "nth order",
      q_start=0.10292306,
      p_start=0.27353)
  PowerSystems.AC3ph.Sensors.Psensor sensor3(term_p(v(start={20e3,0,0})))
  PowerSystems.AC3ph.Lines.RXline line3(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=26e3,
    f_nom=60,
    r=0.02e-3,
    x=0.3e-3), len=150e3,
    dynType=PowerSystems.Types.Dynamics.FreeInitial)
  PowerSystems.AC3ph.Sensors.Psensor sensorLoad
  PowerSystems.AC3ph.Loads.Zload load(
    pq0={0.95,0.2},
    V_nom=26e3,
    S_nom=1500e6,
    use_pq_in=true)
  PowerSystems.Blocks.Signals.Transient[2] pq_change(
    each t_duration=0.1,
    s_start={0.95,0.2},
    s_end={0.2,0.1},
    each t_change=2)
  PowerSystems.Control.Setpoints.Set_w_p_v setpts1
  PowerSystems.Control.Setpoints.Set_w_p_v setpts2
  PowerSystems.Control.Setpoints.Set_w_p_v setpts3
  PowerSystems.Common.Thermal.BdCondV bdCond1(m=2)
  PowerSystems.Common.Thermal.BdCondV bdCond2(m=2)
  PowerSystems.Common.Thermal.BdCondV bdCond3(m=2)

equation
  connect(pq_change.y,load.pq_in)
  connect(setpts1.setpts,turboGen1. setpts)
  connect(setpts2.setpts,turboGen2. setpts)
  connect(sensorLoad.term_p,line3. term_p)
  connect(sensorLoad.term_n,load. term)
  connect(turboGen1.term,bus1. term)
  connect(bus1.term,sensor1. term_p)
  connect(sensor1.term_n,line1. term_p)
  connect(turboGen2.term,bus2. term)
  connect(bus2.term,sensor2. term_p)
  connect(sensor2.term_n,line2. term_n)
  connect(line1.term_n,sensorLoad. term_p)
  connect(line2.term_p,sensorLoad. term_p)
  connect(setpts3.setpts,turboGen3. setpts)
  connect(turboGen3.term, sensor3.term_p)
  connect(sensor3.term_n, line3.term_n)
  connect(turboGen1.heat, bdCond1.heat)
  connect(turboGen2.heat, bdCond2.heat)
  connect(turboGen3.heat, bdCond3.heat)
end TieLine;

model WindGeneratorLine "Asynchronous generator"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Generation.WindGenerator windGen(
    redeclare model Gear =
      PowerSystems.Mechanics.TurboGroups.WindTurbineGear (
        redeclare record Data =
          PowerSystems.Examples.Data.Turbines.WindTurbineGear),
    redeclare model Generator = PowerSystems.AC3ph.Machines.Asynchron (
      redeclare record Data =
        PowerSystems.Examples.Data.Machines.Asynchron400V_30kVA))
  PowerSystems.AC3ph.Nodes.BusBar busbar
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Lines.RXline line(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=400,
    S_nom=30e3,
    r=0.05), len=1.5e3,
    dynType=PowerSystems.Types.Dynamics.FreeInitial)
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=400)
  PowerSystems.Blocks.Signals.Transient trsSignal1(
    t_change=25,
    t_duration=50,
      s_start=5,
      s_end=15)
  PowerSystems.AC3ph.Nodes.GroundOne grd
  PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

equation
  connect(windGen.term, busbar.term)
  connect(busbar.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
  connect(line.term_n, infBus.term)
  connect(infBus.neutral, grd.term)
  connect(windGen.heat, bdCond.heat)
  connect(trsSignal1.y, windGen.windSpeed)
end WindGeneratorLine;

model Islanding "AC synchronous generator in islanding configuration"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  parameter SI.Voltage vAC_nom=560 "AC nominal voltage";
  parameter SI.Voltage vDC_nom=750 "DC nominal voltage";
  PowerSystems.Control.Setpoints.Set_w_p setpts
  PowerSystems.AC3ph.Generation.TurboPMgenerator turboGen(
    redeclare model Governor = PowerSystems.Control.Governors.Governor1st
        "1st order",
    redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_pm (
      redeclare record Data =
        PowerSystems.Examples.Data.Machines.Synchron_pm560V_100kVA)
        "nth order")
  PowerSystems.AC3ph.Nodes.DefReference reference
  PowerSystems.AC3ph.Sensors.Psensor ACpower
  PowerSystems.AC3ph.Inverters.RectifierAverage rectifier(redeclare record Data =
           PowerSystems.Examples.Data.Semiconductors.IdealSC1kV_100A)
  PowerSystems.AC1ph_DC.Impedances.CapacitorSym capSym(
    G=1e-4,
    C=0.020,
    V_start=vDC_nom)
  PowerSystems.AC3ph.Nodes.GroundOne grd
  PowerSystems.AC1ph_DC.Sensors.VdiffSensor DCvoltage
  PowerSystems.AC1ph_DC.Sensors.Psensor DCpower
  PowerSystems.AC1ph_DC.Loads.ZloadDC zLoadDC(S_nom=100e3,
    use_p_in=true,
    V_nom=vDC_nom)
  PowerSystems.Blocks.Signals.Transient transSig(
    t_duration=2.5,
    s_start=1,
    s_end=0.7,
      t_change=10)
  Modelica.Blocks.Continuous.LimPID limPID_DC(
    yMin=0,
    yMax=2,
    xi_start=1,
    Td=0.1,
    Ti=0.5,
    k=1/vDC_nom,
    initType=Modelica.Blocks.Types.Init.SteadyState)
  Modelica.Blocks.Sources.Constant set_vDC(k=vDC_nom)
  PowerSystems.Common.Thermal.BdCondV bdCond1(m=2)
  PowerSystems.Common.Thermal.BdCondV bdCond2(m=1)

equation
  connect(ACpower.term_n, rectifier.AC)
  connect(capSym.term_n, DCpower.term_p)
  connect(DCpower.term_n, zLoadDC.term)
  connect(setpts.setpts, turboGen.setpts)
  connect(set_vDC.y, limPID_DC.u_s)
  connect(limPID_DC.y, setpts.setpt_p)
  connect(capSym.term_p, DCvoltage.term)
  connect(rectifier.DC, capSym.term_p)
  connect(turboGen.heat, bdCond1.heat)
  connect(rectifier.heat, bdCond2.heat)
  connect(transSig.y, zLoadDC.p_in)
  connect(capSym.neutral, grd.term)
  connect(DCvoltage.v, limPID_DC.u_m)
  connect(turboGen.term, reference.term)
  connect(reference.term, ACpower.term_p)
  connect(turboGen.phiRotor, reference.theta)
end Islanding;

model LocalGeneration
    "AC torque controlled synchronous machine as local generator"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system(f_nom=60)
  parameter SI.Voltage vDC_nom=780 "DC nominal voltage";
  final parameter SI.Current I_nom=PMgen.generator.par.S_nom/PMgen.generator.par.V_nom
      "generator nominal current";
  PowerSystems.Blocks.Signals.Transient speedSignal(
    t_duration=5,
    t_change=20,
      s_start=2*pi*180,
      s_end=2*pi*150)
    PowerSystems.Mechanics.Rotational.Speed speed(use_w_in=true, w0=2*pi*180)
  PowerSystems.AC3ph.Generation.PMgenerator PMgen(
    redeclare model Generator =
      PowerSystems.AC3ph.Machines.Synchron3rd_pm_ctrl (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron3rd_pm560V_100kVA (
            neu_iso=true)),
    redeclare model Inverter = PowerSystems.AC3ph.Inverters.InverterAverage (
      redeclare record Data =
        PowerSystems.Examples.Data.Semiconductors.IdealSC1kV_100A(Vf=0)),
      w_start=1130.9733552923)
  PowerSystems.AC1ph_DC.Impedances.CapacitorSym capSym(
    G=1e-4,
    V_start=vDC_nom,
    C=0.020)
  PowerSystems.AC3ph.Nodes.GroundOne grd
  PowerSystems.AC1ph_DC.Sensors.VdiffSensor DCvoltage
  PowerSystems.AC1ph_DC.Sensors.Psensor DCpower
  PowerSystems.AC1ph_DC.Loads.ZloadDC zLoadDC(
    use_p_in=true,
    V_nom=vDC_nom,
    S_nom=100e3)
  PowerSystems.Blocks.Signals.Transient transSig(
    t_duration=2.5,
      t_change=10,
    s_start=0.5,
    s_end=0.9)
  PowerSystems.Common.Thermal.BdCondV bdCond(m=3)
  PowerSystems.Blocks.Signals.Transient i_d(
    t_duration=5,
    s_end=0,
    t_change=20,
      s_start=-0.1)
  Modelica.Blocks.Sources.Constant vDC_set(k=vDC_nom)
  Modelica.Blocks.Continuous.LimPID PI_vDC(
      Td=0.05,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      initType=Modelica.Blocks.Types.Init.SteadyState,
    Ti=0.1,
      k=0.3*I_nom/vDC_nom,
      yMax=1.4*I_nom)
  Modelica.Blocks.Math.Gain gain(k=-1) "generator: negative torque tau_act"

equation
  connect(PMgen.heat, bdCond.heat)
  connect(PMgen.term, capSym.term_p)
  connect(DCpower.term_n, zLoadDC.term)
  connect(capSym.term_p, DCvoltage.term)
  connect(transSig.y, zLoadDC.p_in)
  connect(DCvoltage.v, PI_vDC.u_m)
  connect(vDC_set.y, PI_vDC.u_s)
  connect(PI_vDC.y, gain.u)
  connect(gain.y, PMgen.i_act[2])
  connect(speed.flange, PMgen.flange)
  connect(capSym.term_n, DCpower.term_p)
  connect(capSym.neutral, grd.term)
  connect(speedSignal.y, speed.w_in)
  connect(i_d.y, PMgen.i_act[1])
end LocalGeneration;
end Generation;


Inverters dq0

within PowerSystems.Examples.AC3ph;
package Inverters "Inverters dq0"
  extends Modelica.Icons.ExamplesPackage;

  model Rectifier "Rectifier"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(dynType=PowerSystems.Types.Dynamics.FixedInitial,
      refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh(
      t_change=0.1,
      t_duration=0.1,
      a_start=2,
      a_end=1)
    PowerSystems.AC3ph.Sources.Voltage vAC(use_vPhasor_in=true, V_nom=100)
    PowerSystems.AC3ph.Impedances.Inductor ind(r=0.05,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(abc=true,
      av=true,
      tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Inverters.Rectifier rectifier(redeclare model Rectifier =
      PowerSystems.AC3ph.Inverters.Components.RectifierEquation(redeclare
            record Data =
              PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A))

    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0, V_nom=100)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)

  equation
    connect(vAC.term, ind.term_p)
    connect(ind.term_n, meterAC.term_p)
    connect(meterAC.term_n, rectifier.AC)
    connect(rectifier.DC, meterDC.term_p)
    connect(meterDC.term_n, vDC.term)
    connect(transPh.y, vAC.vPhasor_in)
    connect(grd1.term, vAC.neutral)
    connect(vDC.neutral, grd2.term)
    connect(rectifier.heat, bdCond.heat)
  end Rectifier;

  model InverterToLoad "Inverter to load"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0, V_nom=100)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Inverters.Inverter inverter(redeclare model Inverter =
        PowerSystems.AC3ph.Inverters.Components.InverterEquation(redeclare
            record Data =
            PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
        "equation, with losses")
    PowerSystems.AC3ph.Inverters.Select select(
      fType=PowerSystems.Types.SourceFrequency.Parameter,
      f=100,
      use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(
      abc=true,
      av=true,
      tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.05,
      t_duration=0.05,
      a_start=0)
    PowerSystems.AC3ph.Loads.PQindLoad pqLoad(
      tcst=0.01, imax=1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)

  equation
    connect(vDC.term, meterDC.term_p)
    connect(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(vCtrl.y,select.vPhasor_in)
    connect(meterAC.term_n, pqLoad.term)
    connect(grd.term, vDC.neutral)
    connect(inverter.heat, bdCond.heat)
  end InverterToLoad;

  model InverterToGrid "Inverter to grid"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Synchron)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0,
      V_nom=100,
      v0=2)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(tcst=0.1,
      V_nom=100,
      S_nom=1e3,
      av=true)
    PowerSystems.AC3ph.Inverters.Inverter inverter(redeclare model Inverter =
        PowerSystems.AC3ph.Inverters.Components.InverterEquation(redeclare
            record Data =
              PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
        "equation, with losses")
    PowerSystems.AC3ph.Inverters.Select select(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(
      V_nom=100,
      S_nom=1e3,
      av=true,
      tcst=0.1,
      abc=true)
    PowerSystems.AC3ph.Impedances.Inductor ind(r=0.05,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Sources.Voltage vAC(V_nom=100)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.1,
      t_duration=0.1,
      ph_end=0.5235987755983)
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)

  equation
    connect(vAC.term, ind.term_p)
    connect(vDC.term, meterDC.term_p)
    connect(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    connect(meterAC.term_n, ind.term_n)
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(vCtrl.y,select.vPhasor_in)
    connect(vAC.neutral, grd.term)
    connect(inverter.heat, bdCond.heat)
  end InverterToGrid;

  model InverterAvToGrid "Inverter to grid"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0,
      V_nom=100,
      v0=2)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Inverters.InverterAverage inverter(redeclare record Data =
      PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
    PowerSystems.AC3ph.Inverters.Select select(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(
      abc=true,
      av=true,
      tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Impedances.Inductor ind(r=0.05,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC3ph.Sources.Voltage vAC(V_nom=100)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.1,
      t_duration=0.1,
      ph_end=0.5235987755983)
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=1)

  equation
    connect(vAC.term, ind.term_p)
    connect(vDC.term, meterDC.term_p)
    connect(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    connect(meterAC.term_n, ind.term_n)
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(vCtrl.y,select.vPhasor_in)
    connect(vAC.neutral, grd.term)
    connect(inverter.heat, bdCond.heat)
  end InverterAvToGrid;
end Inverters;


Examples for AC3ph components

within PowerSystems.Examples;
package AC3ph "Examples for AC3ph components"
  extends Modelica.Icons.ExamplesPackage;
end AC3ph;


Precalculation of machine matrices

within PowerSystems.Examples.AC3ph;
package Precalculation "Precalculation of machine matrices"
extends Modelica.Icons.ExamplesPackage;

model Z_matrixTrDat0 "z-matrix from transient data, n=1, 0"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter Boolean use_xtr=true "use t_closed and x_transient?"
  parameter SI.Time[:] tc_d={0.684058354104098}
      "time constant closed-loop d-axis {tc_d', tc_d'', ..}"
  parameter SI.Time[:] tc_q=fill(0,0)
      "time constant closed-loop q-axis {tc_q', tc_q'', ..}"
  parameter SI.Time[:] to_d={4.17178865983301}
      "time constant open-loop d-axis {to_d', to_d'', ..}"
  parameter SI.Time[:] to_q=fill(0,0)
      "time constant open-loop q-axis {to_q', to_q'', ..}"
  parameter SIpu.Reactance[n_d] xtr_d={0.290231213872833}
      "trans reactance d-axis {xtr_d', xtr_d'', ..}"
  parameter SIpu.Reactance[n_q] xtr_q=fill(0,0)
      "trans reactance q-axis {xtr_q', xtr_q'', ..}"
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";
  parameter SIpu.Current if0=0 "induced field current at v_s=V_nom/0deg"
  parameter SI.Angle alpha_if0=0
      "angle(if0) at v_s=Vnom/0deg (sign: i_f behind v_s)"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=true;
  final parameter Integer n_d=size(tc_d,1);
  final parameter Integer n_q=size(tc_q,1);
  function T_open = PowerSystems.Utilities.Precalculation.T_open;
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromTransDat;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, omega_nom*tc_d, T_open(x_d, xtr_d, omega_nom*tc_d), x_d, xsig_s, r_s, if0, alpha_if0+pi, 0, true);
  (zr_q, zx_q) := z_matrix(n_q, omega_nom*tc_q, T_open(x_q, xtr_q, omega_nom*tc_q), x_q, xsig_s, r_s, 0, 0, 0, false);
end Z_matrixTrDat0;

model Z_matrixTrDat1 "z-matrix from transient data, n=1"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter Boolean use_xtr=true "use t_closed and x_transient?"
  parameter SI.Time[:] tc_d={0.684058354104098}
      "time constant closed-loop d-axis {tc_d', tc_d'', ..}"
  parameter SI.Time[:] tc_q={0.684058354104098}
      "time constant closed-loop q-axis {tc_q', tc_q'', ..}"
  parameter SI.Time[:] to_d={4.17178865983301}
      "time constant open-loop d-axis {to_d', to_d'', ..}"
  parameter SI.Time[:] to_q={4.17178865983301}
      "time constant open-loop q-axis {to_q', to_q'', ..}"
  parameter SIpu.Reactance[n_d] xtr_d={0.290231213872833}
      "trans reactance d-axis {xtr_d', xtr_d'', ..}"
  parameter SIpu.Reactance[n_q] xtr_q={0.290231213872833}
      "trans reactance q-axis {xtr_q', xtr_q'', ..}"
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";
  parameter SIpu.Current if0=0 "induced field current at v_s=V_nom/0deg"
  parameter SI.Angle alpha_if0=0
      "angle(if0) at v_s=Vnom/0deg (sign: i_f behind v_s)"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=true;
  final parameter Integer n_d=size(tc_d,1);
  final parameter Integer n_q=size(tc_q,1);
  function T_open = PowerSystems.Utilities.Precalculation.T_open;
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromTransDat;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, omega_nom*tc_d, T_open(x_d, xtr_d, omega_nom*tc_d), x_d, xsig_s, r_s, if0, alpha_if0+pi, 0, true);
  (zr_q, zx_q) := z_matrix(n_q, omega_nom*tc_q, T_open(x_q, xtr_q, omega_nom*tc_q), x_q, xsig_s, r_s, 0, 0, 0, false);
end Z_matrixTrDat1;

model Z_matrixTrDat2 "z-matrix from transient data, n=2"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter Boolean use_xtr=true "use t_closed and x_transient?"
  parameter SI.Time[:] tc_d={0.859012450972537, 0.024700865536969}
      "time constant closed-loop d-axis {tc_d', tc_d'', ..}"
  parameter SI.Time[:] tc_q={0.703091060761508, 0.0226730319219496}
      "time constant closed-loop q-axis {tc_q', tc_q'', ..}"
  parameter SI.Time[:] to_d={4.65929627144818, 0.03185596214872}
      "time constant open-loop d-axis {to_d', to_d'', ..}"
  parameter SI.Time[:] to_q={4.5014019794843, 0.0318010302865584}
      "time constant open-loop q-axis {to_q', to_q'', ..}"
  parameter SIpu.Reactance[n_d] xtr_d={0.32862524982383, 0.253031064823128}
      "trans reactance d-axis {xtr_d', xtr_d'', ..}"
  parameter SIpu.Reactance[n_q] xtr_q={0.27962838258275, 0.197108545894619}
      "trans reactance q-axis {xtr_q', xtr_q'', ..}"
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";
  parameter SIpu.Current if0=0.834830547142614
      "induced field current at v_s=V_nom/0deg"
  parameter SI.Angle alpha_if0=-1.7713318143478
      "angle(if0) at v_s=Vnom/0deg (sign: i_f behind v_s)"
  parameter Real tol=1e-6 "tolerance precalculation"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=true;
  final parameter Integer n_d=size(tc_d,1);
  final parameter Integer n_q=size(tc_q,1);
  function T_open = PowerSystems.Utilities.Precalculation.T_open;
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromTransDat;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, omega_nom*tc_d, T_open(x_d, xtr_d, omega_nom*tc_d), x_d, xsig_s, r_s, if0, alpha_if0+pi, tol, true);
  (zr_q, zx_q) := z_matrix(n_q, omega_nom*tc_q, T_open(x_q, xtr_q, omega_nom*tc_q), x_q, xsig_s, r_s, 0, 0, 0, false);
end Z_matrixTrDat2;

model Z_matrixTrDat3 "z-matrix from transient data, n=3"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter Boolean use_xtr=true "use t_closed and x_transient?"
  parameter SI.Time[:] tc_d={0.869154751730285, 0.028837675377106, 0.00293370131083294}
      "time constant closed-loop d-axis {tc_d', tc_d'', ..}"
  parameter SI.Time[:] tc_q={0.710852334653427, 0.0267828156988275, 0.00180497772676905}
      "time constant closed-loop q-axis {tc_q', tc_q'', ..}"
  parameter SI.Time[:] to_d={4.79391852025869, 0.0390156982688014, 0.00331427152151774}
      "time constant open-loop d-axis {to_d', to_d'', ..}"
  parameter SI.Time[:] to_q={4.63399482930977, 0.0387883296526998, 0.00197933074735668}
      "time constant open-loop q-axis {to_q', to_q'', ..}"
  parameter SIpu.Reactance[n_d] xtr_d={0.324237799805601, 0.238193407852477, 0.209956053815068}
      "trans reactance d-axis {xtr_d', xtr_d'', ..}"
  parameter SIpu.Reactance[n_q] xtr_q={0.275669319075036, 0.187924853846143, 0.170964423631031}
      "trans reactance q-axis {xtr_q', xtr_q'', ..}"
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";
  parameter SIpu.Current if0=0.47426409312074
      "induced field current at v_s=V_nom/0deg"
  parameter SI.Angle alpha_if0=-2.5862242826262
      "angle(if0) at v_s=Vnom/0deg (sign: i_f behind v_s)"
  parameter Real tol=1e-6 "tolerance precalculation"

  Real[n_d + 1] zr_d;
  Real[n_d + 1, n_d + 1] zx_d;
  Real[n_q + 1] zr_q;
  Real[n_q + 1, n_q + 1] zx_q;

  protected
  final parameter Boolean use_trans=true;
  final parameter Integer n_d=size(tc_d,1);
  final parameter Integer n_q=size(tc_q,1);
  function T_open = PowerSystems.Utilities.Precalculation.T_open;
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromTransDat;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, omega_nom*tc_d, T_open(x_d, xtr_d, omega_nom*tc_d), x_d, xsig_s, r_s, if0, alpha_if0+pi, tol, true);
  (zr_q, zx_q) := z_matrix(n_q, omega_nom*tc_q, T_open(x_q, xtr_q, omega_nom*tc_q), x_q, xsig_s, r_s, 0, 0, 0, false);
end Z_matrixTrDat3;

model Z_matrixEqCirc0 "z-matrix from equivalent circuit, n=1, 0"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";

  parameter SIpu.Reactance[:] xsig_rd={0.13}
      "leakage reactance rotor d-axis {f}"
  parameter SIpu.Reactance[:] xsig_rq=fill(0,0)
      "leakage reactance rotor q-axis{Q}"
  parameter SIpu.Reactance[size(xsig_rd,1)-1] xm_d=fill(0,0)
      "coupling-reactance d-axis"
  parameter SIpu.Resistance[size(xsig_rd,1)] r_rd={0.0011}
      "resistance rotor d-axis{f}"
  parameter SIpu.Resistance[size(xsig_rq,1)] r_rq=fill(0,0)
      "resistance rotor q-axis{Q}"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=false;
  final parameter Integer n_d=size(xsig_rd,1);
  final parameter Integer n_q=size(xsig_rq,1);
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromEqCirc;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, x_d, xsig_s, r_s, xm_d, xsig_rd, r_rd);
  (zr_q, zx_q) := z_matrix(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);
end Z_matrixEqCirc0;

model Z_matrixEqCirc1 "z-matrix from equivalent circuit, n=1"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";

  parameter SIpu.Reactance[:] xsig_rd={0.13}
      "leakage reactance rotor d-axis {f}"
  parameter SIpu.Reactance[:] xsig_rq={0.13}
      "leakage reactance rotor q-axis{Q}"
  parameter SIpu.Reactance[size(xsig_rd,1)-1] xm_d=fill(0,0)
      "coupling-reactance d-axis"
  parameter SIpu.Resistance[size(xsig_rd,1)] r_rd={0.0011}
      "resistance rotor d-axis{f}"
  parameter SIpu.Resistance[size(xsig_rq,1)] r_rq={0.0011}
      "resistance rotor q-axis{Q}"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=false;
  final parameter Integer n_d=size(xsig_rd,1);
  final parameter Integer n_q=size(xsig_rq,1);
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromEqCirc;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, x_d, xsig_s, r_s, xm_d, xsig_rd, r_rd);
  (zr_q, zx_q) := z_matrix(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);
end Z_matrixEqCirc1;

model Z_matrixEqCirc2 "z-matrix from equivalent circuit, n=2"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";

  parameter SIpu.Reactance[:] xsig_rd={0.13, 0.035}
      "leakage reactance rotor d-axis {f, D}"
  parameter SIpu.Reactance[:] xsig_rq={0.13, 0.035}
      "leakage reactance rotor q-axis{Q1, Q2}"
  parameter SIpu.Reactance[size(xsig_rd,1)-1] xm_d={0.06}
      "coupling-reactance d-axis"
  parameter SIpu.Resistance[size(xsig_rd,1)] r_rd={0.0011, 0.012}
      "resistance rotor d-axis{f, D}"
  parameter SIpu.Resistance[size(xsig_rq,1)] r_rq={0.0011, 0.012}
      "resistance rotor q-axis{Q1, Q2}"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=false;
  final parameter Integer n_d=size(xsig_rd,1);
  final parameter Integer n_q=size(xsig_rq,1);
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromEqCirc;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, x_d, xsig_s, r_s, xm_d, xsig_rd, r_rd);
  (zr_q, zx_q) := z_matrix(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);
end Z_matrixEqCirc2;

model Z_matrixEqCirc3 "z-matrix from equivalent circuit, n=3"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";

  parameter SIpu.Reactance[:] xsig_rd={0.13, 0.035, 0.001}
      "leakage reactance rotor d-axis {f, D1, D2}"
  parameter SIpu.Reactance[:] xsig_rq={0.13, 0.035, 0.001}
      "leakage reactance rotor q-axis{Q1, Q2, Q3}"
  parameter SIpu.Reactance[size(xsig_rd,1)-1] xm_d={0.02, 0.04}
      "coupling-reactance d-axis"
  parameter SIpu.Resistance[size(xsig_rd,1)] r_rd={0.0011, 0.012, 0.03}
      "resistance rotor d-axis{f, D1, D2}"
  parameter SIpu.Resistance[size(xsig_rq,1)] r_rq={0.0011, 0.012, 0.03}
      "resistance rotor q-axis{Q1, Q2, Q3}"

  Real[n_d+1] zr_d;
  Real[n_d+1, n_d+1] zx_d;
  Real[n_q+1] zr_q;
  Real[n_q+1, n_q+1] zx_q;

  protected
  final parameter Boolean use_trans=false;
  final parameter Integer n_d=size(xsig_rd,1);
  final parameter Integer n_q=size(xsig_rq,1);
  function z_matrix = PowerSystems.Utilities.Precalculation.z_fromEqCirc;

algorithm
  (zr_d, zx_d) := z_matrix(n_d, x_d, xsig_s, r_s, xm_d, xsig_rd, r_rd);
  (zr_q, zx_q) := z_matrix(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);
end Z_matrixEqCirc3;

model TransDatFromEqCirc "Calculates transient data from equivalent circuit"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";

  parameter SIpu.Reactance[:] xsig_rd={0.13, 0.035}
      "leakage reactance rotor d-axis {f, D}"
  parameter SIpu.Reactance[:] xsig_rq={0.13, 0.035}
      "leakage reactance rotor q-axis{Q1, Q2}"
  parameter SIpu.Reactance[size(xsig_rd,1)-1] xm_d={0.06}
      "coupling-reactance d-axis"
  parameter SIpu.Resistance[size(xsig_rd,1)] r_rd={0.0011, 0.012}
      "resistance rotor d-axis{f, D}"
  parameter SIpu.Resistance[size(xsig_rq,1)] r_rq={0.0011, 0.012}
      "resistance rotor q-axis{Q1, Q2}"

  output SI.Time[n_d] tc_d "time constant closed-loop d-axis";
  output SI.Time[n_d] to_d "time constant open-loop d-axis";
  output SIpu.Reactance[n_d] xtr_d(each unit="1") "transient reactance d-axis";
  output SI.Time[n_q] tc_q "time constant closed-loop q-axis";
  output SI.Time[n_q] to_q "time constant open-loop q-axis";
  output SIpu.Reactance[n_q] xtr_q(each unit="1") "transient reactance q-axis";
  protected
  final parameter Boolean use_trans=false;
  final parameter Integer n_d=size(xsig_rd,1);
  final parameter Integer n_q=size(xsig_rq,1);
  function transientData=PowerSystems.Utilities.Precalculation.transientData;
  SI.Angle[n_d] Tc_d "Time constant closed-loop d-axis";
  SI.Angle[n_d] To_d "Time constant open-loop d-axis";
  SI.Angle[n_q] Tc_q "Time constant closed-loop q-axis";
  SI.Angle[n_q] To_q "Time constant open-loop q-axis";

algorithm
  (Tc_d, To_d, xtr_d) := transientData(n_d, x_d, xsig_s, r_s, xm_d, xsig_rd, r_rd);
  tc_d := Tc_d/omega_nom;
  to_d := To_d/omega_nom;
  (Tc_q, To_q, xtr_q) := transientData(n_q, x_q, xsig_s, r_s, zeros(n_q-1), xsig_rq, r_rq);
  tc_q := Tc_q/omega_nom;
  to_q := To_q/omega_nom;
end TransDatFromEqCirc;

model EqCircFromTransDat "Calculates equivalent circuit from transient data"
  extends Modelica.Icons.Example;

  parameter SI.AngularFrequency omega_nom=2*pi*60 "nom ang frequency";
  parameter Boolean use_xtr=true "use t_closed and x_transient?"
  parameter SI.Time[:] tc_d={0.859012450972537, 0.024700865536969}
      "time constant closed-loop d-axis {tc_d', tc_d'', ..}"
  parameter SI.Time[:] tc_q={0.703091060761508, 0.0226730319219496}
      "time constant closed-loop q-axis {tc_q', tc_q'', ..}"
  parameter SI.Time[:] to_d={4.65929627144818, 0.03185596214872}
      "time constant open-loop d-axis {to_d', to_d'', ..}"
  parameter SI.Time[:] to_q={4.5014019794843, 0.0318010302865584}
      "time constant open-loop q-axis {to_q', to_q'', ..}"
  parameter SIpu.Reactance[n_d] xtr_d={0.32862524982383, 0.253031064823128}
      "trans reactance d-axis {xtr_d', xtr_d'', ..}"
  parameter SIpu.Reactance[n_q] xtr_q={0.27962838258275, 0.197108545894619}
      "trans reactance q-axis {xtr_q', xtr_q'', ..}"
  parameter SIpu.Reactance x_d=1.77 "syn reactance d-axis";
  parameter SIpu.Reactance x_q=1.77 "syn reactance q-axis";
  parameter SIpu.Reactance xsig_s=0.17 "leakage reactance stator";
  parameter SIpu.Resistance r_s=0.005 "resistance stator";
  parameter SIpu.Current if0=0.834830547142614
      "induced field current at v_s=V_nom/0deg"
  parameter SI.Angle alpha_if0=-1.7713318143478
      "angle(if0) at v_s=Vnom/0deg (sign: i_f behind v_s)"
  parameter Real tol=1e-6 "tolerance precalculation"

  output SIpu.Resistance[n_d] r_rd(each unit="1");
  output SIpu.Reactance[n_d] xsig_rd(each unit="1");
  output SIpu.Reactance[n_d+1] xm_d(each unit="1");
  output SIpu.Resistance[n_q] r_rq(each unit="1");
  output SIpu.Reactance[n_q] xsig_rq(each unit="1");
  output SIpu.Reactance[n_q+1] xm_q(each unit="1");

  protected
  final parameter Boolean use_trans=true;
  final parameter Integer n_d=size(tc_d,1);
  final parameter Integer n_q=size(tc_q,1);
  function T_open = PowerSystems.Utilities.Precalculation.T_open;
  function equiCircuit = PowerSystems.Utilities.Precalculation.equiCircuit;

algorithm
  (r_rd, xsig_rd, xm_d) := equiCircuit(n_d, omega_nom*tc_d, T_open(x_d, xtr_d, omega_nom*tc_d), x_d, xsig_s, r_s, if0, alpha_if0+pi, tol, true);
  (r_rq, xsig_rq, xm_q) := equiCircuit(n_q, omega_nom*tc_q, T_open(x_q, xtr_q, omega_nom*tc_q), x_q, xsig_s, r_s, 0, 0, 0, false);
end EqCircFromTransDat;
end Precalculation;


Transformation dq0

within PowerSystems.Examples.AC3ph;
package Transformation "Transformation dq0"
  extends Modelica.Icons.ExamplesPackage;

  model PhaseShifts "Phase shift primary-secondary"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system

    PowerSystems.AC3ph.Sources.Voltage voltage
    PowerSystems.AC3ph.Sensors.PVImeter meter1
    PowerSystems.AC3ph.Nodes.BusBar bus
    PowerSystems.AC3ph.Transformers.TrafoStray trafo1(
      redeclare record Data =
      PowerSystems.AC3ph.Transformers.Parameters.TrafoStray(V_nom={1,10}),
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Y,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Y)
    PowerSystems.AC3ph.Sensors.PVImeter meter12(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res12(V_nom=10, r=1000)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo2(
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Y,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Delta,
      redeclare record Data =
        PowerSystems.AC3ph.Transformers.Parameters.TrafoStray(V_nom={1,10}))
    PowerSystems.AC3ph.Sensors.PVImeter meter22(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res22(V_nom=10, r=1000)
    PowerSystems.AC3ph.Nodes.GroundOne grd

    PowerSystems.AC3ph.Transformers.TrafoStray trafo3(
        redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.PAR,
      redeclare record Data =
          PowerSystems.AC3ph.Transformers.Parameters.TrafoStray (V_nom={1,10},
            dv_tap={0.1,0}),
      tap_1=-2)
    PowerSystems.AC3ph.Sensors.PVImeter meter32(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res32(V_nom=10, r=1000)
  equation
    connect(voltage.term,meter1. term_p)
    connect(meter1.term_n,bus. term)
    connect(bus.term, trafo1.term_p)
    connect(trafo1.term_n, meter12.term_p)
    connect(meter12.term_n, res12.term)
    connect(bus.term, trafo2.term_p)
    connect(trafo2.term_n, meter22.term_p)
    connect(meter22.term_n, res22.term)
    connect(grd.term, voltage.neutral)
    connect(trafo3.term_n, meter32.term_p)
    connect(meter32.term_n, res32.term)
    connect(trafo3.term_p, bus.term)
  end PhaseShifts;

  model TapChanger "Tap changing primary and secondary"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.Voltage voltage
    PowerSystems.AC3ph.Sensors.PVImeter meter1
    PowerSystems.AC3ph.Nodes.BusBar bus
    PowerSystems.AC3ph.Transformers.TrafoStray trafo1(
      redeclare record Data =
      PowerSystems.AC3ph.Transformers.Parameters.TrafoStray (
      V_nom={1,10},
      dv_tap={0.1,0.1}),
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter12(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res12(V_nom=10, r=1000)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo2(
      redeclare record Data =
      PowerSystems.AC3ph.Transformers.Parameters.TrafoStray (
      V_nom={1,10},
      dv_tap={0.1,0.1}),
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter22(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res22(V_nom=10, r=1000)
    PowerSystems.Control.Relays.TapChangerRelay tapRelay2(
      preset_1={0,0},
      preset_2={0,-1,0,1},
      t_switch_2={1,2,3})
    PowerSystems.Control.Relays.TapChangerRelay tapRelay1(
      preset_1={0,-1,0,1},
      preset_2={0,0},
      t_switch_1={1,2,3})
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(voltage.term, meter1.term_p)
    connect(meter1.term_n, bus.term)
    connect(bus.term, trafo1.term_p)
    connect(trafo1.term_n, meter12.term_p)
    connect(meter12.term_n, res12.term)
    connect(bus.term, trafo2.term_p)
    connect(trafo2.term_n, meter22.term_p)
    connect(meter22.term_n, res22.term)
    connect(grd.term, voltage.neutral)
    connect(tapRelay1.tap_1, trafo1.tap_1_in)
    connect(tapRelay1.tap_2, trafo1.tap_2_in)
    connect(tapRelay2.tap_1, trafo2.tap_1_in)
    connect(tapRelay2.tap_2, trafo2.tap_2_in)
  end TapChanger;

  model ThreeWinding "Three winding transformer"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system

    PowerSystems.AC3ph.Sources.Voltage voltage
    PowerSystems.AC3ph.Sensors.PVImeter meter1
    PowerSystems.AC3ph.Nodes.BusBar bus
    PowerSystems.AC3ph.Transformers.Trafo3Stray trafo3Stray
    PowerSystems.AC3ph.Sensors.PVImeter meter12(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res12(V_nom=10, r=1000)
    PowerSystems.AC3ph.Sensors.PVImeter meter22(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res22(V_nom=10, r=1000)
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(voltage.term,meter1. term_p)
    connect(meter1.term_n,bus. term)
    connect(meter12.term_n, res12.term)
    connect(meter22.term_n, res22.term)
    connect(bus.term, trafo3Stray.term_p)
    connect(trafo3Stray.term_na, meter12.term_p)
    connect(trafo3Stray.term_nb, meter22.term_p)
    connect(grd.term, voltage.neutral)
  end ThreeWinding;
end Transformation;


AC transmission, dq0

within PowerSystems.Examples.AC3ph;
package Transmission "AC transmission, dq0"
  extends Modelica.Icons.ExamplesPackage;

model PowerTransfer "Power transfer between two nodes"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.Blocks.Signals.TransientPhasor transPh(
      t_change=30,
      t_duration=60,
      ph_end=2*pi,
      ph_start=0)
  PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=130e3, use_vPhasor_in=true)
  PowerSystems.AC3ph.Lines.RXline line(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
    V_nom=130e3,
    S_nom=100e6),
    len=100e3)
  PowerSystems.AC3ph.Sensors.Psensor sensor
  PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=130e3)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd2

equation
  connect(transPh.y,infBus1.vPhasor_in)
  connect(infBus1.term, sensor.term_p)
  connect(sensor.term_n, line.term_p)
    connect(line.term_n, infBus2.term)
  connect(grd1.term,infBus1. neutral)
    connect(grd2.term, infBus2.neutral)
end PowerTransfer;

model VoltageStability "Voltage stability"
  extends Modelica.Icons.Example;

  inner PowerSystems.System system
  PowerSystems.AC3ph.Sources.InfBus Vsource0(V_nom=400e3, alpha0=0)
  PowerSystems.AC3ph.Sources.InfBus infBus(V_nom=400e3, use_vPhasor_in=true)

  PowerSystems.AC3ph.Sensors.Vmeter Vmeter(V_nom=400e3)
  PowerSystems.AC3ph.Sensors.PVImeter meter0(S_nom=100e6)
  PowerSystems.AC3ph.Lines.RXline line0(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=400e3,
        r=2e-3,
        x=0.25e-3), len=500e3)
  PowerSystems.AC3ph.Sources.InfBus Vsource1(V_nom=400e3, alpha0=
          0.087266462599716)
  PowerSystems.AC3ph.Sensors.PVImeter meter1(S_nom=100e6)
  PowerSystems.AC3ph.Lines.RXline line1(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=400e3,
        r=2e-3,
        x=0.25e-3), len=500e3)
  PowerSystems.AC3ph.Sources.InfBus Vsource2(V_nom=400e3, alpha0=-0.087266462599716)
  PowerSystems.AC3ph.Sensors.PVImeter meter2(S_nom=100e6)
  PowerSystems.AC3ph.Lines.RXline line2(redeclare record Data =
    PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=400e3,
        r=2e-3,
        x=0.25e-3), len=500e3)
  PowerSystems.Blocks.Signals.TransientPhasor transPh(
      t_change=90,
      t_duration=120,
      a_start=1,
      a_end=0)
  PowerSystems.AC3ph.Nodes.GroundOne grd1
  PowerSystems.AC3ph.Nodes.GroundOne grd4
  PowerSystems.AC3ph.Nodes.GroundOne grd2
  PowerSystems.AC3ph.Nodes.GroundOne grd3

equation
  connect(transPh.y, infBus.vPhasor_in)
  connect(Vsource0.term, line0.term_p)
  connect(line0.term_n, meter0.term_p)
  connect(meter0.term_n, infBus.term)
  connect(Vsource1.term, line1.term_p)
  connect(line1.term_n, meter1.term_p)
  connect(meter1.term_n, infBus.term)
  connect(Vsource2.term, line2.term_p)
  connect(line2.term_n, meter2.term_p)
  connect(meter2.term_n, infBus.term)
  connect(infBus.term, Vmeter.term)
  connect(grd1.term, Vsource0.neutral)
  connect(grd2.term, Vsource1.neutral)
  connect(grd3.term, Vsource2.neutral)
  connect(infBus.neutral, grd4.term)
end VoltageStability;

  model RXline "Single lumped line"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=400e3,
      v0=1.04,
      alpha0=0.5235987755983)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.RXline line(redeclare record Data =
      PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=400e3,
        x=0.25e-3,
        r=0.02e-3), len=400e3)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=400e3)
    PowerSystems.Control.Relays.SwitchRelay relay1(
      t_switch={0.2,0.65})
    PowerSystems.Control.Relays.SwitchRelay relay2(
      t_switch={0.3,0.7})
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=400e3, S_nom=1000e6)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(infBus1.term, meter.term_p)
    connect(meter.term_n, switch1.term_p)
    connect(switch1.term_n, line.term_p)
    connect(line.term_n, switch2.term_p)
    connect(switch2.term_n, infBus2.term)
    connect(grd1.term,infBus1. neutral)
    connect(infBus2.neutral, grd2.term)
  end RXline;

  model Tline "Single PI-line"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=400e3,
      v0=1.04,
      alpha0=0.5235987755983)
    PowerSystems.AC3ph.Breakers.Breaker breaker1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.Tline line(len=400e3, redeclare record Data =
          PowerSystems.AC3ph.Lines.Parameters.Line (
          V_nom=400e3,
          x=0.25e-3,
          r=0.02e-3))
    PowerSystems.AC3ph.Breakers.Breaker breaker2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=400e3)
    PowerSystems.Control.Relays.SwitchRelay relay1(
      t_switch={0.2,0.65})
    PowerSystems.Control.Relays.SwitchRelay relay2(
      t_switch={0.3,0.7})
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=400e3, S_nom=1000e6)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, breaker1.control)
    connect(relay2.y, breaker2.control)
    connect(infBus1.term, meter.term_p)
    connect(meter.term_n, breaker1.term_p)
    connect(breaker1.term_n, line.term_p)
    connect(line.term_n, breaker2.term_p)
    connect(breaker2.term_n, infBus2.term)
    connect(grd1.term,infBus1. neutral)
    connect(infBus2.neutral, grd2.term)
  end Tline;

  model FaultRXline "Faulted lumped line"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=400e3,
      v0=1.04,
      alpha0=0.5235987755983)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultRXline line(redeclare record Data =
      PowerSystems.AC3ph.Lines.Parameters.RXline (
        V_nom=400e3,
        x=0.25e-3,
        r=0.02e-3), len=400e3)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=400e3)
    PowerSystems.Control.Relays.SwitchRelay relay1(
      t_switch={0.2,0.65})
    PowerSystems.Control.Relays.SwitchRelay relay2(
      t_switch={0.3,0.7})
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=400e3, S_nom=1000e6)
    PowerSystems.AC3ph.Faults.Fault_abc abc
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(infBus1.term, meter.term_p)
    connect(meter.term_n, switch1.term_p)
    connect(switch1.term_n, line.term_p)
    connect(line.term_n, switch2.term_p)
    connect(switch2.term_n, infBus2.term)
    connect(line.term_f, abc.term)
    connect(grd1.term,infBus1. neutral)
    connect(infBus2.neutral, grd2.term)
  end FaultRXline;

  model FaultTline "Faulted PI-line"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=400e3,
      v0=1.04,
      alpha0=0.5235987755983)
    PowerSystems.AC3ph.Breakers.Breaker breaker1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultTline line(len=400e3, redeclare record Data =
          PowerSystems.AC3ph.Lines.Parameters.Line (
          V_nom=400e3,
          x=0.25e-3,
          r=0.02e-3))
    PowerSystems.AC3ph.Breakers.Breaker breaker2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Sources.InfBus infBus2(V_nom=400e3)
    PowerSystems.Control.Relays.SwitchRelay relay1(
      t_switch={0.2,0.65})
    PowerSystems.Control.Relays.SwitchRelay relay2(
      t_switch={0.3,0.7})
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=400e3, S_nom=1000e6)
    PowerSystems.AC3ph.Faults.Fault_abc abc
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, breaker1.control)
    connect(relay2.y, breaker2.control)
    connect(infBus1.term, meter.term_p)
    connect(meter.term_n, breaker1.term_p)
    connect(breaker1.term_n, line.term_p)
    connect(line.term_n, breaker2.term_p)
    connect(breaker2.term_n, infBus2.term)
    connect(line.term_f, abc.term)
    connect(grd1.term,infBus1. neutral)
    connect(infBus2.neutral, grd2.term)
  end FaultTline;

  model DoubleRXline "Parallel lumped lines, one faulted"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=20e3, alpha0=
          0.5235987755983)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo(
      redeclare record Data =
          PowerSystems.Examples.Data.Transformers.TrafoStray,
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Delta,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Y)
    PowerSystems.AC3ph.Lines.RXline line(len=480000, redeclare record Data =
          PowerSystems.Examples.Data.Lines.OHline400kV)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultRXline lineF(
      redeclare record Data = PowerSystems.Examples.Data.Lines.OHline400kV,
        len=430000)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Faults.Fault_abc abc
    PowerSystems.AC3ph.Sources.InfBus InfBus2(V_nom=400e3, alpha0=
          0.5235987755983)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15,0.2})
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153,0.21})
    PowerSystems.AC3ph.Sensors.PVImeter meterL(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Sensors.PVImeter meterF(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(trafo.term_n, meterL.term_p)
    connect(meterL.term_n, line.term_p)
    connect(line.term_n, InfBus2.term)
    connect(trafo.term_n, switch1.term_p)
    connect(switch1.term_n, meterF.term_p)
    connect(meterF.term_n, lineF.term_p)
    connect(lineF.term_n, switch2.term_p)
    connect(switch2.term_n, InfBus2.term)
    connect(lineF.term_f, abc.term)
    connect(infBus1.term, trafo.term_p)
    connect(grd1.term,infBus1. neutral)
    connect(InfBus2.neutral, grd2.term)
  end DoubleRXline;

  model DoubleLine "Parallel lines, one faulted"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.InfBus infBus1(V_nom=20e3, alpha0=
          0.5235987755983)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo(
      redeclare record Data =
        PowerSystems.Examples.Data.Transformers.TrafoStray,
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Delta,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Y)
    PowerSystems.AC3ph.Lines.PIline line(
                                        len=480000, redeclare record Data =
          PowerSystems.Examples.Data.Lines.OHline_400kV)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultTline lineF(
      redeclare record Data =
          PowerSystems.Examples.Data.Lines.OHline_400kV, len=430000)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Faults.Fault_abc abc
    PowerSystems.AC3ph.Sources.InfBus InfBus2(V_nom=400e3, alpha0=
          0.5235987755983)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15,0.2})
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153,0.21})
    PowerSystems.AC3ph.Sensors.PVImeter meterL(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Sensors.PVImeter meterF(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(trafo.term_n, meterL.term_p)
    connect(meterL.term_n, line.term_p)
    connect(line.term_n, InfBus2.term)
    connect(trafo.term_n, switch1.term_p)
    connect(switch1.term_n, meterF.term_p)
    connect(meterF.term_n, lineF.term_p)
    connect(lineF.term_n, switch2.term_p)
    connect(switch2.term_n, InfBus2.term)
    connect(lineF.term_f, abc.term)
    connect(infBus1.term, trafo.term_p)
    connect(grd1.term, infBus1.neutral)
    connect(grd2.term, InfBus2.neutral)
  end DoubleLine;

  model DoubleRXlineTG
    "Parallel lumped lines with turbo generator, one line faulted"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Generation.TurboGenerator turbGen(
      p_start=0.762922,
      redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
            redeclare replaceable record Data =
              PowerSystems.AC3ph.Machines.Parameters.Synchron_ee (
              V_nom=20e3,
              S_nom=1000e6,
              If_nom=2000), dynType=PowerSystems.Types.Dynamics.FreeInitial) "nth order",
      initType=PowerSystems.Types.Init.v_alpha,
      alpha_start=0.5235987755983)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo(
      redeclare record Data =
        PowerSystems.Examples.Data.Transformers.TrafoStray,
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Delta,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Y)
    PowerSystems.AC3ph.Lines.RXline line(
      len=480000,
      redeclare record Data = PowerSystems.Examples.Data.Lines.OHline400kV)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultRXline lineF(
      redeclare record Data = PowerSystems.Examples.Data.Lines.OHline400kV,
        len=430000)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Faults.Fault_abc abc(epsG=1e-5)
    PowerSystems.AC3ph.Sources.InfBus InfBus(V_nom=400e3, alpha0=
          0.5235987755983)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15,0.2})
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153,0.21})
    PowerSystems.AC3ph.Sensors.PVImeter meterL(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Sensors.PVImeter meterF(S_nom=1000e6, V_nom=400e3)
    PowerSystems.Control.Setpoints.Set_w_p_v cst_set
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)
  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(cst_set.setpts, turbGen.setpts)
    connect(turbGen.term, trafo.term_p)
    connect(trafo.term_n, meterL.term_p)
    connect(meterL.term_n, line.term_p)
    connect(line.term_n, InfBus.term)
    connect(trafo.term_n, switch1.term_p)
    connect(switch1.term_n, meterF.term_p)
    connect(meterF.term_n, lineF.term_p)
    connect(lineF.term_n, switch2.term_p)
    connect(switch2.term_n, InfBus.term)
    connect(lineF.term_f, abc.term)
    connect(InfBus.neutral, grd2.term)
    connect(turbGen.heat, boundary.heat)
  end DoubleRXlineTG;

  model DoubleLineTG "Parallel lines with turbo generator, one line faulted"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Generation.TurboGenerator turbGen(
      p_start=0.761825,
      redeclare model Generator = PowerSystems.AC3ph.Machines.Synchron_ee (
        redeclare replaceable record Data =
          PowerSystems.AC3ph.Machines.Parameters.Synchron_ee (
          V_nom=20e3,
          S_nom=1000e6,
          If_nom=2000), dynType=PowerSystems.Types.Dynamics.FreeInitial) "nth order",
      alpha_start=0.5235987755983)
    PowerSystems.AC3ph.Transformers.TrafoStray trafo(
      redeclare record Data =
        PowerSystems.Examples.Data.Transformers.TrafoStray,
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Delta,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Y)
    PowerSystems.AC3ph.Lines.PIline line(
                                        len=480e3, redeclare record Data =
          PowerSystems.Examples.Data.Lines.OHline_400kV)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Lines.FaultTline lineF(
      redeclare record Data =
          PowerSystems.Examples.Data.Lines.OHline_400kV, len=430000)
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=400e3, I_nom=2500)
    PowerSystems.AC3ph.Faults.Fault_abc abc(epsG=1e-5)
    PowerSystems.AC3ph.Sources.InfBus InfBus(V_nom=400e3, alpha0=
          0.5235987755983)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15,0.2})
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153,0.21})
    PowerSystems.AC3ph.Sensors.PVImeter meterL(S_nom=1000e6, V_nom=400e3)
    PowerSystems.AC3ph.Sensors.PVImeter meterF(S_nom=1000e6, V_nom=400e3)
    PowerSystems.Control.Setpoints.Set_w_p_v cst_set
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)
  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(cst_set.setpts, turbGen.setpts)
    connect(turbGen.term, trafo.term_p)
    connect(trafo.term_n, meterL.term_p)
    connect(meterL.term_n, line.term_p)
    connect(line.term_n, InfBus.term)
    connect(trafo.term_n, switch1.term_p)
    connect(switch1.term_n, meterF.term_p)
    connect(meterF.term_n, lineF.term_p)
    connect(lineF.term_n, switch2.term_p)
    connect(switch2.term_n, InfBus.term)
    connect(lineF.term_f, abc.term)
    connect(InfBus.neutral, grd2.term)
    connect(turbGen.heat, boundary.heat)
  end DoubleLineTG;
end Transmission;


Breaker example data

within PowerSystems.Examples.Data;
package Breakers "Breaker example data"
  extends Modelica.Icons.MaterialPropertiesPackage;
end Breakers;


Line example data

within PowerSystems.Examples.Data;
package Lines "Line example data"
  extends Modelica.Icons.MaterialPropertiesPackage;

  record OHline15kV1ph "Overhead RX-line 15kV 1-phase rail, example"
    extends PowerSystems.AC1ph_DC.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=15e3,
      S_nom=100e6,
      f_nom=50/3,
      r={3e-3,3e-3},
      x=2e-3,
      x0=5e-3);
  end OHline15kV1ph;

  record OHline_15kV1ph "Overhead PI-line 15kV 1-phase rail, example"
    extends PowerSystems.AC1ph_DC.Lines.Parameters.Line(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50/3,
      r={3e-3,3e-3},
      x=2e-3,
      x0=5e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.02e-3,
      b_pp=0.02e-3);
  end OHline_15kV1ph;

record OHline132kV1ph "Overhead RX-line 132kV 1-phase rail, example"
  extends PowerSystems.AC1ph_DC.Lines.Parameters.RXline(
    puUnits=true,
    V_nom=132e3,
    S_nom=100e6,
    f_nom=50/3,
    r={1.2e-3,1.2e-3},
    x=1e-3,
    x0=3e-3);
end OHline132kV1ph;

record OHline_132kV1ph "Overhead PI-line 132kV 1-phase rail, example"
  extends PowerSystems.AC1ph_DC.Lines.Parameters.Line(
    puUnits=true,
    V_nom=132e3,
    S_nom=100e6,
    f_nom=50/3,
    r={1.2e-3,1.2e-3},
    x=1e-3,
    x0=3e-3,
    g_pg=1e-10,
    g_pp=1e-10,
    b_pg=0.05e-3,
    b_pp=0.05e-3);
end OHline_132kV1ph;

  record Cable132kVDC "Cable RX-line 132kV DC, example"
    extends PowerSystems.AC1ph_DC.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r={0.65e-3,0.65e-3},
      x=0.8e-3,
      x0=3e-3);
  end Cable132kVDC;

  record Cable_132kVDC "Cable PI-line 132kV DC, example"
    extends PowerSystems.AC1ph_DC.Lines.Parameters.Line(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r={0.65e-3,0.65e-3},
      x=0.08e-3,
      x0=3e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.003,
      b_pp=0.003);
  end Cable_132kVDC;

  record OHline132kV "Overhead RX-line 132kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r=1.2e-3,
      x=3e-3,
      x0=9e-3);
  end OHline132kV;

  record OHline_132kV "Overhead PI-line 132kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.Line(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r=1.2e-3,
      x=3e-3,
      x0=9e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.05e-3,
      b_pp=0.05e-3);
  end OHline_132kV;

  record OHline400kV "Overhead RX-line 400kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=400e3,
      S_nom=100e6,
      f_nom=50,
      r=0.02e-3,
      x=0.25e-3,
      x0=0.75e-3);
  end OHline400kV;

  record OHline_400kV "Overhead PI-line 400kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.Line(
      puUnits=true,
      V_nom=400e3,
      S_nom=100e6,
      f_nom=50,
      r=0.02e-3,
      x=0.25e-3,
      x0=0.75e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.003e-3,
      b_pp=0.003e-3);
  end OHline_400kV;

  record Cable132kV "Cable RX-line 132kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r=0.65e-3,
      x=0.8e-3,
      x0=3e-3);
  end Cable132kV;

  record Cable_132kV "Cable PI-line 132kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.Line(
      puUnits=true,
      V_nom=132e3,
      S_nom=100e6,
      f_nom=50,
      r=0.65e-3,
      x=0.08e-3,
      x0=3e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.003,
      b_pp=0.003);
  end Cable_132kV;

  record Cable400kV "Cable RX-line 400kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.RXline(
      puUnits=true,
      V_nom=400e3,
      S_nom=100e6,
      f_nom=50,
      r=0.05e-3,
      x=0.085e-3,
      x0=3e-3);
  end Cable400kV;

  record Cable_400kV "Cable PI-line 400kV 3-phase, example"
    extends PowerSystems.AC3ph.Lines.Parameters.Line(
      puUnits=true,
      V_nom=400e3,
      S_nom=100e6,
      f_nom=50,
      r=0.05e-3,
      x=0.085e-3,
      x0=3e-3,
      g_pg=1e-10,
      g_pp=1e-10,
      b_pg=0.025,
      b_pp=0.025);
  end Cable_400kV;
end Lines;


Machine example data

within PowerSystems.Examples.Data;
package Machines "Machine example data"
  extends Modelica.Icons.MaterialPropertiesPackage;

record DCser1500V_1p5MVA "DC machine series excited, example"
  extends PowerSystems.AC1ph_DC.Machines.Parameters.DCser(
    pp=2,
    l_fd=0.15,
    r_fd=0.01,
    l_q=0.5,
    r_q=0.05,
    puUnits=true,
    V_nom=1500,
    S_nom=1.5e6,
    w_nom=157.079632679489661923);
end DCser1500V_1p5MVA;

record DCpar1500V_1p5MVA "DC machine parallel excited, example"
  extends PowerSystems.AC1ph_DC.Machines.Parameters.DCpar(
    pp=2,
    l_fd=100*pi,
    r_fd=100,
    l_q=0.5,
    r_q=0.05,
    puUnits=true,
    V_nom=1500,
    S_nom=1.5e6,
    w_nom=157.079632679489661923,
    Vf_nom=1500);
end DCpar1500V_1p5MVA;

record DCpm100V_1kVA "DC machine permanent magnet excited, example"
  extends PowerSystems.AC1ph_DC.Machines.Parameters.DCpm(
    pp=2,
    l_aq=0.5,
    r_aq=0.05,
    puUnits=true,
    V_nom(displayUnit="V")=100,
    S_nom(displayUnit="kVA")=1e3,
    w_nom=157.079632679489661923);
end DCpm100V_1kVA;

record BLDC100V_1kVA
    "BLDC machine (= synchronous pm, 3rd order model), example pu-units"
  extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd(
    puUnits=true,
    V_nom(displayUnit="V")=100*sqrt(3/2)/2,
    S_nom(displayUnit="kVA")=1e3,
    f_nom=60,
    neu_iso=false,
    pp=2,
    final excite=2,
    psi_pm(unit="1")=1.2,
    x_d=0.4,
    x_q=0.4,
    x_0=0.1,
    r_s=0.05,
    r_n=1);
end BLDC100V_1kVA;

record BLDC100V_1kVA_SI
    "BLDC machine (= synchronous pm, 3rd order model), example SI-units"
  extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd(
    puUnits=false,
    V_nom(displayUnit="V")=100*sqrt(3/2)/2,
    S_nom(displayUnit="kVA")=1e3,
    f_nom=60,
    neu_iso=false,
    pp=2,
    final excite=2,
    psi_pm(unit="1")=1.2,
    x_d=1.5,
    x_q=1.5,
    x_0=0.375,
    r_s=0.1875,
    r_n=1);
end BLDC100V_1kVA_SI;

  record Asynchron400V_30kVA "Asynchronous machine, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Asynchron(
      neu_iso=false,
      pp=8,
      x=3,
      x_0=0.1,
      r_s=0.04,
      r_n=1,
      n_r=1,
      transDat=true,
      use_xtr=true,
      xtr={0.196667},
      tc={0.0130419},
      to={0.198944},
      xsig_s=0.1,
      xsig_r={0.1},
      r_r={0.04},
      puUnits=true,
      V_nom(displayUnit="V")=400,
      S_nom(displayUnit="kVA")=30e3,
      f_nom=50);
  end Asynchron400V_30kVA;

  record Asynchron3kV_1p5MVA "Asynchronous machine, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Asynchron(
      neu_iso=false,
      pp=2,
      x=2.8,
      x_0=0.1,
      r_s=0.02,
      r_n=1,
      n_r=2,
      transDat=true,
      use_xtr=true,
      xtr={0.1, 0.075},
      tc={0.014, 0.4e-3},
      to={0.4, 2.8e-3},
      xsig_s=0.05,
      xsig_r={0.0529633, 0.0481803},
      r_r={0.0234304, 0.580595},
      puUnits=true,
      V_nom=3000,
      S_nom=1.5e6,
      f_nom=50);
  end Asynchron3kV_1p5MVA;

  record Synchron3rd_pm400V_30kVA
    "Synchronous machine pm, 3rd order model, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd_pm(
      neu_iso=false,
      pp=2,
      psi_pm=1.1,
      x_d=0.4,
      x_q=0.4,
      x_0=0.1,
      r_s=0.03,
      r_n=1,
      puUnits=true,
      V_nom(displayUnit="V")=400,
      S_nom(displayUnit="kVA")=30e3,
      f_nom=50);
  end Synchron3rd_pm400V_30kVA;

  record Synchron_pm400V_30kVA "Synchronous machine pm, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron_pm(
      neu_iso=false,
      pp=2,
      psi_pm=1.1,
      x_d=0.4,
      x_q=0.4,
      x_0=0.1,
      r_s=0.03,
      r_n=1,
      transDat=true,
      use_xtr=true,
      xtr_d={0.142857},
      xtr_q={0.142857},
      tc_d={0.00994718},
      tc_q={0.00994718},
      to_d={0.0278521},
      to_q={0.0278521},
      use_if0=false,
      if0=0,
      alpha_if0=0,
      tol=1e-6,
      xsig_s=0.1,
      xsig_rd={0.05},
      xsig_rq={0.05},
      xm_d=fill(0, 0),
      r_rd={0.04},
      r_rq={0.04},
      puUnits=true,
      V_nom(displayUnit="V")=400,
      S_nom(displayUnit="kVA")=30e3,
      f_nom=50,
      If_nom=0);
  end Synchron_pm400V_30kVA;

  record Synchron3rd_pm560V_100kVA "Synchronous machine 3rd order pm, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd_pm(
      neu_iso=false,
      pp=2,
      psi_pm=1.1,
      x_d=0.4,
      x_q=0.4,
      x_0=0.1,
      r_s=0.03,
      r_n=1,
      puUnits=true,
      V_nom(displayUnit="V")=560,
      S_nom(displayUnit="kVA")=100e3,
      f_nom=400);
  end Synchron3rd_pm560V_100kVA;

  record Synchron_pm560V_100kVA "Synchronous machine pm, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron_pm(
      neu_iso=false,
      pp=2,
      psi_pm=1.1,
      x_d=0.4,
      x_q=0.4,
      x_0=0.1,
      r_s=0.03,
      r_n=1,
      transDat=true,
      use_xtr=true,
      xtr_d={0.142857},
      xtr_q={0.142857},
      tc_d={0.0132629},
      tc_q={0.0132629},
      to_d={0.0371362},
      to_q={0.0371362},
      use_if0=false,
      if0=0,
      alpha_if0=0,
      tol=1e-6,
      xsig_s=0.1,
      xsig_rd={0.05},
      xsig_rq={0.05},
      xm_d=fill(0, 0),
      r_rd={0.03},
      r_rq={0.03},
      puUnits=true,
      V_nom(displayUnit="V")=560,
      S_nom(displayUnit="kVA")=100e3,
      f_nom=400,
      If_nom=0);
  end Synchron_pm560V_100kVA;

  record Synchron3rd_ee20kV_1200MVA
    "Synchronous machine, 3rd order model, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd_ee(
      neu_iso=false,
      pp=1,
      x_d=2.29,
      x_q=1.95,
      x_0=0.1,
      r_s=0.004,
      r_n=1,
      puUnits=true,
      V_nom=20e3,
      S_nom=1200e6,
      f_nom=50);
  end Synchron3rd_ee20kV_1200MVA;

  record Synchron_ee20kV_1200MVA "Synchronous machine, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron_ee(
      neu_iso=false,
      pp=1,
      x_d=2.29,
      x_q=1.95,
      x_0=0.1,
      r_s=0.004,
      r_n=1,
      transDat=true,
      use_xtr=true,
      xtr_d={0.361123, 0.283696},
      xtr_q={0.464817, 0.303593},
      tc_d={0.93133, 0.0253919},
      tc_q={0.270197, 0.041458},
      to_d={5.94309, 0.0321197},
      to_q={1.207780, 0.0595723},
      use_if0=true,
      if0=0.286,
      alpha_if0=-0.97738438111682,
      tol=1e-6,
      xsig_s=0.2,
      xsig_rd={0.1294, 0.03498},
      xsig_rq={0.3948, 0.1527},
      xm_d={0.05965},
      r_rd={1.321e-3, 14.38e-3},
      r_rq={7.037e-3, 20.38e-3},
      puUnits=true,
      V_nom=20e3,
      S_nom=1200e6,
      f_nom=50,
      If_nom=8000);
  end Synchron_ee20kV_1200MVA;

  record Synchron3rd_ee60Hz_26kV_720MVA
    "Synchronous machine, 3rd order model, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd_ee(
      neu_iso=false,
      pp=1,
      x_d=1.9,
      x_q=1.77,
      x_0=0.1,
      r_s=0.005,
      r_n=1,
      puUnits=true,
      V_nom=26e3,
      S_nom=720e6,
      f_nom=60);
  end Synchron3rd_ee60Hz_26kV_720MVA;

  record Synchron_ee60Hz_26kV_720MVA "Synchronous machine, example"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron_ee(
      neu_iso=false,
      pp=1,
      x_d=1.9,
      x_q=1.77,
      x_0=0.1,
      r_s=0.005,
      r_n=1,
      transDat=true,
      use_xtr=true,
      xtr_d={0.3290, 0.253},
      xtr_q={0.436, 0.2730},
      tc_d={0.7158, 0.02058},
      tc_q={0.2134, 0.03320},
      to_d={4.164, 0.02658},
      to_q={0.9307, 0.04936},
      use_if0=true,
      if0=0.835428,
      alpha_if0=-1.7910219718115,
      tol=1e-6,
      xsig_s=0.17,
      xsig_rd={0.1294, 0.03498},
      xsig_rq={0.3948, 0.1527},
      xm_d={0.05965},
      r_rd={1.321e-3, 14.38e-3},
      r_rq={7.037e-3, 20.38e-3},
      puUnits=true,
      V_nom=26e3,
      S_nom=720e6,
      f_nom=60,
      If_nom=1800);
  end Synchron_ee60Hz_26kV_720MVA;

  record SynchronIso20kV_500MVA
    "Synchronous machine (isotropic), 3rd order model"
    extends PowerSystems.AC3ph.Machines.Parameters.Synchron3rd_ee(
      neu_iso=false,
      pp=1,
      x_d=1.6,
      x_q=1.6,
      x_0=0.1,
      r_s=0.01,
      r_n=1,
      puUnits=true,
      V_nom=20e3,
      S_nom=500e6,
      f_nom=50);
  end SynchronIso20kV_500MVA;
end Machines;


Data

within PowerSystems.Examples;
package Data "Data"
  extends Modelica.Icons.MaterialPropertiesPackage;
end Data;


Breaker example data

within PowerSystems.Examples.Data;
package Semiconductors "Breaker example data"
  extends Modelica.Icons.MaterialPropertiesPackage;

  record IdealSC100V_10A "Ideal semiconductor parameters, example"
    extends PowerSystems.Semiconductors.Ideal.SCparameter(
      V_nom=100,
      I_nom=10,
      eps={1e-4,1e-4},
      Vf=1,
      Hsw_nom=2e-3,
      cT_loss=fill(0,0),
      T0_loss=300);
  end IdealSC100V_10A;

  record IdealSC1kV_100A "Ideal semiconductor parameters, example"
    extends PowerSystems.Semiconductors.Ideal.SCparameter(
      V_nom=100,
      I_nom=10,
      eps={1e-4,1e-4},
      Vf=2.5,
      Hsw_nom=0.25,
      cT_loss=fill(0,0),
      T0_loss=300);
  end IdealSC1kV_100A;

  record IdealSC3kV_500A "Ideal semiconductor parameters, example"
    extends PowerSystems.Semiconductors.Ideal.SCparameter(
      V_nom=3e3,
      I_nom=500,
      eps={1e-4,1e-4},
      Vf=3,
      Hsw_nom=5,
      cT_loss={0.005},
      T0_loss=300);
  end IdealSC3kV_500A;
end Semiconductors;


Transformer example data

within PowerSystems.Examples.Data;
package Transformers "Transformer example data"
  extends Modelica.Icons.MaterialPropertiesPackage;

record TrafoIdeal1ph "Ideal trafo, 1-phase, example"
  extends PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoIdeal1ph(
    puUnits=true,
    V_nom={15000,1400},
    S_nom=5e6,
    f_nom=50/3,
    tap_neutral={3,3},
    dv_tap={0.025,0.025});
end TrafoIdeal1ph;

record TrafoStray1ph "Trafo with ideal magnetic coupling, 1-phase, example"
  extends PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoStray1ph(
    puUnits=true,
    V_nom={15000,1400},
    S_nom=5e6,
    f_nom=50/3,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r={0.03,0.03},
    x={0.05,0.05});
end TrafoStray1ph;

record TrafoMag1ph "Trafo with magnetic coupling, 1-phase, example"
  extends PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoMag1ph(
    puUnits=true,
    V_nom={15000,1400},
    S_nom=5e6,
    f_nom=50/3,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r={0.03,0.03},
    x={0.05,0.05},
    redc=500,
    xm=500);
end TrafoMag1ph;

record TrafoSat1ph "Trafo with saturation, 1-phase, example"
  extends PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoSat1ph(
    puUnits=true,
    V_nom={15000,1400},
    S_nom=5e6,
    f_nom=50/3,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r={0.03,0.03},
    x={0.05,0.05},
    redc=500,
    xm=500,
    psi_sat(unit="1")=1.5,
    xm_sat=1);

end TrafoSat1ph;

record TrafoIdeal "Ideal trafo, 3-phase, example"
  extends PowerSystems.AC3ph.Transformers.Parameters.TrafoIdeal(
    puUnits=true,
    V_nom={20,400}*1e3,
    S_nom=1000e6,
    f_nom=50,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r_n={1,1});
end TrafoIdeal;

record TrafoStray "Trafo with ideal magnetic coupling, 3-phase, example"
  extends PowerSystems.AC3ph.Transformers.Parameters.TrafoStray(
    puUnits=true,
    V_nom={20,400}*1e3,
    S_nom=1000e6,
    f_nom=50,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r_n={1,1},
    r={0.005,0.005},
    x={0.05,0.05},
    x0={x[1],x[2]});
end TrafoStray;

record TrafoMag "Trafo with magnetic coupling, 3-phase, example"
  extends PowerSystems.AC3ph.Transformers.Parameters.TrafoMag(
    puUnits=true,
    V_nom={20,400}*1e3,
    S_nom=1000e6,
    f_nom=50,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r_n={1,1},
    r={0.005,0.005},
    x={0.05,0.05},
    x0={x[1],x[2]},
    redc=500,
    xm=500,
    xm0=50);
end TrafoMag;

record TrafoSat "Trafo with saturation, 3-phase, example"
  extends PowerSystems.AC3ph.Transformers.Parameters.TrafoSat(
    puUnits=true,
    V_nom={20,400}*1e3,
    S_nom=1000e6,
    f_nom=50,
    tap_neutral={3,3},
    dv_tap={0.025,0.025},
    r_n={1,1},
    r={0.005,0.005},
    x={0.05,0.05},
    x0={x[1],x[2]},
    redc=500,
    xm=500,
    xm0=50,
    psi_sat(unit="1")=1.5,
    xm_sat=1);
end TrafoSat;
end Transformers;


Turbine example data

within PowerSystems.Examples.Data;
package Turbines "Turbine example data"
  extends Modelica.Icons.MaterialPropertiesPackage;

  record SteamTurboGroup1200MW "Steam turbo-group, example"
    extends PowerSystems.Mechanics.TurboGroups.Parameters.SteamTurboGroup(
     w_nom(displayUnit="rpm")=314.15926535898,
     P_nom={480e6,240e6,240e6,240e6},
     J_turb={20000,200000,200000,200000},
     J_gen=62000,
     J_aux={460,830},
     stiff={260,355,750,750,750,220}*1e6);
  end SteamTurboGroup1200MW;

  record GasTurbineGear "Small GT with gear, example"
    extends PowerSystems.Mechanics.TurboGroups.Parameters.GasTurbineGear(
      w_nom=1576.7653528367,
      P_nom={12, -2}*1e6,
      J_turb=40,
      J_comp=50,
      J_gear1={0.6,12},
      J_gear2={5,200},
      J_acc=6,
      J_cpl=40,
      J_gen=2500,
      ratio={15057,5067,1500},
      stiff_sh={3,5.5,100,2500,250,200}*1e6,
      stiff_cpl=130*1e6);
  end GasTurbineGear;

  record HydroTurbine "Hydro turbine, example"
    extends PowerSystems.Mechanics.TurboGroups.Parameters.HydroTurbine(
      w_nom=314.15926535898,
      P_nom=20e6,
      J_turb=1000,
      J_shaft=5,
      J_gen=500,
      stiff=300e6);
  end HydroTurbine;

  record Diesel "Diesel, example"
    extends PowerSystems.Mechanics.TurboGroups.Parameters.Diesel(
      w_nom=157.07963267949,
      P_nom=100e3,
      J_turb=20,
      J_gen=20,
      stiff=1e6);
  end Diesel;

  record WindTurbineGear "Wind turbine with gear, example"
    extends PowerSystems.Mechanics.TurboGroups.Parameters.WindTurbineGear(
      w_nom=1.0471975511966,
      P_nom=30e3,
      J_turb=10,
      J_gear={0.3,0.1,0.03},
      J_gen=0.5,
      ratio={1,6,42},
      stiff_sh={16,1}*1e4);
  end WindTurbineGear;
end Turbines;