Opened 6 years ago

Closed 6 years ago

#5527 closed defect (fixed)

when max(boolean_array) then doesn't work - New Fronted

Reported by: Domenico Nucera <domenico.nucera@…> 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 Domenico Nucera <domenico.nucera@…>, 6 years ago

Milestone: Future2.0.0

comment:2 by Domenico Nucera <domenico.nucera@…>, 6 years ago

Component: Code GenerationNew Instantiation
Owner: changed from Lennart Ochel to Per Östlund

comment:3 by Francesco Casella, 6 years ago

The definition of when equations (Section 8.3.5 of the Modelica Specification) says:

The expression of a when-equation shall be a discrete-time Boolean scalar or vector expression. The statements within a when-equation are activated when the scalar expression or any of the elements of the vector expression becomes true.

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) to arr[1] or arr[2] or ... arr[N], while the new one keeps max(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?

in reply to:  3 comment:4 by Domenico Nucera <domenico.nucera@…>, 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 Per Östlund, 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.

comment:6 by Per Östlund, 6 years ago

Resolution: fixed
Status: newclosed

Fixed in 0375f06c.

Note: See TracTickets for help on using tickets.