Opened 11 years ago
Closed 4 years ago
#3284 closed defect (fixed)
Problem with "when+reinit" when using vectors
| Reported by: | Henning Kiel | Owned by: | somebody |
|---|---|---|---|
| Priority: | high | Milestone: | 1.19.0 |
| Component: | Backend | Version: | trunk |
| Keywords: | Cc: |
Description
The following model implements the bouncing ball model with
1) scalars
2) array of arbitrary length (e.g. 1)
Though both models flatten to the same code (except for the "[1]" where appropriate) the model result is different!
model reinit_test
parameter Integer n = 1;
parameter Real g = 9.81;
parameter Real e = 0.9;
Real v[n](start = 10 * (0:n - 1));
Real h[n](each start = 10);
Boolean flying;
Real v_(start = 0);
Real h_(start = 10);
Boolean flying_;
equation
der(h) = v;
der(v) = if flying then -g * ones(n) else zeros(n);
flying = not (h[1] <= 0 and v[1] <= 0);
when h[1] < 0 then
reinit(v, -e * pre(v));
end when;
der(h_) = v_;
der(v_) = if flying_ then -g else 0;
flying_ = not (h_ <= 0 and v_ <= 0);
when h_ < 0 then
reinit(v_, -e * pre(v_));
end when;
annotation(experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.002));
end reinit_test;
Change History (3)
comment:1 by , 11 years ago
| Component: | Backend → Code Generation |
|---|---|
| Owner: | changed from to |
comment:2 by , 11 years ago
| Component: | Code Generation → Backend |
|---|---|
| Owner: | changed from to |
Looking deeper into CodegenC.tpl, I see that the relation has no index (=-1), so it's probably the fault of the Backend.
comment:3 by , 4 years ago
| Milestone: | Future → 1.19.0 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Works in 1.19.0
Note:
See TracTickets
for help on using tickets.

I suspect the error to be (at least) in CodeGeneration.
When comparing the C output I find a difference in how the when condition is done. For the array code there is no hysteresis used:
/* equation index: 10 type: SIMPLE_ASSIGN - $whenCondition1 = h < 0.0 + $whenCondition1 = h[1] < 0.0 */ void reinit_test_eqFunction_10(DATA *data) { TRACE_PUSH const int equationIndexes[2] = {1,10}; modelica_boolean tmp4; - RELATIONHYSTERESIS(tmp4, $Ph, 0.0, 2, Less); + tmp4 = Less($Ph$lB1$rB,0.0); $P$whenCondition1 = tmp4; TRACE_POP }