Derivative as divisor gives division by zero during initialization in Dymola

316 Views Asked by At

I build a model that includes a derivative of dy/dx=5, as shown in the following segment, but the model fails during initialization in Dymola, in another question, it has been answered. The reason is that at time=0, the values of der(x) and der(y) are both 0. So there would be an error of division by 0.

model HowToExpressDerivative "dy/dx=5, how to describe this equation in Modelica?"
  extends Modelica.Icons.Example;
  Real x, y;
equation 
  x = time ^ 2;
  der(y) / der(x) = 5;
end HowToExpressDerivative;

Here is the result in Dymola:
enter image description here

But when I try the same model in the Wolfram System Modeler and OpenModelica, the model works fine.
In the Wolfram System Modeler, it uses the equation of der(y)/der(x)=5 directly.

My questions are:

  1. Why Would the same model fail in Dymola?
  2. Does Dymola NOT have the ability to do automatic symbolic manipulation to transform this equation of der(y)/der(x)=5 into der(y)=5*der(x)?
  3. Or the numerical solver in Dymola can't handle this kind of situation? enter image description here

enter image description here

2

There are 2 best solutions below

2
Hans Olsson On BEST ANSWER

Dymola does currently not recognize that trivial simplification in that case (it is done in another case), not because it would be too complicated, but because Dymola uses a simple rule:

Division in the Modelica code are safe, other divisions are not considered safe.

Thus der(x)/der(y)=5 indicates that division by der(y) is safe (even though it clearly isn't), whereas solving that equation technically involves dividing by 1/der(y) which isn't deemed safe (as it didn't occur in the Modelica code).

Obviously the logic can be improved, but the simplest solution is to use the following rule: don't divide in your code unless it is safe to do so.

A benefit of following that rule is that it will be possible to check all the original equations and see that they are satisfied (up to numerical precision) - without triggering division by zero.

0
Petros Iliadis On

Update: In Dymola2023 the model compiles and runs correctly.

// Initial Section
  der(x) := 2.0*time;
  der(y) := 5.0*der(x);
// --------------------------------------------------------------------------
// Dynamics Section
  der(x) := 2.0*time;
  der(y) := 5.0*der(x);