DOLFIN
DOLFIN C++ interface
Amesos2LUSolver.h
1 // Copyright (C) 2015 Chris Richardson
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef __DOLFIN_AMESOS2_LU_SOLVER_H
20 #define __DOLFIN_AMESOS2_LU_SOLVER_H
21 
22 #ifdef HAS_TRILINOS
23 
24 #include "GenericLinearSolver.h"
25 #include <Amesos2_Factory.hpp>
26 
27 namespace dolfin
28 {
30  class GenericLinearOperator;
31  class GenericVector;
32  class TpetraMatrix;
33  class TpetraVector;
34 
38 
40  {
41  public:
42 
44  Amesos2LUSolver(std::string method="default");
45 
47  Amesos2LUSolver(std::shared_ptr<const TpetraMatrix> A,
48  std::string method="default");
49 
52 
54  void set_operator(std::shared_ptr<const GenericLinearOperator> A);
55 
57  void set_operator(std::shared_ptr<const TpetraMatrix> A);
58 
60  const GenericLinearOperator& get_operator() const;
61 
63  std::size_t solve(GenericVector& x, const GenericVector& b);
64 
66  std::size_t solve(const GenericLinearOperator& A,
67  GenericVector& x,
68  const GenericVector& b);
69 
71  std::size_t solve(const TpetraMatrix& A,
72  TpetraVector& x,
73  const TpetraVector& b);
74 
76  std::string str(bool verbose) const;
77 
79  static std::map<std::string, std::string> methods();
80 
83 
85  std::string parameter_type() const
86  { return "lu_solver"; }
87 
88  private:
89 
90  void init_solver(std::string& method);
91 
92  // Reference counted pointer (RCP) to solver
93  Teuchos::RCP<Amesos2::Solver<TpetraMatrix::matrix_type,
94  TpetraVector::vector_type>> _solver;
95 
96  // Operator (the matrix)
97  std::shared_ptr<const TpetraMatrix> _matA;
98 
99  // Method name
100  std::string _method_name;
101  };
102 
103 }
104 
105 #endif
106 
107 #endif
Definition: adapt.h:29
Definition: GenericLinearOperator.h:42
Definition: TpetraMatrix.h:58
static Parameters default_parameters()
Default parameter values.
Definition: Amesos2LUSolver.cpp:60
Tpetra::MultiVector< double, int, dolfin::la_index, node_type > vector_type
TpetraVector vector type (scalar, local index, global index, node)
Definition: TpetraVector.h:63
const GenericLinearOperator & get_operator() const
Get operator (matrix)
Definition: Amesos2LUSolver.cpp:129
Definition: Amesos2LUSolver.h:39
std::string parameter_type() const
Return parameter type: "krylov_solver" or "lu_solver".
Definition: Amesos2LUSolver.h:85
Definition: Parameters.h:94
Definition: TpetraVector.h:53
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: Amesos2LUSolver.cpp:35
Amesos2LUSolver(std::string method="default")
Constructor.
Definition: Amesos2LUSolver.cpp:68
This class provides a general solver for linear systems Ax = b.
Definition: GenericLinearSolver.h:37
~Amesos2LUSolver()
Destructor.
Definition: Amesos2LUSolver.cpp:95
Tpetra::CrsMatrix< double, int, dolfin::la_index > matrix_type
Matrix type (scalar, local index, global index)
Definition: TpetraMatrix.h:64
void set_operator(std::shared_ptr< const GenericLinearOperator > A)
Set operator (matrix)
Definition: Amesos2LUSolver.cpp:101
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: Amesos2LUSolver.cpp:204
This class defines a common interface for vectors.
Definition: GenericVector.h:47
std::size_t solve(GenericVector &x, const GenericVector &b)
Solve linear system Ax = b.
Definition: Amesos2LUSolver.cpp:140