metrumresearchgroup / FATODEc

C/C++ bindings of FATODE solver library
GNU General Public License v3.0
4 stars 1 forks source link

Is it possible to pass user data to right hand side function? #1

Open kylebaron opened 5 years ago

kylebaron commented 5 years ago
static void f(int* n, double* t, double y[], double fy[], double* theta) {
  fy[0] = y[1];
  fy[1] = -y[0] - theta[0] * y[1];
}
kylebaron commented 5 years ago

@yizhang-cae

yizhang-yiz commented 5 years ago

Yes, but only in C++ binding. The implementation follows Stan's function signature. An example can be found in unit test https://github.com/metrumresearchgroup/FATODEc/blob/70239155cebb85eb05d7435e82c36d648efba80c/test/roberts_test.cpp#L45

One defines the RHS as a functor, with theta, x_r, x_i being parameters from user. Jacobian is defined similarly. To solve it one calls the functions in fatode_cc namespace, such as https://github.com/metrumresearchgroup/FATODEc/blob/70239155cebb85eb05d7435e82c36d648efba80c/test/roberts_test.cpp#L172

I'll add an formal example later.

kylebaron commented 5 years ago

Thanks; I didn't appreciate the difference there. But just what I was looking for.