Opened 6 years ago

Last modified 2 years ago

#4835 assigned defect

Get Complex numbers to work without compromises

Reported by: casella Owned by: casella
Priority: blocker Milestone: 2.0.0
Component: *unknown* Version:
Keywords: Cc: sjoelund.se, ceraolo, dr.christian.kral@…, belen.goncer-maraver@…

Description (last modified by casella)

Complex numbers are increasingly used in Modelica, particularly for power system models. They are used by Modelica.Electrical.QuasiStationary, and also by other libraries being developed for electro-mechanical modelling of power systems.

OMC supports complex numbers, but there are still some issue that prevents their full, uncompromised use. This ticket collects all of them in the attempt of solving the pending problems soon.

In most, possibly all, cases, the best strategy to solve equations involving Complex variables is to turn them into scalar Real equations and then apply all possible symbolic simplifications. This is particularly important when Complex number that happen to be purely real or imaginary are used.

In simple cases, this already happens. If you compile this model

model TestComplex
  Complex z1, z2;
equation
  z1+z2 = Complex(0);
  z2 = Complex(1,2);
end TestComplex;

the record equations are turned into scalar equations and solved symbolically, so eventually z1 and z2 are evaluated at initialization, because they are constant.

Unfortunately, in some cases this does not happen, for reasons that need to be investigated. In #4354 and #4808 this issue leads to problems solving otherwise trivial equations, in #4157 it leads to problems with equations in when statements. #4611 is a slightly more involved case, where arrays of Complex constructors are involved. #4973 has a test case for the new front-end, while #4974 shows an issue with the missing inlining of ComplexMath functions.

The code generation for algorithms involving Complex numbers needs to be fixed, see #4055.

There are also some issues with Complex equations and removeSimpleEquations, see #4793.

Last, but not least, the sum of Complex numbers should be supported, see #4297.

Change History (13)

comment:1 Changed 6 years ago by casella

  • Cc ceraolo dr.christian.kral@… added

comment:2 Changed 6 years ago by casella

  • Description modified (diff)

comment:3 Changed 6 years ago by ceraolo

Another case of Complex number analysis failure, not covered by the tickets mentioned in this ticket's description:

model ComplexTest1
  parameter Integer n = 2;
  Real R[n,n]=ones(n,n);
  Real X[n,n]=ones(n,n);
  Complex Z[n,n];
  constant Complex j = Complex(0.0, 1.0);
equation 
    Z = R + j*X;
end ComplexTest1;

Checking produces the following error message:

[1] 09:46:43 Translation Error
[ComplexTest1: 8:5-8:16]: Failed to elaborate expression: R + j * X.

(checked with OpenModelica 1.13.0~dev-1028-g72f3421 for Linux)

I know that a good workaround exists:

model ComplexTest1
  parameter Integer n = 2;
  Real R[n,n]=ones(n,n);
  Real X[n,n]=ones(n,n);
  Complex Z[n,n];
  constant Complex j = Complex(0.0, 1.0);
equation 
    Z=Complex(R,X);
end ComplexTest1;

but here we are discussing of getting Complex numbers to work "without compromises".

Note that Z=R+jX works in Dymola, while Z=Complex(R,X) does not there. So none of the two ways is able to work in both tools.

Last edited 6 years ago by ceraolo (previous) (diff)

comment:4 Changed 6 years ago by casella

This could be related to #4965

comment:5 Changed 6 years ago by casella

  • Description modified (diff)

comment:6 Changed 5 years ago by casella

  • Milestone changed from 1.13.0 to 1.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:7 Changed 5 years ago by casella

  • Cc belen.goncer-maraver@… added
  • Owner changed from adrpo to casella
  • Priority changed from high to blocker
  • Status changed from new to assigned

We are making good progress in supporting Complex numbers with the new front-end. As of today, issues #4055, #4354, #4793, #4808, and #4973 have been solved, while #4157, #4611, and #4297 are still open.

We can tentatively set the goal to resolve all these issues with the new front-end for the 1.14.0 release (see roadmap), where the new front-end use will still be optional, but reliable enough for most models to work.

comment:8 Changed 5 years ago by casella

#4793 also now solved.

comment:9 Changed 5 years ago by casella

Issues still open as of 10/05/2019:

  • #4157 backend issue with Complex equations in when statements)
  • #4297 frontend issue with sum() of Complex numbers
  • #4611 backend issue with functions taking Real arrays as inputs and returning Complex arrays as outputs

In fact, #2387, involving array products of Complex numbers should also be fixed, though apparently nobody needs this feature for applications at the moment.

comment:10 Changed 5 years ago by casella

  • Milestone changed from 1.14.0 to 2.0.0

Some of the remaining issues require non-trivial work, rescheduling to 2.0.0

comment:11 Changed 5 years ago by Christian Kral <dr.christian.kral@…>

Add ticket #5523 to the list of open issues.

comment:12 Changed 5 years ago by casella

Issues still open as of 16/09/2020

  • #2387 invoving array products of Complex numbers (low priority)
  • #4611 backend issue with functions taking Real arrays as inputs and returning Complex arrays as outputs
  • #5523 issue with products of function outputs involving arrays of Complex
Last edited 4 years ago by casella (previous) (diff)

comment:13 Changed 2 years ago by casella

Continuing the discussion on the corresponding GitHub ticket #4835

Note: See TracTickets for help on using tickets.