Ticket #5886: Bug2.mo

File Bug2.mo, 3.1 KB (added by federico.terraneo@…, 5 years ago)

Undetected index out of bounds

Line 
1package Bug2
2connector HeatPortVector
3 parameter Integer n = 4;
4 Modelica.Thermal.HeatTransfer.Interfaces.HeatPort port[n];
5end HeatPortVector;
6
7 model Component
8 HeatPortVector bottom(n = rows);
9
10 parameter Integer rows = 4;
11 parameter Integer cols = 1; //This causes index out of bounds
12
13 parameter Modelica.SIunits.HeatCapacity c = 1;
14 parameter Modelica.SIunits.ThermalConductance gx = 1;
15 parameter Modelica.SIunits.ThermalConductance gy = 1;
16 parameter Modelica.SIunits.ThermalConductance gf = 1;
17 parameter Modelica.SIunits.Temperature inletFluidTemperature = 300;
18
19 Modelica.SIunits.Temperature T[rows, cols](each start = inletFluidTemperature, each fixed = true);
20 equation
21
22 for i in 1:rows loop
23 bottom.port[i].Q_flow = 2 * gx * (bottom.port[i].T - T[i, 1]);
24 end for;
25
26 c * der(T[1, 1]) = gx * (T[1, 2] - T[1, 1])
27 + gy * (T[2, 1] - T[1, 1])
28 + gf * (inletFluidTemperature - T[1, 1])
29 + bottom.port[1].Q_flow;
30
31 if cols > 1 then
32 c * der(T[1, cols]) = gx * (T[1, cols - 1] - T[1, cols])
33 + gy * (T[2, cols] - T[1, cols])
34 + gf * (inletFluidTemperature - T[1, cols]);
35 end if;
36
37 if rows > 1 then
38 c * der(T[rows, 1]) = gx * (T[rows, 2] - T[rows, 1])
39 + gy * (T[rows - 1, 1] - T[rows, 1])
40 + gf * (inletFluidTemperature - T[rows, 1])
41 + bottom.port[rows].Q_flow;
42 end if;
43
44 if rows > 1 and cols > 1 then
45 c * der(T[rows, cols]) = gx * (T[rows, cols - 1] - T[rows, cols])
46 + gy * (T[rows - 1, cols] - T[rows, cols])
47 + gf * (inletFluidTemperature - T[rows, cols]);
48 end if;
49
50 for i in 2:rows - 1 loop
51 c * der(T[i, 1]) = gx * (T[i, 2] - T[i, 1])
52 + gy * (T[i - 1, 1] + T[i + 1, 1] - 2 * T[i, 1])
53 + gf * (inletFluidTemperature - T[i, 1])
54 + bottom.port[i].Q_flow;
55
56 if cols > 1 then
57 c * der(T[i, cols]) = gx * (T[i, cols - 1] - T[i, cols])
58 + gy * (T[i - 1, cols] + T[i + 1, cols] - 2 * T[i, cols])
59 + gf * (inletFluidTemperature - T[i, cols]);
60 end if;
61 end for;
62
63 for j in 2:cols - 1 loop
64 c * der(T[1, j]) = gx * (T[1, j - 1] + T[1, j + 1] - 2 * T[1, j])
65 + gy * (T[2, j] - T[1, j])
66 + gf * (inletFluidTemperature - T[1, j]);
67
68 if rows > 1 then
69 c * der(T[rows, j]) = gx * (T[rows, j - 1] + T[rows, j + 1] - 2 * T[rows, j])
70 + gy * (T[rows - 1, j] - T[rows, j])
71 + gf * (inletFluidTemperature - T[rows, j]);
72 end if;
73 end for;
74
75 for i in 2:rows - 1 loop
76 for j in 2:cols - 1 loop
77 c * der(T[i, j]) = gx * (T[i, j - 1] + T[i, j + 1] - 2 * T[i, j])
78 + gy * (T[i - 1, j] + T[i + 1, j] - 2 * T[i, j])
79 + gf * (inletFluidTemperature - T[i, j]);
80 end for;
81 end for;
82 end Component;
83end Bug2;