Trapezoidal current source. This current source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model TrapezoidCurrent "Trapezoidal current source"
  parameter SI.Current I(start=1) "Amplitude of trapezoid";
  parameter SI.Time rising(final min=0, start=0)
    "Rising duration of trapezoid";
  parameter SI.Time width(final min=0, start=0.5)
    "Width duration of trapezoid";
  parameter SI.Time falling(final min=0, start=0)
    "Falling duration of trapezoid";
  parameter SI.Time period(final min=Modelica.Constants.small, start=1)
    "Time for one period";
  parameter Integer nperiod(start=-1)
    "Number of periods (< 0 means infinite number of periods)";
  extends Interfaces.CurrentSource(redeclare
      Modelica.Blocks.Sources.Trapezoid signalSource(
      final amplitude=I,
      final rising=rising,
      final width=width,
      final falling=falling,
      final period=period,
      final nperiod=nperiod));
end TrapezoidCurrent;


Trapezoidal voltage source. This voltage source uses the corresponding signal source of the Modelica.Blocks.Sources package. Care for the meaning of the parameters in the Blocks package. Furthermore, an offset parameter is introduced, which is added to the value calculated by the blocks source. The startTime parameter allows to shift the blocks source behavior on the time axis.

within Modelica.Electrical.Analog.Sources;
model TrapezoidVoltage "Trapezoidal voltage source"
  parameter SI.Voltage V(start=1) "Amplitude of trapezoid";
  parameter SI.Time rising(final min=0, start=0)
    "Rising duration of trapezoid";
  parameter SI.Time width(final min=0, start=0.5)
    "Width duration of trapezoid";
  parameter SI.Time falling(final min=0, start=0)
    "Falling duration of trapezoid";
  parameter SI.Time period(final min=Modelica.Constants.small, start=1)
    "Time for one period";
  parameter Integer nperiod(start=-1)
    "Number of periods (< 0 means infinite number of periods)";
  extends Interfaces.VoltageSource(redeclare
      Modelica.Blocks.Sources.Trapezoid signalSource(
      final amplitude=V,
      final rising=rising,
      final width=width,
      final falling=falling,
      final period=period,
      final nperiod=nperiod));
end TrapezoidVoltage;


Type definitions

within Modelica.Electrical.Analog;
package Types "Type definitions"
extends Modelica.Icons.TypesPackage;
end Types;


Simple battery models

within Modelica.Electrical;
package Batteries "Simple battery models"
  extends Modelica.Icons.Package;
end Batteries;


Battery with open-circuit voltage dependent on state of charge, self-discharge and inner resistance. The battery is modeled by open-circuit voltage (OCV) dependent on state of charge (SOC), a self-discharge component and an inner resistance.

Parameters are collected in parameter record cellData.

All losses are dissipated to the optional heatPort.

