1
votes

First, excuse me for not providing a minimal working example, it is that I just can't think of one, really. I'll just give some pieces of code and ask my question "in principle".

I'm doing thermophysical properties calculation with a real gas model (Peng-Robinson) and here I am having problems when translating a model, where I use pressure p and specific enthalpy h as inputs to calculate all other properties. When it comes to calculating the temperature T, it is linked to the enthalpy h via an equation called departure function, which is itself a function of T. In Modelica it looks like this:

Dh_real = R_m*T*(Z - 1) + (T*dadT - a)/(sqrt(8)*b)*log((Z + (1 + sqrt(2))*B)/(Z + (1 - sqrt(2))*B));

Here a, dadT and Z are also temperature-dependent scalars and partly calculated using matrix operations (dadT) or polynomial-root-calculation (Z) in functions, b and B are parameters.

Calculating the enthalpy from an input temperature (in another model) is straightforward and working fine, the solver can solve the departure function analytically. The other direction has to be solved numerically and this is, I think, why Dymola gives me this error, when translating.

Cannot find differentiation function:
DadT_Unique2([some parameters and T])
with respect to time

Failed to differentiate the equation
dadT = DadT_Unique2([some parameters and T]);

in order to reduce the DAE index.

Failed to reduce the DAE index.

Now DadT is a function within the model, where I use some simple matrix operations to calculate dadT from some parameters and the temperature T. Obviously, Dymola is in need of the derivative of some internal _Unique2-function. I couldn't find anything in the specification nor in the web about this. Can I provide a derivative of the functions somehow? I tried the smoothOrder-annotation, but without effect. How can I deal with this?

1
You can provide a derivative function using the annotation(derivative=dxyz). Search the Modelica Language Specification for these annotations (inverse might also be interesting) or read more in Michael Tillers online book: book.xogeny.com/behavior/functions/func_annos/#derivative - matth
Thanks for your hints @matth . Am I right, that in the derivative function I'm soupposed to mathematically give the function for the differential of the original function's outputs, so that the compiler can generate derivatives with respect to any variable (and time)? But what if I don't have/can't give a derivative function? For example in my case Z is the output of the MSL-function Modelica.Math.Vectors.Utilities.roots. How do I get the differential of a root calculation from a third grade polynomial? - paulkernstock
The derivative that you specify is the time derivative, but that one probably calls each partial derivative of your original function. As an example, you can look at the function density_ph (and the functions that it calls) of Modelica.Media.R134a or in the HelmholtzMedia library. Is your Z the compressibility factor? - matth
@matth yes exactly, that's what it is. I chose to calculate Z using the MSL roots-function firstly to be able to access the liquid-phase-Z as well as the vapour-phase-Z and secondly on an earlier development state, I experienced, that the solver automatically picked the wrong solution for Z which lead to nonsense results. - paulkernstock
OK here is how I solved this: I managed to give a derivative for Z and all the other functions. For some reasons the single Failed to reduce the DAE index.-Error remained though, with no further information what was wrong. So my conclusion was to write my own Newton-solving routine within a function which is working fine and converging pretty fast. Thanks @matth for your guidance. - paulkernstock

1 Answers

2
votes

This is not a full answer, but a list of interesting links that you should read: