I would like to use expandable connector
(e.g. a Bus-like structure) to model (mainly) input
and output
connections for more complex subsystems (An array
will not allow having different units for its elements and flattened lists get unwieldly while a record
does not afaik allow for easily connecting only one of its variables without writing equations).
While you may simply connect a variable to an empty expandable connector
without problems, its unit
(and other attributes) will not be passed on. Thus I would like to flexbily declare variables inside an expandable connector (e.g. like x[:]
) and have their dimensions be determined by the actual connection.
Unfortunately neither does this validate in OpenModelica and Wolfram System Modeler:
package FirstAttempt
model SimpleBusModel
DataBus dataBus;
Modelica.Blocks.Interfaces.RealOutput x[ nout ](each unit = "widgets");
parameter Integer nout = 2;
equation
x = ones( nout );
connect( x, dataBus.x );
end SimpleBusModel;
expandable connector DataBus
Real[:] x(each unit = "widgets");
end DataBus;
end FirstAttempt;
... nor does declaring the connector
as a sub-component and passing on the array size via inner
and outer
work out:
model SimpleBusModel
DataBus dataBus;
Modelica.Blocks.Interfaces.RealOutput x[ nout ](each unit = "widgets");
inner parameter Integer nout = 2;
expandable connector DataBus
Real[nout] x(each unit = "widgets");
outer parameter Integer nout;
end DataBus;
equation
x = ones( nout );
connect( x, dataBus.x );
end SimpleBusModel;
How can an expandable connector
with flexible, predefined array variables be set up?
Update:
It seems that this is an issue pertaining to OpenModelica and the Wolfram System Modeler, as the examples given work out fine in Dymola (cf. f.wue's comment below). I cross-posted a similiar question on Wolfram Community.
In the Modelica Specification (Version 3.2 Revision 2) we find in Section 9.1.3 Expandable Connectors:
Before generating connection equations non-parameter scalar variables and non-parameter array elements declared in expandable connectors are marked as only being potentially present. A non-parameter array element may be declared with array dimensions “:” indicating that the size is unknown. This applies to both variables of simple types, and variables of structured types.
As indicated by f.wue we should connect connectors
- not mere inputs and outputs. I changed this in my code above, but it is not fixing the issue.
I have received an answer on a similar question on Wolfram Community confirming, that Wolfram System Modeler (Version 12.0.0 or earlier) currently does not support flexible array sizes inside an expandable connector
.
In Wolfram System Modeler we currently have to pass on the array-size information in a conventional way (i.e. by modification of size parameter):
model SimpleBusModel
DataBus dataBus(nout = nout);
Modelica.Blocks.Interfaces.RealOutput x[nout](each unit = "widgets");
parameter Integer nout = 2;
expandable connector DataBus
Real[nout] x(each unit = "widgets");
parameter Integer nout;
end DataBus;
equation
x = ones(nout);
connect(x, dataBus.x);
end SimpleBusModel;
This will also work in OpenModelica.