Opened 4 years ago
Last modified 4 years ago
#6067 closed defect
Evaluate = true should be applied to entire parameter records — at Version 1
Reported by: | Francesco Casella | Owned by: | Per Östlund |
---|---|---|---|
Priority: | blocker | Milestone: | 1.17.0 |
Component: | New Instantiation | Version: | |
Keywords: | Cc: | enrico.cunietti@… |
Description (last modified by )
Please consider the following test case
package TestEvaluateParameterRecord record R1 parameter Integer N = 3; parameter Real p = 2 annotation(Evaluate = true); parameter Real q[N,N] = [0, 0, 1; 0, 1, 0; 1, 0, 0] annotation(Evaluate = true); end R1; record R2 parameter Integer N = 3; parameter Real p = 2; parameter Real q[N,N] = [0, 0, 1; 0, 1, 0; 1, 0, 0]; end R2; model M replaceable parameter R1 data1; replaceable parameter R2 data2 annotation(Evaluate = true); Real x1[data1.N]; Real x2[data2.N]; Real z1; Real z2; equation x1 = data1.q*{1, 2, 3}; x2 = data2.q*{1, 2, 3}; z1 = data1.p*time; z2 = data2.p*time; end M; end TestEvaluateParameterRecord;
When I flatten model M
with the NF I get
equation x1[1] = 3.0; x1[2] = 2.0; x1[3] = 1.0; x2[1] = data2.q[1,1] + data2.q[1,2] * 2.0 + data2.q[1,3] * 3.0; x2[2] = data2.q[2,1] + data2.q[2,2] * 2.0 + data2.q[2,3] * 3.0; x2[3] = data2.q[3,1] + data2.q[3,2] * 2.0 + data2.q[3,3] * 3.0; z1 = 2.0 * time; z2 = data2.p * time;
In the case of R1
, the parameters p
and q
are indeed evaluated, and the corresponding simple formulations are obtained for the equations, where all the zero terms have been removed.
However, setting the annotation explicitly on each component of the record is a bit inconvenient. One would like to set the annotation once and for all for the entire record. According to Section 18.3 of the specification, I understand the effect should be the same. Unfortunately the NF basically ignores the annotation and does not evaluate the parameters in the record.
This feature is needed to run Modelica models written with matrix formulations, where the matrix parameters are mostly filled in with zeros. In this case, it is absolutely necessary to evaluate the matrix-vector products, as shown in the above example, otherwise the generate code may contain a ludicrous number of useless terms, that should be removed up front since 0*x = 0
no matter what the value of x
is.
@perost, could you please fix that ASAP as you return from you vacation? Thanks!