Opened 2 years ago

Last modified 2 years ago

#5387 new defect

No error checking of derivative function for short class decl

Reported by: Jesper Mattsson Owned by: Jesper Mattsson
Priority: major Milestone:
Component: Modelica/FrontEnd Version: trunk
Keywords: Cc:

Description

If an InstShortClassDecl (not an InstSimpleShortClassDecl) points to a function with derivative annotation, then the derivative function isn't error checked. Also applies when the derivative annotation is on the short class decl. This is due to that check being implemented on InstFullClassDecl.

Might also apply to some other checks.

Example:

model Test
    function f
        input Real x;
        input Real z;
        output Real y;
    algorithm
        y := x ^ 2 + z;
        annotation(derivative=fd);
    end f;
    
    function fd
        input Real x;
        input Real z;
        input Real dx;
        input Real dz;
        output Real dy;
    algorithm
        dy := 2 * x * dx + dz + true;
    end fd;
    
    parameter Real p = 2;
    function f2 = f(z = p);
    
    Real x = f2(time);
end Test;

If the annotation is on a short class declaration that has no modifications, then the annotation is ignored entirely.

Example:

model Test
    function f
        input Real x;
        output Real y;
    algorithm
        y := x ^ 2;
    end f;
    
    function fd
        input Real x;
        input Real dx;
        output Real dy;
    algorithm
        dy := 2 * x * dx + true;
    end fd;
    
    parameter Real p = 2;
    function f2 = f annotation(derivative=fd);
    
    Real x = f2(time);
end Test;

Change History (1)

comment:1 Changed 2 years ago by Jesper Mattsson

Milestone: 2.1.x
Note: See TracTickets for help on using tickets.