Ticket #4545: MWE.mo

File MWE.mo, 8.9 KB (added by Francesco Casella, 7 years ago)
Line 
1package MWE
2
3 model TaskPool_SatInt
4 parameter Real k[:] = {0.01, 0.02, 0.05} "completion integrator gains";
5 Modelica.Blocks.Interfaces.RealInput c[N] "cores to tasks" annotation(
6 Placement(visible = true, transformation(origin = {-108, -2}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
7 Modelica.Blocks.Interfaces.RealOutput compl01[N](each start = 0, each fixed = true) "completions [0,1]" annotation(
8 Placement(visible = true, transformation(origin = {56, -20}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
9 final parameter Integer N = size(k, 1);
10 equation
11 for i in 1:N loop
12 der(compl01[i]) = if compl01[i] < 0 or compl01[i] > 1 then 0 else k[i] * c[i];
13 end for;
14 annotation(
15 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
16 Icon(graphics = {Rectangle(fillColor = {170, 170, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-2, 0}, extent = {{-66, 74}, {66, -74}}, textString = "Tpool\nSatInt")}));
17 end TaskPool_SatInt;
18
19 model CompletionSPs
20 parameter Real release_times[:]={10,20,30} "task release times";
21 parameter Real relative_deadlines[N]={100,10,50} "task deadlimes relative to release";
22 final parameter Integer N=size(release_times,1);
23 Real sps[N](each start=0.0,each fixed=true);
24 Modelica.Blocks.Interfaces.RealOutput SPs[N] annotation(
25 Placement(visible = true, transformation(origin = {84, -12}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {100, -3.55271e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
26 equation
27 SPs = sps;
28 for i in 1:N loop
29 der(sps[i])=if time>=release_times[i] and time<=release_times[i]+relative_deadlines[i]
30 then 1/relative_deadlines[i]
31 else 0;
32 end for;
33 annotation(
34 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
35 experiment(StartTime = 0, StopTime = 200, Tolerance = 1e-06, Interval = 0.066778),
36 Icon(graphics = {Rectangle(fillColor = {170, 170, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {-7, 0}, extent = {{-61, 56}, {71, -62}}, textString = "Compl\nSPs")}));
37 end CompletionSPs;
38
39 model Controller_eq
40 parameter Integer N=3;
41 parameter Real K=10;
42 Modelica.Blocks.Interfaces.RealInput SP[N] annotation(
43 Placement(visible = true, transformation(origin = {-180, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
44 Modelica.Blocks.Interfaces.RealInput PV[N] annotation(
45 Placement(visible = true, transformation(origin = {-180, -30}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
46 Modelica.Blocks.Interfaces.RealOutput CS[N] annotation(
47 Placement(visible = true, transformation(origin = {180, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {99, -1}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
48 equation
49 CS = K * (SP - PV);
50 annotation(
51 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
52 Icon(graphics = {Rectangle(origin = {1, 0}, fillColor = {170, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {38, -13}, extent = {{-92, 75}, {12, -41}}, textString = "C_eq")}, coordinateSystem(initialScale = 0.1)));
53 end Controller_eq;
54
55 model Controller_alg
56 parameter Integer N=3;
57 parameter Real K=10;
58 parameter Real Ts=0.5;
59 Modelica.Blocks.Interfaces.RealInput SP[N] annotation(
60 Placement(visible = true, transformation(origin = {-180, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
61 Modelica.Blocks.Interfaces.RealInput PV[N] annotation(
62 Placement(visible = true, transformation(origin = {-180, -30}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {-100, -60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
63 Modelica.Blocks.Interfaces.RealOutput CS[N] annotation(
64 Placement(visible = true, transformation(origin = {180, 0}, extent = {{-20, -20}, {20, 20}}, rotation = 0), iconTransformation(origin = {99, -1}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
65 discrete Real cs[N](each start=0.0, each fixed=true);
66 equation
67 CS = cs;
68 algorithm
69 when sample(0, Ts) then
70 cs := K * (SP - PV);
71 end when;
72 annotation(
73 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
74 Icon(graphics = {Rectangle(origin = {1, 0}, fillColor = {170, 255, 127}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Text(origin = {28, -7}, extent = {{-92, 75}, {24, -55}}, textString = "C_alg")}, coordinateSystem(initialScale = 0.1)));
75 end Controller_alg;
76
77
78 model Test_controllers
79 Controller_eq Ceq annotation(
80 Placement(visible = true, transformation(origin = {-10, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
81 Controller_alg Calg annotation(
82 Placement(visible = true, transformation(origin = {-10, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
83 Modelica.Blocks.Sources.RealExpression SP[3](each y=0.0) annotation(
84 Placement(visible = true, transformation(origin = {-110, 36}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
85 Modelica.Blocks.Sources.Trapezoid PV[3](each falling = 2, each nperiod = 1, each period = 8, each rising = 2, each startTime = 1, each width = 2) annotation(
86 Placement(visible = true, transformation(origin = {-110, -16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
87 equation
88 connect(PV.y, Ceq.PV) annotation(
89 Line(points = {{-98, -16}, {-60, -16}, {-60, 24}, {-20, 24}, {-20, 24}}, color = {0, 0, 127}, thickness = 0.5));
90 connect(PV.y, Calg.PV) annotation(
91 Line(points = {{-99, -16}, {-20, -16}}, color = {0, 0, 127}, thickness = 0.5));
92 connect(SP.y, Calg.SP) annotation(
93 Line(points = {{-98, 36}, {-40, 36}, {-40, -4}, {-20, -4}, {-20, -4}}, color = {0, 0, 127}, thickness = 0.5));
94 connect(SP.y, Ceq.SP) annotation(
95 Line(points = {{-98, 36}, {-22, 36}, {-22, 36}, {-20, 36}}, color = {0, 0, 127}, thickness = 0.5));
96 annotation(
97 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
98 experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.00333333));
99 end Test_controllers;
100
101 model Loop_eq
102 MWE.CompletionSPs CSP annotation(
103 Placement(visible = true, transformation(origin = {-70, 16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
104 MWE.TaskPool_SatInt Pool annotation(
105 Placement(visible = true, transformation(origin = {50, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
106 MWE.Controller_eq C annotation(
107 Placement(visible = true, transformation(origin = {-10, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
108 equation
109 connect(Pool.compl01, C.PV) annotation(
110 Line(points = {{60, 10}, {70, 10}, {70, -20}, {-30, -20}, {-30, 4}, {-20, 4}, {-20, 4}}, color = {0, 0, 127}, thickness = 0.5));
111 connect(C.CS, Pool.c) annotation(
112 Line(points = {{0, 10}, {38, 10}, {38, 10}, {40, 10}}, color = {0, 0, 127}, thickness = 0.5));
113 connect(CSP.SPs, C.SP) annotation(
114 Line(points = {{-60, 16}, {-20, 16}}, color = {0, 0, 127}, thickness = 0.5));
115 annotation(
116 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
117 experiment(StartTime = 0, StopTime = 150, Tolerance = 1e-06, Interval = 0.05));
118 end Loop_eq;
119
120 model Loop_alg
121 MWE.CompletionSPs CSP annotation(
122 Placement(visible = true, transformation(origin = {-70, 16}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
123 MWE.TaskPool_SatInt Pool annotation(
124 Placement(visible = true, transformation(origin = {50, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
125 MWE.Controller_alg C annotation(
126 Placement(visible = true, transformation(origin = {-10, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
127 equation
128 connect(Pool.compl01, C.PV) annotation(
129 Line(points = {{60, 10}, {70, 10}, {70, -20}, {-30, -20}, {-30, 4}, {-20, 4}, {-20, 4}}, color = {0, 0, 127}, thickness = 0.5));
130 connect(C.CS, Pool.c) annotation(
131 Line(points = {{0, 10}, {38, 10}, {38, 10}, {40, 10}}, color = {0, 0, 127}, thickness = 0.5));
132 connect(CSP.SPs, C.SP) annotation(
133 Line(points = {{-60, 16}, {-20, 16}}, color = {0, 0, 127}, thickness = 0.5));
134 annotation(
135 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
136 experiment(StartTime = 0, StopTime = 150, Tolerance = 1e-06, Interval = 0.05));
137 end Loop_alg;
138
139
140
141
142
143
144
145 annotation(
146 Diagram(coordinateSystem(extent = {{-200, -100}, {200, 100}})),
147 uses(Modelica(version = "3.2.2")));
148end MWE;