modelica / Modelica-Compliance

A semantics compliance suite for the Modelica language
Other
17 stars 16 forks source link

ModelicaCompliance.Classes.Predefined.AttributeStateSelect #62

Closed modelica-trac-importer closed 5 years ago

modelica-trac-importer commented 6 years ago

Reported by jfrenkel on 2 Apr 2015 07:53 UTC The Model ModelicaCompliance.Classes.Predefined.AttributeStateSelect test that all defined values of StateSelect can be used. But there is a mistake vor Real v(stateSelect = StateSelect.always) = 5.0;. This variable have to be always "Do use it as a state.". But this is not possible because it is bind to be 5.0. The tool should reject it with a massage like:

Error In ModelicaCompliance.Classes.Predefined.AttributeStateSelect
The equation:
v=5.;
 constrains the continuous time variables:
v
 requiring them to be continuous time state variables. It is necessary to modify the stateSelect attributes or the model.

Migrated-From: https://trac.modelica.org/Modelica/ticket/1692

modelica-trac-importer commented 6 years ago

Comment by fcasella on 2 Apr 2015 09:20 UTC May I suggest the following error message:

Error In ModelicaCompliance.Classes.Predefined.AttributeStateSelect
The equation:
  v=5.0;
constrains the continuous time variables:
  v
which has stateSelect=StateSelect.always. This is not possible because a state variable cannot have a constant value. Please change the stateSelect attribute or the equation.
modelica-trac-importer commented 6 years ago

Comment by adrpo on 2 Apr 2015 09:41 UTC Jens, you can fix the model and do a pull request at: https://github.com/modelica-compliance/compliance But your point is valid, maybe we should add a new model that tests for this problem.

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 7 Apr 2015 07:38 UTC Replying to [ticket:1692 jfrenkel]:

The Model ModelicaCompliance.Classes.Predefined.AttributeStateSelect test that all defined values of StateSelect can be used. But there is a mistake vor Real v(stateSelect = StateSelect.always) = 5.0;. This variable have to be always "Do use it as a state.". But this is not possible because it is bind to be 5.0.

I agree that it is silly, and superfluous, to have v as a state, but why would it be impossible?

In the general case of

model A
  X x;
  Real v(stateSelect=...)=f(x, time);
end A;

already StateSelect.prefer state that 'v' does not have to be differentiated to be selected as a state (the tools should do that automatically); leading to der(v)=df/dx*der(x)+df/dt*1;

For the degenerate case of 'f' being the constant function this will still be correct; and 'der(v)' will be zero in that case.

modelica-trac-importer commented 6 years ago

Comment by jfrenkel on 15 Apr 2015 09:46 UTC In your example the equtaion v=f(x, time) is used to calculate the variable x.

However, in the degenerate case the equation may look like the following v=f(5, time). So after index reduktion there are 2 equations:

der(v)=0;
v=f(5, time)

In the case of v(stateSelect=StateSelect.always) it is not possible to keep v as state because there is an equation to many v=f(5,time).

In the case of v(stateSelect=StateSelect.prefer) it is also not possible to keep v as state. But in that case it is legal to deselect v and use it as normal algebraic variable.

type StateSelect = enumeration(
...
prefer "Prefer it as state over those having the default value 
        (also variables can be selected, which do not appear
        differentiated). ",
always "Do use it as a state.
);
HansOlsson commented 5 years ago

This has already been corrected without a reference to this ticket: https://github.com/modelica/Modelica-Compliance/commit/e0656a5901990e2f5f2555e6d58aec675e24ea1b