Skip to content

Derivative annotation for NDTable evaluate function #10

@da-andersson

Description

@da-andersson

The evaluate function in SDF.NDTable was blocking generation of analytical ODE Jacobian for me. I found that the c-function to extract the table derivative is already available, so an easy fix is to add this annotation to evaluate:

annotation(derivative=evaluate_der);

and declare evaluate_der as

function evaluate_der
    input SDF.Types.ExternalNDTable table;
    input Real[:] params;
    input SDF.Types.InterpolationMethod interpMethod;
    input SDF.Types.ExtrapolationMethod extrapMethod;
    input Real[:] params_der;
    output Real value;
    external "C" value = ModelicaNDTable_evaluate_derivative(table, size(params, 1), params, interpMethod, extrapMethod, params_der) annotation (
      Include="#include <ModelicaNDTable.c>",
      IncludeDirectory="modelica://SDF/Resources/C-Sources");
  end evaluate_der;

The following test will verify that derivatives are correctly evaluated

model InterpolationMethodsDer "Tests table output differentiation"
  extends SDF.Examples.InterpolationMethods;
  Real der_hold = der(hold.y);
  Real der_nearest = der(nearest.y);
  Real der_linear = der(linear.y);
  Real der_akima = der(akima.y);
  Real der_fritsch_butland = der(fritsch_butland.y);
  Real der_steffen = der(steffen.y);

end InterpolationMethodsDer;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions