Skip to content

Commit

Permalink
changed the repo and package name
Browse files Browse the repository at this point in the history
  • Loading branch information
sn248 committed May 18, 2018
1 parent bf9cabc commit ad6b926
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 36 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: Rcppsbmod
Package: sundialr
Type: Package
Title: Provides a Wrapper Around CVODE from Sundials Library
Title: Ordinary Differential Equation Solvers (ODE) from Sundials C Library in R
Version: 0.1.0
Author: Satya
Maintainer: Satya <[email protected]>
Description: Provides a way to call the CVODE function in SUNDIALS C ODE solving library.
Author: Satyaprakash Nayak
Maintainer: Satyaprakash Nayak <[email protected]>
Description: Provides a way to call the functions in SUNDIALS C ODE solving library (developed by Lawrence Livermore National Laboratory) in R. Currently ODE solver, CVODE, and routine to perform sensitivity analysis, CVODES, from the library can be accessed.
License: MIT + file LICENSE
LazyData: TRUE
Imports:
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
useDynLib(Rcppsbmod)
useDynLib(sundialr)
6 changes: 3 additions & 3 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#'@param reltolerance Relative Tolerance (a scalar)
#'@param abstolerance Absolute Tolerance (a vector with length equal to ydot)
cvode <- function(time_vec, IC, xpsexp, reltolerance, abstolerance) {
.Call('_Rcppsbmod_cvode', PACKAGE = 'Rcppsbmod', time_vec, IC, xpsexp, reltolerance, abstolerance)
.Call('_sundialr_cvode', PACKAGE = 'sundialr', time_vec, IC, xpsexp, reltolerance, abstolerance)
}

#'cvode
#'cvode_test
#'
#' CVODE solver to solve stiff ODEs
#'@param time_vec time vector
Expand All @@ -22,6 +22,6 @@ cvode <- function(time_vec, IC, xpsexp, reltolerance, abstolerance) {
#'@param reltolerance Relative Tolerance (a scalar)
#'@param abstolerance Absolute Tolerance (a vector with length equal to ydot)
cvode_test <- function(time_vec, IC, xpsexp, reltolerance, abstolerance) {
.Call('_Rcppsbmod_cvode_test', PACKAGE = 'Rcppsbmod', time_vec, IC, xpsexp, reltolerance, abstolerance)
.Call('_sundialr_cvode_test', PACKAGE = 'sundialr', time_vec, IC, xpsexp, reltolerance, abstolerance)
}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Rcppsbmod
# sundialr

A wrapper around the SUNDIALS ODE solving library.
A wrapper around the SUNDIALS ODE solving C library.
2 changes: 1 addition & 1 deletion man/cvode_test.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ $(SOURCES_SUNLINSOL_DENSE) $(SOURCES_SUNMAT)

OBJECTS_SUNDIALS_ALL = $(SOURCES_SUNDIALS_ALL:.c=.o)

all: ($SHLIB) ../inst/libsundials_all.a
all: ($SHLIB)

($SHLIB): $(OBJECTS) ../inst/libsundials_all.a

../inst/libsundials_all.a: $(OBJECTS_SUNDIALS_ALL)
ar -rvs ../inst/libsundials_all.a $(OBJECTS_SUNDIALS_ALL)
$(AR) -crvs ../inst/libsundials_all.a $(OBJECTS_SUNDIALS_ALL)

clean:
echo "cleaning .."
(rm -f ./sundials/cvode/*.o; rm -f ./sundials/nvec_ser/*.o; rm -f ./sundials/sun*/*.o;)
(rm -f *.o *.a)
(rm -f ../inst/*.a)
4 changes: 3 additions & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ $(SOURCES_SUNLINSOL_DENSE) $(SOURCES_SUNMAT)

OBJECTS_SUNDIALS_ALL = $(SOURCES_SUNDIALS_ALL:.c=.o)

all: ($SHLIB) ../inst/libsundials_all.a
all: ($SHLIB)

($SHLIB): $(OBJECTS) ../inst/libsundials_all.a

../inst/libsundials_all.a: $(OBJECTS_SUNDIALS_ALL)
$(AR) -crvs ../inst/libsundials_all.a $(OBJECTS_SUNDIALS_ALL)
$(RANLIB) -v $@
10 changes: 5 additions & 5 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace Rcpp;

// cvode
NumericMatrix cvode(NumericVector time_vec, NumericVector IC, SEXP xpsexp, double reltolerance, NumericVector abstolerance);
RcppExport SEXP _Rcppsbmod_cvode(SEXP time_vecSEXP, SEXP ICSEXP, SEXP xpsexpSEXP, SEXP reltoleranceSEXP, SEXP abstoleranceSEXP) {
RcppExport SEXP _sundialr_cvode(SEXP time_vecSEXP, SEXP ICSEXP, SEXP xpsexpSEXP, SEXP reltoleranceSEXP, SEXP abstoleranceSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -22,7 +22,7 @@ END_RCPP
}
// cvode_test
NumericMatrix cvode_test(NumericVector time_vec, NumericVector IC, SEXP xpsexp, double reltolerance, NumericVector abstolerance);
RcppExport SEXP _Rcppsbmod_cvode_test(SEXP time_vecSEXP, SEXP ICSEXP, SEXP xpsexpSEXP, SEXP reltoleranceSEXP, SEXP abstoleranceSEXP) {
RcppExport SEXP _sundialr_cvode_test(SEXP time_vecSEXP, SEXP ICSEXP, SEXP xpsexpSEXP, SEXP reltoleranceSEXP, SEXP abstoleranceSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -37,12 +37,12 @@ END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_Rcppsbmod_cvode", (DL_FUNC) &_Rcppsbmod_cvode, 5},
{"_Rcppsbmod_cvode_test", (DL_FUNC) &_Rcppsbmod_cvode_test, 5},
{"_sundialr_cvode", (DL_FUNC) &_sundialr_cvode, 5},
{"_sundialr_cvode_test", (DL_FUNC) &_sundialr_cvode_test, 5},
{NULL, NULL, 0}
};

RcppExport void R_init_Rcppsbmod(DllInfo *dll) {
RcppExport void R_init_sundialr(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
117 changes: 110 additions & 7 deletions src/cvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ using namespace Rcpp;
// #define NOUT 12

//------------------------------------------------------------------------------
struct sexp_global {
SEXP sexp_g;
};

// struct sexp_global my_sexp_g = {R_NilValue};
// struct sexp_global *my_sexp = &my_sexp_g;

typedef int (*funcPtr)(realtype time, N_Vector y, N_Vector ydot, void *user_data);
typedef NumericVector (*funcPtr_test) (double t, NumericVector y, NumericVector ydot);

struct rhs_data{
SEXP rhs_eqn;
};

struct rhs_data my_rhs = {R_NilValue}; // sets rhs_eqn to NULL
struct rhs_data *my_rhs_ptr = &my_rhs;
//------------------------------------------------------------------------------

// function with the definition required
Expand Down Expand Up @@ -198,9 +213,9 @@ NumericMatrix cvode (NumericVector time_vec, NumericVector IC, SEXP xpsexp,


// cvode - test ----------------------------------------------------------------
typedef int (*funcPtr_test)(double time, NumericVector y, NumericVector ydot);
// typedef int (*funcPtr_test)(double time, NumericVector y, NumericVector ydot);

SEXP sexp_g; // declare a global SEXP
// SEXP sexp_g = R_NilValue; // declare a global SEXP

// XPtr<funcPtr_test> xpfun(sexp_g);
// funcPtr_test fun_test = *xpfun;
Expand All @@ -216,8 +231,12 @@ int fun_test1(realtype t, N_Vector y, N_Vector ydot, void* user_data){
y1[i] = NV_Ith_S(y,i);
}

// cast void pointer to struct
struct rhs_data *my_rhs_ptr2 = (struct rhs_data*)user_data;
SEXP xpsexp = (*my_rhs_ptr2).rhs_eqn;

// use function pointer to get the derivatives
XPtr<funcPtr_test> xpfun(sexp_g);
XPtr<funcPtr_test> xpfun(xpsexp);
funcPtr_test fun_test = *xpfun;

NumericVector ydot1(y1.length());
Expand All @@ -233,7 +252,49 @@ int fun_test1(realtype t, N_Vector y, N_Vector ydot, void* user_data){

return (0);
}
//'cvode

int fun_test2(realtype t, N_Vector y, N_Vector ydot, void* user_data){

// convert y to NumericVector y1
int y_len = NV_LENGTH_S(y);

NumericVector y1(y_len); // filled with zeros
for (int i = 0; i < y_len; i++){
y1[i] = NV_Ith_S(y,i);
}

// convert ydot to NumericVector ydot1
int ydot_len = NV_LENGTH_S(ydot);

NumericVector ydot1(ydot_len); // filled with zeros
for (int i = 0; i < ydot_len; i++){
ydot1[i] = NV_Ith_S(ydot,i);
}

// cast void pointer to struct
struct rhs_data *my_rhs_ptr2 = (struct rhs_data*)user_data;
SEXP xpsexp = (*my_rhs_ptr2).rhs_eqn;

// use function pointer to get the derivatives
XPtr<funcPtr_test> xpfun(xpsexp);
funcPtr_test fun = *xpfun;


ydot1 = fun(t, y1, ydot1);

// convert NumericVector ydot1 to N_Vector ydot
// N_Vector ydot; ydot = NULL;
// ydot = N_VNew_Serial(ydot1.length());
for (int i = 0; i<ydot1.length(); i++){
NV_Ith_S(ydot, i) = ydot1[i];
}


// return ydot1;
return(0);
}

//'cvode_test
//'
//' CVODE solver to solve stiff ODEs
//'@param time_vec time vector
Expand Down Expand Up @@ -315,8 +376,18 @@ NumericMatrix cvode_test (NumericVector time_vec, NumericVector IC,
// NV_Ith_S(ydot1, i) = ydot[i];
// }

sexp_g = xpsexp; // assign to glocal sexp
flag = CVodeInit(cvode_mem, fun_test1, T0, y0);
// (*my_sexp).sexp_g = xpsexp; // assign to glocal sexp

(*my_rhs_ptr).rhs_eqn = xpsexp;

void* my_rhs_ptr1 = (void*)&my_rhs;

flag = CVodeSetUserData(cvode_mem, (void*)&my_rhs);
if (check_flag(&flag, "CVodeSetUserData", 1)) {
return (1);
}

flag = CVodeInit(cvode_mem, fun_test2, T0, y0);

// flag = CVodeInit(cvode_mem, fun, T0, y0);
if (check_flag(&flag, "CVodeInit", 1)) {
Expand Down Expand Up @@ -352,7 +423,8 @@ NumericMatrix cvode_test (NumericVector time_vec, NumericVector IC,

// NumericMatrix to store results - filled with 0.0
// First row for initial conditions, First column is for time
NumericMatrix soln = NumericMatrix(time_vec.length()+1, IC.length() + 1);
// ASSUMING input time vector (time_vec) has the first element as 0
NumericMatrix soln = NumericMatrix(time_vec.length(), IC.length() + 1);

// fill the first row of soln matrix with Initial Conditions
soln(0,0) = time_vec[0];
Expand Down Expand Up @@ -445,4 +517,35 @@ int check_flag(void *flagvalue, const char *funcname, int opt)
}


//------------------------------------------------------------------------------

// // [[Rcpp::export]]
// NumericVector test_sexp(double t, NumericVector y, NumericVector ydot, SEXP xpsexp){
//
// // convert NumericVector to N_Vector
// // Set the initial conditions-------------------------------------------------
// N_Vector y0; y0 = NULL;
// y0 = N_VNew_Serial(y.length());
// for (int i = 0; i<y.length(); i++){
// NV_Ith_S(y0, i) = y[i];
// }
//
// N_Vector ydot0; ydot0 = NULL;
// ydot0 = N_VNew_Serial(ydot.length());
// for (int i = 0; i<ydot.length(); i++){
// NV_Ith_S(ydot0, i) = ydot[i];
// }
//
// (*my_rhs_ptr).rhs_eqn = xpsexp;
//
// // XPtr<funcPtr_test> xpfun(xpsexp);
// // funcPtr_test fun = *xpfun;
// //
// // return fun(t, y, ydot);
//
// return fun_test2(t, y0, ydot0, (void*)&my_rhs);
//
// }



File renamed without changes.
6 changes: 3 additions & 3 deletions vignettes/my-vignette.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: "Rcppsbmod - A wrapper around CVODE solver from SUNDIALS"
author: "Satya"
title: "sundialr - A wrapper around SUNDIALS ODE solving library"
author: "Satyaprakash Nayak"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Rcppsbmod - A wrapper around CVODE solver from SUNDIALS}
%\VignetteIndexEntry{sundialr - A wrapper around CVODE solver from SUNDIALS}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
12 changes: 6 additions & 6 deletions vignettes/my-vignette.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="Satya" />
<meta name="author" content="Satyaprakash Nayak" />

<meta name="date" content="2018-03-14" />
<meta name="date" content="2018-05-18" />

<title>Rcppsbmod - A wrapper around CVODE solver from SUNDIALS</title>
<title>sundialr - A wrapper around SUNDIALS ODE solving library</title>



Expand All @@ -30,9 +30,9 @@



<h1 class="title toc-ignore">Rcppsbmod - A wrapper around CVODE solver from SUNDIALS</h1>
<h4 class="author"><em>Satya</em></h4>
<h4 class="date"><em>2018-03-14</em></h4>
<h1 class="title toc-ignore">sundialr - A wrapper around SUNDIALS ODE solving library</h1>
<h4 class="author"><em>Satyaprakash Nayak</em></h4>
<h4 class="date"><em>2018-05-18</em></h4>



Expand Down

0 comments on commit ad6b926

Please sign in to comment.