Opened 14 years ago
Last modified 7 years ago
#1429 assigned defect
Some kinds of array equations are not supported
Reported by: | Per Östlund | Owned by: | somebody |
---|---|---|---|
Priority: | low | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Cc: | Per Östlund, Jens.Frenkel@…, Willi Braun |
Description
The array equation in this model:
function pointGravity input Real r[3] "position"; output Real g[3] "gravity acceleration"; parameter Real k=1; protected Real n[3]; algorithm n := -r/sqrt(r*r); g := k/(r*r) * n; end pointGravity; model Particle parameter Real m = 1; Real r[3](start = {1,1,0}) "position"; Real v[3](start = {0,1,0}) "velocity"; equation der(r) = v; m*der(v) = m*pointGravity(r); end Particle;
gives the error message (from SimCode.mo):
Error: Internal error array equations currently only supported on form v = functioncall(...)
Change History (18)
comment:1 by , 12 years ago
Cc: | added; removed |
---|---|
Component: | → Backend |
comment:2 by , 12 years ago
I'm not sure how to go about coding the rml yet, but my first thought would be to replace all array equations with component equations using a for loop over all elements. As far as I can tell there are no problems with linearization when I do the math component by component.
comment:3 by , 12 years ago
With some non-obvious changes you can get array equations working with stable. The main change is adding the (Inline=true) annotation. Possibly because it is being inlined there are also some non trivial changes such as parameter to constant/ and removing some intermediate variables that are required.
function pointGravity annotation(Inline=true); input Real r[3] "position"; output Real g[3] "gravity acceleration"; protected constant Real k=1; algorithm g := k*r*(-1)/sqrt(r*r); end pointGravity; model Particle parameter Real m = 1; Real r[3](start = {1,1,0}) "position"; Real v[3](start = {0,1,0}) "velocity"; equation der(r) = v; m*der(v) = m*pointGravity(r); end Particle;
comment:4 by , 12 years ago
Cc: | added; removed |
---|
comment:5 by , 12 years ago
There are several problems with that model.
True, inline the function will solve the problem but this is may not the best way.
First of all there is a problem by extend the equation m*der(v) = m*pointGravity(r); to
{der(v[1]) * m, der(v[2]) * m, der(v[3]) * m} = pointGravity({r[1], r[2], r[3]}) * m;
This is done by the frontend, and will be fixed with the new instantiation implementation. Extend the equations make thinks more complicated.
Second, the paramter m occures in both sides of the equation and could be removed. There is not yet a optimization module availible for such thinks, but on the other side, who wrote equations like a*b=a*c?
Third, solving equations in the form {exp*a[1],exp2*a[2],exp3*a[3]}=func(...) is not so easy.
Fourthly, linearization fails because DAE.ASUB is not yet supported. Fixed in r12735
By the way generate simulation code works fine in the actual trunc.
comment:6 by , 12 years ago
Milestone: | → 1.9.0 |
---|
So if this works, should we... close it? Or is there more to discuss or fix?
comment:8 by , 10 years ago
Milestone: | 1.9.1 → 1.9.2 |
---|
This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).
comment:9 by , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:10 by , 10 years ago
Priority: | high → low |
---|
This doesn't work anymore with the latest trunk. The compiler just prints out lots of internal errors, beginning from Graph.addForbiddenColors.
comment:14 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | accepted → assigned |
Still not working, but it's a backend issue so it shouldn't be assigned to me.
comment:15 by , 9 years ago
The following, equivalent, version works correctly in OM.
Maybe this info can help in finding the issue.
model Particle parameter Real m = 1, M=1, k=1; Real r[3](start = {1,1,0}) "position"; Real v[3](start = {0,1,0}) "velocity"; Real squareR; equation der(r) = v; squareR=r*r; m*der(v) = -k*m*M*r/(squareR*sqrt(r*r)); end Particle;
comment:17 by , 8 years ago
Milestone: | 1.11.0 → 1.12.0 |
---|
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:18 by , 7 years ago
Milestone: | 1.12.0 → Future |
---|
The milestone of this ticket has been reassigned to "Future".
If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.
If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".
In both cases, a short informative comment would be welcome.
This currently breaks linearization support for the MultiBody library. I have been trying to figure out how to handle it in SimCode.mo but haven't had much luck. Is there any documentation for understanding SimCode.mo so I can help submit a patch to fix this?