Modelica defines time as real (sec 3.6.7)
input Real time (final quantity = "Time",
final unit = "s");
In a solver, when using time parsed from a Modelica text for comparison operations, a tolerance has to be taken into consideration, which makes the comparisons slower (and theoretically somewhat imprecise). Though the parsed time values can be converted to integer manually where appropriate, this involves additional processing time.
What is the reason to represent time as a Real instead of as an Integer (e.g. with unit = "ns"
by default)?
To give perspective where the question comes from:
The time type of the ISO C standard is unspecified. However on implementations for Posix-compliant systems, time is an integer:
Older ISO C standards define time_t
as arithmetic type (sec 7.32.1), so it can be either a real-floating or integer. In C11, time_t
is defined as real type (sec 7.27.1), while POSIX requires time_t
to be an integer type.
For example in gcc Debian 4.9.2-10 time_t
is an integer:
typedef long int __time_t;
typedef __time_t time_t;
The primary reason time is a Real is because we often need to differentiate it in models, e.g. if you have Real position=0.14*time;
and want to differentiate it to compute e.g. Real velocity=der(position);
.
(Obviously the functions of time are often more complicated.) For that we need time to be continuous - and thus Real.
A secondary reason is that there are quite different time-scales in Modelica, nano-seconds are sometimes used, but e.g. building simulations might have simulated time of years.
However, having a "integer" time for easier post-processing might be a future extension (in the language or tools), and seems related to the synchronous parts where Clocked sub-systems can use nano-seconds ticks (or milli-second, or days, or weeks).
(BTW: Technically Integer does not have unit-attribute, but that is a minor issue.)