1 | echo(false);
|
---|
2 | s1 := "model BouncingBall
|
---|
3 | parameter Real e=0.7 \"coefficient of restitution\";
|
---|
4 | parameter Real g=9.81 \"gravity acceleration\";
|
---|
5 | Real h(start=1) \"height of ball\";
|
---|
6 | Real v \"velocity of ball\";
|
---|
7 | Boolean flying(start=true) \"true, if ball is flying\";
|
---|
8 | Boolean impact;
|
---|
9 | Real v_new;
|
---|
10 | Integer foo;
|
---|
11 |
|
---|
12 | equation
|
---|
13 | impact = h <= 0.0;
|
---|
14 | foo = if impact then 1 else 2;
|
---|
15 | der(v) = if flying then -g else 0;
|
---|
16 | der(h) = v;
|
---|
17 |
|
---|
18 | when {h <= 0.0 and v <= 0.0,impact} then
|
---|
19 | v_new = if edge(impact) then -e*pre(v) else 0;
|
---|
20 | flying = v_new > 0;
|
---|
21 | reinit(v, v_new);
|
---|
22 | end when;
|
---|
23 |
|
---|
24 | end BouncingBall;";
|
---|
25 | loadString(s1, "BouncingBall");
|
---|
26 | getErrorString();
|
---|
27 | addClassAnnotation(BouncingBall, annotate=experiment(StartTime=0,StopTime=3,Tolerance=1e-6,Interval=0.006));
|
---|
28 | getErrorString();
|
---|
29 | answer := "model BouncingBall
|
---|
30 | parameter Real e=0.7 \"coefficient of restitution\";
|
---|
31 | parameter Real g=9.81 \"gravity acceleration\";
|
---|
32 | Real h(start=1) \"height of ball\";
|
---|
33 | Real v \"velocity of ball\";
|
---|
34 | Boolean flying(start=true) \"true, if ball is flying\";
|
---|
35 | Boolean impact;
|
---|
36 | Real v_new;
|
---|
37 | Integer foo;
|
---|
38 |
|
---|
39 | equation
|
---|
40 | impact = h <= 0.0;
|
---|
41 | foo = if impact then 1 else 2;
|
---|
42 | der(v) = if flying then -g else 0;
|
---|
43 | der(h) = v;
|
---|
44 |
|
---|
45 | when {h <= 0.0 and v <= 0.0,impact} then
|
---|
46 | v_new = if edge(impact) then -e*pre(v) else 0;
|
---|
47 | flying = v_new > 0;
|
---|
48 | reinit(v, v_new);
|
---|
49 | end when;
|
---|
50 | annotation(experiment(StartTime = 0, StopTime = 3, Tolerance = 1e-6, Interval = 0.006));
|
---|
51 | end BouncingBall;";
|
---|
52 | s2 := listFile(BouncingBall);
|
---|
53 | print(s2);
|
---|
54 | if answer<>diffModelicaFileListings(s1, s2, OpenModelica.Scripting.DiffFormat.plain) then
|
---|
55 | print("\nFailed \n");
|
---|
56 | print("\nStart model:\n\n" + s1 + "\n");
|
---|
57 | print("\nExperiment annotation+listFile:\n\n" + s2 + "\n");
|
---|
58 | print("\nDiff:\n\n" + diffModelicaFileListings(s1, s2) + "\n");
|
---|
59 | print(getErrorString());
|
---|
60 | end if;
|
---|