这是用户在 2024-7-1 9:11 为 https://specification.modelica.org/maint/3.6/introduction1.html#overview-of-modelica 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Modelica® Language Specification version 3.6
Modelica ® 语言规范 3.6 版

Chapter 1  第 1 章Introduction 导言

1.1 Overview of Modelica 1.1 Modelica 概述

Modelica is a language for modeling of cyber-physical systems, supporting acausal connection of components governed by mathematical equations to facilitate modeling from first principles. It provides object-oriented constructs that facilitate reuse of models, and can be used conveniently for modeling complex systems containing, e.g., mechanical, electrical, electronic, magnetic, hydraulic, thermal, control, electric power or process-oriented subcomponents.
Modelica 是一种用于网络物理系统建模的语言,它支持由数学公式控制的各组件之间的无因果连接,以便于从第一原理出发进行建模。它提供面向对象的构造,便于模型的重复使用,可方便地用于对包含机械、电气、电子、磁力、液压、热力、控制、电力或面向过程的子组件的复杂系统建模。

1.2 Scope of the Specification
1.2 规范范围

The semantics of the Modelica language is specified by means of a set of rules for translating any class described in the Modelica language to a flat Modelica structure. The semantic specification should be read together with the Modelica grammar.
Modelica 语言的语义是通过一系列规则来指定的,这些规则用于将 Modelica 语言中描述的任何类转换为平面 Modelica 结构。语义规范应与 Modelica 语法一起阅读。

A class (of specialized class model or block) intended to be simulated on its own is called a simulation model.

The flat Modelica structure is also defined for other cases than simulation models; including functions (can be used to provide algorithmic contents), packages (used as a structuring mechanism), and partial models (used as base-models). This allows correctness to be verified for those classes, before using them to build the simulation model.
除仿真模型外,扁平 Modelica 结构还适用于其他情况,包括函数(可用于提供算法内容)、包(用作结构机制)和部分模型(用作基础模型)。这样,在使用这些类构建仿真模型之前,就可以验证它们的正确性。

There are specific semantic restrictions for a simulation model to ensure that the model is complete; they allow its flat Modelica structure to be further transformed into a set of differential, algebraic and discrete equations (= flat hybrid DAE). Note that satisfying the semantic restrictions does not guarantee that the model can be initialized from the initial conditions and simulated.
仿真模型有特定的语义限制,以确保模型的完整性;这些语义限制允许其扁平 Modelica 结构进一步转化为微分、代数和离散方程组(= 扁平混合 DAE)。请注意,满足语义限制并不能保证模型可以从初始条件初始化并进行仿真。

Modelica was designed to facilitate symbolic transformations of models, especially by mapping basically every Modelica language construct to equations in the flat Modelica structure. Many Modelica models, especially in the associated Modelica Standard Library, are higher index systems, and can only be reasonably simulated if symbolic index reduction is performed, i.e., equations are differentiated and appropriate variables are selected as states, so that the resulting system of equations can be transformed to state space form (at least locally numerically), i.e., a hybrid DAE of index zero. In order to allow this structural analysis, a tool may reject simulating a model if parameters cannot be evaluated during translation – due to calls of external functions or initial equations/initial algorithms for fixed = false parameters. Accepting such models is a quality of implementation issue. The Modelica specification does not define how to simulate a model. However, it defines a set of equations that the simulation result should satisfy as well as possible.
Modelica 的设计是为了方便对模型进行符号转换,特别是通过将基本上所有 Modelica 语言构造映射到平面 Modelica 结构中的方程。许多 Modelica 模型,尤其是相关的 Modelica 标准库中的模型,都是高指数系统,只有在进行符号指数还原时才能进行合理的模拟,即对方程进行微分,并选择适当的变量作为状态,这样得到的方程系统才能转换为状态空间形式(至少是局部数值形式),即指数为零的混合 DAE。为了进行这种结构分析,如果在转换过程中由于调用外部函数或初始方程/初始算法以获得固定 = 虚假参数而无法评估参数,工具可能会拒绝模拟模型。接受这样的模型是一个实现质量问题。Modelica 规范没有定义如何模拟模型。但是,它定义了模拟结果应尽可能满足的方程组。

The key issues of the translation (or flattening) are:

  • Expansion of inherited base classes.

    - 扩展继承基类。
  • Parameterization of base classes, local classes and components.

    - 基类、局部类和组件的参数化。
  • Generation of connection equations from connect-equations.

    - 从连接方程生成连接方程。

