root/branches/maintenance/2.2.1/Modelica/Blocks/Routing.mo

Revision 463, 32.1 kB (checked in by hubertus, 22 months ago)

Created maintenance version from Dynasims version with minimal changes (no checksum, 1 graphics, a few improved documentation places, structurallyIncomplete annotations in Visualizers)

Line 
1package Routing "Blocks to combine and extract signals" 
2  extends Icons.Library;
3 
4block ExtractSignal "Extract signals from an input signal vector" 
5  extends Modelica.Blocks.Interfaces.MIMO;
6  parameter Integer extract[nout]=1:nout "Extracting vector";
7  annotation (
8    Coordsys(
9      extent=[-100, -100; 100, 100],
10      grid=[1, 1],
11      component=[20, 20]),
12    Window(
13      x=0.28,
14      y=0.29,
15      width=0.57,
16      height=0.61),
17    Icon(
18      Rectangle(extent=[-100, 100; 100, -100]),
19      Rectangle(extent=[-90, 50; -50, -50], style(fillColor=7)),
20      Rectangle(extent=[50, 50; 90, -50], style(fillColor=7)),
21      Polygon(points=[-94.4104, 1.90792; -94.4104, -2.09208; -90.4104, -
22            0.0920762; -94.4104, 1.90792], style(fillColor=73)),
23      Line(points=[-72, 2; -60.1395, 12.907; -49.1395, 12.907]),
24      Line(points=[-73, 4; -59, 40; -49, 40]),
25      Line(points=[-112, 0; -75.0373, -0.0180176]),
26      Ellipse(extent=[-80.0437, 4.59255; -70.0437, -4.90745], style(fillColor=
27             73)),
28      Line(points=[-73, -5; -60, -40; -49, -40]),
29      Line(points=[-72, -2; -60.0698, -12.907; -49.0698, -12.907]),
30      Polygon(points=[-48.8808, -11; -48.8808, -15; -44.8808, -13; -48.8808,
31            -11], style(fillColor=7)),
32      Line(points=[-46, 13; -35, 13; 35, -30; 45, -30]),
33      Line(points=[-45, 40; -35, 40; 35, 0; 44, 0]),
34      Line(points=[-45, -40; -34, -40; 35, 30; 44, 30]),
35      Polygon(points=[-49, 42; -49, 38; -45, 40; -49, 42], style(fillColor=7)),
36      Polygon(points=[-48.8728, -38.0295; -48.8728, -42.0295; -44.8728, -
37            40.0295; -48.8728, -38.0295], style(fillColor=7)),
38      Polygon(points=[-48.9983, 14.8801; -48.9983, 10.8801; -44.9983, 12.8801;
39              -48.9983, 14.8801], style(fillColor=7)),
40      Ellipse(extent=[70.3052, 4.12743; 80.3052, -5.37257], style(fillColor=
41              73)),
42      Line(points=[80, 0; 100, 0]),
43      Polygon(points=[44.1618, 32.3085; 44.1618, 28.3085; 48.1618, 30.3085;
44            44.1618, 32.3085], style(fillColor=73)),
45      Polygon(points=[44.2575, 1.80443; 44.2575, -2.19557; 48.2575, -0.195573;
46              44.2575, 1.80443], style(fillColor=73)),
47      Polygon(points=[44.8805, -28.1745; 44.8805, -32.1745; 48.8805, -30.1745;
48              44.8805, -28.1745], style(fillColor=73)),
49      Line(points=[48, 0; 70, 0]),
50      Line(points=[47, 30; 60, 30; 73, 3]),
51      Line(points=[49, -30; 60, -30; 74, -4]),
52      Text(
53        extent=[-150, -150; 150, -110],
54        string="extract=%extract",
55        style(color=0))),
56    Diagram(
57      Rectangle(extent=[-90, 50; -50, -50], style(color=73, fillColor=7)),
58      Rectangle(extent=[50, 50; 90, -50], style(color=73, fillColor=7)),
59      Polygon(points=[-94.4104, 1.90792; -94.4104, -2.09208; -90.4104, -
60            0.0920762; -94.4104, 1.90792], style(color=73, fillColor=0)),
61      Line(points=[-72, 2; -60.1395, 12.907; -49.1395, 12.907], style(color=
62              73)),
63      Line(points=[-73, 4; -59, 40; -49, 40], style(color=73)),
64      Line(points=[-112, 0; -75.0373, -0.0180176], style(color=73)),
65      Ellipse(extent=[-80.0437, 4.59255; -70.0437, -4.90745], style(color=73,
66              fillColor=73)),
67      Line(points=[-73, -5; -60, -40; -49, -40], style(color=73)),
68      Line(points=[-72, -2; -60.0698, -12.907; -49.0698, -12.907], style(
69            color=73)),
70      Polygon(points=[-48.8808, -11; -48.8808, -15; -44.8808, -13; -48.8808,
71            -11], style(color=73, fillColor=7)),
72      Line(points=[-46, 13; -35, 13; 35, -30; 45, -30], style(color=73)),
73      Line(points=[-45, 40; -35, 40; 35, 0; 44, 0], style(color=73)),
74      Line(points=[-45, -40; -34, -40; 35, 30; 44, 30], style(color=73)),
75      Polygon(points=[-49, 42; -49, 38; -45, 40; -49, 42], style(color=73,
76            fillColor=7)),
77      Polygon(points=[-48.8728, -38.0295; -48.8728, -42.0295; -44.8728, -
78            40.0295; -48.8728, -38.0295], style(color=73, fillColor=7)),
79      Polygon(points=[-48.9983, 14.8801; -48.9983, 10.8801; -44.9983, 12.8801;
80              -48.9983, 14.8801], style(color=73, fillColor=7)),
81      Ellipse(extent=[70.3052, 4.12743; 80.3052, -5.37257], style(color=73,
82            fillColor=73)),
83      Line(points=[80, 0; 105, 0], style(color=73)),
84      Polygon(points=[44.1618, 32.3085; 44.1618, 28.3085; 48.1618, 30.3085;
85            44.1618, 32.3085], style(color=73, fillColor=73)),
86      Polygon(points=[44.2575, 1.80443; 44.2575, -2.19557; 48.2575, -0.195573;
87              44.2575, 1.80443], style(color=73, fillColor=73)),
88      Polygon(points=[44.8805, -28.1745; 44.8805, -32.1745; 48.8805, -30.1745;
89              44.8805, -28.1745], style(color=73, fillColor=73)),
90      Line(points=[48, 0; 70, 0], style(color=73)),
91      Line(points=[47, 30; 60, 30; 73, 3], style(color=73)),
92      Line(points=[49, -30; 60, -30; 74, -4], style(color=73)),
93      Rectangle(extent=[-100, 80; 100, -81])),
94    Documentation(info="<HTML>
95<p>Extract signals from the input connector and transfer them
96to the output connector.</p>
97<p>The extracting scheme is given by the integer vector 'extract'.
98This vector specifies, which input signals are taken and in which
99order they are transfered to the output vector. Note, that the
100dimension of 'extract' has to match the number of outputs.
101Additionally, the dimensions of the input connector signals and
102the output connector signals have to be explicitly defined via the
103parameters 'nin' and 'nout'.</p>
104<p>Example:</p>
105<pre>     nin = 7 \"Number of inputs\";
106     nout = 4 \"Number of outputs\";
107     extract[nout] = {6,3,3,2} \"Extracting vector\";
108</pre>
109<p>extracts four output signals (nout=4) from the seven elements of the
110input vector (nin=7):</p>
111<pre>   output no. 1 is set equal to input no. 6
112   output no. 2 is set equal to input no. 3
113   output no. 3 is set equal to input no. 3
114   output no. 4 is set equal to input no. 2
115</pre>
116</HTML>
117"));
118equation 
119   
120  for i in 1:nout loop
121    y[i] = u[extract[i]];
122     
123  end for;
124end ExtractSignal;
125 
126block Extractor
127    "Extract scalar signal out of signal vector dependent on IntegerRealInput index" 
128   
129  extends Modelica.Blocks.Interfaces.MISO;
130   
131  parameter Boolean allowOutOfRange=false "Index may be out of range";
132  parameter Real outOfRangeValue=1e10 "Output signal if index is out of range";
133   
134  annotation (Icon(
135      Rectangle(extent=[-80, 50; -40, -50], style(color=73, fillColor=7)),
136      Polygon(points=[-84.4104, 1.9079; -84.4104, -2.09208; -80.4104, -
137            0.09208; -84.4104, 1.9079], style(color=73, fillColor=0)),
138      Line(points=[-62, 2; -50.1395, 12.907; -39.1395, 12.907], style(color=
139              73)),
140      Line(points=[-63, 4; -49, 40; -39, 40], style(color=73)),
141      Line(points=[-102, 0; -65.0373, -0.01802], style(color=73)),
142      Ellipse(extent=[-70.0437, 4.5925; -60.0437, -4.90745], style(color=73,
143            fillColor=73)),
144      Line(points=[-63, -5; -50, -40; -39, -40], style(color=73)),
145      Line(points=[-62, -2; -50.0698, -12.907; -39.0698, -12.907], style(
146            color=73)),
147      Polygon(points=[-38.8808, -11; -38.8808, -15; -34.8808, -13; -38.8808,
148            -11], style(color=73, fillColor=7)),
149      Polygon(points=[-39, 42; -39, 38; -35, 40; -39, 42], style(color=73,
150            fillColor=7)),
151      Polygon(points=[-38.8728, -38.0295; -38.8728, -42.0295; -34.8728, -
152            40.0295; -38.8728, -38.0295], style(color=73, fillColor=7)),
153      Polygon(points=[-38.9983, 14.8801; -38.9983, 10.8801; -34.9983, 12.8801;
154              -38.9983, 14.8801], style(color=73, fillColor=7)),
155      Rectangle(extent=[-30, 50; 30, -50], style(fillColor=30, fillPattern=1)),
156      Line(points=[100, 0; 0, 0], style(
157          color=77,
158          fillColor=58,
159          fillPattern=1)),
160      Line(points=[0,2; 0,-104], style(
161            color=45,
162            rgbcolor={255,128,0},
163            fillColor=58,
164            rgbfillColor={0,191,0},
165            fillPattern=1)),
166      Line(points=[-35, 40; -20, 40], style(
167          color=77,
168          fillColor=58,
169          fillPattern=1)),
170      Line(points=[-35, 13; -20, 13], style(
171          color=77,
172          fillColor=58,
173          fillPattern=1)),
174      Line(points=[-35, -13; -20, -13], style(
175          color=77,
176          fillColor=58,
177          fillPattern=1)),
178      Line(points=[-35, -40; -20, -40], style(
179          color=77,
180          fillColor=58,
181          fillPattern=1)),
182      Polygon(points=[0, 0; -18, 13; -20, 13; -2, 0; 0, 0], style(color=77,
183            fillPattern=1)),
184      Ellipse(extent=[-6, 6; 6, -6], style(
185            color=45,
186            rgbcolor={255,128,0},
187            fillColor=45,
188            rgbfillColor={255,128,0},
189            fillPattern=1))),
190                            Documentation(info="<html>
191<p>This block extracts a scalar output signal out the
192vector of input signals dependent on the Integer
193value of the additional u index:</p>
194<pre>    y = u [ index ] ;
195</pre>
196<p>where index is an additional Integer input signal.</p>
197</html>"));
198  Modelica.Blocks.Interfaces.IntegerInput index             annotation (
199      extent=[-20, -140; 20, -100], rotation=90);
200  protected 
201  Real k[nin];
202equation 
203   
204  when {initial(),change(index)} then
205     
206    for i in 1:nin loop
207      k[i] = if index == i then 1 else 0;
208       
209    end for;
210     
211  end when;
212   
213  y = if not allowOutOfRange or index > 0 and index <= nin then 
214              k*u else outOfRangeValue;
215end Extractor;
216 
217  block Multiplex2 "Multiplexer block for two input connectors" 
218    extends Modelica.Blocks.Interfaces.BlockIcon;
219    parameter Integer n1=1 "dimension of input signal connector 1";
220    parameter Integer n2=1 "dimension of input signal connector 2";
221    Modelica.Blocks.Interfaces.RealInput u1[n1] 
222      "Connector of Real input signals 1" annotation (extent=[-140, 40; -100,
223          80]);
224    Modelica.Blocks.Interfaces.RealInput u2[n2] 
225      "Connector of Real input signals 2" annotation (extent=[-140, -80; -100,
226          -40]);
227    Modelica.Blocks.Interfaces.RealOutput y[n1 + n2] 
228      "Connector of Real output signals" annotation (extent=[100, -10; 120, 10]);
229    annotation (
230      Coordsys(
231        extent=[-100, -100; 100, 100],
232        grid=[2, 2],
233        component=[20, 20]),
234      Window(
235        x=0.2,
236        y=0.34,
237        width=0.56,
238        height=0.6),
239      Documentation(info="<HTML>
240<p>
241The output connector is the <b>concatenation</b> of the two input connectors.
242Note, that the dimensions of the input connector signals have to be
243explicitly defined via parameters n1 and n2.
244</p>
245</HTML>
246"),   Icon(
247        Line(points=[8, 0; 102, 0]),
248        Ellipse(extent=[-14, 16; 16, -14], style(fillColor=73)),
249        Line(points=[-98, 60; -60, 60; -4, 6]),
250        Line(points=[-98, -60; -60, -60; -4, -4])),
251      Diagram(
252        Line(points=[-98, 60; -60, 60; -4, 6]),
253        Line(points=[-98, -60; -60, -60; -4, -4]),
254        Line(points=[8, 0; 102, 0]),
255        Ellipse(extent=[-14, 16; 16, -14], style(fillColor=73))));
256  equation 
257    [y] = [u1; u2];
258  end Multiplex2;
259 
260  block Multiplex3 "Multiplexer block for three input connectors" 
261    extends Modelica.Blocks.Interfaces.BlockIcon;
262    parameter Integer n1=1 "dimension of input signal connector 1";
263    parameter Integer n2=1 "dimension of input signal connector 2";
264    parameter Integer n3=1 "dimension of input signal connector 3";
265    Modelica.Blocks.Interfaces.RealInput u1[n1] 
266      "Connector of Real input signals 1" annotation (extent=[-140, 50; -100,
267          90]);
268    Modelica.Blocks.Interfaces.RealInput u2[n2] 
269      "Connector of Real input signals 2" annotation (extent=[-140, -20; -100,
270          20]);
271    Modelica.Blocks.Interfaces.RealInput u3[n3] 
272      "Connector of Real input signals 3" annotation (extent=[-140, -90; -100,
273          -50]);
274    Modelica.Blocks.Interfaces.RealOutput y[n1 + n2 + n3] 
275      "Connector of Real output signals" annotation (extent=[100, -10; 120, 10]);
276    annotation (
277      Coordsys(
278        extent=[-100, -100; 100, 100],
279        grid=[2, 2],
280        component=[20, 20]),
281      Window(
282        x=0.23,
283        y=0.03,
284        width=0.56,
285        height=0.6),
286      Documentation(info="<HTML>
287<p>
288The output connector is the <b>concatenation</b> of the three input connectors.
289Note, that the dimensions of the input connector signals have to be
290explicitly defined via parameters n1, n2 and n3.
291</HTML>
292"),   Icon(
293        Line(points=[8, 0; 102, 0]),
294        Line(points=[-100, 70; -60, 70; -4, 6]),
295        Line(points=[-100, 0; -12, 0]),
296        Line(points=[-100, -70; -62, -70; -4, -4]),
297        Ellipse(extent=[-14, 16; 16, -14], style(fillColor=73))),
298      Diagram(
299        Line(points=[-100, 70; -60, 70; -4, 6]),
300        Line(points=[-100, -70; -62, -70; -4, -4]),
301        Line(points=[8, 0; 102, 0]),
302        Ellipse(extent=[-14, 16; 16, -14], style(fillColor=73)),
303        Line(points=[-100, 0; -12, 0])));
304  equation 
305    [y] = [u1; u2; u3];
306  end Multiplex3;
307 
308  block Multiplex4 "Multiplexer block for four input connectors" 
309    extends Modelica.Blocks.Interfaces.BlockIcon;
310    parameter Integer n1=1 "dimension of input signal connector 1";
311    parameter Integer n2=1 "dimension of input signal connector 2";
312    parameter Integer n3=1 "dimension of input signal connector 3";
313    parameter Integer n4=1 "dimension of input signal connector 4";
314    Modelica.Blocks.Interfaces.RealInput u1[n1] 
315      "Connector of Real input signals 1" annotation (extent=[-140, 70; -100,
316          110]);
317    Modelica.Blocks.Interfaces.RealInput u2[n2] 
318      "Connector of Real input signals 2" annotation (extent=[-140, 10; -100,
319          50]);
320    Modelica.Blocks.Interfaces.RealInput u3[n3] 
321      "Connector of Real input signals 3" annotation (extent=[-140, -50; -100,
322          -10]);
323    Modelica.Blocks.Interfaces.RealInput u4[n4] 
324      "Connector of Real input signals 4" annotation (extent=[-140, -110; -100,
325            -70]);
326    Modelica.Blocks.Interfaces.RealOutput y[n1 + n2 + n3 + n4] 
327      "Connector of Real output signals" annotation (extent=[100, -10; 120, 10]);
328    annotation (
329      Coordsys(
330        extent=[-100, -100; 100, 100],
331        grid=[1, 1],
332        component=[20, 20]),
333      Window(
334        x=0.33,
335        y=0.1,
336        width=0.59,
337        height=0.67),
338      Documentation(info="<HTML>
339<p>
340The output connector is the <b>concatenation</b> of the four input connectors.
341Note, that the dimensions of the input connector signals have to be
342explicitly defined via parameters n1, n2, n3 and n4.
343</p>
344</HTML>
345"),   Icon(
346        Line(points=[8, 0; 102, 0]),
347        Line(points=[-100, 90; -60, 90; -3, 4]),
348        Line(points=[-100, 30; -60, 30; -9, 0]),
349        Line(points=[-99, -30; -59, -30; -10, -5]),
350        Line(points=[-100, -90; -60, -90; -5, -6]),
351        Ellipse(extent=[-15, 15; 15, -15], style(fillColor=73))),
352      Diagram(
353        Line(points=[-100, 90; -60, 90; -3, 4]),
354        Line(points=[-100, -90; -60, -90; -5, -6]),
355        Line(points=[8, 0; 102, 0]),
356        Ellipse(extent=[-15, 15; 15, -15], style(fillColor=73)),
357        Line(points=[-100, 30; -60, 30; -9, 0]),
358        Line(points=[-99, -30; -59, -30; -10, -5])));
359  equation 
360    [y] = [u1; u2; u3; u4];
361  end Multiplex4;
362 
363  block Multiplex5 "Multiplexer block for five input connectors" 
364    extends Modelica.Blocks.Interfaces.BlockIcon;
365    parameter Integer n1=1 "dimension of input signal connector 1";
366    parameter Integer n2=1 "dimension of input signal connector 2";
367    parameter Integer n3=1 "dimension of input signal connector 3";
368    parameter Integer n4=1 "dimension of input signal connector 4";
369    parameter Integer n5=1 "dimension of input signal connector 5";
370    Modelica.Blocks.Interfaces.RealInput u1[n1] 
371      "Connector of Real input signals 1" annotation (extent=[-140, 80; -100,
372          120]);
373    Modelica.Blocks.Interfaces.RealInput u2[n2] 
374      "Connector of Real input signals 2" annotation (extent=[-140, 30; -100,
375          70]);
376    Modelica.Blocks.Interfaces.RealInput u3[n3] 
377      "Connector of Real input signals 3" annotation (extent=[-140, -20; -100,
378          20]);
379    Modelica.Blocks.Interfaces.RealInput u4[n4] 
380      "Connector of Real input signals 4" annotation (extent=[-140, -70; -100,
381          -30]);
382    Modelica.Blocks.Interfaces.RealInput u5[n5] 
383      "Connector of Real input signals 5" annotation (extent=[-140, -120; -100,
384            -80]);
385    Modelica.Blocks.Interfaces.RealOutput y[n1 + n2 + n3 + n4 + n5] 
386      "Connector of Real output signals" annotation (extent=[100, -10; 120, 10]);
387    annotation (
388      Coordsys(
389        extent=[-100, -100; 100, 100],
390        grid=[1, 1],
391        component=[20, 20]),
392      Window(
393        x=0.26,
394        y=0.12,
395        width=0.59,
396        height=0.68),
397      Documentation(info="<HTML>
398<p>
399The output connector is the <b>concatenation</b> of the five input connectors.
400Note, that the dimensions of the input connector signals have to be
401explicitly defined via parameters n1, n2, n3, n4 and n5.
402</p>
403</HTML>
404"),   Icon(
405        Line(points=[8, 0; 102, 0]),
406        Line(points=[-100, 100; -60, 100; -4, 6]),
407        Line(points=[-99, 50; -60, 50; -8, 5]),
408        Line(points=[-100, 0; -7, 0]),
409        Line(points=[-99, -50; -60, -50; -9, -6]),
410        Line(points=[-100, -100; -60, -100; -4, -4]),
411        Ellipse(extent=[-15, 15; 15, -15], style(fillColor=73))),
412      Diagram(
413        Line(points=[-100, 100; -60, 100; -4, 6]),
414        Line(points=[-100, -100; -60, -100; -4, -4]),
415        Line(points=[8, 0; 102, 0]),
416        Ellipse(extent=[-15, 15; 15, -15], style(fillColor=73)),
417        Line(points=[-99, 50; -60, 50; -8, 5]),
418        Line(points=[-100, 0; -7, 0]),
419        Line(points=[-99, -50; -60, -50; -9, -6])));
420  equation 
421    [y] = [u1; u2; u3; u4; u5];
422  end Multiplex5;
423 
424  block Multiplex6 "Multiplexer block for six input connectors" 
425    extends Modelica.Blocks.Interfaces.BlockIcon;
426    parameter Integer n1