If an array is defined in Dymola and any one array element is assigned a value in an algorithm section, it appears that Dymola implicitly adds equations for all of the unassigned array elements. Consider the example below:
model AlgorithmAssignment
// Declare an array with two elements
Real myArray[2];
algorithm
// Assign a value to array element 1 in algorithm section
// This yields no error and implicitly assigns myArray[2] := 0;
myArray[1] := 10;
end AlgorithmAssignment;
This issue came to my attention when trying to run a model similar to the code below:
model EquationAndAlgorithmAssignment
// Declare an array with two elements
Real myArray[2];
equation
// Define element 1 in the equation section
myArray[1] = 10;
algorithm
// Define element 2 in the algorithm section
myArray[2] := 1;
// This model is over-defined because the equation myArray[2] := 1 in the
// algorithm section implicitly adds an equation myArray[1] := 0
// This behavior is unexpected.
end EquationAndAlgorithmAssignment;
As noted in the code comments, this behavior seems strange to me. One array element is assigned in the equation section, the other is assigned in the algorithm section. It is unintuitive to me that Dymola implicitly adds an equation myArray[1] := 0 simply because the algorithm section contains the equation myArray[2] := 1.
I would appreciate if anyone can provide guidance or comments on why this occurs, and if/why this is design behavior.