Opened 6 years ago

Closed 6 years ago

#5133 closed defect (fixed)

[NF] Problems with variability for impure functions

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

Description

If we change the variability of function calls to impure functions to Variability.CONTINUOUS we get some issues:
https://libraries.openmodelica.org/branches/history/newInst/2018-09-19%2006:44:44..2018-09-19%2013:07:57.html

The question is how do we fix this as these errors seems legit:
https://libraries.openmodelica.org/branches/newInst/Buildings_latest/files/Buildings_latest_Buildings.Utilities.Plotters.Examples.Scatter.err
Basically the pattern is:

  parameter T p = callToImpureFunction(constant_or_parameter);

It seems the only way to handle this is to go back to calculate the variability for the functions based on the input parameters even if they are impure and just disable function evaluation of impure functions.

The spec says:

With the prefix keyword impure it is stated that a Modelica function is impure and it is only allowed to call such a function from within:
- another function marked with the prefix impure
- a when-equation,
- a when-statement,
- pure(impureFunctionCall(…)) - which allows calling impure functions in any pure context,
- in initial equations and initial algorithms,
- in bindings for variables declared as parameter – which is seen as syntactic sugar for having a parameter with fixed=false and the binding as an initial equation [thus there is no guarantee that parameter is equal to the impure function call after initialization] – and in constructing external objects.

Change History (4)

comment:1 by Adrian Pop, 6 years ago

Hopefully PR:
https://github.com/OpenModelica/OMCompiler/pull/2671
will fix this, we'll see.

comment:2 by Adrian Pop, 6 years ago

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

comment:3 by Adrian Pop, 6 years ago

Still some issues with the evaluation of impure functions in if expressions / if equations:
https://libraries.openmodelica.org/branches/history/newInst/2018-09-19%2016:03:18..2018-09-19%2018:55:04.html

comment:4 by Per Östlund, 6 years ago

Resolution: fixed
Status: acceptedclosed

The change in b9d1619 seems to have fixed the remaining issues, or at least all the models that failed in the report linked in the description.

Note: See TracTickets for help on using tickets.