modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
95 stars 41 forks source link

when equations in algebraic loop? #3498

Open gkurzbach opened 2 months ago

gkurzbach commented 2 months ago

Is it allowed for when equations to be part of an algebraic loop? Following model leads to an error in Dymola but not in OMEdit:

model algebraicLoop 
    Real x;
    Real y(start=0.5,fixed=true);
    equation
        x = time - y;
        when time>0.5 then
            y = -x/2;
        end when;
end algebraicLoop;

I have not found any statement to this regard in the specification. Please clarify.

HansOlsson commented 2 months ago

It seems that it is allowed by the specification (there is even one example of it) , but that:

The when-equations are even designed to make it clear how such cases are handled. That's why you cannot write:

                x = time - y;
        when time>0.5 then
            y + x/2 = 0;
        end when;

because it wouldn't make it clear which variables are updated as part of the when and which ones aren't.

HansOlsson commented 2 months ago

I believe the impure part can be handled in #3499 - The remaining part is thus just to state that there is nothing special with when-clauses and they can be part of systems of equations.

henrikt-ma commented 2 months ago

For what it's worth, System Modeler also builds and simulates this without any complaint.

HansOlsson commented 1 month ago

Dymola 2024x Refresh 1 also builds and simulates this without any complaint.

HansOlsson commented 4 weeks ago

I thus believe it was just a tool-issue, but it might be that the specification should be clearer.

HansOlsson commented 4 weeks ago

Language group: Agreement