Opened 6 years ago

Closed 7 months ago

#5051 closed defect (fixed)

OM accepts in a model a parameter with no value

Reported by: massimo ceraolo Owned by: Per Östlund
Priority: blocker Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc: Adrian Pop

Description (last modified by massimo ceraolo)

Consider this package:

package TestParam
  model ResistorSimple
    parameter Real R;
    extends Modelica.Electrical.Analog.Interfaces.OnePort;
  equation
    v = R*i;
  end ResistorSimple;

  model Circuit
    Modelica.Electrical.Analog.Basic.Ground ground;
    Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage(V=1);
    ResistorSimple res;
  equation
    connect(ground.p, constantVoltage.n);
    connect(constantVoltage.n, res.p);
    connect(res.n, ground.p);
  end Circuit;
end TestParam;

I think Circuit should not run because parameter R has no value defined. Instead OM just issues the following message:

[1] 22:53:00 Translation Warning
[TestParam: 5:5-5:21]: Parameter res.R has no value, and is fixed during initialization (fixed=true), using available start value (start=0.0) as default value.

and runs.

This can be very tricky in larger models (for instance models using MSL models with default values for parameters) where there may exist many parameters having just start values. In these cases it can be very difficult to understand that one or some of them are indeed undefined.

Change History (6)

comment:1 by massimo ceraolo, 6 years ago

Description: modified (diff)

comment:2 by Francesco Casella, 6 years ago

Cc: Adrian Pop added
Component: *unknown*New Instantiation
Milestone: 1.13.02.0.0
Owner: changed from somebody to Per Östlund

I re-read section 8.6 of the Modelica Specification. I report here two statements

  • For all variables declared as constant and parameter, with fixed = true; no equation is added to the initialization equations
  • If a parameter has a modifier for the start-attribute, does not have fixed=false , and neither has a binding equation nor is part of a record having a binding equation, the modifier for the start-attribute can be used to add parameter binding equation assigning the parameter to that start-modifier. In this case a diagnostic message is recommended in a simulation model

I understand OMC does not behave correctly: since there is no modifier on the start attribute, using the default start attribute (i.e. zero) to add a parameter binding equation to assign the parameter to the start modifier is not the expected behaviour.

I agree with @ceraolo that such models should fail during compilation with an error message such as:

Error: missing binding equation for parameter res.R with fixed = true

I guess we should implement this behaviour in the new front end, @adrpo @perost, what do you think?

comment:3 by Adrian Pop, 6 years ago

This is already implemented partly in #5062 but only for parameter (fixed=true) annotation(Evaluate=true);

I will discuss with Per and we can make it so that a parameter with (fixed=true) and no start value gives an error.

in reply to:  3 comment:4 by massimo ceraolo, 6 years ago

thank you. I will stay tuned.

Replying to adrpo:

This is already implemented partly in #5062 but only for parameter (fixed=true) annotation(Evaluate=true);

I will discuss with Per and we can make it so that a parameter with (fixed=true) and no start value gives an error.

comment:5 by Francesco Casella, 6 years ago

Priority: highblocker

comment:6 by massimo ceraolo, 7 months ago

Resolution: fixed
Status: newclosed

This issue has been fixed recently. On OM 1.23.0-dev344 the issue is still there, wile in OM 1.24-dev13 the warning has been converted into an error message:

[1] 04:32:41 Translation Error
[a: 3:5-3:21]: Parameter res.R has neither value nor start value, and is fixed during initialization (fixed=true).

Note: See TracTickets for help on using tickets.