within Modelica.Electrical.Batteries.BaseClasses;
partial model BaseCellStack
  "Battery with open-circuit voltage dependent on state of charge, self-discharge and inner resistance"
  extends Modelica.Electrical.Batteries.Icons.BatteryIcon(final displaySOC=SOC);
  parameter Integer Ns(final min=1)=1 "Number of serial connected cells";
  parameter Integer Np(final min=1)=1 "Number of parallel connected cells";
  replaceable parameter ParameterRecords.CellData cellData "Cell parameters"
  parameter Real SOCtolerance=1e-9 "Tolerance to detect depleted of overcharged battery"
  extends Modelica.Electrical.Analog.Interfaces.TwoPin;
  SI.Current i = p.i "Current into the battery";
  SI.Power power = v*i "Power to the battery";
  output Real SOC(start=cellData.SOCmax) = limIntegrator.y "State of charge"
  Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor
  Blocks.Continuous.LimIntegrator limIntegrator(
    final k=1/(Np*cellData.Qnom),
    outMax=1 - SOCtolerance,
    outMin=SOCtolerance,
      final initType=Modelica.Blocks.Types.Init.NoInit)
  Modelica.Blocks.Tables.CombiTable1Ds ocv_soc(
    final table=cellData.OCV_SOC_internal,
    final smoothness=cellData.smoothness,
    extrapolation=Modelica.Blocks.Types.Extrapolation.HoldLastPoint)
  Modelica.Blocks.Math.Gain gainV(final k=Ns*cellData.OCVmax)
  Modelica.Electrical.Analog.Sources.SignalVoltage ocv
  Modelica.Electrical.Analog.Basic.Conductor selfDischarge(
    final G=Np*cellData.Idis/(Ns*cellData.OCVmax),
    T_ref=293.15,
    final useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Resistor r0(
    final T_ref=cellData.T_ref,
    final alpha=cellData.alpha,
    final useHeatPort=true)
  extends Modelica.Electrical.Analog.Interfaces.PartialConditionalHeatPort;
equation
  assert(cellData.OCVmax > cellData.OCVmin, "Specify 0 <= OCVmin < OCVmax");
  assert(cellData.SOCmax > cellData.SOCmin, "Specify 0 <= SOCmin < SOCmax <= 1");
  assert(cellData.OCV_SOC[1, 1] >= 0, "Specify OCV(SOC) table with minimum SOC >= 0");
  assert(cellData.OCV_SOC[end, 1] <= 1,  "Specify OCV(SOC) table with maximum SOC <= 1");
  assert(cellData.OCV_SOC[1, 2] >= 0, "Specify OCV(SOC) table with minimum OCV/OCVmax >= 0");
  assert(cellData.OCV_SOC[end, 2] <= 1, "Specify OCV(SOC) table with maximum OCV/OCVmax <= 1");
  assert(SOC < cellData.SOCmax + SOCtolerance, "Battery overcharged!");
  assert(SOC > cellData.SOCmin - SOCtolerance, "Battery exhausted!");
  connect(gainV.y, ocv.v)
  connect(ocv_soc.y[1], gainV.u)
  connect(limIntegrator.y, ocv_soc.u)
  connect(currentSensor.n, ocv.p)
  connect(limIntegrator.u, currentSensor.i)
  connect(p, currentSensor.p)
  connect(ocv.n, r0.p)
  connect(currentSensor.p, selfDischarge.p)
  connect(ocv.n, selfDischarge.n)
  connect(selfDischarge.heatPort, internalHeatPort)
  connect(internalHeatPort, r0.heatPort)
end BaseCellStack;


Partial cell with sensors. This is a single cell[Np=1, Ns=1] with measurement.

within Modelica.Electrical.Batteries.BaseClasses;
partial model BaseCellWithSensors "Partial cell with sensors"
  extends Modelica.Electrical.Batteries.Icons.BatteryIcon(final displaySOC=SOC);
  replaceable parameter Modelica.Electrical.Batteries.ParameterRecords.CellData cellData
    "Cell parameters"
  parameter Real SOC0=0.1 "Initial SOC";
  parameter Real SOCtolerance=1e-9 "SOC tolerance for detection of depleted or overcharged cell"
  extends Modelica.Electrical.Analog.Interfaces.TwoPin;
  output SI.Current i = p.i "Current into the cell";
  output SI.Power power = v*i "Power to the cell";
  output Real SOC = limIntegrator.y "State of charge";
  extends Modelica.Electrical.Analog.Interfaces.PartialConditionalHeatPort;
  replaceable Modelica.Electrical.Batteries.BatteryStacks.CellStack cell(
    final Ns=1,
    final Np=1,
    SOCtolerance=SOCtolerance,
    cellData=cellData,
    SOC(start=SOC0, fixed=true),
    useHeatPort=true,
    T=T) "Cell"
  Modelica.Electrical.Analog.Sensors.MultiSensor multiSensor
  Modelica.Blocks.Continuous.LimIntegrator limIntegrator(
    k=1/cellData.Qnom,
    outMax=1 - SOCtolerance,
    outMin=SOCtolerance,
    initType=Modelica.Blocks.Types.Init.InitialOutput,
    y_start=SOC0)
  Modelica.Thermal.HeatTransfer.Sensors.TemperatureSensor temperatureSensor
  Modelica.Thermal.HeatTransfer.Sensors.HeatFlowSensor heatFlowSensor
  Modelica.Electrical.Batteries.Interfaces.CellBus cellBus "Cell bus"
equation
  connect(p, multiSensor.pc)
  connect(multiSensor.pc, multiSensor.pv)
  connect(multiSensor.nc, cell.p)
  connect(cell.n, n)
  connect(multiSensor.i, limIntegrator.u)
  connect(limIntegrator.y, cellBus.soc)
  connect(multiSensor.v, cellBus.v)
  connect(multiSensor.i, cellBus.i)
  connect(multiSensor.power, cellBus.power)
  connect(heatFlowSensor.port_b, internalHeatPort)
  connect(heatFlowSensor.port_a, cell.heatPort)
  connect(heatFlowSensor.Q_flow, cellBus.lossPower)
  connect(temperatureSensor.T, cellBus.T)
  connect(n, multiSensor.nv)
  connect(heatFlowSensor.port_a, temperatureSensor.port)
end BaseCellWithSensors;


Partial stack with sensors. This is a stack of Ns x Np cell[Np=1, Ns=1] with measurement, arranged in a matrix.

within Modelica.Electrical.Batteries.BaseClasses;
partial model BaseStackWithSensors "Partial stack with sensors"
  extends Modelica.Electrical.Batteries.Icons.BatteryIcon(final displaySOC=SOC);
  replaceable parameter BaseStackData stackData
  parameter Boolean useAllParallelConnections=true "= true, if all parallel connections are used";
  parameter Real SOC0[stackData.Ns, stackData.Np]=fill(0.1, stackData.Ns, stackData.Np) "Initial SOC";
  parameter Real SOCtolerance=1e-9 "SOC tolerance for detection of depleted or overcharged cell"
  extends Modelica.Electrical.Analog.Interfaces.TwoPin;
  output SI.Current i = p.i "Current into the stack";
  output SI.Power power = v*i "Power to the stack";
  output Real SOC = socTotal.y "Overall State of charge";
  parameter Boolean useHeatPort = false "=true, if HeatPort is enabled"
  parameter SI.Temperature T=293.15
    "Fixed device temperature if useHeatPort = false"
  replaceable Modelica.Electrical.Batteries.BaseClasses.BaseCellWithSensors
    cell[stackData.Ns,stackData.Np](
    each SOCtolerance=SOCtolerance,
    each useHeatPort=false,
    each T=T,
    cellData=stackData.cellData,
    SOC0=SOC0) "Matrix of cells"
  Modelica.Electrical.Analog.Sensors.MultiSensor multiSensor
  Modelica.Electrical.Batteries.Interfaces.StackBus stackBus(Ns=stackData.Ns,
      Np=stackData.Np) "Stack bus"
  Modelica.Electrical.Batteries.Interfaces.CellBus batteryBus
    "Battery bus (average / sum over all cells)"
  Modelica.Blocks.Sources.RealExpression socTotal(
    y=sum(stackBus.cellBus.soc.*stackData.cellData.Qnom)/sum(stackData.cellData.Qnom))
  Modelica.Blocks.Sources.RealExpression lossesTotal(y=sum(stackBus.cellBus.lossPower))
  Modelica.Blocks.Sources.RealExpression temperatureTotal(y=sum(stackBus.cellBus.T)/(stackData.Ns*stackData.Np))
  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort[stackData.Ns, stackData.Np] if useHeatPort
    "Optional port to which dissipated losses are transported in form of heat"
equation
  //connections of cell stack
  connect(multiSensor.nc, cell[1, 1].p)
  connect(cell[stackData.Ns, 1].n, n)
  connect(cell.cellBus, stackBus.cellBus)
  if useAllParallelConnections then
    for ks in 1:stackData.Ns loop
      for kp in 1:stackData.Np-1 loop
        connect(cell[ks, kp].p, cell[ks, kp + 1].p);
        connect(cell[ks, kp].n, cell[ks, kp + 1].n);
      end for;
    end for;
    for ks in 1:stackData.Ns-1 loop
      connect(cell[ks, 1].n, cell[ks + 1, 1].p);
    end for;
  else
    for kp in 1:stackData.Np loop
      for ks in 1:stackData.Ns-1 loop
        connect(cell[ks, kp].n, cell[ks + 1, kp].p);
      end for;
    end for;
    for kp in 1:stackData.Np-1 loop
      connect(cell[1, kp].p, cell[1, kp + 1].p);
      connect(cell[stackData.Ns, kp].n, cell[stackData.Ns, kp + 1].n);
    end for;
  end if;
//other connections
  connect(p,multiSensor.pc)
  connect(multiSensor.pc,multiSensor.pv)
  connect(n, multiSensor.nv)
  connect(multiSensor.i, batteryBus.i)
  connect(multiSensor.power, batteryBus.power)
  connect(multiSensor.v, batteryBus.v)
  connect(socTotal.y, batteryBus.soc)
  connect(temperatureTotal.y, batteryBus.T)
  connect(lossesTotal.y, batteryBus.lossPower)
  connect(cell.heatPort, heatPort)
end BaseStackWithSensors;


Base classes for battery models

within Modelica.Electrical.Batteries;
package BaseClasses "Base classes for battery models"
  extends Modelica.Icons.BasesPackage;
end BaseClasses;


Battery with open-circuit voltage dependent on state of charge, self-discharge, inner resistance and a series of RC-elements. Extends the model CellStack by a series of RC-elements, describing the transient behaviour of the battery.

within Modelica.Electrical.Batteries.BatteryStacks;
model CellRCStack
  "Battery with open-circuit voltage dependent on state of charge, self-discharge, inner resistance and a series of RC-elements"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseCellStack(r0(final R=Ns*cellData.R0/Np),
    redeclare Modelica.Electrical.Batteries.ParameterRecords.TransientData.CellData cellData);
  extends Modelica.Electrical.Batteries.Icons.TransientModel;
  Modelica.Electrical.Analog.Basic.Resistor resistor[cellData.nRC](
    final R=Ns*cellData.rcData.R/Np,
    final T_ref=cellData.rcData.T_ref,
    final alpha=cellData.rcData.alpha,
    each final useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor[cellData.nRC](each v(
        fixed=true, each start=0), final C=Np*cellData.rcData.C/Ns)
equation
  assert(cellData.R0 > 0, "Ri has to be greater than sum(rcParameters.R)");
  assert(cellData.rcData[1].R > 0, "Parameters of RC-elements undefined!");
  //connect the RC-elements
  connect(resistor[1].p, r0.n)
  for k in 1:cellData.nRC loop
    connect(capacitor[k].p, resistor[k].p)
    connect(capacitor[k].n, resistor[k].n)
    connect(internalHeatPort, resistor[k].heatPort)
    if k < cellData.nRC then
      connect(resistor[k].n, resistor[k + 1].p);
    end if;
  end for;
  connect(resistor[cellData.nRC].n, n)
end CellRCStack;


Battery with open-circuit voltage dependent on state of charge, self-discharge and inner resistance. The battery is modeled by open-circuit voltage (OCV) dependent on state of charge (SOC), self-discharge and inner resistance,
as implemented in partial BaseCellStack.

within Modelica.Electrical.Batteries.BatteryStacks;
model CellStack
  "Battery with open-circuit voltage dependent on state of charge, self-discharge and inner resistance"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseCellStack(r0(final R=Ns*cellData.Ri/Np),
    redeclare Modelica.Electrical.Batteries.ParameterRecords.CellData cellData);
equation
  connect(r0.n, n)
end CellStack;


Battery stacks built from cells

within Modelica.Electrical.Batteries;
package BatteryStacks "Battery stacks built from cells"
  extends Modelica.Icons.Package;
end BatteryStacks;


Simple model of a supercapacitor. This is a simple model of a supercapacitor, comprising:

within Modelica.Electrical.Batteries.BatteryStacks;
model SuperCap "Simple model of a supercapacitor"
  extends Modelica.Electrical.Analog.Interfaces.TwoPin;
  SI.Current i = p.i "Current into the supercap";
  parameter SI.Voltage Vnom "Nominal voltage";
  parameter SI.Voltage V0=Vnom "Initial voltage";
  parameter SI.Capacitance C "Capacitance";
  parameter SI.ElectricCharge Qnom=C*Vnom "Nominal charge";
  parameter SI.Resistance Rs "Series resistance";
  parameter SI.Temperature T_ref=293.15 "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0 "Temperature coefficient of resistance at T_ref";
  parameter SI.Current Idis=0 "Self-discharge current at nominal voltage"
  extends Modelica.Electrical.Analog.Interfaces.PartialConditionalHeatPort;
  Modelica.Electrical.Analog.Basic.Resistor resistor(
    final R=Rs,
    final T_ref=T_ref,
    final alpha=alpha,
    final useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Conductor conductor(
    final G=Idis/Vnom,
    T_ref=293.15,
    final useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Capacitor capacitor(v(start=V0, fixed=true), final C=C)
equation
  connect(p, resistor.p)
  connect(resistor.n, capacitor.p)
  connect(capacitor.n, n)
  connect(capacitor.p, conductor.p)
  connect(capacitor.n, conductor.n)
  connect(internalHeatPort, conductor.heatPort)
  connect(internalHeatPort, resistor.heatPort)
end SuperCap;


Cell with measurement. This is a single cell[Np=1, Ns=1] with measurement.

within Modelica.Electrical.Batteries.BatteryStacksWithSensors;
model Cell "Cell with measurement"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseCellWithSensors(
    redeclare Modelica.Electrical.Batteries.ParameterRecords.CellData cellData,
    redeclare Modelica.Electrical.Batteries.BatteryStacks.CellStack cell(
      cellData=cellData,
      SOC(start=SOC0, fixed=true),
      SOCtolerance=SOCtolerance,
      useHeatPort=true,
      T=T));
end Cell;


Cell with measurement. This is a single transient cellRC[Np=1, Ns=1] (with RC-elements) with measurement.

within Modelica.Electrical.Batteries.BatteryStacksWithSensors;
model CellRC "Cell with measurement"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseCellWithSensors(
    redeclare Modelica.Electrical.Batteries.ParameterRecords.TransientData.CellData cellData,
    redeclare Modelica.Electrical.Batteries.BatteryStacks.CellRCStack cell(
      cellData=cellData,
      SOC(start=SOC0, fixed=true),
      SOCtolerance=SOCtolerance,
      useHeatPort=true,
      T=T));
  extends Modelica.Electrical.Batteries.Icons.TransientModel;
end CellRC;


Battery cells and stacks with sensors

within Modelica.Electrical.Batteries;
package BatteryStacksWithSensors "Battery cells and stacks with sensors"
  extends Modelica.Icons.Package;
end BatteryStacksWithSensors;


Stack with sensors. This is a stack of Ns x Np cell[Np=1, Ns=1] with measurement, arranged in a matrix.

within Modelica.Electrical.Batteries.BatteryStacksWithSensors;
model Stack "Stack with sensors"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseStackWithSensors(
    redeclare Modelica.Electrical.Batteries.BaseClasses.BaseStackData stackData,
    redeclare Modelica.Electrical.Batteries.BatteryStacksWithSensors.Cell cell(
      cellData=stackData.cellData,
      SOC0=SOC0,
      each SOCtolerance=SOCtolerance,
      each useHeatPort=useHeatPort,
      each T=T));
end Stack;


Stack with sensors. This is a stack of Ns x Np transient cellRC[Np=1, Ns=1] (with RC-elements) with measurement, arranged in a matrix.

within Modelica.Electrical.Batteries.BatteryStacksWithSensors;
model StackRC "Stack with sensors"
  extends Modelica.Electrical.Batteries.BaseClasses.BaseStackWithSensors(
      redeclare Modelica.Electrical.Batteries.ParameterRecords.TransientData.StackData stackData,
      redeclare Modelica.Electrical.Batteries.BatteryStacksWithSensors.CellRC cell(
        cellData=stackData.cellData,
        SOC0=SOC0,
        each SOCtolerance=SOCtolerance,
        each useHeatPort=useHeatPort,
        each T=T));
  extends Modelica.Electrical.Batteries.Icons.TransientModel;
end StackRC;


Discharge and charge idealized battery. Two batteries with a nominal charge of 10 A.h starting with an initial SOC = 95 % are compared:

within Modelica.Electrical.Batteries.Examples;
model BatteryDischargeCharge "Discharge and charge idealized battery"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Batteries.Utilities.PulseSeries pulseSeries(
    n1=7,
    T1=60,
    Tp1=60,
    n2=7,
    Tp=60,
    startTime=60)
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.CellData cellData1(
    Qnom=18000,
    OCVmax=4.2,
    OCVmin=2.5,
    Ri=cellData1.OCVmax/Isc)
  Modelica.Electrical.Batteries.BatteryStacks.CellStack battery1(
    Ns=10,
    Np=2,
    cellData=cellData1,
    useHeatPort=false,
    SOC(fixed=true, start=0.95))
  Modelica.Electrical.Analog.Basic.Ground ground1
  Modelica.Electrical.Analog.Sources.SignalCurrent signalCurrent1
  Modelica.Electrical.Analog.Sensors.PowerSensor powerSensor1
  Modelica.Blocks.Continuous.Integrator energy1(u(unit="W"), y(unit="J"))
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData2(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellData2.OCVmax/Isc,
    Idis=0.1,
    nRC=2,
    rcData={Modelica.Electrical.Batteries.ParameterRecords.TransientData.RCData(
        R=0.2*cellData2.Ri, C=60/(0.2*cellData2.Ri)),
        Modelica.Electrical.Batteries.ParameterRecords.TransientData.RCData(R=
        0.1*cellData2.Ri, C=10/(0.1*cellData2.Ri))})
  Modelica.Electrical.Batteries.BatteryStacks.CellRCStack battery2(
    Ns=10,
    Np=2,
    cellData=cellData2,
    useHeatPort=false,
    SOC(fixed=true, start=0.95))
  Modelica.Electrical.Analog.Basic.Ground ground2
  Modelica.Electrical.Analog.Sources.SignalCurrent signalCurrent2
  Modelica.Electrical.Analog.Sensors.PowerSensor powerSensor2
  Modelica.Blocks.Continuous.Integrator energy2(u(unit="W"), y(unit="J"))
  Modelica.Blocks.Math.Gain gain(k=75)
equation
  connect(battery1.n, ground1.p)
  connect(signalCurrent1.n, ground1.p)
  connect(signalCurrent1.p, powerSensor1.pc)
  connect(powerSensor1.nc, battery1.p)
  connect(powerSensor1.nv, ground1.p)
  connect(powerSensor1.pc, powerSensor1.pv)
  connect(powerSensor1.power, energy1.u)
  connect(battery2.n,ground2. p)
  connect(signalCurrent2.n,ground2. p)
  connect(signalCurrent2.p,powerSensor2. pc)
  connect(powerSensor2.nc,battery2. p)
  connect(powerSensor2.nv,ground2. p)
  connect(powerSensor2.pc,powerSensor2. pv)
  connect(powerSensor2.power,energy2. u)
  connect(gain.y, signalCurrent1.i)
  connect(gain.y,signalCurrent2. i)
  connect(pulseSeries.y, gain.u)
end BatteryDischargeCharge;


Charge a battery with constant current - constant voltage characteristic. A battery depleted to SOC = 0.1 is recharged with a CC-CV charger.
Charging current in CC mode is 5C which means the battery is theoretically nearly fulled charged after 0.9*3600 s/5 = 648 s and the charger switches to CV mode.

within Modelica.Electrical.Batteries.Examples;
model CCCVcharging
  "Charge a battery with constant current - constant voltage characteristic"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellData.OCVmax/Isc,
    Idis=0.001)
  Modelica.Electrical.Batteries.BatteryStacks.CellRCStack battery(
    Ns=10,
    Np=2,
    cellData=cellData,
    useHeatPort=false,
    SOC(fixed=true, start=0.1))
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sensors.PowerSensor powerSensor
  Modelica.Blocks.Continuous.Integrator energy(u(unit="W"), y(unit="J"))
  Utilities.CCCVcharger cccvCharger(I=50, Vend=42)
equation
  connect(battery.n, ground.p)
  connect(powerSensor.nc, battery.p)
  connect(powerSensor.nv, ground.p)
  connect(powerSensor.pc, powerSensor.pv)
  connect(powerSensor.power, energy.u)
  connect(powerSensor.pc, cccvCharger.p)
  connect(ground.p, cccvCharger.n)
end CCCVcharging;


Charge a cell with constant current - constant voltage characteristic. A single cell depleted to SOC = 0.1 is recharged with a CC-CV charger.
Charging current in CC mode is 5C which means the battery is theoretically nearly fulled charged after 0.9*3600 s/5 = 648 s and the charger switches to CV mode.
Simulate for 1200 s and plot cell.cellBus.soc versus time.

within Modelica.Electrical.Batteries.Examples;
model CCCV_Cell
  "Charge a cell with constant current - constant voltage characteristic"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellData(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellData.OCVmax/Isc,
    Idis=0.001) "Cell data"
  Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=25, Vend=4.2)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Batteries.BatteryStacksWithSensors.Cell cell(cellData=cellData)
  Analog.Sensors.MultiSensor                     multiSensor
  Blocks.Continuous.Integrator          energy(u(unit="W"), y(unit="J"))
equation
  connect(cell.n, ground.p)
  connect(ground.p, cccvCharger.n)
  connect(cccvCharger.p, multiSensor.pc)
  connect(multiSensor.pc, multiSensor.pv)
  connect(multiSensor.nc, cell.p)
  connect(ground.p, multiSensor.nv)
  connect(multiSensor.power, energy.u)
end CCCV_Cell;


Charge a transient cell with constant current - constant voltage characteristic. A single transient cell depleted to SOC = 0.1 is recharged with a CC-CV charger.
Charging current in CC mode is 5C which means the battery is theoretically nearly fulled charged after 0.9*3600 s/5 = 648 s and the charger switches to CV mode.
Simulate for 1200 s and plot cell.cellBus.soc versus time.

within Modelica.Electrical.Batteries.Examples;
model CCCV_CellRC
  "Charge a transient cell with constant current - constant voltage characteristic"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellData(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellData.OCVmax/Isc,
    Idis=0.001) "Cell data"
  Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=25, Vend=4.2)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Batteries.BatteryStacksWithSensors.CellRC cell(cellData=cellData)
  Analog.Sensors.MultiSensor                     multiSensor
  Blocks.Continuous.Integrator          energy(u(unit="W"), y(unit="J"))
equation
  connect(cell.n, ground.p)
  connect(ground.p, cccvCharger.n)
  connect(multiSensor.nc, cell.p)
  connect(multiSensor.power, energy.u)
  connect(ground.p, multiSensor.nv)
  connect(multiSensor.pc, multiSensor.pv)
  connect(multiSensor.pc, cccvCharger.p)
end CCCV_CellRC;


Charge a stack with constant current - constant voltage characteristic. A stack of cells with one degraded cell (with indices [1,1], with double inner resistance), all cells depleted to SOC = 0.1, is recharged with a CC-CV charger.
Simulate for 1200 s and plot versus time:

within Modelica.Electrical.Batteries.Examples;
model CCCV_Stack
  "Charge a stack with constant current - constant voltage characteristic"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellDataOriginal(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellDataOriginal.OCVmax/Isc,
    Idis=0.001) "Original cell data"
  parameter Modelica.Electrical.Batteries.ParameterRecords.ExampleData cellDataDegraded(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=2*cellDataDegraded.OCVmax/Isc,
    Idis=0.001) "Degraded cell data"
  parameter Modelica.Electrical.Batteries.ParameterRecords.StackData
    stackData(
    Ns=3,
    Np=2,
    kDegraded=[1,1],
    cellDataOriginal=cellDataOriginal,
    cellDataDegraded=cellDataDegraded) "Stack data"
  Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=stackData.Np*25, Vend=stackData.Ns*4.2)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Batteries.BatteryStacksWithSensors.Stack stack(
    stackData=stackData,
    useHeatPort=true,
    SOC0=fill(
          0.1,
          stackData.Ns,
          stackData.Np))
  Modelica.Electrical.Batteries.Utilities.BusTranscription busTranscription(
      Np=stackData.Np, Ns=stackData.Ns)
  Modelica.Thermal.HeatTransfer.Components.ThermalCollectorMatrix thermalCollectorMatrix(
    Ns=stackData.Ns, Np=stackData.Np)
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature(T=293.15)
  Modelica.Electrical.Analog.Sensors.MultiSensor multiSensor
  Modelica.Blocks.Continuous.Integrator energy(u(unit="W"), y(unit="J"))
equation
  connect(ground.p, cccvCharger.n)
  connect(ground.p, stack.n)
  connect(stack.stackBus, busTranscription.stackBus)
  connect(stack.heatPort, thermalCollectorMatrix.port_a)
  connect(thermalCollectorMatrix.port_b, fixedTemperature.port)
  connect(cccvCharger.p, multiSensor.pc)
  connect(multiSensor.pc, multiSensor.pv)
  connect(ground.p, multiSensor.nv)
  connect(multiSensor.nc, stack.p)
  connect(multiSensor.power, energy.u)
end CCCV_Stack;


Charge a transient stack with constant current - constant voltage characteristic. A stack of transient cells with one degraded cell (with indices [1,1], with double inner resistance), all cells depleted to SOC = 0.1, is recharged with a CC-CV charger.
Simulate for 1200 s and plot versus time:

within Modelica.Electrical.Batteries.Examples;
model CCCV_StackRC
  "Charge a transient stack with constant current - constant voltage characteristic"
  extends Modelica.Icons.Example;
  parameter Modelica.Units.SI.Current Isc = 1200 "Short-circuit current of cell at OCVmax";
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellDataOriginal(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=cellDataOriginal.OCVmax/Isc,
    Idis=0.001) "Original cell data"
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.ExampleData cellDataDegraded(
    Qnom=18000,
    useLinearSOCDependency=false,
    Ri=2*cellDataDegraded.OCVmax/Isc,
    Idis=0.001) "Degraded cell data"
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.StackData
    stackData(
    Ns=3,
    Np=2,
    kDegraded=[1,1],
    cellDataOriginal=cellDataOriginal,
    cellDataDegraded=cellDataDegraded) "Stack data"
  Modelica.Electrical.Batteries.Utilities.CCCVcharger cccvCharger(I=stackData.Np*25, Vend=stackData.Ns*4.2)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Batteries.BatteryStacksWithSensors.StackRC stack(
    stackData=stackData,
    useHeatPort=false,
    SOC0=fill(
          0.1,
          stackData.Ns,
          stackData.Np))
  Modelica.Electrical.Batteries.Utilities.BusTranscription busTranscription(
      Np=stackData.Np, Ns=stackData.Ns)
  Blocks.Continuous.Integrator          energy(u(unit="W"), y(unit="J"))
  Analog.Sensors.MultiSensor                     multiSensor
equation
  connect(ground.p, cccvCharger.n)
  connect(ground.p, stack.n)
  connect(stack.stackBus, busTranscription.stackBus)
  connect(ground.p, multiSensor.nv)
  connect(cccvCharger.p, multiSensor.pc)
  connect(multiSensor.power, energy.u)
  connect(multiSensor.pc, multiSensor.pv)
  connect(multiSensor.nc, stack.p)
end CCCV_StackRC;


Collection of battery examples

within Modelica.Electrical.Batteries;
package Examples "Collection of battery examples"
  extends Modelica.Icons.ExamplesPackage;
end Examples;


Show complex cell impedance. Plot impedance.z.im versus impedance.z.re

within Modelica.Electrical.Batteries.Examples;
model ShowImpedance "Show complex cell impedance"
  extends Modelica.Icons.Example;
  Blocks.Sources.LogFrequencySweep logSweep(
    wMin=1e-6,
    wMax=1e3,
    duration=1)
  Utilities.Impedance impedance(cellData=cellData)
  parameter ParameterRecords.TransientData.ExampleData cellData(Qnom=3600, Ri=
        0.01)
equation
  connect(logSweep.y, impedance.f)
end ShowImpedance;


Discharge and charge idealized supercap. A supercap with a capacitance of 500 F, starting initially at nominal voltage 48 V,
is discharged with 5 current pulses of 240 A for 10 seconds, and breaks between the pulses of 10 seconds.
Subsequently, the supercap is charged again with 5 current pulses of 240 A for 10 seconds, and breaks between the pulses of 10 seconds.
In the end, the supercap is in no-load condition to reveal self-discharge effects.

within Modelica.Electrical.Batteries.Examples;
model SuperCapDischargeCharge "Discharge and charge idealized supercap"
  extends Modelica.Icons.Example;
  Modelica.Electrical.Batteries.Utilities.PulseSeries pulseSeries(
    n1=5,
    T1=10,
    Tp1=10,
    n2=5,
    Tp=10,
    startTime=10)
  Modelica.Electrical.Batteries.BatteryStacks.SuperCap superCap(
    Vnom=48,
    C=500,
    Rs=0.002,
    Idis=0.05,
    useHeatPort=false)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Sources.SignalCurrent signalCurrent
  Modelica.Electrical.Analog.Sensors.PowerSensor powerSensor
  Modelica.Blocks.Continuous.Integrator energy(u(unit="W"), y(unit="J"))
  Modelica.Blocks.Math.Gain gain(k=300)
equation
  connect(superCap.n, ground.p)
  connect(signalCurrent.n, ground.p)
  connect(signalCurrent.p, powerSensor.pc)
  connect(powerSensor.nc, superCap.p)
  connect(powerSensor.nv, ground.p)
  connect(powerSensor.pc, powerSensor.pv)
  connect(powerSensor.power, energy.u)
  connect(gain.y, signalCurrent.i)
  connect(pulseSeries.y, gain.u)
end SuperCapDischargeCharge;


Icon for cells and stacks.

within Modelica.Electrical.Batteries.Icons;
model BatteryIcon "Icon for cells and stacks"
  input Real displaySOC "SOC for display"
end BatteryIcon;


Icons for battery models

within Modelica.Electrical.Batteries;
package Icons "Icons for battery models"
extends Modelica.Icons.IconsPackage;
end Icons;


within Modelica.Electrical.Batteries.Icons;
partial package TransientRecordsPackage
  "Icon for package containing records with transient data"
end TransientRecordsPackage;


Interfaces of battery models

within Modelica.Electrical.Batteries;
package Interfaces "Interfaces of battery models"
extends Modelica.Icons.InterfacesPackage;
end Interfaces;


Parameter records for batteries

within Modelica.Electrical.Batteries;
package ParameterRecords "Parameter records for batteries"
  extends Modelica.Icons.RecordsPackage;</code> in each individual parameter record.
</p>
</html>"));
end ParameterRecords;


within Modelica.Electrical.Batteries.ParameterRecords;
package TransientData "Parameter records for transient battery models"
  extends Modelica.Electrical.Batteries.Icons.TransientRecordsPackage; in each individual parameter record.

Record RCData is used in record CellData.

"));
end TransientData;


Transcribe bus signals. Transfers the information from the stackBus to the stackBusArrays.

within Modelica.Electrical.Batteries.Utilities;
block BusTranscription "Transcribe bus signals"
  extends Modelica.Blocks.Icons.Block;
  parameter Integer Ns(final min = 1) = 1 "Number of series connected cells";
  parameter Integer Np(final min = 1) = 1 "Number of parallel connected cells";
  Modelica.Electrical.Batteries.Interfaces.StackBus stackBus(Np=Np, Ns=Ns)
    "Stack bus"
  Modelica.Electrical.Batteries.Interfaces.StackBusArrays stackBusArrays(Np=Np,
      Ns=Ns) "Stack bus with signal arrays"
protected
  Modelica.Blocks.Math.Gain gainV[Ns,Np](each k=1)
  Modelica.Blocks.Math.Gain gainI[Ns,Np](each k=1)
  Modelica.Blocks.Math.Gain gainSOC[Ns,Np](each k=1)
  Modelica.Blocks.Math.Gain gainP[Ns,Np](each k=1)
  Modelica.Blocks.Math.Gain gainLosses[Ns,Np](each k=1)
  Modelica.Blocks.Math.Gain gainT[Ns,Np](each k=1)
equation
  connect(gainV.y, stackBusArrays.v)
  connect(gainI.y, stackBusArrays.i)
  connect(gainSOC.y, stackBusArrays.soc)
  connect(gainP.y, stackBusArrays.power)
  connect(gainLosses.y, stackBusArrays.lossPower)
  connect(gainT.y, stackBusArrays.T)
  connect(gainV.u, stackBus.cellBus.v)
  connect(gainI.u, stackBus.cellBus.i)
  connect(gainSOC.u, stackBus.cellBus.soc)
  connect(gainP.u, stackBus.cellBus.power)
  connect(gainLosses.u, stackBus.cellBus.lossPower)
  connect(gainT.u, stackBus.cellBus.T)
end BusTranscription;


Charger with constant current - constant voltage characteristic. Ideal charger switching from constant current to constant voltage characteristic.

within Modelica.Electrical.Batteries.Utilities;
model CCCVcharger
  "Charger with constant current - constant voltage characteristic"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Current I "Constant charge current";
  parameter SI.Time startTime=0 "Start time of charging";
  parameter SI.Time rampTime=60 "Ramp up charging current";
  parameter SI.Voltage Vend "End of charge voltage";
  Boolean CV(start=false, fixed=true) "Indicates CV charging";
equation
  CV=v>=Vend;
  if CV then
    v=Vend;
  else
    i = -I*(if time<startTime then 0 else min(1,(time - startTime)/rampTime));
  end if;
end CCCVcharger;


Calculate complex impedance. Calculates the complex cell impedance from given cell data and frequency.

