Help - Search - Members - Calendar
Full Version: if-equation to if-expression?
Modelica Forum > Modelica > MathModelica / OpenModelica
Jawhar
Hello,

I am using OpenModelica 1.4.3 and i want to export my models from Dymola under OpenModelica.

I know that OpenModelica 1.4.x don't support if-equations. The error message is:

QUOTE

The language feature if-equations is not supported. Suggested workaroung: rewrite equations using if-expressions


In my model i have something like this:

CODE


model Hello
[...]

equation

if x < 2 then
der(x)= 0.3*x;
else
der(x)= 0;
end if;
[...]




How can i transform my code from if-equation to if-expression?

Thank you.

Best regards,

Jawhar
wagner
Hello Jawhar,

for your given example you could use an if-expression to define the proportional factor of the state variable in your differential equation:

CODE

...
Real gain;
...
gain=if (x < 2) then 0.3 else 0;

der(x)=gain*x;


I didn't test the code but something similar like this might be a workaround for your problem.

Regards

Florian
Jawhar
[Thank you Florian,

I have tested "der(x)=if (x < 2) then 0.3 else 0;" and i hadn't an error message..

I have many problems using OpenModelica..(No checking for equations, explicit error message, no warnings..)

I have many models (state1.mo, state2.mo, connector1.mo, connector2.mo and hybrid.mo which connects the other models). I did a package and i include all these model under this package ( i named it test.mo).

So my tet.mo is like this:

CODE


Package test

   model state1
   ...
   ...
   end state1;

   model state2
   ...
   ...
   end state2;


   ...
   etc
   ...


   model hybrid
   ... // here i instantiate state1 and state2... and i connect them.
   ...
   end hybrid,

end test;



I load the package under OMShell and simulate it.
CODE

simulate(test, startTime=0, stopTime=10)

No errors! I want to plot the variables, but i haven't found them!! the variables are in state1 and state2 model.

Is it the good way to simulate many models under OpenModelica? Under Dymola, i didn't a package, i simulated only the hybrid model in which i instantiated and connected the other models.

Hope you can help me..

Best Regard,

Jawhar.
Jawhar
Here is the answer of Adrian Pop, i received by mail now:
QUOTE

Hi,

First, you cannot simulate a package!
You can simulate a model.
simulate(test.hybrid, ...);
plot(test.hybrid.state1.variable, ...)

Is no need to make packages.
You could do a script, for example test.mos:
loadFile("state1.mo");
loadFile("state2.mo");
loadFile("state3.mo");
...
loadFile("hybrid.mo");
simulate(hybrid, ...);
plot(hybrid.state1.variable, ...)

Cheers,
Adrian Pop/
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.