Skip to content

Avoid StateSelect.never in FreeBodiesEnforceStates - #4822

Open
sjoelund wants to merge 3 commits into
modelica:masterfrom
sjoelund:fix-FreeBodiesEnforceStatesFalse-never
Open

sjoelund wants to merge 3 commits into
modelica:masterfrom
sjoelund:fix-FreeBodiesEnforceStatesFalse-never

Conversation

@sjoelund

@sjoelund sjoelund commented Oct 5, 2026

Copy link
Copy Markdown
Member

ModelicaTest.MultiBody.Parts.FreeBodiesEnforceStatesFalse sets stateSelect=StateSelect.never on pointMass, but its r_0 and v_0 are the only possible states. The specification defines never as "Do not use as state at all", so a tool that respects it cannot translate the model; OpenModelica reports an error since it started enforcing this (OpenModelica/OpenModelica#2584).

Use StateSelect.avoid instead. It still gives a wrong indication, as the test intends, without making the model invalid. Dymola already ignored the hint, so its results are unchanged.

Assisted-by: Claude Opus 5.5

ModelicaTest.MultiBody.Parts.FreeBodiesEnforceStatesFalse sets
`stateSelect=StateSelect.never` on `pointMass`, but its `r_0` and `v_0`
are the only possible states. The specification defines `never` as "Do
not use as state at all", so a tool that respects it cannot translate
the model; OpenModelica reports an error since it started enforcing
this (OpenModelica/OpenModelica#2584).

Use `StateSelect.avoid` instead. It still gives a wrong indication, as
the test intends, without making the model invalid. Dymola already
ignored the hint, so its results are unchanged.

Assisted-by: Claude Opus 5.5
@henrikt-ma

Copy link
Copy Markdown
Contributor

In System Modeler we also take StateSelect.never with a grain of salt. From my point of view, we could also consider reformulating the specification to say a tool may give a diagnostic when a variable with StateSelect.never is used as state.

@sjoelund

sjoelund commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

Having examples in MSL be of the kind that are not supposed to be able to run seems a bit odd. The compliance suite does have these and checks that a tool does not allow specifically this kind of model. So an alternative could be that this model should be removed from ModelicaTest as well. Or that ModelicaTest should contain these kinds of models, but use a different icon and annotation to mark them as expected to fail.

@sjoelund

sjoelund commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

In System Modeler we also take StateSelect.never with a grain of salt. From my point of view, we could also consider reformulating the specification to say a tool may give a diagnostic when a variable with StateSelect.never is used as state.

Yes, that could also be an option. But then what's the difference from StateSelect.avoid? Just a slightly more negative weight?

@henrikt-ma

Copy link
Copy Markdown
Contributor

Yes, that could also be an option. But then what's the difference from StateSelect.avoid? Just a slightly more negative weight?

I'd give them equal weight, with the only difference that the specification allows/recommends giving a diagnostic in the case of never.

(While I understand the real use case of always for those working with state-space methods, my guess is that never was added to the language for the sake of symmetry rather than being motivated by relevant use cases.)

@HansOlsson HansOlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself is good, but it makes the documentation inconsistent.

Currently it seems as if the model was intended to fail.

Test whether enforceStates=false give any undesired output

Information
This test case is made with the intent of verifying what choices are made by the compiler in terms of state selection when wrong indications are given, here all the bodies have the flag enforceStates=false but the bodies positions and velocities are the only possible states.

Dymola ignores the flag and uses bodies variables as states.

I'll see if I can provide more detailed suggestions.

Comment thread ModelicaTest/MultiBody.mo Outdated
Co-authored-by: Hans Olsson <HansOlsson@users.noreply.github.com>
@sjoelund
sjoelund requested a review from HansOlsson October 6, 2026 19:24
Comment thread ModelicaTest/MultiBody.mo Outdated
Co-authored-by: Hans Olsson <HansOlsson@users.noreply.github.com>
@sjoelund
sjoelund requested a review from HansOlsson October 7, 2026 14:22

@HansOlsson HansOlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@beutlich beutlich added the L: ModelicaTest Issue addresses ModelicaTest, ModelicaTestConversion4 or ModelicaTestOverdetermined label Oct 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: ModelicaTest Issue addresses ModelicaTest, ModelicaTestConversion4 or ModelicaTestOverdetermined

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants