Opened 6 years ago
Closed 6 years ago
#5527 closed defect (fixed)
when max(boolean_array) then doesn't work - New Fronted
Reported by: | Owned by: | Per Östlund | |
---|---|---|---|
Priority: | critical | Milestone: | 2.0.0 |
Component: | New Instantiation | Version: | v1.14.0-dev-nightly |
Keywords: | boolean max array | Cc: |
Description
It seems to me that the construct - when max(array) then - doesn't work with the new frontend (the one activated by ticking "Enable experimental new instantiation phase"). For example on my machine this basic model results in errors during C code translation
model when_max Boolean arr[1] = {time > 0.7}; algorithm when max(arr) then end when; end when_max;
In sending this I hope the when max() construct is Modelica legal. In case, I experienced that also a construct based on - if max() then - doesn't work, as in the example below
model if_max Boolean arr[1] = {time > 0.7}; Integer n; algorithm if max(arr) then n := n + 1; end if; end if_max;
With reference to: #5439. Component: new instantiation, milestone: 2.0.0
Change History (6)
comment:1 by , 6 years ago
Milestone: | Future → 2.0.0 |
---|
comment:2 by , 6 years ago
Component: | Code Generation → New Instantiation |
---|---|
Owner: | changed from | to
follow-up: 4 comment:3 by , 6 years ago
comment:4 by , 6 years ago
Replying to casella:
... So, I understand this is perfectly legal, and actually means that the statements will be activated when the array goes from being all false to having at least one true element. It is not triggered when there are some true elements and others become true. Is this your required behaviour?...
Yes, that was exactly the desired behaviour.
Then the one posted above is just a code example in which I tried to isolate the construct leading to the code translation error, which appears in some of my models.
comment:5 by , 6 years ago
This should be fixed in PR #262.
The issue was simply that no one had implemented support for min/max of boolean arrays in the runtime, but doing so was fairly trivial. I also added the optimization min/max(arg) => arg[1]
when arg is an array with a single element to the NF.
The definition of when equations (Section 8.3.5 of the Modelica Specification) says:
So, I understand this is perfectly legal, and actually means that the statements will be activated when the array goes from being all false to having at least one true element. It is not triggered when there are some true elements and others become true. Is this your required behaviour?
That said, the old frontend expands
max(arr)
toarr[1] or arr[2] or ... arr[N]
, while the new one keepsmax(arr)
that the current backend cannot handle.@perost, could you add this expansion (and the corresponding one with
min(arr)
->arr[1] and arr[2]
) when-nfScalarize=true
?