1 | package iPSL "iTesla Power System Library"
|
---|
2 | extends Modelica.Icons.Package;
|
---|
3 |
|
---|
4 | package Electrical
|
---|
5 | package Buses
|
---|
6 | model InfiniteBus2
|
---|
7 | iPSL.Connectors.PwPin p;
|
---|
8 | parameter Real angle "Bus voltage angle (deg)";
|
---|
9 | Modelica.Blocks.Interfaces.RealInput V "Bus voltage magnitude (pu)";
|
---|
10 | equation
|
---|
11 | p.vr = V * cos(angle * Modelica.Constants.pi / 180);
|
---|
12 | p.vi = V * sin(angle * Modelica.Constants.pi / 180);
|
---|
13 | end InfiniteBus2;
|
---|
14 | end Buses;
|
---|
15 |
|
---|
16 | package Branches
|
---|
17 | model PwLine "Model for a transmission Line based on the pi-equivalent circuit"
|
---|
18 | outer iPSL.Electrical.SystemBase SysData;
|
---|
19 | iPSL.Connectors.PwPin p;
|
---|
20 | iPSL.Connectors.PwPin n;
|
---|
21 | parameter Real R "Resistance (pu)";
|
---|
22 | parameter Real X "Reactance (pu)";
|
---|
23 | parameter Real G "Shunt half conductance (pu)";
|
---|
24 | parameter Real B "Shunt half susceptance (pu)";
|
---|
25 | parameter Real S_b = SysData.S_b "System base power (MVA)";
|
---|
26 | parameter Real t1 = Modelica.Constants.inf;
|
---|
27 | parameter Real t2 = Modelica.Constants.inf;
|
---|
28 | parameter Integer opening = 1;
|
---|
29 | parameter Boolean displayPF = false "Enable/Disable";
|
---|
30 | Real P12;
|
---|
31 | Real P21;
|
---|
32 | Real Q12;
|
---|
33 | Real Q21;
|
---|
34 | Complex vs(re = p.vr, im = p.vi);
|
---|
35 | Complex is(re = p.ir, im = p.ii);
|
---|
36 | Complex vr(re = n.vr, im = n.vi);
|
---|
37 | Complex ir(re = n.ir, im = n.ii);
|
---|
38 | protected
|
---|
39 | parameter Complex Y(re = G, im = B);
|
---|
40 | parameter Complex Z(re = R, im = X);
|
---|
41 | equation
|
---|
42 | P12 = .Modelica.ComplexMath.real(vs * .Modelica.ComplexMath.conj(is)) * S_b;
|
---|
43 | P21 = -.Modelica.ComplexMath.real(vr * .Modelica.ComplexMath.conj(ir)) * S_b;
|
---|
44 | Q12 = .Modelica.ComplexMath.imag(vs * .Modelica.ComplexMath.conj(is)) * S_b;
|
---|
45 | Q21 = -.Modelica.ComplexMath.imag(vr * .Modelica.ComplexMath.conj(ir)) * S_b;
|
---|
46 | if time >= t1 and time < t2 then
|
---|
47 | if opening == 1 then
|
---|
48 | is = 0 + .Modelica.ComplexMath.j * 0;
|
---|
49 | ir = 0 + .Modelica.ComplexMath.j * 0;
|
---|
50 | elseif opening == 2 then
|
---|
51 | is = 0 + .Modelica.ComplexMath.j * 0;
|
---|
52 | ir = (vr - ir * Z) * Y;
|
---|
53 | else
|
---|
54 | ir = 0 + .Modelica.ComplexMath.j * 0;
|
---|
55 | is = (vs - is * Z) * Y;
|
---|
56 | end if;
|
---|
57 | else
|
---|
58 | vs - vr = Z * (is - vs * Y);
|
---|
59 | vr - vs = Z * (ir - vr * Y);
|
---|
60 | end if;
|
---|
61 | end PwLine;
|
---|
62 | end Branches;
|
---|
63 |
|
---|
64 | package Machines
|
---|
65 | package Eurostag
|
---|
66 | model PwGeneratorM1S "Synchronous machine model according to Park's classical theory (Full model description).
|
---|
67 | The model corresponds to Eurostag's full model for M1S machine
|
---|
68 | (defined by internal parameters). Developed by RTE and adapted by AIA.
|
---|
69 | 2014/03/10. Update and validate by AIA (Change pin_OMEGA to RealOutput). 2016 "
|
---|
70 | iPSL.Connectors.PwPin sortie;
|
---|
71 | Modelica.Blocks.Interfaces.RealInput pin_EFD;
|
---|
72 | Modelica.Blocks.Interfaces.RealOutput pin_OMEGA;
|
---|
73 | Modelica.Blocks.Interfaces.RealInput pin_CM;
|
---|
74 | Modelica.Blocks.Interfaces.RealInput omegaRef;
|
---|
75 | Real cm(start = init_cm);
|
---|
76 | Real efd(start = init_efd);
|
---|
77 | Real ur;
|
---|
78 | Real ui;
|
---|
79 | Real lambdaf(start = init_lambdaf);
|
---|
80 | Real lambdad(start = init_lambdad);
|
---|
81 | Real lambdaad(start = init_lambdaad);
|
---|
82 | Real lambdaaq(start = init_lambdaaq);
|
---|
83 | Real lambdaq1(start = init_lambdaq1);
|
---|
84 | Real lambdaq2(start = init_lambdaq2);
|
---|
85 | Real id(start = init_id);
|
---|
86 | Real iq(start = init_iq);
|
---|
87 | Real theta(start = init_theta);
|
---|
88 | Real omega(start = init_omega);
|
---|
89 | Real E;
|
---|
90 | Real Mds;
|
---|
91 | Real Mqs;
|
---|
92 | Real Md;
|
---|
93 | Real Mq;
|
---|
94 | Real Mi;
|
---|
95 | Real LMD;
|
---|
96 | Real LMQ;
|
---|
97 | parameter Real init_lambdaf = 0;
|
---|
98 | parameter Real init_lambdad = 0;
|
---|
99 | parameter Real init_lambdaad = 0;
|
---|
100 | parameter Real init_lambdaaq = 0;
|
---|
101 | parameter Real init_lambdaq1 = 0;
|
---|
102 | parameter Real init_lambdaq2 = 0;
|
---|
103 | parameter Real init_id = 0;
|
---|
104 | parameter Real init_iq = 0;
|
---|
105 | parameter Real init_theta = 0;
|
---|
106 | parameter Real init_omega = 1;
|
---|
107 | parameter Real init_cm = 0;
|
---|
108 | parameter Real init_efd = 0;
|
---|
109 | parameter Real omega0 = 2 * 3.14159265 * 50 "Nominal network angular frequency";
|
---|
110 | parameter Real SNREF = 100 "MVA system base";
|
---|
111 | parameter Real SN = 1150 "Nominal apparent power (MVA)";
|
---|
112 | parameter Real PN = 1000 "Nominal turbine (active) power (MW)";
|
---|
113 | parameter Real PNALT = 1100;
|
---|
114 | parameter Real rStatIn = 0.004 "Stator resistance p.u. in the machine SN base";
|
---|
115 | parameter Real lStatIn = 0.219 "Stator leakage p.u. in the machine SN base";
|
---|
116 | parameter Real mD0Pu = 2.351 "d axis mutual inductance p.u. in the machine SN base";
|
---|
117 | parameter Real WLMDVPu = 0.7459 "d axis mutual inductance corresponding to magnetic condition taken for setting the voltage regulator";
|
---|
118 | parameter Real mCanPu = 0.0 "CANAY's inductance p.u. in the machine SN base";
|
---|
119 | parameter Real rDPu = 0.01723 "d axis damper winding resistance p.u. in the machine SN base";
|
---|
120 | parameter Real lDPu = 0.12825 "d axis damper winding leakage p.u. in the machine SN base";
|
---|
121 | parameter Real rRotIn = 0.00113 "Rotor resistance p.u. in the machine SN base";
|
---|
122 | parameter Real lRotIn = 0.24253 "Rotor leakage p.u. in the machine SN base";
|
---|
123 | parameter Real mQ0Pu = 2.351 "q axis mutual inductance p.u. in the machine SN base";
|
---|
124 | parameter Real rQ1Pu = 0.0193 "q axis damper 1 winding resistance p.u. in the machine SN base";
|
---|
125 | parameter Real lQ1Pu = 0.08921 "q axis damper 1 winding leakeage p.u. in the machine SN base";
|
---|
126 | parameter Real rQ2Pu = 0.03923 "q axis damper 2 winding resistance p.u. in the machine SN base";
|
---|
127 | parameter Real lQ2Pu = 1.78484 "q axis damper 2 winding leakeage p.u. in the machine SN base";
|
---|
128 | parameter Real md = 0.1 "Coefficient md of the saturation curve";
|
---|
129 | parameter Real mq = 0.1 "Coefficient mq of the saturation curve";
|
---|
130 | parameter Real snd = 6 "Coefficient nd of the saturation curve";
|
---|
131 | parameter Real snq = 6 "Coefficient nq of the saturation curve";
|
---|
132 | parameter Real DIn = 0.0 "mechanical damping coefficient";
|
---|
133 | parameter Real HIn = 6.3 "Constant of inertia";
|
---|
134 | parameter Real U1N = 24 "nominal voltage machine side";
|
---|
135 | parameter Real V1 = 24 "base voltage machine side";
|
---|
136 | parameter Real U2N = 400 "nominal voltage machine side";
|
---|
137 | parameter Real V2 = 380 "base voltage machine side";
|
---|
138 | parameter Boolean transformerIncluded = false;
|
---|
139 | parameter Real RTfoPu = if transformerIncluded then 0.000185 else 0 "Machine transoformer resistance p.u. in the SNTfo base";
|
---|
140 | parameter Real XTfoPu = if transformerIncluded then 0.00769 else 0 "Machine transoformer resistance p.u. in the SNTfo base";
|
---|
141 | parameter Integer IWLMDV = 3;
|
---|
142 | parameter Boolean Saturated = true;
|
---|
143 | parameter Real yscale = if RT > 0.0 or XT > 0.0 then SNREF / SN * rtfo * rtfo else SNREF / SN;
|
---|
144 | parameter Real SNtfo = 1300 "Machine transformer rating";
|
---|
145 | parameter Real r = rStatIn * yscale "Stator Resistance";
|
---|
146 | parameter Real rf = rRotIn * yscale "Rotor Resistance";
|
---|
147 | parameter Real lld = lStatIn * yscale "Stator leakage";
|
---|
148 | parameter Real lf = lRotIn * yscale "Rotor leakage";
|
---|
149 | parameter Real mrc = mCanPu * yscale "CANAY's inductance";
|
---|
150 | parameter Real lD = lDPu * yscale "d axis damper winding leakage";
|
---|
151 | parameter Real rD = rDPu * yscale "d axis damper winding resistance";
|
---|
152 | parameter Real rQ1 = rQ1Pu * yscale "q axis damper 1 winding resistance";
|
---|
153 | parameter Real rQ2 = rQ2Pu * yscale "q axis damper 2 winding resistance";
|
---|
154 | parameter Real lQ1 = lQ1Pu * yscale "q axis damper 1 winding leakeage";
|
---|
155 | parameter Real lQ2 = lQ2Pu * yscale "q axis damper 2 winding leakeage";
|
---|
156 | parameter Real RT = RTfoPu * SNREF / SNtfo * rtfo * rtfo "Machine transformer resistance (p.u.), enter value*SNREF/SNtfo";
|
---|
157 | parameter Real XT = XTfoPu * SNREF / SNtfo * rtfo * rtfo "Machine transformer reactance (p.u.), enter value*SNREF/SNtfo";
|
---|
158 | parameter Real Md0 = mD0Pu * yscale "d axis mutual inductance";
|
---|
159 | parameter Real Mq0 = mQ0Pu * yscale "q axis mutual inductance";
|
---|
160 | parameter Real Mdv = WLMDVPu * yscale;
|
---|
161 | parameter Real D = DIn * SN / SNREF "Mechanical damping coefficient";
|
---|
162 | parameter Real H = HIn * SN / SNREF "Constant of inertia";
|
---|
163 | parameter Real rtfo = if transformerIncluded then U2N / V2 / (U1N / V1) else 1 "Transformer ratio";
|
---|
164 | parameter Real DET = lf * lD + mrc * lf + mrc * lD;
|
---|
165 | parameter Real Mdif = Md0 - Mq0;
|
---|
166 | parameter Real Sdet = lf / DET + lD / DET;
|
---|
167 | parameter Real Slq = 1.0 / lQ1 + 1.0 / lQ2;
|
---|
168 | parameter Real Lddet = lD / DET;
|
---|
169 | parameter Real Lfdet = lf / DET;
|
---|
170 | parameter Real Lq1inv = 1.0 / lQ1;
|
---|
171 | parameter Real Lq2inv = 1.0 / lQ2;
|
---|
172 | parameter Real Sr = r + RT;
|
---|
173 | parameter Real Sx = lld + XT;
|
---|
174 | parameter Real Coef11 = rtfo * omega0 * rf / Mdv;
|
---|
175 | parameter Real Coef12 = rf * omega0 * (lD + mrc) / DET;
|
---|
176 | parameter Real Coef13 = rf * omega0 * mrc / DET;
|
---|
177 | parameter Real Coef14 = omega0 * rf * lD / DET;
|
---|
178 | parameter Real Coef21 = omega0 * rD * mrc / DET;
|
---|
179 | parameter Real Coef22 = omega0 * rD * (lf + mrc) / DET;
|
---|
180 | parameter Real Coef23 = omega0 * rD * lf / DET;
|
---|
181 | parameter Real Coef31 = omega0 * rQ1 / lQ1;
|
---|
182 | parameter Real Coef32 = omega0 * rQ1 / lQ1;
|
---|
183 | parameter Real Coef41 = omega0 * rQ2 / lQ2;
|
---|
184 | parameter Real Coef42 = omega0 * rQ2 / lQ2;
|
---|
185 | parameter Real Coef51 = PN / (SNREF * 2 * H);
|
---|
186 | parameter Real Coef52 = D / (2 * H);
|
---|
187 | parameter Real Coef53 = 1.0 / (2 * H);
|
---|
188 | Modelica.Blocks.Interfaces.RealOutput pin_TETA;
|
---|
189 | Modelica.Blocks.Interfaces.RealOutput pin_UR;
|
---|
190 | Modelica.Blocks.Interfaces.RealOutput pin_UI;
|
---|
191 | Modelica.Blocks.Interfaces.RealOutput pin_FieldCurrent;
|
---|
192 | Modelica.Blocks.Interfaces.RealOutput pin_TerminalVoltage;
|
---|
193 | Modelica.Blocks.Interfaces.RealOutput pin_ActivePowerPNALT;
|
---|
194 | Modelica.Blocks.Interfaces.RealOutput pin_ActivePowerPN;
|
---|
195 | Modelica.Blocks.Interfaces.RealOutput pin_ActivePowerSNREF;
|
---|
196 | Modelica.Blocks.Interfaces.RealOutput pin_ReactivePowerPNALT;
|
---|
197 | Modelica.Blocks.Interfaces.RealOutput pin_ReactivePowerPN;
|
---|
198 | Modelica.Blocks.Interfaces.RealOutput pin_ReactivePowerSNREF;
|
---|
199 | Modelica.Blocks.Interfaces.RealOutput pin_ActivePowerSN;
|
---|
200 | Modelica.Blocks.Interfaces.RealOutput pin_ReactivePowerSN;
|
---|
201 | Modelica.Blocks.Interfaces.RealOutput pin_Current;
|
---|
202 | Modelica.Blocks.Interfaces.RealOutput pin_FRZPU;
|
---|
203 | Modelica.Blocks.Interfaces.RealOutput pin_FRZHZ;
|
---|
204 | equation
|
---|
205 | der(lambdaf) = (-efd * Coef11) - lambdaf * Coef12 + lambdad * Coef13 + lambdaad * Coef14;
|
---|
206 | der(lambdad) = lambdaf * Coef21 - lambdad * Coef22 + lambdaad * Coef23;
|
---|
207 | der(lambdaq1) = (-lambdaq1 * Coef31) + lambdaaq * Coef32;
|
---|
208 | der(lambdaq2) = (-lambdaq2 * Coef41) + lambdaaq * Coef42;
|
---|
209 | der(omega) = cm * Coef51 + (omegaRef - omega) * Coef52 + lambdaad * iq * Coef53 - lambdaaq * id * Coef53;
|
---|
210 | der(theta) = (omega - omegaRef) * omega0;
|
---|
211 | E = sqrt(lambdaad * lambdaad + lambdaaq * lambdaaq);
|
---|
212 | if Saturated then
|
---|
213 | Mds = Md0 / (1 + md / rtfo ^ snd * E ^ snd);
|
---|
214 | Mqs = Mq0 / (1 + mq / rtfo ^ snq * E ^ snq);
|
---|
215 | else
|
---|
216 | Mds = Md0;
|
---|
217 | Mqs = Mq0;
|
---|
218 | end if;
|
---|
219 | Mi = Mds * lambdaad * lambdaad / (E * E) + Mqs * lambdaaq * lambdaaq / (E * E);
|
---|
220 | Md = Mi + Mdif * lambdaaq * lambdaaq / (E * E);
|
---|
221 | Mq = Mi - Mdif * lambdaad * lambdaad / (E * E);
|
---|
222 | LMD = 1.0 / (1.0 / Md + Sdet);
|
---|
223 | LMQ = 1.0 / (1.0 / Mq + Slq);
|
---|
224 | 0 = (-lambdaad) + LMD * (id + lambdaf * Lddet + lambdad * Lfdet);
|
---|
225 | 0 = (-lambdaaq) + LMQ * (iq + lambdaq1 * Lq1inv + lambdaq2 * Lq2inv);
|
---|
226 | 0 = sin(theta) * ur - cos(theta) * ui + id * Sr - iq * Sx - omega * lambdaaq;
|
---|
227 | 0 = cos(theta) * ur + sin(theta) * ui + iq * Sr + id * Sx + omega * lambdaad;
|
---|
228 | sortie.ir = -(sin(theta) * id + cos(theta) * iq);
|
---|
229 | sortie.ii = -((-cos(theta) * id) + sin(theta) * iq);
|
---|
230 | pin_TETA = theta;
|
---|
231 | pin_OMEGA = omega;
|
---|
232 | pin_CM = cm;
|
---|
233 | pin_EFD = efd;
|
---|
234 | pin_UR = ur;
|
---|
235 | pin_UI = ui;
|
---|
236 | sortie.vr = ur;
|
---|
237 | sortie.vi = ui;
|
---|
238 | pin_TerminalVoltage = sqrt((sortie.vr - RT * sortie.ir + XT * sortie.ii) * (sortie.vr - RT * sortie.ir + XT * sortie.ii) + (sortie.vi - RT * sortie.ii - XT * sortie.ir) * (sortie.vi - RT * sortie.ii - XT * sortie.ir)) * 1 / rtfo;
|
---|
239 | pin_ActivePowerPN = (sortie.vr * (-sortie.ir) + sortie.vi * (-sortie.ii)) * SNREF / PN;
|
---|
240 | if PNALT == 0 then
|
---|
241 | pin_ActivePowerPNALT = 0;
|
---|
242 | else
|
---|
243 | pin_ActivePowerPNALT = (sortie.vr * (-sortie.ir) + sortie.vi * (-sortie.ii)) * SNREF / PNALT;
|
---|
244 | end if;
|
---|
245 | pin_ActivePowerSNREF = sortie.vr * (-sortie.ir) + sortie.vi * (-sortie.ii);
|
---|
246 | pin_ReactivePowerPN = (sortie.vi * (-sortie.ir) - sortie.vr * (-sortie.ii)) * SNREF / PN;
|
---|
247 | if PNALT == 0 then
|
---|
248 | pin_ReactivePowerPNALT = 0;
|
---|
249 | else
|
---|
250 | pin_ReactivePowerPNALT = (sortie.vi * (-sortie.ir) - sortie.vr * (-sortie.ii)) * SNREF / PNALT;
|
---|
251 | end if;
|
---|
252 | pin_ReactivePowerSNREF = sortie.vi * (-sortie.ir) - sortie.vr * (-sortie.ii);
|
---|
253 | pin_ActivePowerSN = (sortie.vr * (-sortie.ir) + sortie.vi * (-sortie.ii)) * SNREF / SN;
|
---|
254 | pin_ReactivePowerSN = (sortie.vi * (-sortie.ir) - sortie.vr * (-sortie.ii)) * SNREF / SN;
|
---|
255 | if md == 0 and mq == 0 and snd == 0 and snq == 0 then
|
---|
256 | pin_FieldCurrent = -Mdv / rtfo * ((Md0 + lD + mrc) * lambdaf - (Md0 + mrc) * lambdad - Md0 * lD * id) / ((Md0 + mrc) * (lf + lD) + lf * lD);
|
---|
257 | else
|
---|
258 | pin_FieldCurrent = -Mdv / rtfo * ((lD + mrc) * lambdaf - mrc * lambdad - lD * lambdaad) / (mrc * (lf + lD) + lf * lD);
|
---|
259 | end if;
|
---|
260 | pin_Current = sqrt(sortie.ir * sortie.ir + sortie.ii * sortie.ii);
|
---|
261 | pin_FRZPU = omegaRef;
|
---|
262 | pin_FRZHZ = omegaRef * omega0;
|
---|
263 | end PwGeneratorM1S;
|
---|
264 | end Eurostag;
|
---|
265 | end Machines;
|
---|
266 |
|
---|
267 | package Controls
|
---|
268 | package Eurostag
|
---|
269 | model GOVER1 "Steam turbine governor. Developed by AIA. 2013"
|
---|
270 | parameter Real init_Integrator;
|
---|
271 | parameter Real init_LeadLag;
|
---|
272 | Modelica.Blocks.Sources.Constant imSetPoint(k = 0);
|
---|
273 | Modelica.Blocks.Continuous.LimIntegrator imLimitedIntegrator(outMin = 0, k = 1, outMax = 1.1, y_start = init_Integrator);
|
---|
274 | Modelica.Blocks.Sources.Constant imSetPoint1(k = 25);
|
---|
275 | iPSL.NonElectrical.Continuous.LeadLag imLeadLag(K = 1, T2 = 10, T1 = 3, y_start = init_LeadLag, x_start = init_LeadLag);
|
---|
276 | Modelica.Blocks.Interfaces.RealInput pin_OMEGA;
|
---|
277 | Modelica.Blocks.Interfaces.RealOutput pin_CM;
|
---|
278 | Modelica.Blocks.Math.Add3 add3_1(k1 = -25, k2 = 1, k3 = 1);
|
---|
279 | equation
|
---|
280 | connect(imSetPoint.y, imLimitedIntegrator.u);
|
---|
281 | connect(imLimitedIntegrator.y, add3_1.u2);
|
---|
282 | connect(add3_1.u1, pin_OMEGA);
|
---|
283 | connect(add3_1.u3, imSetPoint1.y);
|
---|
284 | connect(add3_1.y, imLeadLag.u);
|
---|
285 | connect(imLeadLag.y, pin_CM);
|
---|
286 | end GOVER1;
|
---|
287 | end Eurostag;
|
---|
288 | end Controls;
|
---|
289 |
|
---|
290 | package Events
|
---|
291 | model PwFault "Transitory short-circuit on a node. Shunt impedance connected only during a specified interval of time.
|
---|
292 | Developed by AIA. 2014/12/16"
|
---|
293 | iPSL.Connectors.PwPin p;
|
---|
294 | parameter Real R "Resistance (pu)";
|
---|
295 | parameter Real X "Conductance (pu)";
|
---|
296 | parameter Real t1 "Start time of the fault (s)";
|
---|
297 | parameter Real t2 "End time of the fault (s)";
|
---|
298 | protected
|
---|
299 | parameter Real ground = if R == 0 and X == 0 then 0 else 1;
|
---|
300 | equation
|
---|
301 | if time < t1 then
|
---|
302 | p.ii = 0;
|
---|
303 | p.ir = 0;
|
---|
304 | elseif time < t2 and ground == 0 then
|
---|
305 | p.vr = 1E-10;
|
---|
306 | p.vi = 0;
|
---|
307 | elseif time < t2 then
|
---|
308 | p.ii = (R * p.vi - X * p.vr) / (X * X + R * R);
|
---|
309 | p.ir = (R * p.vr + X * p.vi) / (R * R + X * X);
|
---|
310 | else
|
---|
311 | p.ii = 0;
|
---|
312 | p.ir = 0;
|
---|
313 | end if;
|
---|
314 | end PwFault;
|
---|
315 | end Events;
|
---|
316 |
|
---|
317 | model SystemBase "System Base Definition"
|
---|
318 | parameter Real S_b = 100 "System base in MVA";
|
---|
319 | parameter Real fn = 50 "System Frequency in Hz";
|
---|
320 | annotation(defaultAttributes = "inner", missingInnerMessage = "
|
---|
321 | No 'System Data' component is defined. A default component will be used, and generate a system base of 100 MVA, and a frequency of 50 Hz");
|
---|
322 | end SystemBase;
|
---|
323 | end Electrical;
|
---|
324 |
|
---|
325 | package NonElectrical
|
---|
326 | package Continuous
|
---|
327 | block LeadLag "Lead-Lag filter"
|
---|
328 | extends Modelica.Blocks.Interfaces.SISO;
|
---|
329 | parameter Real K "Gain";
|
---|
330 | parameter Modelica.SIunits.Time T1 "Lead time constant";
|
---|
331 | parameter Modelica.SIunits.Time T2 "Lag time constant";
|
---|
332 | parameter Real y_start "Output start value";
|
---|
333 | parameter Real x_start = y_start / K "Start value of state variable";
|
---|
334 | protected
|
---|
335 | parameter Modelica.SIunits.Time T2_dummy = if abs(T1 - T2) < Modelica.Constants.eps then 1000 else T2 "Lead time constant";
|
---|
336 | public
|
---|
337 | Modelica.Blocks.Sources.RealExpression par1(y = T1);
|
---|
338 | Modelica.Blocks.Sources.RealExpression par2(y = T2);
|
---|
339 | Modelica.Blocks.Continuous.TransferFunction TF(b = {K * T1, K}, a = {T2_dummy, 1}, y_start = y_start, initType = Modelica.Blocks.Types.Init.SteadyState, x_start = {x_start});
|
---|
340 | equation
|
---|
341 | if abs(par1.y - par2.y) < Modelica.Constants.eps then
|
---|
342 | y = K * u;
|
---|
343 | else
|
---|
344 | y = TF.y;
|
---|
345 | end if;
|
---|
346 | connect(TF.u, u);
|
---|
347 | end LeadLag;
|
---|
348 | end Continuous;
|
---|
349 | end NonElectrical;
|
---|
350 |
|
---|
351 | package Connectors
|
---|
352 | connector PwPin "connector for electrical blocks treating voltage and current as complex variables"
|
---|
353 | Real vr;
|
---|
354 | Real vi;
|
---|
355 | flow Real ir;
|
---|
356 | flow Real ii;
|
---|
357 | end PwPin;
|
---|
358 | end Connectors;
|
---|
359 | annotation(version = "0.8.1");
|
---|
360 | end iPSL;
|
---|
361 |
|
---|
362 | package sortEqns
|
---|
363 | model iPSL_A
|
---|
364 | .iPSL.Electrical.Machines.Eurostag.PwGeneratorM1S MS(V2 = 24, U2N = 24, init_theta = 0.21995, init_omega = 1.0, init_efd = 1.0251, init_lambdaad = -0.98054, init_cm = 0.10003, init_lambdaq1 = 0.19950, init_lambdaq2 = 0.19950, init_iq = 0.97585, init_id = 0.21796, init_lambdaaq = 0.19950, init_lambdad = -0.98054, init_lambdaf = -1.0863, WLMDVPu = 2.351, Saturated = false);
|
---|
365 | .iPSL.Electrical.Controls.Eurostag.GOVER1 gover(init_Integrator = 0.10003, init_LeadLag = 0.10003);
|
---|
366 | .iPSL.Electrical.Buses.InfiniteBus2 inf(V = 1, angle = 0, p(vr(start = 1)), p(vi(start = 0)));
|
---|
367 | .iPSL.Electrical.Events.PwFault fault(R = 0.001, X = 0, t1 = 5, t2 = 5.5);
|
---|
368 | .iPSL.Electrical.Branches.PwLine lineinf(R = 0.0001, X = 0, B = 0, G = 0);
|
---|
369 | .iPSL.Electrical.Branches.PwLine line(R = 0.0001, X = 0, B = 0, G = 0);
|
---|
370 | Modelica.Blocks.Interfaces.RealInput omegaRef(start = 1);
|
---|
371 | Modelica.Blocks.Interfaces.RealInput efd(start = 1);
|
---|
372 | equation
|
---|
373 | connect(omegaRef, MS.omegaRef);
|
---|
374 | connect(efd, MS.pin_EFD);
|
---|
375 | connect(gover.pin_CM, MS.pin_CM);
|
---|
376 | connect(gover.pin_OMEGA, MS.pin_OMEGA);
|
---|
377 | connect(inf.p, lineinf.p);
|
---|
378 | connect(lineinf.n, line.p);
|
---|
379 | connect(line.n, MS.sortie);
|
---|
380 | connect(fault.p, line.n);
|
---|
381 | annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.0002));
|
---|
382 | end iPSL_A;
|
---|
383 | end sortEqns;
|
---|
384 |
|
---|
385 | package Modelica "Modelica Standard Library - Version 3.2.2"
|
---|
386 | extends Modelica.Icons.Package;
|
---|
387 |
|
---|
388 | package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)"
|
---|
389 | extends Modelica.Icons.Package;
|
---|
390 |
|
---|
391 | package Continuous "Library of continuous control blocks with internal states"
|
---|
392 | extends Modelica.Icons.Package;
|
---|
393 |
|
---|
394 | block LimIntegrator "Integrator with limited value of the output"
|
---|
395 | parameter Real k(unit = "1") = 1 "Integrator gain";
|
---|
396 | parameter Real outMax(start = 1) "Upper limit of output";
|
---|
397 | parameter Real outMin = -outMax "Lower limit of output";
|
---|
398 | parameter Modelica.Blocks.Types.Init initType = Modelica.Blocks.Types.Init.InitialState "Type of initialization (1: no init, 2: steady state, 3/4: initial output)" annotation(Evaluate = true);
|
---|
399 | parameter Boolean limitsAtInit = true "= false, if limits are ignored during initialization (i.e., der(y)=k*u)" annotation(Evaluate = true);
|
---|
400 | parameter Real y_start = 0 "Initial or guess value of output (must be in the limits outMin .. outMax)";
|
---|
401 | parameter Boolean strict = false "= true, if strict limits with noEvent(..)" annotation(Evaluate = true);
|
---|
402 | extends .Modelica.Blocks.Interfaces.SISO(y(start = y_start));
|
---|
403 | initial equation
|
---|
404 | if initType == .Modelica.Blocks.Types.Init.SteadyState then
|
---|
405 | der(y) = 0;
|
---|
406 | elseif initType == .Modelica.Blocks.Types.Init.InitialState or initType == .Modelica.Blocks.Types.Init.InitialOutput then
|
---|
407 | y = y_start;
|
---|
408 | end if;
|
---|
409 | equation
|
---|
410 | if initial() and not limitsAtInit then
|
---|
411 | der(y) = k * u;
|
---|
412 | assert(y >= outMin - 0.001 * abs(outMax - outMin) and y <= outMax + 0.001 * abs(outMax - outMin), "LimIntegrator: During initialization the limits have been ignored.\n" + "However, the result is that the output y is not within the required limits:\n" + " y = " + String(y) + ", outMin = " + String(outMin) + ", outMax = " + String(outMax));
|
---|
413 | elseif strict then
|
---|
414 | der(y) = noEvent(if y < outMin and k * u < 0 or y > outMax and k * u > 0 then 0 else k * u);
|
---|
415 | else
|
---|
416 | der(y) = if y < outMin and k * u < 0 or y > outMax and k * u > 0 then 0 else k * u;
|
---|
417 | end if;
|
---|
418 | end LimIntegrator;
|
---|
419 |
|
---|
420 | block TransferFunction "Linear transfer function"
|
---|
421 | extends .Modelica.Blocks.Interfaces.SISO;
|
---|
422 | parameter Real[:] b = {1} "Numerator coefficients of transfer function (e.g., 2*s+3 is specified as {2,3})";
|
---|
423 | parameter Real[:] a = {1} "Denominator coefficients of transfer function (e.g., 5*s+6 is specified as {5,6})";
|
---|
424 | parameter Modelica.Blocks.Types.Init initType = Modelica.Blocks.Types.Init.NoInit "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)" annotation(Evaluate = true);
|
---|
425 | parameter Real[size(a, 1) - 1] x_start = zeros(nx) "Initial or guess values of states";
|
---|
426 | parameter Real y_start = 0 "Initial value of output (derivatives of y are zero up to nx-1-th derivative)";
|
---|
427 | output Real[size(a, 1) - 1] x(start = x_start) "State of transfer function from controller canonical form";
|
---|
428 | protected
|
---|
429 | parameter Integer na = size(a, 1) "Size of Denominator of transfer function.";
|
---|
430 | parameter Integer nb = size(b, 1) "Size of Numerator of transfer function.";
|
---|
431 | parameter Integer nx = size(a, 1) - 1;
|
---|
432 | parameter Real[:] bb = vector([zeros(max(0, na - nb), 1); b]);
|
---|
433 | parameter Real d = bb[1] / a[1];
|
---|
434 | parameter Real a_end = if a[end] > 100 * Modelica.Constants.eps * sqrt(a * a) then a[end] else 1.0;
|
---|
435 | Real[size(x, 1)] x_scaled "Scaled vector x";
|
---|
436 | initial equation
|
---|
437 | if initType == .Modelica.Blocks.Types.Init.SteadyState then
|
---|
438 | der(x_scaled) = zeros(nx);
|
---|
439 | elseif initType == .Modelica.Blocks.Types.Init.InitialState then
|
---|
440 | x_scaled = x_start * a_end;
|
---|
441 | elseif initType == .Modelica.Blocks.Types.Init.InitialOutput then
|
---|
442 | y = y_start;
|
---|
443 | der(x_scaled[2:nx]) = zeros(nx - 1);
|
---|
444 | end if;
|
---|
445 | equation
|
---|
446 | assert(size(b, 1) <= size(a, 1), "Transfer function is not proper");
|
---|
447 | if nx == 0 then
|
---|
448 | y = d * u;
|
---|
449 | else
|
---|
450 | der(x_scaled[1]) = ((-a[2:na] * x_scaled) + a_end * u) / a[1];
|
---|
451 | der(x_scaled[2:nx]) = x_scaled[1:nx - 1];
|
---|
452 | y = (bb[2:na] - d * a[2:na]) * x_scaled / a_end + d * u;
|
---|
453 | x = x_scaled / a_end;
|
---|
454 | end if;
|
---|
455 | end TransferFunction;
|
---|
456 | end Continuous;
|
---|
457 |
|
---|
458 | package Interfaces "Library of connectors and partial models for input/output blocks"
|
---|
459 | extends Modelica.Icons.InterfacesPackage;
|
---|
460 | connector RealInput = input Real "'input Real' as connector";
|
---|
461 | connector RealOutput = output Real "'output Real' as connector";
|
---|
462 |
|
---|
463 | partial block SO "Single Output continuous control block"
|
---|
464 | extends Modelica.Blocks.Icons.Block;
|
---|
465 | RealOutput y "Connector of Real output signal";
|
---|
466 | end SO;
|
---|
467 |
|
---|
468 | partial block SISO "Single Input Single Output continuous control block"
|
---|
469 | extends Modelica.Blocks.Icons.Block;
|
---|
470 | RealInput u "Connector of Real input signal";
|
---|
471 | RealOutput y "Connector of Real output signal";
|
---|
472 | end SISO;
|
---|
473 | end Interfaces;
|
---|
474 |
|
---|
475 | package Math "Library of Real mathematical functions as input/output blocks"
|
---|
476 | extends Modelica.Icons.Package;
|
---|
477 |
|
---|
478 | block Add3 "Output the sum of the three inputs"
|
---|
479 | extends Modelica.Blocks.Icons.Block;
|
---|
480 | parameter Real k1 = +1 "Gain of upper input";
|
---|
481 | parameter Real k2 = +1 "Gain of middle input";
|
---|
482 | parameter Real k3 = +1 "Gain of lower input";
|
---|
483 | .Modelica.Blocks.Interfaces.RealInput u1 "Connector 1 of Real input signals";
|
---|
484 | .Modelica.Blocks.Interfaces.RealInput u2 "Connector 2 of Real input signals";
|
---|
485 | .Modelica.Blocks.Interfaces.RealInput u3 "Connector 3 of Real input signals";
|
---|
486 | .Modelica.Blocks.Interfaces.RealOutput y "Connector of Real output signals";
|
---|
487 | equation
|
---|
488 | y = k1 * u1 + k2 * u2 + k3 * u3;
|
---|
489 | end Add3;
|
---|
490 | end Math;
|
---|
491 |
|
---|
492 | package Sources "Library of signal source blocks generating Real and Boolean signals"
|
---|
493 | extends Modelica.Icons.SourcesPackage;
|
---|
494 |
|
---|
495 | block RealExpression "Set output signal to a time varying Real expression"
|
---|
496 | Modelica.Blocks.Interfaces.RealOutput y = 0.0 "Value of Real output";
|
---|
497 | end RealExpression;
|
---|
498 |
|
---|
499 | block Constant "Generate constant signal of type Real"
|
---|
500 | parameter Real k(start = 1) "Constant output value";
|
---|
501 | extends .Modelica.Blocks.Interfaces.SO;
|
---|
502 | equation
|
---|
503 | y = k;
|
---|
504 | end Constant;
|
---|
505 | end Sources;
|
---|
506 |
|
---|
507 | package Types "Library of constants and types with choices, especially to build menus"
|
---|
508 | extends Modelica.Icons.TypesPackage;
|
---|
509 | type Init = enumeration(NoInit "No initialization (start values are used as guess values with fixed=false)", SteadyState "Steady state initialization (derivatives of states are zero)", InitialState "Initialization with initial states", InitialOutput "Initialization with initial outputs (and steady state of the states if possible)") "Enumeration defining initialization of a block" annotation(Evaluate = true);
|
---|
510 | end Types;
|
---|
511 |
|
---|
512 | package Icons "Icons for Blocks"
|
---|
513 | extends Modelica.Icons.IconsPackage;
|
---|
514 |
|
---|
515 | partial block Block "Basic graphical layout of input/output block" end Block;
|
---|
516 | end Icons;
|
---|
517 | end Blocks;
|
---|
518 |
|
---|
519 | package Math "Library of mathematical functions (e.g., sin, cos) and of functions operating on vectors and matrices"
|
---|
520 | extends Modelica.Icons.Package;
|
---|
521 |
|
---|
522 | package Icons "Icons for Math"
|
---|
523 | extends Modelica.Icons.IconsPackage;
|
---|
524 |
|
---|
525 | partial function AxisCenter "Basic icon for mathematical function with y-axis in the center" end AxisCenter;
|
---|
526 | end Icons;
|
---|
527 |
|
---|
528 | function asin "Inverse sine (-1 <= u <= 1)"
|
---|
529 | extends Modelica.Math.Icons.AxisCenter;
|
---|
530 | input Real u;
|
---|
531 | output .Modelica.SIunits.Angle y;
|
---|
532 | external "builtin" y = asin(u);
|
---|
533 | end asin;
|
---|
534 |
|
---|
535 | function exp "Exponential, base e"
|
---|
536 | extends Modelica.Math.Icons.AxisCenter;
|
---|
537 | input Real u;
|
---|
538 | output Real y;
|
---|
539 | external "builtin" y = exp(u);
|
---|
540 | end exp;
|
---|
541 | end Math;
|
---|
542 |
|
---|
543 | package ComplexMath "Library of complex mathematical functions (e.g., sin, cos) and of functions operating on complex vectors and matrices"
|
---|
544 | extends Modelica.Icons.Package;
|
---|
545 | final constant Complex j = Complex(0, 1) "Imaginary unit";
|
---|
546 |
|
---|
547 | function conj "Conjugate of complex number"
|
---|
548 | extends Modelica.Icons.Function;
|
---|
549 | input Complex c1 "Complex number";
|
---|
550 | output Complex c2 "= c1.re - j*c1.im";
|
---|
551 | algorithm
|
---|
552 | c2 := Complex(c1.re, -c1.im);
|
---|
553 | annotation(Inline = true);
|
---|
554 | end conj;
|
---|
555 |
|
---|
556 | function real "Real part of complex number"
|
---|
557 | extends Modelica.Icons.Function;
|
---|
558 | input Complex c "Complex number";
|
---|
559 | output Real r "= c.re";
|
---|
560 | algorithm
|
---|
561 | r := c.re;
|
---|
562 | annotation(Inline = true);
|
---|
563 | end real;
|
---|
564 |
|
---|
565 | function imag "Imaginary part of complex number"
|
---|
566 | extends Modelica.Icons.Function;
|
---|
567 | input Complex c "Complex number";
|
---|
568 | output Real r "= c.im";
|
---|
569 | algorithm
|
---|
570 | r := c.im;
|
---|
571 | annotation(Inline = true);
|
---|
572 | end imag;
|
---|
573 | end ComplexMath;
|
---|
574 |
|
---|
575 | package Constants "Library of mathematical constants and constants of nature (e.g., pi, eps, R, sigma)"
|
---|
576 | extends Modelica.Icons.Package;
|
---|
577 | final constant Real pi = 2 * Math.asin(1.0);
|
---|
578 | final constant Real eps = ModelicaServices.Machine.eps "Biggest number such that 1.0 + eps = 1.0";
|
---|
579 | final constant Real inf = ModelicaServices.Machine.inf "Biggest Real number such that inf and -inf are representable on the machine";
|
---|
580 | final constant .Modelica.SIunits.Velocity c = 299792458 "Speed of light in vacuum";
|
---|
581 | final constant Real mue_0(final unit = "N/A2") = 4 * pi * 1.e-7 "Magnetic constant";
|
---|
582 | end Constants;
|
---|
583 |
|
---|
584 | package Icons "Library of icons"
|
---|
585 | extends Icons.Package;
|
---|
586 |
|
---|
587 | partial package Package "Icon for standard packages" end Package;
|
---|
588 |
|
---|
589 | partial package InterfacesPackage "Icon for packages containing interfaces"
|
---|
590 | extends Modelica.Icons.Package;
|
---|
591 | end InterfacesPackage;
|
---|
592 |
|
---|
593 | partial package SourcesPackage "Icon for packages containing sources"
|
---|
594 | extends Modelica.Icons.Package;
|
---|
595 | end SourcesPackage;
|
---|
596 |
|
---|
597 | partial package TypesPackage "Icon for packages containing type definitions"
|
---|
598 | extends Modelica.Icons.Package;
|
---|
599 | end TypesPackage;
|
---|
600 |
|
---|
601 | partial package IconsPackage "Icon for packages containing icons"
|
---|
602 | extends Modelica.Icons.Package;
|
---|
603 | end IconsPackage;
|
---|
604 |
|
---|
605 | partial function Function "Icon for functions" end Function;
|
---|
606 | end Icons;
|
---|
607 |
|
---|
608 | package SIunits "Library of type and unit definitions based on SI units according to ISO 31-1992"
|
---|
609 | extends Modelica.Icons.Package;
|
---|
610 |
|
---|
611 | package Conversions "Conversion functions to/from non SI units and type definitions of non SI units"
|
---|
612 | extends Modelica.Icons.Package;
|
---|
613 |
|
---|
614 | package NonSIunits "Type definitions of non SI units"
|
---|
615 | extends Modelica.Icons.Package;
|
---|
616 | type Temperature_degC = Real(final quantity = "ThermodynamicTemperature", final unit = "degC") "Absolute temperature in degree Celsius (for relative temperature use SIunits.TemperatureDifference)" annotation(absoluteValue = true);
|
---|
617 | end NonSIunits;
|
---|
618 | end Conversions;
|
---|
619 |
|
---|
620 | type Angle = Real(final quantity = "Angle", final unit = "rad", displayUnit = "deg");
|
---|
621 | type Time = Real(final quantity = "Time", final unit = "s");
|
---|
622 | type Velocity = Real(final quantity = "Velocity", final unit = "m/s");
|
---|
623 | type Acceleration = Real(final quantity = "Acceleration", final unit = "m/s2");
|
---|
624 | type FaradayConstant = Real(final quantity = "FaradayConstant", final unit = "C/mol");
|
---|
625 | end SIunits;
|
---|
626 | annotation(version = "3.2.2", versionBuild = 3, versionDate = "2016-04-03", dateModified = "2016-04-03 08:44:41Z");
|
---|
627 | end Modelica;
|
---|
628 |
|
---|
629 | package ModelicaServices "ModelicaServices (OpenModelica implementation) - Models and functions used in the Modelica Standard Library requiring a tool specific implementation"
|
---|
630 | extends Modelica.Icons.Package;
|
---|
631 |
|
---|
632 | package Machine
|
---|
633 | extends Modelica.Icons.Package;
|
---|
634 | final constant Real eps = 1.e-15 "Biggest number such that 1.0 + eps = 1.0";
|
---|
635 | final constant Real small = 1.e-60 "Smallest number such that small and -small are representable on the machine";
|
---|
636 | final constant Real inf = 1.e+60 "Biggest Real number such that inf and -inf are representable on the machine";
|
---|
637 | final constant Integer Integer_inf = OpenModelica.Internal.Architecture.integerMax() "Biggest Integer number such that Integer_inf and -Integer_inf are representable on the machine";
|
---|
638 | end Machine;
|
---|
639 | annotation(Protection(access = Access.hide), version = "3.2.1", versionBuild = 2, versionDate = "2013-08-14", dateModified = "2013-08-14 08:44:41Z");
|
---|
640 | end ModelicaServices;
|
---|
641 |
|
---|
642 | operator record Complex "Complex number with overloaded operators"
|
---|
643 | replaceable Real re "Real part of complex number";
|
---|
644 | replaceable Real im "Imaginary part of complex number";
|
---|
645 |
|
---|
646 | encapsulated operator 'constructor' "Constructor"
|
---|
647 | function fromReal "Construct Complex from Real"
|
---|
648 | input Real re "Real part of complex number";
|
---|
649 | input Real im = 0 "Imaginary part of complex number";
|
---|
650 | output .Complex result(re = re, im = im) "Complex number";
|
---|
651 | algorithm
|
---|
652 | annotation(Inline = true);
|
---|
653 | end fromReal;
|
---|
654 | end 'constructor';
|
---|
655 |
|
---|
656 | encapsulated operator function '0' "Zero-element of addition (= Complex(0))"
|
---|
657 | output .Complex result "Complex(0)";
|
---|
658 | algorithm
|
---|
659 | result := .Complex(0);
|
---|
660 | annotation(Inline = true);
|
---|
661 | end '0';
|
---|
662 |
|
---|
663 | encapsulated operator '-' "Unary and binary minus"
|
---|
664 | function negate "Unary minus (multiply complex number by -1)"
|
---|
665 | input .Complex c1 "Complex number";
|
---|
666 | output .Complex c2 "= -c1";
|
---|
667 | algorithm
|
---|
668 | c2 := .Complex(-c1.re, -c1.im);
|
---|
669 | annotation(Inline = true);
|
---|
670 | end negate;
|
---|
671 |
|
---|
672 | function subtract "Subtract two complex numbers"
|
---|
673 | input .Complex c1 "Complex number 1";
|
---|
674 | input .Complex c2 "Complex number 2";
|
---|
675 | output .Complex c3 "= c1 - c2";
|
---|
676 | algorithm
|
---|
677 | c3 := .Complex(c1.re - c2.re, c1.im - c2.im);
|
---|
678 | annotation(Inline = true);
|
---|
679 | end subtract;
|
---|
680 | end '-';
|
---|
681 |
|
---|
682 | encapsulated operator '*' "Multiplication"
|
---|
683 | function multiply "Multiply two complex numbers"
|
---|
684 | input .Complex c1 "Complex number 1";
|
---|
685 | input .Complex c2 "Complex number 2";
|
---|
686 | output .Complex c3 "= c1*c2";
|
---|
687 | algorithm
|
---|
688 | c3 := .Complex(c1.re * c2.re - c1.im * c2.im, c1.re * c2.im + c1.im * c2.re);
|
---|
689 | annotation(Inline = true);
|
---|
690 | end multiply;
|
---|
691 |
|
---|
692 | function scalarProduct "Scalar product c1*c2 of two complex vectors"
|
---|
693 | input .Complex[:] c1 "Vector of Complex numbers 1";
|
---|
694 | input .Complex[size(c1, 1)] c2 "Vector of Complex numbers 2";
|
---|
695 | output .Complex c3 "= c1*c2";
|
---|
696 | algorithm
|
---|
697 | c3 := .Complex(0);
|
---|
698 | for i in 1:size(c1, 1) loop
|
---|
699 | c3 := c3 + c1[i] * c2[i];
|
---|
700 | end for;
|
---|
701 | annotation(Inline = true);
|
---|
702 | end scalarProduct;
|
---|
703 | end '*';
|
---|
704 |
|
---|
705 | encapsulated operator function '+' "Add two complex numbers"
|
---|
706 | input .Complex c1 "Complex number 1";
|
---|
707 | input .Complex c2 "Complex number 2";
|
---|
708 | output .Complex c3 "= c1 + c2";
|
---|
709 | algorithm
|
---|
710 | c3 := .Complex(c1.re + c2.re, c1.im + c2.im);
|
---|
711 | annotation(Inline = true);
|
---|
712 | end '+';
|
---|
713 |
|
---|
714 | encapsulated operator function '/' "Divide two complex numbers"
|
---|
715 | input .Complex c1 "Complex number 1";
|
---|
716 | input .Complex c2 "Complex number 2";
|
---|
717 | output .Complex c3 "= c1/c2";
|
---|
718 | algorithm
|
---|
719 | c3 := .Complex(((+c1.re * c2.re) + c1.im * c2.im) / (c2.re * c2.re + c2.im * c2.im), ((-c1.re * c2.im) + c1.im * c2.re) / (c2.re * c2.re + c2.im * c2.im));
|
---|
720 | annotation(Inline = true);
|
---|
721 | end '/';
|
---|
722 |
|
---|
723 | encapsulated operator function '^' "Complex power of complex number"
|
---|
724 | input .Complex c1 "Complex number";
|
---|
725 | input .Complex c2 "Complex exponent";
|
---|
726 | output .Complex c3 "= c1^c2";
|
---|
727 | protected
|
---|
728 | Real lnz = 0.5 * log(c1.re * c1.re + c1.im * c1.im);
|
---|
729 | Real phi = atan2(c1.im, c1.re);
|
---|
730 | Real re = lnz * c2.re - phi * c2.im;
|
---|
731 | Real im = lnz * c2.im + phi * c2.re;
|
---|
732 | algorithm
|
---|
733 | c3 := .Complex(exp(re) * cos(im), exp(re) * sin(im));
|
---|
734 | annotation(Inline = true);
|
---|
735 | end '^';
|
---|
736 |
|
---|
737 | encapsulated operator function '==' "Test whether two complex numbers are identical"
|
---|
738 | input .Complex c1 "Complex number 1";
|
---|
739 | input .Complex c2 "Complex number 2";
|
---|
740 | output Boolean result "c1 == c2";
|
---|
741 | algorithm
|
---|
742 | result := c1.re == c2.re and c1.im == c2.im;
|
---|
743 | annotation(Inline = true);
|
---|
744 | end '==';
|
---|
745 |
|
---|
746 | encapsulated operator function 'String' "Transform Complex number into a String representation"
|
---|
747 | input .Complex c "Complex number to be transformed in a String representation";
|
---|
748 | input String name = "j" "Name of variable representing sqrt(-1) in the string";
|
---|
749 | input Integer significantDigits = 6 "Number of significant digits that are shown";
|
---|
750 | output String s = "";
|
---|
751 | algorithm
|
---|
752 | s := String(c.re, significantDigits = significantDigits);
|
---|
753 | if c.im <> 0 then
|
---|
754 | if c.im > 0 then
|
---|
755 | s := s + " + ";
|
---|
756 | else
|
---|
757 | s := s + " - ";
|
---|
758 | end if;
|
---|
759 | s := s + String(abs(c.im), significantDigits = significantDigits) + "*" + name;
|
---|
760 | else
|
---|
761 | end if;
|
---|
762 | annotation(Inline = true);
|
---|
763 | end 'String';
|
---|
764 | annotation(Protection(access = Access.hide), version = "3.2.1", versionBuild = 2, versionDate = "2013-08-14", dateModified = "2013-08-14 08:44:41Z");
|
---|
765 | end Complex;
|
---|
766 |
|
---|
767 | model iPSL_A_total
|
---|
768 | extends sortEqns.iPSL_A;
|
---|
769 | annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.0002));
|
---|
770 | end iPSL_A_total;
|
---|