Opened 7 years ago

Closed 5 years ago

#4297 closed defect (fixed)

Sum of complex quantities cannot be handled

Reported by: dr.christian.kral@… Owned by: perost
Priority: high Milestone: 1.14.0
Component: New Instantiation Version:
Keywords: Cc: adeas31

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@…> 7 years ago.
Package demonstrating issue of sum of complex quantities

Download all attachments as: .zip

Change History (12)

Changed 7 years ago by Christian Kral <dr.christian.kral@…>

Package demonstrating issue of sum of complex quantities

comment:1 Changed 7 years ago by adeas31

  • Component changed from OMEdit to Code Generation
  • Owner changed from adeas31 to mahge930
  • Status changed from new to assigned

comment:2 Changed 5 years ago by casella

  • Component changed from Code Generation to New Instantiation
  • Milestone changed from Future to 2.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 Changed 5 years ago by casella

  • Owner changed from mahge930 to 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 Changed 5 years ago by casella

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 Changed 5 years ago by casella

  • Milestone changed from 2.0.0 to 1.14.0
  • Owner changed from casella to perost

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

Thanks!

Francesco

comment:6 Changed 5 years ago by perost

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in 0331720d.

comment:7 follow-ups: Changed 5 years ago by Christian Kral <dr.christian.kral@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:8 in reply to: ↑ 7 Changed 5 years ago by perost

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 Changed 5 years ago by casella

  • Cc adeas31 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?

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

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 Changed 5 years ago by casella

  • Resolution set to fixed
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.