Skip to content

Commit

Permalink
Merge pull request #87 from ICB-DCM/dw_work
Browse files Browse the repository at this point in the history
Cleanup API
  • Loading branch information
dweindl authored May 9, 2017
2 parents e0d11bc + 4da8e66 commit a841b0c
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 166 deletions.
26 changes: 13 additions & 13 deletions include/amici.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
void *setupAMI(int *status, UserData *udata, TempData *tdata);
void setupAMIB(int *status, void *ami_mem, UserData *udata, TempData *tdata);

void getDataSensisFSA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getDataSensisASA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getDataSensisFSA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);
void getDataSensisASA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);

void getEventSensisFSA(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, TempData *tdata);
void getEventSensisASA(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getEventSensisASA(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);

void getEventSigma(int *status, int ie, int iz, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getEventObjective(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getEventSigma(int *status, int ie, int iz, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);
void getEventObjective(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);

void getDataOutput(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getEventOutput(int *status, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void fillEventOutput(int *status, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void getDataOutput(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);
void getEventOutput(int *status, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);
void fillEventOutput(int *status, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);

void handleEvent(int *status, int *iroot, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata, int seflag);
void handleDataPoint(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata);
void handleEvent(int *status, int *iroot, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata, int seflag);
void handleDataPoint(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata);
void handleDataPointB(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, TempData *tdata);
void handleEventB(int *status, int iroot, void *ami_mem, UserData *udata, TempData *tdata);

Expand All @@ -61,11 +61,11 @@ void updateHeavisideB(int *status, int iroot, UserData *udata, TempData *tdata);
void getDiagnosis(int *status,int it, void *ami_mem, UserData *udata, ReturnData *rdata);
void getDiagnosisB(int *status,int it, void *ami_mem, UserData *udata, ReturnData *rdata, TempData *tdata);

int workForwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, ExpData *edata, int* status, void *ami_mem, int* iroot);
int workBackwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, ExpData *edata, int *status, void *ami_mem, int *iroot, booleantype *setupBdone);
int workForwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, const ExpData *edata, int* status, void *ami_mem, int* iroot);
int workBackwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, const ExpData *edata, int *status, void *ami_mem, int *iroot, booleantype *setupBdone);
void storeJacobianAndDerivativeInReturnData(UserData *udata, TempData *tdata, ReturnData *rdata);
void freeTempDataAmiMem(UserData *udata, TempData *tdata, void *ami_mem, booleantype setupBdone, int status);
void applyChainRuleFactorToSimulationResults(const UserData *udata, ReturnData *rdata, ExpData *edata);
void applyChainRuleFactorToSimulationResults(const UserData *udata, ReturnData *rdata, const ExpData *edata);
void unscaleParameters(UserData *udata);

void processUserData(UserData *udata);
Expand Down
23 changes: 20 additions & 3 deletions include/amici_interface_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@
#define EXTERNC
#endif

EXTERNC void initUserDataFields(UserData user_data, ReturnData *rdata, double *pstatus);
EXTERNC ReturnData *getSimulationResults(UserData *udata, ExpData *edata, int *pstatus);
EXTERNC ReturnData *initReturnData(UserData *udata, int *pstatus);
/**
* getSimulationResults runs the forward an backwards simulation and returns results in a ReturnData struct
*
* @param[in] udata pointer to the user data struct @type UserData
* @param[in] edata pointer to the experimental data struct @type ExpData
* @param[out] pstatus flag indicating success of execution @type *int
* @return rdata data struct with simulation results @type ReturnData
*/

EXTERNC ReturnData *getSimulationResults(UserData *udata, const ExpData *edata, int *pstatus);

/**
* initReturnData initialises a ReturnData struct
*
* @param[in] udata pointer to the user data struct @type UserData
* @param[out] pstatus flag indicating success of execution @type *int
* @return rdata initialized return data struct @type ReturnData
*/

EXTERNC ReturnData *initReturnData(const UserData *udata, int *pstatus);

#endif
27 changes: 24 additions & 3 deletions include/amici_interface_matlab.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
#include <mex.h>
#include "include/amici.h"

UserData *setupUserData(const mxArray *prhs[]);
ReturnData *setupReturnData(mxArray *plhs[], UserData *udata, double *pstatus);
ExpData *setupExpData(const mxArray *prhs[], UserData *udata, int *status);
/**
* @brief userDataFromMatlabCall extracts information from the matlab call and returns the corresponding UserData struct
* @param[in] prhs: pointer to the array of input arguments @type mxArray
* @return udata: struct containing all provided user data @type UserData
*/
UserData *userDataFromMatlabCall(const mxArray *prhs[]);

/**
* setupReturnData initialises the return data struct
* @param[in] plhs user input @type mxArray
* @param[in] udata pointer to the user data struct @type UserData
* @param[out] pstatus pointer to the flag indicating the execution status @type double
* @return rdata: return data struct @type ReturnData
*/
ReturnData *setupReturnData(mxArray *plhs[], const UserData *udata, double *pstatus);

/**
* expDataFromMatlabCall initialises the experimental data struct
* @param[in] prhs user input @type *mxArray
* @param[in] udata pointer to the user data struct @type UserData
* @param[out] status non-zero on failure, zero on success
* @return edata: experimental data struct @type ExpData
*/
ExpData *expDataFromMatlabCall(const mxArray *prhs[], const UserData *udata, int *status);


#endif
26 changes: 13 additions & 13 deletions src/amici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void setupAMIB(int *status,void *ami_mem, UserData *udata, TempData *tdata) {
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getDataSensisFSA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getDataSensisFSA(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getDataSensisFSA extracts data information for forward sensitivity analysis
*
Expand Down Expand Up @@ -583,7 +583,7 @@ void getDataSensisFSA(int *status, int it, void *ami_mem, UserData *udata, Retur
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void prepDataSensis(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void prepDataSensis(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* prepDataSensis preprocesses the provided experimental data to compute sensitivities via adjoint or forward methods later on
*
Expand Down Expand Up @@ -647,7 +647,7 @@ void prepDataSensis(int *status, int it, void *ami_mem, UserData *udata, ReturnD
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getDataOutput(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getDataOutput(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getDataOutput extracts output information for data-points
*
Expand Down Expand Up @@ -755,7 +755,7 @@ void getEventSensisFSA_tf(int *status, int ie, void *ami_mem, UserData *udata, R
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getEventSensisASA(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getEventSensisASA(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getEventSensisASA extracts event information for adjoint sensitivity analysis
*
Expand Down Expand Up @@ -808,7 +808,7 @@ void getEventSensisASA(int *status, int ie, void *ami_mem, UserData *udata, Retu
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getEventSigma(int *status, int ie, int iz, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getEventSigma(int *status, int ie, int iz, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getEventSigma extracts fills sigma_z either from the user defined function or from user input
*
Expand Down Expand Up @@ -839,7 +839,7 @@ void getEventSigma(int *status, int ie, int iz, void *ami_mem, UserData *udata,
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getEventObjective(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getEventObjective(int *status, int ie, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getEventObjective updates the objective function on the occurence of an event
*
Expand Down Expand Up @@ -871,7 +871,7 @@ void getEventObjective(int *status, int ie, void *ami_mem, UserData *udata, Retu
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void getEventOutput(int *status, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void getEventOutput(int *status, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* getEventOutput extracts output information for events
*
Expand Down Expand Up @@ -928,7 +928,7 @@ void getEventOutput(int *status, realtype *tlastroot, void *ami_mem, UserData *u
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void fillEventOutput(int *status, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void fillEventOutput(int *status, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* fillEventOutput fills missing roots at last timepoint
*
Expand Down Expand Up @@ -985,7 +985,7 @@ void fillEventOutput(int *status, void *ami_mem, UserData *udata, ReturnData *rd
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void handleDataPoint(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata) {
void handleDataPoint(int *status, int it, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata) {
/**
* handleDataPoint executes everything necessary for the handling of data points
*
Expand Down Expand Up @@ -1061,7 +1061,7 @@ void handleDataPointB(int *status, int it, void *ami_mem, UserData *udata, Retur
/* ------------------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------------------- */

void handleEvent(int *status, int *iroot, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, ExpData *edata, TempData *tdata, int seflag) {
void handleEvent(int *status, int *iroot, realtype *tlastroot, void *ami_mem, UserData *udata, ReturnData *rdata, const ExpData *edata, TempData *tdata, int seflag) {
/**
* handleEvent executes everything necessary for the handling of events
*
Expand Down Expand Up @@ -1538,7 +1538,7 @@ void getDiagnosisB(int *status,int it, void *ami_mem, UserData *udata, ReturnDat
}


int workForwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, ExpData *edata, int *status, void *ami_mem, int *iroot) {
int workForwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, const ExpData *edata, int *status, void *ami_mem, int *iroot) {
/**
* workForwardProblem solves the forward problem. if forward sensitivities are enabled this will also compute sensitivies
*
Expand Down Expand Up @@ -1620,7 +1620,7 @@ int workForwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, ExpD
return 0;
}

int workBackwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, ExpData *edata, int *status, void *ami_mem, int *iroot, booleantype *setupBdone) {
int workBackwardProblem(UserData *udata, TempData *tdata, ReturnData *rdata, const ExpData *edata, int *status, void *ami_mem, int *iroot, booleantype *setupBdone) {
/**
* workBackwardProblem solves the backward problem. if adjoint sensitivities are enabled this will also compute sensitivies
* workForwardProblem should be called before this is function is called
Expand Down Expand Up @@ -1940,7 +1940,7 @@ void unscaleParameters(UserData *udata) {
}
}

void applyChainRuleFactorToSimulationResults(const UserData *udata, ReturnData *rdata, ExpData *edata)
void applyChainRuleFactorToSimulationResults(const UserData *udata, ReturnData *rdata, const ExpData *edata)
{
if(udata->am_pscale == AMI_SCALING_NONE)
return;
Expand Down
58 changes: 8 additions & 50 deletions src/amici_interface_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* @ param D2 number of columns in the matrix
*/
#define initField2(FIELD,D1,D2) \
double *mx ## FIELD; \
mx ## FIELD = new double[D1 * D2](); \
FIELD ## data = mx ## FIELD;
FIELD ## data = new double[D1 * D2]();

/**
* @ brief initialise 3D tensor and attach to the field
Expand All @@ -26,12 +24,7 @@ FIELD ## data = mx ## FIELD;
* @ param D3 number of elements in the third dimension of the tensor
*/
#define initField3(FIELD,D1,D2,D3) \
double *mx ## FIELD; \
dims ## FIELD[0]=D1; \
dims ## FIELD[1]=D2; \
dims ## FIELD[2]=D3; \
mx ## FIELD = new double[D1 * D2 * D3](); \
FIELD ## data = mx ## FIELD;
FIELD ## data = new double[D1 * D2 * D3]();

/**
* @ brief initialise 4D tensor and attach to the field
Expand All @@ -42,35 +35,16 @@ FIELD ## data = mx ## FIELD;
* @ param D4 number of elements in the fourth dimension of the tensor
*/
#define initField4(FIELD,D1,D2,D3,D4) \
double *mx ## FIELD; \
dims ## FIELD[0]=D1; \
dims ## FIELD[1]=D2; \
dims ## FIELD[2]=D3; \
dims ## FIELD[3]=D4; \
mx ## FIELD = new double[D1 * D2 * D3 * D4](); \
FIELD ## data = mx ## FIELD;
FIELD ## data = new double[D1 * D2 * D3 * D4]();


typedef double mxArray;



void initUserDataFields(UserData *udata, ReturnData *rdata) {
size_t dimssx[] = {0,0,0};
size_t dimssy[] = {0,0,0};
size_t dimssz[] = {0,0,0};
size_t dimssrz[] = {0,0,0};
size_t dimss2rz[] = {0,0,0,0};
size_t dimssigmay[] = {0,0,0};
size_t dimssigmaz[] = {0,0,0};
size_t dimsssigmay[] = {0,0,0};
size_t dimsssigmaz[] = {0,0,0};
static void initUserDataFields(const UserData user_data, ReturnData *rdata, double *pstatus);

void initUserDataFields(const UserData *udata, ReturnData *rdata) {
initField2(llh,1,1);
initField2(chi2,1,1);

double *mxts = new double[nt]();
tsdata = mxts;
tsdata = new double[nt]();

initField2(numsteps,nt,1);
initField2(numrhsevals,nt,1);
Expand Down Expand Up @@ -130,14 +104,7 @@ void initUserDataFields(UserData *udata, ReturnData *rdata) {
}


ReturnData *initReturnData(UserData *udata, int *pstatus) {
/**
* initReturnData initialises a ReturnData struct
*
* @param[in] udata pointer to the user data struct @type UserData
* @param[out] pstatus flag indicating success of execution @type *int
* @return rdata initialized return data struct @type ReturnData
*/
ReturnData *initReturnData(const UserData *udata, int *pstatus) {
ReturnData *rdata; /* returned rdata struct */

/* Return rdata structure */
Expand All @@ -155,16 +122,7 @@ ReturnData *initReturnData(UserData *udata, int *pstatus) {
}


ReturnData *getSimulationResults(UserData *udata, ExpData *edata, int *pstatus) {
/**
* getSimulationResults runs the forward an backwards simulation and returns results in a ReturnData struct
*
* @param[in] udata pointer to the user data struct @type UserData
* @param[in] edata pointer to the experimental data struct @type ExpData
* @param[out] pstatus flag indicating success of execution @type *int
* @return rdata data struct with simulation results @type ReturnData
*/

ReturnData *getSimulationResults(UserData *udata, const ExpData *edata, int *pstatus) {
double *originalParams = 0;

if(udata->am_pscale != AMI_SCALING_NONE) {
Expand Down
Loading

0 comments on commit a841b0c

Please sign in to comment.