Download Modeling, Simulation and Control with Modelica 3.0 and Dymola 7

Transcript
Draft, Jan. 21, 2009
5.5 Records
103
erated:
Beam beam(data( crossSection = BeamChoices.circle(diameter=0.04) ));
The different functions to define the cross section are provided in a separate sub-library:
package BeamChoices
...
function circle
input Modelica.SIunits.Length diameter = 0.02;
input Integer numberOfPoints(min=4) = 8;
output BeamCrossSection crossSection(
redeclare Real polyLine[numberOfPoints,2]);
import Modelica.Constants.pi;
protected
Modelica.SIunits.Angle phi;
algorithm
crossSection.area = pi*diameter^2/4;
crossSection.Iyy = pi*diameter^4/64;
crossSection.Izz = crossSection.Iyy;
crossSection.It
= 2*crossSection.Iyy;
for i in 1:numberOfPoints loop
phi = 2*pi*(i-1)/numberOfPoints;
crossSection.polyLine[i,:] = diameter/2*{sin(phi), cos(phi)};
end for;
end circle;
...
end BeamChoices;
Function “BeamChoices.circle” has diameter and numberOfPoints as input arguments and returns an instance of the BeamCrossSection record. In the function, all elements of this record are computed and assigned. The record contains a vector of type “Real[numberOfPoints,2]”, i.e., the dimension of this vector changes according to the input argument numberOfPoints. It is a bit tricky to define the
actual dimensions of an array that is used in an output record of a function. Currently, the only possible way
in Dymola is to use a “redeclaration”, see section 5.10, where the declaration of the array is given as
modifier to the output argument with the actual dimensions and with the prefix “redeclare”.
The above approach allows to define pop-down menus in a quite convenient way. There is, however, one
drawback: The modifier to the record instance is a function call, i.e., an expression. This means that the
record cannot be modified in the plot variable browser, before simulation starts. If for example, the diameter
in the example above is changed, Dymola has to re-translate the model. Providing the input arguments to the
function as parameters, e.g., as in:
parameter Modelica.SIunits.Diameter D = 0.04;
Beam beam(data( crossSection = BeamChoices.circle(diameter=D) ));
does not help either currently in Dymola, since Dymola does not allow to change “D” before simulation starts
and therefore changing “D” requires again a re-translation of the model.
5.5.3
Records with array elements (partially available)
Records may have arrays as elements. For example, in the Modelica_LinearSystems library (a free library available from the “File / Libraries” menu in Dymola) linear state space systems are available as:
ẋ
y
= A⋅x  B⋅u
= C⋅x  D⋅u
The data of such a system is basically provided as a record:
record StateSpace
Real A[:,:];
Real B[size(A,1), :];
(5.7)