Loading...
Searching...
No Matches
BelosKrylovSolver.h
// Copyright (C) 2014 Chris Richardson
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef __DOLFIN_BELOS_KRYLOV_SOLVER_H
#define __DOLFIN_BELOS_KRYLOV_SOLVER_H
#ifdef HAS_TRILINOS
#include <map>
#include <memory>
#include <BelosTpetraAdapter.hpp>
#include <BelosSolverFactory.hpp>
#include <Ifpack2_Factory.hpp>
#include <dolfin/common/types.h>
#include "GenericLinearSolver.h"
#include "TpetraVector.h"
#include "TpetraMatrix.h"
#include "TrilinosPreconditioner.h"
namespace dolfin
{
class GenericMatrix;
class GenericVector;
class TpetraMatrix;
class TpetraVector;
class TrilinosPreconditioner;
class BelosKrylovSolver : public GenericLinearSolver
{
public:
typedef Tpetra::Operator<double, int, dolfin::la_index,
TpetraVector::node_type> op_type;
typedef Belos::LinearProblem<double, TpetraVector::vector_type,
op_type> problem_type;
BelosKrylovSolver(std::string method = "default",
std::string preconditioner = "default");
BelosKrylovSolver(std::string method,
std::shared_ptr<TrilinosPreconditioner> preconditioner);
~BelosKrylovSolver();
void set_operator(std::shared_ptr<const GenericLinearOperator> A);
void set_operators(std::shared_ptr<const GenericLinearOperator> A,
std::shared_ptr<const GenericLinearOperator> P);
const TpetraMatrix& get_operator() const;
std::size_t solve(GenericVector& x, const GenericVector& b);
std::size_t solve(const GenericLinearOperator& A, GenericVector& x,
const GenericVector& b);
std::string str(bool verbose) const;
static std::map<std::string, std::string> methods();
static std::map<std::string, std::string> preconditioners();
static Parameters default_parameters();
std::string parameter_type() const
{
return "krylov_solver";
}
private:
friend class Ifpack2Preconditioner;
friend class MueluPreconditioner;
// Initialize solver
void init(const std::string& method);
// Set operator (matrix)
void _set_operator(std::shared_ptr<const TpetraMatrix> A);
// Set operator (matrix) and preconditioner matrix
void _set_operators(std::shared_ptr<const TpetraMatrix> A,
std::shared_ptr<const TpetraMatrix> P);
// Solve linear system Ax = b and return number of iterations
std::size_t _solve(TpetraVector& x, const TpetraVector& b);
// Solve linear system Ax = b and return number of iterations
std::size_t _solve(const TpetraMatrix& A, TpetraVector& x,
const TpetraVector& b);
// Set options for solver
void set_options();
void check_dimensions(const TpetraMatrix& A, const GenericVector& x,
const GenericVector& b) const;
// Belos solver pointer
Teuchos::RCP<Belos::SolverManager<double, TpetraVector::vector_type,
op_type>> _solver;
// The preconditioner, if any
std::shared_ptr<TrilinosPreconditioner> _prec;
// Container for the problem, see Belos::LinearProblem
// documentation
Teuchos::RCP<problem_type> _problem;
// Operator (the matrix)
std::shared_ptr<const TpetraMatrix> _matA;
};
}
#endif
#endif
dolfin::BelosKrylovSolver::solve
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b and return number of iterations.
Definition BelosKrylovSolver.cpp:153
dolfin::BelosKrylovSolver::problem_type
Belos::LinearProblem< double, TpetraVector::vector_type, op_type > problem_type
Belos problem type.
Definition BelosKrylovSolver.h:60
dolfin::BelosKrylovSolver::op_type
Tpetra::Operator< double, int, dolfin::la_index, TpetraVector::node_type > op_type
Tpetra operator type.
Definition BelosKrylovSolver.h:57
dolfin::BelosKrylovSolver::parameter_type
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition BelosKrylovSolver.h:104
dolfin::BelosKrylovSolver::get_operator
const TpetraMatrix & get_operator() const
Get operator (matrix).
Definition BelosKrylovSolver.cpp:142
dolfin::BelosKrylovSolver::set_operator
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix).
Definition BelosKrylovSolver.cpp:129
dolfin::BelosKrylovSolver::~BelosKrylovSolver
~BelosKrylovSolver()
Destructor.
Definition BelosKrylovSolver.cpp:112
dolfin::BelosKrylovSolver::default_parameters
static Parameters default_parameters()
Default parameter values.
Definition BelosKrylovSolver.cpp:117
dolfin::BelosKrylovSolver::BelosKrylovSolver
BelosKrylovSolver(std::string method="default", std::string preconditioner="default")
Definition BelosKrylovSolver.cpp:67
dolfin::BelosKrylovSolver::preconditioners
static std::map< std::string, std::string > preconditioners()
Return a list of available preconditioners.
Definition BelosKrylovSolver.cpp:39
dolfin::BelosKrylovSolver::methods
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition BelosKrylovSolver.cpp:50
dolfin::BelosKrylovSolver::set_operators
void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition BelosKrylovSolver.cpp:135
dolfin::BelosKrylovSolver::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition BelosKrylovSolver.cpp:167
dolfin::GenericLinearOperator
Definition GenericLinearOperator.h:43
dolfin::GenericLinearSolver
This class provides a general solver for linear systems Ax = b.
Definition GenericLinearSolver.h:38
dolfin::GenericMatrix
This class defines a common interface for matrices.
Definition GenericMatrix.h:47
dolfin::GenericVector
This class defines a common interface for vectors.
Definition GenericVector.h:48
dolfin::Ifpack2Preconditioner
Implements preconditioners using Ifpack2 from Trilinos.
Definition Ifpack2Preconditioner.h:41
dolfin::MueluPreconditioner
Implements Muelu preconditioner from Trilinos.
Definition MueluPreconditioner.h:41
dolfin::Parameters
Definition Parameters.h:95
dolfin::TpetraMatrix
Definition TpetraMatrix.h:59
dolfin::TpetraVector
Definition TpetraVector.h:54
dolfin::TpetraVector::vector_type
Tpetra::MultiVector< double, int, dolfin::la_index, node_type > vector_type
TpetraVector vector type (scalar, local index, global index, node).
Definition TpetraVector.h:63
dolfin::TpetraVector::node_type
Tpetra::MultiVector ::node_type node_type
Node type.
Definition TpetraVector.h:58
dolfin::TrilinosPreconditioner
This class provides a common base for Trilinos preconditioners.
Definition TrilinosPreconditioner.h:37
dolfin
Definition adapt.h:30
dolfin::la_index
PetscInt la_index
Index type for compatibility with linear algebra backend(s).
Definition types.h:32
dolfin::init
void init(int argc, char *argv[])
Definition init.cpp:27