Search code examples
modelicaopenmodelica

How can I generate complex events in modelica for when statement?


I tryed to use this code:

Real x,y;
Boolean trigger(start = true) 
when x < y and trigger then
   trigger = false;
end when;

I want to generate event for "when" only once. But my code doesn't work. How can I generate complex events in modelica for when statement?


Solution

  • In Dymola you get the following error message:

    The computational causality analysis requires the variables trigger to be solved from the equation: when x < y and trigger then trigger = false; end when; however, the when condition also depends on the unknowns.

    You may be able to cut the loop by putting 'pre' around these references in the when condition.

    Thus the solution would be:

    Real x,y;
    Boolean trigger(start = true) ;
    equation
    when x < y and pre(trigger) then
       trigger = false;
    end when;
    

    As you see this is quite simple (and simulates in Dymola), but I haven't checked it in OpenModelica.