Opened 7 years ago

Closed 3 years ago

#4907 closed defect (wontfix)

Support for Real x(value=10.0)

Reported by: Adrian Pop Owned by: Adrian Pop
Priority: high Milestone: 1.19.0
Component: New Instantiation Version:
Keywords: Cc:

Description

It seems that some Modelica libraries such as ClaRa (http://www.claralib.com/) is using modification (value=someValue) on Real and we don't support that. Dymola accepts this and just makes a binding out of it.

The question is: does Modelica spec actually allows this?

Change History (11)

comment:1 by Adrian Pop, 7 years ago

Also it seems that:

Real x(value = 10) = 15;

generates a duplicate modification for value.

comment:2 by Adrian Pop, 7 years ago

Component: FrontendNew Instantiation
Owner: changed from somebody to Per Östlund
Status: newassigned

Per, how easy would be to support this in the NF?

comment:3 by Adrian Pop, 7 years ago

Owner: changed from Per Östlund to Adrian Pop
Status: assignedaccepted

Actually this should be an easy fix in Absyn to SCode translation. Just make a binding out of the modification (value=someValue) while checking that it doesn't have one already.

comment:4 by Adrian Pop, 7 years ago

Actually, I spoke too soon, at Absyn to SCode level you don't know the type yet to see if is a basic Modelica type that has a value attribute.

comment:5 by Per Östlund, 7 years ago

It would be fairly easy to support this in the NF, but probably not without some small performance penalty (would have to look up the value attribute for every variable of simple type, at least if we want to catch duplicate modifications). I don't think being able to modify value is really intended though, since e.g. 4.8.5.1 doesn't list value as one of the forbidden literal values for enumerations.

comment:6 by Francesco Casella, 7 years ago

Besides, why should one prefer

Real x(value = 3);

over the more compact and readable

Real x = 3;

Shall we discuss this with the library developers? I never saw this pattern anywhere else.

comment:7 by Adrian Pop, 7 years ago

@casella: is actually for readability. They are using this kind of pattern in some cases:

RealInput x(value=if cond then someThen else someElse) if componentCondition;

comment:8 by Francesco Casella, 7 years ago

OK. I don't get the point of declaring x as an input variable if it always has a binding equation when it actually exists, but I guess I'm missing the whole picture.

comment:9 by Martin Sjölund, 7 years ago

I don't quite see the point since the code does not really become more readable. And since it's not allowed in the specification as far as I can tell, there should be no reason to support it. I would suggest the library owner to open a ticket with DS to make Dymola pedantic mode catch the error, and fix the library...

RealInput x(value=if cond then someThen else someElse) if componentCondition;
RealInput x    = (if cond then someThen else someElse) if componentCondition;

comment:10 by Francesco Casella, 7 years ago

BTW, the specification defines Real as

type Real // Note: Defined with Modelica syntax although predefined
  RealType value; // Accessed without dot-notation
  parameter StringType quantity = "";
  parameter StringType unit = "" "Unit used in equations";
  parameter StringType displayUnit = "" "Default display unit";
  parameter RealType min=-Inf, max=+Inf; // Inf denotes a large value
  parameter RealType start = 0; // Initial value
  parameter BooleanType fixed = true, // default for parameter/constant;
                              = false; // default for other variables
  parameter RealType nominal; // Nominal value
  parameter BooleanType unbounded=false; // For error control
  parameter StateSelect stateSelect = StateSelect.default;
equation
  assert(value >= min and value <= max, "Variable value out of limit");
end Real;

IMO, the comment "accessed without dot-notation" also implies that modifiers should not refer to this attribute explicitly, though of course this is a matter of interpretation.

comment:11 by Adrian Pop, 3 years ago

Milestone: Future1.19.0
Resolution: wontfix
Status: acceptedclosed
Note: See TracTickets for help on using tickets.