Opened 7 years ago

Last modified 3 years ago

#4483 new defect

Error due to bogus dynamic state selection

Reported by: Francesco Casella Owned by: Lennart Ochel
Priority: normal Milestone:
Component: Backend Version:
Keywords: Cc: PMCardoso@…, mciten@…, Karim Adbdelhak

Description

Please consider the attached test case. During compilation, OMC generates the following error

Error: Internal error It is not possible to select continues states because Number of equations 203 greater than number of States 197 to select from

The model compiles and runs correctly in Dymola. It has two potential state variables with stateSelect.prefer attribute; one is eliminated by the dummy derivatives method, and the only remaining one, which can definitely be selected statically is pipeToCoolingTower.htilde[1].

  • Why is this error generated?
  • What does "Number of equations greater than number of states to select from" mean? Which set of equations is the message referring to? Please improve the clarity of the error message. Also note that the correct spelling of "continues" is "continuous"
  • More specifically, why trying (and failing) dynamic state selection among 197 potential states, for a model that has a very obvious static state selection?

Attachments (1)

Bug.zip (302.6 KB ) - added by Francesco Casella 7 years ago.
Test case

Download all attachments as: .zip

Change History (10)

by Francesco Casella, 7 years ago

Attachment: Bug.zip added

Test case

comment:1 by Francesco Casella, 7 years ago

Priority: highnormal

I have performed some further analyis. The problem is caused by the cooling tower model, that has a stateSelect.prefer on some state variables, but that is optionally reduced to purely algebraic model by setting staticModel = true.

Something like

model M
  Real x(stateSelect = StateSelect.prefer);
  Real u;
  Boolean static = true;
equation
  u = sin(time);
  if static then
    der(x) = -x + u; 
  else
    0 = -x + u;
  end if;
end M;

In this case, there are actually no der() operators at all in the model, but there are some variables with StateSelect.prefer. Apparently, the current state selection algorithm tries hard to select these variables as states, and it obviously fails, because there are not enough differential equations. However, this should not cause an error, because StateSelect.prefer means that the variable should preferably be used as state, but not necessarily; that would be StateSelect.always. As far as I understand, models as the attached one are perfectly legal and well-posed.

The workaround is to set the proper StateSelect attribute based on the static/dynamic mode, as in

model Mfix
  Real x(if static then stateSelect = StateSelect.default else StateSelect.prefer);
  Real u;
  Boolean static = true;
equation
  u = sin(time);
  if static then
    0 = -x + u; 
  else
    der(x) = -x + u;
  end if;
end Mfix;

This modification makes it possible to run the attached model in OpenModelica. However, I think it would be good if the state selection algorithm was able to also handle models like the attached one without the workaround, just in case.

comment:2 by Francesco Casella, 7 years ago

Milestone: 1.12.01.13.0

Milestone moved to 1.13.0 due to 1.12.0 already being released.

comment:3 by Jens Frenkel, 6 years ago

If a variable is modified with stateSelect=StateSelect.prefer the index reduction consider this variables as potential states. Since it is not possible to decide before index reduction and state selection if a potential state is a state or only an algebraic variable (at least there is no procedure known to the developer how to do it) all potential states lead to differentiation of statements (Pantelides Algorithm).
Then the state selection algorithm have to detect the real states of the system. All other potential states became algebraic variables.
After sorting the statements of the system in BLT form (Tarjan's algorithm) the superfluous statements from differentiation can be removed from the system very simple because all variables of the block are derivatives from differentiation and modified to algebraic variables. In addition those blocks are not used to calculate derivatives or variables for results. This is since a long time the state of the implementation. One difficult issue with this procedure is for example a not differentiable function call in an statement of a pure algebraic loop marked for differentiation from Pantelides Algorithm.

comment:4 by Willi Braun, 6 years ago

Cc: Karim Adbdelhak added

comment:5 by Francesco Casella, 6 years ago

Milestone: 1.13.01.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:6 by Francesco Casella, 5 years ago

Milestone: 1.14.01.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:7 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:8 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:9 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.