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;

1 Answer 1

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.

2
  • 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 4, 2016 at 8: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, 2016 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.