0

I´m trying to set a connection with a conditional on the temperature, to represent a temperature-sensible charging pipe that works inside a stratified heat storage tank, with the following for loop reading the several volumes of the tank,

`for i in 2:nSeg loop
    if (sensor_T_inflow.T > vol[i].T) and (sensor_T_inflow.T < vol[i-1].T) then
      connect(feedPort, vol[i].ports[3])
        annotation (Line(points={{-50,-60},{6,-60},{6,
          -16},{16,-16}}, color={0,127,255}));
    end if;
  end for;`

However I get the errors such as this one for the volume 2:

Failed to expand block containing connect: if (sensor_T_inflow.T > vol[2].T and sensor_T_inflow.T < vol[1].T) then connect(feedPort, vol[2].ports[3]); end if;

The model contained invalid connect statements. Check aborted.

This might have a silly solution but I checked the names of all my elements and their temperature properties and they match with this code snippet, and I confirmed the error comes specially from the if conditional. Here is my model If you could take a look at it.

I tried commenting out the conditional and the check was succesful, only that I have a misbalance of about 40 variables to equations. If you got any advice on how to solve those misbalances I´d be much grateful as well.

Thanks a lot in advance.

Rob
  • 14,746
  • 28
  • 47
  • 65
Werner
  • 1

1 Answers1

1

The connect-statements may not depend on time-varying variables.

(The technical statement is first in the list in https://specification.modelica.org/master/connectors-and-connections.html#restrictions-of-connections-and-connectors )

A solution would be to turn that into an array of valve-components, and have them controlled in a similar way.

Hans Olsson
  • 11,123
  • 15
  • 38
  • That makes a lot of sense Hans, I'll build the model in this manner. Thank you very much :D – Werner Feb 20 '23 at 23:01