Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions manual/sphinx/user_docs/time_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ nonlinear solvers:
`CVodeSetEpsLin
<https://sundials.readthedocs.io/en/latest/cvodes/Usage/SIM.html#c.CVodeSetEpsLin>`_.

The linear solver type can be set using the ``linear_solver`` option.
Valid choices include ``gmres`` (the default), ``fgmres``, ``tfqmr``, ``bcgs``.

IMEX-BDF2
---------

Expand Down
25 changes: 24 additions & 1 deletion src/solver/impls/cvode/cvode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#include <cvode/cvode_bbdpre.h>
#include <cvode/cvode_ls.h>

#include <sunlinsol/sunlinsol_spbcgs.h>
#include <sunlinsol/sunlinsol_spfgmr.h>
#include <sunlinsol/sunlinsol_sptfqmr.h>

#include <algorithm>
#include <iterator>
#include <numeric>
Expand All @@ -59,6 +63,8 @@
BOUT_ENUM_CLASS(positivity_constraint, none, positive, non_negative, negative,
non_positive);

BOUT_ENUM_CLASS(linear_solver, gmres, fgmres, tfqmr, bcgs);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: enum 'linear_solver' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

BOUT_ENUM_CLASS(linear_solver, gmres, fgmres, tfqmr, bcgs);
                ^


// NOLINTBEGIN(readability-identifier-length)
namespace {
int cvode_linear_rhs(BoutReal t, N_Vector u, N_Vector du, void* user_data);
Expand Down Expand Up @@ -344,7 +350,24 @@ int CvodeSolver::init() {

const auto prectype =
use_precon ? (rightprec ? SUN_PREC_RIGHT : SUN_PREC_LEFT) : SUN_PREC_NONE;
sun_solver = callWithSUNContext(SUNLinSol_SPGMR, suncontext, uvec, prectype, maxl);

switch ((*options)["linear_solver"]
.doc("Set linear solver type. Default is gmres.")
.withDefault(linear_solver::gmres)) {
case linear_solver::gmres:
sun_solver = callWithSUNContext(SUNLinSol_SPGMR, suncontext, uvec, prectype, maxl);
break;
case linear_solver::fgmres:
sun_solver = callWithSUNContext(SUNLinSol_SPFGMR, suncontext, uvec, prectype, maxl);
break;
case linear_solver::tfqmr:
sun_solver =
callWithSUNContext(SUNLinSol_SPTFQMR, suncontext, uvec, prectype, maxl);
break;
case linear_solver::bcgs:
sun_solver = callWithSUNContext(SUNLinSol_SPBCGS, suncontext, uvec, prectype, maxl);
break;
};
if (sun_solver == nullptr) {
throw BoutException("Creating SUNDIALS linear solver failed\n");
}
Expand Down
Loading