Loading...
Searching...
No Matches
GenericLinearSolver.h
// Copyright (C) 2008-2013 Garth N. Wells
//
// 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 __GENERIC_LINEAR_SOLVER_H
#define __GENERIC_LINEAR_SOLVER_H
#include <vector>
#include <memory>
#include <dolfin/common/Variable.h>
#include <dolfin/log/log.h>
namespace dolfin
{
// Forward declarations
class GenericLinearOperator;
class GenericMatrix;
class GenericVector;
class VectorSpaceBasis;
class GenericLinearSolver : public Variable
{
public:
virtual void
set_operator(std::shared_ptr<const GenericLinearOperator> A) = 0;
virtual void
set_operators(std::shared_ptr<const GenericLinearOperator> A,
std::shared_ptr<const GenericLinearOperator> P)
{
dolfin_error("GenericLinearSolver.h",
"set operator and preconditioner for linear solver",
"Not supported by current linear algebra backend");
}
virtual std::size_t solve(const GenericLinearOperator& A, GenericVector& x,
const GenericVector& b)
{
dolfin_error("GenericLinearSolver.h",
"solve linear system",
"Not supported by current linear algebra backend. Consider using solve(x, b)");
return 0;
}
virtual std::size_t solve(GenericVector& x, const GenericVector& b) = 0;
// FIXME: This should not be needed. Need to cleanup linear solver
// name jungle: default, lu, iterative, direct, krylov, etc
virtual std::string parameter_type() const
{
return "default";
}
virtual void update_parameters(const Parameters& parameters)
{
this->parameters.update(parameters);
}
protected:
// Developer note: The functions here provide similar
// functionality as the as_type functions in the
// LinearAlgebraObject base class. The difference is that they
// specifically complain that a matrix is required, which gives a
// user a more informative error message from solvers that don't
// support matrix-free representation of linear operators.
static const GenericMatrix& require_matrix(const GenericLinearOperator& A);
static std::shared_ptr<const GenericMatrix>
require_matrix(std::shared_ptr<const GenericLinearOperator> A);
};
}
#endif
dolfin::GenericLinearOperator
Definition GenericLinearOperator.h:43
dolfin::GenericLinearSolver
This class provides a general solver for linear systems Ax = b.
Definition GenericLinearSolver.h:38
dolfin::GenericLinearSolver::solve
virtual std::size_t solve(const GenericLinearOperator &A, GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition GenericLinearSolver.h:56
dolfin::GenericLinearSolver::parameter_type
virtual std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition GenericLinearSolver.h:71
dolfin::GenericLinearSolver::set_operator
virtual void set_operator(std::shared_ptr< const GenericLinearOperator > A)=0
Set operator (matrix).
dolfin::GenericLinearSolver::solve
virtual std::size_t solve(GenericVector &x, const GenericVector &b)=0
Solve linear system Ax = b.
dolfin::GenericLinearSolver::set_operators
virtual void set_operators(std::shared_ptr< const GenericLinearOperator > A, std::shared_ptr< const GenericLinearOperator > P)
Set operator (matrix) and preconditioner matrix.
Definition GenericLinearSolver.h:47
dolfin::GenericLinearSolver::update_parameters
virtual void update_parameters(const Parameters &parameters)
Update solver parameters (useful for LinearSolver wrapper).
Definition GenericLinearSolver.h:77
dolfin::GenericLinearSolver::require_matrix
static const GenericMatrix & require_matrix(const GenericLinearOperator &A)
Definition GenericLinearSolver.cpp:25
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::Parameters
Definition Parameters.h:95
dolfin::Parameters::update
void update(const Parameters &parameters)
Update parameters with another set of parameters.
Definition Parameters.cpp:245
dolfin::Variable::parameters
Parameters parameters
Parameters.
Definition Variable.h:74
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin::VectorSpaceBasis
Definition VectorSpaceBasis.h:34
dolfin
Definition adapt.h:30
dolfin::dolfin_error
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition log.cpp:129