/** * Function called by cvodes to evaluate ydot given y. The CVODE * integrator allows passing in a void* pointer to access * external data. This pointer is cast to a pointer to a instance * of class FuncEval. The equations to be integrated should be * specified by deriving a class from FuncEval that evaluates the * desired equations. * @ingroup odeGroup */ static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot, void* f_data) { try { double* ydata = NV_DATA_S(y); double* ydotdata = NV_DATA_S(ydot); FuncData* d = (FuncData*)f_data; FuncEval* f = d->m_func; if (d->m_pars.size() == 0) { f->eval(t, ydata, ydotdata, NULL); } else { f->eval(t, ydata, ydotdata, d->m_pars.data()); } } catch (CanteraError& err) { std::cerr << err.what() << std::endl; return 1; // possibly recoverable error } catch (...) { std::cerr << "cvodes_rhs: unhandled exception" << std::endl; return -1; // unrecoverable error } return 0; // successful evaluation }
/** * Function called by cvodes to evaluate ydot given y. The CVODE integrator * allows passing in a void* pointer to access external data. This pointer * is cast to a pointer to a instance of class FuncEval. The equations to be * integrated should be specified by deriving a class from FuncEval that * evaluates the desired equations. * @ingroup odeGroup */ static int cvodes_rhs(realtype t, N_Vector y, N_Vector ydot, void* f_data) { try { FuncEval* f = (FuncEval*) f_data; f->eval(t, NV_DATA_S(y), NV_DATA_S(ydot), f->m_sens_params.data()); } catch (CanteraError& err) { std::cerr << err.what() << std::endl; return 1; // possibly recoverable error } catch (std::exception& err) { std::cerr << "cvodes_rhs: unhandled exception:" << std::endl; std::cerr << err.what() << std::endl; return -1; // unrecoverable error } catch (...) { std::cerr << "cvodes_rhs: unhandled exception of uknown type" << std::endl; return -1; // unrecoverable error } return 0; // successful evaluation }