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;
答案 0 :(得分:6)
时间是真实的主要原因是因为我们经常需要在模型中区分它,例如如果你有Real position=0.14*time;
并希望将其区分为例如Real velocity=der(position);
。
(显然,时间的功能往往更复杂。)为此,我们需要时间连续 - 因此是真实的。
次要原因是Modelica中存在完全不同的时标,有时使用纳秒,但是建筑模拟可能模拟了多年的时间。
然而,具有“整数”时间以便于后处理可能是未来的扩展(在语言或工具中),并且似乎与同步部分有关,其中Clocked子系统可以使用纳秒秒(或毫秒) - 秒,或几天或几周)。
(BTW:Technically Integer没有单位属性,但这是一个小问题。)