Skip to content

Local balance per type#3818

Merged
HansOlsson merged 9 commits intomodelica:masterfrom
henrikt-ma:local-balance-per-type
Mar 6, 2026
Merged

Local balance per type#3818
HansOlsson merged 9 commits intomodelica:masterfrom
henrikt-ma:local-balance-per-type

Conversation

@henrikt-ma
Copy link
Copy Markdown
Collaborator

Fixing #3763. Opening as draft to make clear that this is not ready for merging, and so that a discussion about how to do this can be started already.

In particular, I am looking for input on which type concepts to use when defining scalar type class, that is the formal categorization used to break down the local balance counting based on type.

Note that this PR contains some language fixing commits which have also been isolated in the PR #3817, so the changes of the present PR will look much cleaner once #3817 has been merged.

@henrikt-ma henrikt-ma requested a review from HansOlsson January 27, 2026 08:13
Comment thread chapters/classes.tex Outdated
Comment thread chapters/classes.tex Outdated
Comment thread chapters/classes.tex Outdated
Comment thread chapters/classes.tex Outdated
Copy link
Copy Markdown
Collaborator

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

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

I assume it was intended to be "Ready for Review", after merging the other one, right?

Looks good overall.
However, there are some minor comments.

@HansOlsson HansOlsson added this to the 2026-February milestone Feb 4, 2026
@HansOlsson
Copy link
Copy Markdown
Collaborator

Language group: Will be a clear separation integer/enumeration; so cannot write an equation with inverse for that (example to be given).
In the worst case we would need to merge these types, but hopefully not needed.

@MarkusOlssonModelon
Copy link
Copy Markdown
Collaborator

Here is an example where separating integers/enumerations would break a currently working model:

model IntEnumExample
    type E = enumeration(A, B);
    function intToE
        input Integer i;
        output E e /*= E(i)*/;
    protected
        E values[:] = {E.A, E.B};
    algorithm
        e := values[i];
        annotation(Inline=false, inverse(i = eToInt(e)));
    end intToE;
    function eToInt
        input E e;
        output Integer i = Integer(e);
    algorithm
        annotation(Inline=false, inverse(e = intToE(i)));
    end eToInt;

    input Integer i(min=1, max=2, start=1);
    E e;
equation
    i = eToInt(e);
end IntEnumExample;

This model currently compiles and simulates in Modelon Impact. But it would not be valid with the proposed type separation, the only unknown variable has type E and the only equation has type Integer.

@henrikt-ma
Copy link
Copy Markdown
Collaborator Author

henrikt-ma commented Feb 6, 2026

This model currently compiles and simulates in Modelon Impact. But it would not be valid with the proposed type separation, the only unknown variable has type E and the only equation has type Integer.

SystemModeler does not accept the model based on the following rule in https://specification.modelica.org/master/modelica-dae-representation.html:

The key difference between the two groups of discrete-time variables $z$ and $m$ here is how they are determined.
The interpretation of the solved form of \eqref{eq:dae-discrete-valued} is that given values for everything else, there is a closed-form solution for $m$ in the form of a sequence of assignments to each of the variables of $m$ in turn – there must be no cyclic dependencies between the equations used to solve for $m$.
Further, each of the original model equations behind \eqref{eq:dae-discrete-valued} must be given in almost solved form:

  • Non-Integer equations at most requiring flipping sides of the equation to obtain the used assignment form.

@HansOlsson
Copy link
Copy Markdown
Collaborator

Dymola doesn't accept it either.

@MarkusOlssonModelon
Copy link
Copy Markdown
Collaborator

This model currently compiles and simulates in Modelon Impact. But it would not be valid with the proposed type separation, the only unknown variable has type E and the only equation has type Integer.

SystemModeler does not accept the model based on the following rule in https://specification.modelica.org/master/modelica-dae-representation.html:

The key difference between the two groups of discrete-time variables
z
and
m
here is how they are determined.
The interpretation of the solved form of \eqref{eq:dae-discrete-valued} is that given values for everything else, there is a closed-form solution for
m
in the form of a sequence of assignments to each of the variables of
m
in turn – there must be no cyclic dependencies between the equations used to solve for
m
.
Further, each of the original model equations behind \eqref{eq:dae-discrete-valued} must be given in almost solved form:

  • Non-Integer equations at most requiring flipping sides of the equation to obtain the used assignment form.

You are right. In that case I have no concerns, should be fine to separate integers/enumerations.

Comment thread chapters/classes.tex Outdated
Good enough as start
@HansOlsson HansOlsson marked this pull request as ready for review March 5, 2026 15:14
Copy link
Copy Markdown
Collaborator

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

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

Ok now. Should preferably clean up the type compatible expression part.

@HansOlsson HansOlsson merged commit 0ebd9ae into modelica:master Mar 6, 2026
1 check passed
@HansOlsson HansOlsson linked an issue Mar 16, 2026 that may be closed by this pull request
@henrikt-ma henrikt-ma deleted the local-balance-per-type branch March 30, 2026 14:57
@HansOlsson HansOlsson added the M37 For pull requests merged into Modelica 3.7 label Apr 16, 2026
@HansOlsson HansOlsson added the enhancement New feature or request label Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request M37 For pull requests merged into Modelica 3.7

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local balance does not consider type

3 participants