TerminalBox

model TerminalBox "Terminal box Y/D-connection"
    parameter Integer m(min = 1) = 3 "Number of phases";
    parameter String terminalConnection(start = "Y") "Choose Y=star/D=delta"
        annotation (choices(
            choice = "Y" "Star connection",
            choice = "D" "Delta connection"));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug plug_sp(final m = m) "To positive stator plug"
        annotation (Placement(
            transformation(extent = {
                {50, -50}, 
                {70, -70}}),
            iconTransformation(extent = {
                {50, -50}, 
                {70, -70}})));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.NegativePlug plug_sn(final m = m) "To negative stator plug"
        annotation (Placement(
            transformation(extent = {
                {-70, -50}, 
                {-50, -70}}),
            iconTransformation(extent = {
                {-70, -50}, 
                {-50, -70}})));
    Electrical.QuasiStationary.MultiPhase.Basic.Star star(final m = m) if terminalConnection <> "D" annotation (Placement(transformation(
        origin = {-70, -80},
        extent = {
            {-10, 10}, 
            {10, -10}},
        rotation = 180)));
    Electrical.QuasiStationary.MultiPhase.Basic.Delta delta(final m = m) if terminalConnection == "D" annotation (Placement(transformation(extent = {
        {-20, -70}, 
        {-40, -50}})));
    Modelica.Electrical.QuasiStationary.MultiPhase.Interfaces.PositivePlug plugSupply(final m = m) "To grid"
        annotation (Placement(
            transformation(extent = {
                {-10, -30}, 
                {10, -50}}),
            iconTransformation(extent = {
                {-10, -30}, 
                {10, -50}})));
    Electrical.QuasiStationary.SinglePhase.Interfaces.NegativePin starpoint if terminalConnection <> "D" annotation (Placement(
        transformation(extent = {
            {-110, -50}, 
            {-90, -30}}),
        iconTransformation(extent = {
            {-110, -50}, 
            {-90, -30}})));
equation
    connect(plugSupply,plug_sp) annotation (Line(
        points = {
            {0, -40}, 
            {0, -60}, 
            {60, -60}},
        color = {85, 170, 255}));
    connect(delta.plug_n,plug_sn) annotation (Line(
        points = {
            {-40, -60}, 
            {-40, -60}, 
            {-60, -60}},
        color = {85, 170, 255}));
    connect(delta.plug_p,plug_sp) annotation (Line(
        points = {
            {-20, -60}, 
            {60, -60}, 
            {60, -60}},
        color = {85, 170, 255}));
    connect(star.pin_n,starpoint) annotation (Line(
        points = {
            {-80, -80}, 
            {-86, -80}, 
            {-86, -40}, 
            {-100, -40}},
        color = {85, 170, 255}));
    connect(star.plug_p,plug_sn) annotation (Line(
        points = {
            {-60, -80}, 
            {-60, -60}},
        color = {85, 170, 255}));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = false,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {-40, -50}, 
                        {40, -90}},
                    textString = "%terminalConnection"), 
                Polygon(
                    points = {
                        {-80, -40}, 
                        {-80, -44}, 
                        {-80, -80}, 
                        {-40, -100}, 
                        {40, -100}, 
                        {80, -70}, 
                        {80, -44}, 
                        {76, -40}, 
                        {-80, -40}},
                    lineColor = {95, 95, 95},
                    fillColor = {135, 135, 135},
                    fillPattern = FillPattern.Solid)}),
        Documentation(info = "<html>\nTerminalBox: at the bottom connected to both machine plugs, connect at the top to the grid as usual,<br>\nchoosing Y-connection (StarDelta=Y) or D-connection (StarDelta=D).\n</html>"));
end TerminalBox;