Last active
June 2, 2022 06:47
-
-
Save christiankral/252b8ba32e80e339a9fd35ced6ae3ac2 to your computer and use it in GitHub Desktop.
Fix copy and paste error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LinearSystems | |
model IdealTransformer "Ideal transformer" | |
import Modelica.Constants.pi; | |
import Modelica.Units.SI; | |
import Modelica.Electrical.QuasiStatic; | |
import Modelica.ComplexMath.conj; | |
import Modelica.ComplexMath.fromPolar; | |
parameter SI.Angle phi = 90 * pi / 180 "Angle of reltaive change of side 2 voltage"; | |
Modelica.Blocks.Interfaces.RealInput delta "Magntidue of relative change of side 2 voltage" annotation( | |
Placement(visible = true, transformation(origin = {0, -120}, extent = {{-20, -20}, {20, 20}}, rotation = 90), iconTransformation(origin = {0, -120}, extent = {{-20, -20}, {20, 20}}, rotation = 90))); | |
Complex n = Complex(1,0) + fromPolar(delta, phi) "Ratio of primary to secondary voltage"; | |
SI.ComplexVoltage v1 = pin_p1.v - pin_n1.v "Voltage drop of side 1"; | |
SI.ComplexCurrent i1 = pin_p1.i "Current into side 1"; | |
SI.ComplexVoltage v2 = pin_p2.v - pin_n2.v "Voltage drop of side 2"; | |
SI.ComplexCurrent i2 = pin_p2.i "Current into side 2"; | |
SI.Voltage abs_v1 = Modelica.ComplexMath.abs(v1) "Magnitude of complex voltage v1"; | |
SI.Angle arg_v1 = Modelica.ComplexMath.arg(v1) "Argument of complex voltage v1"; | |
SI.Current abs_i1 = Modelica.ComplexMath.abs(i1) "Magnitude of complex current i1"; | |
SI.Angle arg_i1 = Modelica.ComplexMath.arg(i1) "Argument of complex current i1"; | |
SI.ActivePower P1 = Modelica.ComplexMath.real(v1 * Modelica.ComplexMath.conj(i1)) "Active power, side 1"; | |
SI.ReactivePower Q1 = Modelica.ComplexMath.imag(v1 * Modelica.ComplexMath.conj(i1)) "Reactive power, side 1"; | |
SI.ApparentPower S1 = Modelica.ComplexMath.abs(v1 * Modelica.ComplexMath.conj(i1)) "Magnitude of complex apparent power, side 1"; | |
Real pf1 = cos(Modelica.ComplexMath.arg(Complex(P1, Q1))) "Power factor, side 1"; | |
SI.Voltage abs_v2 = Modelica.ComplexMath.abs(v2) "Magnitude of complex voltage v2"; | |
SI.Angle arg_v2 = Modelica.ComplexMath.arg(v2) "Argument of complex voltage v2"; | |
SI.Current abs_i2 = Modelica.ComplexMath.abs(i2) "Magnitude of complex current i2"; | |
SI.Angle arg_i2 = Modelica.ComplexMath.arg(i2) "Argument of complex current i2"; | |
SI.ActivePower P2 = Modelica.ComplexMath.real(v2 * Modelica.ComplexMath.conj(i2)) "Active power, side 2"; | |
SI.ReactivePower Q2 = Modelica.ComplexMath.imag(v2 * Modelica.ComplexMath.conj(i2)) "Reactive power, side 2"; | |
SI.ApparentPower S2 = Modelica.ComplexMath.abs(v2 * Modelica.ComplexMath.conj(i2)) "Magnitude of complex apparent power, side 2"; | |
Real pf2 = cos(Modelica.ComplexMath.arg(Complex(P2, Q2))) "Power factor, side 2"; | |
QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p1 "Primary positive pin" annotation( | |
Placement(transformation(extent = {{-110, 90}, {-90, 110}}), iconTransformation(extent = {{-110, 90}, {-90, 110}}))); | |
QuasiStatic.SinglePhase.Interfaces.PositivePin pin_p2 "Secondary positive pin" annotation( | |
Placement(transformation(extent = {{90, 90}, {110, 110}}), iconTransformation(extent = {{90, 90}, {110, 110}}))); | |
QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n1 "Primary negative pin" annotation( | |
Placement(transformation(extent = {{-110, -110}, {-90, -90}}), iconTransformation(extent = {{-110, -110}, {-90, -90}}))); | |
QuasiStatic.SinglePhase.Interfaces.NegativePin pin_n2 "Secondary negative pin" annotation( | |
Placement(transformation(extent = {{90, -108}, {110, -88}}), iconTransformation(extent = {{90, -108}, {110, -88}}))); | |
equation | |
// Current balance | |
pin_p1.i + pin_n1.i = Complex(0, 0); | |
pin_p2.i + pin_n2.i = Complex(0, 0); | |
// Transformation ratios | |
v1 = n * v2; | |
i2 = -conj(n) * i1; | |
Connections.branch(pin_p1.reference, pin_n1.reference); | |
pin_p1.reference.gamma = pin_n1.reference.gamma; | |
Connections.branch(pin_n1.reference, pin_n2.reference); | |
pin_p2.reference.gamma = pin_n2.reference.gamma; | |
Connections.branch(pin_p1.reference, pin_p2.reference); | |
pin_p1.reference.gamma = pin_p2.reference.gamma; | |
annotation( | |
defaultComponentName = "transformer", | |
Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Text(lineColor = {0, 0, 255}, extent = {{-100, 10}, {0, -10}}, textString = "1=primary"), Text(lineColor = {0, 0, 255}, extent = {{0, 10}, {100, -10}}, textString = "2=secondary"), Polygon(lineColor = {160, 160, 164}, fillColor = {160, 160, 164}, fillPattern = FillPattern.Solid, points = {{-120, 53}, {-110, 50}, {-120, 47}, {-120, 53}}), Line(points = {{-136, 50}, {-111, 50}}, color = {160, 160, 164}), Text(lineColor = {160, 160, 164}, extent = {{-136, 53}, {-119, 68}}, textString = "i1"), Line(points = {{-136, -49}, {-111, -49}}, color = {160, 160, 164}), Polygon(lineColor = {160, 160, 164}, fillColor = {160, 160, 164}, fillPattern = FillPattern.Solid, points = {{-126, -46}, {-136, -49}, {-126, -52}, {-126, -46}}), Text(lineColor = {160, 160, 164}, extent = {{-127, -46}, {-110, -31}}, textString = "i1"), Polygon(lineColor = {160, 160, 164}, fillColor = {160, 160, 164}, fillPattern = FillPattern.Solid, points = {{127, -47}, {137, -50}, {127, -53}, {127, -47}}), Line(points = {{111, -50}, {136, -50}}, color = {160, 160, 164}), Text(lineColor = {160, 160, 164}, extent = {{112, -44}, {128, -29}}, textString = "i2"), Text(extent = {{118, 52}, {135, 67}}, textString = "i2"), Polygon(fillColor = {160, 160, 164}, fillPattern = FillPattern.HorizontalCylinder, points = {{120, 53}, {110, 50}, {120, 47}, {120, 53}}), Line(points = {{111, 50}, {136, 50}})}), | |
Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Text(lineColor = {85, 170, 255}, extent = {{-100, 20}, {-60, -20}}, textString = "1"), Text(lineColor = {85, 170, 255}, extent = {{60, 20}, {100, -20}}, textString = "2"), Line(points = {{-40, 60}, {-40, 100}, {-90, 100}}, color = {85, 170, 255}), Line(points = {{40, 60}, {40, 100}, {90, 100}}, color = {85, 170, 255}), Line(points = {{-40, -60}, {-40, -100}, {-90, -100}}, color = {85, 170, 255}), Line(points = {{40, -60}, {40, -100}, {90, -100}}, color = {85, 170, 255}), Line(origin = {-33, 45}, rotation = 270, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {-33, 15}, rotation = 270, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {-33, -15}, rotation = 270, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {-33, -45}, rotation = 270, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {33, 45}, rotation = 90, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {33, 15}, rotation = 90, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {33, -15}, rotation = 90, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Line(origin = {33, -45}, rotation = 90, points = {{-15, -7}, {-14, -1}, {-7, 7}, {7, 7}, {14, -1}, {15, -7}}, color = {85, 170, 255}, smooth = Smooth.Bezier), Text(lineColor = {0, 0, 255}, extent = {{-150, 149}, {150, 109}}, textString = "%name")}), | |
Documentation(info = "<html> | |
<p> | |
The ideal transformer is a two-port circuit element without magnetization. Voltages and currents are ideally transformed: | |
</p> | |
<blockquote><pre> | |
v1 = v2*n; | |
i2 = -i1*n; | |
</pre></blockquote> | |
<p> | |
where <code>n</code> is a real number called the turns ratio.</p> | |
</html>", revisions = "<html> | |
<h5>2014-01-02, Christian Kral</h5> | |
<ul> | |
<li>Initial implementation of ideal transformer model</li> | |
</ul> | |
</html>")); | |
end IdealTransformer; | |
model TransformerFlow | |
extends Modelica.Icons.Example; | |
import Modelica.Constants.pi; | |
parameter Modelica.Units.SI.Impedance ZLoad = 1 "Load impedance"; | |
parameter Modelica.Units.SI.Impedance ZLine = 0.1 "Load impedance"; | |
parameter Modelica.Units.SI.Angle phiLoad = 1E-3 * pi / 180 "Load phase angle"; | |
parameter Modelica.Units.SI.Angle phiLine = 90 * pi / 180 "Line phase angle"; | |
parameter Modelica.Units.SI.Angle phi = 1E-3 * pi / 180 "Transformer voltage phase angle"; | |
Modelica.Electrical.QuasiStatic.SinglePhase.Sources.VoltageSource voltageSource(V = 100, f = 50, gamma(displayUnit = "rad"), phi = 0) annotation( | |
Placement(visible = true, transformation(origin = {-80, -10}, extent = {{-10, -10}, {10, 10}}, rotation = -90))); | |
Modelica.Electrical.QuasiStatic.SinglePhase.Basic.Ground ground annotation( | |
Placement(visible = true, transformation(origin = {-80, -50}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
Modelica.Electrical.QuasiStatic.SinglePhase.Basic.Impedance impedance1(Z_ref = Complex(ZLine * cos(phiLine), ZLine * sin(phiLine))) annotation( | |
Placement(visible = true, transformation(origin = {-10, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
Modelica.Electrical.QuasiStatic.SinglePhase.Basic.Impedance impedance1p(Z_ref = Complex(ZLine * cos(phiLine), ZLine * sin(phiLine))) annotation( | |
Placement(visible = true, transformation(origin = {-10, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor1 annotation( | |
Placement(visible = true, transformation(origin = {20, 20}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
Modelica.Electrical.QuasiStatic.SinglePhase.Sensors.PowerSensor powerSensor1p annotation( | |
Placement(visible = true, transformation(origin = {40, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
IdealTransformer transformer(phi (displayUnit = "rad") = 1E-2) annotation( | |
Placement(visible = true, transformation(origin = {-50, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); | |
Modelica.Blocks.Sources.Ramp ramp(duration = 1, height = 0.1) annotation( | |
Placement(visible = true, transformation(origin = {-50, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 90))); | |
equation | |
connect(ground.pin, voltageSource.pin_n) annotation( | |
Line(points = {{-80, -40}, {-80, -20}}, color = {85, 170, 255})); | |
connect(powerSensor1p.currentP, powerSensor1p.voltageP) annotation( | |
Line(points = {{30, 60}, {30, 70}, {40, 70}}, color = {85, 170, 255})); | |
connect(powerSensor1.currentP, powerSensor1.voltageP) annotation( | |
Line(points = {{10, 20}, {10, 30}, {20, 30}}, color = {85, 170, 255})); | |
connect(powerSensor1.voltageN, ground.pin) annotation( | |
Line(points = {{20, 10}, {20, -40}, {-80, -40}}, color = {85, 170, 255})); | |
connect(powerSensor1p.voltageN, ground.pin) annotation( | |
Line(points = {{40, 50}, {40, -40}, {-80, -40}}, color = {85, 170, 255})); | |
connect(impedance1.pin_n, powerSensor1.currentP) annotation( | |
Line(points = {{0, 20}, {10, 20}}, color = {85, 170, 255})); | |
connect(impedance1p.pin_n, powerSensor1p.currentP) annotation( | |
Line(points = {{0, 60}, {30, 60}}, color = {85, 170, 255})); | |
connect(impedance1p.pin_p, voltageSource.pin_p) annotation( | |
Line(points = {{-20, 60}, {-80, 60}, {-80, 0}}, color = {85, 170, 255})); | |
connect(powerSensor1p.currentN, powerSensor1.currentN) annotation( | |
Line(points = {{50, 60}, {60, 60}, {60, 20}, {30, 20}}, color = {85, 170, 255})); | |
connect(transformer.pin_p1, voltageSource.pin_p) annotation( | |
Line(points = {{-60, 0}, {-60, 20}, {-80, 20}, {-80, 0}}, color = {85, 170, 255})); | |
connect(transformer.pin_n1, ground.pin) annotation( | |
Line(points = {{-60, -20}, {-60, -40}, {-80, -40}}, color = {85, 170, 255})); | |
connect(transformer.pin_n2, ground.pin) annotation( | |
Line(points = {{-40, -20}, {-40, -40}, {-80, -40}}, color = {85, 170, 255})); | |
connect(transformer.pin_p2, impedance1.pin_p) annotation( | |
Line(points = {{-40, 0}, {-40, 20}, {-20, 20}}, color = {85, 170, 255})); | |
connect(ramp.y, transformer.delta) annotation( | |
Line(points = {{-50, -58}, {-50, -22}}, color = {0, 0, 127})); | |
end TransformerFlow; | |
extends Modelica.Icons.Package; | |
end LinearSystems; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment