0
votes

I have been facing some problem with Modelica initialisation. I want to simulate the initial step of a finite state machine and I would like the initial state to start from false and instantly turns to true at the beginning of the simulation.

equation
      OUTPUT=active;
    algorithm
      when change(INPUT) then X:= not X; reinit(t,0); end when;
    initial algorithm
      active:=true;

Here is the code. Variable INPUT, OUTPUT and X are all Boolean type. INPUT is a variable that makes the state changes ( from true to false and vice versa).

What the code does is to set variable active to true at the initialisation. What I would like to get is that it starts from false and it gets to true at time t=0; basically I would like to see the transition from false to true at the first instant of the simulation. Is it possible?

1
It would be much easier to help, if you provide a minimal reproducible example: stackoverflow.com/help/minimal-reproducible-example - marco

1 Answers

0
votes

EDIT 2: Looking at this issue, using initial() for the when clause solves the problem.

model Test
  Boolean x(start=false) "state";
  Boolean u;
  Modelica.Blocks.Interfaces.BooleanOutput y;
equation
  u=true;
  when initial() then
    x = not pre(x);
  elsewhen edge(u) then
    x = not pre(x);
  end when;
  y=x;
end Test;

Looking at the debugger of OpenModelica, first x gets the start-value false assigned, then it jumps into the when clause and sets it to true.

enter image description here