Signal Comparison Block

Hello,

I’m trying to compare 3 signals from the cells array like this:

...
  @equations begin
        # Series connect all cells
        [connect(cells[i].n, cells[i+1].p) for i in 1:length(cells)-1]
        v_max ~ maximum([cells[i].v for i in eachindex(Qs1)])
        v_min ~ minimum([cells[i].v for i in eachindex(Qs1)])
        v_output ~ ifelse(v_min <= 2.5, v_min, v_max)
    end
...

But is there a better way to get the max and min of several input signals? Like a predefined Block?
I’m afraid the whole ifelse comparison makes the system slow when more than a few signals are being compared.

You might want Base.extrema. In your case, you might be able to speed it up using manual loop by detecting when the first value is <= 2.5, then switching to a loop that only computes v_min.

In addition to @jakobnissen 's suggestion, one improvement could be to switch your comprehension to a generator (), you don’t need the full Vector.

v_m, v_M ~ extrema( (cells[i].v for …) )

A quick test with @time or @btime can show if your extra time is lost in allocations or compute