Opened 10 years ago

Last modified 10 years ago

#2788 assigned defect

Enumerated types causing errors

Reported by: klenk@… Owned by: Willi Braun
Priority: high Milestone: Future
Component: Code Generation Version: trunk
Keywords: Cc: Lennart Ochel, Willi Braun

Description

When I attempt to simulate the model Test.SimpleEngine_pass from the attached file, I get the follow error. This model works with omc r21000, but does not work with the latest nightly version of omc r21957. I see similar errors in all of my models that use enumerated types.

Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
Error: Error building simulator. Build log: clang -fPIC -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o G18802.o G18802.c
clang -fPIC -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o G18802_functions.o G18802_functions.c
clang -fPIC -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o G18802_records.o G18802_records.c
clang -fPIC -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o G18802_01exo.o G18802_01exo.c
clang -fPIC -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -c -o G18802_02nls.o G18802_02nls.c
G18802_02nls.c:50:43: error: no member named 'nominal' in 'struct INTEGER_ATTRIBUTE'

nlsData->nominal[i] = $P$ATTRIBUTE$PReq.nominal;

~

G18802_02nls.c:70:43: error: no member named 'nominal' in 'struct INTEGER_ATTRIBUTE'

nlsData->nominal[i] = $P$ATTRIBUTE$PReq.nominal;

~

2 errors generated.
make: * [G18802_02nls.o] Error 1

Attachments (2)

SimpleEngine.mo (2.4 KB ) - added by anonymous 10 years ago.
Test.SimpleEngine_pass.Req.png (45.6 KB ) - added by Lennart Ochel 10 years ago.

Download all attachments as: .zip

Change History (16)

by anonymous, 10 years ago

Attachment: SimpleEngine.mo added

comment:1 by Martin Sjölund, 10 years ago

Cc: Lennart Ochel Willi Braun added
Component: UnknownCode Generation
Owner: changed from somebody to Lennart Ochel

comment:2 by Lennart Ochel, 10 years ago

Owner: changed from Lennart Ochel to Willi Braun
Status: newassigned

Yes, you are right. The models worked in r21000 because no nonlinear systems are generated. Now, there are some nonlinear systems with enumeration types as iteration variables. That’s a bit strange and sounds not that wise. Probably, there should be no such nonlinear systems.

comment:3 by Lennart Ochel, 10 years ago

Owner: changed from Willi Braun to Vitalij Ruge

I did some analysis and figured out that the issue was introduced in r21426.

comment:4 by Lennart Ochel, 10 years ago

Owner: changed from Vitalij Ruge to Lennart Ochel
Status: assignedaccepted

