Opened 15 years ago
Last modified 15 years ago
#1170 closed defect (fixed)
vector causes assertion errors
Reported by: | Per Östlund | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Version: | 1.5.0RC2 | |
Keywords: | Cc: | Per Östlund, Per Östlund |
Description
The models
package Modelica package Icons partial function Function "Icon for a function" annotation(Icon(coordinateSystem(preserveAspectRatio = true, extent = {{ -100, -100},{100,100}}), graphics = {Text(extent = {{ -140,162},{136,102}}, textString = "%name", lineColor = {0,0,255}),Ellipse(extent = {{ -100,100},{100, -100}}, lineColor = {255,127,0}, fillColor = {255,255,255}, fillPattern = FillPattern.Solid),Text(extent = {{ -100,100},{100, -100}}, lineColor = {255,127,0}, textString = "f")}), Documentation(info = "<html><p>This icon is designed for a <b>function</b></p></html>")); end Function; end Icons; package SIunits type Length = Real(final quantity = "Length", final unit = "m"); type Position = Length; end SIunits; end Modelica; function PolyToRelCoord "Transforms polygon to relative coordinate system" extends Modelica.Icons.Function; import SI=Modelica.SIunits; input Real T[4, 4] "Transformation matrix"; input SI.Position s[3, :] "Polygon to be transformed"; output SI.Position r[3, size(s, 2)] "Transformed polygon"; protected Real p[4] "auxillary vector variable"; algorithm for i in 1:size(s, 2) loop p := vector(T*[s[:, i]; 1]); r[:, i] := p[1:3]; //r := cat(2,r,[p[1];p[2];p[3]]); end for; end PolyToRelCoord; model TestPoly Real crap[3,:] = PolyToRelCoord(ones(4, 4), ones(3, 4)); end TestPoly;
and
model VectorTest function PolyToRelCoord "Transforms polygon to relative coordinate system" input Real T[4, 4] "Transformation matrix"; input Real s[3, :] "Polygon to be transformed"; output Real r[3, size(s, 2)] "Transformed polygon"; protected Real p[4] "auxillary vector variable"; algorithm for i in 1:size(s, 2) loop p := vector(T*[s[:, i]; 1]); r[:, i] := p[1:3]; end for; end PolyToRelCoord; constant Real H[4,4] = diagonal(ones(4)); constant Real ply[3,4] = [1.0, 0.0, 0.0, 1.0; 1.0, 0.0, 1.0, 0.0; 0.0, 0.0, 1.0, 1.0]; constant Real plyprime[3,4] = PolyToRelCoord(H,ply); end VectorTest;
both cause an assertion to fail in the C runtime:
Assertion failed: j == dest->ndims, file real_array.c, line 358
Note:
See TracTickets
for help on using tickets.
It seems the index_spec for xxx := p[1:3] is [{1,2,3}], and that index_spec will reduce the dimensions of the matrix p (which is a vector, dim=1), by 1. This is the fault. From my naive point of view, the dimensions of the result should be the addition of A, W and S*; not the subtraction of A,W from the original dims...
If I remove some assertions from the C runtime, the code does run just fine. Which is weird; someone made the assertions for a reason...