within Modelica.Electrical.Batteries.Utilities;
block Impedance "Calculate complex impedance"
  extends Blocks.Icons.Block;
  import Modelica.Constants.pi;
  import Modelica.ComplexMath.sum;
  parameter Modelica.Electrical.Batteries.ParameterRecords.TransientData.CellData cellData "Transient cell data";
  Blocks.Interfaces.RealInput f(unit="Hz") "Frequency"
  ComplexBlocks.Interfaces.ComplexOutput z(re(unit="Ohm"), im(unit="Ohm")) "Complex impedance"
equation
  z = Complex(cellData.R0, 0) + sum({1/Complex(1/cellData.rcData[k].R, 2*pi*f*cellData.rcData[k].C) for k in 1:cellData.nRC});
end Impedance;


Utilities for battery applications

within Modelica.Electrical.Batteries;
package Utilities "Utilities for battery applications"
  extends Modelica.Icons.UtilitiesPackage;
end Utilities;


Series of pulses.

within Modelica.Electrical.Batteries.Utilities;
block PulseSeries "Series of pulses"
  import Modelica.Math.BooleanVectors.oneTrue;
  parameter Real amplitude1= 1 "Amplitude of 1st pulse series";
  parameter Integer n1(min=0)=1 "Number of pulses of 1st series";
  parameter SI.Time T1 "Length of pulses of 1st series";
  parameter SI.Time Tp1 "Pause between pulses of 1st series";
  parameter Real amplitude2=-amplitude1 "Amplitude of 2nd pulse series";
  parameter Integer n2(min=0)=1 "Number of pulses of 2nd series";
  parameter SI.Time T2=T1 "Length of pulses of 2nd series";
  parameter SI.Time Tp2=Tp1 "Pause between pulses of 2nd series";
  parameter SI.Time Tp "Pause (in addition to TP1) between the two series"
  extends Modelica.Blocks.Interfaces.SignalSource;
protected
  parameter SI.Time Tstart1[n1]={startTime + (k-1)*(T1 + Tp1) for k in 1:n1};
  parameter SI.Time Tstart2[n2]={startTime + n1*(T1 + Tp1) + Tp + (k-1)*(T2 + Tp2) for k in 1:n2};
  Boolean on1, on2;
equation
  on1 = oneTrue({time >= Tstart1[k] and time < Tstart1[k] + T1 for k in 1:n1});
  on2 = oneTrue({time >= Tstart2[k] and time < Tstart2[k] + T2 for k in 1:n2});
  y= offset + (if on1 then amplitude1 elseif on2 then amplitude2 else 0);
end PulseSeries;


Library for electric machines

within Modelica.Electrical;
package Machines "Library for electric machines"
  extends Modelica.Icons.Package;
end Machines;


Basic machine models

within Modelica.Electrical.Machines;
package BasicMachines "Basic machine models"
  extends Modelica.Icons.Package;
end BasicMachines;


Linear airgap model of a DC machine.

within Modelica.Electrical.Machines.BasicMachines.Components;
model AirGapDC "Linear airgap model of a DC machine"
  extends PartialAirGapDC;
  parameter SI.Inductance Le "Excitation inductance";
equation
  // excitation flux: linearly dependent on excitation current
  psi_e = Le*ie;
end AirGapDC;


Airgap in rotor-fixed coordinate system.

within Modelica.Electrical.Machines.BasicMachines.Components;
model AirGapR "Airgap in rotor-fixed coordinate system"
  parameter SI.Inductance Lmd
    "Main field inductance d-axis";
  parameter SI.Inductance Lmq
    "Main field inductance q-axis";
  extends PartialAirGap;
  SI.Current i_mr[2]
    "Magnetizing current space phasor with respect to the rotor fixed frame";
protected
  parameter SI.Inductance L[2, 2]={{Lmd,0},{0,Lmq}}
    "Inductance matrix";
equation
  // Magnetizing current with respect to the rotor reference frame
  i_mr = i_sr + i_rr;
  // Main flux linkage with respect to the rotor reference frame
  psi_mr = L*i_mr;
  // Main flux linkage with respect to the stator reference frame
  psi_ms = RotationMatrix*psi_mr;
end AirGapR;


Airgap in stator-fixed coordinate system.

within Modelica.Electrical.Machines.BasicMachines.Components;
model AirGapS "Airgap in stator-fixed coordinate system"
  parameter SI.Inductance Lm "Main field inductance";
  extends PartialAirGap;
  SI.Current i_ms[2]
    "Magnetizing current space phasor with respect to the stator fixed frame";
protected
  parameter SI.Inductance L[2, 2]={{Lm,0},{0,Lm}}
    "Inductance matrix";
equation
  // Magnetizing current with respect to the stator reference frame
  i_ms = i_ss + i_rs;
  // Magnetizing flux linkage with respect to the stator reference frame
  psi_ms = L*i_ms;
  // Magnetizing flux linkage with respect to the rotor reference frame
  psi_mr = transpose(RotationMatrix)*psi_ms;
end AirGapS;


Compound excitation = shunt + series.

within Modelica.Electrical.Machines.BasicMachines.Components;
model CompoundDCExcitation "Compound excitation = shunt + series"
  parameter Real excitationTurnsRatio
    "Ratio of series excitation turns over shunt excitation turns";
  SI.Voltage v=pin_p.v - pin_n.v;
  SI.Current i=pin_p.i;
  SI.Voltage ve=pin_ep.v - pin_en.v;
  SI.Current ie=pin_ep.i;
  SI.Voltage vse=pin_sep.v - pin_sen.v;
  SI.Current ise=pin_sep.i;
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_p
    "Positive pin to airgap"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_n
    "Negative pin to airgap"
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
    "Positive pin to shunt excitation"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
    "Negative pin to shunt excitation"
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_sep
    "Positive pin to series excitation"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_sen
    "Negative pin to series excitation"
equation
  //current balances
  pin_p.i + pin_n.i = 0;
  pin_ep.i + pin_en.i = 0;
  pin_sep.i + pin_sen.i = 0;
  //compound currents
  -i = ie + excitationTurnsRatio*ise;
  //induced voltages
  ve = v;
  vse = v*excitationTurnsRatio;
end CompoundDCExcitation;


Squirrel Cage. Model of an asymmetrical damper cage in two axis.

within Modelica.Electrical.Machines.BasicMachines.Components;
model DamperCage "Squirrel Cage"
  parameter SI.Inductance Lrsigmad
    "Stray inductance in d-axis per phase translated to stator";
  parameter SI.Inductance Lrsigmaq
    "Stray inductance in q-axis per phase translated to stator";
  parameter SI.Resistance Rrd
    "Resistance in d-axis per phase translated to stator at T_ref";
  parameter SI.Resistance Rrq
    "Resistance in q-axis per phase translated to stator at T_ref";
  parameter SI.Temperature T_ref=293.15
    "Reference temperature of both resistances in d- and q-axis";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of both resistances in d- and q-axis at T_ref";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance Rrd_actual
    "Actual resistance = Rrd*(1 + alpha*(T_heatPort - T_ref))";
  SI.Resistance Rrq_actual
    "Actual resistance = Rrq*(1 + alpha*(T_heatPort - T_ref))";
  Modelica.Blocks.Interfaces.RealOutput i[2](
    each final quantity="ElectricCurrent",
    each final unit="A") = -spacePhasor_r.i_ "Currents out from damper";
  Modelica.Blocks.Interfaces.RealOutput lossPower(
    final quantity="Power",
    final unit="W") = LossPower "Damper losses";
  Machines.Interfaces.SpacePhasor spacePhasor_r
equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  Rrd_actual = Rrd*(1 + alpha*(T_heatPort - T_ref));
  Rrq_actual = Rrq*(1 + alpha*(T_heatPort - T_ref));
  spacePhasor_r.v_[1] = Rrd_actual*spacePhasor_r.i_[1] + Lrsigmad*der(
    spacePhasor_r.i_[1]);
  spacePhasor_r.v_[2] = Rrq_actual*spacePhasor_r.i_[2] + Lrsigmaq*der(
    spacePhasor_r.i_[2]);
  2/3*LossPower = Rrd_actual*spacePhasor_r.i_[1]*spacePhasor_r.i_[1] +
    Rrq_actual*spacePhasor_r.i_[2]*spacePhasor_r.i_[2];
end DamperCage;


Electrical excitation.

within Modelica.Electrical.Machines.BasicMachines.Components;
model ElectricalExcitation "Electrical excitation"
  parameter Real turnsRatio(start=1)
    "Ratio stator current / excitation current";
  SI.Current ie "Excitation current";
  SI.Voltage ve "Excitation voltage";
  Machines.Interfaces.SpacePhasor spacePhasor_r
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
equation
  pin_ep.i + pin_en.i = 0;
  ie = +pin_ep.i;
  ve = pin_ep.v - pin_en.v;
  spacePhasor_r.i_ = {-ie*turnsRatio,0};
  ve = spacePhasor_r.v_[1]*turnsRatio*3/2;
end ElectricalExcitation;


Ideal transformer with 3 windings.

within Modelica.Electrical.Machines.BasicMachines.Components;
model IdealCore "Ideal transformer with 3 windings"
  extends PartialCore;
equation
  im = zeros(m);
  v1 = n12*v2;
  v1 = n13*v3;
end IdealCore;


Space phasor inductor.

within Modelica.Electrical.Machines.BasicMachines.Components;
model Inductor "Space phasor inductor"
  parameter SI.Inductance L[2] "Inductance of both axes";
  SI.Voltage v_[2];
  SI.Current i_[2];
  Machines.Interfaces.SpacePhasor spacePhasor_a
  Machines.Interfaces.SpacePhasor spacePhasor_b
equation
  spacePhasor_a.i_ + spacePhasor_b.i_ = zeros(2);
  v_ = spacePhasor_a.v_ - spacePhasor_b.v_;
  i_ = spacePhasor_a.i_;
  v_[1] = L[1]*der(i_[1]);
  v_[2] = L[2]*der(i_[2]);
end Inductor;


Ideal linear electrical inductor for electrical DC machines. The linear inductor connects the branch voltage v with the branch current i by v = L * di/dt.
If quasiStatic == false, the electrical transients are neglected, i.e., the voltage drop is zero.

within Modelica.Electrical.Machines.BasicMachines.Components;
model InductorDC
  "Ideal linear electrical inductor for electrical DC machines"
  extends Modelica.Electrical.Analog.Interfaces.OnePort;
  parameter SI.Inductance L(start=1) "Inductance";
  parameter Boolean quasiStatic(start=false)
    "No electrical transients if true"
equation
  v = if quasiStatic then 0 else L*der(i);
end InductorDC;


Machine components like AirGaps

within Modelica.Electrical.Machines.BasicMachines;
package Components "Machine components like AirGaps"
  extends Modelica.Icons.Package;
end Components;


Partial airgap model.

within Modelica.Electrical.Machines.BasicMachines.Components;
partial model PartialAirGap "Partial airgap model"
  parameter Integer m=3 "Number of phases"
  parameter Integer p(min=1) "Number of pole pairs";
  output SI.Torque tauElectrical;
  SI.Angle gamma "Rotor displacement angle";
  SI.Current i_ss[2]
    "Stator current space phasor with respect to the stator fixed frame";
  SI.Current i_sr[2]
    "Stator current space phasor with respect to the rotor fixed frame";
  SI.Current i_rs[2]
    "Rotor current space phasor with respect to the stator fixed frame";
  SI.Current i_rr[2]
    "Rotor current space phasor with respect to the rotor fixed frame";
  SI.MagneticFlux psi_ms[2]
    "Magnetizing flux phasor with respect to the stator fixed frame";
  SI.MagneticFlux psi_mr[2]
    "Magnetizing flux phasor with respect to the rotor fixed frame";
  Real RotationMatrix[2, 2] "Matrix of rotation from rotor to stator";
