Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#2563 closed defect (fixed)

Problem with PFPlusExt Pantelides algorithm

Reported by: casella Owned by: lochel
Priority: critical Milestone: 1.9.4
Component: Backend Version: trunk
Keywords: Cc: vwaurich, ryanh@…

Description

The model ThermoPower.Examples.HRB.Simulators.OpenLoopSimulator in the testsuite generates the following errors

Error: Model is structurally singular, error found sorting equations
<...>
Error: Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

The model works fine in Dymola. There are other 10 models in the library that lead to the same error, so probably solving this one would also solve the other ones.

Also, how can I try compiling the code with other matching algorithms, either from OMEdit or from the command line?

Attachments (1)

OpenLoopSimulatorTotal.mo (801.0 KB) - added by casella 10 years ago.
Save Total file with complete definition of reduced-order model

Download all attachments as: .zip

Change History (32)

comment:1 follow-up: Changed 10 years ago by adrpo

Running omc without parameters or with +help gives you:

      +matchingAlgorithm     Sets the matching algorithm to use. See 
                              +help=optmodules for more info.
                               Valid options:
                                * BFSB
                                * DFSB
                                * MC21A
                                * PF
                                * PFPlus
                                * HK
                                * HKDW
                                * ABMP
                                * PR
                                * DFSBExt
                                * BFSBExt
                                * MC21AExt
                                * PFExt
                                * PFPlusExt
                                * HKExt
                                * HKDWExt
                                * ABMPExt
                                * PRExt

comment:2 in reply to: ↑ 1 Changed 10 years ago by casella

  • Owner changed from probably noone to lochel
  • Status changed from new to assigned

Replying to adrpo:

Running omc without parameters or with +help gives you:

      +matchingAlgorithm     Sets the matching algorithm to use. See 
                              +help=optmodules for more info.
                               Valid options:
                                * BFSB
                                * DFSB
                                * MC21A
                                * PF
                                * PFPlus
                                * HK
                                * HKDW
                                * ABMP
                                * PR
                                * DFSBExt
                                * BFSBExt
                                * MC21AExt
                                * PFExt
                                * PFPlusExt
                                * HKExt
                                * HKDWExt
                                * ABMPExt
                                * PRExt

OK. But I have been warned that the optmodules "should be applied in the correct order" and I am bit clueless about that

comment:3 Changed 10 years ago by lochel

  • Status changed from assigned to accepted

Changing the matching algorithm does not affect the opt-module at all. So you can just try it out as Adrian proposed. Anyway, I will have a look too.

Changed 10 years ago by casella

Save Total file with complete definition of reduced-order model

comment:4 Changed 10 years ago by casella

I have tried many different matching algorithms, but they all fail because of Pantelides. Unfortunately the diagnostic message is not very informative, as it just tells me that a big bunch of equations is singular, but doesn't point to any possible root cause.

I have prepared a reduced-order version of the model for easier analysis, you can get it by loading the attached file.

Please:

  • have a look at the problem
  • if possible improve the diagnostic message with more useful information for the modeller to help fix the problem

comment:5 Changed 10 years ago by casella

You may start your analysis from this other model:

ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_A

which gives this much simpler error message:

Error: Model is structurally singular, error found sorting equations 
 1: hex.dddX[1] = 0.0;
 for variables 
 hex.dddX[1,1](1)}}
Error: Internal error Transformation Module PFPlusExt index Reduction
Method Pantelides failed!

I cannot really see what's wrong with that equation.

comment:6 Changed 10 years ago by sjoelund.se

hex.dddx[1] does not exist. It seems the flattened equation: hex.dddX[1,:] = ThermoPower.Gas.Flow1DFV.Medium.density_derX(hex.gas[1].state); loses the second index when the back-end performs some transformation. I guess Lennart can pinpoint and fix it ;)

comment:7 Changed 10 years ago by lochel

This is a problem of the pre-optimization module >>inlineArrayEqn<<.

comment:8 Changed 10 years ago by lochel

The pre-opt module transforms the following equations (left) into the right ones:

hex.dddX[2,:] = {0.0} -> hex.dddX[1] = 0.0
hex.dddX[3,:] = {0.0} -> hex.dddX[1] = 0.0
hex.dddX[4,:] = {0.0} -> hex.dddX[1] = 0.0
...

