model StateSelector "Transform instantaneous values to space phasors and select states"
import Modelica.Constants.pi;
parameter Integer m(min = 3) = 3 "Number of phases";
input Real xi[m](each stateSelect = StateSelect.avoid) "Instantaneous values"
annotation (Dialog);
input Modelica.SIunits.Angle gamma "Angle of rotation"
annotation (Dialog);
parameter StateSelect x0StateSelect = StateSelect.prefer "Priority to use zero systems as states";
parameter StateSelect xrStateSelect = StateSelect.prefer "Priority to use space phasors w.r.t. rotating frame as states";
Real x0(stateSelect = x0StateSelect) = sqrt(m) ^ (-1) * sum(xi) "Zero system";
Real x00(stateSelect = x0StateSelect) = sqrt(m) ^ (-1) * sum({xi[2 * l - 1] - xi[2 * l] for l in 1:integer(0.5 * m)}) if m == 2 * integer(0.5 * m) "Second zero system, if present (mp even)";
final parameter Integer np = integer(0.5 * (m - 1)) "Number of space phasors";
Complex xf[np](each re(stateSelect = StateSelect.avoid), each im(stateSelect = StateSelect.avoid)) "Space phasors w.r.t. fixed frame";
Complex xr[np](each re(stateSelect = xrStateSelect), each im(stateSelect = xrStateSelect)) "Space phasors w.r.t. rotating frame";
equation
for k in 1:np loop
xf[k].re = sqrt(m) ^ (-1) * sum({cos(k * (l - 1) * 2 * pi / m) * xi[l] for l in 1:m});
xf[k].im = sqrt(m) ^ (-1) * sum({sin(k * (l - 1) * 2 * pi / m) * xi[l] for l in 1:m});
xr[k] = xf[k] * Modelica.ComplexMath.conj(Modelica.ComplexMath.exp(Complex(0, gamma)));
end for;
annotation (
Documentation(info = "<html>\n<p>\nTransforms instantaneous values into space phasors and zero system currents,\nrotates space phasors and sets stateSelect modifiers in order to choose states w.r.t. rotating frame,\ni.e., with small derivatives.\n</p>\n</html>"),
Icon(
coordinateSystem(
preserveAspectRatio = false,
extent = {
{-100, -100},
{100, 100}}),
graphics = {
Ellipse(
extent = {
{-60, 60},
{60, -60}},
lineColor = {170, 213, 255},
fillColor = {170, 213, 255},
fillPattern = FillPattern.Solid),
Text(
extent = {
{-60, 60},
{60, -60}},
textString = "S",
lineColor = {0, 0, 255}),
Text(
extent = {
{0, -60},
{0, -100}},
lineColor = {0, 0, 255},
textString = "%name")}));
end StateSelector;