Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving static equations (or systems thereof)

I wanted to do the following in Modelica: in a specific model I have several parameters h and I want to deduce some time independent values k from them by solving a set of implicit equations between the parameters and the other values. Since the equations are implicit by nature, I cannot simply assign an expression, I rather have to let the solver find the solution.

Since the parameters are constant, I want to be able to solve the equations only once at the beginning, before the actual time integration of the rest of the system (e.g. a differential equation that contains k as a coefficient) takes place.

See the following example of what I would like to be able to write:

model ConstantTest
  parameter Real h = 2;
  const Real k;
initial equation
  k*k=h; // just an example of an implicit equation, which in this simple case could also be written explicitly
end ConstantTest;

But this fails because a "constant" in Modelica is not only constant in the sense of having vanishing time derivative, but it is also already immutable at the time when the initial equations are being solved. So the solver complains that it cannot solve the initial equation 0 = 2, which is because it is assuming that k invariably equals 0.

Of course I can just make k a variable, but then I have to tell the solver explicitly that k has vanishing time derivative (amounting to it being practically "constant" in the naive physical sense):

model ConstantTest
  parameter Real h = 2;
  Real k;
initial equation
  k*k=h;
equation
  der(k) = 0;
end ConstantTest;

This works, but it is somewhat odd because the solver has to solve a trivial differential equation at every time step in order to do basically nothing at all to k. And that would be a waste of computational resources.

Is there any way to solve static implicit equations with Modelica without introducing "time evolution overhead"?

like image 524
oliver Avatar asked Feb 07 '19 17:02

oliver


2 Answers

I guess you could do this:

model ConstantTest
  parameter Real h = 2;
  parameter Real k(fixed=false);
initial equation
  k*k=h;
end ConstantTest;

k will be computed at initialization.

like image 132
Adrian Pop Avatar answered Oct 03 '22 07:10

Adrian Pop


I think the best way to define these kinds of systems is:

model ConstantTest
  parameter Real h = 2;
  Real k;
equation
  2*k=h;
end ConstantTest;

Which OpenModelica will put in an initial section and solve only once. I would consider OpenModelica's behaviour for your system a bug since it's solving a time-independent equation multiple times.

like image 20
sjoelund.se Avatar answered Oct 03 '22 08:10

sjoelund.se