0

In my model, I got confused that why the initial conditions are NOT fully specified.

Here are the code and screenshot:

model WithAlgebraicLoop_Right
  extends Modelica.Icons.Example;
  Real x;
  Real y(start=1, fixed=true);
  Boolean cond;
equation 
  cond = x > 0.5;
  when pre(cond) then
    y = 1*time;
  end when;
  x = sin(y*10*time);
end WithAlgebraicLoop_Right;

enter image description here

I think that during the initialization, x could be calculated from y, so cond could be calculated from x, so why doesn't Dymola do as I think?

Jack
  • 1,094
  • 6
  • 16

1 Answers1

7

Sure, discrete-time variable cond can be calucated according to the given equations. However, its pre-value for the event iteration at initialization is not known and must be set, either by setting a fixed start value or by an initial equation, whatever you prefer.

model WithAlgebraicLoop_Right1
  Real x;
  Real y(start=1, fixed=true);
  Boolean cond(start=false, fixed=true);
equation 
  cond = x > 0.5;
  when pre(cond) then
    y = 1*time;
  end when;
  x = sin(y*10*time);
end WithAlgebraicLoop_Right1;

or

model WithAlgebraicLoop_Right2
  Real x;
  Real y(start=1, fixed=true);
  Boolean cond;
initial equation
  pre(cond) = false;
equation 
  cond = x > 0.5;
  when pre(cond) then
    y = 1*time;
  end when;
  x = sin(y*10*time);
end WithAlgebraicLoop_Right2;
tbeu
  • 1,235
  • 7
  • 12
  • setting a fixed start value could calculate the pre-value of variables? I thought setting a fixed start value means that you know the value of a variable from time=0s and on, but not the `pre-value`. But I check the model, it works without warnings, so I am not sure what the inner mechanism is. – Jack Dec 13 '20 at 06:26
  • 1
    Yes, that's the case, see section 8.6 on the initialization of the Modelica Language specification version 3.4 (https://specification.modelica.org/maint/3.4/Ch8.html#initialization-initial-equation-and-initial-algorithm): For all discrete variables vd, the equation pre(vd) = startExpression is added to the initialization equations, if start = startExpression and fixed = true. – tbeu Dec 13 '20 at 08:39
  • 3
    By the way, my preference would be the fixed start value, since you can easily modify them in components, which is not the case for initial equations. See this discussion for some more background: https://github.com/mtiller/ModelicaBook/issues/133 – tbeu Dec 13 '20 at 08:43
  • 1
    In section 8.6 you can also read on the different initialization of continous-time variables and discrete-time variables. What you mentioned above only holds for continuous-time variables, but `cond` is a discrete-time variable. – tbeu Dec 13 '20 at 08:49