Opened 7 years ago
Closed 7 years ago
#4503 closed defect (fixed)
OMCompiler doesn't remove mathematical signs when flattening model + libraries
Reported by: | anonymous | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | 1.13.0 |
Component: | Frontend | Version: | |
Keywords: | Cc: |
Description
Using OMCompiler compiled from master, I'm trying to generate a flat modelica model through combination of the two following files:
-Ball_Platform_im.mo:
model Ball_Platform_im Ball_Platform Ball_Platform1; OutPutPort OutPutPort1; OutPutPort OutPutPort2; equation Ball_Platform1.y2 = OutPutPort1.vi; Ball_Platform1.y1 = OutPutPort2.vi; end Ball_Platform_im;
-Ball_Platform.mo:
class Ball_Platform parameter Real g=9.8; parameter Real m1=0.50; //platformKg parameter Real m2=0.30;//Kg parameter Real k=2; //Kg/sec Real y1(start=11),v1(start=0);//Platform Real y2(start=15),v2(start=1);//ball Real y0; discrete Real v1p,v2p; equation y0=10; //Nominal position //----------------------------------- der(y1)=v1; m1*der(v1)=if noEvent(v1<0.001 and v1>-0.001) then 0 else -m1*g-k*(y1-y0)-0.2*v1; der(y2)=v2; der(v2)=if noEvent(v2<0.001 and v2>-0.001) then 0 else -g; //----------------------------------- when y2<y1 then v1p=(m1*v1+2*m2*v2-m2*v1)/(m1+m2); v2p=(m2*v2+2*m1*v1-m1*v2)/(m1+m2); reinit(v1,v1p*0.98); reinit(v2,v2p*0.98); end when; //----------------------------------- end Ball_Platform;
using the following shell command:
$ omc /tmp/SCI_TMP_1358_LuFlNI/Ball_Platform_im.mo /tmp/SCI_TMP_1358_LuFlNI/modelica/Ball_Platform.mo --modelicaOutput --useLocalDirection --reduceTerms
which runs fine, but produces a line with side to side mathematical signs (in line under comment: "+ -0.2") that prevents further compilation.
class Ball_Platform_im parameter Real Ball_Platform1__g = 9.800000000000001; parameter Real Ball_Platform1__m1 = 0.5; parameter Real Ball_Platform1__m2 = 0.3; parameter Real Ball_Platform1__k = 2.0; Real Ball_Platform1__y1(start = 11.0); Real Ball_Platform1__v1(start = 0.0); Real Ball_Platform1__y2(start = 15.0); Real Ball_Platform1__v2(start = 1.0); Real Ball_Platform1__y0; discrete Real Ball_Platform1__v1p; discrete Real Ball_Platform1__v2p; output Real OutPutPort1__vo; Real OutPutPort1__vi; output Real OutPutPort2__vo; Real OutPutPort2__vi; equation Ball_Platform1__y0 = 10.0; der(Ball_Platform1__y1) = Ball_Platform1__v1; // Minus sign following plus sign and not isolated by parentheses Ball_Platform1__m1 * der(Ball_Platform1__v1) = if noEvent(Ball_Platform1__v1 < 0.001) and noEvent(Ball_Platform1__v1 > -0.001) then 0.0 else Ball_Platform1__k * (Ball_Platform1__y0 - Ball_Platform1__y1) + -0.2 * Ball_Platform1__v1 - Ball_Platform1__m1 * Ball_Platform1__g; der(Ball_Platform1__y2) = Ball_Platform1__v2; der(Ball_Platform1__v2) = if noEvent(Ball_Platform1__v2 < 0.001) and noEvent(Ball_Platform1__v2 > -0.001) then 0.0 else -Ball_Platform1__g; when Ball_Platform1__y2 < Ball_Platform1__y1 then Ball_Platform1__v1p = (Ball_Platform1__m1 * Ball_Platform1__v1 + Ball_Platform1__m2 * (2.0 * Ball_Platform1__v2 - Ball_Platform1__v1)) / (Ball_Platform1__m1 + Ball_Platform1__m2); Ball_Platform1__v2p = (Ball_Platform1__m2 * Ball_Platform1__v2 + Ball_Platform1__m1 * (2.0 * Ball_Platform1__v1 - Ball_Platform1__v2)) / (Ball_Platform1__m1 + Ball_Platform1__m2); reinit(Ball_Platform1__v1, 0.98 * Ball_Platform1__v1p); reinit(Ball_Platform1__v2, 0.98 * Ball_Platform1__v2p); end when; OutPutPort1__vi = OutPutPort1__vo; OutPutPort2__vi = OutPutPort2__vo; Ball_Platform1__y2 = OutPutPort1__vi; Ball_Platform1__y1 = OutPutPort2__vi; end Ball_Platform_im;
It's a simple thing, but as the flattening should be part of an automated process for generation of FMI2 libraries, modifying it each time by hand wouldn't be feasible.
Thanks in advance.
Change History (2)
comment:1 by , 7 years ago
Component: | *unknown* → Frontend |
---|---|
Owner: | changed from | to
Status: | new → accepted |
comment:2 by , 7 years ago
Milestone: | Future → 1.13.0 |
---|---|
Resolution: | → fixed |
Status: | accepted → closed |
Note:
See TracTickets
for help on using tickets.
Fixed in https://github.com/OpenModelica/OMCompiler/pull/2096