Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

derivative annotation doubt

derivative annotation doubt

Hello all

I have questions about the use of "derivative" annotation I wanted to ask you. Lets put a sample.

The equation is this:

Code:

z_level = LevelZ(time);

where LevelZ(time) is an external C function, and there are also LevelZ_der(time) and LevelZ_der2(time) that are the first and second derivative.

It the code is like this, it works well...

Code:

function LevelZ_der2

    input Real t;
    input Real dt;
    input Real ddt;
    output Real res;
external
    res = LevelZ_der2(t);
annotation(Library="...", Include="..."); 
end LevelZ_der2;

function LevelZ_der
    input Real t
    input Real dt
    output Real res;
external
    res = LevelZ_der(t);
annotation(derivative=LevelZ_der2,
           Library="...", Include="..."); 
end LevelZ_der;

function LevelZ
    input Real t
    output Real res;
external
    res = LevelZ(t)
annotation(derivative=LevelZ_der,
           derivative(order=2)=LevelZ_der2,
           Library="...", Include="..."); 
end LevelZ;

... although these errors appear:

Code:

[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der2.

[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable ddt in function .LevelZ_der2.
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der.

Error: Derivative of expression
Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.

And if the code is like this, OpenModelica ignores the derivatives...

Code:

function LevelZ_der2

    input Real t;
    output Real res;
external
    res = LevelZ_der2(t);
annotation(Library="...", Include="..."); 
end LevelZ_der2;

function LevelZ_der
    input Real t
    output Real res;
external
    res = LevelZ_der(t);
annotation(derivative(zeroDerivative=t)=LevelZ_der2,
           Library="...", Include="..."); 
end LevelZ_der;

function LevelZ
    input Real t
    output Real res;
external
    res = LevelZ(t)
annotation(derivative(zeroDerivative=t)=LevelZ_der, 
           derivative(order=2)=LevelZ_der2,
           Library="...", Include="..."); 
end LevelZ;

... and this error appear:

Code:

Error: Derivative of expression 

Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.

What is the right way to do it?

Best regards
Koldo

Edited by: Koldo - Nov-21-14 21:57:13

Re: derivative annotation doubt

"Error: Derivative of expression
Differentiate.differentiateExpSolve failed ..." error message is got for almost all external functions called, even the simplest:

netpower = power*Performance(speed);

where while "power" and "speed" are obtained by solving differential equations, Performance() is a "pure" external function and "netpower"  is just an output.

Do you now how to solve this?

Edited by: Koldo - Mar-11-15 16:16:21
There are 0 guests and 0 other users also viewing this topic
You are here: