Opened 8 years ago

Closed 6 years ago

#4297 closed defect (fixed)

Sum of complex quantities cannot be handled

Reported by: dr.christian.kral@… Owned by: Per Östlund
Priority: high Milestone: 1.14.0
Component: New Instantiation Version:
Keywords: Cc: Adeel Asghar

Description

Please consider the attached example and check model MutualInductor. Apparently there occurs an issue with the sum of complex quantities in line 67. The following error is caused:

[MutualInductanceTesting: 67:7-67:52]: 
Expected a reduction function with type signature 
('A,'B) => 'B, but got .sum<function>() => #NORETCALL#.

A similar implementation is made in Modelica.Electrical.MultiPhase.Basic.MutualInductor with real quantities -- not causing such a problem.

However this issue was caused around the implementation of the following Modelica tickets:

I used

OMEdit 1.12.0~dev-219-g62f7633
Connected to OpenModelica 1.12.0~dev-474-gbd934af
Linux Mint 18.1 64 bit

Attachments (1)

MutualInductanceTesting.mo (5.9 KB ) - added by Christian Kral <dr.christian.kral@…> 8 years ago.
Package demonstrating issue of sum of complex quantities

Download all attachments as: .zip

Change History (12)

by Christian Kral <dr.christian.kral@…>, 8 years ago

Attachment: MutualInductanceTesting.mo added

Package demonstrating issue of sum of complex quantities

comment:1 by Adeel Asghar, 8 years ago

Component: OMEditCode Generation
Owner: changed from Adeel Asghar to Mahder Alemseged Gebremedhin
Status: newassigned

comment:2 by Francesco Casella, 6 years ago

Component: Code GenerationNew Instantiation
Milestone: Future2.0.0

I checked this model with the new front-end -d=newInst using OMC v1.13.0-dev-1096-g6770e6300. I currently get this error:

[1] 20:02:03 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo: 1107:9-1107:121]: Internal error NFTyping.typeExp got unknown expression: {1, 2, 3, 4}

I guess this issue should eventually be fixed in the new front-end.

comment:3 by Francesco Casella, 6 years ago

Owner: changed from Mahder Alemseged Gebremedhin to Francesco Casella

I just opened #5277 on the specific issue with the new front-end. When that is fixed, please try to run this test case with -d=newInst and report.

comment:4 by Francesco Casella, 6 years ago

Quoting @perost in ticket:5277#comment:4:

This is based on 10.3.4.1 in the Modelica specification that explicitly says that the argument of a sum reduction must be an Integer or Real expression.

One might expect that the reduction operators would work on operator records with the appropriate operator too, but this is not specified anywhere.

This has already been addressed in Modelica 3.5, see ticket #1897 of the Modelica issue tracker. The resolution was to allow operator records defining '+' and '0' in sum() reduction expressions.

I did quickly check what would happen if the NF actually allowed it, and the model actually passed the backend but failed during compilation since I didn't change the fold expression we generate (i.e. it was still trying to use + instead of the '+'-operator from Complex).

Since there is a user requirement from Christian to have this feature, and this has already been decided upon by the MAP-LANG group and will appear in Modelica 3.5, I would suggest you allow this, and also change the fold expression, so that the following test case works:

model M
  Complex z[3];
  Complex s1 = sum(z);
  Complex s2 = sum(z[i] for i in 1:2);
  Complex s3 = sum(z[i]*z[i] for i in 1:2);
equation
  z[1] = Complex(1);
  z[2] = Complex(2,3);
  z[3] = Complex(0,1);
end M;

comment:5 by Francesco Casella, 6 years ago

Milestone: 2.0.01.14.0
Owner: changed from Francesco Casella to Per Östlund

@perost, can you please go ahead with the suggestion of comment:4?

Thanks!

Francesco

comment:6 by Per Östlund, 6 years ago

Resolution: fixed
Status: assignedclosed

Fixed in 0331720d.

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

Resolution: fixed
Status: closedreopened

I tested the originally attached example MutualInductanceTesting.MutualInductorTest using the current version 3.2.3+build.2~5~g2556186~om2-1 of the Modelica Standard Library (see #5347).

I tried to simulate the example with -d=newInst but the compilation failed, showing the following error message:

[1] 16:23:05 Translation Error
[MutualInductanceTesting: 67:7-67:52]: Expected a reduction function with type signature ('A,'B) => 'B, but got .sum<function>() => #NORETCALL#.

[2] 16:23:05 Translation Error
Error occurred while flattening model MutualInductanceTesting.MutualInductorTest

What is the reason for failing the simulation?

  1. The issue is not fully fixed
  2. The fixed issue is not implemented in my nightly build version of OpenModelica Connected to OpenModelica 1.14.0~dev-26494-g4d4d809
  3. I am missing another simulation flag to be used which I am not aware of

in reply to:  7 comment:8 by Per Östlund, 6 years ago

Replying to Christian Kral <dr.christian.kral@…>:

What is the reason for failing the simulation?

  1. The issue is not fully fixed
  2. The fixed issue is not implemented in my nightly build version of OpenModelica Connected to OpenModelica 1.14.0~dev-26494-g4d4d809
  3. I am missing another simulation flag to be used which I am not aware of

The issue seems to be d: you're not actually using the NF. The error message you get is specific to the OF, the NF will never print that particular error. If you're using OMEdit you should just need to turn on the "Enable experimental new instantiation phase" in Options->Simulation.

comment:9 by Francesco Casella, 6 years ago

Cc: Adeel Asghar added

Which also suggests that we should change the text of that option to

"Enable new front-end"

which is no longer experimental, and also known by that name since more than two years.

@adeas31, could you do that?

in reply to:  7 comment:10 by Christian Kral <dr.christian.kral@…>, 6 years ago

Replying to Christian Kral <dr.christian.kral@…>:

I tested the originally attached example MutualInductanceTesting.MutualInductorTest using the current version 3.2.3+build.2~5~g2556186~om2-1 of the Modelica Standard Library (see #5347).

I tried to simulate the example with -d=newInst but the compilation failed, showing the following error message:

After switching to the new intantiation phase on OpenModelica, this issue does not occur any more. So this ticket can be closed from my point of view.

comment:11 by Francesco Casella, 6 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.