Opened 7 years ago
Closed 7 years ago
#4993 closed defect (fixed)
Parameter-dependent conditional equations are not handled by the NF
| Reported by: | Francesco Casella | Owned by: | Per Östlund |
|---|---|---|---|
| Priority: | high | Milestone: | 2.0.0 |
| Component: | New Instantiation | Version: | |
| Keywords: | Cc: | danieljose.penagos@… |
Description
Consider the following test case
model Test
Real x[2];
parameter Boolean p[2] = {false, true};
equation
x[1] = 1;
for i in 1:2 loop
if p[i] then
x[i] = 2;
end if;
end for;
end Test;
Section 8.3.4 of the specification states
If-equations in equation sections which do not have exclusively parameter expressions as switching conditions shall have the same number of equations in each branch
so this model is valid, since p[i] is a parameter expression.
The old front end flattens this model to
class Test2 Real x[1]; Real x[2]; parameter Boolean p[1] = false; parameter Boolean p[2] = true; equation x[1] = 1.0; x[2] = 2.0; end Test2;
which is correct, and then simulates it correctly.
The NF instead produces this flat code
class Test
Real x[1];
Real x[2];
parameter Boolean p[1] = false;
parameter Boolean p[2] = true;
equation
x[1] = 1.0;
if p[1] then
x[1] = 2.0;
end if;
if p[2] then
x[2] = 2.0;
end if;
end Test;
then, when trying to simulate it, produces the following error:
[1] 16:19:58 Symbolic Error Too few equations, under-determined system. The model has 1 equation(s) and 2 variable(s).
The problem persists even when setting -d=evaluateAllParameters.
@perost, can you please make sure that these parameter dependent conditions are evaluated properly?
As an interim measure, getting them right with -d=evaluateAllParameters would already be good.

Fixed in fd56610.