/
Math.mo
243 lines (219 loc) · 7.52 KB
/
Math.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
within PowerSystems.Blocks;
package Math "Auxiliary blocks"
extends Modelica.Icons.VariantsPackage;
block Integrator "Integral of input-signal"
extends Partials.SISO(y(start=y_ini, fixed=true));
parameter Real y_ini=0 "initial value";
equation
der(y) = u;
annotation (
Documentation(info="<html>
<p/>Calculates:
<pre> y_ini + Integral dt u</pre>
</html>
"), Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={
Text(
extent={{-70,40},{90,-40}},
lineColor={128,128,128},
textString=
"dt u"),
Line(
points={{-61,31},{-59,41},{-55,45},{-49,47}},
color={135,135,135},
thickness=0.5),
Line(
points={{-61,-31},{-63,-41},{-67,-45},{-73,-47}},
color={135,135,135},
thickness=0.5),
Line(
points={{-61,31},{-61,-31}},
color={135,135,135},
thickness=0.5)}));
end Integrator;
block TimeAverage "Time average of input signal"
extends Partials.MIMO(final nin=n, final nout=n);
parameter Integer n=1 "dim of input/output signal";
parameter SI.Time tcst(min=Modelica.Constants.eps)=1 "memory time constant";
initial equation
y = u;
equation
der(y) = (u - y)/tcst;
annotation (defaultComponentName = "time_av",
Documentation(
info="<html>
<p>Calculates the time-average of the input-signal u with exponential memory function (first order transfer function with initial condition).</p>
<p>This block does NOT need the delay operator. It may be replaced by something more specific in context with inverters/modulation.</p>
</html>
"), Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-80,40},{80,-40}},
lineColor={128,128,128},
textString=
"(...)"), Text(
extent={{-80,80},{80,40}},
lineColor={128,128,128},
textString=
"_____")}));
end TimeAverage;
block TimeAvInterval "Time average over interval of input signal"
extends Partials.MIMO(final nin=n, final nout=n);
parameter Integer n=1 "dim of input/output signal";
parameter SI.Time tcst(min=1e-9)=1 "average time";
protected
Real[n] U(start=zeros(n), fixed=true, each stateSelect=StateSelect.always);
equation
der(U) = u;
y = (U - delay(U, tcst))/tcst;
annotation (defaultComponentName = "time_avI",
Documentation(
info="<html>
<p>Calculates the time-average of the input-signal u over the interval {time - tau, time}.</p>
<p>This block needs the delay operator!</p>
</html>
"), Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-80,80},{80,40}},
lineColor={128,128,128},
textString=
"_____"), Text(
extent={{-80,40},{80,-40}},
lineColor={128,128,128},
textString=
"[...]")}));
end TimeAvInterval;
block ComponentAverage "Component average of input signal"
extends Partials.MISO;
algorithm
y := sum(u)/n;
annotation (defaultComponentName = "average",
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-80,40},{80,-40}},
lineColor={128,128,128},
textString=
"av(..)")}),
Documentation(
info="<html>
<p>Calculates the average over the components of the input-signal u.</p>
</html>"));
end ComponentAverage;
block Norm "Norm of input signal"
extends Partials.MISO(n=3);
parameter Integer n_eval(
min=2,
max=3) = 2 "dim of evaluated input signal u[1:n_eval]";
equation
y = sqrt(u[1:n_eval]*u[1:n_eval]);
annotation (defaultComponentName = "norm",
Documentation(
info="<html>
<p>Allows in particular to calculate the dq0-norm (n_eval=3) or dq-norm (n_eval=2) of the input signal.</p>
</html>
"), Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-80,40},{80,-40}},
lineColor={128,128,128},
textString=
"|u|")}));
end Norm;
block ToPolar "Rotation of input signal-vector"
extends Partials.MIMO(final nin=2, final nout=2);
parameter Integer sig(min=-1, max=1)=1 "+u or -u as input"
annotation(Evaluate=true);
protected
function atan2=Modelica.Math.atan2;
equation
y[1] = sqrt(u*u);
y[2] = atan2(sig*u[2], sig*u[1]);
annotation (defaultComponentName = "toPolar",
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-70,36},{80,-44}},
lineColor={128,128,128},
textString=
"polar >")}),
Documentation(info="<html>
<p>Converts Euclidean {u[1], u[2]} to polar {y[1], y[2]} coordinates, where
<pre>
y[1] absolute value
y[2] argument, phase
</pre></p>
<p>The phase <tt>y[2]</tt> is continuous in the interval
<pre> -pi < phi < = +pi</pre></p>
</html>"));
end ToPolar;
block ToPolarR "Rotation of input signal-vector"
extends Partials.MIMO(final nin=2, final nout=2);
parameter Integer sig(min=-1, max=1)=1 "+u or -u as input"
annotation(Evaluate=true);
protected
SI.Angle alpha(stateSelect=StateSelect.always);
SI.AngularVelocity omega;
function atan2=Modelica.Math.atan2;
function atanV=Basic.Math.atanVarCut;
function angVelocity=Basic.Math.angVelocity;
initial equation
alpha = atan2(sig*u[2], sig*u[1]); // leads to troubles with GNU-compiler.
equation
omega = angVelocity(u, der(u));
der(alpha) = omega;
y[1] = sqrt(u*u);
y[2] = atanV(sig*u, alpha);
annotation (defaultComponentName = "toPolar",
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-70,36},{80,-44}},
lineColor={255,85,85},
textString=
"polar >")}),
Documentation(info="<html>
<p>Converts Euclidean {u[1], u[2]} to polar {y[1], y[2]} coordinates, where
<pre>
y[1] absolute value
y[2] argument, phase
</pre></p>
<p>The phase <tt>y[2]</tt> is continuous on the whole real axis
<pre> -inf < phi < +inf</pre></p>
</html>"));
end ToPolarR;
block FromPolar "Rotation of input signal-vector"
extends Partials.MIMO(final nin=2, final nout=2);
equation
y = u[1]*{cos(u[2]), sin(u[2])};
annotation (defaultComponentName = "fromPolar",
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}},
grid={2,2}), graphics={Text(
extent={{-80,36},{70,-44}},
lineColor={128,128,128},
textString=
"< polar")}),
Documentation(info="<html>
<p>Converts polar {u[1], u[2]} to Euclidean {y[1], y[2]} coordinates, where
<pre>
u[1] absolute value
u[2] argument, phase
</pre></p>
</html>
"));
end FromPolar;
annotation (preferredView="info",
Documentation(info="<html>
</html>"));
end Math;