Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more idaklu solver options (number 2) #4282

Merged
merged 9 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## Features

- Added additional user-configurable options to the (`IDAKLUSolver`). ([#4249](https://github.com/pybamm-team/PyBaMM/pull/4249))
- Added functionality to pass in arbitrary functions of time as the argument for a (`pybamm.step`). ([#4222](https://github.com/pybamm-team/PyBaMM/pull/4222))
- Added new parameters `"f{pref]Initial inner SEI on cracks thickness [m]"` and `"f{pref]Initial outer SEI on cracks thickness [m]"`, instead of hardcoding these to `L_inner_0 / 10000` and `L_outer_0 / 10000`. ([#4168](https://github.com/pybamm-team/PyBaMM/pull/4168))
- Added `pybamm.DataLoader` class to fetch data files from [pybamm-data](https://github.com/pybamm-team/pybamm-data/releases/tag/v1.0.0) and store it under local cache. ([#4098](https://github.com/pybamm-team/PyBaMM/pull/4098))
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
Loading