Ticket #5847: InitializationInInitial.mo

File InitializationInInitial.mo, 3.2 KB (added by dariomangoni@…, 5 years ago)

Example package

Line 
1package InitializationInInitial
2
3
4 model ModelWithInitialScalar
5 inner Modelica.Mechanics.MultiBody.World world annotation(
6 Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
7 Modelica.Mechanics.MultiBody.Parts.FixedRotation fixedRotation(
8 angle = Modelica.SIunits.Conversions.to_deg(angle),
9 n = {0,0,1},
10 rotationType = Modelica.Mechanics.MultiBody.Types.RotationTypes.RotationAxis) annotation(
11 Placement(visible = true, transformation(origin = {-8, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
12 Modelica.Mechanics.MultiBody.Parts.Body body(m = 1, r_CM = {0, 0, 0}) annotation(
13 Placement(visible = true, transformation(origin = {30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
14 parameter Real myParam[3] = {0,1,0};
15 protected
16 // parameter Real axis[3](each fixed = false);
17 parameter Modelica.SIunits.Angle angle(fixed = false);
18 initial equation
19 angle = myInitFunScalar(myParam);
20 equation
21 connect(fixedRotation.frame_b, body.frame_a) annotation(
22 Line(points = {{2, 0}, {20, 0}, {20, 0}, {20, 0}}, color = {95, 95, 95}));
23 connect(world.frame_b, fixedRotation.frame_a) annotation(
24 Line(points = {{-40, 0}, {-18, 0}, {-18, 0}, {-18, 0}}));
25 end ModelWithInitialScalar;
26
27 model ModelWithInitialVect
28 inner Modelica.Mechanics.MultiBody.World world annotation(
29 Placement(visible = true, transformation(origin = {-50, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
30 Modelica.Mechanics.MultiBody.Parts.FixedRotation fixedRotation(
31 angle = Modelica.SIunits.Conversions.to_deg(angle),
32 n = axis,
33 rotationType = Modelica.Mechanics.MultiBody.Types.RotationTypes.RotationAxis) annotation(
34 Placement(visible = true, transformation(origin = {-8, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
35 Modelica.Mechanics.MultiBody.Parts.Body body(m = 1, r_CM = {0, 0, 0}) annotation(
36 Placement(visible = true, transformation(origin = {30, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
37 parameter Real myParam[3] = {0,1,0};
38 protected
39 parameter Real axis[3](each fixed = false);
40 parameter Modelica.SIunits.Angle angle(fixed = false);
41 initial equation
42 (axis, angle) = myInitFunVect(myParam);
43 equation
44 connect(fixedRotation.frame_b, body.frame_a) annotation(
45 Line(points = {{2, 0}, {20, 0}, {20, 0}, {20, 0}}, color = {95, 95, 95}));
46 connect(world.frame_b, fixedRotation.frame_a) annotation(
47 Line(points = {{-40, 0}, {-18, 0}, {-18, 0}, {-18, 0}}));
48 end ModelWithInitialVect;
49
50 function myInitFunScalar
51 input Real rotatedVersor[3];
52 output Modelica.SIunits.Angle rotationAngle;
53 algorithm
54 rotationAngle := 0;
55 annotation (Inline=true);
56 end myInitFunScalar;
57
58 function myInitFunVect
59 input Real rotatedVersor[3];
60 output Real rotationAxis[3];
61 output Modelica.SIunits.Angle rotationAngle;
62 algorithm
63 rotationAxis := {0,0,1};
64 rotationAngle := 0;
65 annotation (
66 Inline=true);
67 end myInitFunVect;
68 annotation(
69 uses(Modelica(version = "3.2.3")));
70end InitializationInInitial;