Ticket #4979: InputOptIssues.mo

File InputOptIssues.mo, 5.6 KB (added by massimo ceraolo, 6 years ago)
Line 
1package InputOptIssues
2 model Trapezoid "Dynamical Optimization of Ideal Drive"
3 parameter Real p = 1 "required for optimization";
4 parameter Real powLim = 9000;
5 Real power = torque * angSpeed;
6 //
7 /*** Optimization requests ***/
8 input Real torque(min = -90, max = 90);
9 Real targetPhi(nominal = 1) = -torque2.flange.phi "minimize -pos(tf)" annotation(
10 isMayer = true);
11 Real angSpeed(min = 0, max = 0) = p * der(torque2.flange.phi) annotation(
12 isFinalConstraint = true);
13 Real pow(min = -powLim, max = powLim) = power annotation(
14 isConstraint = true);
15 /*** end of Optimization requests ***/
16 //
17 Real constPhi(nominal = 100) = -torque2.flange.phi "minimize -phi(tf)" annotation(
18 isLagrange = true);
19 Modelica.Blocks.Sources.RealExpression realexp(y = torque) annotation(
20 Placement(visible = true, transformation(origin = {0, -34}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
21 Modelica.Mechanics.Rotational.Components.Inertia inertia1 annotation(
22 Placement(visible = true, transformation(origin = {-10, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
23 Modelica.Mechanics.Rotational.Sources.Torque torque1 annotation(
24 Placement(visible = true, transformation(origin = {-48, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
25 Modelica.Blocks.Sources.Trapezoid trapezoid1(amplitude = 10, falling = 1, period = 5, rising = 1, startTime = 1, width = 1) annotation(
26 Placement(visible = true, transformation(origin = {58, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
27 Modelica.Mechanics.Rotational.Sources.Torque torque2 annotation(
28 Placement(visible = true, transformation(origin = {24, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
29 equation
30 connect(trapezoid1.y, torque2.tau) annotation(
31 Line(points = {{47, 0}, {42, 0}, {42, -2}, {37, -2}}, color = {0, 0, 127}));
32 connect(torque1.flange, inertia1.flange_a) annotation(
33 Line(points = {{-38, 0}, {-18, 0}}));
34 connect(inertia1.flange_b, torque2.flange) annotation(
35 Line(points = {{2, 0}, {14, 0}}));
36 connect(realexp.y, torque1.tau) annotation(
37 Line(points = {{-9, -34}, {-70, -34}, {-70, 0}, {-60, 0}}, color = {0, 0, 127}));
38 annotation(
39 Diagram(coordinateSystem(extent = {{-80, -60}, {80, 40}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2})),
40 Icon(coordinateSystem(extent = {{-80, -60}, {80, 40}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2})),
41 experiment(StartTime = 0, StopTime = 8, Tolerance = 1e-07, Interval = 0.16),
42 __OpenModelica_commandLineOptions = "+gDynOpt",
43 __OpenModelica_simulationFlags(optimizerNP = "1", s = "optimization"));
44 end Trapezoid;
45
46 model TimeTable "Dynamical Optimization of Ideal Drive"
47 parameter Real p = 1 "required for optimization";
48 parameter Real powLim = 9000;
49 Real power = torque * angSpeed;
50 //
51 /*** Optimization requests ***/
52 input Real torque(min = -90, max = 90);
53 Real targetPhi(nominal = 1) = -torque2.flange.phi "minimize -pos(tf)" annotation(
54 isMayer = true);
55 Real angSpeed(min = 0, max = 0) = p * der(torque2.flange.phi) annotation(
56 isFinalConstraint = true);
57 Real pow(min = -powLim, max = powLim) = power annotation(
58 isConstraint = true);
59 /*** end of Optimization requests ***/
60 //
61 Real constPhi(nominal = 100) = -torque2.flange.phi "minimize -phi(tf)" annotation(
62 isLagrange = true);
63 Modelica.Blocks.Sources.RealExpression realexp(y = torque) annotation(
64 Placement(visible = true, transformation(origin = {0, -34}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
65 Modelica.Mechanics.Rotational.Components.Inertia inertia1 annotation(
66 Placement(visible = true, transformation(origin = {-10, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
67 Modelica.Mechanics.Rotational.Sources.Torque torque1 annotation(
68 Placement(visible = true, transformation(origin = {-48, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
69 Modelica.Mechanics.Rotational.Sources.Torque torque2 annotation(
70 Placement(visible = true, transformation(origin = {24, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
71 Modelica.Blocks.Sources.TimeTable timeTable1(table = [
72 0, 0; 1, 0;
73 2,10; 3, 10;
74 4, 0; 5, 0;
75 6,10; 7,10;
76 8,0; 9,0]
77 ) annotation(
78 Placement(visible = true, transformation(origin = {64, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
79 equation
80 connect(timeTable1.y, torque2.tau) annotation(
81 Line(points = {{52, 0}, {38, 0}, {38, 0}, {36, 0}}, color = {0, 0, 127}));
82 connect(torque1.flange, inertia1.flange_a) annotation(
83 Line(points = {{-38, 0}, {-18, 0}}));
84 connect(inertia1.flange_b, torque2.flange) annotation(
85 Line(points = {{2, 0}, {14, 0}}));
86 connect(realexp.y, torque1.tau) annotation(
87 Line(points = {{-9, -34}, {-70, -34}, {-70, 0}, {-60, 0}}, color = {0, 0, 127}));
88 annotation(
89 Diagram(coordinateSystem(extent = {{-80, -60}, {80, 40}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2})),
90 Icon(coordinateSystem(extent = {{-80, -60}, {80, 40}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2})),
91 experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-07, Interval = 0.2),
92 __OpenModelica_commandLineOptions = "+gDynOpt",
93 __OpenModelica_simulationFlags(optimizerNP = "1", s = "optimization"));
94 end TimeTable;
95
96
97
98 annotation(
99 Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
100 uses(Modelica(version = "3.2.2")));
101end InputOptIssues;