The flat hybrid DAE form consists of:
平面混合 DAE 形式包括

  • Declarations of variables with the appropriate basic types, prefixes and attributes, such as parameter Real v = 5.

    - 用适当的基本类型、前缀和属性声明变量,如参数 Real v = 5。
  • Equations from equation sections.

    - 方程式部分的方程式。
  • Function invocations where an invocation is treated as a set of equations which involves all input and all result variables (number of equations = number of basic result variables).

    - 函数调用,一次调用被视为一组方程,涉及所有输入变量和所有结果变量(方程数 = 基本结果变量数)。
  • Algorithm sections where every section is treated as a set of equations which involves the variables occurring in the algorithm section (number of equations = number of different assigned variables).

    - 算法部分,每个部分都被视为一组方程,涉及算法部分中出现的变量(方程数 = 不同分配变量的数量)。
  • The when-clauses where every when-clause is treated as a set of conditionally evaluated equations, which are functions of the variables occurring in the clause (number of equations = number of different assigned variables).

    - 当值子句,其中每个当值子句都被视为一组条件评价方程,它们是子句中出现的变量的函数(方程数 = 不同赋值变量的个数)。

Therefore, a flat hybrid DAE is seen as a set of equations where some of the equations are only conditionally evaluated. Initial setup of the model is specified using start-attributes and equations that hold only during initialization.
因此,平面混合 DAE 被视为一组方程,其中一些方程只进行条件评估。模型的初始设置使用起始属性和仅在初始化期间成立的方程来指定。

A Modelica class may also contain annotations, i.e., formal comments, which specify graphical representations of the class (icon and diagram), documentation text for the class, and version information.
Modelica 类还可能包含注释(即正式注释),其中指定了类的图形表示(图标和图表)、类的文档文本和版本信息。

1.3 Some Definitions 1.3 一些定义

Explanations of many terms can be found using the document index in Modelica® Language Specification version 3.6. Some important terms are defined below.
许多术语的解释可通过 Modelica ® 语言规范 3.6 版中的文档索引找到。下面定义了一些重要术语。

Definition 1.1. Component.

An element defined by the production component-clause in the Modelica grammar (basically a variable or an instance of a class) ∎

定义 1.1.Modelica语法中由生产组件条款定义的元素(基本上是一个变量或一个类的实例) ∎
Definition 1.2. Element.

Class definition, extends-clause, or component-clause declared in a class (basically a class reference or a component in a declaration). ∎

定义 1.2.元素.类定义、扩展条款或在类中声明的组件条款(基本上是类引用或声明中的组件)。∎
Definition 1.3. Flattening.

The translation of a model described in Modelica to the corresponding model described as a hybrid DAE (see appendix B), involving expansion of inherited base classes, parameterization of base classes, local classes and components, and generation of connection equations from connect-equations. In other words, mapping the hierarchical structure of a model into a set of differential, algebraic and discrete equations together with the corresponding variable declarations and function definitions from the model. ∎

定义 1.3.扁平化(Flattening):将 Modelica 描述的模型转换为混合 DAE 描述的相应模型(见附录 B),包括继承基类的扩展,基类、局部类和组件的参数化,以及从连接方程生成连接方程。换句话说,将模型的层次结构映射为一组微分方程、代数方程和离散方程,以及模型中相应的变量声明和函数定义。∎
Definition 1.4. Initialization.

Simulation starts with solving the initialization problem at the starting time, resulting in values for all variables that are consistent with the result of the flattening. ∎

定义 1.4.初始化.仿真开始时首先要解决起始时间的初始化问题,使所有变量的值与扁平化的结果一致。∎
Definition 1.5. Transient analysis.

Starting from the result of the initialization problem, the model is simulated forward in time. This uses numerical methods for handling the hybrid DAE, resulting in solution trajectories for the model’s variables, i.e., the value of the variables as a function of time. ∎

定义 1.5.从初始化问题的结果开始,对模型进行时间模拟。这将使用数值方法来处理混合 DAE,从而得到模型变量的解轨迹,即变量值与时间的函数关系。∎

[In the numerical literature transient analysis is often called solving the initial value problem, but that term is not used here to avoid confusion with the initialization problem.]

Definition 1.6. Simulation.

Simulation is the combination of initialization followed by transient analysis. ∎

定义 1.6.模拟是初始化与瞬态分析的结合。∎

[The model can be analyzed in ways other than simulation, e.g., linearization, and parameter estimation, but they are not described in the specification.]

Definition 1.7. Translation.

Translation is the process of preparing a Modelica simulation model for simulation, starting with flattening but not including the simulation itself. ∎