public
  Modelica.Mechanics.Rotational.Interfaces.Flange_a flange
  Modelica.Mechanics.Rotational.Interfaces.Flange_a support
    "Support at which the reaction torque is acting"
  Machines.Interfaces.SpacePhasor spacePhasor_s
  Machines.Interfaces.SpacePhasor spacePhasor_r
  /*
  SI.AngularVelocity omegaPsi_ms
    "Angular velocity of main flux with respect to the stator fixed frame";
  SI.AngularVelocity omegaPsi_mr
    "Angular velocity of main flux with respect to the rotor fixed frame";
  SI.Current i_sm[2]
    "Stator current space phasor with respect to the main flux fixed frame";
  SI.Current i_rm[2]
    "Rotor current space phasor with respect to the main flux fixed frame";
protected
  SI.MagneticFlux psi_msAbs "Length of main flux phasor";
  SI.Angle psi_msArg
    "(Wrapped) angle of main flux phasor with respect to the stator fixed frame";
  SI.Angle psi_mrArg
    "(Wrapped) angle of main flux phasor with respect to the rotor fixed frame";
initial equation
  i_sm = Machines.SpacePhasors.Functions.Rotator(i_ss, psi_msArg);
  i_rm = Machines.SpacePhasors.Functions.Rotator(i_rr, psi_mrArg);
equation
  // AngularVelocity of main flux phasor
  (psi_msAbs, psi_msArg) = Machines.SpacePhasors.Functions.ToPolar(psi_ms);
  psi_mrArg = psi_msArg - gamma;
  omegaPsi_ms = if noEvent(psi_msAbs<Modelica.Constants.small) then 0 else
    (spacePhasor_s.v_[2]*cos(psi_msArg) - spacePhasor_s.v_[1]*sin(psi_msArg))/psi_msAbs;
  omegaPsi_mr = omegaPsi_ms - der(gamma);
  // stator and rotor current w.r.t. main flux fixed frame
  der(i_sm) = Machines.SpacePhasors.Functions.Rotator(
    {der(i_ss[1]) + omegaPsi_ms*i_ss[2], der(i_ss[2]) - omegaPsi_ms*i_ss[1]}, psi_msArg);
  der(i_rm) = Machines.SpacePhasors.Functions.Rotator(
    {der(i_rr[1]) + omegaPsi_mr*i_rr[2], der(i_rr[2]) - omegaPsi_mr*i_rr[1]}, psi_mrArg);
*/
equation
  // mechanical angle of the rotor of an equivalent 2-pole machine
  gamma = p*(flange.phi - support.phi);
  RotationMatrix = {{+cos(gamma),-sin(gamma)},{+sin(gamma),+cos(gamma)}};
  i_ss = spacePhasor_s.i_;
  i_ss = RotationMatrix*i_sr;
  i_rr = spacePhasor_r.i_;
  i_rs = RotationMatrix*i_rr;
  // Stator voltage induction
  spacePhasor_s.v_ = der(psi_ms);
  // Rotor voltage induction
  spacePhasor_r.v_ = der(psi_mr);
  // Electromechanical torque (cross product of current and flux space phasor)
  tauElectrical = m/2*p*(spacePhasor_s.i_[2]*psi_ms[1] - spacePhasor_s.i_[
    1]*psi_ms[2]);
  flange.tau = -tauElectrical;
  support.tau = tauElectrical;
end PartialAirGap;


Partial airgap model of a DC machine.

within Modelica.Electrical.Machines.BasicMachines.Components;
partial model PartialAirGapDC "Partial airgap model of a DC machine"
  parameter Boolean quasiStatic(start=false)
    "No electrical transients if true"
  parameter Real turnsRatio
    "Ratio of armature turns over number of turns of the excitation winding";
  output SI.AngularVelocity w "Angular velocity";
  SI.Voltage vei
    "Voltage drop across field excitation inductance";
  SI.Current ie "Excitation current";
  SI.MagneticFlux psi_e "Excitation flux";
  SI.Voltage vai "Induced armature voltage";
  SI.Current ia "Armature current";
  output SI.Torque tauElectrical;
  Modelica.Mechanics.Rotational.Interfaces.Flange_a flange
  Modelica.Mechanics.Rotational.Interfaces.Flange_a support
    "Support at which the reaction torque is acting"
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ap
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_an
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
equation
  // armature pins
  vai = pin_ap.v - pin_an.v;
  ia = +pin_ap.i;
  ia = -pin_an.i;
  // excitation pins
  vei = pin_ep.v - pin_en.v;
  ie = +pin_ep.i;
  ie = -pin_en.i;
  // induced voltage across field excitation inductance
  vei = if quasiStatic then 0 else der(psi_e);
  // mechanical speed
  w = der(flange.phi) - der(support.phi);
  // induced armature voltage
  vai = turnsRatio*psi_e*w;
  // electrical torque (ia is perpendicular to flux)
  tauElectrical = turnsRatio*psi_e*ia;
  flange.tau = -tauElectrical;
  support.tau = tauElectrical;
end PartialAirGapDC;


Partial model of transformer core with 3 windings.

within Modelica.Electrical.Machines.BasicMachines.Components;
partial model PartialCore
  "Partial model of transformer core with 3 windings"
  parameter Integer m(final min=1) = 3 "Number of phases"
  parameter Real n12(start=1) "Turns ratio 1:2";
  parameter Real n13(start=1) "Turns ratio 1:3";
  SI.Voltage v1[m]=plug_p1.pin.v - plug_n1.pin.v;
  SI.Current i1[m]=plug_p1.pin.i;
  SI.Voltage v2[m]=plug_p2.pin.v - plug_n2.pin.v;
  SI.Current i2[m]=plug_p2.pin.i;
  SI.Voltage v3[m]=plug_p3.pin.v - plug_n3.pin.v;
  SI.Current i3[m]=plug_p3.pin.i;
  SI.Current im[m]=i1 + i2/n12 + i3/n13
    "Magnetizing current";
  Modelica.Electrical.Polyphase.Interfaces.PositivePlug plug_p1(final m=
        m)
  Modelica.Electrical.Polyphase.Interfaces.NegativePlug plug_n1(final m=
        m)
  Modelica.Electrical.Polyphase.Interfaces.PositivePlug plug_p2(final m=
        m)
  Modelica.Electrical.Polyphase.Interfaces.NegativePlug plug_n2(final m=
        m)
  Modelica.Electrical.Polyphase.Interfaces.PositivePlug plug_p3(final m=
        m)
  Modelica.Electrical.Polyphase.Interfaces.NegativePlug plug_n3(final m=
        m)
equation
  plug_p1.pin.i + plug_n1.pin.i = zeros(m);
  plug_p2.pin.i + plug_n2.pin.i = zeros(m);
  plug_p3.pin.i + plug_n3.pin.i = zeros(m);
end PartialCore;


Permanent magnet excitation.

within Modelica.Electrical.Machines.BasicMachines.Components;
model PermanentMagnet "Permanent magnet excitation"
  parameter SI.Current Ie "Equivalent excitation current";
  Machines.Interfaces.SpacePhasor spacePhasor_r
equation
  spacePhasor_r.i_ = {-Ie,0};
end PermanentMagnet;


Permanent magnet excitation.

within Modelica.Electrical.Machines.BasicMachines.Components;
model PermanentMagnetWithLosses "Permanent magnet excitation"
  extends Machines.BasicMachines.Components.PermanentMagnet;
  extends Machines.Losses.InductionMachines.PermanentMagnetLosses;
end PermanentMagnetWithLosses;


Squirrel Cage. Model of a squirrel cage / symmetrical damper cage in two axis.

within Modelica.Electrical.Machines.BasicMachines.Components;
model SquirrelCage "Squirrel Cage"
  parameter SI.Inductance Lrsigma
    "Rotor stray inductance per phase translated to stator";
  parameter SI.Resistance Rr
    "Rotor resistance per phase translated to stator at T_ref";
  parameter SI.Temperature T_ref=293.15
    "Reference temperature";
  parameter SI.LinearTemperatureCoefficient alpha=0
    "Temperature coefficient of resistance at T_ref";
  extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(T=T_ref);
  SI.Resistance Rr_actual
    "Actual resistance = Rr*(1 + alpha*(T_heatPort - T_ref))";
  Machines.Interfaces.SpacePhasor spacePhasor_r
  Modelica.Blocks.Interfaces.RealOutput i[2](
    each final quantity="ElectricCurrent",
    each final unit="A") = -spacePhasor_r.i_
    "Currents out from squirrel cage";
equation
  assert((1 + alpha*(T_heatPort - T_ref)) >= Modelica.Constants.eps,
    "Temperature outside scope of model!");
  Rr_actual = Rr*(1 + alpha*(T_heatPort - T_ref));
  spacePhasor_r.v_ = Rr_actual*spacePhasor_r.i_ + Lrsigma*der(
    spacePhasor_r.i_);
  2/3*LossPower = Rr_actual*(spacePhasor_r.i_[1]*spacePhasor_r.i_[1] +
    spacePhasor_r.i_[2]*spacePhasor_r.i_[2]);
end SquirrelCage;


Electrical shunt/separate excited linear DC machine. Model of a DC Machine with electrical shunt or separate excitation.

Armature resistance and inductance are modeled directly after the armature pins, then using a AirGapDC model.

The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.DCMachines;
model DC_ElectricalExcited
  "Electrical shunt/separate excited linear DC machine"
  extends Machines.Interfaces.PartialBasicDCMachine(
    final ViNominal=VaNominal - Machines.Thermal.convertResistance(
        Ra,
        TaRef,
        alpha20a,
        TaNominal)*IaNominal - Machines.Losses.DCMachines.brushVoltageDrop(
        brushParameters, IaNominal),
    final psi_eNominal=Lme*IeNominal,
    redeclare final Machines.Thermal.DCMachines.ThermalAmbientDCEE
      thermalAmbient(final Te=TeOperational),
    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCEE thermalPort,

    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCEE
      internalThermalPort,
    redeclare final Machines.Interfaces.DCMachines.PowerBalanceDCEE
      powerBalance(final powerExcitation=ve*ie, final lossPowerExcitation=re.LossPower),

    core(final w=airGapDC.w));
  parameter SI.Current IeNominal(start=1)
    "Nominal excitation current"
  parameter SI.Resistance Re(start=100)
    "Field excitation resistance at TeRef"
  parameter SI.Temperature TeRef(start=293.15)
    "Reference temperature of excitation resistance"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20e(start=0)
    "Temperature coefficient of excitation resistance"
  parameter SI.Inductance Le(start=1)
    "Total field excitation inductance"
  parameter Real sigmae(
    min=0,
    max=0.99,
    start=0) "Stray fraction of total excitation inductance"
  parameter SI.Temperature TeOperational(start=293.15)
    "Operational (shunt) excitation temperature"
  output SI.Voltage ve=pin_ep.v - pin_en.v
    "Field excitation voltage";
  output SI.Current ie(start=0) = pin_ep.i
    "Field excitation current";
  Machines.BasicMachines.Components.AirGapDC airGapDC(
    final turnsRatio=turnsRatio,
    final Le=Lme,
    final quasiStatic=quasiStatic)
  Modelica.Electrical.Analog.Basic.Ground ground
  Machines.BasicMachines.Components.CompoundDCExcitation compoundDCExcitation(final
      excitationTurnsRatio=1)
  Modelica.Electrical.Analog.Basic.Ground groundSE
  Modelica.Electrical.Analog.Basic.Resistor re(
    final R=Re,
    final T_ref=TeRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20e, TeRef),
    final useHeatPort=true)
  Machines.BasicMachines.Components.InductorDC lesigma(final L=Lesigma, final
      quasiStatic=quasiStatic)
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
    "Positive excitation pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
    "Negative excitation pin"
protected
  final parameter SI.Inductance Lme=Le*(1 - sigmae)
    "Main part of excitation inductance";
  final parameter SI.Inductance Lesigma=Le*sigmae
    "Stray part of excitation inductance"
equation
  connect(airGapDC.pin_ap, la.n)
  connect(airGapDC.support, internalSupport)
  connect(airGapDC.flange, inertiaRotor.flange_a)
  connect(re.p, pin_ep)
  connect(re.n, lesigma.p)
  connect(ground.p, airGapDC.pin_en)
  connect(airGapDC.pin_en, compoundDCExcitation.pin_n)
  connect(airGapDC.pin_ep, compoundDCExcitation.pin_p)
  connect(groundSE.p, compoundDCExcitation.pin_sen)
  connect(pin_en, compoundDCExcitation.pin_en)
  connect(compoundDCExcitation.pin_ep, lesigma.n)
  connect(airGapDC.pin_an, brush.p)
  connect(re.heatPort, internalThermalPort.heatPortExcitation)
end DC_ElectricalExcited;


Permanent magnet DC machine. Model of a DC Machine with permanent magnets.

