Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are discrete inputs allowed in Modelica? #3527

Open
casella opened this issue Jun 10, 2024 · 3 comments
Open

Are discrete inputs allowed in Modelica? #3527

casella opened this issue Jun 10, 2024 · 3 comments
Labels
clarification Specification of feature is unclear, but not incorrect

Comments

@casella
Copy link
Collaborator

casella commented Jun 10, 2024

Follow-up of ticket OpenModelica/OpenModelica#12531 by @BasilioPV. Consider the following MWE:

model DiscreteIssue
  discrete input Real In(start=1);
  discrete output Real Out(start=0);
equation
  when In>1 then
    Out=1;
  end when;
end DiscreteIssue;

As I understand, this model is not legal in Modelica because of the provision in Sect. 4.5.3:

If a Real variable is declared with the prefix discrete it must in a simulation model be assigned in a when-clause, either by an assignment or an equation.

On the other hand, the FMI 2.0.4 standard explicitly allows the discrete input combination.

In view of the MA supporting open coordinated standards, could we amend the MLS to make this model legal, so it could be exported as an FMU?

BTW,

If a Real variable is declared with the prefix discrete it must in a simulation model be assigned in a when-clause, either by an assignment or an equation.

looks very German to me, shouldn't it better be

If a Real variable in a simulation model is declared with the prefix discrete, it must in be assigned in a when-clause, either by an assignment or an equation.

@HansOlsson
Copy link
Collaborator

If a Real variable is declared with the prefix discrete it must in a simulation model be assigned in a when-clause, either by an assignment or an equation.

That is correct.

On the other hand, the FMI 2.0.4 standard explicitly allows the discrete input combination.

The "discrete" have different meaning.

Modelica is (in contrast to FMU) a language where you combine different models - this means that we need to consider how a model works as a sub-model and as a base-class etc. Enforcing that a variable is "discrete" in all those cases would require additional rules that are complicated to get right - and without those rules different tools would interpret "discrete" differently.

The better solution would be to remove "discrete" in the Modelica Language - as it isn't really needed
Similarly Modelica also have Clocked variables, but there isn't any primitive to say that a variable is on a clock (in contrast to FMI) as the idea is that it is deduced from the variable.

The goal in Modelica is instead that the same sub-model (such as add-block) can be used in continuous time and clocked.

In view of the MA supporting open coordinated standards, could we amend the MLS to make this model legal, so it could be exported as an FMU?

If you just remove "discrete" it can be exported as an FMU.

If a Real variable is declared with the prefix discrete it must in a simulation model be assigned in a when-clause, either by an assignment or an equation.

looks very German to me, shouldn't it better be

If a Real variable in a simulation model is declared with the prefix discrete, it must in be assigned in a when-clause, either by an assignment or an equation.

Likely an improvement.

@HansOlsson HansOlsson added the clarification Specification of feature is unclear, but not incorrect label Jun 11, 2024
@BasilioPV
Copy link

Thanks @HansOlsson, then as far I understand, there is no benefit in any case to declare a "discrete input" into Modelica.

@henrikt-ma
Copy link
Collaborator

I don't share the desire to eliminate discrete from Modelica. I find it the concept of variability very helpful for developing models with meaningful semantics, in the same way that I find it very useful to add type annotations that can both make the intent of working code easier for a human to understand, and enable the compiler to direct me to the right place in the code in case of a type error.

I have long desired that discrete in Modelica would only mean that the variable must be solved so that it gets a discrete-time solution. Being assigned in a when-clause would then be just one of the valid ways that a discrete variable can be determined. I don't see any real difficulty in implementing this more general requirement.

Regarding blocks that can operate both in discrete-time and non-discrete-time, my claim is that the missing feature in Modelica is the ability to use a function as a block. This would both fill the gap of not having a way to express that a block in Modelica does not contain stateful dynamics, and allow us to take advantage of the variability rules for function calls when making block-oriented models.

@HansOlsson HansOlsson mentioned this issue Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Specification of feature is unclear, but not incorrect
Projects
None yet
Development

No branches or pull requests

4 participants