Hence, the system becomes singular.

comment:9 follow-up: Changed 10 years ago by casella

I tried the following test case, which should capture all the features of the example, but it works just fine:

model TestArray
  parameter Integer N = 3;
  parameter Integer nX = 4;
  Real dddx[N, nX];
equation
  for j in 1:N loop
    dddx[j, :] = zeros(nX);
  end for;
end TestArray;

comment:10 follow-ups: Changed 10 years ago by lochel

I found a fix for the ThermoPower example, which breaks none of the test cases from the test suite. Anyway, I am not sure if it is a bad hack or a proper fix.

comment:11 in reply to: ↑ 10 Changed 10 years ago by casella

  • Cc vwaurich added; lochel removed

Replying to lochel:

I found a fix for the ThermoPower example, which breaks none of the test cases from the test suite. Anyway, I am not sure if it is a bad hack or a proper fix.

Volker, can you please have a look at that?

comment:12 in reply to: ↑ 9 ; follow-up: Changed 10 years ago by sjoelund.se

Replying to casella:

I tried the following test case, which should capture all the features of the example, but it works just fine

I would guess because zeros() is known and is simplified. I suppose it would be different if the call is a user-defined function.

comment:13 in reply to: ↑ 12 Changed 10 years ago by casella

Replying to sjoelund.se:

Replying to casella:

I tried the following test case, which should capture all the features of the example, but it works just fine

I would guess because zeros() is known and is simplified. I suppose it would be different if the call is a user-defined function.

Maybe, but in the ThermoPower models that fail to compile in the test suite, the zeros() function is used as well. This is the offending code:

  for j in 1:N loop
    if not QuasiStatic then
      cv[j] = Medium.heatCapacity_cv(gas[j].state);
      dddT[j] = Medium.density_derT_p(gas[j].state);
      dddp[j] = Medium.density_derp_T(gas[j].state);
      if nX > 0 then
        dddX[j, :] = Medium.density_derX(gas[j].state);
      end if;
    else
      // Dummy values (not needed by dynamic equations)
      cv[j] = 0;
      dddT[j] = 0;
      dddp[j] = 0;
      dddX[j, :] = zeros(nX);
    end if;
  end for;

In the case at hand, QuasiStatic==true, so the else branch is considered.

Of course your remark would apply if QuasiStatic = false.

comment:14 in reply to: ↑ 10 ; follow-up: Changed 10 years ago by lochel

Replying to lochel:

I found a fix for the ThermoPower example, which breaks none of the test cases from the test suite. Anyway, I am not sure if it is a bad hack or a proper fix.

I committed the fix in r20343. I am still not so happy with that commit, but it works at least for the model above.

comment:15 Changed 10 years ago by casella

ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_A now compiles. However, all the other models in the library that showed the reported problem don't, namely:

ThermoPower.Examples.HRB.Simulators.ClosedLoopDigitalSimulator
ThermoPower.Examples.HRB.Simulators.ClosedLoopDigitalSimulatorSimplified
ThermoPower.Examples.HRB.Simulators.ClosedLoopSimulator
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulator
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulatorSS
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulatorSimplified
ThermoPower.Examples.RankineCycle.Simulators.ClosedLoop
ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_B
ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_C

The problem is still the same: all elements of dddX[j, 1] are scalarized as dddx[1] in the equations.

comment:16 Changed 10 years ago by anonymous

I get this when I connect an ideal cell to a resistor.

model ultraboost
  Modelica.Electrical.Analog.Basic.Resistor resistor1(R = 1);
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantvoltage1(V = 1);
equation
  connect(resistor1.n,constantvoltage1.n);
  connect(constantvoltage1.p,resistor1.p);
end ultraboost;

[:0:0-0:0] Error: Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!
[:0:0-0:0] Error: Internal error pre-optimization module removeSimpleEquations failed.
[:0:0-0:0] Error: Internal error Circular Equalities Detected for Variables:
constantvoltage1.p.i
constantvoltage1.n.i


resistor1.p.i
constantvoltage1.p.i


resistor1.p.i
resistor1.n.i


comment:17 Changed 10 years ago by anonymous

I was using Openmodelica1.9.1Beta2 r19512 on Linux.