Armature resistance and inductance are modeled directly after the armature pins, then using a AirGapDC model. Permanent magnet excitation is modelled by a constant equivalent excitation current feeding AirGapDC. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.DCMachines;
model DC_PermanentMagnet "Permanent magnet DC machine"
  extends Machines.Interfaces.PartialBasicDCMachine(
    final ViNominal=VaNominal - Machines.Thermal.convertResistance(
        Ra,
        TaRef,
        alpha20a,
        TaNominal)*IaNominal - Machines.Losses.DCMachines.brushVoltageDrop(
        brushParameters, IaNominal),
    final psi_eNominal=Lme*IeNominal,
    redeclare final Machines.Thermal.DCMachines.ThermalAmbientDCPM
      thermalAmbient(final Tpm=TpmOperational),
    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCPM thermalPort,

    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCPM
      internalThermalPort,
    redeclare final Machines.Interfaces.DCMachines.PowerBalanceDCPM
      powerBalance(final lossPowerPermanentMagnet=0),
    core(final w=airGapDC.w));
  final parameter SI.Temperature TpmOperational=293.15
    "Operational temperature of permanent magnet"
  Machines.BasicMachines.Components.AirGapDC airGapDC(
    final turnsRatio=turnsRatio,
    final Le=Lme,
    final quasiStatic=quasiStatic)
  Modelica.Electrical.Analog.Basic.Ground eGround
  Modelica.Electrical.Analog.Sources.ConstantCurrent ie(I=IeNominal)
protected
  constant SI.Inductance Lme=1
    "Field excitation inductance";
  constant SI.Current IeNominal=1
    "Equivalent excitation current";
equation
  connect(eGround.p, ie.p)
  connect(airGapDC.pin_ep, ie.n)
  connect(airGapDC.pin_en, eGround.p)
  connect(airGapDC.pin_ap, la.n)
  connect(airGapDC.support, internalSupport)
  connect(airGapDC.flange, inertiaRotor.flange_a)
  connect(airGapDC.pin_an, brush.p)
end DC_PermanentMagnet;


Series excited linear DC machine. Model of a DC Machine with series excitation.

Armature resistance and inductance are modeled directly after the armature pins, then using a AirGapDC model.

The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.DCMachines;
model DC_SeriesExcited "Series excited linear DC machine"
  extends Machines.Interfaces.PartialBasicDCMachine(
    wNominal(start=1410*2*pi/60),
    final ViNominal=VaNominal - (Machines.Thermal.convertResistance(
        Ra,
        TaRef,
        alpha20a,
        TaNominal) + Machines.Thermal.convertResistance(
        Re,
        TeRef,
        alpha20e,
        TeNominal))*IaNominal - Machines.Losses.DCMachines.brushVoltageDrop(
        brushParameters, IaNominal),
    final psi_eNominal=Lme*abs(IaNominal),
    redeclare final Machines.Thermal.DCMachines.ThermalAmbientDCSE
      thermalAmbient(final Tse=TeOperational),
    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCSE thermalPort,

    redeclare final Machines.Interfaces.DCMachines.ThermalPortDCSE
      internalThermalPort,
    redeclare final Machines.Interfaces.DCMachines.PowerBalanceDCSE
      powerBalance(final powerSeriesExcitation=ve*ie, final
        lossPowerSeriesExcitation=re.LossPower),
    core(final w=airGapDC.w));
  parameter SI.Resistance Re(start=0.01)
    "Series excitation resistance at TeRef"
  parameter SI.Temperature TeRef(start=293.15)
    "Reference temperature of excitation resistance"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20e(start=0)
    "Temperature coefficient of excitation resistance"
  parameter SI.Inductance Le(start=0.0005)
    "Total field excitation inductance"
  parameter Real sigmae(
    min=0,
    max=0.99,
    start=0) "Stray fraction of total excitation inductance"
  parameter SI.Temperature TeNominal(start=293.15)
    "Nominal series excitation temperature"
  parameter SI.Temperature TeOperational(start=293.15)
    "Operational series excitation temperature"
  output SI.Voltage ve=pin_ep.v - pin_en.v
    "Field excitation voltage";
  output SI.Current ie=pin_ep.i "Field excitation current";
  Machines.BasicMachines.Components.AirGapDC airGapDC(
    final turnsRatio=turnsRatio,
    final Le=Lme,
    final quasiStatic=quasiStatic)
  Machines.BasicMachines.Components.CompoundDCExcitation compoundDCExcitation(final
      excitationTurnsRatio=1)
  Modelica.Electrical.Analog.Basic.Ground ground
  Modelica.Electrical.Analog.Basic.Ground groundE
  Modelica.Electrical.Analog.Basic.Resistor re(
    final R=Re,
    final T_ref=TeRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20e, TeRef),
    final useHeatPort=true)
  Machines.BasicMachines.Components.InductorDC lesigma(final L=Lesigma, final
      quasiStatic=quasiStatic)
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
    "Positive series excitation pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
    "Negative series excitation pin"
protected
  final parameter SI.Inductance Lme=Le*(1 - sigmae)
    "Main part of excitation inductance";
  final parameter SI.Inductance Lesigma=Le*sigmae
    "Stray part of excitation inductance"
equation
  connect(airGapDC.pin_ap, la.n)
  connect(airGapDC.support, internalSupport)
  connect(airGapDC.flange, inertiaRotor.flange_a)
  connect(pin_ep, re.p)
  connect(re.n, lesigma.p)
  connect(airGapDC.pin_en, compoundDCExcitation.pin_n)
  connect(compoundDCExcitation.pin_p, airGapDC.pin_ep)
  connect(airGapDC.pin_en, ground.p)
  connect(compoundDCExcitation.pin_sen, pin_en)
  connect(compoundDCExcitation.pin_sep, lesigma.n)
  connect(compoundDCExcitation.pin_en, groundE.p)
  connect(airGapDC.pin_an, brush.p)
  connect(re.heatPort, internalThermalPort.heatPortSeriesExcitation)
end DC_SeriesExcited;


Models of DC machines

within Modelica.Electrical.Machines.BasicMachines;
package DCMachines "Models of DC machines"
  extends Modelica.Icons.VariantsPackage;
end DCMachines;


Induction machine with slipring rotor. Model of a three-phase induction machine with slipring rotor.

Resistance and stray inductance of stator and rotor are modeled directly in stator respectively rotor phases, then using space phasor transformation and a stator-fixed AirGap model. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.InductionMachines;
model IM_SlipRing "Induction machine with slipring rotor"
  extends Machines.Interfaces.PartialBasicInductionMachine(
    final idq_ss=airGap.i_ss,
    final idq_sr=airGap.i_sr,
    final idq_rs=airGap.i_rs,
    final idq_rr=airGap.i_rr,
    redeclare final Machines.Thermal.InductionMachines.ThermalAmbientIMS
      thermalAmbient(final Tr=TrOperational, final mr=m),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortIMS
      thermalPort(final mr=m),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortIMS
      internalThermalPort(final mr=m),
    redeclare final Machines.Interfaces.InductionMachines.PowerBalanceIMS
      powerBalance(
      final lossPowerRotorWinding=sum(rr.resistor.LossPower),
      final lossPowerRotorCore=rotorCore.lossPower,
      final lossPowerBrush=0,
      final powerRotor=Machines.SpacePhasors.Functions.activePower(vr, ir)),
    statorCore(final w=statorCoreParameters.wRef));

  Machines.BasicMachines.Components.AirGapS airGap(
    final p=p,
    final Lm=Lm,
    final m=m)
  parameter SI.Inductance Lm(start=3*ZsRef*sqrt(1 - 0.0667)/(2*pi
        *fsNominal)) "Stator main field inductance per phase"
  parameter SI.Inductance Lrsigma(start=3*ZsRef*(1 - sqrt(1 -
        0.0667))/(2*pi*fsNominal))
    "Rotor stray inductance per phase w.r.t. rotor side"
  parameter SI.Inductance Lrzero=Lrsigma
    "Rotor zero sequence inductance w.r.t. rotor side"
  parameter SI.Resistance Rr(start=0.04*ZsRef)
    "Rotor resistance per phase at TRef w.r.t. rotor side"
  parameter SI.Temperature TrRef(start=293.15)
    "Reference temperature of rotor resistance"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start=0)
    "Temperature coefficient of rotor resistance at 20 degC"
  parameter Boolean useTurnsRatio(start=true)
    "Use turnsRatio or calculate from locked-rotor voltage?";
  parameter Real turnsRatio(final min=Modelica.Constants.small, start=1)
    "Effective number of stator turns / effective number of rotor turns"
  parameter SI.Voltage VsNominal(start=100)
    "Nominal stator voltage per phase"
  parameter SI.Voltage VrLockedRotor(start=100*(2*pi*
        fsNominal*Lm)/sqrt(Rs^2 + (2*pi*fsNominal*(Lm + Lssigma))^2))
    "Locked-rotor voltage per phase"
  parameter SI.Temperature TrOperational(start=293.15)
    "Operational temperature of rotor resistance"
  parameter Machines.Losses.CoreParameters rotorCoreParameters(
    final m=3,
    PRef=0,
    VRef(start=1) = 1,
    wRef(start=1) = 1)
    "Rotor core loss parameter record; all parameters refer to rotor side"
  output SI.Current i_0_r(stateSelect=StateSelect.prefer)=
       spacePhasorR.zero.i "Rotor zero-sequence current";
  output SI.Voltage vr[m]=plug_rp.pin.v - plug_rn.pin.v
    "Rotor instantaneous voltages";
  output SI.Current ir[m]=plug_rp.pin.i
    "Rotor instantaneous currents";
protected
  final parameter Real internalTurnsRatio=if useTurnsRatio then
      turnsRatio else VsNominal/VrLockedRotor*(2*pi*fsNominal*Lm)/sqrt(Rs
      ^2 + (2*pi*fsNominal*(Lm + Lssigma))^2);
public
  Machines.SpacePhasors.Components.SpacePhasor spacePhasorR(final turnsRatio=
        internalTurnsRatio)
  Modelica.Electrical.Polyphase.Basic.Resistor rr(
    final m=m,
    final R=fill(Rr, m),
    final T_ref=fill(TrRef, m),
    final alpha=fill(Machines.Thermal.convertAlpha(alpha20r, TrRef), m),
    final useHeatPort=true,
    final T=fill(TrRef, m))
  Modelica.Electrical.Polyphase.Interfaces.PositivePlug plug_rp(final m=
        m) "Positive rotor plug"
  Modelica.Electrical.Polyphase.Interfaces.NegativePlug plug_rn(final m=
        m) "Negative rotor plug"
  Machines.BasicMachines.Components.Inductor lrsigma(final L=fill(
        internalTurnsRatio^2*Lrsigma, 2))
  Modelica.Electrical.Analog.Basic.Inductor lrzero(final L=
        internalTurnsRatio^2*Lrzero)
  Machines.Losses.InductionMachines.Core rotorCore(
    final coreParameters=rotorCoreParameters,
    final w=rotorCoreParameters.wRef,
    final useHeatPort=true,
    final turnsRatio=internalTurnsRatio)
equation
  connect(lssigma.spacePhasor_b, airGap.spacePhasor_s)
  connect(lrsigma.spacePhasor_b, airGap.spacePhasor_r)
  connect(rr.plug_n, spacePhasorR.plug_p)
  connect(spacePhasorR.plug_n, plug_rn)
  connect(spacePhasorR.zero, lrzero.p)
  connect(spacePhasorR.ground, lrzero.n)
  connect(spacePhasorR.spacePhasor, lrsigma.spacePhasor_a)
  connect(rotorCore.spacePhasor, lrsigma.spacePhasor_a)
  connect(rotorCore.heatPort, internalThermalPort.heatPortRotorCore)
  connect(rr.heatPort, internalThermalPort.heatPortRotorWinding)
  connect(plug_rp, rr.plug_p)
  connect(airGap.flange, inertiaRotor.flange_a)
  connect(fixed.flange, internalSupport)
  connect(internalSupport, airGap.support)
end IM_SlipRing;


Induction machine with squirrel cage rotor. Model of a three-phase induction machine with squirrel cage.

