Skip to content

Commit

Permalink
Add more idaklu solver options (number 2) (pybamm-team#4282)
Browse files Browse the repository at this point in the history
* IDAKLU options updates

* format

* update defaults and docstrings

* Update CHANGELOG.md

* Update test_idaklu_solver.py

* Move changelog to `Unreleased`

* Update CHANGELOG.md

---------

Co-authored-by: kratman <[email protected]>
Co-authored-by: Eric G. Kratz <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent ce407ae commit ba39170
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 266 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Features

- Added additional user-configurable options to the (`IDAKLUSolver`) and adjusted the default values to improve performance. ([#4282](https://github.com/pybamm-team/PyBaMM/pull/4282))

# [v24.5rc2](https://github.com/pybamm-team/PyBaMM/tree/v24.5rc2) - 2024-07-12

## Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExpressionSet
const int n_s,
const int n_e,
const int n_p,
const Options& options)
const SetupOptions& options)
: number_of_states(n_s),
number_of_events(n_e),
number_of_parameters(n_p),
Expand All @@ -46,7 +46,7 @@ class ExpressionSet
events(events),
tmp_state_vector(number_of_states),
tmp_sparse_jacobian_data(jac_times_cjmass_nnz),
options(options)
setup_opts(options)
{};

int number_of_states;
Expand All @@ -73,7 +73,7 @@ class ExpressionSet
std::vector<int64_t> jac_times_cjmass_colptrs; // cppcheck-suppress unusedStructMember
std::vector<realtype> inputs; // cppcheck-suppress unusedStructMember

Options options;
SetupOptions setup_opts;

virtual realtype *get_tmp_state_vector() = 0;
virtual realtype *get_tmp_sparse_jacobian_data() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CasadiFunctions : public ExpressionSet<CasadiFunction>
const std::vector<BaseFunctionType*>& var_fcns,
const std::vector<BaseFunctionType*>& dvar_dy_fcns,
const std::vector<BaseFunctionType*>& dvar_dp_fcns,
const Options& options
const SetupOptions& setup_opts
) :
rhs_alg_casadi(rhs_alg),
jac_times_cjmass_casadi(jac_times_cjmass),
Expand All @@ -98,7 +98,7 @@ class CasadiFunctions : public ExpressionSet<CasadiFunction>
static_cast<Expression*>(&sens_casadi),
static_cast<Expression*>(&events_casadi),
n_s, n_e, n_p,
options)
setup_opts)
{
// convert BaseFunctionType list to CasadiFunction list
// NOTE: You must allocate ALL std::vector elements before taking references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class IREEFunctions : public ExpressionSet<IREEFunction>
const std::vector<BaseFunctionType*>& var_fcns,
const std::vector<BaseFunctionType*>& dvar_dy_fcns,
const std::vector<BaseFunctionType*>& dvar_dp_fcns,
const Options& options
const SetupOptions& setup_opts
) :
iree_init_status(iree_init()),
rhs_alg_iree(rhs_alg),
Expand All @@ -82,7 +82,7 @@ class IREEFunctions : public ExpressionSet<IREEFunction>
static_cast<Expression*>(&sens_iree),
static_cast<Expression*>(&events_iree),
n_s, n_e, n_p,
options)
setup_opts)
{
// convert BaseFunctionType list to IREEFunction list
// NOTE: You must allocate ALL std::vector elements before taking references
Expand Down
17 changes: 15 additions & 2 deletions pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class IDAKLUSolverOpenMP : public IDAKLUSolver
std::vector<realtype> res;
std::vector<realtype> res_dvar_dy;
std::vector<realtype> res_dvar_dp;
Options options;
SetupOptions setup_opts;
SolverOptions solver_opts;

#if SUNDIALS_VERSION_MAJOR >= 6
SUNContext sunctx;
Expand All @@ -84,7 +85,9 @@ class IDAKLUSolverOpenMP : public IDAKLUSolver
int jac_bandwidth_lower,
int jac_bandwidth_upper,
std::unique_ptr<ExprSet> functions,
const Options& options);
const SetupOptions &setup_opts,
const SolverOptions &solver_opts
);

/**
* @brief Destructor
Expand Down Expand Up @@ -139,6 +142,16 @@ class IDAKLUSolverOpenMP : public IDAKLUSolver
* @brief Allocate memory for matrices (noting appropriate matrix format/types)
*/
void SetMatrix();

/**
* @brief Apply user-configurable IDA options
*/
void SetSolverOptions();

/**
* @brief Check the return flag for errors
*/
void CheckErrors(int const & flag);
};

#include "IDAKLUSolverOpenMP.inl"
Expand Down
Loading

0 comments on commit ba39170

Please sign in to comment.