Skip to content

Commit

Permalink
#1863 done use the cxx11 namespace for std::string to match casadi
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Apr 4, 2022
1 parent fee37fc commit 259adf0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# casadi seems to compile without the newer versions of std::string
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)

if(NOT PYBIND11_DIR)
set(PYBIND11_DIR pybind11)
endif()
Expand Down
29 changes: 13 additions & 16 deletions pybamm/solvers/c_solvers/idaklu_casadi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CasadiFunction {
};


class PybammFunctions {
class CasadiFunctions {
public:
int number_of_states;
int number_of_parameters;
Expand All @@ -64,7 +64,7 @@ class PybammFunctions {
CasadiFunction mass_action;
CasadiFunction events;

PybammFunctions(const Function &rhs_alg,
CasadiFunctions(const Function &rhs_alg,
const Function &jac_times_cjmass,
const int jac_times_cjmass_nnz,
const np_array_int &jac_times_cjmass_rowvals,
Expand Down Expand Up @@ -101,8 +101,8 @@ class PybammFunctions {
int residual_casadi(realtype tres, N_Vector yy, N_Vector yp, N_Vector rr,
void *user_data)
{
PybammFunctions *p_python_functions =
static_cast<PybammFunctions *>(user_data);
CasadiFunctions *p_python_functions =
static_cast<CasadiFunctions *>(user_data);

//std::cout << "RESIDUAL t = " << tres << " y = [";
//for (int i = 0; i < p_python_functions->number_of_states; i++) {
Expand Down Expand Up @@ -179,8 +179,8 @@ int residual_casadi(realtype tres, N_Vector yy, N_Vector yp, N_Vector rr,
int jtimes_casadi(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr,
N_Vector v, N_Vector Jv, realtype cj, void *user_data,
N_Vector tmp1, N_Vector tmp2) {
PybammFunctions *p_python_functions =
static_cast<PybammFunctions *>(user_data);
CasadiFunctions *p_python_functions =
static_cast<CasadiFunctions *>(user_data);

// rr has ∂F/∂y v
py::buffer_info input_buf = p_python_functions->inputs.request();
Expand Down Expand Up @@ -224,8 +224,8 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp,
N_Vector resvec, SUNMatrix JJ, void *user_data, N_Vector tempv1,
N_Vector tempv2, N_Vector tempv3) {

PybammFunctions *p_python_functions =
static_cast<PybammFunctions *>(user_data);
CasadiFunctions *p_python_functions =
static_cast<CasadiFunctions *>(user_data);

// create pointer to jac data, column pointers, and row values
sunindextype *jac_colptrs = SUNSparseMatrix_IndexPointers(JJ);
Expand Down Expand Up @@ -275,8 +275,8 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp,
int events_casadi(realtype t, N_Vector yy, N_Vector yp, realtype *events_ptr,
void *user_data)
{
PybammFunctions *p_python_functions =
static_cast<PybammFunctions *>(user_data);
CasadiFunctions *p_python_functions =
static_cast<CasadiFunctions *>(user_data);

//std::cout << "EVENTS" << std::endl;
//std::cout << "t = " << t << " y = [";
Expand Down Expand Up @@ -331,8 +331,8 @@ int sensitivities_casadi(int Ns, realtype t, N_Vector yy, N_Vector yp,
N_Vector resval, N_Vector *yS, N_Vector *ypS, N_Vector *resvalS,
void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) {

PybammFunctions *p_python_functions =
static_cast<PybammFunctions *>(user_data);
CasadiFunctions *p_python_functions =
static_cast<CasadiFunctions *>(user_data);

const int np = p_python_functions->number_of_parameters;

Expand Down Expand Up @@ -508,7 +508,7 @@ Solution solve_casadi(np_array t_np, np_array y0_np, np_array yp0_np,
IDARootInit(ida_mem, number_of_events, events_casadi);

// set pybamm functions by passing pointer to it
PybammFunctions* p_pybamm_functions = new PybammFunctions(
CasadiFunctions pybamm_functions = CasadiFunctions(
rhs_alg,
jac_times_cjmass,
jac_times_cjmass_nnz,
Expand All @@ -519,7 +519,6 @@ Solution solve_casadi(np_array t_np, np_array y0_np, np_array yp0_np,
sens, events,
number_of_states, number_of_events,
number_of_parameters);
PybammFunctions &pybamm_functions = *p_pybamm_functions;

void *user_data = &pybamm_functions;
IDASetUserData(ida_mem, user_data);
Expand Down Expand Up @@ -731,8 +730,6 @@ Solution solve_casadi(np_array t_np, np_array y0_np, np_array yp0_np,
IDAFree(&ida_mem);

//std::cout << "finished solving 9" << std::endl;
// Why does this bus error?
// delete p_pybamm_functions;

//std::cout << "finished solving 10" << std::endl;

Expand Down

0 comments on commit 259adf0

Please sign in to comment.