Resistance and stray inductance of stator is modeled directly in stator phases, then using space phasor transformation. Resistance and stray inductance of rotor's squirrel cage is modeled in two axis of the rotor-fixed coordinate system. Both together connected via a stator-fixed AirGap model. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.InductionMachines;
model IM_SquirrelCage
  "Induction machine with squirrel cage rotor"
  extends Machines.Interfaces.PartialBasicInductionMachine(
    final idq_ss=airGap.i_ss,
    final idq_sr=airGap.i_sr,
    final idq_rs=airGap.i_rs,
    final idq_rr=airGap.i_rr,
    redeclare final Machines.Thermal.InductionMachines.ThermalAmbientIMC
      thermalAmbient(final Tr=TrOperational),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortIMC
      thermalPort,
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortIMC
      internalThermalPort,
    redeclare final Machines.Interfaces.InductionMachines.PowerBalanceIMC
      powerBalance(final lossPowerRotorWinding=squirrelCageR.LossPower, final
        lossPowerRotorCore=0),
    statorCore(final w=statorCoreParameters.wRef));
  output SI.Current ir[2]=squirrelCageR.i
    "Rotor cage currents";
  Machines.BasicMachines.Components.AirGapS airGap(
    final p=p,
    final Lm=Lm,
    final m=m)
  parameter SI.Inductance Lm(start=3*ZsRef*sqrt(1 - 0.0667)/(2*pi
        *fsNominal)) "Stator main field inductance per phase"
  parameter SI.Inductance Lrsigma(start=3*ZsRef*(1 - sqrt(1 -
        0.0667))/(2*pi*fsNominal))
    "Rotor stray inductance per phase (equivalent three-phase winding)"
  parameter SI.Resistance Rr(start=0.04*ZsRef)
    "Rotor resistance per phase (equivalent three-phase winding) at TRef"
  parameter SI.Temperature TrRef(start=293.15)
    "Reference temperature of rotor resistance"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start=0)
    "Temperature coefficient of rotor resistance at 20 degC"
  parameter SI.Temperature TrOperational(start=293.15)
    "Operational temperature of rotor resistance"
  Machines.BasicMachines.Components.SquirrelCage squirrelCageR(
    final Lrsigma=Lrsigma,
    final Rr=Rr,
    final useHeatPort=true,
    final T_ref=TrRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20r, TrRef))
equation
  connect(airGap.spacePhasor_r, squirrelCageR.spacePhasor_r)
  connect(airGap.flange, inertiaRotor.flange_a)
  connect(lssigma.spacePhasor_b, airGap.spacePhasor_s)
  connect(squirrelCageR.heatPort, internalThermalPort.heatPortRotorWinding)
  connect(airGap.support, internalSupport)
end IM_SquirrelCage;


Models of induction machines

within Modelica.Electrical.Machines.BasicMachines;
package InductionMachines "Models of induction machines"
  extends Modelica.Icons.VariantsPackage;
end InductionMachines;


Quasi-static electrical shunt/separate excited linear DC machine.

within Modelica.Electrical.Machines.BasicMachines.QuasiStaticDCMachines;
model DC_ElectricalExcited
  "Quasi-static electrical shunt/separate excited linear DC machine"
  extends Machines.BasicMachines.DCMachines.DC_ElectricalExcited(final
      quasiStatic=true);
  extends Machines.Icons.QuasiStaticMachine;
end DC_ElectricalExcited;


Quasi-static permanent magnet DC machine.

within Modelica.Electrical.Machines.BasicMachines.QuasiStaticDCMachines;
model DC_PermanentMagnet "Quasi-static permanent magnet DC machine"
  extends Machines.BasicMachines.DCMachines.DC_PermanentMagnet(final
      quasiStatic=true);
  extends Machines.Icons.QuasiStaticMachine;
end DC_PermanentMagnet;


Quasi-static series excited linear DC machine.

within Modelica.Electrical.Machines.BasicMachines.QuasiStaticDCMachines;
model DC_SeriesExcited "Quasi-static series excited linear DC machine"
  extends Machines.BasicMachines.DCMachines.DC_SeriesExcited(final quasiStatic=
        true);
  extends Machines.Icons.QuasiStaticMachine;
end DC_SeriesExcited;


Models of quasi-static DC machines

within Modelica.Electrical.Machines.BasicMachines;
package QuasiStaticDCMachines "Models of quasi-static DC machines"
  extends Modelica.Icons.VariantsPackage;
end QuasiStaticDCMachines;


Models of synchronous machines

within Modelica.Electrical.Machines.BasicMachines;
package SynchronousMachines "Models of synchronous machines"
  extends Modelica.Icons.VariantsPackage;
end SynchronousMachines;


Electrical excited synchronous machine with damper cage. Model of a three-phase electrical excited synchronous machine with damper cage.

