Skip to content

Avoid Complex sum reduction in QuasiStatic.Polyphase.Basic.MutualInductor - #4846

Open
hubertus65 wants to merge 1 commit into
modelica:masterfrom
hubertus65:fix-QS-MutualInductor-complex-sum
Open

hubertus65 wants to merge 1 commit into
modelica:masterfrom
hubertus65:fix-QS-MutualInductor-complex-sum

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant