Skip to content

Commit

Permalink
#2217 raise error on bad options to idaklu solver
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Nov 17, 2022
1 parent a975b42 commit d7b203e
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions pybamm/solvers/c_solvers/idaklu/options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "options.hpp"
#include <stdexcept>


using namespace std::string_literals;

Options::Options(py::dict options)
: print_stats(options["print_stats"].cast<bool>()),
Expand All @@ -23,8 +27,10 @@ Options::Options(py::dict options)
}
else
{
py::print("Unknown jacobian type, using sparse by default");
jacobian = "sparse";
throw std::domain_error(
"Unknown jacobian type \""s + jacobian +
"\". Should be one of \"sparse\", \"dense\", \"matrix-free\" or \"none\"."s
);
}

using_iterative_solver = false;
Expand All @@ -47,30 +53,37 @@ Options::Options(py::dict options)
}
else if (jacobian == "sparse")
{
py::print("Unknown linear solver or incompatible options using "
"SUNLinSol_KLU by default");
linear_solver = "SUNLinSol_KLU";
throw std::domain_error(
"Unknown linear solver or incompatible options. For a sparse jacobian "
"please use the SUNLinSol_KLU linear solver"
);
}
else if (jacobian == "matrix-free")
{
py::print("Unknown linear solver or incompatible options using "
"SUNLinSol_SPBCGS by default");
linear_solver = "SUNLinSol_SPBCGS";
using_iterative_solver = true;
throw std::domain_error(
"Unknown linear solver or incompatible options. For a matrix-free jacobian "
"please use one of the iterative linear solvers: \"SUNLinSol_SPBCGS\", "
"\"SUNLinSol_SPFGMR\", \"SUNLinSol_SPGMR\", or \"SUNLinSol_SPTFQMR\"."
);
}
else
{
py::print("Unknown linear solver or incompatible options using "
"SUNLinSol_Dense by default");
linear_solver = "SUNLinSol_Dense";
throw std::domain_error(
"Unknown linear solver \""s + linear_solver +
"\", use one of \"SUNLinSol_KLU\", \"SUNLinSol_Dense\", "
"\"SUNLinSol_LapackDense\", \"SUNLinSol_SPBCGS\", \"SUNLinSol_SPFGMR\", "
"\"SUNLinSol_SPGMR\", or \"SUNLinSol_SPTFQMR\""
);
}

if (using_iterative_solver)
{
if (preconditioner != "none" && preconditioner != "BBDP")
{
py::print("Unknown preconditioner using BBDP by default");
preconditioner = "BBDP";
throw std::domain_error(
"Unknown preconditioner \""s + preconditioner +
"\", use one of \"BBDP\" or \"none\""s
);
}
}
else
Expand Down

0 comments on commit d7b203e

Please sign in to comment.