Opened 10 years ago
Last modified 10 years ago
#2788 assigned defect
Enumerated types causing errors
Reported by: | 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)
Change History (16)
by , 10 years ago
Attachment: | SimpleEngine.mo added |
---|
comment:1 by , 10 years ago
Cc: | added |
---|---|
Component: | Unknown → Code Generation |
Owner: | changed from | to
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
Owner: | changed from | to
---|
I did some analysis and figured out that the issue was introduced in r21426.
comment:4 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | assigned → accepted |
I get your models working again, by partially reverting the changes from r21426:
-
Compiler/BackEnd/ExpressionSolve.mo
96 96 local 97 97 DAE.Exp rhs,lhs,res,e1,e2,e3,crexp; 98 98 DAE.ComponentRef cr,cr1; 99 list<DAE.Statement> asserts,asserts1 ;99 list<DAE.Statement> asserts,asserts1,asserts2; 100 100 /* 101 101 case(_,_,_,_) // FOR DEBBUGING... 102 102 equation … … 115 115 then 116 116 (res,asserts); 117 117 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 118 136 // solving linear equation system using newton iteration ( converges directly ) 119 137 case (_,_,DAE.CREF(componentRef = _),_) 120 138 equation
I will check it in if this will not break any test from the test suite.
comment:5 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
comment:7 by , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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 , 10 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
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 , 10 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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!
comment:10 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | reopened → assigned |
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 , 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 , 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.
comment:13 by , 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 , 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 , 10 years ago
Attachment: | Test.SimpleEngine_pass.Req.png added |
---|
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.