Skip to content

Commit d7b203e

Browse files
committed
#2217 raise error on bad options to idaklu solver
1 parent a975b42 commit d7b203e

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

pybamm/solvers/c_solvers/idaklu/options.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#include "options.hpp"
2+
#include <stdexcept>
3+
4+
5+
using namespace std::string_literals;
26

37
Options::Options(py::dict options)
48
: print_stats(options["print_stats"].cast<bool>()),
@@ -23,8 +27,10 @@ Options::Options(py::dict options)
2327
}
2428
else
2529
{
26-
py::print("Unknown jacobian type, using sparse by default");
27-
jacobian = "sparse";
30+
throw std::domain_error(
31+
"Unknown jacobian type \""s + jacobian +
32+
"\". Should be one of \"sparse\", \"dense\", \"matrix-free\" or \"none\"."s
33+
);
2834
}
2935

3036
using_iterative_solver = false;
@@ -47,30 +53,37 @@ Options::Options(py::dict options)
4753
}
4854
else if (jacobian == "sparse")
4955
{
50-
py::print("Unknown linear solver or incompatible options using "
51-
"SUNLinSol_KLU by default");
52-
linear_solver = "SUNLinSol_KLU";
56+
throw std::domain_error(
57+
"Unknown linear solver or incompatible options. For a sparse jacobian "
58+
"please use the SUNLinSol_KLU linear solver"
59+
);
5360
}
5461
else if (jacobian == "matrix-free")
5562
{
56-
py::print("Unknown linear solver or incompatible options using "
57-
"SUNLinSol_SPBCGS by default");
58-
linear_solver = "SUNLinSol_SPBCGS";
59-
using_iterative_solver = true;
63+
throw std::domain_error(
64+
"Unknown linear solver or incompatible options. For a matrix-free jacobian "
65+
"please use one of the iterative linear solvers: \"SUNLinSol_SPBCGS\", "
66+
"\"SUNLinSol_SPFGMR\", \"SUNLinSol_SPGMR\", or \"SUNLinSol_SPTFQMR\"."
67+
);
6068
}
6169
else
6270
{
63-
py::print("Unknown linear solver or incompatible options using "
64-
"SUNLinSol_Dense by default");
65-
linear_solver = "SUNLinSol_Dense";
71+
throw std::domain_error(
72+
"Unknown linear solver \""s + linear_solver +
73+
"\", use one of \"SUNLinSol_KLU\", \"SUNLinSol_Dense\", "
74+
"\"SUNLinSol_LapackDense\", \"SUNLinSol_SPBCGS\", \"SUNLinSol_SPFGMR\", "
75+
"\"SUNLinSol_SPGMR\", or \"SUNLinSol_SPTFQMR\""
76+
);
6677
}
6778

6879
if (using_iterative_solver)
6980
{
7081
if (preconditioner != "none" && preconditioner != "BBDP")
7182
{
72-
py::print("Unknown preconditioner using BBDP by default");
73-
preconditioner = "BBDP";
83+
throw std::domain_error(
84+
"Unknown preconditioner \""s + preconditioner +
85+
"\", use one of \"BBDP\" or \"none\""s
86+
);
7487
}
7588
}
7689
else

0 commit comments

Comments
 (0)