AC 1-phase and DC components

within PowerSystems.Examples.AC1ph_DC;
package Elementary "AC 1-phase and DC components"
  extends Modelica.Icons.ExamplesPackage;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.Control.Relays.SwitchRelay relay(
      n=1,
      ini_state=true,
      t_switch={0.1})
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(V_nom=10e3, use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind(r={0.1,0.1},
      V_nom=10e3,
      S_nom=1e6)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter(V_nom=10e3, S_nom=1e6)
    replaceable PowerSystems.AC1ph_DC.Breakers.Breaker breaker(V_nom=10e3, I_nom=100)
    PowerSystems.AC1ph_DC.Nodes.Ground grd
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, ind.term_p)
    connect(ind.term_n, meter.term_p)
    connect(meter.term_n, breaker.term_p)
    connect(breaker.term_n, grd.term)
    connect(relay.y[1], breaker.control)
    connect(grd1.term, voltage.neutral)
  end Breaker;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Control.Relays.SwitchRelay relay1(                       n=2, t_switch=
         {3.5,29.5}/50)
    PowerSystems.Control.Relays.SwitchRelay relay2(                       n=2, t_switch=
         {3.6,29.4}/50)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage1(V_nom=10e3, alpha0=
          0.17453292519943)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage2(V_nom=10e3)
    PowerSystems.AC1ph_DC.Breakers.DoubleSwitch switch1(V_nom=10e3,I_nom=100)
    PowerSystems.AC1ph_DC.Breakers.DoubleSwitch switch2(V_nom=10e3, I_nom=100)
    PowerSystems.AC1ph_DC.Lines.FaultRXline line(redeclare record Data =
      PowerSystems.AC1ph_DC.Lines.Parameters.RXline(V_nom = 10e3, S_nom=1e6))
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter(V_nom=10e3, S_nom=1e6)
    replaceable PowerSystems.AC1ph_DC.Faults.Fault_Ab fault_Ab
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2

  equation
    connect(voltage1.term, switch1.term_p)
    connect(switch1.term_n, line.term_p)
    connect(line.term_n, switch2.term_p)
    connect(switch2.term_n, voltage2.term)
    connect(line.term_f, meter.term_p)
    connect(meter.term_n,fault_Ab. term)
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(grd1.term, voltage1.neutral)
    connect(voltage2.neutral, grd2.term)
  end Fault;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    replaceable PowerSystems.AC1ph_DC.Impedances.Inductor ind(r={0.1,0.1})
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.Ground grd2

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, ind.term_p)
    connect(ind.term_n, grd2.term)
    connect(grd1.term, voltage.neutral)
  end Impedance;

  model ImpedanceOneTerm "Impedance One-terminal"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    replaceable PowerSystems.AC1ph_DC.ImpedancesOneTerm.Inductor ind(r=0.1)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, ind.term)
    connect(grd.term, voltage.neutral)
  end ImpedanceOneTerm;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh(ph_end=
          0.087266462599716)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage1(
      V_nom=132e3,
      use_vPhasor_in=true,
      alpha0=0.087266462599716)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage2(V_nom=132e3)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter(V_nom=132e3, S_nom=100e6)
    replaceable PowerSystems.AC1ph_DC.Lines.Tline line(redeclare record Data =
      PowerSystems.AC1ph_DC.Lines.Parameters.Line ( V_nom=132e3))
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2

  equation
    connect(transPh.y, voltage1.vPhasor_in)
    connect(voltage1.term, meter.term_p)
    connect(meter.term_n, line.term_p)
    connect(line.term_n, voltage2.term)
    connect(grd1.term, voltage1.neutral)
    connect(voltage2.neutral, grd2.term)
  end Line;

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

    inner PowerSystems.System system
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage1(V_nom=20e3, alpha0=0.5235987755983)
    PowerSystems.AC1ph_DC.Transformers.TrafoStray trafo(redeclare record Data =
          PowerSystems.Examples.Data.Transformers.TrafoStray1ph (
          V_nom={20e3,132e3},
          S_nom=100e6,
          f_nom=50))
    PowerSystems.AC1ph_DC.Lines.Tline line(len=480000, redeclare record Data =
          PowerSystems.AC1ph_DC.Lines.Parameters.Line(V_nom = 132e3))
    PowerSystems.AC1ph_DC.Breakers.Switch switch1(V_nom=132e3, I_nom=2500)
    PowerSystems.AC1ph_DC.Lines.FaultTline lineF(
      redeclare record Data =
          PowerSystems.AC1ph_DC.Lines.Parameters.Line(V_nom = 132e3), len=
          430000)
    PowerSystems.AC1ph_DC.Breakers.Switch switch2(V_nom=132e3, I_nom=2500)
    PowerSystems.AC1ph_DC.Faults.Fault_ab ab
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage2(V_nom=132e3, alpha0=0.5235987755983)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15,0.2}, n=1)
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153,0.21}, n=1)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterL(S_nom=1000e6, V_nom=132e3)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterF(S_nom=1000e6, V_nom=132e3)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2

  equation
    connect(trafo.term_n, meterL.term_p)
    connect(meterL.term_n, line.term_p)
    connect(line.term_n, voltage2.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, voltage2.term)
    connect(lineF.term_f, ab.term)
    connect(voltage1.term, trafo.term_p)
    connect(grd1.term, voltage1.neutral)
    connect(grd2.term, voltage2.neutral)
    connect(relay1.y[1], switch1.control)
    connect(relay2.y[1], switch2.control)
  end DoubleLine;

  model LoadAC "AC load"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.Transient[2] trsSignal(s_start={1,2}, s_end={2,3})
    PowerSystems.Blocks.Signals.TransientPhasor transPh(a_end=0.9)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    replaceable PowerSystems.AC1ph_DC.Loads.ZloadAC zLoadAC(use_pq_in=true)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, zLoadAC.term)
    connect(grd.term, voltage.neutral)
    connect(trsSignal.y,zLoadAC.pq_in)
  end LoadAC;

  model LoadDC "AC load"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Blocks.Signals.Transient trsSignalL(s_start=0.5, s_end=1)
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(use_vDC_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    replaceable PowerSystems.AC1ph_DC.Loads.PindLoadDC pLoadDC(use_p_in=true)
    PowerSystems.Blocks.Signals.Transient transV(s_end=0.9)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, pLoadDC.term)
    connect(grd.term, voltage.neutral)
    connect(transV.y, voltage.vDC_in)
    connect(trsSignalL.y, pLoadDC.p_in)
  end LoadDC;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Mechanics.Rotational.Rotor rotor
    PowerSystems.Mechanics.Rotational.Torque torq(tau0=-1)
    PowerSystems.Blocks.Signals.Transient transTau(s_start=0, s_end=-1)

    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage1(use_vDC_in=true, V_nom=
          100)
    PowerSystems.Blocks.Signals.Transient transV(s_start=0, s_end=1)
    PowerSystems.AC1ph_DC.Sensors.Psensor power
    replaceable PowerSystems.AC1ph_DC.Machines.DCser motor(redeclare
        replaceable record Data =
        PowerSystems.AC1ph_DC.Machines.Parameters.DCser(V_nom=100, S_nom=1e3))
      "DC machine series"
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)

  equation
    connect(voltage1.term, power.term_p)
    connect(power.term_n, motor.term)
    connect(motor.airgap,rotor.flange_a)
    connect(rotor.flange_b, torq.flange)
    connect(grd.term, voltage1.neutral)
    connect(transV.y, voltage1.vDC_in)
    connect(motor.heat, boundary.heat)
    connect(transTau.y, torq.tau_in)
  end Machines;

  model Sensor "Sensor and meter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Resistor res
    replaceable PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    PowerSystems.AC1ph_DC.Sources.Vspectrum voltage(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, res.term)
    connect(grd.term, voltage.neutral)
  end Sensor;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    replaceable PowerSystems.AC1ph_DC.Sources.ACvoltage voltage
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Inductor ind
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, ind.term)
    connect(grd.term, voltage.neutral)
  end Source;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.Control.Relays.TapChangerRelay tapChanger(
      preset_1={1,1,2},
      preset_2={1,1,2},
      t_switch_1={0.9,1.9},
      t_switch_2={1.1,2.1})
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter1
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter2(V_nom=10)
    replaceable PowerSystems.AC1ph_DC.Transformers.TrafoStray trafo(
      redeclare record Data =
          PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoStray1ph (
      tap_neutral={1,1},
      dv_tap = {0.1,0.2},
      V_nom = {1,10}),
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Resistor res(V_nom=10, r=100)
    PowerSystems.AC1ph_DC.Nodes.PolarityGround polGrd1(pol=0)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter1.term_p)
    connect(meter1.term_n, trafo.term_p)
    connect(trafo.term_n, meter2.term_p)
    connect(meter2.term_n, res.term)
    connect(res.term, polGrd1.term)
    connect(grd.term, voltage.neutral)
    connect(tapChanger.tap_1, trafo.tap_1_in)
    connect(tapChanger.tap_2, trafo.tap_2_in)
  end Transformer;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC1ph_DC.Sources.ACvoltage vAC(V_nom=2, use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1)
    replaceable PowerSystems.AC1ph_DC.Inverters.Rectifier rectifier
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)

  equation
    connect(transPh.y, vAC.vPhasor_in)
    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(grd1.term, vAC.neutral)
    connect(vDC.neutral, grd2.term)
    connect(rectifier.heat, boundary.heat)
  end Rectifier;

  model Inverter "Inverter, controlled rectifier"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial,
      dynType=PowerSystems.Types.Dynamics.FixedInitial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC1ph_DC.Sources.ACvoltage vAC(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1)
    replaceable PowerSystems.AC1ph_DC.Inverters.Inverter dc_ac
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0, V_nom=2)
    PowerSystems.AC1ph_DC.Inverters.Select select(alpha0=0.5235987755983)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)

  equation
    connect(transPh.y, vAC.vPhasor_in)
    connect(select.theta_out,dc_ac. theta)
    connect(select.vPhasor_out,dc_ac.vPhasor)
    connect(vDC.term, meterDC.term_p)
    connect(meterDC.term_n, dc_ac.DC)
    connect(dc_ac.AC, meterAC.term_p)
    connect(meterAC.term_n, ind.term_n)
    connect(ind.term_p, vAC.term)
    connect(grd1.term, vDC.neutral)
    connect(grd2.term, vAC.neutral)
    connect(dc_ac.heat, boundary.heat)
  end Inverter;