I get your models working again, by partially reverting the changes from r21426:

  • Compiler/BackEnd/ExpressionSolve.mo

     
    9696    local
    9797      DAE.Exp rhs,lhs,res,e1,e2,e3,crexp;
    9898      DAE.ComponentRef cr,cr1;
    99       list<DAE.Statement> asserts,asserts1;
     99      list<DAE.Statement> asserts,asserts1,asserts2;
    100100/*
    101101    case(_,_,_,_) // FOR DEBBUGING...
    102102      equation
     
    115115      then
    116116        (res,asserts);
    117117
     118    case (_,DAE.IFEXP(e1,e2,e3),_,_)
     119      equation
     120        (lhs,asserts) = solve_work(inExp1,e2,inExp3,linearExps);
     121        (rhs,asserts1) = solve_work(inExp1,e3,inExp3,linearExps);
     122        (res,_) = ExpressionSimplify.simplify1(DAE.IFEXP(e1,lhs,rhs));
     123        asserts2 = listAppend(asserts,asserts1);
     124      then
     125        (res,asserts2);
     126
     127    case (DAE.IFEXP(e1,e2,e3),_,_,_)
     128      equation
     129        (lhs,asserts) = solve_work(e2,inExp2,inExp3,linearExps);
     130        (rhs,asserts1) = solve_work(e3,inExp2,inExp3,linearExps);
     131        (res,_) = ExpressionSimplify.simplify1(DAE.IFEXP(e1,lhs,rhs));
     132        asserts2 = listAppend(asserts,asserts1);
     133      then
     134        (res,asserts2);
     135
    118136    // solving linear equation system using newton iteration ( converges directly )
    119137    case (_,_,DAE.CREF(componentRef = _),_)
    120138      equation

I will check it in if this will not break any test from the test suite.

Last edited 10 years ago by Lennart Ochel (previous) (diff)

comment:5 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: acceptedclosed

Vitalij, is there any good reason for the changes I reverted with r21963? Otherwise, this is fixed with that r21963. :-)

Last edited 10 years ago by Lennart Ochel (previous) (diff)

comment:6 by Lennart Ochel, 10 years ago

I added the tests from SimpleEngine.mo to the test suite in r21964.

comment:7 by Vitalij Ruge, 10 years ago

Resolution: fixed
Status: closedreopened

Lennart,

you can try
e.g.

model foo
  Real y1;
equation
  2*y1+time = (if y1 < 0.5 then y1 + 3 else y1 + 5);
end foo;

bevor and after you changes.

After you commit we get the wrong soulution

  RELATIONHYSTERESIS(tmp1, $Py1, 0.5, 0, Less);
  $Py1 = (tmp1?(3.0 - time):(5.0 - time)); //y1 = f(y1) 

comment:8 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: reopenedclosed

Well, in that case your fix from r21426 was not good enough ;-). I still consider this ticket as fixed and you should try to find a better fix for your model above.
BTW: Please, add a test to the test suite once it is working.

comment:9 by Vitalij Ruge, 10 years ago

Resolution: fixed
Status: closedreopened

The solution of SimpleEngine.mo is wrong!

 Req = if Req == Test.SimpleEngine_pass.Requirement.success or (-the_model_under_test.damper1.w_rel) > desired_velocity then Test.SimpleEngine_pass.Requirement.success else Test.SimpleEngine_pass.Requirement.unknown

We get as solution the Req = f(Req), which is still a nonlinear loop and not the soultion, because left and right side depennds on Req.
My fix worked for this good enough!

Last edited 10 years ago by Vitalij Ruge (previous) (diff)

comment:10 by Lennart Ochel, 10 years ago

Owner: changed from Lennart Ochel to Willi Braun
Status: reopenedassigned

Okay, Vitalij is right. Your model worked in accident and the solution was wrong. Now it generates the correct algebraic loop that is a bit tricky to solve. Nevertheless, there should be no code generation issue.

I reverted the previous commit in r21966 and added the foo test instead of the SimpleEngine test.

comment:11 by Bill Janssen, 10 years ago

This was bothering us in Friday's nightly build. r21946.

Why is there no code generation issue? Integer variables do not have an attribute called "nominal". Yet code is being generated that references this attribute.

comment:12 by Lennart Ochel, 10 years ago

Sorry, I expressed myself badly:
The nonlinear equation from your model is not supported by OpenModelica (and probably most other Modelica Tools as well). The reason is that it needs to have an integer (or enumeration) variable as iteration variable.
Anyway, the code generation should not fail in this strange manner. A solution would be to cache those systems during the symbolic transformation and before doing code generation at all. There we could introduce a traceable error message.

If there will be support for such systems can wbraun tell you. That's why I put him in to this discussion.

I am not sure what you want to model. But you can break the loop using the pre-operator like the following:

  equation
    if pre(Req) == Requirement.success or the_model_under_test.inertia1.w > desired_velocity then
      Req = Requirement.success;
    else
      Req = Requirement.unknown;
    end if;
  end SimpleEngine_fail;

If this fits still your requirement, it would solve your issues.

Last edited 10 years ago by Lennart Ochel (previous) (diff)

comment:13 by Martin Sjölund, 10 years ago

Well... A non-linear system with enumeration types should be generated as a mixed discrete/continuous nonlinear system. Not a regular nonlinear system. And just as we do for Integers in a mixed system, an error message should be generated saying we only support Boolean mixed systems.

I guess anyway.

comment:14 by Lennart Ochel, 10 years ago

If there is support for boolean systems, it should be easy to extend the approach to support (small) enumerations as well.

by Lennart Ochel, 10 years ago

Note: See TracTickets for help on using tickets.