Resistance and stray inductance of stator is modeled directly in stator phases, then using space phasor transformation and a rotor-fixed AirGap model. Resistance and stray inductance of rotor's squirrel cage is modeled in two axis of the rotor-fixed coordinate system. Electrical excitation is modelled by converting excitation current and voltage to d-axis space phasors. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.SynchronousMachines;
model SM_ElectricalExcited
  "Electrical excited synchronous machine with damper cage"
  extends Machines.Interfaces.PartialBasicInductionMachine(
    Lssigma(start=0.1*ZsRef/(2*pi*fsNominal)),
    final idq_ss=airGap.i_ss,
    final idq_sr=airGap.i_sr,
    final idq_rs=airGap.i_rs,
    final idq_rr=airGap.i_rr,
    redeclare final Machines.Thermal.SynchronousMachines.ThermalAmbientSMEE
      thermalAmbient(
      final useDamperCage=useDamperCage,
      final Te=TeOperational,
      final Tr=TrOperational),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMEE
      thermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMEE
      internalThermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.PowerBalanceSMEE
      powerBalance(
      final lossPowerRotorWinding=damperCageLossPower,
      final powerExcitation=ve*ie,
      final lossPowerExcitation=re.LossPower,
      final lossPowerBrush=brush.lossPower,
      final lossPowerRotorCore=0),
    statorCore(final w=statorCoreParameters.wRef));
  Modelica.Blocks.Interfaces.RealOutput ir[2](
    start=zeros(2),
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage "Damper cage currents"
  Modelica.Blocks.Interfaces.RealOutput idq_dr[2](
    each stateSelect=StateSelect.prefer,
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage
    "Damper space phasor current / rotor fixed frame"
  Machines.BasicMachines.Components.AirGapR airGap(
    final p=p,
    final Lmd=Lmd,
    final Lmq=Lmq,
    final m=m)
  parameter SI.Temperature TrOperational(start=293.15)
    "Operational temperature of (optional) damper cage"
  parameter SI.Inductance Lmd(start=1.5*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in d-axis"
  parameter SI.Inductance Lmq(start=1.5*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in q-axis"
  parameter Boolean useDamperCage(start=true)
    "Enable / disable damper cage"
  parameter SI.Inductance Lrsigmad(start=0.05*ZsRef/(2*pi*
        fsNominal)) "Damper stray inductance in d-axis"
  parameter SI.Inductance Lrsigmaq=Lrsigmad
    "Damper stray inductance in q-axis"
  parameter SI.Resistance Rrd(start=0.04*ZsRef)
    "Damper resistance in d-axis at TRef"
  parameter SI.Resistance Rrq=Rrd
    "Damper resistance in q-axis at TRef"
  parameter SI.Temperature TrRef(start=293.15)
    "Reference temperature of damper resistances in d- and q-axis"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start=0)
    "Temperature coefficient of damper resistances in d- and q-axis"
  parameter SI.Voltage VsNominal(start=100)
    "Nominal stator RMS voltage per phase"
  parameter SI.Current IeOpenCircuit(start=10)
    "Open circuit excitation current @ nominal voltage and frequency"
  parameter SI.Resistance Re(start=2.5)
    "Excitation resistance at TRef"
  parameter SI.Temperature TeRef(start=293.15)
    "Reference temperature of excitation resistance"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20e(start=0)
    "Temperature coefficient of excitation resistance"
  parameter Real sigmae(
    min=0,
    max=0.99,
    start=0.025) "Stray fraction of total excitation inductance"
  parameter SI.Temperature TeOperational(start=293.15)
    "Operational excitation temperature"
  parameter Machines.Losses.BrushParameters brushParameters
    "Brush loss parameter record"
  output SI.Voltage ve=pin_ep.v - pin_en.v
    "Excitation voltage";
  output SI.Current ie=pin_ep.i "Excitation current";
  Machines.BasicMachines.Components.DamperCage damperCage(
    final Lrsigmad=Lrsigmad,
    final Lrsigmaq=Lrsigmaq,
    final Rrd=Rrd,
    final Rrq=Rrq,
    final T_ref=TrRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20r, TrRef),
    final useHeatPort=true) if useDamperCage
  Machines.BasicMachines.Components.ElectricalExcitation electricalExcitation(final
      turnsRatio=turnsRatio)
  Modelica.Electrical.Analog.Basic.Resistor re(
    final R=Re,
    final T_ref=TeRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20e, TeRef),
    final useHeatPort=true)
  Modelica.Electrical.Analog.Basic.Inductor lesigma(final L=Lesigma)
  Modelica.Electrical.Analog.Interfaces.PositivePin pin_ep
    "Positive excitation pin"
  Modelica.Electrical.Analog.Interfaces.NegativePin pin_en
    "Negative excitation pin"
  Machines.Losses.DCMachines.Brush brush(final brushParameters=brushParameters,
      final useHeatPort=true)
protected
  final parameter Real turnsRatio=sqrt(2)*VsNominal/(2*pi*fsNominal*Lmd*
      IeOpenCircuit) "Stator current / excitation current";
  final parameter SI.Inductance Lesigma=Lmd*turnsRatio^2*3/
      2*sigmae/(1 - sigmae);
  Modelica.Blocks.Interfaces.RealOutput damperCageLossPower(final
      quantity="Power", final unit="W") "Damper losses";
equation
  connect(ir, damperCage.i);
  connect(idq_dr, damperCage.i);
  connect(damperCageLossPower, damperCage.lossPower);
  if not useDamperCage then
    damperCageLossPower = 0;
  end if;
  connect(airGap.spacePhasor_r, damperCage.spacePhasor_r)
  connect(airGap.spacePhasor_r, electricalExcitation.spacePhasor_r)
  connect(electricalExcitation.pin_en, pin_en)
  connect(pin_ep, brush.p)
  connect(brush.n, re.p)
  connect(re.n, lesigma.p)
  connect(lesigma.n, electricalExcitation.pin_ep)
  connect(lssigma.spacePhasor_b, airGap.spacePhasor_s)
  connect(brush.heatPort, internalThermalPort.heatPortBrush)
  connect(re.heatPort, internalThermalPort.heatPortExcitation)
  connect(airGap.flange, inertiaRotor.flange_a)
  connect(airGap.support, internalSupport)

  connect(damperCage.heatPort, internalThermalPort.heatPortRotorWinding)
end SM_ElectricalExcited;


Permanent magnet synchronous machine. Model of a three-phase permanent magnet synchronous machine.

Resistance and stray inductance of stator is modeled directly in stator phases, then using space phasor transformation and a rotor-fixed AirGap model. Resistance and stray inductance of rotor's squirrel cage is modeled in two axis of the rotor-fixed coordinate system. Permanent magnet excitation is modelled by a constant equivalent excitation current feeding the d-axis. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.SynchronousMachines;
model SM_PermanentMagnet "Permanent magnet synchronous machine"
  extends Machines.Interfaces.PartialBasicInductionMachine(
    Lssigma(start=0.1*ZsRef/(2*pi*fsNominal)),
    final idq_ss=airGap.i_ss,
    final idq_sr=airGap.i_sr,
    final idq_rs=airGap.i_rs,
    final idq_rr=airGap.i_rr,
    redeclare final Machines.Thermal.SynchronousMachines.ThermalAmbientSMPM
      thermalAmbient(
      final useDamperCage=useDamperCage,
      final Tr=TrOperational,
      final Tpm=TpmOperational),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMPM
      thermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMPM
      internalThermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.PowerBalanceSMPM
      powerBalance(
      final lossPowerRotorWinding=damperCageLossPower,
      final lossPowerRotorCore=0,
      final lossPowerPermanentMagnet=permanentMagnet.lossPower),
    statorCore(final w=statorCoreParameters.wRef));
  Modelica.Blocks.Interfaces.RealOutput ir[2](
    start=zeros(2),
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage "Damper cage currents"
  Modelica.Blocks.Interfaces.RealOutput idq_dr[2](
    each stateSelect=StateSelect.prefer,
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage
    "Damper space phasor current / rotor fixed frame"
  Machines.BasicMachines.Components.AirGapR airGap(
    final p=p,
    final Lmd=Lmd,
    final Lmq=Lmq,
    final m=m)
  final parameter SI.Temperature TpmOperational=293.15
    "Operational temperature of permanent magnet"
  parameter SI.Temperature TrOperational(start=293.15)
    "Operational temperature of (optional) damper cage"
  parameter SI.Voltage VsOpenCircuit(start=112.3)
    "Open circuit RMS voltage per phase @ fsNominal";
  parameter SI.Inductance Lmd(start=0.3*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in d-axis"
  parameter SI.Inductance Lmq(start=0.3*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in q-axis"
  parameter Boolean useDamperCage(start=true)
    "Enable / disable damper cage"
  parameter SI.Inductance Lrsigmad(start=0.05*ZsRef/(2*pi*
        fsNominal)) "Damper stray inductance in d-axis"
  parameter SI.Inductance Lrsigmaq=Lrsigmad
    "Damper stray inductance in q-axis"
  parameter SI.Resistance Rrd(start=0.04*ZsRef)
    "Damper resistance in d-axis at TRef"
  parameter SI.Resistance Rrq=Rrd
    "Damper resistance in q-axis at TRef"
  parameter SI.Temperature TrRef(start=293.15)
    "Reference temperature of damper resistances in d- and q-axis"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start=0)
    "Temperature coefficient of damper resistances in d- and q-axis"
  parameter Machines.Losses.PermanentMagnetLossParameters permanentMagnetLossParameters(IRef(
        start=100), wRef(start=2*pi*fsNominal/p))
    "Permanent magnet loss parameter record"
  Components.PermanentMagnetWithLosses permanentMagnet(
    final Ie=Ie,
    final useHeatPort=true,
    final m=m,
    final permanentMagnetLossParameters=permanentMagnetLossParameters,
    final is=is)
  Machines.BasicMachines.Components.DamperCage damperCage(
    final Lrsigmad=Lrsigmad,
    final Lrsigmaq=Lrsigmaq,
    final Rrd=Rrd,
    final Rrq=Rrq,
    final T_ref=TrRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20r, TrRef),
    final useHeatPort=true) if useDamperCage
protected
  final parameter SI.Current Ie=sqrt(2)*VsOpenCircuit/(Lmd*
      2*pi*fsNominal) "Equivalent excitation current";
  Modelica.Blocks.Interfaces.RealOutput damperCageLossPower(final
      quantity="Power", final unit="W") "Damper losses";
equation
  connect(ir, damperCage.i);
  connect(idq_dr, damperCage.i);
  connect(damperCageLossPower, damperCage.lossPower);
  if not useDamperCage then
    damperCageLossPower = 0;
  end if;
  connect(airGap.spacePhasor_r, damperCage.spacePhasor_r)
  connect(airGap.spacePhasor_r, permanentMagnet.spacePhasor_r)
  connect(airGap.support, internalSupport)
  connect(lssigma.spacePhasor_b, airGap.spacePhasor_s)
  connect(airGap.flange, inertiaRotor.flange_a)
  connect(permanentMagnet.heatPort, internalThermalPort.heatPortPermanentMagnet)
  connect(permanentMagnet.flange, inertiaRotor.flange_b)
  connect(damperCage.heatPort, internalThermalPort.heatPortRotorWinding)
  connect(internalSupport, permanentMagnet.support)
end SM_PermanentMagnet;


Synchronous machine with reluctance rotor and damper cage. Model of a three-phase synchronous machine with reluctance rotor and damper cage.

Resistance and stray inductance of stator is modeled directly in stator phases, then using space phasor transformation. Resistance and stray inductance of rotor's squirrel cage is modeled in two axis of the rotor-fixed coordinate system. Both together connected via a rotor-fixed AirGap model. The machine models take the following loss effects into account:

within Modelica.Electrical.Machines.BasicMachines.SynchronousMachines;
model SM_ReluctanceRotor
  "Synchronous machine with reluctance rotor and damper cage"
  extends Machines.Interfaces.PartialBasicInductionMachine(
    Lssigma(start=0.1*ZsRef/(2*pi*fsNominal)),
    final idq_ss=airGap.i_ss,
    final idq_sr=airGap.i_sr,
    final idq_rs=airGap.i_rs,
    final idq_rr=airGap.i_rr,
    redeclare final Machines.Thermal.SynchronousMachines.ThermalAmbientSMR
      thermalAmbient(final useDamperCage=useDamperCage, final Tr=TrOperational),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMR
      thermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.ThermalPortSMR
      internalThermalPort(final useDamperCage=useDamperCage),
    redeclare final Machines.Interfaces.InductionMachines.PowerBalanceSMR
      powerBalance(final lossPowerRotorWinding=damperCageLossPower, final
        lossPowerRotorCore=0),
    statorCore(final w=statorCoreParameters.wRef));

  Modelica.Blocks.Interfaces.RealOutput ir[2](
    start=zeros(2),
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage "Damper cage currents"
  Modelica.Blocks.Interfaces.RealOutput idq_dr[2](
    each stateSelect=StateSelect.prefer,
    each final quantity="ElectricCurrent",
    each final unit="A") if useDamperCage
    "Damper space phasor current / rotor fixed frame"
  Machines.BasicMachines.Components.AirGapR airGap(
    final p=p,
    final Lmd=Lmd,
    final Lmq=Lmq,
    final m=m)
  parameter SI.Temperature TrOperational(start=293.15)
    "Operational temperature of (optional) damper cage"
  parameter SI.Inductance Lmd(start=2.9*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in d-axis"
  parameter SI.Inductance Lmq(start=0.9*ZsRef/(2*pi*fsNominal))
    "Stator main field inductance per phase in q-axis"
  parameter Boolean useDamperCage(start=true)
    "Enable / disable damper cage"
  parameter SI.Inductance Lrsigmad(start=0.05*ZsRef/(2*pi*
        fsNominal)) "Damper stray inductance in d-axis"
  parameter SI.Inductance Lrsigmaq=Lrsigmad
    "Damper stray inductance in q-axis"
  parameter SI.Resistance Rrd(start=0.04*ZsRef)
    "Damper resistance in d-axis at TRef"
  parameter SI.Resistance Rrq=Rrd
    "Damper resistance in q-axis at TRef"
  parameter SI.Temperature TrRef(start=293.15)
    "Reference temperature of damper resistances in d- and q-axis"
  parameter Machines.Thermal.LinearTemperatureCoefficient20 alpha20r(start=0)
    "Temperature coefficient of damper resistances in d- and q-axis"
  Machines.BasicMachines.Components.DamperCage damperCage(
    final Lrsigmad=Lrsigmad,
    final Lrsigmaq=Lrsigmaq,
    final Rrd=Rrd,
    final Rrq=Rrq,
    final T_ref=TrRef,
    final alpha=Machines.Thermal.convertAlpha(alpha20r, TrRef),
    final useHeatPort=true) if useDamperCage
protected
  Modelica.Blocks.Interfaces.RealOutput damperCageLossPower(final
      quantity="Power", final unit="W") "Damper losses";
equation
  connect(ir, damperCage.i);
  connect(idq_dr, damperCage.i);
  connect(damperCageLossPower, damperCage.lossPower);
  if not useDamperCage then
    damperCageLossPower = 0;
  end if;
  connect(airGap.spacePhasor_r, damperCage.spacePhasor_r)
  connect(airGap.support, internalSupport)
  connect(lssigma.spacePhasor_b, airGap.spacePhasor_s)
  connect(airGap.flange, inertiaRotor.flange_a)
  connect(damperCage.heatPort, internalThermalPort.heatPortRotorWinding)
end SM_ReluctanceRotor;


within Modelica.Electrical.Machines.BasicMachines;
package Transformers "Library for technical 3phase transformers"
  extends Modelica.Icons.Package;
end Transformers;


Transformer Dd0.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd00 "Transformer Dd0"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd00");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
equation
  connect(r1.plug_p, Delta1.plug_p)
  connect(Delta2.plug_p, r2.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_p2, l2sigma.plug_n)
  connect(core.plug_n3, Delta2.plug_n)
end Dd00;


Transformer Dd2.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd02 "Transformer Dd2"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd02");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
equation
  connect(r1.plug_p, Delta1.plug_p)
  connect(Delta2.plug_n, r2.plug_p)
  connect(l2sigma.plug_n, Rot2.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_p2, Delta2.plug_p)
  connect(core.plug_n3, Rot2.plug_n)
end Dd02;


Transformer Dd4.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd04 "Transformer Dd4"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd04");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
equation
  connect(r1.plug_p, Delta1.plug_p)
  connect(Delta2.plug_n, r2.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_p2, Delta2.plug_p)
  connect(core.plug_n3, l2sigma.plug_n)
end Dd04;


Transformer Dd6.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd06 "Transformer Dd6"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd06");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
equation
  connect(Delta2.plug_p, r2.plug_p)
  connect(Delta1.plug_p, r1.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(Delta2.plug_n, core.plug_p2)
  connect(core.plug_n3, l2sigma.plug_n)
end Dd06;


Transformer Dd8.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd08 "Transformer Dd8"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd08");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
equation
  connect(r1.plug_p, Delta1.plug_p)
  connect(Delta2.plug_n, r2.plug_p)
  connect(Rot2.plug_p, l2sigma.plug_n)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(core.plug_n1, Delta1.plug_n)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_p2, Rot2.plug_n)
  connect(core.plug_n3, Delta2.plug_p)
end Dd08;


Transformer Dd10.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dd;
model Dd10 "Transformer Dd10"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dd10");
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta2(final m=m)
equation
  connect(r1.plug_p, Delta1.plug_p)
  connect(Delta2.plug_n, r2.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_p2, l2sigma.plug_n)
  connect(core.plug_n3, Delta2.plug_p)
end Dd10;


Transformers: primary D / secondary d

within Modelica.Electrical.Machines.BasicMachines.Transformers;
package Dd "Transformers: primary D / secondary d"
  extends Modelica.Icons.VariantsPackage;
end Dd;


Transformer Dy1.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy01 "Transformer Dy1"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy01");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(l2sigma.plug_n, Rot2.plug_p)
  connect(Delta1.plug_p, r1.plug_p)
  connect(Delta1.plug_n, core.plug_n1)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_n3, Rot2.plug_n)
  connect(core.plug_p2, star2.plug_p)
end Dy01;


Transformer Dy3.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy03 "Transformer Dy3"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy03");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(Rot2.plug_n, l2sigma.plug_n)
  connect(Delta1.plug_p, r1.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_p2, Rot2.plug_p)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_n3, star2.plug_p)
end Dy03;


Transformer Dy5.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy05 "Transformer Dy5"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy05");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(Delta1.plug_p, r1.plug_p)
  connect(Delta1.plug_n, core.plug_n1)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(core.plug_n2, core.plug_p3)
  connect(l2sigma.plug_n, core.plug_n3)
  connect(core.plug_p2, star2.plug_p)
end Dy05;


Transformer Dy7.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy07 "Transformer Dy7"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy07");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(r1.plug_p, Delta1.plug_p)
  connect(Rot2.plug_p, l2sigma.plug_n)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_n3, star2.plug_p)
  connect(core.plug_p2, Rot2.plug_n)
end Dy07;


Transformer Dy9.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy09 "Transformer Dy9"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy09");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot2(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(r1.plug_p, Delta1.plug_p)
  connect(l2sigma.plug_n, Rot2.plug_n)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_n3, Rot2.plug_p)
  connect(core.plug_p2, star2.plug_p)
end Dy09;


Transformer Dy11.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dy;
model Dy11 "Transformer Dy11"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dy11");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(r1.plug_p, Delta1.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_n2, core.plug_p3)
  connect(core.plug_n3, star2.plug_p)
  connect(core.plug_p2, l2sigma.plug_n)
end Dy11;


Transformers: primary D / secondary y

within Modelica.Electrical.Machines.BasicMachines.Transformers;
package Dy "Transformers: primary D / secondary y"
  extends Modelica.Icons.VariantsPackage;
end Dy;


Transformer Dz0.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dz;
model Dz00 "Transformer Dz0"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dz00");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Rot21(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot22(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(r1.plug_p, Delta1.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_p2, Rot21.plug_n)
  connect(core.plug_p3, Rot21.plug_p)
  connect(l2sigma.plug_n, Rot22.plug_p)
  connect(Rot22.plug_n, core.plug_n2)
  connect(core.plug_n3, star2.plug_p)
end Dz00;


Transformer Dz2.

within Modelica.Electrical.Machines.BasicMachines.Transformers.Dz;
model Dz02 "Transformer Dz2"
  extends Machines.Interfaces.PartialBasicTransformer(final VectorGroup="Dz02");
  Modelica.Electrical.Polyphase.Basic.Star star2(final m=m)
  Modelica.Electrical.Analog.Interfaces.NegativePin starpoint2
  Modelica.Electrical.Polyphase.Basic.Delta Rot21(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Rot22(final m=m)
  Modelica.Electrical.Polyphase.Basic.Delta Delta1(final m=m)
equation
  connect(star2.pin_n, starpoint2)
  connect(r1.plug_p, Delta1.plug_p)
  connect(l1sigma.plug_n, core.plug_p1)
  connect(Delta1.plug_n, core.plug_n1)
  connect(core.plug_p2, Rot21.plug_p)
  connect(core.plug_p3, Rot21.plug_n)
  connect(l2sigma.plug_n, Rot22.plug_p)
  connect(Rot22.plug_n, core.plug_n2)
  connect(core.plug_n3, star2.plug_p)
end Dz02;