Opened 7 years ago

Last modified 3 years ago

#4835 assigned defect

Get Complex numbers to work without compromises

Reported by: Francesco Casella Owned by: Francesco Casella
Priority: blocker Milestone: 2.0.0
Component: *unknown* Version:
Keywords: Cc: Martin Sjölund, massimo ceraolo, dr.christian.kral@…, belen.goncer-maraver@…

Description (last modified by Francesco 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 by Francesco Casella, 7 years ago

Cc: massimo ceraolo dr.christian.kral@… added

comment:2 by Francesco Casella, 7 years ago

Description: modified (diff)

comment:3 by massimo ceraolo, 7 years ago

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 7 years ago by massimo ceraolo (previous) (diff)

comment:4 by Francesco Casella, 7 years ago

This could be related to #4965

comment:5 by Francesco Casella, 7 years ago

Description: modified (diff)

comment:6 by Francesco Casella, 6 years ago

Milestone: 1.13.01.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:7 by Francesco Casella, 6 years ago

Cc: belen.goncer-maraver@… added
Owner: changed from Adrian Pop to Francesco Casella
Priority: highblocker
Status: newassigned

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 by Francesco Casella, 6 years ago

#4793 also now solved.

comment:9 by Francesco Casella, 6 years ago

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 by Francesco Casella, 6 years ago

Milestone: 1.14.02.0.0

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

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

Add ticket #5523 to the list of open issues.

comment:12 by Francesco Casella, 6 years ago

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 Francesco Casella (previous) (diff)

comment:13 by Francesco Casella, 3 years ago

Continuing the discussion on the corresponding GitHub ticket #4835

Note: See TracTickets for help on using tickets.