Ticket #1680: test.mo

File test.mo, 799 bytes (added by chenouard-r, 13 years ago)
Line 
1package Test
2 import Modelica.Blocks.Sources.Ramp;
3 import Modelica.Blocks.Interfaces.*;
4
5 model M1
6 parameter Integer t1 [:]; // list of indices for t2
7 parameter Real t2 [:]; // list of items to sum
8
9 RealInput d;
10 Integer n (start=1);
11 Real s;
12 algorithm
13 s := sum(t2[i] for i in t1[1:n]);
14 n := F1(n,d,s,t1,t2);
15 end M1;
16
17 function F1
18 input Integer nb;
19 input Real d;
20 input Real s;
21 input Integer t1 [:];
22 input Real t2 [:];
23
24 output Integer nbNew;
25
26 algorithm
27 nbNew := if d >= s and nb < size(t1,1) then
28 nb + 1
29 elseif d <= s/2 and nb > 1 then
30 nb - 1
31 else
32 nb;
33 end F1;
34
35 model Test1
36 Ramp rp(offset=5000,startTime=0,duration=10,height=95000);
37 M1 m(t1={2,4,1,5,3,6,7},t2={11400,11400,11400,15200,15200,15200,15200});
38 equation
39 connect(rp.y,m.d);
40 end Test1;
41
42end Test;