Reputation: 1232
I build a simple model in Dymola, I choose to use i_R1 to set the intializaiton condition, as shown in the follwing code and screenshot.
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;
But after translation, in the dsin.txt, it shows that i_R1
is a free variable, but u_2
is fixed.
My question is:
Why Dymola sets u_2
as fixed instead of i_R1
?
Upvotes: 3
Views: 350
Reputation: 12507
The first column in dsin.txt is now primarily used for continue simulation in Dymola, and is otherwise sort of ignored.
If you want to know which values are relevant for starting the simulation, i.e. parameters and variables with fixed=true you should instead look at the 6th column and x&8
, that shows that i_R1
, U0
, freq
, phi
, R1
, R2
, C
, Is
, and Vt
will influence a normal simulation.
For continue simulation it is instead x&16
that matters, so u_2
instead of i_R1
.
The x above is the value in the 6th column, and &8
represents bitwise and. In Modelica you could do mod(div(x, 8),2)==1 to test the numbers.
Upvotes: 3
Reputation: 7500
Better read Hans Olsson's answer, he knows better, still here is what I wrote:
I didn't implement it, so take everything with a grain of salt:
dsmodel.mof
for the posted example, contains the following code:
// Initial Section
u_1 := U0*sin(w*time+phi);
u_2 := u_1-i_R1*R1;
Using the values from the example results in u_1 = 0
and u_2=-100
. So it seems the fixed start value for i_R1
is used to compute the initial value u_2
using the above equations.
This should be the reason for the fixed statements in the model and dsin.txt
being different in dsin.txt
compared to the original Modelica code. Basically information from the model is used to compute the initial value of the state (u_2
) from the start value from an auxiliary variable (i_R1
). In the executed code, the state is being initialized.
Speculation: u_2
is unknown when creating dsin.txt
, so it is set to zero and computed later. This should correspond to the first case described in dsin.txt
in
"Initial values are calculated according to the following procedure:"
which is when all states are fixed.
Upvotes: 2
Reputation:
I think it is a bug: even though it is signed as fixed, the voltage u_2 starts at -100V instead of 0V when I simulate it, and i_R1 starts at 1A.
Speculation: Perhaps the sorting algorithms are allowed during translation to set fixed initial values to more meaningful variables, as long as the condition given by the Modelica code (i_R1=1, in your case) is met. If that's the case, it would still count as a bug for me, but it might explain what's going on.
Upvotes: 1