Opened 4 years ago

Closed 4 years ago

#6257 closed defect (fixed)

Issue with ThermoSysPro

Reported by: Francesco Casella Owned by: Andreas Heuermann
Priority: high Milestone: 1.17.0
Component: Backend Version: 1.16.0
Keywords: Cc: daniel.bouskela@…

Description (last modified by Francesco Casella)

The attached model doesn't work in ThermoSysPro 3.2. daniel.bouskela@… reports the following error:

post-optimization module wrapFunctionCalls (simulation) failed

Attachments (2)

Reconciled_NewDataReconciliationSimpleTests_TSP_FourFlows5.mo (13.8 KB ) - added by Francesco Casella 4 years ago.
results_new.mat (655.0 KB ) - added by Andreas Heuermann 4 years ago.
Results with fixed OMC

Download all attachments as: .zip

Change History (20)

comment:1 by Francesco Casella, 4 years ago

Description: modified (diff)

comment:2 by Francesco Casella, 4 years ago

I tried with the latest nightly build, but I actually get a different issue

[1] 13:15:49 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo: 342:7-342:48]: 
Internal error BackendDAETransform.analyseStrongComponentBlock failed
variables:
  singularPressureLoss4_C1_P
  singularPressureLoss4_C2_P
equations:
  singularPressureLoss4_Pm = 0.5 * (singularPressureLoss4_C1_P + singularPressureLoss4_C2_P)
  singularPressureLoss4_C1_P - singularPressureLoss4_C2_P = singularPressureLoss4_deltaP

[2] 13:15:49 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo: 346:7-346:90]: Internal error function analyseStrongComponentBlock failed

[3] 13:15:49 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo: 196:5-196:89]: Internal error function analyseStrongComponentScalar failed

[4] 13:15:49 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo: 107:7-107:113]: Internal error function strongComponentsScalar failed (sorting strong components)

[5] 13:15:49 Translation Error
[C:/dev/OM64bit/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo: 7903:5-7903:89]: Internal error Transformation module sort components failed

comment:3 by Francesco Casella, 4 years ago

This looks quite similar to the issue reported in https://github.com/OpenModelica/OpenModelica/pull/6991 PR #6991, I wonder if some change was recently introduced that broke some stuff, so I don't see the same error that @daniel sees, I guess he's using 1.16.1. Or maybe I have some weird setting in OMEdit I'm not aware of.

@AnHeuermann, mind having a look?

Thanks!

Version 0, edited 4 years ago by Francesco Casella (next)

comment:4 by Andreas Heuermann, 4 years ago

So I tried with ThermoSysPro from https://github.com/ThermoSysPro/v3.2

loadFile("/some/path/To/ThermoSysPro/package.mo"); getErrorString();
loadFile("Reconciled_NewDataReconciliationSimpleTests_TSP_FourFlows5.mo"); getErrorString();
setCommandLineOptions("-d=newInst"); getErrorString();
buildModel(Reconciled_NewDataReconciliationSimpleTests_TSP_FourFlows5); getErrorString();

and got the same error message as daniel.bouskela:

"Notification: ThermoSysPro requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Error: post-optimization module wrapFunctionCalls (simulation) failed.
"

I'll dig into this.

EDIT:
I'm using latest OMCompiler v1.17.0-dev.232+g990310b9f5 on Ubuntu 20.04.

Last edited 4 years ago by Andreas Heuermann (previous) (diff)

comment:5 by Andreas Heuermann, 4 years ago

Of course the error is a missing else case in a match expression. I'll create a PR which will issue an error at the correct location.

And now I have to find the cause for the error.

My PR: https://github.com/OpenModelica/OpenModelica/pull/6999

comment:6 by Adrian Pop, 4 years ago

Windows had 133 test failures 10 days ago:
https://test.openmodelica.org/jenkins/job/Windows/job/OM_Win/987/
and then the next build went up to 183:
https://test.openmodelica.org/jenkins/job/Windows/job/OM_Win/988/
Some of the messages in the new failures are similar to what I see in this ticket.
So it might be this?
https://github.com/OpenModelica/OpenModelica/commit/34a1da0a24cb60c363e323d2d71206305ebcd5fc

comment:7 by Mahder Alemseged Gebremedhin, 4 years ago

@AnHeuermann Can you try adding

#define HAVE_LAPACK

to Compiler/runtime/omc_config.h and compile omc and try again.

Let's see if that is the issue.

Last edited 4 years ago by Mahder Alemseged Gebremedhin (previous) (diff)

comment:8 by Andreas Heuermann, 4 years ago

@mahge Currently I'm on Linux, that's a Windows issue, right? Also my Windows won't build at the moment.

comment:9 by Andreas Heuermann, 4 years ago

We have a cse-equation:

(ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat(staticDrum1_lsat_P, staticDrum1_lsat_T, staticDrum1_lsat_rho, staticDrum1_lsat_h, staticDrum1_lsat.cp, staticDrum1_lsat.pt, staticDrum1_lsat.cv), ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat(staticDrum1_vsat_P, staticDrum1_vsat_T, staticDrum1_vsat_rho, staticDrum1_vsat_h, staticDrum1_vsat.cp, staticDrum1_vsat.pt, staticDrum1_vsat.cv)) = ThermoSysPro.Properties.WaterSteam.IF97.Water_sat_P(staticDrum1_P)

coming from

(staticDrum1_lsat, staticDrum1_vsat) = ThermoSysPro.Properties.WaterSteam.IF97.Water_sat_P(staticDrum1_P);

wrapFunctionCalls is struggling with it.

I dumped the expression and the record and it looks kinda strange:

--> cse-equation: (ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat(staticDrum1_lsat_P, staticDrum1_lsat_T, staticDrum1_lsat_rho, staticDrum1_lsat_h, staticDrum1_lsat.cp, staticDrum1_lsat.pt, staticDrum1_lsat.cv), ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat(staticDrum1_vsat_P, staticDrum1_vsat_T, staticDrum1_vsat_rho, staticDrum1_vsat_h, staticDrum1_vsat.cp, staticDrum1_vsat.pt, staticDrum1_vsat.cv)) = ThermoSysPro.Properties.WaterSteam.IF97.Water_sat_P(staticDrum1_P)
Left expression:
TUPLE    |CALL ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
   |   |CREF staticDrum1_lsat_P [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat_T [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat_rho [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat_h [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .cp [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .pt [Real] CREFTYPE:Real
   |   |CREF staticDrum1_lsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .cv [Real] CREFTYPE:Real
   |CALL ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
   |   |CREF staticDrum1_vsat_P [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat_T [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat_rho [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat_h [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .cp [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .pt [Real] CREFTYPE:Real
   |   |CREF staticDrum1_vsat [record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat
  Real P;
  Real T;
  Real rho;
  Real h;
  Real cp;
  Real pt;
  Real cv;
end ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat;] .cv [Real] CREFTYPE:Real
Right expression:
CALL ThermoSysPro.Properties.WaterSteam.IF97.Water_sat_P
   |CREF staticDrum1_P [Real] CREFTYPE:Real

I think the record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat is containing a record of type ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat as 5th element but that should be Modelica.SIunits.SpecificHeatCapacity cp??
Not sure if the dump is correct, though.

in reply to:  8 comment:10 by Mahder Alemseged Gebremedhin, 4 years ago

Replying to AnHeuermann:

@mahge Currently I'm on Linux, that's a Windows issue, right? Also my Windows won't build at the moment.

Yes. I thought the errors were for Windows. If the problem is not on Windows you can ignore it.

comment:11 by Andreas Heuermann, 4 years ago

I think the record ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat is containing a record of type ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat as 5th element but that should be Modelica.SIunits.SpecificHeatCapacity cp??
Not sure if the dump is correct, though.

Never mind, the dump was just different than I thought.

The basic problem:
In CommonSubExpressions.mo in function isEquationRedundant_flatten we need an additional case

case BackendDAE.COMPLEX_EQUATION(_, exp1 as DAE.TUPLE(lhs), exp2 as DAE.CALL(), _, _)

But I'm not 100% sure how to handle that case.

This is basically an equation of the form TUPLE(a,b,c,d) = CALL(e). I need a variable cse1 for CALL(e) and possibly additional cse variables for a,b,c and d because they could be CALL's as well.

comment:12 by Andreas Heuermann, 4 years ago

I managed to simplify the test and create a smaller example to reproduce the error:

model simplified
  parameter Real P = 1450000;
  ThermoSysPro.Properties.WaterSteam.Common.PropThermoSat staticDrum1_lsat, staticDrum1_vsat;
  Real staticDrum1_vsat_P = staticDrum1_vsat.P;  // Remove me to simulate correctly
equation
  (staticDrum1_lsat, staticDrum1_vsat) = ThermoSysPro.Properties.WaterSteam.IF97.Water_sat_P(P);
end simplified;

If all alias variables from record elements are removed the model will simulate just fine.

comment:13 by Andreas Heuermann, 4 years ago

And another one:

loadString("
model simplified
  parameter Real inputParam = 1;
  record ARecord
    Real var1;
    Real var2;
  end ARecord;
  ARecord recordLeft, recordRight;
  Real recordLeft_var1 = recordLeft.var1;  // Remove me to simulate correctly
  function myFunc
    input Real inp;
    output ARecord leftOutput;
    output ARecord rightOutput;
  algorithm
    leftOutput := ARecord(1,2);
    rightOutput := ARecord(3,4);
  end myFunc;
equation
  (recordLeft, recordRight) = myFunc(inputParam);
end simplified;
"); getErrorString();
setCommandLineOptions("-d=newInst,dumpCSE_verbose"); getErrorString();
buildModel(simplified); getErrorString();

This should simplify debugging immensely.

comment:14 by Francesco Casella, 4 years ago

I confirm I can reproduce the issue with the .mos script.

by Andreas Heuermann, 4 years ago

Attachment: results_new.mat added

Results with fixed OMC

comment:15 by Andreas Heuermann, 4 years ago

Okay, I got something and for my newest model simplified I'm getting the correct solution 1,2,3,4. So there is noooo way this could ever fail *strong sarcasm*.

I pushed the changes to my PR.

I uploaded the new results https://trac.openmodelica.org/OpenModelica/attachment/ticket/6257/results_new.mat

Last edited 4 years ago by Andreas Heuermann (previous) (diff)

in reply to:  12 comment:16 by Andreas Heuermann, 4 years ago

I used the model from comment 12 to validate my results. They seem to be correct.

comment:17 by Francesco Casella, 4 years ago

Very good!

@AnHeuermann, please notify here when PR 6999 is merged in.

@daniel, if you are on Windows, on the following day you can download the nightly build and check if all works fine. If you are on Linux, we have some trouble with the nightly builds, I hope it gets resolved soon.

comment:18 by Andreas Heuermann, 4 years ago

Resolution: fixed
Status: newclosed

https://github.com/OpenModelica/OpenModelica/pull/6999 is now merged.

Set ticket to solved.
@daniel If the problem is not solved for you please reopen this ticket or open a new one.

Note: See TracTickets for help on using tickets.