version 3.10-dev
istlsolversmultitype.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_LINEAR_ISTL_SOLVERS_MULTITYPE_HH
14#define DUMUX_LINEAR_ISTL_SOLVERS_MULTITYPE_HH
15
16#include <dune/common/version.hh>
17
18#include <dune/istl/solvers.hh>
19#include <dune/istl/cholmod.hh>
20#include <dune/istl/umfpack.hh>
21
23
24namespace Dumux {
25
26DUMUX_REGISTER_SOLVER("loopsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::LoopSolver>());
27DUMUX_REGISTER_SOLVER("gradientsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::GradientSolver>());
28DUMUX_REGISTER_SOLVER("cgsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::CGSolver>());
29DUMUX_REGISTER_SOLVER("bicgstabsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::BiCGSTABSolver>());
30DUMUX_REGISTER_SOLVER("minressolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::MINRESSolver>());
31DUMUX_REGISTER_SOLVER("restartedgmressolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::RestartedGMResSolver>());
32DUMUX_REGISTER_SOLVER("restartedflexiblegmressolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::RestartedFlexibleGMResSolver>());
33DUMUX_REGISTER_SOLVER("generalizedpcgsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::GeneralizedPCGSolver>());
34DUMUX_REGISTER_SOLVER("restartedfcgsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::RestartedFCGSolver>());
35DUMUX_REGISTER_SOLVER("completefcgsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator<Dune::CompleteFCGSolver>());
36#if HAVE_SUITESPARSE_CHOLMOD
37DUMUX_REGISTER_SOLVER("cholmod", Dumux::MultiTypeBlockMatrixSolverTag,
38 [](auto opTraits, const auto& op, const Dune::ParameterTree& config)
39 -> std::shared_ptr<typename decltype(opTraits)::solver_type>
40 {
41 using OpTraits = decltype(opTraits);
42 using M = typename OpTraits::matrix_type;
43 using D = typename OpTraits::domain_type;
44 // works only for sequential operators
45 if constexpr (OpTraits::isParallel){
46 if(opTraits.getCommOrThrow(op).communicator().size() > 1)
47 DUNE_THROW(Dune::InvalidStateException, "CholMod works only for sequential operators.");
48 }
49 if constexpr (OpTraits::isAssembled &&
50 // check whether the Matrix field_type is double or float
51 (std::is_same_v<typename FieldTraits<D>::field_type, double> ||
52 std::is_same_v<typename FieldTraits<D>::field_type, float>)){
53 const auto& A = opTraits.getAssembledOpOrThrow(op);
54 const M& mat = A->getmat();
55 auto solver = std::make_shared<Dune::Cholmod<D>>();
56 solver->setMatrix(mat);
57 return solver;
58 }
59 DUNE_THROW(UnsupportedType,
60 "Unsupported Type in Cholmod (only double and float supported)");
61 });
62#endif // HAVE_SUITESPARSE_CHOLMOD
63#if HAVE_SUITESPARSE_UMFPACK && DUNE_VERSION_GTE(DUNE_ISTL, 2, 10)
64DUMUX_REGISTER_SOLVER("umfpack", Dumux::MultiTypeBlockMatrixSolverTag,
65 [](auto opTraits, const auto& op, const Dune::ParameterTree& config)
66 -> std::shared_ptr<typename decltype(opTraits)::solver_type>
67 {
68 using OpTraits = decltype(opTraits);
69 // works only for sequential operators
70 if constexpr (OpTraits::isParallel){
71 if(opTraits.getCommOrThrow(op).communicator().size() > 1)
72 DUNE_THROW(Dune::InvalidStateException, "UMFPack works only for sequential operators.");
73 }
74 if constexpr (OpTraits::isAssembled){
75 using M = typename OpTraits::matrix_type;
76 // check if UMFPack<M>* is convertible to
77 // InverseOperator*. This checks compatibility of the
78 // domain and range types
79 if constexpr (UMFPackImpl::isValidBlock<OpTraits>::value) {
80 const auto& A = opTraits.getAssembledOpOrThrow(op);
81 const M& mat = A->getmat();
82 int verbose = config.get("verbose", 0);
83 return std::make_shared<Dune::UMFPack<M>>(mat,verbose);
84 }
85 }
86 DUNE_THROW(UnsupportedType,
87 "Unsupported Type in UMFPack (only double and std::complex<double> supported)");
88 return nullptr;
89 });
90#endif // HAVE_SUITESPARSE_UMFPACK && DUNE_VERSION_GTE(DUNE_ISTL, 2, 10)
91} // end namespace Dumux
92
93#endif // DUMUX_LINEAR_ISTL_SOLVERS_MULTITYPE_HH
The specialized Dumux macro and tag for the ISTL registry to choose the solver and preconditioner at ...
Definition: adapt.hh:17
DUMUX_REGISTER_SOLVER("loopsolver", Dumux::MultiTypeBlockMatrixSolverTag, defaultIterativeSolverCreator< Dune::LoopSolver >())