为什么 dsin.txt 文件中的初始化设置与 Dymola 中的模型不同?

Why the initialization setting in the dsin.txt file is different from the Model in Dymola?

我在Dymola搭建了一个简单的模型,我选择使用i_R1设置初始化条件,如下代码和截图所示。

model circuit1
Real i_gen(unit="A") "Current of the generator";
Real i_R1(start=1,fixed=true,unit="A") "Current of R1";
Real i_R2(unit="A") "Current of R2";
Real i_C(unit="A") "Current of the capacitor";
Real i_D(unit="A") "Current of the diode";
Real u_1(unit="V") "Voltage of generator";
Real u_2(unit="V") "Output voltage";
// Voltage generator
constant Real PI = 3.1415926536;
parameter Real U0( unit="V") = 5;
parameter Real frec( unit="Hz") = 100;
parameter Real w( unit="rad/s") = 2*PI*frec;
parameter Real phi( unit="rad") = 0;
// Resistors
parameter Real R1( unit="Ohm") = 100;
parameter Real R2( unit="Ohm") = 100;
// Capacitor
parameter Real C( unit="F") = 1e-6;
// Diode
parameter Real Is( unit="A") = 1e-9;
parameter Real Vt( unit="V") = 0.025;
equation 
// Node equations
i_gen = i_R1;
i_R1 = i_D + i_R2 + i_C;
// Constitutive relationships
u_1 = U0 * sin( w * time + phi);
u_1 - u_2 = i_R1 * R1;
i_D = Is * ( exp(u_2 / Vt) - 1);
u_2 = i_R2 * R2;
C * der(u_2) = i_C;
end circuit1;

但是翻译后,在dsin.txt中显示i_R1是自由变量,而u_2是固定的。 我的问题是: 为什么 Dymola 将 u_2 设置为固定而不是 i_R1

我认为这是一个错误:即使它被标记为固定,电压 u_2 在我模拟时从 -100V 而不是 0V 开始,并且 i_R1 从 1A 开始。

推测:也许在翻译过程中允许排序算法将固定的初始值设置为更有意义的变量,只要满足 Modelica 代码给出的条件(i_R1=1,在您的情况下) .如果是这样的话,它对我来说仍然算作一个错误,但它可能会解释发生了什么。

最好读一下 Hans Olsson 的回答,他知道得更多,还是我写的:

我没有实现它,所以对一切持保留态度:

dsmodel.mof 对于发布的示例,包含以下代码:

// Initial Section
  u_1 := U0*sin(w*time+phi);
  u_2 := u_1-i_R1*R1;

使用示例中的值得到 u_1 = 0u_2=-100。因此,i_R1 的固定起始值似乎用于使用上述等式计算初始值 u_2

这应该是模型中的固定语句和 dsin.txt 与原始 Modelica 代码相比 dsin.txt 中不同的原因。基本上,来自模型的信息用于根据辅助变量 (i_R1) 的起始值计算状态的初始值 (u_2)。在执行的代码中,状态正在被初始化。

推测:u_2在创建dsin.txt时是未知的,所以设置为零,稍后计算。这应该对应于

dsin.txt中描述的第一种情况

"Initial values are calculated according to the following procedure:"

这是所有状态都固定的时候。

dsin.txt 中的第一列现在主要用于在 Dymola 中继续模拟,否则会被忽略。

如果您想知道哪些值与启动模拟相关,即 fixed=true 的参数和变量,您应该查看第 6 列和 x&8,这表明 i_R1U0freqphiR1R2CIsVt 将影响正常模拟。 对于继续模拟,重要的是 x&16,因此 u_2 而不是 i_R1

上面的x是第6列的值,&8表示按位与。在 Modelica 中,您可以执行 mod(div(x, 8),2)==1 来测试数字。