end Elementary;


Inverters 1 phase and DC

within PowerSystems.Examples.AC1ph_DC;
package Inverters "Inverters 1 phase and DC"
  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.AC1ph_DC.Sources.ACvoltage vAC(use_vPhasor_in=true, V_nom=100,
      pol=0)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind(r={0.05,0.05},
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Inverters.Rectifier rectifier(redeclare model
        Rectifier =
          PowerSystems.AC1ph_DC.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.AC1ph_DC.Nodes.GroundOne grd1
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(vAC.term, ind.term_p)
    connect(ind.term_n, meterAC.term_p)
    connect(meterDC.term_n, vDC.term)
    connect(meterAC.term_n, rectifier.AC)
    connect(rectifier.DC, meterDC.term_p)
    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(dynType=PowerSystems.Types.Dynamics.FixedInitial,
      refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(V_nom=100)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Inverters.Inverter inverter(redeclare model Inverter =
        PowerSystems.AC1ph_DC.Inverters.Components.InverterEquation(redeclare
            record Data =
            PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
        "equation, with losses")
    PowerSystems.AC1ph_DC.Inverters.Select select(
      fType=PowerSystems.Types.SourceFrequency.Parameter,
      f=100,
      use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Inductor ind(x=0.5, r=0.5,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.05,
      t_duration=0.05,
      a_start=1.05,
      a_end=1.05,
      ph_end=0.5235987755983)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(vDC.term, meterDC.term_p)
    connect(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    connect(meterAC.term_n, ind.term)
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(vCtrl.y,select.vPhasor_in)
    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(dynType=PowerSystems.Types.Dynamics.FixedInitial,
      refType=PowerSystems.Types.ReferenceFrame.Inertial)
    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.AC1ph_DC.Inverters.Inverter inverter(redeclare model Inverter =
        PowerSystems.AC1ph_DC.Inverters.Components.InverterEquation (
          redeclare record Data =
          PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
        "equation, with losses")
    PowerSystems.AC1ph_DC.Inverters.Select select(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind(r={0.05,0.05},
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Sources.ACvoltage vAC(V_nom=100)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.1,
      t_duration=0.1,
      a_start=1,
      a_end=1,
      ph_end=0.5235987755983)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(vAC.term, ind.term_p)
    connect(vDC.term, meterDC.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(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    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,
      refType=PowerSystems.Types.ReferenceFrame.Inertial)
    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.AC1ph_DC.Inverters.InverterAverage inverter(redeclare record
        Data=PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A)
    PowerSystems.AC1ph_DC.Inverters.Select select(use_vPhasor_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterAC(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Impedances.Inductor ind(r={0.05,0.05},
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Sources.ACvoltage vAC(V_nom=100)
    PowerSystems.Blocks.Signals.TransientPhasor vCtrl(
      t_change=0.1,
      t_duration=0.1,
      ph_end=0.5235987755983)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=1)

  equation
    connect(vAC.term, ind.term_p)
    connect(vDC.term, meterDC.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(meterDC.term_n, inverter.DC)
    connect(inverter.AC, meterAC.term_p)
    connect(inverter.heat, bdCond.heat)
  end InverterAvToGrid;

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

    inner PowerSystems.System system(dynType=PowerSystems.Types.Dynamics.FixedInitial,
      refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(V_nom=100)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDCin(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Inverters.Chopper chopper(redeclare model Chopper =
      PowerSystems.AC1ph_DC.Inverters.Components.ChopperModular(redeclare
            record Data =
               PowerSystems.Examples.Data.Semiconductors.IdealSC100V_10A))
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDCout(av=true, tcst=0.1,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.Blocks.Signals.Transient vDCoutCtrl(
      t_change=0,
      t_duration=0.2,
      s_start=0,
      s_end=0.7)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Inductor load(x=0.5, r=0.5,
      V_nom=100,
      S_nom=1e3)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)

  equation
    connect(grd.term, vDC.neutral)
    connect(vDC.term, meterDCin.term_p)
    connect(meterDCin.term_n, chopper.DCin)
    connect(chopper.DCout, meterDCout.term_p)
    connect(meterDCout.term_n, load.term)
    connect(vDCoutCtrl.y,chopper.vDC)
    connect(chopper.heat, bdCond.heat)
  end Chopper;
end Inverters;


Examples for AC1ph_DC components

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


Transformation 1 phase

within PowerSystems.Examples.AC1ph_DC;
package Transformation "Transformation 1 phase"
  extends Modelica.Icons.ExamplesPackage;

  model OnePhase "One phase transformer"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC1ph_DC.Sources.ACvoltage voltage(pol=-1)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter1
    PowerSystems.AC1ph_DC.Nodes.BusBar bus
    PowerSystems.AC1ph_DC.Transformers.TrafoStray trafo(
      redeclare record Data =
        PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoStray1ph(V_nom={1,10}))
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter2(V_nom=10)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Resistor res(V_nom=10, r=1000)
    PowerSystems.AC1ph_DC.Nodes.PolarityGround polGrd(pol=0)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd

  equation
    connect(voltage.term, meter1.term_p)
    connect(meter1.term_n, bus.term)
    connect(bus.term, trafo.term_p)
    connect(trafo.term_n, meter2.term_p)
    connect(meter2.term_n, res.term)
    connect(res.term, polGrd.term)
    connect(grd.term, voltage.neutral)
  end OnePhase;

  model TapChanger "One phase tap changing primary and secondary"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    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.AC1ph_DC.Sources.ACvoltage voltage(pol=-1)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter1
    PowerSystems.AC1ph_DC.Nodes.BusBar bus
    PowerSystems.AC1ph_DC.Transformers.TrafoStray trafo1(
      redeclare record Data =
      PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoStray1ph (
      dv_tap={0.1,0.1},
      V_nom={1,10}),
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter12(V_nom=10)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Resistor res12(V_nom=10, r=1000)
    PowerSystems.AC1ph_DC.Transformers.TrafoStray trafo2(
      redeclare record Data =
      PowerSystems.AC1ph_DC.Transformers.Parameters.TrafoStray1ph (
      dv_tap={0.1,0.1},
      V_nom={1,10}),
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC1ph_DC.Sensors.PVImeter meter22(V_nom=10)
    PowerSystems.AC1ph_DC.ImpedancesOneTerm.Resistor res22(V_nom=10, r=1000)
    PowerSystems.AC1ph_DC.Nodes.PolarityGround polGrd1(pol=0)
    PowerSystems.AC1ph_DC.Nodes.PolarityGround polGrd2(pol=0)
    PowerSystems.AC1ph_DC.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(res12.term, polGrd1.term)
    connect(res22.term, polGrd2.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;
end Transformation;


AC drives, dq0

within PowerSystems.Examples.AC3ph;
package Drives "AC drives, dq0"
  extends Modelica.Icons.ExamplesPackage;

  model ASMcharacteristic
    "AC asynchronous machine: torque - slip characteristic"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(dynType=PowerSystems.Types.Dynamics.SteadyState)
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.AC3ph.Sources.Voltage voltage(V_nom=400)
    PowerSystems.AC3ph.Drives.ASM asm(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron (
        redeclare record Data =
            PowerSystems.Examples.Data.Machines.Asynchron400V_30kVA))
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)
    PowerSystems.Mechanics.Rotational.Speed speed(
      w0=system.omega_nom/2,
      use_w_in=true,
      tcst=0.01)
    PowerSystems.Blocks.Signals.Transient speedSignal(
    t_duration=0.5,
      s_end=2*system.omega_nom/asm.motor.pp,
      s_start=-system.omega_nom/asm.motor.pp)

  equation
    connect(grd.term, voltage.neutral)
    connect(asm.flange, speed.flange)
    connect(asm.heat, bdCond.heat)
    connect(voltage.term, asm.term)
    connect(speedSignal.y, speed.w_in)
  end ASMcharacteristic;

  model ASM_Y_D "AC asynchronous machine Y-Delta switcheable"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.AC3ph.Sources.Voltage voltage(V_nom=400, v0=1)
    PowerSystems.AC3ph.Sensors.Psensor power
    PowerSystems.AC3ph.Drives.ASM_Y_D asm_Y_D(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Motor = PowerSystems.AC3ph.Machines.AsynchronY_D (
        redeclare record Data =
            PowerSystems.Examples.Data.Machines.Asynchron400V_30kVA),
      w_start=4.1887902047864)
    PowerSystems.Common.Thermal.BdCondV bdCond(m=2)
    PowerSystems.Mechanics.Rotational.Rotor loadInertia(J=40)
    PowerSystems.Mechanics.Rotational.FrictionTorque frictTorq(cFrict={1,0.05})
    PowerSystems.Control.Relays.Y_DeltaControl relay1(t_switch={1.5})

  equation
    connect(relay1.y,asm_Y_D. YDcontrol)
    connect(voltage.term, power.term_p)
    connect(asm_Y_D.flange,loadInertia.flange_a)
    connect(loadInertia.flange_b, frictTorq.flange)
    connect(grd.term, voltage.neutral)
    connect(power.term_n, asm_Y_D.term)
    connect(asm_Y_D.heat, bdCond.heat)
  end ASM_Y_D;

  model ASMav
    "AC asynchronous machine, voltage controlled with average inverter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Synchron)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*6000)
    PowerSystems.AC3ph.Inverters.Select select
    PowerSystems.AC3ph.Inverters.InverterAverage inverter(redeclare record Data =
      PowerSystems.Examples.Data.Semiconductors.IdealSC3kV_500A)
    PowerSystems.AC3ph.Sensors.PVImeter power(av=true,
      tcst=0.05)
    PowerSystems.AC3ph.Drives.ASM asm(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=6.4),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron (
        redeclare record Data =
            PowerSystems.Examples.Data.Machines.Asynchron3kV_1p5MVA),
      w_start=157.07963267949)
    PowerSystems.Common.Thermal.BdCondV bdCond1(m=2)
    PowerSystems.Common.Thermal.BdCondV bdCond2(m=1)
    PowerSystems.Mechanics.Rotational.TabPosSlopeTorque tabLoad(
      r=0.4,
      gRatio=40/17,
      cFrict={50,15},
      mass=200e3,
      scale=true,
      D=1.5e3,
      slope_scale=0.025,
      tableName="height",
      fileName=TableDir + "hNormProfile.tab",
      colData=3)

  equation
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(voltage.term, inverter.DC)
    connect(inverter.AC, power.term_p)
    connect(power.term_n, asm.term)
    connect(grd.term, voltage.neutral)
    connect(asm.flange,tabLoad.flange_a)
    connect(asm.heat, bdCond1.heat)
    connect(inverter.heat,bdCond2. heat)
  end ASMav;

  model ASMav_icontrol
    "AC asynchronous machine, current controlled with average inverter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Synchron)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*6000)
    PowerSystems.AC3ph.Drives.ASM_ctrl asm_ctrl(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron_ctrl (
        redeclare record Data =
            PowerSystems.Examples.Data.Machines.Asynchron3kV_1p5MVA),
      redeclare model Inverter = PowerSystems.AC3ph.Inverters.InverterAverage (
        redeclare record Data =
          PowerSystems.Examples.Data.Semiconductors.IdealSC3kV_500A),
      w_start=157.07963267949)
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)
    PowerSystems.Mechanics.Rotational.TabPosSlopeTorque tabLoad(
      r=0.4,
      gRatio=40/17,
      cFrict={50,15},
      mass=200e3,
      scale=true,
      D=1.5e3,
      slope_scale=0.025,
      tableName="height",
      fileName=TableDir + "hNormProfile.tab",
      colData=3)
    PowerSystems.Blocks.Signals.Transient i_q(s_end=0.2, s_start=0)
      "phase of modulation signal"
    PowerSystems.Blocks.Signals.Transient i_d(
      s_start=0.36,
      s_end=0.36,
      t_change=30,
      t_duration=60) "phase of modulation signal"
    Modelica.Blocks.Continuous.LimPID PI_i_q(
      Td=0.1,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      Ti=0.1,
      yMax=1,
      initType=Modelica.Blocks.Types.Init.SteadyState,
      gainPID(y(start=0.1)))

  equation
    connect(grd.term, voltage.neutral)
    connect(voltage.term, asm_ctrl.term)
    connect(asm_ctrl.flange,tabLoad.flange_a)
    connect(i_q.y,PI_i_q. u_s)
    connect(i_d.y, asm_ctrl.i_act[1])
    connect(asm_ctrl.i_meas[2], PI_i_q.u_m)
    connect(PI_i_q.y, asm_ctrl.i_act[2])
    connect(asm_ctrl.heat, bdCond.heat)
  end ASMav_icontrol;

  model ASM "AC asynchronous machine, voltage controlled"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*6000)
    PowerSystems.AC3ph.Inverters.Select select
    PowerSystems.AC3ph.Inverters.Inverter inverter
    PowerSystems.AC3ph.Sensors.PVImeter power(
      av=true,
      tcst=0.05,
      abc=true)
    PowerSystems.AC3ph.Drives.ASM asm(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=6.4),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron (
        redeclare record Data =
            PowerSystems.Examples.Data.Machines.Asynchron3kV_1p5MVA),
      w_start=157.07963267949)
    PowerSystems.Common.Thermal.BdCondV bdCond1(m=2)
    PowerSystems.Common.Thermal.BdCondV bdCond2(m=3)
    PowerSystems.Mechanics.Rotational.TabPosSlopeTorque tabLoad(
      r=0.4,
      gRatio=40/17,
      cFrict={50,15},
      mass=200e3,
      scale=true,
      D=1.5e3,
      slope_scale=0.025,
      tableName="height",
      fileName=TableDir + "hNormProfile.tab",
      colData=3)

  equation
    connect(select.theta_out, inverter.theta)
    connect(select.vPhasor_out,inverter.vPhasor)
    connect(voltage.term, inverter.DC)
    connect(inverter.AC, power.term_p)
    connect(power.term_n, asm.term)
    connect(grd.term, voltage.neutral)
    connect(asm.flange,tabLoad.flange_a)
    connect(asm.heat, bdCond1.heat)
    connect(inverter.heat,bdCond2. heat)
  end ASM;

  model SM_ctrlAv
    "AC synchronous pm machine, current controlled with average inverter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*2*400)
    PowerSystems.AC3ph.Drives.SM_ctrl sm_ctrl(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Inverter = PowerSystems.AC3ph.Inverters.InverterAverage (
        redeclare record Data =
          PowerSystems.Examples.Data.Semiconductors.IdealSC1kV_100A),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Synchron3rd_pm_ctrl (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron3rd_pm400V_30kVA))
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)
    PowerSystems.Mechanics.Rotational.Rotor loadInertia(J=0.5)
    PowerSystems.Mechanics.Rotational.FrictionTorque frictTorq(cFrict={0.1,0.01})
    Modelica.Mechanics.Rotational.Sources.TorqueStep torqueStep(
      offsetTorque=0,
      startTime=6,
      stepTorque=-100,
      useSupport=false)
    PowerSystems.Blocks.Signals.Transient i_q(t_change=3, s_start=0.1)
      "phase of modulation signal"
    PowerSystems.Blocks.Signals.Transient i_d(
      t_change=3,
      s_start=0,
      s_end=0) "phase of modulation signal"
    Modelica.Blocks.Continuous.LimPID PI_i_q(
      Ti=0.2,
      Td=0.1,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      initType=Modelica.Blocks.Types.Init.SteadyState,
      yMax=1,
      gainPID(y(start=0.1)))

  equation
    connect(sm_ctrl.heat, bdCond.heat)
    connect(grd.term, voltage.neutral)
    connect(i_q.y, PI_i_q.u_s)
    connect(sm_ctrl.flange,loadInertia.flange_a)
    connect(loadInertia.flange_b, frictTorq.flange)
    connect(loadInertia.flange_b, torqueStep.flange)
    connect(voltage.term, sm_ctrl.term)
    connect(sm_ctrl.i_meas[2], PI_i_q.u_m)
    connect(PI_i_q.y, sm_ctrl.i_act[2])
    connect(i_d.y, sm_ctrl.i_act[1])
  end SM_ctrlAv;

  model SM_ctrl "AC synchronous pm machine, current controlled"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*2*400)
    PowerSystems.AC3ph.Drives.SM_ctrl sm_ctrl(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Inverter = PowerSystems.AC3ph.Inverters.Inverter (
        redeclare model Inverter =
          PowerSystems.AC3ph.Inverters.Components.InverterSwitch
            "switch, no diode, no losses") "inverter with modulator",
      redeclare model Motor = PowerSystems.AC3ph.Machines.Synchron3rd_pm_ctrl (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Synchron3rd_pm400V_30kVA(r_n=0)))
    PowerSystems.Common.Thermal.BdCondV bdCond(m=5)
    PowerSystems.Mechanics.Rotational.Rotor loadInertia(J=0.5)
    PowerSystems.Mechanics.Rotational.FrictionTorque frictTorq(cFrict={0.1,0.01})
    Modelica.Mechanics.Rotational.Sources.TorqueStep torqueStep(
      offsetTorque=0,
      stepTorque=-100,
      startTime=2,
      useSupport=false)
    PowerSystems.Blocks.Signals.Transient i_q(
                    s_start=0.1) "phase of modulation signal"
    Modelica.Blocks.Continuous.LimPID PI_i_q(
      Td=0.05,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      Ti=0.2,
      initType=Modelica.Blocks.Types.Init.InitialState,
      xi_start=0.1,
      yMax=1)
    PowerSystems.Blocks.Signals.Transient i_d(
      s_start=0,
      s_end=0) "phase of modulation signal"

  equation
    connect(sm_ctrl.heat, bdCond.heat)
    connect(grd.term, voltage.neutral)
    connect(i_q.y, PI_i_q.u_s)
    connect(sm_ctrl.flange,loadInertia.flange_a)
    connect(loadInertia.flange_b, frictTorq.flange)
    connect(loadInertia.flange_b, torqueStep.flange)
    connect(voltage.term, sm_ctrl.term)
    connect(sm_ctrl.i_meas[2], PI_i_q.u_m)
    connect(PI_i_q.y, sm_ctrl.i_act[2])
    connect(i_d.y, sm_ctrl.i_act[1])
  end SM_ctrl;

  model ASM_ctrlAv
    "AC asynchronous machine, current controlled with average inverter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*2*400)
    PowerSystems.AC3ph.Drives.ASM_ctrl asm_ctrl(
      rotor(J=0.3),
      redeclare model Inverter = PowerSystems.AC3ph.Inverters.InverterAverage (
        redeclare record Data =
          PowerSystems.Examples.Data.Semiconductors.IdealSC1kV_100A),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron_ctrl (
            redeclare record Data =
              PowerSystems.Examples.Data.Machines.Asynchron400V_30kVA,
            i_start={10,10,0}))
    PowerSystems.Common.Thermal.BdCondV bdCond(m=3)
    PowerSystems.Mechanics.Rotational.Rotor loadInertia(J=0.5)
    PowerSystems.Mechanics.Rotational.FrictionTorque frictTorq(cFrict={5,0.5})
    Modelica.Mechanics.Rotational.Sources.TorqueStep torqueStep(
      offsetTorque=0,
      startTime=6,
      stepTorque=-200,
      useSupport=false)
    PowerSystems.Blocks.Signals.Transient i_q(t_change=3,
      s_end=0.7,
      s_start=0.6) "phase of modulation signal"
    PowerSystems.Blocks.Signals.Transient i_d(
      t_change=8,
      s_end=0.45,
      s_start=0.35) "phase of modulation signal"
    Modelica.Blocks.Continuous.LimPID PI_i_q(
      Td=0.1,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      Ti=0.1,
      yMax=1,
      gainPID(y(start=0.1)),
      initType=Modelica.Blocks.Types.Init.SteadyState)

  equation
    connect(asm_ctrl.heat, bdCond.heat)
    connect(grd.term, voltage.neutral)
    connect(i_q.y, PI_i_q.u_s)
    connect(asm_ctrl.flange,loadInertia.flange_a)
    connect(loadInertia.flange_b, frictTorq.flange)
    connect(loadInertia.flange_b, torqueStep.flange)
    connect(voltage.term, asm_ctrl.term)
    connect(asm_ctrl.i_meas[2], PI_i_q.u_m)
    connect(PI_i_q.y, asm_ctrl.i_act[2])
    connect(i_d.y, asm_ctrl.i_act[1])
  end ASM_ctrlAv;

  model ASM_ctrl "AC asynchronous machine, current controlled"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.AC1ph_DC.Nodes.GroundOne grd
    PowerSystems.AC1ph_DC.Sources.DCvoltage voltage(pol=0, V_nom=sqrt(2/3)*2*400)
    PowerSystems.AC3ph.Drives.ASM_ctrl asm_ctrl(
      redeclare model Rotor = PowerSystems.Mechanics.Rotational.ElectricRotor (
                                                                            J=0.3),
      redeclare model Motor = PowerSystems.AC3ph.Machines.Asynchron_ctrl (
        redeclare record Data =
          PowerSystems.Examples.Data.Machines.Asynchron400V_30kVA(r_n=0)),
      redeclare model Inverter = PowerSystems.AC3ph.Inverters.Inverter (
        redeclare model Inverter =
          PowerSystems.AC3ph.Inverters.Components.InverterSwitch
            "switch, no diode, no losses") "inverter with modulator",
      w_start=0.10471975511966)
    PowerSystems.Common.Thermal.BdCondV bdCond(m=5)
    PowerSystems.Mechanics.Rotational.Rotor loadInertia(J=0.5, w_start(
          displayUnit="rpm") = 0.10471975511966)
    PowerSystems.Mechanics.Rotational.FrictionTorque frictTorq(cFrict={5,0.5})
    Modelica.Mechanics.Rotational.Sources.TorqueStep torqueStep(
      offsetTorque=0,
      startTime=2,
      stepTorque=-200,
      useSupport=false)
    PowerSystems.Blocks.Signals.Transient i_q(s_start=0.6, s_end=0.7)
      "phase of modulation signal"
    Modelica.Blocks.Continuous.LimPID PI_i_q(
      Td=0.05,
      controllerType=Modelica.Blocks.Types.SimpleController.PI,
      Ti=0.1,
      yMax=1)
    PowerSystems.Blocks.Signals.Transient i_d(
      s_end=0.45,
      t_change=2.5,
      t_duration=0.5,
      s_start=0.35) "phase of modulation signal"

  equation
    connect(asm_ctrl.heat, bdCond.heat)
    connect(grd.term, voltage.neutral)
    connect(i_q.y, PI_i_q.u_s)
    connect(asm_ctrl.flange,loadInertia.flange_a)
    connect(loadInertia.flange_b, frictTorq.flange)
    connect(loadInertia.flange_b, torqueStep.flange)
    connect(voltage.term, asm_ctrl.term)
    connect(asm_ctrl.i_meas[2], PI_i_q.u_m)
    connect(PI_i_q.y, asm_ctrl.i_act[2])
    connect(i_d.y, asm_ctrl.i_act[1])
  end ASM_ctrl;
end Drives;


AC 3-phase components dq0

within PowerSystems.Examples.AC3ph;
package Elementary "AC 3-phase components dq0"
  extends Modelica.Icons.ExamplesPackage;

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

    inner PowerSystems.System system
    PowerSystems.AC3ph.Nodes.Ground grd2
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(V_nom=10e3, use_vPhasor_in=true)
    PowerSystems.AC3ph.Impedances.Inductor ind(
      r=0.1,
      V_nom=10e3,
      S_nom=1e6)
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=10e3, S_nom=1e6)
    replaceable PowerSystems.AC3ph.Breakers.Breaker breaker(V_nom=10e3, I_nom=100)
    PowerSystems.Control.Relays.SwitchRelay relay(t_switch={0.1})
    PowerSystems.AC3ph.Nodes.GroundOne grd1

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(relay.y, breaker.control)
    connect(voltage.term, ind.term_p)
    connect(ind.term_n, meter.term_p)
    connect(meter.term_n, breaker.term_p)
    connect(breaker.term_n, grd2.term)
    connect(grd1.term, voltage.neutral)
  end Breaker;

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

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.Voltage voltage1(
      V_nom=10e3, alpha0=0.17453292519943)
    PowerSystems.AC3ph.Breakers.Switch switch1(V_nom=10e3, I_nom=100)
    PowerSystems.AC3ph.Lines.FaultRXline line(redeclare record Data =
      PowerSystems.AC3ph.Lines.Parameters.RXline(V_nom=10e3, S_nom=1e6))
    PowerSystems.AC3ph.Breakers.Switch switch2(V_nom=10e3, I_nom=100)
    PowerSystems.AC3ph.Sources.Voltage voltage2(V_nom=10e3)
    PowerSystems.Control.Relays.SwitchRelay relay1(t_switch={0.15})
    PowerSystems.Control.Relays.SwitchRelay relay2(t_switch={0.153})
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=10e3, S_nom=1e6)
    replaceable PowerSystems.AC3ph.Faults.Fault_ab fault_ab
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(relay1.y, switch1.control)
    connect(relay2.y, switch2.control)
    connect(voltage1.term, switch1.term_p)
    connect(switch1.term_n, line.term_p)
    connect(line.term_n, switch2.term_p)
    connect(switch2.term_n, voltage2.term)
    connect(line.term_f, meter.term_p)
    connect(meter.term_n, fault_ab.term)
    connect(grd1.term, voltage1.neutral)
    connect(voltage2.neutral, grd2.term)
  end Fault;

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

    inner PowerSystems.System system
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter
    replaceable PowerSystems.AC3ph.Impedances.Inductor ind(r=0.1)
    PowerSystems.AC3ph.Nodes.Ground grd2
    PowerSystems.AC3ph.Nodes.GroundOne grd1

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, ind.term_p)
    connect(ind.term_n, grd2.term)
    connect(grd1.term, voltage.neutral)
  end Impedance;

  model ImpedanceYD "Impedance Y-Delta"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter
    replaceable PowerSystems.AC3ph.ImpedancesYD.Inductor indYD(r=0.1)
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, indYD.term)
    connect(grd.term, voltage.neutral)
  end ImpedanceYD;

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

    inner PowerSystems.System system
    PowerSystems.Blocks.Signals.TransientPhasor transPh(ph_end=
          0.087266462599716)
    PowerSystems.AC3ph.Sources.Voltage voltage1(
      V_nom=132e3,
      use_vPhasor_in=true,
      alpha0=0.087266462599716)
    PowerSystems.AC3ph.Sensors.PVImeter meter(V_nom=132e3, S_nom=100e6)
    PowerSystems.AC3ph.Sources.Voltage voltage2(V_nom=132e3)
    replaceable PowerSystems.AC3ph.Lines.Tline line(redeclare record Data =
          PowerSystems.AC3ph.Lines.Parameters.Line (  V_nom=132e3))
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2

  equation
    connect(transPh.y, voltage1.vPhasor_in)
    connect(voltage1.term, meter.term_p)
    connect(meter.term_n, line.term_p)
    connect(line.term_n, voltage2.term)
    connect(grd1.term, voltage1.neutral)
    connect(voltage2.neutral, grd2.term)
  end Line;

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

    inner PowerSystems.System system
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter
    replaceable PowerSystems.AC3ph.Loads.PQindLoad load(tcst=0.01, use_pq_in=true)
    PowerSystems.Blocks.Signals.Transient[2] trsSignal(s_start={sqrt(3)/2,1/2}, s_end={1,0.2})
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(trsSignal.y,load.pq_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, load.term)
    connect(grd.term, voltage.neutral)
  end Load;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Synchron)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(
      v0=1,
      use_vPhasor_in=true,
      V_nom=400)
    PowerSystems.AC3ph.Sensors.Psensor power
    replaceable PowerSystems.AC3ph.Machines.Asynchron asynchron(
      redeclare record Data =
        PowerSystems.AC3ph.Machines.Parameters.Asynchron_cage(V_nom=400, S_nom=1e3))
    PowerSystems.Mechanics.Rotational.Rotor rotor(w_start = 314.1592653589793)
    PowerSystems.Mechanics.Rotational.Torque torq
    PowerSystems.Blocks.Signals.Transient trsSignal
    PowerSystems.AC3ph.Nodes.GroundOne grd
    PowerSystems.Common.Thermal.BoundaryV boundary(m=2)

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, power.term_p)
    connect(power.term_n, asynchron.term)
    connect(asynchron.airgap,rotor.flange_a)
    connect(rotor.flange_b, torq.flange)
    connect(grd.term, voltage.neutral)
    connect(asynchron.heat, boundary.heat)
    connect(trsSignal.y, torq.tau_in)
  end Machines;

  model Sensor "Sensor and meter"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system
    PowerSystems.AC3ph.Sources.Vspectrum voltage(use_vPhasor_in=true)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    replaceable PowerSystems.AC3ph.Sensors.PVImeter meter(abc=true)
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, res.term)
    connect(grd.term, voltage.neutral)
  end Sensor;

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

    inner PowerSystems.System system
    PowerSystems.AC3ph.ImpedancesYD.Inductor ind(r=0.1)
    PowerSystems.AC3ph.Sensors.PVImeter meter(abc=true)
    replaceable PowerSystems.AC3ph.Sources.Voltage voltage
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(voltage.term, meter.term_p)
    connect(meter.term_n, ind.term)
    connect(grd.term, voltage.neutral)
  end Source;

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

    inner PowerSystems.System system
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage voltage(use_vPhasor_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter1
    replaceable PowerSystems.AC3ph.Transformers.TrafoStray trafo(
      redeclare record Data =
          PowerSystems.AC3ph.Transformers.Parameters.TrafoStray (
      tap_neutral={1,1},
      dv_tap={0.1, 0.2},
      V_nom={1,10}),
      redeclare model Topology_p = PowerSystems.AC3ph.Ports.Topology.Y,
      redeclare model Topology_n = PowerSystems.AC3ph.Ports.Topology.Delta,
      use_tap_1_in=true,
      use_tap_2_in=true)
    PowerSystems.AC3ph.Sensors.PVImeter meter2(V_nom=10)
    PowerSystems.AC3ph.ImpedancesYD.Resistor res(V_nom=10, r=100)
    PowerSystems.Control.Relays.TapChangerRelay tapChanger(
      preset_1={1,1,2},
      preset_2={1,1,2},
      t_switch_1={0.9,1.9},
      t_switch_2={1.1,2.1})
    PowerSystems.AC3ph.Nodes.GroundOne grd

  equation
    connect(transPh.y, voltage.vPhasor_in)
    connect(voltage.term, meter1.term_p)
    connect(meter1.term_n, trafo.term_p)
    connect(trafo.term_n, meter2.term_p)
    connect(meter2.term_n, res.term)
    connect(grd.term, voltage.neutral)
    connect(tapChanger.tap_1, trafo.tap_1_in)
    connect(tapChanger.tap_2, trafo.tap_2_in)
  end Transformer;

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

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage vAC(V_nom=2, use_vPhasor_in=true)
    PowerSystems.AC3ph.Impedances.Inductor ind(r=0.05)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(av=true, tcst=0.1)
    replaceable PowerSystems.AC3ph.Inverters.Rectifier rectifier
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0)
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=3)

  equation
    connect(transPh.y, vAC.vPhasor_in)
    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(grd1.term, vAC.neutral)
    connect(vDC.neutral, grd2.term)
    connect(rectifier.heat, boundary.heat)
  end Rectifier;

  model Inverter "Inverter, controlled rectifier"
    extends Modelica.Icons.Example;

    inner PowerSystems.System system(refType=PowerSystems.Types.ReferenceFrame.Inertial)
    PowerSystems.Blocks.Signals.TransientPhasor transPh
    PowerSystems.AC3ph.Sources.Voltage vAC(V_nom=2, use_vPhasor_in=true)
    PowerSystems.AC3ph.Impedances.Inductor ind(r=0.05)
    PowerSystems.AC3ph.Sensors.PVImeter meterAC(av=true, tcst=0.1)
    replaceable PowerSystems.AC3ph.Inverters.Inverter ac_dc
    PowerSystems.AC1ph_DC.Sensors.PVImeter meterDC(av=true, tcst=0.1)
    PowerSystems.AC1ph_DC.Sources.DCvoltage vDC(pol=0)
    PowerSystems.AC3ph.Inverters.Select select
    PowerSystems.AC3ph.Nodes.GroundOne grd1
    PowerSystems.AC3ph.Nodes.GroundOne grd2
    PowerSystems.Common.Thermal.BoundaryV boundary(m=3)

  equation
    connect(transPh.y, vAC.vPhasor_in)
    connect(vAC.term, ind.term_p)
    connect(ind.term_n, meterAC.term_p)
    connect(meterAC.term_n, ac_dc.AC)
    connect(ac_dc.DC, meterDC.term_p)
    connect(meterDC.term_n, vDC.term)
    connect(select.theta_out, ac_dc.theta)
    connect(select.vPhasor_out,ac_dc.vPhasor)
    connect(grd1.term, vAC.neutral)
    connect(vDC.neutral, grd2.term)
    connect(ac_dc.heat, boundary.heat)
  end Inverter;
end Elementary;


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;