Access derivatives from Embedded Coder

조회 수: 2(최근 30일)
Etienne Coetzee
Etienne Coetzee 2013년 11월 10일
Hi Folks
I am trying to access the derivative values from code generated by embedded coder. I have a Fortran program that is linked to a c-function via the ISO_C_BINDING module (below). I am now trying to link this function to the generated code from embedded coder. When I define the derivative values in C in the below function, the program works correctly. I then generate code from a Simulink model that contains the same derivative definitions, but cannot figure out if I have implemented the code in the best way. I have included the code below. It seems to work, but I am having to initialise the model on each iteration, which does not seem correct. I cannot figure out why. I have initialised it before this function call as well, but this doe not work, hence I have to initialise on each iteration. The code also does not work when running with OpenMP, even though the original C-code does work with OpenMP. Any help or examples will be appreciated.
Cheers, Etienne
#include "fintrf.h"
#include "auto_f2c.h"
#include <stdio.h> /* This ert_main.c example uses printf/fflush */
#include "ab.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
/*extern void ab_initialize(void);*/
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* ab : The A --> B reaction */
/* ---------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/* Subroutine */ int func(integer *ndim, doublereal *u, integer *icp,
doublereal *par, integer *ijac, doublereal *f, doublereal *dfdu,
doublereal *dfdp)
/* ---------- ---- */
/* Evaluates the algebraic equations or ODE right hand side */
/* Input arguments : */
/* NDIM : Dimension of the ODE system */
/* U : State variables */
/* ICP : Array indicating the free parameter(s) */
/* PAR : Equation parameters */
/* Values to be returned : */
/* F : ODE right hand side values */
/* Normally unused Jacobian arguments : IJAC, DFDU, DFDP (see manual)*/
real_T *f0 = 0;
/* Function Body */
/* InitializeConditions for Integrator: '<Root>/U2' */
f[0] = ab_dX.U1_CSTATE;
f[1] = ab_dX.U2_CSTATE;
return 0;
} /* func_ */



Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by