1 | within ;
|
---|
2 | package TestCaching
|
---|
3 | model FirstOrder
|
---|
4 | Real u = 0;
|
---|
5 | Real x(start = 0, fixed = true);
|
---|
6 | Modelica.SIunits.Time T = 1;
|
---|
7 | equation
|
---|
8 | T*der(x) = u - x;
|
---|
9 | end FirstOrder;
|
---|
10 |
|
---|
11 | model ResistorSource
|
---|
12 | FirstOrder m1(u = u);
|
---|
13 | Real u = 0;
|
---|
14 | Modelica.Electrical.Analog.Interfaces.Pin p;
|
---|
15 | Modelica.Electrical.Analog.Interfaces.Pin n;
|
---|
16 | parameter Modelica.SIunits.Resistance R = 1;
|
---|
17 | equation
|
---|
18 | p.i + n.i = 0;
|
---|
19 | p.v - n.v = R*p.i + m1.x;
|
---|
20 | end ResistorSource;
|
---|
21 |
|
---|
22 | model SystemSmall
|
---|
23 | Modelica.Electrical.Analog.Basic.Ground g1, g2;
|
---|
24 | TestCaching.ResistorSource rs_1(R = 1, u = sin(time));
|
---|
25 | TestCaching.ResistorSource rs_2(R = 2);
|
---|
26 | TestCaching.ResistorSource rs_3(R = 3, u = sin(time));
|
---|
27 | TestCaching.ResistorSource rs_4(R = 4);
|
---|
28 | TestCaching.ResistorSource rs_5(R = 5, u = sin(time));
|
---|
29 | equation
|
---|
30 | connect(rs_1.n, g1.p);
|
---|
31 | connect(rs_5.p, g2.p);
|
---|
32 | connect(rs_1.p, rs_2.n);
|
---|
33 | connect(rs_2.p, rs_3.n);
|
---|
34 | connect(rs_3.p, rs_4.n);
|
---|
35 | connect(rs_4.p, rs_5.n);
|
---|
36 | end SystemSmall;
|
---|
37 |
|
---|
38 | model GenerateSystemLarge
|
---|
39 | constant Integer N = 100 "Number of generators with modifier";
|
---|
40 | constant Integer M = 50
|
---|
41 | "Number of modifier-less generator per generator with modifier";
|
---|
42 | constant String fn = "SystemLarge.mo";
|
---|
43 | algorithm
|
---|
44 | when terminal() then
|
---|
45 | Modelica.Utilities.Streams.print("model SystemLarge", fn);
|
---|
46 | Modelica.Utilities.Streams.print(" Modelica.Electrical.Analog.Basic.Ground g1, g2;", fn);
|
---|
47 | for i in 0:N-1 loop
|
---|
48 | Modelica.Utilities.Streams.print(" TestCaching.ResistorSource rs_"+String(i*M+1)+"(R = "+String(i*M+1)+", u = sin(time));", fn);
|
---|
49 | for j in 2:M loop
|
---|
50 | Modelica.Utilities.Streams.print(" TestCaching.ResistorSource rs_"+String(i*M+j)+"(R = "+String(i*M+j)+");", fn);
|
---|
51 | end for;
|
---|
52 | end for;
|
---|
53 | Modelica.Utilities.Streams.print(" TestCaching.ResistorSource rs_"+String(N*M+1)+"(R = "+String(N*M+1)+", u = sin(time));", fn);
|
---|
54 | Modelica.Utilities.Streams.print("equation", fn);
|
---|
55 | Modelica.Utilities.Streams.print(" connect(rs_1.n, g1.p);", fn);
|
---|
56 | Modelica.Utilities.Streams.print(" connect(rs_"+String(N*M+1)+".p, g2.p);", fn);
|
---|
57 | for i in 0:N-1 loop
|
---|
58 | for j in 1:M loop
|
---|
59 | Modelica.Utilities.Streams.print(" connect(rs_"+String(i*M+j)+".p, rs_"+String(i*M+j+1)+".n);", fn);
|
---|
60 | end for;
|
---|
61 | end for;
|
---|
62 | Modelica.Utilities.Streams.print("end SystemLarge;", fn);
|
---|
63 | end when;
|
---|
64 | end GenerateSystemLarge;
|
---|
65 | annotation (uses(Modelica(version="3.2.1")));
|
---|
66 | end TestCaching;
|
---|