2

I am working on a simple model which includes a derivative of dy/dx, but in Modelica, I can't write this equation directly, I could use the combination of x=timeand der(y), but I think this is a compromise because of limitation of Modelica language.

My question is: Is there another better method to describe derivative in Modelica?

Here is the code:

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

I also tried to use der(y)/der(x) to express dy/dx, but there is an error when x equals time^2.

model HowToExpressDerivative "dy/dx=5, how to describe this equation in Modelica?"
  Real x,y;
equation 
  x=time^2;
  der(y)/der(x)=5;
end HowToExpressDerivative;
Error: The following error was detected at time: 0

Model error - division by zero: (1.0) / (der(x)) = (1) / (0)

Error: Integrator failed to start model.
... "HowToExpressDerivative.mat" creating (simulation result file)

ERROR: The simulation of HowToExpressDerivative FAILED
Jack
  • 1,094
  • 6
  • 16
  • 4
    Partial derivatives are only supported via functions, but I guess you know that as it was an answer to one of your own questions: https://stackoverflow.com/questions/64262053/why-does-the-der-operator-in-modelica-apply-to-the-time-variable-only/64262535#64262535. If that is formulated correctly, you can likely set `der_f1` = 5. – Markus A. Dec 09 '20 at 13:30
  • 1
    What are you trying to model where you need dy/dx? If dy/dx is known it seems quite different from the function-case. – Hans Olsson Dec 09 '20 at 15:50
  • @HansOlsson. Here is an example: the rate of change of enthalpy and density with respect to crank-angle. Like the Equation(5) in the following paper https://www.sciencedirect.com/science/article/pii/S2405896316324843 – Jack Dec 10 '20 at 03:03

1 Answers1

5

Given enthalpy h and crank-angle phi you could replace dh/dphi=... by:

  der(h)/der(phi)=...

However, even if correct that formula will break down when the engine is standing still (der(phi)=0), so it is not ideal.

An alternative would be to rewrite the formulas. Looking more closely the formula seems to be:

  dh/dphi=(\partial a/\partial T)*dT/dphi+...

which suggests that they could be rewritten as:

  der(h)=(\partial a/\partial T)*der(T)+...
Hans Olsson
  • 11,123
  • 15
  • 38