#4553 closed defect (fixed)
Wrong structural reporting in systems with complex array equations
Reported by: | Francesco Casella | Owned by: | Patrick Täuber |
---|---|---|---|
Priority: | high | Milestone: | 1.13.0 |
Component: | Backend | Version: | |
Keywords: | Cc: |
Description
Consider this test case
model foo function f input Real x[2]; output Real y[2]; output Real z[2]; algorithm y := {x[1], 2*x[2]}; z := {x[1], -3*x[2]}; end f; Real y[2], w[2]; equation (, y) = f(w); (, y) = f(w); end foo;
OpenModelica-v1.13.0-dev-63-g453e1c7-64bit reports
[2] 23:25:37 Symbolic Error Too few equations, under-determined system. The model has 2 equation(s) and 4 variable(s). [3] 23:25:37 Translation Error Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed! [4] 23:25:37 Translation Error post-optimization module wrapFunctionCalls (simulation) failed.
This system is singular (same equation repeated twice) but it is not underdetermined; there are 4 equations in 4 unknowns.
Change History (8)
comment:1 by , 7 years ago
Cc: | removed |
---|---|
Owner: | changed from | to
Status: | new → assigned |
follow-up: 4 comment:2 by , 7 years ago
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:4 by , 7 years ago
Replying to ptaeuber:
WrapFunctionCalls encapsulates the function
f
and removes it in the equation system. After finding the equationy=y
it is removed because of redundancy.
I'm not sure I understand this. With the exception of intial equations (where redundancy can arise from index reduction), redundant equations in models should be reported as errors, not silently eliminated. Do I miss something?
follow-up: 6 comment:5 by , 7 years ago
Sure, but in this case the removal of redundant euqations is part of the WFC algorithm. The algorithm creates a new equation system by filtering the non-redundant equations from the expandable array, where the substitutions are performed. So it often happens that there are redundant equations. If the system is regular we will end up having the same number of equations and variables again. If the system is singular we will lose equations.
The new introduced check points to this problem by adding a warning. The model fails in the normal "system check" which is executed after each optimization module.
follow-up: 7 comment:6 by , 7 years ago
Replying to ptaeuber:
Sure, but in this case the removal of redundant euqations is part of the WFC algorithm. The algorithm creates a new equation system by filtering the non-redundant equations from the expandable array, where the substitutions are performed. So it often happens that there are redundant equations. If the system is regular we will end up having the same number of equations and variables again. If the system is singular we will lose equations.
Sorry, but I don't get this. My understanding is that if you start from a system of N equations in N variables, and one of them is equivalent to y=y, then the system is hopelessly singular, and that's the end of it.
Could you provide a simple example?
comment:7 by , 7 years ago
Replying to casella:
Sorry, but I don't get this. My understanding is that if you start from a system of N equations in N variables, and one of them is equivalent to y=y, then the system is hopelessly singular, and that's the end of it.
In general, you are right, of course. But inside of the wrapFunctionCalls
-algorithm the equations are manipulated in four phases. First, you look for calls and save them in a separate list (i.e. ExpandableArray). In the third phase the equations are traversed again and substituted. This is when you might get redundant equations. In the last phase, the cse-equations are created from the expandable array.
Could you provide a simple example?
Simple Example:
x = sin(time)
- Phase: You find
sin(time)
and store it in the expandable array with cse-variablex
- Phase: Do the dependency stuff (no dependencies here)
- Phase: Traverse equations again and substitute:
->
x=x
. This is expected and no error. The algorithm continues but does not add this equation to the new system. - Phase: The expandable array is traversed and cse-equation
x = sin(time)
is added to the system.
At the end the system is x = sin(time)
again. So it is possible to have redundant equations during the algorithm if you have equations of the form cref=call
in your equation system. If the system is not singular, you will always have a balanced system in the end.
In the example in the ticket description the two equations (,y) = (,y)
and (,y) = (,y)
are removed in the substitution phase and (, y) = f(w)
is added in the fourth phase. So, in the end, you have lost an equation and this is the first time you can realize that there is something wrong.
Hope this makes it a bit clearer.
WrapFunctionCalls encapsulates the function
f
and removes it in the equation system. After finding the equationy=y
it is removed because of redundancy.In OMCompiler/624b9a6 I added a check for unbalanced systems after the WFC algorithm, so that a warning is printed if the system is unbalanced, that points to the original problem (singularity).