1

Is there a way to measure the time at which an event occurs (without using sample or anything similar) in Modelica? something like the tic toc command in MATLAB? what I would like to see is the difference in time when different events happen. For example, in the following sample code, is there a way to see the elapsed time using test_time1 and test_time2?

when event1 then 
 a:=2;
 event2:= true;
 test_time1 := time;
end when;
when event2 then 
a:= 5;
test_time2 := time;
end when;
Shaga
  • 170
  • 8

1 Answers1

1

abs(test_time2-test_time1) should do it if you do not know which occurs first. Note that this would be the simulation time, not real (wall) time. If you want to measure the real time it takes for a simulation to trigger the two events, you need to use external C functions calling your own tic and toc.

sjoelund.se
  • 3,468
  • 12
  • 15
  • Thanks for the reply @sjoelund.se . I edited the sample code a bit. `event1` triggers `event2` and in this case I always get the same values in `test_time1` and `test_time2`. What I realized is that I've been looking at the `time` variable always as the real time (with a lot of MATLAB kind of programming logic in mind). – Shaga Mar 04 '16 at 08:45
  • Thanks to your comment I read a bit more and realized that I was looking at the problem all wrong and the simulation time actually stops when an event happens until the condition `pre(var) == var` is satisfied. – Shaga Mar 17 '16 at 14:02