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?
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 - matthZis the output of the MSL-functionModelica.Math.Vectors.Utilities.roots. How do I get the differential of a root calculation from a third grade polynomial? - paulkernstockdensity_ph(and the functions that it calls) of Modelica.Media.R134a or in the HelmholtzMedia library. Is yourZthe compressibility factor? - matthZusing 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 forZwhich lead to nonsense results. - paulkernstockFailed 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