Opened 10 years ago
Last modified 6 years ago
#3186 assigned defect
Record constructor function lost during flattening — at Initial Version
Reported by: | Rüdiger Franke | Owned by: | somebody |
---|---|---|---|
Priority: | critical | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | trunk |
Keywords: | Cc: | Per Östlund |
Description
OpenModelica appears to ignore constructors for parameter records.
Today's test show an increase from 74 to 89 built models for the PowerSystems library, see
https://test.openmodelica.org/libraries/history/PowerSystems-trend.svg
This is due to the introduction of the workaround M3 of #3183, see
https://github.com/modelica/PowerSystems/commit/bb0593fd7db98de8af4ead2c2047a280267955ef
Interestingly no compilation error occurs. The simulations fail with divisions by zero, because the record constructor functions are not called.
See the following example:
package MissingPrecalculation record R parameter Integer nr; parameter Real[nr] vr; end R; record S parameter Integer ns; Real[:] vs; end S; function precalculation input R r; output S s(ns = r.nr); algorithm s.vs := 2*r.vr; end precalculation; model M3 parameter R r(nr = 2, vr = {1, 2}); record S2 = S(ns = r.nr); parameter S2 s = precalculation(r); end M3; end MissingPrecalculation;
Flattening results in:
function MissingPrecalculation.precalculation input MissingPrecalculation.R r; output MissingPrecalculation.S s; algorithm s.vs := r.vr * 2.0; end MissingPrecalculation.precalculation; class MissingPrecalculation.M3 parameter Integer r.nr = 2; parameter Real r.vr[1] = 1.0; parameter Real r.vr[2] = 2.0; parameter Integer s.ns = s.r.nr; parameter Real s.vs[1]; end MissingPrecalculation.M3;
Couldn't the the modifier for ns be kept in the precalculation function and the function call be placed in initial equations:
function MissingPrecalculation.precalculation input MissingPrecalculation.R r; output MissingPrecalculation.S s(ns = r.nr); algorithm s.vs := r.vr * 2.0; end MissingPrecalculation.precalculation; class MissingPrecalculation.M3 parameter Integer r.nr = 2; parameter Real r.vr[1] = 1.0; parameter Real r.vr[2] = 2.0; parameter Integer s.ns(fixed = false); parameter Real s.vs[1](fixed = false); parameter Real s.vs[2](fixed = false); initial equation s = /*.MissingPrecalculation.S*/(MissingPrecalculation.precalculation(/*.MissingPrecalculation.R*/(r))); end MissingPrecalculation.M3;