Registry Mirror
Skip to content

Conversation

@hubertus65

Copy link
Copy Markdown
Member

Modelica.Electrical.QuasiStatic.Polyphase.Basic.MutualInductor computes its voltages with a sum reduction over time-varying Complex operator records:

v[l] = sum(j*omega*L[l, k]*i[k] for k in 1:m);

OCT, the compiler of Modelon Impact, crashes on this equation with a java.lang.StackOverflowError in FType.createRecordConstructor. The array-constructor form sum({...}) crashes the same way. As a result the component cannot be used in Impact at all, and nothing else in the MSL uses it, so the problem went unnoticed. It was found while writing a ModelicaTest coverage test for the component.

This PR writes the same sum as scalar products of the real and imaginary parts:

v[l] = j*omega*Complex(L[l, :]*i.re, L[l, :]*i.im);

The equation is mathematically identical. Verification with a 3-phase test circuit: unsymmetric source, non-uniform L matrix, unequal load resistors.

Tool Original This PR
OpenModelica 1.27.1 simulates simulates; all 644 variables agree with the original within 4.3e-13 absolute
OCT (Modelon Impact) compiler crash (StackOverflowError) simulates; same currents as OpenModelica
Dymola 2026x translates (646 unknowns/equations) translates (646 unknowns/equations)

Dymola was limited to translation by the local license size limit.

Alternatives that also compile in both OCT and OpenModelica were not chosen because they change the component's notation more. They are an explicit split into v.re/v.im and a real-valued sum(... for k in 1:m) per part. The form chosen keeps the j*omega notation of the original.

🤖 Generated with Claude Code

…ctor

The voltage equation v[l] = sum(j*omega*L[l, k]*i[k] for k in 1:m) sums
time-varying Complex operator records. OCT (Modelon Impact) crashes on it
with a StackOverflowError in record scalarization, so the component cannot
be used there at all. Write the sum as scalar products of the real and
imaginary parts instead:

  v[l] = j*omega*Complex(L[l, :]*i.re, L[l, :]*i.im);

The equation is mathematically identical. In OpenModelica 1.27.1, all 644
variables of a 3-phase test circuit (unsymmetric source, L and load) agree
with the original within 4.3e-13 absolute. OCT now compiles and simulates
the component and matches that result. Dymola 2026x translates both
versions to the same balanced system.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AHaumer

AHaumer commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Without testing: This is legal Modelica. I prefer versions that are easier to read for humans.
@hubertus65 If you think it's not legal Modelica, please cite the passage in the Modelica specification.
I'd rather consider this being worth a bug report at Modelica Impact.

@AHaumer AHaumer added the L: Complex* Issue addresses Complex, Modelica.ComplexBlocks or Modelica.ComplexMath label Nov 1, 2026
@hubertus65

Copy link
Copy Markdown
Member Author

Same argument as in the last comment:The question is what we want to achieve with the Standard Library: make it work for as many tools as possible, or make it a gate by using as many features of the Modelica language as possible. FWIW: I also filed a bug report for Modelon Impact. That doesn't mean that a rewrite that works on more tools is isn't useful. I also have made similar changes that make models work in OpenModelica. And regarding speed: there is no measurable difference.

@AHaumer

AHaumer commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Same reply as in the last comment:
I don't see that we "are using as many features of the Modelica language as possible." There are members that would perfer to use much more feature from Modelica 3.7.
In the past we distinguished in such a case: Is it a bug in MSL (in many cases not compiant with the Modelica Specification) or is it a tool issue?
It is also a question of clarity and readability for humans.
In MAP-Lib we try to test with as many tools as possible.

@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.

I neither see it as necessary nor that it improves readability.

@casella casella 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.

I also agree that readability is not really improved by this PR.

@AHaumer AHaumer added the worksforme Clarified issue label Nov 11, 2026
@AHaumer

AHaumer commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

This seems to be tool issue.
Closing with "works for me".

@AHaumer AHaumer closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: Complex* Issue addresses Complex, Modelica.ComplexBlocks or Modelica.ComplexMath worksforme Clarified issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants