Skip to content

Commit

Permalink
Pre-commit tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbrittain committed Aug 31, 2023
1 parent 16c80ca commit 58cee45
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pybamm/solvers/c_solvers/idaklu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PYBIND11_MODULE(idaklu, m)

//py::bind_vector<std::vector<Function>>(m, "VectorFunction");
//py::implicitly_convertible<py::iterable, std::vector<Function>>();

m.def("create_casadi_solver", &create_casadi_solver,
"Create a casadi idaklu solver object",
py::arg("number_of_states"),
Expand Down
2 changes: 1 addition & 1 deletion pybamm/solvers/c_solvers/idaklu/CasadiSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
/*
* This is an abstract base class for the Idaklu solver
*/

CasadiSolver::CasadiSolver() {}
CasadiSolver::~CasadiSolver() {}
8 changes: 4 additions & 4 deletions pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* are intended to be overriden to support alternative solver
* approaches, as needed.
*/

/* Skeleton workflow:
https://sundials.readthedocs.io/en/latest/ida/Usage/index.html
1. (N/A) Initialize parallel or multi-threaded environment
Expand Down Expand Up @@ -135,7 +135,7 @@ void CasadiSolverOpenMP::Initialize() {
N_VConst(RCONST(0.0), yyS[is]);
N_VConst(RCONST(0.0), ypS[is]);
}

// create Matrix objects
SetMatrix();

Expand Down Expand Up @@ -210,7 +210,7 @@ CasadiSolverOpenMP::~CasadiSolverOpenMP()
N_VDestroy(yy);
N_VDestroy(yp);
N_VDestroy(id);

if (number_of_parameters > 0)
{
N_VDestroyVectorArray(yyS, number_of_parameters);
Expand Down Expand Up @@ -367,7 +367,7 @@ Solution CasadiSolverOpenMP::solve(
realtype *yS_return = new realtype[number_of_parameters *
number_of_timesteps *
length_of_return_vector];

res = new realtype[max_res_size];
res_dvar_dy = new realtype[max_res_dvar_dy];
res_dvar_dp = new realtype[max_res_dvar_dp];
Expand Down
2 changes: 1 addition & 1 deletion pybamm/solvers/c_solvers/idaklu/casadi_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ CasadiFunctions::CasadiFunctions(
for (auto& var : dvar_dp_fcns) {
this->dvar_dp_fcns.push_back(CasadiFunction(*var));
}

// copy across numpy array values
const int n_row_vals = jac_times_cjmass_rowvals_arg.request().size;
auto p_jac_times_cjmass_rowvals = jac_times_cjmass_rowvals_arg.unchecked<1>();
Expand Down
8 changes: 4 additions & 4 deletions pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void csc_csr(realtype f[], T1 c[], T1 r[], realtype nf[], T2 nc[], T2 nr[], int
int rr[N];
for (int i=0; i<cols+1; i++)
nc[i] = 0;

for (int k = 0, i = 0; i < cols+1; i++) {
for (int j = 0; j < r[i+1] - r[i]; j++) {
if (k == N) // SUNDIALS indexing does not include the count element
Expand Down Expand Up @@ -97,13 +97,13 @@ class CasadiFunctions
std::vector<CasadiFunction> var_casadi_fcns;
std::vector<CasadiFunction> dvar_dy_fcns;
std::vector<CasadiFunction> dvar_dp_fcns;

std::vector<int64_t> jac_times_cjmass_rowvals;
std::vector<int64_t> jac_times_cjmass_colptrs;
std::vector<realtype> inputs;

Options options;

realtype *get_tmp_state_vector();
realtype *get_tmp_sparse_jacobian_data();

Expand Down
4 changes: 2 additions & 2 deletions pybamm/solvers/c_solvers/idaklu/casadi_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CasadiSolver *create_casadi_solver(
const std::vector<Function*> dvar_dy_fcns,
const std::vector<Function*> dvar_dp_fcns,
py::dict options
) {
) {
auto options_cpp = Options(options);
auto functions = std::make_unique<CasadiFunctions>(
rhs_alg,
Expand All @@ -54,7 +54,7 @@ CasadiSolver *create_casadi_solver(
);

CasadiSolver *casadiSolver = nullptr;

// Instantiate solver class
if (options_cpp.linear_solver == "SUNLinSol_Dense")
{
Expand Down
4 changes: 2 additions & 2 deletions pybamm/solvers/c_solvers/idaklu/casadi_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ CasadiSolver *create_casadi_solver(
const Function &jac_times_cjmass,
const np_array_int &jac_times_cjmass_colptrs,
const np_array_int &jac_times_cjmass_rowvals,
const int jac_times_cjmass_nnz,
const int jac_times_cjmass_nnz,
const int jac_bandwidth_lower,
const int jac_bandwidth_upper,
const int jac_bandwidth_upper,
const Function &jac_action,
const Function &mass_action,
const Function &sens,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp,
realtype newjac[SUNSparseMatrix_NNZ(JJ)];
sunindextype *jac_ptrs = SUNSparseMatrix_IndexPointers(JJ);
sunindextype *jac_vals = SUNSparseMatrix_IndexValues(JJ);

// args are t, y, cj, put result in jacobian data matrix
p_python_functions->jac_times_cjmass.m_arg[0] = &tt;
p_python_functions->jac_times_cjmass.m_arg[1] = NV_DATA(yy);
Expand Down
4 changes: 2 additions & 2 deletions pybamm/solvers/c_solvers/idaklu/sundials_legacy_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
{
return N_VNew_Serial(vec_length);
}

N_Vector N_VNew_OpenMP(sunindextype vec_length, SUNContext sunctx)
{
return N_VNew_OpenMP(vec_length);
}

N_Vector N_VNew_Cuda(sunindextype vec_length, SUNContext sunctx)
{
return N_VNew_Cuda(vec_length);
Expand Down

0 comments on commit 58cee45

Please sign in to comment.