Opened 12 years ago
Closed 6 years ago
#1963 closed defect (fixed)
Frontend replaces constant array with parameter subscripts
Reported by: | Jens Frenkel | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | trunk |
Keywords: | Cc: | Christian Schubert |
Description
In the model Modelica.Electrical.Digital.Examples.DFFREG the frontend replace the line of an algorithm
nextstate[i] := T.StrengthMap[L.'0', strength];
to
dFFREG.dFFR.nextstate[i] := .Modelica.Electrical.Digital.Interfaces.Logic.'0';
but strength is a parameter, hence the replacement is illegal.
With the debugflag "setDebugFlags("scodeInstShortcut");" it is the same.
Change History (21)
comment:1 by , 12 years ago
Status: | new → accepted |
---|
comment:2 by , 12 years ago
Hi again,
It seems we do constant evaluation for all subscripts that are constant or parameter.
So I guess we shouldn't do it for parameters. I'll see what tests I break when I only constant-evaluate constants.
Cheers,
Adrian Pop/
comment:3 by , 12 years ago
Unfortunately the fix breaks too many models and we cannot fix this bug right now.
The problem is that we don't have a way yet to detect which parameters are final and we should constant evaluate and which are not and we shouldn't constant evaluate.
The fix is in the svn commented out.
Note for me: maybe add final prefix to DAE.ATTR so we can access it in Static.mo.
As far as I see the model works fine, but needs to be re-translated if strength changes.
Cheers,
Adrian Pop/
comment:4 by , 12 years ago
It is allowed to evaluate any parameter you like in a Modelica front-end. It is only an error if strength was not marked as a structural parameter. And else it's a minor loss of functionality (user cannot modify the parameter between the build and simulate steps).
comment:5 by , 12 years ago
So if the frontend evaluate a parameter it would be good to mark it as evalutate=True. Then it can be also replaced by the backend and the user can get an information about that.
I know that this model works fine with the replacement but work also models fine with parameter(fixed=false)? (see also Ticket #1964)
Why do we not inserd the row with the parameter as index:
= {L.'0', L.'0', L.'L', L.'0', L.'Z', L.'L', L.'L', L.'Z', L.'0', L.'L'}[strength];
I know minor less effizient, but at least correct.
comment:6 by , 12 years ago
I do believe it is because (previously?) the backend would be unable to handle code like:
arr[x] = 1.5;
Unless it knew the index x.
As for the evaluated parameters, you have them in: Env.CACHE(evaluatedParams=(_,lst))
And they should be marked final through Compiler/FrontEnd/DAEUtil.mo: elts := List.map1(elts,makeEvaluatedParamFinal,Env.getEvaluatedParams(cache));
Maybe it is possible to modify that code to also mark them Evaluate=true, and force a ceval of the binding?
comment:7 by , 12 years ago
These are not the problems we face.
My fix does this, basically as Jens said:
elseif dFFREG.dFFR.reset_flag == 2 then dFFREG.dFFR.nextstate[i] := {{Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U', .Modelica.Electrical.Digital.Interfaces.Logic.'U'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'L'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'1'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'L', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'0', .Modelica.Electrical.Digital.Interfaces.Logic.'L'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'1', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'Z', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'H', .Modelica.Electrical.Digital.Interfaces.Logic.'1'}, {.Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'X', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W', .Modelica.Electrical.Digital.Interfaces.Logic.'W'}}[Modelica.Electrical.Digital.Interfaces.Logic.'0', dFFREG.dFFR.strength];
The problem is that for other models (mainly Fluid) we get a lot of flowModel.states[1]
not found in scope and I have no way of fixing that right now.
I could probably add Evaluate=true, but where is that stored? In the parameter comment/annotation?
comment:8 by , 12 years ago
Yes in the comment of the Variable, see also BackendDAEOptimize.hasEvaluateAnnotation
comment:9 by , 12 years ago
Summary: | Frontend replace Constantearray with parameter Subscripts → Frontend replaces constant array with parameter subscripts |
---|
Ok. I'll see if I can add the Evaluate=true for these.
comment:11 by , 10 years ago
Milestone: | 1.9.1 → 1.9.2 |
---|
This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).
comment:12 by , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:17 by , 8 years ago
Milestone: | 1.11.0 → 1.12.0 |
---|
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:18 by , 7 years ago
Component: | Frontend → New Instantiation |
---|---|
Milestone: | 1.12.0 → 2.0.0 |
Owner: | changed from | to
Status: | accepted → assigned |
comment:20 by , 6 years ago
Replying to casella:
This issue is still valid with the NF
For the mentioned equation the NF right now generates:
dFFREG.dFFR.nextstate[i] := { Modelica.Electrical.Digital.Interfaces.Logic.'0', Modelica.Electrical.Digital.Interfaces.Logic.'0', Modelica.Electrical.Digital.Interfaces.Logic.'L', Modelica.Electrical.Digital.Interfaces.Logic.'0', Modelica.Electrical.Digital.Interfaces.Logic.'Z', Modelica.Electrical.Digital.Interfaces.Logic.'L', Modelica.Electrical.Digital.Interfaces.Logic.'L', Modelica.Electrical.Digital.Interfaces.Logic.'Z', Modelica.Electrical.Digital.Interfaces.Logic.'0', Modelica.Electrical.Digital.Interfaces.Logic.'L'}[dFFREG.dFFR.strength];
The way constants are handled in the NF was recently changed, but even before that the strength
parameter wasn't evaluated since it's not structural. So I don't think the NF has ever had the issue this ticket is about (it had other unrelated issues with Digital
models though).
comment:21 by , 6 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
OK.
@jfrenkel, feel free to reopen this if needed
Hi,
I guess T.StrengthMap is a package constant. We replace package constants where they appear but it seems we don't calculate the seconds index (strenght) constant-ness correctly in this case. I'll look what we do wrong there.
Cheers,
Adrian Pop/