定义 1.7.Translation.Translation 是为仿真准备 Modelica 仿真模型的过程,从扁平化开始,但不包括仿真本身。∎

[Typically, in addition to flattening, translation involves symbolic manipulation of the hybrid DAE and transforming the result into computer code that can simulate the model.]
[通常情况下,除了扁平化之外,翻译还包括对混合 DAE 进行符号操作,并将结果转化为可以模拟模型的计算机代码。]

1.4 Notation 1.4 符号

The remainder of this section shows examples of the presentation used in this document.

Syntax highlighting of Modelica code is illustrated by the code listing below. Things to note include keywords that define code structure such as equation, keywords that do not define code structure such as connect, and recognized identifiers with meaning defined by the specification such as semiLinear:
下面的代码列表说明了 Modelica 代码的语法高亮显示。需要注意的事项包括定义代码结构的关键字(如方程)、不定义代码结构的关键字(如连接)以及由规范定义含义的公认标识符(如半线性):

model Example "Example used to illustrate syntax highlighting"
示范示例 "用于说明语法高亮的示例"
  /* The string above is a class description string, this is a comment. */
/* 上面的字符串是类描述字符串,这是注释。*/
  /* Invalid code is typically presented like this: */
/* 无效代码通常是这样显示的:*/
  String s = 1.0; // Error: No conversion form Real to String.
String s = 1.0; // Error:没有将实数转换为字符串。
  Real x; 真实 x;
equation 方程式
  2 * x = semiLinear(time - 0.5, 2, 3);
2 * x = semiLinear(时间 - 0.5,2,3);
  /* The annotation below has omitted details represented by an ellipsis: */
/* 下面的注释省略了一些细节,用省略号表示:*/
  connect(resistor.n, conductor.p) annotation();
connect(resistor.n, conductor.p) 注解( );
end Example; 结束示例;

Relying on implicit conversion of Integer literals to Real is common, as seen in the equation above (note use of Modelica code appearing inline in the text).
将 Integer 字面隐式转换为 Real 是常见的方法,如上式所示(注意文中使用了内联的 Modelica 代码)。

It is common to mix Modelica code with mathematical notation. For example, average(x, y) could be defined as x+y2.
将 Modelica 代码与数学符号混合是很常见的。例如, average( x , y ) 可以定义为 x+y2

Inline code fragments are sometimes surrounded by quotes to clearly mark their beginning and end, or to emphasize separation from the surrounding text. For example, ‘,’ is used to separate the arguments of a function call.
内联代码片段有时会用引号包围,以明确标记其开始和结束,或强调与周围文本的分离。例如,", "用于分隔函数调用的参数。

Definition 1.8. Something.

Text defining the meaning of something. ∎

定义 1.8.something.定义事物含义的文本。∎

In addition to the style of definition above, new terminology can be introduced in the running text. For example, a dummy is something that…

[This is non-normative content that provides some explanation, motivation, and/or additional things to keep in mind. It has no defining power and may be skipped by readers strictly interested in just the definition of the Modelica language.]
[这是非规范性内容,提供了一些解释、动机和/或需要牢记的附加事项。它不具有定义功能,对 Modelica 语言定义感兴趣的读者可以跳过]。

[Example: This is an example, which is a special kind of non-normative content. Examples often contain a mix of code listings and explanatory text, and this is no exception:

String s = 1.0; // Error: No conversion form Real to String.
String s = 1.0; // Error:没有将实数转换为字符串。

To fix the type mismatch above, the number has to be replaced by a String expression, such as "1.0".]
要解决上述类型不匹配问题,必须用字符串表达式替换数字,如 "1.0"]。

Other code listings in the document include specification of lexical units and grammatical structure, both using metasymbols of the extended BNF-grammar defined in section A.1. Lexical units are named with all upper-case letters and introduced with the ‘=’ sign:
文件中的其他代码列表包括词法单位和语法结构的规范,两者均使用 A.1 节中定义的扩展 BNF 语法的元符号。词法单位的命名均使用大写字母,并以"="符号引入:


Grammatical structure is recognized by production rules being named with lower-case letters and introduced with the ‘:’ sign (also note appearance of the Modelica keyword der):
语法结构通过以小写字母命名并以": "符号引入的生产规则来识别(同时注意 Modelica 关键字 der 的出现):

differentiated-expression :
分化表达 :
    der "(" SOME-TOKEN ")"
    | "(" differentiated-expression "+" differentiated-expression ")"
| "(" 有区别的表达式 "+" 有区别的表达式")"