Ticket #5260: temp2.mo

File temp2.mo, 12.1 KB (added by J-Ph Tavella <jean-philippe.tavella@…>, 6 years ago)
Line 
1package temp
2 package Basic "TelSysPro Basic Components"
3 package Operators "low level operators"
4 model RealTransmission
5 // Parameters
6 parameter Integer samplingPeriod[nR] = zeros(nR) "sampling period (ms)";
7 parameter Integer nR "number of Reals to transmit";
8 parameter Real maxDelay = 1000 "maxDelay value required for OM";
9 // Connectors
10 Modelica.Blocks.Interfaces.RealOutput y[nR] annotation(
11 Placement(transformation(extent = {{100, -10}, {120, 10}})));
12 Modelica.Blocks.Interfaces.RealInput u[nR] annotation(
13 Placement(transformation(extent = {{-140, -20}, {-100, 20}})));
14 Interfaces.ToReceive u_UL annotation(
15 Placement(transformation(extent = {{-10, -120}, {10, -100}}), iconTransformation(extent = {{-10, -120}, {10, -100}})));
16 // Local variables
17 //discrete Real ud1[nR](start=u) annotation(HideResult = true);
18 //Real ud2[nR](start=u) annotation(HideResult = true);
19 discrete Real ud1[nR] annotation(HideResult = true);
20 Real ud2[nR] annotation(HideResult = true);
21 // to initialize with a variable
22
23initial equation
24 ud1 = u;
25 ud2 = u;
26
27 equation
28 if cardinality(u_UL) == 0 then
29 u_UL.latency = 20;
30 u_UL.isWorking = true;
31 end if;
32 for i in 1:nR loop
33 if samplingPeriod[i] == 0 then
34 when u_UL.isWorking == false then
35 ud1[i] = pre(u[i]);
36 end when;
37 ud2[i] = if u_UL.isWorking then u[i] else ud1[i];
38 else
39 when sample(0, samplingPeriod[i] / 1000) then
40 ud1[i] = u[i];
41 ud2[i] = if u_UL.isWorking then ud1[i] else pre(ud2[i]);
42 end when;
43 end if;
44//y[i] = if u_UL.latency == 0 then ud2[i] else delay(ud2[i], u_UL.latency / 1000);
45 y[i] = if u_UL.latency == 0 then ud2[i] else delay(ud2[i], u_UL.latency / 1000, maxDelay);
46 end for;
47
48 annotation(
49 Icon(coordinateSystem(preserveAspectRatio = false)),
50 Diagram(coordinateSystem(preserveAspectRatio = false)));
51 end RealTransmission;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 end Operators;
75
76 package Tests "unitary tests for basic Components"
77 model TestRealTransmission
78 Basic.Operators.RealTransmission realTransmission(nR = 6, samplingPeriod = {10, 10, 10, 10, 10, 10}) annotation(
79 Placement(transformation(extent = {{-4, -10}, {34, 8}})));
80 Modelica.Blocks.Sources.Sine sine(freqHz = 2, phase = 0.78539816339745) annotation(
81 Placement(transformation(extent = {{-54, 2}, {-34, 22}})));
82 Modelica.Blocks.Sources.Constant const(k = 1.5) annotation(
83 Placement(transformation(extent = {{-88, 48}, {-68, 68}})));
84 Modelica.Blocks.Sources.Ramp ramp(duration = 4) annotation(
85 Placement(transformation(extent = {{-54, 32}, {-34, 52}})));
86 Modelica.Blocks.Sources.Exponentials exponentials(riseTime = 3, startTime = 1, offset = 0.5) annotation(
87 Placement(transformation(extent = {{-54, -30}, {-34, -10}})));
88 Modelica.Blocks.Sources.Pulse pulse(period = 1, offset = 0.2) annotation(
89 Placement(transformation(extent = {{-54, -60}, {-34, -40}})));
90 Modelica.Blocks.Sources.Trapezoid trapezoid(period = 1.5) annotation(
91 Placement(transformation(extent = {{-54, -92}, {-34, -72}})));
92 equation
93 connect(const.y, realTransmission.u[1]) annotation(
94 Line(points = {{-67, 58}, {-20, 58}, {-20, -2.5}, {-7.8, -2.5}}, color = {0, 0, 127}));
95 connect(ramp.y, realTransmission.u[2]) annotation(
96 Line(points = {{-33, 42}, {-20, 42}, {-20, -1.9}, {-7.8, -1.9}}, color = {0, 0, 127}));
97 connect(sine.y, realTransmission.u[3]) annotation(
98 Line(points = {{-33, 12}, {-20, 12}, {-20, -1.3}, {-7.8, -1.3}}, color = {0, 0, 127}));
99 connect(exponentials.y, realTransmission.u[4]) annotation(
100 Line(points = {{-33, -20}, {-20, -20}, {-20, -0.7}, {-7.8, -0.7}}, color = {0, 0, 127}));
101 connect(pulse.y, realTransmission.u[5]) annotation(
102 Line(points = {{-33, -50}, {-20, -50}, {-20, -0.1}, {-7.8, -0.1}}, color = {0, 0, 127}));
103 connect(trapezoid.y, realTransmission.u[6]) annotation(
104 Line(points = {{-33, -82}, {-20, -82}, {-20, 0.5}, {-7.8, 0.5}}, color = {0, 0, 127}));
105 annotation(
106 Icon(coordinateSystem(preserveAspectRatio = false)),
107 Diagram(coordinateSystem(preserveAspectRatio = false), graphics = {Text(extent = {{-60, 92}, {26, 64}}, lineColor = {0, 0, 0}, fontSize = 16, horizontalAlignment = TextAlignment.Left, textString = "Validate transmission of reals with respect to their initial value:
108- default latency is 20 ms (default value when no network is connected)
109- try no discretization (parameter samplingPeriod={0} in realTransmission)
110and then with a sampling period (e.g. parameter samplingPeriod={10})
111
112Recommended time interval is [0, 6]"), Text(extent = {{-14, -72}, {72, -100}}, lineColor = {0, 0, 0}, fontSize = 16, horizontalAlignment = TextAlignment.Left, textString = "Expected results:
113- no difference between const.y and realTransmission.y[1]
114- correct shifting between ramp.y and realTransmission.y[2]
115- correct shifting between sin.y and realTransmission.y[3]
116- correct shifting between exponentials.y and realTransmission.y[4]
117- correct shifting between pulse.y and realTransmission.y[5]
118- correct shifting between trapezoid.y and realTransmission.y[6]
119
120- with discretization, the output signals are piecewise constant
121
122
123
124
125
126
127
128
129
130
131
132
133 ")}));
134 end TestRealTransmission;
135
136 end Tests;
137 annotation(
138 Icon(graphics = {Rectangle(lineColor = {200, 200, 200}, fillColor = {248, 248, 248}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-100.0, -100.0}, {100.0, 100.0}}, radius = 25.0), Rectangle(lineColor = {128, 128, 128}, extent = {{-100.0, -100.0}, {100.0, 100.0}}, radius = 25.0), Rectangle(origin = {0.0, 35.1488}, fillColor = {255, 255, 255}, extent = {{-30.0, -20.1488}, {30.0, 20.1488}}), Rectangle(origin = {0.0, -34.8512}, fillColor = {255, 255, 255}, extent = {{-30.0, -20.1488}, {30.0, 20.1488}}), Line(origin = {-51.25, 0.0}, points = {{21.25, -35.0}, {-13.75, -35.0}, {-13.75, 35.0}, {6.25, 35.0}}), Polygon(origin = {-40.0, 35.0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{10.0, 0.0}, {-5.0, 5.0}, {-5.0, -5.0}}), Line(origin = {51.25, 0.0}, points = {{-21.25, 35.0}, {13.75, 35.0}, {13.75, -35.0}, {-6.25, -35.0}}), Polygon(origin = {40.0, -35.0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-10.0, 0.0}, {5.0, 5.0}, {5.0, -5.0}})}),
139 Documentation(info = "<html>
140 <p><span style=\"font-family: MS Shell Dlg 2;\">This package contains basic TelSysPro components.</span></p>
141 </html>"),
142 Diagram(graphics = {Text(extent = {{116, 34}, {-114, 10}}, lineColor = {0, 0, 0}, fontSize = 17, textStyle = {TextStyle.Bold}, textString = "TelSysPro Basic Components")}));
143 end Basic;
144
145 package Interfaces "TelSysPro Interfaces"
146 connector ToReceive = input Types.TelCoVars "System variables as input" annotation(
147 Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {135, 135, 135}, fillPattern = FillPattern.Forward)}),
148 Diagram(graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {135, 135, 135}, fillPattern = FillPattern.Forward)}));
149 connector ToSend = output Types.TelCoVars "System variables as output" annotation(
150 Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {135, 135, 135}, fillPattern = FillPattern.Forward)}),
151 Diagram(graphics = {Rectangle(extent = {{-100, 100}, {100, -100}}, lineColor = {0, 0, 0}, fillColor = {135, 135, 135}, fillPattern = FillPattern.Forward)}));
152 annotation(
153 Icon(graphics = {Rectangle(lineColor = {200, 200, 200}, fillColor = {248, 248, 248}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-100, -100}, {100, 100}}, radius = 25.0), Rectangle(lineColor = {128, 128, 128}, fillPattern = FillPattern.None, extent = {{-100, -100}, {100, 100}}, radius = 25.0), Polygon(origin = {20, 0}, lineColor = {64, 64, 64}, fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, points = {{-10.0, 70.0}, {10.0, 70.0}, {40.0, 20.0}, {80.0, 20.0}, {80.0, -20.0}, {40.0, -20.0}, {10.0, -70.0}, {-10.0, -70.0}}), Polygon(fillColor = {102, 102, 102}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-100, 20}, {-60, 20}, {-30, 70}, {-10, 70}, {-10, -70}, {-30, -70}, {-60, -20}, {-100, -20}})}),
154 Documentation(info = "<html>
155 <p><span style=\"font-family: MS Shell Dlg 2;\">This package contains the input and output connectors required by TelSysPro.</span></p>
156 <p>Each connector is composed with two system variables:</p>
157<ul>
158<li>Boolean 'isWorking' as Operating Mode</li>
159<li>Integer 'latency' as Latency</li>
160</ul>
161</html>"),
162 Diagram(graphics = {Text(extent = {{116, 34}, {-114, 10}}, lineColor = {0, 0, 0}, fontSize = 18, textStyle = {TextStyle.Bold}, textString = "TelSysPro Interfaces")}));
163 end Interfaces;
164
165 package Types "TelSysPro Types"
166 record TelCoVars "System Variables to exchange"
167 Boolean isWorking "Current operationg mode";
168 Integer latency "Cuurent latency";
169 annotation(
170 Documentation(info = "<html>
171
172</html>"));
173 end TelCoVars;
174 annotation(
175 Icon(graphics = {Rectangle(lineColor = {200, 200, 200}, fillColor = {248, 248, 248}, fillPattern = FillPattern.HorizontalCylinder, extent = {{-100, -100}, {100, 100}}, radius = 25.0), Rectangle(lineColor = {128, 128, 128}, extent = {{-100, -100}, {100, 100}}, radius = 25, lineThickness = 0.5), Polygon(origin = {-12.167, -23}, fillColor = {0, 0, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{12.167, 65}, {14.167, 93}, {36.167, 89}, {24.167, 20}, {4.167, -30}, {14.167, -30}, {24.167, -30}, {24.167, -40}, {-5.833, -50}, {-15.833, -30}, {4.167, 20}, {12.167, 65}}, smooth = Smooth.Bezier, lineColor = {0, 0, 0}), Polygon(origin = {2.7403, 1.6673}, fillColor = {0, 0, 0}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{49.2597, 22.3327}, {31.2597, 24.3327}, {7.2597, 18.3327}, {-26.7403, 10.3327}, {-46.7403, 14.3327}, {-48.7403, 6.3327}, {-32.7403, 0.3327}, {-6.7403, 4.3327}, {33.2597, 14.3327}, {49.2597, 14.3327}, {49.2597, 22.3327}}, smooth = Smooth.Bezier, lineColor = {0, 0, 0})}),
176 Documentation(info = "<html>
177 <p><span style=\"font-family: MS Shell Dlg 2;\">This package defines the type to declare system varizbles.</span></p>
178 <p>This type is a record composed with two parts:</p>
179<ul>
180<li>a Boolean</li>
181<li>an Integer</li>
182</ul></html>"),
183 Diagram(graphics = {Text(extent = {{116, 34}, {-114, 10}}, lineColor = {0, 0, 0}, fontSize = 18, textStyle = {TextStyle.Bold}, textString = "TelSysPro Types")}));
184 end Types;
185 annotation(
186 uses(Modelica(version = "3.2.2"), ThermoSysPro(version = "3.3")),
187 Diagram(coordinateSystem(initialScale = 0.1)),
188 Icon(graphics = {Rectangle(lineColor = {128, 128, 128}, extent = {{-100.0, -100.0}, {100.0, 100.0}}, radius = 25, lineThickness = 0.5), Text(extent = {{-120, -26}, {126, 30}}, lineColor = {128, 128, 128}, lineThickness = 0.5, textString = "TSP", fontName = "Century Gothic", textStyle = {TextStyle.Bold, TextStyle.Italic})}),
189 Documentation(info = "<html>
190<p><b><span style=\"font-family: MS Shell Dlg 2;\">TelSysPro</span></b> is a Modelica library able to model telecommunication networks. This library is being developped and maintained by J.Ph. Tavella and A. Jardin at EDF R&amp;D Saclay Lab in the frame of the project SIMSE (2016-19). </p>
191<p><b><span style=\"font-family: MS Shell Dlg 2;\">Copyright &copy; 2017-18, EDF</span></b> </p>
192</html>"),
193 version = "2");
194end temp;