comment:18 Changed 10 years ago by adrpo

For the ultraboost model the message is correct. you're missing a ground:

model ultraboost
  Modelica.Electrical.Analog.Basic.Resistor resistor;
  Modelica.Electrical.Analog.Basic.Ground ground;
  Modelica.Electrical.Analog.Sources.ConstantVoltage constantVoltage;
equation 
  connect(constantVoltage.p, resistor.p);
  connect(ground.p, constantVoltage.n);
  connect(ground.p, resistor.n);
end ultraboost;

comment:19 in reply to: ↑ 14 ; follow-up: Changed 10 years ago by vwaurich

Replying to lochel:

Replying to lochel:

I found a fix for the ThermoPower example, which breaks none of the test cases from the test suite. Anyway, I am not sure if it is a bad hack or a proper fix.

I committed the fix in r20343. I am still not so happy with that commit, but it works at least for the model above.

I was so bold to remove your commit and added a more proper solution. The problem was in the declaration of the array. The Exp was a CREF and the concrete index of the vector is inside the ComponentRef and not in the T_ARRAY (there is only the dimension of the whole vector). Anyway, the current implementation works only for vectors. Since the remaining models contain matrices or arrays of higher dimension, they still fail. I will have a look on them but handling the various array declarations and subscript stuff is a bit puzzling.

comment:20 in reply to: ↑ 19 Changed 10 years ago by casella

Replying to vwaurich:

I was so bold to remove your commit and added a more proper solution. The problem was in the declaration of the array. The Exp was a CREF and the concrete index of the vector is inside the ComponentRef and not in the T_ARRAY (there is only the dimension of the whole vector). Anyway, the current implementation works only for vectors. Since the remaining models contain matrices or arrays of higher dimension, they still fail. I will have a look on them but handling the various array declarations and subscript stuff is a bit puzzling.

Doesn't seem to help much, the examples in HRB and RankineCycle still have the same problem (https://test.openmodelica.org/libraries/ThermoPower/BuildModelRecursive.html)

comment:21 Changed 10 years ago by vwaurich

At least a bit has improved for the models:

ThermoPower.Examples.HRB.Simulators.ClosedLoopDigitalSimulator
ThermoPower.Examples.HRB.Simulators.ClosedLoopSimulator
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulator
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulatorSS
ThermoPower.Examples.HRB.Simulators.OpenLoopSimulatorSimplified
ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_B
ThermoPower.Test.DistributedParameterComponents.TestGasFlow1DFV_C

comment:22 Changed 10 years ago by casella

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

Now I see it. It took some time for the changes to make their way down to https://test.openmodelica.org/libraries/ThermoPower/BuildModelRecursive.html

Thanks a lot, we are making good progress towards 100% support of ThermoPower!

comment:23 Changed 9 years ago by ryanh@…

  • Cc ryanh@… added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Can we re-open this ticket? It looks like the fix in r20343 was reverted in r20470. I am running into the same issue as stated above when trying to simulate some models in the OpenHydraulics library. I can attach one of them for reference if needed.

Last edited 9 years ago by adrpo (previous) (diff)

comment:24 Changed 9 years ago by ryanh@…

I'm just realizing that r20470 was actually a more proper fix for what r20343 was trying to address (the changeset wasn't referenced in the comments). Regardless, I am still running into similar issues with the OpenHydraulics library where the PFPlusExt Pantelides algorithm fails. It may be failing due to other reasons though, I get a "Internal error post-optimization module encapsulateWhenConditions failed." error message prior to the Pantelides algorithm failing.

comment:25 Changed 9 years ago by hkiel

  • Milestone changed from 1.9.1 to 1.9.3

comment:26 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.3 to 1.9.4

Moved to new milestone 1.9.4

comment:27 Changed 9 years ago by lochel

Are there still problems with PFPlusExt Pantelides algorithm?

comment:28 Changed 9 years ago by res@…

i have the same problem with modelica EnergyStoragesLibrary

comment:29 Changed 8 years ago by lochel

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

The models I've tested from this ticket are working. In the case that there are similar issues with other models (e.g. OpenHydraulics library), please open another ticket and assign it to me.

comment:30 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.4 to 1.9.4-1.9.x

Milestone renamed

comment:31 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.4-1.9.x to 1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.