Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int <FUNCTION_NAME> (realtype t, N_Vector y, N_Vector ydot, void *user_data)
- time_t <- c(0.0, 0.4, seq(from = 10.4, len = 12, by = 10)) # time vector
- cvode(time_t, c(1,0,0), my_fun, 1e-04, c(1e-08, 1e-08, 1e-08))
- if (fstr == "<USER_DEFINED_FUNCTION_NAME>")
- XPtr<funcPtr> fun(new funcPtr(&<USER_DEFINED_FUNCTION_NAME>), true);
- else
- Rcpp::Rout << "Supply the correct function name" << std::endl;
- #include <Rcpp.h>
- using namespace Rcpp;
- #include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
- #include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
- #include <cvode/cvode_dense.h> /* prototype for CVDense */
- #include <sundials/sundials_dense.h> /* definitions DlsMat DENSE_ELEM */
- #include <sundials/sundials_types.h> /* definition of type realtype */
- int test (realtype t, N_Vector y, N_Vector ydot, void *user_data){
- // static keyword before int is not really required here
- NV_Ith_S(ydot,0) = -0.04 * NV_Ith_S(y,0) + 1e04 * NV_Ith_S(y,1) * NV_Ith_S(y,2);
- NV_Ith_S(ydot,2) = 3e07 * NV_Ith_S(y,1) * NV_Ith_S(y,1);
- NV_Ith_S(ydot,1) = -NV_Ith_S(ydot,0) - NV_Ith_S(ydot,2);
- return(0);
- }
- // declare funcPtr as a type for function pointer to a function with the
- // signature same as function which describes the RHS for ODEs
- // see reference here - http://gallery.rcpp.org/articles/passing-cpp-function-pointers/
- typedef int (*funcPtr)(realtype t, N_Vector y, N_Vector ydot, void *user_data);
- // [[Rcpp::export]]
- XPtr<funcPtr> putFunPtrInXPtr() {
- // return(XPtr<funcPtr> (new funcPtr(&test)));
- XPtr<funcPtr> testptr(new funcPtr(&test), true);
- return testptr;
- }
Add Comment
Please, Sign In to add comment