#4419 closed defect (fixed)
Bug in simplification of rem() or div()
Reported by: | Henning Kiel | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | blocker | Milestone: | 1.12.0 |
Component: | Code Generation | Version: | v1.12.0 |
Keywords: | Cc: | Martin Sjölund, Adrian Pop, Francesco Casella |
Description
These two models behave wrong (and even differently):
model test1 Real x(start=0,fixed=true); Real y1,y2; equation der(x)=10; y1 = rem(x,2); y2 = rem(x+1,2); end test1;
model test2 Real x(start=0,fixed=true); Real y2; equation der(x)=10; y2 = rem(x+1,2); end test2;
Model test1 shows sawtooth, but not in the correct value range of 0..2, but in 1..3 for y2
.
Model test2 does not show any sawtooth for y2
, it is just plain ramp x+1
.
Also the flattened code is not valid Modelica x + -2.0
instantiateModel(test1)
"class test1 Real x(start = 0.0, fixed = true); Real y1; Real y2; equation der(x) = 10.0; y1 = x + -2.0 * div(x, 2.0); y2 = 1.0 + x + -2.0 * div(1.0 + x, 2.0); end test1; "
I think that simplification does wrong things. The (syntactically fixed) model from instantiateModel(test1) is also simulated wrong, so maybe the problem lies within div
simplifications.
Change History (6)
comment:1 by , 8 years ago
Cc: | added |
---|
comment:2 by , 8 years ago
comment:3 by , 8 years ago
Component: | Backend → Code Generation |
---|---|
Status: | new → accepted |
Thanks for this very good report. I will fix the issue.
comment:4 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Fixed with OMCompiler#1655.
comment:6 by , 8 years ago
Replying to hkiel:
@lochel Can you add a test case for this?
Test added with OpenModelica-testsuite#640.
This seems to be a problem with zero crossing detection in
div()
.This model behaves wrong:
this model behaves correct using
noEvent()
around thediv()
:However, adding
noEvent()
around therem()
in the initial problem does not fix it. It even makes things look worse...